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