Bläddra i källkod

Merge remote-tracking branch 'origin/20210716' into 20210716

hym 3 år sedan
förälder
incheckning
041ea37b1d

+ 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>

+ 1 - 1
zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/config/ResourceServerConfig.java

@@ -24,7 +24,7 @@ public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
                     "/file/**","/meter/read/record/list/sync/data","/import/downloadFailFile",
                    "/v2/**","/syncData/**","/meter/read/record/querySettlementWaterConsumption"
                     ,"/meter/read/record/queryDeviceMeterReadRecordWithCondtion","/common/getProductId"
-                    ,"/notify/add/alarm","/notify/pdate/device/state")
+                    ,"/notify/add/alarm","notify/update/device/state")
             .permitAll() //配置不需要身份认证的请求路径
             .anyRequest().authenticated() //其他所有访问路径都需要身份认证
             .and()

+ 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()));

+ 23 - 8
zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/service/impl/AlarmTypeServiceImpl.java

@@ -19,8 +19,12 @@ import com.zcxk.rmcp.api.enums.WaterErrorEnum;
 import com.zcxk.rmcp.api.vo.alarm.AlarmTypeVo;
 import com.zcxk.rmcp.core.dao.AlarmRuleMapper;
 import com.zcxk.rmcp.core.dao.AlarmTypeMapper;
+import com.zcxk.rmcp.core.dao.DeviceMapper;
+import com.zcxk.rmcp.core.dao.ProductMapper;
 import com.zcxk.rmcp.core.entity.AlarmRule;
 import com.zcxk.rmcp.core.entity.AlarmType;
+import com.zcxk.rmcp.core.entity.Device;
+import com.zcxk.rmcp.core.entity.Product;
 import com.zcxk.rmcp.web.service.AlarmTypeService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
@@ -50,6 +54,10 @@ public class AlarmTypeServiceImpl implements AlarmTypeService {
 
     @Autowired
     private SyncAlarmService syncAlarmService;
+    @Resource
+    private ProductMapper productMapper;
+    @Resource
+    private DeviceMapper deviceMapper;
 
     @Override
     public int insertSelective(AlarmType record) {
@@ -90,19 +98,22 @@ public class AlarmTypeServiceImpl implements AlarmTypeService {
         LoginUser loginUser = UserUtil.getCurrentUser();
         AlarmType alarmType = BeanCopyUtils.copy(dto, AlarmType.class);
         setUserInfo(loginUser, alarmType, dto.getRules());
+
+        Product product = productMapper.findById(dto.getProductId());
+        Device device = deviceMapper.findById(dto.getDeviceId());
         // 设备告警
         if (AlarmCategoryEnum.DATA_ALARM.getType() == dto.getAlarmCategory()) {
             AlarmDataDTO dataDTO = BeanCopyUtils.copy(dto, AlarmDataDTO.class);
             dataDTO.setCustomerId(loginUser.getCustomerId());
-            dataDTO.setDeviceId(dto.getIotDeviceId());
-            dataDTO.setProductId(dto.getIotProductId());
+            if(device!=null)dataDTO.setDeviceId(device.getIotDeviceId());
+            if(product!=null)dataDTO.setProductId(product.getIotProductId());
             dataDTO.setCode(dto.getIdentifier());
             iotAlarmId = syncAlarmService.addDataWaringConfig(dataDTO);
         } else if (AlarmCategoryEnum.OFFLINE_ALARM.getType() == dto.getAlarmCategory()) {
             AlarmOfflineDTO dataDTO = BeanCopyUtils.copy(dto, AlarmOfflineDTO.class);
             dataDTO.setCustomerId(loginUser.getCustomerId());
-            dataDTO.setDeviceId(dto.getIotDeviceId());
-            dataDTO.setProductId(dto.getIotProductId());
+            if(device!=null)dataDTO.setDeviceId(device.getIotDeviceId());
+            if(product!=null)dataDTO.setProductId(product.getIotProductId());
             dataDTO.setCode(dto.getIdentifier());
             dataDTO.setOperator(dto.getRules().get(0).getOperator());
             dataDTO.setValue(dto.getRules().get(0).getValue());
@@ -138,19 +149,23 @@ public class AlarmTypeServiceImpl implements AlarmTypeService {
         } else {
             alarmType.setAlarmRuleNum(0);
         }
+
+        Product product = productMapper.findById(dto.getProductId());
+        Device device = deviceMapper.findById(dto.getDeviceId());
+
         if (AlarmCategoryEnum.DATA_ALARM.getType() == alarm.getAlarmCategory()) {
             AlarmDataDTO dataDTO = BeanCopyUtils.copy(dto, AlarmDataDTO.class);
             dataDTO.setCustomerId(loginUser.getCustomerId());
-            dataDTO.setDeviceId(dto.getIotDeviceId());
-            dataDTO.setProductId(dto.getIotProductId());
+            if(device!=null)dataDTO.setDeviceId(device.getIotDeviceId());
+            if(product!=null)dataDTO.setProductId(product.getIotProductId());
             dataDTO.setRuleId(alarm.getIotAlarmId());
             dataDTO.setCode(dto.getIdentifier());
             iotAlarmId = syncAlarmService.updateDataWaringConfig(dataDTO);
         } else if (AlarmCategoryEnum.OFFLINE_ALARM.getType() == dto.getAlarmCategory()) {
             AlarmOfflineDTO dataDTO = BeanCopyUtils.copy(dto, AlarmOfflineDTO.class);
             dataDTO.setCustomerId(loginUser.getCustomerId());
-            dataDTO.setDeviceId(dto.getIotDeviceId());
-            dataDTO.setProductId(dto.getIotProductId());
+            if(device!=null)dataDTO.setDeviceId(device.getIotDeviceId());
+            if(product!=null)dataDTO.setProductId(product.getIotProductId());
             dataDTO.setRuleId(alarm.getIotAlarmId());
             dataDTO.setCode(dto.getIdentifier());
             iotAlarmId = syncAlarmService.updateOfflineConfig(dataDTO);

+ 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());
     }