Răsfoiți Sursa

Merge branch 'dev' into sky_v2

15928045575 2 ani în urmă
părinte
comite
c5995b6d63

+ 23 - 18
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/consumer/MqttCallbackHandler.java

@@ -202,7 +202,7 @@ public class MqttCallbackHandler extends AbstractHandler {
                         if (!CollectionUtils.isEmpty(emailList)) {
                             emailAddress = list.stream().map(KwsAlarmInfo::getValueDesc).distinct().collect(Collectors.toList());
                         }
-                        if (!CollectionUtils.isEmpty(emailAddress)){
+                        if (!CollectionUtils.isEmpty(emailAddress)) {
                             Map<String, Object> templateParam = new HashMap<>();
                             if (StringUtils.isBlank(time)) {
                                 LocalDateTime localDateTime = Instant.ofEpochSecond(ts).atZone(ZoneId.systemDefault()).toLocalDateTime();
@@ -212,7 +212,7 @@ public class MqttCallbackHandler extends AbstractHandler {
                             templateParam.put("level", level.toString());
                             templateParam.put("name", device.getName());
                             templateParam.put("time", time);
-                            templateParam.put("project", vo.getProjectName());
+                            templateParam.put("project", vo == null ? null : vo.getProjectName());
                             templateParam.put("value", itemValue);
                             commonService.pushEmailMessage(emailAddress
                                     , templateParam);
@@ -640,12 +640,13 @@ public class MqttCallbackHandler extends AbstractHandler {
                                      String alarmTitle, Integer type
     ) {
         Long deviceId = device.getId();
-        KwsProjectDevice projectDevice = projectDeviceMapper.selectOne(new LambdaQueryWrapper<KwsProjectDevice>()
-                .eq(KwsProjectDevice::getDeviceId, deviceId)
-                .eq(KwsProjectDevice::getDelFlag, 0)
-                .orderByDesc(KwsProjectDevice::getCreateTime)
-                .last(" limit 1")
-        );
+//        KwsProjectDevice projectDevice = projectDeviceMapper.selectOne(new LambdaQueryWrapper<KwsProjectDevice>()
+//                .eq(KwsProjectDevice::getDeviceId, deviceId)
+//                .eq(KwsProjectDevice::getDelFlag, 0)
+//                .orderByDesc(KwsProjectDevice::getCreateTime)
+//                .last(" limit 1")
+//        );
+        KwsProjectDevice projectDevice = projectDeviceMapper.selectProjectDeviceByDeviceId(deviceId);
         //新增未读数据
         long alarmId = insertUnread(level, device, thresholdId, itemValue, ts, alarmTitle, type, deviceId, projectDevice);
         //新增历史数据
@@ -675,7 +676,7 @@ public class MqttCallbackHandler extends AbstractHandler {
         KwsAlarm alarms = alarmMapper.selectOne(wrapper);
         if (alarms == null) {
             KwsAlarm alarm = new KwsAlarm();
-            String mountainId = projectDevice == null ? null : projectDevice.getMountainId();
+            String mountainId = device == null ? null : device.getMountainId();
             String companyId = projectDevice == null ? null : projectDevice.getCompanyId();
             String projectId = projectDevice == null ? null :
                     (projectDevice.getProjectId() == null ? null : projectDevice.getProjectId().toString());
@@ -702,7 +703,7 @@ public class MqttCallbackHandler extends AbstractHandler {
                              String alarmTitle, Integer type, Long deviceId, KwsProjectDevice projectDevice) {
 
         long alarmId = new IdWorker(NumberConstant.ONE).nextId();
-        KwsAlarm alarms = selectAlarmData(level, deviceId, type, alarmTitle, projectDevice);
+        KwsAlarm alarms = selectAlarmData(level, deviceId, type, alarmTitle, projectDevice, device);
 //        if (!CollectionUtils.isEmpty() && alarms.size() > 1) {
 //            //去重
 //            checkAlarmData(alarms, level, deviceId, type, alarmTitle, projectDevice);
@@ -710,7 +711,7 @@ public class MqttCallbackHandler extends AbstractHandler {
 //        alarms = selectAlarmData(level, deviceId, type, alarmTitle, projectDevice);
         if (alarms == null) {
             KwsAlarm alarm = new KwsAlarm();
-            String mountainId = projectDevice == null ? null : projectDevice.getMountainId();
+            String mountainId = device == null ? null : device.getMountainId();
             String companyId = projectDevice == null ? null : projectDevice.getCompanyId();
             String projectId = projectDevice == null ? null :
                     (projectDevice.getProjectId() == null ? null : projectDevice.getProjectId().toString());
@@ -760,7 +761,7 @@ public class MqttCallbackHandler extends AbstractHandler {
             );
             alarm.setTriggerTimes(aLong.intValue() + 1);
             alarmMapper.updateById(alarm);
-            String mountainId = projectDevice == null ? null : projectDevice.getMountainId();
+            String mountainId = device == null ? null : device.getMountainId();
             String companyId = projectDevice == null ? null : projectDevice.getCompanyId();
             String projectId = projectDevice == null ? null :
                     (projectDevice.getProjectId() == null ? null : projectDevice.getProjectId().toString());
@@ -784,7 +785,7 @@ public class MqttCallbackHandler extends AbstractHandler {
         return alarmId;
     }
 
-    private KwsAlarm selectAlarmData(Long level, Long deviceId, Integer type, String alarmTitle, KwsProjectDevice projectDevice) {
+    private KwsAlarm selectAlarmData(Long level, Long deviceId, Integer type, String alarmTitle, KwsProjectDevice projectDevice, KwsDevice device) {
         LambdaQueryWrapper<KwsAlarm> wrapper = new LambdaQueryWrapper<KwsAlarm>()
                 .eq(KwsAlarm::getLevel, level.intValue())
                 .eq(KwsAlarm::getDeviceId, deviceId)
@@ -795,14 +796,18 @@ public class MqttCallbackHandler extends AbstractHandler {
                 .eq(KwsAlarm::getDelFlag, NumberConstant.ZERO)
                 .orderByDesc(KwsAlarm::getCreateTime);
         if (projectDevice != null) {
-            wrapper.eq(KwsAlarm::getProjectId, projectDevice.getProjectId())
-                    .eq(KwsAlarm::getMountainId, projectDevice.getMountainId());
+            wrapper.eq(Objects.nonNull(projectDevice.getProjectId()), KwsAlarm::getProjectId, projectDevice.getProjectId())
+                    .eq(StringUtils.isNotBlank(device.getMountainId()), KwsAlarm::getMountainId, device.getMountainId());
             if (projectDevice.getProjectId() != null) {
-                wrapper.eq(KwsAlarm::getCompanyId, projectDevice.getCompanyId());
+                wrapper.eq(StringUtils.isNotBlank(projectDevice.getCompanyId()), KwsAlarm::getCompanyId, projectDevice.getCompanyId());
             }
         }
-        KwsAlarm alarms = alarmMapper.selectOne(wrapper);
-        return alarms;
+        KwsAlarm kwsAlarm = new KwsAlarm();
+        List<KwsAlarm> alarms = alarmMapper.selectList(wrapper);
+        if (alarms.size() > 0) {
+            kwsAlarm = alarms.get(0);
+        }
+        return kwsAlarm;
     }
 
     private void checkAlarmData(List<KwsAlarm> alarms, Long level, Long deviceId, Integer type, String alarmTitle, KwsProjectDevice projectDevice) {

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

@@ -35,6 +35,13 @@ public interface KwsProjectDeviceMapper extends BaseMapper<KwsProjectDevice> {
      */
     ProjectVo selectProjectByDeviceId(@Param("deviceId") long id);
 
+    /**
+     * 设备id查项目数据
+     * @param id 设备id
+     * @return
+     */
+    KwsProjectDevice selectProjectDeviceByDeviceId(@Param("deviceId") long id);
+
 
     List<IntegrationItemVO> selectIntegrationItemByProjectId(@Param("id") long id);
 

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

@@ -48,11 +48,13 @@ public class ProjectAddDTO implements Serializable {
     /**
      * 省级平台名
      */
+//    @NotBlank(message = "省级平台名不能为空")
     private String platformName;
 
     /**
      * 省级平台地址(url)
      */
+//    @NotBlank(message = "省级平台地址不能为空")
     private String platformAddress;
 
     /**

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

@@ -55,13 +55,13 @@ public class ProjectUpdateDTO implements Serializable {
     /**
      * 省级平台名
      */
-    @NotBlank(message = "项目区域不能为空")
+//    @NotBlank(message = "项目区域不能为空")
     private String platformName;
 
     /**
      * 省级平台地址(url)
      */
-    @NotBlank(message = "项目区域不能为空")
+//    @NotBlank(message = "项目区域不能为空")
     private String platformAddress;
 
     /**

+ 6 - 2
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/CommonService.java

@@ -18,7 +18,8 @@ import com.sckw.slope.detection.dao.mysql.KwsDictMapper;
 import com.sckw.slope.detection.dao.mysql.KwsLogMapper;
 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.mysql.KwsDeviceReference;
+import com.sckw.slope.detection.model.dos.mysql.KwsLog;
 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;
@@ -93,7 +94,9 @@ public class CommonService {
             uInfo = "eyJjb21wYW55SWQiOiIxOTgiLCJjb21wYW55TmFtZSI6IuWbm+W3nemHkemhtumbhuWboiIsImNyZWF0ZUJ5IjoiMiIsImNyZWF0ZU5hbWUiOiI2MDA2NzgiLCJ1cGRhdGVCeSI6IjIiLCJ1cGRhdGVOYW1lIjoiNjAwNjc4IiwibW91bnRhaW5JZCI6IjE5OCJ9";
         }
         String message = new String(Base64.getDecoder().decode(uInfo));
+        log.info("获取请求http数据:{}", message);
         HeaderData headerData = JSONObject.parseObject(message, HeaderData.class);
+        log.info("获取解析后请求http数据:{}", JSONObject.toJSONString(headerData));
         /*if (headerData.getMountainId().isBlank()) {
             throw new BusinessException("矿山id不能为空");
         }
@@ -438,6 +441,7 @@ public class CommonService {
         headerMap.put("sign", new MD5Utils().getMd5("sign"));
         headerMap.put("account", "zhangsan");
         headerMap.put("msgId", UUIDUtils.get32UUID());
-        detectionApiService.pushSmsMessage(smsUrl, JSONObject.toJSONString(param));
+        JSONObject jsonObject = detectionApiService.pushSmsMessage(smsUrl, JSONObject.toJSONString(param));
+        log.info("邮寄发送返回结果:{}",jsonObject.toString());
     }
 }

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

@@ -282,6 +282,7 @@
         WHERE a.del_flag = 0
           AND c.del_flag = 0
           AND d.del_flag = 0
+          AND c.relevance_level = 0
           AND c.id NOT in (SELECT DISTINCT a.relate_device_id
                            FROM kws_device_relation a
                                     LEFT JOIN kws_project b ON a.mountain_id = b.mountain_id where a.del_flag = 0)

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

@@ -235,5 +235,14 @@ WHERE
                 LEFT JOIN kws_project_device b ON a.id = b.project_id
         WHERE
             b.id = #{deviceId}
+        order by  b.create_time desc  limit 1
     </select>
+
+  <select id="selectProjectDeviceByDeviceId" resultMap="BaseResultMap">
+      SELECT b.*
+      FROM kws_project a
+               LEFT JOIN kws_project_device b ON a.id = b.project_id
+      WHERE b.id = #{deviceId}
+      order by b.create_time desc limit 1
+  </select>
 </mapper>