Răsfoiți Sursa

温控仪可用状态

李进 1 an în urmă
părinte
comite
eb52e0ecdb

+ 42 - 38
device-api-service/src/main/java/com/xy/service/DeviceStatusServiceImpl.java

@@ -7,6 +7,7 @@ import com.xy.config.DeviceThreadPoolConfig;
 import com.xy.dbmapper.SyncUpdate;
 import com.xy.device.EnumDevcieDoorStatus;
 import com.xy.device.EnumDeviceTempConfig;
+import com.xy.device.EnumDeviceTempStatus;
 import com.xy.dto.ActivityInfoDto;
 import com.xy.dto.DeviceEventMsgDto;
 import com.xy.dto.DeviceStatusDto;
@@ -67,48 +68,51 @@ public class DeviceStatusServiceImpl extends ServiceImpl<DeviceStatusMapper, Dev
         updateById(deviceStatus);
         //温度上报
         if (Emptys.check(deviceStatus.getTempValue())) {
-            //添加设备温度日志
-            DeviceTempRecordsDto.Save save = new DeviceTempRecordsDto.Save()
-                    .setDeviceId(up.getDeviceId());
-            save.setTempValue(deviceStatus.getTempValue());
-            deviceTempRecordsService.save(save);
-            //查询设备配置
-            DeviceConfig deviceConfig = deviceConfigService.getById(deviceStatus.getDeviceId());
-            Integer tempMax = deviceConfig.getTempMax();
-            Integer tempMin = deviceConfig.getTempMin();
-            //温度有异常
-            String key = String.format("device_temp_error:%s:%s", deviceStatus.getDeviceId(), deviceStatus.getTempValue() >= tempMax ? "max" : "min");
-            if (deviceStatus.getTempValue() > tempMax || deviceStatus.getTempValue() < tempMin) {
-                //校验异常次数
-                Integer errorSize = SysDictUtils.getValue(EnumDeviceTempConfig.Code.CODE.getCode(), EnumDeviceTempConfig.ERROR_SIZE.getCode(), Integer.class);
-                boolean fal = false;
-                Integer maxSize = redisService.get(key);
-                if (maxSize == null) {
-                    redisService.set(key, 1, 60 * 60);
-                } else {
-                    if (maxSize >= errorSize) {
-                        fal = true;
-                        redisService.remove(key);
+            int value = SysDictUtils.getValue(EnumDeviceTempStatus.Code.CODE.getCode(), EnumDeviceTempStatus.NO_WKY.getCode(), Integer.class);
+            if(deviceStatusInfo.getTempState() != value) {
+                //添加设备温度日志
+                DeviceTempRecordsDto.Save save = new DeviceTempRecordsDto.Save()
+                        .setDeviceId(up.getDeviceId());
+                save.setTempValue(deviceStatus.getTempValue());
+                deviceTempRecordsService.save(save);
+                //查询设备配置
+                DeviceConfig deviceConfig = deviceConfigService.getById(deviceStatus.getDeviceId());
+                Integer tempMax = deviceConfig.getTempMax();
+                Integer tempMin = deviceConfig.getTempMin();
+                //温度有异常
+                String key = String.format("device_temp_error:%s:%s", deviceStatus.getDeviceId(), deviceStatus.getTempValue() >= tempMax ? "max" : "min");
+                if (deviceStatus.getTempValue() > tempMax || deviceStatus.getTempValue() < tempMin) {
+                    //校验异常次数
+                    Integer errorSize = SysDictUtils.getValue(EnumDeviceTempConfig.Code.CODE.getCode(), EnumDeviceTempConfig.ERROR_SIZE.getCode(), Integer.class);
+                    boolean fal = false;
+                    Integer maxSize = redisService.get(key);
+                    if (maxSize == null) {
+                        redisService.set(key, 1, 60 * 60);
                     } else {
-                        redisService.set(key, maxSize + 1, 60 * 60);
-                    }
-                }
-                //添加事件
-                if (fal) {
-                    DeviceEventMsgDto.Save deviceEventMsg = new DeviceEventMsgDto.Save()
-                            .setDeviceId(deviceStatus.getDeviceId());
-                    deviceEventMsg.setCode(DeviceErrorRecordTypesEnum.T.getCode());
-                    String msg = "温度异常-温度阈值%d,当前温度%d";
-                    if (deviceStatus.getTempValue() >= tempMax) {
-                        deviceEventMsg.setMsg(String.format(msg, tempMax, deviceStatus.getTempValue()));
+                        if (maxSize >= errorSize) {
+                            fal = true;
+                            redisService.remove(key);
+                        } else {
+                            redisService.set(key, maxSize + 1, 60 * 60);
+                        }
                     }
-                    if (deviceStatus.getTempValue() <= tempMin) {
-                        deviceEventMsg.setMsg(String.format(msg, tempMin, deviceStatus.getTempValue()));
+                    //添加事件
+                    if (fal) {
+                        DeviceEventMsgDto.Save deviceEventMsg = new DeviceEventMsgDto.Save()
+                                .setDeviceId(deviceStatus.getDeviceId());
+                        deviceEventMsg.setCode(DeviceErrorRecordTypesEnum.T.getCode());
+                        String msg = "温度异常-温度阈值%d,当前温度%d";
+                        if (deviceStatus.getTempValue() >= tempMax) {
+                            deviceEventMsg.setMsg(String.format(msg, tempMax, deviceStatus.getTempValue()));
+                        }
+                        if (deviceStatus.getTempValue() <= tempMin) {
+                            deviceEventMsg.setMsg(String.format(msg, tempMin, deviceStatus.getTempValue()));
+                        }
+                        deviceEventMsgService.save(deviceEventMsg);
                     }
-                    deviceEventMsgService.save(deviceEventMsg);
+                } else {
+                    redisService.remove(key);
                 }
-            } else {
-                redisService.remove(key);
             }
         }
         //上报关门