沙钢智慧能源系统后端代码
潘志宝
2024-12-24 70ef272e51099f11672a103cdf8e41384bd66489
提交 | 用户 | 时间
cf56eb 1 package com.iailab.module.shasteel.mq.consumer;
L 2
3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.JSONObject;
5 import com.iailab.framework.common.util.date.DateUtils;
6 import com.iailab.module.model.api.mcs.McsApi;
7 import com.iailab.module.model.api.mcs.dto.AlarmMessageRespDTO;
8 import com.iailab.module.model.api.mcs.dto.ScheduleSuggestRespDTO;
9 import com.iailab.module.model.api.mcs.dto.StScheduleSchemeDTO;
10 import com.iailab.module.model.api.mdk.MdkApi;
11 import com.iailab.module.model.api.mdk.dto.MdkScheduleReqDTO;
12 import com.iailab.module.model.api.mdk.dto.MdkScheduleRespDTO;
13 import com.iailab.module.shasteel.mq.common.constant.CommonConstant;
14 import com.iailab.module.shasteel.mq.common.enums.TriggerConditionEnum;
15 import com.iailab.module.shasteel.mq.config.QueueModelAlarmConfig;
16 import com.iailab.module.shasteel.mq.config.QueuePredictFinishConfig;
17 import lombok.extern.slf4j.Slf4j;
18 import org.springframework.amqp.core.Message;
19 import org.springframework.amqp.rabbit.annotation.RabbitListener;
20 import org.springframework.stereotype.Component;
21 import org.springframework.util.CollectionUtils;
22
23 import javax.annotation.Resource;
24 import java.util.HashMap;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.UUID;
28
29 /**
30  * 监听报警信息
31  *
32  * @author PanZhibao
33  * @Description
34  * @createTime 2024年12月11日
35  */
36 @Slf4j
37 @Component
38 public class ModelPredictFinish2Consumer {
39
40     @Resource
41     private McsApi mcsApi;
42
43     @Resource
44     private MdkApi mdkApi;
45
46     /**
47      * 监听预测完成,执行调度
48      *
49      * @param message
50      */
51     @RabbitListener(queues = QueuePredictFinishConfig.QUEUE_NAME)
52     public void listen(Message message) {
53         String routingKey = message.getMessageProperties().getReceivedRoutingKey();
54         log.info("routingKey:" + routingKey);
55         String messageBody = new String(message.getBody());
56         log.info("messageBody:" + messageBody);
57         JSONObject messageJson = JSONObject.parseObject(messageBody);
58         if (CollectionUtils.isEmpty(messageJson)) {
59             return;
60         }
61         // 查找需要执行的调度方案
62         Map<String, Object> params = new HashMap<>();
63         params.put("trigger_method", TriggerConditionEnum.EVENT);
64         params.put("trigger_condition", routingKey);
65         List<StScheduleSchemeDTO> scheduleSchemeList = mcsApi.listScheduleScheme(params);//根据触发条件获取调度方案列表
66         for(StScheduleSchemeDTO stScheduleSchemeDTO : scheduleSchemeList){
67             MdkScheduleReqDTO mdkScheduleReqDTO = new MdkScheduleReqDTO();
68             mdkScheduleReqDTO.setScheduleCode(stScheduleSchemeDTO.getCode());
69             mdkScheduleReqDTO.setScheduleTime(stScheduleSchemeDTO.getScheduleTime());
70             MdkScheduleRespDTO mdkScheduleRespDTO = mdkApi.doSchedule(mdkScheduleReqDTO);//执行调度方案
71             if(mdkScheduleRespDTO == null){
72                 return;
73             }
74             Map<String, Object> result = mdkScheduleRespDTO.getResult();
75             switch (mdkScheduleRespDTO.getScheduleCode()) {
76                 case CommonConstant.COMPRESSOR_CODE://压缩空气调度方案
456a64 77                     if(!result.containsKey("pressureWarning") || !result.containsKey("dispatchStart") || !result.containsKey("dispatchEnd")){
L 78                         return;
cf56eb 79                     }
456a64 80                     for (String key : result.keySet()) {
L 81                         if("pressureWarning".equals(key) && !"".equals(result.get("pressureWarning").toString())){
82                             AlarmMessageRespDTO alarmRespDTO = new AlarmMessageRespDTO();
83                             alarmRespDTO.setId(UUID.randomUUID().toString());
84                             alarmRespDTO.setContent(result.get("pressureWarning").toString());//压力预警信息
85                             alarmRespDTO.setAlarmTime(DateUtils.parse(messageJson.get("predictTime").toString(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND));
86                             mcsApi.createAlarmMessage(alarmRespDTO);
87                         }else if("dispatchStart".equals(key) && !"".equals(result.get("dispatchStart").toString())){
88                             ScheduleSuggestRespDTO suggestRespDTO = new ScheduleSuggestRespDTO();
89                             suggestRespDTO.setId(UUID.randomUUID().toString());
90                             suggestRespDTO.setContent(result.get("dispatchStart").toString());//空压机启动调度建议
91                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
92                             mcsApi.createScheduleSuggest(suggestRespDTO);
93                         }else if("dispatchEnd".equals(key) && !"".equals(result.get("dispatchEnd").toString())){
94                             ScheduleSuggestRespDTO suggestRespDTO = new ScheduleSuggestRespDTO();
95                             suggestRespDTO.setId(UUID.randomUUID().toString());
96                             suggestRespDTO.setContent(result.get("dispatchClose").toString());//空压机关停调度建议
97                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
98                             mcsApi.createScheduleSuggest(suggestRespDTO);
99                         }
cf56eb 100                     }
L 101                     break;
102                 case CommonConstant.STEAM_CODE://蒸汽调度方案
456a64 103                     if(!result.containsKey("daxinWarning") || !result.containsKey("jinfengWarning") || !result.containsKey("zhuanlu1Warning")
L 104                             || !result.containsKey("zhuanlu2Warning") || !result.containsKey("jinfengAdvice") || !result.containsKey("daxinAdvice")){
105                         return;
cf56eb 106                     }
456a64 107                     for (String key : result.keySet()) {
L 108                         if ("daxinWarning".equals(key) && !"".equals(result.get("daxinWarning").toString())) {
109                             AlarmMessageRespDTO alarmRespDTO = new AlarmMessageRespDTO();
110                             alarmRespDTO.setId(UUID.randomUUID().toString());
111                             alarmRespDTO.setContent(result.get("daxinWarning").toString());//大新预警
112                             alarmRespDTO.setAlarmTime(DateUtils.parse(messageJson.get("predictTime").toString(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND));
113                             mcsApi.createAlarmMessage(alarmRespDTO);
114                         }else if ("jinfengWarning".equals(key) && !"".equals(result.get("jinfengWarning").toString())) {
115                             AlarmMessageRespDTO alarmRespDTO = new AlarmMessageRespDTO();
116                             alarmRespDTO.setId(UUID.randomUUID().toString());
117                             alarmRespDTO.setContent(result.get("jinfengWarning").toString());//锦丰预警
118                             alarmRespDTO.setAlarmTime(DateUtils.parse(messageJson.get("predictTime").toString(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND));
119                             mcsApi.createAlarmMessage(alarmRespDTO);
120                         }else if ("zhuanlu1Warning".equals(key) && !"".equals(result.get("zhuanlu1Warning").toString())) {
121                             AlarmMessageRespDTO alarmRespDTO = new AlarmMessageRespDTO();
122                             alarmRespDTO.setId(UUID.randomUUID().toString());
123                             alarmRespDTO.setContent(result.get("zhuanlu1Warning").toString());//转炉一预警
124                             alarmRespDTO.setAlarmTime(DateUtils.parse(messageJson.get("predictTime").toString(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND));
125                             mcsApi.createAlarmMessage(alarmRespDTO);
126                         }else if ("zhuanlu2Warning".equals(key) && !"".equals(result.get("zhuanlu2Warning").toString())) {
127                             AlarmMessageRespDTO alarmRespDTO = new AlarmMessageRespDTO();
128                             alarmRespDTO.setId(UUID.randomUUID().toString());
129                             alarmRespDTO.setContent(result.get("zhuanlu2Warning").toString());//转炉二预警
130                             alarmRespDTO.setAlarmTime(DateUtils.parse(messageJson.get("predictTime").toString(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND));
131                             mcsApi.createAlarmMessage(alarmRespDTO);
132                         }else if ("jinfengAdvice".equals(key) && !"".equals(result.get("jinfengAdvice").toString())) {
133                             ScheduleSuggestRespDTO suggestRespDTO = new ScheduleSuggestRespDTO();
134                             suggestRespDTO.setId(UUID.randomUUID().toString());
135                             suggestRespDTO.setContent(result.get("jinfengAdvice").toString());//锦丰调度建议
136                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
137                             mcsApi.createScheduleSuggest(suggestRespDTO);
138                         }else if ("daxinAdvice".equals(key) && !"".equals(result.get("daxinAdvice").toString())) {
139                             ScheduleSuggestRespDTO suggestRespDTO = new ScheduleSuggestRespDTO();
140                             suggestRespDTO.setId(UUID.randomUUID().toString());
141                             suggestRespDTO.setContent(result.get("daxinAdvice").toString());//大新调度建议
142                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
143                             mcsApi.createScheduleSuggest(suggestRespDTO);
144                         }
cf56eb 145                     }
L 146                     break;
147                 default:
148                     break;
149             }
150         }
151     }
152 }