Browse Source
# Conflicts: # src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/SubscribeListenerForPlatform.javapull/446/head
648540858
3 years ago
39 changed files with 1024 additions and 340 deletions
@ -0,0 +1,34 @@ |
|||||
|
package com.genersoft.iot.vmp.gb28181.bean; |
||||
|
|
||||
|
/** |
||||
|
* 摄像机同步状态 |
||||
|
*/ |
||||
|
public class SyncStatus { |
||||
|
private int total; |
||||
|
private int current; |
||||
|
private String errorMsg; |
||||
|
|
||||
|
public int getTotal() { |
||||
|
return total; |
||||
|
} |
||||
|
|
||||
|
public void setTotal(int total) { |
||||
|
this.total = total; |
||||
|
} |
||||
|
|
||||
|
public int getCurrent() { |
||||
|
return current; |
||||
|
} |
||||
|
|
||||
|
public void setCurrent(int current) { |
||||
|
this.current = current; |
||||
|
} |
||||
|
|
||||
|
public String getErrorMsg() { |
||||
|
return errorMsg; |
||||
|
} |
||||
|
|
||||
|
public void setErrorMsg(String errorMsg) { |
||||
|
this.errorMsg = errorMsg; |
||||
|
} |
||||
|
} |
@ -1,49 +0,0 @@ |
|||||
package com.genersoft.iot.vmp.gb28181.event.subscribe; |
|
||||
|
|
||||
import com.genersoft.iot.vmp.common.VideoManagerConstants; |
|
||||
import com.genersoft.iot.vmp.conf.DynamicTask; |
|
||||
import com.genersoft.iot.vmp.conf.RedisKeyExpirationEventMessageListener; |
|
||||
import com.genersoft.iot.vmp.conf.UserSetting; |
|
||||
import org.slf4j.Logger; |
|
||||
import org.slf4j.LoggerFactory; |
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
|
||||
import org.springframework.data.redis.connection.Message; |
|
||||
import org.springframework.data.redis.listener.RedisMessageListenerContainer; |
|
||||
import org.springframework.stereotype.Component; |
|
||||
|
|
||||
/** |
|
||||
* 平台订阅到期事件 |
|
||||
*/ |
|
||||
@Component |
|
||||
public class SubscribeListenerForPlatform extends RedisKeyExpirationEventMessageListener { |
|
||||
|
|
||||
private Logger logger = LoggerFactory.getLogger(SubscribeListenerForPlatform.class); |
|
||||
|
|
||||
@Autowired |
|
||||
private UserSetting userSetting; |
|
||||
|
|
||||
@Autowired |
|
||||
private DynamicTask dynamicTask; |
|
||||
|
|
||||
public SubscribeListenerForPlatform(RedisMessageListenerContainer listenerContainer, UserSetting userSetting) { |
|
||||
super(listenerContainer, userSetting); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 监听失效的key |
|
||||
* @param message |
|
||||
* @param pattern |
|
||||
*/ |
|
||||
@Override |
|
||||
public void onMessage(Message message, byte[] pattern) { |
|
||||
// 获取失效的key
|
|
||||
String expiredKey = message.toString(); |
|
||||
// 订阅到期
|
|
||||
String PLATFORM_KEEPLIVEKEY_PREFIX = VideoManagerConstants.SIP_SUBSCRIBE_PREFIX + userSetting.getServerId() + "_"; |
|
||||
if (expiredKey.startsWith(PLATFORM_KEEPLIVEKEY_PREFIX)) { |
|
||||
// 取消定时任务
|
|
||||
dynamicTask.stop(expiredKey); |
|
||||
} |
|
||||
} |
|
||||
} |
|
@ -1,5 +1,9 @@ |
|||||
package com.genersoft.iot.vmp.gb28181.task; |
package com.genersoft.iot.vmp.gb28181.task; |
||||
|
|
||||
|
import javax.sip.DialogState; |
||||
|
|
||||
public interface ISubscribeTask extends Runnable{ |
public interface ISubscribeTask extends Runnable{ |
||||
void stop(); |
void stop(); |
||||
|
|
||||
|
DialogState getDialogState(); |
||||
} |
} |
||||
|
@ -0,0 +1,126 @@ |
|||||
|
package com.genersoft.iot.vmp.utils; |
||||
|
|
||||
|
/** |
||||
|
* 坐标转换 |
||||
|
* 一个提供了百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换的工具类 |
||||
|
* 参考https://github.com/wandergis/coordtransform 写的Java版本
|
||||
|
* @author Xinconan |
||||
|
* @date 2016-03-18 |
||||
|
* @url https://github.com/xinconan/coordtransform
|
||||
|
*/ |
||||
|
public class Coordtransform { |
||||
|
|
||||
|
private static double x_PI = 3.14159265358979324 * 3000.0 / 180.0; |
||||
|
private static double PI = 3.1415926535897932384626; |
||||
|
private static double a = 6378245.0; |
||||
|
private static double ee = 0.00669342162296594323; |
||||
|
|
||||
|
/** |
||||
|
* 百度坐标系 (BD-09) 与 火星坐标系 (GCJ-02)的转换 |
||||
|
* 即 百度 转 谷歌、高德 |
||||
|
* @param bd_lon |
||||
|
* @param bd_lat |
||||
|
* @return Double[lon,lat] |
||||
|
*/ |
||||
|
public static Double[] BD09ToGCJ02(Double bd_lon,Double bd_lat){ |
||||
|
double x = bd_lon - 0.0065; |
||||
|
double y = bd_lat - 0.006; |
||||
|
double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_PI); |
||||
|
double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_PI); |
||||
|
Double[] arr = new Double[2]; |
||||
|
arr[0] = z * Math.cos(theta); |
||||
|
arr[1] = z * Math.sin(theta); |
||||
|
return arr; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换 |
||||
|
* 即谷歌、高德 转 百度 |
||||
|
* @param gcj_lon |
||||
|
* @param gcj_lat |
||||
|
* @return Double[lon,lat] |
||||
|
*/ |
||||
|
public static Double[] GCJ02ToBD09(Double gcj_lon,Double gcj_lat){ |
||||
|
double z = Math.sqrt(gcj_lon * gcj_lon + gcj_lat * gcj_lat) + 0.00002 * Math.sin(gcj_lat * x_PI); |
||||
|
double theta = Math.atan2(gcj_lat, gcj_lon) + 0.000003 * Math.cos(gcj_lon * x_PI); |
||||
|
Double[] arr = new Double[2]; |
||||
|
arr[0] = z * Math.cos(theta) + 0.0065; |
||||
|
arr[1] = z * Math.sin(theta) + 0.006; |
||||
|
return arr; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* WGS84转GCJ02 |
||||
|
* @param wgs_lon |
||||
|
* @param wgs_lat |
||||
|
* @return Double[lon,lat] |
||||
|
*/ |
||||
|
public static Double[] WGS84ToGCJ02(Double wgs_lon,Double wgs_lat){ |
||||
|
if(outOfChina(wgs_lon, wgs_lat)){ |
||||
|
return new Double[]{wgs_lon,wgs_lat}; |
||||
|
} |
||||
|
double dlat = transformlat(wgs_lon - 105.0, wgs_lat - 35.0); |
||||
|
double dlng = transformlng(wgs_lon - 105.0, wgs_lat - 35.0); |
||||
|
double radlat = wgs_lat / 180.0 * PI; |
||||
|
double magic = Math.sin(radlat); |
||||
|
magic = 1 - ee * magic * magic; |
||||
|
double sqrtmagic = Math.sqrt(magic); |
||||
|
dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * PI); |
||||
|
dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * PI); |
||||
|
Double[] arr = new Double[2]; |
||||
|
arr[0] = wgs_lon + dlng; |
||||
|
arr[1] = wgs_lat + dlat; |
||||
|
return arr; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* GCJ02转WGS84 |
||||
|
* @param gcj_lon |
||||
|
* @param gcj_lat |
||||
|
* @return Double[lon,lat] |
||||
|
*/ |
||||
|
public static Double[] GCJ02ToWGS84(Double gcj_lon,Double gcj_lat){ |
||||
|
if(outOfChina(gcj_lon, gcj_lat)){ |
||||
|
return new Double[]{gcj_lon,gcj_lat}; |
||||
|
} |
||||
|
double dlat = transformlat(gcj_lon - 105.0, gcj_lat - 35.0); |
||||
|
double dlng = transformlng(gcj_lon - 105.0, gcj_lat - 35.0); |
||||
|
double radlat = gcj_lat / 180.0 * PI; |
||||
|
double magic = Math.sin(radlat); |
||||
|
magic = 1 - ee * magic * magic; |
||||
|
double sqrtmagic = Math.sqrt(magic); |
||||
|
dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * PI); |
||||
|
dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * PI); |
||||
|
double mglat = gcj_lat + dlat; |
||||
|
double mglng = gcj_lon + dlng; |
||||
|
return new Double[]{gcj_lon * 2 - mglng, gcj_lat * 2 - mglat}; |
||||
|
} |
||||
|
|
||||
|
private static Double transformlat(double lng, double lat) { |
||||
|
double ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * Math.sqrt(Math.abs(lng)); |
||||
|
ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0; |
||||
|
ret += (20.0 * Math.sin(lat * PI) + 40.0 * Math.sin(lat / 3.0 * PI)) * 2.0 / 3.0; |
||||
|
ret += (160.0 * Math.sin(lat / 12.0 * PI) + 320 * Math.sin(lat * PI / 30.0)) * 2.0 / 3.0; |
||||
|
return ret; |
||||
|
} |
||||
|
|
||||
|
private static Double transformlng(double lng,double lat) { |
||||
|
double ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt(Math.abs(lng)); |
||||
|
ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0; |
||||
|
ret += (20.0 * Math.sin(lng * PI) + 40.0 * Math.sin(lng / 3.0 * PI)) * 2.0 / 3.0; |
||||
|
ret += (150.0 * Math.sin(lng / 12.0 * PI) + 300.0 * Math.sin(lng / 30.0 * PI)) * 2.0 / 3.0; |
||||
|
return ret; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* outOfChina |
||||
|
* @描述: 判断是否在国内,不在国内则不做偏移 |
||||
|
* @param lng |
||||
|
* @param lat |
||||
|
* @return {boolean} |
||||
|
*/ |
||||
|
private static boolean outOfChina(Double lng,Double lat) { |
||||
|
return (lng < 72.004 || lng > 137.8347) || ((lat < 0.8293 || lat > 55.8271) || false); |
||||
|
}; |
||||
|
|
||||
|
} |
@ -0,0 +1,102 @@ |
|||||
|
<template> |
||||
|
<div id="SyncChannelProgress" v-loading="isLoging"> |
||||
|
<el-dialog |
||||
|
width="240px" |
||||
|
top="13%" |
||||
|
:append-to-body="true" |
||||
|
:close-on-click-modal="false" |
||||
|
:visible.sync="showDialog" |
||||
|
:destroy-on-close="true" |
||||
|
:show-close="true" |
||||
|
@close="close()" |
||||
|
style="text-align: center"> |
||||
|
<el-progress type="circle" :percentage="percentage" :status="syncStatus"></el-progress> |
||||
|
<div style="text-align: center"> |
||||
|
{{msg}} |
||||
|
</div> |
||||
|
</el-dialog> |
||||
|
</div> |
||||
|
</template> |
||||
|
|
||||
|
<script> |
||||
|
|
||||
|
export default { |
||||
|
name: "SyncChannelProgress", |
||||
|
computed: {}, |
||||
|
props: ['platformId'], |
||||
|
created() {}, |
||||
|
data() { |
||||
|
return { |
||||
|
syncStatus: null, |
||||
|
percentage: 0, |
||||
|
total: 0, |
||||
|
current: 0, |
||||
|
showDialog: false, |
||||
|
isLoging: false, |
||||
|
syncFlag: false, |
||||
|
deviceId: null, |
||||
|
timmer: null, |
||||
|
msg: "正在同步", |
||||
|
}; |
||||
|
}, |
||||
|
methods: { |
||||
|
openDialog: function (deviceId) { |
||||
|
console.log("deviceId: " + deviceId) |
||||
|
this.deviceId = deviceId; |
||||
|
this.showDialog = true; |
||||
|
this.msg = ""; |
||||
|
this.percentage= 0; |
||||
|
this.total= 0; |
||||
|
this.current= 0; |
||||
|
this.syncFlag= false; |
||||
|
this.syncStatus = null; |
||||
|
this.getProgress() |
||||
|
}, |
||||
|
getProgress(){ |
||||
|
this.$axios({ |
||||
|
method: 'get', |
||||
|
url:`/api/device/query/${this.deviceId}/sync_status/`, |
||||
|
}).then((res) => { |
||||
|
if (res.data.code == 0) { |
||||
|
if (!this.syncFlag) { |
||||
|
this.syncFlag = true; |
||||
|
} |
||||
|
if (res.data.data == null) { |
||||
|
this.syncStatus = "success" |
||||
|
this.percentage = 100; |
||||
|
this.msg = '同步成功'; |
||||
|
}else if (res.data.data.total == 0){ |
||||
|
this.msg = `等待同步中`; |
||||
|
this.timmer = setTimeout(this.getProgress, 300) |
||||
|
}else if (res.data.data.errorMsg !== null ){ |
||||
|
this.msg = res.data.data.errorMsg; |
||||
|
this.syncStatus = "exception" |
||||
|
}else { |
||||
|
this.total = res.data.data.total; |
||||
|
this.current = res.data.data.current; |
||||
|
this.percentage = Math.floor(Number(res.data.data.current)/Number(res.data.data.total)* 10000)/100; |
||||
|
this.msg = `同步中...[${res.data.data.current}/${res.data.data.total}]`; |
||||
|
this.timmer = setTimeout(this.getProgress, 300) |
||||
|
} |
||||
|
}else { |
||||
|
if (this.syncFlag) { |
||||
|
this.syncStatus = "success" |
||||
|
this.percentage = 100; |
||||
|
this.msg = '同步成功'; |
||||
|
}else { |
||||
|
this.syncStatus = "error" |
||||
|
this.msg = res.data.msg; |
||||
|
} |
||||
|
} |
||||
|
}).catch((error) =>{ |
||||
|
console.log(error); |
||||
|
this.syncStatus = "error" |
||||
|
this.msg = error.response.data.msg; |
||||
|
}); |
||||
|
}, |
||||
|
close: function (){ |
||||
|
window.clearTimeout(this.timmer) |
||||
|
} |
||||
|
}, |
||||
|
}; |
||||
|
</script> |
Loading…
Reference in new issue