Commit 3955e6ed53d450f8faf488d4b74ba0c0c83c5aaa

Authored by 648540858
1 parent c2e2e245

异步通道刷新,优化ui效果

Showing 20 changed files with 492 additions and 171 deletions
src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java
... ... @@ -22,6 +22,9 @@ public class VideoManagerConstants {
22 22  
23 23 public static final String DEVICE_PREFIX = "VMP_DEVICE_";
24 24  
  25 + // 设备同步完成
  26 + public static final String DEVICE_SYNC_PREFIX = "VMP_DEVICE_SYNC_";
  27 +
25 28 public static final String CACHEKEY_PREFIX = "VMP_CHANNEL_";
26 29  
27 30 public static final String KEEPLIVEKEY_PREFIX = "VMP_KEEPALIVE_";
... ... @@ -69,6 +72,7 @@ public class VideoManagerConstants {
69 72  
70 73 public static final String SYSTEM_INFO_NET_PREFIX = "VMP_SYSTEM_INFO_NET_";
71 74  
  75 +
72 76 //************************** redis 消息*********************************
73 77  
74 78 // 流变化的通知
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/bean/CatalogData.java
... ... @@ -8,6 +8,12 @@ public class CatalogData {
8 8 private List<DeviceChannel> channelList;
9 9 private Date lastTime;
10 10 private Device device;
  11 + private String errorMsg;
  12 +
  13 + public enum CatalogDataStatus{
  14 + ready, runIng, end
  15 + }
  16 + private CatalogDataStatus status;
11 17  
12 18 public int getTotal() {
13 19 return total;
... ... @@ -40,4 +46,20 @@ public class CatalogData {
40 46 public void setDevice(Device device) {
41 47 this.device = device;
42 48 }
  49 +
  50 + public String getErrorMsg() {
  51 + return errorMsg;
  52 + }
  53 +
  54 + public void setErrorMsg(String errorMsg) {
  55 + this.errorMsg = errorMsg;
  56 + }
  57 +
  58 + public CatalogDataStatus getStatus() {
  59 + return status;
  60 + }
  61 +
  62 + public void setStatus(CatalogDataStatus status) {
  63 + this.status = status;
  64 + }
43 65 }
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/bean/SyncStatus.java 0 → 100644
  1 +package com.genersoft.iot.vmp.gb28181.bean;
  2 +
  3 +/**
  4 + * 摄像机同步状态
  5 + */
  6 +public class SyncStatus {
  7 + private int total;
  8 + private int current;
  9 + private String errorMsg;
  10 +
  11 + public int getTotal() {
  12 + return total;
  13 + }
  14 +
  15 + public void setTotal(int total) {
  16 + this.total = total;
  17 + }
  18 +
  19 + public int getCurrent() {
  20 + return current;
  21 + }
  22 +
  23 + public void setCurrent(int current) {
  24 + this.current = current;
  25 + }
  26 +
  27 + public String getErrorMsg() {
  28 + return errorMsg;
  29 + }
  30 +
  31 + public void setErrorMsg(String errorMsg) {
  32 + this.errorMsg = errorMsg;
  33 + }
  34 +}
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/event/online/OnlineEventListener.java
... ... @@ -97,8 +97,6 @@ public class OnlineEventListener implements ApplicationListener&lt;OnlineEvent&gt; {
97 97 }
98 98 // 处理上线监听
99 99 storager.updateDevice(device);
100   - List<DeviceChannel> deviceChannelList = storager.queryOnlineChannelsByDeviceId(device.getDeviceId());
101   - eventPublisher.catalogEventPublish(null, deviceChannelList, CatalogEvent.ON);
102 100 // 上线添加订阅
103 101 if (device.getSubscribeCycleForCatalog() > 0) {
104 102 deviceService.addCatalogSubscribe(device);
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/session/CatalogDataCatch.java
... ... @@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.gb28181.session;
3 3 import com.genersoft.iot.vmp.gb28181.bean.CatalogData;
4 4 import com.genersoft.iot.vmp.gb28181.bean.Device;
5 5 import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
  6 +import com.genersoft.iot.vmp.gb28181.bean.SyncStatus;
6 7 import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
7 8 import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
8 9 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
... ... @@ -25,6 +26,17 @@ public class CatalogDataCatch {
25 26 @Autowired
26 27 private IVideoManagerStorage storager;
27 28  
  29 + public void addReady(String key) {
  30 + CatalogData catalogData = data.get(key);
  31 + if (catalogData == null || catalogData.getStatus().equals(CatalogData.CatalogDataStatus.end)) {
  32 + catalogData = new CatalogData();
  33 + catalogData.setChannelList(new ArrayList<>());
  34 + catalogData.setStatus(CatalogData.CatalogDataStatus.ready);
  35 + catalogData.setLastTime(new Date(System.currentTimeMillis()));
  36 + data.put(key, catalogData);
  37 + }
  38 + }
  39 +
28 40 public void put(String key, int total, Device device, List<DeviceChannel> deviceChannelList) {
29 41 CatalogData catalogData = data.get(key);
30 42 if (catalogData == null) {
... ... @@ -32,10 +44,16 @@ public class CatalogDataCatch {
32 44 catalogData.setTotal(total);
33 45 catalogData.setDevice(device);
34 46 catalogData.setChannelList(new ArrayList<>());
  47 + catalogData.setStatus(CatalogData.CatalogDataStatus.runIng);
  48 + catalogData.setLastTime(new Date(System.currentTimeMillis()));
35 49 data.put(key, catalogData);
  50 + }else {
  51 + catalogData.setTotal(total);
  52 + catalogData.setDevice(device);
  53 + catalogData.setStatus(CatalogData.CatalogDataStatus.runIng);
  54 + catalogData.getChannelList().addAll(deviceChannelList);
  55 + catalogData.setLastTime(new Date(System.currentTimeMillis()));
36 56 }
37   - catalogData.getChannelList().addAll(deviceChannelList);
38   - catalogData.setLastTime(new Date(System.currentTimeMillis()));
39 57 }
40 58  
41 59 public List<DeviceChannel> get(String key) {
... ... @@ -50,6 +68,16 @@ public class CatalogDataCatch {
50 68 return catalogData.getTotal();
51 69 }
52 70  
  71 + public SyncStatus getSyncStatus(String key) {
  72 + CatalogData catalogData = data.get(key);
  73 + if (catalogData == null) return null;
  74 + SyncStatus syncStatus = new SyncStatus();
  75 + syncStatus.setCurrent(catalogData.getChannelList().size());
  76 + syncStatus.setTotal(catalogData.getTotal());
  77 + syncStatus.setErrorMsg(catalogData.getErrorMsg());
  78 + return syncStatus;
  79 + }
  80 +
53 81 public void del(String key) {
54 82 data.remove(key);
55 83 }
... ... @@ -57,24 +85,32 @@ public class CatalogDataCatch {
57 85 @Scheduled(fixedRate = 5 * 1000) //每5秒执行一次, 发现数据5秒未更新则移除数据并认为数据接收超时
58 86 private void timerTask(){
59 87 Set<String> keys = data.keySet();
60   - Calendar calendar = Calendar.getInstance();
61   - calendar.setTime(new Date());
62   - calendar.set(Calendar.SECOND, calendar.get(Calendar.SECOND) - 5);
  88 + Calendar calendarBefore5S = Calendar.getInstance();
  89 + calendarBefore5S.setTime(new Date());
  90 + calendarBefore5S.set(Calendar.SECOND, calendarBefore5S.get(Calendar.SECOND) - 5);
  91 +
  92 + Calendar calendarBefore30S = Calendar.getInstance();
  93 + calendarBefore30S.setTime(new Date());
  94 + calendarBefore30S.set(Calendar.SECOND, calendarBefore30S.get(Calendar.SECOND) - 30);
63 95 for (String key : keys) {
64 96 CatalogData catalogData = data.get(key);
65   - if (catalogData.getLastTime().before(calendar.getTime())) {
66   -
  97 + if (catalogData.getLastTime().before(calendarBefore5S.getTime())) { // 超过五秒收不到消息任务超时, 只更新这一部分数据
67 98 storager.resetChannels(catalogData.getDevice().getDeviceId(), catalogData.getChannelList());
68   - RequestMessage msg = new RequestMessage();
69   - msg.setKey(key);
70   - WVPResult<Object> result = new WVPResult<>();
71   - result.setCode(0);
72   - result.setMsg("更新成功,共" + catalogData.getTotal() + "条,已更新" + catalogData.getChannelList().size() + "条");
73   - result.setData(catalogData.getDevice());
74   - msg.setData(result);
75   - deferredResultHolder.invokeAllResult(msg);
  99 + String errorMsg = "更新成功,共" + catalogData.getTotal() + "条,已更新" + catalogData.getChannelList().size() + "条";
  100 + catalogData.setStatus(CatalogData.CatalogDataStatus.end);
  101 + catalogData.setErrorMsg(errorMsg);
  102 + }
  103 + if (catalogData.getLastTime().before(calendarBefore30S.getTime())) { // 超过三十秒,如果标记为end则删除
76 104 data.remove(key);
77 105 }
78 106 }
79 107 }
  108 +
  109 +
  110 + public void setChannelSyncEnd(String key, String errorMsg) {
  111 + CatalogData catalogData = data.get(key);
  112 + if (catalogData == null)return;
  113 + catalogData.setStatus(CatalogData.CatalogDataStatus.end);
  114 + catalogData.setErrorMsg(errorMsg);
  115 + }
80 116 }
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommanderForPlatform.java
... ... @@ -46,6 +46,7 @@ public interface ISIPCommanderForPlatform {
46 46 * @return
47 47 */
48 48 boolean catalogQuery(DeviceChannel channel, ParentPlatform parentPlatform, String sn, String fromTag, int size);
  49 + boolean catalogQuery(List<DeviceChannel> channels, ParentPlatform parentPlatform, String sn, String fromTag);
49 50  
50 51 /**
51 52 * 向上级回复DeviceInfo查询信息
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
... ... @@ -235,7 +235,7 @@ public class SIPCommander implements ISIPCommander {
235 235 String cmdStr= cmdString(leftRight, upDown, inOut, moveSpeed, zoomSpeed);
236 236 StringBuffer ptzXml = new StringBuffer(200);
237 237 String charset = device.getCharset();
238   - ptzXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
  238 + ptzXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
239 239 ptzXml.append("<Control>\r\n");
240 240 ptzXml.append("<CmdType>DeviceControl</CmdType>\r\n");
241 241 ptzXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
... ... @@ -278,7 +278,7 @@ public class SIPCommander implements ISIPCommander {
278 278 logger.debug("控制字符串:" + cmdStr);
279 279 StringBuffer ptzXml = new StringBuffer(200);
280 280 String charset = device.getCharset();
281   - ptzXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
  281 + ptzXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
282 282 ptzXml.append("<Control>\r\n");
283 283 ptzXml.append("<CmdType>DeviceControl</CmdType>\r\n");
284 284 ptzXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
... ... @@ -314,7 +314,7 @@ public class SIPCommander implements ISIPCommander {
314 314 try {
315 315 StringBuffer ptzXml = new StringBuffer(200);
316 316 String charset = device.getCharset();
317   - ptzXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
  317 + ptzXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
318 318 ptzXml.append("<Control>\r\n");
319 319 ptzXml.append("<CmdType>DeviceControl</CmdType>\r\n");
320 320 ptzXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
... ... @@ -778,7 +778,7 @@ public class SIPCommander implements ISIPCommander {
778 778 try {
779 779 StringBuffer broadcastXml = new StringBuffer(200);
780 780 String charset = device.getCharset();
781   - broadcastXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
  781 + broadcastXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
782 782 broadcastXml.append("<Notify>\r\n");
783 783 broadcastXml.append("<CmdType>Broadcast</CmdType>\r\n");
784 784 broadcastXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
... ... @@ -804,7 +804,7 @@ public class SIPCommander implements ISIPCommander {
804 804 try {
805 805 StringBuffer broadcastXml = new StringBuffer(200);
806 806 String charset = device.getCharset();
807   - broadcastXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
  807 + broadcastXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
808 808 broadcastXml.append("<Notify>\r\n");
809 809 broadcastXml.append("<CmdType>Broadcast</CmdType>\r\n");
810 810 broadcastXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
... ... @@ -837,7 +837,7 @@ public class SIPCommander implements ISIPCommander {
837 837 try {
838 838 StringBuffer cmdXml = new StringBuffer(200);
839 839 String charset = device.getCharset();
840   - cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
  840 + cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
841 841 cmdXml.append("<Control>\r\n");
842 842 cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
843 843 cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
... ... @@ -873,7 +873,7 @@ public class SIPCommander implements ISIPCommander {
873 873 try {
874 874 StringBuffer cmdXml = new StringBuffer(200);
875 875 String charset = device.getCharset();
876   - cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
  876 + cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
877 877 cmdXml.append("<Control>\r\n");
878 878 cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
879 879 cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
... ... @@ -906,7 +906,7 @@ public class SIPCommander implements ISIPCommander {
906 906 try {
907 907 StringBuffer cmdXml = new StringBuffer(200);
908 908 String charset = device.getCharset();
909   - cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
  909 + cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
910 910 cmdXml.append("<Control>\r\n");
911 911 cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
912 912 cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
... ... @@ -938,7 +938,7 @@ public class SIPCommander implements ISIPCommander {
938 938 try {
939 939 StringBuffer cmdXml = new StringBuffer(200);
940 940 String charset = device.getCharset();
941   - cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
  941 + cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
942 942 cmdXml.append("<Control>\r\n");
943 943 cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
944 944 cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
... ... @@ -983,7 +983,7 @@ public class SIPCommander implements ISIPCommander {
983 983 try {
984 984 StringBuffer cmdXml = new StringBuffer(200);
985 985 String charset = device.getCharset();
986   - cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
  986 + cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
987 987 cmdXml.append("<Control>\r\n");
988 988 cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
989 989 cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
... ... @@ -1022,7 +1022,7 @@ public class SIPCommander implements ISIPCommander {
1022 1022 try {
1023 1023 StringBuffer cmdXml = new StringBuffer(200);
1024 1024 String charset = device.getCharset();
1025   - cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
  1025 + cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
1026 1026 cmdXml.append("<Control>\r\n");
1027 1027 cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
1028 1028 cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
... ... @@ -1091,7 +1091,7 @@ public class SIPCommander implements ISIPCommander {
1091 1091 try {
1092 1092 StringBuffer cmdXml = new StringBuffer(200);
1093 1093 String charset = device.getCharset();
1094   - cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
  1094 + cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
1095 1095 cmdXml.append("<Control>\r\n");
1096 1096 cmdXml.append("<CmdType>DeviceConfig</CmdType>\r\n");
1097 1097 cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
... ... @@ -1146,7 +1146,7 @@ public class SIPCommander implements ISIPCommander {
1146 1146 try {
1147 1147 String charset = device.getCharset();
1148 1148 StringBuffer catalogXml = new StringBuffer(200);
1149   - catalogXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
  1149 + catalogXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
1150 1150 catalogXml.append("<Query>\r\n");
1151 1151 catalogXml.append("<CmdType>DeviceStatus</CmdType>\r\n");
1152 1152 catalogXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
... ... @@ -1179,7 +1179,7 @@ public class SIPCommander implements ISIPCommander {
1179 1179 try {
1180 1180 StringBuffer catalogXml = new StringBuffer(200);
1181 1181 String charset = device.getCharset();
1182   - catalogXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
  1182 + catalogXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
1183 1183 catalogXml.append("<Query>\r\n");
1184 1184 catalogXml.append("<CmdType>DeviceInfo</CmdType>\r\n");
1185 1185 catalogXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
... ... @@ -1212,7 +1212,7 @@ public class SIPCommander implements ISIPCommander {
1212 1212 try {
1213 1213 StringBuffer catalogXml = new StringBuffer(200);
1214 1214 String charset = device.getCharset();
1215   - catalogXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
  1215 + catalogXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
1216 1216 catalogXml.append("<Query>\r\n");
1217 1217 catalogXml.append("<CmdType>Catalog</CmdType>\r\n");
1218 1218 catalogXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
... ... @@ -1252,7 +1252,7 @@ public class SIPCommander implements ISIPCommander {
1252 1252 try {
1253 1253 StringBuffer recordInfoXml = new StringBuffer(200);
1254 1254 String charset = device.getCharset();
1255   - recordInfoXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
  1255 + recordInfoXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
1256 1256 recordInfoXml.append("<Query>\r\n");
1257 1257 recordInfoXml.append("<CmdType>RecordInfo</CmdType>\r\n");
1258 1258 recordInfoXml.append("<SN>" + sn + "</SN>\r\n");
... ... @@ -1306,7 +1306,7 @@ public class SIPCommander implements ISIPCommander {
1306 1306 try {
1307 1307 StringBuffer cmdXml = new StringBuffer(200);
1308 1308 String charset = device.getCharset();
1309   - cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
  1309 + cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
1310 1310 cmdXml.append("<Query>\r\n");
1311 1311 cmdXml.append("<CmdType>Alarm</CmdType>\r\n");
1312 1312 cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
... ... @@ -1357,7 +1357,7 @@ public class SIPCommander implements ISIPCommander {
1357 1357 try {
1358 1358 StringBuffer cmdXml = new StringBuffer(200);
1359 1359 String charset = device.getCharset();
1360   - cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
  1360 + cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
1361 1361 cmdXml.append("<Query>\r\n");
1362 1362 cmdXml.append("<CmdType>ConfigDownload</CmdType>\r\n");
1363 1363 cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
... ... @@ -1393,7 +1393,7 @@ public class SIPCommander implements ISIPCommander {
1393 1393 try {
1394 1394 StringBuffer cmdXml = new StringBuffer(200);
1395 1395 String charset = device.getCharset();
1396   - cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
  1396 + cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
1397 1397 cmdXml.append("<Query>\r\n");
1398 1398 cmdXml.append("<CmdType>PresetQuery</CmdType>\r\n");
1399 1399 cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
... ... @@ -1428,7 +1428,7 @@ public class SIPCommander implements ISIPCommander {
1428 1428 try {
1429 1429 StringBuffer mobilePostitionXml = new StringBuffer(200);
1430 1430 String charset = device.getCharset();
1431   - mobilePostitionXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
  1431 + mobilePostitionXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
1432 1432 mobilePostitionXml.append("<Query>\r\n");
1433 1433 mobilePostitionXml.append("<CmdType>MobilePosition</CmdType>\r\n");
1434 1434 mobilePostitionXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
... ... @@ -1462,7 +1462,7 @@ public class SIPCommander implements ISIPCommander {
1462 1462 try {
1463 1463 StringBuffer subscribePostitionXml = new StringBuffer(200);
1464 1464 String charset = device.getCharset();
1465   - subscribePostitionXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
  1465 + subscribePostitionXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
1466 1466 subscribePostitionXml.append("<Query>\r\n");
1467 1467 subscribePostitionXml.append("<CmdType>MobilePosition</CmdType>\r\n");
1468 1468 subscribePostitionXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
... ... @@ -1513,7 +1513,7 @@ public class SIPCommander implements ISIPCommander {
1513 1513 try {
1514 1514 StringBuffer cmdXml = new StringBuffer(200);
1515 1515 String charset = device.getCharset();
1516   - cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
  1516 + cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
1517 1517 cmdXml.append("<Query>\r\n");
1518 1518 cmdXml.append("<CmdType>Alarm</CmdType>\r\n");
1519 1519 cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
... ... @@ -1559,7 +1559,7 @@ public class SIPCommander implements ISIPCommander {
1559 1559 try {
1560 1560 StringBuffer cmdXml = new StringBuffer(200);
1561 1561 String charset = device.getCharset();
1562   - cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
  1562 + cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
1563 1563 cmdXml.append("<Query>\r\n");
1564 1564 cmdXml.append("<CmdType>Catalog</CmdType>\r\n");
1565 1565 cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
... ... @@ -1590,7 +1590,7 @@ public class SIPCommander implements ISIPCommander {
1590 1590 try {
1591 1591 StringBuffer dragXml = new StringBuffer(200);
1592 1592 String charset = device.getCharset();
1593   - dragXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\" ?>\r\n");
  1593 + dragXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
1594 1594 dragXml.append("<Control>\r\n");
1595 1595 dragXml.append("<CmdType>DeviceControl</CmdType>\r\n");
1596 1596 dragXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java
... ... @@ -147,7 +147,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
147 147 try {
148 148 String characterSet = parentPlatform.getCharacterSet();
149 149 StringBuffer keepaliveXml = new StringBuffer(200);
150   - keepaliveXml.append("<?xml version=\"1.0\" encoding=\"" + characterSet + "\" ?>\r\n");
  150 + keepaliveXml.append("<?xml version=\"1.0\" encoding=\"" + characterSet + "\"?>\r\n");
151 151 keepaliveXml.append("<Notify>\r\n");
152 152 keepaliveXml.append("<CmdType>Keepalive</CmdType>\r\n");
153 153 keepaliveXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
... ... @@ -215,44 +215,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
215 215 return false;
216 216 }
217 217 try {
218   - String characterSet = parentPlatform.getCharacterSet();
219   - StringBuffer catalogXml = new StringBuffer(600);
220   - catalogXml.append("<?xml version=\"1.0\" encoding=\"" + characterSet +"\" ?>\r\n");
221   - catalogXml.append("<Response>\r\n");
222   - catalogXml.append("<CmdType>Catalog</CmdType>\r\n");
223   - catalogXml.append("<SN>" +sn + "</SN>\r\n");
224   - catalogXml.append("<DeviceID>" + parentPlatform.getDeviceGBId() + "</DeviceID>\r\n");
225   - catalogXml.append("<SumNum>" + size + "</SumNum>\r\n");
226   - catalogXml.append("<DeviceList Num=\"1\">\r\n");
227   - catalogXml.append("<Item>\r\n");
228   - if (channel != null) {
229   - catalogXml.append("<DeviceID>" + channel.getChannelId() + "</DeviceID>\r\n");
230   - catalogXml.append("<Name>" + channel.getName() + "</Name>\r\n");
231   - catalogXml.append("<Manufacturer>" + channel.getManufacture() + "</Manufacturer>\r\n");
232   - catalogXml.append("<Model>" + channel.getModel() + "</Model>\r\n");
233   - catalogXml.append("<Owner>" + channel.getOwner() + "</Owner>\r\n");
234   - catalogXml.append("<CivilCode>" + channel.getCivilCode() + "</CivilCode>\r\n");
235   - catalogXml.append("<Address>" + channel.getAddress() + "</Address>\r\n");
236   - catalogXml.append("<Parental>" + channel.getParental() + "</Parental>\r\n");
237   - if (channel.getParentId() != null) {
238   - catalogXml.append("<ParentID>" + channel.getParentId() + "</ParentID>\r\n");
239   - }
240   - catalogXml.append("<Secrecy>" + channel.getSecrecy() + "</Secrecy>\r\n");
241   - catalogXml.append("<RegisterWay>" + channel.getRegisterWay() + "</RegisterWay>\r\n");
242   - catalogXml.append("<Status>" + (channel.getStatus() == 0?"OFF":"ON") + "</Status>\r\n");
243   - catalogXml.append("<Longitude>" + channel.getLongitude() + "</Longitude>\r\n");
244   - catalogXml.append("<Latitude>" + channel.getLatitude() + "</Latitude>\r\n");
245   - catalogXml.append("<IPAddress>" + channel.getIpAddress() + "</IPAddress>\r\n");
246   - catalogXml.append("<Port>" + channel.getPort() + "</Port>\r\n");
247   - catalogXml.append("<Info>\r\n");
248   - catalogXml.append("<PTZType>" + channel.getPTZType() + "</PTZType>\r\n");
249   - catalogXml.append("</Info>\r\n");
250   - }
251   -
252   -
253   - catalogXml.append("</Item>\r\n");
254   - catalogXml.append("</DeviceList>\r\n");
255   - catalogXml.append("</Response>\r\n");
  218 + String catalogXml = getCatalogXml(channel, sn, parentPlatform, size);
256 219  
257 220 // callid
258 221 CallIdHeader callIdHeader = parentPlatform.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
... ... @@ -268,6 +231,77 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
268 231 return true;
269 232 }
270 233  
  234 + @Override
  235 + public boolean catalogQuery(List<DeviceChannel> channels, ParentPlatform parentPlatform, String sn, String fromTag) {
  236 + if ( parentPlatform ==null) {
  237 + return false;
  238 + }
  239 + sendCatalogResponse(channels, parentPlatform, sn, fromTag, 0);
  240 + return true;
  241 + }
  242 + private String getCatalogXml(DeviceChannel channel, String sn, ParentPlatform parentPlatform, int size) {
  243 + String characterSet = parentPlatform.getCharacterSet();
  244 + StringBuffer catalogXml = new StringBuffer(600);
  245 + catalogXml.append("<?xml version=\"1.0\" encoding=\"" + characterSet +"\"?>\r\n");
  246 + catalogXml.append("<Response>\r\n");
  247 + catalogXml.append("<CmdType>Catalog</CmdType>\r\n");
  248 + catalogXml.append("<SN>" +sn + "</SN>\r\n");
  249 + catalogXml.append("<DeviceID>" + parentPlatform.getDeviceGBId() + "</DeviceID>\r\n");
  250 + catalogXml.append("<SumNum>" + size + "</SumNum>\r\n");
  251 + catalogXml.append("<DeviceList Num=\"1\">\r\n");
  252 + catalogXml.append("<Item>\r\n");
  253 + if (channel != null) {
  254 + catalogXml.append("<DeviceID>" + channel.getChannelId() + "</DeviceID>\r\n");
  255 + catalogXml.append("<Name>" + channel.getName() + "</Name>\r\n");
  256 + catalogXml.append("<Manufacturer>" + channel.getManufacture() + "</Manufacturer>\r\n");
  257 + catalogXml.append("<Model>" + channel.getModel() + "</Model>\r\n");
  258 + catalogXml.append("<Owner>" + channel.getOwner() + "</Owner>\r\n");
  259 + catalogXml.append("<CivilCode>" + channel.getCivilCode() + "</CivilCode>\r\n");
  260 + catalogXml.append("<Address>" + channel.getAddress() + "</Address>\r\n");
  261 + catalogXml.append("<Parental>" + channel.getParental() + "</Parental>\r\n");
  262 + if (channel.getParentId() != null) {
  263 + catalogXml.append("<ParentID>" + channel.getParentId() + "</ParentID>\r\n");
  264 + }
  265 + catalogXml.append("<Secrecy>" + channel.getSecrecy() + "</Secrecy>\r\n");
  266 + catalogXml.append("<RegisterWay>" + channel.getRegisterWay() + "</RegisterWay>\r\n");
  267 + catalogXml.append("<Status>" + (channel.getStatus() == 0?"OFF":"ON") + "</Status>\r\n");
  268 + catalogXml.append("<Longitude>" + channel.getLongitude() + "</Longitude>\r\n");
  269 + catalogXml.append("<Latitude>" + channel.getLatitude() + "</Latitude>\r\n");
  270 + catalogXml.append("<IPAddress>" + channel.getIpAddress() + "</IPAddress>\r\n");
  271 + catalogXml.append("<Port>" + channel.getPort() + "</Port>\r\n");
  272 + catalogXml.append("<Info>\r\n");
  273 + catalogXml.append("<PTZType>" + channel.getPTZType() + "</PTZType>\r\n");
  274 + catalogXml.append("</Info>\r\n");
  275 + }
  276 +
  277 +
  278 + catalogXml.append("</Item>\r\n");
  279 + catalogXml.append("</DeviceList>\r\n");
  280 + catalogXml.append("</Response>\r\n");
  281 + return catalogXml.toString();
  282 + }
  283 +
  284 + private void sendCatalogResponse(List<DeviceChannel> channels, ParentPlatform parentPlatform, String sn, String fromTag, int index) {
  285 + if (index >= channels.size()) {
  286 + return;
  287 + }
  288 + try {
  289 + DeviceChannel deviceChannel = channels.get(index);
  290 + String catalogXml = getCatalogXml(deviceChannel, sn, parentPlatform, channels.size());
  291 + // callid
  292 + CallIdHeader callIdHeader = parentPlatform.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
  293 + : udpSipProvider.getNewCallId();
  294 +
  295 + Request request = headerProviderPlarformProvider.createMessageRequest(parentPlatform, catalogXml, fromTag, callIdHeader);
  296 + transmitRequest(parentPlatform, request, null, eventResult -> {
  297 + int indexNext = index + 1;
  298 + sendCatalogResponse(channels, parentPlatform, sn, fromTag, indexNext);
  299 + });
  300 + } catch (SipException | ParseException | InvalidArgumentException e) {
  301 + e.printStackTrace();
  302 + }
  303 + }
  304 +
271 305 /**
272 306 * 向上级回复DeviceInfo查询信息
273 307 * @param parentPlatform 平台信息
... ... @@ -283,7 +317,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
283 317 try {
284 318 String characterSet = parentPlatform.getCharacterSet();
285 319 StringBuffer deviceInfoXml = new StringBuffer(600);
286   - deviceInfoXml.append("<?xml version=\"1.0\" encoding=\"" + characterSet + "\" ?>\r\n");
  320 + deviceInfoXml.append("<?xml version=\"1.0\" encoding=\"" + characterSet + "\"?>\r\n");
287 321 deviceInfoXml.append("<Response>\r\n");
288 322 deviceInfoXml.append("<CmdType>DeviceInfo</CmdType>\r\n");
289 323 deviceInfoXml.append("<SN>" +sn + "</SN>\r\n");
... ... @@ -323,7 +357,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
323 357 try {
324 358 String characterSet = parentPlatform.getCharacterSet();
325 359 StringBuffer deviceStatusXml = new StringBuffer(600);
326   - deviceStatusXml.append("<?xml version=\"1.0\" encoding=\"" + characterSet + "\" ?>\r\n");
  360 + deviceStatusXml.append("<?xml version=\"1.0\" encoding=\"" + characterSet + "\"?>\r\n");
327 361 deviceStatusXml.append("<Response>\r\n");
328 362 deviceStatusXml.append("<CmdType>DeviceStatus</CmdType>\r\n");
329 363 deviceStatusXml.append("<SN>" +sn + "</SN>\r\n");
... ... @@ -355,7 +389,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
355 389 try {
356 390 String characterSet = parentPlatform.getCharacterSet();
357 391 StringBuffer deviceStatusXml = new StringBuffer(600);
358   - deviceStatusXml.append("<?xml version=\"1.0\" encoding=\"" + characterSet + "\" ?>\r\n");
  392 + deviceStatusXml.append("<?xml version=\"1.0\" encoding=\"" + characterSet + "\"?>\r\n");
359 393 deviceStatusXml.append("<Notify>\r\n");
360 394 deviceStatusXml.append("<CmdType>MobilePosition</CmdType>\r\n");
361 395 deviceStatusXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
... ... @@ -472,7 +506,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
472 506 channel.setParentId(parentPlatform.getDeviceGBId());
473 507 }
474 508 String characterSet = parentPlatform.getCharacterSet();
475   - catalogXml.append("<?xml version=\"1.0\" encoding=\"" + characterSet + "\" ?>\r\n");
  509 + catalogXml.append("<?xml version=\"1.0\" encoding=\"" + characterSet + "\"?>\r\n");
476 510 catalogXml.append("<Notify>\r\n");
477 511 catalogXml.append("<CmdType>Catalog</CmdType>\r\n");
478 512 catalogXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
... ... @@ -546,7 +580,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
546 580 }
547 581 String characterSet = parentPlatform.getCharacterSet();
548 582 StringBuffer catalogXml = new StringBuffer(600);
549   - catalogXml.append("<?xml version=\"1.0\" encoding=\"" + characterSet + "\" ?>\r\n");
  583 + catalogXml.append("<?xml version=\"1.0\" encoding=\"" + characterSet + "\"?>\r\n");
550 584 catalogXml.append("<Notify>\r\n");
551 585 catalogXml.append("<CmdType>Catalog</CmdType>\r\n");
552 586 catalogXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
... ... @@ -569,7 +603,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
569 603 try {
570 604 String characterSet = parentPlatform.getCharacterSet();
571 605 StringBuffer recordXml = new StringBuffer(600);
572   - recordXml.append("<?xml version=\"1.0\" encoding=\"" + characterSet + "\" ?>\r\n");
  606 + recordXml.append("<?xml version=\"1.0\" encoding=\"" + characterSet + "\"?>\r\n");
573 607 recordXml.append("<Response>\r\n");
574 608 recordXml.append("<CmdType>RecordInfo</CmdType>\r\n");
575 609 recordXml.append("<SN>" +recordInfo.getSn() + "</SN>\r\n");
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/MessageRequestProcessor.java
... ... @@ -12,6 +12,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorP
12 12 import com.genersoft.iot.vmp.gb28181.utils.SipUtils;
13 13 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
14 14 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
  15 +import gov.nist.javax.sip.message.SIPRequest;
15 16 import org.dom4j.DocumentException;
16 17 import org.dom4j.Element;
17 18 import org.slf4j.Logger;
... ... @@ -23,6 +24,7 @@ import org.springframework.stereotype.Component;
23 24 import javax.sip.InvalidArgumentException;
24 25 import javax.sip.RequestEvent;
25 26 import javax.sip.SipException;
  27 +import javax.sip.address.SipURI;
26 28 import javax.sip.header.CSeqHeader;
27 29 import javax.sip.header.CallIdHeader;
28 30 import javax.sip.message.Response;
... ... @@ -81,6 +83,17 @@ public class MessageRequestProcessor extends SIPRequestProcessorParent implement
81 83 // 查询上级平台是否存在
82 84 ParentPlatform parentPlatform = storage.queryParentPlatByServerGBId(deviceId);
83 85 try {
  86 + if (device != null && parentPlatform != null) {
  87 + logger.warn("[重复]平台与设备编号重复:{}", deviceId);
  88 + SIPRequest request = (SIPRequest) evt.getRequest();
  89 + String hostAddress = request.getRemoteAddress().getHostAddress();
  90 + int remotePort = request.getRemotePort();
  91 + if (device.getHostAddress().equals(hostAddress + ":" + remotePort)) {
  92 + parentPlatform = null;
  93 + }else {
  94 + device = null;
  95 + }
  96 + }
84 97 if (device == null && parentPlatform == null) {
85 98 // 不存在则回复404
86 99 responseAck(evt, Response.NOT_FOUND, "device "+ deviceId +" not found");
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/CatalogNotifyMessageHandler.java
... ... @@ -18,6 +18,7 @@ import javax.sip.SipException;
18 18 import javax.sip.header.FromHeader;
19 19 import javax.sip.message.Response;
20 20 import java.text.ParseException;
  21 +import java.util.ArrayList;
21 22 import java.util.List;
22 23  
23 24 @Component
... ... @@ -58,7 +59,8 @@ public class CatalogNotifyMessageHandler extends SIPRequestProcessorParent imple
58 59 List<DeviceChannelInPlatform> deviceChannels = storage.queryChannelListInParentPlatform(parentPlatform.getServerGBId());
59 60 // 查询关联的直播通道
60 61 List<GbStream> gbStreams = storage.queryGbStreamListInPlatform(parentPlatform.getServerGBId());
61   - int size = deviceChannels.size() + gbStreams.size();
  62 +
  63 + List<DeviceChannel> allChannels = new ArrayList<>();
62 64 // 回复目录信息
63 65 List<PlatformCatalog> catalogs = storage.queryCatalogInPlatform(parentPlatform.getServerGBId());
64 66 if (catalogs.size() > 0) {
... ... @@ -81,9 +83,7 @@ public class CatalogNotifyMessageHandler extends SIPRequestProcessorParent imple
81 83 deviceChannel.setModel("live");
82 84 deviceChannel.setOwner("wvp-pro");
83 85 deviceChannel.setSecrecy("0");
84   - cmderFroPlatform.catalogQuery(deviceChannel, parentPlatform, sn, fromHeader.getTag(), size);
85   - // 防止发送过快
86   - Thread.sleep(100);
  86 + allChannels.add(deviceChannel);
87 87 }
88 88 }
89 89 // 回复级联的通道
... ... @@ -96,9 +96,7 @@ public class CatalogNotifyMessageHandler extends SIPRequestProcessorParent imple
96 96 deviceChannel.setParental(0);
97 97 deviceChannel.setParentId(channel.getCatalogId());
98 98 deviceChannel.setCivilCode(parentPlatform.getDeviceGBId().substring(0, 6));
99   - cmderFroPlatform.catalogQuery(deviceChannel, parentPlatform, sn, fromHeader.getTag(), size);
100   - // 防止发送过快
101   - Thread.sleep(100);
  99 + allChannels.add(deviceChannel);
102 100 }
103 101 }
104 102 // 回复直播的通道
... ... @@ -123,16 +121,16 @@ public class CatalogNotifyMessageHandler extends SIPRequestProcessorParent imple
123 121 deviceChannel.setOwner("wvp-pro");
124 122 deviceChannel.setParental(0);
125 123 deviceChannel.setSecrecy("0");
126   - cmderFroPlatform.catalogQuery(deviceChannel, parentPlatform, sn, fromHeader.getTag(), size);
127   - // 防止发送过快
128   - Thread.sleep(100);
  124 + allChannels.add(deviceChannel);
129 125 }
130 126 }
131   - if (size == 0) {
  127 + if (allChannels.size() > 0) {
  128 + cmderFroPlatform.catalogQuery(allChannels, parentPlatform, sn, fromHeader.getTag());
  129 + }else {
132 130 // 回复无通道
133   - cmderFroPlatform.catalogQuery(null, parentPlatform, sn, fromHeader.getTag(), size);
  131 + cmderFroPlatform.catalogQuery(null, parentPlatform, sn, fromHeader.getTag(), 0);
134 132 }
135   - } catch (SipException | InvalidArgumentException | ParseException | InterruptedException e) {
  133 + } catch (SipException | InvalidArgumentException | ParseException e) {
136 134 e.printStackTrace();
137 135 }
138 136  
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/query/cmd/CatalogQueryMessageHandler.java
... ... @@ -22,6 +22,7 @@ import javax.sip.SipException;
22 22 import javax.sip.header.FromHeader;
23 23 import javax.sip.message.Response;
24 24 import java.text.ParseException;
  25 +import java.util.ArrayList;
25 26 import java.util.List;
26 27  
27 28 @Component
... ... @@ -45,6 +46,9 @@ public class CatalogQueryMessageHandler extends SIPRequestProcessorParent implem
45 46 @Autowired
46 47 private EventPublisher publisher;
47 48  
  49 + @Autowired
  50 + private IVideoManagerStorage storage;
  51 +
48 52 @Override
49 53 public void afterPropertiesSet() throws Exception {
50 54 queryMessageHandler.addHandler(cmdType, this);
... ... @@ -71,10 +75,11 @@ public class CatalogQueryMessageHandler extends SIPRequestProcessorParent implem
71 75 List<GbStream> gbStreams = storager.queryGbStreamListInPlatform(parentPlatform.getServerGBId());
72 76 // 回复目录信息
73 77 List<PlatformCatalog> catalogs = storager.queryCatalogInPlatform(parentPlatform.getServerGBId());
74   - int size = catalogs.size() + deviceChannelInPlatforms.size() + gbStreams.size();
  78 +
  79 + List<DeviceChannel> allChannels = new ArrayList<>();
75 80 if (catalogs.size() > 0) {
76 81 for (PlatformCatalog catalog : catalogs) {
77   - if (catalog.getParentId().equals(parentPlatform.getServerGBId())) {
  82 + if (catalog.getParentId().equals(catalog.getPlatformId())) {
78 83 catalog.setParentId(parentPlatform.getDeviceGBId());
79 84 }
80 85 DeviceChannel deviceChannel = new DeviceChannel();
... ... @@ -92,9 +97,7 @@ public class CatalogQueryMessageHandler extends SIPRequestProcessorParent implem
92 97 deviceChannel.setModel("live");
93 98 deviceChannel.setOwner("wvp-pro");
94 99 deviceChannel.setSecrecy("0");
95   - cmderFroPlatform.catalogQuery(deviceChannel, parentPlatform, sn, fromHeader.getTag(), size);
96   - // 防止发送过快
97   - Thread.sleep(100);
  100 + allChannels.add(deviceChannel);
98 101 }
99 102 }
100 103 // 回复级联的通道
... ... @@ -103,20 +106,18 @@ public class CatalogQueryMessageHandler extends SIPRequestProcessorParent implem
103 106 if (channel.getCatalogId().equals(parentPlatform.getServerGBId())) {
104 107 channel.setCatalogId(parentPlatform.getDeviceGBId());
105 108 }
106   - DeviceChannel deviceChannel = storager.queryChannel(channel.getDeviceId(), channel.getChannelId());
  109 + DeviceChannel deviceChannel = storage.queryChannel(channel.getDeviceId(), channel.getChannelId());
107 110 deviceChannel.setParental(0);
108 111 deviceChannel.setParentId(channel.getCatalogId());
109 112 deviceChannel.setCivilCode(parentPlatform.getDeviceGBId().substring(0, 6));
110   - cmderFroPlatform.catalogQuery(deviceChannel, parentPlatform, sn, fromHeader.getTag(), size);
111   - // 防止发送过快
112   - Thread.sleep(100);
  113 + allChannels.add(deviceChannel);
113 114 }
114 115 }
115 116 // 回复直播的通道
116 117 if (gbStreams.size() > 0) {
117 118 for (GbStream gbStream : gbStreams) {
118 119 if (gbStream.getCatalogId().equals(parentPlatform.getServerGBId())) {
119   - gbStream.setCatalogId(parentPlatform.getDeviceGBId());
  120 + gbStream.setCatalogId(null);
120 121 }
121 122 DeviceChannel deviceChannel = new DeviceChannel();
122 123 deviceChannel.setChannelId(gbStream.getGbId());
... ... @@ -134,15 +135,14 @@ public class CatalogQueryMessageHandler extends SIPRequestProcessorParent implem
134 135 deviceChannel.setOwner("wvp-pro");
135 136 deviceChannel.setParental(0);
136 137 deviceChannel.setSecrecy("0");
137   -
138   - cmderFroPlatform.catalogQuery(deviceChannel, parentPlatform, sn, fromHeader.getTag(), size);
139   - // 防止发送过快
140   - Thread.sleep(100);
  138 + allChannels.add(deviceChannel);
141 139 }
142 140 }
143   - if (size == 0) {
  141 + if (allChannels.size() > 0) {
  142 + cmderFroPlatform.catalogQuery(allChannels, parentPlatform, sn, fromHeader.getTag());
  143 + }else {
144 144 // 回复无通道
145   - cmderFroPlatform.catalogQuery(null, parentPlatform, sn, fromHeader.getTag(), size);
  145 + cmderFroPlatform.catalogQuery(null, parentPlatform, sn, fromHeader.getTag(), 0);
146 146 }
147 147 } catch (SipException e) {
148 148 e.printStackTrace();
... ... @@ -150,8 +150,6 @@ public class CatalogQueryMessageHandler extends SIPRequestProcessorParent implem
150 150 e.printStackTrace();
151 151 } catch (ParseException e) {
152 152 e.printStackTrace();
153   - } catch (InterruptedException e) {
154   - e.printStackTrace();
155 153 }
156 154  
157 155 }
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java
... ... @@ -123,7 +123,7 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp
123 123  
124 124 channelList.add(deviceChannel);
125 125 }
126   - logger.debug("收到来自设备【{}】的通道: {}个,{}/{}", device.getDeviceId(), channelList.size(), catalogDataCatch.get(key) == null ? 0 :catalogDataCatch.get(key).size(), sumNum);
  126 + logger.info("收到来自设备【{}】的通道: {}个,{}/{}", device.getDeviceId(), channelList.size(), catalogDataCatch.get(key) == null ? 0 :catalogDataCatch.get(key).size(), sumNum);
127 127 catalogDataCatch.put(key, sumNum, device, channelList);
128 128 if (catalogDataCatch.get(key).size() == sumNum) {
129 129 // 数据已经完整接收
... ... @@ -230,8 +230,22 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp
230 230 }
231 231 }
232 232  
233   - public String getChannelSyncProgress(String deviceId) {
  233 + public SyncStatus getChannelSyncProgress(String deviceId) {
234 234 String key = DeferredResultHolder.CALLBACK_CMD_CATALOG + deviceId;
235   - return catalogDataCatch.get(key) == null ? "0/0" : catalogDataCatch.get(key).size() + "/" + catalogDataCatch.getTotal(key);
  235 + if (catalogDataCatch.get(key) == null) {
  236 + return null;
  237 + }else {
  238 + return catalogDataCatch.getSyncStatus(key);
  239 + }
  240 + }
  241 +
  242 + public void setChannelSyncReady(String deviceId) {
  243 + String key = DeferredResultHolder.CALLBACK_CMD_CATALOG + deviceId;
  244 + catalogDataCatch.addReady(key);
  245 + }
  246 +
  247 + public void setChannelSyncEnd(String deviceId, String errorMsg) {
  248 + String key = DeferredResultHolder.CALLBACK_CMD_CATALOG + deviceId;
  249 + catalogDataCatch.setChannelSyncEnd(key, errorMsg);
236 250 }
237 251 }
... ...
src/main/java/com/genersoft/iot/vmp/service/IDeviceService.java
1 1 package com.genersoft.iot.vmp.service;
2 2  
3 3 import com.genersoft.iot.vmp.gb28181.bean.Device;
  4 +import com.genersoft.iot.vmp.gb28181.bean.SyncStatus;
4 5  
5 6 /**
6 7 * 设备相关业务处理
... ... @@ -34,4 +35,24 @@ public interface IDeviceService {
34 35 * @return
35 36 */
36 37 boolean removeMobilePositionSubscribe(Device device);
  38 +
  39 + /**
  40 + * 移除移动位置订阅
  41 + * @param deviceId 设备ID
  42 + * @return
  43 + */
  44 + SyncStatus getChannelSyncStatus(String deviceId);
  45 +
  46 + /**
  47 + * 设置通道同步状态
  48 + * @param deviceId 设备ID
  49 + */
  50 + void setChannelSyncReady(String deviceId);
  51 +
  52 + /**
  53 + * 设置同步结束
  54 + * @param deviceId 设备ID
  55 + * @param errorMsg 错误信息
  56 + */
  57 + void setChannelSyncEnd(String deviceId, String errorMsg);
37 58 }
... ...
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java
... ... @@ -3,9 +3,12 @@ package com.genersoft.iot.vmp.service.impl;
3 3 import com.genersoft.iot.vmp.conf.DynamicTask;
4 4 import com.genersoft.iot.vmp.gb28181.bean.Device;
5 5 import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
  6 +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd.CatalogResponseMessageHandler;
6 7 import com.genersoft.iot.vmp.service.IDeviceService;
7 8 import com.genersoft.iot.vmp.gb28181.task.impl.CatalogSubscribeTask;
8 9 import com.genersoft.iot.vmp.gb28181.task.impl.MobilePositionSubscribeTask;
  10 +import com.genersoft.iot.vmp.gb28181.bean.SyncStatus;
  11 +import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
9 12 import org.slf4j.Logger;
10 13 import org.slf4j.LoggerFactory;
11 14 import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -25,6 +28,12 @@ public class DeviceServiceImpl implements IDeviceService {
25 28 @Autowired
26 29 private ISIPCommander sipCommander;
27 30  
  31 + @Autowired
  32 + private CatalogResponseMessageHandler catalogResponseMessageHandler;
  33 +
  34 + @Autowired
  35 + private IRedisCatchStorage redisCatchStorage;
  36 +
28 37 @Override
29 38 public boolean addCatalogSubscribe(Device device) {
30 39 if (device == null || device.getSubscribeCycleForCatalog() < 0) {
... ... @@ -86,4 +95,19 @@ public class DeviceServiceImpl implements IDeviceService {
86 95 dynamicTask.stop(device.getDeviceId() + "mobile_position");
87 96 return true;
88 97 }
  98 +
  99 + @Override
  100 + public SyncStatus getChannelSyncStatus(String deviceId) {
  101 + return catalogResponseMessageHandler.getChannelSyncProgress(deviceId);
  102 + }
  103 +
  104 + @Override
  105 + public void setChannelSyncReady(String deviceId) {
  106 + catalogResponseMessageHandler.setChannelSyncReady(deviceId);
  107 + }
  108 +
  109 + @Override
  110 + public void setChannelSyncEnd(String deviceId, String errorMsg) {
  111 + catalogResponseMessageHandler.setChannelSyncEnd(deviceId, errorMsg);
  112 + }
89 113 }
... ...
src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java
... ... @@ -216,4 +216,5 @@ public interface IRedisCatchStorage {
216 216 void sendMobilePositionMsg(JSONObject jsonObject);
217 217  
218 218 void sendStreamPushRequestedMsg(MessageForPushChannel messageForPushChannel);
  219 +
219 220 }
... ...
src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
... ... @@ -638,4 +638,5 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
638 638 logger.info("[redis 推流被请求通知] {}: {}-{}", key, msg.getApp(), msg.getStream());
639 639 redis.convertAndSend(key, (JSONObject)JSON.toJSON(msg));
640 640 }
  641 +
641 642 }
... ...
src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java
... ... @@ -445,8 +445,6 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
445 445 device.setOnline(1);
446 446 logger.info("更新设备在线: " + deviceId);
447 447 redisCatchStorage.updateDevice(device);
448   - List<DeviceChannel> deviceChannelList = deviceChannelMapper.queryOnlineChannelsByDeviceId(deviceId);
449   - eventPublisher.catalogEventPublish(null, deviceChannelList, CatalogEvent.ON);
450 448 return deviceMapper.update(device) > 0;
451 449 }
452 450  
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java
... ... @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
4 4 import com.genersoft.iot.vmp.conf.DynamicTask;
5 5 import com.genersoft.iot.vmp.gb28181.bean.Device;
6 6 import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
  7 +import com.genersoft.iot.vmp.gb28181.bean.SyncStatus;
7 8 import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector;
8 9 import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
9 10 import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
... ... @@ -18,6 +19,7 @@ import io.swagger.annotations.Api;
18 19 import io.swagger.annotations.ApiImplicitParam;
19 20 import io.swagger.annotations.ApiImplicitParams;
20 21 import io.swagger.annotations.ApiOperation;
  22 +import org.kxml2.wap.wv.WV;
21 23 import org.slf4j.Logger;
22 24 import org.slf4j.LoggerFactory;
23 25 import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -149,49 +151,30 @@ public class DeviceQuery {
149 151 @ApiImplicitParam(name="deviceId", value = "设备id", required = true, dataTypeClass = String.class),
150 152 })
151 153 @PostMapping("/devices/{deviceId}/sync")
152   - public DeferredResult<ResponseEntity<Device>> devicesSync(@PathVariable String deviceId){
  154 + public WVPResult<SyncStatus> devicesSync(@PathVariable String deviceId){
153 155  
154 156 if (logger.isDebugEnabled()) {
155 157 logger.debug("设备通道信息同步API调用,deviceId:" + deviceId);
156 158 }
157 159 Device device = storager.queryVideoDevice(deviceId);
158   - String key = DeferredResultHolder.CALLBACK_CMD_CATALOG + deviceId;
159   - String uuid = UUID.randomUUID().toString();
160   - // 默认超时时间为30分钟
161   - DeferredResult<ResponseEntity<Device>> result = new DeferredResult<ResponseEntity<Device>>(30*60*1000L);
162   - result.onTimeout(()->{
163   - logger.warn("设备[{}]通道信息同步超时", deviceId);
164   - // 释放rtpserver
165   - RequestMessage msg = new RequestMessage();
166   - msg.setKey(key);
167   - msg.setId(uuid);
168   - WVPResult<Object> wvpResult = new WVPResult<>();
169   - wvpResult.setCode(-1);
170   - wvpResult.setData(device);
171   - wvpResult.setMsg("更新超时");
172   - msg.setData(wvpResult);
173   - resultHolder.invokeAllResult(msg);
174   -
175   - });
176   - // 等待其他相同请求返回时一起返回
177   - if (resultHolder.exist(key, null)) {
178   - resultHolder.put(key, uuid, result);
179   - return result;
180   - }else {
181   - cmder.catalogQuery(device, event -> {
182   - RequestMessage msg = new RequestMessage();
183   - msg.setKey(key);
184   - msg.setId(uuid);
185   - WVPResult<Object> wvpResult = new WVPResult<>();
186   - wvpResult.setCode(-1);
187   - wvpResult.setData(device);
188   - wvpResult.setMsg(String.format("同步通道失败,错误码: %s, %s", event.statusCode, event.msg));
189   - msg.setData(wvpResult);
190   - resultHolder.invokeAllResult(msg);
191   - });
192   - resultHolder.put(key, uuid, result);
193   - return result;
  160 + SyncStatus syncStatus = deviceService.getChannelSyncStatus(deviceId);
  161 + // 已存在则返回进度
  162 + if (syncStatus != null && syncStatus.getErrorMsg() == null) {
  163 + WVPResult<SyncStatus> wvpResult = new WVPResult<>();
  164 + wvpResult.setCode(0);
  165 + wvpResult.setData(syncStatus);
  166 + return wvpResult;
194 167 }
  168 + SyncStatus syncStatusReady = new SyncStatus();
  169 + deviceService.setChannelSyncReady(deviceId);
  170 + cmder.catalogQuery(device, event -> {
  171 + String errorMsg = String.format("同步通道失败,错误码: %s, %s", event.statusCode, event.msg);
  172 + deviceService.setChannelSyncEnd(deviceId, errorMsg);
  173 + });
  174 + WVPResult<SyncStatus> wvpResult = new WVPResult<>();
  175 + wvpResult.setCode(0);
  176 + wvpResult.setMsg("开始同步");
  177 + return wvpResult;
195 178 }
196 179  
197 180 /**
... ... @@ -468,4 +451,22 @@ public class DeviceQuery {
468 451 public WVPResult<List<DeviceChannelTree>> tree(@PathVariable String deviceId) {
469 452 return WVPResult.Data(storager.tree(deviceId));
470 453 }
  454 +
  455 + @GetMapping("/{deviceId}/sync_status")
  456 + @ApiOperation(value = "获取通道同步进度", notes = "获取通道同步进度")
  457 + public WVPResult<SyncStatus> getSyncStatus(@PathVariable String deviceId) {
  458 + SyncStatus channelSyncStatus = deviceService.getChannelSyncStatus(deviceId);
  459 + WVPResult<SyncStatus> wvpResult = new WVPResult<>();
  460 + if (channelSyncStatus == null) {
  461 + wvpResult.setCode(-1);
  462 + wvpResult.setMsg("同步尚未开始");
  463 + }else {
  464 + wvpResult.setCode(0);
  465 + wvpResult.setData(channelSyncStatus);
  466 + if (channelSyncStatus.getErrorMsg() != null) {
  467 + wvpResult.setMsg(channelSyncStatus.getErrorMsg());
  468 + }
  469 + }
  470 + return wvpResult;
  471 + }
471 472 }
... ...
web_src/src/components/DeviceList.vue
... ... @@ -57,7 +57,7 @@
57 57  
58 58 <el-table-column label="操作" width="450" align="center" fixed="right">
59 59 <template slot-scope="scope">
60   - <el-button size="mini" :loading="syncDevices.includes(scope.row.deviceId)" v-if="scope.row.online!=0" icon="el-icon-refresh" @click="refDevice(scope.row)">刷新</el-button>
  60 + <el-button size="mini" v-if="scope.row.online!=0" icon="el-icon-refresh" @click="refDevice(scope.row)" @mouseover="getTooltipContent(scope.row.deviceId)">刷新</el-button>
61 61 <el-button-group>
62 62 <el-button size="mini" icon="el-icon-video-camera-solid" v-bind:disabled="scope.row.online==0" type="primary" @click="showChannelList(scope.row)">通道</el-button>
63 63 <el-button size="mini" icon="el-icon-location" v-bind:disabled="scope.row.online==0" type="primary" @click="showDevicePosition(scope.row)">定位</el-button>
... ... @@ -78,6 +78,7 @@
78 78 :total="total">
79 79 </el-pagination>
80 80 <deviceEdit ref="deviceEdit" ></deviceEdit>
  81 + <syncChannelProgress ref="syncChannelProgress" ></syncChannelProgress>
81 82 </el-main>
82 83 </el-container>
83 84 </div>
... ... @@ -86,11 +87,13 @@
86 87 <script>
87 88 import uiHeader from './UiHeader.vue'
88 89 import deviceEdit from './dialog/deviceEdit.vue'
  90 + import syncChannelProgress from './dialog/SyncChannelProgress.vue'
89 91 export default {
90 92 name: 'app',
91 93 components: {
92 94 uiHeader,
93   - deviceEdit
  95 + deviceEdit,
  96 + syncChannelProgress,
94 97 },
95 98 data() {
96 99 return {
... ... @@ -105,7 +108,6 @@
105 108 count:15,
106 109 total:0,
107 110 getDeviceListLoading: false,
108   - syncDevices:[]
109 111 };
110 112 },
111 113 computed: {
... ... @@ -198,8 +200,7 @@
198 200 //刷新设备信息
199 201 refDevice: function(itemData) {
200 202 console.log("刷新对应设备:" + itemData.deviceId);
201   - var that = this;
202   - this.syncDevices.push(itemData.deviceId)
  203 + let that = this;
203 204 this.$axios({
204 205 method: 'post',
205 206 url: '/api/device/query/devices/' + itemData.deviceId + '/sync'
... ... @@ -212,14 +213,14 @@
212 213 type: 'error'
213 214 });
214 215 }else{
215   - that.$message({
216   - showClose: true,
217   - message: res.data.msg,
218   - type: 'success'
219   - });
  216 + // that.$message({
  217 + // showClose: true,
  218 + // message: res.data.msg,
  219 + // type: 'success'
  220 + // });
  221 + this.$refs.syncChannelProgress.openDialog(itemData.deviceId)
220 222 }
221 223 that.initData()
222   - this.syncDevices.splice(this.syncDevices.indexOf(itemData.deviceId, 1));
223 224 }).catch((e) => {
224 225 console.error(e)
225 226 that.$message({
... ... @@ -227,9 +228,29 @@
227 228 message: e,
228 229 type: 'error'
229 230 });
230   - this.syncDevices.splice(this.syncDevices.indexOf(itemData.deviceId, 1));
231 231 });
  232 +
232 233 },
  234 +
  235 + getTooltipContent: async function (deviceId){
  236 + let result = "";
  237 + await this.$axios({
  238 + method: 'get',
  239 + async: false,
  240 + url:`/api/device/query/${deviceId}/sync_status/`,
  241 + }).then((res) => {
  242 + if (res.data.code == 0) {
  243 + if (res.data.data.errorMsg !== null) {
  244 + result = res.data.data.errorMsg
  245 + } else if (res.data.msg !== null) {
  246 + result = res.data.msg
  247 + } else {
  248 + result = `同步中...[${res.data.data.current}/${res.data.data.total}]`;
  249 + }
  250 + }
  251 + })
  252 + return result;
  253 + },
233 254 //通知设备上传媒体流
234 255 sendDevicePush: function(itemData) {
235 256 // let deviceId = this.currentDevice.deviceId;
... ...
web_src/src/components/dialog/SyncChannelProgress.vue 0 → 100644
  1 +<template>
  2 + <div id="SyncChannelProgress" v-loading="isLoging">
  3 + <el-dialog
  4 + width="240px"
  5 + top="13%"
  6 + :append-to-body="true"
  7 + :close-on-click-modal="false"
  8 + :visible.sync="showDialog"
  9 + :destroy-on-close="true"
  10 + :show-close="true"
  11 + @close="close()"
  12 + style="text-align: center">
  13 + <el-progress type="circle" :percentage="percentage" :status="syncStatus"></el-progress>
  14 + <div style="text-align: center">
  15 + {{msg}}
  16 + </div>
  17 + </el-dialog>
  18 + </div>
  19 +</template>
  20 +
  21 +<script>
  22 +
  23 +export default {
  24 + name: "SyncChannelProgress",
  25 + computed: {},
  26 + props: ['platformId'],
  27 + created() {},
  28 + data() {
  29 + return {
  30 + syncStatus: null,
  31 + percentage: 0,
  32 + total: 0,
  33 + current: 0,
  34 + showDialog: false,
  35 + isLoging: false,
  36 + syncFlag: false,
  37 + deviceId: null,
  38 + timmer: null,
  39 + msg: "正在同步",
  40 + };
  41 + },
  42 + methods: {
  43 + openDialog: function (deviceId) {
  44 + console.log("deviceId: " + deviceId)
  45 + this.deviceId = deviceId;
  46 + this.showDialog = true;
  47 + this.msg = "";
  48 + this.percentage= 0;
  49 + this.total= 0;
  50 + this.current= 0;
  51 + this.syncFlag= false;
  52 + this.syncStatus = null;
  53 + this.getProgress()
  54 + },
  55 + getProgress(){
  56 + this.$axios({
  57 + method: 'get',
  58 + url:`/api/device/query/${this.deviceId}/sync_status/`,
  59 + }).then((res) => {
  60 + if (res.data.code == 0) {
  61 + if (!this.syncFlag) {
  62 + this.syncFlag = true;
  63 + }
  64 + if (res.data.data == null) {
  65 + this.syncStatus = "success"
  66 + this.percentage = 100;
  67 + this.msg = '同步成功';
  68 + }else if (res.data.data.total == 0){
  69 + this.msg = `等待同步中`;
  70 + this.timmer = setTimeout(this.getProgress, 300)
  71 + }else if (res.data.data.errorMsg !== null ){
  72 + this.msg = res.data.data.errorMsg;
  73 + this.syncStatus = "exception"
  74 + }else {
  75 + this.total = res.data.data.total;
  76 + this.current = res.data.data.current;
  77 + this.percentage = Math.floor(Number(res.data.data.current)/Number(res.data.data.total)* 10000)/100;
  78 + this.msg = `同步中...[${res.data.data.current}/${res.data.data.total}]`;
  79 + this.timmer = setTimeout(this.getProgress, 300)
  80 + }
  81 + }else {
  82 + if (this.syncFlag) {
  83 + this.syncStatus = "success"
  84 + this.percentage = 100;
  85 + this.msg = '同步成功';
  86 + }else {
  87 + this.syncStatus = "error"
  88 + this.msg = res.data.msg;
  89 + }
  90 + }
  91 + }).catch((error) =>{
  92 + console.log(error);
  93 + this.syncStatus = "error"
  94 + this.msg = error.response.data.msg;
  95 + });
  96 + },
  97 + close: function (){
  98 + window.clearTimeout(this.timmer)
  99 + }
  100 + },
  101 +};
  102 +</script>
... ...