| | |
| | | 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.CokingAnalyIndEntity; |
| | | import com.iailab.module.ansteel.coking.entity.CokingTraceDeviationEntity; |
| | | import com.iailab.module.ansteel.coking.entity.CokingTraceSuggestEntity; |
| | | import com.iailab.module.ansteel.coking.service.*; |
| | | import com.iailab.module.ansteel.common.constant.CommonConstant; |
| | | import com.iailab.module.model.api.mcs.McsApi; |
| | | import com.iailab.module.model.api.mcs.dto.ChartParamDTO; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import com.iailab.module.ansteel.common.enums.TraceProcessTypeEnum; |
| | | 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.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * 炼焦工序-异常溯源 |
| | |
| | | private CokingTraceChartService cokingTraceChartService; |
| | | |
| | | @Autowired |
| | | private McsApi mcsApi; |
| | | private MdkApi mdkApi; |
| | | |
| | | private final static String process = "炼焦工序"; |
| | | private final static String process = TraceProcessTypeEnum.LJ.getProcess(); |
| | | |
| | | private final static String reportName = "炼焦工序异常溯源"; |
| | | |
| | |
| | | |
| | | private final static String indType = "炼焦工序异常溯源"; |
| | | |
| | | private final static String cokeRow = "cokeRow"; |
| | | private final static String row = "cokeRow"; |
| | | |
| | | 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 final static String total = "cokeTotal"; |
| | | |
| | | 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" + " " + |
| | | "\"cokeRow0\":[[0,13],[0,42],[0,34]],\n" + " " + |
| | | "\"cokeRow1\":[[13,12],[12,34],[24,42]],\n" + " " + |
| | | "\"cokeRow2\":[[27,45],[58,42],[70,31]],\n" + " " + |
| | | "\"cokeRow3\":[[18,56],[10,89],[15,21]],\n" + " " + |
| | | "\"cokeRow4\":[[19,13],[20,51],[17,34]],\n" + " " + |
| | | "\"cokeRow5\":[[47,33],[31,12],[22,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\":\"4月25日甲班:吨焦耗热量异常\",\n" + " " + |
| | | "\"cokeHomeErr\":\"4月25日煤气预热器前数据异常(无数据)\"\n" + " " + "}\n" + "}"; |
| | | private static final String jsonStr = "{\n" + |
| | | "\"result\": {\n" + |
| | | "\"cokeElec\":[583562.4]," + |
| | | "\"cokeHeat1\":[130820.4,136710.3]," + |
| | | "\"cokeRow0\":[[0.0,13.6],[2.0,10.5],[69.0,34.6]]," + |
| | | "\"cokeIndex\":[[0.0149,0.0148],[23.6,24.5],[1350.2,1423.5],[1.21,1.25],[0.28],[103542.3,135238.5],[104668.63,137826.5],[155678.2]]," + |
| | | "\"cokeRow1\":[[0.0,12.51],[81.0,34.3],[69.0,42.3],[86.0,56.4],[92.0,89.4]]," + |
| | | "\"cokeRow2\":[[0.0,45.3],[9.0,42.5],[81.0,31.2],[88.0,16.3]]," + |
| | | "\"cokeHeat2\":[135220.3,134720.3]," + |
| | | "\"cokeCOG2\":[64525.8,64824.2]," + |
| | | "\"cokeHomeIndex\":[[90.4,90.2],[80.3,78.5],[103.6,100.3],[280.9,270.4]]," + |
| | | "\"cokeHomeIndexInfo\":\"吨焦耗热量异常\"," + |
| | | "\"cokeCOG1\":[64435.5,64532.6]," + |
| | | "\"cokeHomePage\":[[124439.4,124428.4],[320.6],[224.3],[248305.4],[124436.2],[3.96],[0.43]]," + |
| | | "\"cokeTotal\":\"炼焦吨焦耗热量因煤气流量偏高、煤气水分偏低而增加23,经模型计算,延建议调整煤气流量,预计可使吨焦耗热量指标降低17\"" + |
| | | " }" + |
| | | "}"; |
| | | |
| | | @Override |
| | | public void run(String params) { |
| | |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | | calendar.set(Calendar.SECOND, 0); |
| | | calendar.set(Calendar.MINUTE, 0); |
| | | int hour = calendar.get(Calendar.HOUR_OF_DAY); |
| | | Date startDate = calendar.getTime(); |
| | | |
| | | calendar.set(Calendar.HOUR_OF_DAY, 0); |
| | | Date endDate = calendar.getTime(); |
| | | String clock = ""; |
| | | String analyClass = ""; |
| | | if (hour >= 8 && hour < 16) { |
| | | calendar.set(Calendar.HOUR_OF_DAY, 0); |
| | | startDate = calendar.getTime(); |
| | | calendar.add(Calendar.HOUR_OF_DAY, 8); |
| | | endDate = calendar.getTime(); |
| | | clock = DateUtils.format(startDate).concat("-").concat("A"); |
| | | analyClass = "甲班"; |
| | | } else if (hour >= 16 && hour < 24) { |
| | | calendar.set(Calendar.HOUR_OF_DAY, 8); |
| | | startDate = calendar.getTime(); |
| | | calendar.add(Calendar.HOUR_OF_DAY, 8); |
| | | endDate = calendar.getTime(); |
| | | clock = DateUtils.format(startDate).concat("-").concat("B"); |
| | | analyClass = "乙班"; |
| | | } else if (hour >= 0 && hour < 8) { |
| | | calendar.add(Calendar.DAY_OF_YEAR, -1); |
| | | calendar.set(Calendar.HOUR_OF_DAY, 16); |
| | | startDate = calendar.getTime(); |
| | | calendar.add(Calendar.HOUR_OF_DAY, 8); |
| | | endDate = calendar.getTime(); |
| | | clock = DateUtils.format(startDate).concat("-").concat("B"); |
| | | analyClass = "丙班"; |
| | | } |
| | | calendar.add(Calendar.DAY_OF_YEAR, -1); |
| | | Date startDate = calendar.getTime(); |
| | | String clock = DateUtils.format(startDate); |
| | | |
| | | // 调用模型 |
| | | JSONObject jsonObject = JSONObject.parseObject(jsonStr); |
| | |
| | | |
| | | // 保存报告 |
| | | String analyDate = DateUtils.format(startDate); |
| | | String analyContent = result.getString("cokeHomeIndexInfo"); |
| | | String relId = cokingTraceReportService.save(process, reportName, analyDate, analyClass, clock, analyContent); |
| | | String analyContent = clock + " " + result.getString("cokeHomeIndexInfo"); |
| | | String content = result.getString(total); |
| | | String relId = cokingTraceReportService.save(process, reportName, analyDate, clock, analyContent); |
| | | |
| | | // 保存一级分析指标 |
| | | saveAnalyInd(relId, process, analyDate, analyClass, analyContent); |
| | | cokingAnalyIndService.saveAnalyInd(relId, process, analyDate, analyContent); |
| | | |
| | | // 保存优化建议 |
| | | saveTraceSuggest(relId, process, clock, result); |
| | | cokingTraceSuggestService.saveTraceSuggest(relId, process, clock, content, SugObj); |
| | | |
| | | // 保存偏差值 |
| | | saveTraceDeviation(relId, process, clock, result); |
| | | cokingTraceDeviationService.saveTraceDeviation(relId, process, clock, result, CommonConstant.COKE_INDEX_CHARTCODE, row, SugObj); |
| | | |
| | | // 保存溯源指标 |
| | | cokingTraceIndService.saveTraceInd(relId, indType, clock); |
| | |
| | | ex.printStackTrace(); |
| | | } |
| | | logger.info("RunCokingTraceModelLJTask运行完成"); |
| | | } |
| | | |
| | | public void saveTraceSuggest(String relId, String process, String clock, JSONObject result) { |
| | | String cokeTotal = result.get("cokeTotal").toString(); |
| | | if (StringUtils.isBlank(cokeTotal)) { |
| | | logger.info("cokeTotal is null"); |
| | | return; |
| | | } |
| | | CokingTraceSuggestEntity suggestEntity = new CokingTraceSuggestEntity(); |
| | | suggestEntity.setRelId(relId); |
| | | suggestEntity.setProcess(process); |
| | | suggestEntity.setSugObj(SugObj); |
| | | suggestEntity.setClock(clock); |
| | | suggestEntity.setContent(cokeTotal); |
| | | suggestEntity.setCreateDate(new Date()); |
| | | cokingTraceSuggestService.save(suggestEntity); |
| | | } |
| | | |
| | | @Transactional |
| | | public void saveTraceDeviation(String relId, String process, String clock, 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())); |
| | | |
| | | List<String> coalRowKeys = new ArrayList<>(); |
| | | result.forEach((key, value) -> { |
| | | if (StringUtils.isNotBlank(key) && key.contains(cokeRow)) { |
| | | coalRowKeys.add(key); |
| | | } |
| | | |
| | | }); |
| | | |
| | | List<CokingTraceDeviationEntity> entityList = new ArrayList<>(); |
| | | for (String key : coalRowKeys) { |
| | | JSONArray rowArr = JSON.parseArray(result.get(key).toString()); |
| | | if (CollectionUtils.isEmpty(rowArr)) { |
| | | continue; |
| | | } |
| | | CokingTraceDeviationEntity entity = new CokingTraceDeviationEntity(); |
| | | entity.setRelId(relId); |
| | | entity.setProcess(process); |
| | | entity.setClock(clock); |
| | | entity.setSugObj(SugObj); |
| | | |
| | | entity.setInd1Name(steamIndexMaps.get(rowArr.getJSONArray(0).get(0).toString())); |
| | | entity.setInd1Value(rowArr.getJSONArray(0).get(1).toString()); |
| | | entity.setInd1Unit(""); |
| | | |
| | | entity.setInd2Name(steamIndexMaps.get(rowArr.getJSONArray(1).get(0).toString())); |
| | | entity.setInd2Value(rowArr.getJSONArray(1).get(1).toString()); |
| | | entity.setInd2Unit(""); |
| | | |
| | | if (rowArr.size() > 2) { |
| | | entity.setFac1Name(steamIndexMaps.get(rowArr.getJSONArray(2).get(0).toString())); |
| | | entity.setFac1Value(rowArr.getJSONArray(2).get(1).toString()); |
| | | entity.setFac1Unit(""); |
| | | } |
| | | if (rowArr.size() > 3) { |
| | | entity.setFac2Name(steamIndexMaps.get(rowArr.getJSONArray(3).get(0).toString())); |
| | | entity.setFac2Value(rowArr.getJSONArray(3).get(1).toString()); |
| | | entity.setFac2Unit(""); |
| | | } |
| | | if (rowArr.size() > 4) { |
| | | entity.setFac3Name(steamIndexMaps.get(rowArr.getJSONArray(4).get(0).toString())); |
| | | entity.setFac3Value(rowArr.getJSONArray(4).get(1).toString()); |
| | | entity.setFac3Unit(""); |
| | | } |
| | | if (rowArr.size() > 5) { |
| | | entity.setFac4Name(steamIndexMaps.get(rowArr.getJSONArray(5).get(0).toString())); |
| | | entity.setFac4Value(rowArr.getJSONArray(5).get(1).toString()); |
| | | entity.setFac4Unit(""); |
| | | } |
| | | if (rowArr.size() > 6) { |
| | | entity.setFac5Name(steamIndexMaps.get(rowArr.getJSONArray(6).get(0).toString())); |
| | | entity.setFac5Value(rowArr.getJSONArray(6).get(1).toString()); |
| | | entity.setFac5Unit(""); |
| | | } |
| | | entityList.add(entity); |
| | | } |
| | | |
| | | cokingTraceDeviationService.save(entityList); |
| | | } |
| | | |
| | | public void saveAnalyInd(String relId, String process, String analyDate, String analyClass, String analyContent) { |
| | | if (StringUtils.isBlank(analyContent)) { |
| | | logger.info("analyContent is null"); |
| | | return; |
| | | } |
| | | String[] analyContentArr = analyContent.split(";"); |
| | | List<CokingAnalyIndEntity> entityList = new ArrayList<>(); |
| | | for (int i = 0; i < analyContentArr.length; i++) { |
| | | CokingAnalyIndEntity analyIndEntity = new CokingAnalyIndEntity(); |
| | | analyIndEntity.setRelId(relId); |
| | | analyIndEntity.setAnalyType(process); |
| | | analyIndEntity.setAnalyDate(analyDate); |
| | | analyIndEntity.setAnalyClass(analyClass); |
| | | analyIndEntity.setAnalyContent(analyContentArr[i]); |
| | | analyIndEntity.setSort(i + 1); |
| | | entityList.add(analyIndEntity); |
| | | } |
| | | cokingAnalyIndService.save(entityList); |
| | | } |
| | | } |