沙钢智慧能源系统后端代码
liriming
2 天以前 b7245f9d1308595e1405d11ffb524d96a2c8a7a8
提交 | 用户 | 时间
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());
64e8b5 86                             suggestRespDTO.setScheduleObj(stScheduleSchemeDTO.getScheduleObj());
456a64 87                             suggestRespDTO.setContent(result.get("dispatchStart").toString());//空压机启动调度建议
L 88                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
89                             mcsApi.createScheduleSuggest(suggestRespDTO);
90                         }else if("dispatchEnd".equals(key) && !"".equals(result.get("dispatchEnd").toString())){
91                             ScheduleSuggestRespDTO suggestRespDTO = new ScheduleSuggestRespDTO();
92                             suggestRespDTO.setId(UUID.randomUUID().toString());
64e8b5 93                             suggestRespDTO.setScheduleObj(stScheduleSchemeDTO.getScheduleObj());
456a64 94                             suggestRespDTO.setContent(result.get("dispatchClose").toString());//空压机关停调度建议
L 95                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
96                             mcsApi.createScheduleSuggest(suggestRespDTO);
97                         }
cf56eb 98                     }
L 99                     break;
100                 case CommonConstant.STEAM_CODE://蒸汽调度方案
456a64 101                     if(!result.containsKey("daxinWarning") || !result.containsKey("jinfengWarning") || !result.containsKey("zhuanlu1Warning")
L 102                             || !result.containsKey("zhuanlu2Warning") || !result.containsKey("jinfengAdvice") || !result.containsKey("daxinAdvice")){
103                         return;
cf56eb 104                     }
456a64 105                     for (String key : result.keySet()) {
L 106                         if ("daxinWarning".equals(key) && !"".equals(result.get("daxinWarning").toString())) {
107                             AlarmMessageRespDTO alarmRespDTO = new AlarmMessageRespDTO();
108                             alarmRespDTO.setId(UUID.randomUUID().toString());
109                             alarmRespDTO.setContent(result.get("daxinWarning").toString());//大新预警
110                             alarmRespDTO.setAlarmTime(DateUtils.parse(messageJson.get("predictTime").toString(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND));
111                             mcsApi.createAlarmMessage(alarmRespDTO);
112                         }else if ("jinfengWarning".equals(key) && !"".equals(result.get("jinfengWarning").toString())) {
113                             AlarmMessageRespDTO alarmRespDTO = new AlarmMessageRespDTO();
114                             alarmRespDTO.setId(UUID.randomUUID().toString());
115                             alarmRespDTO.setContent(result.get("jinfengWarning").toString());//锦丰预警
116                             alarmRespDTO.setAlarmTime(DateUtils.parse(messageJson.get("predictTime").toString(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND));
117                             mcsApi.createAlarmMessage(alarmRespDTO);
118                         }else if ("zhuanlu1Warning".equals(key) && !"".equals(result.get("zhuanlu1Warning").toString())) {
119                             AlarmMessageRespDTO alarmRespDTO = new AlarmMessageRespDTO();
120                             alarmRespDTO.setId(UUID.randomUUID().toString());
121                             alarmRespDTO.setContent(result.get("zhuanlu1Warning").toString());//转炉一预警
122                             alarmRespDTO.setAlarmTime(DateUtils.parse(messageJson.get("predictTime").toString(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND));
123                             mcsApi.createAlarmMessage(alarmRespDTO);
124                         }else if ("zhuanlu2Warning".equals(key) && !"".equals(result.get("zhuanlu2Warning").toString())) {
125                             AlarmMessageRespDTO alarmRespDTO = new AlarmMessageRespDTO();
126                             alarmRespDTO.setId(UUID.randomUUID().toString());
127                             alarmRespDTO.setContent(result.get("zhuanlu2Warning").toString());//转炉二预警
128                             alarmRespDTO.setAlarmTime(DateUtils.parse(messageJson.get("predictTime").toString(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND));
129                             mcsApi.createAlarmMessage(alarmRespDTO);
130                         }else if ("jinfengAdvice".equals(key) && !"".equals(result.get("jinfengAdvice").toString())) {
131                             ScheduleSuggestRespDTO suggestRespDTO = new ScheduleSuggestRespDTO();
132                             suggestRespDTO.setId(UUID.randomUUID().toString());
64e8b5 133                             suggestRespDTO.setScheduleObj(stScheduleSchemeDTO.getScheduleObj());
456a64 134                             suggestRespDTO.setContent(result.get("jinfengAdvice").toString());//锦丰调度建议
L 135                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
136                             mcsApi.createScheduleSuggest(suggestRespDTO);
137                         }else if ("daxinAdvice".equals(key) && !"".equals(result.get("daxinAdvice").toString())) {
138                             ScheduleSuggestRespDTO suggestRespDTO = new ScheduleSuggestRespDTO();
139                             suggestRespDTO.setId(UUID.randomUUID().toString());
64e8b5 140                             suggestRespDTO.setScheduleObj(stScheduleSchemeDTO.getScheduleObj());
456a64 141                             suggestRespDTO.setContent(result.get("daxinAdvice").toString());//大新调度建议
L 142                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
143                             mcsApi.createScheduleSuggest(suggestRespDTO);
144                         }
cf56eb 145                     }
L 146                     break;
147                 default:
148                     break;
149             }
150         }
151     }
152 }