lengfaqiang пре 2 година
родитељ
комит
44f8adeb95

+ 53 - 0
slope-common/slope-common-core/src/main/java/com/sckw/core/model/enums/IntegrationStatusEnum.java

@@ -0,0 +1,53 @@
+package com.sckw.core.model.enums;
+
+/**
+ * @author lfdc
+ * @description 设备状态
+ * @date 2023-11-01 10:07:23
+ */
+public enum IntegrationStatusEnum {
+
+    /**
+     * 识别失败
+     */
+    INTEGRATION_ZERO(0, "0", "未自适应"),
+    /**
+     * 识别中
+     */
+    INTEGRATION_ONE(1, "1", "启用自适应"),
+
+    ;
+
+    public Integer getCode() {
+        return code;
+    }
+
+    public String getStatus() {
+        return status;
+    }
+
+    public String getDestination() {
+        return destination;
+    }
+
+    private final Integer code;
+    private final String status;
+    private final String destination;
+
+    IntegrationStatusEnum(Integer code, String status, String destination) {
+        this.code = code;
+        this.status = status;
+        this.destination = destination;
+    }
+    public static String getDestination(Integer code) {
+        for (IntegrationStatusEnum enums : IntegrationStatusEnum.values()) {
+            if (enums.getCode().equals(code)) {
+                return enums.getDestination();
+            }
+        }
+        return null;
+    }
+
+
+
+}

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

@@ -90,6 +90,71 @@ public enum MessageLogEnum {
     DELETE_DEVICE_THRESHOLD("slope_manage", "PROJECT_LOG", "删除设备阈值", "13",
             "设备【${deviceName}】已删除了【${element}】监测要素阈值,所属边坡【${projectName}】", "删除设备阈值"),
 
+    /**
+     * 新增集成分析方案
+     */
+    INTEGRATION_ADD("slope_manage", "PROJECT_LOG", "新增集成分析方案", "14",
+            "集成要素【${name}】已被新增,【${type}】所有设备", "新增集成分析方案"),
+    /**
+     * 修改集成分析方案
+     */
+    INTEGRATION_UPDATE("slope_manage", "PROJECT_LOG", "修改集成分析方案", "15",
+            "集成要素【${name}】已被修改,【${type}】所有设备", "修改集成分析方案"),
+
+    /**
+     * 新增设备型号
+     */
+    MODEL_ADD("slope_manage", "PROJECT_LOG", "新增设备型号", "16",
+            "型号【${name}】已被新增", "新增设备型号"),
+
+    /**
+     * 修改设备型号
+     */
+    MODEL_UPDATE("slope_manage", "PROJECT_LOG", "修改设备型号", "17",
+            "型号【${name}】已被修改", "修改设备型号"),
+
+    /**
+     * 删除设备型号
+     */
+    MODEL_DELETE("slope_manage", "PROJECT_LOG", "删除设备型号", "18",
+            "型号【${name}】已被删除", "删除设备型号"),
+    /**
+     * 新增设备
+     */
+    DEVICE_ADD("slope_manage", "PROJECT_LOG", "新增设备", "19",
+            "设备【${name}】已被新增,所属型号【${type}】", "新增设备"),
+    /**
+     * 修改设备
+     */
+    DEVICE_UPDATE("slope_manage", "PROJECT_LOG", "修改设备", "20",
+            "设备【${name}】已被修改,所属型号【${type}】", "修改设备"),
+    /**
+     * 删除设备
+     */
+    DEVICE_DELETE("slope_manage", "PROJECT_LOG", "删除设备", "21",
+            "设备【${name}】已被删除,所属型号【${type}】", "删除设备"),
+    /**
+     * 禁用设备
+     */
+    DEVICE_DISABLED("slope_manage", "PROJECT_LOG", "禁用设备", "22",
+            "设备【${name}】已被禁用,所属型号【${type}】", "禁用设备"),
+
+    /**
+     * 启用设备
+     */
+    DEVICE_ABLED("slope_manage", "PROJECT_LOG", "启用设备", "23",
+            "设备【${name}】已被启用,所属型号【${type}】", "启用设备"),
+    /**
+     * 设备基准值设置
+     */
+    DEVICE_SETBASE("slope_manage", "PROJECT_LOG", "设备基准值设置", "24",
+            "设备【${name}】已被设置阈值,相关要素【${type}】,所属边坡【${desc}】", "设备基准值设置"),
+    /**
+     * 设备基准值调整
+     */
+    DEVICE_SETVALUE("slope_manage", "PROJECT_LOG", "设备基准值调整", "25",
+            "设备【${name}】已被调整阈值,相关要素【${type}】,所属边坡【${desc}】", "设备基准值调整"),
+
     ;
 
 

+ 4 - 0
slope-common/slope-common-core/src/main/java/com/sckw/core/web/constant/HttpStatus.java

@@ -148,6 +148,10 @@ public class HttpStatus {
     public static final String CONTRACT_NOT_EXISTS = "未查询到合同或已失效";
     public static final String BANNER_NOT_EXISTS = "未查询到banner数据或已失效";
 
+    public static final String INTEGRATION_NOT_EXISTS = "未查询到集成元素或已失效";
+    public static final String MODEL_NOT_EXISTS = "未查询到设备型号或已失效";
+    public static final String DEVICE_NOT_EXISTS = "未查询到设备或已失效";
+
 
     /**自定义提示消息*/
     public static final String PASSWD_ERROR = "密码不正确";

+ 2 - 3
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/controller/DeviceController.java

@@ -34,10 +34,9 @@ public class DeviceController {
     @Log(description = "设备删除")
     //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
     @RequestMapping(name = "设备删除", value = "/dels", method = RequestMethod.GET)
-    public HttpResult dels(@RequestParam("ids") @NotBlank(message = "设备id不能为空") String ids) {
+    public HttpResult dels(@RequestParam("ids") @NotBlank(message = "设备id不能为空") String ids, HttpServletRequest request) {
         log.info("设备删除 delete param:{}", ids);
-        return deviceService.dels(ids
-        );
+        return deviceService.dels(ids,request);
     }
 
     @Log(description = "所属设备查询")

+ 2 - 2
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/controller/DeviceModelController.java

@@ -35,9 +35,9 @@ public class DeviceModelController {
     @Log(description = "设备型号删除")
     //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
     @RequestMapping(name = "设备型号删除", value = "/dels", method = RequestMethod.GET)
-    public HttpResult dels(@RequestParam("ids") @NotBlank(message = "设备id不能为空") String ids) {
+    public HttpResult dels(@RequestParam("ids") @NotBlank(message = "设备id不能为空") String ids, HttpServletRequest response) {
         log.info("设备型号删除 delete param:{}", ids);
-        return deviceModelService.dels(ids);
+        return deviceModelService.dels(ids,response);
     }
 
 

+ 19 - 5
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/controller/backTrackController.java

@@ -43,17 +43,17 @@ public class backTrackController {
     @Log(description = "返回要素所属于的设备")
     //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
     @RequestMapping(name = "返回要素所属于的设备", value = "/getDeviceByParts", method = RequestMethod.GET)
-    public HttpResult getDeviceByParts(@RequestParam("parts") String parts) {
-        log.info("返回要素所属于的设备 getDeviceByParts param :{}",parts);
-        return backTrackService.getDeviceByParts(parts);
+    public HttpResult getDeviceByParts(@RequestParam("parts") String parts,@RequestParam("projectId") String projectId) {
+        log.info("返回要素所属于的设备 getDeviceByParts param :{},projectId:{}",parts,projectId);
+        return backTrackService.getDeviceByParts(parts,projectId);
     }
 
     @Log(description = "返回设备折线图")
     //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
     @RequestMapping(name = "返回设备折线图", value = "/getDeviceChart", method = RequestMethod.GET)
-    public HttpResult getDeviceChart(@RequestParam("deviceId") String deviceId,@RequestParam("snCode") String snCode, @RequestParam("part") String part, @RequestParam("dateStart") String dateStart, @RequestParam("dateEnd") String dateEnd) {
+    public HttpResult getDeviceChart(@RequestParam("deviceId") String deviceId,@RequestParam("snCode") String snCode, @RequestParam("part") String part, @RequestParam("dateStart") String dateStart, @RequestParam("dateEnd") String dateEnd, @RequestParam("original") Integer original) {
         log.info("返回设备折线图 getDeviceChart param :{},part:{}",deviceId,part);
-        return backTrackService.getDeviceChart(deviceId,snCode,part,dateStart,dateEnd);
+        return backTrackService.getDeviceChart(deviceId,snCode,part,dateStart,dateEnd,original);
     }
 
 
@@ -80,7 +80,21 @@ public class backTrackController {
         log.info("新增集成分析 integrationAdd param:{}", JSONObject.toJSONString(Vo));
         return HttpResult.ok(backTrackService.integrationAdd(Vo, request));
     }
+    @Log(description = "修改集成分析")
+    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
+    @RequestMapping(name = "修改集成分析", value = "/integrationUpdate", method = RequestMethod.POST)
+    public HttpResult integrationUpdate(@Valid @RequestBody IntegrationVo Vo, HttpServletRequest request) {
+        log.info("修改集成分析 integrationUpdate param:{}", JSONObject.toJSONString(Vo));
+        return HttpResult.ok(backTrackService.integrationUpdate(Vo, request));
+    }
 
+    @Log(description = "返回选择设备的所有要素")
+    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
+    @RequestMapping(name = "返回选择设备的所有要素", value = "/getPartsByDeviceId", method = RequestMethod.GET)
+    public HttpResult getPartsByDeviceId(@RequestParam("deviceId") String deviceId) {
+        log.info("返回选择设备的所有要素 getPartsByDeviceId deviceId:{}",deviceId);
+        return backTrackService.getPartsByDeviceId(deviceId);
+    }
 
 
 }

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

@@ -64,4 +64,9 @@ public class DeviceQuery {
      */
 
     private String status;
+    /**
+     * 设备名称
+     */
+
+    private String deviceName;
 }

+ 70 - 13
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/BackTrackService.java

@@ -11,10 +11,7 @@ import com.sckw.core.exception.BusinessException;
 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.enums.MessageLogEnum;
+import com.sckw.core.model.enums.*;
 import com.sckw.core.model.page.PageRes;
 import com.sckw.core.utils.IdWorker;
 import com.sckw.core.utils.StringUtils;
@@ -90,29 +87,34 @@ public class BackTrackService {
         List<KwsDeviceReference> references = deviceReferenceMapper.selectList(new LambdaQueryWrapper<KwsDeviceReference>()
                 .in(KwsDeviceReference::getDeviceId, devicesId)
                 .eq(KwsDeviceReference::getDelFlag, NumberConstant.ZERO)
+                .groupBy(KwsDeviceReference::getItem)
         );
         return HttpResult.ok(references);
     }
 
-    public HttpResult getDeviceByParts(String parts) {
+    public HttpResult getDeviceByParts(String parts,String projectId) {
+        //获取项目中的设备
+        List<DeviceDataDTO> listDevice = deviceMapper.selectDeviceAllNotDeviceRelation(projectId);
+        List<String> devicesId = listDevice.stream().map(DeviceDataDTO::getDeviceId).toList();
         //在获取设备的要素
         String[] arr = parts.split(",");
         List<String> list = Arrays.asList(arr);
         List<KwsDeviceReference> references = deviceReferenceMapper.selectList(new LambdaQueryWrapper<KwsDeviceReference>()
-                .in(KwsDeviceReference::getId, list)
+                .in(KwsDeviceReference::getItem, list)
+                .in(KwsDeviceReference::getDeviceId, devicesId)
                 .eq(KwsDeviceReference::getDelFlag, NumberConstant.ZERO)
         );
         //获取对应的设备
-        List<Long> devicesId = references.stream().map(KwsDeviceReference::getDeviceId).toList();
+        List<Long> devicesIds = references.stream().map(KwsDeviceReference::getDeviceId).toList();
 
         List<KwsDevice> devices = deviceMapper.selectList(new LambdaQueryWrapper<KwsDevice>()
-                .in(KwsDevice::getId, devicesId)
+                .in(KwsDevice::getId, devicesIds)
                 .eq(KwsDevice::getDelFlag, NumberConstant.ZERO)
         );
         return HttpResult.ok(devices);
     }
 
-    public HttpResult getDeviceChart(String devicesId,String snCode, String parts, String dateStart,String dateEnd) {
+    public HttpResult getDeviceChart(String devicesId,String snCode, String parts, String dateStart,String dateEnd,Integer original) {
         Map<String, Object> returnData = new HashMap<>();
         //在获取设备的要素
         List<KwsDeviceReference> references = deviceReferenceMapper.selectList(new LambdaQueryWrapper<KwsDeviceReference>()
@@ -139,10 +141,16 @@ public class BackTrackService {
             if(!parts.isEmpty() && !parts.contains(element.getItem())){
                 continue;
             }
-            BigDecimal currentValue = element.getCurrentValue();//当前要素的基准值
+            BigDecimal currentValue =  new BigDecimal("0.00");
+            if(original == 1){
+                currentValue = element.getOriginalValue();//以原始基准参考
+            }else{
+                currentValue = element.getCurrentValue();//以当前基准参考
+            }
+
 
             BigDecimal offsetValue = new BigDecimal("0.00");
-            Map<String, Object> datemap = new HashMap<>();
+            List<Object> datemap = new ArrayList<>();
             Date date = new Date();
             List<SlopeData> selected = slopeDataMapper.selectLineList(snCode, element.getItem(), dateStart, dateEnd);
             if(!Objects.isNull((selected))) {
@@ -163,7 +171,10 @@ public class BackTrackService {
                     }else{//如果是其他
                         offsetValue = subtract;
                     }
-                    datemap.put(key, offsetValue);
+                    Map<String, Object> temp = new HashMap<>();
+                    temp.put("time",key);
+                    temp.put("offset",offsetValue);
+                    datemap.add(temp);
                 }
                 mapList.put(element.getItem(), datemap);
             }
@@ -222,7 +233,7 @@ public class BackTrackService {
     }
 
     /**
-     * 新增设备
+     * 新增集成元素
      *
      * @param vo 请求参数
      * @param request   http流
@@ -253,6 +264,52 @@ public class BackTrackService {
         integration.setDelFlag(zero);
         integration.setMountainId(headerData.getCompanyId());
         integrationMapper.insert(integration);
+        Map<String, Object> logMap = new HashMap<>(NumberConstant.SIXTEEN);
+        logMap.put("name", integration.getIntegrationName());
+        logMap.put("type", IntegrationStatusEnum.getDestination(Byte.toUnsignedInt(integration.getStatus())));
+        commonService.insertLog(MessageLogEnum.INTEGRATION_ADD, headerData, logMap, headerData.getUpdateBy() == null ? null : Long.parseLong(headerData.getUpdateBy()));
+        return HttpResult.ok();
+    }
+
+    /**
+     * 修改集成分析
+     *
+     * @param vo 请求参数
+     * @param request   http流
+     * @return 返回值
+     */
+    @Transactional
+    public HttpResult integrationUpdate(IntegrationVo vo, HttpServletRequest request) {
+        KwsIntegration has = integrationMapper.selectOne(new LambdaQueryWrapper<KwsIntegration>()
+                .eq(KwsIntegration::getId, vo.getId())
+                .eq(KwsIntegration::getDelFlag, 0)
+        );
+        if (Objects.isNull(has)) {
+            throw new SystemException(HttpStatus.QUERY_FAIL_CODE, HttpStatus.INTEGRATION_NOT_EXISTS);
+        }
+        HeaderData headerData = commonService.getHeaderData(request);
+        KwsIntegration integration = new KwsIntegration();
+        BeanUtils.copyProperties(vo, integration);
+        Date now = new Date();
+        integration.setUpdateBy(Long.parseLong(headerData.getUpdateBy()));
+        integration.setUpdateTime(now);
+        integrationMapper.updateById(integration);
+        Map<String, Object> logMap = new HashMap<>(NumberConstant.SIXTEEN);
+        logMap.put("name", integration.getIntegrationName());
+        logMap.put("type", IntegrationStatusEnum.getDestination(Byte.toUnsignedInt(integration.getStatus())));
+        commonService.insertLog(MessageLogEnum.INTEGRATION_ADD, headerData, logMap, headerData.getUpdateBy() == null ? null : Long.parseLong(headerData.getUpdateBy()));
         return HttpResult.ok();
     }
+
+    public HttpResult getPartsByDeviceId(String deviceId) {
+        //在获取设备的要素
+        String[] arr = deviceId.split(",");
+        List<String> list = Arrays.asList(arr);
+        List<KwsDeviceReference> references = deviceReferenceMapper.selectList(new LambdaQueryWrapper<KwsDeviceReference>()
+                .in(KwsDeviceReference::getDeviceId, list)
+                .eq(KwsDeviceReference::getDelFlag, NumberConstant.ZERO)
+        );
+
+        return HttpResult.ok(references);
+    }
 }

+ 30 - 3
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/DeviceModelService.java

@@ -6,11 +6,15 @@ 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.exception.SystemException;
 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.IntegrationStatusEnum;
+import com.sckw.core.model.enums.MessageLogEnum;
 import com.sckw.core.model.page.PageRes;
 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.KwsDeviceModelMapper;
 import com.sckw.slope.detection.dao.mysql.KwsDeviceModelPartMapper;
@@ -99,6 +103,10 @@ public class DeviceModelService {
         deviceModel.setDelFlag(NumberConstant.ZERO);
         deviceModel.setMountainId(headerData.getCompanyId());
         kwsDeviceModelMapper.insert(deviceModel);
+        //新增log
+        Map<String, Object> logMap = new HashMap<>(NumberConstant.SIXTEEN);
+        logMap.put("name", deviceModel.getName());
+        commonService.insertLog(MessageLogEnum.MODEL_ADD, headerData, logMap, Long.parseLong(headerData.getUpdateBy()));
         return HttpResult.ok();
     }
 
@@ -157,18 +165,37 @@ public class DeviceModelService {
         device.setUpdateBy(Long.parseLong(commonService.getHeaderData(response).getUpdateBy()));
         device.setUpdateTime(now);
         kwsDeviceModelMapper.updateById(device);
+
+        //新增log
+        HeaderData headerData = commonService.getHeaderData(response);
+        Map<String, Object> logMap = new HashMap<>(NumberConstant.SIXTEEN);
+        logMap.put("name", device.getName());
+        commonService.insertLog(MessageLogEnum.MODEL_UPDATE, headerData, logMap, Long.parseLong(headerData.getUpdateBy()));
         return HttpResult.ok();
     }
 
     @Transactional
-    public HttpResult dels(String ids) {
-        List<Long> list = StringUtils.splitStrToList(ids, Long.class);
+    public HttpResult dels(String ids, HttpServletRequest response) {
+        KwsDeviceModel has = kwsDeviceModelMapper.selectOne(new LambdaQueryWrapper<KwsDeviceModel>()
+                .eq(KwsDeviceModel::getId, ids)
+                .eq(KwsDeviceModel::getDelFlag, 0)
+        );
+        if (Objects.isNull(has)) {
+            throw new SystemException(HttpStatus.QUERY_FAIL_CODE, HttpStatus.MODEL_NOT_EXISTS);
+        }
+
+        //List<Long> list = StringUtils.splitStrToList(ids, Long.class);
         int update = kwsDeviceModelMapper.update(null, new LambdaUpdateWrapper<KwsDeviceModel>()
-                .in(KwsDeviceModel::getId, list)
+                .eq(KwsDeviceModel::getId, ids)
                 .set(KwsDeviceModel::getDelFlag, NumberConstant.ONE));
         if (update < 1) {
             throw new BusinessException("删除型号异常");
         }
+        //新增log
+        HeaderData headerData = commonService.getHeaderData(response);
+        Map<String, Object> logMap = new HashMap<>(NumberConstant.SIXTEEN);
+        logMap.put("name", has.getName());
+        commonService.insertLog(MessageLogEnum.MODEL_DELETE, headerData, logMap, Long.parseLong(headerData.getUpdateBy()));
         return HttpResult.ok("删除型号成功");
     }
 }

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

@@ -96,14 +96,27 @@ public class DeviceService {
 
 
     @Transactional
-    public HttpResult dels(String ids) {
-        List<Long> list = StringUtils.splitStrToList(ids, Long.class);
+    public HttpResult dels(String ids, HttpServletRequest response) {
+        KwsDevice device = deviceMapper.selectOne(new LambdaQueryWrapper<KwsDevice>()
+                .eq(KwsDevice::getId, ids));
+        if(Objects.isNull(device)){
+            throw new SystemException(HttpStatus.QUERY_FAIL_CODE, HttpStatus.DEVICE_NOT_EXISTS);
+        }
+        //List<Long> list = StringUtils.splitStrToList(ids, Long.class);
         int update = deviceMapper.update(null, new LambdaUpdateWrapper<KwsDevice>()
-                .in(KwsDevice::getId, list)
+                .in(KwsDevice::getId, ids)
                 .set(KwsDevice::getDelFlag, NumberConstant.ONE));
         if (update < 1) {
             throw new BusinessException("删除设备异常");
         }
+        //获取新增设备的型号
+        HeaderData headerData = commonService.getHeaderData(response);
+        KwsDeviceModel model = deviceModelMapper.selectOne(new LambdaQueryWrapper<KwsDeviceModel>()
+                .eq(KwsDeviceModel::getId, device.getModelId()));
+        Map<String, Object> logMap = new HashMap<>(NumberConstant.SIXTEEN);
+        logMap.put("name", device.getName());
+        logMap.put("type", model.getName());
+        commonService.insertLog(MessageLogEnum.DEVICE_DELETE, headerData, logMap, Long.parseLong(headerData.getUpdateBy()));
         return HttpResult.ok("删除设备成功");
     }
 
@@ -136,7 +149,7 @@ public class DeviceService {
             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 (map.get("device_id").toString().equals(vo.getId().toString())) {
                         vo.setDataErrorCount(map.get("count"));
                         vo.setDeviceErrorCount(map.get("count"));
                     }
@@ -194,6 +207,15 @@ public class DeviceService {
             deIntergration.setUpdateTime(now);
             deviceIntegrationMapper.insert(deIntergration);
         }
+
+        //新增log
+        //获取新增设备的型号
+        KwsDeviceModel model = deviceModelMapper.selectOne(new LambdaQueryWrapper<KwsDeviceModel>()
+                .eq(KwsDeviceModel::getId, device.getModelId()));
+        Map<String, Object> logMap = new HashMap<>(NumberConstant.SIXTEEN);
+        logMap.put("name", device.getName());
+        logMap.put("type", model.getName());
+        commonService.insertLog(MessageLogEnum.DEVICE_ADD, headerData, logMap, Long.parseLong(headerData.getUpdateBy()));
         return HttpResult.ok();
     }
 
@@ -268,49 +290,7 @@ public class DeviceService {
 
 
 
-        //vo.setReference(references);
-        //获取td里面的要数数据
-        /*List<Map<String, DeviceOutputValueVO>> mapList = new ArrayList<>();
-        if (!CollectionUtils.isEmpty(references)) {
-            vo.setReference(references);
-            references.forEach(re -> {
-                String snCode = device.getSnCode();
-                String item = re.getItem();
-                Date date = new Date();
-                BigDecimal decimal = new BigDecimal("0.00");
-                String dateStart = DateUtil.getLastWeekDateEndToString(6);
-                String dateEnd = LocalDateTime.now().toString();
-                List<SlopeData> selected = slopeDataMapper.selectLineList(snCode, item, dateStart,dateEnd);
-                List<Map<String, Object>> mapListXy = 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);
-                        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM-dd HH:mm:ss");
-                        String key = simpleDateFormat.format(currSlopeData.getTs());
-                        SlopeData lastSlopeData = selected.get(i + 1);
-                        Date localDateTime = currSlopeData.getTs();
-                        long epochMilli1 = 0L;
-                        String val2 = "0";
-                        Date localDateTime1 = lastSlopeData.getTs();
-                        if (lastSlopeData != null) {
-                            epochMilli1 = localDateTime1.getTime();
-                            val2 = lastSlopeData.getVal();
-                        }
-                        long epochMilli = localDateTime.getTime();
-                        epochMilli1 = localDateTime1.getTime();
-                        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))), 9, BigDecimal.ROUND_HALF_UP);
-                        map.put(key, decimal);
-                        mapListXy.add(map);
-                    }
-                }
-                vo.setMonitor(mapListXy);
-            });
 
-        }*/
         return HttpResult.ok(vo);
     }
 
@@ -380,28 +360,39 @@ public class DeviceService {
                     .set(KwsDeviceIntegration::getDelFlag, NumberConstant.ONE)
                     .set(KwsDeviceIntegration::getUpdateBy,Long.parseLong(headerData.getUpdateBy()) )
                     .set(KwsDeviceIntegration::getUpdateTime, now));
-            if (update < 1) {
-                throw new BusinessException("删除设备集成要素异常");
-            }
+            //if (update < 1) {
+                //throw new BusinessException("删除设备集成要素异常");
+            //}
 
             //新增到数据表kws_device_Integration
             KwsDeviceIntegration deIntergration = new KwsDeviceIntegration();
             String[] temp;//接收分割后的数组
-            temp = deviceAdd.getIntegrationId().split(Global.COMMA);
-
-            for (int i = 0; i < temp.length; i++) {
-                long interId = new IdWorker(NumberConstant.ONE).nextId();
-                deIntergration.setId(interId);
-                deIntergration.setDeviceId(Long.parseLong(deviceAdd.getId()));
-                deIntergration.setMountainId(headerData.getCompanyId());
-                deIntergration.setIntegrationId(Long.parseLong(temp[i]));
-                deIntergration.setCreateBy(Long.parseLong(headerData.getCreateBy()));
-                deIntergration.setCreateTime(now);
-                deIntergration.setStatus(NumberConstant.ZERO);
-                deIntergration.setUpdateBy(Long.parseLong(headerData.getUpdateBy()));
-                deIntergration.setUpdateTime(now);
-                deviceIntegrationMapper.insert(deIntergration);
+            if(!deviceAdd.getIntegrationId().isEmpty()){
+                temp = deviceAdd.getIntegrationId().split(Global.COMMA);
+
+                for (int i = 0; i < temp.length; i++) {
+                    long interId = new IdWorker(NumberConstant.ONE).nextId();
+                    deIntergration.setId(interId);
+                    deIntergration.setDeviceId(Long.parseLong(deviceAdd.getId()));
+                    deIntergration.setMountainId(headerData.getCompanyId());
+                    deIntergration.setIntegrationId(Long.parseLong(temp[i]));
+                    deIntergration.setCreateBy(Long.parseLong(headerData.getCreateBy()));
+                    deIntergration.setCreateTime(now);
+                    deIntergration.setStatus(NumberConstant.ZERO);
+                    deIntergration.setUpdateBy(Long.parseLong(headerData.getUpdateBy()));
+                    deIntergration.setUpdateTime(now);
+                    deviceIntegrationMapper.insert(deIntergration);
+                }
             }
+
+            //新增log
+            //获取新增设备的型号
+            KwsDeviceModel model = deviceModelMapper.selectOne(new LambdaQueryWrapper<KwsDeviceModel>()
+                    .eq(KwsDeviceModel::getId, device.getModelId()));
+            Map<String, Object> logMap = new HashMap<>(NumberConstant.SIXTEEN);
+            logMap.put("name", device.getName());
+            logMap.put("type", model.getName());
+            commonService.insertLog(MessageLogEnum.DEVICE_UPDATE, headerData, logMap, Long.parseLong(headerData.getUpdateBy()));
             return HttpResult.ok();
         }
 
@@ -633,7 +624,7 @@ public class DeviceService {
                 BigDecimal offset = value.subtract(reference.getValue());
                 kwsDeviceReference.setOffset(offset);
                 kwsDeviceReference.setCurrentValue(reference.getValue());
-                kwsDeviceReference.setOriginalValue(value);
+                kwsDeviceReference.setOriginalValue(reference.getOriginalValue());
             }
             kwsDeviceReference.setId(interId);
             kwsDeviceReference.setDeviceId(deviceId);

+ 0 - 64
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/Task/ReportTemplateTaskService.java

@@ -1,64 +0,0 @@
-package com.sckw.slope.detection.service.task;
-
-import cn.hutool.core.date.DateUtil;
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.sckw.core.model.enums.ReportTypeEnum;
-import com.sckw.core.utils.StringUtils;
-import com.sckw.slope.detection.dao.mysql.KwsReportTemplateMapper;
-import com.sckw.slope.detection.model.dos.mysql.KwsReportTemplate;
-import jakarta.annotation.Resource;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.scheduling.annotation.EnableScheduling;
-import org.springframework.stereotype.Component;
-import org.springframework.util.CollectionUtils;
-
-import java.time.LocalDateTime;
-import java.util.List;
-
-/**
- * @author lfdc
- * @description 报表任务
- * @date 2023-11-10 11:11:25
- */
-
-@Slf4j
-@Component
-@EnableScheduling
-public class ReportTemplateTaskService {
-
-    @Resource
-    KwsReportTemplateMapper reportTemplateMapper;
-
-    /**
-     * 报表生成定时任务
-     */
-    //    @Scheduled(cron = "0 0 0 ? * *")
-    public void templateTask() {
-        List<KwsReportTemplate> kwsReportTemplates = reportTemplateMapper.selectList(new LambdaQueryWrapper<KwsReportTemplate>()
-                .eq(KwsReportTemplate::getStatus, 0)
-                .eq(KwsReportTemplate::getDelFlag, 0));
-        if (!CollectionUtils.isEmpty(kwsReportTemplates)) {
-            for (KwsReportTemplate kwsReportTemplate : kwsReportTemplates) {
-                Integer type = kwsReportTemplate.getType();
-                if (ReportTypeEnum.DAY.getCode() == type) {
-                    LocalDateTime localDateTime = LocalDateTime.now().minusDays(1);
-                    LocalDateTime dateEnd = com.sckw.excel.utils.DateUtil.localDateToLocalDateTimeEnd(localDateTime.toLocalDate());
-                    LocalDateTime dateStart = com.sckw.excel.utils.DateUtil.localDateToLocalDateTimeStart(localDateTime.toLocalDate());
-                    String partNames = kwsReportTemplate.getPartNames();
-                    String intergrationNames = kwsReportTemplate.getIntergrationNames();
-                    List<String> stringList = StringUtils.splitStrToList(partNames, String.class);
-
-                }
-                if (ReportTypeEnum.WEEK.getCode() == type) {
-                    if (2 != DateUtil.thisDayOfWeekEnum().getValue()) {
-                        continue;
-                    }
-                }
-                if (ReportTypeEnum.MONTH.getCode() == type) {
-
-                }
-            }
-        }
-
-    }
-}

+ 82 - 67
slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsAlarmMapper.xml

@@ -40,16 +40,16 @@
 
     <select id="selectByDevicesId" parameterType="java.lang.String" resultType="java.util.Map">
         <!--@mbg.generated-->
-        select count(id) as count,pid,type
+        select count(id) as count,device_id,type
         from kws_alarm
         where 1 = 1
         <if test="devicesId != null and devicesId.size() > 0">
-            AND pid IN
+            AND device_id IN
             <foreach collection="devicesId" open="(" close=")" item="item" separator=",">
                 #{item}
             </foreach>
         </if>
-        group by pid, type
+        group by device_id, type
     </select>
 
     <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
@@ -191,39 +191,39 @@
         <!--@mbg.generated-->
         update kws_alarm
         set pid           = #{pid,jdbcType=BIGINT},
-            title         = #{title,jdbcType=VARCHAR},
-            val           = #{val,jdbcType=VARCHAR},
-            content       = #{content,jdbcType=VARCHAR},
-            `level`       = #{level,jdbcType=INTEGER},
-            `type`        = #{type,jdbcType=INTEGER},
-            lat           = #{lat,jdbcType=VARCHAR},
-            lng           = #{lng,jdbcType=VARCHAR},
-            alt           = #{alt,jdbcType=VARCHAR},
-            create_time   = #{createTime,jdbcType=TIMESTAMP},
-            trigger_times = #{triggerTimes,jdbcType=INTEGER},
-            `status`      = #{status,jdbcType=TINYINT}
+        title         = #{title,jdbcType=VARCHAR},
+        val           = #{val,jdbcType=VARCHAR},
+        content       = #{content,jdbcType=VARCHAR},
+        `level`       = #{level,jdbcType=INTEGER},
+        `type`        = #{type,jdbcType=INTEGER},
+        lat           = #{lat,jdbcType=VARCHAR},
+        lng           = #{lng,jdbcType=VARCHAR},
+        alt           = #{alt,jdbcType=VARCHAR},
+        create_time   = #{createTime,jdbcType=TIMESTAMP},
+        trigger_times = #{triggerTimes,jdbcType=INTEGER},
+        `status`      = #{status,jdbcType=TINYINT}
         where id = #{id,jdbcType=BIGINT}
     </update>
 
     <select id="getDataAlarmToDay" resultType="java.util.Map">
         SELECT DATE_FORMAT(h.h, '%Y-%m-%d %H:00:00') AS dateTime, COUNT(t.id) AS number
         FROM (SELECT #{startTime} + INTERVAL n HOUR AS h
-              FROM (
-                  SELECT 0 AS n
-                  UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5
-                  UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL SELECT 10
-                  UNION ALL SELECT 11 UNION ALL SELECT 12 UNION ALL SELECT 13 UNION ALL SELECT 14 UNION ALL SELECT 15
-                  UNION ALL SELECT 16 UNION ALL SELECT 17 UNION ALL SELECT 18 UNION ALL SELECT 19 UNION ALL SELECT 20
-                  UNION ALL SELECT 21 UNION ALL SELECT 22 UNION ALL SELECT 23
-                  ) hours) h
-            LEFT JOIN
+        FROM (
+        SELECT 0 AS n
+        UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5
+        UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL SELECT 10
+        UNION ALL SELECT 11 UNION ALL SELECT 12 UNION ALL SELECT 13 UNION ALL SELECT 14 UNION ALL SELECT 15
+        UNION ALL SELECT 16 UNION ALL SELECT 17 UNION ALL SELECT 18 UNION ALL SELECT 19 UNION ALL SELECT 20
+        UNION ALL SELECT 21 UNION ALL SELECT 22 UNION ALL SELECT 23
+        ) hours) h
+        LEFT JOIN
         (SELECT a.id,
-                a.create_time,
-                b.project_id  as projectId,
-                b.company_id  as companyId,
-                b.mountain_id as mountainId
-         FROM kws_alarm_detail a
-                  LEFT JOIN kws_alarm b ON a.alarm_id = b.id
+        a.create_time,
+        b.project_id  as projectId,
+        b.company_id  as companyId,
+        b.mountain_id as mountainId
+        FROM kws_alarm_detail a
+        LEFT JOIN kws_alarm b ON a.alarm_id = b.id
         <where>
             <if test="type != null and type != ''">
                 and b.type =#{type}
@@ -238,7 +238,7 @@
         ) t
         ON DATE_FORMAT(t.create_time, '%Y-%m-%d %H') = DATE_FORMAT(h.h, '%Y-%m-%d %H')
         WHERE h.h BETWEEN #{startTime}
-                  AND #{endTime}
+        AND #{endTime}
         GROUP BY dateTime
         ORDER BY dateTime ASC;
     </select>
@@ -246,27 +246,27 @@
     <select id="getDataAlarmToWeek" resultType="java.util.Map">
         SELECT a.date as dateTime, COALESCE(b.number, 0) as number
         from (select date_add(#{startTime}, interval row1 DAY) date
-              from
-                  (
-                  SELECT @row := @row + 1 as row1 FROM
-                  (select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union
-                  all select 6 union all select 7 union all select 8 union all select 9) t, (select 0 union all select 1 union all
-                  select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union
-                  all select 8 union all select 9) t2, (select 0 union all select 1 union all select 2 union all select 3 union
-                  all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) t3, (select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union
-                  all select 6 union all select 7 union all select 8 union all select 9) t4, (SELECT @row := -1) r
-                  ) se
-              where date_add(#{startTime}
-                  , interval row1 DAY) &lt;= #{endTime}) a
-            LEFT JOIN
+        from
+        (
+        SELECT @row := @row + 1 as row1 FROM
+        (select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union
+        all select 6 union all select 7 union all select 8 union all select 9) t, (select 0 union all select 1 union all
+        select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union
+        all select 8 union all select 9) t2, (select 0 union all select 1 union all select 2 union all select 3 union
+        all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) t3, (select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union
+        all select 6 union all select 7 union all select 8 union all select 9) t4, (SELECT @row := -1) r
+        ) se
+        where date_add(#{startTime}
+        , interval row1 DAY) &lt;= #{endTime}) a
+        LEFT JOIN
         (SELECT count(b.id)   as                       number,
-                DATE_FORMAT(b.create_time, '%Y-%m-%d') date_time,
-                a.project_id  as                       projectId,
-                a.company_id  as                       companyId,
-                a.mountain_id as                       mountainId
-         FROM kws_alarm a
-                  LEFT JOIN
-              kws_alarm_detail b on a.id = b.alarm_id
+        DATE_FORMAT(b.create_time, '%Y-%m-%d') date_time,
+        a.project_id  as                       projectId,
+        a.company_id  as                       companyId,
+        a.mountain_id as                       mountainId
+        FROM kws_alarm a
+        LEFT JOIN
+        kws_alarm_detail b on a.id = b.alarm_id
         <where>
             <if test="type != null and type != ''">
                 and a.type =#{type}
@@ -286,16 +286,16 @@
 
     <select id="getDataAlarmToYear" resultType="java.util.Map">
         SELECT a.dateTime            AS dateTime,
-               COALESCE(b.number, 0) AS num
+        COALESCE(b.number, 0) AS num
         FROM (SELECT DATE_FORMAT(DATE_ADD(#{startTime}, INTERVAL ROW1 MONTH ), '%Y-%m') dateTime
-              FROM (SELECT @ROW := @ROW + 1 AS row1
-                    FROM
-                        (select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) t, (select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) t2, (select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) t3, (select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) t4, ( SELECT @ROW := - 1 ) r) se
-              WHERE date_add(#{startTime}, INTERVAL row1 MONTH ) &lt;= #{endTime}) a
-            LEFT JOIN (SELECT count(b.id) AS                      number,
-                              DATE_FORMAT(b.create_time, '%Y-%m') dateTime
-                       FROM kws_alarm a
-                                LEFT JOIN kws_alarm_detail b ON a.id = b.alarm_id
+        FROM (SELECT @ROW := @ROW + 1 AS row1
+        FROM
+        (select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) t, (select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) t2, (select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) t3, (select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) t4, ( SELECT @ROW := - 1 ) r) se
+        WHERE date_add(#{startTime}, INTERVAL row1 MONTH ) &lt;= #{endTime}) a
+        LEFT JOIN (SELECT count(b.id) AS                      number,
+        DATE_FORMAT(b.create_time, '%Y-%m') dateTime
+        FROM kws_alarm a
+        LEFT JOIN kws_alarm_detail b ON a.id = b.alarm_id
         <where>
             <if test="type != null and type != ''">
                 and a.type =#{type}
@@ -315,15 +315,30 @@
 
     <select id="getProjectAlarmList" resultType="java.util.Map">
         SELECT
-            project_id as projectId,COUNT(DISTINCT a.id) as alarmTotal
+        project_id as projectId,COUNT(DISTINCT a.id) as alarmTotal
         FROM
-            kws_alarm a
-                LEFT JOIN kws_alarm_detail b ON a.id = b.alarm_id
-            <where>
-               <if test="type != null and type != ''">
-                   and a.type =#{type}
-               </if>
-            </where>
+        kws_alarm a
+        LEFT JOIN kws_alarm_detail b ON a.id = b.alarm_id
+        <where>
+            <if test="type != null and type != ''">
+                and a.type =#{type}
+            </if>
+        </where>
         GROUP BY a.project_id
     </select>
+
+    <select id="selectDetailList" resultType="com.sckw.slope.detection.model.vo.AlarmLogThresholdVO">
+        SELECT a.id          AS id,
+               b.project_id  AS projectId,
+               b.mountain_id AS mountainId,
+               b.title       AS title,
+               a.val         AS val,
+               b.`level`     AS LEVEL,
+               a.create_time AS createTime
+        FROM kws_alarm_detail a
+                 LEFT JOIN kws_alarm b ON a.alarm_id = b.id
+        WHERE a.mountain_id = b.mountain_id
+          and b.`status` = 0
+        ORDER BY a.create_time DESC
+    </select>
 </mapper>