Просмотр исходного кода

Merge branch 'dev' into sky_v2

15928045575 2 лет назад
Родитель
Сommit
33ce00e2dc
35 измененных файлов с 1369 добавлено и 147 удалено
  1. 175 0
      slope-common/slope-common-core/src/main/java/com/sckw/core/model/enums/MessageLogEnum.java
  2. 9 3
      slope-common/slope-common-core/src/main/java/com/sckw/core/utils/StringUtils.java
  3. 38 5
      slope-common/slope-common-excel/src/main/java/com/sckw/excel/utils/DateUtil.java
  4. 19 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/controller/LogController.java
  5. 10 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/controller/TdengineDemoController.java
  6. 0 2
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/dao/mysql/KwsLogMapper.java
  7. 3 1
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/dao/mysql/KwsProjectMapper.java
  8. 23 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/dao/tdengine/InsTablesMapper.java
  9. 1 1
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dos/mysql/KwsIntegration.java
  10. 4 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dos/mysql/KwsLog.java
  11. 5 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dos/mysql/KwsReportTemplate.java
  12. 29 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dos/tdengine/InsTables.java
  13. 3 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dto/LocationDTO.java
  14. 2 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/param/DeviceQuery.java
  15. 4 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/param/ProjectChartLogParam.java
  16. 18 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/param/ProjectLogQuery.java
  17. 8 5
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/DeviceOutputValueVO.java
  18. 48 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/ProjectCatLogVO.java
  19. 15 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/ThreeLevelAlarm.java
  20. 23 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/ThresholdLevelVO.java
  21. 28 2
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/CommonService.java
  22. 81 29
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/DeviceService.java
  23. 32 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/LogService.java
  24. 606 76
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/ProjectService.java
  25. 22 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/ReportService.java
  26. 40 1
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/ReportTemplateService.java
  27. 18 1
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/TdengineDemoService.java
  28. 17 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/ThresholdService.java
  29. 4 1
      slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsDeviceMapper.xml
  30. 1 1
      slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsIntegrationMapper.xml
  31. 2 8
      slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsLogMapper.xml
  32. 3 0
      slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsProjectMapper.xml
  33. 2 0
      slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsReportTemplateMapper.xml
  34. 52 0
      slope-modules/slope-detection/src/main/resources/mapper/tdengine/InsTables.xml
  35. 24 11
      slope-modules/slope-detection/src/main/resources/mapper/tdengine/SlopeDataMapper.xml

+ 175 - 0
slope-common/slope-common-core/src/main/java/com/sckw/core/model/enums/MessageLogEnum.java

@@ -0,0 +1,175 @@
+package com.sckw.core.model.enums;
+
+import com.sckw.core.utils.CollectionUtils;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * @author lfdc
+ * @description 项目日志枚举
+ * @date 2023-11-09 09:30:07
+ */
+@Getter
+@AllArgsConstructor
+public enum MessageLogEnum {
+    /**
+     * 新增边坡项目
+     */
+    ADD_PROJECT("slope_manage", "PROJECT_LOG", "新增边坡项目",
+            "边坡【${projectName}】已新增,所属矿山:${mountainName}",  "新增边坡项目"),
+    /**
+     * 修改边坡项目
+     */
+    UPDATE_PROJECT("slope_manage", "PROJECT_LOG", "修改边坡项目",
+            "边坡【${projectName}】已修改,所属矿山:${mountainName}", "修改边坡项目"),
+    /**
+     * 删除边坡项目
+     */
+    DELETE_PROJECT("slope_manage", "PROJECT_LOG", "删除边坡项目",
+            "边坡【${projectName}】已删除,所属矿山:${mountainName}", "删除边坡项目"),
+
+    /**
+     * 新增组网设备
+     */
+    ADD_NETWORKING_DEVICE("slope_manage", "PROJECT_LOG", "新增组网设备",
+            "设备【${deviceName}】已关联组网,所属边坡【${projectName}】",  "新增组网设备"),
+    /**
+     * 删除组网设备
+     */
+    DELETE_NETWORKING_DEVICE("slope_manage", "PROJECT_LOG", "删除组网设备",
+            "设备【${deviceName}】已取消组网,所属边坡【${projectName}】",  "删除组网设备"),
+    /**
+     * 调整设备布设
+     */
+    UPDATE_DEVICE_LAY("slope_manage", "PROJECT_LOG", "调整设备布设",
+            "设备【${deviceName}】已调整项目位置,所属边坡【${projectName}】",  "调整设备布设"),
+    /**
+     * 新增报表模版
+     */
+    ADD_REPORT_TEMPLATE("slope_manage", "PROJECT_LOG", "新增报表模版",
+            "报表模版【${templateName}】已新增,所属边坡【${projectName}】",  "新增报表模版"),
+
+    /**
+     * 修改报表模版
+     */
+    UPDATE_REPORT_TEMPLATE("slope_manage", "PROJECT_LOG", "修改报表模版",
+                                "报表模版【${templateName}】已修改,所属边坡【${projectName}】",  "修改报表模版"),
+
+    /**
+     * 删除报表模版
+     */
+    DELETE_REPORT_TEMPLATE("slope_manage", "PROJECT_LOG", "删除报表模版",
+                                "报表模版【${templateName}】已删除,所属边坡【${projectName}】",  "删除报表模版"),
+
+    /**
+     * 禁用报表模版
+     */
+    FORBIDDEN_REPORT_TEMPLATE("slope_manage", "PROJECT_LOG", "禁用报表模版",
+            "报表模版【${templateName}】已禁用,所属边坡【${projectName}】",  "禁用报表模版"),
+
+    /**
+     * 启用报表模版
+     */
+    ENABLE_REPORT_TEMPLATE("slope_manage", "PROJECT_LOG", "启用报表模版",
+            "报表模版【${templateName}】已启用,所属边坡【${projectName}】",  "启用报表模版"),
+
+    /**
+     * 设置设备阈值
+     */
+    SETTINGS_DEVICE_THRESHOLD("slope_manage", "PROJECT_LOG", "设置设备阈值",
+            "设备【${deviceName}】已设置了【${element}】监测要素阈值,所属边坡【${projectName}】",  "设置设备阈值"),
+
+    /**
+     * 删除设备阈值
+     */
+    DELETE_DEVICE_THRESHOLD("slope_manage", "PROJECT_LOG", "删除设备阈值",
+            "设备【${deviceName}】已删除了【${element}】监测要素阈值,所属边坡【${projectName}】",  "删除设备阈值"),
+
+    ;
+
+
+    /**
+     * 消息分类:BUSINESS业务消息,SYSTEM系统消息
+     */
+    private final String category;
+
+    /**
+     * 消息类型
+     */
+    private final String type;
+
+    /**
+     * 消息标题
+     */
+    private final String title;
+
+    /**
+     * 消息内容
+     */
+    private final String content;
+
+    /**
+     * 字段含义解释
+     */
+    private final String desc;
+
+
+    public static String getCategoryByType(String type) {
+        for (MessageLogEnum entityEnum : MessageLogEnum.values()) {
+            if (entityEnum.getType().equals(type)) {
+                return entityEnum.getCategory();
+            }
+        }
+        return null;
+    }
+
+    public static String getTitleByType(String type) {
+        for (MessageLogEnum entityEnum : MessageLogEnum.values()) {
+            if (entityEnum.getType().equals(type)) {
+                return entityEnum.getTitle();
+            }
+        }
+        return null;
+    }
+
+    public static String getContentByType(String type) {
+        for (MessageLogEnum entityEnum : MessageLogEnum.values()) {
+            if (entityEnum.getType().equals(type)) {
+                return entityEnum.getContent();
+            }
+        }
+        return null;
+    }
+
+    public static String getDesc(MessageLogEnum messageEnum) {
+        for (MessageLogEnum entityEnum : MessageLogEnum.values()) {
+            if (entityEnum.equals(messageEnum)) {
+                return entityEnum.getDesc();
+            }
+        }
+        return null;
+    }
+
+    public static List<MessageLogEnum> getEnums(Boolean isMain, Integer length, Set<MessageLogEnum> excludeEnums) {
+        List<MessageLogEnum> list = Arrays.stream(MessageLogEnum.values())
+                .filter(e -> CollectionUtils.isEmpty(excludeEnums) || !excludeEnums.contains(e))
+                .filter(e -> Boolean.TRUE.equals(isMain) || "BUSINESS".equals(e.getCategory()))
+                .limit(length)
+                .collect(Collectors.toList());
+        return CollectionUtils.emptyIfNull(list);
+    }
+
+    public static MessageLogEnum getEnumByCategoryAndType(String category, String type) {
+        for (MessageLogEnum e : MessageLogEnum.values()) {
+            if (e.getCategory().equals(category) && e.getType().equals(type)) {
+                return e;
+            }
+        }
+        return null;
+    }
+}

+ 9 - 3
slope-common/slope-common-core/src/main/java/com/sckw/core/utils/StringUtils.java

@@ -2,6 +2,7 @@ package com.sckw.core.utils;
 
 
 import com.sckw.core.exception.BusinessException;
 import com.sckw.core.exception.BusinessException;
 import com.sckw.core.model.constant.Global;
 import com.sckw.core.model.constant.Global;
+import com.sckw.core.model.enums.MessageLogEnum;
 
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.InvocationTargetException;
 import java.math.BigDecimal;
 import java.math.BigDecimal;
@@ -717,7 +718,7 @@ public class StringUtils {
             return str;
             return str;
         }
         }
         // cannot be longer than the char array
         // cannot be longer than the char array
-        final int [] newCodePoints = new int[strLen];
+        final int[] newCodePoints = new int[strLen];
         int outOffset = 0;
         int outOffset = 0;
         // copy the first codepoint
         // copy the first codepoint
         newCodePoints[outOffset++] = newCodePoint;
         newCodePoints[outOffset++] = newCodePoint;
@@ -817,8 +818,9 @@ public class StringUtils {
 
 
     /**
     /**
      * 去除字符串中 指定字符
      * 去除字符串中 指定字符
-     * @param sourceString  "-154-15"
-     * @param chElemData "-"
+     *
+     * @param sourceString "-154-15"
+     * @param chElemData   "-"
      * @return "15415"
      * @return "15415"
      */
      */
     public static String deleteCharString(String sourceString, String chElemData) {
     public static String deleteCharString(String sourceString, String chElemData) {
@@ -836,6 +838,10 @@ public class StringUtils {
     }
     }
 
 
     public static void main(String[] args) {
     public static void main(String[] args) {
+        Map<String, Object> map = new HashMap<>();
+        map.put("projectName","项目名称");
+        map.put("mountainName","矿山名称");
+        String s = replaceTextVar(MessageLogEnum.ADD_PROJECT.getContent(), map);
         Map<String, Object> param = new HashMap<>(Global.NUMERICAL_SIXTEEN);
         Map<String, Object> param = new HashMap<>(Global.NUMERICAL_SIXTEEN);
         param.put("account", "17358629955");
         param.put("account", "17358629955");
         param.put("pwd", "123456");
         param.put("pwd", "123456");

+ 38 - 5
slope-common/slope-common-excel/src/main/java/com/sckw/excel/utils/DateUtil.java

@@ -22,6 +22,7 @@ import java.util.*;
  **/
  **/
 public class DateUtil {
 public class DateUtil {
     public static final String DEFAULT_DATE_PATTERN = "yyyy-MM-dd HH:mm:ss";
     public static final String DEFAULT_DATE_PATTERN = "yyyy-MM-dd HH:mm:ss";
+    public static final String DEFAULT_DATE_PATTERN_SSS = "yyyy-MM-dd HH:mm:ss.SSS";
     public static final String DEF_DATE_FORMAT = "yyyy-MM-dd";
     public static final String DEF_DATE_FORMAT = "yyyy-MM-dd";
     public static final DateTimeFormatter YYYY_MM_DD_HH_MM_SS = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
     public static final DateTimeFormatter YYYY_MM_DD_HH_MM_SS = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
     public static final DateTimeFormatter YYYY_MM_DD_HH_MM_SS_SSS = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
     public static final DateTimeFormatter YYYY_MM_DD_HH_MM_SS_SSS = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
@@ -537,14 +538,14 @@ public class DateUtil {
     }
     }
 
 
     public static void main(String[] args) throws ParseException {
     public static void main(String[] args) throws ParseException {
-
-        String s = localDateTimeFormat(LocalDateTime.now());
+        List<Date> list = new ArrayList<>();
+        List<Date> dateTimeSS = getDateTimeDayToDate(LocalDateTime.now(), 7, list);
+        System.out.println(dateTimeSS);
         List<String> dateTimeHour = getDateTimeHour(new Date(), 24, new ArrayList<String>());
         List<String> dateTimeHour = getDateTimeHour(new Date(), 24, new ArrayList<String>());
         String dateTimeHour1 = getDateTimeToHour(new Date(), 24);
         String dateTimeHour1 = getDateTimeToHour(new Date(), 24);
         System.out.println(dateTimeHour);
         System.out.println(dateTimeHour);
-        List<String> list = new ArrayList<>();
-        List<String> dateTimeSS = getDateTimeDay(LocalDateTime.now(), 7, list);
-        System.out.println(dateTimeSS);
+
+
 //        // 获取当前日期
 //        // 获取当前日期
 //        LocalDate currentDate = LocalDate.now();
 //        LocalDate currentDate = LocalDate.now();
 //        // 计算一年前的日期
 //        // 计算一年前的日期
@@ -826,6 +827,38 @@ public class DateUtil {
         return list;
         return list;
     }
     }
 
 
+    /**
+     * 获取当前时间的前${amount}时间的每一天
+     *
+     * @param now    当前时间
+     * @param amount 当前时间的前几天
+     * @param list   获取到时间的数组
+     * @return
+     */
+    public static List<Date> getDateTimeDayToDate(LocalDateTime now, int amount, List<Date> list) {
+        for (int i = 0; i < amount; i++) {
+            LocalDateTime lastWeekDate = DateUtil.getLastWeekDate(now, i);
+            DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+            String key = df.format(lastWeekDate);
+            String key1 = cn.hutool.core.date.DateUtil.format(new Date(), df);
+            if (key.equals(key1)) {
+                key = cn.hutool.core.date.DateUtil.format(new Date(), YYYY_MM_DD_HH_MM_SS_SSS);
+            } else {
+                key = key + " 23:59:59.999";
+            }
+            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DEFAULT_DATE_PATTERN_SSS);
+            Date date;
+            try {
+                date = simpleDateFormat.parse(key);
+            } catch (ParseException e) {
+                System.out.println("时间转换异常:" + e.getMessage() + "," + e);
+                throw new RuntimeException();
+            }
+            list.add(date);
+        }
+        return list;
+    }
+
 
 
     /**
     /**
      * 获取当前时间的前${amount}时间的每个小时(包含当前的小时)
      * 获取当前时间的前${amount}时间的每个小时(包含当前的小时)

+ 19 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/controller/LogController.java

@@ -1,7 +1,17 @@
 package com.sckw.slope.detection.controller;
 package com.sckw.slope.detection.controller;
 
 
+import com.alibaba.fastjson2.JSONObject;
+import com.sckw.core.annotation.Log;
+import com.sckw.core.web.response.HttpResult;
+import com.sckw.slope.detection.model.param.ProjectLogQuery;
+import com.sckw.slope.detection.service.LogService;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.validation.Valid;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.bind.annotation.RestController;
 
 
 /**
 /**
@@ -14,4 +24,13 @@ import org.springframework.web.bind.annotation.RestController;
 @RequestMapping("/log")
 @RequestMapping("/log")
 public class LogController {
 public class LogController {
 
 
+    @Autowired
+    LogService logService;
+
+    @Log(description = "日志查询-分页")
+    @RequestMapping(name = "日志查询-分页", value = "/select", method = RequestMethod.POST)
+    public HttpResult select(@Valid @RequestBody ProjectLogQuery projectLogQuery, HttpServletRequest request) {
+        log.info("日志查询-分页 select param:{}", JSONObject.toJSONString(projectLogQuery));
+        return HttpResult.ok(logService.select(projectLogQuery, request));
+    }
 }
 }

+ 10 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/controller/TdengineDemoController.java

@@ -22,4 +22,14 @@ public class TdengineDemoController {
     public void tdengineDemo(){
     public void tdengineDemo(){
         tdengineDemoService.tdengineDemo();
         tdengineDemoService.tdengineDemo();
     }
     }
+
+    @RequestMapping(value = "/getTable",method = RequestMethod.GET)
+    public void getTable(){
+        tdengineDemoService.getTable();
+    }
+
+    @RequestMapping(value = "/createTable",method = RequestMethod.GET)
+    public void createTable(){
+        tdengineDemoService.createTable();
+    }
 }
 }

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

@@ -10,8 +10,6 @@ import org.apache.ibatis.annotations.Mapper;
 public interface KwsLogMapper extends BaseMapper<KwsLog> {
 public interface KwsLogMapper extends BaseMapper<KwsLog> {
     int deleteByPrimaryKey(Long id);
     int deleteByPrimaryKey(Long id);
 
 
-    int insert(KwsLog record);
-
     int insertSelective(KwsLog record);
     int insertSelective(KwsLog record);
 
 
     KwsLog selectByPrimaryKey(Long id);
     KwsLog selectByPrimaryKey(Long id);

+ 3 - 1
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/dao/mysql/KwsProjectMapper.java

@@ -24,10 +24,12 @@ public interface KwsProjectMapper extends BaseMapper<KwsProject> {
      */
      */
     List<ProjectVo> selectByProjectParam(@Param("projectQueryDto") ProjectQuery projectQueryDto, @Param("companyId") String companyId);
     List<ProjectVo> selectByProjectParam(@Param("projectQueryDto") ProjectQuery projectQueryDto, @Param("companyId") String companyId);
 
 
-    List<ProjectDeviceVO> selectDeviceByProjectId(@Param("mountainId") String mountainId, @Param("projectId") Long projectId, @Param("deviceId") Long deviceId);
+    List<ProjectDeviceVO> selectDeviceByProjectId(@Param("mountainId") String mountainId, @Param("projectId") Long projectId,
+                                                  @Param("deviceId") Long deviceId, @Param("type") String type);
 
 
     List<ProjectDeviceVO> selectDeviceList(@Param("deviceQuery") DeviceQuery deviceQuery);
     List<ProjectDeviceVO> selectDeviceList(@Param("deviceQuery") DeviceQuery deviceQuery);
 
 
     List<ProjectDeviceVO> selectDeviceNotBindList(@Param("deviceQuery") DeviceQuery deviceQuery);
     List<ProjectDeviceVO> selectDeviceNotBindList(@Param("deviceQuery") DeviceQuery deviceQuery);
+
     List<ProjectDeviceVO> selectNotBindDeviceList(@Param("deviceQuery") DeviceQuery deviceQuery);
     List<ProjectDeviceVO> selectNotBindDeviceList(@Param("deviceQuery") DeviceQuery deviceQuery);
 }
 }

+ 23 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/dao/tdengine/InsTablesMapper.java

@@ -0,0 +1,23 @@
+package com.sckw.slope.detection.dao.tdengine;
+
+import com.baomidou.dynamic.datasource.annotation.DS;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.sckw.slope.detection.model.dos.tdengine.InsTables;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
+
+/**
+ * @author lfdc
+ * @description
+ * @date 2023-11-08 13:11:37
+ */
+@DS("td")
+@Mapper
+@Repository
+public interface InsTablesMapper extends BaseMapper<InsTables> {
+
+    InsTables selectTableIsExit(@Param("tableName") String tableName);
+
+    int createTable(@Param("tableName") String tableName);
+}

+ 1 - 1
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dos/mysql/KwsIntegration.java

@@ -22,7 +22,7 @@ public class KwsIntegration implements Serializable {
     /**
     /**
      * 企业id
      * 企业id
      */
      */
-    private String companyId;
+    private String mountainId;
 
 
     /**
     /**
      * 要素名称字符串
      * 要素名称字符串

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

@@ -25,6 +25,10 @@ public class KwsLog implements Serializable {
      * 企业id
      * 企业id
      */
      */
     private String companyId;
     private String companyId;
+    /**
+     * 矿山id
+     */
+    private String mountainId;
 
 
     /**
     /**
      * 操作内容
      * 操作内容

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

@@ -32,6 +32,11 @@ public class KwsReportTemplate implements Serializable {
      */
      */
     private String companyId;
     private String companyId;
 
 
+    /**
+     * 企业id
+     */
+    private String mountainId;
+
     /**
     /**
      * 制表时间
      * 制表时间
      */
      */

+ 29 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dos/tdengine/InsTables.java

@@ -0,0 +1,29 @@
+package com.sckw.slope.detection.model.dos.tdengine;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * @author lfdc
+ * @description
+ * @date 2023-11-08 13:11:37
+ */
+@Data
+@TableName("ins_tables")
+public class InsTables implements Serializable {
+
+    private String tableName;
+    private String dbName;
+    private Date createTime;
+    private Long columns;
+    private String stableName;
+    private Long uid;
+    private Long vgroupId;
+//    private int ttl;
+    private String tableComment;
+    private String type;
+
+}

+ 3 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dto/LocationDTO.java

@@ -1,5 +1,6 @@
 package com.sckw.slope.detection.model.dto;
 package com.sckw.slope.detection.model.dto;
 
 
+import jakarta.validation.constraints.NotBlank;
 import lombok.Data;
 import lombok.Data;
 
 
 import java.io.Serializable;
 import java.io.Serializable;
@@ -12,5 +13,7 @@ import java.util.List;
  */
  */
 @Data
 @Data
 public class LocationDTO implements Serializable {
 public class LocationDTO implements Serializable {
+    @NotBlank(message = "项目id不能为空")
+    private String projectId;
     private List<DeviceLocationDTO> deviceLocationList;
     private List<DeviceLocationDTO> deviceLocationList;
 }
 }

+ 2 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/param/DeviceQuery.java

@@ -1,5 +1,6 @@
 package com.sckw.slope.detection.model.param;
 package com.sckw.slope.detection.model.param;
 
 
+import jakarta.validation.constraints.NotBlank;
 import lombok.Data;
 import lombok.Data;
 
 
 /**
 /**
@@ -22,6 +23,7 @@ public class DeviceQuery {
     /**
     /**
      * 项目id
      * 项目id
      */
      */
+    @NotBlank(message = "项目id不能为空")
     private String projectId;
     private String projectId;
 
 
     /**
     /**

+ 4 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/param/ProjectChartLogParam.java

@@ -2,6 +2,7 @@ package com.sckw.slope.detection.model.param;
 
 
 import jakarta.validation.constraints.NotBlank;
 import jakarta.validation.constraints.NotBlank;
 import lombok.Data;
 import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
 
 
 import java.io.Serializable;
 import java.io.Serializable;
 
 
@@ -34,6 +35,7 @@ public class ProjectChartLogParam implements Serializable {
     /**
     /**
      * 维度(1年、2月、3周,4日)
      * 维度(1年、2月、3周,4日)
      */
      */
+    @NotBlank(message = "统计维度不能为空")
     private String latitude;
     private String latitude;
     /**
     /**
      * 设备id
      * 设备id
@@ -48,10 +50,12 @@ public class ProjectChartLogParam implements Serializable {
     /**
     /**
      * 开始时间
      * 开始时间
      */
      */
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private String startTime;
     private String startTime;
     /**
     /**
      * 结束时间
      * 结束时间
      */
      */
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private String endTime;
     private String endTime;
     /**
     /**
      * 检测要素
      * 检测要素

+ 18 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/param/ProjectLogQuery.java

@@ -0,0 +1,18 @@
+package com.sckw.slope.detection.model.param;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @author lfdc
+ * @description 分页查询项目dto
+ * @date 2023-10-30 13:10:38
+ */
+@Data
+public class ProjectLogQuery implements Serializable {
+
+    private int page;
+
+    private int pageSize;
+}

+ 8 - 5
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/DeviceOutputValueVO.java

@@ -2,8 +2,6 @@ package com.sckw.slope.detection.model.vo;
 
 
 import lombok.Data;
 import lombok.Data;
 
 
-import java.util.Map;
-
 /**
 /**
  * @author lfdc
  * @author lfdc
  * @description 边坡详情,测量值基准值vo
  * @description 边坡详情,测量值基准值vo
@@ -14,13 +12,18 @@ public class DeviceOutputValueVO {
     /**
     /**
      * 当前基准值
      * 当前基准值
      */
      */
-    private Map<String, Object> currentMap;
+    private String currentValue;
     /**
     /**
      * 原始基准值
      * 原始基准值
      */
      */
-    private Map<String, Object> primitive;
+    private String originalValue;
     /**
     /**
      * 当前测量值
      * 当前测量值
      */
      */
-    private Map<String, Object> currentMeasurement;
+    private String currentMeasurementValue;
+
+    /**
+     * 当前测量值时间
+     */
+    private String currentMeasurementTime;
 }
 }

+ 48 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/ProjectCatLogVO.java

@@ -0,0 +1,48 @@
+package com.sckw.slope.detection.model.vo;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author lfdc
+ * @description 项目详情折线图统计
+ * @date 2023-11-08 09:11:46
+ */
+@Data
+public class ProjectCatLogVO implements Serializable {
+
+    /**
+     * 阈值map (123级别都在其中)
+     */
+    /**
+     * 第三等级阈值
+     */
+    private ThresholdLevelVO threeLevelAlarm;
+    /**
+     * 第二等级阈值
+     */
+    private ThresholdLevelVO twoLevelAlarm;
+    /**
+     * 第一阈值等级
+     */
+    private ThresholdLevelVO oneLevelAlarm;
+
+    /**
+     * 基准值
+     */
+    private BigDecimal reference;
+
+    /**
+     * 统计检测要素时间轴数据
+     */
+    private List<Map<String, Object>> monitor;
+
+    /**
+     * 要素类型
+     */
+    private String type;
+}

+ 15 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/ThreeLevelAlarm.java

@@ -0,0 +1,15 @@
+//package com.sckw.slope.detection.model.vo;
+//
+//import lombok.Data;
+//
+//import java.io.Serializable;
+//
+///**
+// * @author lfdc
+// * @description
+// * @date 2023-11-08 10:11:23
+// */
+//@Data
+//public class ThreeLevelAlarm implements Serializable {
+//    private ThresholdLevelVO thresholdLevelVO;
+//}

+ 23 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/ThresholdLevelVO.java

@@ -0,0 +1,23 @@
+package com.sckw.slope.detection.model.vo;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @author lfdc
+ * @description 阈值等级vo
+ * @date 2023-11-08 09:11:53
+ */
+@Data
+public class ThresholdLevelVO implements Serializable {
+
+    /**
+     * 阈值最大值
+     */
+    private String thresholdMax;
+    /**
+     * 阈值最小值
+     */
+    private String thresholdMin;
+}

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

@@ -6,9 +6,13 @@ import com.github.pagehelper.PageInfo;
 import com.sckw.core.exception.BusinessException;
 import com.sckw.core.exception.BusinessException;
 import com.sckw.core.model.constant.NumberConstant;
 import com.sckw.core.model.constant.NumberConstant;
 import com.sckw.core.model.enums.DictEnum;
 import com.sckw.core.model.enums.DictEnum;
+import com.sckw.core.model.enums.MessageLogEnum;
 import com.sckw.core.model.page.PageRes;
 import com.sckw.core.model.page.PageRes;
+import com.sckw.core.utils.IdWorker;
 import com.sckw.core.web.response.PhpResult;
 import com.sckw.core.web.response.PhpResult;
 import com.sckw.slope.detection.dao.mysql.KwsDictMapper;
 import com.sckw.slope.detection.dao.mysql.KwsDictMapper;
+import com.sckw.slope.detection.dao.mysql.KwsLogMapper;
+import com.sckw.slope.detection.model.dos.mysql.KwsLog;
 import com.sckw.slope.detection.model.dto.HeaderData;
 import com.sckw.slope.detection.model.dto.HeaderData;
 import com.sckw.slope.detection.model.dto.SystemDict;
 import com.sckw.slope.detection.model.dto.SystemDict;
 import com.sckw.slope.detection.model.vo.QueryDictTypePageReqVo;
 import com.sckw.slope.detection.model.vo.QueryDictTypePageReqVo;
@@ -19,7 +23,6 @@ import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
-import org.springframework.util.CollectionUtils;
 
 
 import java.util.*;
 import java.util.*;
 
 
@@ -41,6 +44,9 @@ public class CommonService {
     @Autowired
     @Autowired
     KwsDictMapper dictMapper;
     KwsDictMapper dictMapper;
 
 
+    @Autowired
+    KwsLogMapper logMapper;
+
     public HeaderData getHeaderData(HttpServletRequest request) {
     public HeaderData getHeaderData(HttpServletRequest request) {
         /**
         /**
          * {"companyId":"198","companyName":"四川金顶集团","createBy":"2","createName":"600678","updateBy":"2","updateName":"600678","mountainId":"198"}
          * {"companyId":"198","companyName":"四川金顶集团","createBy":"2","createName":"600678","updateBy":"2","updateName":"600678","mountainId":"198"}
@@ -71,7 +77,7 @@ public class CommonService {
         return PageRes.build(info, list);
         return PageRes.build(info, list);
     }
     }
 
 
-    public Map<String,SystemDict> getDictList(Map<String, Object> mapBody, Map<String, String> mapPara) {
+    public Map<String, SystemDict> getDictList(Map<String, Object> mapBody, Map<String, String> mapPara) {
         PhpResult result = detectionApiService.toSaasGetDict(url,
         PhpResult result = detectionApiService.toSaasGetDict(url,
                 "/common/getDict", mapBody
                 "/common/getDict", mapBody
                 , mapPara);
                 , mapPara);
@@ -87,4 +93,24 @@ public class CommonService {
     }
     }
 
 
 
 
+    public Map<String, SystemDict> getDictByDictCode(DictEnum dictEnum) {
+        Map<String, SystemDict> dictList = getDictList(null, new HashMap<String, String>() {{
+            put("code", dictEnum.getCodeType());
+            put("type", "1");
+        }});
+        return dictList;
+    }
+
+    public int insertLog(MessageLogEnum messageLogEnum, HeaderData headerData, Map<String, Object> logMap, Long operationBy) {
+        String content = com.sckw.core.utils.StringUtils.replaceTextVar(messageLogEnum.getContent(), logMap);
+        KwsLog log = new KwsLog();
+        log.setId(new IdWorker(NumberConstant.ONE).nextId());
+        log.setType(messageLogEnum.getType());
+        log.setCompanyId(headerData.getCompanyId());
+        log.setMountainId(headerData.getMountainId());
+        log.setContent(content);
+        log.setCreateBy(operationBy);
+        log.setCreateTime(new Date());
+        return logMapper.insert(log);
+    }
 }
 }

+ 81 - 29
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/DeviceService.java

@@ -9,15 +9,19 @@ import com.sckw.core.exception.SystemException;
 import com.sckw.core.model.constant.Global;
 import com.sckw.core.model.constant.Global;
 import com.sckw.core.model.constant.NumberConstant;
 import com.sckw.core.model.constant.NumberConstant;
 import com.sckw.core.model.enums.DeviceEnum;
 import com.sckw.core.model.enums.DeviceEnum;
+import com.sckw.core.model.enums.DictEnum;
 import com.sckw.core.model.enums.DictItemEnum;
 import com.sckw.core.model.enums.DictItemEnum;
+import com.sckw.core.model.enums.MessageLogEnum;
 import com.sckw.core.model.page.PageRes;
 import com.sckw.core.model.page.PageRes;
 import com.sckw.core.utils.IdWorker;
 import com.sckw.core.utils.IdWorker;
 import com.sckw.core.utils.StringUtils;
 import com.sckw.core.utils.StringUtils;
 import com.sckw.core.web.constant.HttpStatus;
 import com.sckw.core.web.constant.HttpStatus;
 import com.sckw.core.web.response.HttpResult;
 import com.sckw.core.web.response.HttpResult;
 import com.sckw.slope.detection.dao.mysql.*;
 import com.sckw.slope.detection.dao.mysql.*;
+import com.sckw.slope.detection.dao.tdengine.InsTablesMapper;
 import com.sckw.slope.detection.dao.tdengine.SlopeDataMapper;
 import com.sckw.slope.detection.dao.tdengine.SlopeDataMapper;
 import com.sckw.slope.detection.model.dos.mysql.*;
 import com.sckw.slope.detection.model.dos.mysql.*;
+import com.sckw.slope.detection.model.dos.tdengine.InsTables;
 import com.sckw.slope.detection.model.dos.tdengine.SlopeData;
 import com.sckw.slope.detection.model.dos.tdengine.SlopeData;
 import com.sckw.slope.detection.model.dto.*;
 import com.sckw.slope.detection.model.dto.*;
 import com.sckw.slope.detection.model.param.DeviceAdd;
 import com.sckw.slope.detection.model.param.DeviceAdd;
@@ -35,6 +39,7 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.CollectionUtils;
 
 
 import java.math.BigDecimal;
 import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
 import java.time.LocalDateTime;
 import java.time.ZoneOffset;
 import java.time.ZoneOffset;
 import java.util.*;
 import java.util.*;
@@ -63,6 +68,9 @@ public class DeviceService {
     @Autowired
     @Autowired
     SlopeDataMapper slopeDataMapper;
     SlopeDataMapper slopeDataMapper;
 
 
+    @Autowired
+    InsTablesMapper insTablesMapper;
+
     @Autowired
     @Autowired
     KwsDeviceModelMapper deviceModelMapper;
     KwsDeviceModelMapper deviceModelMapper;
 
 
@@ -148,7 +156,7 @@ public class DeviceService {
     public HttpResult add(DeviceAdd deviceAdd, HttpServletRequest request) {
     public HttpResult add(DeviceAdd deviceAdd, HttpServletRequest request) {
         KwsDevice deviceHas = deviceMapper.selectOne(new LambdaQueryWrapper<KwsDevice>()
         KwsDevice deviceHas = deviceMapper.selectOne(new LambdaQueryWrapper<KwsDevice>()
                 .eq(KwsDevice::getSnCode, deviceAdd.getSnCode()));
                 .eq(KwsDevice::getSnCode, deviceAdd.getSnCode()));
-        if(!Objects.isNull(deviceHas)){
+        if (!Objects.isNull(deviceHas)) {
             throw new SystemException(HttpStatus.QUERY_FAIL_CODE, HttpStatus.DEVICE_SN_EXISTS);
             throw new SystemException(HttpStatus.QUERY_FAIL_CODE, HttpStatus.DEVICE_SN_EXISTS);
         }
         }
         HeaderData headerData = commonService.getHeaderData(request);
         HeaderData headerData = commonService.getHeaderData(request);
@@ -168,7 +176,7 @@ public class DeviceService {
         KwsDeviceIntegration deIntergration = new KwsDeviceIntegration();
         KwsDeviceIntegration deIntergration = new KwsDeviceIntegration();
         String[] temp;//接收分割后的数组
         String[] temp;//接收分割后的数组
         temp = deviceAdd.getIntegrationId().split(Global.COMMA);
         temp = deviceAdd.getIntegrationId().split(Global.COMMA);
-        for(int i=0;i<temp.length;i++){
+        for (int i = 0; i < temp.length; i++) {
             long interId = new IdWorker(NumberConstant.ONE).nextId();
             long interId = new IdWorker(NumberConstant.ONE).nextId();
             deIntergration.setId(interId);
             deIntergration.setId(interId);
             deIntergration.setDeviceId(id);
             deIntergration.setDeviceId(id);
@@ -192,7 +200,7 @@ public class DeviceService {
 
 
         KwsDeviceModel deviceModel = deviceModelMapper.selectOne(new LambdaQueryWrapper<KwsDeviceModel>()
         KwsDeviceModel deviceModel = deviceModelMapper.selectOne(new LambdaQueryWrapper<KwsDeviceModel>()
                 .eq(KwsDeviceModel::getId, vo.getModelId()));
                 .eq(KwsDeviceModel::getId, vo.getModelId()));
-        if (deviceModel!=null){
+        if (deviceModel != null) {
             vo.setManufacturer(deviceModel.getManufacturer());
             vo.setManufacturer(deviceModel.getManufacturer());
             vo.setManufacturer_contacts(deviceModel.getManufacturerContacts());
             vo.setManufacturer_contacts(deviceModel.getManufacturerContacts());
             vo.setManufacturer_phone(deviceModel.getManufacturerPhone());
             vo.setManufacturer_phone(deviceModel.getManufacturerPhone());
@@ -208,9 +216,15 @@ public class DeviceService {
 
 
     @Transactional
     @Transactional
     public HttpResult locationSet(LocationDTO list, HttpServletRequest request) {
     public HttpResult locationSet(LocationDTO list, HttpServletRequest request) {
+        String projectId = list.getProjectId();
+        KwsProject project = projectMapper.selectOne(new LambdaQueryWrapper<KwsProject>()
+                .eq(KwsProject::getId, Long.parseLong(projectId)));
         HeaderData headerData = commonService.getHeaderData(request);
         HeaderData headerData = commonService.getHeaderData(request);
         List<DeviceLocationDTO> deviceLocationList = list.getDeviceLocationList();
         List<DeviceLocationDTO> deviceLocationList = list.getDeviceLocationList();
         if (!CollectionUtils.isEmpty(deviceLocationList)) {
         if (!CollectionUtils.isEmpty(deviceLocationList)) {
+            List<String> collect = deviceLocationList.stream().map(DeviceLocationDTO::getDeviceId).collect(Collectors.toList());
+            List<KwsDevice> kwsDevices = deviceMapper.selectList(new LambdaQueryWrapper<KwsDevice>()
+                    .in(KwsDevice::getId, collect).eq(KwsDevice::getDelFlag, 0));
             deviceLocationList.forEach(device -> {
             deviceLocationList.forEach(device -> {
                 deviceMapper.update(null, new LambdaUpdateWrapper<KwsDevice>()
                 deviceMapper.update(null, new LambdaUpdateWrapper<KwsDevice>()
                         .set(KwsDevice::getLogicLng, device.getLogicLng())
                         .set(KwsDevice::getLogicLng, device.getLogicLng())
@@ -221,6 +235,24 @@ public class DeviceService {
                         .eq(KwsDevice::getId, device.getDeviceId())
                         .eq(KwsDevice::getId, device.getDeviceId())
                 );
                 );
             });
             });
+            List<String> deviceNames = new ArrayList<>();
+            if (!CollectionUtils.isEmpty(kwsDevices)) {
+                deviceNames = kwsDevices.stream().map(KwsDevice::getName).collect(Collectors.toList());
+            }
+            StringBuilder deviceName = new StringBuilder();
+            if (!CollectionUtils.isEmpty(deviceNames)) {
+                for (int i = 0; i < deviceNames.size(); i++) {
+                    if (i != deviceNames.size() - 1) {
+                        deviceName.append(deviceNames.get(i)).append(",");
+                    } else {
+                        deviceName.append(deviceNames.get(i));
+                    }
+                }
+            }
+            Map<String, Object> logMap = new HashMap<>(NumberConstant.SIXTEEN);
+            logMap.put("projectName", project.getName());
+            logMap.put("deviceName", deviceName.toString());
+            commonService.insertLog(MessageLogEnum.UPDATE_DEVICE_LAY, headerData, logMap, headerData.getUpdateBy() == null ? null : Long.parseLong(headerData.getUpdateBy()));
         }
         }
         return HttpResult.ok();
         return HttpResult.ok();
     }
     }
@@ -258,10 +290,10 @@ public class DeviceService {
                 headerData.getMountainId(), status, Long.parseLong(deviceId));
                 headerData.getMountainId(), status, Long.parseLong(deviceId));
 
 
 
 
-        List<ProjectDeviceVO> projectDeviceList = projectMapper.selectDeviceByProjectId(headerData.getMountainId(), Long.parseLong(projectId), Long.parseLong(deviceId));
+        List<ProjectDeviceVO> projectDeviceList = projectMapper.selectDeviceByProjectId(headerData.getMountainId(), Long.parseLong(projectId), Long.parseLong(deviceId),null);
         List<String> deviceIds = new ArrayList<>();
         List<String> deviceIds = new ArrayList<>();
         if (!CollectionUtils.isEmpty(projectDeviceList)) {
         if (!CollectionUtils.isEmpty(projectDeviceList)) {
-            deviceIds = projectDeviceList.stream().map(ProjectDeviceVO::getId).collect(Collectors.toList());
+            deviceIds = projectDeviceList.stream().map(ProjectDeviceVO::getId).distinct().collect(Collectors.toList());
         }
         }
         //基本要素
         //基本要素
         List<KwsDeviceReference> references = deviceReferenceMapper.selectList(new LambdaQueryWrapper<KwsDeviceReference>()
         List<KwsDeviceReference> references = deviceReferenceMapper.selectList(new LambdaQueryWrapper<KwsDeviceReference>()
@@ -270,23 +302,34 @@ public class DeviceService {
                 .eq(KwsDeviceReference::getType, 1)
                 .eq(KwsDeviceReference::getType, 1)
                 .eq(KwsDeviceReference::getDelFlag, NumberConstant.ZERO)
                 .eq(KwsDeviceReference::getDelFlag, NumberConstant.ZERO)
         );
         );
-        List<DeviceOutputValueVO> mapList = new ArrayList<>();
+        List<Map<String, DeviceOutputValueVO>> mapList = new ArrayList<>();
         if (!CollectionUtils.isEmpty(references)) {
         if (!CollectionUtils.isEmpty(references)) {
             references.forEach(re -> {
             references.forEach(re -> {
+                Map<String, DeviceOutputValueVO> map = new HashMap<>();
                 DeviceOutputValueVO vo = new DeviceOutputValueVO();
                 DeviceOutputValueVO vo = new DeviceOutputValueVO();
                 String item = re.getItem();
                 String item = re.getItem();
+                Map<String, SystemDict> dictList = commonService.getDictList(null, new HashMap<>() {{
+                    put("code", DictEnum.MODEL_PART.getCodeType());
+                    put("type", "1");
+                }});
+                String itemName = dictList == null ? item : dictList.get(item).getLabel();
                 BigDecimal originalValue = re.getOriginalValue();
                 BigDecimal originalValue = re.getOriginalValue();
                 BigDecimal currentValue = re.getCurrentValue();
                 BigDecimal currentValue = re.getCurrentValue();
                 BigDecimal offset = re.getOffset();
                 BigDecimal offset = re.getOffset();
                 //当前基准值
                 //当前基准值
-                HashMap<String, Object> currentMap = new HashMap<>();
-                currentMap.put(item, currentValue);
+                vo.setCurrentValue(currentValue == null ? null : currentValue.toString());
                 //原始基准值
                 //原始基准值
-                HashMap<String, Object> primitive = new HashMap<>();
-                primitive.put(item, originalValue);
+//                HashMap<String, Object> primitive = new HashMap<>();
+//                primitive.put(itemName, originalValue);
+                vo.setOriginalValue(originalValue == null ? null : originalValue.toString());
                 //当前测量值-TD获取
                 //当前测量值-TD获取
                 HashMap<String, Object> currentMeasurement = new HashMap<>();
                 HashMap<String, Object> currentMeasurement = new HashMap<>();
-                SlopeData slopeData = slopeDataMapper.selectListByLine(kwsDevice.getSnCode(), item);
+                String snCode = kwsDevice.getSnCode();
+                InsTables insTables = insTablesMapper.selectTableIsExit("slope_data_" + snCode);
+                if (insTables == null) {
+                    insTablesMapper.createTable("slope_data_" + snCode);
+                }
+                SlopeData slopeData = slopeDataMapper.selectListByLine(snCode, item);
                 String val = slopeData == null ? null : slopeData.getVal();
                 String val = slopeData == null ? null : slopeData.getVal();
                 //存在经度纬度海拔等要素 要进行公式计算
                 //存在经度纬度海拔等要素 要进行公式计算
                 /**
                 /**
@@ -309,7 +352,8 @@ public class DeviceService {
                             offsetValue = new BigDecimal(equatorial_circumference).multiply(new BigDecimal(cosValue)).multiply(new BigDecimal(doubleValue));
                             offsetValue = new BigDecimal(equatorial_circumference).multiply(new BigDecimal(cosValue)).multiply(new BigDecimal(doubleValue));
                         }
                         }
                     }
                     }
-                    currentMeasurement.put(item, offsetValue);
+//                    currentMeasurement.put(itemName, offsetValue);
+                    vo.setCurrentMeasurementValue(offsetValue == null ? null : offsetValue.toString());
                 }
                 }
                 itemList.clear();
                 itemList.clear();
                 itemList.add(DictItemEnum.LATITUDE_Y.getValue());
                 itemList.add(DictItemEnum.LATITUDE_Y.getValue());
@@ -318,7 +362,8 @@ public class DeviceService {
                     if (org.apache.commons.lang3.StringUtils.isNotBlank(val)) {
                     if (org.apache.commons.lang3.StringUtils.isNotBlank(val)) {
                         offsetValue = new BigDecimal(val).subtract(currentValue);
                         offsetValue = new BigDecimal(val).subtract(currentValue);
                     }
                     }
-                    currentMeasurement.put(item, offsetValue);
+//                    currentMeasurement.put(itemName, offsetValue);
+                    vo.setCurrentMeasurementValue(offsetValue == null ? null : offsetValue.toString());
                 }
                 }
                 itemList.clear();
                 itemList.clear();
                 itemList.add(DictItemEnum.ALTITUDE_Z.getValue());
                 itemList.add(DictItemEnum.ALTITUDE_Z.getValue());
@@ -327,12 +372,11 @@ public class DeviceService {
                     if (org.apache.commons.lang3.StringUtils.isNotBlank(val)) {
                     if (org.apache.commons.lang3.StringUtils.isNotBlank(val)) {
                         offsetValue = new BigDecimal(val).divide(new BigDecimal(1000));
                         offsetValue = new BigDecimal(val).divide(new BigDecimal(1000));
                     }
                     }
-                    currentMeasurement.put(item, offsetValue);
+//                    currentMeasurement.put(itemName, offsetValue);
+                    vo.setCurrentMeasurementValue(offsetValue == null ? null : offsetValue.toString());
                 }
                 }
-                vo.setCurrentMap(currentMap);
-                vo.setPrimitive(primitive);
-                vo.setCurrentMeasurement(currentMeasurement);
-                mapList.add(vo);
+                map.put(itemName, vo);
+                mapList.add(map);
             });
             });
         }
         }
         //集成要素-测量值计算
         //集成要素-测量值计算
@@ -356,18 +400,22 @@ public class DeviceService {
                             .eq(KwsDeviceReference::getDelFlag, 0)
                             .eq(KwsDeviceReference::getDelFlag, 0)
                             .eq(KwsDeviceReference::getType, 2)
                             .eq(KwsDeviceReference::getType, 2)
                     );
                     );
+                    Map<String, DeviceOutputValueVO> map = new HashMap<>();
                     DeviceOutputValueVO vo = new DeviceOutputValueVO();
                     DeviceOutputValueVO vo = new DeviceOutputValueVO();
                     //当前基准值
                     //当前基准值
-                    HashMap<String, Object> currentMap = new HashMap<>();
-                    currentMap.put(integrationName, reference == null ? null : reference.getCurrentValue());
+//                    HashMap<String, Object> currentMap = new HashMap<>();
+//                    currentMap.put(integrationName, reference == null ? null : reference.getCurrentValue());
+                    vo.setCurrentValue(reference == null ? null : (reference.getCurrentValue() == null ? null : reference.getCurrentValue().toString()));
                     //原始基准值
                     //原始基准值
-                    HashMap<String, Object> primitive = new HashMap<>();
-                    primitive.put(integrationName, reference == null ? null : reference.getOriginalValue());
+//                    HashMap<String, Object> primitive = new HashMap<>();
+//                    primitive.put(integrationName, reference == null ? null : reference.getOriginalValue());
+                    vo.setOriginalValue(reference == null ? null : (reference.getOriginalValue() == null ? null : reference.getOriginalValue().toString()));
                     //当前测量值-TD获取
                     //当前测量值-TD获取
                     HashMap<String, Object> currentMeasurement = new HashMap<>();
                     HashMap<String, Object> currentMeasurement = new HashMap<>();
                     String formula = integration.getFormula();
                     String formula = integration.getFormula();
                     List<String> stringList = StringUtils.splitStrToList(partNames, String.class);
                     List<String> stringList = StringUtils.splitStrToList(partNames, String.class);
                     BigDecimal decimal = new BigDecimal("0.00");
                     BigDecimal decimal = new BigDecimal("0.00");
+                    String currentMeasurementTime = "";
                     if (!CollectionUtils.isEmpty(stringList)) {
                     if (!CollectionUtils.isEmpty(stringList)) {
                         for (int i = 0; i < stringList.size(); i++) {
                         for (int i = 0; i < stringList.size(); i++) {
                             List<SlopeData> selected = slopeDataMapper.selectListByLineOrderByCreateTime(integrationName, stringList.get(i));
                             List<SlopeData> selected = slopeDataMapper.selectListByLineOrderByCreateTime(integrationName, stringList.get(i));
@@ -375,8 +423,12 @@ public class DeviceService {
                                 if (selected.size() == 2) {
                                 if (selected.size() == 2) {
                                     SlopeData currSlopeData = selected.get(0);
                                     SlopeData currSlopeData = selected.get(0);
                                     SlopeData lastSlopeData = selected.get(1);
                                     SlopeData lastSlopeData = selected.get(1);
-                                    LocalDateTime date = currSlopeData.getCreateTime();
-                                    LocalDateTime date1 = lastSlopeData.getCreateTime();
+                                    LocalDateTime date = currSlopeData.getTs();
+                                    if (date != null) {
+                                        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM-dd HH:mm:ss");
+                                        currentMeasurementTime = simpleDateFormat.format(date);
+                                    }
+                                    LocalDateTime date1 = lastSlopeData.getTs();
                                     long epochMilli = date.toInstant(ZoneOffset.of("+8")).toEpochMilli();
                                     long epochMilli = date.toInstant(ZoneOffset.of("+8")).toEpochMilli();
                                     long epochMilli1 = date1.toInstant(ZoneOffset.of("+8")).toEpochMilli();
                                     long epochMilli1 = date1.toInstant(ZoneOffset.of("+8")).toEpochMilli();
                                     long t = (epochMilli - epochMilli1) / (60 * 60 * 1000);
                                     long t = (epochMilli - epochMilli1) / (60 * 60 * 1000);
@@ -386,11 +438,11 @@ public class DeviceService {
                             }
                             }
                         }
                         }
                     }
                     }
-                    currentMeasurement.put(integrationName, decimal);
-                    vo.setCurrentMap(currentMap);
-                    vo.setPrimitive(primitive);
-                    vo.setCurrentMeasurement(currentMeasurement);
-                    mapList.add(vo);
+//                    currentMeasurement.put(integrationName, decimal);
+                    vo.setCurrentMeasurementValue(decimal.toString());
+                    vo.setCurrentMeasurementTime(currentMeasurementTime);
+                    map.put(integrationName, vo);
+                    mapList.add(map);
                 });
                 });
             }
             }
         }
         }

+ 32 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/LogService.java

@@ -0,0 +1,32 @@
+package com.sckw.slope.detection.service;
+
+import com.github.pagehelper.PageHelper;
+import com.sckw.core.model.page.PageRes;
+import com.sckw.slope.detection.dao.mysql.KwsLogMapper;
+import com.sckw.slope.detection.model.dos.mysql.KwsLog;
+import com.sckw.slope.detection.model.param.ProjectLogQuery;
+import jakarta.servlet.http.HttpServletRequest;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * @author lfdc
+ * @description 日志service
+ * @date 2023-11-09 14:11:21
+ */
+@Slf4j
+@Service
+public class LogService {
+
+    @Autowired
+    KwsLogMapper logMapper;
+
+    public PageRes select(ProjectLogQuery query, HttpServletRequest request) {
+        PageHelper.startPage(query.getPage(), query.getPageSize());
+        List<KwsLog> kwsLogs = logMapper.selectList(null);
+        return null;
+    }
+}

+ 606 - 76
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/ProjectService.java

@@ -10,6 +10,7 @@ import com.sckw.core.model.constant.NumberConstant;
 import com.sckw.core.model.enums.DeviceEnum;
 import com.sckw.core.model.enums.DeviceEnum;
 import com.sckw.core.model.enums.DictEnum;
 import com.sckw.core.model.enums.DictEnum;
 import com.sckw.core.model.enums.DictItemEnum;
 import com.sckw.core.model.enums.DictItemEnum;
+import com.sckw.core.model.enums.MessageLogEnum;
 import com.sckw.core.model.page.PageRes;
 import com.sckw.core.model.page.PageRes;
 import com.sckw.core.utils.IdWorker;
 import com.sckw.core.utils.IdWorker;
 import com.sckw.core.utils.RegularUtils;
 import com.sckw.core.utils.RegularUtils;
@@ -37,8 +38,9 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.CollectionUtils;
 
 
 import java.math.BigDecimal;
 import java.math.BigDecimal;
-import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.LocalDateTime;
+import java.time.ZoneOffset;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.*;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
 
 
@@ -65,6 +67,9 @@ public class ProjectService {
     @Autowired
     @Autowired
     KwsDeviceIntegrationMapper deviceIntegrationMapper;
     KwsDeviceIntegrationMapper deviceIntegrationMapper;
 
 
+    @Autowired
+    KwsIntegrationMapper integrationMapper;
+
     @Autowired
     @Autowired
     KwsDeviceMapper deviceMapper;
     KwsDeviceMapper deviceMapper;
 
 
@@ -77,6 +82,9 @@ public class ProjectService {
     @Autowired
     @Autowired
     KwsDeviceReferenceMapper deviceReferenceMapper;
     KwsDeviceReferenceMapper deviceReferenceMapper;
 
 
+    @Autowired
+    KwsThresholdMapper thresholdMapper;
+
     @Autowired
     @Autowired
     KwsMountainCompanyMapper mountainCompanyMapper;
     KwsMountainCompanyMapper mountainCompanyMapper;
 
 
@@ -137,6 +145,10 @@ public class ProjectService {
         company.setMountainId(headerData.getMountainId());
         company.setMountainId(headerData.getMountainId());
         company.setCompanyId(headerData.getCompanyId());
         company.setCompanyId(headerData.getCompanyId());
         mountainCompanyMapper.insert(company);
         mountainCompanyMapper.insert(company);
+        Map<String, Object> logMap = new HashMap<>(NumberConstant.SIXTEEN);
+        logMap.put("projectName", projectAddDto.getName());
+        logMap.put("mountainName", projectAddDto.getMountainName());
+        commonService.insertLog(MessageLogEnum.ADD_PROJECT, headerData, logMap, headerData.getCreateBy() == null ? null : Long.parseLong(headerData.getCreateBy()));
         return HttpResult.ok();
         return HttpResult.ok();
     }
     }
 
 
@@ -176,13 +188,14 @@ public class ProjectService {
     }
     }
 
 
     @Transactional
     @Transactional
-    public HttpResult update(ProjectUpdateDTO projectAddDto, HttpServletRequest response) {
+    public HttpResult update(ProjectUpdateDTO projectAddDto, HttpServletRequest request) {
+        HeaderData headerData = commonService.getHeaderData(request);
         KwsProject project = new KwsProject();
         KwsProject project = new KwsProject();
         BeanUtils.copyProperties(projectAddDto, project);
         BeanUtils.copyProperties(projectAddDto, project);
         project.setId(Long.parseLong(projectAddDto.getId()));
         project.setId(Long.parseLong(projectAddDto.getId()));
         project.setStatus(NumberConstant.ZERO);
         project.setStatus(NumberConstant.ZERO);
         LocalDateTime now = LocalDateTime.now();
         LocalDateTime now = LocalDateTime.now();
-        project.setUpdateBy(Long.parseLong(commonService.getHeaderData(response).getUpdateBy()));
+        project.setUpdateBy(headerData.getUpdateBy() == null ? null : Long.parseLong(headerData.getUpdateBy()));
         project.setUpdateTime(now);
         project.setUpdateTime(now);
         projectMapper.updateById(project);
         projectMapper.updateById(project);
         String fence = projectAddDto.getFence();
         String fence = projectAddDto.getFence();
@@ -191,13 +204,27 @@ public class ProjectService {
                 .set(KwsProjectArea::getFence, fence)
                 .set(KwsProjectArea::getFence, fence)
                 .set(KwsProjectArea::getArea, projectAddDto.getArea())
                 .set(KwsProjectArea::getArea, projectAddDto.getArea())
         );
         );
+        Map<String, Object> logMap = new HashMap<>(NumberConstant.SIXTEEN);
+        logMap.put("projectName", projectAddDto.getName());
+        logMap.put("mountainName", projectAddDto.getMountainName());
+        commonService.insertLog(MessageLogEnum.UPDATE_PROJECT, headerData, logMap, headerData.getUpdateBy() == null ? null : Long.parseLong(headerData.getUpdateBy()));
         return HttpResult.ok();
         return HttpResult.ok();
     }
     }
 
 
     @Transactional
     @Transactional
     public HttpResult dels(String ids, HttpServletRequest request) {
     public HttpResult dels(String ids, HttpServletRequest request) {
+        HeaderData headerData = commonService.getHeaderData(request);
         List<Long> list = StringUtils.splitStrToList(ids, Long.class);
         List<Long> list = StringUtils.splitStrToList(ids, Long.class);
+        KwsProject project = projectMapper.selectOne(new LambdaQueryWrapper<KwsProject>()
+                .eq(KwsProject::getId, list.get(0)));
+        if (project == null) {
+            throw new BusinessException("要删除的项目不存在");
+        }
         int update = projectMapper.update(null, new LambdaUpdateWrapper<KwsProject>().in(KwsProject::getId, list).set(KwsProject::getDelFlag, "1"));
         int update = projectMapper.update(null, new LambdaUpdateWrapper<KwsProject>().in(KwsProject::getId, list).set(KwsProject::getDelFlag, "1"));
+        Map<String, Object> logMap = new HashMap<>(NumberConstant.SIXTEEN);
+        logMap.put("projectName", project.getName());
+        logMap.put("mountainName", project.getMountainName());
+        commonService.insertLog(MessageLogEnum.DELETE_PROJECT, headerData, logMap, headerData.getUpdateBy() == null ? null : Long.parseLong(headerData.getUpdateBy()));
         if (update < 1) {
         if (update < 1) {
             throw new BusinessException("删除失败");
             throw new BusinessException("删除失败");
         }
         }
@@ -254,6 +281,20 @@ public class ProjectService {
         String bindDeviceId = bindDevice.getBindDeviceId();
         String bindDeviceId = bindDevice.getBindDeviceId();
         //设备主从绑定
         //设备主从绑定
         List<KwsDeviceRelation> saveList = new ArrayList<>();
         List<KwsDeviceRelation> saveList = new ArrayList<>();
+        StringBuilder deviceName = new StringBuilder();
+        List<KwsDevice> kwsDevices = deviceMapper.selectList(new LambdaQueryWrapper<KwsDevice>()
+                .eq(KwsDevice::getDelFlag, 0)
+                .in(KwsDevice::getId, list));
+        if (CollectionUtils.isEmpty(kwsDevices)) {
+            throw new BusinessException("需要关联设备不存在");
+        }
+        for (int i = 0; i < kwsDevices.size(); i++) {
+            if (i != kwsDevices.size() - 1) {
+                deviceName.append(kwsDevices.get(i).getName()).append(",");
+            } else {
+                deviceName.append(kwsDevices.get(i).getName());
+            }
+        }
         list.forEach(id -> {
         list.forEach(id -> {
             String deviceId = "";
             String deviceId = "";
             if (bindDeviceId == null) {
             if (bindDeviceId == null) {
@@ -320,6 +361,10 @@ public class ProjectService {
                 );
                 );
             });
             });
         }
         }
+        Map<String, Object> logMap = new HashMap<>(NumberConstant.SIXTEEN);
+        logMap.put("projectName", project.getName());
+        logMap.put("deviceName", deviceName.toString());
+        commonService.insertLog(MessageLogEnum.ADD_NETWORKING_DEVICE, headerData, logMap, headerData.getCreateBy() == null ? null : Long.parseLong(headerData.getCreateBy()));
         return HttpResult.ok();
         return HttpResult.ok();
     }
     }
 
 
@@ -364,11 +409,8 @@ public class ProjectService {
         HeaderData headerData = commonService.getHeaderData(request);
         HeaderData headerData = commonService.getHeaderData(request);
         String latitude = param.getLatitude();
         String latitude = param.getLatitude();
         String projectId = param.getProjectId();
         String projectId = param.getProjectId();
+        String type = param.getType();
         if (String.valueOf(NumberConstant.FOUR).equals(latitude)) {
         if (String.valueOf(NumberConstant.FOUR).equals(latitude)) {
-            Map<String, SystemDict> dictList = commonService.getDictList(null, new HashMap<String, String>() {{
-                put("code", DictEnum.MODEL_PART.getCodeType());
-                put("type", "1");
-            }});
             String deviceId = param.getDeviceId();
             String deviceId = param.getDeviceId();
             String mountainId = headerData.getMountainId();
             String mountainId = headerData.getMountainId();
             KwsDevice kwsDevice = deviceMapper.selectOne(new LambdaQueryWrapper<KwsDevice>()
             KwsDevice kwsDevice = deviceMapper.selectOne(new LambdaQueryWrapper<KwsDevice>()
@@ -379,47 +421,279 @@ public class ProjectService {
             if (kwsDevice == null) {
             if (kwsDevice == null) {
                 return HttpResult.ok();
                 return HttpResult.ok();
             }
             }
-            //集成要素
-            List<DeviceElementDTO> integratedElementList = deviceIntegrationMapper.selectIntegratedElement(projectId,
-                    mountainId, null, Long.parseLong(deviceId));
-            //集成要素
-            List<KwsDeviceIntegration> deviceIntegrations = deviceIntegrationMapper.selectList(new LambdaQueryWrapper<KwsDeviceIntegration>()
-                    .eq(KwsDeviceIntegration::getMountainId, mountainId)
-                    .eq(KwsDeviceIntegration::getDeviceId, deviceId)
+            List<Map<String, ProjectCatLogVO>> returnList = new ArrayList<>();
+            Map<String, SystemDict> dictByDictCode = new HashMap<>();
+            if (Objects.nonNull(type)) {
+                dictByDictCode = commonService.getDictByDictCode(DictEnum.MODEL_PART);
+                if (dictByDictCode.get(type) != null) {
+                    //当前设备下的所有基本要素
+                    basicItem(mountainId, projectId, deviceId, kwsDevice, returnList, type);
+                } else {
+                    //集成要素 折线图
+                    //集成要素-测量值计算
+                    integrationItem(headerData, deviceId, kwsDevice, returnList, type);
+                }
+            } else {
+                //当前设备下的所有基本要素
+                basicItem(mountainId, projectId, deviceId, kwsDevice, returnList, type);
+                //集成要素 折线图
+                //集成要素-测量值计算
+                integrationItem(headerData, deviceId, kwsDevice, returnList, type);
+            }
+            return HttpResult.ok(returnList);
+        } else if (String.valueOf(NumberConstant.THREE).equals(latitude)) {
+            String deviceId = param.getDeviceId();
+            String mountainId = headerData.getMountainId();
+            KwsDevice kwsDevice = deviceMapper.selectOne(new LambdaQueryWrapper<KwsDevice>()
+                    .eq(KwsDevice::getId, Long.parseLong(deviceId))
+                    .eq(KwsDevice::getMountainId, mountainId)
+                    .eq(KwsDevice::getDelFlag, NumberConstant.ZERO)
             );
             );
+            if (kwsDevice == null) {
+                return HttpResult.ok();
+            }
+            List<Map<String, ProjectCatLogVO>> returnList = new ArrayList<>();
+            Map<String, SystemDict> dictByDictCode = new HashMap<>();
+            if (Objects.nonNull(type)) {
+                dictByDictCode = commonService.getDictByDictCode(DictEnum.MODEL_PART);
+                if (dictByDictCode.get(type) != null) {
+                    List<Date> dateTimeDay = DateUtil.getDateTimeDayToDate(LocalDateTime.now(), 7, new ArrayList<>());
+                    //当前设备下的所有基本要素
+                    basicItemByWeek(mountainId, projectId, deviceId, kwsDevice, returnList, dateTimeDay, type);
+                } else {
+                    //集成要素-测量值计算
+                    integrationItemWeek(headerData, deviceId, kwsDevice, returnList, type);
+                }
+            } else {
+                List<Date> dateTimeDay = DateUtil.getDateTimeDayToDate(LocalDateTime.now(), 7, new ArrayList<>());
+                //当前设备下的所有基本要素
+                basicItemByWeek(mountainId, projectId, deviceId, kwsDevice, returnList, dateTimeDay, type);
+                integrationItemWeek(headerData, deviceId, kwsDevice, returnList, type);
+            }
+            return HttpResult.ok(returnList);
+        } else if (String.valueOf(NumberConstant.TWO).equals(latitude)) {
+        } else if (String.valueOf(NumberConstant.ONE).equals(latitude)) {
+        } else {
+            throw new BusinessException("数据传输异常");
+        }
+        return HttpResult.ok();
+    }
 
 
-            //当前设备下的所有基本要素
-            List<ProjectDeviceVO> projectDeviceList = projectMapper.selectDeviceByProjectId(mountainId, Long.parseLong(projectId), Long.parseLong(deviceId));
-            if (!CollectionUtils.isEmpty(projectDeviceList)) {
-                for (ProjectDeviceVO projectDeviceVO : projectDeviceList) {
-                    String partName = projectDeviceVO.getPartName();
-                    //设置过阈值的基本要素
-                    List<KwsDeviceReference> references = deviceReferenceMapper.selectList(new LambdaQueryWrapper<KwsDeviceReference>()
-                            .eq(KwsDeviceReference::getDeviceId, deviceId)
-                            .eq(KwsDeviceReference::getMountainId, mountainId)
-                            .eq(KwsDeviceReference::getType, 1)
-                            .eq(KwsDeviceReference::getItem, partName)
-                            .eq(KwsDeviceReference::getDelFlag, NumberConstant.ZERO)
+    private void integrationItemWeek(HeaderData headerData, String deviceId, KwsDevice kwsDevice, List<Map<String, ProjectCatLogVO>> returnList, String type) {
+        List<KwsDeviceIntegration> deviceIntegrations = deviceIntegrationMapper.selectList(new LambdaQueryWrapper<KwsDeviceIntegration>()
+                .eq(KwsDeviceIntegration::getMountainId, headerData.getMountainId())
+                .eq(KwsDeviceIntegration::getDeviceId, deviceId)
+        );
+        List<Long> longList = new ArrayList<>();
+        if (!CollectionUtils.isEmpty(deviceIntegrations)) {
+            longList = deviceIntegrations.stream().map(KwsDeviceIntegration::getIntegrationId).collect(Collectors.toList());
+        }
+        if (!CollectionUtils.isEmpty(longList)) {
+            List<KwsIntegration> kwsIntegrations = integrationMapper.selectList(new LambdaQueryWrapper<KwsIntegration>()
+                    .in(KwsIntegration::getId, longList)
+                    .eq(org.apache.commons.lang3.StringUtils.isNotBlank(type),KwsIntegration::getIntegrationName,type));
+            if (!CollectionUtils.isEmpty(kwsIntegrations) && kwsIntegrations.size() > 0) {
+                kwsIntegrations.forEach(integration -> {
+                    Map<String, ProjectCatLogVO> returnMap = new HashMap<>(NumberConstant.SIXTEEN);
+                    ProjectCatLogVO projectCatLogVO = new ProjectCatLogVO();
+                    String integrationName = integration.getIntegrationName();
+                    String partNames = integration.getPartNames();
+                    List<KwsDeviceReference> referenceList = deviceReferenceMapper.selectList(new LambdaQueryWrapper<KwsDeviceReference>()
+                            .eq(KwsDeviceReference::getMountainId, headerData.getMountainId())
+                            .eq(KwsDeviceReference::getDeviceId, Long.parseLong(deviceId))
+                            .eq(KwsDeviceReference::getItem, integrationName)
+                            .eq(KwsDeviceReference::getDelFlag, 0)
+                            .eq(KwsDeviceReference::getType, 2)
                     );
                     );
-                    KwsDeviceReference deviceReference = new KwsDeviceReference();
-                    if (!CollectionUtils.isEmpty(references)) {
-                        deviceReference = references.get(0);
+                    //当前基准值
+                    projectCatLogVO.setReference(CollectionUtils.isEmpty(referenceList) ? null :
+                            (referenceList.get(0).getCurrentValue() == null ? null : referenceList.get(0).getCurrentValue()));
+                    //当前要素阈值
+                    List<KwsThreshold> kwsThresholds = thresholdMapper.selectList(new LambdaQueryWrapper<KwsThreshold>()
+                            .eq(KwsThreshold::getDelFlag, 0)
+                            .eq(KwsThreshold::getItemName, integrationName)
+                            .eq(KwsThreshold::getMountainId, headerData.getMountainId())
+                            .eq(KwsThreshold::getDeviceId, deviceId)
+                    );
+                    Map<Integer, List<KwsThreshold>> listMap = new HashMap<>();
+                    if (!CollectionUtils.isEmpty(kwsThresholds)) {
+                        listMap = kwsThresholds.stream().collect(Collectors.groupingBy(KwsThreshold::getLevel));
+                    }
+                    //阈值等级map
+//                Map<String, Map<String, String>> thresholdMap = new HashMap<>();
+//                Map<String, String> map = new HashMap<>();
+                    ThresholdLevelVO thresholdLevelVO = new ThresholdLevelVO();
+                    String thresholdMax = "";
+                    String thresholdMin = "";
+                    if (listMap.get(1) != null) {
+                        KwsThreshold kwsThreshold = listMap.get(1).get(0);
+                        thresholdMax = kwsThreshold.getMax();
+                        thresholdMin = kwsThreshold.getMin();
+                        thresholdLevelVO.setThresholdMax(thresholdMax);
+                        thresholdLevelVO.setThresholdMin(thresholdMin);
+//                    map.put("thresholdMax", thresholdMax);
+//                    map.put("thresholdMin", thresholdMin);
+                    }
+//                thresholdMap.put("oneLevelAlarm", map);
+                    projectCatLogVO.setOneLevelAlarm(thresholdLevelVO);
+                    if (listMap.get(2) != null) {
+                        KwsThreshold kwsThreshold = listMap.get(2).get(0);
+                        thresholdMax = kwsThreshold.getMax();
+                        thresholdMin = kwsThreshold.getMin();
+                        thresholdLevelVO.setThresholdMax(thresholdMax);
+                        thresholdLevelVO.setThresholdMin(thresholdMin);
+//                    map.put("thresholdMax", thresholdMax);
+//                    map.put("thresholdMin", thresholdMin);
+                    }
+//                thresholdMap.put("twoLevelAlarm", map);
+                    projectCatLogVO.setTwoLevelAlarm(thresholdLevelVO);
+
+                    if (listMap.get(3) != null) {
+                        KwsThreshold kwsThreshold = listMap.get(3).get(0);
+                        thresholdMax = kwsThreshold.getMax();
+                        thresholdMin = kwsThreshold.getMin();
+                        thresholdLevelVO.setThresholdMax(thresholdMax);
+                        thresholdLevelVO.setThresholdMin(thresholdMin);
+//                    map.put("thresholdMax", thresholdMax);
+//                    map.put("thresholdMin", thresholdMin);
+                    }
+//                thresholdMap.put("threeLevelAlarm", map);
+                    projectCatLogVO.setThreeLevelAlarm(thresholdLevelVO);
+
+                    //当前测量值-TD获取
+                    String formula = integration.getFormula();
+                    List<String> stringList = StringUtils.splitStrToList(partNames, String.class);
+                    if (!CollectionUtils.isEmpty(stringList)) {
+                        for (String item : stringList) {
+                            //当前仅有加速度
+                            BigDecimal decimal = new BigDecimal("0.00");
+                            Date date = new Date();
+                            String dateStart = DateUtil.getDateTimeToHour(date, 24);
+                            String dateEnd = DateUtil.localDateTimeFormat(LocalDateTime.now());
+                            List<SlopeData> selected = slopeDataMapper.selectLineList(kwsDevice.getSnCode(), item, dateStart, dateEnd);
+                            List<Map<String, Object>> mapList = new ArrayList<>();
+                            if (!CollectionUtils.isEmpty(selected)) {
+                                for (int i = 0; i < selected.size(); i++) {
+                                    Map<String, Object> map = new HashMap<>();
+                                    SlopeData currSlopeData = selected.get(i);
+                                    String key = currSlopeData.getTs().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH"));
+                                    SlopeData lastSlopeData = selected.get(i + 1);
+                                    LocalDateTime localDateTime = currSlopeData.getTs();
+                                    long epochMilli1 = 0L;
+                                    String val2 = "0";
+                                    LocalDateTime localDateTime1 = lastSlopeData.getTs();
+                                    if (lastSlopeData != null) {
+                                        epochMilli1 = localDateTime1.toInstant(ZoneOffset.of("+8")).toEpochMilli();
+                                        val2 = lastSlopeData.getVal();
+                                    }
+                                    long epochMilli = localDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();
+                                    epochMilli1 = localDateTime1.toInstant(ZoneOffset.of("+8")).toEpochMilli();
+                                    String val1 = currSlopeData.getVal();
+                                    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))));
+                                    map.put(key, decimal);
+                                    mapList.add(map);
+                                }
+                            }
+                            projectCatLogVO.setType(integrationName);
+                            projectCatLogVO.setMonitor(mapList);
+                            returnMap.put(integrationName, projectCatLogVO);
+                            returnList.add(returnMap);
+                        }
                     }
                     }
-                    SlopeData slopeData = slopeDataMapper.selectListByLine(kwsDevice.getSnCode(), partName);
-                    String val = slopeData == null ? null : slopeData.getVal();
-                    //基准值
-                    BigDecimal currentValue = deviceReference.getCurrentValue();
-                    BigDecimal offsetValue = new BigDecimal("0.00");
-                    if (currentValue != null) {
-                        /**存在经纬度海拔值的需要公式计算*/
-                        List<String> itemList = new ArrayList<>();
-                        itemList.add(DictItemEnum.LONGITUDE_X.getValue());
-                        Date date = new Date();
-                        String dateStart = DateUtil.getDateTimeToHour(date, 24);
+                });
+            }
+        }
+    }
+
+    /**
+     * 周为纬度  折线图计算
+     *
+     * @param mountainId 所属企业
+     * @param projectId  所属项目
+     * @param deviceId   所属设备
+     * @param kwsDevice  设备信息
+     * @param returnList 返回数据
+     * @param dateList   时间范围
+     */
+    private void basicItemByWeek(String mountainId, String projectId, String deviceId, KwsDevice kwsDevice, List<Map<String, ProjectCatLogVO>> returnList, List<Date> dateList, String type) {
+        List<ProjectDeviceVO> projectDeviceList = projectMapper.selectDeviceByProjectId(mountainId, Long.parseLong(projectId), Long.parseLong(deviceId), type);
+        if (!CollectionUtils.isEmpty(projectDeviceList)) {
+            for (ProjectDeviceVO projectDeviceVO : projectDeviceList) {
+                Map<String, ProjectCatLogVO> returnMap = new HashMap<>();
+                ProjectCatLogVO returnVO = new ProjectCatLogVO();
+                String partName = projectDeviceVO.getPartName();
+                Map<String, SystemDict> dictByDictCode = commonService.getDictByDictCode(DictEnum.MODEL_PART);
+                String itemName = dictByDictCode.get(partName) == null ? partName : dictByDictCode.get(partName).getLabel();
+                //设置过阈值的基本要素
+                List<KwsDeviceReference> references = deviceReferenceMapper.selectList(new LambdaQueryWrapper<KwsDeviceReference>()
+                        .eq(KwsDeviceReference::getDeviceId, deviceId)
+                        .eq(KwsDeviceReference::getMountainId, mountainId)
+                        .eq(KwsDeviceReference::getType, 1)
+                        .eq(KwsDeviceReference::getItem, partName)
+                        .eq(KwsDeviceReference::getDelFlag, NumberConstant.ZERO)
+                );
+                KwsDeviceReference deviceReference = new KwsDeviceReference();
+                if (!CollectionUtils.isEmpty(references)) {
+                    deviceReference = references.get(0);
+                }
+                //基准值
+                BigDecimal currentValue = deviceReference.getCurrentValue();
+                List<KwsThreshold> kwsThresholds = thresholdMapper.selectList(new LambdaQueryWrapper<KwsThreshold>()
+                        .eq(KwsThreshold::getDelFlag, 0)
+                        .eq(KwsThreshold::getItemName, partName)
+                        .eq(KwsThreshold::getMountainId, mountainId)
+                        .eq(KwsThreshold::getDeviceId, deviceId)
+                );
+                Map<Integer, List<KwsThreshold>> listMap = new HashMap<>();
+                if (!CollectionUtils.isEmpty(kwsThresholds)) {
+                    listMap = kwsThresholds.stream().collect(Collectors.groupingBy(KwsThreshold::getLevel));
+                }
+                ThresholdLevelVO thresholdLevelVO = new ThresholdLevelVO();
+                String thresholdMax = "";
+                String thresholdMin = "";
+                if (listMap.get(1) != null) {
+                    KwsThreshold kwsThreshold = listMap.get(1).get(0);
+                    thresholdMax = kwsThreshold.getMax();
+                    thresholdMin = kwsThreshold.getMin();
+                    thresholdLevelVO.setThresholdMax(thresholdMax);
+                    thresholdLevelVO.setThresholdMin(thresholdMin);
+                }
+                returnVO.setOneLevelAlarm(thresholdLevelVO);
+                if (listMap.get(2) != null) {
+                    KwsThreshold kwsThreshold = listMap.get(2).get(0);
+                    thresholdMax = kwsThreshold.getMax();
+                    thresholdMin = kwsThreshold.getMin();
+                    thresholdLevelVO.setThresholdMax(thresholdMax);
+                    thresholdLevelVO.setThresholdMin(thresholdMin);
+                }
+                returnVO.setTwoLevelAlarm(thresholdLevelVO);
+                if (listMap.get(3) != null) {
+                    KwsThreshold kwsThreshold = listMap.get(3).get(0);
+                    thresholdMax = kwsThreshold.getMax();
+                    thresholdMin = kwsThreshold.getMin();
+                    thresholdLevelVO.setThresholdMax(thresholdMax);
+                    thresholdLevelVO.setThresholdMin(thresholdMin);
+                }
+                returnVO.setThreeLevelAlarm(thresholdLevelVO);
+                //时间统计轴(当前数据检测值)
+                List<Map<String, Object>> 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);
                         String dateEnd = DateUtil.localDateTimeFormat(LocalDateTime.now());
                         String dateEnd = DateUtil.localDateTimeFormat(LocalDateTime.now());
                         List<SlopeData> selected = slopeDataMapper.selectLineList(kwsDevice.getSnCode(), partName, dateStart, dateEnd);
                         List<SlopeData> selected = slopeDataMapper.selectLineList(kwsDevice.getSnCode(), partName, dateStart, dateEnd);
-                        if (!CollectionUtils.isEmpty(selected)){
+                        if (!CollectionUtils.isEmpty(selected)) {
                             for (SlopeData message : selected) {
                             for (SlopeData message : selected) {
+                                BigDecimal offsetValue = new BigDecimal("0.00");
+                                Map<String, Object> datemap = new HashMap<>(NumberConstant.SIXTEEN);
+                                LocalDateTime createTime = message.getCreateTime();
+                                String key = createTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH"));
                                 String line = message.getLine();
                                 String line = message.getLine();
                                 String val1 = message.getVal();
                                 String val1 = message.getVal();
                                 if (itemList.contains(partName)) {
                                 if (itemList.contains(partName)) {
@@ -427,8 +701,8 @@ public class ProjectService {
                                         SlopeData selectListByLine = slopeDataMapper.selectListByLine(kwsDevice.getSnCode(), "2");
                                         SlopeData selectListByLine = slopeDataMapper.selectListByLine(kwsDevice.getSnCode(), "2");
                                         double angleInRadians = Math.toRadians(selected == null ? 0L : Double.parseDouble(selectListByLine.getVal()));
                                         double angleInRadians = Math.toRadians(selected == null ? 0L : Double.parseDouble(selectListByLine.getVal()));
                                         double cosValue = Math.cos(angleInRadians);
                                         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();
+                                        if (org.apache.commons.lang3.StringUtils.isNotBlank(val1)) {
+                                            double doubleValue = (new BigDecimal(val1).subtract(currentValue)).divide(new BigDecimal(360)).doubleValue();
                                             offsetValue = new BigDecimal(equatorial_circumference).multiply(new BigDecimal(cosValue)).multiply(new BigDecimal(doubleValue));
                                             offsetValue = new BigDecimal(equatorial_circumference).multiply(new BigDecimal(cosValue)).multiply(new BigDecimal(doubleValue));
                                         }
                                         }
                                     }
                                     }
@@ -436,8 +710,8 @@ public class ProjectService {
                                 itemList.add(DictItemEnum.LATITUDE_Y.getValue());
                                 itemList.add(DictItemEnum.LATITUDE_Y.getValue());
                                 if (itemList.contains(partName)) {
                                 if (itemList.contains(partName)) {
                                     if (Objects.nonNull(currentValue)) {
                                     if (Objects.nonNull(currentValue)) {
-                                        if (org.apache.commons.lang3.StringUtils.isNotBlank(val)) {
-                                            offsetValue = new BigDecimal(val).subtract(currentValue);
+                                        if (org.apache.commons.lang3.StringUtils.isNotBlank(line)) {
+                                            offsetValue = new BigDecimal(line).subtract(currentValue);
                                         }
                                         }
                                     }
                                     }
                                 }
                                 }
@@ -445,51 +719,290 @@ public class ProjectService {
                                 itemList.add(DictItemEnum.ALTITUDE_Z.getValue());
                                 itemList.add(DictItemEnum.ALTITUDE_Z.getValue());
                                 if (itemList.contains(partName)) {
                                 if (itemList.contains(partName)) {
                                     if (Objects.nonNull(currentValue)) {
                                     if (Objects.nonNull(currentValue)) {
-                                        if (org.apache.commons.lang3.StringUtils.isNotBlank(val)) {
-                                            offsetValue = new BigDecimal(val).divide(new BigDecimal(1000));
+                                        if (org.apache.commons.lang3.StringUtils.isNotBlank(line)) {
+                                            offsetValue = new BigDecimal(line).divide(new BigDecimal(1000));
                                         }
                                         }
                                     }
                                     }
                                 }
                                 }
+                                datemap.put(key, offsetValue);
+                                mapList.add(datemap);
                             }
                             }
                         }
                         }
-
                     }
                     }
                 }
                 }
+                returnVO.setType(partName);
+                returnVO.setMonitor(mapList);
+                returnMap.put(itemName, returnVO);
+                returnList.add(returnMap);
             }
             }
+        }
+    }
 
 
-            LocalDateTime localDateTime = DateUtil.localDateToLocalDateTimeStart(LocalDate.now());
-        } else if (String.valueOf(NumberConstant.THREE).equals(latitude)) {
-//            //开始时间
-//            dateStart = DateUtil.getLastWeekDateStartToString(LocalDate.now(), 6);
-//            //结束时间
-//            dateEnd = DateUtil.getLastWeekDateEndToString(0);
-            List<String> dateTimeDay = DateUtil.getDateTimeDay(LocalDateTime.now(), 7, new ArrayList<String>());
-            for (String dateTime : dateTimeDay) {
-
-            }
-            /**下面是查询当天每小时数据总量的代码示例:
-
-             SELECT DATE_FORMAT(timestamp, '%Y-%m-%d %H:00:00') AS hour,
-             COUNT(*) AS count
-             FROM data
-             WHERE DATE(timestamp) = CURDATE()
-             GROUP BY hour;*/
+    /**
+     * 集成要素折线图计算
+     */
+    private void integrationItem(HeaderData headerData, String deviceId, KwsDevice kwsDevice, List<Map<String, ProjectCatLogVO>> returnList, String type) {
+        List<KwsDeviceIntegration> deviceIntegrations = deviceIntegrationMapper.selectList(new LambdaQueryWrapper<KwsDeviceIntegration>()
+                .eq(KwsDeviceIntegration::getMountainId, headerData.getMountainId())
+                .eq(KwsDeviceIntegration::getDeviceId, deviceId)
+        );
+        List<Long> longList = new ArrayList<>();
+        if (!CollectionUtils.isEmpty(deviceIntegrations)) {
+            longList = deviceIntegrations.stream().map(KwsDeviceIntegration::getIntegrationId).collect(Collectors.toList());
+        }
+        if (!CollectionUtils.isEmpty(longList)) {
+            List<KwsIntegration> kwsIntegrations = integrationMapper.selectList(new LambdaQueryWrapper<KwsIntegration>()
+                    .in(KwsIntegration::getId, longList)
+                    .eq(org.apache.commons.lang3.StringUtils.isNotBlank(type),KwsIntegration::getIntegrationName,type));
+            if (!CollectionUtils.isEmpty(kwsIntegrations) && kwsIntegrations.size() > 0) {
+                kwsIntegrations.forEach(integration -> {
+                    Map<String, ProjectCatLogVO> returnMap = new HashMap<>(NumberConstant.SIXTEEN);
+                    ProjectCatLogVO projectCatLogVO = new ProjectCatLogVO();
+                    String integrationName = integration.getIntegrationName();
+                    String partNames = integration.getPartNames();
+                    List<KwsDeviceReference> referenceList = deviceReferenceMapper.selectList(new LambdaQueryWrapper<KwsDeviceReference>()
+                            .eq(KwsDeviceReference::getMountainId, headerData.getMountainId())
+                            .eq(KwsDeviceReference::getDeviceId, Long.parseLong(deviceId))
+                            .eq(KwsDeviceReference::getItem, integrationName)
+                            .eq(KwsDeviceReference::getDelFlag, 0)
+                            .eq(KwsDeviceReference::getType, 2)
+                    );
+                    //当前基准值
+                    projectCatLogVO.setReference(CollectionUtils.isEmpty(referenceList) ? null :
+                            (referenceList.get(0).getCurrentValue() == null ? null : referenceList.get(0).getCurrentValue()));
+                    //当前要素阈值
+                    List<KwsThreshold> kwsThresholds = thresholdMapper.selectList(new LambdaQueryWrapper<KwsThreshold>()
+                            .eq(KwsThreshold::getDelFlag, 0)
+                            .eq(KwsThreshold::getItemName, integrationName)
+                            .eq(KwsThreshold::getMountainId, headerData.getMountainId())
+                            .eq(KwsThreshold::getDeviceId, deviceId)
+                    );
+                    Map<Integer, List<KwsThreshold>> listMap = new HashMap<>();
+                    if (!CollectionUtils.isEmpty(kwsThresholds)) {
+                        listMap = kwsThresholds.stream().collect(Collectors.groupingBy(KwsThreshold::getLevel));
+                    }
+                    //阈值等级map
+//                Map<String, Map<String, String>> thresholdMap = new HashMap<>();
+//                Map<String, String> map = new HashMap<>();
+                    ThresholdLevelVO thresholdLevelVO = new ThresholdLevelVO();
+                    String thresholdMax = "";
+                    String thresholdMin = "";
+                    if (listMap.get(1) != null) {
+                        KwsThreshold kwsThreshold = listMap.get(1).get(0);
+                        thresholdMax = kwsThreshold.getMax();
+                        thresholdMin = kwsThreshold.getMin();
+                        thresholdLevelVO.setThresholdMax(thresholdMax);
+                        thresholdLevelVO.setThresholdMin(thresholdMin);
+//                    map.put("thresholdMax", thresholdMax);
+//                    map.put("thresholdMin", thresholdMin);
+                    }
+//                thresholdMap.put("oneLevelAlarm", map);
+                    projectCatLogVO.setOneLevelAlarm(thresholdLevelVO);
+                    if (listMap.get(2) != null) {
+                        KwsThreshold kwsThreshold = listMap.get(2).get(0);
+                        thresholdMax = kwsThreshold.getMax();
+                        thresholdMin = kwsThreshold.getMin();
+                        thresholdLevelVO.setThresholdMax(thresholdMax);
+                        thresholdLevelVO.setThresholdMin(thresholdMin);
+//                    map.put("thresholdMax", thresholdMax);
+//                    map.put("thresholdMin", thresholdMin);
+                    }
+//                thresholdMap.put("twoLevelAlarm", map);
+                    projectCatLogVO.setTwoLevelAlarm(thresholdLevelVO);
 
 
-            /** 下面是查询当天每小时某个字段平均值的代码示例:
+                    if (listMap.get(3) != null) {
+                        KwsThreshold kwsThreshold = listMap.get(3).get(0);
+                        thresholdMax = kwsThreshold.getMax();
+                        thresholdMin = kwsThreshold.getMin();
+                        thresholdLevelVO.setThresholdMax(thresholdMax);
+                        thresholdLevelVO.setThresholdMin(thresholdMin);
+//                    map.put("thresholdMax", thresholdMax);
+//                    map.put("thresholdMin", thresholdMin);
+                    }
+//                thresholdMap.put("threeLevelAlarm", map);
+                    projectCatLogVO.setThreeLevelAlarm(thresholdLevelVO);
 
 
+                    //当前测量值-TD获取
+                    String formula = integration.getFormula();
+                    List<String> stringList = StringUtils.splitStrToList(partNames, String.class);
+                    if (!CollectionUtils.isEmpty(stringList)) {
+                        for (String item : stringList) {
+                            //当前仅有加速度
+                            BigDecimal decimal = new BigDecimal("0.00");
+                            Date date = new Date();
+                            String dateStart = DateUtil.getDateTimeToHour(date, 24);
+                            String dateEnd = DateUtil.localDateTimeFormat(LocalDateTime.now());
+                            List<SlopeData> selected = slopeDataMapper.selectLineList(kwsDevice.getSnCode(), item, dateStart, dateEnd);
+                            List<Map<String, Object>> mapList = new ArrayList<>();
+                            if (!CollectionUtils.isEmpty(selected)) {
+                                for (int i = 0; i < selected.size(); i++) {
+                                    Map<String, Object> map = new HashMap<>();
+                                    SlopeData currSlopeData = selected.get(i);
+                                    String key = currSlopeData.getTs().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH"));
+                                    SlopeData lastSlopeData = selected.get(i + 1);
+                                    LocalDateTime localDateTime = currSlopeData.getTs();
+                                    long epochMilli1 = 0L;
+                                    String val2 = "0";
+                                    LocalDateTime localDateTime1 = lastSlopeData.getTs();
+                                    if (lastSlopeData != null) {
+                                        epochMilli1 = localDateTime1.toInstant(ZoneOffset.of("+8")).toEpochMilli();
+                                        val2 = lastSlopeData.getVal();
+                                    }
+                                    long epochMilli = localDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();
+                                    epochMilli1 = localDateTime1.toInstant(ZoneOffset.of("+8")).toEpochMilli();
+                                    String val1 = currSlopeData.getVal();
+                                    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))));
+                                    map.put(key, decimal);
+                                    mapList.add(map);
+                                }
+                            }
+                            projectCatLogVO.setType(integrationName);
+                            projectCatLogVO.setMonitor(mapList);
+                            returnMap.put(integrationName, projectCatLogVO);
+                            returnList.add(returnMap);
+                        }
+                    }
+                });
+            }
+        }
+    }
 
 
-             SELECT DATE_FORMAT(timestamp, '%Y-%m-%d %H:00:00') AS hour,
-             AVG(value) AS average
-             FROM data
-             WHERE DATE(timestamp) = CURDATE()
-             GROUP BY hour;*/
+    /**
+     * 折线图 基本要素
+     */
+    private void basicItem(String mountainId, String projectId, String deviceId, KwsDevice kwsDevice, List<Map<String, ProjectCatLogVO>> returnList, String type) {
+        List<ProjectDeviceVO> projectDeviceList = projectMapper.selectDeviceByProjectId(mountainId, Long.parseLong(projectId), Long.parseLong(deviceId), type);
+        if (!CollectionUtils.isEmpty(projectDeviceList)) {
+            for (ProjectDeviceVO projectDeviceVO : projectDeviceList) {
+                Map<String, ProjectCatLogVO> returnMap = new HashMap<>();
+                ProjectCatLogVO returnVO = new ProjectCatLogVO();
+                String partName = projectDeviceVO.getPartName();
+                Map<String, SystemDict> dictByDictCode = commonService.getDictByDictCode(DictEnum.MODEL_PART);
+                String itemName = dictByDictCode.get(partName) == null ? partName : dictByDictCode.get(partName).getLabel();
+                //设置过阈值的基本要素
+                List<KwsDeviceReference> references = deviceReferenceMapper.selectList(new LambdaQueryWrapper<KwsDeviceReference>()
+                        .eq(KwsDeviceReference::getDeviceId, deviceId)
+                        .eq(KwsDeviceReference::getMountainId, mountainId)
+                        .eq(KwsDeviceReference::getType, 1)
+                        .eq(KwsDeviceReference::getItem, partName)
+                        .eq(KwsDeviceReference::getDelFlag, NumberConstant.ZERO)
+                );
+                KwsDeviceReference deviceReference = new KwsDeviceReference();
+                if (!CollectionUtils.isEmpty(references)) {
+                    deviceReference = references.get(0);
+                }
+                //基准值
+                BigDecimal currentValue = deviceReference == null ? null : deviceReference.getCurrentValue();
+                returnVO.setReference(currentValue);
+                List<KwsThreshold> kwsThresholds = thresholdMapper.selectList(new LambdaQueryWrapper<KwsThreshold>()
+                        .eq(KwsThreshold::getDelFlag, 0)
+                        .eq(KwsThreshold::getItemName, partName)
+                        .eq(KwsThreshold::getMountainId, mountainId)
+                        .eq(KwsThreshold::getDeviceId, deviceId)
+                );
+                Map<Integer, List<KwsThreshold>> listMap = new HashMap<>();
+                if (!CollectionUtils.isEmpty(kwsThresholds)) {
+                    listMap = kwsThresholds.stream().collect(Collectors.groupingBy(KwsThreshold::getLevel));
+                }
+                //阈值等级map
+//                Map<String, Map<String, String>> thresholdMap = new HashMap<>();
+//                Map<String, String> map = new HashMap<>();
+                ThresholdLevelVO thresholdLevelVO = new ThresholdLevelVO();
+                String thresholdMax = "";
+                String thresholdMin = "";
+                if (listMap.get(1) != null) {
+                    KwsThreshold kwsThreshold = listMap.get(1).get(0);
+                    thresholdMax = kwsThreshold.getMax();
+                    thresholdMin = kwsThreshold.getMin();
+                    thresholdLevelVO.setThresholdMax(thresholdMax);
+                    thresholdLevelVO.setThresholdMin(thresholdMin);
+//                    map.put("thresholdMax", thresholdMax);
+//                    map.put("thresholdMin", thresholdMin);
+                }
+//                thresholdMap.put("oneLevelAlarm", map);
+                returnVO.setOneLevelAlarm(thresholdLevelVO);
+                if (listMap.get(2) != null) {
+                    KwsThreshold kwsThreshold = listMap.get(2).get(0);
+                    thresholdMax = kwsThreshold.getMax();
+                    thresholdMin = kwsThreshold.getMin();
+                    thresholdLevelVO.setThresholdMax(thresholdMax);
+                    thresholdLevelVO.setThresholdMin(thresholdMin);
+//                    map.put("thresholdMax", thresholdMax);
+//                    map.put("thresholdMin", thresholdMin);
+                }
+//                thresholdMap.put("twoLevelAlarm", map);
+                returnVO.setTwoLevelAlarm(thresholdLevelVO);
 
 
-        } else if (String.valueOf(NumberConstant.TWO).equals(latitude)) {
-        } else if (String.valueOf(NumberConstant.ONE).equals(latitude)) {
-        } else {
-            throw new BusinessException("数据传输异常");
+                if (listMap.get(3) != null) {
+                    KwsThreshold kwsThreshold = listMap.get(3).get(0);
+                    thresholdMax = kwsThreshold.getMax();
+                    thresholdMin = kwsThreshold.getMin();
+                    thresholdLevelVO.setThresholdMax(thresholdMax);
+                    thresholdLevelVO.setThresholdMin(thresholdMin);
+//                    map.put("thresholdMax", thresholdMax);
+//                    map.put("thresholdMin", thresholdMin);
+                }
+//                thresholdMap.put("threeLevelAlarm", map);
+                returnVO.setThreeLevelAlarm(thresholdLevelVO);
+                //时间统计轴(当前数据检测值)
+                List<Map<String, Object>> mapList = new ArrayList<>();
+                if (currentValue != null) {
+                    /**存在经纬度海拔值的需要公式计算*/
+                    List<String> itemList = new ArrayList<>();
+                    itemList.add(DictItemEnum.LONGITUDE_X.getValue());
+                    Date date = new Date();
+                    String dateStart = DateUtil.getDateTimeToHour(date, 24);
+                    String dateEnd = DateUtil.localDateTimeFormat(LocalDateTime.now());
+                    List<SlopeData> selected = slopeDataMapper.selectLineList(kwsDevice.getSnCode(), partName, dateStart, dateEnd);
+                    if (!CollectionUtils.isEmpty(selected)) {
+                        for (SlopeData message : selected) {
+                            BigDecimal offsetValue = new BigDecimal("0.00");
+                            Map<String, Object> datemap = new HashMap<>(NumberConstant.SIXTEEN);
+                            LocalDateTime createTime = message.getCreateTime();
+                            String key = createTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH"));
+                            String line = message.getLine();
+                            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()));
+                                    double cosValue = Math.cos(angleInRadians);
+                                    if (org.apache.commons.lang3.StringUtils.isNotBlank(val1)) {
+                                        double doubleValue = (new BigDecimal(val1).subtract(currentValue)).divide(new BigDecimal(360)).doubleValue();
+                                        offsetValue = new BigDecimal(equatorial_circumference).multiply(new BigDecimal(cosValue)).multiply(new BigDecimal(doubleValue));
+                                    }
+                                }
+                            }
+                            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);
+                                    }
+                                }
+                            }
+                            itemList.clear();
+                            itemList.add(DictItemEnum.ALTITUDE_Z.getValue());
+                            if (itemList.contains(partName)) {
+                                if (Objects.nonNull(currentValue)) {
+                                    if (org.apache.commons.lang3.StringUtils.isNotBlank(line)) {
+                                        offsetValue = new BigDecimal(line).divide(new BigDecimal(1000));
+                                    }
+                                }
+                            }
+                            datemap.put(key, offsetValue);
+                            mapList.add(datemap);
+                        }
+                    }
+                }
+                returnVO.setType(partName);
+                returnVO.setMonitor(mapList);
+                returnMap.put(itemName, returnVO);
+                returnList.add(returnMap);
+            }
         }
         }
-        return null;
     }
     }
 
 
 
 
@@ -571,6 +1084,23 @@ public class ProjectService {
                     .set(KwsDevice::getUpdateBy, headerData.getUpdateBy() == null ? Long.parseLong(headerData.getCreateBy()) : Long.parseLong(headerData.getUpdateBy()))
                     .set(KwsDevice::getUpdateBy, headerData.getUpdateBy() == null ? Long.parseLong(headerData.getCreateBy()) : Long.parseLong(headerData.getUpdateBy()))
             );
             );
         }
         }
+        if (!CollectionUtils.isEmpty(deleteList)) {
+            List<KwsDevice> kwsDevices = deviceMapper.selectList(new LambdaQueryWrapper<KwsDevice>().in(KwsDevice::getId, deleteList).eq(KwsDevice::getDelFlag, 0));
+            if (!CollectionUtils.isEmpty(kwsDevices)) {
+                StringBuilder deviceName = new StringBuilder();
+                for (int i = 0; i < kwsDevices.size(); i++) {
+                    if (i != kwsDevices.size() - 1) {
+                        deviceName.append(kwsDevices.get(i).getName()).append(",");
+                    } else {
+                        deviceName.append(kwsDevices.get(i).getName());
+                    }
+                }
+                Map<String, Object> logMap = new HashMap<>(NumberConstant.SIXTEEN);
+                logMap.put("projectName", project.getName());
+                logMap.put("deviceName", deviceName.toString());
+                commonService.insertLog(MessageLogEnum.DELETE_NETWORKING_DEVICE, headerData, logMap, headerData.getUpdateBy() == null ? null : Long.parseLong(headerData.getUpdateBy()));
+            }
+        }
         return HttpResult.ok("删除关联设备成功!");
         return HttpResult.ok("删除关联设备成功!");
     }
     }
 }
 }

+ 22 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/ReportService.java

@@ -1,15 +1,20 @@
 package com.sckw.slope.detection.service;
 package com.sckw.slope.detection.service;
 
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import com.github.pagehelper.PageInfo;
+import com.sckw.core.exception.BusinessException;
 import com.sckw.core.model.constant.NumberConstant;
 import com.sckw.core.model.constant.NumberConstant;
+import com.sckw.core.model.enums.MessageLogEnum;
 import com.sckw.core.model.enums.ReportEnum;
 import com.sckw.core.model.enums.ReportEnum;
 import com.sckw.core.model.enums.ReportTypeEnum;
 import com.sckw.core.model.enums.ReportTypeEnum;
 import com.sckw.core.model.page.PageRes;
 import com.sckw.core.model.page.PageRes;
 import com.sckw.core.web.response.HttpResult;
 import com.sckw.core.web.response.HttpResult;
+import com.sckw.slope.detection.dao.mysql.KwsProjectMapper;
 import com.sckw.slope.detection.dao.mysql.KwsReportDataMapper;
 import com.sckw.slope.detection.dao.mysql.KwsReportDataMapper;
 import com.sckw.slope.detection.dao.mysql.KwsReportTemplateMapper;
 import com.sckw.slope.detection.dao.mysql.KwsReportTemplateMapper;
+import com.sckw.slope.detection.model.dos.mysql.KwsProject;
 import com.sckw.slope.detection.model.dos.mysql.KwsReportTemplate;
 import com.sckw.slope.detection.model.dos.mysql.KwsReportTemplate;
 import com.sckw.slope.detection.model.dto.HeaderData;
 import com.sckw.slope.detection.model.dto.HeaderData;
 import com.sckw.slope.detection.model.param.StatementQuery;
 import com.sckw.slope.detection.model.param.StatementQuery;
@@ -22,7 +27,9 @@ import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.CollectionUtils;
 
 
 import java.time.LocalDateTime;
 import java.time.LocalDateTime;
+import java.util.HashMap;
 import java.util.List;
 import java.util.List;
+import java.util.Map;
 
 
 /**
 /**
  * @author lfdc
  * @author lfdc
@@ -38,6 +45,8 @@ public class ReportService {
 
 
     @Autowired
     @Autowired
     KwsReportDataMapper reportDataMapper;
     KwsReportDataMapper reportDataMapper;
+    @Autowired
+    KwsProjectMapper projectMapper;
 
 
     @Autowired
     @Autowired
     KwsReportTemplateMapper reportTemplateMapper;
     KwsReportTemplateMapper reportTemplateMapper;
@@ -67,12 +76,25 @@ public class ReportService {
 
 
     public HttpResult dels(String id, HttpServletRequest request) {
     public HttpResult dels(String id, HttpServletRequest request) {
         HeaderData headerData = commonService.getHeaderData(request);
         HeaderData headerData = commonService.getHeaderData(request);
+        KwsReportTemplate template = reportTemplateMapper.selectOne(new LambdaQueryWrapper<KwsReportTemplate>().eq(KwsReportTemplate::getDelFlag, 0)
+                .eq(KwsReportTemplate::getId, Long.parseLong(id)));
+        if (template == null) {
+            throw new BusinessException("模板删除失败,参数错误");
+        }
         reportTemplateMapper.update(null, new LambdaUpdateWrapper<KwsReportTemplate>()
         reportTemplateMapper.update(null, new LambdaUpdateWrapper<KwsReportTemplate>()
                 .eq(KwsReportTemplate::getId, Long.parseLong(id))
                 .eq(KwsReportTemplate::getId, Long.parseLong(id))
                 .set(KwsReportTemplate::getUpdateTime, LocalDateTime.now())
                 .set(KwsReportTemplate::getUpdateTime, LocalDateTime.now())
                 .set(KwsReportTemplate::getUpdateBy, (headerData.getUpdateBy() == null ? null : Long.parseLong(headerData.getUpdateBy())))
                 .set(KwsReportTemplate::getUpdateBy, (headerData.getUpdateBy() == null ? null : Long.parseLong(headerData.getUpdateBy())))
                 .set(KwsReportTemplate::getStatus, NumberConstant.ONE)
                 .set(KwsReportTemplate::getStatus, NumberConstant.ONE)
         );
         );
+        KwsProject project = projectMapper.selectOne(new LambdaQueryWrapper<KwsProject>()
+                .eq(KwsProject::getId, Long.parseLong(template.getProjectId())));
+        Map<String, Object> logMap = new HashMap<>(NumberConstant.SIXTEEN);
+        logMap.put("projectName", project.getName());
+        logMap.put("templateName", template.getName());
+        commonService.insertLog(MessageLogEnum.DELETE_REPORT_TEMPLATE, headerData, logMap, headerData.getUpdateBy() == null ?
+                null : Long.parseLong(headerData.getUpdateBy()));
+
         return HttpResult.ok("删除成功");
         return HttpResult.ok("删除成功");
     }
     }
 }
 }

+ 40 - 1
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/ReportTemplateService.java

@@ -4,10 +4,13 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.sckw.core.exception.BusinessException;
 import com.sckw.core.exception.BusinessException;
 import com.sckw.core.model.constant.NumberConstant;
 import com.sckw.core.model.constant.NumberConstant;
+import com.sckw.core.model.enums.MessageLogEnum;
 import com.sckw.core.model.enums.ReportTypeEnum;
 import com.sckw.core.model.enums.ReportTypeEnum;
 import com.sckw.core.utils.IdWorker;
 import com.sckw.core.utils.IdWorker;
 import com.sckw.core.web.response.HttpResult;
 import com.sckw.core.web.response.HttpResult;
+import com.sckw.slope.detection.dao.mysql.KwsProjectMapper;
 import com.sckw.slope.detection.dao.mysql.KwsReportTemplateMapper;
 import com.sckw.slope.detection.dao.mysql.KwsReportTemplateMapper;
+import com.sckw.slope.detection.model.dos.mysql.KwsProject;
 import com.sckw.slope.detection.model.dos.mysql.KwsReportTemplate;
 import com.sckw.slope.detection.model.dos.mysql.KwsReportTemplate;
 import com.sckw.slope.detection.model.dto.HeaderData;
 import com.sckw.slope.detection.model.dto.HeaderData;
 import com.sckw.slope.detection.model.dto.IsEnableDTO;
 import com.sckw.slope.detection.model.dto.IsEnableDTO;
@@ -22,6 +25,8 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
 
 
 import java.time.LocalDateTime;
 import java.time.LocalDateTime;
+import java.util.HashMap;
+import java.util.Map;
 
 
 /**
 /**
  * @author lfdc
  * @author lfdc
@@ -35,6 +40,9 @@ public class ReportTemplateService {
     @Autowired
     @Autowired
     CommonService commonService;
     CommonService commonService;
 
 
+    @Autowired
+    KwsProjectMapper projectMapper;
+
     @Autowired
     @Autowired
     KwsReportTemplateMapper reportTemplateMapper;
     KwsReportTemplateMapper reportTemplateMapper;
 
 
@@ -68,6 +76,12 @@ public class ReportTemplateService {
         template.setCreateTime(now);
         template.setCreateTime(now);
         template.setUpdateTime(now);
         template.setUpdateTime(now);
         reportTemplateMapper.insert(template);
         reportTemplateMapper.insert(template);
+        KwsProject project = projectMapper.selectOne(new LambdaQueryWrapper<KwsProject>()
+                .eq(KwsProject::getId, Long.parseLong(projectId)));
+        Map<String, Object> logMap = new HashMap<>(NumberConstant.SIXTEEN);
+        logMap.put("projectName", project.getName());
+        logMap.put("templateName", reportTemplateDTO.getName());
+        commonService.insertLog(MessageLogEnum.ADD_REPORT_TEMPLATE, headerData, logMap, headerData.getCreateBy() == null ? null : Long.parseLong(headerData.getCreateBy()));
         return HttpResult.ok();
         return HttpResult.ok();
     }
     }
 
 
@@ -111,6 +125,13 @@ public class ReportTemplateService {
         template.setStatus(Integer.parseInt(reportTemplateUpdateDTO.getStatus()));
         template.setStatus(Integer.parseInt(reportTemplateUpdateDTO.getStatus()));
         template.setUpdateBy(headerData.getUpdateBy() == null ? null : Long.parseLong(headerData.getUpdateBy()));
         template.setUpdateBy(headerData.getUpdateBy() == null ? null : Long.parseLong(headerData.getUpdateBy()));
         template.setUpdateTime(LocalDateTime.now());
         template.setUpdateTime(LocalDateTime.now());
+        KwsProject project = projectMapper.selectOne(new LambdaQueryWrapper<KwsProject>()
+                .eq(KwsProject::getId, Long.parseLong(template.getProjectId())));
+        Map<String, Object> logMap = new HashMap<>(NumberConstant.SIXTEEN);
+        logMap.put("projectName", project.getName());
+        logMap.put("templateName", template.getName());
+        commonService.insertLog(MessageLogEnum.UPDATE_REPORT_TEMPLATE, headerData, logMap, headerData.getUpdateBy() == null ?
+                null : Long.parseLong(headerData.getUpdateBy()));
         return HttpResult.ok();
         return HttpResult.ok();
     }
     }
 
 
@@ -121,12 +142,30 @@ public class ReportTemplateService {
         if (!isEnable.isFlag()) {
         if (!isEnable.isFlag()) {
             status = "1";
             status = "1";
         }
         }
+        Long templateId = Long.parseLong(isEnable.getId());
+        KwsReportTemplate template = reportTemplateMapper.selectOne(new LambdaQueryWrapper<KwsReportTemplate>()
+                .eq(KwsReportTemplate::getId, templateId)
+                .eq(KwsReportTemplate::getMountainId, headerData.getMountainId()));
+        if (template == null) {
+            throw new BusinessException("模板数据异常!");
+        }
         reportTemplateMapper.update(null, new LambdaUpdateWrapper<KwsReportTemplate>()
         reportTemplateMapper.update(null, new LambdaUpdateWrapper<KwsReportTemplate>()
                 .set(KwsReportTemplate::getStatus, status)
                 .set(KwsReportTemplate::getStatus, status)
                 .set(KwsReportTemplate::getUpdateTime, LocalDateTime.now())
                 .set(KwsReportTemplate::getUpdateTime, LocalDateTime.now())
                 .set(KwsReportTemplate::getUpdateBy, (headerData.getUpdateBy() == null ? null : Long.parseLong(headerData.getUpdateBy())))
                 .set(KwsReportTemplate::getUpdateBy, (headerData.getUpdateBy() == null ? null : Long.parseLong(headerData.getUpdateBy())))
-                .eq(KwsReportTemplate::getId, isEnable.getId())
+                .eq(KwsReportTemplate::getId, templateId)
         );
         );
+        KwsProject project = projectMapper.selectOne(new LambdaQueryWrapper<KwsProject>()
+                .eq(KwsProject::getId, Long.parseLong(template.getProjectId())));
+        Map<String, Object> logMap = new HashMap<>(NumberConstant.SIXTEEN);
+        logMap.put("projectName", project.getName());
+        logMap.put("templateName", template.getName());
+        MessageLogEnum messageLogEnum = MessageLogEnum.FORBIDDEN_REPORT_TEMPLATE;
+        if (isEnable.isFlag()) {
+             messageLogEnum = MessageLogEnum.FORBIDDEN_REPORT_TEMPLATE;
+        }
+        commonService.insertLog(messageLogEnum, headerData, logMap, headerData.getUpdateBy() == null ?
+                null : Long.parseLong(headerData.getUpdateBy()));
         return HttpResult.ok("修改成功");
         return HttpResult.ok("修改成功");
     }
     }
 }
 }

+ 18 - 1
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/TdengineDemoService.java

@@ -1,7 +1,9 @@
 package com.sckw.slope.detection.service;
 package com.sckw.slope.detection.service;
 
 
 import com.alibaba.fastjson2.JSONObject;
 import com.alibaba.fastjson2.JSONObject;
+import com.sckw.slope.detection.dao.tdengine.InsTablesMapper;
 import com.sckw.slope.detection.dao.tdengine.SlopeDataMapper;
 import com.sckw.slope.detection.dao.tdengine.SlopeDataMapper;
+import com.sckw.slope.detection.model.dos.tdengine.InsTables;
 import com.sckw.slope.detection.model.dos.tdengine.SlopeData;
 import com.sckw.slope.detection.model.dos.tdengine.SlopeData;
 import com.sckw.slope.detection.model.vo.SlopeDataVo;
 import com.sckw.slope.detection.model.vo.SlopeDataVo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -20,8 +22,11 @@ public class TdengineDemoService {
     @Autowired
     @Autowired
     SlopeDataMapper slopeDataMapper;
     SlopeDataMapper slopeDataMapper;
 
 
+    @Autowired
+    InsTablesMapper insTablesMapper;
+
     public void tdengineDemo() {
     public void tdengineDemo() {
-        List<SlopeDataVo> list = slopeDataMapper.selectAll("6","7");
+        List<SlopeDataVo> list = slopeDataMapper.selectAll("6", "7");
         System.out.println(JSONObject.toJSONString(list));
         System.out.println(JSONObject.toJSONString(list));
         List<SlopeDataVo> list1 = slopeDataMapper.selectList();
         List<SlopeDataVo> list1 = slopeDataMapper.selectList();
         System.out.println(JSONObject.toJSONString(list1));
         System.out.println(JSONObject.toJSONString(list1));
@@ -41,4 +46,16 @@ public class TdengineDemoService {
         data.setCreateTime(now);
         data.setCreateTime(now);
         int insert = slopeDataMapper.insertData(data);
         int insert = slopeDataMapper.insertData(data);
     }
     }
+
+    public void getTable() {
+        String tableName = "slope_data_6_7";
+        InsTables insTables = insTablesMapper.selectTableIsExit(tableName);
+        if (insTables != null){
+        }
+    }
+
+    public void createTable() {
+        String tableName = "slope_data_20231108";
+        insTablesMapper.createTable(tableName);
+    }
 }
 }

+ 17 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/ThresholdService.java

@@ -8,6 +8,7 @@ import com.sckw.core.exception.BusinessException;
 import com.sckw.core.model.constant.NumberConstant;
 import com.sckw.core.model.constant.NumberConstant;
 import com.sckw.core.model.enums.DeviceEnum;
 import com.sckw.core.model.enums.DeviceEnum;
 import com.sckw.core.model.enums.DictEnum;
 import com.sckw.core.model.enums.DictEnum;
+import com.sckw.core.model.enums.MessageLogEnum;
 import com.sckw.core.model.enums.ThresholdEnum;
 import com.sckw.core.model.enums.ThresholdEnum;
 import com.sckw.core.model.page.PageRes;
 import com.sckw.core.model.page.PageRes;
 import com.sckw.core.utils.IdWorker;
 import com.sckw.core.utils.IdWorker;
@@ -16,7 +17,9 @@ import com.sckw.core.utils.StringUtils;
 import com.sckw.core.web.constant.HttpStatus;
 import com.sckw.core.web.constant.HttpStatus;
 import com.sckw.core.web.response.HttpResult;
 import com.sckw.core.web.response.HttpResult;
 import com.sckw.slope.detection.dao.mysql.*;
 import com.sckw.slope.detection.dao.mysql.*;
+import com.sckw.slope.detection.model.dos.mysql.KwsDevice;
 import com.sckw.slope.detection.model.dos.mysql.KwsDeviceReference;
 import com.sckw.slope.detection.model.dos.mysql.KwsDeviceReference;
+import com.sckw.slope.detection.model.dos.mysql.KwsProject;
 import com.sckw.slope.detection.model.dos.mysql.KwsThreshold;
 import com.sckw.slope.detection.model.dos.mysql.KwsThreshold;
 import com.sckw.slope.detection.model.dto.*;
 import com.sckw.slope.detection.model.dto.*;
 import com.sckw.slope.detection.model.param.ThresholdDetailQuery;
 import com.sckw.slope.detection.model.param.ThresholdDetailQuery;
@@ -57,6 +60,9 @@ public class ThresholdService {
     @Autowired
     @Autowired
     KwsDeviceMapper deviceMapper;
     KwsDeviceMapper deviceMapper;
 
 
+    @Autowired
+    KwsProjectMapper projectMapper;
+
     @Autowired
     @Autowired
     KwsDeviceIntegrationMapper deviceIntegrationMapper;
     KwsDeviceIntegrationMapper deviceIntegrationMapper;
 
 
@@ -229,6 +235,7 @@ public class ThresholdService {
     @Transactional
     @Transactional
     public HttpResult configuration(ThresholdConfigurationDTO configurationDTO, HttpServletRequest request) {
     public HttpResult configuration(ThresholdConfigurationDTO configurationDTO, HttpServletRequest request) {
         HeaderData headerData = commonService.getHeaderData(request);
         HeaderData headerData = commonService.getHeaderData(request);
+        String projectId = configurationDTO.getProjectId();
         List<ThresholdBean> threshold = configurationDTO.getThreshold();
         List<ThresholdBean> threshold = configurationDTO.getThreshold();
         String itemName = configurationDTO.getItemName();
         String itemName = configurationDTO.getItemName();
         String phones = configurationDTO.getPhones();
         String phones = configurationDTO.getPhones();
@@ -292,6 +299,16 @@ public class ThresholdService {
                 thresholdRepository.saveOrUpdate(selected);
                 thresholdRepository.saveOrUpdate(selected);
             }
             }
         }
         }
+        Map<String, SystemDict> dict = commonService.getDictByDictCode(DictEnum.MODEL_PART);
+        KwsProject project = projectMapper.selectOne(new LambdaQueryWrapper<KwsProject>()
+                .eq(KwsProject::getId, Long.parseLong(projectId)));
+        KwsDevice kwsDevice = deviceMapper.selectOne(new LambdaQueryWrapper<KwsDevice>().eq(KwsDevice::getId, Long.parseLong(deviceId)));
+        Map<String, Object> logMap = new HashMap<>(NumberConstant.SIXTEEN);
+        logMap.put("projectName", project.getName());
+        logMap.put("element", dict == null ? itemName : dict.get(itemName).getLabel());
+        logMap.put("deviceName", kwsDevice == null ? null : kwsDevice.getName());
+        commonService.insertLog(MessageLogEnum.SETTINGS_DEVICE_THRESHOLD, headerData, logMap, headerData.getUpdateBy() == null ?
+                null : Long.parseLong(headerData.getUpdateBy()));
         return HttpResult.ok();
         return HttpResult.ok();
     }
     }
 
 

+ 4 - 1
slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsDeviceMapper.xml

@@ -299,7 +299,10 @@
         FROM kws_device a
         FROM kws_device a
                  LEFT JOIN kws_project_device b ON a.id = b.device_id
                  LEFT JOIN kws_project_device b ON a.id = b.device_id
                  LEFT JOIN kws_project c ON b.project_id = c.id
                  LEFT JOIN kws_project c ON b.project_id = c.id
-        WHERE c.id = #{projectId}
+        WHERE a.del_flag = 0
+          and b.del_flag = 0
+          and c.del_flag = 0
+          and c.id = #{projectId}
     </select>
     </select>
 
 
     <select id="selectDeviceAllByProjectAndMountainId" resultType="com.sckw.slope.detection.model.dto.ThresholdSelectDTO">
     <select id="selectDeviceAllByProjectAndMountainId" resultType="com.sckw.slope.detection.model.dto.ThresholdSelectDTO">

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

@@ -12,7 +12,7 @@
     <result column="remark" jdbcType="VARCHAR" property="remark" />
     <result column="remark" jdbcType="VARCHAR" property="remark" />
     <result column="status" jdbcType="TINYINT" property="status" />
     <result column="status" jdbcType="TINYINT" property="status" />
     <result column="create_by" jdbcType="BIGINT" property="createBy" />
     <result column="create_by" jdbcType="BIGINT" property="createBy" />
-      <result column="mountain_id" jdbcType="VARCHAR" property="mountainId" />
+    <result column="mountain_id" jdbcType="VARCHAR" property="mountainId" />
     <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
     <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
     <result column="update_by" jdbcType="BIGINT" property="updateBy" />
     <result column="update_by" jdbcType="BIGINT" property="updateBy" />
     <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
     <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />

+ 2 - 8
slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsLogMapper.xml

@@ -8,12 +8,13 @@
     <result column="type" jdbcType="VARCHAR" property="type" />
     <result column="type" jdbcType="VARCHAR" property="type" />
     <result column="content" jdbcType="VARCHAR" property="content" />
     <result column="content" jdbcType="VARCHAR" property="content" />
       <result column="company_id" jdbcType="VARCHAR" property="companyId" />
       <result column="company_id" jdbcType="VARCHAR" property="companyId" />
+      <result column="mountain_id" jdbcType="VARCHAR" property="mountainId" />
     <result column="create_by" jdbcType="BIGINT" property="createBy" />
     <result column="create_by" jdbcType="BIGINT" property="createBy" />
     <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
     <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
   </resultMap>
   </resultMap>
   <sql id="Base_Column_List">
   <sql id="Base_Column_List">
     <!--@mbg.generated-->
     <!--@mbg.generated-->
-    id, `type`, content, create_by, create_time,company_id
+    id, `type`, content, create_by, create_time,company_id,mountain_id
   </sql>
   </sql>
   <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
   <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
     <!--@mbg.generated-->
     <!--@mbg.generated-->
@@ -27,13 +28,6 @@
     delete from kws_log
     delete from kws_log
     where id = #{id,jdbcType=BIGINT}
     where id = #{id,jdbcType=BIGINT}
   </delete>
   </delete>
-  <insert id="insert" parameterType="com.sckw.slope.detection.model.dos.mysql.KwsLog">
-    <!--@mbg.generated-->
-    insert into kws_log (id, `type`, content, 
-      create_by, create_time)
-    values (#{id,jdbcType=BIGINT}, #{type,jdbcType=VARCHAR}, #{content,jdbcType=VARCHAR}, 
-      #{createBy,jdbcType=BIGINT}, #{createTime,jdbcType=TIMESTAMP})
-  </insert>
   <insert id="insertSelective" parameterType="com.sckw.slope.detection.model.dos.mysql.KwsLog">
   <insert id="insertSelective" parameterType="com.sckw.slope.detection.model.dos.mysql.KwsLog">
     <!--@mbg.generated-->
     <!--@mbg.generated-->
     insert into kws_log
     insert into kws_log

+ 3 - 0
slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsProjectMapper.xml

@@ -91,6 +91,9 @@
         <if test="deviceId != null and deviceId != ''">
         <if test="deviceId != null and deviceId != ''">
             AND c.id = #{deviceId}
             AND c.id = #{deviceId}
         </if>
         </if>
+        <if test="type != null and type != ''">
+           and  e.part_name  = #{type}
+        </if>
     </select>
     </select>
 
 
     <select id="selectDeviceList" resultType="com.sckw.slope.detection.model.vo.ProjectDeviceVO">
     <select id="selectDeviceList" resultType="com.sckw.slope.detection.model.vo.ProjectDeviceVO">

+ 2 - 0
slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsReportTemplateMapper.xml

@@ -8,6 +8,7 @@
         <result column="name" jdbcType="VARCHAR" property="name"/>
         <result column="name" jdbcType="VARCHAR" property="name"/>
         <result column="type" jdbcType="INTEGER" property="type"/>
         <result column="type" jdbcType="INTEGER" property="type"/>
         <result column="company_id" jdbcType="VARCHAR" property="companyId"/>
         <result column="company_id" jdbcType="VARCHAR" property="companyId"/>
+        <result column="mountain_id" jdbcType="VARCHAR" property="mountainId"/>
         <result column="project_id" jdbcType="VARCHAR" property="projectId"/>
         <result column="project_id" jdbcType="VARCHAR" property="projectId"/>
         <result column="part_names" jdbcType="VARCHAR" property="partNames"/>
         <result column="part_names" jdbcType="VARCHAR" property="partNames"/>
         <result column="tabulation_time" jdbcType="VARCHAR" property="tabulationTime"/>
         <result column="tabulation_time" jdbcType="VARCHAR" property="tabulationTime"/>
@@ -34,6 +35,7 @@
         update_time,
         update_time,
         del_flag,
         del_flag,
         company_id,
         company_id,
+        mountain_id,
         tabulation_time
         tabulation_time
     </sql>
     </sql>
     <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
     <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">

+ 52 - 0
slope-modules/slope-detection/src/main/resources/mapper/tdengine/InsTables.xml

@@ -0,0 +1,52 @@
+<?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.tdengine.InsTablesMapper">
+    <resultMap id="BaseResultMap" type="com.sckw.slope.detection.model.dos.tdengine.InsTables">
+        <!--@mbg.generated-->
+        <!--@Table ins_tables-->
+        <id column="table_name" jdbcType="VARCHAR" property="tableName"/>
+        <result column="db_name" jdbcType="VARCHAR" property="dbName"/>
+        <result column="createTime" jdbcType="TIMESTAMP" property="createTime"/>
+        <result column="columns" jdbcType="INTEGER" property="columns"/>
+        <result column="stable_name" jdbcType="VARCHAR" property="stableName"/>
+        <result column="uid" jdbcType="INTEGER" property="uid"/>
+        <result column="vgroup_id" jdbcType="INTEGER" property="vgroupId"/>
+        <!--        <result column="ttl" jdbcType="TINYINT" property="ttl"/>-->
+        <result column="table_comment" jdbcType="TINYINT" property="tableComment"/>
+        <result column="type" jdbcType="VARCHAR" property="type"/>
+    </resultMap>
+
+    <sql id="Base_List">
+        table_name    as tableName,
+        db_name       as dbName,
+        create_time as createTime,
+        columns,
+        stable_name   as stableName,
+        uid,
+        vgroup_id     as vgroupId,
+        table_comment as tableComment,
+        type
+    </sql>
+
+    <select id="selectTableIsExit" resultType="com.sckw.slope.detection.model.dos.tdengine.InsTables">
+        select
+        <include refid="Base_List">
+        </include>
+        from information_schema.ins_tables a
+        where a.db_name = 'devices'
+          and a.table_name = #{tableName}
+    </select>
+
+    <insert id="createTable">
+        CREATE TABLE #{tableName}
+        (
+            ts          TIMESTAMP,
+            raw_id      TIMESTAMP,
+            tslver_id   INT ,
+            guid        VARCHAR(64),
+            line        VARCHAR(16),
+            val         VARCHAR(16),
+            create_time TIMESTAMP
+        )
+    </insert>
+</mapper>

+ 24 - 11
slope-modules/slope-detection/src/main/resources/mapper/tdengine/SlopeDataMapper.xml

@@ -6,14 +6,14 @@
         <!--@mbg.generated-->
         <!--@mbg.generated-->
         <!--@Table slope_data-->
         <!--@Table slope_data-->
         <id column="ts" jdbcType="TIMESTAMP" property="tslverId"/>
         <id column="ts" jdbcType="TIMESTAMP" property="tslverId"/>
-        <result column="raw_id" jdbcType="TIMESTAMP" property="rawId"/>
-        <result column="tslver_id" jdbcType="TINYINT" property="tslverId"/>
+        <result column="rawId" jdbcType="TIMESTAMP" property="rawId"/>
+        <result column="tslverId" jdbcType="TINYINT" property="tslverId"/>
         <result column="guid" jdbcType="VARCHAR" property="guid"/>
         <result column="guid" jdbcType="VARCHAR" property="guid"/>
         <result column="line" jdbcType="VARCHAR" property="line"/>
         <result column="line" jdbcType="VARCHAR" property="line"/>
         <result column="val" jdbcType="VARCHAR" property="val"/>
         <result column="val" jdbcType="VARCHAR" property="val"/>
-        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
-        <result column="msg_id" jdbcType="VARCHAR" property="msgId"/>
-        <result column="name" jdbcType="TINYINT" property="name"/>
+        <result column="createTime" jdbcType="TIMESTAMP" property="createTime"/>
+<!--        <result column="msgId" jdbcType="VARCHAR" property="msgId"/>-->
+<!--        <result column="name" jdbcType="TINYINT" property="name"/>-->
     </resultMap>
     </resultMap>
 
 
     <select id="selectList" resultType="com.sckw.slope.detection.model.vo.SlopeDataVo">
     <select id="selectList" resultType="com.sckw.slope.detection.model.vo.SlopeDataVo">
@@ -37,9 +37,7 @@
         guid,
         guid,
         line,
         line,
         val,
         val,
-        create_time as createTime,
-        msg_id      as msgId,
-        name
+        create_time as createTime
     </sql>
     </sql>
     <select id="selectListByLine" resultType="com.sckw.slope.detection.model.dos.tdengine.SlopeData">
     <select id="selectListByLine" resultType="com.sckw.slope.detection.model.dos.tdengine.SlopeData">
         SELECT
         SELECT
@@ -47,7 +45,7 @@
         </include>
         </include>
         FROM devices.slope_data_#{snCode}
         FROM devices.slope_data_#{snCode}
         where line = #{item}
         where line = #{item}
-        order by create_time desc limit 1
+        order by ts desc limit 1
     </select>
     </select>
 
 
     <select id="selectListByLineOrderByCreateTime" resultType="com.sckw.slope.detection.model.dos.tdengine.SlopeData">
     <select id="selectListByLineOrderByCreateTime" resultType="com.sckw.slope.detection.model.dos.tdengine.SlopeData">
@@ -56,7 +54,7 @@
         </include>
         </include>
         FROM devices.slope_data_#{snCode}
         FROM devices.slope_data_#{snCode}
         where line = #{item}
         where line = #{item}
-        order by create_time desc limit 2
+        order by ts desc limit 2
     </select>
     </select>
 
 
     <insert id="insertData" parameterType="com.sckw.slope.detection.model.dos.tdengine.SlopeData">
     <insert id="insertData" parameterType="com.sckw.slope.detection.model.dos.tdengine.SlopeData">
@@ -74,6 +72,21 @@
         <include refid="Base_List">
         <include refid="Base_List">
         </include>
         </include>
         FROM devices.slope_data_#{snCode}
         FROM devices.slope_data_#{snCode}
-        where line = #{item} and create_time &gt;= #{dateStart} and create_time &lt;= #{dateEnd}
+        where line = #{item} and ts &gt;= #{dateStart} and ts &lt;= #{dateEnd} order by ts desc
     </select>
     </select>
+
+    <select id="selectTableIsExit">
+        select * from information_schema.ins_tables a where a.db_name = 'devices' and a.table_name = #{name}
+    </select>
+    <insert id="createTable">
+        CREATE TABLE #{name} (
+        ts TIMESTAMP,
+        raw_id TIMESTAMP,
+        tslver_id TINYINT(4),
+        guid VARCHAR(64),
+        line VARCHAR(16),
+        val VARCHAR(16),
+        create_time TIMESTAMP
+        )
+    </insert>
 </mapper>
 </mapper>