| | |
| | | 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.ansteel.common.enums.TraceProcessTypeEnum; |
| | | import com.iailab.module.model.api.mcs.McsApi; |
| | | import com.iailab.module.model.api.mcs.dto.ChartParamDTO; |
| | | import com.iailab.module.model.api.mdk.MdkApi; |
| | | 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.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * 化产工序异常溯源 |
| | |
| | | @Autowired |
| | | private MdkApi mdkApi; |
| | | |
| | | private final static String process = "化产工序"; |
| | | private final static String process = TraceProcessTypeEnum.HC.getProcess(); |
| | | |
| | | private final static String reportName = "化产工序异常溯源"; |
| | | |
| | |
| | | |
| | | private final static String indType = "化产工序异常溯源"; |
| | | |
| | | private final static String chemProdRow = "chemProdRow"; |
| | | private final static String row = "chemProdRow"; |
| | | |
| | | private final static String total = "chemProdTotal"; |
| | | |
| | | private static final String jsonStr = "{\n" + |
| | | "\"result\":{\n" + |
| | |
| | | "\"chemProdRow2\":[[0.0,42.3],[12.0,23.5],[35.0,54.33]]," + |
| | | "\"chemProdSteam\":[46.3]," + |
| | | "\"chemProdTotal\":\"蒸汽消耗量异常,经模型计算,原因和调整建议如下:电捕绝缘箱温度异常,当前值190,建议调整电捕绝缘箱温度至区间[80,110], 蒸氨塔塔顶温度异常,当前值190,建议调整蒸氨塔塔顶温度至区间[101,103]\"," + |
| | | "\"chemProdHomeIndexInfo\":\"2025-04-28 甲班 化产蒸汽消耗量异常\""+ |
| | | "\"chemProdHomeIndexInfo\":\"化产蒸汽消耗量异常\""+ |
| | | " }" + |
| | | "}"; |
| | | |
| | |
| | | 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("chemProdHomeIndexInfo"); |
| | | String relId = cokingTraceReportService.save(process, reportName, analyDate, analyClass, clock, analyContent); |
| | | String analyContent = clock + " " + result.getString("chemProdHomeIndexInfo"); |
| | | 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("RunCokingTraceModelHCTask运行完成"); |
| | | } |
| | | |
| | | public void saveTraceSuggest(String relId, String process, String clock, JSONObject result) { |
| | | String chemProdTotal = result.get("chemProdTotal").toString(); |
| | | if (StringUtils.isBlank(chemProdTotal)) { |
| | | logger.info("coalPrepElecTotal1 is null"); |
| | | return; |
| | | } |
| | | CokingTraceSuggestEntity suggestEntity = new CokingTraceSuggestEntity(); |
| | | suggestEntity.setRelId(relId); |
| | | suggestEntity.setProcess(process); |
| | | suggestEntity.setSugObj(SugObj); |
| | | suggestEntity.setClock(clock); |
| | | suggestEntity.setContent(chemProdTotal); |
| | | 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.CHEMPROD_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(chemProdRow)) { |
| | | 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(new BigDecimal(rowArr.getJSONArray(0).get(0).toString()).setScale(0,BigDecimal.ROUND_HALF_UP).toString())); |
| | | entity.setInd1Value(rowArr.getJSONArray(0).get(1).toString()); |
| | | entity.setInd1Unit(""); |
| | | |
| | | entity.setInd2Name(steamIndexMaps.get(new BigDecimal(rowArr.getJSONArray(1).get(0).toString()).setScale(0,BigDecimal.ROUND_HALF_UP).toString())); |
| | | entity.setInd2Value(rowArr.getJSONArray(1).get(1).toString()); |
| | | entity.setInd2Unit(""); |
| | | |
| | | if (rowArr.size() > 2) { |
| | | entity.setFac1Name(steamIndexMaps.get(new BigDecimal(rowArr.getJSONArray(2).get(0).toString()).setScale(0,BigDecimal.ROUND_HALF_UP).toString())); |
| | | entity.setFac1Value(rowArr.getJSONArray(2).get(1).toString()); |
| | | entity.setFac1Unit(""); |
| | | } |
| | | if (rowArr.size() > 3) { |
| | | entity.setFac2Name(steamIndexMaps.get(new BigDecimal(rowArr.getJSONArray(3).get(0).toString()).setScale(0,BigDecimal.ROUND_HALF_UP).toString())); |
| | | entity.setFac2Value(rowArr.getJSONArray(3).get(1).toString()); |
| | | entity.setFac2Unit(""); |
| | | } |
| | | if (rowArr.size() > 4) { |
| | | entity.setFac3Name(steamIndexMaps.get(new BigDecimal(rowArr.getJSONArray(4).get(0).toString()).setScale(0,BigDecimal.ROUND_HALF_UP).toString())); |
| | | entity.setFac3Value(rowArr.getJSONArray(4).get(1).toString()); |
| | | entity.setFac3Unit(""); |
| | | } |
| | | if (rowArr.size() > 5) { |
| | | entity.setFac4Name(steamIndexMaps.get(new BigDecimal(rowArr.getJSONArray(5).get(0).toString()).setScale(0,BigDecimal.ROUND_HALF_UP).toString())); |
| | | entity.setFac4Value(rowArr.getJSONArray(5).get(1).toString()); |
| | | entity.setFac4Unit(""); |
| | | } |
| | | if (rowArr.size() > 6) { |
| | | entity.setFac5Name(steamIndexMaps.get(new BigDecimal(rowArr.getJSONArray(6).get(0).toString()).setScale(0,BigDecimal.ROUND_HALF_UP).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.delete(process, analyDate, analyClass); |
| | | cokingAnalyIndService.save(entityList); |
| | | } |
| | | } |