Эх сурвалжийг харах

录像完整性接口代码提交

jingyuanchao 1 жил өмнө
parent
commit
1ffb29e45b

+ 6 - 2
project_data/sql/0.1.1/升级文档.txt

@@ -38,7 +38,7 @@ security:
         - /ws1/**
 
 3.nginx配置文件修改
-    3.1在监听8080de server块下增加配置:
+    3.1在监听8080 server块下增加配置:
         location /ws {
                  proxy_pass http://api;
                  proxy_http_version 1.1;
@@ -46,5 +46,9 @@ security:
                  proxy_set_header Connection "upgrade";
                  proxy_set_header Host $host;
         }
-    3.2 重新加载配置文件:
+    3.2在监听8080的 server块下 location @api { 这一行下一行追加两行代码:
+        proxy_set_header X-Local-Ip $host;
+        proxy_set_header X-Local-Port $server_port;
+
+    3.3 重新加载配置文件:
         在nginx的安装目录下的sbin目录执行命令: ./nginx -s reload

+ 3 - 1
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/dto/protection/ReceiveErrorDto.java

@@ -1,5 +1,6 @@
 package com.xunmei.system.api.dto.protection;
 
+import io.netty.util.internal.StringUtil;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.AllArgsConstructor;
@@ -21,11 +22,12 @@ public class ReceiveErrorDto {
     private Boolean success = true;
 
     @ApiModelProperty("提示信息")
-    private String errorMsg;
+    private String errorMsg = StringUtil.EMPTY_STRING;
 
     public static ReceiveErrorDto success() {
         return new ReceiveErrorDto();
     }
+
     public static ReceiveErrorDto success(String msg) {
         final ReceiveErrorDto dto = new ReceiveErrorDto();
         dto.setErrorMsg(msg);

+ 7 - 4
soc-common/soc-common-core/src/main/java/com/xunmei/common/core/constant/Constants.java

@@ -122,17 +122,20 @@ public class Constants {
     /**
      * 定时任务白名单配置(仅允许访问的包名,如其他需要可以自行添加)
      */
-    public static final List<String> JOB_WHITELIST_STR = new ArrayList(){{add("com.xunmei");}};
+    public static final List<String> JOB_WHITELIST_STR = new ArrayList() {{
+        add("com.xunmei");
+    }};
 
     /**
      * 定时任务违规的字符
      */
-    public static final List<String> JOB_ERROR_STR = new ArrayList(){{
+    public static final List<String> JOB_ERROR_STR = new ArrayList() {{
         add("java.net.URL");
         add("javax.naming.InitialContext");
         add("org.yaml.snakeyaml");
         add("org.springframework");
-        add("org.apache");add("com.xunmei.common.core.utils.file");
+        add("org.apache");
+        add("com.xunmei.common.core.utils.file");
     }};
 
     public static final Long TOP_ORG_PARENT_ID = -1L;
@@ -158,7 +161,7 @@ public class Constants {
     public static final String DAILY_FORMAT_ZH = "yyyy年MM月dd日";
 
     public static final String HMS_FORMAT = "yyyy-MM-dd HH:mm:ss";
-    public static final String UTC_FORMAT = "yyyy-MM-dd'T'HH:mm:ss";
+    public static final String UTC_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS+08:00";
 
     public static final String HM_FORMAT = "yyyyMMddHHmmss";
 

+ 1 - 0
soc-modules/soc-modules-iot/src/main/resources/mapper/IotServerInfoMapper.xml

@@ -22,5 +22,6 @@
                 </otherwise>
             </choose>
         </where>
+        order by i.last_connect_time desc
     </select>
 </mapper>

+ 9 - 7
soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/api/video/service/impl/VideoIntegrityCheckServiceImpl.java

@@ -13,6 +13,7 @@ import com.xunmei.common.core.constant.SecurityConstants;
 import com.xunmei.common.core.domain.video.MediatorVideoDaysCheck;
 import com.xunmei.common.core.domain.video.MediatorVideoIntegrityCheck;
 import com.xunmei.common.core.domain.video.MediatorVideoIntegrityCheckLog;
+import com.xunmei.common.core.enums.iot.DeviceTypeEnum;
 import com.xunmei.common.core.enums.iot.VideoIntegrityStatus;
 import com.xunmei.common.core.utils.JacksonUtils;
 import com.xunmei.mediator.api.north.service.NorthErrorService;
@@ -27,7 +28,6 @@ import com.xunmei.mediator.iot.service.IIotDeviceInfoService;
 import com.xunmei.mediator.websocket.constant.WebSocketConstants;
 import com.xunmei.mediator.websocket.dto.WebsocketExecuteReq;
 import com.xunmei.mediator.websocket.dto.WebsocketResult;
-import com.xunmei.common.core.enums.iot.DeviceTypeEnum;
 import com.xunmei.mediator.websocket.enums.ProductEnums;
 import com.xunmei.mediator.websocket.enums.TopicTypeEnums;
 import com.xunmei.mediator.websocket.holder.WebSocketSessionHolder;
@@ -100,22 +100,24 @@ public class VideoIntegrityCheckServiceImpl extends ServiceImpl<VideoIntegrityCh
         checkDto.setProductName(req.getProductName());
         SysOrg sysOrg = iotServerInfoService.selectOrgByToken(req.getToken());
         checkDto.setOrganizationGuid(sysOrg.getCode());
+        //执行业务
         final ReceiveErrorDto dto = this.saveData(checkDto, req.getId());
-        String topic=req.getTopic()+"/reply";
-        return WebsocketResult.of(dto, topic, req.getId());
+        String topic = req.getTopic() + "/reply";
+        final JSONObject errorDto = IotServerUtils.dealReceiveErrorDto(dto);
+        return IotServerUtils.invokeUpLinkServer(topic, req.getProductName(), req.getDeviceName(), req.getEvent(), errorDto, req.getId());
     }
 
     @Override
     public void invokeRecordInfosForSchedule() {
         List<IotDeviceInfo> deviceInfoList = iotDeviceInfoService.selectAllDeviceByDeviceType(Arrays.asList(DeviceTypeEnum.MONITOR_CAMERA, DeviceTypeEnum.NUMBER_CAMERA));
-        if (ObjectUtil.isEmpty(deviceInfoList)){
+        if (ObjectUtil.isEmpty(deviceInfoList)) {
             return;
         }
         for (IotDeviceInfo iotDeviceInfo : deviceInfoList) {
             JSONObject object = new JSONObject();
             object.put("dvsCode", iotDeviceInfo.getHostCode());
             object.put("index", iotDeviceInfo.getDeviceCode());
-            object.put("recordDate", Arrays.asList(DateUtil.format(DateUtil.offsetDay(new Date(),-1), Constants.DAILY_FORMAT)));
+            object.put("recordDate", Arrays.asList(DateUtil.format(DateUtil.offsetDay(new Date(), -1), Constants.DAILY_FORMAT)));
             WebsocketResult websocketResult = IotServerUtils.invokeDownLinkServer(TopicTypeEnums.PRODUCT_SERVICE_INVOKE, iotDeviceInfo.getDeviceProduct(), iotDeviceInfo.getDeviceCode(), WebSocketConstants.GET_RECORD_INFOS_SERVICES, object);
             LogUtils.WEBSOCKET_MSG.info("获取录像完整性数据:{}", JacksonUtils.toJSONString(websocketResult));
             WebSocketSessionHolder.sendAll(JacksonUtils.toJSONString(websocketResult));
@@ -154,7 +156,7 @@ public class VideoIntegrityCheckServiceImpl extends ServiceImpl<VideoIntegrityCh
             northErrorService.saveError(new NorthError(msgId, "/video/complete", videoIntegrityCheckDto, "参数非法:organizationGuid:" + organizationGuid + "不正确"));
             return ReceiveErrorDto.error("参数非法:organizationGuid:" + organizationGuid + "不正确");
         }
-        IotDeviceInfo channel = iotDeviceInfoService.selectByTypeAndHostAndCode(videoIntegrityCheckDto.getToken(), videoIntegrityCheckDto.getEquipmentCode(),videoIntegrityCheckDto.getProductName(), videoIntegrityCheckDto.getChannelCode());
+        IotDeviceInfo channel = iotDeviceInfoService.selectByTypeAndHostAndCode(videoIntegrityCheckDto.getToken(), videoIntegrityCheckDto.getEquipmentCode(), videoIntegrityCheckDto.getProductName(), videoIntegrityCheckDto.getChannelCode());
         //final IotDvrChannel channel = dvrChannelService.findChannel(videoIntegrityCheckDto.getChannelCode(), videoIntegrityCheckDto.getEquipmentCode(), org.getId());
         if (ObjectUtil.isNull(channel)) {
             northErrorService.saveError(new NorthError(msgId, "/video/complete", videoIntegrityCheckDto, "通道/设备不存在"));
@@ -175,7 +177,7 @@ public class VideoIntegrityCheckServiceImpl extends ServiceImpl<VideoIntegrityCh
         }
 
         //获取监控主机
-        IotDeviceInfo hostDevice = iotDeviceInfoService.selectByTypeAndCode(videoIntegrityCheckDto.getToken(), DeviceTypeEnum.DVS.getCode(),videoIntegrityCheckDto.getProductName(), videoIntegrityCheckDto.getDeviceName());
+        IotDeviceInfo hostDevice = iotDeviceInfoService.selectByTypeAndCode(videoIntegrityCheckDto.getToken(), DeviceTypeEnum.DVS.getCode(), videoIntegrityCheckDto.getProductName(), videoIntegrityCheckDto.getDeviceName());
 
         if (hostDevice == null) {
             northErrorService.saveError(new NorthError(msgId, "/video/complete", videoIntegrityCheckDto, "监控主机不存在"));

+ 2 - 0
soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/websocket/constant/WebSocketConstants.java

@@ -176,4 +176,6 @@ public interface WebSocketConstants {
     String PRODUCT_NAME="productName";
 
     String DEVICE_NAME="deviceName";
+
+    String REPLY_ID="replyId";
 }

+ 6 - 9
soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/websocket/enums/TopicTypeEnums.java

@@ -20,11 +20,11 @@ public enum TopicTypeEnums {
     //设备状态通知
     DEVICE_STATUS("^/device/status/([^/]+)/([^/]+)$", StringUtil.EMPTY_STRING, StringUtil.EMPTY_STRING, "/device/status/%s/%s"),
     //产品事件通知消息
-    PRODUCT_EVENT_NOTICE("^/things/([^/]+)/([^/]+)/event/post$", StringUtil.EMPTY_STRING, StringUtil.EMPTY_STRING,"/things/%s/%s/event/post"),
+    PRODUCT_EVENT_NOTICE("^/things/([^/]+)/([^/]+)/event/post$", StringUtil.EMPTY_STRING, StringUtil.EMPTY_STRING, "/things/%s/%s/event/post"),
     //产品事件通知返回发给IOT消息
-    PRODUCT_EVENT_NOTICE_REPLY("^/things/([^/]+)/([^/]+)/event/post/reply$", StringUtil.EMPTY_STRING, StringUtil.EMPTY_STRING,"/things/%s/%s/event/post/reply"),
+    PRODUCT_EVENT_NOTICE_REPLY("^/things/([^/]+)/([^/]+)/event/post/reply$", StringUtil.EMPTY_STRING, StringUtil.EMPTY_STRING, "/things/%s/%s/event/post/reply"),
     //应用方调用IoT产品服务消息
-    PRODUCT_SERVICE_INVOKE("^/things/([^/]+)/([^/]+)/service/invoke$", StringUtil.EMPTY_STRING, StringUtil.EMPTY_STRING,"/things/%s/%s/service/invoke"),
+    PRODUCT_SERVICE_INVOKE("^/things/([^/]+)/([^/]+)/service/invoke$", StringUtil.EMPTY_STRING, StringUtil.EMPTY_STRING, "/things/%s/%s/service/invoke"),
     //IoT返回服务调用消息
     PRODUCT_SERVICE_REPLY("^/things/([^/]+)/([^/]+)/service/invoke/reply$", StringUtil.EMPTY_STRING, StringUtil.EMPTY_STRING, "/things/%s/%s/service/invoke/reply"),
     //应用方读取属性
@@ -50,16 +50,13 @@ public enum TopicTypeEnums {
     private String url;
 
 
-
-
     public static TopicTypeEnums matcherTopicTypeEnums(String topic) {
         TopicTypeEnums[] typeEnums = TopicTypeEnums.values();
         for (TopicTypeEnums regex : typeEnums) {
             Pattern pattern = Pattern.compile(regex.getTopic());
-            if (TopicTypeEnums.SYS_NOTICE.equals(regex)){
+            if (TopicTypeEnums.SYS_NOTICE.getTopic().equals(topic)) {
                 return TopicTypeEnums.SYS_NOTICE;
             }
-
             // 创建Matcher对象
             Matcher matcher = pattern.matcher(topic);
             // 检查是否匹配成功
@@ -75,8 +72,8 @@ public enum TopicTypeEnums {
         return null;
     }
 
-    public static String formatUrl(TopicTypeEnums enumEnums,String productName, String deviceName) {
-        return  String.format(enumEnums.getUrl(), productName, deviceName);
+    public static String formatUrl(String topicUrl, String productName, String deviceName) {
+        return String.format(topicUrl, productName, deviceName);
 
     }
 

+ 5 - 6
soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/websocket/service/impl/WebsocketServiceImpl.java

@@ -2,6 +2,7 @@ package com.xunmei.mediator.websocket.service.impl;
 
 import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.xunmei.common.core.domain.iot.domain.IotAlarmDefenceArea;
@@ -54,7 +55,6 @@ import org.springframework.transaction.annotation.Transactional;
 import java.time.LocalDateTime;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
 
 @Service
 public class WebsocketServiceImpl implements WebsocketService, RouterService {
@@ -87,7 +87,7 @@ public class WebsocketServiceImpl implements WebsocketService, RouterService {
 
     @Override
     public void invokeBaseDeviceInfoForSchedule() {
-        List<String> categories = Arrays.asList(WebSocketConstants.DVS, WebSocketConstants.ALARM_HOST, WebSocketConstants.FSU_GATEWAY);
+        List<String> categories = Arrays.asList(WebSocketConstants.DVS, WebSocketConstants.ALARM_HOST);
         JSONObject args = new JSONObject();
         args.put("categories", categories);
         WebsocketResult websocketResult = IotServerUtils.invokeIotServer(iotServerDeviceTopic, WebSocketConstants.GET_DEVICE_BASE_INFOS, args);
@@ -958,10 +958,9 @@ public class WebsocketServiceImpl implements WebsocketService, RouterService {
     public Object execute(WebsocketExecuteReq req) {
         try {
             if (WebSocketConstants.GET_DEVICE_BASE_INFOS.equals(req.getEvent())) {
-                JSONObject object = (JSONObject) req.getData();
-                if (object != null) {
-                    List<JSONObject> deviceBaseInfos = (List<JSONObject>) object.get("deviceBaseInfos");
-                    final List<DeviceBaseInfo> list = deviceBaseInfos.stream().map(r -> JSON.toJavaObject(r, DeviceBaseInfo.class)).collect(Collectors.toList());
+                JSONArray object = (JSONArray) req.getData();
+                if (ObjectUtil.isNotEmpty(object)) {
+                    final List<DeviceBaseInfo> list = object.toJavaList(DeviceBaseInfo.class);
                     dealBaseDeviceInfo(list, req.getToken());
                 }
             } else if (WebSocketConstants.GET_ALARM_HOST_DEVICE_INFOS.equals(req.getEvent())) {

+ 54 - 5
soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/websocket/utils/IotServerUtils.java

@@ -3,11 +3,12 @@ package com.xunmei.mediator.websocket.utils;
 import cn.hutool.core.date.DateUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.xunmei.common.core.constant.Constants;
-import com.xunmei.common.core.utils.JacksonUtils;
+import com.xunmei.common.core.constant.HttpStatus;
 import com.xunmei.mediator.websocket.constant.WebSocketConstants;
 import com.xunmei.mediator.websocket.dto.WebsocketResult;
 import com.xunmei.mediator.websocket.enums.TopicTypeEnums;
-import com.xunmei.mediator.websocket.holder.WebSocketSessionHolder;
+import com.xunmei.system.api.dto.protection.ReceiveErrorDto;
+import io.netty.util.internal.StringUtil;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -20,7 +21,7 @@ import java.util.UUID;
 @NoArgsConstructor(access = AccessLevel.PRIVATE)
 public class IotServerUtils {
 
-    public static WebsocketResult invokeIotServer(String topic, String service, Object args){
+    public static WebsocketResult invokeIotServer(String topic, String service, Object args) {
         WebsocketResult websocketResult = new WebsocketResult();
         websocketResult.setId(UUID.randomUUID().toString());
         websocketResult.setTimestamp(DateUtil.format(new Date(), Constants.UTC_FORMAT));
@@ -38,7 +39,7 @@ public class IotServerUtils {
         String id = UUID.randomUUID().toString();
         WebsocketResult iotWebsocketResult = new WebsocketResult();
         //Iot消息透穿至主机 固定Topic
-        iotWebsocketResult.setTopic(TopicTypeEnums.formatUrl(TopicTypeEnums.PRODUCT_SERVICE_INVOKE, WebSocketConstants.IOT_SERVER,WebSocketConstants.IOT_SERVER_DEVICE));
+        iotWebsocketResult.setTopic(TopicTypeEnums.formatUrl(TopicTypeEnums.PRODUCT_SERVICE_INVOKE.getUrl(), WebSocketConstants.IOT_SERVER,WebSocketConstants.IOT_SERVER_DEVICE));
         iotWebsocketResult.setId(id);
         iotWebsocketResult.setTimestamp(DateUtil.format(new Date(), Constants.UTC_FORMAT));
         //iot消息头
@@ -55,7 +56,7 @@ public class IotServerUtils {
         iotPayloadObj.put(WebSocketConstants.ARGS,hostData );
         hostData.setId(id);
         hostData.setTimestamp(DateUtil.format(new Date(), Constants.UTC_FORMAT));
-        hostData.setTopic(TopicTypeEnums.formatUrl(topicTypeEnums, produceName,deviceName));
+        hostData.setTopic(TopicTypeEnums.formatUrl(topicTypeEnums.getUrl(), produceName,deviceName));
         JSONObject hostHeaderObj = new JSONObject();
         hostHeaderObj.put(WebSocketConstants.PRODUCT_NAME,produceName);
         hostHeaderObj.put(WebSocketConstants.DEVICE_NAME, deviceName);
@@ -68,4 +69,52 @@ public class IotServerUtils {
         hostData.setPayload(hostPayloadObj);
         return iotWebsocketResult;
     }
+
+    public static WebsocketResult invokeUpLinkServer(String topic,String produceName,String deviceName,String invokeMethod,JSONObject object,String replyId){
+        WebsocketResult iotWebsocketResult = new WebsocketResult();
+        //Iot消息透穿至主机 固定Topic
+        iotWebsocketResult.setTopic(TopicTypeEnums.formatUrl(TopicTypeEnums.PRODUCT_SERVICE_INVOKE.getUrl(), WebSocketConstants.IOT_SERVER,WebSocketConstants.IOT_SERVER_DEVICE));
+        iotWebsocketResult.setId(replyId);
+        iotWebsocketResult.setTimestamp(DateUtil.format(new Date(), Constants.UTC_FORMAT));
+        //iot消息头
+        JSONObject iotHeaderObj = new JSONObject();
+        iotHeaderObj.put(WebSocketConstants.PRODUCT_NAME,WebSocketConstants.IOT_SERVER);
+        iotHeaderObj.put(WebSocketConstants.DEVICE_NAME, WebSocketConstants.IOT_SERVER_DEVICE);
+        iotHeaderObj.put(WebSocketConstants.REPLY_ID, replyId);
+        iotWebsocketResult.setHeaders(iotHeaderObj);
+        //iot消息体,完整的消息包含在payload中
+        JSONObject iotPayloadObj = new JSONObject();
+        iotWebsocketResult.setPayload(iotPayloadObj);
+        iotPayloadObj.put(WebSocketConstants.SERVICE, WebSocketConstants.UP_LINK_SERVICE_PASS_THROUGH);
+        //以下是主机消息内容
+        WebsocketResult hostData = new WebsocketResult();
+        iotPayloadObj.put(WebSocketConstants.ARGS,hostData );
+        hostData.setId(replyId);
+        hostData.setTimestamp(DateUtil.format(new Date(), Constants.UTC_FORMAT));
+        hostData.setTopic(topic);
+        JSONObject hostHeaderObj = new JSONObject();
+        hostHeaderObj.put(WebSocketConstants.PRODUCT_NAME,produceName);
+        hostHeaderObj.put(WebSocketConstants.DEVICE_NAME, deviceName);
+        hostHeaderObj.put(WebSocketConstants.REPLY_ID, replyId);
+        hostData.setHeaders(hostHeaderObj);
+
+        JSONObject hostPayloadObj = new JSONObject();
+        hostPayloadObj.put(WebSocketConstants.EVENT, invokeMethod);
+        hostPayloadObj.put(WebSocketConstants.ARGS, object);
+
+        hostData.setPayload(hostPayloadObj);
+        return iotWebsocketResult;
+    }
+
+    public static JSONObject dealReceiveErrorDto(ReceiveErrorDto dto) {
+        final JSONObject object = new JSONObject();
+        if (dto.getSuccess()){
+            object.put(WebSocketConstants.STATUS_CODE, HttpStatus.SUCCESS);
+            object.put(WebSocketConstants.STATUS_DESCRIPTION, dto.getErrorMsg());
+        }else {
+            object.put(WebSocketConstants.STATUS_CODE, HttpStatus.ERROR);
+            object.put(WebSocketConstants.STATUS_DESCRIPTION, dto.getErrorMsg());
+        }
+        return object;
+    }
 }