|
@@ -1,10 +1,10 @@
|
|
|
package com.bz.zoneiot.water.web.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.bz.zoneiot.core.common.enums.StatusEnum;
|
|
|
-import com.bz.zoneiot.core.common.util.BeanCopyUtils;
|
|
|
+import com.bz.zoneiot.core.common.pojo.Message;
|
|
|
import com.bz.zoneiot.core.oauth2.util.UserUtil;
|
|
|
-import com.bz.zoneiot.core.utils.BigDecimalUtils;
|
|
|
import com.bz.zoneiot.water.api.dto.AlarmDetailsAddDto;
|
|
|
import com.bz.zoneiot.water.api.dto.AlarmTypeDetailsDto;
|
|
|
import com.bz.zoneiot.water.api.enums.AlarmStateEnum;
|
|
@@ -15,10 +15,13 @@ import com.bz.zoneiot.water.core.dao.DeviceSceneMapper;
|
|
|
import com.bz.zoneiot.water.core.entity.AlarmDetailsEntity;
|
|
|
import com.bz.zoneiot.water.core.entity.AlarmType;
|
|
|
import com.bz.zoneiot.water.core.entity.DeviceAttributeEntity;
|
|
|
+import com.bz.zoneiot.water.web.client.UserCenterClient;
|
|
|
import com.bz.zoneiot.water.web.service.AlarmTypeDetailsService;
|
|
|
import com.bz.zoneiot.water.web.service.AlarmTypeService;
|
|
|
-import io.swagger.models.auth.In;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
+import org.springframework.amqp.core.AmqpTemplate;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
@@ -27,6 +30,7 @@ import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
/**
|
|
|
* @description
|
|
@@ -37,6 +41,18 @@ import java.util.List;
|
|
|
@Log4j2
|
|
|
public class AlarmTypeDetailsServiceImpl implements AlarmTypeDetailsService {
|
|
|
|
|
|
+ @Resource
|
|
|
+ private AmqpTemplate amqpTemplate;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserCenterClient userCenterClient;
|
|
|
+
|
|
|
+ @Value("${receive.exchange.name}")
|
|
|
+ private String receiveExchangeName;
|
|
|
+
|
|
|
+ @Value("${dispath.routing.key}")
|
|
|
+ private String dispathRoutingKey;
|
|
|
+
|
|
|
@Resource
|
|
|
private AlarmTypeDetailMapper alarmTypeDetailMapper;
|
|
|
|
|
@@ -122,6 +138,8 @@ public class AlarmTypeDetailsServiceImpl implements AlarmTypeDetailsService {
|
|
|
}
|
|
|
result = new ArrayList<>();
|
|
|
BigDecimal value;
|
|
|
+ String attrName = null;
|
|
|
+ String deviceName = null;
|
|
|
// 离线告警
|
|
|
if (alarmType.getAlarmCategory() == 2 || alarmType.getAttributeId() == null) {
|
|
|
value = new BigDecimal("0");
|
|
@@ -131,6 +149,7 @@ public class AlarmTypeDetailsServiceImpl implements AlarmTypeDetailsService {
|
|
|
log.error("【接收告警信息失败】:属性为空 ,请求参数:{}", dto.toString());
|
|
|
return null;
|
|
|
}
|
|
|
+ attrName = attributeEntity.getName();
|
|
|
value = new BigDecimal(dto.getData().get(attributeEntity.getIdentifier()).toString());
|
|
|
}
|
|
|
List<DeviceSceneVo> sceneVos = deviceSceneMapper.findSceneByDeviceId(alarmType.getDeviceId());
|
|
@@ -161,9 +180,49 @@ public class AlarmTypeDetailsServiceImpl implements AlarmTypeDetailsService {
|
|
|
alarmDetailsEntity.setStatus(StatusEnum.OK.getCode());
|
|
|
alarmDetailsEntity.setState(AlarmStateEnum.REALTIME_ALARM.getCode());
|
|
|
alarmDetailsEntity.setDateCreate(new Date());
|
|
|
+ deviceName = sceneVo.getDeviceName();
|
|
|
+ sendMessage(alarmDetailsEntity, attrName, deviceName);
|
|
|
result.add(alarmDetailsEntity);
|
|
|
}
|
|
|
+
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ private void sendMessage(AlarmDetailsEntity alarmDetailsEntity, String attrName, String deviceName){
|
|
|
+ Message message = new Message();
|
|
|
+ message.setStatus(1);
|
|
|
+ message.setTenantId(alarmDetailsEntity.getTenantId());
|
|
|
+ message.setMessageId(UUID.randomUUID().toString());
|
|
|
+ JSONObject jsonContent = new JSONObject();
|
|
|
+ // ${场景名称}${设备名称}【${报警字段}】异常报警
|
|
|
+ jsonContent.put("场景名称",alarmDetailsEntity.getSceneName());
|
|
|
+ jsonContent.put("设备名称",deviceName);
|
|
|
+ jsonContent.put("报警字段", attrName);
|
|
|
+ // 消息内容,如果需要动态使用,配合模板使用{key:value}
|
|
|
+ message.setMessageContent(jsonContent.toJSONString());
|
|
|
+ // 消息类型、模板id、渠道
|
|
|
+ message.setMessageType(1);
|
|
|
+ message.setMessageTemplateId(1);
|
|
|
+ message.setChannel(0);
|
|
|
+ Integer companyOrgId = alarmDetailsEntity.getCompanyOrgId();
|
|
|
+ Integer departmentOrgId = alarmDetailsEntity.getDeptOrgId();
|
|
|
+ try{
|
|
|
+ List<Integer> taskUsers = userCenterClient.findUserIdsByPermissonOrg(alarmDetailsEntity.getTenantId(),companyOrgId,departmentOrgId);
|
|
|
+ if (taskUsers == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ taskUsers.forEach(id -> {
|
|
|
+ message.setUserId(id);
|
|
|
+ this.send(message);
|
|
|
+ });
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error ("推送报警消息失败:{}",e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void send(Message message){
|
|
|
+ log.debug("消息发送 exchange={} routingkey={} 用户id={}",receiveExchangeName,dispathRoutingKey,message.getUserId());
|
|
|
+ amqpTemplate.convertAndSend(receiveExchangeName, dispathRoutingKey, JSONObject.toJSONString(message));
|
|
|
+ }
|
|
|
+
|
|
|
}
|