Ver Fonte

mqtt消费bug
告警通知bug

lengfaqiang há 2 anos atrás
pai
commit
3afb4fdb8a
15 ficheiros alterados com 706 adições e 74 exclusões
  1. 2 2
      slope-common/slope-common-core/src/main/java/com/sckw/core/model/enums/AlarmTypeEnum.java
  2. 1 1
      slope-common/slope-common-excel/src/main/java/com/sckw/excel/utils/ExcelUtil.java
  3. 7 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/common/config/mqtt/MqttConfig.java
  4. 204 49
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/consumer/MqttCallbackHandler.java
  5. 2 2
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/consumer/MqttDeviceCallbackHandler.java
  6. 20 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/dao/mysql/KwsAlarmDetailHistoryMapper.java
  7. 10 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dos/mysql/KwsAlarm.java
  8. 10 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dos/mysql/KwsAlarmDetail.java
  9. 79 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dos/mysql/KwsAlarmDetailHistory.java
  10. 10 4
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/excel/ThresholdRecordDetailExportVO.java
  11. 151 12
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/KwsAlarmService.java
  12. 3 2
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/ProjectService.java
  13. 201 0
      slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsAlarmDetailHistoryMapper.xml
  14. 3 1
      slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsAlarmDetailMapper.xml
  15. 3 1
      slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsAlarmMapper.xml

+ 2 - 2
slope-common/slope-common-core/src/main/java/com/sckw/core/model/enums/AlarmTypeEnum.java

@@ -11,9 +11,9 @@ import lombok.Getter;
 public enum AlarmTypeEnum {
 
     //数据告警
-    ALARM_ONE(1, "1", "数据告警"),
+    ALARM_ONE(2, "2", "数据告警"),
     //设备告警
-    ALARM_TWO(2, "2", "设备告警");
+    ALARM_TWO(1, "1", "设备告警");
 
     private final int code;
 

+ 1 - 1
slope-common/slope-common-excel/src/main/java/com/sckw/excel/utils/ExcelUtil.java

@@ -248,7 +248,7 @@ public class ExcelUtil {
         WriteSheet writeSheet;
         for (int i = 1; i <= lists.size(); ++i) {
             excelWriterSheetBuilder = new ExcelWriterSheetBuilder(excelWriter);
-            excelWriterSheetBuilder.sheetNo(i).sheetName(sheetName + i);
+            excelWriterSheetBuilder.sheetNo(i).sheetName(sheetName/* + i*/);
             writeSheet = excelWriterSheetBuilder.build();
             excelWriter.write(lists.get(i - 1), writeSheet);
         }

+ 7 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/common/config/mqtt/MqttConfig.java

@@ -197,6 +197,10 @@ public class MqttConfig {
 
     @Autowired
     private MqttCallbackHandler mqttCallbackHandler;
+
+    @Value("${mqtt.isConsume}")
+    private String isConsume;
+
     /**
      * MQTT消息处理器(消费者)
      */
@@ -204,6 +208,9 @@ public class MqttConfig {
     @ServiceActivator(inputChannel = CHANNEL_NAME_IN)
     public MessageHandler handler() {
         return message -> {
+//            if ("false".equals(isConsume)){
+//                return;
+//            }
             String topic = message.getHeaders().get("mqtt_receivedTopic").toString();
             String payload = message.getPayload().toString();
 //            mqttCallbackHandler.handle(topic, payload);

+ 204 - 49
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/consumer/MqttCallbackHandler.java

@@ -1,15 +1,19 @@
 package com.sckw.slope.detection.consumer;
 
+import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.sckw.core.model.constant.NumberConstant;
+import com.sckw.core.model.enums.AlarmTitleEnum;
+import com.sckw.core.model.enums.AlarmTypeEnum;
 import com.sckw.core.model.enums.DictEnum;
 import com.sckw.core.model.enums.DictItemEnum;
 import com.sckw.core.utils.CollectionUtils;
 import com.sckw.core.utils.IdWorker;
 import com.sckw.core.web.response.HttpResult;
+import com.sckw.log.TraceLog.TraceLog;
 import com.sckw.slope.detection.dao.mysql.*;
-import com.sckw.slope.detection.dao.tdengine.DevicesMapper;
 import com.sckw.slope.detection.dao.tdengine.SlopeDataMapper;
 import com.sckw.slope.detection.model.dos.mysql.*;
 import com.sckw.slope.detection.model.dos.tdengine.Devices;
@@ -26,23 +30,21 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
-import java.time.LocalDateTime;
-import java.time.ZoneOffset;
+import java.time.*;
 import java.util.*;
 import java.util.stream.Collectors;
 
 /**
  * @author lfdc
  * @description
- * @date 2023-11-18 16:11:36
+ * @date 2023-10-26 08:10:45
  */
 @Slf4j
-@Service
-public class MqttCallbackHandler {
+@Service("system/iot/deviceDataSlopeDemo")
+public class MqttCallbackHandler extends AbstractHandler {
 
     @Value("${sms.url}")
     private String messageUrl;
@@ -65,17 +67,26 @@ public class MqttCallbackHandler {
     @Autowired
     HandlerFactory handlerFactory;
 
-    @Transactional
+    @TraceLog(description = "处理system/iot/device_data_slope")
+    @DSTransactional
     public HttpResult handle(String topic, String payload) {
         // 根据topic分别进行消息处理。
         log.info("MqttDeviceCallbackHandler:" + topic + "|" + payload);
-        System.out.println("处理sharjeck/ai/test/out");
+        System.out.println("system/iot/device_data_slope");
+        DevicesAlarm devicesAlarm = JSONObject.parseObject(payload, DevicesAlarm.class);
+        Map<String, SystemDict> dictByDictCode = commonService.getDictByDictCode(DictEnum.MODEL_PART);
+        JSONObject objects = JSONObject.parseObject(payload);
+        String deviceTs = objects.getString("ts");
+        String deviceGuid = objects.getString("guid");
+        String deviceTslverId = objects.getString("tslver_id");
+        String deviceMsgId = objects.getString("msg_id");
+        String deviceRawTs = objects.getString("raw_ts");
+        JSONArray checkArr = objects.getJSONArray("check_arr");
         try {
-            Map<String, SystemDict> dictByDictCode = commonService.getDictByDictCode(DictEnum.MODEL_PART);
-            DevicesAlarm devicesAlarm = JSONObject.parseObject(payload, DevicesAlarm.class);
+//            DevicesAlarm devicesAlarm = JSONObject.parseObject(payload, DevicesAlarm.class);
             String deviceCode = devicesAlarm.getGuid();
             List<KwsDevice> deviceList = deviceMapper.selectList(new LambdaQueryWrapper<KwsDevice>()
-                    .eq(KwsDevice::getSnCode, deviceCode)
+                    .eq(KwsDevice::getSnCodeFullName, deviceCode)
                     .eq(KwsDevice::getDelFlag, NumberConstant.ZERO)
             );
             KwsDevice device = null;
@@ -84,7 +95,7 @@ public class MqttCallbackHandler {
             }
             if (device == null) {
                 log.error("接收处理数据:{}", payload);
-                log.error("设备数据并未维护,不做处理");
+                log.error("设备数据并未维护+[" + devicesAlarm.getGuid() + "],不做处理");
                 return null;
             }
             List<DevicesItem> devicesItemList = devicesAlarm.getDevicesItemList();
@@ -101,6 +112,10 @@ public class MqttCallbackHandler {
                         continue;
                     }
                     Long ts = devicesAlarm.getTs();
+//                    //获取到是 十位 1700970600
+//                    if (Objects.nonNull(ts)) {
+//                        ts = ts * 1000;
+//                    }
                     //判断是否满足设备超时离线报警
                     checkDeviceAlarm(deviceCode, device, itemValue, ts);
                     //判断是否满足数值超阈值报警
@@ -109,7 +124,22 @@ public class MqttCallbackHandler {
                         Long level = Long.valueOf(map.get("level"));
                         Long thresholdId = Long.valueOf(map.get("thresholdId"));
                         //阈值表以及明细表存储
-                        insertAlarmAndDetail(level, device, thresholdId, itemValue, ts);
+                        long id = insertAlarmAndDetail(level, device, thresholdId, itemValue, ts, AlarmTitleEnum.ALARM_TITLE_TWO.getStatus(), AlarmTypeEnum.ALARM_ONE.getCode());
+                        //todo 不适用redis存统计  使用新字段处理
+                        /**阈值次数存redis*/
+//                        String key = Global.REDIS_SYS_ALARM_PREFIX + Global.POUND + String.valueOf(id) + Global.POUND + AlarmTypeEnum.ALARM_ONE.getStatus()
+//                                + Global.POUND + AlarmTitleEnum.ALARM_TITLE_TWO.getStatus();
+//                        String number = RedissonUtils.getString(key);
+//                        Long count = alarmDetailMapper.selectCount(new LambdaQueryWrapper<KwsAlarmDetail>()
+//                                .eq(KwsAlarmDetail::getAlarmId, id)
+//                                .eq(KwsAlarmDetail::getStatus, 0)
+//                        );
+//                        if (StringUtils.isBlank(number)) {
+//                            RedissonUtils.putString(key, "1", Global.COMMON_EXPIRE);
+//                        } else {
+//                            RedissonUtils.putString(key, count.toString(), Global.COMMON_EXPIRE);
+//                        }
+
                         /*【露天矿山边坡监测系统】尊敬的管理员,2023-10-01 12:23:34监测到一级告警。
                             设备名称:位移监测设备-gnss一号机,监测数值:55。123456789N,请尽快处理问题。*/
                         Map<String, Object> messageMap = new HashMap<>();
@@ -164,25 +194,26 @@ public class MqttCallbackHandler {
 
     }
 
-    @Autowired
-    DevicesMapper devicesMapper;
-
     private void checkDeviceAlarm(String deviceCode, KwsDevice device, String itemValue, Long ts) {
-        Devices devices = tdengineService.selectLastData(deviceCode);
-        if (devices != null) {
-            Date deviceTime = devices.getTs();
-            Date date = new Date();
-            long diff = Math.abs(date.getTime() - deviceTime.getTime());
-            long diffHours = diff / (60 * 60 * 1000) % 24;
-            if (diffHours > 24) {
-                insertAlarmAndDetail(1L, device, device.getId(), itemValue, ts);
-                // todo 暂未设备告警电话,设备告警不推送短信
-                device.setOnline(1);
-                deviceMapper.updateById(device);
-            } else {
-                device.setOnline(0);
-                deviceMapper.updateById(device);
+        try {
+            Devices devices = tdengineService.selectLastData(device.getSnCode());
+            if (devices != null) {
+                Date deviceTime = devices.getTs();
+                Date date = new Date();
+                long diff = Math.abs(date.getTime() - deviceTime.getTime());
+                long diffHours = diff / (60 * 60 * 1000) % 24;
+                if (diffHours > 24) {
+                    long id = insertAlarmAndDetail(1L, device, device.getId(), itemValue, ts, AlarmTitleEnum.ALARM_TITLE_ONE.getStatus(), AlarmTypeEnum.ALARM_TWO.getCode());
+                    // todo 暂未设备告警电话,设备告警不推送短信
+                    device.setOnline(1);
+                    deviceMapper.updateById(device);
+                } else {
+                    device.setOnline(0);
+                    deviceMapper.updateById(device);
+                }
             }
+        } catch (Exception e) {
+            log.error("判断是否满足设备超时离线报警 error ", e.getMessage(), e);
         }
     }
 
@@ -227,6 +258,17 @@ public class MqttCallbackHandler {
             Map<String, Long> minMap = new HashMap<>();
             List<BigDecimal> maxList = new ArrayList<>();
             List<BigDecimal> minList = new ArrayList<>();
+            //添加阈值map
+            for (KwsThreshold kwsThreshold : kwsThresholds) {
+                String max = kwsThreshold.getMax();
+                Long thresholdId = kwsThreshold.getId();
+                String min = kwsThreshold.getMin();
+                Integer level = kwsThreshold.getLevel();
+                maxMap.put(max, level.longValue());
+                maxMap.put(level.toString(), thresholdId.longValue());
+                minMap.put(min, level.longValue());
+                minMap.put(level.toString(), thresholdId.longValue());
+            }
             for (KwsThreshold kwsThreshold : kwsThresholds) {
                 maxList.add(new BigDecimal(kwsThreshold.getMax()));
                 minList.add(new BigDecimal(kwsThreshold.getMin()));
@@ -261,9 +303,9 @@ public class MqttCallbackHandler {
             map.put("level", "1");
             map.put("thresholdId", "1");
             map.put("flag", "1");
-            if (min != null && max != null) {
+            if (min != null || max != null) {
                 if (max != null) {
-                    Long level = maxMap.get(max);
+                    Long level = maxMap.get(max.toString());
                     Long thresholdId = maxMap.get(level.toString());
                     map.put("level", level.toString());
                     map.put("thresholdId", thresholdId.toString());
@@ -271,7 +313,7 @@ public class MqttCallbackHandler {
 //                    insertAlarmAndDetail(level, device, thresholdId, itemValue, ts);
                 }
                 if (min != null) {
-                    Long level = minMap.get(min);
+                    Long level = minMap.get(min.toString());
                     Long thresholdId = minMap.get(level.toString());
                     map.put("level", level.toString());
                     map.put("thresholdId", thresholdId.toString());
@@ -285,6 +327,16 @@ public class MqttCallbackHandler {
             Map<String, Long> minMap = new HashMap<>();
             List<BigDecimal> maxList = new ArrayList<>();
             List<BigDecimal> minList = new ArrayList<>();
+            for (KwsThreshold kwsThreshold : kwsThresholds) {
+                String max = kwsThreshold.getMax();
+                Long thresholdId = kwsThreshold.getId();
+                String min = kwsThreshold.getMin();
+                Integer level = kwsThreshold.getLevel();
+                maxMap.put(max, level.longValue());
+                maxMap.put(level.toString(), thresholdId.longValue());
+                minMap.put(min, level.longValue());
+                minMap.put(level.toString(), thresholdId.longValue());
+            }
             for (KwsThreshold kwsThreshold : kwsThresholds) {
                 maxList.add(new BigDecimal(kwsThreshold.getMax()));
                 minList.add(new BigDecimal(kwsThreshold.getMin()));
@@ -348,20 +400,78 @@ public class MqttCallbackHandler {
      * @param thresholdId 阈值id/设备id
      * @param itemValue   td数据当时检测值
      * @param ts          td时间
+     * @param alarmTitle  设备类型明细
+     * @param type        设备类型
      */
-    private void insertAlarmAndDetail(Long level, KwsDevice device, Long thresholdId, String itemValue, Long ts) {
+    private long insertAlarmAndDetail(Long level, KwsDevice device, Long thresholdId,
+                                      String itemValue, Long ts,
+                                      String alarmTitle, Integer type
+    ) {
         Long deviceId = device.getId();
         KwsProjectDevice projectDevice = projectDeviceMapper.selectOne(new LambdaQueryWrapper<KwsProjectDevice>()
                 .eq(KwsProjectDevice::getDeviceId, deviceId)
                 .eq(KwsProjectDevice::getDelFlag, 0)
-                .eq(KwsProjectDevice::getStatus, 0)
                 .orderByDesc(KwsProjectDevice::getCreateTime)
                 .last(" limit 1")
         );
+        //新增未读数据
+        long alarmId = insertUnread(level, device, thresholdId, itemValue, ts, alarmTitle, type, deviceId, projectDevice);
+        //新增历史数据
+        insertHistoryRead(level, device, thresholdId, itemValue, ts, alarmTitle, type, deviceId, projectDevice);
+
+        return alarmId;
+    }
+
+    private void insertHistoryRead(Long level, KwsDevice device, Long thresholdId, String itemValue, Long ts, String alarmTitle, Integer type, Long deviceId, KwsProjectDevice projectDevice) {
         LambdaQueryWrapper<KwsAlarm> wrapper = new LambdaQueryWrapper<KwsAlarm>()
                 .eq(KwsAlarm::getLevel, level.intValue())
                 .eq(KwsAlarm::getDeviceId, deviceId)
-                .eq(KwsAlarm::getType, NumberConstant.ONE)
+                .eq(KwsAlarm::getStatus, NumberConstant.ONE)
+                .eq(KwsAlarm::getType, type)
+                .orderByDesc(KwsAlarm::getCreateTime);
+        if (projectDevice != null) {
+            wrapper.eq(KwsAlarm::getProjectId, projectDevice.getProjectId())
+                    .eq(KwsAlarm::getMountainId, projectDevice.getMountainId());
+            if (projectDevice.getProjectId() != null) {
+                wrapper.eq(KwsAlarm::getCompanyId, projectDevice.getCompanyId());
+            }
+        }
+        long alarmId = new IdWorker(NumberConstant.ONE).nextId();
+        List<KwsAlarm> alarms = alarmMapper.selectList(wrapper);
+        if (CollectionUtils.isEmpty(alarms)) {
+            KwsAlarm alarm = new KwsAlarm();
+            String mountainId = projectDevice == null ? null : projectDevice.getMountainId();
+            String companyId = projectDevice == null ? null : projectDevice.getCompanyId();
+            String projectId = projectDevice == null ? null :
+                    (projectDevice.getProjectId() == null ? null : projectDevice.getProjectId().toString());
+            alarm.setId(alarmId);
+            alarm.setCompanyId(companyId);
+            alarm.setMountainId(mountainId);
+            alarm.setProjectId(projectId);
+            alarm.setDeviceId(deviceId);
+            alarm.setTitle(alarmTitle);
+            alarm.setLevel(level.intValue());
+            alarm.setType(type);
+            LocalDateTime localDateTime = Instant.ofEpochSecond(ts).atZone(ZoneId.systemDefault()).toLocalDateTime();
+            alarm.setCreateTime(localDateTime);
+            alarm.setUpdateTime(localDateTime);
+            alarm.setStatus(1);
+            alarm.setTriggerTimes(0);
+            alarm.setIsHistory(1);
+            alarmMapper.insert(alarm);
+        }
+    }
+
+    private long insertUnread(Long level, KwsDevice device, Long thresholdId,
+                              String itemValue, Long ts,
+                              String alarmTitle, Integer type, Long deviceId, KwsProjectDevice projectDevice) {
+        LambdaQueryWrapper<KwsAlarm> wrapper = new LambdaQueryWrapper<KwsAlarm>()
+                .eq(KwsAlarm::getLevel, level.intValue())
+                .eq(KwsAlarm::getDeviceId, deviceId)
+                .eq(KwsAlarm::getStatus, NumberConstant.ZERO)
+                .eq(KwsAlarm::getType, type)
+                .eq(KwsAlarm::getIsHistory, NumberConstant.ZERO)
+                .eq(KwsAlarm::getDelFlag, NumberConstant.ZERO)
                 .orderByDesc(KwsAlarm::getCreateTime);
         if (projectDevice != null) {
             wrapper.eq(KwsAlarm::getProjectId, projectDevice.getProjectId())
@@ -370,10 +480,10 @@ public class MqttCallbackHandler {
                 wrapper.eq(KwsAlarm::getCompanyId, projectDevice.getCompanyId());
             }
         }
+        long alarmId = new IdWorker(NumberConstant.ONE).nextId();
         List<KwsAlarm> alarms = alarmMapper.selectList(wrapper);
         if (CollectionUtils.isEmpty(alarms)) {
             KwsAlarm alarm = new KwsAlarm();
-            long alarmId = new IdWorker(NumberConstant.ONE).nextId();
             String mountainId = projectDevice == null ? null : projectDevice.getMountainId();
             String companyId = projectDevice == null ? null : projectDevice.getCompanyId();
             String projectId = projectDevice == null ? null :
@@ -383,13 +493,15 @@ public class MqttCallbackHandler {
             alarm.setMountainId(mountainId);
             alarm.setProjectId(projectId);
             alarm.setDeviceId(deviceId);
-            alarm.setTitle("2");
+            alarm.setTitle(alarmTitle);
             alarm.setLevel(level.intValue());
-            alarm.setType(2);
-            LocalDateTime localDateTime = new Date(ts).toInstant().atOffset(ZoneOffset.of("+8")).toLocalDateTime();
+            alarm.setType(type);
+            LocalDateTime localDateTime = Instant.ofEpochSecond(ts).atZone(ZoneId.systemDefault()).toLocalDateTime();
+//            LocalDateTime localDateTime = new Date(ts).toInstant().atOffset(ZoneOffset.of("+8")).toLocalDateTime();
             alarm.setCreateTime(localDateTime);
             alarm.setUpdateTime(localDateTime);
             alarm.setStatus(0);
+            alarm.setTriggerTimes(1);
             alarmMapper.insert(alarm);
             KwsAlarmDetail alarmDetail = new KwsAlarmDetail();
             alarmDetail.setId(new IdWorker(NumberConstant.ONE).nextId());
@@ -399,18 +511,51 @@ public class MqttCallbackHandler {
             alarmDetail.setPid(thresholdId);
             alarmDetail.setVal(itemValue);
             alarmDetail.setLat(device.getLogicLat());
-            alarmDetail.setLng(device.getLogicAlt());
+            alarmDetail.setLng(device.getLogicLng());
             alarmDetail.setAlt(device.getLogicAlt());
             alarmDetail.setCreateTime(localDateTime);
             alarmDetail.setUpdateTime(localDateTime);
             alarmDetail.setStatus(0);
+            alarmDetail.setDelFlag(NumberConstant.ZERO);
+            alarmDetail.setIsHistory(NumberConstant.ZERO);
             alarmDetailMapper.insert(alarmDetail);
         } else {
+            alarmId = alarms.get(0).getId();
             KwsAlarm alarm = alarms.get(0);
-            LocalDateTime localDateTime = new Date(ts).toInstant().atOffset(ZoneOffset.of("+8")).toLocalDateTime();
+            LocalDateTime localDateTime = Instant.ofEpochSecond(ts).atZone(ZoneId.systemDefault()).toLocalDateTime();
+//            LocalDateTime localDateTime = new Date(ts).toInstant().atOffset(ZoneOffset.of("+8")).toLocalDateTime();
             alarm.setUpdateTime(localDateTime);
+            alarm.setStatus(0);
+            Long aLong = alarmDetailMapper.selectCount(new LambdaQueryWrapper<KwsAlarmDetail>()
+                    .eq(KwsAlarmDetail::getAlarmId, alarmId)
+                    .eq(KwsAlarmDetail::getStatus, 0)
+                    .eq(KwsAlarmDetail::getIsHistory, 0)
+                    .eq(KwsAlarmDetail::getDelFlag, 0)
+            );
+            alarm.setTriggerTimes(aLong.intValue() + 1);
             alarmMapper.updateById(alarm);
+            String mountainId = projectDevice == null ? null : projectDevice.getMountainId();
+            String companyId = projectDevice == null ? null : projectDevice.getCompanyId();
+            String projectId = projectDevice == null ? null :
+                    (projectDevice.getProjectId() == null ? null : projectDevice.getProjectId().toString());
+            KwsAlarmDetail alarmDetail = new KwsAlarmDetail();
+            alarmDetail.setId(new IdWorker(NumberConstant.TWO).nextId());
+            alarmDetail.setMountainId(mountainId);
+            alarmDetail.setCompanyId(companyId);
+            alarmDetail.setAlarmId(alarm.getId());
+            alarmDetail.setPid(thresholdId);
+            alarmDetail.setVal(itemValue);
+            alarmDetail.setLat(device.getLogicLat());
+            alarmDetail.setLng(device.getLogicLng());
+            alarmDetail.setAlt(device.getLogicAlt());
+            alarmDetail.setCreateTime(localDateTime);
+            alarmDetail.setUpdateTime(localDateTime);
+            alarmDetail.setStatus(0);
+            alarmDetail.setDelFlag(NumberConstant.ZERO);
+            alarmDetail.setIsHistory(NumberConstant.ZERO);
+            alarmDetailMapper.insert(alarmDetail);
         }
+        return alarmId;
     }
 
     /**
@@ -439,21 +584,30 @@ public class MqttCallbackHandler {
     }
 
     public static void main(String[] args) {
+
+        Long ts = 1700969880l;
+        Instant timestamp = Instant.ofEpochSecond(ts);
+
+        ts = ts * 1000;
+        Instant instant = new Date(ts).toInstant();
+        OffsetDateTime offsetDateTime = instant.atOffset(ZoneOffset.of("+8"));
+        LocalDateTime timeLocalDateTime = offsetDateTime.toLocalDateTime();
+
+        instant = Instant.ofEpochMilli(ts);
+        ZonedDateTime zonedDateTime = instant.atZone(ZoneId.systemDefault());
+        LocalDateTime localDateTimes = zonedDateTime.toLocalDateTime();
+        System.out.println(localDateTimes);
+
+        String aaa = "{\"ts\":1700808976,\"guid\":\"0838161D-4C64-EC3E-A3A8-C736C47D93D4\",\"tslver_id\":\"3\",\"msg_id\":\"586569123094614016\",\"raw_ts\":\"\",\"check_arr\":[{\"itemName\":\"lng\",\"itemValue\":\"103.51826198069217\"},{\"itemName\":\"lat\",\"itemValue\":\"29.46725728245242\"},{\"itemName\":\"high\",\"itemValue\":\"710.1730218537282\"},{\"itemName\":\"fix\",\"itemValue\":4015},{\"itemName\":\"e\",\"itemValue\":\"302.7644742928626\"},{\"itemName\":\"n\",\"itemValue\":\"711.0632664506148\"},{\"itemName\":\"u\",\"itemValue\":\"-271.97856155098333\"},{\"itemName\":\"num\",\"itemValue\":7200},{\"itemName\":\"time\",\"itemValue\":\"2023-11-0818:00:00\"}]}";
         DevicesAlarm alarm = new DevicesAlarm();
-        alarm.setGuid("s8");
         List<DevicesItem> list = new ArrayList<>();
         DevicesItem item = new DevicesItem();
         item.setItemName("alt");
         item.setItemValue("20.12646584");
         long time = new Date().getTime();
-//        item.setTs(new Date().getTime());
         String md5 = new MD5Utils().getMd5(String.valueOf(time));
-//        item.setGuid(md5);
         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         String format = simpleDateFormat.format(new Date());
-//        item.setTslverId(format);
-//        item.setMsgId(format);
-//        item.setRawTs(format);
         list.add(item);
         alarm.setDevicesItemList(list);
         String demoTest = "{\"deviceCode\":\"s8\",\"devicesItemList\":[{\"guid\":\"c7653b298bec06eb78be3140b5c2ea9b\",\"itemName\":\"alt\",\"itemValue\":\"20.12646584\",\"msg_id\":\"2023-11-18 14:49:06\",\"raw_ts\":\"2023-11-18 14:49:06\",\"ts\":1700290146508,\"tslver_Id\":\"2023-11-18 14:49:06\"}]}";
@@ -474,3 +628,4 @@ public class MqttCallbackHandler {
         System.out.println(min);
     }
 }
+

+ 2 - 2
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/consumer/MqttDeviceCallbackHandler.java

@@ -43,7 +43,7 @@ import java.util.stream.Collectors;
  * @date 2023-10-26 08:10:45
  */
 @Slf4j
-@Service("system/iot/device_data_slope")
+@Service("system/iot/device_data_slope_demo")
 public class MqttDeviceCallbackHandler extends AbstractHandler {
 
     @Value("${sms.url}")
@@ -432,7 +432,7 @@ public class MqttDeviceCallbackHandler extends AbstractHandler {
                 .eq(KwsAlarm::getLevel, level.intValue())
                 .eq(KwsAlarm::getDeviceId, deviceId)
                 .eq(KwsAlarm::getStatus, NumberConstant.ZERO)
-                .eq(KwsAlarm::getType, NumberConstant.ONE)
+                .eq(KwsAlarm::getType, type)
                 .orderByDesc(KwsAlarm::getCreateTime);
         if (projectDevice != null) {
             wrapper.eq(KwsAlarm::getProjectId, projectDevice.getProjectId())

+ 20 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/dao/mysql/KwsAlarmDetailHistoryMapper.java

@@ -0,0 +1,20 @@
+package com.sckw.slope.detection.dao.mysql;
+
+import com.baomidou.dynamic.datasource.annotation.DS;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.sckw.slope.detection.model.dos.mysql.KwsAlarmDetailHistory;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+@DS("mysql")
+public interface KwsAlarmDetailHistoryMapper extends BaseMapper<KwsAlarmDetailHistory> {
+    int deleteByPrimaryKey(Long id);
+
+    int insertSelective(KwsAlarmDetailHistory record);
+
+    KwsAlarmDetailHistory selectByPrimaryKey(Long id);
+
+    int updateByPrimaryKeySelective(KwsAlarmDetailHistory record);
+
+    int updateByPrimaryKey(KwsAlarmDetailHistory record);
+}

+ 10 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dos/mysql/KwsAlarm.java

@@ -72,6 +72,16 @@ public class KwsAlarm implements Serializable {
      */
     private int status;
 
+    /**
+     * 状态
+     */
+    private int isHistory;
+
+    /**
+     * 状态
+     */
+    private int delFlag;
+
     private static final long serialVersionUID = 1L;
 
 }

+ 10 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dos/mysql/KwsAlarmDetail.java

@@ -65,5 +65,15 @@ public class KwsAlarmDetail implements Serializable {
      */
     private int status;
 
+    /**
+     * 状态
+     */
+    private int isHistory;
+
+    /**
+     * 状态
+     */
+    private int delFlag;
+
     private static final long serialVersionUID = 1L;
 }

+ 79 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dos/mysql/KwsAlarmDetailHistory.java

@@ -0,0 +1,79 @@
+package com.sckw.slope.detection.model.dos.mysql;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
+/**
+ * 告警详情
+ */
+@Data
+@TableName("kws_alarm_detail_history")
+public class KwsAlarmDetailHistory implements Serializable {
+
+    private Long id;
+
+
+    private String mountainId;
+
+
+    private String companyId;
+
+//    private Long projectId;
+
+    /**
+     * 告警id
+     */
+    private Long alarmId;
+
+    private Long pid;
+
+    private String val;
+
+    /**
+     * 纬度
+     */
+
+    private String lat;
+
+    /**
+     * 经度
+     */
+
+    private String lng;
+
+    /**
+     * 海拔
+     */
+
+    private String alt;
+
+    /**
+     * 创建时间
+     */
+    private LocalDateTime createTime;
+
+    /**
+     * 修改时间
+     */
+    private LocalDateTime updateTime;
+
+    /**
+     * 状态
+     */
+    private int status;
+
+    /**
+     * 状态
+     */
+    private int isHistory;
+
+    /**
+     * 状态
+     */
+    private int delFlag;
+
+    private static final long serialVersionUID = 1L;
+}

+ 10 - 4
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/excel/ThresholdRecordDetailExportVO.java

@@ -1,7 +1,9 @@
 package com.sckw.slope.detection.model.vo.excel;
 
+import com.alibaba.excel.annotation.ExcelIgnore;
 import com.alibaba.excel.annotation.ExcelProperty;
 import com.fasterxml.jackson.annotation.JsonFormat;
+import com.sckw.excel.annotation.ExcelContext;
 import lombok.Data;
 
 import java.io.Serializable;
@@ -13,26 +15,30 @@ import java.time.LocalDateTime;
  * @date 2023-11-14 14:11:06
  */
 @Data
+@ExcelContext(fileName = "告警记录明细", sheetName = "告警记录明细")
 public class ThresholdRecordDetailExportVO implements Serializable {
     /**
      * ID
      */
+    @ExcelIgnore
     private Long id;
     /**
-     * 告警类型
+     * 告警等级
      */
-    @ExcelProperty("告警类型")
+    @ExcelProperty("告警等级")
     private String alarmLevel;
     /**
-     * 监测类型
+     * 监测要素
      */
+    @ExcelProperty("监测要素")
     private String type;
     /**
      * 当前测量值
      */
     @ExcelProperty("当前测量值")
     private String value;
-    @ExcelProperty("监测要素")
+//    @ExcelProperty("监测要素")
+    @ExcelIgnore
     private String itemName;
     /**
      * 通知短信

+ 151 - 12
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/KwsAlarmService.java

@@ -6,11 +6,13 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import com.sckw.core.exception.BusinessException;
+import com.sckw.core.model.constant.NumberConstant;
 import com.sckw.core.model.enums.DictEnum;
 import com.sckw.core.model.enums.DictItemEnum;
 import com.sckw.core.model.page.PageRes;
 import com.sckw.core.model.vo.BaseList;
 import com.sckw.core.model.vo.PublicBaseList;
+import com.sckw.core.utils.IdWorker;
 import com.sckw.core.web.response.HttpResult;
 import com.sckw.slope.detection.dao.mysql.*;
 import com.sckw.slope.detection.dao.tdengine.DevicesMapper;
@@ -122,7 +124,9 @@ public class KwsAlarmService {
 
         LambdaQueryWrapper<KwsAlarm> wrapper = new LambdaQueryWrapper<>();
         wrapper.eq(StringUtils.isNotBlank(headerData.getMountainId()), KwsAlarm::getMountainId, headerData.getMountainId())
-                .eq(KwsAlarm::getStatus, query.getStatus());
+                .eq(KwsAlarm::getStatus, query.getStatus())
+                .gt(KwsAlarm::getTriggerTimes, 0)
+        ;
         if (StringUtils.isNotBlank(query.getProjectId())) {
             wrapper.eq(KwsAlarm::getProjectId, Long.parseLong(query.getProjectId()));
         }
@@ -165,22 +169,142 @@ public class KwsAlarmService {
         return PageRes.build(info, alarmVOS);
     }
 
-    public HttpResult read(BaseList baseList, HttpServletRequest request) {
+    @Autowired
+    KwsAlarmDetailHistoryMapper historyMapper;
+
+    @Autowired
+    KwsProjectDeviceMapper projectDeviceMapper;
+
+
+    public HttpResult read1(BaseList baseList, HttpServletRequest request) {
         String ids = baseList.getIds();
         List<Long> list = com.sckw.core.utils.StringUtils.splitStrToList(ids, Long.class);
         list.forEach(id -> {
-            int update = alarmMapper.update(null, new LambdaUpdateWrapper<KwsAlarm>()
-                    .set(KwsAlarm::getStatus, 1)
-                    .eq(KwsAlarm::getId, id)
+            KwsAlarm alarm = alarmMapper.selectById(id);
+            /**历史表新增数据*/
+            LambdaQueryWrapper<KwsAlarm> wrapper = new LambdaQueryWrapper<KwsAlarm>()
+                    .eq(KwsAlarm::getLevel, alarm.getLevel())
+                    .eq(KwsAlarm::getDeviceId, alarm.getDeviceId())
+                    .eq(KwsAlarm::getStatus, NumberConstant.ZERO)
+                    .eq(KwsAlarm::getType, alarm.getType())
+                    .eq(KwsAlarm::getProjectId, alarm.getProjectId())
+                    .eq(KwsAlarm::getMountainId, alarm.getMountainId())
+                    .eq(KwsAlarm::getCompanyId, alarm.getCompanyId())
+                    .orderByDesc(KwsAlarm::getCreateTime);
+            List<KwsAlarm> alarms = alarmMapper.selectList(wrapper);
+            List<KwsAlarmDetail> details = alarmDetailMapper.selectList(new LambdaUpdateWrapper<KwsAlarmDetail>()
+                    .eq(KwsAlarmDetail::getDelFlag, 0)
+                    .eq(KwsAlarmDetail::getAlarmId, alarm.getId())
             );
+            /**修改当前数据为已读*/
+            Integer historyCount = alarm.getTriggerTimes();
+            alarm.setTriggerTimes(0);
+            alarmMapper.updateById(alarm);
             alarmDetailMapper.update(null, new LambdaUpdateWrapper<KwsAlarmDetail>()
                     .set(KwsAlarmDetail::getStatus, 1)
                     .eq(KwsAlarmDetail::getAlarmId, id)
             );
+
         });
         return HttpResult.ok("消息已读");
     }
 
+    public HttpResult read(BaseList baseList, HttpServletRequest request) {
+        String ids = baseList.getIds();
+        List<Long> list = com.sckw.core.utils.StringUtils.splitStrToList(ids, Long.class);
+        for (Long id : list) {
+            KwsAlarm alarm = alarmMapper.selectById(id);
+            /**前端误调用 进行排除*/
+            if (1 == alarm.getIsHistory()) {
+                continue;
+            }
+            Integer historyCount = alarm.getTriggerTimes();
+            List<KwsAlarmDetail> details = alarmDetailMapper.selectList(new LambdaUpdateWrapper<KwsAlarmDetail>()
+                    .eq(KwsAlarmDetail::getIsHistory, 0)
+                    .eq(KwsAlarmDetail::getDelFlag, 0)
+                    .eq(KwsAlarmDetail::getAlarmId, alarm.getId())
+            );
+            /**历史触发次数累积*/
+            KwsAlarm historyAlarm = alarmMapper.selectOne(new LambdaQueryWrapper<KwsAlarm>()
+                    .eq(KwsAlarm::getStatus, 1)
+                    .eq(KwsAlarm::getType, alarm.getType())
+                    .eq(KwsAlarm::getLevel, alarm.getLevel())
+                    .eq(KwsAlarm::getMountainId, alarm.getMountainId())
+                    .eq(KwsAlarm::getProjectId, alarm.getProjectId())
+                    .eq(KwsAlarm::getDeviceId, alarm.getDeviceId())
+                    .eq(KwsAlarm::getCompanyId, alarm.getCompanyId())
+                    .eq(KwsAlarm::getIsHistory, NumberConstant.ONE)
+            );
+            if (historyAlarm != null) {
+                alarmMapper.update(null, new LambdaUpdateWrapper<KwsAlarm>()
+                        .set(KwsAlarm::getStatus, 1)
+                        .set(KwsAlarm::getTriggerTimes, historyAlarm.getTriggerTimes() + historyCount)
+                        .set(KwsAlarm::getUpdateTime, LocalDateTime.now())
+                        .eq(KwsAlarm::getId, historyAlarm.getId())
+                );
+                details.forEach(alarmDetail -> {
+                    KwsAlarmDetail historyAlarmDetail = new KwsAlarmDetail();
+                    historyAlarmDetail.setId(new IdWorker(NumberConstant.ONE).nextId());
+                    historyAlarmDetail.setMountainId(alarmDetail.getMountainId());
+                    historyAlarmDetail.setCompanyId(alarmDetail.getCompanyId());
+                    historyAlarmDetail.setAlarmId(historyAlarm.getId());
+                    historyAlarmDetail.setPid(alarmDetail.getPid());
+                    historyAlarmDetail.setVal(alarmDetail.getVal());
+                    historyAlarmDetail.setLat(alarmDetail.getLat());
+                    historyAlarmDetail.setLng(alarmDetail.getLng());
+                    historyAlarmDetail.setAlt(alarmDetail.getAlt());
+                    historyAlarmDetail.setCreateTime(alarmDetail.getCreateTime());
+                    historyAlarmDetail.setUpdateTime(alarmDetail.getUpdateTime());
+                    historyAlarmDetail.setStatus(1);
+                    historyAlarmDetail.setIsHistory(1);
+                    historyAlarmDetail.setDelFlag(0);
+                    alarmDetailMapper.insert(historyAlarmDetail);
+                });
+            } else {
+                KwsAlarm newAlarm = new KwsAlarm();
+                BeanUtils.copyProperties(alarm, newAlarm);
+                long alarmId = new IdWorker(NumberConstant.ONE).nextId();
+                newAlarm.setStatus(1);
+                newAlarm.setIsHistory(1);
+                newAlarm.setDelFlag(0);
+                newAlarm.setId(alarmId);
+                newAlarm.setCreateTime(LocalDateTime.now());
+                newAlarm.setUpdateTime(LocalDateTime.now());
+                alarmMapper.updateById(newAlarm);
+
+                details.forEach(alarmDetail -> {
+                    KwsAlarmDetail historyAlarmDetail = new KwsAlarmDetail();
+                    historyAlarmDetail.setId(new IdWorker(NumberConstant.ONE).nextId());
+                    historyAlarmDetail.setMountainId(alarmDetail.getMountainId());
+                    historyAlarmDetail.setCompanyId(alarmDetail.getCompanyId());
+                    historyAlarmDetail.setAlarmId(alarmId);
+                    historyAlarmDetail.setPid(alarmDetail.getPid());
+                    historyAlarmDetail.setVal(alarmDetail.getVal());
+                    historyAlarmDetail.setLat(alarmDetail.getLat());
+                    historyAlarmDetail.setLng(alarmDetail.getLng());
+                    historyAlarmDetail.setAlt(alarmDetail.getAlt());
+                    historyAlarmDetail.setCreateTime(alarmDetail.getCreateTime());
+                    historyAlarmDetail.setUpdateTime(alarmDetail.getUpdateTime());
+                    historyAlarmDetail.setStatus(1);
+                    historyAlarmDetail.setIsHistory(1);
+                    historyAlarmDetail.setDelFlag(0);
+                    alarmDetailMapper.insert(historyAlarmDetail);
+                });
+
+            }
+            /**修改当前数据为已读*/
+            alarm.setTriggerTimes(0);
+            alarmMapper.updateById(alarm);
+            alarmDetailMapper.update(null, new LambdaUpdateWrapper<KwsAlarmDetail>()
+                    .eq(KwsAlarmDetail::getAlarmId, id)
+                    .set(KwsAlarmDetail::getStatus, NumberConstant.ONE)
+                    .set(KwsAlarmDetail::getDelFlag, NumberConstant.ONE)
+            );
+        }
+        return HttpResult.ok("消息已读");
+    }
+
+
     public List<KwsAlarmExportVO> export(AlarmLogThresholdExport query, HttpServletRequest request, HttpServletResponse response) {
         List<Long> idsList = null;
         String ids = query.getIds();
@@ -190,7 +314,11 @@ public class KwsAlarmService {
         HeaderData headerData = commonService.getHeaderData(request);
         LambdaQueryWrapper<KwsAlarm> wrapper = new LambdaQueryWrapper<>();
         wrapper.eq(StringUtils.isNotBlank(headerData.getMountainId()), KwsAlarm::getMountainId, headerData.getMountainId())
-                .eq(KwsAlarm::getStatus, query.getStatus()).orderByDesc(KwsAlarm::getCreateTime)
+                .eq(KwsAlarm::getStatus, query.getStatus())
+                .eq(KwsAlarm::getIsHistory, query.getStatus())
+                .eq(KwsAlarm::getDelFlag, 0)
+                .gt(KwsAlarm::getTriggerTimes, 0)
+                .orderByDesc(KwsAlarm::getCreateTime)
         ;
         if (StringUtils.isNotBlank(query.getProjectId())) {
             wrapper.eq(KwsAlarm::getProjectId, Long.parseLong(query.getProjectId()));
@@ -248,8 +376,9 @@ public class KwsAlarmService {
         KwsAlarm kwsAlarm = alarmMapper.selectById(id);
         PageHelper.startPage(baseList.getPage(), baseList.getPageSize());
         List<KwsAlarmDetail> detailList = alarmDetailMapper.selectList(new LambdaQueryWrapper<KwsAlarmDetail>()
-                .eq(KwsAlarmDetail::getAlarmId, Long.parseLong(id))
-                .eq(KwsAlarmDetail::getStatus, 0)
+                        .eq(KwsAlarmDetail::getAlarmId, Long.parseLong(id))
+                        .eq(KwsAlarmDetail::getDelFlag, 0)
+//                .eq(KwsAlarmDetail::getStatus, 0)
         );
         PageInfo<ThresholdRecordDetailVO> info = new PageInfo(detailList);
         if (CollectionUtils.isEmpty(detailList)) {
@@ -344,7 +473,7 @@ public class KwsAlarmService {
             KwsDeviceReference deviceReference = deviceReferenceMapper.selectOne(new LambdaQueryWrapper<KwsDeviceReference>()
                     .eq(KwsDeviceReference::getDelFlag, 0)
                     .eq(KwsDeviceReference::getDeviceId, deviceId)
-                    .eq(KwsDeviceReference::getItem, itemName)
+                    .eq(KwsDeviceReference::getItem, kwsThreshold.getItemName())
             );
             KwsDevice device = deviceMapper.selectById(deviceId);
             if (device == null) {
@@ -368,7 +497,7 @@ public class KwsAlarmService {
             vo.setLastReferenceValue(deviceReference == null ? null : deviceReference.getCurrentValue());
             if (devices != null) {
                 String val = devices.getVal();
-                if (list.contains(itemName)) {
+                if (list.contains(kwsThreshold.getItemName())) {
                     if (deviceReference != null) {
                         BigDecimal computeOffset = commonService.computeOffset(val, kwsThreshold.getItemName(), deviceReference);
                         BigDecimal computeOriginalOffset = commonService.computeOriginalOffset(val, kwsThreshold.getItemName(), deviceReference);
@@ -388,7 +517,7 @@ public class KwsAlarmService {
         Map<String, SystemDict> typeDict = commonService.getDictByDictCode(DictEnum.ALARM_TYPE);
         Map<String, SystemDict> alarmDetailTypeDict = commonService.getDictByDictCode(DictEnum.ALARM_DETAIL_TYPE);
         vo.setAlarmType(kwsAlarm.getType() == null ? null :
-                (typeDict == null ? String.valueOf(kwsAlarm.getType()) : typeDict.get(String.valueOf(kwsAlarm.getType())).getValue()));
+                (typeDict == null ? String.valueOf(kwsAlarm.getType()) : typeDict.get(String.valueOf(kwsAlarm.getType())).getLabel()));
         vo.setAlarmLevel(kwsAlarm.getLevel() == null ? null :
                 (levelDict == null ? String.valueOf(kwsAlarm.getLevel()) : levelDict.get(String.valueOf(kwsAlarm.getLevel())).getLabel()));
         vo.setAlarmTitle(kwsAlarm.getTitle() == null ? null :
@@ -649,7 +778,17 @@ public class KwsAlarmService {
                 vo.setItemName(kwsThreshold.getItemName());
                 vo.setPhone(kwsThreshold.getPhones());
                 KwsDevice kwsDevice = deviceMapper.selectById(kwsThreshold.getDeviceId());
-                vo.setLocation(kwsDevice == null ? null : kwsDevice.getLogicAlt() + " " + kwsDevice.getLogicLat() + "" + kwsDevice.getLogicLng());
+                StringBuilder location = new StringBuilder();
+                if (StringUtils.isNotBlank(kwsDevice.getLogicAlt())){
+                    location.append(kwsDevice.getLogicAlt()).append(";");
+                }
+                if (StringUtils.isNotBlank(kwsDevice.getLogicLat())){
+                    location.append(kwsDevice.getLogicLat()).append(";");
+                }
+                if (StringUtils.isNotBlank(kwsDevice.getLogicLng())){
+                    location.append(kwsDevice.getLogicLng());
+                }
+                vo.setLocation(location.toString());
                 vo.setCreateTime(detail.getCreateTime());
                 list.add(vo);
             }

+ 3 - 2
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/ProjectService.java

@@ -57,6 +57,7 @@ import java.util.stream.Collectors;
 public class ProjectService {
 
     private static final Long equatorial_circumference = 40075020000L;
+    private static final Long LATITUDE_REFERENCE = 111000000L;
 
     @Autowired
     CommonService commonService;
@@ -759,7 +760,7 @@ public class ProjectService {
                                     if (Objects.nonNull(currentValue)) {
                                         if (org.apache.commons.lang3.StringUtils.isNotBlank(line)) {
                                             SlopeData selectListByLine = slopeDataMapper.selectListByLine(kwsDevice.getSnCode(), DictItemEnum.LATITUDE_Y.getValue());
-                                            offsetValue = selectListByLine == null ? new BigDecimal("0.00") : (new BigDecimal(selectListByLine.getVal()).subtract(currentValue));
+                                            offsetValue = selectListByLine == null ? new BigDecimal("0.00") : ((new BigDecimal(selectListByLine.getVal()).subtract(currentValue)).multiply(new BigDecimal(LATITUDE_REFERENCE)));
                                         }
                                     }
                                 }
@@ -1076,7 +1077,7 @@ public class ProjectService {
                                 if (Objects.nonNull(currentValue)) {
                                     SlopeData selectListByLine = slopeDataMapper.selectListByLine(kwsDevice.getSnCode(), DictItemEnum.LATITUDE_Y.getValue());
                                     if (org.apache.commons.lang3.StringUtils.isNotBlank(line)) {
-                                        offsetValue = selectListByLine == null ? new BigDecimal("0.00") : new BigDecimal(selectListByLine.getVal()).subtract(currentValue);
+                                        offsetValue = selectListByLine == null ? new BigDecimal("0.00") : ((new BigDecimal(selectListByLine.getVal()).subtract(currentValue)).multiply(new BigDecimal(LATITUDE_REFERENCE)));
                                     }
                                 }
                             }

+ 201 - 0
slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsAlarmDetailHistoryMapper.xml

@@ -0,0 +1,201 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.sckw.slope.detection.dao.mysql.KwsAlarmDetailHistoryMapper">
+  <resultMap id="BaseResultMap" type="com.sckw.slope.detection.model.dos.mysql.KwsAlarmDetailHistory">
+    <!--@mbg.generated-->
+    <!--@Table kws_alarm_detail_history-->
+    <id column="id" jdbcType="BIGINT" property="id" />
+    <result column="mountain_id" jdbcType="VARCHAR" property="mountainId" />
+    <result column="company_id" jdbcType="VARCHAR" property="companyId" />
+<!--    <result column="project_id" jdbcType="BIGINT" property="projectId" />-->
+    <result column="alarm_id" jdbcType="BIGINT" property="alarmId" />
+    <result column="pid" jdbcType="BIGINT" property="pid" />
+    <result column="val" jdbcType="VARCHAR" property="val" />
+<!--    <result column="item_name" jdbcType="VARCHAR" property="itemName" />-->
+    <result column="lat" jdbcType="VARCHAR" property="lat" />
+    <result column="lng" jdbcType="VARCHAR" property="lng" />
+    <result column="alt" jdbcType="VARCHAR" property="alt" />
+    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
+    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
+    <result column="status" jdbcType="TINYINT" property="status" />
+    <result column="is_history" jdbcType="TINYINT" property="isHistory" />
+    <result column="del_flag" jdbcType="TINYINT" property="delFlag" />
+  </resultMap>
+  <sql id="Base_Column_List">
+    <!--@mbg.generated-->
+    id, mountain_id, company_id, alarm_id,
+    lat, lng, alt, create_time, update_time, `status`,val,pid,is_history,del_flag
+  </sql>
+  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
+    <!--@mbg.generated-->
+    select 
+    <include refid="Base_Column_List" />
+    from kws_alarm_detail
+    where id = #{id,jdbcType=BIGINT}
+  </select>
+  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
+    <!--@mbg.generated-->
+    delete from kws_alarm_detail
+    where id = #{id,jdbcType=BIGINT}
+  </delete>
+  <insert id="insertSelective" parameterType="com.sckw.slope.detection.model.dos.mysql.KwsAlarmDetail">
+    <!--@mbg.generated-->
+    insert into kws_alarm_detail
+    <trim prefix="(" suffix=")" suffixOverrides=",">
+      <if test="id != null">
+        id,
+      </if>
+      <if test="mountainId != null">
+        mountain_id,
+      </if>
+      <if test="companyId != null">
+        company_id,
+      </if>
+      <if test="alarmId != null">
+        alarm_id,
+      </if>
+      <if test="level != null">
+        `level`,
+      </if>
+      <if test="title != null">
+        title,
+      </if>
+      <if test="content != null">
+        content,
+      </if>
+      <if test="type != null">
+        `type`,
+      </if>
+      <if test="lat != null">
+        lat,
+      </if>
+      <if test="lng != null">
+        lng,
+      </if>
+      <if test="alt != null">
+        alt,
+      </if>
+      <if test="createTime != null">
+        create_time,
+      </if>
+      <if test="updateTime != null">
+        update_time,
+      </if>
+      <if test="status != null">
+        `status`,
+      </if>
+    </trim>
+    <trim prefix="values (" suffix=")" suffixOverrides=",">
+      <if test="id != null">
+        #{id,jdbcType=BIGINT},
+      </if>
+      <if test="mountainId != null">
+        #{mountainId,jdbcType=VARCHAR},
+      </if>
+      <if test="companyId != null">
+        #{companyId,jdbcType=VARCHAR},
+      </if>
+      <if test="alarmId != null">
+        #{alarmId,jdbcType=BIGINT},
+      </if>
+      <if test="level != null">
+        #{level,jdbcType=INTEGER},
+      </if>
+      <if test="title != null">
+        #{title,jdbcType=VARCHAR},
+      </if>
+      <if test="content != null">
+        #{content,jdbcType=VARCHAR},
+      </if>
+      <if test="type != null">
+        #{type,jdbcType=INTEGER},
+      </if>
+      <if test="lat != null">
+        #{lat,jdbcType=VARCHAR},
+      </if>
+      <if test="lng != null">
+        #{lng,jdbcType=VARCHAR},
+      </if>
+      <if test="alt != null">
+        #{alt,jdbcType=VARCHAR},
+      </if>
+      <if test="createTime != null">
+        #{createTime,jdbcType=TIMESTAMP},
+      </if>
+      <if test="updateTime != null">
+        #{updateTime,jdbcType=TIMESTAMP},
+      </if>
+      <if test="status != null">
+        #{status,jdbcType=TINYINT},
+      </if>
+    </trim>
+  </insert>
+  <update id="updateByPrimaryKeySelective" parameterType="com.sckw.slope.detection.model.dos.mysql.KwsAlarmDetail">
+    <!--@mbg.generated-->
+    update kws_alarm_detail
+    <set>
+      <if test="mountainId != null">
+        mountain_id = #{mountainId,jdbcType=VARCHAR},
+      </if>
+      <if test="companyId != null">
+        company_id = #{companyId,jdbcType=VARCHAR},
+      </if>
+      <if test="projectId != null">
+        project_id = #{projectId,jdbcType=BIGINT},
+      </if>
+      <if test="alarmId != null">
+        alarm_id = #{alarmId,jdbcType=BIGINT},
+      </if>
+      <if test="level != null">
+        `level` = #{level,jdbcType=INTEGER},
+      </if>
+      <if test="title != null">
+        title = #{title,jdbcType=VARCHAR},
+      </if>
+      <if test="content != null">
+        content = #{content,jdbcType=VARCHAR},
+      </if>
+      <if test="type != null">
+        `type` = #{type,jdbcType=INTEGER},
+      </if>
+      <if test="lat != null">
+        lat = #{lat,jdbcType=VARCHAR},
+      </if>
+      <if test="lng != null">
+        lng = #{lng,jdbcType=VARCHAR},
+      </if>
+      <if test="alt != null">
+        alt = #{alt,jdbcType=VARCHAR},
+      </if>
+      <if test="createTime != null">
+        create_time = #{createTime,jdbcType=TIMESTAMP},
+      </if>
+      <if test="updateTime != null">
+        update_time = #{updateTime,jdbcType=TIMESTAMP},
+      </if>
+      <if test="status != null">
+        `status` = #{status,jdbcType=TINYINT},
+      </if>
+    </set>
+    where id = #{id,jdbcType=BIGINT}
+  </update>
+  <update id="updateByPrimaryKey" parameterType="com.sckw.slope.detection.model.dos.mysql.KwsAlarmDetail">
+    <!--@mbg.generated-->
+    update kws_alarm_detail
+    set mountain_id = #{mountainId,jdbcType=VARCHAR},
+      company_id = #{companyId,jdbcType=VARCHAR},
+      project_id = #{projectId,jdbcType=BIGINT},
+      alarm_id = #{alarmId,jdbcType=BIGINT},
+      `level` = #{level,jdbcType=INTEGER},
+      title = #{title,jdbcType=VARCHAR},
+      content = #{content,jdbcType=VARCHAR},
+      `type` = #{type,jdbcType=INTEGER},
+      lat = #{lat,jdbcType=VARCHAR},
+      lng = #{lng,jdbcType=VARCHAR},
+      alt = #{alt,jdbcType=VARCHAR},
+      create_time = #{createTime,jdbcType=TIMESTAMP},
+      update_time = #{updateTime,jdbcType=TIMESTAMP},
+      `status` = #{status,jdbcType=TINYINT}
+    where id = #{id,jdbcType=BIGINT}
+  </update>
+</mapper>

+ 3 - 1
slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsAlarmDetailMapper.xml

@@ -18,11 +18,13 @@
     <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
     <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
     <result column="status" jdbcType="TINYINT" property="status" />
+    <result column="is_history" jdbcType="TINYINT" property="isHistory" />
+    <result column="del_flag" jdbcType="TINYINT" property="delFlag" />
   </resultMap>
   <sql id="Base_Column_List">
     <!--@mbg.generated-->
     id, mountain_id, company_id, alarm_id,
-    lat, lng, alt, create_time, update_time, `status`,val,pid
+    lat, lng, alt, create_time, update_time, `status`,val,pid,is_history,del_flag
   </sql>
   <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
     <!--@mbg.generated-->

+ 3 - 1
slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsAlarmMapper.xml

@@ -16,6 +16,8 @@
         <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
         <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
         <result column="status" jdbcType="TINYINT" property="status"/>
+        <result column="is_history" jdbcType="TINYINT" property="isHistory" />
+        <result column="del_flag" jdbcType="TINYINT" property="delFlag" />
     </resultMap>
     <sql id="Base_Column_List">
         <!--@mbg.generated-->
@@ -30,7 +32,7 @@
         project_id,
         update_time,
         device_id,
-        trigger_times
+        trigger_times,is_history,del_flag
     </sql>
     <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
         <!--@mbg.generated-->