Forráskód Böngészése

1.修复边坡详情,左侧列表bigdecimal计算小数位bug
2.修复导出时间超长bug
3.修改原型边坡详情右侧折线图数据展示异常问题
4.新增log组件

lengfaqiang 2 éve
szülő
commit
b18af35f7d
14 módosított fájl, 201 hozzáadás és 195 törlés
  1. 1 1
      slope-common/slope-common-log/src/main/java/com/sckw/log/TraceLog/interceptor/MDCInterceptor.java
  2. 1 1
      slope-common/slope-common-log/src/main/java/com/sckw/log/TraceLog/interceptor/RestTemplateTraceIdInterceptor.java
  3. 1 1
      slope-common/slope-common-log/src/main/java/com/sckw/log/TraceLog/interceptor/WebMvcConfig.java
  4. 33 28
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/consumer/MqttDeviceCallbackHandler.java
  5. 0 2
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/dao/mysql/KwsAlarmMapper.java
  6. 6 3
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dos/mysql/KwsAlarm.java
  7. 22 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/DevicesAlarmLogVO.java
  8. 1 2
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/ProjectCatLogVO.java
  9. 51 51
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/excel/KwsAlarmExportVO.java
  10. 2 1
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/CommonService.java
  11. 30 11
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/DeviceService.java
  12. 15 64
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/KwsAlarmService.java
  13. 35 29
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/ProjectService.java
  14. 3 1
      slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsAlarmMapper.xml

+ 1 - 1
slope-common/slope-common-log/src/main/java/com/sckw/log/TraceLog/interceptor/MDCInterceptor.java

@@ -13,7 +13,7 @@ import org.springframework.web.servlet.HandlerInterceptor;
 import org.springframework.web.servlet.ModelAndView;
 
 /**
- * @author JiangPan
+ * @author lfdc
  * @version 1.0.0
  * @ClassName MDCInterceptor.java
  * @Description MDC拦截器

+ 1 - 1
slope-common/slope-common-log/src/main/java/com/sckw/log/TraceLog/interceptor/RestTemplateTraceIdInterceptor.java

@@ -16,7 +16,7 @@ import org.springframework.stereotype.Component;
 import java.io.IOException;
 
 /**
- * @author JiangPan
+ * @author lfdc
  * @version 1.0.0
  * @ClassName RestTemplateTraceIdInterceptor.java
  * @Description RestTemplate拦截器

+ 1 - 1
slope-common/slope-common-log/src/main/java/com/sckw/log/TraceLog/interceptor/WebMvcConfig.java

@@ -6,7 +6,7 @@ import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
 
 /**
- * @author JiangPan
+ * @author lfdc
  * @version 1.0.0
  * @ClassName WebMvcConfig.java
  * @Description MDC注册

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

@@ -4,7 +4,6 @@ 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.Global;
 import com.sckw.core.model.constant.NumberConstant;
 import com.sckw.core.model.enums.AlarmTitleEnum;
 import com.sckw.core.model.enums.AlarmTypeEnum;
@@ -14,7 +13,6 @@ 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.redis.utils.RedissonUtils;
 import com.sckw.slope.detection.dao.mysql.*;
 import com.sckw.slope.detection.dao.tdengine.SlopeDataMapper;
 import com.sckw.slope.detection.model.dos.mysql.*;
@@ -27,7 +25,6 @@ import com.sckw.slope.detection.service.CommonService;
 import com.sckw.slope.detection.service.TdengineService;
 import com.sckw.slope.detection.service.api.DetectionApiService;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.StringUtils;
 import org.apache.dubbo.common.utils.MD5Utils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -129,19 +126,21 @@ public class MqttDeviceCallbackHandler extends AbstractHandler {
                         Long thresholdId = Long.valueOf(map.get("thresholdId"));
                         //阈值表以及明细表存储
                         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);
-                        }
+//                        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<>();
@@ -206,19 +205,19 @@ public class MqttDeviceCallbackHandler extends AbstractHandler {
                 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());
-                    /**阈值次数存redis*/
-                    String key = Global.REDIS_SYS_ALARM_PREFIX + Global.POUND + String.valueOf(id) + Global.POUND+ AlarmTypeEnum.ALARM_TWO.getStatus()
-                            + Global.POUND + AlarmTitleEnum.ALARM_TITLE_ONE.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);
-                    }
+//                    /**阈值次数存redis*/
+//                    String key = Global.REDIS_SYS_ALARM_PREFIX + Global.POUND + String.valueOf(id) + Global.POUND + AlarmTypeEnum.ALARM_TWO.getStatus()
+//                            + Global.POUND + AlarmTitleEnum.ALARM_TITLE_ONE.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);
+//                    }
                     // todo 暂未设备告警电话,设备告警不推送短信
                     device.setOnline(1);
                     deviceMapper.updateById(device);
@@ -432,6 +431,7 @@ public class MqttDeviceCallbackHandler extends AbstractHandler {
         LambdaQueryWrapper<KwsAlarm> wrapper = new LambdaQueryWrapper<KwsAlarm>()
                 .eq(KwsAlarm::getLevel, level.intValue())
                 .eq(KwsAlarm::getDeviceId, deviceId)
+                .eq(KwsAlarm::getStatus, NumberConstant.ZERO)
                 .eq(KwsAlarm::getType, NumberConstant.ONE)
                 .orderByDesc(KwsAlarm::getCreateTime);
         if (projectDevice != null) {
@@ -462,6 +462,7 @@ public class MqttDeviceCallbackHandler extends AbstractHandler {
             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());
@@ -484,6 +485,10 @@ public class MqttDeviceCallbackHandler extends AbstractHandler {
 //            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));
+            alarm.setTriggerTimes(aLong.intValue());
             alarmMapper.updateById(alarm);
             String mountainId = projectDevice == null ? null : projectDevice.getMountainId();
             String companyId = projectDevice == null ? null : projectDevice.getCompanyId();

+ 0 - 2
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/dao/mysql/KwsAlarmMapper.java

@@ -15,8 +15,6 @@ import java.util.Map;
 public interface KwsAlarmMapper extends BaseMapper<KwsAlarm> {
     int deleteByPrimaryKey(Long id);
 
-    int insert(KwsAlarm record);
-
     int insertSelective(KwsAlarm record);
 
     KwsAlarm selectByPrimaryKey(Long id);

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

@@ -17,7 +17,10 @@ import java.time.LocalDateTime;
 public class KwsAlarm implements Serializable {
     private Long id;
 
-
+    /**
+     * 预警次数
+     */
+    private Integer triggerTimes;
 
     /**
      * 企业id
@@ -55,13 +58,13 @@ public class KwsAlarm implements Serializable {
     /**
      * 创建时间
      */
-    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
     private LocalDateTime createTime;
 
     /**
      * 创建时间
      */
-    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
     private LocalDateTime updateTime;
 
     /**

+ 22 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/DevicesAlarmLogVO.java

@@ -0,0 +1,22 @@
+package com.sckw.slope.detection.model.vo;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @author lfdc
+ * @description 告警vo
+ * @date 2023-11-28 09:11:45
+ */
+@Data
+public class DevicesAlarmLogVO implements Serializable {
+    /**
+     * 时间
+     */
+    private String dateTime;
+    /**
+     * 计算展示值
+     */
+    private String dataValue;
+}

+ 1 - 2
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/ProjectCatLogVO.java

@@ -5,7 +5,6 @@ import lombok.Data;
 import java.io.Serializable;
 import java.math.BigDecimal;
 import java.util.List;
-import java.util.Map;
 
 /**
  * @author lfdc
@@ -39,7 +38,7 @@ public class ProjectCatLogVO implements Serializable {
     /**
      * 统计检测要素时间轴数据
      */
-    private List<Map<String, Object>> monitor;
+    private List<DevicesAlarmLogVO> monitor;
 
     /**
      * 要素类型

+ 51 - 51
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/excel/KwsAlarmExportVO.java

@@ -17,6 +17,57 @@ import java.time.LocalDateTime;
 @Data
 @ExcelContext(fileName = "告警数据", sheetName = "告警数据")
 public class KwsAlarmExportVO implements Serializable {
+
+    /**
+     * 设备名称
+     */
+    @ExcelProperty(value = "设备名称")
+    private String deviceName;
+
+    /**
+     * 项目名称
+     */
+    @ExcelProperty(value = "所属检测项目")
+    private String projectName;
+
+    /**
+     * 告警等级
+     */
+    @ExcelProperty(value = "告警等级")
+    private String level;
+
+    /**
+     * 1数据告警  2设备告警
+     */
+    @ExcelProperty(value = "告警类型")
+    private String type;
+
+    /**
+     * 告警类型
+     */
+    @ExcelProperty(value = "类型明细")
+    private String alarmLevel;
+
+    /**
+     * 触发次数
+     */
+    @ExcelProperty(value = "触发次数")
+    private String triggerTimes;
+
+    /**
+     * 开始时间
+     */
+    @ExcelProperty(value = "首次时间")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private LocalDateTime startTime;
+
+    /**
+     * 结束时间
+     */
+    @ExcelProperty(value = "末次时间")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private LocalDateTime endTime;
+
     /**
      * 触发的id(阈值id或者设备id)
      */
@@ -51,18 +102,6 @@ public class KwsAlarmExportVO implements Serializable {
     @ExcelIgnore
     private String content;
 
-    /**
-     * 告警等级
-     */
-    @ExcelProperty(value = "告警等级", index = 3)
-    private String level;
-
-    /**
-     * 1数据告警  2设备告警
-     */
-    @ExcelProperty(value = "告警类型", index = 4)
-    private String type;
-
     /**
      * 纬度
      */
@@ -81,50 +120,11 @@ public class KwsAlarmExportVO implements Serializable {
     @ExcelIgnore
     private String alt;
 
-    /**
-     * 触发次数
-     */
-    @ExcelProperty(value = "触发次数", index = 6)
-    private String triggerTimes;
-
     /**
      * 状态
      */
     @ExcelIgnore
     private int status;
 
-    /**
-     * 设备名称
-     */
-    @ExcelProperty(value = "设备名称", index = 1)
-    private String deviceName;
-
-    /**
-     * 项目名称
-     */
-    @ExcelProperty(value = "所属检测项目", index = 2)
-    private String projectName;
-
-    /**
-     * 告警类型
-     */
-    @ExcelProperty(value = "类型明细", index = 5)
-    private String alarmLevel;
-
-    /**
-     * 开始时间
-     */
-    @ExcelProperty(value = "首次时间", index = 7)
-    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
-    private LocalDateTime startTime;
-
-    /**
-     * 结束时间
-     */
-    @ExcelProperty(value = "末次时间", index = 8)
-    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
-    private LocalDateTime endTime;
-
-
     private static final long serialVersionUID = 1L;
 }

+ 2 - 1
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/CommonService.java

@@ -4,7 +4,6 @@ import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 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;
@@ -25,6 +24,7 @@ import jakarta.servlet.http.HttpServletRequest;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
@@ -41,6 +41,7 @@ import java.util.Map;
  */
 @Slf4j
 @Service
+@RefreshScope
 public class CommonService {
 
     @Value("${spring.profiles.active}")

+ 30 - 11
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/DeviceService.java

@@ -38,6 +38,7 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
 import java.util.*;
@@ -541,32 +542,50 @@ public class DeviceService {
                         double angleInRadians = Math.toRadians(selected == null ? 0L : Double.parseDouble(selected.getVal()));
                         double cosValue = Math.cos(angleInRadians);
                         if (org.apache.commons.lang3.StringUtils.isNotBlank(val)) {
-                            double doubleValue = (new BigDecimal(val).subtract(currentValue)).divide(new BigDecimal(360)).doubleValue();
+                            double doubleValue = (new BigDecimal(val).subtract(currentValue)).divide(new BigDecimal(360),9, RoundingMode.HALF_UP).doubleValue();
                             offsetValue = new BigDecimal(equatorial_circumference).multiply(new BigDecimal(cosValue)).multiply(new BigDecimal(doubleValue));
                         }
                     }
 //                    currentMeasurement.put(itemName, offsetValue);
                     vo.setCurrentMeasurementValue(offsetValue == null ? null : offsetValue.toString());
+                    Date date = slopeData.getTs();
+                    if (date!=null){
+                        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM-dd HH:mm:ss");
+                        vo.setCurrentMeasurementTime(simpleDateFormat.format(date));
+                    }
                 }
                 itemList.clear();
                 itemList.add(DictItemEnum.LATITUDE_Y.getValue());
                 if (itemList.contains(re.getItem())) {
-                    BigDecimal offsetValue = new BigDecimal("0.00");
-                    if (org.apache.commons.lang3.StringUtils.isNotBlank(val)) {
-                        offsetValue = new BigDecimal(val).subtract(currentValue);
-                    }
+//                    BigDecimal offsetValue = new BigDecimal("0.00");
+//                    if (org.apache.commons.lang3.StringUtils.isNotBlank(val)) {
+//                        offsetValue = new BigDecimal(val).subtract(currentValue);
+//                    }
 //                    currentMeasurement.put(itemName, offsetValue);
-                    vo.setCurrentMeasurementValue(offsetValue == null ? null : offsetValue.toString());
+//                    vo.setCurrentMeasurementValue(offsetValue == null ? null : offsetValue.toString());
+                    vo.setCurrentMeasurementValue(val);
+                    Date date = slopeData.getTs();
+                    if (date!=null){
+                        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM-dd HH:mm:ss");
+                        vo.setCurrentMeasurementTime(simpleDateFormat.format(date));
+                    }
+
                 }
                 itemList.clear();
                 itemList.add(DictItemEnum.ALTITUDE_Z.getValue());
                 if (itemList.contains(re.getItem())) {
-                    BigDecimal offsetValue = new BigDecimal("0.00");
-                    if (org.apache.commons.lang3.StringUtils.isNotBlank(val)) {
-                        offsetValue = new BigDecimal(val).divide(new BigDecimal(1000), 12, BigDecimal.ROUND_HALF_UP);
-                    }
+//                    BigDecimal offsetValue = new BigDecimal("0.00");
+//                    if (org.apache.commons.lang3.StringUtils.isNotBlank(val)) {
+//                        offsetValue = new BigDecimal(val).divide(new BigDecimal(1000), 12, BigDecimal.ROUND_HALF_UP);
+//                    }
 //                    currentMeasurement.put(itemName, offsetValue);
-                    vo.setCurrentMeasurementValue(offsetValue == null ? null : offsetValue.toString());
+//                    vo.setCurrentMeasurementValue(offsetValue == null ? null : offsetValue.toString());
+                    vo.setCurrentMeasurementValue(val);
+                    Date date = slopeData.getTs();
+                    if (date!=null){
+                        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM-dd HH:mm:ss");
+                        vo.setCurrentMeasurementTime(simpleDateFormat.format(date));
+                    }
                 }
                 map.put(itemName, vo);
                 mapList.add(map);

+ 15 - 64
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/KwsAlarmService.java

@@ -1,22 +1,17 @@
 package com.sckw.slope.detection.service;
 
 import cn.hutool.core.date.DateUtil;
-import com.alibaba.excel.util.DateUtils;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 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.Global;
-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.model.page.PageRes;
 import com.sckw.core.model.vo.BaseList;
 import com.sckw.core.model.vo.PublicBaseList;
 import com.sckw.core.web.response.HttpResult;
-import com.sckw.redis.utils.RedissonUtils;
 import com.sckw.slope.detection.dao.mysql.*;
 import com.sckw.slope.detection.dao.tdengine.DevicesMapper;
 import com.sckw.slope.detection.model.dos.mysql.*;
@@ -45,7 +40,6 @@ import java.math.BigDecimal;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -163,8 +157,8 @@ public class KwsAlarmService {
                     (alarmDetailType == null ? kwsAlarm.getTitle() : (alarmDetailType.get(kwsAlarm.getTitle()) == null ? kwsAlarm.getTitle() : alarmDetailType.get(kwsAlarm.getTitle()).getLabel())));
             vo.setStartTime(kwsAlarm.getCreateTime());
             vo.setEndTime(kwsAlarm.getUpdateTime());
-            Long count = alarmDetailMapper.selectCount(new LambdaQueryWrapper<KwsAlarmDetail>().eq(KwsAlarmDetail::getAlarmId, kwsAlarm.getId()));
-            vo.setTriggerTimes(count.intValue());
+//            Long count = alarmDetailMapper.selectCount(new LambdaQueryWrapper<KwsAlarmDetail>().eq(KwsAlarmDetail::getAlarmId, kwsAlarm.getId()));
+            vo.setTriggerTimes(kwsAlarm.getTriggerTimes());
             alarmVOS.add(vo);
         }
 //        Map<Integer, List<KwsAlarm>> listMap = list.stream().collect(Collectors.groupingBy(KwsAlarm::getType));
@@ -212,80 +206,37 @@ public class KwsAlarmService {
         Map<String, SystemDict> thresholdLevel = commonService.getDictByDictCode(DictEnum.THRESHOLD_LEVEL);
         Map<String, SystemDict> alarmType = commonService.getDictByDictCode(DictEnum.ALARM_TYPE);
         Map<String, SystemDict> alarmDetailType = commonService.getDictByDictCode(DictEnum.ALARM_DETAIL_TYPE);
-        String now = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
-        System.out.println("数据翻译开始时间" + now);
-        int i = 1;
         List<KwsProject> projectList = projectMapper.selectList(null);
         Map<Long, String> projectMap = projectList.stream().collect(Collectors.toMap(KwsProject::getId, KwsProject::getName));
         List<KwsDevice> deviceList = deviceMapper.selectList(null);
         Map<Long, String> deviceMap = deviceList.stream().collect(Collectors.toMap(KwsDevice::getId, KwsDevice::getName));
         for (KwsAlarm kwsAlarm : list) {
-            i++;
-            System.out.println("数据翻译开始时间" + i + "次数" + now);
             KwsAlarmExportVO vo = new KwsAlarmExportVO();
             BeanUtils.copyProperties(kwsAlarm, vo);
-
-            String levelTime = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
-            System.out.println("数据翻译等级开始时间" + i + "次数" + levelTime);
             vo.setLevel(kwsAlarm.getLevel() == null ? null : (thresholdLevel.get(String.valueOf(kwsAlarm.getLevel())).getLabel()));
-            String levelEndTime = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
-            System.out.println("数据翻译等级结束时间" + i + "次数" + levelEndTime);
-
-            String typeTime = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
-            System.out.println("数据翻译类型开始时间" + i + "次数" + typeTime);
             vo.setType(kwsAlarm.getType() == null ? null : (alarmType.get(String.valueOf(kwsAlarm.getType())).getLabel()));
-            String typeEndTime = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
-            System.out.println("数据翻译类型结束时间" + i + "次数" + typeEndTime);
-
-
-            String deviceTime = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
-            System.out.println("数据翻译设备名称开始时间" + i + "次数" + deviceTime);
             vo.setDeviceName(deviceMap == null ? kwsAlarm.getDeviceId().toString() : deviceMap.get(kwsAlarm.getDeviceId()));
-            String deviceEndTime = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
-            System.out.println("数据翻译设备名称结束时间" + i + "次数" + deviceEndTime);
-
-            String projectTime = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
-            System.out.println("数据翻译项目名称开始时间" + i + "次数" + projectTime);
             vo.setProjectName(projectMap == null ? kwsAlarm.getProjectId() : projectMap.get(Long.parseLong(kwsAlarm.getProjectId())));
-            String projectEndTime = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
-            System.out.println("数据翻译项目名称结束时间" + i + "次数" + projectEndTime);
-
-            String alarmTime = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
-            System.out.println("数据翻译告警等级开始时间" + i + "次数" + alarmTime);
             vo.setAlarmLevel(kwsAlarm.getTitle() == null ? null : (alarmDetailType.get(kwsAlarm.getTitle()).getLabel()));
-            String alarmEndTime = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
-            System.out.println("数据翻译告警等级结束时间" + i + "次数" + alarmEndTime);
-
             vo.setStartTime(kwsAlarm.getCreateTime());
             vo.setEndTime(kwsAlarm.getUpdateTime());
-
-            String countTime = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
-            System.out.println("数据翻译统计开始时间" + i + "次数" + countTime);
 //            Long count = alarmDetailMapper.selectCount(new LambdaQueryWrapper<KwsAlarmDetail>().eq(KwsAlarmDetail::getAlarmId, kwsAlarm.getId()));
+            //todo 不使用缓存  使用新字段处理
             /**结合到mqtt阈值触发数据存储*/
-            String count = null;
-            Long id = kwsAlarm.getId();
-            if (AlarmTypeEnum.ALARM_ONE.getStatus().equals(String.valueOf(kwsAlarm.getType()))) {
-                /**阈值次数存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();
-                count = RedissonUtils.getString(key);
-            } else {
-                /**阈值次数存redis*/
-                String key = Global.REDIS_SYS_ALARM_PREFIX + Global.POUND + String.valueOf(id) + Global.POUND + AlarmTypeEnum.ALARM_TWO.getStatus()
-                        + Global.POUND + AlarmTitleEnum.ALARM_TITLE_ONE.getStatus();
-                count = RedissonUtils.getString(key);
-            }
-            vo.setTriggerTimes(count);
-            String countEndTime = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
-            System.out.println("数据翻译统计结束时间" + i + "次数" + countEndTime);
-
+//            if (AlarmTypeEnum.ALARM_ONE.getStatus().equals(String.valueOf(kwsAlarm.getType()))) {
+//                /**阈值次数存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();
+//                count = RedissonUtils.getString(key);
+//            } else {
+//                /**阈值次数存redis*/
+//                String key = Global.REDIS_SYS_ALARM_PREFIX + Global.POUND + String.valueOf(id) + Global.POUND + AlarmTypeEnum.ALARM_TWO.getStatus()
+//                        + Global.POUND + AlarmTitleEnum.ALARM_TITLE_ONE.getStatus();
+//                count = RedissonUtils.getString(key);
+//            }
+            vo.setTriggerTimes(kwsAlarm.getTriggerTimes() == null ? null : kwsAlarm.getTriggerTimes().toString());
             alarmVOS.add(vo);
-            String format = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
-            System.out.println("数据翻译结束时间" + i + "次数" + format);
         }
-        System.out.println("数据翻译开始时间" + now);
-        System.out.println("数据翻译结束时间" + DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS"));
         return alarmVOS;
     }
 

+ 35 - 29
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/ProjectService.java

@@ -604,10 +604,10 @@ public class ProjectService {
                             } catch (Exception e) {
                                 log.error("select tdengine devices error :{}", e.getMessage(), e);
                             }
-                            List<Map<String, Object>> mapList = new ArrayList<>();
+                            List<DevicesAlarmLogVO> mapList = new ArrayList<>();
                             if (!CollectionUtils.isEmpty(selected)) {
                                 for (int i = 0; i < selected.size(); i++) {
-                                    Map<String, Object> map = new HashMap<>();
+                                    DevicesAlarmLogVO map = new DevicesAlarmLogVO();
                                     SlopeData currSlopeData = selected.get(i);
 //                                    String key = currSlopeData.getTs().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH"));
                                     SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM-dd HH:mm:ss");
@@ -630,8 +630,8 @@ public class ProjectService {
                                     long t = (epochMilli - epochMilli1) / (60 * 60 * 1000);
                                     long val = Long.parseLong(val1) - Long.parseLong(val2);
                                     decimal = BigDecimal.valueOf(val).divide((new BigDecimal(t).multiply(new BigDecimal(t))), 9, BigDecimal.ROUND_HALF_UP);
-                                    map.put("dateTime", key);
-                                    map.put("dateValue", decimal);
+                                    map.setDateTime(key);
+                                    map.setDataValue(decimal.toString());
                                     mapList.add(map);
                                 }
                             }
@@ -717,11 +717,8 @@ public class ProjectService {
                 }
                 returnVO.setThreeLevelAlarm(thresholdLevelVO);
                 //时间统计轴(当前数据检测值)
-                List<Map<String, Object>> mapList = new ArrayList<>();
+                List<DevicesAlarmLogVO> mapList = new ArrayList<>();
                 if (currentValue != null) {
-                    /**存在经纬度海拔值的需要公式计算*/
-                    List<String> itemList = new ArrayList<>();
-                    itemList.add(DictItemEnum.LONGITUDE_X.getValue());
 //                    Date date = new Date();
                     for (int i = 0; i < dateList.size(); i++) {
                         String dateStart = DateUtil.getDateTimeToHour(dateList.get(i), 24);
@@ -734,8 +731,11 @@ public class ProjectService {
                         }
                         if (!CollectionUtils.isEmpty(selected)) {
                             for (SlopeData message : selected) {
+                                /**存在经纬度海拔值的需要公式计算*/
+                                List<String> itemList = new ArrayList<>();
+                                itemList.add(DictItemEnum.LONGITUDE_X.getValue());
                                 BigDecimal offsetValue = new BigDecimal("0.00");
-                                Map<String, Object> datemap = new HashMap<>(NumberConstant.SIXTEEN);
+                                DevicesAlarmLogVO datemap = new DevicesAlarmLogVO();
                                 Date createTime = message.getTs();
 //                                String key = createTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH"));
                                 SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH");
@@ -744,8 +744,8 @@ public class ProjectService {
                                 String val1 = message.getVal();
                                 if (itemList.contains(partName)) {
                                     if (Objects.nonNull(currentValue)) {
-                                        SlopeData selectListByLine = slopeDataMapper.selectListByLine(kwsDevice.getSnCode(), "2");
-                                        double angleInRadians = Math.toRadians(selected == null ? 0L : Double.parseDouble(selectListByLine.getVal()));
+                                        SlopeData selectListByLine = slopeDataMapper.selectListByLine(kwsDevice.getSnCode(), DictItemEnum.LATITUDE_Y.getValue());
+                                        double angleInRadians = Math.toRadians(selectListByLine == null ? 0L : Double.parseDouble(selectListByLine.getVal()));
                                         double cosValue = Math.cos(angleInRadians);
                                         if (org.apache.commons.lang3.StringUtils.isNotBlank(val1)) {
                                             double doubleValue = (new BigDecimal(val1).subtract(currentValue)).divide(new BigDecimal(360), 9, BigDecimal.ROUND_HALF_UP).doubleValue();
@@ -753,11 +753,13 @@ public class ProjectService {
                                         }
                                     }
                                 }
+                                itemList.clear();
                                 itemList.add(DictItemEnum.LATITUDE_Y.getValue());
                                 if (itemList.contains(partName)) {
                                     if (Objects.nonNull(currentValue)) {
                                         if (org.apache.commons.lang3.StringUtils.isNotBlank(line)) {
-                                            offsetValue = new BigDecimal(line).subtract(currentValue);
+                                            SlopeData selectListByLine = slopeDataMapper.selectListByLine(kwsDevice.getSnCode(), DictItemEnum.LATITUDE_Y.getValue());
+                                            offsetValue = selectListByLine == null ? new BigDecimal("0.00") : (new BigDecimal(selectListByLine.getVal()).subtract(currentValue));
                                         }
                                     }
                                 }
@@ -766,12 +768,13 @@ public class ProjectService {
                                 if (itemList.contains(partName)) {
                                     if (Objects.nonNull(currentValue)) {
                                         if (org.apache.commons.lang3.StringUtils.isNotBlank(line)) {
-                                            offsetValue = new BigDecimal(line).divide(new BigDecimal(1000), 9, BigDecimal.ROUND_HALF_UP);
+                                            SlopeData selectListByLine = slopeDataMapper.selectListByLine(kwsDevice.getSnCode(), DictItemEnum.ALTITUDE_Z.getValue());
+                                            offsetValue = selectListByLine == null ? new BigDecimal("0.00") : new BigDecimal(selectListByLine.getVal()).divide(new BigDecimal(1000), 9, BigDecimal.ROUND_HALF_UP);
                                         }
                                     }
                                 }
-                                datemap.put("dateTime", key);
-                                datemap.put("dataValue", offsetValue);
+                                datemap.setDateTime(key);
+                                datemap.setDataValue(offsetValue.toString());
                                 mapList.add(datemap);
                             }
                         }
@@ -894,10 +897,10 @@ public class ProjectService {
                             } catch (Exception e) {
                                 log.error("select tdengine devices error :{}", e.getMessage(), e);
                             }
-                            List<Map<String, Object>> mapList = new ArrayList<>();
+                            List<DevicesAlarmLogVO> mapList = new ArrayList<>();
                             if (!CollectionUtils.isEmpty(selected)) {
                                 for (int i = 0; i < selected.size(); i++) {
-                                    Map<String, Object> map = new HashMap<>();
+                                    DevicesAlarmLogVO map = new DevicesAlarmLogVO();
                                     SlopeData currSlopeData = selected.get(i);
 //                                    String key = currSlopeData.getTs().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH"));
                                     SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM-dd HH:mm:ss");
@@ -911,8 +914,8 @@ public class ProjectService {
 //                                        long t = (epochMilli - epochMilli1) / (60 * 60 * 1000);
 //                                        long val = Long.parseLong(val1) - Long.parseLong(val2);
 //                                        decimal = BigDecimal.valueOf(val).divide((new BigDecimal(t).multiply(new BigDecimal(t))), 9, BigDecimal.ROUND_HALF_UP);
-                                        map.put("dataTime", key);
-                                        map.put("dataValue", decimal);
+                                        map.setDateTime(key);
+                                        map.setDataValue(decimal.toString());
                                         mapList.add(map);
                                     } else {
                                         SlopeData lastSlopeData = selected.get(i + 1);
@@ -934,8 +937,8 @@ public class ProjectService {
                                         long val = Long.parseLong(val1) - Long.parseLong(val2);
                                         decimal = BigDecimal.valueOf(val).divide((new BigDecimal(t).multiply(new BigDecimal(t))), 9, BigDecimal.ROUND_HALF_UP);
 //                                        map.put(key, decimal);
-                                        map.put("dataTime", key);
-                                        map.put("dataValue", decimal);
+                                        map.setDataValue(decimal.toString());
+                                        map.setDateTime(key);
                                         mapList.add(map);
                                     }
                                 }
@@ -1029,7 +1032,7 @@ public class ProjectService {
 //                thresholdMap.put("threeLevelAlarm", map);
                 returnVO.setThreeLevelAlarm(thresholdLevelVO);
                 //时间统计轴(当前数据检测值)
-                List<Map<String, Object>> mapList = new ArrayList<>();
+                List<DevicesAlarmLogVO> mapList = new ArrayList<>();
                 if (currentValue != null) {
                     /**存在经纬度海拔值的需要公式计算*/
                     List<String> itemList = new ArrayList<>();
@@ -1046,7 +1049,7 @@ public class ProjectService {
                     if (!CollectionUtils.isEmpty(selected)) {
                         for (SlopeData message : selected) {
                             BigDecimal offsetValue = new BigDecimal("0.00");
-                            Map<String, Object> datemap = new HashMap<>(NumberConstant.SIXTEEN);
+                            DevicesAlarmLogVO datemap = new DevicesAlarmLogVO();
                             Date createTime = message.getTs();
 //                            String key = createTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH"));
                             SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH");
@@ -1055,23 +1058,25 @@ public class ProjectService {
                             String val1 = message.getVal();
                             if (itemList.contains(partName)) {
                                 if (Objects.nonNull(currentValue)) {
-                                    SlopeData selectListByLine = slopeDataMapper.selectListByLine(kwsDevice.getSnCode(), "2");
+                                    SlopeData selectListByLine = slopeDataMapper.selectListByLine(kwsDevice.getSnCode(), DictItemEnum.LATITUDE_Y.getValue());
                                     double angleInRadians = Math.toRadians(selected == null ? 0L : (selectListByLine == null ? 0L : Double.parseDouble(selectListByLine.getVal())));
                                     double cosValue = Math.cos(angleInRadians);
                                     if (org.apache.commons.lang3.StringUtils.isNotBlank(val1)) {
                                         BigDecimal subtract = new BigDecimal(val1).subtract(currentValue);
                                         if (subtract.compareTo(new BigDecimal("0.00")) != 0) {
-                                            double doubleValue = subtract.divide(new BigDecimal("360"), 9, BigDecimal.ROUND_HALF_UP).doubleValue();
+                                            double doubleValue = subtract.divide(new BigDecimal("360.00"), 9, BigDecimal.ROUND_HALF_UP).doubleValue();
                                             offsetValue = new BigDecimal(equatorial_circumference).multiply(new BigDecimal(cosValue)).multiply(new BigDecimal(doubleValue));
                                         }
                                     }
                                 }
                             }
+                            itemList.clear();
                             itemList.add(DictItemEnum.LATITUDE_Y.getValue());
                             if (itemList.contains(partName)) {
                                 if (Objects.nonNull(currentValue)) {
+                                    SlopeData selectListByLine = slopeDataMapper.selectListByLine(kwsDevice.getSnCode(), DictItemEnum.LATITUDE_Y.getValue());
                                     if (org.apache.commons.lang3.StringUtils.isNotBlank(line)) {
-                                        offsetValue = new BigDecimal(line).subtract(currentValue);
+                                        offsetValue = selectListByLine == null ? new BigDecimal("0.00") : new BigDecimal(selectListByLine.getVal()).subtract(currentValue);
                                     }
                                 }
                             }
@@ -1080,12 +1085,13 @@ public class ProjectService {
                             if (itemList.contains(partName)) {
                                 if (Objects.nonNull(currentValue)) {
                                     if (org.apache.commons.lang3.StringUtils.isNotBlank(line)) {
-                                        offsetValue = new BigDecimal(line).divide(new BigDecimal(1000), 9, BigDecimal.ROUND_HALF_UP);
+                                        SlopeData selectListByLine = slopeDataMapper.selectListByLine(kwsDevice.getSnCode(), DictItemEnum.ALTITUDE_Z.getValue());
+                                        offsetValue = selectListByLine == null ? new BigDecimal("0.00") : new BigDecimal(selectListByLine.getVal()).divide(new BigDecimal(1000), 9, BigDecimal.ROUND_HALF_UP);
                                     }
                                 }
                             }
-                            datemap.put("dateTime", key);
-                            datemap.put("dataValue", offsetValue);
+                            datemap.setDateTime(key);
+                            datemap.setDataValue(offsetValue.toString());
                             mapList.add(datemap);
                         }
                     }

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

@@ -11,6 +11,7 @@
         <result column="project_id" jdbcType="VARCHAR" property="projectId"/>
         <result column="device_id" jdbcType="VARCHAR" property="deviceId"/>
         <result column="level" jdbcType="INTEGER" property="level"/>
+        <result column="trigger_times" jdbcType="INTEGER" property="triggerTimes"/>
         <result column="type" jdbcType="INTEGER" property="type"/>
         <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
         <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
@@ -28,7 +29,8 @@
         mountain_id,
         project_id,
         update_time,
-        device_id
+        device_id,
+        trigger_times
     </sql>
     <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
         <!--@mbg.generated-->