|
@@ -14,12 +14,12 @@ import com.huaxu.common.StringUtils;
|
|
import com.huaxu.dao.AlarmDetailMapper;
|
|
import com.huaxu.dao.AlarmDetailMapper;
|
|
import com.huaxu.dto.AlarmDetailsDto;
|
|
import com.huaxu.dto.AlarmDetailsDto;
|
|
import com.huaxu.dto.DeviceCheckAlarmDto;
|
|
import com.huaxu.dto.DeviceCheckAlarmDto;
|
|
|
|
+import com.huaxu.dto.WorkOrderManageByAlarmDto;
|
|
import com.huaxu.entity.AlarmDetailsEntity;
|
|
import com.huaxu.entity.AlarmDetailsEntity;
|
|
import com.huaxu.entity.Message;
|
|
import com.huaxu.entity.Message;
|
|
import com.huaxu.entity.MonitorDataEntity;
|
|
import com.huaxu.entity.MonitorDataEntity;
|
|
import com.huaxu.entity.MonitorDataValueEntity;
|
|
import com.huaxu.entity.MonitorDataValueEntity;
|
|
import com.huaxu.service.MonitorDataService;
|
|
import com.huaxu.service.MonitorDataService;
|
|
-import com.huaxu.util.MessageSendUtil;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang.exception.ExceptionUtils;
|
|
import org.apache.commons.lang.exception.ExceptionUtils;
|
|
import org.springframework.amqp.core.AmqpTemplate;
|
|
import org.springframework.amqp.core.AmqpTemplate;
|
|
@@ -31,9 +31,11 @@ import org.springframework.context.annotation.Bean;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+import java.awt.*;
|
|
import java.text.ParseException;
|
|
import java.text.ParseException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
+import java.util.List;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Component
|
|
@Component
|
|
@@ -41,18 +43,19 @@ import java.util.stream.Collectors;
|
|
public class ReceiveData {
|
|
public class ReceiveData {
|
|
|
|
|
|
|
|
|
|
- @Autowired
|
|
|
|
- private AmqpTemplate rabbitTemplate;
|
|
|
|
|
|
+ @Resource(name = "messageRabbitTemplate")
|
|
|
|
+ private AmqpTemplate messageRabbitTemplate;
|
|
|
|
+
|
|
|
|
+ @Resource(name = "receiveDataRabbitTemplate")
|
|
|
|
+ private AmqpTemplate receiveDataRabbitTemplate;
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
private AlarmDetailMapper alarmDetailMapper;
|
|
private AlarmDetailMapper alarmDetailMapper;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private UserCenterClient userCenterClient;
|
|
private UserCenterClient userCenterClient;
|
|
- @Autowired
|
|
|
|
- private MessageSendUtil messageSendUtil;
|
|
|
|
|
|
|
|
- @Value("${spring.rabbitmq.listener.queue}")
|
|
|
|
|
|
+ @Value("${receiveData.spring.rabbitmq.listener.queue}")
|
|
private String rabbitmqQueue;
|
|
private String rabbitmqQueue;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
@@ -69,17 +72,28 @@ public class ReceiveData {
|
|
return rabbitmqQueue;
|
|
return rabbitmqQueue;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Value("${receive.exchange.name}")
|
|
|
|
+ private String receiveExchangeName;
|
|
|
|
+ @Value("${dispath.routing.key}")
|
|
|
|
+ private String dispathRoutingKey;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private void send(Message message){
|
|
|
|
+ log.debug("消息发送 exchange={} routingkey={} 用户id={}",receiveExchangeName,dispathRoutingKey,message.getUserId());
|
|
|
|
+ messageRabbitTemplate.convertAndSend(receiveExchangeName,dispathRoutingKey, JSONObject.toJSONString(message));
|
|
|
|
+ }
|
|
|
|
+
|
|
@RabbitHandler
|
|
@RabbitHandler
|
|
- @RabbitListener(queues = "#{rabbitmqQueue}")
|
|
|
|
|
|
+ @RabbitListener(queues = "#{rabbitmqQueue}",containerFactory = "receiveDataContainerFactory")
|
|
public void received(byte[] receivedData) {
|
|
public void received(byte[] receivedData) {
|
|
|
|
|
|
try {
|
|
try {
|
|
- log.info("rabbitMq接收消息:"+new String(receivedData));
|
|
|
|
|
|
+ log.debug("rabbitMq接收消息:"+new String(receivedData));
|
|
receivedDataHandle(receivedData);
|
|
receivedDataHandle(receivedData);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
log.error(ExceptionUtils.getStackTrace(e));
|
|
log.error(ExceptionUtils.getStackTrace(e));
|
|
// 发送异常时消息返回队列
|
|
// 发送异常时消息返回队列
|
|
- rabbitTemplate.convertAndSend(rabbitmqQueue, receivedData);
|
|
|
|
|
|
+// receiveDataRabbitTemplate.convertAndSend(rabbitmqQueue, receivedData);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
@@ -151,7 +165,7 @@ public class ReceiveData {
|
|
if(deviceCheckAlarmDtos.size()>0 && StringUtils.isNotBlank(deviceCheckAlarmDtos.get(0).getIdentifiter())){
|
|
if(deviceCheckAlarmDtos.size()>0 && StringUtils.isNotBlank(deviceCheckAlarmDtos.get(0).getIdentifiter())){
|
|
Integer deviceId= deviceCheckAlarmDtos.get(0).getDeviceId();
|
|
Integer deviceId= deviceCheckAlarmDtos.get(0).getDeviceId();
|
|
//系统中已存在的报警信息
|
|
//系统中已存在的报警信息
|
|
- List<AlarmDetailsDto> alarmDetailsDtos = alarmDetailMapper.selectStateAlarm(deviceId,"参数报警");
|
|
|
|
|
|
+ List<AlarmDetailsDto> alarmDetailsDtos = alarmDetailMapper.selectStateAlarm(deviceId,"参数报警",null);
|
|
//已存在的报警信息转为map方便匹配alarmSettingId
|
|
//已存在的报警信息转为map方便匹配alarmSettingId
|
|
Map<Integer,AlarmDetailsDto> alarmDetailsDtoMap = alarmDetailsDtos.stream().collect(Collectors.toMap(AlarmDetailsDto::getAlarmSettingId, a -> a,(k1, k2)->k1));
|
|
Map<Integer,AlarmDetailsDto> alarmDetailsDtoMap = alarmDetailsDtos.stream().collect(Collectors.toMap(AlarmDetailsDto::getAlarmSettingId, a -> a,(k1, k2)->k1));
|
|
|
|
|
|
@@ -224,7 +238,7 @@ public class ReceiveData {
|
|
if(taskUsers!=null){
|
|
if(taskUsers!=null){
|
|
taskUsers.forEach(id->{
|
|
taskUsers.forEach(id->{
|
|
message.setUserId(id);
|
|
message.setUserId(id);
|
|
- messageSendUtil.send(message);
|
|
|
|
|
|
+ this.send(message);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
}catch(Exception e){
|
|
}catch(Exception e){
|
|
@@ -236,32 +250,53 @@ public class ReceiveData {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- //处理完成后,剩下的标记为历史数据
|
|
|
|
- for(AlarmDetailsDto alarmDetailsDto:alarmDetailsDtoMap.values()){
|
|
|
|
- alarmDetailsDto.setState(0);
|
|
|
|
- alarmDetailsDto.setAlarmEndTime(receiveDateTime);
|
|
|
|
- alarmDetailsDto.setDateUpdate(new Date());
|
|
|
|
- alarmDetailMapper.update(alarmDetailsDto);
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
//批量插入新增报警
|
|
//批量插入新增报警
|
|
if(insert.size()>0){
|
|
if(insert.size()>0){
|
|
alarmDetailMapper.batchInsert(insert);
|
|
alarmDetailMapper.batchInsert(insert);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if(alarmDetailsDtoMap.values().size() > 0){
|
|
|
|
+ //处理完成后,剩下的标记为历史数据
|
|
|
|
+ List<Long> deviceIds = new ArrayList<>();
|
|
|
|
+ deviceIds.add(monitorDataEntity.getDeviceId().longValue());
|
|
|
|
+ List<WorkOrderManageByAlarmDto> workOrders = operationManagerClient.findWorkOrderByDeviceIds(deviceIds);
|
|
|
|
+ if(workOrders.size()>0){
|
|
|
|
+ WorkOrderManageByAlarmDto orderManageByAlarmDto = workOrders.get(0);
|
|
|
|
+ String taskDesc = orderManageByAlarmDto.getTaskDesc();
|
|
|
|
+ //标记为历史数据 并 修改工单描述
|
|
|
|
+ for(AlarmDetailsDto alarmDetailsDto : alarmDetailsDtoMap.values()){
|
|
|
|
+ alarmDetailsDto.setState(0);
|
|
|
|
+ alarmDetailsDto.setAlarmEndTime(receiveDateTime);
|
|
|
|
+ alarmDetailsDto.setDateUpdate(new Date());
|
|
|
|
+ alarmDetailMapper.update(alarmDetailsDto);
|
|
|
|
+
|
|
|
|
+ taskDesc = taskDesc.replace(";"+alarmDetailsDto.getAlarmContent(),"")
|
|
|
|
+ .replace(alarmDetailsDto.getAlarmContent(),"");
|
|
|
|
+ }
|
|
|
|
+ orderManageByAlarmDto.setTaskDesc(taskDesc);
|
|
|
|
+ if(orderManageByAlarmDto != null
|
|
|
|
+ && (orderManageByAlarmDto.getOrderStatus() == null || orderManageByAlarmDto.getOrderStatus() == 0)
|
|
|
|
+ && StringUtils.isBlank(taskDesc)){
|
|
|
|
+ //工单未派单且无报警信息,删除工单
|
|
|
|
+ operationManagerClient.batchDeleteByAlarms(new ArrayList<>(deviceIds));
|
|
|
|
+ }else{
|
|
|
|
+ //其他情况修改描述
|
|
|
|
+ operationManagerClient.updateByAlarms(workOrders);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
//报警恢复的删除工单
|
|
//报警恢复的删除工单
|
|
- Map<Integer,AlarmDetailsEntity> AlarmDtoNewsMap = insert.stream().collect(Collectors.toMap(AlarmDetailsEntity::getDeviceId, a -> a,(k1, k2)->k1));
|
|
|
|
- Map<Integer,AlarmDetailsEntity> AlarmDtoOldsMap = update.stream().collect(Collectors.toMap(AlarmDetailsEntity::getDeviceId, a -> a,(k1, k2)->k1));
|
|
|
|
- Set<Long> deviceIds = alarmDetailsDtoMap.values().stream()
|
|
|
|
- .filter(a -> !(AlarmDtoNewsMap.containsKey(a.getDeviceId())||AlarmDtoOldsMap.containsKey(a.getDeviceId())))
|
|
|
|
- .map(a -> a.getDeviceId().longValue())
|
|
|
|
- .collect(Collectors.toSet());
|
|
|
|
- if(deviceIds.size()>0){
|
|
|
|
- operationManagerClient.batchDeleteByAlarms(new ArrayList<>(deviceIds));
|
|
|
|
- }
|
|
|
|
|
|
+// Map<Integer,AlarmDetailsEntity> AlarmDtoOldsMap = update.stream().collect(Collectors.toMap(AlarmDetailsEntity::getDeviceId, a -> a,(k1, k2)->k1));
|
|
|
|
+// Set<Long> deviceIds = alarmDetailsDtoMap.values().stream()
|
|
|
|
+// .filter(a -> !AlarmDtoOldsMap.containsKey(a.getDeviceId()))
|
|
|
|
+// .map(a -> a.getDeviceId().longValue())
|
|
|
|
+// .collect(Collectors.toSet());
|
|
|
|
+// if(deviceIds.size()>0){
|
|
|
|
+// operationManagerClient.batchDeleteByAlarms(new ArrayList<>(deviceIds));
|
|
|
|
+// }
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|