Bladeren bron

告警单位修改

lengfaqiang 2 jaren geleden
bovenliggende
commit
f38d87e6d4

+ 31 - 14
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/consumer/MqttCallbackHandler.java

@@ -40,6 +40,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.text.SimpleDateFormat;
 import java.time.*;
 import java.util.*;
@@ -153,10 +154,22 @@ public class MqttCallbackHandler extends AbstractHandler {
                         Long level = Long.valueOf(map.get("level"));
                         Long thresholdId = Long.valueOf(map.get("thresholdId"));
                         String offset = map.get("offset");
+//                        /**x、y、z要进行偏移量计算  其他数值保持源数据进行计算*/
+//                        List<String> checkItemName = new ArrayList<>();
+//                        checkItemName.add(DictItemEnum.ALTITUDE_Z.getValue());
+//                        checkItemName.add(DictItemEnum.LONGITUDE_X.getValue());
+//                        checkItemName.add(DictItemEnum.LATITUDE_Y.getValue());
+//                        String itemValueAndUnit = "";
+//                        String url = "";
+//                        if (checkItemName.contains(itemName)) {
+//
+//                            itemValueAndUnit = StringUtils.isBlank(url) ? itemValue : (itemValue + url);
+//                        } else {
+//                            url = dictByDictCode.get(itemName) == null ? null : dictByDictCode.get(itemName).getRemark();
+//                            itemValueAndUnit = StringUtils.isBlank(url) ? itemValue : (itemValue + url);
+//                        }
                         //阈值表以及明细表存储
-                        String url = dictByDictCode.get(itemName) == null ? null : dictByDictCode.get(itemName).getUrl();
-                        String itemValueAndUnit = StringUtils.isBlank(url) ? itemValue : (itemValue + url);
-                        long id = insertAlarmAndDetail(level, device, thresholdId, itemValueAndUnit, ts, AlarmTitleEnum.ALARM_TITLE_TWO.getStatus(), AlarmTypeEnum.ALARM_ONE.getCode());
+                        long id = insertAlarmAndDetail(level, device, thresholdId, offset, ts, AlarmTitleEnum.ALARM_TITLE_TWO.getStatus(), AlarmTypeEnum.ALARM_ONE.getCode());
                         //todo 不适用redis存统计  使用新字段处理
                         /**阈值次数存redis*/
 //                        redisPutAlarmCount(id);
@@ -186,7 +199,7 @@ public class MqttCallbackHandler extends AbstractHandler {
                             templateParam.put("level", level.toString());
                             templateParam.put("name", device.getName());
 //                            templateParam.put("value", itemValue);
-                            templateParam.put("value", offset+url);
+                            templateParam.put("value", offset);
                             commonService.pushSmsMessage(pushToPhone
                                     , smsTemplateConfig.getDataAlarm().getSmsCode()
                                     , smsTemplateConfig.getDataAlarm().getSignName()
@@ -216,7 +229,7 @@ public class MqttCallbackHandler extends AbstractHandler {
                             templateParam.put("time", time);
                             templateParam.put("project", vo == null ? null : vo.getProjectName());
 //                            templateParam.put("value", itemValue);
-                            templateParam.put("value", offset+url);
+                            templateParam.put("value", offset);
                             commonService.pushEmailMessage(emailAddress
                                     , templateParam);
                         }
@@ -288,9 +301,10 @@ public class MqttCallbackHandler extends AbstractHandler {
                         Long level = Long.valueOf(map.get("level"));
                         Long thresholdId = Long.valueOf(map.get("thresholdId"));
                         //阈值表以及明细表存储
-                        String url = deviceIntegration.getUnit() == null ? null : deviceIntegration.getUnit();
-                        String itemValueAndUnit = StringUtils.isBlank(url) ? String.valueOf(offset) : (offset + deviceIntegration.getUnit());
-                        long id = insertAlarmAndDetail(level, device, thresholdId, itemValueAndUnit, ts, AlarmTitleEnum.ALARM_TITLE_TWO.getStatus(), AlarmTypeEnum.ALARM_ONE.getCode());
+//                        String url = deviceIntegration.getUnit() == null ? null : deviceIntegration.getUnit();
+//                        String itemValueAndUnit = StringUtils.isBlank(url) ? String.valueOf(offset) : (offset + deviceIntegration.getUnit());
+//                        long id = insertAlarmAndDetail(level, device, thresholdId, itemValueAndUnit, ts, AlarmTitleEnum.ALARM_TITLE_TWO.getStatus(), AlarmTypeEnum.ALARM_ONE.getCode());
+                        long id = insertAlarmAndDetail(level, device, thresholdId, offset + deviceIntegration.getUnit(), ts, AlarmTitleEnum.ALARM_TITLE_TWO.getStatus(), AlarmTypeEnum.ALARM_ONE.getCode());
                         /**最初发送短信模式*/
 //                        oldPushSms(device,level,thresholdId);
                         /**目前发送短信模式*/
@@ -317,7 +331,7 @@ public class MqttCallbackHandler extends AbstractHandler {
                             templateParam.put("level", level.toString());
                             templateParam.put("name", device.getName());
 //                            templateParam.put("value", itemValueAndUnit);
-                            templateParam.put("value", String.valueOf(offset)+url);
+                            templateParam.put("value", String.valueOf(offset) + deviceIntegration.getUnit());
                             commonService.pushSmsMessage(pushToPhone
                                     , smsTemplateConfig.getDataAlarm().getSmsCode()
                                     , smsTemplateConfig.getDataAlarm().getSignName()
@@ -347,7 +361,7 @@ public class MqttCallbackHandler extends AbstractHandler {
                             templateParam.put("time", time);
                             templateParam.put("project", vo == null ? null : vo.getProjectName());
 //                            templateParam.put("value", itemValueAndUnit);
-                            templateParam.put("value", String.valueOf(offset)+url);
+                            templateParam.put("value", String.valueOf(offset) + deviceIntegration.getUnit());
                             commonService.pushEmailMessage(emailAddress
                                     , templateParam);
                         }
@@ -445,13 +459,16 @@ public class MqttCallbackHandler extends AbstractHandler {
         //放入告警数值-告警等级
         //放入告警等级-告警主键id
         Map<String, String> map = new HashMap<>();
+        Map<String, SystemDict> dictByDictCode = commonService.getDictByDictCode(DictEnum.MODEL_PART);
         if (checkItemName.contains(itemName)) {
             BigDecimal offset = commonService.computeOffset(itemValue, itemName, deviceRelation);
             map = newAlarmCompute(offset, kwsThresholds);
-            map.put("offset",String.valueOf(offset));
+            String url = dictByDictCode.get(itemName) == null ? null : dictByDictCode.get(itemName).getUrl();
+            map.put("offset", String.valueOf(offset.setScale(2, RoundingMode.HALF_UP)) + url);
         } else {
             map = newAlarmCompute(new BigDecimal(itemValue), kwsThresholds);
-            map.put("offset",itemValue);
+            String remarkUnit = dictByDictCode.get(itemName) == null ? null : dictByDictCode.get(itemName).getRemark();
+            map.put("offset", itemValue + remarkUnit);
         }
 //        map = oldAlarmCompute(checkItemName, itemName, itemValue, deviceRelation, kwsThresholds);
         return map;
@@ -705,9 +722,9 @@ public class MqttCallbackHandler extends AbstractHandler {
                 .orderByDesc(KwsAlarm::getCreateTime);
         if (projectDevice != null) {
             wrapper.eq(Objects.nonNull(projectDevice.getProjectId()), KwsAlarm::getProjectId, projectDevice.getProjectId())
-                    .eq(StringUtils.isNotBlank(device.getMountainId()),KwsAlarm::getMountainId, projectDevice.getMountainId());
+                    .eq(StringUtils.isNotBlank(device.getMountainId()), KwsAlarm::getMountainId, projectDevice.getMountainId());
             if (projectDevice.getProjectId() != null) {
-                wrapper.eq(StringUtils.isNotBlank(projectDevice.getCompanyId()),KwsAlarm::getCompanyId, projectDevice.getCompanyId());
+                wrapper.eq(StringUtils.isNotBlank(projectDevice.getCompanyId()), KwsAlarm::getCompanyId, projectDevice.getCompanyId());
             }
         }
         long alarmId = new IdWorker(NumberConstant.ONE).nextId();