소스 검색

Merge branch 'dev' into sky_v2

15928045575 2 년 전
부모
커밋
24cacee9df
16개의 변경된 파일417개의 추가작업 그리고 129개의 파일을 삭제
  1. 1 1
      slope-common/slope-common-excel/src/main/java/com/sckw/excel/utils/ExcelUtil.java
  2. 5 0
      slope-common/slope-common-sms/pom.xml
  3. 6 0
      slope-modules/slope-detection/pom.xml
  4. 50 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/common/config/SmsTemplateConfig.java
  5. 85 51
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/consumer/MqttCallbackHandler.java
  6. 29 7
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/consumer/MqttDeviceCallbackHandler.java
  7. 52 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/controller/CommonController.java
  8. 1 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/controller/ThresholdController.java
  9. 3 8
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/param/SmsMessageParam.java
  10. 118 30
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/CommonService.java
  11. 9 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/DeviceService.java
  12. 16 8
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/KwsAlarmService.java
  13. 12 21
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/api/DetectionApiService.java
  14. 20 0
      slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/task/DeviceAlarmTaskService.java
  15. 1 3
      slope-modules/slope-detection/src/main/resources/bootstrap-dev.yml
  16. 9 0
      slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsAlarmMapper.xml

+ 1 - 1
slope-common/slope-common-excel/src/main/java/com/sckw/excel/utils/ExcelUtil.java

@@ -273,7 +273,7 @@ public class ExcelUtil {
 
         // 文件上传到OSS
         Map<String, String> map = FileUtils.uploadFileByInfo(is, fileName, FileEnum.FILE_STORE_TYPE_ALIYUN);
-        System.out.println(com.alibaba.fastjson2.JSONObject.toJSONString(map));
+//        System.out.println(com.alibaba.fastjson2.JSONObject.toJSONString(map));
         String ossAddressPrefix = FileUtils.getOSSAddressPrefix();
         if (map != null && (map.get("filePath") != null)) {
             ossAddressPrefix = ossAddressPrefix + map.get("filePath");

+ 5 - 0
slope-common/slope-common-sms/pom.xml

@@ -30,5 +30,10 @@
             <artifactId>spring-cloud-alicloud-sms</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-context</artifactId>
+        </dependency>
+
     </dependencies>
 </project>

+ 6 - 0
slope-modules/slope-detection/pom.xml

@@ -77,6 +77,12 @@
             <groupId>org.springframework</groupId>
             <artifactId>spring-web</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>com.sckw</groupId>
+            <artifactId>slope-common-sms</artifactId>
+            <version>1.0.0</version>
+        </dependency>
     </dependencies>
 
     <build>

+ 50 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/common/config/SmsTemplateConfig.java

@@ -0,0 +1,50 @@
+package com.sckw.slope.detection.common.config;
+
+import lombok.Data;
+import lombok.Getter;
+import lombok.Setter;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author lfdc
+ * @description 文件上传获取配置yml信息
+ * @date 2023-08-10 09:08:41
+ */
+@Getter
+@Setter
+@Component
+@RefreshScope
+@ConfigurationProperties(prefix = "sms.template")
+public class SmsTemplateConfig {
+//    private String smsUrl;
+    private DeviceAlarm deviceAlarm;
+    private DataAlarm dataAlarm;
+
+    /**
+     * 设备告警
+     * 尊敬的管理员,${name}设备已离线,离线时间: ${time},请尽快安排处理问题。
+     */
+    @Data
+    public static class DeviceAlarm {
+
+        private String smsCode;
+
+        private String signName;
+
+    }
+
+    /**
+     * 数据告警
+     * 尊敬的管理员,${time}监测到${level}级告警。
+     * 设备名称: ${name},监测数值: ${value},请尽快处理问题。
+     */
+    @Data
+    public static class DataAlarm {
+
+        private String smsCode;
+
+        private String signName;
+    }
+}

+ 85 - 51
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/consumer/MqttCallbackHandler.java

@@ -1,5 +1,6 @@
 package com.sckw.slope.detection.consumer;
 
+import cn.hutool.core.date.DateUtil;
 import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.dynamic.datasource.annotation.DSTransactional;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -7,6 +8,7 @@ import com.sckw.core.model.constant.Global;
 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.model.enums.DictEnum;
 import com.sckw.core.model.enums.DictItemEnum;
 import com.sckw.core.utils.CollectionUtils;
 import com.sckw.core.utils.DateUtils;
@@ -14,6 +16,7 @@ import com.sckw.core.utils.IdWorker;
 import com.sckw.core.web.response.HttpResult;
 import com.sckw.log.TraceLog.TraceLog;
 import com.sckw.redis.utils.RedissonUtils;
+import com.sckw.slope.detection.common.config.SmsTemplateConfig;
 import com.sckw.slope.detection.dao.mysql.*;
 import com.sckw.slope.detection.dao.tdengine.SlopeDataMapper;
 import com.sckw.slope.detection.model.dos.mysql.*;
@@ -22,7 +25,7 @@ import com.sckw.slope.detection.model.dos.tdengine.SlopeData;
 import com.sckw.slope.detection.model.dto.AlarmList;
 import com.sckw.slope.detection.model.dto.DevicesAlarm;
 import com.sckw.slope.detection.model.dto.DevicesItem;
-import com.sckw.slope.detection.model.param.SmsMessageParam;
+import com.sckw.slope.detection.model.dto.SystemDict;
 import com.sckw.slope.detection.model.vo.DeviceIntegrationVo;
 import com.sckw.slope.detection.service.CommonService;
 import com.sckw.slope.detection.service.TdengineService;
@@ -32,7 +35,6 @@ 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.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -78,6 +80,9 @@ public class MqttCallbackHandler extends AbstractHandler {
     @Autowired
     KwsIntegrationMapper integrationMapper;
 
+    @Autowired
+    SmsTemplateConfig smsTemplateConfig;
+
     @TraceLog(description = "处理system/iot/device_data_slope")
     @DSTransactional
     public HttpResult handle(String topic, String payload) {
@@ -85,7 +90,7 @@ public class MqttCallbackHandler extends AbstractHandler {
         log.info("MqttDeviceCallbackHandler:" + topic + "|" + payload);
 
         DevicesAlarm devicesAlarm = JSONObject.parseObject(payload, DevicesAlarm.class);
-//        Map<String, SystemDict> dictByDictCode = commonService.getDictByDictCode(DictEnum.MODEL_PART);
+        Map<String, SystemDict> dictByDictCode = commonService.getDictByDictCode(DictEnum.MODEL_PART);
 //        JSONObject objects = JSONObject.parseObject(payload);
 //        String deviceTs = objects.getString("ts");
 //        String deviceGuid = objects.getString("guid");
@@ -146,14 +151,47 @@ public class MqttCallbackHandler extends AbstractHandler {
                         Long level = Long.valueOf(map.get("level"));
                         Long thresholdId = Long.valueOf(map.get("thresholdId"));
                         //阈值表以及明细表存储
-                        long id = insertAlarmAndDetail(level, device, thresholdId, itemValue, ts, AlarmTitleEnum.ALARM_TITLE_TWO.getStatus(), AlarmTypeEnum.ALARM_ONE.getCode());
+                        String url = dictByDictCode.get(itemName) == null ? null : dictByDictCode.get(itemName).getUrl();
+                        String itemValueAndUnit = StringUtils.isBlank(url) ? itemValue : (itemValue + url);
+                        long id = insertAlarmAndDetail(level, device, thresholdId, itemValueAndUnit, ts, AlarmTitleEnum.ALARM_TITLE_TWO.getStatus(), AlarmTypeEnum.ALARM_ONE.getCode());
                         //todo 不适用redis存统计  使用新字段处理
                         /**阈值次数存redis*/
 //                        redisPutAlarmCount(id);
                         /*【露天矿山边坡监测系统】尊敬的管理员,2023-10-01 12:23:34监测到一级告警。
                             设备名称:位移监测设备-gnss一号机,监测数值:55。123456789N,请尽快处理问题。*/
                         Map<String, Object> messageMap = new HashMap<>();
-                        pushSmsMessage(messageUrl, device, level, thresholdId, 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());
+                            }
+                        }
+                        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);
@@ -190,11 +228,11 @@ public class MqttCallbackHandler extends AbstractHandler {
         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)
-                        .eq(KwsIntegration::getDelFlag, NumberConstant.ZERO)
-        );
+//        List<KwsIntegration> integrations = integrationMapper.selectList(
+//                new LambdaQueryWrapper<KwsIntegration>()
+//                        .in(KwsIntegration::getId, integrationIds)
+//                        .eq(KwsIntegration::getDelFlag, NumberConstant.ZERO)
+//        );
 //        Map<String, Long> integrationMap = new HashMap<>(NumberConstant.SIXTEEN);
 //        if (!org.springframework.util.CollectionUtils.isEmpty(integrations)) {
 //            integrationMap = integrations.stream().collect(Collectors.toMap(KwsIntegration::getPartNames, KwsIntegration::getId));
@@ -218,54 +256,50 @@ public class MqttCallbackHandler extends AbstractHandler {
                         Long level = Long.valueOf(map.get("level"));
                         Long thresholdId = Long.valueOf(map.get("thresholdId"));
                         //阈值表以及明细表存储
-                        long id = insertAlarmAndDetail(level, device, thresholdId, deviceIntegration.getPartNames(), ts, AlarmTitleEnum.ALARM_TITLE_TWO.getStatus(), AlarmTypeEnum.ALARM_ONE.getCode());
+                        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<>();
-                        pushSmsMessage(messageUrl, device, level, thresholdId, 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());
+                            }
+                        }
+                        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);
                     }
                 }
             }
         }
     }
 
-    @Async
-    public void pushSmsMessage(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());
-            }
-        }
-        SmsMessageParam param = new SmsMessageParam();
-        param.setCode("123456");
-        param.setType("2");
-        List<String> stringList = new ArrayList<>();
-        stringList.add("18215677925");
-        param.setPushTo(stringList);
-        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);
-        param.setContent(content);
-        detectionApiService.pushSmsMessage(messageUrl, JSONObject.toJSONString(param));
-
-    }
 
     private void checkDeviceAlarm(String deviceCode, KwsDevice device, String itemValue, Long ts) {
         try {

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

@@ -1,5 +1,6 @@
 package com.sckw.slope.detection.consumer;
 
+import cn.hutool.core.date.DateUtil;
 import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.dynamic.datasource.annotation.DSTransactional;
@@ -11,8 +12,10 @@ import com.sckw.core.model.enums.DictEnum;
 import com.sckw.core.model.enums.DictItemEnum;
 import com.sckw.core.utils.CollectionUtils;
 import com.sckw.core.utils.IdWorker;
+import com.sckw.core.utils.StringUtils;
 import com.sckw.core.web.response.HttpResult;
 import com.sckw.log.TraceLog.TraceLog;
+import com.sckw.slope.detection.common.config.SmsTemplateConfig;
 import com.sckw.slope.detection.dao.mysql.*;
 import com.sckw.slope.detection.dao.tdengine.SlopeDataMapper;
 import com.sckw.slope.detection.model.dos.mysql.*;
@@ -67,6 +70,9 @@ public class MqttDeviceCallbackHandler extends AbstractHandler {
     @Autowired
     HandlerFactory handlerFactory;
 
+    @Autowired
+    SmsTemplateConfig smsTemplateConfig;
+
     @TraceLog(description = "处理system/iot/device_data/")
 //    @Transactional
     @DSTransactional
@@ -143,8 +149,24 @@ public class MqttDeviceCallbackHandler extends AbstractHandler {
 
                         /*【露天矿山边坡监测系统】尊敬的管理员,2023-10-01 12:23:34监测到一级告警。
                             设备名称:位移监测设备-gnss一号机,监测数值:55。123456789N,请尽快处理问题。*/
-                        Map<String, Object> messageMap = new HashMap<>();
-                        pushSmsMessage(messageUrl, device, level, thresholdId, messageMap);
+                        /**
+                         * 数据告警
+                         * 尊敬的管理员,${time}监测到${level}级告警。
+                         * 设备名称: ${name},监测数值: ${value},请尽快处理问题。
+                         */
+                        KwsThreshold kwsThreshold = thresholdMapper.selectById(thresholdId);
+                        String phones = kwsThreshold.getPhones();
+                        List<String> pushToPhone = 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",itemValue);
+                        commonService.pushSmsMessage(pushToPhone,
+                                smsTemplateConfig.getDataAlarm().getSmsCode(),
+                                smsTemplateConfig.getDataAlarm().getSignName(),templateParam);
                     }
 
                 }
@@ -179,17 +201,17 @@ public class MqttDeviceCallbackHandler extends AbstractHandler {
         }
         SmsMessageParam param = new SmsMessageParam();
         param.setCode("123456");
-        param.setType("2");
+        param.setType(2);
         List<String> stringList = new ArrayList<>();
         stringList.add("18215677925");
         param.setPushTo(stringList);
         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);
+//        SmsMessageParam.TemplateParam templateParam = new SmsMessageParam.TemplateParam();
+//        templateParam.setName("123");
+//        templateParam.setStart("123");
+//        content.setTemplateParam(templateParam);
         param.setContent(content);
         detectionApiService.pushSmsMessage(messageUrl, JSONObject.toJSONString(param));
 

+ 52 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/controller/CommonController.java

@@ -1,6 +1,8 @@
 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;
 import com.sckw.slope.detection.service.CommonService;
 import jakarta.validation.Valid;
@@ -10,6 +12,13 @@ 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 公共字典查询
@@ -26,4 +35,47 @@ public class CommonController {
     public HttpResult getDict(@RequestBody @Valid QueryDictTypePageReqVo queryDictTypePageReqVo){
         return  HttpResult.ok(commonService.getDict(queryDictTypePageReqVo));
     }
+
+
+    @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();
+    }
 }

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

@@ -59,6 +59,7 @@ public class ThresholdController {
         return thresholdService.detail(thresholdQuery, request);
     }
 
+    @TraceLog(description = "阈值配置")
     @Log(description = "阈值配置")
     //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
     @RequestMapping(name = "阈值配置", value = "/configuration", method = RequestMethod.POST)

+ 3 - 8
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/param/SmsMessageParam.java

@@ -4,6 +4,7 @@ import lombok.Data;
 
 import java.io.Serializable;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @author lfdc
@@ -20,7 +21,7 @@ public class SmsMessageParam implements Serializable {
     /**
      * 类型
      */
-    private String type;
+    private int type;
     /**
      * 手机
      */
@@ -32,12 +33,6 @@ public class SmsMessageParam implements Serializable {
     public static class Content implements Serializable{
         private String templateCode;
         private String signName;
-        private TemplateParam templateParam;
-    }
-
-    @Data
-    public static class TemplateParam implements Serializable{
-        private String name;
-        private String start;
+        private Map<String,String> templateParam;
     }
 }

+ 118 - 30
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/CommonService.java

@@ -10,28 +10,30 @@ import com.sckw.core.model.enums.DictItemEnum;
 import com.sckw.core.model.enums.MessageLogEnum;
 import com.sckw.core.model.page.PageRes;
 import com.sckw.core.utils.IdWorker;
-import com.sckw.core.web.response.HttpResult;
+import com.sckw.core.utils.UUIDUtils;
 import com.sckw.core.web.response.PhpResult;
-
+import com.sckw.slope.detection.common.config.SmsTemplateConfig;
 import com.sckw.slope.detection.dao.mysql.KwsDeviceReferenceMapper;
 import com.sckw.slope.detection.dao.mysql.KwsDictMapper;
 import com.sckw.slope.detection.dao.mysql.KwsLogMapper;
-import com.sckw.slope.detection.model.dos.mysql.KwsDeviceReference;
-import com.sckw.slope.detection.model.dos.mysql.KwsLog;
+import com.sckw.slope.detection.dao.mysql.KwsProjectDeviceMapper;
+import com.sckw.slope.detection.dao.tdengine.SlopeDataMapper;
+import com.sckw.slope.detection.model.dos.mysql.*;
 import com.sckw.slope.detection.model.dos.tdengine.SlopeData;
 import com.sckw.slope.detection.model.dto.HeaderData;
 import com.sckw.slope.detection.model.dto.SystemDict;
+import com.sckw.slope.detection.model.param.SmsMessageParam;
 import com.sckw.slope.detection.model.vo.DeviceIntegrationVo;
 import com.sckw.slope.detection.model.vo.QueryDictTypePageReqVo;
 import com.sckw.slope.detection.service.api.DetectionApiService;
 import jakarta.servlet.http.HttpServletRequest;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.dubbo.common.utils.MD5Utils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
-import com.sckw.slope.detection.dao.tdengine.SlopeDataMapper;
-import org.springframework.util.CollectionUtils;
 
 import java.math.BigDecimal;
 import java.text.ParseException;
@@ -48,6 +50,14 @@ import java.util.*;
 @Service
 @RefreshScope
 public class CommonService {
+    /**
+     * 设备告警短信模板
+     */
+    private static final String DEVICE_ALARM_SMS_TEMPLATE_CODE = "SMS_464035567";
+    /**
+     * 数据告警短信模板
+     */
+    private static final String DATA_ALARM_SMS_TEMPLATE_CODE = "SMS_464050617";
 
     @Value("${spring.profiles.active}")
     private String isDev;
@@ -67,6 +77,9 @@ public class CommonService {
     @Autowired
     SlopeDataMapper slopeDataMapper;
 
+    @Autowired
+    KwsProjectDeviceMapper projectDeviceMapper;
+
     public HeaderData getHeaderData(HttpServletRequest request) {
         /**
          * {"companyId":"198","companyName":"四川金顶集团","createBy":"2","createName":"600678","updateBy":"2","updateName":"600678","mountainId":"198"}
@@ -76,7 +89,7 @@ public class CommonService {
 //        if (StringUtils.isBlank(uInfo)) {
 //            throw new BusinessException("数据请求异常!");
 //        }
-        if ("lfdc".equals(isDev) || "dev".equals(isDev)) {
+        if ("lfdc".equals(isDev)/* || "dev".equals(isDev)*/) {
             uInfo = "eyJjb21wYW55SWQiOiIxOTgiLCJjb21wYW55TmFtZSI6IuWbm+W3nemHkemhtumbhuWboiIsImNyZWF0ZUJ5IjoiMiIsImNyZWF0ZU5hbWUiOiI2MDA2NzgiLCJ1cGRhdGVCeSI6IjIiLCJ1cGRhdGVOYW1lIjoiNjAwNjc4IiwibW91bnRhaW5JZCI6IjE5OCJ9";
         }
         String message = new String(Base64.getDecoder().decode(uInfo));
@@ -258,15 +271,15 @@ public class CommonService {
     }
 
     //集成要数判断
-    public double returnIntegrationData(String snCode, List<SlopeData> data, DeviceIntegrationVo inter){
+    public double returnIntegrationData(String snCode, List<SlopeData> data, DeviceIntegrationVo inter) {
 
         BigDecimal offsetValue = new BigDecimal("0.00");
         BigDecimal subtract = new BigDecimal(data.get(0).getVal()).subtract(new BigDecimal(data.get(1).getVal()));
         Date newD = data.get(0).getTs();
         Date oldD = data.get(1).getTs();
-        double diff = (newD.getTime()-oldD.getTime())/(1000*60*60.0);
+        double diff = (newD.getTime() - oldD.getTime()) / (1000 * 60 * 60.0);
         //判断集成要素
-        if(DictItemEnum.LONGITUDE_X.getValue().equals(inter.getPartNames())){
+        if (DictItemEnum.LONGITUDE_X.getValue().equals(inter.getPartNames())) {
             List<SlopeData> y = slopeDataMapper.selectListByTwoLine(snCode, DictItemEnum.LATITUDE_Y.getValue());
             double angleInRadians = Double.parseDouble(y.get(1).getVal());
             double cosValue = Math.cos(angleInRadians);
@@ -280,48 +293,48 @@ public class CommonService {
         if (DictItemEnum.ALTITUDE_Z.getValue().equals(inter.getPartNames())) {
             offsetValue = subtract.divide(new BigDecimal(1000), 9, BigDecimal.ROUND_HALF_UP);
         }
-        if(inter.getFormula().equals(String.valueOf(NumberConstant.ONE))){//加速度(a-a’)/t²   formula=1
+        if (inter.getFormula().equals(String.valueOf(NumberConstant.ONE))) {//加速度(a-a’)/t²   formula=1
             BigDecimal t = new BigDecimal(diff).multiply(new BigDecimal(diff));
-            return offsetValue.divide(t,9, BigDecimal.ROUND_HALF_UP).doubleValue();
+            return offsetValue.divide(t, 9, BigDecimal.ROUND_HALF_UP).doubleValue();
 
-        }else if(inter.getFormula().equals(String.valueOf(NumberConstant.TWO))){//速度(a-a’)/t    formula=2
-            return offsetValue.divide(new BigDecimal(diff),9, BigDecimal.ROUND_HALF_UP).doubleValue();
+        } else if (inter.getFormula().equals(String.valueOf(NumberConstant.TWO))) {//速度(a-a’)/t    formula=2
+            return offsetValue.divide(new BigDecimal(diff), 9, BigDecimal.ROUND_HALF_UP).doubleValue();
         }
         return 0;
     }
 
-    public Map<String,List<Object>> getDateByNull(String dateStart,String dateEnd,String[] arr) throws ParseException {
-        Map<String,List<Object>>  map = new HashMap<>();
+    public Map<String, List<Object>> getDateByNull(String dateStart, String dateEnd, String[] arr) throws ParseException {
+        Map<String, List<Object>> map = new HashMap<>();
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH");
         Date start = sdf.parse(dateStart);
         Date end = sdf.parse(dateEnd);
 
-        for(String ar: arr){
+        for (String ar : arr) {
             Date temp = start;
             Calendar calendar = Calendar.getInstance();
             calendar.setTime(start);
             List<Object> list = new ArrayList<>();
 
-            while(temp.getTime() < end.getTime()){
-                Map<Object,Object> map1 =  new HashMap<>();
+            while (temp.getTime() < end.getTime()) {
+                Map<Object, Object> map1 = new HashMap<>();
                 temp = calendar.getTime();
                 map1.put("ts", sdf.format(temp.getTime()));
                 list.add(map1);
-                calendar.add(Calendar.HOUR_OF_DAY,1);
+                calendar.add(Calendar.HOUR_OF_DAY, 1);
             }
-            map.put(ar,list);
+            map.put(ar, list);
         }
         return map;
     }
 
-    public List<Object> returnIntegrationDataArray(String snCode, String dateStart, String dateEnd,DeviceIntegrationVo listvo,String key1,String key2){
+    public List<Object> returnIntegrationDataArray(String snCode, String dateStart, String dateEnd, DeviceIntegrationVo listvo, String key1, String key2) {
         //首先获取全部数据
-        String[] partName  = {listvo.getPartNames()};
+        String[] partName = {listvo.getPartNames()};
         List<SlopeData> selectedData = slopeDataMapper.selectLineListByArray(snCode, partName, dateStart, dateEnd);
         Map<String, List<Object>> mapList = new HashMap<>();
         List<Object> listTmp = new ArrayList<>();
-        for(int i=0;i<selectedData.size();i++) {
-            if(i+1>=selectedData.size()){
+        for (int i = 0; i < selectedData.size(); i++) {
+            if (i + 1 >= selectedData.size()) {
                 continue;
             }
             BigDecimal offsetValue = new BigDecimal("0.00");
@@ -333,8 +346,8 @@ public class CommonService {
             //判断集成要素
             if (DictItemEnum.LONGITUDE_X.getValue().equals(listvo.getPartNames())) {
                 //依次获取当前推送的Y轴数据
-                List<SlopeData> y = slopeDataMapper.selectListLineByMsgId(snCode, DictItemEnum.LATITUDE_Y.getValue(),selectedData.get(i).getMsgId());
-                if(y.size()>0){
+                List<SlopeData> y = slopeDataMapper.selectListLineByMsgId(snCode, DictItemEnum.LATITUDE_Y.getValue(), selectedData.get(i).getMsgId());
+                if (y.size() > 0) {
                     double angleInRadians = Double.parseDouble(y.get(0).getVal());
                     double cosValue = Math.cos(angleInRadians);
                     double doubleValue = subtract.divide(new BigDecimal("360"), 9, BigDecimal.ROUND_HALF_UP).doubleValue();
@@ -354,14 +367,89 @@ public class CommonService {
             } else if (listvo.getFormula().equals(String.valueOf(NumberConstant.TWO))) {//速度(a-a’)/t    formula=2
                 offsetRetrun = offsetValue.divide(new BigDecimal(diff), 9, BigDecimal.ROUND_HALF_UP).doubleValue();
             }
-            Map<String ,Object> map = new HashMap();
+            Map<String, Object> map = new HashMap();
             SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
             String time = sdf.format(selectedData.get(i + 1).getRawId());
-            map.put(key1,time);
-            map.put(key2,offsetRetrun);
+            map.put(key1, time);
+            map.put(key2, offsetRetrun);
             listTmp.add(map);
         }
         //mapList.put(listvo.getIntegrationName(),listTmp);
         return listTmp;
     }
+
+
+    /**
+     * 发送短信
+     *
+     * @param messageUrl  消息地址
+     * @param device      设备
+     * @param level       等级
+     * @param thresholdId 阈值id
+     * @param messageMap  消息内容
+     */
+    @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());
+            }
+        }
+        SmsMessageParam param = new SmsMessageParam();
+        param.setCode(DEVICE_ALARM_SMS_TEMPLATE_CODE);
+        param.setType(2);
+        List<String> stringList = new ArrayList<>();
+        stringList.add("18215677925");
+        param.setPushTo(stringList);
+        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);
+        param.setContent(content);
+        detectionApiService.pushSmsMessage(messageUrl, JSONObject.toJSONString(param));
+
+    }
+
+    @Autowired
+    SmsTemplateConfig smsTemplateConfig;
+
+    @Value("${sms.url}")
+    private String smsUrl;
+
+
+//    @Async
+    public void pushSmsMessage(List<String> pushToPhone, String templateCode, String signName, Map<String, String> templateParam) {
+        SmsMessageParam param = new SmsMessageParam();
+        param.setCode("");
+        param.setType(2);
+        param.setPushTo(pushToPhone);
+        SmsMessageParam.Content content = new SmsMessageParam.Content();
+        content.setTemplateCode(templateCode);
+        content.setSignName(signName);
+        content.setTemplateParam(templateParam);
+        param.setContent(content);
+        Map<String, String> headerMap = new HashMap<>();
+        headerMap.put("sign", new MD5Utils().getMd5("sign"));
+        headerMap.put("account", "zhangsan");
+        headerMap.put("msgId", UUIDUtils.get32UUID());
+        detectionApiService.pushSmsMessage(smsUrl, JSONObject.toJSONString(param));
+    }
 }

+ 9 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/DeviceService.java

@@ -99,6 +99,15 @@ public class DeviceService {
         if (Objects.isNull(device)) {
             throw new SystemException(HttpStatus.QUERY_FAIL_CODE, HttpStatus.DEVICE_NOT_EXISTS);
         }
+        //验证设备存在与项目关联管理 设备不允许删除
+        List<KwsProjectDevice> projectDevices = projectDeviceMapper.selectList(
+                new LambdaQueryWrapper<KwsProjectDevice>()
+                        .eq(KwsProjectDevice::getDeviceId, ids)
+                        .eq(KwsProjectDevice::getDelFlag, NumberConstant.ZERO)
+        );
+        if (!CollectionUtils.isEmpty(projectDevices) && projectDevices.size()>0){
+            return HttpResult.error(HttpStatus.GLOBAL_EXCEPTION_CODE,"设备与项目存在关联,解除关联后,可允许删除");
+        }
         HeaderData headerData = commonService.getHeaderData(response);
         //List<Long> list = StringUtils.splitStrToList(ids, Long.class);
         int update = deviceMapper.update(null, new LambdaUpdateWrapper<KwsDevice>()

+ 16 - 8
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/KwsAlarmService.java

@@ -337,7 +337,7 @@ public class KwsAlarmService {
         if (!CollectionUtils.isEmpty(idsList) && idsList.size() > 0) {
             wrapper.in(KwsAlarm::getId, idsList);
         }
-        List<KwsAlarm> list = alarmMapper.selectExportListByQuery(query, headerData.getMountainId(),idsList);
+        List<KwsAlarm> list = alarmMapper.selectExportListByQuery(query, headerData.getMountainId(), idsList);
 //        List<KwsAlarm> list = alarmMapper.selectList(wrapper);
         List<KwsAlarmExportVO> alarmVOS = new ArrayList<>();
         if (CollectionUtils.isEmpty(list)) {
@@ -435,16 +435,19 @@ public class KwsAlarmService {
             for (KwsAlarmDetail detail : detailList) {
                 Long pid = detail.getPid();
                 KwsThreshold kwsThreshold = thresholdMapper.selectById(pid);
+                if (kwsThreshold == null) {
+                    kwsThreshold = thresholdMapper.selectByPrimaryKey(pid);
+                }
                 ThresholdRecordDetailVO vo = new ThresholdRecordDetailVO();
                 vo.setId(detail.getId());
                 vo.setAlarmLevel(kwsAlarm.getLevel() == null ? null :
                         (thresholdLevel == null ? String.valueOf(kwsAlarm.getLevel()) : thresholdLevel.get(String.valueOf(kwsAlarm.getLevel())).getLabel()));
-                vo.setType(kwsThreshold.getItemName() == null ? null :
-                        (dictByDictCode == null ? kwsThreshold.getItemName() : dictByDictCode.get(kwsThreshold.getItemName()).getLabel()));
+                vo.setType(kwsThreshold == null ? null : (kwsThreshold.getItemName() == null ? null :
+                        (dictByDictCode == null ? kwsThreshold.getItemName() : (dictByDictCode.get(kwsThreshold.getItemName()) == null ? kwsThreshold.getItemName() : dictByDictCode.get(kwsThreshold.getItemName()).getLabel()))));
                 vo.setValue(detail.getVal());
-                vo.setItemName(kwsThreshold.getItemName());
-                vo.setPhone(kwsThreshold.getPhones());
-                KwsDevice kwsDevice = deviceMapper.selectById(kwsThreshold.getDeviceId());
+                vo.setItemName(kwsThreshold == null ? null : kwsThreshold.getItemName());
+                vo.setPhone(kwsThreshold == null ? null : kwsThreshold.getPhones());
+                KwsDevice kwsDevice = deviceMapper.selectById(kwsThreshold == null ? null : kwsThreshold.getDeviceId());
                 StringBuilder location = new StringBuilder();
                 if (StringUtils.isNotBlank(kwsDevice.getLogicLng())) {
                     location.append(kwsDevice.getLogicLng()).append(";");
@@ -771,6 +774,7 @@ public class KwsAlarmService {
         List<KwsAlarmDetail> detailList = alarmDetailMapper.selectList(new LambdaQueryWrapper<KwsAlarmDetail>()
                 .eq(KwsAlarmDetail::getAlarmId, Long.parseLong(parentId))
                 .in(!CollectionUtils.isEmpty(idsList), KwsAlarmDetail::getId, idsList)
+                .orderByAsc(KwsAlarmDetail::getCreateTime)
         );
         if (CollectionUtils.isEmpty(detailList)) {
             return list;
@@ -784,12 +788,16 @@ public class KwsAlarmService {
             for (KwsAlarmDetail detail : detailList) {
                 Long pid = detail.getPid();
                 KwsThreshold kwsThreshold = thresholdMapper.selectById(pid);
+                if (kwsThreshold == null) {
+                    kwsThreshold = thresholdMapper.selectByPrimaryKey(pid);
+                }
                 ThresholdRecordDetailExportVO vo = new ThresholdRecordDetailExportVO();
                 vo.setId(detail.getId());
                 vo.setAlarmLevel(kwsAlarm.getType() == null ? null :
                         (alarmType == null ? String.valueOf(kwsAlarm.getType()) : alarmType.get(String.valueOf(kwsAlarm.getType())).getLabel()));
-                vo.setType(kwsThreshold.getItemName() == null ? null :
-                        (dictByDictCode == null ? kwsThreshold.getItemName() : dictByDictCode.get(kwsThreshold.getItemName()).getLabel()));
+                vo.setType(kwsThreshold == null ? null : (kwsThreshold.getItemName() == null ? null :
+                        (dictByDictCode == null ? kwsThreshold.getItemName() :
+                                (dictByDictCode.get(kwsThreshold.getItemName()) == null ? kwsThreshold.getItemName() : dictByDictCode.get(kwsThreshold.getItemName()).getLabel()))));
                 vo.setValue(detail.getVal());
                 vo.setItemName(kwsThreshold.getItemName());
                 vo.setPhone(kwsThreshold.getPhones());

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

@@ -4,6 +4,7 @@ import com.alibaba.fastjson2.JSONObject;
 import com.sckw.core.model.constant.NumberConstant;
 import com.sckw.core.utils.CollectionUtils;
 import com.sckw.core.utils.OkHttpUtils;
+import com.sckw.core.utils.UUIDUtils;
 import com.sckw.core.web.response.HttpResult;
 import com.sckw.core.web.response.PhpResult;
 import com.sckw.slope.detection.model.dto.SystemDict;
@@ -144,24 +145,25 @@ public class DetectionApiService {
 
     public static void main(String[] args) throws Exception {
         SmsMessageParam param = new SmsMessageParam();
-        param.setCode("123456");
-        param.setType("2");
+        param.setCode("");
+        param.setType(2);
         List<String> stringList = new ArrayList<>();
         stringList.add("18215677925");
         param.setPushTo(stringList);
         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.setTemplateCode("SMS_464035567");
+        content.setSignName("开物云ECO");
+        Map<String, String> templateParam = new HashMap<>();
+        templateParam.put("name","设备一号");
+        templateParam.put("time","2023-12-03 11:00:20");
         content.setTemplateParam(templateParam);
         param.setContent(content);
         Map<String, String> headerMap = new HashMap<>();
         headerMap.put("sign", new MD5Utils().getMd5("sign"));
         headerMap.put("account", "zhangsan");
-        headerMap.put("msgId", "msgid");
-        pushSmsMessage("http://10.10.10.149:8830/msg_api/push", JSONObject.toJSONString(param));
+        headerMap.put("msgId", UUIDUtils.get32UUID());
+//        pushSmsMessage("http://10.10.10.149:8830/msg_api/push", JSONObject.toJSONString(param));
+        pushSmsMessage("http://10.10.10.223:8830/msg_api/push", JSONObject.toJSONString(param));
     }
 
     private static OkHttpClient client = new OkHttpClient();
@@ -170,22 +172,11 @@ public class DetectionApiService {
 
     public static JSONObject pushSmsMessage(String url, String json) {
         RequestBody body = RequestBody.create(JSON, json);
-//        Request.Builder builder = new Request.Builder();
-//        Map<String, Object> map = new HashMap<>();
-//        if (map != null) {
-//            for (Map.Entry<String, Object> entry : map.entrySet()) {
-//                String key = entry.getKey();
-//                Object value = entry.getValue();
-//                builder.addHeader(key, value.toString());
-//            }
-//        }
-//        builder.post(body);
-//        Request request = builder.build();
         Request request = new Request.Builder()
                 .url(url)
                 .addHeader("sign", new MD5Utils().getMd5("sign"))
                 .addHeader("account", "zhangsan")
-                .addHeader("msgId", "msgld")
+                .addHeader("msgId", UUIDUtils.get32UUID())
                 .post(body)
                 .build();
         try {

+ 20 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/task/DeviceAlarmTaskService.java

@@ -6,6 +6,7 @@ import com.sckw.core.model.enums.AlarmTitleEnum;
 import com.sckw.core.model.enums.AlarmTypeEnum;
 import com.sckw.core.utils.IdWorker;
 import com.sckw.log.TraceLog.TraceLog;
+import com.sckw.slope.detection.common.config.SmsTemplateConfig;
 import com.sckw.slope.detection.dao.mysql.KwsAlarmDetailMapper;
 import com.sckw.slope.detection.dao.mysql.KwsAlarmMapper;
 import com.sckw.slope.detection.dao.mysql.KwsDeviceMapper;
@@ -16,6 +17,7 @@ import com.sckw.slope.detection.model.dos.mysql.KwsAlarmDetail;
 import com.sckw.slope.detection.model.dos.mysql.KwsDevice;
 import com.sckw.slope.detection.model.dos.mysql.KwsProjectDevice;
 import com.sckw.slope.detection.model.dos.tdengine.Devices;
+import com.sckw.slope.detection.service.CommonService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -58,6 +60,12 @@ public class DeviceAlarmTaskService {
     @Autowired
     KwsProjectDeviceMapper projectDeviceMapper;
 
+    @Autowired
+    CommonService commonService;
+
+    @Autowired
+    SmsTemplateConfig smsTemplateConfig;
+
     /**
      * 设备告警数据
      */
@@ -131,8 +139,20 @@ public class DeviceAlarmTaskService {
         if (diffHours > 24) {
             long id = insertAlarmAndDetailByDevice(1L, device, device.getId(), AlarmTitleEnum.ALARM_TITLE_ONE.getStatus(), AlarmTypeEnum.ALARM_TWO.getCode());
             // todo 暂未设备告警电话,设备告警不推送短信
+            //设备离线
             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);
         } else {
             device.setOnline(0);
             deviceMapper.updateById(device);

+ 1 - 3
slope-modules/slope-detection/src/main/resources/bootstrap-dev.yml

@@ -51,14 +51,12 @@ mqtt:
   isConsume: true
 OkHttpClit:
   url: http://10.10.10.220:9501
-sms:
-  url: http://10.10.10.223:8830/msg_api/push
 
 scheduled:
   template:
     enable: true
   device:
-    enable: false
+    enable: true
 
 #oss上传
 aliyun:

+ 9 - 0
slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsAlarmMapper.xml

@@ -329,6 +329,15 @@
             <if test="type != null and type != ''">
                 and a.type = #{type}
             </if>
+            <if test="startTime != null and startTime != ''">
+                and b.create_time &gt; #{startTime}
+            </if>
+            <if test="endTime != null and endTime != ''">
+                and b.create_time &lt; #{endTime}
+            </if>
+            <if test="level != null and level != ''">
+                and a.level = #{level}
+            </if>
         </where>
         GROUP BY a.project_id
     </select>