From 2ee54ad8c0b9b081479b178fdcf3105cc2865b76 Mon Sep 17 00:00:00 2001 From: 潘志宝 <979469083@qq.com> Date: 星期一, 20 一月 2025 23:54:39 +0800 Subject: [PATCH] 煤气模型调度 --- shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/ModelAlarmConsumer.java | 44 +++++++++++++++++++++++++++++++++----------- shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/ModelPredictFinishConsumer.java | 3 +++ 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/ModelAlarmConsumer.java b/shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/ModelAlarmConsumer.java index 846333f..85e7427 100644 --- a/shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/ModelAlarmConsumer.java +++ b/shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/ModelAlarmConsumer.java @@ -1,5 +1,6 @@ package com.iailab.module.shasteel.mq.consumer; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.iailab.framework.common.util.date.DateUtils; import com.iailab.module.model.api.mcs.McsApi; @@ -13,16 +14,14 @@ import com.iailab.module.shasteel.mq.common.constant.CommonConstant; import com.iailab.module.shasteel.mq.config.QueueModelAlarmConfig; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.amqp.core.Message; import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; import javax.annotation.Resource; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; +import java.util.*; /** * 监听报警信息 @@ -57,27 +56,36 @@ log.info("routingKey:" + routingKey); String messageBody = new String(message.getBody()); log.info("messageBody:" + messageBody); - JSONObject messageJson = JSONObject.parseObject(messageBody); + Map<String, Object> messageJson = JSONObject.parseObject(messageBody); if (CollectionUtils.isEmpty(messageJson)) { return; } + Date predictTime = DateUtils.parse(messageJson.get("predictTime").toString(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND); + // 查找需要执行的调度方案 List<StScheduleSchemeDTO> scheduleSchemeList = mcsApi.listScheduleScheme(ScheduleTriggerMethodEnum.EVENT.getCode(), routingKey); for(StScheduleSchemeDTO stScheduleSchemeDTO : scheduleSchemeList){ MdkScheduleReqDTO mdkScheduleReqDTO = new MdkScheduleReqDTO(); mdkScheduleReqDTO.setScheduleCode(stScheduleSchemeDTO.getCode()); mdkScheduleReqDTO.setScheduleTime(stScheduleSchemeDTO.getScheduleTime()); - MdkScheduleRespDTO mdkScheduleRespDTO = mdkApi.doSchedule(mdkScheduleReqDTO);//执行调度方案 + //执行调度方案 + MdkScheduleRespDTO mdkScheduleRespDTO = mdkApi.doSchedule(mdkScheduleReqDTO); if(mdkScheduleRespDTO == null){ return; } - AlarmMessageRespDTO alarmRespDTO = (AlarmMessageRespDTO)messageJson.get("AlarmMessageRespDTO"); - alarmRespDTO.setId(UUID.randomUUID().toString()); - alarmRespDTO.setAlarmTime(DateUtils.parse(messageJson.get("predictTime").toString(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); - mcsApi.createAlarmMessage(alarmRespDTO); Map<String, Object> result = mdkScheduleRespDTO.getResult(); switch (mdkScheduleRespDTO.getScheduleCode()) { - case CommonConstant.OXYGEN_ONE_CODE://氧气班平衡计划方案 + case CommonConstant.GAS_MODEL_CODE: + String sch_obj_gas = "GAS"; + saveScheduleSuggest("adviceBFG", result.get("adviceBFG"), sch_obj_gas, predictTime); + saveScheduleSuggest("adviceCOG", result.get("adviceCOG"), sch_obj_gas, predictTime); + saveScheduleSuggest("adviceLDG13W", result.get("adviceLDG13W"), sch_obj_gas, predictTime); + saveScheduleSuggest("adviceLDG12W", result.get("adviceLDG12W"), sch_obj_gas, predictTime); + saveScheduleSuggest("adviceLDG12WT", result.get("adviceLDG12WT"), sch_obj_gas, predictTime); + // 结果写入测点 + mdkApi.scheduleModelOut(mdkScheduleRespDTO); + break; + case CommonConstant.OXYGEN_ONE_CODE: if(!result.containsKey("faAdvice") || !result.containsKey("yingDiAdvice") || !result.containsKey("yingZhongAdvice") || !result.containsKey("hongAdvice") || !result.containsKey("RunAdvice")){ return; @@ -163,4 +171,18 @@ } } } + + private void saveScheduleSuggest(String title, Object content, String scheduleObj, Date scheduleTime) { + if (content == null || StringUtils.isBlank(content.toString()) || "0".equals(content.toString())) { + log.info(title + "content为空"); + return; + } + ScheduleSuggestRespDTO suggest = new ScheduleSuggestRespDTO(); + suggest.setTitle(title); + suggest.setContent(content.toString()); + suggest.setScheduleObj(scheduleObj); + suggest.setScheduleTime(scheduleTime); + suggest.setSort(0); + mcsApi.createScheduleSuggest(suggest); + } } \ No newline at end of file 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 35368f1..d042091 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 @@ -151,6 +151,9 @@ } if (!CollectionUtils.isEmpty(alarmList)) { log.info("发送预警消息"); + Map<String, Object> msg = new HashMap<>(2); + msg.put("predictTime", predictTime); + msg.put("alarmList", alarmList); rabbitTemplate.convertAndSend(RoutingConstant.EXCHANGE, RoutingConstant.Iailab_Model_Alarm, alarmList); } } catch (Exception e) { -- Gitblit v1.9.3