临时提交

结构优化
648540858 2023-12-20 18:02:47 +08:00
parent 913d4bdc8f
commit 8a605ad722
20 changed files with 332 additions and 94 deletions

View File

@ -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;
}
}

View File

@ -0,0 +1,5 @@
package com.genersoft.iot.vmp.gb28181.bean;
public enum DataStatus {
ready, runIng, end
}

View File

@ -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<PresetItem> 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<PresetItem> getPresetItemList() {
return presetItemList;
}
public void setPresetItemList(List<PresetItem> 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;
}
}

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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<Integer, PresetData> 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<PresetItem> 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<PresetItem> 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<Integer> 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);
}
}

View File

@ -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;
/**
*

View File

@ -183,7 +183,7 @@ public class SIPCommander implements ISIPCommander {
ptzXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
ptzXml.append("<Control>\r\n");
ptzXml.append("<CmdType>DeviceControl</CmdType>\r\n");
ptzXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
ptzXml.append("<SN>" + SipUtils.getNewSn() + "</SN>\r\n");
ptzXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
ptzXml.append("<PTZCmd>" + cmdStr + "</PTZCmd>\r\n");
ptzXml.append("<Info>\r\n");
@ -215,7 +215,7 @@ public class SIPCommander implements ISIPCommander {
ptzXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
ptzXml.append("<Control>\r\n");
ptzXml.append("<CmdType>DeviceControl</CmdType>\r\n");
ptzXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
ptzXml.append("<SN>" + SipUtils.getNewSn() + "</SN>\r\n");
ptzXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
ptzXml.append("<PTZCmd>" + cmdStr + "</PTZCmd>\r\n");
ptzXml.append("<Info>\r\n");
@ -246,7 +246,7 @@ public class SIPCommander implements ISIPCommander {
ptzXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
ptzXml.append("<Control>\r\n");
ptzXml.append("<CmdType>DeviceControl</CmdType>\r\n");
ptzXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
ptzXml.append("<SN>" + SipUtils.getNewSn() + "</SN>\r\n");
ptzXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
ptzXml.append("<PTZCmd>" + cmdString + "</PTZCmd>\r\n");
ptzXml.append("<Info>\r\n");
@ -653,7 +653,7 @@ public class SIPCommander implements ISIPCommander {
broadcastXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
broadcastXml.append("<Notify>\r\n");
broadcastXml.append("<CmdType>Broadcast</CmdType>\r\n");
broadcastXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
broadcastXml.append("<SN>" + SipUtils.getNewSn() + "</SN>\r\n");
broadcastXml.append("<SourceID>" + sipConfig.getId() + "</SourceID>\r\n");
broadcastXml.append("<TargetID>" + device.getDeviceId() + "</TargetID>\r\n");
broadcastXml.append("</Notify>\r\n");
@ -673,7 +673,7 @@ public class SIPCommander implements ISIPCommander {
broadcastXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
broadcastXml.append("<Notify>\r\n");
broadcastXml.append("<CmdType>Broadcast</CmdType>\r\n");
broadcastXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
broadcastXml.append("<SN>" + SipUtils.getNewSn() + "</SN>\r\n");
broadcastXml.append("<SourceID>" + sipConfig.getId() + "</SourceID>\r\n");
broadcastXml.append("<TargetID>" + device.getDeviceId() + "</TargetID>\r\n");
broadcastXml.append("</Notify>\r\n");
@ -700,7 +700,7 @@ public class SIPCommander implements ISIPCommander {
cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
cmdXml.append("<Control>\r\n");
cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
cmdXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
cmdXml.append("<SN>" + SipUtils.getNewSn() + "</SN>\r\n");
if (ObjectUtils.isEmpty(channelId)) {
cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
} else {
@ -728,7 +728,7 @@ public class SIPCommander implements ISIPCommander {
cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
cmdXml.append("<Control>\r\n");
cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
cmdXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
cmdXml.append("<SN>" + SipUtils.getNewSn() + "</SN>\r\n");
cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
cmdXml.append("<TeleBoot>Boot</TeleBoot>\r\n");
cmdXml.append("</Control>\r\n");
@ -753,7 +753,7 @@ public class SIPCommander implements ISIPCommander {
cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
cmdXml.append("<Control>\r\n");
cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
cmdXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
cmdXml.append("<SN>" + SipUtils.getNewSn() + "</SN>\r\n");
cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
cmdXml.append("<GuardCmd>" + guardCmdStr + "</GuardCmd>\r\n");
cmdXml.append("</Control>\r\n");
@ -775,7 +775,7 @@ public class SIPCommander implements ISIPCommander {
cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
cmdXml.append("<Control>\r\n");
cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
cmdXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
cmdXml.append("<SN>" + SipUtils.getNewSn() + "</SN>\r\n");
cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
cmdXml.append("<AlarmCmd>ResetAlarm</AlarmCmd>\r\n");
if (!ObjectUtils.isEmpty(alarmMethod) || !ObjectUtils.isEmpty(alarmType)) {
@ -812,7 +812,7 @@ public class SIPCommander implements ISIPCommander {
cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
cmdXml.append("<Control>\r\n");
cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
cmdXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
cmdXml.append("<SN>" + SipUtils.getNewSn() + "</SN>\r\n");
if (ObjectUtils.isEmpty(channelId)) {
cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
} else {
@ -844,7 +844,7 @@ public class SIPCommander implements ISIPCommander {
cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
cmdXml.append("<Control>\r\n");
cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
cmdXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
cmdXml.append("<SN>" + SipUtils.getNewSn() + "</SN>\r\n");
if (ObjectUtils.isEmpty(channelId)) {
cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
} else {
@ -904,7 +904,7 @@ public class SIPCommander implements ISIPCommander {
cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
cmdXml.append("<Control>\r\n");
cmdXml.append("<CmdType>DeviceConfig</CmdType>\r\n");
cmdXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
cmdXml.append("<SN>" + SipUtils.getNewSn() + "</SN>\r\n");
if (ObjectUtils.isEmpty(channelId)) {
cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
} else {
@ -951,7 +951,7 @@ public class SIPCommander implements ISIPCommander {
catalogXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
catalogXml.append("<Query>\r\n");
catalogXml.append("<CmdType>DeviceStatus</CmdType>\r\n");
catalogXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
catalogXml.append("<SN>" + SipUtils.getNewSn() + "</SN>\r\n");
catalogXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
catalogXml.append("</Query>\r\n");
@ -973,7 +973,7 @@ public class SIPCommander implements ISIPCommander {
catalogXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
catalogXml.append("<Query>\r\n");
catalogXml.append("<CmdType>DeviceInfo</CmdType>\r\n");
catalogXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
catalogXml.append("<SN>" + SipUtils.getNewSn() + "</SN>\r\n");
catalogXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
catalogXml.append("</Query>\r\n");
@ -1076,7 +1076,7 @@ public class SIPCommander implements ISIPCommander {
cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
cmdXml.append("<Query>\r\n");
cmdXml.append("<CmdType>Alarm</CmdType>\r\n");
cmdXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
cmdXml.append("<SN>" + SipUtils.getNewSn() + "</SN>\r\n");
cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
if (!ObjectUtils.isEmpty(startPriority)) {
cmdXml.append("<StartAlarmPriority>" + startPriority + "</StartAlarmPriority>\r\n");
@ -1119,7 +1119,7 @@ public class SIPCommander implements ISIPCommander {
cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
cmdXml.append("<Query>\r\n");
cmdXml.append("<CmdType>ConfigDownload</CmdType>\r\n");
cmdXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
cmdXml.append("<SN>" + SipUtils.getNewSn() + "</SN>\r\n");
if (ObjectUtils.isEmpty(channelId)) {
cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\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("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
cmdXml.append("<Query>\r\n");
cmdXml.append("<CmdType>PresetQuery</CmdType>\r\n");
cmdXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
cmdXml.append("<SN>" + sn + "</SN>\r\n");
if (ObjectUtils.isEmpty(channelId)) {
cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
} else {
@ -1173,7 +1173,7 @@ public class SIPCommander implements ISIPCommander {
mobilePostitionXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
mobilePostitionXml.append("<Query>\r\n");
mobilePostitionXml.append("<CmdType>MobilePosition</CmdType>\r\n");
mobilePostitionXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
mobilePostitionXml.append("<SN>" + SipUtils.getNewSn() + "</SN>\r\n");
mobilePostitionXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
mobilePostitionXml.append("<Interval>60</Interval>\r\n");
mobilePostitionXml.append("</Query>\r\n");
@ -1200,7 +1200,7 @@ public class SIPCommander implements ISIPCommander {
subscribePostitionXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
subscribePostitionXml.append("<Query>\r\n");
subscribePostitionXml.append("<CmdType>MobilePosition</CmdType>\r\n");
subscribePostitionXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
subscribePostitionXml.append("<SN>" + SipUtils.getNewSn() + "</SN>\r\n");
subscribePostitionXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
if (device.getSubscribeCycleForMobilePosition() > 0) {
subscribePostitionXml.append("<Interval>" + device.getMobilePositionSubmissionInterval() + "</Interval>\r\n");
@ -1241,7 +1241,7 @@ public class SIPCommander implements ISIPCommander {
cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
cmdXml.append("<Query>\r\n");
cmdXml.append("<CmdType>Alarm</CmdType>\r\n");
cmdXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
cmdXml.append("<SN>" + SipUtils.getNewSn() + "</SN>\r\n");
cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
if (!ObjectUtils.isEmpty(startPriority)) {
cmdXml.append("<StartAlarmPriority>" + startPriority + "</StartAlarmPriority>\r\n");
@ -1275,7 +1275,7 @@ public class SIPCommander implements ISIPCommander {
cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
cmdXml.append("<Query>\r\n");
cmdXml.append("<CmdType>Catalog</CmdType>\r\n");
cmdXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
cmdXml.append("<SN>" + SipUtils.getNewSn() + "</SN>\r\n");
cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
cmdXml.append("</Query>\r\n");
@ -1302,7 +1302,7 @@ public class SIPCommander implements ISIPCommander {
dragXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
dragXml.append("<Control>\r\n");
dragXml.append("<CmdType>DeviceControl</CmdType>\r\n");
dragXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
dragXml.append("<SN>" + SipUtils.getNewSn() + "</SN>\r\n");
if (ObjectUtils.isEmpty(channelId)) {
dragXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
} else {
@ -1408,7 +1408,7 @@ public class SIPCommander implements ISIPCommander {
deviceStatusXml.append("<?xml version=\"1.0\" encoding=\"" + characterSet + "\"?>\r\n");
deviceStatusXml.append("<Notify>\r\n");
deviceStatusXml.append("<CmdType>Alarm</CmdType>\r\n");
deviceStatusXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
deviceStatusXml.append("<SN>" + SipUtils.getNewSn() + "</SN>\r\n");
deviceStatusXml.append("<DeviceID>" + deviceAlarm.getChannelId() + "</DeviceID>\r\n");
deviceStatusXml.append("<AlarmPriority>" + deviceAlarm.getAlarmPriority() + "</AlarmPriority>\r\n");
deviceStatusXml.append("<AlarmMethod>" + deviceAlarm.getAlarmMethod() + "</AlarmMethod>\r\n");

View File

@ -556,7 +556,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
catalogXml.append("<?xml version=\"1.0\" encoding=\"" + characterSet + "\"?>\r\n")
.append("<Notify>\r\n")
.append("<CmdType>Catalog</CmdType>\r\n")
.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n")
.append("<SN>" + SipUtils.getNewSn() + "</SN>\r\n")
.append("<DeviceID>" + parentPlatform.getDeviceGBId() + "</DeviceID>\r\n")
.append("<SumNum>1</SumNum>\r\n")
.append("<DeviceList Num=\"" + channels.size() + "\">\r\n");
@ -717,7 +717,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
catalogXml.append("<?xml version=\"1.0\" encoding=\"" + characterSet + "\"?>\r\n")
.append("<Notify>\r\n")
.append("<CmdType>Catalog</CmdType>\r\n")
.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n")
.append("<SN>" + SipUtils.getNewSn() + "</SN>\r\n")
.append("<DeviceID>" + parentPlatform.getDeviceGBId() + "</DeviceID>\r\n")
.append("<SumNum>1</SumNum>\r\n")
.append("<DeviceList Num=\" " + channels.size() + " \">\r\n");

View File

@ -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) {

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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<GbStream> streamPushItems);
boolean batchStop(List<StreamPush> streamPushItems);
/**
*

View File

@ -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<GbStream> gbStreams) {
if (gbStreams == null || gbStreams.size() == 0) {
public boolean batchStop(List<StreamPush> 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;

View File

@ -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("<script> "+
"DELETE FROM wvp_stream_push where " +
"<foreach collection='gbStreams' item='item' separator='or'>" +
"<foreach collection='streamPushList' item='item' separator='or'>" +
"(app=#{item.app} and stream=#{item.stream}) " +
"</foreach>" +
"</script>")
int delAllForGbStream(List<GbStream> gbStreams);
int delAllForStream(List<StreamPush> streamPushList);
@Select(value = {" <script>" +

View File

@ -1,6 +1,6 @@
package com.genersoft.iot.vmp.vmanager.bean;
import com.genersoft.iot.vmp.gb28181.bean.GbStream;
import com.genersoft.iot.vmp.media.zlm.dto.StreamPush;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
@ -11,13 +11,13 @@ import java.util.List;
@Schema(description = "多个推流信息")
public class BatchGBStreamParam {
@Schema(description = "推流信息列表")
private List<GbStream> gbStreams;
private List<StreamPush> streamPushes;
public List<GbStream> getGbStreams() {
return gbStreams;
public List<StreamPush> getStreamPushes() {
return streamPushes;
}
public void setGbStreams(List<GbStream> gbStreams) {
this.gbStreams = gbStreams;
public void setStreamPushes(List<StreamPush> streamPushes) {
this.streamPushes = streamPushes;
}
}

View File

@ -3,9 +3,12 @@ package com.genersoft.iot.vmp.vmanager.gb28181.ptz;
import com.genersoft.iot.vmp.conf.exception.ControllerException;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.bean.PresetItem;
import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
import com.genersoft.iot.vmp.gb28181.utils.SipUtils;
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import io.swagger.v3.oas.annotations.Operation;
@ -21,6 +24,7 @@ import org.springframework.web.context.request.async.DeferredResult;
import javax.sip.InvalidArgumentException;
import javax.sip.SipException;
import java.text.ParseException;
import java.util.List;
import java.util.UUID;
@Tag(name = "云台控制")
@ -32,7 +36,7 @@ public class PtzController {
private final static Logger logger = LoggerFactory.getLogger(PtzController.class);
@Autowired
private SIPCommander cmder;
private ISIPCommander cmder;
@Autowired
private IVideoManagerStorage storager;
@ -141,31 +145,33 @@ public class PtzController {
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
@Parameter(name = "channelId", description = "通道国标编号", required = true)
@GetMapping("/preset/query/{deviceId}/{channelId}")
public DeferredResult<String> presetQueryApi(@PathVariable String deviceId, @PathVariable String channelId) {
public DeferredResult<List<PresetItem>> presetQueryApi(@PathVariable String deviceId, @PathVariable String channelId) {
if (logger.isDebugEnabled()) {
logger.debug("设备预置位查询API调用");
}
Device device = storager.queryVideoDevice(deviceId);
String uuid = UUID.randomUUID().toString();
String key = DeferredResultHolder.CALLBACK_CMD_PRESETQUERY + (ObjectUtils.isEmpty(channelId) ? deviceId : channelId);
DeferredResult<String> result = new DeferredResult<String> (3 * 1000L);
int sn = SipUtils.getNewSn();
String msgId = sn + "";
String key = DeferredResultHolder.CALLBACK_CMD_PRESETQUERY + sn;
DeferredResult<List<PresetItem>> result = new DeferredResult<> (3 * 1000L);
result.onTimeout(()->{
logger.warn(String.format("获取设备预置位超时"));
// 释放rtpserver
RequestMessage msg = new RequestMessage();
msg.setId(uuid);
msg.setId(msgId);
msg.setKey(key);
msg.setData("获取设备预置位超时");
resultHolder.invokeResult(msg);
});
if (resultHolder.exist(key, null)) {
return result;
}
resultHolder.put(key, uuid, result);
resultHolder.put(key, msgId, result);
try {
cmder.presetQuery(device, channelId, event -> {
cmder.presetQuery(device, channelId, sn, event -> {
RequestMessage msg = new RequestMessage();
msg.setId(uuid);
msg.setId(msgId);
msg.setKey(key);
msg.setData(String.format("获取设备预置位失败,错误码: %s, %s", event.statusCode, event.msg));
resultHolder.invokeResult(msg);

View File

@ -106,10 +106,10 @@ public class StreamPushController {
@ResponseBody
@Operation(summary = "中止多个推流")
public void batchStop(@RequestBody BatchGBStreamParam batchGBStreamParam){
if (batchGBStreamParam.getGbStreams().size() == 0) {
if (batchGBStreamParam.getStreamPushes().size() == 0) {
throw new ControllerException(ErrorCode.ERROR100);
}
if (!streamPushService.batchStop(batchGBStreamParam.getGbStreams())){
if (!streamPushService.batchStop(batchGBStreamParam.getStreamPushes())){
throw new ControllerException(ErrorCode.ERROR100);
}
}

View File

@ -194,7 +194,7 @@ public class ApiDeviceController {
Device device = storager.queryVideoDevice(serial);
String uuid = UUID.randomUUID().toString();
String key = DeferredResultHolder.CALLBACK_CMD_PRESETQUERY + (ObjectUtils.isEmpty(code) ? serial : code);
String key = DeferredResultHolder.CALLBACK_CMD_PRESETQUERY + serial + code;
DeferredResult<Object> result = new DeferredResult<> (timeout * 1000L);
DeferredResultEx<Object> deferredResultEx = new DeferredResultEx<>(result);
result.onTimeout(()->{