沙钢智慧能源系统后端代码
潘志宝
2024-12-24 d92c3113a9c69473fb5139e63df393a644dafd0f
提交 | 用户 | 时间
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;
456a64 12 import com.iailab.module.shasteel.mq.common.constant.CommonConstant;
cf56eb 13 import com.iailab.module.shasteel.mq.common.enums.TriggerConditionEnum;
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         // 查找需要执行的调度方案
d66e44 65         Map<String, Object> params = new HashMap<>();
cf56eb 66         params.put("trigger_method", TriggerConditionEnum.EVENT);
d66e44 67         params.put("trigger_condition", routingKey);
L 68         List<StScheduleSchemeDTO> scheduleSchemeList = mcsApi.listScheduleScheme(params);//根据触发条件获取调度方案列表
69         for(StScheduleSchemeDTO stScheduleSchemeDTO : scheduleSchemeList){
70             MdkScheduleReqDTO mdkScheduleReqDTO = new MdkScheduleReqDTO();
71             mdkScheduleReqDTO.setScheduleCode(stScheduleSchemeDTO.getCode());
72             mdkScheduleReqDTO.setScheduleTime(stScheduleSchemeDTO.getScheduleTime());
cf56eb 73             MdkScheduleRespDTO mdkScheduleRespDTO = mdkApi.doSchedule(mdkScheduleReqDTO);//执行调度方案
456a64 74             if(mdkScheduleRespDTO == null){
L 75                 return;
76             }
77             AlarmMessageRespDTO alarmRespDTO = (AlarmMessageRespDTO)messageJson.get("AlarmMessageRespDTO");
78             alarmRespDTO.setId(UUID.randomUUID().toString());
79             alarmRespDTO.setAlarmTime(DateUtils.parse(messageJson.get("predictTime").toString(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND));
80             mcsApi.createAlarmMessage(alarmRespDTO);
81             Map<String, Object> result = mdkScheduleRespDTO.getResult();
82             switch (mdkScheduleRespDTO.getScheduleCode()) {
83                 case CommonConstant.OXYGEN_ONE_CODE://氧气班平衡计划方案
84                     if(!result.containsKey("faAdvice") || !result.containsKey("yingDiAdvice") || !result.containsKey("yingZhongAdvice")
85                             || !result.containsKey("hongAdvice") || !result.containsKey("RunAdvice")){
86                         return;
87                     }
88                     for (String key : result.keySet()) {
89                         if ("faAdvice".equals(key) && !"".equals(result.get("faAdvice").toString())) {
90                             ScheduleSuggestRespDTO suggestRespDTO = new ScheduleSuggestRespDTO();
91                             suggestRespDTO.setId(UUID.randomUUID().toString());
92                             suggestRespDTO.setContent(result.get("faAdvice").toString());//法夜空建议送出量建议
93                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
94                             mcsApi.createScheduleSuggest(suggestRespDTO);
95                         }else if ("yingDiAdvice".equals(key) && !"".equals(result.get("yingDiAdvice").toString())) {
96                             ScheduleSuggestRespDTO suggestRespDTO = new ScheduleSuggestRespDTO();
97                             suggestRespDTO.setId(UUID.randomUUID().toString());
98                             suggestRespDTO.setContent(result.get("yingDiAdvice").toString());//盈德低压建议送出量建议
99                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
100                             mcsApi.createScheduleSuggest(suggestRespDTO);
101                         }else if ("yingZhongAdvice".equals(key) && !"".equals(result.get("yingZhongAdvice").toString())) {
102                             ScheduleSuggestRespDTO suggestRespDTO = new ScheduleSuggestRespDTO();
103                             suggestRespDTO.setId(UUID.randomUUID().toString());
104                             suggestRespDTO.setContent(result.get("yingZhongAdvice").toString());//盈德中压建议送出量建议
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());
110                             suggestRespDTO.setContent(result.get("hongAdvice").toString());//宏昌建议送出量建议
111                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
112                             mcsApi.createScheduleSuggest(suggestRespDTO);
113                         }else if ("RunAdvice".equals(key) && !"".equals(result.get("RunAdvice").toString())) {
114                             ScheduleSuggestRespDTO suggestRespDTO = new ScheduleSuggestRespDTO();
115                             suggestRespDTO.setId(UUID.randomUUID().toString());
116                             suggestRespDTO.setContent(result.get("RunAdvice").toString());//润忠建议送出量建议
117                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
118                             mcsApi.createScheduleSuggest(suggestRespDTO);
119                         }
120                     }
121                     break;
122                 case CommonConstant.OXYGEN_TWO_CODE://氧气系统优化调度决策方案
123                     if(!result.containsKey("yingdiAdvice") || !result.containsKey("faAdvice") || !result.containsKey("hongAdvice")
124                             || !result.containsKey("RunAdvice")){
125                         return;
126                     }
127                     for (String key : result.keySet()) {
128                         if ("yingdiAdvice".equals(key) && !"".equals(result.get("yingdiAdvice").toString())) {
129                             ScheduleSuggestRespDTO suggestRespDTO = new ScheduleSuggestRespDTO();
130                             suggestRespDTO.setId(UUID.randomUUID().toString());
131                             suggestRespDTO.setContent(result.get("yingdiAdvice").toString());//盈德中压建议调整量建议
132                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
133                             mcsApi.createScheduleSuggest(suggestRespDTO);
134                         }else if ("faAdvice".equals(key) && !"".equals(result.get("faAdvice").toString())) {
135                             ScheduleSuggestRespDTO suggestRespDTO = new ScheduleSuggestRespDTO();
136                             suggestRespDTO.setId(UUID.randomUUID().toString());
137                             suggestRespDTO.setContent(result.get("faAdvice").toString());//法夜空建议调整量建议
138                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
139                             mcsApi.createScheduleSuggest(suggestRespDTO);
140                         }else if ("hongAdvice".equals(key) && !"".equals(result.get("hongAdvice").toString())) {
141                             ScheduleSuggestRespDTO suggestRespDTO = new ScheduleSuggestRespDTO();
142                             suggestRespDTO.setId(UUID.randomUUID().toString());
143                             suggestRespDTO.setContent(result.get("hongAdvice").toString());//宏昌建议调整量建议
144                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
145                             mcsApi.createScheduleSuggest(suggestRespDTO);
146                         }else if ("RunAdvice".equals(key) && !"".equals(result.get("RunAdvice").toString())) {
147                             ScheduleSuggestRespDTO suggestRespDTO = new ScheduleSuggestRespDTO();
148                             suggestRespDTO.setId(UUID.randomUUID().toString());
149                             suggestRespDTO.setContent(result.get("RunAdvice").toString());//润忠建议调整量建议
150                             suggestRespDTO.setSchemeId(stScheduleSchemeDTO.getId());
151                             mcsApi.createScheduleSuggest(suggestRespDTO);
152                         }
153                     }
154                     break;
155                 default:
156                     break;
157             }
d66e44 158         }
c9ff6a 159     }
160 }