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