yf_zn 8 ay önce
ebeveyn
işleme
611e8002c7
19 değiştirilmiş dosya ile 140 ekleme ve 78 silme
  1. 3 1
      src/main/java/com/yunfeiyun/agmp/iots/device/controller/TestController.java
  2. 1 0
      src/main/java/com/yunfeiyun/agmp/iots/device/serviceImp/BzyDeviceImpl.java
  3. 1 0
      src/main/java/com/yunfeiyun/agmp/iots/device/serviceImp/CqCbdDeviceImpl.java
  4. 1 0
      src/main/java/com/yunfeiyun/agmp/iots/device/serviceImp/IYfXctDeviceImpl.java
  5. 1 0
      src/main/java/com/yunfeiyun/agmp/iots/device/serviceImp/XphYfQxzDeviceImpl.java
  6. 1 0
      src/main/java/com/yunfeiyun/agmp/iots/device/serviceImp/YfQxzDeviceImpl.java
  7. 22 20
      src/main/java/com/yunfeiyun/agmp/iots/device/serviceImp/YfScdDeviceImpl.java
  8. 18 16
      src/main/java/com/yunfeiyun/agmp/iots/device/serviceImp/YfXycbIIIDeviceImpl.java
  9. 1 0
      src/main/java/com/yunfeiyun/agmp/iots/task/IotStatusService.java
  10. 2 1
      src/main/java/com/yunfeiyun/agmp/iots/task/YbqScheduler.java
  11. 1 0
      src/main/java/com/yunfeiyun/agmp/iots/warn/model/IotWarnconfigDevVo.java
  12. 1 0
      src/main/java/com/yunfeiyun/agmp/iots/warn/model/WarnStatusDto.java
  13. 10 6
      src/main/java/com/yunfeiyun/agmp/iots/warn/service/MsgService.java
  14. 7 4
      src/main/java/com/yunfeiyun/agmp/iots/warn/service/WarnDiseaseService.java
  15. 24 15
      src/main/java/com/yunfeiyun/agmp/iots/warn/service/WarnPestService.java
  16. 6 5
      src/main/java/com/yunfeiyun/agmp/iots/warn/service/WarnService.java
  17. 30 0
      src/main/java/com/yunfeiyun/agmp/iots/warn/util/NumberUtil.java
  18. 8 8
      src/main/java/com/yunfeiyun/agmp/iots/warn/util/WarnMessageBuilderUtil.java
  19. 2 2
      src/main/resources/mapper/IotWarnBusinessMapper.xml

+ 3 - 1
src/main/java/com/yunfeiyun/agmp/iots/device/controller/TestController.java

@@ -29,6 +29,7 @@ import com.yunfeiyun.agmp.iots.service.IotYbqPredictDataService;
 import com.yunfeiyun.agmp.iots.service.impl.IotCbdImgService;
 import com.yunfeiyun.agmp.iots.warn.service.WarnPestService;
 import com.yunfeiyun.agmp.iots.warn.service.WarnService;
+import com.yunfeiyun.agmp.iots.warn.util.NumberUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.mongodb.core.MongoTemplate;
@@ -730,6 +731,7 @@ public class TestController {
             newIotDevice.setDevCreateddate(iotDevice.getDevCreateddate());
             newIotDevice.setDevUpdateddate(iotDevice.getDevUpdateddate());
             newIotDevice.setDevCode(iotDevice.getDevCode());
+            newIotDevice.setDevName(iotDevice.getDevName());
             iIotDeviceService.updateIotDevice(newIotDevice);
             //发送离线预警
             SpringUtils.getBean(WarnService.class).processWarningOfflineData(newIotDevice, JSONObject.from(iotDevice));
@@ -784,7 +786,7 @@ public class TestController {
                 // 得到第三方返回的设备的预测数据
                 String computeDate = jobj.getString("computeDate");
                 String deviceId = jobj.getString("deviceId");
-                String value = jobj.getString("value");
+                String value = NumberUtil.keepTwoDecimalPlaces(jobj.getString("value"))  ;
                 //保存预测记录、更新预测最新数据
                 // 查查当天的有没有,有的话更新,没有的话添加
                 IotYbqPredictData iotYbqPredictDataToday = iotYbqPredictDataService.getTodayData(devBid);

+ 1 - 0
src/main/java/com/yunfeiyun/agmp/iots/device/serviceImp/BzyDeviceImpl.java

@@ -249,6 +249,7 @@ public class BzyDeviceImpl extends DeviceAbstractImpl implements IBzyDevice {
         newIotDevice.setDevUpdateddate(oldIotDevice.getDevUpdateddate());
         newIotDevice.setDevCode(oldIotDevice.getDevCode());
         newIotDevice.setDevOriginalStatus(oldIotDevice.getDevOriginalStatus());
+        newIotDevice.setDevName(oldIotDevice.getDevName());
         iIotDeviceService.updateIotDevice(newIotDevice);
 
         //发送离线预警

+ 1 - 0
src/main/java/com/yunfeiyun/agmp/iots/device/serviceImp/CqCbdDeviceImpl.java

@@ -302,6 +302,7 @@ public class CqCbdDeviceImpl extends DeviceAbstractImpl implements ICbdDevice {
         newIotDevice.setDevCreateddate(iotDevice.getDevCreateddate());
         newIotDevice.setDevUpdateddate(iotDevice.getDevUpdateddate());
         newIotDevice.setDevCode(iotDevice.getDevCode());
+        newIotDevice.setDevName(iotDevice.getDevName());
         iIotDeviceService.updateIotDevice(newIotDevice);
 
 

+ 1 - 0
src/main/java/com/yunfeiyun/agmp/iots/device/serviceImp/IYfXctDeviceImpl.java

@@ -247,6 +247,7 @@ public class IYfXctDeviceImpl extends DeviceAbstractImpl implements IYfXctDevice
         newIotDevice.setDevUpdateddate(iotDevice.getDevUpdateddate());
         newIotDevice.setDevCode(iotDevice.getDevCode());
         newIotDevice.setDevOriginalStatus(iotDevice.getDevOriginalStatus());
+        newIotDevice.setDevName(iotDevice.getDevName());
         iIotDeviceService.updateIotDevice(newIotDevice);
 
 

+ 1 - 0
src/main/java/com/yunfeiyun/agmp/iots/device/serviceImp/XphYfQxzDeviceImpl.java

@@ -313,6 +313,7 @@ public class XphYfQxzDeviceImpl extends DeviceAbstractImpl implements IXphYfQxzD
         newIotDevice.setDevUpdateddate(iotDeviceOld.getDevUpdateddate());
         newIotDevice.setDevCode(iotDeviceOld.getDevCode());
         newIotDevice.setDevOriginalStatus(iotDeviceOld.getDevOriginalStatus());
+        newIotDevice.setDevName(iotDeviceOld.getDevName());
         iIotDeviceService.updateIotDevice(newIotDevice);
 
 

+ 1 - 0
src/main/java/com/yunfeiyun/agmp/iots/device/serviceImp/YfQxzDeviceImpl.java

@@ -463,6 +463,7 @@ public class YfQxzDeviceImpl extends DeviceAbstractImpl implements IYfQxzDevice
         newIotDevice.setDevCreateddate(iotDeviceOld.getDevCreateddate());
         newIotDevice.setDevUpdateddate(iotDeviceOld.getDevUpdateddate());
         newIotDevice.setDevCode(iotDeviceOld.getDevCode());
+        newIotDevice.setDevName(iotDeviceOld.getDevName());
         iIotDeviceService.updateIotDevice(newIotDevice);
 
 

+ 22 - 20
src/main/java/com/yunfeiyun/agmp/iots/device/serviceImp/YfScdDeviceImpl.java

@@ -27,7 +27,9 @@ import org.springframework.stereotype.Component;
 
 import java.util.*;
 
-/** 云飞杀虫灯 */
+/**
+ * 云飞杀虫灯
+ */
 @Component(ServiceNameConst.SERVICE_YF_SCD)
 @Slf4j
 public class YfScdDeviceImpl extends DeviceAbstractImpl implements IYfScdDevice {
@@ -58,16 +60,16 @@ public class YfScdDeviceImpl extends DeviceAbstractImpl implements IYfScdDevice
         List<String> topicList = new ArrayList<>();
         topicList.add(IotMqttConstant.YFScdTopic.TOPIC_SCD_CMD_PREFIX + devCode);
         topicList.add(IotMqttConstant.YFScdTopic.TOPIC_SCD_2_CMD_PREFIX + devCode);
-        if(Objects.equals(iotDevice.getDevtypeBid(), IotDeviceDictConst.TYPE_YF_FXSSCD)){
+        if (Objects.equals(iotDevice.getDevtypeBid(), IotDeviceDictConst.TYPE_YF_FXSSCD)) {
             //新款风吸式杀虫灯
             topicList.add(IotMqttConstant.YFScdTopic.TOPIC_FXSSCD_CMD_PREFIX + devCode);
         }
-        for(String topic:topicList){
-            try{
+        for (String topic : topicList) {
+            try {
                 mqttManager.publishMsg(iotDevice.getDevconnBid(), topic, mqttMsgContent);
-                log.info("【YFSCD】发送指令完毕!connectionId:{},topic :{} mqttMsgContent: {}",iotDevice.getDevconnBid(),topic, mqttMsgContent);
-            }catch (Exception e){
-                log.error("【YFSCD】发送指令失败!connectionId:{},topic :{} mqttMsgContent: {}",iotDevice.getDevconnBid(),topic, mqttMsgContent);
+                log.info("【YFSCD】发送指令完毕!connectionId:{},topic :{} mqttMsgContent: {}", iotDevice.getDevconnBid(), topic, mqttMsgContent);
+            } catch (Exception e) {
+                log.error("【YFSCD】发送指令失败!connectionId:{},topic :{} mqttMsgContent: {}", iotDevice.getDevconnBid(), topic, mqttMsgContent);
             }
         }
     }
@@ -90,7 +92,7 @@ public class YfScdDeviceImpl extends DeviceAbstractImpl implements IYfScdDevice
         String mqttMsgContent = "";
         String clogSendresult = "发送指令成功";
         switch (methodName) {
-            case CmdDef.YfScdCmdDef.CMD_CONFIG:{
+            case CmdDef.YfScdCmdDef.CMD_CONFIG: {
                 JSONObject jobjParam = cmdDistribution.getJsons();
                 Map<String, String> keyMap = new HashMap<>();
                 keyMap.put("ds", "ds");
@@ -101,7 +103,7 @@ public class YfScdDeviceImpl extends DeviceAbstractImpl implements IYfScdDevice
                 keyMap.put("et", "et");
 
                 JSONObject configObj = new JSONObject();
-                for(Map.Entry<String, String> entry : keyMap.entrySet()) {
+                for (Map.Entry<String, String> entry : keyMap.entrySet()) {
                     String key = entry.getKey();
                     String keyName = entry.getValue();
 
@@ -119,13 +121,13 @@ public class YfScdDeviceImpl extends DeviceAbstractImpl implements IYfScdDevice
                 log.info("【杀虫灯】发送指令【config】 mqttMsgContent={}", mqttMsgContent);
                 break;
             }
-            case CmdDef.YfScdCmdDef.CMD_REFRESH:{
+            case CmdDef.YfScdCmdDef.CMD_REFRESH: {
                 JSONObject jobjParam = cmdDistribution.getJsons();
                 mqttMsgContent = JSONUtils.toJSONString(jobjParam);
                 log.info("【杀虫灯】发送指令【refresh】 mqttMsgContent={}", mqttMsgContent);
                 break;
             }
-            case CmdDef.YfScdCmdDef.CMD_COMMON:{
+            case CmdDef.YfScdCmdDef.CMD_COMMON: {
                 JSONObject jobjParam = cmdDistribution.getJsons();
                 mqttMsgContent = JSONUtils.toJSONString(jobjParam);
                 log.info("【杀虫灯】发送指令【report】 mqttMsgContent={}", mqttMsgContent);
@@ -133,8 +135,8 @@ public class YfScdDeviceImpl extends DeviceAbstractImpl implements IYfScdDevice
             }
         }
 
-        if(StringUtils.isNotEmpty(mqttMsgContent)){
-            IotDevice iotDevice= iIotDeviceService.selectIotDeviceByDevBid(cmdModel.getIotDevice().getDevBid());
+        if (StringUtils.isNotEmpty(mqttMsgContent)) {
+            IotDevice iotDevice = iIotDeviceService.selectIotDeviceByDevBid(cmdModel.getIotDevice().getDevBid());
             publish(iotDevice, mqttMsgContent);
         }
 
@@ -146,7 +148,7 @@ public class YfScdDeviceImpl extends DeviceAbstractImpl implements IYfScdDevice
     }
 
     public Object cmdData(JSONObject dataJson, String topic, String connectionId, String devUpdateddate) throws Exception {
-        log.info("杀虫灯数据解析 {},topic:{}", dataJson.toString(),topic);
+        log.info("杀虫灯数据解析 {},topic:{}", dataJson.toString(), topic);
 
         IotDevice oldIotDevice = findIotDevice(topic, dataJson, connectionId);
         if (oldIotDevice == null) {
@@ -234,9 +236,9 @@ public class YfScdDeviceImpl extends DeviceAbstractImpl implements IYfScdDevice
         newIotDevice.setDevUpdateddate(oldIotDevice.getDevUpdateddate());
         newIotDevice.setDevCode(oldIotDevice.getDevCode());
         newIotDevice.setDevOriginalStatus(oldIotDevice.getDevOriginalStatus());
+        newIotDevice.setDevName(oldIotDevice.getDevName());
         iIotDeviceService.updateIotDevice(newIotDevice);
 
-
         //发送离线预警
         SpringUtils.getBean(WarnService.class).processWarningOfflineData(newIotDevice, dataJson);
 
@@ -260,7 +262,7 @@ public class YfScdDeviceImpl extends DeviceAbstractImpl implements IYfScdDevice
      * @return
      */
     @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 cmd = dataJson.getString("cmd");
@@ -270,8 +272,8 @@ public class YfScdDeviceImpl extends DeviceAbstractImpl implements IYfScdDevice
         }
         JSONObject ext = dataJson.getJSONObject("ext");
         String devUpdateddate = dataJson.getString("devUpdateddate");
-        if(StringUtils.isEmpty(devUpdateddate)){
-            devUpdateddate= DateUtils.dateTimeNow();
+        if (StringUtils.isEmpty(devUpdateddate)) {
+            devUpdateddate = DateUtils.dateTimeNow();
         }
         if (ext == null) {
             log.error("未取到ext");
@@ -299,8 +301,8 @@ public class YfScdDeviceImpl extends DeviceAbstractImpl implements IYfScdDevice
      * @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);
         return iIotDeviceService.selectIotDeviceByDevBid(devId);
     }
 }

+ 18 - 16
src/main/java/com/yunfeiyun/agmp/iots/device/serviceImp/YfXycbIIIDeviceImpl.java

@@ -68,13 +68,13 @@ public class YfXycbIIIDeviceImpl extends DeviceAbstractImpl implements IYfXycbII
      * @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);
         return iIotDeviceService.selectIotDeviceByDevBid(devId);
     }
 
     public void cmdData(JSONObject dataJson, String topic, String connectionId, String devUpdateddate) throws Exception {
-        log.info("【{}】数据解析 {},topic:{}", tag, dataJson.toString(),topic);
+        log.info("【{}】数据解析 {},topic:{}", tag, dataJson.toString(), topic);
 
         IotDevice oldIotDevice = findIotDevice(topic, dataJson, connectionId);
         if (oldIotDevice == null) {
@@ -135,7 +135,7 @@ public class YfXycbIIIDeviceImpl extends DeviceAbstractImpl implements IYfXycbII
     }
 
     public void cmdDataConfig(JSONObject dataJson, String topic, String connectionId, String devUpdateddate) throws Exception {
-        log.info("【{}】配置 数据解析 {},topic:{}", tag, dataJson.toString(),topic);
+        log.info("【{}】配置 数据解析 {},topic:{}", tag, dataJson.toString(), topic);
 
         IotDevice oldIotDevice = findIotDevice(topic, dataJson, connectionId);
         if (oldIotDevice == null) {
@@ -158,7 +158,7 @@ public class YfXycbIIIDeviceImpl extends DeviceAbstractImpl implements IYfXycbII
 
         if (dataJson.containsKey("data_tim")) {
             JSONObject dataTim = dataJson.getJSONObject("data_tim");
-            transformedObject.put("dat_f",  dataTim.getOrDefault("dat_f", defaultValue)); // 注意这里将dat_f值改为1
+            transformedObject.put("dat_f", dataTim.getOrDefault("dat_f", defaultValue)); // 注意这里将dat_f值改为1
         }
 
         if (dataJson.containsKey("power")) {
@@ -168,7 +168,7 @@ public class YfXycbIIIDeviceImpl extends DeviceAbstractImpl implements IYfXycbII
 
         if (dataJson.containsKey("clt_tim")) {
             JSONObject cltTim = dataJson.getJSONObject("clt_tim");
-            transformedObject.put("clt_t",  cltTim.getOrDefault("clt_t", defaultValue)); // 注意这里将clt_t值改为10
+            transformedObject.put("clt_t", cltTim.getOrDefault("clt_t", defaultValue)); // 注意这里将clt_t值改为10
         }
 
         IotDevice newIotDevice = new IotDevice();
@@ -186,18 +186,18 @@ public class YfXycbIIIDeviceImpl extends DeviceAbstractImpl implements IYfXycbII
         String devCode = iotDevice.getDevCode();
         List<String> topicList = new ArrayList<>();
         topicList.add(IotMqttConstant.YFXycbIIITopic.TOPIC_XYCB_III_CMD_PREFIX + devCode);
-        for(String topic:topicList){
-            try{
+        for (String topic : topicList) {
+            try {
                 mqttManager.publishMsg(iotDevice.getDevconnBid(), topic, mqttMsgContent);
-                log.info("【{}】发送指令完毕!connectionId:{},topic :{} mqttMsgContent: {}", tag, iotDevice.getDevconnBid(),topic, mqttMsgContent);
-            }catch (Exception e){
-                log.error("【{}】发送指令失败!connectionId:{},topic :{} mqttMsgContent: {}", tag, iotDevice.getDevconnBid(),topic, mqttMsgContent);
+                log.info("【{}】发送指令完毕!connectionId:{},topic :{} mqttMsgContent: {}", tag, iotDevice.getDevconnBid(), topic, mqttMsgContent);
+            } catch (Exception e) {
+                log.error("【{}】发送指令失败!connectionId:{},topic :{} mqttMsgContent: {}", tag, iotDevice.getDevconnBid(), topic, mqttMsgContent);
             }
         }
     }
 
     public void cmdOffline(JSONObject dataJson, String topic, String connectionId, String devUpdateddate) throws MqttException {
-        log.info("【{}】离线 数据解析 {},topic:{}", tag, dataJson.toString(),topic);
+        log.info("【{}】离线 数据解析 {},topic:{}", tag, dataJson.toString(), topic);
         IotDevice oldIotDevice = findIotDevice(topic, dataJson, connectionId);
         if (oldIotDevice == null) {
             log.error("未取到 iotDevice");
@@ -214,6 +214,8 @@ public class YfXycbIIIDeviceImpl extends DeviceAbstractImpl implements IYfXycbII
         newIotDevice.setDevUpdateddate(oldIotDevice.getDevUpdateddate());
         newIotDevice.setDevCode(oldIotDevice.getDevCode());
         newIotDevice.setDevOriginalStatus(oldIotDevice.getDevOriginalStatus());
+        newIotDevice.setDevName(oldIotDevice.getDevName());
+
         iIotDeviceService.updateIotDevice(newIotDevice);
 
 
@@ -293,8 +295,8 @@ public class YfXycbIIIDeviceImpl extends DeviceAbstractImpl implements IYfXycbII
             }
         }
 
-        if(StringUtils.isNotEmpty(mqttMsgContent)){
-            IotDevice iotDevice= iIotDeviceService.selectIotDeviceByDevBid(cmdModel.getIotDevice().getDevBid());
+        if (StringUtils.isNotEmpty(mqttMsgContent)) {
+            IotDevice iotDevice = iIotDeviceService.selectIotDeviceByDevBid(cmdModel.getIotDevice().getDevBid());
             publish(iotDevice, mqttMsgContent);
         }
 
@@ -325,8 +327,8 @@ public class YfXycbIIIDeviceImpl extends DeviceAbstractImpl implements IYfXycbII
         }
         JSONObject ext = dataJson.getJSONObject("ext");
         String devUpdateddate = dataJson.getString("devUpdateddate");
-        if(StringUtils.isEmpty(devUpdateddate)){
-            devUpdateddate= DateUtils.dateTimeNow();
+        if (StringUtils.isEmpty(devUpdateddate)) {
+            devUpdateddate = DateUtils.dateTimeNow();
         }
         if (ext == null) {
             log.error("未取到ext");

+ 1 - 0
src/main/java/com/yunfeiyun/agmp/iots/task/IotStatusService.java

@@ -160,6 +160,7 @@ public class IotStatusService {
         iotDevice.setTid(iotDeviceStatusResVo.getTid());
         iotDevice.setDevCreateddate(iotDeviceStatusResVo.getDevCreateddate());
         iotDevice.setDevUpdateddate(iotDeviceStatusResVo.getDevUpdateddate());
+        iotDevice.setDevName(iotDeviceStatusResVo.getDevName());
         //编辑离线
         iIotDeviceService.updateIotDevice(iotDevice);
         //发送预警

+ 2 - 1
src/main/java/com/yunfeiyun/agmp/iots/task/YbqScheduler.java

@@ -15,6 +15,7 @@ import com.yunfeiyun.agmp.iots.service.IotYbqPredictDataService;
 import com.yunfeiyun.agmp.iots.core.http.YbqCmbService;
 import com.yunfeiyun.agmp.iots.service.IIotDeviceService;
 import com.yunfeiyun.agmp.iots.service.IIotDevicelasteddataService;
+import com.yunfeiyun.agmp.iots.warn.util.NumberUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
@@ -119,7 +120,7 @@ public class YbqScheduler {
                         // 得到第三方返回的设备的预测数据
                         String computeDate = jobj.getString("computeDate");
                         String deviceId = jobj.getString("deviceId");
-                        String value = jobj.getString("value");
+                        String value = NumberUtil.keepTwoDecimalPlaces(jobj.getString("value"));
                         //保存预测记录、更新预测最新数据
                         // 查查当天的有没有,有的话更新,没有的话添加
                         IotYbqPredictData iotYbqPredictDataToday = iotYbqPredictDataService.getTodayData(devBid);

+ 1 - 0
src/main/java/com/yunfeiyun/agmp/iots/warn/model/IotWarnconfigDevVo.java

@@ -7,6 +7,7 @@ import lombok.Data;
 public class IotWarnconfigDevVo extends IotWarnconfig {
     private String wiBid;
     private String devBid;
+    private String devName;
     private String devCode;
     private String devtypeBid;
     private String devCbdrecogtype;

+ 1 - 0
src/main/java/com/yunfeiyun/agmp/iots/warn/model/WarnStatusDto.java

@@ -5,6 +5,7 @@ import lombok.Data;
 @Data
 public class WarnStatusDto {
     private String devType;
+    private String devName;
     private String devCode;
     private String name;
     private String value;

+ 10 - 6
src/main/java/com/yunfeiyun/agmp/iots/warn/service/MsgService.java

@@ -78,7 +78,7 @@ public class MsgService {
                 log.info("【告警通知】消息标识{}:当前设备ID:{},即时推送", messageId, warnResult.getDevId());
                 //如果设置有推送频率,结合最后一次发送时间,如果上次距离当下超过发送频率,那就可以发送
                 // 发送频率,每N时,数字类型
-                String wpFrequency = StringUtils.isEmpty(iotWarnpolicy.getWpFrequency())?"0":iotWarnpolicy.getWpFrequency();
+                String wpFrequency = StringUtils.isEmpty(iotWarnpolicy.getWpFrequency()) ? "0" : iotWarnpolicy.getWpFrequency();
                 // 判断是否到了发送时间
                 IotWarnlog lastedUnSendWarnLog = getLastedUnSendWarnLog(warnResult.getConfigId());
                 if (lastedUnSendWarnLog != null) {
@@ -97,12 +97,12 @@ public class MsgService {
                 String deliveryTimePeriod = iotWarnpolicy.getDeliveryTimePeriod();
                 String startTime = deliveryTimePeriod.split("-")[0];
                 String endTime = deliveryTimePeriod.split("-")[1];
-                Date startDate = DateUtils.parseDate(DateUtils.getDate()+" "+startTime);
-                Date endDate = DateUtils.parseDate(DateUtils.getDate()+" "+endTime);
-                log.info("【告警通知】消息标识{}:当前设备ID:{},时间段推送:deliveryTimePeriod{},start:{},end:{}", messageId, warnResult.getDevId(),deliveryTimePeriod,startDate,endDate);
+                Date startDate = DateUtils.parseDate(DateUtils.getDate() + " " + startTime);
+                Date endDate = DateUtils.parseDate(DateUtils.getDate() + " " + endTime);
+                log.info("【告警通知】消息标识{}:当前设备ID:{},时间段推送:deliveryTimePeriod{},start:{},end:{}", messageId, warnResult.getDevId(), deliveryTimePeriod, startDate, endDate);
                 if (DateUtils.isBetween(new Date(), startDate, endDate)) {
                     // 发送频率,每N时,数字类型
-                    String wpFrequency = StringUtils.isEmpty(iotWarnpolicy.getWpFrequency())?"0":iotWarnpolicy.getWpFrequency();
+                    String wpFrequency = StringUtils.isEmpty(iotWarnpolicy.getWpFrequency()) ? "0" : iotWarnpolicy.getWpFrequency();
                     // 判断是否到了发送时间
                     IotWarnlog lastedUnSendWarnLog = getLastedUnSendWarnLog(warnResult.getConfigId());
                     if (lastedUnSendWarnLog != null) {
@@ -173,7 +173,11 @@ public class MsgService {
         messageDto.setMsgbatchContent(warnResult.getMessage());  // 使用预警消息作为消息批次内容
         messageDto.setMsgbatchContenttype("1");  // 假定使用固定内容,具体依据业务需求确定
         messageDto.setMsgbatchMsgtype(MsgType.WARN_INFO.getCode());
-        messageDto.setMsgbatchBiztype(resolveMsgBusTypeByDevtype(warnResult.getDevtypeBid()).getCode());  // 业务类型,这里假设为预警配置ID
+        if (warnResult.isOffline()) {
+            messageDto.setMsgbatchBiztype(MsgBusType.WARN_OFFLINE_WARN.getCode());  // 事务类型
+        } else {
+            messageDto.setMsgbatchBiztype(resolveMsgBusTypeByDevtype(warnResult.getDevtypeBid()).getCode());  // 事务类型
+        }
         messageDto.setMsgbatchBizobj(warnResult.getDevId());  // 设备ID作为业务对象
         messageDto.setMsgbatchLevel(iotWarnconfig.getWcLevel());  // 消息等级,这里默认为1,实际应用中应依据具体情况设置
         messageDto.setMsgbatchSource("iots");  // 消息来源,假设来自物联网系统

+ 7 - 4
src/main/java/com/yunfeiyun/agmp/iots/warn/service/WarnDiseaseService.java

@@ -75,8 +75,10 @@ public class WarnDiseaseService {
         if (StringUtils.isNotEmpty(detailedDevice.getExtInfo())) {
             JSONObject extInfo = JSONObject.parseObject(detailedDevice.getExtInfo());
             Double computeValue = Double.parseDouble(extInfo.getOrDefault("computeValue", "0.0").toString());
-            WarnStatusDto warnStatusDto = buildWarnStatusDto(computeValue, indicator);
+            WarnStatusDto warnStatusDto = buildWarnStatusDto(computeValue, indicator, device.getDevName());
             if (warnStatusDto != null) {
+                warnStatusDto.setDevName(detailedDevice.getDevName());
+                warnStatusDto.setDevCode(detailedDevice.getDevCode());
                 handlerAllWarnLog(device.getDevBid(), warnConfig, warnStatusDto, detailedDevice.getExtInfo());
             } else {
                 log.warn("【设备预警】病虫害:设备id 不可为空. 设备ID: {}, 设备Code:{} , 未触发: ", detailedDevice.getDevBid(), detailedDevice.getDevCode());
@@ -94,7 +96,7 @@ public class WarnDiseaseService {
      * @param indicator    预警指标对象
      * @return 构建好的WarnStatusDto对象
      */
-    private WarnStatusDto buildWarnStatusDto(Double currentValue, IotWarnindicator indicator) {
+    private WarnStatusDto buildWarnStatusDto(Double currentValue, IotWarnindicator indicator, String devName) {
         if (!"0".equals(indicator.getWiStatus())) {
             return null;
         }
@@ -105,6 +107,7 @@ public class WarnDiseaseService {
         dto.setDevCode(indicator.getDevCode());
         dto.setName(indicator.getWiName());
         dto.setValue(currentValue.toString());
+        dto.setDevName(devName);
         dto.setUnit(indicator.getWiUnit());
         dto.setOpt(op.getName());
         dto.setIndicatorValue(indicator.getWiValue());
@@ -127,7 +130,7 @@ public class WarnDiseaseService {
             throw new BizException(ErrorCode.FAILURE.getCode(), "病虫害:设备id 不可为空");
         }
         log.info("开始处理设备ID为 {}, 配置ID为 {} 的预警信息", devBid, config.getWcBid());
-        String message = WarnMessageBuilderUtil.buildWarningMessage(dto.getDevType(), dto.getDevCode(),
+        String message = WarnMessageBuilderUtil.buildWarningMessage(dto.getDevName(), dto.getDevCode(),
                 dto.getName(), dto.getValue(), dto.getUnit(), dto.getOpt(), dto.getIndicatorValue());
         log.info("根据类型生成警告消息: {}. 设备ID: {}, 配置ID: {}", message, devBid, config.getWcBid());
 
@@ -158,7 +161,7 @@ public class WarnDiseaseService {
         result.setConfig(config);
         result.setTriggered(dto.isWarn());
         result.setMessage(WarnMessageBuilderUtil.buildWarningMessage(
-                dto.getDevType(), dto.getDevCode(), dto.getName(), dto.getValue(), dto.getUnit(), dto.getOpt(), dto.getIndicatorValue()
+                dto.getDevName(), dto.getDevCode(), dto.getName(), dto.getValue(), dto.getUnit(), dto.getOpt(), dto.getIndicatorValue()
         ));
         return result;
     }

+ 24 - 15
src/main/java/com/yunfeiyun/agmp/iots/warn/service/WarnPestService.java

@@ -104,7 +104,11 @@ public class WarnPestService {
         String endTime = datePre + " 23:59:59";
         String devBid = iotWarnindicator.getDevBid();
         int currentValue = iotWarnBussinessService.statPestTypeCountByDevBid(devBid, startTime, endTime);
-        return buildWarnStatusDto(currentValue, iotWarnindicator);
+        WarnStatusDto warnStatusDto = buildWarnStatusDto(currentValue, iotWarnindicator);
+        if (warnStatusDto != null) {
+            warnStatusDto.setDevName(iotDevice.getDevName());
+        }
+        return warnStatusDto;
     }
 
     String getDateBefore() {
@@ -122,7 +126,11 @@ public class WarnPestService {
         String endTime = datePre + " 23:59:59";
         String devBid = iotDevice.getDevBid();
         int currentValue = iotWarnBussinessService.statPestCountByDevBid(devBid, startTime, endTime);
-        return buildWarnStatusDto(currentValue, iotWarnindicator);
+        WarnStatusDto warnStatusDto = buildWarnStatusDto(currentValue, iotWarnindicator);
+        if (warnStatusDto != null) {
+            warnStatusDto.setDevName(iotDevice.getDevName());
+        }
+        return warnStatusDto;
     }
 
     /**
@@ -162,11 +170,11 @@ public class WarnPestService {
         List<IotWarnindicator> childrenList = iotWarnindicator.getChildrenList();
         List<WarnStatusDto> warnStatusDtoList = new ArrayList<>();
 
-        if(Objects.equals(iotWarnindicator.getWiStatus(), "1")){
+        if (Objects.equals(iotWarnindicator.getWiStatus(), "1")) {
             return warnStatusDtoList;
         }
 
-        if(childrenList == null || childrenList.isEmpty()){
+        if (childrenList == null || childrenList.isEmpty()) {
             return warnStatusDtoList;
         }
 
@@ -198,7 +206,8 @@ public class WarnPestService {
                 continue;
             }
             WarnStatusDto warnStatusDto = buildWarnStatusDto(totalPestCount, iotWarnindicatorItem);
-            if(warnStatusDto != null && warnStatusDto.isWarn()){
+            if (warnStatusDto != null && warnStatusDto.isWarn()) {
+                warnStatusDto.setDevName(iotDevice.getDevName());
                 warnStatusDtoList.add(warnStatusDto);
             }
         }
@@ -212,7 +221,7 @@ public class WarnPestService {
      * @param iotWarnconfig
      * @param pestByType
      * @param pestByCount
-     * @param designatePest
+     * @param warnStatusDtoList
      */
     private void handlerAllWarnLog(String devBid, IotWarnconfig iotWarnconfig, WarnStatusDto pestByType, WarnStatusDto pestByCount, List<WarnStatusDto> warnStatusDtoList) {
         if (StringUtils.isEmpty(devBid)) {
@@ -228,12 +237,12 @@ public class WarnPestService {
         String pestByCountMessage = null;
         String designatePestMessage = null;
         boolean isWarn = false;
-        String devType = null;
+        String devName = null;
         String devCode = null;
 
         // 构建消息
         if (pestByType != null && pestByType.isWarn()) {
-            devType = pestByType.getDevType();
+            devName = pestByType.getDevName();
             devCode = pestByType.getDevCode();
 
             pestByTypeMessage = WarnMessageBuilderUtil.buildWarningMessage(
@@ -250,7 +259,7 @@ public class WarnPestService {
         }
 
         if (pestByCount != null && pestByCount.isWarn()) {
-            devType = pestByCount.getDevType();
+            devName = pestByCount.getDevName();
             devCode = pestByCount.getDevCode();
 
             pestByCountMessage = WarnMessageBuilderUtil.buildWarningMessage(
@@ -266,10 +275,10 @@ public class WarnPestService {
             isWarn = true;
         }
         StringBuilder messageBuilder = new StringBuilder();
-        if(warnStatusDtoList != null && !warnStatusDtoList.isEmpty()) {
+        if (warnStatusDtoList != null && !warnStatusDtoList.isEmpty()) {
             messageBuilder.append("指定虫害: \n");
-            for(WarnStatusDto warnStatusDto : warnStatusDtoList) {
-                devType = warnStatusDto.getDevType();
+            for (WarnStatusDto warnStatusDto : warnStatusDtoList) {
+                devName = warnStatusDto.getDevName();
                 devCode = warnStatusDto.getDevCode();
 
                 String message = WarnMessageBuilderUtil.buildWarningMessage(
@@ -284,15 +293,15 @@ public class WarnPestService {
                 messageBuilder.append(message).append("\n");
             }
         }
-        if(messageBuilder.length() > 0) {
+        if (messageBuilder.length() > 0) {
             designatePestMessage = messageBuilder.toString();
             log.info("针对指定病虫害生成警告消息: {}. 设备ID: {}, 配置ID: {}", designatePestMessage, devBid, iotWarnconfig.getWcBid());
             isWarn = true;
         }
 
         StringBuffer buffer = new StringBuffer();
-        if(isWarn){
-            buffer.append(devType).append("设备(").append(devCode).append("), 触发告警,告警原因: \n");
+        if (isWarn) {
+            buffer.append(devName).append("设备(").append(devCode).append("), 触发告警,告警原因: \n");
         }
         if (pestByTypeMessage != null) {
             buffer.append(pestByTypeMessage);

+ 6 - 5
src/main/java/com/yunfeiyun/agmp/iots/warn/service/WarnService.java

@@ -115,7 +115,7 @@ public class WarnService {
                             warnResult.setConfig(warnConfigInfo);
                             warnResult.setOffline(true);
                             warnResult.setTriggered(true);
-                            warnResult.setMessage(WarnMessageBuilderUtil.buildWarningOfflineMessage(iotDevice.getDevtypeBid(), iotDevice.getDevCode(), StringUtils.isEmpty(iotDevice.getDevUpdateddate()) ? iotDevice.getDevCreateddate() : iotDevice.getDevUpdateddate()));
+                            warnResult.setMessage(WarnMessageBuilderUtil.buildWarningOfflineMessage(iotDevice.getDevName(), iotDevice.getDevCode(), StringUtils.isEmpty(iotDevice.getDevUpdateddate()) ? iotDevice.getDevCreateddate() : iotDevice.getDevUpdateddate()));
                             // 处理警告记录前的日志
                             log.info("[设备告警] 正在为设备{}处理警告记录:{}", iotDevice.getDevBid(), warnResult);
                             handleWarnRecord(warnResult);
@@ -370,6 +370,7 @@ public class WarnService {
 
         WarnStatusDto warnStatusDto = new WarnStatusDto();
         warnStatusDto.setDevType(iotDeviceTypeLv1Enum.getName());
+        warnStatusDto.setDevName(iotDevice.getDevName());
         warnStatusDto.setDevCode(devCode);
         warnStatusDto.setName(wiName);
         warnStatusDto.setValue(currentValue);
@@ -402,7 +403,7 @@ public class WarnService {
         }
         if (warnStatusDto != null && warnStatusDto.isWarn()) {
             String message = WarnMessageBuilderUtil.buildWarningMessage(
-                    warnStatusDto.getDevType(),
+                    warnStatusDto.getDevName(),
                     warnStatusDto.getDevCode(),
                     warnStatusDto.getName(),
                     warnStatusDto.getValue(),
@@ -446,14 +447,14 @@ public class WarnService {
         StringBuilder messageBuilder = new StringBuilder();
         for (int i = 0; i < warnStatusDtos.size(); i++) {
             warnStatusDto = warnStatusDtos.get(i);
-            String devType = null;
+            String devName = null;
             String dCode = null;
             if (i == 0) {
-                devType = warnStatusDto.getDevType();
+                devName = warnStatusDto.getDevName();
                 dCode = warnStatusDto.getDevCode();
             }
             String message = WarnMessageBuilderUtil.buildWarningMessage(
-                    devType,
+                    devName,
                     dCode,
                     warnStatusDto.getName(),
                     warnStatusDto.getValue(),

+ 30 - 0
src/main/java/com/yunfeiyun/agmp/iots/warn/util/NumberUtil.java

@@ -0,0 +1,30 @@
+package com.yunfeiyun.agmp.iots.warn.util;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+
+public class NumberUtil {
+    /**
+     * 将传入的字符串形式的数字转换为保留两位小数的字符串。
+     *
+     * @param numberStr 字符串形式的数字
+     * @return 保留两位小数的字符串;如果输入无效,则返回"0.00"作为默认值
+     */
+    public static String keepTwoDecimalPlaces(String numberStr) {
+        if (numberStr == null || numberStr.trim().isEmpty()) {
+            // 返回默认值
+            return "0.00";
+        }
+
+        try {
+            BigDecimal number = new BigDecimal(numberStr.trim());
+            // 使用RoundingMode.HALF_UP进行四舍五入
+            BigDecimal result = number.setScale(2, RoundingMode.HALF_UP);
+            return result.toString();
+        } catch (NumberFormatException e) {
+            // 如果输入不是一个有效的数字字符串,返回默认值
+            return "0.00";
+        }
+    }
+
+}

+ 8 - 8
src/main/java/com/yunfeiyun/agmp/iots/warn/util/WarnMessageBuilderUtil.java

@@ -7,7 +7,7 @@ public class WarnMessageBuilderUtil {
     /**
      * 构建告警信息。
      *
-     * @param devType        设备类型,例如“气象站设备”。
+     * @param devName        设备名称,例如“气象站设备”。
      * @param devCode        设备唯一编码,例如“87872877485”。
      * @param name           告警参数名,例如“温度”。
      * @param value          当前值,例如42。
@@ -16,11 +16,11 @@ public class WarnMessageBuilderUtil {
      * @param indicatorValue 设定的目标对比值,例如“10-35℃”。
      * @return 格式化后的告警信息。
      */
-    public static String buildWarningMessage(String devType, String devCode, String name, String value, String unit, String opt, String indicatorValue) {
+    public static String buildWarningMessage(String devName, String devCode, String name, String value, String unit, String opt, String indicatorValue) {
         // 格式化字符串,将设备类型、设备唯一编码、告警参数名、当前值、单位、动作和目标对比值插入到模板中
         String tag = "";
-        if (devType != null && devCode != null) {
-            tag = String.format("%s设备(%s), 触发告警,告警原因: \n", devType, devCode);
+        if (devName != null && devCode != null) {
+            tag = String.format("%s设备(%s), 触发告警,告警原因: \n", devName, devCode);
         }
         return String.format("%s %s 上报值 %s%s,%s设置的阀值%s。",
                 tag,
@@ -34,12 +34,12 @@ public class WarnMessageBuilderUtil {
     /**
      * 构建离线消息
      *
-     * @param devType
+     * @param devName
      * @param devCode
-     * @param name
+     * @param lastUpdateTime
      * @return
      */
-    public static String buildWarningOfflineMessage(String devType, String devCode, String lastUpdateTime) {
+    public static String buildWarningOfflineMessage(String devName, String devCode, String lastUpdateTime) {
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         try {
             Date lastUpdate = sdf.parse(lastUpdateTime);
@@ -58,7 +58,7 @@ public class WarnMessageBuilderUtil {
                 durationStr = String.format("已离线%d分钟", diffMinutes);
             }
 
-            String content = String.format("%s设备(%s)%s;", devType, devCode, durationStr);
+            String content = String.format("%s设备(%s)%s;", devName, devCode, durationStr);
             return content;
 
         } catch (Exception e) {

+ 2 - 2
src/main/resources/mapper/IotWarnBusinessMapper.xml

@@ -174,7 +174,7 @@
     </update>
 
     <select id="selectIotWarnconfigCbdDevList" resultType="com.yunfeiyun.agmp.iots.warn.model.IotWarnconfigDevVo">
-        SELECT wi.wiBid, d.devBid, d.devCode, d.devtypeBid, d.devCbdrecogtype, wc.*
+        SELECT wi.wiBid, d.devBid, d.devCode,d.devName, d.devtypeBid, d.devCbdrecogtype, wc.*
         FROM IotWarnindicator AS wi
             LEFT JOIN IotWarnconfig AS wc ON wc.wcBid = wi.wcBid
             LEFT JOIN IotWarnobject AS wo ON wo.wcBid = wc.wcBid
@@ -233,7 +233,7 @@
 
     <select id="selectIotWarnconfigYbqDevList"
             resultType="com.yunfeiyun.agmp.iots.warn.model.IotWarnconfigDevVo">
-                  SELECT wi.wiBid, d.devBid, d.devCode, d.devtypeBid, d.devCbdrecogtype, wc.*
+                  SELECT wi.wiBid, d.devBid, d.devCode,d.devName, d.devtypeBid, d.devCbdrecogtype, wc.*
         FROM IotWarnindicator AS wi
             LEFT JOIN IotWarnconfig AS wc ON wc.wcBid = wi.wcBid
             LEFT JOIN IotWarnobject AS wo ON wo.wcBid = wc.wcBid