From c9ff6a7f2e89f751e2eec68ec02fa93919d05296 Mon Sep 17 00:00:00 2001 From: 潘志宝 <979469083@qq.com> Date: 星期三, 11 十二月 2024 13:56:59 +0800 Subject: [PATCH] 监听报警信息 --- shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/ModelPredictFinishConsumer.java | 35 +++++++++++++++++++---------------- 1 files changed, 19 insertions(+), 16 deletions(-) diff --git a/shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/ModelPredictFinishConsumer.java b/shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/ModelPredictFinishConsumer.java index 971d2a9..0bee1be 100644 --- a/shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/ModelPredictFinishConsumer.java +++ b/shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/ModelPredictFinishConsumer.java @@ -6,10 +6,12 @@ import com.iailab.module.model.api.mcs.dto.AlarmConfigRespDTO; import com.iailab.module.model.api.mcs.dto.AlarmMessageRespDTO; import com.iailab.module.model.api.mcs.dto.PreDataJsonReqVO; +import com.iailab.module.shasteel.mq.common.RoutingConstant; import com.iailab.module.shasteel.mq.config.QueuePredictFinishConfig; import lombok.extern.slf4j.Slf4j; import org.springframework.amqp.core.Message; import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; @@ -21,6 +23,8 @@ import java.util.Map; /** + * 监听预测完成 + * * @author PanZhibao * @Description * @createTime 2024年12月11日 @@ -33,8 +37,13 @@ private McsApi mcsApi; @Resource - private AlarmConsumer alarmConsumer; + private RabbitTemplate rabbitTemplate; + /** + * 监听预测完成,产生预警消息 + * + * @param message + */ @RabbitListener(queues = QueuePredictFinishConfig.QUEUE_NAME) public void listen(Message message) { String routingKey = message.getMessageProperties().getReceivedRoutingKey(); @@ -68,29 +77,23 @@ for (Object[] data : predictList) { BigDecimal dataValue = new BigDecimal(Double.parseDouble(data[1].toString())).setScale(2, BigDecimal.ROUND_HALF_UP); if (!(dataValue.compareTo(item.getLowerLimit()) >= 0 && dataValue.compareTo(item.getUpperLimit()) <= 0)) { - AlarmMessage alarmMessage = new AlarmMessage(); - AlarmMessageRespDTO alarmMessageRespDTO = new AlarmMessageRespDTO(); - alarmMessageRespDTO.setConfigId(item.getId()); + AlarmMessageRespDTO alarmMessage = new AlarmMessageRespDTO(); + alarmMessage.setConfigId(item.getId()); if (dataValue.compareTo(item.getLowerLimit()) < 0) { - alarmMessageRespDTO.setAlarmType("1");//超下限 + alarmMessage.setAlarmType("1");//超下限 } else if (dataValue.compareTo(item.getUpperLimit()) > 0) { - alarmMessageRespDTO.setAlarmType("2");//超上限 + alarmMessage.setAlarmType("2");//超上限 } - alarmMessageRespDTO.setAlarmTime(DateUtils.parse(data[0].toString(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); + alarmMessage.setAlarmTime(DateUtils.parse(data[0].toString(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); JSONObject content = new JSONObject(); content.put("alarmObj", item.getAlarmObj()); - content.put("alarmType", alarmMessageRespDTO.getAlarmType()); + content.put("alarmType", alarmMessage.getAlarmType()); content.put("unit", item.getUnit()); content.put("overLimitTime", data[0]); content.put("overLimitValue", dataValue); - alarmMessageRespDTO.setContent(JSONObject.toJSONString(content)); - System.out.println("预警消息=" + alarmMessageRespDTO); - alarmMessage.setAlarmMessageRespDTO(alarmMessageRespDTO); - try { - alarmConsumer.process(alarmMessage); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } + alarmMessage.setContent(JSONObject.toJSONString(content)); + System.out.println("预警消息=" + alarmMessage); + rabbitTemplate.convertAndSend(RoutingConstant.EXCHANGE, RoutingConstant.Iailab_Model_Alarm, alarmMessage); break; } } -- Gitblit v1.9.3