沙钢智慧能源系统后端代码
潘志宝
5 天以前 7c1d912558f9917f06a520fc8153f01426b1de76
提交 | 用户 | 时间
c9ff6a 1 package com.iailab.module.shasteel.mq.consumer;
2
cf56eb 3 import com.alibaba.fastjson.JSONObject;
456a64 4 import com.iailab.framework.common.util.date.DateUtils;
c9ff6a 5 import com.iailab.module.model.api.mcs.McsApi;
cf56eb 6 import com.iailab.module.model.api.mcs.dto.AlarmMessageRespDTO;
456a64 7 import com.iailab.module.model.api.mcs.dto.ScheduleSuggestRespDTO;
d66e44 8 import com.iailab.module.model.api.mcs.dto.StScheduleSchemeDTO;
L 9 import com.iailab.module.model.api.mdk.MdkApi;
10 import com.iailab.module.model.api.mdk.dto.MdkScheduleReqDTO;
cf56eb 11 import com.iailab.module.model.api.mdk.dto.MdkScheduleRespDTO;
7c1d91 12 import com.iailab.module.model.enums.ScheduleTriggerMethodEnum;
456a64 13 import com.iailab.module.shasteel.mq.common.constant.CommonConstant;
c9ff6a 14 import com.iailab.module.shasteel.mq.config.QueueModelAlarmConfig;
15 import lombok.extern.slf4j.Slf4j;
16 import org.springframework.amqp.core.Message;
17 import org.springframework.amqp.rabbit.annotation.RabbitListener;
18 import org.springframework.stereotype.Component;
cf56eb 19 import org.springframework.util.CollectionUtils;
c9ff6a 20
21 import javax.annotation.Resource;
d66e44 22 import java.util.HashMap;
L 23 import java.util.List;
24 import java.util.Map;
456a64 25 import java.util.UUID;
c9ff6a 26
27 /**
28  * 监听报警信息
29  *
30  * @author PanZhibao
31  * @Description
32  * @createTime 2024年12月11日
33  */
34 @Slf4j
35 @Component
36 public class ModelAlarmConsumer {
37
38     @Resource
39     private McsApi mcsApi;
40
d66e44 41     @Resource
L 42     private MdkApi mdkApi;
43
c9ff6a 44     /**
45      * 事件标识
46      */
47     private final String EVENT_FLAG = "GasAlarm";
48
49     /**
50      * 监听报警信息,执行调度
51      *
52      * @param message
53      */
54     @RabbitListener(queues = QueueModelAlarmConfig.QUEUE_NAME)
55     public void listen(Message message) {
d66e44 56         String routingKey = message.getMessageProperties().getReceivedRoutingKey();
L 57         log.info("routingKey:" + routingKey);
58         String messageBody = new String(message.getBody());
59         log.info("messageBody:" + messageBody);
cf56eb 60         JSONObject messageJson = JSONObject.parseObject(messageBody);
L 61         if (CollectionUtils.isEmpty(messageJson)) {
62             return;
63         }
c9ff6a 64         // 查找需要执行的调度方案
7c1d91 65         List<StScheduleSchemeDTO> scheduleSchemeList = mcsApi.listScheduleScheme(ScheduleTriggerMethodEnum.EVENT.getCode(), routingKey);
d66e44 66         for(StScheduleSchemeDTO stScheduleSchemeDTO : scheduleSchemeList){
L 67             MdkScheduleReqDTO mdkScheduleReqDTO = new MdkScheduleReqDTO();
68             mdkScheduleReqDTO.setScheduleCode(stScheduleSchemeDTO.getCode());
69             mdkScheduleReqDTO.setScheduleTime(stScheduleSchemeDTO.getScheduleTime());
cf56eb 70             MdkScheduleRespDTO mdkScheduleRespDTO = mdkApi.doSchedule(mdkScheduleReqDTO);//执行调度方案
456a64 71             if(mdkScheduleRespDTO == null){
L 72                 return;
73             }
74             AlarmMessageRespDTO alarmRespDTO = (AlarmMessageRespDTO)messageJson.get("AlarmMessageRespDTO");
75             alarmRespDTO.setId(UUID.randomUUID().toString());
76             alarmRespDTO.setAlarmTime(DateUtils.parse(messageJson.get("predictTime").toString(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND));
77             mcsApi.createAlarmMessage(alarmRespDTO);
78             Map<String, Object> result = mdkScheduleRespDTO.getResult();
79             switch (mdkScheduleRespDTO.getScheduleCode()) {
80                 case CommonConstant.OXYGEN_ONE_CODE://氧气班平衡计划方案
81                     if(!result.containsKey("faAdvice") || !result.containsKey("yingDiAdvice") || !result.containsKey("yingZhongAdvice")
82                             || !result.containsKey("hongAdvice") || !result.containsKey("RunAdvice")){
83                         return;
84                     }
85                     for (String key : result.keySet()) {
86                         if ("faAdvice".equals(key) && !"".equals(result.get("faAdvice").toString())) {
87                             ScheduleSuggestRespDTO suggestRespDTO = new ScheduleSuggestRespDTO();
88                             suggestRespDTO.setId(UUID.randomUUID().toString());
89                             suggestRespDTO.setContent(result.get("faAdvice").toString());//法夜空建议送出量建议
90                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
91                             mcsApi.createScheduleSuggest(suggestRespDTO);
92                         }else if ("yingDiAdvice".equals(key) && !"".equals(result.get("yingDiAdvice").toString())) {
93                             ScheduleSuggestRespDTO suggestRespDTO = new ScheduleSuggestRespDTO();
94                             suggestRespDTO.setId(UUID.randomUUID().toString());
95                             suggestRespDTO.setContent(result.get("yingDiAdvice").toString());//盈德低压建议送出量建议
96                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
97                             mcsApi.createScheduleSuggest(suggestRespDTO);
98                         }else if ("yingZhongAdvice".equals(key) && !"".equals(result.get("yingZhongAdvice").toString())) {
99                             ScheduleSuggestRespDTO suggestRespDTO = new ScheduleSuggestRespDTO();
100                             suggestRespDTO.setId(UUID.randomUUID().toString());
101                             suggestRespDTO.setContent(result.get("yingZhongAdvice").toString());//盈德中压建议送出量建议
102                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
103                             mcsApi.createScheduleSuggest(suggestRespDTO);
104                         }else if ("hongAdvice".equals(key) && !"".equals(result.get("hongAdvice").toString())) {
105                             ScheduleSuggestRespDTO suggestRespDTO = new ScheduleSuggestRespDTO();
106                             suggestRespDTO.setId(UUID.randomUUID().toString());
107                             suggestRespDTO.setContent(result.get("hongAdvice").toString());//宏昌建议送出量建议
108                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
109                             mcsApi.createScheduleSuggest(suggestRespDTO);
110                         }else if ("RunAdvice".equals(key) && !"".equals(result.get("RunAdvice").toString())) {
111                             ScheduleSuggestRespDTO suggestRespDTO = new ScheduleSuggestRespDTO();
112                             suggestRespDTO.setId(UUID.randomUUID().toString());
113                             suggestRespDTO.setContent(result.get("RunAdvice").toString());//润忠建议送出量建议
114                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
115                             mcsApi.createScheduleSuggest(suggestRespDTO);
116                         }
117                     }
118                     break;
119                 case CommonConstant.OXYGEN_TWO_CODE://氧气系统优化调度决策方案
120                     if(!result.containsKey("yingdiAdvice") || !result.containsKey("faAdvice") || !result.containsKey("hongAdvice")
121                             || !result.containsKey("RunAdvice")){
122                         return;
123                     }
124                     for (String key : result.keySet()) {
125                         if ("yingdiAdvice".equals(key) && !"".equals(result.get("yingdiAdvice").toString())) {
126                             ScheduleSuggestRespDTO suggestRespDTO = new ScheduleSuggestRespDTO();
127                             suggestRespDTO.setId(UUID.randomUUID().toString());
128                             suggestRespDTO.setContent(result.get("yingdiAdvice").toString());//盈德中压建议调整量建议
129                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
130                             mcsApi.createScheduleSuggest(suggestRespDTO);
131                         }else if ("faAdvice".equals(key) && !"".equals(result.get("faAdvice").toString())) {
132                             ScheduleSuggestRespDTO suggestRespDTO = new ScheduleSuggestRespDTO();
133                             suggestRespDTO.setId(UUID.randomUUID().toString());
134                             suggestRespDTO.setContent(result.get("faAdvice").toString());//法夜空建议调整量建议
135                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
136                             mcsApi.createScheduleSuggest(suggestRespDTO);
137                         }else if ("hongAdvice".equals(key) && !"".equals(result.get("hongAdvice").toString())) {
138                             ScheduleSuggestRespDTO suggestRespDTO = new ScheduleSuggestRespDTO();
139                             suggestRespDTO.setId(UUID.randomUUID().toString());
140                             suggestRespDTO.setContent(result.get("hongAdvice").toString());//宏昌建议调整量建议
141                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
142                             mcsApi.createScheduleSuggest(suggestRespDTO);
143                         }else if ("RunAdvice".equals(key) && !"".equals(result.get("RunAdvice").toString())) {
144                             ScheduleSuggestRespDTO suggestRespDTO = new ScheduleSuggestRespDTO();
145                             suggestRespDTO.setId(UUID.randomUUID().toString());
146                             suggestRespDTO.setContent(result.get("RunAdvice").toString());//润忠建议调整量建议
147                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
148                             mcsApi.createScheduleSuggest(suggestRespDTO);
149                         }
150                     }
151                     break;
152                 default:
153                     break;
154             }
d66e44 155         }
c9ff6a 156     }
157 }