沙钢智慧能源系统后端代码
潘志宝
3 天以前 20ca11322c7a11f8442c24fe9c521f614a54583e
提交 | 用户 | 时间
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);
70             if (CommonConstant.MDK_STATUS_100.equals(mdkScheduleRespDTO.getStatusCode())) {
71                 logger.info("调度结果异常,STATUS=" + mdkScheduleRespDTO.getStatusCode());
72                 return;
73             }
74
75             // 保存预警信息
76             String pressureLWarning = mdkScheduleRespDTO.getResult().get("pressureLWarning").toString();
77             if (StringUtils.isNotBlank(pressureLWarning)) {
78                 AlarmMessageRespDTO alarm = new AlarmMessageRespDTO();
79                 alarm.setTitle("压力低于下限预警");
80                 alarm.setContent(pressureLWarning);
81                 alarm.setAlarmObj(scheme.getScheduleObj());
82                 alarm.setAlarmType("低于下限");
83                 alarm.setAlarmTime(scheduleTime);
84                 mcsApi.createAlarmMessage(alarm);
85             }
86
87             String pressureHWarning = mdkScheduleRespDTO.getResult().get("pressureHWarning").toString();
88             if (StringUtils.isNotBlank(pressureHWarning)) {
89                 AlarmMessageRespDTO alarm = new AlarmMessageRespDTO();
90                 alarm.setTitle("压力高于上限预警");
91                 alarm.setContent(pressureHWarning);
92                 alarm.setAlarmObj(scheme.getScheduleObj());
93                 alarm.setAlarmType("高于上限");
94                 alarm.setAlarmTime(scheduleTime);
95                 mcsApi.createAlarmMessage(alarm);
96             }
97
98             // 保存调度建议
99             String dispatchStart = mdkScheduleRespDTO.getResult().get("dispatchStart").toString();
100             if (StringUtils.isNotBlank(pressureHWarning)) {
101                 ScheduleSuggestRespDTO suggest = new ScheduleSuggestRespDTO();
102                 suggest.setTitle("空压机启动调度建议");
103                 suggest.setContent(dispatchStart);
104                 suggest.setScheduleObj(scheme.getScheduleObj());
105                 suggest.setScheduleTime(scheduleTime);
106                 suggest.setSort(0);
107                 mcsApi.createScheduleSuggest(suggest);
108             }
109
110             String dispatchClose = mdkScheduleRespDTO.getResult().get("dispatchClose").toString();
111             if (StringUtils.isNotBlank(dispatchClose)) {
112                 ScheduleSuggestRespDTO suggest = new ScheduleSuggestRespDTO();
113                 suggest.setTitle("空压机关停调度建议");
114                 suggest.setContent(dispatchClose);
115                 suggest.setScheduleObj(scheme.getScheduleObj());
116                 suggest.setScheduleTime(scheduleTime);
117                 suggest.setSort(0);
118                 mcsApi.createScheduleSuggest(suggest);
119             }
120
121             logger.info(params + "调度方案执行完成");
122         } catch (Exception ex) {
123             logger.error("RunScheduleAirDispatchTask运行异常");
124             ex.printStackTrace();
125         }
126         logger.info("RunScheduleAirDispatchTask运行完成");
127     }
128 }