鞍钢鲅鱼圈能源管控系统后端代码
潘志宝
21 小时以前 8eecc7078abc724f8c01a2b4f73e96da666c5c74
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
package com.iailab.module.ansteel.job.task;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.iailab.framework.common.util.date.DateUtils;
import com.iailab.module.ansteel.coking.entity.*;
import com.iailab.module.ansteel.coking.service.*;
import com.iailab.module.ansteel.common.constant.CommonConstant;
import com.iailab.module.ansteel.common.enums.ProcessConfDataTypeEnum;
import com.iailab.module.data.api.ind.IndItemApi;
import com.iailab.module.data.api.ind.dto.ApiIndItemValueDTO;
import com.iailab.module.data.api.point.DataPointApi;
import com.iailab.module.model.api.mcs.McsApi;
import com.iailab.module.model.api.mcs.dto.ChartParamDTO;
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.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
 
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * 炼焦工序-异常溯源
 *
 * @author lirm
 * @Description
 * @createTime 2025年04月21日
 */
@Component("runCokingTraceModelLJTask")
public class RunCokingTraceModelLJTask 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 CokingTraceConfService cokingTraceConfService;
 
    @Autowired
    private CokingTraceChartService cokingTraceChartService;
 
    @Autowired
    private McsApi mcsApi;
 
    @Autowired
    private DataPointApi dataPointApi;
 
    @Autowired
    private IndItemApi indItemApi;
 
    private static final HashMap<String, Object> cokeColoumMap = new HashMap<String, Object>() {{
        put("cokeColoum0", "一级指标-偏差值");
        put("cokeColoum1", "二级指标-偏差值");
        put("cokeColoum2", "影响因素1-偏差值");
        put("cokeColoum3", "影响因素2-偏差值");
        put("cokeColoum4", "影响因素3-偏差值");
        put("cokeColoum5", "影响因素n-偏差值");
    }};
 
    private static final HashMap<String, Object> historyPointMap = new HashMap<String, Object>() {{
        put("F0000101009", "荒煤气发生");
        put("F0000101009", "耗热量");
    }};
 
    private static final String jsonStr="{\n" +
            "    \"result\": {\n" +
            "      \"cokeCOG\":[100.5,99.8],\n" +
            "      \"cokeHeat\":[3.7,3.8],\n" +
            "      \"cokeIndex\":[[0.8,0.7],[608,608],[1440,1460],[1346,1293],[0.8,0.7],[1372,1293]],\n" +
            "      \"cokeTotal\":\"炼焦吨焦耗热量因煤气流量偏高、煤气水分偏低而增加23,经模型计算,延建议调整煤气流量,预计可使吨焦耗热量指标降低17\",\n" +
            "      \"cokeColoum0\":[[0,13],[0,42],[0,34]],\n" +
            "      \"cokeColoum1\":[[13,12],[12,34],[24,42]],\n" +
            "      \"cokeColoum2\":[[27,45],[58,42],[70,31]],\n" +
            "      \"cokeColoum3\":[[108,56],[110,89],[185,21]],\n" +
            "      \"cokeColoum4\":[[199,13],[200,51],[197,34]],\n" +
            "      \"cokeColoum5\":[[147,33],[131,12],[122,13]],\n" +
            "      \"cokeHomePage\":[[202,42],[203,13],[204,45],[205,34],[206,17]],\n" +
            "      \"cokeHomeIndex\":[[90.4,90.2],[80.3,78],[103,100],[280,270]],\n" +
            "      \"cokeHomeIndexInfo\":\"2月18日甲班:吨焦耗热量异常\",\n" +
            "      \"cokeHomeErr\":\"2月18日煤气预热器前数据异常(无数据)\"\n" +
            "    }\n" +
            "}";
 
    @Override
    public void run(String params) {
        logger.info("RunCokingTraceModelLJTask,参数为:{}", params);
        try {
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.MILLISECOND, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MINUTE,0);
            calendar.add(Calendar.DAY_OF_YEAR, -1);
            String yesterday = DateUtils.format(calendar.getTime(), DateUtils.FORMAT_YEAR_MONTH_DAY);
            int hour = calendar.get(Calendar.HOUR_OF_DAY);
            Date startDate = calendar.getTime();
            calendar.add(Calendar.HOUR, 8);
            Date endDate = calendar.getTime();
            String clock = "";
            String analyClass = "";
            if (hour == 0) {
                clock = yesterday.concat("-").concat("A");
                analyClass = "甲班";
            } else if (hour == 8) {
                clock = yesterday.concat("-").concat("B");
                analyClass = "乙班";
            } else if (hour == 16) {
                clock = yesterday.concat("-").concat("C");
                analyClass = "丙班";
            }
            Map<String, Object> tMap = new HashMap<>();
            tMap.put("relId", UUID.randomUUID().toString());
            tMap.put("process", "炼焦工序");
            tMap.put("reportName", "炼焦工序");
            tMap.put("analyDate", yesterday);
            tMap.put("analyClass", analyClass);
            tMap.put("clock", clock);
            tMap.put("analyContent", "COG回收量异常;吨焦耗热量异常");
            tMap.put("startDate", startDate);
            tMap.put("endDate", endDate);
 
            JSONObject jsonObject= JSONObject.parseObject(jsonStr);
            JSONObject result = (JSONObject) JSON.toJSON(jsonObject.get("result"));
            if(!Objects.isNull(result)){
                saveTraceReport(tMap,result);
                saveTraceSuggest(tMap,result);
                saveTraceDeviation(tMap,result);
                saveAnalyInd(tMap,result);
                saveTraceInd(tMap,result);
                saveTraceChart(tMap,result,startDate,endDate);
            }
        } catch (Exception ex) {
            logger.error("RunCokingTraceModelLJTask运行异常");
            ex.printStackTrace();
        }
        logger.info("RunCokingTraceModelLJTask运行完成");
    }
 
    public void saveTraceReport(Map<String, Object> tMap,JSONObject result) {
        CokingTraceReportEntity reportEntity = new CokingTraceReportEntity();
        reportEntity.setId(tMap.get("relId").toString());
        reportEntity.setProcess(tMap.get("process").toString());
        reportEntity.setReportName(tMap.get("reportName").toString());
        reportEntity.setAnalyDate(tMap.get("analyDate").toString());
        reportEntity.setAnalyClass(tMap.get("analyClass").toString());
        reportEntity.setClock(tMap.get("clock").toString());
        reportEntity.setAnalyContent(tMap.get("analyContent").toString());
        reportEntity.setCreateDate(new Date());
        cokingTraceReportService.save(reportEntity);
    }
 
    public void saveTraceSuggest(Map<String, Object> tMap,JSONObject result) {
        String cokeTotal = result.get("cokeTotal").toString();
        if(StringUtils.isNotBlank(cokeTotal)){
            CokingTraceSuggestEntity suggestEntity = new CokingTraceSuggestEntity();
            suggestEntity.setRelId(tMap.get("relId").toString());
            suggestEntity.setProcess(tMap.get("process").toString());
            suggestEntity.setSugObj("LJ");
            suggestEntity.setClock(tMap.get("clock").toString());
            suggestEntity.setContent(cokeTotal);
            suggestEntity.setCreateDate(new Date());
            cokingTraceSuggestService.save(suggestEntity);
        }
    }
 
    public void saveTraceDeviation(Map<String, Object> tMap,JSONObject result) {
        List<ChartParamDTO> list = mcsApi.getChartParamList(CommonConstant.COKE_INDEX_CHARTCODE);
        Map<String, String> steamIndexMaps = list.stream().collect(Collectors.toMap(ChartParamDTO::getParamCode, e -> e.getParamName()));
        for(int i=0;i<=5;i++){
            String cokeColoum = result.get("cokeColoum"+i).toString();
            if(StringUtils.isNotBlank(cokeColoum)){
                JSONArray responseArr = JSON.parseArray(cokeColoum);
                List<CokingTraceDeviationEntity> entityList = new ArrayList<>();
                for (int j = 0; j < responseArr.size(); j++) {
                    JSONArray element = JSON.parseArray(responseArr.get(j).toString());
                    CokingTraceDeviationEntity deviationEntity = new CokingTraceDeviationEntity();
                    deviationEntity.setRelId(tMap.get("relId").toString());
                    deviationEntity.setProcess(tMap.get("process").toString());
                    deviationEntity.setClock(tMap.get("clock").toString());
                    deviationEntity.setSugObj("LJ");
                    deviationEntity.setGroupName(cokeColoumMap.get("cokeColoum"+i).toString());
                    deviationEntity.setIndName(steamIndexMaps.get(element.get(0).toString()));
                    deviationEntity.setIndValue(element.get(1).toString());
                    deviationEntity.setCreateDate(new Date());
                    entityList.add(deviationEntity);
                }
                cokingTraceDeviationService.save(entityList);
            }
        }
    }
 
    public void saveAnalyInd(Map<String, Object> tMap,JSONObject result) {
        String[] analyContent = tMap.get("analyContent").toString().split(";");
        List<CokingAnalyIndEntity> entityList = new ArrayList<>();
        for(int i=0;i<analyContent.length;i++){
            CokingAnalyIndEntity analyIndEntity = new CokingAnalyIndEntity();
            analyIndEntity.setRelId(tMap.get("relId").toString());
            analyIndEntity.setAnalyType(tMap.get("process").toString());
            analyIndEntity.setAnalyDate(tMap.get("analyDate").toString());
            analyIndEntity.setAnalyClass(tMap.get("analyClass").toString());
            analyIndEntity.setAnalyContent(analyContent[i]);
            analyIndEntity.setSort(i+1);
            entityList.add(analyIndEntity);
        }
        cokingAnalyIndService.save(entityList);
    }
 
    public void saveTraceInd(Map<String, Object> tMap,JSONObject result) {
        Map<String,Object> map = new HashMap<>();
        map.put("indType","炼焦工序异常溯源");
        List<CokingTraceConfEntity> list = cokingTraceConfService.list(map);
        if (CollectionUtils.isEmpty(list)) {
            logger.info("ConfLis is Empty");
            return;
        }
        List<CokingTraceIndEntity> entityList = new ArrayList<>();
        for (CokingTraceConfEntity conf : list) {
            if (StringUtils.isBlank(conf.getDataType())) {
                logger.info("DataType is Empty");
                continue;
            }
            if (StringUtils.isBlank(conf.getPointNo())) {
                logger.info("PointNo is Empty");
                continue;
            }
            String value = "";
            switch (ProcessConfDataTypeEnum.getEumByCode(conf.getDataType())) {
                case DATAPOINT:
                    List<String> points = new ArrayList<>();
                    points.add(conf.getPointNo());
                    Map<String, Object> pointsRealValue = dataPointApi.queryPointsRealValue(points);
                    value = pointsRealValue.get(conf.getPointNo()).toString();
                    break;
                case IND:
                    List<ApiIndItemValueDTO> indValues = indItemApi.queryIndItemDefaultValue(conf.getPointNo());
                    if (!CollectionUtils.isEmpty(indValues)) {
                        value = indValues.get(indValues.size() - 1).getDataValue().toString();
                    }
                    break;
                default:
                    break;
            }
            CokingTraceIndEntity cokingTraceIndEntity = new CokingTraceIndEntity();
            cokingTraceIndEntity.setRelId(tMap.get("relId").toString());
            cokingTraceIndEntity.setTitle(conf.getIndType());
            cokingTraceIndEntity.setClock(tMap.get("clock").toString());
            cokingTraceIndEntity.setIndCode(conf.getIndCode());
            cokingTraceIndEntity.setIndName(conf.getIndName());
            cokingTraceIndEntity.setIndValue(value);
            cokingTraceIndEntity.setIndUnit(conf.getIndUnit());
            entityList.add(cokingTraceIndEntity);
        }
        cokingTraceIndService.save(entityList);
    }
 
    public void saveTraceChart(Map<String, Object> tMap, JSONObject result,Date startDate,Date endDate) {
        List<CokingTraceChartEntity> entityList = new ArrayList<>();
        historyPointMap.forEach((key,value) ->{
            CokingTraceChartEntity cokingTraceChartEntity = new CokingTraceChartEntity();
            cokingTraceChartEntity.setRelId(tMap.get("relId").toString());
            cokingTraceChartEntity.setName(value.toString());
            cokingTraceChartEntity.setClock(tMap.get("clock").toString());
            cokingTraceChartEntity.setDataNo(key);
            cokingTraceChartEntity.setDataType("DATAPOINT");
            cokingTraceChartEntity.setStartTime(startDate);
            cokingTraceChartEntity.setEndTime(endDate);
            cokingTraceChartEntity.setCreateDate(new Date());
            entityList.add(cokingTraceChartEntity);
        });
        cokingTraceChartService.insert(entityList);
    }
}