diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/CatalogData.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/CatalogData.java index 965d7f2a..6ccaca9c 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/CatalogData.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/CatalogData.java @@ -16,11 +16,7 @@ public class CatalogData { private Instant lastTime; private Device device; private String errorMsg; - - public enum CatalogDataStatus{ - ready, runIng, end - } - private CatalogDataStatus status; + private DataStatus status; public int getSn() { @@ -71,11 +67,11 @@ public class CatalogData { this.errorMsg = errorMsg; } - public CatalogDataStatus getStatus() { + public DataStatus getStatus() { return status; } - public void setStatus(CatalogDataStatus status) { + public void setStatus(DataStatus status) { this.status = status; } } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/DataStatus.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/DataStatus.java new file mode 100644 index 00000000..7dd14d6c --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/DataStatus.java @@ -0,0 +1,5 @@ +package com.genersoft.iot.vmp.gb28181.bean; + +public enum DataStatus { + ready, runIng, end +} diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/PresetData.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/PresetData.java new file mode 100644 index 00000000..2b96b1f7 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/PresetData.java @@ -0,0 +1,70 @@ +package com.genersoft.iot.vmp.gb28181.bean; + +import java.time.Instant; +import java.util.List; + +/** + * 预置位数据 + * @author lin + */ +public class PresetData { + /** + * 命令序列号 + */ + private int sn; + private int total; + private List presetItemList; + private Instant lastTime; + private String errorMsg; + + private DataStatus status; + + + public int getSn() { + return sn; + } + + public void setSn(int sn) { + this.sn = sn; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public List getPresetItemList() { + return presetItemList; + } + + public void setPresetItemList(List presetItemList) { + this.presetItemList = presetItemList; + } + + public Instant getLastTime() { + return lastTime; + } + + public void setLastTime(Instant lastTime) { + this.lastTime = lastTime; + } + + public String getErrorMsg() { + return errorMsg; + } + + public void setErrorMsg(String errorMsg) { + this.errorMsg = errorMsg; + } + + public DataStatus getStatus() { + return status; + } + + public void setStatus(DataStatus status) { + this.status = status; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/PresetItem.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/PresetItem.java new file mode 100644 index 00000000..10218f76 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/PresetItem.java @@ -0,0 +1,23 @@ +package com.genersoft.iot.vmp.gb28181.bean; + +public class PresetItem { + + private int presetID; + private String presetName; + + public int getPresetID() { + return presetID; + } + + public void setPresetID(int presetID) { + this.presetID = presetID; + } + + public String getPresetName() { + return presetName; + } + + public void setPresetName(String presetName) { + this.presetName = presetName; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEvent.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEvent.java index 3af91c8e..e4de7477 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEvent.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEvent.java @@ -1,8 +1,6 @@ package com.genersoft.iot.vmp.gb28181.event.subscribe.catalog; import com.genersoft.iot.vmp.common.CommonGbChannel; -import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; -import com.genersoft.iot.vmp.gb28181.bean.GbStream; import org.springframework.context.ApplicationEvent; import java.util.List; diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/session/CatalogDataCatch.java b/src/main/java/com/genersoft/iot/vmp/gb28181/session/CatalogDataCatch.java index 3ed8c954..0526b706 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/session/CatalogDataCatch.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/session/CatalogDataCatch.java @@ -1,9 +1,6 @@ package com.genersoft.iot.vmp.gb28181.session; -import com.genersoft.iot.vmp.gb28181.bean.CatalogData; -import com.genersoft.iot.vmp.gb28181.bean.Device; -import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; -import com.genersoft.iot.vmp.gb28181.bean.SyncStatus; +import com.genersoft.iot.vmp.gb28181.bean.*; import com.genersoft.iot.vmp.service.IDeviceChannelService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; @@ -24,12 +21,12 @@ public class CatalogDataCatch { public void addReady(Device device, int sn ) { CatalogData catalogData = data.get(device.getDeviceId()); - if (catalogData == null || catalogData.getStatus().equals(CatalogData.CatalogDataStatus.end)) { + if (catalogData == null || catalogData.getStatus().equals(DataStatus.end)) { catalogData = new CatalogData(); catalogData.setChannelList(Collections.synchronizedList(new ArrayList<>())); catalogData.setDevice(device); catalogData.setSn(sn); - catalogData.setStatus(CatalogData.CatalogDataStatus.ready); + catalogData.setStatus(DataStatus.ready); catalogData.setLastTime(Instant.now()); data.put(device.getDeviceId(), catalogData); } @@ -43,7 +40,7 @@ public class CatalogDataCatch { catalogData.setTotal(total); catalogData.setDevice(device); catalogData.setChannelList(deviceChannelList); - catalogData.setStatus(CatalogData.CatalogDataStatus.runIng); + catalogData.setStatus(DataStatus.runIng); catalogData.setLastTime(Instant.now()); data.put(deviceId, catalogData); }else { @@ -53,7 +50,7 @@ public class CatalogDataCatch { } catalogData.setTotal(total); catalogData.setDevice(device); - catalogData.setStatus(CatalogData.CatalogDataStatus.runIng); + catalogData.setStatus(DataStatus.runIng); catalogData.getChannelList().addAll(deviceChannelList); catalogData.setLastTime(Instant.now()); } @@ -84,7 +81,7 @@ public class CatalogDataCatch { syncStatus.setCurrent(catalogData.getChannelList().size()); syncStatus.setTotal(catalogData.getTotal()); syncStatus.setErrorMsg(catalogData.getErrorMsg()); - if (catalogData.getStatus().equals(CatalogData.CatalogDataStatus.end)) { + if (catalogData.getStatus().equals(DataStatus.end)) { syncStatus.setSyncIng(false); }else { syncStatus.setSyncIng(true); @@ -97,7 +94,7 @@ public class CatalogDataCatch { if (catalogData == null) { return false; } - return !catalogData.getStatus().equals(CatalogData.CatalogDataStatus.end); + return !catalogData.getStatus().equals(DataStatus.end); } @Scheduled(fixedRate = 5 * 1000) //每5秒执行一次, 发现数据5秒未更新则移除数据并认为数据接收超时 @@ -111,17 +108,17 @@ public class CatalogDataCatch { CatalogData catalogData = data.get(deviceId); if ( catalogData.getLastTime().isBefore(instantBefore5S)) { // 超过五秒收不到消息任务超时, 只更新这一部分数据, 收到数据与声明的总数一致,则重置通道数据,数据不全则只对收到的数据做更新操作 - if (catalogData.getStatus().equals(CatalogData.CatalogDataStatus.runIng)) { + if (catalogData.getStatus().equals(DataStatus.runIng)) { deviceChannelService.updateChannelsForCatalog(catalogData.getDevice(), catalogData.getChannelList()); String errorMsg = "更新成功,共" + catalogData.getTotal() + "条,已更新" + catalogData.getChannelList().size() + "条"; catalogData.setErrorMsg(errorMsg); - }else if (catalogData.getStatus().equals(CatalogData.CatalogDataStatus.ready)) { + }else if (catalogData.getStatus().equals(DataStatus.ready)) { String errorMsg = "同步失败,等待回复超时"; catalogData.setErrorMsg(errorMsg); } - catalogData.setStatus(CatalogData.CatalogDataStatus.end); + catalogData.setStatus(DataStatus.end); } - if (catalogData.getStatus().equals(CatalogData.CatalogDataStatus.end) && catalogData.getLastTime().isBefore(instantBefore30S)) { // 超过三十秒,如果标记为end则删除 + if (catalogData.getStatus().equals(DataStatus.end) && catalogData.getLastTime().isBefore(instantBefore30S)) { // 超过三十秒,如果标记为end则删除 data.remove(deviceId); } } @@ -133,7 +130,7 @@ public class CatalogDataCatch { if (catalogData == null) { return; } - catalogData.setStatus(CatalogData.CatalogDataStatus.end); + catalogData.setStatus(DataStatus.end); catalogData.setErrorMsg(errorMsg); } } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/session/PresetDataCatch.java b/src/main/java/com/genersoft/iot/vmp/gb28181/session/PresetDataCatch.java new file mode 100755 index 00000000..886ff778 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/session/PresetDataCatch.java @@ -0,0 +1,145 @@ +package com.genersoft.iot.vmp.gb28181.session; + +import com.genersoft.iot.vmp.gb28181.bean.*; +import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; +import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; +import com.genersoft.iot.vmp.service.IDeviceChannelService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.time.Instant; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.TimeUnit; + +/** + * 预置位缓存 + */ +@Component +public class PresetDataCatch { + + public static Map data = new ConcurrentHashMap<>(); + + + @Autowired + private DeferredResultHolder deferredResultHolder; + + + public void addReady(int sn ) { + PresetData presetData = data.get(sn); + if (presetData == null || presetData.getStatus().equals(DataStatus.end)) { + presetData = new PresetData(); + presetData.setPresetItemList(Collections.synchronizedList(new ArrayList<>())); + presetData.setSn(sn); + presetData.setStatus(DataStatus.ready); + presetData.setLastTime(Instant.now()); + data.put(sn, presetData); + } + } + + public void put(int sn, int total, Device device, List deviceChannelList) { + PresetData presetData = data.get(sn); + if (presetData == null) { + presetData = new PresetData(); + presetData.setSn(sn); + presetData.setTotal(total); + presetData.setPresetItemList(deviceChannelList); + presetData.setStatus(DataStatus.runIng); + presetData.setLastTime(Instant.now()); + data.put(sn, presetData); + }else { + // 同一个设备的通道同步请求只考虑一个,其他的直接忽略 + if (presetData.getSn() != sn) { + return; + } + presetData.setTotal(total); + presetData.setStatus(DataStatus.runIng); + presetData.getPresetItemList().addAll(deviceChannelList); + presetData.setLastTime(Instant.now()); + } + } + + public List get(int sn) { + PresetData presetData = data.get(sn); + if (presetData == null) { + return null; + } + return presetData.getPresetItemList(); + } + + public int getTotal(int sn) { + PresetData presetData = data.get(sn); + if (presetData == null) { + return 0; + } + return presetData.getTotal(); + } + + public SyncStatus getSyncStatus(int sn) { + PresetData presetData = data.get(sn); + if (presetData == null) { + return null; + } + SyncStatus syncStatus = new SyncStatus(); + syncStatus.setCurrent(presetData.getPresetItemList().size()); + syncStatus.setTotal(presetData.getTotal()); + syncStatus.setErrorMsg(presetData.getErrorMsg()); + if (presetData.getStatus().equals(DataStatus.end)) { + syncStatus.setSyncIng(false); + }else { + syncStatus.setSyncIng(true); + } + return syncStatus; + } + + public boolean isSyncRunning(int sn) { + PresetData presetData = data.get(sn); + if (presetData == null) { + return false; + } + return !presetData.getStatus().equals(DataStatus.end); + } + + @Scheduled(fixedRate = 5 * 1000) //每5秒执行一次, 发现数据5秒未更新则移除数据并认为数据接收超时 + private void timerTask(){ + Set keys = data.keySet(); + + Instant instantBefore5S = Instant.now().minusMillis(TimeUnit.SECONDS.toMillis(5)); + Instant instantBefore30S = Instant.now().minusMillis(TimeUnit.SECONDS.toMillis(30)); + + for (Integer sn : keys) { + PresetData presetData = data.get(sn); + String key = DeferredResultHolder.CALLBACK_CMD_PRESETQUERY + sn; + if ( presetData.getLastTime().isBefore(instantBefore5S)) { + // 超过五秒收不到消息任务超时, 只更新这一部分数据, 收到数据与声明的总数一致,则重置通道数据,数据不全则只对收到的数据做更新操作 + if (presetData.getStatus().equals(DataStatus.runIng)) { + RequestMessage requestMessage = new RequestMessage(); + requestMessage.setKey(key); + requestMessage.setData(presetData.getPresetItemList()); + deferredResultHolder.invokeAllResult(requestMessage); + + String errorMsg = "更新成功,共" + presetData.getTotal() + "条,已更新" + presetData.getPresetItemList().size() + "条"; + presetData.setErrorMsg(errorMsg); + }else if (presetData.getStatus().equals(DataStatus.ready)) { + String errorMsg = "同步失败,等待回复超时"; + presetData.setErrorMsg(errorMsg); + } + presetData.setStatus(DataStatus.end); + } + if (presetData.getStatus().equals(DataStatus.end) && presetData.getLastTime().isBefore(instantBefore30S)) { // 超过三十秒,如果标记为end则删除 + data.remove(sn); + } + } + } + + + public void setChannelSyncEnd(int sn, String errorMsg) { + PresetData presetData = data.get(sn); + if (presetData == null) { + return; + } + presetData.setStatus(DataStatus.end); + presetData.setErrorMsg(errorMsg); + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java index a169a317..bc0527d2 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java @@ -306,7 +306,7 @@ public interface ISIPCommander { * * @param device 视频设备 */ - void presetQuery(Device device, String channelId, SipSubscribe.Event errorEvent) throws InvalidArgumentException, SipException, ParseException; + void presetQuery(Device device, String channelId, int sn, SipSubscribe.Event errorEvent) throws InvalidArgumentException, SipException, ParseException; /** * 查询移动设备位置数据 diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java index 2266f0bf..f33d293f 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java @@ -183,7 +183,7 @@ public class SIPCommander implements ISIPCommander { ptzXml.append("\r\n"); ptzXml.append("\r\n"); ptzXml.append("DeviceControl\r\n"); - ptzXml.append("" + (int) ((Math.random() * 9 + 1) * 100000) + "\r\n"); + ptzXml.append("" + SipUtils.getNewSn() + "\r\n"); ptzXml.append("" + channelId + "\r\n"); ptzXml.append("" + cmdStr + "\r\n"); ptzXml.append("\r\n"); @@ -215,7 +215,7 @@ public class SIPCommander implements ISIPCommander { ptzXml.append("\r\n"); ptzXml.append("\r\n"); ptzXml.append("DeviceControl\r\n"); - ptzXml.append("" + (int) ((Math.random() * 9 + 1) * 100000) + "\r\n"); + ptzXml.append("" + SipUtils.getNewSn() + "\r\n"); ptzXml.append("" + channelId + "\r\n"); ptzXml.append("" + cmdStr + "\r\n"); ptzXml.append("\r\n"); @@ -246,7 +246,7 @@ public class SIPCommander implements ISIPCommander { ptzXml.append("\r\n"); ptzXml.append("\r\n"); ptzXml.append("DeviceControl\r\n"); - ptzXml.append("" + (int) ((Math.random() * 9 + 1) * 100000) + "\r\n"); + ptzXml.append("" + SipUtils.getNewSn() + "\r\n"); ptzXml.append("" + channelId + "\r\n"); ptzXml.append("" + cmdString + "\r\n"); ptzXml.append("\r\n"); @@ -653,7 +653,7 @@ public class SIPCommander implements ISIPCommander { broadcastXml.append("\r\n"); broadcastXml.append("\r\n"); broadcastXml.append("Broadcast\r\n"); - broadcastXml.append("" + (int) ((Math.random() * 9 + 1) * 100000) + "\r\n"); + broadcastXml.append("" + SipUtils.getNewSn() + "\r\n"); broadcastXml.append("" + sipConfig.getId() + "\r\n"); broadcastXml.append("" + device.getDeviceId() + "\r\n"); broadcastXml.append("\r\n"); @@ -673,7 +673,7 @@ public class SIPCommander implements ISIPCommander { broadcastXml.append("\r\n"); broadcastXml.append("\r\n"); broadcastXml.append("Broadcast\r\n"); - broadcastXml.append("" + (int) ((Math.random() * 9 + 1) * 100000) + "\r\n"); + broadcastXml.append("" + SipUtils.getNewSn() + "\r\n"); broadcastXml.append("" + sipConfig.getId() + "\r\n"); broadcastXml.append("" + device.getDeviceId() + "\r\n"); broadcastXml.append("\r\n"); @@ -700,7 +700,7 @@ public class SIPCommander implements ISIPCommander { cmdXml.append("\r\n"); cmdXml.append("\r\n"); cmdXml.append("DeviceControl\r\n"); - cmdXml.append("" + (int) ((Math.random() * 9 + 1) * 100000) + "\r\n"); + cmdXml.append("" + SipUtils.getNewSn() + "\r\n"); if (ObjectUtils.isEmpty(channelId)) { cmdXml.append("" + device.getDeviceId() + "\r\n"); } else { @@ -728,7 +728,7 @@ public class SIPCommander implements ISIPCommander { cmdXml.append("\r\n"); cmdXml.append("\r\n"); cmdXml.append("DeviceControl\r\n"); - cmdXml.append("" + (int) ((Math.random() * 9 + 1) * 100000) + "\r\n"); + cmdXml.append("" + SipUtils.getNewSn() + "\r\n"); cmdXml.append("" + device.getDeviceId() + "\r\n"); cmdXml.append("Boot\r\n"); cmdXml.append("\r\n"); @@ -753,7 +753,7 @@ public class SIPCommander implements ISIPCommander { cmdXml.append("\r\n"); cmdXml.append("\r\n"); cmdXml.append("DeviceControl\r\n"); - cmdXml.append("" + (int) ((Math.random() * 9 + 1) * 100000) + "\r\n"); + cmdXml.append("" + SipUtils.getNewSn() + "\r\n"); cmdXml.append("" + device.getDeviceId() + "\r\n"); cmdXml.append("" + guardCmdStr + "\r\n"); cmdXml.append("\r\n"); @@ -775,7 +775,7 @@ public class SIPCommander implements ISIPCommander { cmdXml.append("\r\n"); cmdXml.append("\r\n"); cmdXml.append("DeviceControl\r\n"); - cmdXml.append("" + (int) ((Math.random() * 9 + 1) * 100000) + "\r\n"); + cmdXml.append("" + SipUtils.getNewSn() + "\r\n"); cmdXml.append("" + device.getDeviceId() + "\r\n"); cmdXml.append("ResetAlarm\r\n"); if (!ObjectUtils.isEmpty(alarmMethod) || !ObjectUtils.isEmpty(alarmType)) { @@ -812,7 +812,7 @@ public class SIPCommander implements ISIPCommander { cmdXml.append("\r\n"); cmdXml.append("\r\n"); cmdXml.append("DeviceControl\r\n"); - cmdXml.append("" + (int) ((Math.random() * 9 + 1) * 100000) + "\r\n"); + cmdXml.append("" + SipUtils.getNewSn() + "\r\n"); if (ObjectUtils.isEmpty(channelId)) { cmdXml.append("" + device.getDeviceId() + "\r\n"); } else { @@ -844,7 +844,7 @@ public class SIPCommander implements ISIPCommander { cmdXml.append("\r\n"); cmdXml.append("\r\n"); cmdXml.append("DeviceControl\r\n"); - cmdXml.append("" + (int) ((Math.random() * 9 + 1) * 100000) + "\r\n"); + cmdXml.append("" + SipUtils.getNewSn() + "\r\n"); if (ObjectUtils.isEmpty(channelId)) { cmdXml.append("" + device.getDeviceId() + "\r\n"); } else { @@ -904,7 +904,7 @@ public class SIPCommander implements ISIPCommander { cmdXml.append("\r\n"); cmdXml.append("\r\n"); cmdXml.append("DeviceConfig\r\n"); - cmdXml.append("" + (int) ((Math.random() * 9 + 1) * 100000) + "\r\n"); + cmdXml.append("" + SipUtils.getNewSn() + "\r\n"); if (ObjectUtils.isEmpty(channelId)) { cmdXml.append("" + device.getDeviceId() + "\r\n"); } else { @@ -951,7 +951,7 @@ public class SIPCommander implements ISIPCommander { catalogXml.append("\r\n"); catalogXml.append("\r\n"); catalogXml.append("DeviceStatus\r\n"); - catalogXml.append("" + (int) ((Math.random() * 9 + 1) * 100000) + "\r\n"); + catalogXml.append("" + SipUtils.getNewSn() + "\r\n"); catalogXml.append("" + device.getDeviceId() + "\r\n"); catalogXml.append("\r\n"); @@ -973,7 +973,7 @@ public class SIPCommander implements ISIPCommander { catalogXml.append("\r\n"); catalogXml.append("\r\n"); catalogXml.append("DeviceInfo\r\n"); - catalogXml.append("" + (int) ((Math.random() * 9 + 1) * 100000) + "\r\n"); + catalogXml.append("" + SipUtils.getNewSn() + "\r\n"); catalogXml.append("" + device.getDeviceId() + "\r\n"); catalogXml.append("\r\n"); @@ -1076,7 +1076,7 @@ public class SIPCommander implements ISIPCommander { cmdXml.append("\r\n"); cmdXml.append("\r\n"); cmdXml.append("Alarm\r\n"); - cmdXml.append("" + (int) ((Math.random() * 9 + 1) * 100000) + "\r\n"); + cmdXml.append("" + SipUtils.getNewSn() + "\r\n"); cmdXml.append("" + device.getDeviceId() + "\r\n"); if (!ObjectUtils.isEmpty(startPriority)) { cmdXml.append("" + startPriority + "\r\n"); @@ -1119,7 +1119,7 @@ public class SIPCommander implements ISIPCommander { cmdXml.append("\r\n"); cmdXml.append("\r\n"); cmdXml.append("ConfigDownload\r\n"); - cmdXml.append("" + (int) ((Math.random() * 9 + 1) * 100000) + "\r\n"); + cmdXml.append("" + SipUtils.getNewSn() + "\r\n"); if (ObjectUtils.isEmpty(channelId)) { cmdXml.append("" + device.getDeviceId() + "\r\n"); } else { @@ -1140,14 +1140,14 @@ public class SIPCommander implements ISIPCommander { * @param device 视频设备 */ @Override - public void presetQuery(Device device, String channelId, SipSubscribe.Event errorEvent) throws InvalidArgumentException, SipException, ParseException { + public void presetQuery(Device device, String channelId, int sn, SipSubscribe.Event errorEvent) throws InvalidArgumentException, SipException, ParseException { StringBuffer cmdXml = new StringBuffer(200); String charset = device.getCharset(); cmdXml.append("\r\n"); cmdXml.append("\r\n"); cmdXml.append("PresetQuery\r\n"); - cmdXml.append("" + (int) ((Math.random() * 9 + 1) * 100000) + "\r\n"); + cmdXml.append("" + sn + "\r\n"); if (ObjectUtils.isEmpty(channelId)) { cmdXml.append("" + device.getDeviceId() + "\r\n"); } else { @@ -1173,7 +1173,7 @@ public class SIPCommander implements ISIPCommander { mobilePostitionXml.append("\r\n"); mobilePostitionXml.append("\r\n"); mobilePostitionXml.append("MobilePosition\r\n"); - mobilePostitionXml.append("" + (int) ((Math.random() * 9 + 1) * 100000) + "\r\n"); + mobilePostitionXml.append("" + SipUtils.getNewSn() + "\r\n"); mobilePostitionXml.append("" + device.getDeviceId() + "\r\n"); mobilePostitionXml.append("60\r\n"); mobilePostitionXml.append("\r\n"); @@ -1200,7 +1200,7 @@ public class SIPCommander implements ISIPCommander { subscribePostitionXml.append("\r\n"); subscribePostitionXml.append("\r\n"); subscribePostitionXml.append("MobilePosition\r\n"); - subscribePostitionXml.append("" + (int) ((Math.random() * 9 + 1) * 100000) + "\r\n"); + subscribePostitionXml.append("" + SipUtils.getNewSn() + "\r\n"); subscribePostitionXml.append("" + device.getDeviceId() + "\r\n"); if (device.getSubscribeCycleForMobilePosition() > 0) { subscribePostitionXml.append("" + device.getMobilePositionSubmissionInterval() + "\r\n"); @@ -1241,7 +1241,7 @@ public class SIPCommander implements ISIPCommander { cmdXml.append("\r\n"); cmdXml.append("\r\n"); cmdXml.append("Alarm\r\n"); - cmdXml.append("" + (int) ((Math.random() * 9 + 1) * 100000) + "\r\n"); + cmdXml.append("" + SipUtils.getNewSn() + "\r\n"); cmdXml.append("" + device.getDeviceId() + "\r\n"); if (!ObjectUtils.isEmpty(startPriority)) { cmdXml.append("" + startPriority + "\r\n"); @@ -1275,7 +1275,7 @@ public class SIPCommander implements ISIPCommander { cmdXml.append("\r\n"); cmdXml.append("\r\n"); cmdXml.append("Catalog\r\n"); - cmdXml.append("" + (int) ((Math.random() * 9 + 1) * 100000) + "\r\n"); + cmdXml.append("" + SipUtils.getNewSn() + "\r\n"); cmdXml.append("" + device.getDeviceId() + "\r\n"); cmdXml.append("\r\n"); @@ -1302,7 +1302,7 @@ public class SIPCommander implements ISIPCommander { dragXml.append("\r\n"); dragXml.append("\r\n"); dragXml.append("DeviceControl\r\n"); - dragXml.append("" + (int) ((Math.random() * 9 + 1) * 100000) + "\r\n"); + dragXml.append("" + SipUtils.getNewSn() + "\r\n"); if (ObjectUtils.isEmpty(channelId)) { dragXml.append("" + device.getDeviceId() + "\r\n"); } else { @@ -1408,7 +1408,7 @@ public class SIPCommander implements ISIPCommander { deviceStatusXml.append("\r\n"); deviceStatusXml.append("\r\n"); deviceStatusXml.append("Alarm\r\n"); - deviceStatusXml.append("" + (int) ((Math.random() * 9 + 1) * 100000) + "\r\n"); + deviceStatusXml.append("" + SipUtils.getNewSn() + "\r\n"); deviceStatusXml.append("" + deviceAlarm.getChannelId() + "\r\n"); deviceStatusXml.append("" + deviceAlarm.getAlarmPriority() + "\r\n"); deviceStatusXml.append("" + deviceAlarm.getAlarmMethod() + "\r\n"); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java index ac6bc43b..996be0fb 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java @@ -556,7 +556,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { catalogXml.append("\r\n") .append("\r\n") .append("Catalog\r\n") - .append("" + (int) ((Math.random() * 9 + 1) * 100000) + "\r\n") + .append("" + SipUtils.getNewSn() + "\r\n") .append("" + parentPlatform.getDeviceGBId() + "\r\n") .append("1\r\n") .append("\r\n"); @@ -717,7 +717,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { catalogXml.append("\r\n") .append("\r\n") .append("Catalog\r\n") - .append("" + (int) ((Math.random() * 9 + 1) * 100000) + "\r\n") + .append("" + SipUtils.getNewSn() + "\r\n") .append("" + parentPlatform.getDeviceGBId() + "\r\n") .append("1\r\n") .append("\r\n"); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/PresetQueryResponseMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/PresetQueryResponseMessageHandler.java index 862a8eea..f4d1c8f5 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/PresetQueryResponseMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/PresetQueryResponseMessageHandler.java @@ -7,6 +7,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler; +import com.genersoft.iot.vmp.gb28181.utils.SipUtils; import gov.nist.javax.sip.message.SIPRequest; import org.dom4j.DocumentException; import org.dom4j.Element; @@ -43,6 +44,7 @@ public class PresetQueryResponseMessageHandler extends SIPRequestProcessorParent private DeferredResultHolder deferredResultHolder; + @Override public void afterPropertiesSet() throws Exception { responseMessageHandler.addHandler(cmdType, this); @@ -52,7 +54,7 @@ public class PresetQueryResponseMessageHandler extends SIPRequestProcessorParent public void handForDevice(RequestEvent evt, Device device, Element element) { SIPRequest request = (SIPRequest) evt.getRequest(); - + String deviceId = SipUtils.getUserIdFromFromHeader(request); try { Element rootElement = getRootElement(evt, device.getCharset()); @@ -66,11 +68,14 @@ public class PresetQueryResponseMessageHandler extends SIPRequestProcessorParent return; } Element presetListNumElement = rootElement.element("PresetList"); - Element snElement = rootElement.element("SN"); + String sn = getText(rootElement, "SN"); //该字段可能为通道或则设备的id - String deviceId = getText(rootElement, "DeviceID"); - String key = DeferredResultHolder.CALLBACK_CMD_PRESETQUERY + deviceId; - if (snElement == null || presetListNumElement == null) { + String channelId = getText(rootElement, "DeviceID"); + if (channelId == null) { + + } + String key = DeferredResultHolder.CALLBACK_CMD_PRESETQUERY + deviceId + channelId; + if (sn == null || presetListNumElement == null) { try { responseAck(request, Response.BAD_REQUEST, "xml error"); } catch (InvalidArgumentException | ParseException | SipException e) { diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java b/src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java index 49f6cc05..65f26ce0 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java @@ -325,4 +325,8 @@ public class SipUtils { subscribeInfo.setSimulatedToTag(UUID.randomUUID().toString().replace("-", "")); return subscribeInfo; } + + public static int getNewSn(){ + return (int) ((Math.random() * 9 + 1) * 100000); + } } \ No newline at end of file diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMMediaListManager.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMMediaListManager.java index 1b93e9ac..1ffc58fc 100755 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMMediaListManager.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMMediaListManager.java @@ -1,12 +1,10 @@ package com.genersoft.iot.vmp.media.zlm; import com.genersoft.iot.vmp.conf.UserSetting; -import com.genersoft.iot.vmp.gb28181.bean.GbStream; import com.genersoft.iot.vmp.media.zlm.dto.*; import com.genersoft.iot.vmp.media.zlm.dto.hook.OnStreamChangedHookParam; import com.genersoft.iot.vmp.service.IMediaServerService; import com.genersoft.iot.vmp.service.IResourceService; -import com.genersoft.iot.vmp.service.IStreamProxyService; import com.genersoft.iot.vmp.service.IStreamPushService; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.IVideoManagerStorage; diff --git a/src/main/java/com/genersoft/iot/vmp/service/IStreamPushService.java b/src/main/java/com/genersoft/iot/vmp/service/IStreamPushService.java index 60694d80..1c2aa58b 100755 --- a/src/main/java/com/genersoft/iot/vmp/service/IStreamPushService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/IStreamPushService.java @@ -1,7 +1,5 @@ package com.genersoft.iot.vmp.service; -import com.genersoft.iot.vmp.common.CommonGbChannel; -import com.genersoft.iot.vmp.gb28181.bean.GbStream; import com.genersoft.iot.vmp.media.zlm.dto.hook.OnStreamChangedHookParam; import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; import com.genersoft.iot.vmp.media.zlm.dto.StreamPush; @@ -62,7 +60,7 @@ public interface IStreamPushService { /** * 中止多个推流 */ - boolean batchStop(List streamPushItems); + boolean batchStop(List streamPushItems); /** * 导入时批量增加 diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushServiceImpl.java index 7ea38d5f..e66b0faf 100755 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushServiceImpl.java @@ -7,15 +7,12 @@ import com.genersoft.iot.vmp.common.BatchLimit; import com.genersoft.iot.vmp.common.CommonGbChannel; import com.genersoft.iot.vmp.conf.MediaConfig; import com.genersoft.iot.vmp.conf.UserSetting; -import com.genersoft.iot.vmp.gb28181.bean.*; import com.genersoft.iot.vmp.gb28181.event.EventPublisher; -import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent; import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils; import com.genersoft.iot.vmp.media.zlm.dto.*; import com.genersoft.iot.vmp.media.zlm.dto.hook.OnStreamChangedHookParam; import com.genersoft.iot.vmp.media.zlm.dto.hook.OriginType; import com.genersoft.iot.vmp.service.*; -import com.genersoft.iot.vmp.service.bean.CommonGbChannelType; import com.genersoft.iot.vmp.service.bean.GPSMsgInfo; import com.genersoft.iot.vmp.service.bean.Group; import com.genersoft.iot.vmp.service.bean.StreamPushItemFromRedis; @@ -29,14 +26,11 @@ import com.github.pagehelper.PageInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.stereotype.Service; -import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; import java.util.*; -import java.util.stream.Collectors; @Service public class StreamPushServiceImpl implements IStreamPushService { @@ -366,15 +360,15 @@ public class StreamPushServiceImpl implements IStreamPushService { } @Override - public boolean batchStop(List gbStreams) { - if (gbStreams == null || gbStreams.size() == 0) { + public boolean batchStop(List streamPushList) { + if (streamPushList == null || streamPushList.size() == 0) { return false; } - int delStream = streamPushMapper.delAllForGbStream(gbStreams); + int delStream = streamPushMapper.delAllForStream(streamPushList); if (delStream > 0) { - for (GbStream gbStream : gbStreams) { - MediaServerItem mediaServerItem = mediaServerService.getOne(gbStream.getMediaServerId()); - zlmresTfulUtils.closeStreams(mediaServerItem, gbStream.getApp(), gbStream.getStream()); + for (StreamPush streamPush : streamPushList) { + MediaServerItem mediaServerItem = mediaServerService.getOne(streamPush.getMediaServerId()); + zlmresTfulUtils.closeStreams(mediaServerItem, streamPush.getApp(), streamPush.getStream()); } } return true; diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/StreamPushMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/StreamPushMapper.java index c5884d89..411f8171 100755 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/StreamPushMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/StreamPushMapper.java @@ -1,6 +1,5 @@ package com.genersoft.iot.vmp.storager.dao; -import com.genersoft.iot.vmp.gb28181.bean.GbStream; import com.genersoft.iot.vmp.media.zlm.dto.StreamPush; import com.genersoft.iot.vmp.service.bean.GPSMsgInfo; import com.genersoft.iot.vmp.service.bean.StreamPushItemFromRedis; @@ -56,11 +55,11 @@ public interface StreamPushMapper { @Delete("") - int delAllForGbStream(List gbStreams); + int delAllForStream(List streamPushList); @Select(value = {"