沙钢智慧能源系统后端代码
liriming
2 天以前 b7245f9d1308595e1405d11ffb524d96a2c8a7a8
提交 | 用户 | 时间
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());
64e8b5 89                             suggestRespDTO.setScheduleObj(stScheduleSchemeDTO.getScheduleObj());
456a64 90                             suggestRespDTO.setContent(result.get("faAdvice").toString());//法夜空建议送出量建议
L 91                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
92                             mcsApi.createScheduleSuggest(suggestRespDTO);
93                         }else if ("yingDiAdvice".equals(key) && !"".equals(result.get("yingDiAdvice").toString())) {
94                             ScheduleSuggestRespDTO suggestRespDTO = new ScheduleSuggestRespDTO();
95                             suggestRespDTO.setId(UUID.randomUUID().toString());
64e8b5 96                             suggestRespDTO.setScheduleObj(stScheduleSchemeDTO.getScheduleObj());
456a64 97                             suggestRespDTO.setContent(result.get("yingDiAdvice").toString());//盈德低压建议送出量建议
L 98                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
99                             mcsApi.createScheduleSuggest(suggestRespDTO);
100                         }else if ("yingZhongAdvice".equals(key) && !"".equals(result.get("yingZhongAdvice").toString())) {
101                             ScheduleSuggestRespDTO suggestRespDTO = new ScheduleSuggestRespDTO();
102                             suggestRespDTO.setId(UUID.randomUUID().toString());
64e8b5 103                             suggestRespDTO.setScheduleObj(stScheduleSchemeDTO.getScheduleObj());
456a64 104                             suggestRespDTO.setContent(result.get("yingZhongAdvice").toString());//盈德中压建议送出量建议
L 105                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
106                             mcsApi.createScheduleSuggest(suggestRespDTO);
107                         }else if ("hongAdvice".equals(key) && !"".equals(result.get("hongAdvice").toString())) {
108                             ScheduleSuggestRespDTO suggestRespDTO = new ScheduleSuggestRespDTO();
109                             suggestRespDTO.setId(UUID.randomUUID().toString());
64e8b5 110                             suggestRespDTO.setScheduleObj(stScheduleSchemeDTO.getScheduleObj());
456a64 111                             suggestRespDTO.setContent(result.get("hongAdvice").toString());//宏昌建议送出量建议
L 112                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
113                             mcsApi.createScheduleSuggest(suggestRespDTO);
114                         }else if ("RunAdvice".equals(key) && !"".equals(result.get("RunAdvice").toString())) {
115                             ScheduleSuggestRespDTO suggestRespDTO = new ScheduleSuggestRespDTO();
116                             suggestRespDTO.setId(UUID.randomUUID().toString());
64e8b5 117                             suggestRespDTO.setScheduleObj(stScheduleSchemeDTO.getScheduleObj());
456a64 118                             suggestRespDTO.setContent(result.get("RunAdvice").toString());//润忠建议送出量建议
L 119                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
120                             mcsApi.createScheduleSuggest(suggestRespDTO);
121                         }
122                     }
123                     break;
124                 case CommonConstant.OXYGEN_TWO_CODE://氧气系统优化调度决策方案
125                     if(!result.containsKey("yingdiAdvice") || !result.containsKey("faAdvice") || !result.containsKey("hongAdvice")
126                             || !result.containsKey("RunAdvice")){
127                         return;
128                     }
129                     for (String key : result.keySet()) {
130                         if ("yingdiAdvice".equals(key) && !"".equals(result.get("yingdiAdvice").toString())) {
131                             ScheduleSuggestRespDTO suggestRespDTO = new ScheduleSuggestRespDTO();
132                             suggestRespDTO.setId(UUID.randomUUID().toString());
64e8b5 133                             suggestRespDTO.setScheduleObj(stScheduleSchemeDTO.getScheduleObj());
456a64 134                             suggestRespDTO.setContent(result.get("yingdiAdvice").toString());//盈德中压建议调整量建议
L 135                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
136                             mcsApi.createScheduleSuggest(suggestRespDTO);
137                         }else if ("faAdvice".equals(key) && !"".equals(result.get("faAdvice").toString())) {
138                             ScheduleSuggestRespDTO suggestRespDTO = new ScheduleSuggestRespDTO();
139                             suggestRespDTO.setId(UUID.randomUUID().toString());
64e8b5 140                             suggestRespDTO.setScheduleObj(stScheduleSchemeDTO.getScheduleObj());
456a64 141                             suggestRespDTO.setContent(result.get("faAdvice").toString());//法夜空建议调整量建议
L 142                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
143                             mcsApi.createScheduleSuggest(suggestRespDTO);
144                         }else if ("hongAdvice".equals(key) && !"".equals(result.get("hongAdvice").toString())) {
145                             ScheduleSuggestRespDTO suggestRespDTO = new ScheduleSuggestRespDTO();
146                             suggestRespDTO.setId(UUID.randomUUID().toString());
64e8b5 147                             suggestRespDTO.setScheduleObj(stScheduleSchemeDTO.getScheduleObj());
456a64 148                             suggestRespDTO.setContent(result.get("hongAdvice").toString());//宏昌建议调整量建议
L 149                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
150                             mcsApi.createScheduleSuggest(suggestRespDTO);
151                         }else if ("RunAdvice".equals(key) && !"".equals(result.get("RunAdvice").toString())) {
152                             ScheduleSuggestRespDTO suggestRespDTO = new ScheduleSuggestRespDTO();
153                             suggestRespDTO.setId(UUID.randomUUID().toString());
64e8b5 154                             suggestRespDTO.setScheduleObj(stScheduleSchemeDTO.getScheduleObj());
456a64 155                             suggestRespDTO.setContent(result.get("RunAdvice").toString());//润忠建议调整量建议
L 156                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
157                             mcsApi.createScheduleSuggest(suggestRespDTO);
158                         }
159                     }
160                     break;
161                 default:
162                     break;
163             }
d66e44 164         }
c9ff6a 165     }
166 }