Przeglądaj źródła

Merge branch 'dev' into sky_v2

15928045575 2 lat temu
rodzic
commit
b71223aec3
20 zmienionych plików z 494 dodań i 439 usunięć
  1. 6 0
      slope-common/slope-common-core/src/main/java/com/sckw/core/model/enums/MessageLogEnum.java
  2. 4 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/consumer/HandlerFactory.java
  3. 94 74
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/consumer/MqttCallbackHandler.java
  4. 3 3
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/consumer/MqttDeviceCallbackHandler.java
  5. 0 3
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/consumer/mqApi/MqttApiHandler.java
  6. 39 47
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/controller/CommonController.java
  7. 17 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/controller/ProjectController.java
  8. 0 20
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/dao/mysql/KwsAlarmDetailHistoryMapper.java
  9. 1 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dto/BindDevice.java
  10. 2 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dto/DeviceDeleteDTO.java
  11. 1 1
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dto/ThresholdConfigurationDTO.java
  12. 5 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dto/ThresholdSelectDTO.java
  13. 38 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/UpdateDeviceBindSelectVO.java
  14. 32 49
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/CommonService.java
  15. 0 3
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/KwsAlarmService.java
  16. 171 10
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/ProjectService.java
  17. 12 5
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/ThresholdService.java
  18. 1 1
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/api/DetectionApiService.java
  19. 68 22
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/task/DeviceAlarmTaskService.java
  20. 0 201
      slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsAlarmDetailHistoryMapper.xml

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

@@ -38,6 +38,12 @@ public enum MessageLogEnum {
      */
     ADD_NETWORKING_DEVICE("slope_manage", "PROJECT_LOG", "新增组网设备", "4",
             "设备【${deviceName}】已关联组网,所属边坡【${projectName}】", "新增组网设备"),
+
+    /**
+     * 修改组网设备
+     */
+    UPDATE_NETWORKING_DEVICE("slope_manage", "PROJECT_LOG", "修改组网设备", "28",
+            "设备【${deviceName}】已修改组网,所属边坡【${projectName}】", "修改组网设备"),
     /**
      * 删除组网设备
      */

+ 4 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/consumer/HandlerFactory.java

@@ -1,6 +1,8 @@
 package com.sckw.slope.detection.consumer;
 
+import com.alibaba.fastjson2.JSONObject;
 import com.sckw.core.exception.BusinessException;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -12,6 +14,7 @@ import java.util.Map;
  * @description
  * @date 2023-11-15 17:11:09
  */
+@Slf4j
 @Service
 public class HandlerFactory {
 
@@ -20,6 +23,7 @@ public class HandlerFactory {
 
     public AbstractHandler getHandler(String type) {
         AbstractHandler receiptHandler = handlerMap.get(type);
+        log.info("mqtt当前定义接收:{}", JSONObject.toJSONString(handlerMap));
         if (receiptHandler == null) {
             throw new BusinessException("mqtt单据类型错误,type=" + type);
         }

+ 94 - 74
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/consumer/MqttCallbackHandler.java

@@ -30,11 +30,11 @@ import com.sckw.slope.detection.model.vo.DeviceIntegrationVo;
 import com.sckw.slope.detection.service.CommonService;
 import com.sckw.slope.detection.service.TdengineService;
 import com.sckw.slope.detection.service.api.DetectionApiService;
+import com.sckw.slope.detection.service.repository.KwsAlarmInfoRepository;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.dubbo.common.utils.MD5Utils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -53,8 +53,6 @@ import java.util.stream.Collectors;
 @Service("system/iot/device_data_slope")
 public class MqttCallbackHandler extends AbstractHandler {
 
-    @Value("${sms.url}")
-    private String messageUrl;
 
     @Autowired
     CommonService commonService;
@@ -80,6 +78,9 @@ public class MqttCallbackHandler extends AbstractHandler {
     @Autowired
     KwsIntegrationMapper integrationMapper;
 
+    @Autowired
+    KwsAlarmInfoRepository alarmInfoRepository;
+
     @Autowired
     SmsTemplateConfig smsTemplateConfig;
 
@@ -159,39 +160,35 @@ public class MqttCallbackHandler extends AbstractHandler {
 //                        redisPutAlarmCount(id);
                         /*【露天矿山边坡监测系统】尊敬的管理员,2023-10-01 12:23:34监测到一级告警。
                             设备名称:位移监测设备-gnss一号机,监测数值:55。123456789N,请尽快处理问题。*/
-                        Map<String, Object> messageMap = new HashMap<>();
-                        Long deviceId = device.getId();
-                        KwsProjectDevice projectDevice = projectDeviceMapper.selectOne(new LambdaQueryWrapper<KwsProjectDevice>()
-                                .eq(KwsProjectDevice::getDeviceId, deviceId)
-                                .eq(KwsProjectDevice::getDelFlag, 0)
-                                .eq(KwsProjectDevice::getStatus, 0)
-                                .orderByDesc(KwsProjectDevice::getCreateTime)
-                                .last(" limit 1")
+                        String mountainId = device.getMountainId();
+                        List<KwsAlarmInfo> list = alarmInfoRepository.list(new LambdaQueryWrapper<KwsAlarmInfo>()
+                                .eq(KwsAlarmInfo::getMountainId, mountainId)
+                                .eq(KwsAlarmInfo::getLevel, level.intValue())
+                                .eq(KwsAlarmInfo::getType, NumberConstant.ONE)
+                                .eq(KwsAlarmInfo::getDelFlag, NumberConstant.ZERO)
                         );
-                        LambdaQueryWrapper<KwsAlarm> wrapper = new LambdaQueryWrapper<KwsAlarm>()
-                                .eq(KwsAlarm::getLevel, level.intValue())
-                                .eq(KwsAlarm::getDeviceId, deviceId)
-                                .eq(KwsAlarm::getType, NumberConstant.ONE)
-                                .orderByDesc(KwsAlarm::getCreateTime);
-                        if (projectDevice != null) {
-                            wrapper.eq(KwsAlarm::getProjectId, projectDevice.getProjectId())
-                                    .eq(KwsAlarm::getMountainId, projectDevice.getMountainId());
-                            if (projectDevice.getProjectId() != null) {
-                                wrapper.eq(KwsAlarm::getCompanyId, projectDevice.getCompanyId());
+                        List<String> pushToPhone = new ArrayList<>();
+                        if (!CollectionUtils.isEmpty(list)) {
+                            pushToPhone = list.stream().map(KwsAlarmInfo::getValueDesc).distinct().collect(Collectors.toList());
+                        }
+                        if (!CollectionUtils.isEmpty(pushToPhone)) {
+//                        KwsThreshold kwsThreshold = thresholdMapper.selectById(thresholdId);
+//                        String phones = kwsThreshold.getPhones();
+//                        List<String> pushToPhone = com.sckw.core.utils.StringUtils.splitStrToList(phones, String.class);
+                            Map<String, String> templateParam = new HashMap<>();
+                            if (StringUtils.isBlank(time)) {
+                                LocalDateTime localDateTime = Instant.ofEpochSecond(ts).atZone(ZoneId.systemDefault()).toLocalDateTime();
+                                time = com.sckw.excel.utils.DateUtil.format(localDateTime);
                             }
+                            templateParam.put("time", time);
+                            templateParam.put("level", level.toString());
+                            templateParam.put("name", device.getName());
+                            templateParam.put("value", itemValue);
+                            commonService.pushSmsMessage(pushToPhone
+                                    , smsTemplateConfig.getDataAlarm().getSmsCode()
+                                    , smsTemplateConfig.getDataAlarm().getSignName()
+                                    , templateParam);
                         }
-                        KwsThreshold kwsThreshold = thresholdMapper.selectById(thresholdId);
-                        String phones = kwsThreshold.getPhones();
-                        List<String> pushToPhone = com.sckw.core.utils.StringUtils.splitStrToList(phones, String.class);
-                        Map<String, String> templateParam = new HashMap<>();
-                        templateParam.put("time", time);
-                        templateParam.put("level", level.toString());
-                        templateParam.put("name", device.getName());
-                        templateParam.put("value", itemValue);
-                        commonService.pushSmsMessage(pushToPhone
-                                , smsTemplateConfig.getDataAlarm().getSmsCode()
-                                , smsTemplateConfig.getDataAlarm().getSignName()
-                                , templateParam);
                     }
                     //集成要素阈值告警
                     deviceIntegrationsAlarm(device, ts);
@@ -219,15 +216,15 @@ public class MqttCallbackHandler extends AbstractHandler {
     }
 
     private void deviceIntegrationsAlarm(KwsDevice device, Long ts) {
-        List<KwsDeviceIntegration> deviceIntegrations = deviceIntegrationMapper.selectList(
-                new LambdaQueryWrapper<KwsDeviceIntegration>()
-                        .eq(KwsDeviceIntegration::getDeviceId, device.getId())
-                        .eq(KwsDeviceIntegration::getDelFlag, 0)
-        );
-        List<Long> integrationIds = null;
-        if (!org.springframework.util.CollectionUtils.isEmpty(deviceIntegrations)) {
-            integrationIds = deviceIntegrations.stream().map(KwsDeviceIntegration::getIntegrationId).collect(Collectors.toList());
-        }
+//        List<KwsDeviceIntegration> deviceIntegrations = deviceIntegrationMapper.selectList(
+//                new LambdaQueryWrapper<KwsDeviceIntegration>()
+//                        .eq(KwsDeviceIntegration::getDeviceId, device.getId())
+//                        .eq(KwsDeviceIntegration::getDelFlag, 0)
+//        );
+//        List<Long> integrationIds = null;
+//        if (!org.springframework.util.CollectionUtils.isEmpty(deviceIntegrations)) {
+//            integrationIds = deviceIntegrations.stream().map(KwsDeviceIntegration::getIntegrationId).collect(Collectors.toList());
+//        }
 //        List<KwsIntegration> integrations = integrationMapper.selectList(
 //                new LambdaQueryWrapper<KwsIntegration>()
 //                        .in(KwsIntegration::getId, integrationIds)
@@ -259,47 +256,70 @@ public class MqttCallbackHandler extends AbstractHandler {
                         String url = deviceIntegration.getUnit() == null ? null : deviceIntegration.getUnit();
                         String itemValueAndUnit = StringUtils.isBlank(url) ? String.valueOf(offset) : (offset + deviceIntegration.getUnit());
                         long id = insertAlarmAndDetail(level, device, thresholdId, itemValueAndUnit, ts, AlarmTitleEnum.ALARM_TITLE_TWO.getStatus(), AlarmTypeEnum.ALARM_ONE.getCode());
-                        Map<String, Object> messageMap = new HashMap<>();
-                        Long deviceId = device.getId();
-                        KwsProjectDevice projectDevice = projectDeviceMapper.selectOne(new LambdaQueryWrapper<KwsProjectDevice>()
-                                .eq(KwsProjectDevice::getDeviceId, deviceId)
-                                .eq(KwsProjectDevice::getDelFlag, 0)
-                                .eq(KwsProjectDevice::getStatus, 0)
-                                .orderByDesc(KwsProjectDevice::getCreateTime)
-                                .last(" limit 1")
+                        /**最初发送短信模式*/
+//                        oldPushSms(device,level,thresholdId);
+                        /**目前发送短信模式*/
+                        String mountainId = device.getMountainId();
+                        List<KwsAlarmInfo> list = alarmInfoRepository.list(new LambdaQueryWrapper<KwsAlarmInfo>()
+                                .eq(KwsAlarmInfo::getMountainId, mountainId)
+                                .eq(KwsAlarmInfo::getLevel, level.intValue())
+                                .eq(KwsAlarmInfo::getType, NumberConstant.ONE)
+                                .eq(KwsAlarmInfo::getDelFlag, NumberConstant.ZERO)
                         );
-                        LambdaQueryWrapper<KwsAlarm> wrapper = new LambdaQueryWrapper<KwsAlarm>()
-                                .eq(KwsAlarm::getLevel, level.intValue())
-                                .eq(KwsAlarm::getDeviceId, deviceId)
-                                .eq(KwsAlarm::getType, NumberConstant.ONE)
-                                .orderByDesc(KwsAlarm::getCreateTime);
-                        if (projectDevice != null) {
-                            wrapper.eq(KwsAlarm::getProjectId, projectDevice.getProjectId())
-                                    .eq(KwsAlarm::getMountainId, projectDevice.getMountainId());
-                            if (projectDevice.getProjectId() != null) {
-                                wrapper.eq(KwsAlarm::getCompanyId, projectDevice.getCompanyId());
+                        List<String> pushToPhone = new ArrayList<>();
+                        if (!CollectionUtils.isEmpty(list)) {
+                            pushToPhone = list.stream().map(KwsAlarmInfo::getValueDesc).distinct().collect(Collectors.toList());
+                        }
+                        if (!CollectionUtils.isEmpty(pushToPhone)) {
+                            LocalDateTime localDateTime = Instant.ofEpochSecond(ts).atZone(ZoneId.systemDefault()).toLocalDateTime();
+                            String time = DateUtil.format(localDateTime, "yyyy-MM-dd HH:mm:ss");
+                            Map<String, String> templateParam = new HashMap<>();
+                            if (StringUtils.isBlank(time)) {
+                                LocalDateTime localDateTimes = Instant.ofEpochSecond(ts).atZone(ZoneId.systemDefault()).toLocalDateTime();
+                                time = com.sckw.excel.utils.DateUtil.format(localDateTimes);
                             }
+                            templateParam.put("time", time);
+                            templateParam.put("level", level.toString());
+                            templateParam.put("name", device.getName());
+                            templateParam.put("value", itemValueAndUnit);
+                            commonService.pushSmsMessage(pushToPhone
+                                    , smsTemplateConfig.getDataAlarm().getSmsCode()
+                                    , smsTemplateConfig.getDataAlarm().getSignName()
+                                    , templateParam);
                         }
-                        KwsThreshold kwsThreshold = thresholdMapper.selectById(thresholdId);
-                        String phones = kwsThreshold.getPhones();
-                        List<String> pushToPhone = com.sckw.core.utils.StringUtils.splitStrToList(phones, String.class);
-                        LocalDateTime localDateTime = Instant.ofEpochSecond(ts).atZone(ZoneId.systemDefault()).toLocalDateTime();
-                        String time = DateUtil.format(localDateTime, "yyyy-MM-dd HH:mm:ss");
-                        Map<String, String> templateParam = new HashMap<>();
-                        templateParam.put("time", time);
-                        templateParam.put("level", level.toString());
-                        templateParam.put("name", device.getName());
-                        templateParam.put("value", itemValueAndUnit);
-                        commonService.pushSmsMessage(pushToPhone
-                                , smsTemplateConfig.getDataAlarm().getSmsCode()
-                                , smsTemplateConfig.getDataAlarm().getSignName()
-                                , templateParam);
                     }
                 }
             }
         }
     }
 
+    private void oldPushSms(KwsDevice device, Long level, Long thresholdId) {
+        Map<String, Object> messageMap = new HashMap<>();
+        Long deviceId = device.getId();
+        KwsProjectDevice projectDevice = projectDeviceMapper.selectOne(new LambdaQueryWrapper<KwsProjectDevice>()
+                .eq(KwsProjectDevice::getDeviceId, deviceId)
+                .eq(KwsProjectDevice::getDelFlag, 0)
+                .eq(KwsProjectDevice::getStatus, 0)
+                .orderByDesc(KwsProjectDevice::getCreateTime)
+                .last(" limit 1")
+        );
+        LambdaQueryWrapper<KwsAlarm> wrapper = new LambdaQueryWrapper<KwsAlarm>()
+                .eq(KwsAlarm::getLevel, level.intValue())
+                .eq(KwsAlarm::getDeviceId, deviceId)
+                .eq(KwsAlarm::getType, NumberConstant.ONE)
+                .orderByDesc(KwsAlarm::getCreateTime);
+        if (projectDevice != null) {
+            wrapper.eq(KwsAlarm::getProjectId, projectDevice.getProjectId())
+                    .eq(KwsAlarm::getMountainId, projectDevice.getMountainId());
+            if (projectDevice.getProjectId() != null) {
+                wrapper.eq(KwsAlarm::getCompanyId, projectDevice.getCompanyId());
+            }
+        }
+        KwsThreshold kwsThreshold = thresholdMapper.selectById(thresholdId);
+        String phones = kwsThreshold.getPhones();
+        List<String> pushToPhone = com.sckw.core.utils.StringUtils.splitStrToList(phones, String.class);
+    }
+
 
     private void checkDeviceAlarm(String deviceCode, KwsDevice device, String itemValue, Long ts) {
         try {

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

@@ -164,9 +164,9 @@ public class MqttDeviceCallbackHandler extends AbstractHandler {
                         templateParam.put("level",level.toString());
                         templateParam.put("name",device.getName());
                         templateParam.put("value",itemValue);
-                        commonService.pushSmsMessage(pushToPhone,
-                                smsTemplateConfig.getDataAlarm().getSmsCode(),
-                                smsTemplateConfig.getDataAlarm().getSignName(),templateParam);
+//                        commonService.pushSmsMessage(pushToPhone,
+//                                smsTemplateConfig.getDataAlarm().getSmsCode(),
+//                                smsTemplateConfig.getDataAlarm().getSignName(),templateParam);
                     }
 
                 }

+ 0 - 3
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/consumer/mqApi/MqttApiHandler.java

@@ -20,9 +20,6 @@ public class MqttApiHandler {
 
     @TraceLog(description = "mqtt消费")
     public HttpResult handle(String topic, String payload) {
-        System.out.println(topic);
-        // 根据topic分别进行消息处理。
-        System.out.println("MqttCallbackHandle:" + topic + "|" + payload);
         try {
             AbstractHandler handler = handlerFactory.getHandler(topic);
             return handler.handle(topic,payload);

+ 39 - 47
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/controller/CommonController.java

@@ -1,6 +1,5 @@
 package com.sckw.slope.detection.controller;
 
-import cn.hutool.core.date.DateUtil;
 import com.sckw.core.web.response.HttpResult;
 import com.sckw.slope.detection.common.config.SmsTemplateConfig;
 import com.sckw.slope.detection.model.vo.QueryDictTypePageReqVo;
@@ -12,13 +11,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
-import java.time.Instant;
-import java.time.LocalDateTime;
-import java.time.ZoneId;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
 /**
  * @author lfdc
  * @description 公共字典查询
@@ -39,43 +31,43 @@ public class CommonController {
 
     @Autowired
     SmsTemplateConfig  smsTemplateConfig;
-
-    @RequestMapping(value = "/pushSmsMessageByDataAlarm",method = RequestMethod.GET)
-    public HttpResult pushSmsMessageByDataAlarm(){
-
-        String phones = "18215677925,18215677925";
-        List<String> pushToPhone = com.sckw.core.utils.StringUtils.splitStrToList(phones, String.class);
-        Long ts=1700970600L;
-        LocalDateTime localDateTime = Instant.ofEpochSecond(ts).atZone(ZoneId.systemDefault()).toLocalDateTime();
-        String time = DateUtil.format(localDateTime, "yyyy-MM-dd HH:mm:ss");
-        Map<String, String> templateParam = new HashMap<>();
-        templateParam.put("time", time);
-        templateParam.put("level", "1");
-        templateParam.put("name", "device.getName()");
-        templateParam.put("value", "itemValueAndUnit");
-        commonService.pushSmsMessage(pushToPhone
-                , smsTemplateConfig.getDataAlarm().getSmsCode()
-                , smsTemplateConfig.getDataAlarm().getSignName()
-                , templateParam);
-        return  HttpResult.ok();
-    }
-
-    @RequestMapping(value = "/pushSmsMessageByDeviceAlarm",method = RequestMethod.GET)
-    public HttpResult pushSmsMessageByDeviceAlarm(){
-        String phones = "18215677925,18215677925";
-        List<String> pushToPhone = com.sckw.core.utils.StringUtils.splitStrToList(phones, String.class);
-        Long ts=1700970600L;
-        LocalDateTime localDateTime = Instant.ofEpochSecond(ts).atZone(ZoneId.systemDefault()).toLocalDateTime();
-        String time = DateUtil.format(localDateTime, "yyyy-MM-dd HH:mm:ss");
-        Map<String, String> templateParam = new HashMap<>();
-        templateParam.put("time", time);
-        templateParam.put("level", "1");
-        templateParam.put("name", "device.getName()");
-        templateParam.put("value", "itemValueAndUnit");
-        commonService.pushSmsMessage(pushToPhone
-                , smsTemplateConfig.getDeviceAlarm().getSmsCode()
-                , smsTemplateConfig.getDeviceAlarm().getSignName()
-                , templateParam);
-        return  HttpResult.ok();
-    }
+//
+//    @RequestMapping(value = "/pushSmsMessageByDataAlarm",method = RequestMethod.GET)
+//    public HttpResult pushSmsMessageByDataAlarm(){
+//
+//        String phones = "18215677925,18215677925";
+//        List<String> pushToPhone = com.sckw.core.utils.StringUtils.splitStrToList(phones, String.class);
+//        Long ts=1700970600L;
+//        LocalDateTime localDateTime = Instant.ofEpochSecond(ts).atZone(ZoneId.systemDefault()).toLocalDateTime();
+//        String time = DateUtil.format(localDateTime, "yyyy-MM-dd HH:mm:ss");
+//        Map<String, String> templateParam = new HashMap<>();
+//        templateParam.put("time", time);
+//        templateParam.put("level", "1");
+//        templateParam.put("name", "device.getName()");
+//        templateParam.put("value", "itemValueAndUnit");
+//        commonService.pushSmsMessage(pushToPhone
+//                , smsTemplateConfig.getDataAlarm().getSmsCode()
+//                , smsTemplateConfig.getDataAlarm().getSignName()
+//                , templateParam);
+//        return  HttpResult.ok();
+//    }
+//
+//    @RequestMapping(value = "/pushSmsMessageByDeviceAlarm",method = RequestMethod.GET)
+//    public HttpResult pushSmsMessageByDeviceAlarm(){
+//        String phones = "18215677925,18215677925";
+//        List<String> pushToPhone = com.sckw.core.utils.StringUtils.splitStrToList(phones, String.class);
+//        Long ts=1700970600L;
+//        LocalDateTime localDateTime = Instant.ofEpochSecond(ts).atZone(ZoneId.systemDefault()).toLocalDateTime();
+//        String time = DateUtil.format(localDateTime, "yyyy-MM-dd HH:mm:ss");
+//        Map<String, String> templateParam = new HashMap<>();
+//        templateParam.put("time", time);
+//        templateParam.put("level", "1");
+//        templateParam.put("name", "device.getName()");
+//        templateParam.put("value", "itemValueAndUnit");
+//        commonService.pushSmsMessage(pushToPhone
+//                , smsTemplateConfig.getDeviceAlarm().getSmsCode()
+//                , smsTemplateConfig.getDeviceAlarm().getSignName()
+//                , templateParam);
+//        return  HttpResult.ok();
+//    }
 }

+ 17 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/controller/ProjectController.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.log.TraceLog.TraceLog;
 import com.sckw.slope.detection.model.dto.BindDevice;
 import com.sckw.slope.detection.model.dto.DeviceDeleteDTO;
 import com.sckw.slope.detection.model.dto.ProjectAddDTO;
@@ -103,6 +104,22 @@ public class ProjectController {
         return projectService.deviceBind(bindDevice, request);
     }
 
+    @TraceLog(description = "修改组网设备-关联设备-查询")
+    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
+    @RequestMapping(name = "修改组网设备-关联设备-查询", value = "/updateDeviceBindSelect", method = RequestMethod.GET)
+    public HttpResult updateDeviceBindSelect(@RequestParam("id") @NotBlank(message = "关联id不能为空") String id, HttpServletRequest request) {
+        log.info("修改组网设备-关联设备-查询 updateDeviceBindSelect param:{}", id);
+        return projectService.updateDeviceBindSelect(id, request);
+    }
+
+    @TraceLog(description = "修改组网设备-关联设备")
+    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
+    @RequestMapping(name = "修改组网设备-关联设备", value = "/updateDeviceBind", method = RequestMethod.POST)
+    public HttpResult updateDeviceBind(@RequestBody @Valid BindDevice bindDevice, HttpServletRequest request) {
+        log.info("新增组网设备-关联设备 updateDeviceBind param:{}", JSONObject.toJSONString(bindDevice));
+        return projectService.updateDeviceBind(bindDevice, request);
+    }
+
     @Log(description = "项目设备查询")
     //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
     @RequestMapping(name = "项目设备查询", value = "/deviceFind", method = RequestMethod.POST)

+ 0 - 20
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/dao/mysql/KwsAlarmDetailHistoryMapper.java

@@ -1,20 +0,0 @@
-package com.sckw.slope.detection.dao.mysql;
-
-import com.baomidou.dynamic.datasource.annotation.DS;
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.sckw.slope.detection.model.dos.mysql.KwsAlarmDetailHistory;
-import org.apache.ibatis.annotations.Mapper;
-
-@Mapper
-@DS("mysql")
-public interface KwsAlarmDetailHistoryMapper extends BaseMapper<KwsAlarmDetailHistory> {
-    int deleteByPrimaryKey(Long id);
-
-    int insertSelective(KwsAlarmDetailHistory record);
-
-    KwsAlarmDetailHistory selectByPrimaryKey(Long id);
-
-    int updateByPrimaryKeySelective(KwsAlarmDetailHistory record);
-
-    int updateByPrimaryKey(KwsAlarmDetailHistory record);
-}

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

@@ -13,6 +13,7 @@ import java.io.Serializable;
 @Data
 public class BindDevice implements Serializable {
 
+    private String deviceRelationId;
     /**
      * 项目ID
      */

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

@@ -24,4 +24,6 @@ public class DeviceDeleteDTO {
 //    @NotBlank(message = "主设备id不能为空")
     private String parentId;
 
+    private String deviceParentId;
+
 }

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

@@ -28,7 +28,7 @@ public class ThresholdConfigurationDTO implements Serializable {
     private String deviceId;
     @NotBlank(message = "监测项不能为空")
     private String itemName;
-    @NotBlank(message = "联系电话不能为空")
+//    @NotBlank(message = "联系电话不能为空")
     private String phones;
     @NotNull
     private List<ThresholdBean> threshold;

+ 5 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dto/ThresholdSelectDTO.java

@@ -28,6 +28,11 @@ public class ThresholdSelectDTO implements Serializable {
      * 监测项(字典value)
      */
     private String itemName;
+
+    /**
+     * 监测项(字典value)
+     */
+    private int itemNameCount;
     /**
      * 设备设置基准总数
      */

+ 38 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/UpdateDeviceBindSelectVO.java

@@ -0,0 +1,38 @@
+package com.sckw.slope.detection.model.vo;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @author lfdc
+ * @description 修改设备组网查询返回vo
+ * @date 2023-12-05 11:12:58
+ */
+@Data
+public class UpdateDeviceBindSelectVO implements Serializable {
+    /**
+     * 主设备id
+     */
+    private Long deviceId;
+    /**
+     * 主设备名称
+     */
+    private String deviceName;  /**
+     * 主设备名称-别名
+     */
+    private String deviceNameAlias;
+    /**
+     * 子设备id
+     */
+    private Long relateDeviceId;
+    /**
+     * 子设备名称
+     */
+    private String relateDeviceName;
+    /**
+     * 子设备名称-别名
+     */
+    private String relateDeviceAlias;
+
+}

+ 32 - 49
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/CommonService.java

@@ -379,64 +379,47 @@ public class CommonService {
     }
 
 
+    @Autowired
+    SmsTemplateConfig smsTemplateConfig;
+
+    @Value("${sms.url}")
+    private String smsUrl;
+
     /**
-     * 发送短信
-     *
-     * @param messageUrl  消息地址
-     * @param device      设备
-     * @param level       等级
-     * @param thresholdId 阈值id
-     * @param messageMap  消息内容
+     * 推送sms短信
+     * @param pushToPhone 手机号
+     * @param templateCode  模板编码
+     * @param signName  签名
+     * @param templateParam 请求参数
      */
     @Async
-    public void pushDataAlarmSmsMessage(String messageUrl, KwsDevice device, Long level, Long thresholdId, Map<String, Object> messageMap) {
-        Long deviceId = device.getId();
-        KwsProjectDevice projectDevice = projectDeviceMapper.selectOne(new LambdaQueryWrapper<KwsProjectDevice>()
-                .eq(KwsProjectDevice::getDeviceId, deviceId)
-                .eq(KwsProjectDevice::getDelFlag, 0)
-                .eq(KwsProjectDevice::getStatus, 0)
-                .orderByDesc(KwsProjectDevice::getCreateTime)
-                .last(" limit 1")
-        );
-        LambdaQueryWrapper<KwsAlarm> wrapper = new LambdaQueryWrapper<KwsAlarm>()
-                .eq(KwsAlarm::getLevel, level.intValue())
-                .eq(KwsAlarm::getDeviceId, deviceId)
-                .eq(KwsAlarm::getType, NumberConstant.ONE)
-                .orderByDesc(KwsAlarm::getCreateTime);
-        if (projectDevice != null) {
-            wrapper.eq(KwsAlarm::getProjectId, projectDevice.getProjectId())
-                    .eq(KwsAlarm::getMountainId, projectDevice.getMountainId());
-            if (projectDevice.getProjectId() != null) {
-                wrapper.eq(KwsAlarm::getCompanyId, projectDevice.getCompanyId());
-            }
-        }
+    public void pushSmsMessage(List<String> pushToPhone, String templateCode, String signName, Map<String, String> templateParam) {
         SmsMessageParam param = new SmsMessageParam();
-        param.setCode(DEVICE_ALARM_SMS_TEMPLATE_CODE);
+        param.setCode("");
         param.setType(2);
-        List<String> stringList = new ArrayList<>();
-        stringList.add("18215677925");
-        param.setPushTo(stringList);
+        param.setPushTo(pushToPhone);
         SmsMessageParam.Content content = new SmsMessageParam.Content();
-        content.setTemplateCode("SMS_262585113");
-        content.setSignName("矿拉拉");
-//        SmsMessageParam.TemplateParam templateParam = new SmsMessageParam.TemplateParam();
-//        templateParam.setName("123");
-//        templateParam.setStart("123");
-//        content.setTemplateParam(templateParam);
+        content.setTemplateCode(templateCode);
+        content.setSignName(signName);
+        content.setTemplateParam(templateParam);
         param.setContent(content);
-        detectionApiService.pushSmsMessage(messageUrl, JSONObject.toJSONString(param));
-
+        Map<String, String> headerMap = new HashMap<>();
+        headerMap.put("sign", new MD5Utils().getMd5("sign"));
+        headerMap.put("account", "zhangsan");
+        headerMap.put("msgId", UUIDUtils.get32UUID());
+        JSONObject jsonObject = detectionApiService.pushSmsMessage(smsUrl, JSONObject.toJSONString(param));
+        log.info("推送短信:请求参数:{},响应结果:{}", JSONObject.toJSONString(param), jsonObject.toString());
     }
 
-    @Autowired
-    SmsTemplateConfig smsTemplateConfig;
-
-    @Value("${sms.url}")
-    private String smsUrl;
-
-
-//    @Async
-    public void pushSmsMessage(List<String> pushToPhone, String templateCode, String signName, Map<String, String> templateParam) {
+    /**
+     * 推送邮箱
+     * @param pushToPhone
+     * @param templateCode
+     * @param signName
+     * @param templateParam
+     */
+    @Async
+    public void pushEmailMessage(List<String> pushToPhone, String templateCode, String signName, Map<String, String> templateParam) {
         SmsMessageParam param = new SmsMessageParam();
         param.setCode("");
         param.setType(2);

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

@@ -179,9 +179,6 @@ public class KwsAlarmService {
         return PageRes.build(info, alarmVOS);
     }
 
-    @Autowired
-    KwsAlarmDetailHistoryMapper historyMapper;
-
     @Autowired
     KwsProjectDeviceMapper projectDeviceMapper;
 

+ 171 - 10
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/ProjectService.java

@@ -1191,7 +1191,10 @@ public class ProjectService {
         KwsProject project = projectMapper.selectOne(new LambdaQueryWrapper<KwsProject>().eq(KwsProject::getId, projectId));
         String deviceId = deviceDelete.getDeviceId();
         String bindDeviceId = deviceDelete.getDeviceRelationId();
-        String deviceParentId = deviceDelete.getParentId();
+        String deviceParentId = deviceDelete.getDeviceParentId();
+        if (StringUtils.isBlank(bindDeviceId)) {
+            return HttpResult.error("删除id并未传递");
+        }
         //设备主从解绑
         //如果删除主设备  子设备也要删除
         //id集合
@@ -1215,15 +1218,17 @@ public class ProjectService {
             if (deviceRelation != null) {
                 deleteList.add(deviceRelation.getId());
             }
-            if (!CollectionUtils.isEmpty(deviceRelationList)) {
+            if (!CollectionUtils.isEmpty(deviceRelationList) && deviceRelationList.size() > 0) {
                 deleteList = deviceRelationList.stream().map(KwsDeviceRelation::getId).collect(Collectors.toList());
                 deleteList.add(Long.parseLong(bindDeviceId));
             }
-            deviceRelationMapper.update(null, new LambdaUpdateWrapper<KwsDeviceRelation>()
-                    .eq(KwsDeviceRelation::getMountainId, headerData.getMountainId())
-                    .set(KwsDeviceRelation::getDelFlag, 1)
-                    .in(KwsDeviceRelation::getRelateDeviceId, deleteList)
-            );
+            if (deleteList.size() > 0 && !CollectionUtils.isEmpty(deleteList)) {
+                deviceRelationMapper.update(null, new LambdaUpdateWrapper<KwsDeviceRelation>()
+                        .eq(KwsDeviceRelation::getMountainId, headerData.getMountainId())
+                        .set(KwsDeviceRelation::getDelFlag, 1)
+                        .in(KwsDeviceRelation::getId, deleteList)
+                );
+            }
         } else {
             deleteList.add(Long.parseLong(deviceId));
             deviceRelationMapper.update(null, new LambdaUpdateWrapper<KwsDeviceRelation>()
@@ -1241,13 +1246,13 @@ public class ProjectService {
                     .eq(KwsProjectDevice::getDelFlag, 0)
                     .eq(KwsProjectDevice::getProjectId, projectId)
                     .eq(KwsProjectDevice::getMountainId, headerData.getMountainId())
-                    .in(KwsProjectDevice::getDeviceId, deleteList)
+                    .in(KwsProjectDevice::getDeviceId, deviceId)
             );
         }
         //设备修改状态
         if (!CollectionUtils.isEmpty(deleteList)) {
             deviceMapper.update(null, new LambdaUpdateWrapper<KwsDevice>()
-                    .in(KwsDevice::getId, deleteList)
+                    .in(KwsDevice::getId, deviceId)
                     .eq(KwsDevice::getMountainId, headerData.getMountainId())
                     .eq(KwsDevice::getDelFlag, 0)
                     .set(KwsDevice::getRelevanceLevel, 0)
@@ -1257,7 +1262,7 @@ public class ProjectService {
             );
         }
         if (!CollectionUtils.isEmpty(deleteList)) {
-            List<KwsDevice> kwsDevices = deviceMapper.selectList(new LambdaQueryWrapper<KwsDevice>().in(KwsDevice::getId, deleteList).eq(KwsDevice::getDelFlag, 0));
+            List<KwsDevice> kwsDevices = deviceMapper.selectList(new LambdaQueryWrapper<KwsDevice>().in(KwsDevice::getId, deviceId).eq(KwsDevice::getDelFlag, 0));
             if (!CollectionUtils.isEmpty(kwsDevices)) {
                 StringBuilder deviceName = new StringBuilder();
                 for (int i = 0; i < kwsDevices.size(); i++) {
@@ -1409,4 +1414,160 @@ public class ProjectService {
         });
         return HttpResult.ok(returnList);
     }
+
+    /**
+     * 修改组网设备-关联设备-查询
+     *
+     * @param id
+     * @param request
+     * @return
+     */
+    public HttpResult updateDeviceBindSelect(String id, HttpServletRequest request) {
+        KwsDeviceRelation deviceRelation = deviceRelationMapper.selectOne(
+                new LambdaQueryWrapper<KwsDeviceRelation>()
+                        .eq(KwsDeviceRelation::getId, Long.parseLong(id))
+                        .eq(KwsDeviceRelation::getDelFlag, NumberConstant.ZERO)
+        );
+        UpdateDeviceBindSelectVO bindSelectVO = new UpdateDeviceBindSelectVO();
+        if (deviceRelation != null) {
+            Long deviceId1 = deviceRelation.getDeviceId();
+            KwsDevice kwsDevice = deviceMapper.selectById(deviceId1);
+            bindSelectVO.setDeviceId(deviceId1);
+            bindSelectVO.setDeviceName(kwsDevice == null ? null : kwsDevice.getName());
+            bindSelectVO.setDeviceNameAlias(kwsDevice == null ? null : kwsDevice.getAlias());
+            Long relateDeviceId = deviceRelation.getRelateDeviceId();
+            KwsDevice relateDevice = deviceMapper.selectById(relateDeviceId);
+            bindSelectVO.setRelateDeviceId(relateDeviceId);
+            bindSelectVO.setRelateDeviceName(relateDevice == null ? null : relateDevice.getName());
+            bindSelectVO.setRelateDeviceAlias(relateDevice == null ? null : relateDevice.getAlias());
+        }
+        return HttpResult.ok(bindSelectVO);
+    }
+
+    @Transactional
+    public HttpResult updateDeviceBind(BindDevice bindDevice, HttpServletRequest request) {
+        String deviceRelationId = bindDevice.getDeviceRelationId();
+        if (StringUtils.isBlank(deviceRelationId)) {
+            return HttpResult.error("关联主键id不能为空");
+        }
+        String bindDeviceId = bindDevice.getBindDeviceId();
+        String deviceIds = bindDevice.getDeviceIds();
+        String alias = bindDevice.getAlias();
+        HeaderData headerData = commonService.getHeaderData(request);
+        /**验证主设备是否存在子设备*/
+//        List<KwsDeviceRelation> deviceRelations = deviceRelationMapper.selectList(
+//                new LambdaQueryWrapper<KwsDeviceRelation>()
+//                        .ne(KwsDeviceRelation::getDeviceId,deviceIds)
+//                        .eq(KwsDeviceRelation::getRelateDeviceId,deviceIds)
+//        );
+        if (!deviceIds.equals(bindDeviceId)) {
+            KwsDevice selectById = deviceMapper.selectById(bindDeviceId);
+            if ("2".equals(selectById.getRelevanceLevel())) {
+                return HttpResult.error("所选所属设备是二级设备不可作为主设备");
+            }
+        }
+        /**删除所存在的关联设备组网关系*/
+        deviceRelationMapper.update(null,
+                new LambdaUpdateWrapper<KwsDeviceRelation>()
+                        .set(KwsDeviceRelation::getDelFlag, 1)
+                        .set(KwsDeviceRelation::getUpdateBy, headerData.getUpdateBy())
+                        .set(KwsDeviceRelation::getUpdateTime, LocalDateTime.now())
+                        .eq(KwsDeviceRelation::getId, Long.parseLong(deviceRelationId))
+        );
+
+
+        /**新增组网设备*/
+        Long projectId = Long.parseLong(bindDevice.getProjectId());
+        KwsProject project = projectMapper.selectOne(new LambdaQueryWrapper<KwsProject>().eq(KwsProject::getId, projectId));
+        String companyId = project.getCompanyId();
+        List<Long> list = StringUtils.splitStrToList(deviceIds, Long.class);
+        //设备主从绑定
+        List<KwsDeviceRelation> saveList = new ArrayList<>();
+        StringBuilder deviceName = new StringBuilder();
+        List<KwsDevice> kwsDevices = deviceMapper.selectList(new LambdaQueryWrapper<KwsDevice>()
+                .eq(KwsDevice::getDelFlag, 0)
+                .in(KwsDevice::getId, list));
+        if (CollectionUtils.isEmpty(kwsDevices)) {
+            throw new BusinessException("需要关联设备不存在");
+        }
+        for (int i = 0; i < kwsDevices.size(); i++) {
+            if (i != kwsDevices.size() - 1) {
+                deviceName.append(kwsDevices.get(i).getName()).append(",");
+            } else {
+                deviceName.append(kwsDevices.get(i).getName());
+            }
+        }
+        list.forEach(id -> {
+            String deviceId = "";
+            if (!bindDeviceId.equals(String.valueOf(id))) {
+                //当主设备设置关联时,未关联主设备,即当前设备为主设备
+                deviceId = bindDeviceId;
+            } else {
+                deviceId = String.valueOf(id);
+            }
+            KwsDeviceRelation deviceRelation = new KwsDeviceRelation();
+            deviceRelation.setId(new IdWorker(NumberConstant.ONE).nextId());
+            deviceRelation.setDeviceId(Long.parseLong(deviceId));
+            deviceRelation.setMountainId(headerData.getMountainId());
+            deviceRelation.setRelateDeviceId(id);
+            deviceRelation.setStatus(NumberConstant.ZERO);
+            deviceRelation.setCreateBy(headerData.getCreateBy() == null ? null : Long.parseLong(headerData.getCreateBy()));
+            LocalDateTime now = LocalDateTime.now();
+            deviceRelation.setCreateTime(now);
+            deviceRelation.setUpdateBy(headerData.getCreateBy() == null ? null : Long.parseLong(headerData.getCreateBy()));
+            deviceRelation.setUpdateTime(now);
+            deviceRelation.setDelFlag(NumberConstant.ZERO);
+            saveList.add(deviceRelation);
+        });
+        deviceRelationRepository.saveBatch(saveList);
+        //矿山与设备绑定
+        if (!CollectionUtils.isEmpty(list)) {
+            list.forEach(id -> {
+                KwsProjectDevice device = new KwsProjectDevice();
+                device.setId(new IdWorker(NumberConstant.ONE).nextId());
+                device.setProjectId(projectId);
+                device.setMountainId(headerData.getMountainId());
+                device.setDeviceId(id);
+                device.setStatus(NumberConstant.ONE);
+                device.setCreateBy(headerData.getCreateBy() == null ? null : Long.parseLong(headerData.getCreateBy()));
+                LocalDateTime now = LocalDateTime.now();
+                device.setCreateTime(now);
+                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 -> {
+                String level = "1";
+                if (bindDeviceId != null) {
+                    KwsDevice kwsDevice = deviceMapper.selectByPrimaryKey(Long.parseLong(bindDeviceId));
+                    if (kwsDevice == null) {
+                        throw new BusinessException("所属主设备id错误!");
+                    }
+                    kwsDevice.setRelevanceLevel(level);
+                    kwsDevice.setUpdateTime(LocalDateTime.now());
+                    kwsDevice.setUpdateBy(headerData.getUpdateBy() == null ? null : Long.parseLong(headerData.getUpdateBy()));
+                    level = "2";
+                }
+                KwsDevice kwsDevice = deviceMapper.selectByPrimaryKey(id);
+                deviceMapper.update(null, new LambdaUpdateWrapper<KwsDevice>()
+                        .eq(KwsDevice::getId, id)
+                        .set(KwsDevice::getRelevanceLevel, level)
+                        .set(KwsDevice::getStatus, DeviceEnum.BE_CHECKING.getCode())
+                        .set(KwsDevice::getOnline, 1)
+                        .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()))
+                );
+            });
+        }
+        Map<String, Object> logMap = new HashMap<>(NumberConstant.SIXTEEN);
+        logMap.put("projectName", project.getName());
+        logMap.put("deviceName", deviceName.toString());
+        commonService.insertLog(MessageLogEnum.UPDATE_NETWORKING_DEVICE, headerData, logMap, headerData.getCreateBy() == null ? null : Long.parseLong(headerData.getCreateBy()));
+        return HttpResult.ok();
+    }
 }

+ 12 - 5
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/ThresholdService.java

@@ -232,6 +232,7 @@ public class ThresholdService {
             if (!CollectionUtils.isEmpty(collect1) && collect1.size() > 0) {
                 itemNameList.addAll(collect1);
             }
+            dto.setItemNameCount(itemNameList.size());
             dto.setItemName(JSONObject.toJSONString(itemNameList));
             //获取总数和设置阈值数
             int deviceTotal = getThresholdNumber(thresholdQuery.getProjectId(), headerData, deviceId);
@@ -245,7 +246,8 @@ public class ThresholdService {
             dto.setStatus(setting);
             dto.setStatusName(statusName);
             dto.setPhones(phones.toString());
-            dto.setUpdateByName(CollectionUtils.isEmpty(kwsThresholds) ? null : kwsThresholds.get(0).getCreateBy().toString());
+            dto.setCreateByName(CollectionUtils.isEmpty(kwsThresholds) ? null : kwsThresholds.get(0).getCreateBy().toString());
+            dto.setUpdateByName(CollectionUtils.isEmpty(kwsThresholds) ? null : kwsThresholds.get(0).getUpdateBy().toString());
             dto.setUpdateTime(CollectionUtils.isEmpty(kwsThresholds) ? null : kwsThresholds.get(0).getCreateTime());
         }
         return PageRes.build(info, dtoList);
@@ -334,10 +336,12 @@ public class ThresholdService {
         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, "联系电话格式不正确,请检查并重新输入!");
+        if (org.apache.commons.lang3.StringUtils.isNotBlank(phones)) {
+            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, "联系电话格式不正确,请检查并重新输入!");
+                }
             }
         }
         //页面阈值等级校验
@@ -374,6 +378,9 @@ public class ThresholdService {
                 kwsThreshold.setCreateName(headerData.getCreateName());
                 LocalDateTime now = LocalDateTime.now();
                 kwsThreshold.setCreateTime(now);
+                kwsThreshold.setUpdateTime(now);
+                kwsThreshold.setUpdateBy(headerData.getUpdateBy() == null ? null : Long.parseLong(headerData.getUpdateBy()));
+                kwsThreshold.setUpdateName(headerData.getUpdateName());
                 thresholdMapper.insert(kwsThreshold);
             } else {
                 selected.setLevel(Integer.valueOf(thresholdBean.getLevel()));

+ 1 - 1
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/api/DetectionApiService.java

@@ -181,7 +181,7 @@ public class DetectionApiService {
                 .build();
         try {
             Response response = client.newCall(request).execute();
-            System.out.println(JSONObject.toJSONString(response));
+//            System.out.println(JSONObject.toJSONString(response));
             System.out.println("请求响应状态码:" + response.code());
             if (response.isSuccessful()) {
                 String responseBody = response.body().string();

+ 68 - 22
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/task/DeviceAlarmTaskService.java

@@ -5,6 +5,7 @@ import com.sckw.core.model.constant.NumberConstant;
 import com.sckw.core.model.enums.AlarmTitleEnum;
 import com.sckw.core.model.enums.AlarmTypeEnum;
 import com.sckw.core.utils.IdWorker;
+import com.sckw.excel.utils.DateUtil;
 import com.sckw.log.TraceLog.TraceLog;
 import com.sckw.slope.detection.common.config.SmsTemplateConfig;
 import com.sckw.slope.detection.dao.mysql.KwsAlarmDetailMapper;
@@ -29,8 +30,7 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
 import java.time.LocalDateTime;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 
 /**
  * @author lfdc
@@ -92,21 +92,61 @@ public class DeviceAlarmTaskService {
                         devices = devicesMapper.selectLastData(snCode);
                     } catch (Exception e) {
                         log.error("select deviceAlarm tdengine device error :{}", e.getMessage(), e);
-                        continue;
-//                        insertAlarmAndDetailByDevice(1L, device, device.getId(), AlarmTitleEnum.ALARM_TITLE_ONE.getStatus(), AlarmTypeEnum.ALARM_TWO.getCode());
+//                        continue;
+                        long id = insertAlarmAndDetailByDevice(1L, device, device.getId(), AlarmTitleEnum.ALARM_TITLE_ONE.getStatus(), AlarmTypeEnum.ALARM_TWO.getCode());
 //                        // todo 暂未设备告警电话,设备告警不推送短信
-//                        device.setOnline(1);
-//                        deviceMapper.updateById(device);
+                        device.setOnline(1);
+                        deviceMapper.updateById(device);
+                        //设备离线
+                        String servicePhones = device.getServicePhones();
+                        List<String> pushToPhone = new ArrayList<>();
+                        if (StringUtils.isNotBlank(servicePhones)) {
+                            pushToPhone = com.sckw.core.utils.StringUtils.splitStrToList(servicePhones, String.class);
+                        }
+                        if (!CollectionUtils.isEmpty(pushToPhone) && pushToPhone.size() > 0) {
+                            Map<String, String> templateParam = new HashMap<>();
+                            String dateString = DateUtil.getDateString(new Date(), "yyyy-MM-dd HH:mm:ss");
+                            templateParam.put("time", dateString);
+                            templateParam.put("level", "1");
+                            templateParam.put("name", device.getName());
+                            templateParam.put("value", "");
+                            commonService.pushSmsMessage(pushToPhone
+                                    , smsTemplateConfig.getDataAlarm().getSmsCode()
+                                    , smsTemplateConfig.getDataAlarm().getSignName()
+                                    , templateParam);
+                        }
                     }
                     if (devices == null) {
-                        continue;
-//                        insertAlarmAndDetailByDevice(1L, device, device.getId(), AlarmTitleEnum.ALARM_TITLE_ONE.getStatus(), AlarmTypeEnum.ALARM_TWO.getCode());
+//                        continue;
+                        long id = insertAlarmAndDetailByDevice(1L, device, device.getId(), AlarmTitleEnum.ALARM_TITLE_ONE.getStatus(), AlarmTypeEnum.ALARM_TWO.getCode());
 //                        // todo 暂未设备告警电话,设备告警不推送短信
-//                        device.setOnline(1);
-//                        deviceMapper.updateById(device);
+                        device.setOnline(1);
+                        deviceMapper.updateById(device);
+                        //设备离线
+                        String servicePhones = device.getServicePhones();
+                        List<String> pushToPhone = new ArrayList<>();
+                        if (StringUtils.isNotBlank(servicePhones)) {
+                            pushToPhone = com.sckw.core.utils.StringUtils.splitStrToList(servicePhones, String.class);
+                        }
+                        if (!CollectionUtils.isEmpty(pushToPhone) && pushToPhone.size() > 0) {
+                            Map<String, String> templateParam = new HashMap<>();
+                            String dateString = DateUtil.getDateString(new Date(), "yyyy-MM-dd HH:mm:ss");
+                            templateParam.put("time", dateString);
+                            templateParam.put("level", "1");
+                            templateParam.put("name", device.getName());
+                            templateParam.put("value", "");
+                            commonService.pushSmsMessage(pushToPhone
+                                    , smsTemplateConfig.getDataAlarm().getSmsCode()
+                                    , smsTemplateConfig.getDataAlarm().getSignName()
+                                    , templateParam);
+                        }
                     }
                     //判断是否满足设备超时离线报警
-                    checkDeviceAlarm(snCode, device, devices);
+                    try {
+                        checkDeviceAlarm(snCode, device, devices);
+                    } catch (Exception e) {
+                        log.error("判断是否满足设备超时离线报警 :{}", e.getMessage(), e);
+                    }
                 }
             }
         }
@@ -142,17 +182,23 @@ public class DeviceAlarmTaskService {
             //设备离线
             device.setOnline(1);
             deviceMapper.updateById(device);
-//            List<String> pushToPhone = com.sckw.core.utils.StringUtils.splitStrToList(phones, String.class);
-//            Map<String, String> templateParam = new HashMap<>();
-//            String dateString = DateUtil.getDateString(deviceTime, "yyyy-MM-dd HH:mm:ss");
-//            templateParam.put("time", dateString);
-//            templateParam.put("level", "1");
-//            templateParam.put("name", device.getName());
-//            templateParam.put("value", itemValue);
-//            commonService.pushSmsMessage(pushToPhone
-//                    , smsTemplateConfig.getDataAlarm().getSmsCode()
-//                    , smsTemplateConfig.getDataAlarm().getSignName()
-//                    , templateParam);
+            String servicePhones = device.getServicePhones();
+            List<String> pushToPhone = new ArrayList<>();
+            if (StringUtils.isNotBlank(servicePhones)) {
+                pushToPhone = com.sckw.core.utils.StringUtils.splitStrToList(servicePhones, String.class);
+            }
+            if (!CollectionUtils.isEmpty(pushToPhone) && pushToPhone.size() > 0) {
+                Map<String, String> templateParam = new HashMap<>();
+                String dateString = DateUtil.getDateString(deviceTime, "yyyy-MM-dd HH:mm:ss");
+                templateParam.put("time", dateString);
+                templateParam.put("level", "1");
+                templateParam.put("name", device.getName());
+                templateParam.put("value", "");
+                commonService.pushSmsMessage(pushToPhone
+                        , smsTemplateConfig.getDataAlarm().getSmsCode()
+                        , smsTemplateConfig.getDataAlarm().getSignName()
+                        , templateParam);
+            }
         } else {
             device.setOnline(0);
             deviceMapper.updateById(device);

+ 0 - 201
slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsAlarmDetailHistoryMapper.xml

@@ -1,201 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.sckw.slope.detection.dao.mysql.KwsAlarmDetailHistoryMapper">
-  <resultMap id="BaseResultMap" type="com.sckw.slope.detection.model.dos.mysql.KwsAlarmDetailHistory">
-    <!--@mbg.generated-->
-    <!--@Table kws_alarm_detail_history-->
-    <id column="id" jdbcType="BIGINT" property="id" />
-    <result column="mountain_id" jdbcType="VARCHAR" property="mountainId" />
-    <result column="company_id" jdbcType="VARCHAR" property="companyId" />
-<!--    <result column="project_id" jdbcType="BIGINT" property="projectId" />-->
-    <result column="alarm_id" jdbcType="BIGINT" property="alarmId" />
-    <result column="pid" jdbcType="BIGINT" property="pid" />
-    <result column="val" jdbcType="VARCHAR" property="val" />
-<!--    <result column="item_name" jdbcType="VARCHAR" property="itemName" />-->
-    <result column="lat" jdbcType="VARCHAR" property="lat" />
-    <result column="lng" jdbcType="VARCHAR" property="lng" />
-    <result column="alt" jdbcType="VARCHAR" property="alt" />
-    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
-    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
-    <result column="status" jdbcType="TINYINT" property="status" />
-    <result column="is_history" jdbcType="TINYINT" property="isHistory" />
-    <result column="del_flag" jdbcType="TINYINT" property="delFlag" />
-  </resultMap>
-  <sql id="Base_Column_List">
-    <!--@mbg.generated-->
-    id, mountain_id, company_id, alarm_id,
-    lat, lng, alt, create_time, update_time, `status`,val,pid,is_history,del_flag
-  </sql>
-  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
-    <!--@mbg.generated-->
-    select 
-    <include refid="Base_Column_List" />
-    from kws_alarm_detail
-    where id = #{id,jdbcType=BIGINT}
-  </select>
-  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
-    <!--@mbg.generated-->
-    delete from kws_alarm_detail
-    where id = #{id,jdbcType=BIGINT}
-  </delete>
-  <insert id="insertSelective" parameterType="com.sckw.slope.detection.model.dos.mysql.KwsAlarmDetail">
-    <!--@mbg.generated-->
-    insert into kws_alarm_detail
-    <trim prefix="(" suffix=")" suffixOverrides=",">
-      <if test="id != null">
-        id,
-      </if>
-      <if test="mountainId != null">
-        mountain_id,
-      </if>
-      <if test="companyId != null">
-        company_id,
-      </if>
-      <if test="alarmId != null">
-        alarm_id,
-      </if>
-      <if test="level != null">
-        `level`,
-      </if>
-      <if test="title != null">
-        title,
-      </if>
-      <if test="content != null">
-        content,
-      </if>
-      <if test="type != null">
-        `type`,
-      </if>
-      <if test="lat != null">
-        lat,
-      </if>
-      <if test="lng != null">
-        lng,
-      </if>
-      <if test="alt != null">
-        alt,
-      </if>
-      <if test="createTime != null">
-        create_time,
-      </if>
-      <if test="updateTime != null">
-        update_time,
-      </if>
-      <if test="status != null">
-        `status`,
-      </if>
-    </trim>
-    <trim prefix="values (" suffix=")" suffixOverrides=",">
-      <if test="id != null">
-        #{id,jdbcType=BIGINT},
-      </if>
-      <if test="mountainId != null">
-        #{mountainId,jdbcType=VARCHAR},
-      </if>
-      <if test="companyId != null">
-        #{companyId,jdbcType=VARCHAR},
-      </if>
-      <if test="alarmId != null">
-        #{alarmId,jdbcType=BIGINT},
-      </if>
-      <if test="level != null">
-        #{level,jdbcType=INTEGER},
-      </if>
-      <if test="title != null">
-        #{title,jdbcType=VARCHAR},
-      </if>
-      <if test="content != null">
-        #{content,jdbcType=VARCHAR},
-      </if>
-      <if test="type != null">
-        #{type,jdbcType=INTEGER},
-      </if>
-      <if test="lat != null">
-        #{lat,jdbcType=VARCHAR},
-      </if>
-      <if test="lng != null">
-        #{lng,jdbcType=VARCHAR},
-      </if>
-      <if test="alt != null">
-        #{alt,jdbcType=VARCHAR},
-      </if>
-      <if test="createTime != null">
-        #{createTime,jdbcType=TIMESTAMP},
-      </if>
-      <if test="updateTime != null">
-        #{updateTime,jdbcType=TIMESTAMP},
-      </if>
-      <if test="status != null">
-        #{status,jdbcType=TINYINT},
-      </if>
-    </trim>
-  </insert>
-  <update id="updateByPrimaryKeySelective" parameterType="com.sckw.slope.detection.model.dos.mysql.KwsAlarmDetail">
-    <!--@mbg.generated-->
-    update kws_alarm_detail
-    <set>
-      <if test="mountainId != null">
-        mountain_id = #{mountainId,jdbcType=VARCHAR},
-      </if>
-      <if test="companyId != null">
-        company_id = #{companyId,jdbcType=VARCHAR},
-      </if>
-      <if test="projectId != null">
-        project_id = #{projectId,jdbcType=BIGINT},
-      </if>
-      <if test="alarmId != null">
-        alarm_id = #{alarmId,jdbcType=BIGINT},
-      </if>
-      <if test="level != null">
-        `level` = #{level,jdbcType=INTEGER},
-      </if>
-      <if test="title != null">
-        title = #{title,jdbcType=VARCHAR},
-      </if>
-      <if test="content != null">
-        content = #{content,jdbcType=VARCHAR},
-      </if>
-      <if test="type != null">
-        `type` = #{type,jdbcType=INTEGER},
-      </if>
-      <if test="lat != null">
-        lat = #{lat,jdbcType=VARCHAR},
-      </if>
-      <if test="lng != null">
-        lng = #{lng,jdbcType=VARCHAR},
-      </if>
-      <if test="alt != null">
-        alt = #{alt,jdbcType=VARCHAR},
-      </if>
-      <if test="createTime != null">
-        create_time = #{createTime,jdbcType=TIMESTAMP},
-      </if>
-      <if test="updateTime != null">
-        update_time = #{updateTime,jdbcType=TIMESTAMP},
-      </if>
-      <if test="status != null">
-        `status` = #{status,jdbcType=TINYINT},
-      </if>
-    </set>
-    where id = #{id,jdbcType=BIGINT}
-  </update>
-  <update id="updateByPrimaryKey" parameterType="com.sckw.slope.detection.model.dos.mysql.KwsAlarmDetail">
-    <!--@mbg.generated-->
-    update kws_alarm_detail
-    set mountain_id = #{mountainId,jdbcType=VARCHAR},
-      company_id = #{companyId,jdbcType=VARCHAR},
-      project_id = #{projectId,jdbcType=BIGINT},
-      alarm_id = #{alarmId,jdbcType=BIGINT},
-      `level` = #{level,jdbcType=INTEGER},
-      title = #{title,jdbcType=VARCHAR},
-      content = #{content,jdbcType=VARCHAR},
-      `type` = #{type,jdbcType=INTEGER},
-      lat = #{lat,jdbcType=VARCHAR},
-      lng = #{lng,jdbcType=VARCHAR},
-      alt = #{alt,jdbcType=VARCHAR},
-      create_time = #{createTime,jdbcType=TIMESTAMP},
-      update_time = #{updateTime,jdbcType=TIMESTAMP},
-      `status` = #{status,jdbcType=TINYINT}
-    where id = #{id,jdbcType=BIGINT}
-  </update>
-</mapper>