lin 3 лет назад
Родитель
Сommit
110dd9311e

+ 4 - 0
zoniot-rmcp/zoniot-rmcp-api/src/main/java/com/zcxk/rmcp/api/enums/DeviceStatusEnum.java

@@ -61,4 +61,8 @@ public enum DeviceStatusEnum {
                 .findFirst();
         return optional.get().getMessage();
     }
+
+    public static boolean offline(int code){
+        return  code == DeviceStatusEnum.ALARM.getCode() || code == DeviceStatusEnum.OFFLINE.getCode();
+    }
 }

+ 2 - 0
zoniot-rmcp/zoniot-rmcp-core/src/main/java/com/zcxk/rmcp/core/dao/DeviceMapper.java

@@ -199,4 +199,6 @@ public interface DeviceMapper {
      * @date 16:04 2021/9/10
      **/
     int countDeviceByCommunityId(int communityId);
+
+    Device findByIotDeviceId(@Param("iotDeviceId") Long iotDeviceId);
 }

+ 4 - 0
zoniot-rmcp/zoniot-rmcp-core/src/main/java/com/zcxk/rmcp/core/mapper/DeviceMapper.xml

@@ -851,4 +851,8 @@
   <select id="countDeviceByCommunityId" resultType="java.lang.Integer">
     select count(1) from rmcp_device where community_id = #{communityId} and status = 1
   </select>
+
+  <select id="findByIotDeviceId" resultMap="BaseResultMap">
+    select <include refid="Base_Column_List"/> from rmcp_device where status = 1 and iot_device_id = #{iotDeviceId}
+  </select>
 </mapper>

+ 12 - 5
zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/service/impl/AlarmTypeDetailsServiceImpl.java

@@ -13,8 +13,10 @@ import com.zcxk.rmcp.api.dto.alarm.AlarmTypeDetailsDto;
 import com.zcxk.rmcp.api.enums.AlarmStateEnum;
 import com.zcxk.rmcp.api.vo.alarm.AlarmTypeDetailsEntityVo;
 import com.zcxk.rmcp.core.dao.AlarmTypeDetailMapper;
+import com.zcxk.rmcp.core.dao.DeviceMapper;
 import com.zcxk.rmcp.core.entity.AlarmDetailsEntity;
 import com.zcxk.rmcp.core.entity.AlarmType;
+import com.zcxk.rmcp.core.entity.Device;
 import com.zcxk.rmcp.web.service.AlarmTypeDetailsService;
 import com.zcxk.rmcp.web.service.AlarmTypeService;
 import lombok.extern.log4j.Log4j2;
@@ -56,6 +58,8 @@ public class AlarmTypeDetailsServiceImpl implements AlarmTypeDetailsService {
 
     @Resource
     private AlarmTypeService alarmTypeService;
+    @Resource
+    private DeviceMapper deviceMapper;
 
 
     @Override
@@ -140,15 +144,18 @@ public class AlarmTypeDetailsServiceImpl implements AlarmTypeDetailsService {
     **/
     private List<AlarmDetailsEntity> convert(AlarmDetailsAddDto dto){
         BigDecimal value;
-        String deviceName;
-        Integer sceneType;
-        String attrName = null;
+
+        Device device = deviceMapper.findByIotDeviceId(Long.valueOf(dto.getDeviceId()));
+        if (device == null) {
+            log.error("【接收告警信息失败】:设备为空 ,请求参数:{}", dto.toString());
+            return null;
+        }
+
         AlarmType alarmType = alarmTypeService.findByIotAlarmId(dto.getAlarmTypeId());
         if (alarmType == null) {
             log.error("【接收告警信息失败】:告警信息为空 ,请求参数:{}", dto.toString());
             return null;
         }
-        sceneType = alarmType.getSceneType();
         Long alarmId = alarmTypeDetailMapper.selectLastAlarmId(alarmType.getId());
         List<AlarmDetailsEntity> result = new ArrayList<>();
         // 离线告警
@@ -183,7 +190,7 @@ public class AlarmTypeDetailsServiceImpl implements AlarmTypeDetailsService {
         alarmDetailsEntity.setTenantId(alarmType.getTenantId());
         alarmDetailsEntity.setAlarmId(Long.parseLong(alarmType.getId().toString()));
         alarmDetailsEntity.setAlarmType(alarmType.getAlarmCategory() == 1 ? "参数报警" : "状态报警");
-        alarmDetailsEntity.setDeviceId(Long.valueOf(dto.getDeviceId()));
+        alarmDetailsEntity.setDeviceId(device.getId());
 
         if (alarmType.getAttributeId() != null){
             alarmDetailsEntity.setAttributeId(Integer.parseInt(alarmType.getAttributeId().toString()));

+ 7 - 6
zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/service/impl/NotifyServiceImpl.java

@@ -1,6 +1,7 @@
 package com.zcxk.rmcp.web.service.impl;
 
 
+import com.alibaba.fastjson.JSON;
 import com.zcxk.rmcp.api.dto.DeviceStateDto;
 import com.zcxk.rmcp.api.dto.alarm.AlarmDetailsAddDto;
 import com.zcxk.rmcp.api.dto.device.DeviceDataDto;
@@ -37,9 +38,9 @@ public class NotifyServiceImpl implements NotifyService {
 
     @Override
     public Integer insertAlarmInfo(AlarmDetailsAddDto dto) {
-        log.info("【接收通知】物联告警信息begin:{}", dto.toString());
+        log.info("【接收通知】物联告警信息begin:{}", JSON.toJSONString(dto));
         Integer result = alarmTypeDetailsService.insert(dto);
-        log.info("【接收通知】物联告警信息end:{}", dto.toString());
+        log.info("【接收通知】物联告警信息end:{}", JSON.toJSONString(dto));
         return result;
     }
 
@@ -54,10 +55,10 @@ public class NotifyServiceImpl implements NotifyService {
         device.setDeviceStatus(dto.getDeviceStatus());
         deviceMapper.updateByPrimaryKeySelective(device);
         // 如果状态正常就要变更报警为正常
-        /*if (!DeviceStatusEnum.offline(dto.getDeviceStatus())) {
-            Long deviceId = deviceMapper.findDeviceIdByIotDeviceId(dto.getDeviceId());
-            alarmTypeDetailsService.updateStateByDeviceId(deviceId, AlarmStateEnum.HISTORY_ALARM.getCode());
-        }*/
+        if (!DeviceStatusEnum.offline(dto.getDeviceStatus())) {
+            Device deviceTemp = deviceMapper.findByIotDeviceId(dto.getDeviceId());
+            alarmTypeDetailsService.updateStateByDeviceId(deviceTemp.getId(), AlarmStateEnum.HISTORY_ALARM.getCode());
+        }
         log.info("【接收通知】物联修改设备状态信息end:{}", dto.toString());
     }