Browse Source

soc-modules-job模块,主动获取视频诊断绑定

humingshi-7@163.com 10 tháng trước cách đây
mục cha
commit
2a88f099b8

+ 6 - 0
project_data/sql/1.0.11/quartz/quartz.sql

@@ -18,3 +18,9 @@ INSERT INTO `sys_job`(`job_name`, `job_group`, `invoke_target`, `cron_expression
                       `concurrent`, `status`, `create_by`, `create_time`, `update_by`, `update_time`)
 VALUES ('删除三日前ws重试消息', 'DEFAULT', 'HostTask.deletedRetryMsg()', '0 0 1 * * ?', '1', '1', '0',
         '超级管理员', '2024-11-28 15:26:34', '', NULL);
+
+
+INSERT INTO `sys_job`(`job_name`, `job_group`, `invoke_target`, `cron_expression`, `misfire_policy`, `concurrent`,
+                      `status`, `create_by`, `create_time`, `update_by`, `update_time`)
+VALUES ('视频诊断绑定获取', 'DEFAULT', 'HostTask.getCameraMissionRules()', '0 0 2 * * ?', '1', '1', '1', NULL, now(), NULL,
+        NULL);

+ 7 - 0
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/RemoteHostService.java

@@ -65,6 +65,13 @@ public interface RemoteHostService {
     AjaxResult syncAlarmRuleToHost(@PathVariable("id") Long id);
 
     /**
+     * 获取所有主机的视频诊断绑定
+     * @param
+     * @return
+     */
+    @GetMapping("/getCameraMissionRules")
+    AjaxResult getCameraMissionRules();
+    /**
      * 向主机同步视频诊断
      * @param iotCodes
      * @return

+ 4 - 0
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/factory/RemoteHostFallbackFactory.java

@@ -78,6 +78,10 @@ public class RemoteHostFallbackFactory implements FallbackFactory<RemoteHostServ
             }
 
             @Override
+            public AjaxResult getCameraMissionRules() {
+                return null;
+            }
+            @Override
             public AjaxResult syncDiagnoseToHost(Set<String> iotCodes) {
                 return null;
             }

+ 2 - 0
soc-modules/soc-modules-host/src/main/java/com/xunmei/host/iot/mapper/IotDeviceDiagnoseMissionChMapper.java

@@ -8,6 +8,7 @@ import com.xunmei.host.iot.dto.IotDeviceDiagnoseThresholdReq;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
+import java.util.Set;
 
 /**
  * <p>
@@ -25,4 +26,5 @@ public interface IotDeviceDiagnoseMissionChMapper extends BaseMapper<IotDeviceDi
 
     //修改阈值绑定的设备数量
     Integer updateDiagnoseNumber(@Param("thresholdCode")String thresholdCode);
+    Set<String> selectIotTokensByCamera();
 }

+ 1 - 0
soc-modules/soc-modules-host/src/main/java/com/xunmei/host/iot/service/IotCameraMissionRuleService.java

@@ -4,4 +4,5 @@ import java.util.List;
 
 public interface IotCameraMissionRuleService {
     void syncDiagnoseToHost(List<String> iotCodes);
+    void getCameraMissionRules();
 }

+ 34 - 11
soc-modules/soc-modules-host/src/main/java/com/xunmei/host/iot/service/impl/IotCameraMissionRuleServiceImpl.java

@@ -61,23 +61,32 @@ public class IotCameraMissionRuleServiceImpl implements IotCameraMissionRuleServ
     public String routerKey() {
 
         StringJoiner result = new StringJoiner(",");
-        //诊断绑定数据
+        //诊断绑定数据-主机上报事件
         result.add(WebSocketConstants.CAMERA_MISSION_AND_THRESHOLD_EVENT);
+        //诊断绑定数据-平台调用服务
+        result.add(WebSocketConstants.GET_CAMERA_MISSION_AND_THRESHOLD_SERVICES);
         return result.toString();
     }
 
     @Override
     @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
     public WebsocketResult execute(WebsocketExecuteReq req) {
-        final JSONObject jsb = receiveAndUpdateMissionCamera(req);
+        String event = req.getEvent();
+        String msg;
+        if(event.equals(WebSocketConstants.CAMERA_MISSION_AND_THRESHOLD_EVENT)) {
+            msg = "主机上传诊断绑定";
+        }else{
+            msg = "平台获取诊断绑定Res";
+        }
+        final JSONObject jsb = receiveAndUpdateMissionCamera(msg,req);
         return WebsocketResult.reply(req, jsb);
     }
 
-    private JSONObject receiveAndUpdateMissionCamera(WebsocketExecuteReq req) {
+    private JSONObject receiveAndUpdateMissionCamera(String msg,WebsocketExecuteReq req) {
         try {
             final String iotToken = req.getServerInfo().getIotCode();
             final JSONObject param = JSON.parseObject(req.getData().toString(), JSONObject.class);
-            LogUtils.STATUS_INFO_STATUS_SENSOR.info("主机上传诊断绑定:iotToken={}开始执行",iotToken);
+            LogUtils.STATUS_INFO_STATUS_SENSOR.info("{}:iotToken={}开始执行",msg,iotToken);
 
             Set<String> iotCodes = Sets.newHashSet();
             String deviceProduct,dvs,channel;
@@ -100,7 +109,7 @@ public class IotCameraMissionRuleServiceImpl implements IotCameraMissionRuleServ
                         if(!missionReq.getName().equals(bean.getName())){//规则一样,但名称不一样,治理该主机的诊断阈值(添加下发该主机IotToken同步)
                             missionReq.setName(bean.getName());
                             //todo:
-                            LogUtils.STATUS_INFO_STATUS_SENSOR.info("主机上传诊断绑定:治理的主机iotToken={},missionId={}",iotToken,missionReq.getMissionId());
+                            LogUtils.STATUS_INFO_STATUS_SENSOR.info("{}:治理的主机iotToken={},missionId={}",msg,iotToken,missionReq.getMissionId());
                             iotCodes.add(iotToken);
                         }
                         missionMapper.updateById(missionReq);
@@ -115,7 +124,7 @@ public class IotCameraMissionRuleServiceImpl implements IotCameraMissionRuleServ
                         if(similarBean != null){
                             missionId = similarBean.getMissionId();
                             //todo:
-                            LogUtils.STATUS_INFO_STATUS_SENSOR.info("主机上传诊断绑定:治理的主机iotToken={},missionId={}",iotToken,missionReq.getMissionId());
+                            LogUtils.STATUS_INFO_STATUS_SENSOR.info("{}:治理的主机iotToken={},missionId={}",msg,iotToken,missionReq.getMissionId());
                             iotCodes.add(iotToken);
                         }else{//未匹配到missionId,且名称或规则不一样
                             missionId = IDHelper.id().toString();
@@ -140,7 +149,7 @@ public class IotCameraMissionRuleServiceImpl implements IotCameraMissionRuleServ
                         equWrapper.last(limitOne);
                         IotDeviceInfo camera=iotDeviceInfoMapper.selectOne(equWrapper);
                         if(camera == null){
-                            LogUtils.STATUS_INFO_STATUS_SENSOR.error("主机上传诊断绑定:dvs={},channel={},未找到有效的摄像机基础信息(IotDeviceInfo)",dvs,channel);
+                            LogUtils.STATUS_INFO_STATUS_SENSOR.error("{}:dvs={},channel={},未找到有效的摄像机基础信息(IotDeviceInfo)",msg,dvs,channel);
                             continue;
                         }
                         Long deviceId = camera.getId();
@@ -187,7 +196,7 @@ public class IotCameraMissionRuleServiceImpl implements IotCameraMissionRuleServ
                             thresholdReq.setThresholdName(newThresholdName);
 
                             //todo:
-                            LogUtils.STATUS_INFO_STATUS_SENSOR.info("主机上传诊断绑定:治理的主机iotToken={},thresholdCode={}",iotToken,thresholdReq.getThresholdCode());
+                            LogUtils.STATUS_INFO_STATUS_SENSOR.info("{}:治理的主机iotToken={},thresholdCode={}",msg,iotToken,thresholdReq.getThresholdCode());
                             iotCodes.add(iotToken);
                         }
 
@@ -202,7 +211,7 @@ public class IotCameraMissionRuleServiceImpl implements IotCameraMissionRuleServ
                         if(!thresholdReq.getThresholdName().equals(bean.getThresholdName())){//规则一样,但名称不一样,治理该主机的诊断阈值(添加下发该主机IotToken同步)
                             thresholdReq.setThresholdName(bean.getThresholdName());
                             //todo:
-                            LogUtils.STATUS_INFO_STATUS_SENSOR.info("主机上传诊断绑定:治理的主机iotToken={},thresholdCode={}",iotToken,thresholdReq.getThresholdCode());
+                            LogUtils.STATUS_INFO_STATUS_SENSOR.info("{}:治理的主机iotToken={},thresholdCode={}",msg,iotToken,thresholdReq.getThresholdCode());
                             iotCodes.add(iotToken);
                         }
                         thresholdMapper.updateById(thresholdReq);
@@ -223,7 +232,7 @@ public class IotCameraMissionRuleServiceImpl implements IotCameraMissionRuleServ
                         equWrapper.last(limitOne);
                         IotDeviceInfo camera=iotDeviceInfoMapper.selectOne(equWrapper);
                         if(camera == null){
-                            LogUtils.STATUS_INFO_STATUS_SENSOR.error("主机上传诊断绑定:dvs={},channel={},未找到有效的摄像机基础信息(IotDeviceInfo)",dvs,channel);
+                            LogUtils.STATUS_INFO_STATUS_SENSOR.error("{}:dvs={},channel={},未找到有效的摄像机基础信息(IotDeviceInfo)",msg,dvs,channel);
                             continue;
                         }
                         Long deviceId = camera.getId();
@@ -254,7 +263,7 @@ public class IotCameraMissionRuleServiceImpl implements IotCameraMissionRuleServ
                 this.syncDiagnoseToHost(new ArrayList<>(iotCodes));
             }
         } catch (Exception e) {
-            LogUtils.STATUS_INFO_STATUS_SENSOR.info("主机上传诊断绑定: 处理出现异常{}", e);
+            LogUtils.STATUS_INFO_STATUS_SENSOR.error("{}: 处理出现异常{}",msg, e);
             throw new RuntimeException(e);
         }
         return WebsocketResult.getSuccessPayload();
@@ -318,4 +327,18 @@ public class IotCameraMissionRuleServiceImpl implements IotCameraMissionRuleServ
             }
         }
     }
+
+    @Override
+    public void getCameraMissionRules(){
+        final String topic = TopicTypeEnums.formatUrl(TopicTypeEnums.PRODUCT_SERVICE_INVOKE.getUrl(), WebSocketConstants.DETECTION_HOST, WebSocketConstants.DETECTION_HOST_DEVICE);
+        final WebsocketResult result = WebsocketResult.invokeHostServer(topic, new JSONObject(), WebSocketConstants.GET_CAMERA_MISSION_AND_THRESHOLD_SERVICES, new JSONObject());
+        final Set<String> set = missionChMapper.selectIotTokensByCamera();
+        if (set.isEmpty()) {
+            return;
+        }
+        LogUtils.WEBSOCKET_MSG.info("平台获取诊断绑定Req:目标主机code={}", JSON.toJSONString(set));
+        for (String token : set) {
+            websocketService.sendMsgByTokens(result, token);
+        }
+    }
 }

+ 6 - 0
soc-modules/soc-modules-host/src/main/java/com/xunmei/host/north/controller/HostController.java

@@ -115,6 +115,12 @@ public class HostController {
         return AjaxResult.success();
     }
 
+    @GetMapping("/getCameraMissionRules")
+    AjaxResult getCameraMissionRules() {
+        iotCameraMissionRuleService.getCameraMissionRules();
+        return AjaxResult.success();
+    }
+
     @PostMapping("/syncDiagnose")
     AjaxResult syncDiagnoseToHost(@RequestParam(value = "iotCodes") List<String> iotCodes) {
         iotCameraMissionRuleService.syncDiagnoseToHost(iotCodes);

+ 4 - 0
soc-modules/soc-modules-host/src/main/java/com/xunmei/host/websocket/constant/WebSocketConstants.java

@@ -216,6 +216,10 @@ public interface WebSocketConstants {
     /**
      * 全量诊断任务绑定关系
      */
+    String GET_CAMERA_MISSION_AND_THRESHOLD_SERVICES = "getCameraMissionAndThreshold";
+    /**
+     * 全量诊断任务绑定关系
+     */
     String CAMERA_MISSION_AND_THRESHOLD_EVENT = "cameraMissionAndThreshold";
 
 

+ 4 - 0
soc-modules/soc-modules-host/src/main/resources/mapper/IotDeviceDiagnoseMissionChMapper.xml

@@ -32,4 +32,8 @@
         )
         where threshold_code =  #{thresholdCode}
     </select>
+
+    <select id="selectIotTokensByCamera" resultType="java.lang.String">
+        select distinct iot_token from iot_device_info where device_type in (2,3) and deleted = 0
+    </select>
 </mapper>

+ 7 - 0
soc-modules/soc-modules-job/src/main/java/com/xunmei/job/task/HostTask.java

@@ -27,6 +27,13 @@ public class HostTask {
         log.info("获取所有主机信息结束....,当前任务 id:{},当前时间:{},结果:{}", id, new Date(), JSON.toJSONString(result));
     }
 
+    public void getCameraMissionRules() {
+        String id = UUID.fastUUID().toString();
+        log.info("开始获取所有主机视频诊断绑定,当前任务 id:{},当前时间:{}", id, new Date());
+        AjaxResult result = hostService.getCameraMissionRules();
+        log.info("获取所有主机视频诊断绑定结束....,当前任务 id:{},当前时间:{},结果:{}", id, new Date(), JSON.toJSONString(result));
+    }
+
     public void deletedRetryMsg() {
         String id = UUID.fastUUID().toString();
         final DateTime beginOfDay = DateUtil.beginOfDay(new Date());