lin před 3 roky
rodič
revize
d3fa0b1404

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