沙钢智慧能源系统后端代码
潘志宝
3 天以前 1a9badc78ca5795758321049870ffc5875e0ec79
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package com.iailab.module.shasteel.job.task;
 
import com.iailab.module.model.api.mcs.McsApi;
import com.iailab.module.model.api.mcs.dto.AlarmMessageRespDTO;
import com.iailab.module.model.api.mcs.dto.ScheduleSuggestRespDTO;
import com.iailab.module.model.api.mcs.dto.StScheduleSchemeDTO;
import com.iailab.module.model.api.mdk.MdkApi;
import com.iailab.module.model.api.mdk.dto.MdkScheduleReqDTO;
import com.iailab.module.model.api.mdk.dto.MdkScheduleRespDTO;
import com.iailab.module.model.enums.CommonConstant;
import com.iailab.module.model.enums.ScheduleTriggerMethodEnum;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
 
import java.util.*;
 
/**
 * 06
 * 氧气班平衡计划
 * 法夜空建议送出量    faAdvice
 * 盈德低压建议送出量    yingDiAdvice
 * 盈德中压建议送出量    yingZhongAdvice
 * 宏昌建议送出量    hongAdvice
 * 润忠建议送出量    RunAdvice
 * 调整值    adviceValues
 *
 * 05
 * 氧气系统优化调度决策
 * 盈德中压建议调整量    yingdiAdvice
 * 法夜空建议调整量    faAdvice
 * 宏昌建议调整量    hongAdvice
 * 润忠建议调整量    RunAdvice
 *
 * 01
 * 氮气预警模型
 * 预警信号    advice
 *
 * @author PanZhibao
 * @Description
 * @createTime 2025年01月07日
 */
@Component("runScheduleOnaOptTask")
public class RunScheduleOnaOptTask implements ITask {
    private Logger logger = LoggerFactory.getLogger(getClass());
 
    @Autowired
    private McsApi mcsApi;
 
    @Autowired
    private MdkApi mdkApi;
 
    private Map<String, StScheduleSchemeDTO> schemeMap = new HashMap<>();
 
    private static final String CODE06 = "06";
 
    private static final String CODE05 = "05";
 
    private static final String CODE01 = "01";
 
    @Override
    public void run(String params) {
        logger.info("RunScheduleOnaOptTask,参数为:{}", params);
        try {
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.MILLISECOND, 0);
            calendar.set(Calendar.SECOND, 0);
            Date scheduleTime = calendar.getTime();
            if (StringUtils.isEmpty(params)) {
                logger.info("参数为空");
                return;
            }
 
            // 根据条件查找方案
            List<StScheduleSchemeDTO> schemeList = mcsApi.listScheduleScheme(ScheduleTriggerMethodEnum.JOB.getCode(), params);
            if (CollectionUtils.isEmpty(schemeList)) {
                logger.info("方案为空");
                return;
            }
            schemeMap.clear();
            Map<String, MdkScheduleRespDTO> resultMap = new HashMap<String, MdkScheduleRespDTO>();
            schemeList.forEach(item -> {
                schemeMap.put(item.getCode(), item);
                StScheduleSchemeDTO scheme = schemeList.get(0);
                MdkScheduleReqDTO dto = new MdkScheduleReqDTO();
                dto.setScheduleTime(scheduleTime);
                dto.setScheduleCode(scheme.getCode());
                MdkScheduleRespDTO mdkScheduleRespDTO = mdkApi.doSchedule(dto);
                resultMap.put(item.getCode(), mdkScheduleRespDTO);
            });
            if (CollectionUtils.isEmpty(resultMap)) {
                logger.info("resultMap为空");
                return;
            }
            for (Map.Entry<String, MdkScheduleRespDTO> entry : resultMap.entrySet()) {
                if (CommonConstant.MDK_STATUS_100.equals(entry.getValue().getStatusCode())) {
                    logger.info("调度结果异常,STATUS=" + entry.getValue().getStatusCode());
                    continue;
                }
 
                if (entry.getKey().equals(CODE06)) {
                    // 氧气班平衡计划,建议值写入测点
                    mdkApi.scheduleModelOut(entry.getValue());
                } else if (entry.getKey().equals(CODE05)) {
                    String scheduleObj = schemeMap.get(CODE05).getScheduleObj();
                    // double[] adviceValues = (double[]) entry.getValue().getResult().get("adviceValues");
                    String yingdiAdvice = entry.getValue().getResult().get("yingdiAdvice").toString();
                    saveScheduleSuggest("盈德中压建议调整量", yingdiAdvice, scheduleObj, scheduleTime);
                    String faAdvice = entry.getValue().getResult().get("faAdvice").toString();
                    saveScheduleSuggest("法夜空建议调整量", faAdvice, scheduleObj, scheduleTime);
                    String hongAdvice = entry.getValue().getResult().get("hongAdvice").toString();
                    saveScheduleSuggest("宏昌建议调整量", hongAdvice, scheduleObj, scheduleTime);
                    String runAdvice = entry.getValue().getResult().get("RunAdvice").toString();
                    saveScheduleSuggest("宏昌建议调整量", runAdvice, scheduleObj, scheduleTime);
                } else if (entry.getKey().equals(CODE01)) {
                    String scheduleObj = schemeMap.get(CODE01).getScheduleObj();
                    String advice = entry.getValue().getResult().get("advice").toString();
                    saveScheduleSuggest("氮气预警", advice, scheduleObj, scheduleTime);
                }
            }
            logger.info(params + "调度方案执行完成");
        } catch (Exception ex) {
            logger.error("RunScheduleOnaOptTask运行异常");
            ex.printStackTrace();
        }
        logger.info("RunScheduleOnaOptTask运行完成");
    }
 
    private void saveScheduleSuggest(String title, String content, String scheduleObj, Date scheduleTime) {
        if (StringUtils.isBlank(content)) {
            return;
        }
        ScheduleSuggestRespDTO suggest = new ScheduleSuggestRespDTO();
        suggest.setTitle(title);
        suggest.setContent(content);
        suggest.setScheduleObj(scheduleObj);
        suggest.setScheduleTime(scheduleTime);
        suggest.setSort(0);
        mcsApi.createScheduleSuggest(suggest);
    }
}