鞍钢鲅鱼圈能源管控系统后端代码
liriming
2025-05-28 8183d37dee3b4aec48f8b4189693853054801a42
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
package com.iailab.module.ansteel.job.task;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.iailab.framework.common.util.date.DateUtils;
import com.iailab.module.ansteel.coking.entity.CokingTraceChartEntity;
import com.iailab.module.ansteel.coking.entity.CokingTraceConfEntity;
import com.iailab.module.ansteel.coking.service.*;
import com.iailab.module.ansteel.common.constant.CommonConstant;
import com.iailab.module.ansteel.common.enums.TraceProcessTypeEnum;
import com.iailab.module.model.api.mcs.McsApi;
import com.iailab.module.model.api.mdk.MdkApi;
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.*;
import java.util.stream.Collectors;
 
/**
 * 备煤工序异常溯源
 *
 * @author lirm
 * @Description
 * @createTime 2025年04月22日
 */
@Component("runCokingTraceModelBMTask")
public class RunCokingTraceModelBMTask implements ITask {
    private Logger logger = LoggerFactory.getLogger(getClass());
 
    @Autowired
    private CokingTraceReportService cokingTraceReportService;
 
    @Autowired
    private CokingTraceSuggestService cokingTraceSuggestService;
 
    @Autowired
    private CokingTraceDeviationService cokingTraceDeviationService;
 
    @Autowired
    private CokingAnalyIndService cokingAnalyIndService;
 
    @Autowired
    private CokingTraceIndService cokingTraceIndService;
 
    @Autowired
    private CokingTraceChartService cokingTraceChartService;
 
    @Autowired
    private CokingTraceConfService cokingTraceConfService;
 
 
    @Autowired
    private McsApi mcsApi;
 
    @Autowired
    private MdkApi mdkApi;
 
    private final static String process = TraceProcessTypeEnum.BM.getProcess();
 
    private final static String reportName = "备煤工序异常溯源";
 
    private final static String SugObj = "BM";
 
    private final static String indType = "备煤工序异常溯源";
 
    private final static String row = "coalRow";
 
    private final static String total = "coalPrepElecTotal1";
 
    private static final String jsonStr = "{\n" + "    " +
            "\"result\": {\n" +
            "\"coalHomeIndexInfo\":\"备煤耗电偏高\"," +
            "\"coalPrepElec\":[1600.8,1613.5]," +
            "\"coalPrepElecTotal1\":\"备煤耗电量偏高,经模型计算,原因和调整建议如下:煤量异常,当前值2000, 建议调整煤量至区间[765.0,1020.0]\"," +
            "\"coalPrepElecTime\":[[0.3,0.3],[1700.31,1900.2],[120.3]]," +
            "\"coalPrepElecIndex\":[133527.2,283517.6,83451.5,233461.2,83564.4]," +
            "\"coalRow0\":[[0.0,1000.3],[1.0,120.2],[7.0,1150.32]]," +
            "\"coalRow1\":[[0.0,1000.5],[2.0,200.56],[7.0,120.2]]," +
            "\"coalRow2\":[[0.0,1000.6],[3.0,261.7],[7.0,170.52]]," +
            "\"coalPrepElecHomePage\":[503000.6,84.04]," +
            "\"coalHomeIndex\":[30.0,4.6,523000.6]" +
            "  }" +
            "}";
 
    @Override
    public void run(String params) {
        logger.info("RunCokingTraceModelBMTask,参数为:{}", params);
        try {
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.MILLISECOND, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MINUTE, 0);
 
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            Date endDate = calendar.getTime();
            calendar.add(Calendar.DAY_OF_YEAR, -1);
            Date startDate = calendar.getTime();
            String clock = DateUtils.format(startDate);
 
            calendar.add(Calendar.DAY_OF_YEAR, 1);
            calendar.add(Calendar.MINUTE, -3);
            Date collectStartDate = calendar.getTime();
 
            // 调用模型
//            MdkScheduleReqDTO dto = new MdkScheduleReqDTO();
//            dto.setScheduleTime(calendar.getTime());
//            dto.setScheduleCode(params);
//            MdkScheduleRespDTO mdkScheduleRespDTO = mdkApi.doSchedule(dto);
//            logger.info(params + "调度方案执行完成," + mdkScheduleRespDTO);
//
//            Map<String, Object> tResult = mdkScheduleRespDTO.getResult();
//            JSONObject result = new JSONObject(tResult);
//            logger.info("result===" +  JSONObject.toJSONString(result));
 
            JSONObject jsonObject = JSONObject.parseObject(jsonStr);
            JSONObject result = (JSONObject) JSON.toJSON(jsonObject.get("result"));
 
            if (Objects.isNull(result)) {
                logger.info("模型结果为空");
                return;
            }
 
            // 保存报告
            String analyDate = DateUtils.format(startDate);
            String analyContent = clock + " " + result.getString("coalHomeIndexInfo");
            String content = result.getString(total);
            String relId = cokingTraceReportService.save(process, reportName, analyDate, clock, analyContent);
 
            // 保存一级分析指标
            cokingAnalyIndService.saveAnalyInd(relId, process, analyDate, analyContent);
 
            // 保存优化建议
            cokingTraceSuggestService.saveTraceSuggest(relId, process, clock, content, SugObj);
 
            // 保存偏差值
            cokingTraceDeviationService.saveTraceDeviation(relId, process, clock, result, CommonConstant.COKE_INDEX_CHARTCODE, row, SugObj);
 
            // 保存溯源指标
            cokingTraceIndService.saveTraceInd(relId, indType, clock, collectStartDate, endDate);
 
            // 保存溯源折线图
            save(relId, clock, indType, startDate, endDate);
 
        } catch (Exception ex) {
            logger.error("RunCokingTraceModelBMTask运行异常");
            ex.printStackTrace();
        }
        logger.info("RunCokingTraceModelBMTask运行完成");
    }
 
    public void save(String relId, String clock, String indType, Date startDate, Date endDate) {
        logger.info("查询需要保存chart的配置");
 
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.MILLISECOND, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        Date monthStartDate = calendar.getTime();
 
        Map<String, Object> map = new HashMap<>();
        map.put("indType", indType);
        map.put("ext1", "chart");
        List<CokingTraceConfEntity> list = cokingTraceConfService.list(map);
        if (CollectionUtils.isEmpty(list)) {
            return;
        }
        logger.info("list.size={}", list.size());
 
        List<CokingTraceChartEntity> entityList = new ArrayList<>();
 
        List<CokingTraceConfEntity> listMin = list.stream().filter(e -> e.getIndCode().equals("BMSY025")).collect(Collectors.toList());
 
        listMin.forEach(value -> {
            CokingTraceChartEntity cokingTraceChartEntity = new CokingTraceChartEntity();
            cokingTraceChartEntity.setRelId(relId);
            cokingTraceChartEntity.setName(value.getIndName());
            cokingTraceChartEntity.setClock(clock);
            cokingTraceChartEntity.setDataType(value.getDataType());
            cokingTraceChartEntity.setDataNo(value.getPointNo());
            cokingTraceChartEntity.setStartTime(startDate);
            cokingTraceChartEntity.setEndTime(endDate);
            cokingTraceChartEntity.setCreateDate(new Date());
            entityList.add(cokingTraceChartEntity);
        });
 
        List<CokingTraceConfEntity> listMonth = list.stream().filter(e -> e.getIndCode().equals("BMSY026")).collect(Collectors.toList());
 
        listMonth.forEach(value -> {
            CokingTraceChartEntity cokingTraceChartEntity = new CokingTraceChartEntity();
            cokingTraceChartEntity.setRelId(relId);
            cokingTraceChartEntity.setName(value.getIndName());
            cokingTraceChartEntity.setClock(clock);
            cokingTraceChartEntity.setDataType(value.getDataType());
            cokingTraceChartEntity.setDataNo(value.getPointNo());
            cokingTraceChartEntity.setStartTime(monthStartDate);
            cokingTraceChartEntity.setEndTime(endDate);
            cokingTraceChartEntity.setCreateDate(new Date());
            entityList.add(cokingTraceChartEntity);
        });
        cokingTraceChartService.insert(entityList);
    }
}