修复WVP作为下级平台接受devicecontrol命令处理-调试修改逻辑

pull/741/head
gaofw189 2023-02-07 09:26:08 +08:00
parent 25fca14e62
commit 55ee6f5f0d
11 changed files with 350 additions and 105 deletions

View File

@ -1,5 +1,7 @@
package com.genersoft.iot.vmp.common.enums; package com.genersoft.iot.vmp.common.enums;
import com.alibaba.fastjson2.JSONObject;
import com.genersoft.iot.vmp.gb28181.utils.XmlUtil;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import org.dom4j.Element; import org.dom4j.Element;
@ -60,7 +62,7 @@ public enum DeviceControlType {
public static DeviceControlType typeOf(Element rootElement) { public static DeviceControlType typeOf(Element rootElement) {
for (DeviceControlType item : DeviceControlType.values()) { for (DeviceControlType item : DeviceControlType.values()) {
if (!ObjectUtils.isEmpty(getText(rootElement,item.val))) { if (!ObjectUtils.isEmpty(rootElement.element(item.val)) || !ObjectUtils.isEmpty(rootElement.elements(item.val))) {
return item; return item;
} }
} }

View File

@ -0,0 +1,70 @@
package com.genersoft.iot.vmp.gb28181.bean;
import com.genersoft.iot.vmp.gb28181.utils.MessageElement;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
*
*
* @author Y.G
* @version 1.0
* @date 2022/6/28 14:55
*/
@Data
public class DragZoomRequest {
/**
*
*/
@MessageElement("SN")
private String sn;
@MessageElement("DeviceID")
private String deviceId;
@MessageElement(value = "DragZoomIn")
private DragZoom dragZoomIn;
@MessageElement(value = "DragZoomOut")
private DragZoom dragZoomOut;
/**
*
*/
@Data
public static class DragZoom {
/**
*
*/
@MessageElement("Length")
protected Integer length;
/**
*
*/
@MessageElement("Width")
protected Integer width;
/**
*
*/
@MessageElement("MidPointX")
protected Integer midPointX;
/**
*
*/
@MessageElement("MidPointY")
protected Integer midPointY;
/**
*
*/
@MessageElement("LengthX")
protected Integer lengthX;
/**
*
*/
@MessageElement("LengthY")
protected Integer lengthY;
}
}

View File

@ -0,0 +1,50 @@
package com.genersoft.iot.vmp.gb28181.bean;
import com.genersoft.iot.vmp.gb28181.utils.MessageElement;
import lombok.Data;
/**
*
*
* @author Y.G
* @version 1.0
* @date 2022/6/28 14:55
*/
@Data
public class HomePositionRequest {
/**
*
*/
@MessageElement("SN")
private String sn;
@MessageElement("DeviceID")
private String deviceId;
@MessageElement(value = "HomePosition")
private HomePosition homePosition;
/**
*
*/
@Data
public static class HomePosition {
/**
*
*/
@MessageElement("Enabled")
protected String enabled;
/**
*
*/
@MessageElement("ResetTime")
protected String resetTime;
/**
*
*/
@MessageElement("PresetIndex")
protected String presetIndex;
}
}

View File

@ -226,7 +226,7 @@ public interface ISIPCommander {
* @param resetTime 使:(s) * @param resetTime 使:(s)
* @param presetIndex 使0~255 * @param presetIndex 使0~255
*/ */
void homePositionCmd(Device device, String channelId,String frontCmd, String enabled, String resetTime, String presetIndex, SipSubscribe.Event errorEvent,SipSubscribe.Event okEvent) throws InvalidArgumentException, SipException, ParseException; void homePositionCmd(Device device, String channelId, String enabled, String resetTime, String presetIndex, SipSubscribe.Event errorEvent,SipSubscribe.Event okEvent) throws InvalidArgumentException, SipException, ParseException;
/** /**
* *

View File

@ -808,7 +808,7 @@ public class SIPCommander implements ISIPCommander {
* @param presetIndex 使0~255 * @param presetIndex 使0~255
*/ */
@Override @Override
public void homePositionCmd(Device device, String channelId,String frontCmd, String enabled, String resetTime, String presetIndex, SipSubscribe.Event errorEvent,SipSubscribe.Event okEvent) throws InvalidArgumentException, SipException, ParseException { public void homePositionCmd(Device device, String channelId, String enabled, String resetTime, String presetIndex, SipSubscribe.Event errorEvent,SipSubscribe.Event okEvent) throws InvalidArgumentException, SipException, ParseException {
StringBuffer cmdXml = new StringBuffer(200); StringBuffer cmdXml = new StringBuffer(200);
String charset = device.getCharset(); String charset = device.getCharset();
@ -822,26 +822,21 @@ public class SIPCommander implements ISIPCommander {
cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n"); cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
} }
cmdXml.append("<HomePosition>\r\n"); cmdXml.append("<HomePosition>\r\n");
if (StringUtils.hasText(frontCmd)){ if (NumericUtil.isInteger(enabled) && (!enabled.equals("0"))) {
cmdXml.append(frontCmd); cmdXml.append("<Enabled>1</Enabled>\r\n");
}else{ if (NumericUtil.isInteger(resetTime)) {
if (NumericUtil.isInteger(enabled) && (!enabled.equals("0"))) { cmdXml.append("<ResetTime>" + resetTime + "</ResetTime>\r\n");
cmdXml.append("<Enabled>1</Enabled>\r\n");
if (NumericUtil.isInteger(resetTime)) {
cmdXml.append("<ResetTime>" + resetTime + "</ResetTime>\r\n");
} else {
cmdXml.append("<ResetTime>0</ResetTime>\r\n");
}
if (NumericUtil.isInteger(presetIndex)) {
cmdXml.append("<PresetIndex>" + presetIndex + "</PresetIndex>\r\n");
} else {
cmdXml.append("<PresetIndex>0</PresetIndex>\r\n");
}
} else { } else {
cmdXml.append("<Enabled>0</Enabled>\r\n"); cmdXml.append("<ResetTime>0</ResetTime>\r\n");
} }
if (NumericUtil.isInteger(presetIndex)) {
cmdXml.append("<PresetIndex>" + presetIndex + "</PresetIndex>\r\n");
} else {
cmdXml.append("<PresetIndex>0</PresetIndex>\r\n");
}
} else {
cmdXml.append("<Enabled>0</Enabled>\r\n");
} }
cmdXml.append("</HomePosition>\r\n"); cmdXml.append("</HomePosition>\r\n");
cmdXml.append("</Control>\r\n"); cmdXml.append("</Control>\r\n");

View File

@ -2,6 +2,8 @@ package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.contro
import com.genersoft.iot.vmp.common.enums.DeviceControlType; import com.genersoft.iot.vmp.common.enums.DeviceControlType;
import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.bean.DragZoomRequest;
import com.genersoft.iot.vmp.gb28181.bean.HomePositionRequest;
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe; import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
@ -20,18 +22,14 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import javax.sip.*; import javax.sip.*;
import javax.sip.address.SipURI; import javax.sip.address.SipURI;
import javax.sip.header.HeaderAddress;
import javax.sip.header.ToHeader;
import javax.sip.message.Response; import javax.sip.message.Response;
import java.text.ParseException; import java.text.ParseException;
import java.util.Iterator; import java.util.List;
import java.util.Objects;
import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.*;
@Component @Component
public class DeviceControlQueryMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { public class DeviceControlQueryMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler {
@ -83,7 +81,7 @@ public class DeviceControlQueryMessageHandler extends SIPRequestProcessorParent
} catch (InvalidArgumentException | ParseException | SipException e) { } catch (InvalidArgumentException | ParseException | SipException e) {
logger.error("[命令发送失败] 国标级联 注销: {}", e.getMessage()); logger.error("[命令发送失败] 国标级联 注销: {}", e.getMessage());
} }
taskExecutor.execute(()->{ taskExecutor.execute(() -> {
// 远程启动 // 远程启动
// try { // try {
// Thread.sleep(3000); // Thread.sleep(3000);
@ -106,7 +104,8 @@ public class DeviceControlQueryMessageHandler extends SIPRequestProcessorParent
} }
} }
DeviceControlType deviceControlType = DeviceControlType.typeOf(rootElement); DeviceControlType deviceControlType = DeviceControlType.typeOf(rootElement);
if (!ObjectUtils.isEmpty(deviceControlType) && !parentPlatform.getServerGBId().equals(targetGBId)){ logger.info("[接受deviceControl命令] 命令: {}", deviceControlType);
if (!ObjectUtils.isEmpty(deviceControlType) && !parentPlatform.getServerGBId().equals(targetGBId)) {
//判断是否存在该通道 //判断是否存在该通道
Device deviceForPlatform = storager.queryVideoDeviceByPlatformIdAndChannelId(parentPlatform.getServerGBId(), channelId); Device deviceForPlatform = storager.queryVideoDeviceByPlatformIdAndChannelId(parentPlatform.getServerGBId(), channelId);
if (deviceForPlatform == null) { if (deviceForPlatform == null) {
@ -117,33 +116,33 @@ public class DeviceControlQueryMessageHandler extends SIPRequestProcessorParent
} }
return; return;
} }
switch (deviceControlType){ switch (deviceControlType) {
case PTZ: case PTZ:
handlePtzCmd(deviceForPlatform,channelId,rootElement,request,DeviceControlType.PTZ); handlePtzCmd(deviceForPlatform, channelId, rootElement, request, DeviceControlType.PTZ);
break; break;
case ALARM: case ALARM:
handleAlarmCmd(deviceForPlatform,rootElement,request); handleAlarmCmd(deviceForPlatform, rootElement, request);
break; break;
case GUARD: case GUARD:
handleGuardCmd(deviceForPlatform,rootElement,request,DeviceControlType.GUARD); handleGuardCmd(deviceForPlatform, rootElement, request, DeviceControlType.GUARD);
break; break;
case RECORD: case RECORD:
handleRecordCmd(deviceForPlatform,channelId,rootElement,request,DeviceControlType.RECORD); handleRecordCmd(deviceForPlatform, channelId, rootElement, request, DeviceControlType.RECORD);
break; break;
case I_FRAME: case I_FRAME:
handleIFameCmd(deviceForPlatform,request,channelId); handleIFameCmd(deviceForPlatform, request, channelId);
break; break;
case TELE_BOOT: case TELE_BOOT:
handleTeleBootCmd(deviceForPlatform,request); handleTeleBootCmd(deviceForPlatform, request);
break; break;
case DRAG_ZOOM_IN: case DRAG_ZOOM_IN:
handleDragZoom(deviceForPlatform,channelId,rootElement,request,DeviceControlType.DRAG_ZOOM_IN); handleDragZoom(deviceForPlatform, channelId, rootElement, request, DeviceControlType.DRAG_ZOOM_IN);
break; break;
case DRAG_ZOOM_OUT: case DRAG_ZOOM_OUT:
handleDragZoom(deviceForPlatform,channelId,rootElement,request,DeviceControlType.DRAG_ZOOM_OUT); handleDragZoom(deviceForPlatform, channelId, rootElement, request, DeviceControlType.DRAG_ZOOM_OUT);
break; break;
case HOME_POSITION: case HOME_POSITION:
handleHomePositionCmd(deviceForPlatform,channelId,rootElement,request,DeviceControlType.HOME_POSITION); handleHomePositionCmd(deviceForPlatform, channelId, rootElement, request, DeviceControlType.HOME_POSITION);
break; break;
default: default:
break; break;
@ -153,17 +152,18 @@ public class DeviceControlQueryMessageHandler extends SIPRequestProcessorParent
/** /**
* *
* @param device *
* @param channelId id * @param device
* @param channelId id
* @param rootElement * @param rootElement
* @param request * @param request
*/ */
private void handlePtzCmd(Device device,String channelId,Element rootElement,SIPRequest request,DeviceControlType type){ private void handlePtzCmd(Device device, String channelId, Element rootElement, SIPRequest request, DeviceControlType type) {
String cmdString = getText(rootElement,type.getVal()); String cmdString = getText(rootElement, type.getVal());
try { try {
cmder.fronEndCmd(device, channelId, cmdString, cmder.fronEndCmd(device, channelId, cmdString,
errorResult -> onError(request,errorResult), errorResult -> onError(request, errorResult),
okResult -> onOk(request,okResult)); okResult -> onOk(request, okResult));
} catch (InvalidArgumentException | SipException | ParseException e) { } catch (InvalidArgumentException | SipException | ParseException e) {
logger.error("[命令发送失败] 云台/前端: {}", e.getMessage()); logger.error("[命令发送失败] 云台/前端: {}", e.getMessage());
} }
@ -171,12 +171,13 @@ public class DeviceControlQueryMessageHandler extends SIPRequestProcessorParent
/** /**
* *
* @param device *
* @param device
* @param channelId id * @param channelId id
*/ */
private void handleIFameCmd(Device device,SIPRequest request,String channelId){ private void handleIFameCmd(Device device, SIPRequest request, String channelId) {
try { try {
cmder.iFrameCmd(device,channelId); cmder.iFrameCmd(device, channelId);
responseAck(request, Response.OK); responseAck(request, Response.OK);
} catch (InvalidArgumentException | SipException | ParseException e) { } catch (InvalidArgumentException | SipException | ParseException e) {
logger.error("[命令发送失败] 强制关键帧: {}", e.getMessage()); logger.error("[命令发送失败] 强制关键帧: {}", e.getMessage());
@ -185,9 +186,10 @@ public class DeviceControlQueryMessageHandler extends SIPRequestProcessorParent
/** /**
* *
*
* @param device * @param device
*/ */
private void handleTeleBootCmd(Device device,SIPRequest request){ private void handleTeleBootCmd(Device device, SIPRequest request) {
try { try {
cmder.teleBootCmd(device); cmder.teleBootCmd(device);
responseAck(request, Response.OK); responseAck(request, Response.OK);
@ -198,67 +200,82 @@ public class DeviceControlQueryMessageHandler extends SIPRequestProcessorParent
} }
/** /**
* * ***
* @param device *
* @param channelId id * @param device
* @param channelId id
* @param rootElement * @param rootElement
* @param type * @param type
*/ */
private void handleDragZoom(Device device,String channelId,Element rootElement,SIPRequest request,DeviceControlType type){ private void handleDragZoom(Device device, String channelId, Element rootElement, SIPRequest request, DeviceControlType type) {
String cmdString = getText(rootElement,type.getVal());
StringBuffer cmdXml = new StringBuffer(200);
cmdXml.append("<" + type.getVal() + ">\r\n");
cmdXml.append(cmdString);
cmdXml.append("</" + type.getVal() + ">\r\n");
try { try {
cmder.dragZoomCmd(device,channelId,cmdXml.toString()); DragZoomRequest dragZoomRequest = loadElement(rootElement, DragZoomRequest.class);
DragZoomRequest.DragZoom dragZoom = dragZoomRequest.getDragZoomIn();
if (dragZoom == null) {
dragZoom = dragZoomRequest.getDragZoomOut();
}
StringBuffer cmdXml = new StringBuffer(200);
cmdXml.append("<" + type.getVal() + ">\r\n");
cmdXml.append("<Length>" + dragZoom.getLength() + "</Length>\r\n");
cmdXml.append("<Width>" + dragZoom.getWidth() + "</Width>\r\n");
cmdXml.append("<MidPointX>" + dragZoom.getMidPointX() + "</MidPointX>\r\n");
cmdXml.append("<MidPointY>" + dragZoom.getMidPointY() + "</MidPointY>\r\n");
cmdXml.append("<LengthX>" + dragZoom.getLengthX() + "</LengthX>\r\n");
cmdXml.append("<LengthY>" + dragZoom.getLengthY() + "</LengthY>\r\n");
cmdXml.append("</" + type.getVal() + ">\r\n");
cmder.dragZoomCmd(device, channelId, cmdXml.toString());
responseAck(request, Response.OK); responseAck(request, Response.OK);
} catch (InvalidArgumentException | SipException | ParseException e) { } catch (Exception e) {
logger.error("[命令发送失败] 拉框控制: {}", e.getMessage()); logger.error("[命令发送失败] 拉框控制: {}", e.getMessage());
} }
} }
/** /**
* * ***
* @param device *
* @param channelId id * @param device
* @param channelId id
* @param rootElement * @param rootElement
* @param request * @param request
* @param type * @param type
*/ */
private void handleHomePositionCmd(Device device,String channelId,Element rootElement,SIPRequest request,DeviceControlType type){ private void handleHomePositionCmd(Device device, String channelId, Element rootElement, SIPRequest request, DeviceControlType type) {
//获取整个消息主体,我们只需要修改请求头即可
String cmdString = getText(rootElement,type.getVal());
try { try {
cmder.homePositionCmd(device, channelId, cmdString,null,null,null, HomePositionRequest homePosition = loadElement(rootElement, HomePositionRequest.class);
errorResult -> onError(request,errorResult), //获取整个消息主体,我们只需要修改请求头即可
okResult -> onOk(request,okResult)); HomePositionRequest.HomePosition info = homePosition.getHomePosition();
} catch (InvalidArgumentException | SipException | ParseException e) { cmder.homePositionCmd(device, channelId, info.getEnabled(), info.getResetTime(), info.getPresetIndex(),
errorResult -> onError(request, errorResult),
okResult -> onOk(request, okResult));
} catch (Exception e) {
logger.error("[命令发送失败] 看守位设置: {}", e.getMessage()); logger.error("[命令发送失败] 看守位设置: {}", e.getMessage());
} }
} }
/** /**
* * ***
* @param device *
* @param device
* @param rootElement * @param rootElement
* @param request * @param request
*/ */
private void handleAlarmCmd(Device device,Element rootElement,SIPRequest request){ private void handleAlarmCmd(Device device, Element rootElement, SIPRequest request) {
//告警方法 //告警方法
String alarmMethod = ""; String alarmMethod = "";
//告警类型 //告警类型
String alarmType = ""; String alarmType = "";
Element info = rootElement.element("Info"); List<Element> info = rootElement.elements("Info");
if (info !=null){ if (info != null) {
alarmMethod = getText(rootElement,"AlarmMethod"); for (Element element : info) {
alarmType = getText(rootElement,"AlarmType"); alarmMethod = getText(element, "AlarmMethod");
alarmType = getText(element, "AlarmType");
}
} }
try { try {
cmder.alarmCmd(device, alarmMethod,alarmType, cmder.alarmCmd(device, alarmMethod, alarmType,
errorResult -> onError(request,errorResult), errorResult -> onError(request, errorResult),
okResult -> onOk(request,okResult)); okResult -> onOk(request, okResult));
} catch (InvalidArgumentException | SipException | ParseException e) { } catch (InvalidArgumentException | SipException | ParseException e) {
logger.error("[命令发送失败] 告警消息: {}", e.getMessage()); logger.error("[命令发送失败] 告警消息: {}", e.getMessage());
} }
@ -266,19 +283,20 @@ public class DeviceControlQueryMessageHandler extends SIPRequestProcessorParent
/** /**
* *
* @param device *
* @param channelId id * @param device
* @param channelId id
* @param rootElement * @param rootElement
* @param request * @param request
* @param type * @param type
*/ */
private void handleRecordCmd(Device device,String channelId,Element rootElement,SIPRequest request,DeviceControlType type){ private void handleRecordCmd(Device device, String channelId, Element rootElement, SIPRequest request, DeviceControlType type) {
//获取整个消息主体,我们只需要修改请求头即可 //获取整个消息主体,我们只需要修改请求头即可
String cmdString = getText(rootElement,type.getVal()); String cmdString = getText(rootElement, type.getVal());
try { try {
cmder.recordCmd(device, channelId,cmdString, cmder.recordCmd(device, channelId, cmdString,
errorResult -> onError(request,errorResult), errorResult -> onError(request, errorResult),
okResult -> onOk(request,okResult)); okResult -> onOk(request, okResult));
} catch (InvalidArgumentException | SipException | ParseException e) { } catch (InvalidArgumentException | SipException | ParseException e) {
logger.error("[命令发送失败] 录像控制: {}", e.getMessage()); logger.error("[命令发送失败] 录像控制: {}", e.getMessage());
} }
@ -286,18 +304,19 @@ public class DeviceControlQueryMessageHandler extends SIPRequestProcessorParent
/** /**
* / * /
* @param device *
* @param device
* @param rootElement * @param rootElement
* @param request * @param request
* @param type * @param type
*/ */
private void handleGuardCmd(Device device,Element rootElement,SIPRequest request,DeviceControlType type){ private void handleGuardCmd(Device device, Element rootElement, SIPRequest request, DeviceControlType type) {
//获取整个消息主体,我们只需要修改请求头即可 //获取整个消息主体,我们只需要修改请求头即可
String cmdString = getText(rootElement,type.getVal()); String cmdString = getText(rootElement, type.getVal());
try { try {
cmder.guardCmd(device, cmdString, cmder.guardCmd(device, cmdString,
errorResult -> onError(request,errorResult), errorResult -> onError(request, errorResult),
okResult -> onOk(request,okResult)); okResult -> onOk(request, okResult));
} catch (InvalidArgumentException | SipException | ParseException e) { } catch (InvalidArgumentException | SipException | ParseException e) {
logger.error("[命令发送失败] 布防/撤防命令: {}", e.getMessage()); logger.error("[命令发送失败] 布防/撤防命令: {}", e.getMessage());
} }
@ -306,10 +325,11 @@ public class DeviceControlQueryMessageHandler extends SIPRequestProcessorParent
/** /**
* *
* @param request *
* @param request
* @param eventResult * @param eventResult
*/ */
private void onError(SIPRequest request, SipSubscribe.EventResult eventResult){ private void onError(SIPRequest request, SipSubscribe.EventResult eventResult) {
// 失败的回复 // 失败的回复
try { try {
responseAck(request, eventResult.statusCode, eventResult.msg); responseAck(request, eventResult.statusCode, eventResult.msg);
@ -317,12 +337,14 @@ public class DeviceControlQueryMessageHandler extends SIPRequestProcessorParent
logger.error("[命令发送失败] 回复: {}", e.getMessage()); logger.error("[命令发送失败] 回复: {}", e.getMessage());
} }
} }
/** /**
* *
* @param request *
* @param request
* @param eventResult * @param eventResult
*/ */
private void onOk(SIPRequest request, SipSubscribe.EventResult eventResult){ private void onOk(SIPRequest request, SipSubscribe.EventResult eventResult) {
// 成功的回复 // 成功的回复
try { try {
responseAck(request, eventResult.statusCode); responseAck(request, eventResult.statusCode);

View File

@ -0,0 +1,17 @@
package com.genersoft.iot.vmp.gb28181.utils;
import java.lang.annotation.*;
/**
* @author gaofuwang
* @version 1.0
* @date 2022/6/28 14:58
*/
@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface MessageElement {
String value();
String subVal() default "";
}

View File

@ -1,5 +1,6 @@
package com.genersoft.iot.vmp.gb28181.utils; package com.genersoft.iot.vmp.gb28181.utils;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.gb28181.bean.Device;
@ -15,12 +16,16 @@ import org.dom4j.io.SAXReader;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils; import org.springframework.util.ReflectionUtils;
import javax.sip.RequestEvent; import javax.sip.RequestEvent;
import javax.sip.message.Request; import javax.sip.message.Request;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.StringReader; import java.io.StringReader;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.*; import java.util.*;
/** /**
@ -411,4 +416,76 @@ public class XmlUtil {
} }
return deviceChannel; return deviceChannel;
} }
/**
*
*
* @param element xmlElement
* @param clazz
* @param <T>
* @return
* @throws NoSuchMethodException
* @throws InvocationTargetException
* @throws InstantiationException
* @throws IllegalAccessException
*/
public static <T> T loadElement(Element element, Class<T> clazz) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
Field[] fields = clazz.getDeclaredFields();
T t = clazz.getDeclaredConstructor().newInstance();
for (Field field : fields) {
ReflectionUtils.makeAccessible(field);
MessageElement annotation = field.getAnnotation(MessageElement.class);
if (annotation == null) {
continue;
}
String value = annotation.value();
String subVal = annotation.subVal();
Element element1 = element.element(value);
if (element1 == null) {
continue;
}
if ("".equals(subVal)) {
// 无下级数据
Object fieldVal = element1.isTextOnly() ? element1.getText() : loadElement(element1, field.getType());
Object o = simpleTypeDeal(field.getType(), fieldVal);
ReflectionUtils.setField(field, t, o);
} else {
// 存在下级数据
ArrayList<Object> list = new ArrayList<>();
Type genericType = field.getGenericType();
if (!(genericType instanceof ParameterizedType)) {
continue;
}
Class<?> aClass = (Class<?>) ((ParameterizedType) genericType).getActualTypeArguments()[0];
for (Element element2 : element1.elements(subVal)) {
list.add(loadElement(element2, aClass));
}
ReflectionUtils.setField(field, t, list);
}
}
return t;
}
/**
*
*
* @param tClass
* @param val
* @return
*/
private static Object simpleTypeDeal(Class<?> tClass, Object val) {
if (tClass.equals(String.class)) {
return val.toString();
}
if (tClass.equals(Integer.class)) {
return Integer.valueOf(val.toString());
}
if (tClass.equals(Double.class)) {
return Double.valueOf(val.toString());
}
if (tClass.equals(Long.class)) {
return Long.valueOf(val.toString());
}
return val;
}
} }

View File

@ -114,4 +114,7 @@ public interface PlatformChannelMapper {
" left join device d on dc.deviceId = d.deviceId\n" + " left join device d on dc.deviceId = d.deviceId\n" +
"where dc.channelId = #{channelId} and pgc.platformId=#{platformId}") "where dc.channelId = #{channelId} and pgc.platformId=#{platformId}")
List<Device> queryDeviceInfoByPlatformIdAndChannelId(String platformId, String channelId); List<Device> queryDeviceInfoByPlatformIdAndChannelId(String platformId, String channelId);
@Select("SELECT pgc.platformId FROM platform_gb_channel pgc left join device_channel dc on dc.id = pgc.deviceChannelId WHERE dc.channelId='${channelId}'")
List<String> queryParentPlatformByChannelId(String channelId);
} }

View File

@ -133,6 +133,15 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
if (allChannelMap.containsKey(deviceChannel.getChannelId())) { if (allChannelMap.containsKey(deviceChannel.getChannelId())) {
deviceChannel.setStreamId(allChannelMap.get(deviceChannel.getChannelId()).getStreamId()); deviceChannel.setStreamId(allChannelMap.get(deviceChannel.getChannelId()).getStreamId());
deviceChannel.setHasAudio(allChannelMap.get(deviceChannel.getChannelId()).isHasAudio()); deviceChannel.setHasAudio(allChannelMap.get(deviceChannel.getChannelId()).isHasAudio());
if (allChannelMap.get(deviceChannel.getChannelId()).getStatus() !=deviceChannel.getStatus()){
List<String> strings = platformChannelMapper.queryParentPlatformByChannelId(deviceChannel.getChannelId());
if (!CollectionUtils.isEmpty(strings)){
strings.forEach(platformId->{
eventPublisher.catalogEventPublish(platformId, deviceChannel, deviceChannel.getStatus()==1?CatalogEvent.ON:CatalogEvent.OFF);
});
}
}
} }
channels.add(deviceChannel); channels.add(deviceChannel);
if (!ObjectUtils.isEmpty(deviceChannel.getParentId())) { if (!ObjectUtils.isEmpty(deviceChannel.getParentId())) {

View File

@ -268,7 +268,7 @@ public class DeviceControl {
String uuid = UUID.randomUUID().toString(); String uuid = UUID.randomUUID().toString();
Device device = storager.queryVideoDevice(deviceId); Device device = storager.queryVideoDevice(deviceId);
try { try {
cmder.homePositionCmd(device, channelId,null, enabled, resetTime, presetIndex, event -> { cmder.homePositionCmd(device, channelId, enabled, resetTime, presetIndex, event -> {
RequestMessage msg = new RequestMessage(); RequestMessage msg = new RequestMessage();
msg.setId(uuid); msg.setId(uuid);
msg.setKey(key); msg.setKey(key);