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

项目详情以及项目详情折线图接口

lengfaqiang 2 лет назад
Родитель
Сommit
ee36e9e1d5
15 измененных файлов с 755 добавлено и 139 удалено
  1. 38 5
      slope-common/slope-common-excel/src/main/java/com/sckw/excel/utils/DateUtil.java
  2. 10 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/controller/TdengineDemoController.java
  3. 23 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/dao/tdengine/InsTablesMapper.java
  4. 29 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dos/tdengine/InsTables.java
  5. 2 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/param/DeviceQuery.java
  6. 8 5
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/DeviceOutputValueVO.java
  7. 44 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/ProjectCatLogVO.java
  8. 15 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/ThreeLevelAlarm.java
  9. 23 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/ThresholdLevelVO.java
  10. 55 28
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/DeviceService.java
  11. 410 88
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/ProjectService.java
  12. 18 1
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/TdengineDemoService.java
  13. 4 1
      slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsDeviceMapper.xml
  14. 52 0
      slope-modules/slope-detection/src/main/resources/mapper/tdengine/InsTables.xml
  15. 24 11
      slope-modules/slope-detection/src/main/resources/mapper/tdengine/SlopeDataMapper.xml

+ 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 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 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");
@@ -537,14 +538,14 @@ public class DateUtil {
     }
 
     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>());
         String dateTimeHour1 = getDateTimeToHour(new Date(), 24);
         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();
 //        // 计算一年前的日期
@@ -826,6 +827,38 @@ public class DateUtil {
         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}时间的每个小时(包含当前的小时)

+ 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(){
         tdengineDemoService.tdengineDemo();
     }
+
+    @RequestMapping(value = "/getTable",method = RequestMethod.GET)
+    public void getTable(){
+        tdengineDemoService.getTable();
+    }
+
+    @RequestMapping(value = "/createTable",method = RequestMethod.GET)
+    public void createTable(){
+        tdengineDemoService.createTable();
+    }
 }

+ 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);
+}

+ 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;
+
+}

+ 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;
 
+import jakarta.validation.constraints.NotBlank;
 import lombok.Data;
 
 /**
@@ -22,6 +23,7 @@ public class DeviceQuery {
     /**
      * 项目id
      */
+    @NotBlank(message = "项目id不能为空")
     private String projectId;
 
     /**

+ 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 java.util.Map;
-
 /**
  * @author lfdc
  * @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;
 }

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

@@ -0,0 +1,44 @@
+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>> mapList;
+
+}

+ 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;
+}

+ 55 - 28
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/DeviceService.java

@@ -9,6 +9,7 @@ import com.sckw.core.exception.SystemException;
 import com.sckw.core.model.constant.Global;
 import com.sckw.core.model.constant.NumberConstant;
 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.page.PageRes;
 import com.sckw.core.utils.IdWorker;
@@ -16,8 +17,10 @@ import com.sckw.core.utils.StringUtils;
 import com.sckw.core.web.constant.HttpStatus;
 import com.sckw.core.web.response.HttpResult;
 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.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.dto.*;
 import com.sckw.slope.detection.model.param.DeviceAdd;
@@ -35,6 +38,7 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
 import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
 import java.time.ZoneOffset;
 import java.util.*;
@@ -63,6 +67,9 @@ public class DeviceService {
     @Autowired
     SlopeDataMapper slopeDataMapper;
 
+    @Autowired
+    InsTablesMapper insTablesMapper;
+
     @Autowired
     KwsDeviceModelMapper deviceModelMapper;
 
@@ -148,7 +155,7 @@ public class DeviceService {
     public HttpResult add(DeviceAdd deviceAdd, HttpServletRequest request) {
         KwsDevice deviceHas = deviceMapper.selectOne(new LambdaQueryWrapper<KwsDevice>()
                 .eq(KwsDevice::getSnCode, deviceAdd.getSnCode()));
-        if(!Objects.isNull(deviceHas)){
+        if (!Objects.isNull(deviceHas)) {
             throw new SystemException(HttpStatus.QUERY_FAIL_CODE, HttpStatus.DEVICE_SN_EXISTS);
         }
         HeaderData headerData = commonService.getHeaderData(request);
@@ -168,7 +175,7 @@ public class DeviceService {
         KwsDeviceIntegration deIntergration = new KwsDeviceIntegration();
         String[] temp;//接收分割后的数组
         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();
             deIntergration.setId(interId);
             deIntergration.setDeviceId(id);
@@ -192,7 +199,7 @@ public class DeviceService {
 
         KwsDeviceModel deviceModel = deviceModelMapper.selectOne(new LambdaQueryWrapper<KwsDeviceModel>()
                 .eq(KwsDeviceModel::getId, vo.getModelId()));
-        if (deviceModel!=null){
+        if (deviceModel != null) {
             vo.setManufacturer(deviceModel.getManufacturer());
             vo.setManufacturer_contacts(deviceModel.getManufacturerContacts());
             vo.setManufacturer_phone(deviceModel.getManufacturerPhone());
@@ -255,7 +262,7 @@ public class DeviceService {
         List<ProjectDeviceVO> projectDeviceList = projectMapper.selectDeviceByProjectId(headerData.getMountainId(), Long.parseLong(projectId), Long.parseLong(deviceId));
         List<String> deviceIds = new ArrayList<>();
         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>()
@@ -264,23 +271,34 @@ public class DeviceService {
                 .eq(KwsDeviceReference::getType, 1)
                 .eq(KwsDeviceReference::getDelFlag, NumberConstant.ZERO)
         );
-        List<DeviceOutputValueVO> mapList = new ArrayList<>();
+        List<Map<String, DeviceOutputValueVO>> mapList = new ArrayList<>();
         if (!CollectionUtils.isEmpty(references)) {
             references.forEach(re -> {
+                Map<String, DeviceOutputValueVO> map = new HashMap<>();
                 DeviceOutputValueVO vo = new DeviceOutputValueVO();
                 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 currentValue = re.getCurrentValue();
                 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获取
                 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();
                 //存在经度纬度海拔等要素 要进行公式计算
                 /**
@@ -303,7 +321,8 @@ public class DeviceService {
                             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.add(DictItemEnum.LATITUDE_Y.getValue());
@@ -312,7 +331,8 @@ public class DeviceService {
                     if (org.apache.commons.lang3.StringUtils.isNotBlank(val)) {
                         offsetValue = new BigDecimal(val).subtract(currentValue);
                     }
-                    currentMeasurement.put(item, offsetValue);
+//                    currentMeasurement.put(itemName, offsetValue);
+                    vo.setCurrentMeasurementValue(offsetValue == null ? null : offsetValue.toString());
                 }
                 itemList.clear();
                 itemList.add(DictItemEnum.ALTITUDE_Z.getValue());
@@ -321,12 +341,11 @@ public class DeviceService {
                     if (org.apache.commons.lang3.StringUtils.isNotBlank(val)) {
                         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);
             });
         }
         //集成要素-测量值计算
@@ -350,18 +369,22 @@ public class DeviceService {
                             .eq(KwsDeviceReference::getDelFlag, 0)
                             .eq(KwsDeviceReference::getType, 2)
                     );
+                    Map<String, DeviceOutputValueVO> map = new HashMap<>();
                     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获取
                     HashMap<String, Object> currentMeasurement = new HashMap<>();
                     String formula = integration.getFormula();
                     List<String> stringList = StringUtils.splitStrToList(partNames, String.class);
                     BigDecimal decimal = new BigDecimal("0.00");
+                    String currentMeasurementTime = "";
                     if (!CollectionUtils.isEmpty(stringList)) {
                         for (int i = 0; i < stringList.size(); i++) {
                             List<SlopeData> selected = slopeDataMapper.selectListByLineOrderByCreateTime(integrationName, stringList.get(i));
@@ -369,8 +392,12 @@ public class DeviceService {
                                 if (selected.size() == 2) {
                                     SlopeData currSlopeData = selected.get(0);
                                     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 epochMilli1 = date1.toInstant(ZoneOffset.of("+8")).toEpochMilli();
                                     long t = (epochMilli - epochMilli1) / (60 * 60 * 1000);
@@ -380,11 +407,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);
                 });
             }
         }

+ 410 - 88
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/ProjectService.java

@@ -8,7 +8,6 @@ import com.github.pagehelper.PageInfo;
 import com.sckw.core.exception.BusinessException;
 import com.sckw.core.model.constant.NumberConstant;
 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.page.PageRes;
 import com.sckw.core.utils.IdWorker;
@@ -39,6 +38,8 @@ import org.springframework.util.CollectionUtils;
 import java.math.BigDecimal;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
+import java.time.ZoneOffset;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -65,6 +66,9 @@ public class ProjectService {
     @Autowired
     KwsDeviceIntegrationMapper deviceIntegrationMapper;
 
+    @Autowired
+    KwsIntegrationMapper integrationMapper;
+
     @Autowired
     KwsDeviceMapper deviceMapper;
 
@@ -77,6 +81,9 @@ public class ProjectService {
     @Autowired
     KwsDeviceReferenceMapper deviceReferenceMapper;
 
+    @Autowired
+    KwsThresholdMapper thresholdMapper;
+
     @Autowired
     KwsMountainCompanyMapper mountainCompanyMapper;
 
@@ -365,10 +372,6 @@ public class ProjectService {
         String latitude = param.getLatitude();
         String projectId = param.getProjectId();
         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 mountainId = headerData.getMountainId();
             KwsDevice kwsDevice = deviceMapper.selectOne(new LambdaQueryWrapper<KwsDevice>()
@@ -379,93 +382,32 @@ public class ProjectService {
             if (kwsDevice == null) {
                 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<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)
-                    );
-                    KwsDeviceReference deviceReference = new KwsDeviceReference();
-                    if (!CollectionUtils.isEmpty(references)) {
-                        deviceReference = references.get(0);
-                    }
-                    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);
-                        String dateEnd = DateUtil.localDateTimeFormat(LocalDateTime.now());
-                        List<SlopeData> selected = slopeDataMapper.selectLineList(kwsDevice.getSnCode(), partName, dateStart, dateEnd);
-                        if (!CollectionUtils.isEmpty(selected)){
-                            for (SlopeData message : selected) {
-                                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(val)) {
-                                            double doubleValue = (new BigDecimal(val).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(val)) {
-                                            offsetValue = new BigDecimal(val).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(val)) {
-                                            offsetValue = new BigDecimal(val).divide(new BigDecimal(1000));
-                                        }
-                                    }
-                                }
-                            }
-                        }
-
-                    }
-                }
-            }
+            List<ProjectCatLogVO> returnList = new ArrayList<>();
+            basicItem(mountainId, projectId, deviceId, kwsDevice, returnList);
 
+            //集成要素 折线图
+            //集成要素-测量值计算
+            integrationItem(headerData, deviceId, kwsDevice, returnList);
             LocalDateTime localDateTime = DateUtil.localDateToLocalDateTimeStart(LocalDate.now());
+            return HttpResult.ok(returnList);
         } 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) {
-
+            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<String> dateTimeDay = DateUtil.getDateTimeDay(LocalDateTime.now(), 7, new ArrayList<String>());
+            List<Date> dateTimeDay = DateUtil.getDateTimeDayToDate(LocalDateTime.now(), 7, new ArrayList<Date>());
+            for (Date dateTime : dateTimeDay) {
+                //当前设备下的所有基本要素
+                List<ProjectCatLogVO> returnList = new ArrayList<>();
+                basicItemByWeek(mountainId, projectId, deviceId, kwsDevice, returnList, dateTime);
             }
             /**下面是查询当天每小时数据总量的代码示例:
 
@@ -492,6 +434,386 @@ public class ProjectService {
         return null;
     }
 
+    /**
+     * 周为纬度  折线图计算
+     *
+     * @param mountainId 所属企业
+     * @param projectId  所属项目
+     * @param deviceId   所属设备
+     * @param kwsDevice  设备信息
+     * @param returnList 返回数据
+     * @param date   时间范围
+     */
+    private void basicItemByWeek(String mountainId, String projectId, String deviceId, KwsDevice kwsDevice, List<ProjectCatLogVO> returnList, Date date) {
+        List<ProjectDeviceVO> projectDeviceList = projectMapper.selectDeviceByProjectId(mountainId, Long.parseLong(projectId), Long.parseLong(deviceId));
+        if (!CollectionUtils.isEmpty(projectDeviceList)) {
+            for (ProjectDeviceVO projectDeviceVO : projectDeviceList) {
+                ProjectCatLogVO returnVO = new ProjectCatLogVO();
+                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)
+                );
+                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();
+                    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.setMapList(mapList);
+                returnList.add(returnVO);
+            }
+        }
+    }
+
+    /**
+     * 集成要素折线图计算
+     */
+    private void integrationItem(HeaderData headerData, String deviceId, KwsDevice kwsDevice, List<ProjectCatLogVO> returnList) {
+        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));
+            if (!CollectionUtils.isEmpty(kwsIntegrations) && kwsIntegrations.size() > 0) {
+                kwsIntegrations.forEach(integration -> {
+                    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.setMapList(mapList);
+                        }
+                    }
+                });
+            }
+        }
+    }
+
+    /**
+     * 折线图 基本要素
+     */
+    private void basicItem(String mountainId, String projectId, String deviceId, KwsDevice kwsDevice, List<ProjectCatLogVO> returnList) {
+        List<ProjectDeviceVO> projectDeviceList = projectMapper.selectDeviceByProjectId(mountainId, Long.parseLong(projectId), Long.parseLong(deviceId));
+        if (!CollectionUtils.isEmpty(projectDeviceList)) {
+            for (ProjectDeviceVO projectDeviceVO : projectDeviceList) {
+                ProjectCatLogVO returnVO = new ProjectCatLogVO();
+                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)
+                );
+                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));
+                }
+                //阈值等级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);
+
+                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.setMapList(mapList);
+                returnList.add(returnVO);
+            }
+        }
+    }
+
 
     /**
      * 项目关联设备删除

+ 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;
 
 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.model.dos.tdengine.InsTables;
 import com.sckw.slope.detection.model.dos.tdengine.SlopeData;
 import com.sckw.slope.detection.model.vo.SlopeDataVo;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -20,8 +22,11 @@ public class TdengineDemoService {
     @Autowired
     SlopeDataMapper slopeDataMapper;
 
+    @Autowired
+    InsTablesMapper insTablesMapper;
+
     public void tdengineDemo() {
-        List<SlopeDataVo> list = slopeDataMapper.selectAll("6","7");
+        List<SlopeDataVo> list = slopeDataMapper.selectAll("6", "7");
         System.out.println(JSONObject.toJSONString(list));
         List<SlopeDataVo> list1 = slopeDataMapper.selectList();
         System.out.println(JSONObject.toJSONString(list1));
@@ -41,4 +46,16 @@ public class TdengineDemoService {
         data.setCreateTime(now);
         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);
+    }
 }

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

@@ -299,7 +299,10 @@
         FROM kws_device a
                  LEFT JOIN kws_project_device b ON a.id = b.device_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 id="selectDeviceAllByProjectAndMountainId" resultType="com.sckw.slope.detection.model.dto.ThresholdSelectDTO">

+ 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-->
         <!--@Table slope_data-->
         <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="line" jdbcType="VARCHAR" property="line"/>
         <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>
 
     <select id="selectList" resultType="com.sckw.slope.detection.model.vo.SlopeDataVo">
@@ -37,9 +37,7 @@
         guid,
         line,
         val,
-        create_time as createTime,
-        msg_id      as msgId,
-        name
+        create_time as createTime
     </sql>
     <select id="selectListByLine" resultType="com.sckw.slope.detection.model.dos.tdengine.SlopeData">
         SELECT
@@ -47,7 +45,7 @@
         </include>
         FROM devices.slope_data_#{snCode}
         where line = #{item}
-        order by create_time desc limit 1
+        order by ts desc limit 1
     </select>
 
     <select id="selectListByLineOrderByCreateTime" resultType="com.sckw.slope.detection.model.dos.tdengine.SlopeData">
@@ -56,7 +54,7 @@
         </include>
         FROM devices.slope_data_#{snCode}
         where line = #{item}
-        order by create_time desc limit 2
+        order by ts desc limit 2
     </select>
 
     <insert id="insertData" parameterType="com.sckw.slope.detection.model.dos.tdengine.SlopeData">
@@ -74,6 +72,21 @@
         <include refid="Base_List">
         </include>
         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 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>