Преглед на файлове

修复离线判断的修改时间字段,去掉cbd测试代码

yf_zn преди 1 година
родител
ревизия
41adcc2028

+ 20 - 39
src/main/java/com/yunfeiyun/agmp/iots/device/serviceImp/CqCbdDeviceImpl.java

@@ -119,10 +119,10 @@ public class CqCbdDeviceImpl extends DeviceAbstractImpl implements ICbdDevice {
             }
         }
         String topic = IotMqttConstant.YFCbdTopic.TOPIC_CBD_CMD_PREFIX + cmdModel.getIotDevice().getDevCode();
-        IotDevice iotDevice= iIotDeviceService.selectIotDeviceByDevBid(cmdModel.getIotDevice().getDevBid());
+        IotDevice iotDevice = iIotDeviceService.selectIotDeviceByDevBid(cmdModel.getIotDevice().getDevBid());
         mqttManager.publishMsg(iotDevice.getDevconnBid(), topic, mqttMsgContent);
 
-        log.info("【CBD】发送指令完毕!connectionId:{},topic :{} mqttMsgContent: {}",iotDevice.getDevconnBid(),topic, mqttMsgContent);
+        log.info("【CBD】发送指令完毕!connectionId:{},topic :{} mqttMsgContent: {}", iotDevice.getDevconnBid(), topic, mqttMsgContent);
 
         cmdModel.setClogSendresult(clogSendresult);
         cmdModel.setClogDesc(mqttMsgContent);
@@ -199,20 +199,19 @@ public class CqCbdDeviceImpl extends DeviceAbstractImpl implements ICbdDevice {
     }
 
     /**
-     *
      * @param ext
      * @param devUpdateddate
      * @param topic
      * @param connectionId
      * @throws Exception
      */
-    public void cmdData(JSONObject ext, String devUpdateddate,String topic,String connectionId) throws Exception {
+    public void cmdData(JSONObject ext, String devUpdateddate, String topic, String connectionId) throws Exception {
         log.info("【测报灯】数据解析 {}", ext.toString());
-        String devId=mqttManager.getDevIdByTopic(connectionId,topic);
-        IotDevice iotDeviceFromDb= iIotDeviceService.selectIotDeviceByDevBid(devId);
+        String devId = mqttManager.getDevIdByTopic(connectionId, topic);
+        IotDevice iotDeviceFromDb = iIotDeviceService.selectIotDeviceByDevBid(devId);
         if (iotDeviceFromDb == null) {
             log.info("【测报灯】iotDeviceFromDb 空 {} ", devId);
-            return ;
+            return;
         }
         boolean isCbd = true;
         String vtype = ext.getString("vtype");
@@ -222,7 +221,7 @@ public class CqCbdDeviceImpl extends DeviceAbstractImpl implements ICbdDevice {
         if (StringUtils.isNotEmpty(vtype) && vtype.equals("6")) {
             isCbd = false;
         }
-        if(!isCbd){
+        if (!isCbd) {
             return;
         }
         iotDeviceFromDb.setDevUpdateddate(devUpdateddate);
@@ -278,17 +277,16 @@ public class CqCbdDeviceImpl extends DeviceAbstractImpl implements ICbdDevice {
     }
 
     /**
-     *
      * @param ext
      * @param topic
      * @param connectionId
      */
-    public void cmdOffline(JSONObject ext,String topic,String connectionId) {
+    public void cmdOffline(JSONObject ext, String topic, String connectionId) {
         log.debug("测报灯离线数据 {}", ext.toString());
-        String devId=mqttManager.getDevIdByTopic(connectionId,topic);
-        IotDevice iotDevice= iIotDeviceService.selectIotDeviceByDevBid(devId);
+        String devId = mqttManager.getDevIdByTopic(connectionId, topic);
+        IotDevice iotDevice = iIotDeviceService.selectIotDeviceByDevBid(devId);
         if (iotDevice == null) {
-            return ;
+            return;
         }
         IotDevice newIotDevice = new IotDevice();
         newIotDevice.setDevBid(devId);
@@ -298,7 +296,6 @@ public class CqCbdDeviceImpl extends DeviceAbstractImpl implements ICbdDevice {
     }
 
     /**
-     *
      * @param topic
      * @param dataJson
      * @param connectionId
@@ -306,7 +303,7 @@ public class CqCbdDeviceImpl extends DeviceAbstractImpl implements ICbdDevice {
      * @throws Exception
      */
     @Override
-    public Object receiveData(String topic, JSONObject dataJson,String connectionId) throws Exception {
+    public Object receiveData(String topic, JSONObject dataJson, String connectionId) throws Exception {
         log.info("【测报灯】收到的 设备上报数据 {}", dataJson.toString());
         // 接收设备上报数据后的处理逻辑
         String devUpdateddate = dataJson.getString("devUpdateddate");
@@ -314,7 +311,7 @@ public class CqCbdDeviceImpl extends DeviceAbstractImpl implements ICbdDevice {
             devUpdateddate = DateUtils.dateTimeNow();
         }
         if (dataJson.containsKey("Image")) {
-            Object result = this.receivePicData(dataJson, devUpdateddate, topic,connectionId);
+            Object result = this.receivePicData(dataJson, devUpdateddate, topic, connectionId);
             log.info("测报灯实现类 接收数据:" + result);
         } else {
             String cmd = dataJson.getString("cmd");
@@ -329,26 +326,15 @@ public class CqCbdDeviceImpl extends DeviceAbstractImpl implements ICbdDevice {
             }
 
             if (cmd.equals("data")) {
-                this.cmdData(ext, devUpdateddate,topic,connectionId);
+                this.cmdData(ext, devUpdateddate, topic, connectionId);
             } else if (cmd.equals("offline")) {
-                this.cmdOffline(ext,topic,connectionId);
+                this.cmdOffline(ext, topic, connectionId);
             }
         }
         return true;
     }
 
-    private JSONObject makeTestData(JSONObject jsonObject){
-        jsonObject.put("Image", "https://web.hnyfwlw.com:58003/Basics/cbd/866547058614465/2024/7/13/192.168.1.105_01_20240520134121057_ALARM_INPUT.jpg");
-        jsonObject.put("Result_c", "0,26");
-        jsonObject.put("Image_b", "https://web.hnyfwlw.com:58003/Basics/cbd/866547058614465/2024/7/13/192.168.1.105_01_20240520134121057_ALARM_INPUT.jpg");
-        jsonObject.put("Result_image_b", "https://web.hnyfwlw.com:58003/ResultB/cbd/866547058614465/2024/7/13/192.168.1.105_01_20240520134121057_ALARM_INPUT.jpg");
-        jsonObject.put("Result_b", "160,1#260,1");
-        jsonObject.put("Result_code_b", "[{'160': [2116, 2679, 2220, 2749, 0.92]}, {'260': [2401, 2355, 2446, 2378, 0.79]}]");
-        return jsonObject;
-    }
-
     /**
-     *
      * @param jsonObject
      * @param devUpdateddate
      * @param topic
@@ -356,9 +342,9 @@ public class CqCbdDeviceImpl extends DeviceAbstractImpl implements ICbdDevice {
      * @return
      */
     @Override
-    public Object receivePicData(JSONObject jsonObject, String devUpdateddate ,String topic,String connectionId) {
-        String devId=mqttManager.getDevIdByTopic(connectionId,topic);
-        IotDevice iotDevice= iIotDeviceService.selectIotDeviceByDevBid(devId);
+    public Object receivePicData(JSONObject jsonObject, String devUpdateddate, String topic, String connectionId) {
+        String devId = mqttManager.getDevIdByTopic(connectionId, topic);
+        IotDevice iotDevice = iIotDeviceService.selectIotDeviceByDevBid(devId);
         if (iotDevice == null) {
             return "设备不存在 就不在处理";
         }
@@ -375,9 +361,6 @@ public class CqCbdDeviceImpl extends DeviceAbstractImpl implements ICbdDevice {
         if (!isCbd) {
             return "暂不处理吸虫塔设备";
         }
-        // 测试数据
-//        jsonObject = makeTestData(jsonObject);
-
         String cbdimgAddr = jsonObject.getString("Image");
         if (StringUtils.isEmpty(cbdimgAddr)) {
             return "图片地址不存在,则不处理";
@@ -389,7 +372,6 @@ public class CqCbdDeviceImpl extends DeviceAbstractImpl implements ICbdDevice {
     }
 
     /**
-     *
      * @param jobjMsg
      * @return
      */
@@ -402,15 +384,14 @@ public class CqCbdDeviceImpl extends DeviceAbstractImpl implements ICbdDevice {
     }
 
     /**
-     *
      * @param topic
      * @param jobjMsg
      * @param connectionId
      * @return
      */
     @Override
-    public IotDevice findIotDevice(String topic, JSONObject jobjMsg,String connectionId) {
-        String devId = mqttManager.getDevIdByTopic(connectionId,topic);
+    public IotDevice findIotDevice(String topic, JSONObject jobjMsg, String connectionId) {
+        String devId = mqttManager.getDevIdByTopic(connectionId, topic);
         IotDevice ret = iIotDeviceService.selectIotDeviceByDevBid(devId);
         log.debug("查到了一个iotdevice {}", ret);
         return ret;

+ 9 - 2
src/main/java/com/yunfeiyun/agmp/iots/task/IotStatusService.java

@@ -76,7 +76,8 @@ public class IotStatusService {
     /**
      * 定期根据类型查设备最新设备数据,是否长时间不上报。
      */
-    @Scheduled(cron = "0 0 */1 * * ?")
+    //@Scheduled(cron = "0 0 */1 * * ?")
+    @Scheduled(cron = "0 0/2 0/1 * * ?")
     public void validateStatusByDevType() {
         printMqttStatus();
         Iterator<String> iterator = validateDeviceType.iterator();
@@ -104,7 +105,7 @@ public class IotStatusService {
                 String tid = iotDeviceStatusResVo.getDevtypeBid();
                 if (validateDeviceType.contains(tid)) {
                     // 获取最新上报时间
-                    String updateTime = iotDeviceStatusResVo.getDevModifieddate();
+                    String updateTime = iotDeviceStatusResVo.getDevUpdateddate();
                     String createdTime = iotDeviceStatusResVo.getDevCreateddate();
                     String vTime = StringUtils.isEmpty(updateTime) ? createdTime : updateTime;
                     String devCode = iotDeviceStatusResVo.getDevCode();
@@ -130,6 +131,12 @@ public class IotStatusService {
                         iIotDeviceService.updateIotDevice(iotDevice);
                         log.info("【设备检测】【设备状态异常更新-设备类型{} 】设备标识:{} 设备编号 {} 设备名称 {} 异常状态 {}", type, devBid, devCode, devName, iotDeviceStatusResVo.getDevStatus());
                         reCreateDeviceTopic(iotDevice);
+                    }else{
+                        // 更新状态
+                        IotDevice iotDevice = new IotDevice();
+                        iotDevice.setDevBid(devBid);
+                        iotDevice.setDevStatus("1");
+                        iIotDeviceService.updateIotDevice(iotDevice);
                     }
                 }
             } catch (Exception e) {