Explorar o código

Merge branch 'dev' into sky_v2

15928045575 %!s(int64=2) %!d(string=hai) anos
pai
achega
954b0a1857
Modificáronse 24 ficheiros con 680 adicións e 108 borrados
  1. 21 0
      slope-common/slope-common-core/src/main/java/com/sckw/core/utils/StringUtils.java
  2. 20 11
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/controller/DeviceController.java
  3. 9 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/controller/ThresholdController.java
  4. 0 2
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/dao/mysql/KwsProjectDeviceMapper.java
  5. 1 1
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/dao/mysql/KwsProjectMapper.java
  6. 0 2
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/dao/mysql/KwsThresholdMapper.java
  7. 8 1
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dos/mysql/KwsThreshold.java
  8. 2 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dto/BindDevice.java
  9. 16 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dto/LocationDTO.java
  10. 23 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dto/ThresholdBean.java
  11. 36 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dto/ThresholdConfigurationDTO.java
  12. 1 2
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/param/DeviceQuery.java
  13. 44 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/OutputValueVO.java
  14. 5 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/ProjectDeviceVO.java
  15. 1 13
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/ThresholdDetailVO.java
  16. 48 26
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/DeviceService.java
  17. 3 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/ProjectService.java
  18. 378 9
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/ThresholdService.java
  19. 7 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/repository/KwsThresholdRepository.java
  20. 17 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/repository/impl/kwsThresholdImpl.java
  21. 25 15
      slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsDeviceMapper.xml
  22. 0 11
      slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsProjectDeviceMapper.xml
  23. 13 4
      slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsProjectMapper.xml
  24. 2 11
      slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsThresholdMapper.xml

+ 21 - 0
slope-common/slope-common-core/src/main/java/com/sckw/core/utils/StringUtils.java

@@ -814,6 +814,27 @@ public class StringUtils {
         return d.setScale(2, RoundingMode.HALF_UP);
     }
 
+
+    /**
+     * 去除字符串中 指定字符
+     * @param sourceString  "-154-15"
+     * @param chElemData "-"
+     * @return "15415"
+     */
+    public static String deleteCharString(String sourceString, String chElemData) {
+        String tmpString = "";
+        tmpString += chElemData;
+        StringBuffer stringBuffer = new StringBuffer(sourceString);
+        int iFlag = -1;
+        do {
+            iFlag = stringBuffer.indexOf(tmpString);
+            if (iFlag != -1) {
+                stringBuffer.deleteCharAt(iFlag);
+            }
+        } while (iFlag != -1);
+        return stringBuffer.toString();
+    }
+
     public static void main(String[] args) {
         Map<String, Object> param = new HashMap<>(Global.NUMERICAL_SIXTEEN);
         param.put("account", "17358629955");

+ 20 - 11
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/controller/DeviceController.java

@@ -4,24 +4,18 @@ import com.alibaba.fastjson2.JSONObject;
 import com.sckw.core.annotation.Log;
 import com.sckw.core.annotation.RepeatSubmit;
 import com.sckw.core.web.response.HttpResult;
-import com.sckw.slope.detection.model.dto.ProjectUpdateDTO;
+import com.sckw.slope.detection.model.dto.LocationDTO;
 import com.sckw.slope.detection.model.param.DeviceAdd;
 import com.sckw.slope.detection.model.param.DeviceQuery;
 import com.sckw.slope.detection.service.DeviceService;
 import jakarta.servlet.http.HttpServletRequest;
-import com.sckw.slope.detection.model.dto.DeviceLocationDTO;
-import com.sckw.slope.detection.service.DeviceService;
-import jakarta.servlet.http.HttpServletRequest;
 import jakarta.validation.Valid;
 import jakarta.validation.constraints.NotBlank;
 import jakarta.validation.constraints.NotNull;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.http.HttpResponse;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
-import com.alibaba.fastjson2.JSONObject;
-import jakarta.validation.Valid;
-import org.apache.http.HttpResponse;
-import java.util.List;
 
 /**
  * @author lfdc
@@ -75,12 +69,27 @@ public class DeviceController {
         log.info("设备 detail param:{}", id);
         return deviceService.detail(id, response);
     }
+
     @Log(description = "设备位置配置")
     //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
     @RequestMapping(name = "设备位置配置", value = "/locationSet", method = RequestMethod.POST)
-    public HttpResult locationSet(@RequestBody @Valid List<DeviceLocationDTO> list, HttpServletRequest request) {
-        log.info("设备位置配置 locationSet param :{}", JSONObject.toJSONString(list));
-        return deviceService.locationSet(list,request);
+    public HttpResult locationSet(@RequestBody @Valid LocationDTO list, HttpServletRequest request) {
+        try {
+            log.info("设备位置配置 locationSet param :{}", JSONObject.toJSONString(list));
+            return deviceService.locationSet(list, request);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    @Log(description = "设备监测值-原始/当前/测量")
+    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
+    @RequestMapping(name = "设备监测值-原始/当前/测量", value = "/outputValue", method = RequestMethod.GET)
+    public HttpResult outputValue(@RequestParam("projectId") @NotBlank(message = "项目id不能为空") String projectId,
+                                  @RequestParam("deviceId") @NotBlank(message = "设备id不能为空") String deviceId,
+                                  HttpServletRequest request) {
+        log.info("设备监测值-原始/当前/测量 outputValue param1 :{},param2:{}", projectId, deviceId);
+        return deviceService.outputValue(projectId,deviceId, request);
     }
 
     @Log(description = "设备编辑")

+ 9 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/controller/ThresholdController.java

@@ -3,6 +3,7 @@ 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.dto.ThresholdConfigurationDTO;
 import com.sckw.slope.detection.model.param.ThresholdDetailQuery;
 import com.sckw.slope.detection.model.param.ThresholdQuery;
 import com.sckw.slope.detection.service.ThresholdService;
@@ -44,4 +45,12 @@ public class ThresholdController {
         return thresholdService.detail(thresholdQuery, request);
     }
 
+    @Log(description = "阈值配置")
+    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
+    @RequestMapping(name = "阈值配置", value = "/configuration", method = RequestMethod.POST)
+    public HttpResult configuration(@Valid @RequestBody ThresholdConfigurationDTO configurationDTO, HttpServletRequest request) {
+        log.info("阈值配置 configuration param:{}", JSONObject.toJSONString(configurationDTO));
+        return thresholdService.configuration(configurationDTO, request);
+    }
+
 }

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

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

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

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

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

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

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

@@ -1,5 +1,6 @@
 package com.sckw.slope.detection.model.dos.mysql;
 
+import com.baomidou.mybatisplus.annotation.TableLogic;
 import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.Data;
 
@@ -56,13 +57,18 @@ public class KwsThreshold implements Serializable {
     /**
      * 状态
      */
-    private Byte status;
+    private int status;
 
     /**
      * 创建人
      */
     private Long createBy;
 
+    /**
+     * 创建人
+     */
+    private String createName;
+
     /**
      * 创建时间
      */
@@ -82,6 +88,7 @@ public class KwsThreshold implements Serializable {
     /**
      * 删除标识
      */
+    @TableLogic(value = "0")
     private int delFlag;
 
     private static final long serialVersionUID = 1L;

+ 2 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dto/BindDevice.java

@@ -28,4 +28,6 @@ public class BindDevice implements Serializable {
      */
 //    @NotBlank(message = "所属设备ID不能为空")
     private String bindDeviceId;
+
+    private String alias;
 }

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

@@ -0,0 +1,16 @@
+package com.sckw.slope.detection.model.dto;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * @author lfdc
+ * @description
+ * @date 2023-11-03 09:11:21
+ */
+@Data
+public class LocationDTO implements Serializable {
+    private List<DeviceLocationDTO> deviceLocationList;
+}

+ 23 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dto/ThresholdBean.java

@@ -0,0 +1,23 @@
+package com.sckw.slope.detection.model.dto;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @author lfdc
+ * @description 阈值等级数
+ * @date 2023-11-03 08:11:49
+ */
+@Data
+public class ThresholdBean implements Serializable {
+    /**
+     * level : 等级
+     * max : 阈值配置最大值
+     * min : 阈值配置最小值
+     */
+
+    private int level;
+    private String max;
+    private String min;
+}

+ 36 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dto/ThresholdConfigurationDTO.java

@@ -0,0 +1,36 @@
+package com.sckw.slope.detection.model.dto;
+
+import jakarta.validation.constraints.NotBlank;
+import jakarta.validation.constraints.NotNull;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * @author lfdc
+ * @description 阈值配置dto
+ * @date 2023-11-03 08:11:48
+ */
+@Data
+public class ThresholdConfigurationDTO implements Serializable {
+
+    /**
+     * projectId : 项目id
+     * deviceId : 设备ID
+     * itemName : 监测项(字典value)
+     * phones : 联系电话,多个用分隔符
+     * threshold : [{"level":"等级","max":"阈值配置最大值","min":"阈值配置最小值"}]
+     */
+    @NotBlank(message = "项目id不能为空")
+    private String projectId;
+    @NotBlank(message = "设备id不能为空")
+    private String deviceId;
+    @NotBlank(message = "监测项不能为空")
+    private String itemName;
+    @NotBlank(message = "联系电话不能为空")
+    private String phones;
+    @NotNull
+    private List<ThresholdBean> threshold;
+}
+

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

@@ -1,6 +1,5 @@
 package com.sckw.slope.detection.model.param;
 
-import jakarta.validation.constraints.NotBlank;
 import lombok.Data;
 
 /**
@@ -33,7 +32,7 @@ public class DeviceQuery {
     /**
      * 设备名称
      */
-    private String deviceName;
+    private String name;
 
     /**
      * 设备类型

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

@@ -0,0 +1,44 @@
+package com.sckw.slope.detection.model.vo;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @author lfdc
+ * @description 项目详情-项目要素
+ * @date 2023-11-03 16:11:26
+ */
+@Data
+public class OutputValueVO implements Serializable {
+
+    /**
+     * initialLng : 逻辑经度(初始)
+     * initialLat : 逻辑纬度(初始)
+     * initialAlt : 逻辑海拔(初始)
+     * presentLng : 逻辑经度(当前)
+     * presentLat : 逻辑纬度(当前)
+     * presentAlt : 逻辑海拔(当前)
+     * measureLng : 逻辑经度(测量)
+     * measureLat : 逻辑纬度(测量)
+     * measureAlt : 逻辑海拔(测量)
+     * measureLngLevel : 逻辑经度告警级别(测量)
+     * measureLatLevel : 逻辑纬度告警级别(测量)
+     * measureAltLevel : 逻辑海拔告警级别(测量)
+     * measureTime : 测量时间
+     */
+
+    private String initialLng;
+    private String initialLat;
+    private String initialAlt;
+    private String presentLng;
+    private String presentLat;
+    private String presentAlt;
+    private String measureLng;
+    private String measureLat;
+    private String measureAlt;
+    private String measureLngLevel;
+    private String measureLatLevel;
+    private String measureAltLevel;
+    private String measureTime;
+}

+ 5 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/ProjectDeviceVO.java

@@ -26,6 +26,11 @@ public class ProjectDeviceVO implements Serializable {
      */
     private String name;
 
+    /**
+     * 别名(单元名称)
+     */
+    private String alias;
+
     /**
      * 状态
      */

+ 1 - 13
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/ThresholdDetailVO.java

@@ -1,5 +1,6 @@
 package com.sckw.slope.detection.model.vo;
 
+import com.sckw.slope.detection.model.dto.ThresholdBean;
 import lombok.Data;
 
 import java.io.Serializable;
@@ -29,17 +30,4 @@ public class ThresholdDetailVO implements Serializable {
     private BigDecimal itemValue;
     private String variation;
     private List<ThresholdBean> threshold;
-
-    @Data
-    public static class ThresholdBean implements Serializable{
-        /**
-         * level : 等级
-         * max : 阈值配置最大值
-         * min : 阈值配置最小值
-         */
-
-        private String level;
-        private String max;
-        private String min;
-    }
 }

+ 48 - 26
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/DeviceService.java

@@ -2,33 +2,31 @@ package com.sckw.slope.detection.service;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
 import com.sckw.core.exception.BusinessException;
-import com.sckw.core.model.constant.NumberConstant;
-import com.sckw.core.model.page.PageRes;
 import com.sckw.core.model.enums.DeviceEnum;
+import com.sckw.core.model.page.PageRes;
 import com.sckw.core.utils.StringUtils;
-import com.sckw.core.model.enums.AlarmTypeEnum;
-import com.sckw.core.model.enums.DeviceEnum;
 import com.sckw.core.web.response.HttpResult;
-import com.sckw.slope.detection.dao.mysql.KwsDeviceMapper;
-import com.sckw.slope.detection.dao.mysql.KwsAlarmMapper;
-import com.sckw.slope.detection.dao.mysql.KwsDeviceModelMapper;
-import com.sckw.slope.detection.model.dos.mysql.*;
-import com.sckw.slope.detection.model.dto.*;
+import com.sckw.slope.detection.dao.mysql.*;
+import com.sckw.slope.detection.model.dos.mysql.KwsDevice;
+import com.sckw.slope.detection.model.dos.mysql.KwsDeviceModel;
+import com.sckw.slope.detection.model.dto.DeviceDataDTO;
+import com.sckw.slope.detection.model.dto.DeviceLocationDTO;
+import com.sckw.slope.detection.model.dto.HeaderData;
+import com.sckw.slope.detection.model.dto.LocationDTO;
 import com.sckw.slope.detection.model.param.DeviceAdd;
 import com.sckw.slope.detection.model.param.DeviceQuery;
-import com.sckw.slope.detection.model.vo.ProjectVo;
-import com.sckw.slope.detection.model.dto.HeaderData;
+import com.sckw.slope.detection.model.vo.DeviceVo;
+import com.sckw.slope.detection.model.vo.ProjectDeviceVO;
 import jakarta.servlet.http.HttpServletRequest;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.http.HttpResponse;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
-import org.apache.http.HttpResponse;
-import com.github.pagehelper.PageHelper;
-import com.github.pagehelper.PageInfo;
-import com.sckw.slope.detection.model.vo.DeviceVo;
 import org.springframework.util.CollectionUtils;
 
 import java.time.LocalDateTime;
@@ -56,6 +54,12 @@ public class DeviceService {
     @Autowired
     KwsDeviceModelMapper deviceModelMapper;
 
+    @Autowired
+    KwsProjectMapper projectMapper;
+
+    @Autowired
+    KwsProjectDeviceMapper projectDeviceMapper;
+
 
     @Transactional
     public HttpResult dels(String ids) {
@@ -79,7 +83,7 @@ public class DeviceService {
      * 项目管理分页查询
      *
      * @param deviceQuery 请求分页
-     * @param response        http流
+     * @param response    http流
      * @return 返回值
      */
     public PageRes select(DeviceQuery deviceQuery, HttpResponse response) {
@@ -90,13 +94,13 @@ public class DeviceService {
             return PageRes.build(pageInfo, list);
         }
         List<Long> devicesId = list.stream().map(DeviceVo::getId).toList();
-        List<Map<String,Long>> alarmData = alarmMapper.selectByDevicesId(devicesId);
+        List<Map<String, Long>> alarmData = alarmMapper.selectByDevicesId(devicesId);
         for (DeviceVo vo : list) {
             vo.setStatusText(DeviceEnum.getName(vo.getStatus()));
-            if(!CollectionUtils.isEmpty(alarmData)){
-                for(int i=0;i<alarmData.size();i++){
-                    Map<String,Long> map = alarmData.get(i);
-                    if(map.get("pid").toString().equals(vo.getId().toString())){
+            if (!CollectionUtils.isEmpty(alarmData)) {
+                for (int i = 0; i < alarmData.size(); i++) {
+                    Map<String, Long> map = alarmData.get(i);
+                    if (map.get("pid").toString().equals(vo.getId().toString())) {
                         vo.setDataErrorCount(map.get("count"));
                         vo.setDeviceErrorCount(map.get("count"));
                     }
@@ -113,7 +117,7 @@ public class DeviceService {
      * 新增设备
      *
      * @param deviceAdd 请求参数
-     * @param request       http流
+     * @param request   http流
      * @return 返回值
      */
     @Transactional
@@ -147,16 +151,17 @@ public class DeviceService {
     }
 
     @Transactional
-    public HttpResult locationSet(List<DeviceLocationDTO> list, HttpServletRequest request) {
+    public HttpResult locationSet(LocationDTO list, HttpServletRequest request) {
         HeaderData headerData = commonService.getHeaderData(request);
-        if (!CollectionUtils.isEmpty(list)) {
-            list.forEach(device -> {
+        List<DeviceLocationDTO> deviceLocationList = list.getDeviceLocationList();
+        if (!CollectionUtils.isEmpty(deviceLocationList)) {
+            deviceLocationList.forEach(device -> {
                 deviceMapper.update(null, new LambdaUpdateWrapper<KwsDevice>()
                         .set(KwsDevice::getLogicLng, device.getLogicLng())
                         .set(KwsDevice::getLogicLat, device.getLogicLat())
                         .set(KwsDevice::getLogicAlt, device.getLogicAlt())
                         .set(KwsDevice::getUpdateBy, headerData.getUpdateBy() == null ? null : Long.parseLong(headerData.getUpdateBy()))
-                        .set(KwsDevice::getStatus, DeviceEnum.BE_CHECKING)
+                        .set(KwsDevice::getStatus, DeviceEnum.BE_CHECKING.getCode())
                         .eq(KwsDevice::getId, device.getDeviceId())
                 );
             });
@@ -175,4 +180,21 @@ public class DeviceService {
         deviceMapper.updateById(device);
         return HttpResult.ok();
     }
+
+    /**
+     * 设备监测值-原始/当前/测量
+     *
+     * @param projectId 项目id
+     * @param deviceId  设备id
+     * @param request   请求流
+     * @return 设备信息
+     */
+    public HttpResult outputValue(String projectId, String deviceId, HttpServletRequest request) {
+        HeaderData headerData = commonService.getHeaderData(request);
+        List<ProjectDeviceVO> projectDeviceList = projectMapper.selectDeviceByProjectId(headerData.getMountainId(), Long.parseLong(projectId), Long.parseLong(deviceId));
+        if (!CollectionUtils.isEmpty(projectDeviceList)) {
+
+        }
+        return null;
+    }
 }

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

@@ -256,14 +256,17 @@ public class ProjectService {
                 device.setUpdateBy(headerData.getUpdateBy() == null ? Long.parseLong(headerData.getCreateBy()) : Long.parseLong(headerData.getUpdateBy()));
                 device.setUpdateTime(now);
                 device.setCompanyId(headerData.getCompanyId());
+                projectDeviceMapper.insert(device);
             });
         }
         //设备修改状态
         if (!CollectionUtils.isEmpty(list)) {
             list.forEach(id -> {
+                KwsDevice kwsDevice = deviceMapper.selectByPrimaryKey(id);
                 deviceMapper.update(null, new LambdaUpdateWrapper<KwsDevice>()
                         .eq(KwsDevice::getId, id)
                         .set(KwsDevice::getStatus, DeviceEnum.BE_CHECKING.getCode())
+                        .set(KwsDevice::getAlias, bindDevice.getAlias() == null ? kwsDevice.getName() : bindDevice.getAlias())
                         .set(KwsDevice::getUpdateTime, LocalDateTime.now())
                         .set(KwsDevice::getUpdateBy, headerData.getUpdateBy() == null ? Long.parseLong(headerData.getCreateBy()) : Long.parseLong(headerData.getUpdateBy()))
                 );

+ 378 - 9
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/ThresholdService.java

@@ -3,27 +3,36 @@ package com.sckw.slope.detection.service;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
+import com.sckw.core.exception.BusinessException;
 import com.sckw.core.model.constant.NumberConstant;
 import com.sckw.core.model.enums.DeviceEnum;
 import com.sckw.core.model.page.PageRes;
+import com.sckw.core.utils.IdWorker;
+import com.sckw.core.utils.RegularUtils;
+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.model.dos.mysql.KwsDeviceReference;
 import com.sckw.slope.detection.model.dos.mysql.KwsThreshold;
-import com.sckw.slope.detection.model.dto.DeviceElementDTO;
-import com.sckw.slope.detection.model.dto.HeaderData;
-import com.sckw.slope.detection.model.dto.ThresholdSelectDTO;
+import com.sckw.slope.detection.model.dto.*;
 import com.sckw.slope.detection.model.param.ThresholdDetailQuery;
 import com.sckw.slope.detection.model.param.ThresholdQuery;
 import com.sckw.slope.detection.model.vo.ThresholdDetailVO;
+import com.sckw.slope.detection.service.repository.KwsThresholdRepository;
 import jakarta.servlet.http.HttpServletRequest;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 /**
@@ -50,6 +59,9 @@ public class ThresholdService {
     @Autowired
     KwsThresholdMapper thresholdMapper;
 
+    @Autowired
+    KwsThresholdRepository thresholdRepository;
+
     @Autowired
     KwsDeviceReferenceMapper deviceReferenceMapper;
 
@@ -75,7 +87,7 @@ public class ThresholdService {
                     .eq(KwsThreshold::getDeviceId, deviceId)
                     .eq(KwsThreshold::getMountainId, headerData.getMountainId())
                     .eq(KwsThreshold::getDelFlag, NumberConstant.ZERO)
-                    .orderByDesc(KwsThreshold::getUpdateTime)
+                    .orderByDesc(KwsThreshold::getCreateTime)
             );
             String setting = "0";
             String statusName = "未设置";
@@ -113,8 +125,8 @@ public class ThresholdService {
             dto.setStatus(setting);
             dto.setStatusName(statusName);
             dto.setPhones(phones.toString());
-            dto.setUpdateByName(CollectionUtils.isEmpty(kwsThresholds) ? null : kwsThresholds.get(0).getUpdateName());
-            dto.setUpdateTime(CollectionUtils.isEmpty(kwsThresholds) ? null : kwsThresholds.get(0).getUpdateTime());
+            dto.setUpdateByName(CollectionUtils.isEmpty(kwsThresholds) ? null : kwsThresholds.get(0).getCreateName());
+            dto.setUpdateTime(CollectionUtils.isEmpty(kwsThresholds) ? null : kwsThresholds.get(0).getCreateTime());
         }
         return PageRes.build(info, dtoList);
     }
@@ -143,10 +155,10 @@ public class ThresholdService {
             vo.setItemValue(deviceReference == null ? null : deviceReference.getValue());
             //查询td获取数据
 //            vo.setVariation();
-            List<ThresholdDetailVO.ThresholdBean> beanList = new ArrayList<>();
+            List<ThresholdBean> beanList = new ArrayList<>();
             for (KwsThreshold threshold : kwsThreshold) {
-                ThresholdDetailVO.ThresholdBean bean = new ThresholdDetailVO.ThresholdBean();
-                bean.setLevel(threshold.getLevel().toString());
+                ThresholdBean bean = new ThresholdBean();
+                bean.setLevel(threshold.getLevel());
                 bean.setMax(threshold.getMax());
                 bean.setMin(threshold.getMin());
                 beanList.add(bean);
@@ -155,4 +167,361 @@ public class ThresholdService {
         }
         return HttpResult.ok(vo);
     }
+
+    @Transactional
+    public HttpResult configuration(ThresholdConfigurationDTO configurationDTO, HttpServletRequest request) {
+        HeaderData headerData = commonService.getHeaderData(request);
+        List<ThresholdBean> threshold = configurationDTO.getThreshold();
+        String itemName = configurationDTO.getItemName();
+        String phones = configurationDTO.getPhones();
+        String deviceId = configurationDTO.getDeviceId();
+        if (CollectionUtils.isEmpty(threshold)) {
+            return HttpResult.error(HttpStatus.GLOBAL_EXCEPTION_CODE, "设置阈值不能全部为空");
+        }
+        List<String> phonesStr = StringUtils.splitStrToList(phones, String.class);
+        for (String phone : phonesStr) {
+            if (!RegularUtils.matchs(RegularUtils.PHONE_REG, phone)) {
+                return HttpResult.error(HttpStatus.GLOBAL_EXCEPTION_CODE, "联系电话格式不正确,请检查并重新输入!");
+            }
+        }
+        //页面阈值等级校验
+        //当前使用阈值123级硬编码校验
+        checkThresholdLevel(configurationDTO, headerData);
+        //后期阈值等级扩容可调用此方法
+        //checkLevelMax(threshold, configurationDTO, headerData);
+        for (ThresholdBean thresholdBean : threshold) {
+            //验证数据库层面阈值数据存储值
+            int level = thresholdBean.getLevel();
+            checkDatabaseThresholdLevel(level, thresholdBean, headerData, deviceId, itemName);
+            KwsThreshold selected = thresholdMapper.selectOne(new LambdaQueryWrapper<KwsThreshold>()
+                    .eq(KwsThreshold::getMountainId, headerData.getMountainId())
+                    .eq(KwsThreshold::getDeviceId, deviceId)
+                    .eq(KwsThreshold::getItemName, itemName)
+                    .eq(KwsThreshold::getCompanyId, headerData.getMountainId())
+                    .eq(KwsThreshold::getLevel, level)
+                    .eq(KwsThreshold::getDelFlag, NumberConstant.ZERO)
+            );
+            if (selected == null) {
+                KwsThreshold kwsThreshold = new KwsThreshold();
+                kwsThreshold.setId(new IdWorker(NumberConstant.ONE).nextId());
+                kwsThreshold.setDeviceId(Long.parseLong(deviceId));
+                kwsThreshold.setItemName(itemName);
+                kwsThreshold.setCompanyId(headerData.getCompanyId());
+                kwsThreshold.setMountainId(headerData.getMountainId());
+                //计算设置状态  便于select
+                String setting = checkAndSettings(configurationDTO, headerData);
+                kwsThreshold.setSetting(setting);
+                kwsThreshold.setLevel(Integer.valueOf(thresholdBean.getLevel()));
+                kwsThreshold.setMax(thresholdBean.getMax());
+                kwsThreshold.setMin(thresholdBean.getMin());
+                kwsThreshold.setPhones(phones);
+                kwsThreshold.setStatus(0);
+                kwsThreshold.setCreateBy(headerData.getCreateBy() == null ? null : Long.parseLong(headerData.getCreateBy()));
+                kwsThreshold.setCreateName(headerData.getCreateName());
+                LocalDateTime now = LocalDateTime.now();
+                kwsThreshold.setCreateTime(now);
+                thresholdMapper.insert(kwsThreshold);
+            } else {
+                selected.setLevel(Integer.valueOf(thresholdBean.getLevel()));
+                //计算设置状态  便于select
+                String setting = checkAndSettings(configurationDTO, headerData);
+                selected.setSetting(setting);
+                selected.setMax(thresholdBean.getMax());
+                selected.setMin(thresholdBean.getMin());
+                selected.setPhones(phones);
+                selected.setStatus(0);
+                selected.setUpdateBy(headerData.getUpdateBy() == null ? null : Long.parseLong(headerData.getUpdateBy()));
+                selected.setUpdateName(headerData.getUpdateName());
+                selected.setUpdateTime(LocalDateTime.now());
+                thresholdRepository.saveOrUpdate(selected);
+            }
+        }
+        return HttpResult.ok();
+    }
+
+    /**
+     * 比较数据库中存在的阈值与页面填写的阈值范围
+     * @param level 阈值等级
+     * @param thresholdBean 页面填写数据
+     * @param headerData    请求头信息
+     * @param deviceId  设备id
+     * @param itemName  要素项
+     */
+    private void checkDatabaseThresholdLevel(int level, ThresholdBean thresholdBean, HeaderData headerData, String deviceId, String itemName) {
+        if (1 == level) {
+            KwsThreshold twoKwsThreshold = thresholdSelect(2, headerData, deviceId, itemName);
+            KwsThreshold threeKwsThreshold = thresholdSelect(3, headerData, deviceId, itemName);
+            if (twoKwsThreshold != null) {
+                String min = twoKwsThreshold.getMin();
+                if (min.contains("-")) {
+                    min = StringUtils.deleteCharString(min, "-");
+                }
+                String max = twoKwsThreshold.getMax();
+                if (Long.parseLong(thresholdBean.getMax()) > Long.parseLong(max)) {
+                    throw new BusinessException("阈值设置数据填写错误");
+                }
+                if (Long.parseLong(thresholdBean.getMin()) > Long.parseLong(min)) {
+                    throw new BusinessException("阈值设置数据填写错误");
+                }
+            }
+            if (threeKwsThreshold != null) {
+                String min = threeKwsThreshold.getMin();
+                if (min.contains("-")) {
+                    min = StringUtils.deleteCharString(min, "-");
+                }
+                String max = threeKwsThreshold.getMax();
+                if (Long.parseLong(thresholdBean.getMax()) > Long.parseLong(max)) {
+                    throw new BusinessException("阈值设置数据填写错误");
+                }
+                if (Long.parseLong(thresholdBean.getMin()) > Long.parseLong(min)) {
+                    throw new BusinessException("阈值设置数据填写错误");
+                }
+            }
+        } else if (2 == level) {
+            KwsThreshold oneKwsThreshold = thresholdSelect(1, headerData, deviceId, itemName);
+            KwsThreshold threeKwsThreshold = thresholdSelect(3, headerData, deviceId, itemName);
+            if (oneKwsThreshold != null) {
+                String max = oneKwsThreshold.getMax();
+                String min = oneKwsThreshold.getMin();
+                if (min.contains("-")) {
+                    min = StringUtils.deleteCharString(min, "-");
+                }
+                if (Long.parseLong(thresholdBean.getMax()) < Long.parseLong(max)) {
+                    throw new BusinessException("阈值设置数据填写错误");
+                }
+                if (Long.parseLong(thresholdBean.getMin()) < Long.parseLong(min)) {
+                    throw new BusinessException("阈值设置数据填写错误");
+                }
+            }
+            if (threeKwsThreshold != null) {
+                String max = threeKwsThreshold.getMax();
+                String min = threeKwsThreshold.getMin();
+                if (min.contains("-")) {
+                    min = StringUtils.deleteCharString(min, "-");
+                }
+                if (Long.parseLong(thresholdBean.getMax()) > Long.parseLong(max)) {
+                    throw new BusinessException("阈值设置数据填写错误");
+                }
+                if (Long.parseLong(thresholdBean.getMin()) > Long.parseLong(min)) {
+                    throw new BusinessException("阈值设置数据填写错误");
+                }
+            }
+        } else if (3 == level) {
+            KwsThreshold oneKwsThreshold = thresholdSelect(1, headerData, deviceId, itemName);
+            KwsThreshold twoKwsThreshold = thresholdSelect(2, headerData, deviceId, itemName);
+            if (oneKwsThreshold != null) {
+                String max = oneKwsThreshold.getMax();
+                String min = oneKwsThreshold.getMin();
+                if (min.contains("-")) {
+                    min = StringUtils.deleteCharString(min, "-");
+                }
+                if (Long.parseLong(thresholdBean.getMax()) < Long.parseLong(max)) {
+                    throw new BusinessException("阈值设置数据填写错误");
+                }
+                if (Long.parseLong(thresholdBean.getMin()) < Long.parseLong(min)) {
+                    throw new BusinessException("阈值设置数据填写错误");
+                }
+            }
+            if (twoKwsThreshold != null) {
+                String max = twoKwsThreshold.getMax();
+                String min = twoKwsThreshold.getMin();
+                if (min.contains("-")) {
+                    min = StringUtils.deleteCharString(min, "-");
+                }
+                if (Long.parseLong(thresholdBean.getMax()) < Long.parseLong(max)) {
+                    throw new BusinessException("阈值设置数据填写错误");
+                }
+                if (Long.parseLong(thresholdBean.getMin()) < Long.parseLong(min)) {
+                    throw new BusinessException("阈值设置数据填写错误");
+                }
+            }
+
+        }
+    }
+
+    private KwsThreshold thresholdSelect(int level, HeaderData headerData, String deviceId, String itemName) {
+        KwsThreshold threshold = thresholdMapper.selectOne(new LambdaQueryWrapper<KwsThreshold>()
+                .eq(KwsThreshold::getMountainId, headerData.getMountainId())
+                .eq(KwsThreshold::getDeviceId, deviceId)
+                .eq(KwsThreshold::getItemName, itemName)
+                .eq(KwsThreshold::getCompanyId, headerData.getMountainId())
+                .eq(KwsThreshold::getLevel, 2)
+                .eq(KwsThreshold::getDelFlag, NumberConstant.ZERO)
+        );
+        return threshold;
+    }
+
+    private void checkThresholdLevel(ThresholdConfigurationDTO configurationDTO, HeaderData headerData) {
+        List<ThresholdBean> threshold = configurationDTO.getThreshold();
+        Map<Integer, ThresholdBean> maps = threshold.stream().collect(Collectors.toMap(ThresholdBean::getLevel, Function.identity(), (key1, key2) -> key2));
+        ThresholdBean thresholdBeanOne = maps.get(1);
+        ThresholdBean thresholdBeanTwo = maps.get(2);
+        ThresholdBean thresholdBeanThree = maps.get(3);
+        if (thresholdBeanTwo != null) {
+            String min = thresholdBeanTwo.getMin();
+            if (min.contains("-")) {
+                min = com.sckw.core.utils.StringUtils.deleteCharString(min, "-");
+            }
+            String max = thresholdBeanTwo.getMax();
+            if (thresholdBeanThree != null) {
+                String minThree = thresholdBeanThree.getMin();
+                if (minThree.contains("-")) {
+                    minThree = com.sckw.core.utils.StringUtils.deleteCharString(minThree, "-");
+                }
+                String maxThree = thresholdBeanThree.getMax();
+                if (BigDecimal.valueOf(Long.parseLong(max)).compareTo(BigDecimal.valueOf(Long.parseLong(maxThree))) > 0) {
+                    throw new BusinessException("阈值填写错误");
+                }
+                if (BigDecimal.valueOf(Long.parseLong(min)).compareTo(BigDecimal.valueOf(Long.parseLong(minThree))) < 0) {
+                    throw new BusinessException("阈值填写错误");
+                }
+            }
+            if (thresholdBeanOne != null) {
+                String minOne = thresholdBeanOne.getMin();
+                if (minOne.contains("-")) {
+                    minOne = com.sckw.core.utils.StringUtils.deleteCharString(minOne, "-");
+                }
+                String maxThree = thresholdBeanOne.getMax();
+                if (BigDecimal.valueOf(Long.parseLong(max)).compareTo(BigDecimal.valueOf(Long.parseLong(maxThree))) < 0) {
+                    throw new BusinessException("阈值填写错误");
+                }
+                if (BigDecimal.valueOf(Long.parseLong(min)).compareTo(BigDecimal.valueOf(Long.parseLong(minOne))) > 0) {
+                    throw new BusinessException("阈值填写错误");
+                }
+            }
+        }
+        if (thresholdBeanThree != null) {
+            String minThree = thresholdBeanThree.getMin();
+            if (minThree.contains("-")) {
+                minThree = com.sckw.core.utils.StringUtils.deleteCharString(minThree, "-");
+            }
+            String maxThree = thresholdBeanThree.getMax();
+            if (thresholdBeanTwo != null) {
+                String twoMax = thresholdBeanTwo.getMax();
+                String twoMin = thresholdBeanTwo.getMin();
+                if (BigDecimal.valueOf(Long.parseLong(twoMax)).compareTo(BigDecimal.valueOf(Long.parseLong(maxThree))) > 0) {
+                    throw new BusinessException("阈值填写错误");
+                }
+                if (BigDecimal.valueOf(Long.parseLong(twoMin)).compareTo(BigDecimal.valueOf(Long.parseLong(minThree))) > 0) {
+                    throw new BusinessException("阈值填写错误");
+                }
+            }
+        }
+    }
+
+    private void checkLevelMax(List<ThresholdBean> threshold, ThresholdConfigurationDTO configurationDTO, HeaderData headerData) {
+        Integer maxLevel = threshold.stream().map(ThresholdBean::getLevel).max((x, y) -> x - y).get();
+        if (threshold.size() > 1) {
+            Map<Integer, ThresholdBean> maps = threshold.stream().collect(Collectors.toMap(ThresholdBean::getLevel, Function.identity(), (key1, key2) -> key2));
+            int count = 0;
+            for (int i = maxLevel; i > 0; i--) {
+                ThresholdBean thresholdBean = maps.get(maxLevel);
+                if (thresholdBean != null) {
+                    String thresholdBeanMin = thresholdBean.getMin();
+                    if (thresholdBeanMin.contains("-")) {
+                        thresholdBeanMin = com.sckw.core.utils.StringUtils.deleteCharString(thresholdBeanMin, "-");
+                    }
+                    ThresholdBean thresholdBean1 = maps.get(i);
+                    if (thresholdBean1 != null) {
+                        String max = thresholdBean1.getMax();
+                        String min = thresholdBean1.getMin();
+                        if (min.contains("-")) {
+                            min = com.sckw.core.utils.StringUtils.deleteCharString(min, "-");
+                        }
+                        if (BigDecimal.valueOf(Long.parseLong(max)).compareTo(BigDecimal.valueOf(Long.parseLong(thresholdBean.getMax()))) > 0) {
+                            throw new BusinessException("阈值填写错误");
+                        }
+                        if (BigDecimal.valueOf(Long.parseLong(min)).compareTo(BigDecimal.valueOf(Long.parseLong(thresholdBeanMin))) < 0) {
+                            throw new BusinessException("阈值填写错误");
+                        }
+                    }
+                }
+            }
+            for (ThresholdBean value : maps.values()) {
+                int level = value.getLevel();
+                if (level == count) {
+                    int levelMax = level + 1;
+                    int levelMin = level - 1;
+                    if (maps.get(levelMax) != null) {
+                        String min = value.getMin();
+                        String max = value.getMax();
+                    }
+                    if (maps.get(levelMin) != null) {
+
+                    }
+                }
+            }
+            ThresholdBean thresholdBean2 = maps.get(2);
+            ThresholdBean thresholdBean1 = maps.get(1);
+            ThresholdBean thresholdBean3 = maps.get(3);
+        }
+        if (1 != maxLevel) {
+            //上限界定
+            KwsThreshold maxThreshold = thresholdMapper.selectOne(new LambdaQueryWrapper<KwsThreshold>()
+                    .eq(KwsThreshold::getMountainId, headerData.getMountainId())
+                    .eq(KwsThreshold::getDeviceId, Long.parseLong(configurationDTO.getDeviceId()))
+                    .eq(KwsThreshold::getItemName, configurationDTO.getItemName())
+                    .eq(KwsThreshold::getCompanyId, headerData.getMountainId())
+                    .eq(KwsThreshold::getLevel, (maxLevel + 1))
+                    .eq(KwsThreshold::getDelFlag, NumberConstant.ZERO)
+            );
+            if (maxThreshold != null) {
+                String max = maxThreshold.getMax();
+                String min = maxThreshold.getMin();
+            }
+            //下限界定
+        }
+    }
+
+    private String checkAndSettings(ThresholdConfigurationDTO configurationDTO, HeaderData headerData) {
+        String deviceId = configurationDTO.getDeviceId();
+        List<Integer> status = new ArrayList<>();
+        status.add(DeviceEnum.ALREADY_REFERRED_TO.getCode());
+        //基本要素
+        List<DeviceElementDTO> basiclElementList = deviceModelPartMapper.selectElementList(configurationDTO.getProjectId(),
+                headerData.getMountainId(), status, Long.parseLong(deviceId));
+        //集成要素
+        List<DeviceElementDTO> integratedElementList = deviceIntegrationMapper.selectIntegratedElement(configurationDTO.getProjectId(),
+                headerData.getMountainId(), status, Long.parseLong(deviceId));
+        int count = 0;
+        if (!CollectionUtils.isEmpty(basiclElementList)) {
+            List<String> collect = basiclElementList.stream().map(DeviceElementDTO::getElement).collect(Collectors.toList());
+            if (!CollectionUtils.isEmpty(collect)) {
+                for (String s : collect) {
+                    List<String> stringList = StringUtils.splitStrToList(s, String.class);
+                    count = count + stringList.size();
+                }
+            }
+
+        }
+        if (!CollectionUtils.isEmpty(integratedElementList)) {
+            List<String> collect = basiclElementList.stream().map(DeviceElementDTO::getIntegrationElement).collect(Collectors.toList());
+            if (!CollectionUtils.isEmpty(collect)) {
+                for (String s : collect) {
+                    List<String> stringList = StringUtils.splitStrToList(s, String.class);
+                    count = count + stringList.size();
+                }
+            }
+        }
+        List<KwsThreshold> kwsThresholds = thresholdMapper.selectList(new LambdaQueryWrapper<KwsThreshold>()
+                .eq(KwsThreshold::getDeviceId, configurationDTO.getDeviceId())
+                .eq(KwsThreshold::getMountainId, headerData.getMountainId())
+                .eq(KwsThreshold::getDelFlag, NumberConstant.ZERO)
+        );
+        int number = 0;
+        if (!CollectionUtils.isEmpty(kwsThresholds)) {
+            List<String> collect = kwsThresholds.stream().map(KwsThreshold::getItemName).distinct().collect(Collectors.toList());
+            number = collect.size();
+        }
+        // 0未设置 1 部分设置 2 已设置
+        String setting = "0";
+        if (number != 0) {
+            if (count == number) {
+                setting = "2";
+            } else if (count > number) {
+                setting = "1";
+            }
+        }
+        return setting;
+    }
 }

+ 7 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/repository/KwsThresholdRepository.java

@@ -0,0 +1,7 @@
+package com.sckw.slope.detection.service.repository;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.sckw.slope.detection.model.dos.mysql.KwsThreshold;
+
+public interface KwsThresholdRepository extends IService<KwsThreshold> {
+}

+ 17 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/repository/impl/kwsThresholdImpl.java

@@ -0,0 +1,17 @@
+package com.sckw.slope.detection.service.repository.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.sckw.slope.detection.dao.mysql.KwsThresholdMapper;
+import com.sckw.slope.detection.model.dos.mysql.KwsThreshold;
+import com.sckw.slope.detection.service.repository.KwsThresholdRepository;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author lfdc
+ * @description 阈值实现类
+ * @date 2023-11-03 09:11:19
+ */
+@Service
+public class kwsThresholdImpl extends ServiceImpl<KwsThresholdMapper, KwsThreshold> implements KwsThresholdRepository {
+
+}

+ 25 - 15
slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsDeviceMapper.xml

@@ -35,21 +35,31 @@
     where id = #{id,jdbcType=BIGINT}
   </select>
   <select id="selectByDeviceParam" resultType="com.sckw.slope.detection.model.vo.DeviceVo">
-    select
-    d.id, d.name,manufacturer,device_type,m.name as m_name,d.remark,d.update_by,d.update_time,p.`name` as project_name,d.status
-    from kws_device as d
-        inner join kws_device_model as m on d.model_id=m.id
-        left join kws_project_device as pd on d.id=pd.device_id
-        left join kws_project as p on pd.project_id=p.id
-    WHERE d.del_flag = 0 and m.del_flag = 0
-    <where>
-      <if test="deviceQuery.deviceName != null and deviceQuery.deviceName != ''">
-        and name like concat('%', #{deviceQuery.deviceName}, '%')
-      </if>
-      <if test="deviceQuery.id != null and deviceQuery.id != ''">
-        and id = #{id,jdbcType=BIGINT}
-      </if>
-    </where>
+      select d.id,
+             d.name,
+             manufacturer,
+             device_type,
+             m.name   as m_name,
+             d.remark,
+             d.update_by,
+             d.update_time,
+             p.`name` as project_name,
+             d.status
+      from kws_device as d
+               inner join kws_device_model as m on d.model_id = m.id
+               left join kws_project_device as pd on d.id = pd.device_id
+               left join kws_project as p on pd.project_id = p.id
+      WHERE d.del_flag = 0
+        and m.del_flag = 0
+      <where>
+          <if test="deviceQuery.name != null and deviceQuery.name != ''">
+              and name like concat('%', #{deviceQuery.name}
+                   , '%')
+          </if>
+          <if test="deviceQuery.id != null and deviceQuery.id != ''">
+              and id = #{deviceQuery.id,jdbcType=BIGINT}
+          </if>
+      </where>
   </select>
   <insert id="insert" parameterType="com.sckw.slope.detection.model.dos.mysql.KwsDevice">
     <!--@mbg.generated-->

+ 0 - 11
slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsProjectDeviceMapper.xml

@@ -33,17 +33,6 @@
     delete from kws_project_device
     where id = #{id,jdbcType=BIGINT}
   </delete>
-  <insert id="insert" parameterType="com.sckw.slope.detection.model.dos.mysql.KwsProjectDevice">
-    <!--@mbg.generated-->
-    insert into kws_project_device (id, project_id, device_id, 
-      `status`, create_by, create_time, 
-      update_by, update_time, del_flag
-      )
-    values (#{id,jdbcType=BIGINT}, #{projectId,jdbcType=BIGINT}, #{deviceId,jdbcType=BIGINT}, 
-      #{status,jdbcType=TINYINT}, #{createBy,jdbcType=BIGINT}, #{createTime,jdbcType=TIMESTAMP}, 
-      #{updateBy,jdbcType=BIGINT}, #{updateTime,jdbcType=TIMESTAMP}, #{delFlag,jdbcType=TINYINT}
-      )
-  </insert>
   <insert id="insertSelective" parameterType="com.sckw.slope.detection.model.dos.mysql.KwsProjectDevice">
     <!--@mbg.generated-->
     insert into kws_project_device

+ 13 - 4
slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsProjectMapper.xml

@@ -72,14 +72,22 @@
                d.`name`       AS modelName,
                c.create_time  AS createTime
         FROM kws_project a
-                 LEFT JOIN kws_project_device b ON a.id = b.project_id
-                 LEFT JOIN kws_device c ON b.device_id = c.id
-                 LEFT JOIN kws_device_model d ON c.model_id = d.id
+                 LEFT JOIN kws_project_device b ON a.id = b.project_id and a.mountain_id = b.mountain_id
+                 LEFT JOIN kws_device c ON b.device_id = c.id and c.mountain_id = b.mountain_id
+                 LEFT JOIN kws_device_model d ON c.model_id = d.id and d.mountain_id = c.mountain_id
         WHERE a.del_flag = 0
           AND b.del_flag = 0
           AND c.del_flag = 0
           AND d.del_flag = 0
-          AND a.id = #{projectId,jdbcType=BIGINT}
+        <if test="mountainId != null and mountainId != ''">
+            AND c.mountain_id = #{mountainId}
+        </if>
+        <if test="projectId != null  and projectId != ''">
+            AND a.id = #{projectId}
+        </if>
+        <if test="deviceId != null and deviceId != ''">
+            AND c.id = #{deviceId}
+        </if>
     </select>
 
     <select id="selectDeviceList" resultType="com.sckw.slope.detection.model.vo.ProjectDeviceVO">
@@ -87,6 +95,7 @@
                a.`name`       AS projectName,
                c.id           AS id,
                c.`name`       AS NAME,
+               c.alias        AS alias,
                d.device_type  AS deviceType,
                d.manufacturer AS manufacturer,
                d.`name`       AS modelName,

+ 2 - 11
slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsThresholdMapper.xml

@@ -18,6 +18,7 @@
         <result column="create_by" jdbcType="BIGINT" property="createBy"/>
         <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
         <result column="update_by" jdbcType="BIGINT" property="updateBy"/>
+        <result column="create_name" jdbcType="VARCHAR" property="createName"/>
         <result column="update_name" jdbcType="VARCHAR" property="updateName"/>
         <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
         <result column="del_flag" jdbcType="TINYINT" property="delFlag"/>
@@ -29,6 +30,7 @@
         setting,
         mountain_id,
         update_name,
+        create_name,
         item_name,
         `level`,
         `max`,
@@ -56,17 +58,6 @@
         from kws_threshold
         where id = #{id,jdbcType=BIGINT}
     </delete>
-    <insert id="insert" parameterType="com.sckw.slope.detection.model.dos.mysql.KwsThreshold">
-        <!--@mbg.generated-->
-        insert into kws_threshold (id, device_id, item_name,
-                                   `level`, `max`, `min`, phones,
-                                   `status`, create_by, create_time,
-                                   update_by, update_time, del_flag)
-        values (#{id,jdbcType=BIGINT}, #{deviceId,jdbcType=BIGINT}, #{itemName,jdbcType=VARCHAR},
-                #{level,jdbcType=INTEGER}, #{max,jdbcType=VARCHAR}, #{min,jdbcType=VARCHAR}, #{phones,jdbcType=VARCHAR},
-                #{status,jdbcType=TINYINT}, #{createBy,jdbcType=BIGINT}, #{createTime,jdbcType=TIMESTAMP},
-                #{updateBy,jdbcType=BIGINT}, #{updateTime,jdbcType=TIMESTAMP}, #{delFlag,jdbcType=TINYINT})
-    </insert>
     <insert id="insertSelective" parameterType="com.sckw.slope.detection.model.dos.mysql.KwsThreshold">
         <!--@mbg.generated-->
         insert into kws_threshold