沙钢智慧能源系统后端代码
潘志宝
2 天以前 6cce675bb26ab0ffbdc19fe7f48cb3fcbd9890e3
提交 | 用户 | 时间
5ca975 1 package com.iailab.module.shasteel.job.task;
2
3 import com.iailab.module.model.api.mcs.McsApi;
4 import com.iailab.module.model.api.mcs.dto.AlarmMessageRespDTO;
5 import com.iailab.module.model.api.mcs.dto.ScheduleSuggestRespDTO;
6 import com.iailab.module.model.api.mcs.dto.StScheduleSchemeDTO;
7 import com.iailab.module.model.api.mdk.MdkApi;
8 import com.iailab.module.model.api.mdk.dto.MdkScheduleReqDTO;
9 import com.iailab.module.model.api.mdk.dto.MdkScheduleRespDTO;
10 import com.iailab.module.model.enums.CommonConstant;
11 import com.iailab.module.model.enums.ScheduleTriggerMethodEnum;
12 import org.apache.commons.lang3.StringUtils;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
15 import org.springframework.beans.factory.annotation.Autowired;
16 import org.springframework.stereotype.Component;
17 import org.springframework.util.CollectionUtils;
18
19 import java.util.Calendar;
20 import java.util.Date;
21 import java.util.List;
22
23 /**
24  * 压缩空气优化调度
25  * 定时触发 30 0/2 * * * ?
26  * 压力低于下限预警信息    pressureLWarning
27  * 压力高于上限预警信息    pressureHWarning
28  * 空压机启动调度建议    dispatchStart
29  * 空压机关停调度建议    dispatchClose
30  *
31  * @author PanZhibao
32  * @Description
33  * @createTime 2025年01月07日
34  */
35 @Component("runScheduleAirDispatchTask")
36 public class RunScheduleAirDispatchTask implements ITask {
37     private Logger logger = LoggerFactory.getLogger(getClass());
38
39     @Autowired
40     private McsApi mcsApi;
41
42     @Autowired
43     private MdkApi mdkApi;
44
45     @Override
46     public void run(String params) {
47         logger.info("RunScheduleAirDispatchTask,参数为:{}", params);
48         try {
49             Calendar calendar = Calendar.getInstance();
50             calendar.set(Calendar.MILLISECOND, 0);
51             calendar.set(Calendar.SECOND, 0);
52             Date scheduleTime = calendar.getTime();
53             if (StringUtils.isEmpty(params)) {
54                 logger.info("参数为空");
55                 return;
56             }
57
58             // 根据条件查找方案
59             List<StScheduleSchemeDTO> schemeList = mcsApi.listScheduleScheme(ScheduleTriggerMethodEnum.JOB.getCode(), params);
60             if (CollectionUtils.isEmpty(schemeList)) {
61                 logger.info("方案为空");
62                 return;
63             }
64
65             StScheduleSchemeDTO scheme = schemeList.get(0);
66             MdkScheduleReqDTO dto = new MdkScheduleReqDTO();
67             dto.setScheduleTime(scheduleTime);
68             dto.setScheduleCode(scheme.getCode());
69             MdkScheduleRespDTO mdkScheduleRespDTO = mdkApi.doSchedule(dto);
6cce67 70             if (!CommonConstant.MDK_STATUS_100.equals(mdkScheduleRespDTO.getStatusCode())) {
5ca975 71                 logger.info("调度结果异常,STATUS=" + mdkScheduleRespDTO.getStatusCode());
72                 return;
73             }
74
75             // 保存预警信息
6cce67 76             if (mdkScheduleRespDTO.getResult().get("pressureLWarning") != null &&
77                     StringUtils.isNotEmpty(mdkScheduleRespDTO.getResult().get("pressureLWarning").toString())) {
78                 String pressureLWarning = mdkScheduleRespDTO.getResult().get("pressureLWarning").toString();
5ca975 79                 AlarmMessageRespDTO alarm = new AlarmMessageRespDTO();
80                 alarm.setTitle("压力低于下限预警");
81                 alarm.setContent(pressureLWarning);
82                 alarm.setAlarmObj(scheme.getScheduleObj());
83                 alarm.setAlarmType("低于下限");
84                 alarm.setAlarmTime(scheduleTime);
85                 mcsApi.createAlarmMessage(alarm);
86             }
87
6cce67 88
89             if (mdkScheduleRespDTO.getResult().get("pressureHWarning") != null &&
90                     StringUtils.isNotEmpty(mdkScheduleRespDTO.getResult().get("pressureHWarning").toString())) {
91                 String pressureHWarning = mdkScheduleRespDTO.getResult().get("pressureHWarning").toString();
5ca975 92                 AlarmMessageRespDTO alarm = new AlarmMessageRespDTO();
93                 alarm.setTitle("压力高于上限预警");
94                 alarm.setContent(pressureHWarning);
95                 alarm.setAlarmObj(scheme.getScheduleObj());
96                 alarm.setAlarmType("高于上限");
97                 alarm.setAlarmTime(scheduleTime);
98                 mcsApi.createAlarmMessage(alarm);
99             }
100
101             // 保存调度建议
6cce67 102             if (mdkScheduleRespDTO.getResult().get("dispatchStart") != null &&
103                     StringUtils.isNotEmpty(mdkScheduleRespDTO.getResult().get("dispatchStart").toString())) {
104                 String dispatchStart = mdkScheduleRespDTO.getResult().get("dispatchStart").toString();
5ca975 105                 ScheduleSuggestRespDTO suggest = new ScheduleSuggestRespDTO();
106                 suggest.setTitle("空压机启动调度建议");
107                 suggest.setContent(dispatchStart);
108                 suggest.setScheduleObj(scheme.getScheduleObj());
109                 suggest.setScheduleTime(scheduleTime);
110                 suggest.setSort(0);
111                 mcsApi.createScheduleSuggest(suggest);
112             }
113
6cce67 114             if (mdkScheduleRespDTO.getResult().get("dispatchClose") != null &&
115                     StringUtils.isNotEmpty(mdkScheduleRespDTO.getResult().get("dispatchClose").toString())) {
116                 String dispatchClose = mdkScheduleRespDTO.getResult().get("dispatchClose").toString();
5ca975 117                 ScheduleSuggestRespDTO suggest = new ScheduleSuggestRespDTO();
118                 suggest.setTitle("空压机关停调度建议");
119                 suggest.setContent(dispatchClose);
120                 suggest.setScheduleObj(scheme.getScheduleObj());
121                 suggest.setScheduleTime(scheduleTime);
122                 suggest.setSort(0);
123                 mcsApi.createScheduleSuggest(suggest);
124             }
125
126             logger.info(params + "调度方案执行完成");
127         } catch (Exception ex) {
128             logger.error("RunScheduleAirDispatchTask运行异常");
129             ex.printStackTrace();
130         }
131         logger.info("RunScheduleAirDispatchTask运行完成");
132     }
133 }