From 867e3d0bd0760950ed0dc7a303106e47063d0928 Mon Sep 17 00:00:00 2001 From: liriming <1343021927@qq.com> Date: 星期四, 24 四月 2025 17:48:48 +0800 Subject: [PATCH] 定时任务修改 --- ansteel-biz/src/main/java/com/iailab/module/ansteel/job/task/RunCokingTraceModelLJTask.java | 265 +++++++++++++++++++++------------------------------- 1 files changed, 109 insertions(+), 156 deletions(-) diff --git a/ansteel-biz/src/main/java/com/iailab/module/ansteel/job/task/RunCokingTraceModelLJTask.java b/ansteel-biz/src/main/java/com/iailab/module/ansteel/job/task/RunCokingTraceModelLJTask.java index 1ee01e1..ce57dff 100644 --- a/ansteel-biz/src/main/java/com/iailab/module/ansteel/job/task/RunCokingTraceModelLJTask.java +++ b/ansteel-biz/src/main/java/com/iailab/module/ansteel/job/task/RunCokingTraceModelLJTask.java @@ -4,12 +4,12 @@ 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.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.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; @@ -19,7 +19,6 @@ 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; @@ -65,6 +64,14 @@ @Autowired private IndItemApi indItemApi; + private final static String process = "炼焦工序"; + + private final static String reportName = "炼焦工序异常溯源"; + + private final static String SugObj = "LJ"; + + private final static String indType = "炼焦工序异常溯源"; + private static final HashMap<String, Object> cokeColoumMap = new HashMap<String, Object>() {{ put("cokeColoum0", "一级指标-偏差值"); put("cokeColoum1", "二级指标-偏差值"); @@ -79,24 +86,22 @@ 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" + - "}"; + 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) { @@ -105,46 +110,65 @@ 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); + calendar.set(Calendar.MINUTE, 0); 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"); + 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 == 8) { - clock = yesterday.concat("-").concat("B"); + } 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 == 16) { - clock = yesterday.concat("-").concat("C"); + } 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 = "丙班"; } - 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 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); + + if (Objects.isNull(result)) { + logger.info("模型结果为空"); + return; } + + // 保存报告 + String analyDate = DateUtils.format(startDate); + String analyContent = result.getString("coalIndexInfo"); + String relId = cokingTraceReportService.save(process, reportName, analyDate, analyClass, clock, analyContent); + + // 保存一级分析指标 + saveAnalyInd(relId, process, analyDate, analyClass, analyContent); + + // 保存优化建议 + saveTraceSuggest(relId, process, clock, result); + + // 保存偏差值 + saveTraceDeviation(relId, process, clock, result); + + // 保存溯源指标 + cokingTraceIndService.saveTraceInd(relId, indType, clock); + + // 保存溯源折线图 + cokingTraceChartService.save(relId, clock, indType, startDate, endDate); + } catch (Exception ex) { logger.error("RunCokingTraceModelLJTask运行异常"); ex.printStackTrace(); @@ -152,49 +176,39 @@ 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) { + public void saveTraceSuggest(String relId, String process, String clock, 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); + 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); } - public void saveTraceDeviation(Map<String, Object> tMap,JSONObject result) { + @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())); - for(int i=0;i<=5;i++){ - String cokeColoum = result.get("cokeColoum"+i).toString(); - if(StringUtils.isNotBlank(cokeColoum)){ + 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.setRelId(relId); + deviationEntity.setProcess(process); + deviationEntity.setClock(clock); + deviationEntity.setSugObj(SugObj); + 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()); @@ -205,84 +219,23 @@ } } - public void saveAnalyInd(Map<String, Object> tMap,JSONObject result) { - String[] analyContent = tMap.get("analyContent").toString().split(";"); + 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<analyContent.length;i++){ + for (int i = 0; i < analyContentArr.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); + 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); - } - - 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); } } \ No newline at end of file -- Gitblit v1.9.3