沙钢智慧能源系统后端代码
潘志宝
2024-12-11 17a6e42c685b7aee80a953f182ab514db2643fe0
shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/ModelPredictFinishConsumer.java
@@ -46,11 +46,15 @@
     */
    @RabbitListener(queues = QueuePredictFinishConfig.QUEUE_NAME)
    public void listen(Message message) {
        try {
        String routingKey = message.getMessageProperties().getReceivedRoutingKey();
        log.info("routingKey:" + routingKey);
        String messageBody = new String(message.getBody());
        log.info("messageBody:" + messageBody);
        JSONObject messageJson = JSONObject.parseObject(messageBody);
            if (CollectionUtils.isEmpty(messageJson)) {
                return;
            }
        List<AlarmConfigRespDTO> configList = mcsApi.listAlarmConfig(new HashMap<String, Object>());
        if (CollectionUtils.isEmpty(configList)) {
            return;
@@ -85,13 +89,18 @@
                        alarmMessage.setAlarmType("2");//超上限
                    }
                    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", alarmMessage.getAlarmType());
                    content.put("unit", item.getUnit());
                    content.put("overLimitTime", data[0]);
                    content.put("overLimitValue", dataValue);
                    alarmMessage.setContent(JSONObject.toJSONString(content));
                        StringBuffer sb = new StringBuffer();
                        sb.append(data[0]);
                        sb.append(" ");
                        sb.append(item.getAlarmObj());
                        if ("1".equals(alarmMessage.getAlarmType())) {
                            sb.append("超下限");
                        } else if ("2".equals(alarmMessage.getAlarmType())) {
                            sb.append("超上限");
                        }
                        sb.append(dataValue);
                        sb.append(item.getUnit());
                        alarmMessage.setContent(sb.toString());
                    System.out.println("预警消息=" + alarmMessage);
                    rabbitTemplate.convertAndSend(RoutingConstant.EXCHANGE, RoutingConstant.Iailab_Model_Alarm, alarmMessage);
                    break;
@@ -99,5 +108,9 @@
            }
            System.out.println(preData);
        });
        } catch (Exception e) {
            return;
        }
    }
}