| | |
| | | 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.CokingTraceReportEntity; |
| | | import com.iailab.module.ansteel.coking.entity.CokingTraceSuggestEntity; |
| | | import com.iailab.module.ansteel.coking.service.CokingAnalyIndService; |
| | | import com.iailab.module.ansteel.coking.service.CokingTraceDeviationService; |
| | | import com.iailab.module.ansteel.coking.service.CokingTraceReportService; |
| | | import com.iailab.module.ansteel.coking.service.CokingTraceSuggestService; |
| | | 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.util.CollectionUtils; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 干熄焦工序-异常溯源 |
| | | * |
| | | * @author lirm |
| | | * @Description |
| | | * @createTime 2025年04月17日 |
| | |
| | | @Autowired |
| | | private CokingAnalyIndService cokingAnalyIndService; |
| | | |
| | | private static final HashMap<String, Object> sugObjMap = new HashMap<String, Object>() {{ |
| | | put("1#", "1#干熄焦主蒸汽温度因装焦量、装焦温度偏低而降低13℃。经模型计算,建议调整XX,预计可使XX指标升高/降低XX"); |
| | | put("2#", "2#干熄焦蒸汽发生量因空气导入量偏高、锅炉入口温度偏低而减少13t。经模型计算,建议调整XX,预计可使XX指标升高/降低XX\n"); |
| | | @Autowired |
| | | private CokingTraceIndService cokingTraceIndService; |
| | | |
| | | @Autowired |
| | | private CokingTraceConfService cokingTraceConfService; |
| | | |
| | | @Autowired |
| | | private McsApi mcsApi; |
| | | |
| | | @Autowired |
| | | private DataPointApi dataPointApi; |
| | | |
| | | @Autowired |
| | | private IndItemApi indItemApi; |
| | | |
| | | private static final HashMap<String, Object> steamFirstColoumMap = new HashMap<String, Object>() {{ |
| | | put("steamFirstColoum0", "一级指标-偏差值"); |
| | | put("steamFirstColoum1", "二级指标-偏差值"); |
| | | put("steamFirstColoum2", "影响因素1-偏差值"); |
| | | put("steamFirstColoum3", "影响因素2-偏差值"); |
| | | put("steamFirstColoum4", "影响因素3-偏差值"); |
| | | put("steamFirstColoum5", "影响因素n-偏差值"); |
| | | }}; |
| | | |
| | | private static final HashMap<String, List<String>> deviationMap = new HashMap<String, List<String>>() {{ |
| | | put("1", Arrays.asList("1#", "一级指标-偏差值", "主蒸汽温度", "13", "℃")); |
| | | put("2", Arrays.asList("1#", "二级指标-偏差值", "装焦温度", "50", "℃")); |
| | | put("3", Arrays.asList("1#", "影响因素1-偏差值", "CO含量", "5", "%")); |
| | | put("4", Arrays.asList("1#", "影响因素2-偏差值", "H2含量", "4", "%")); |
| | | put("5", Arrays.asList("2#", "一级指标-偏差值", "蒸汽产量", "15", "t")); |
| | | put("6", Arrays.asList("2#", "二级指标-偏差值", "空气导入量", "350", "")); |
| | | put("7", Arrays.asList("2#", "影响因素1-偏差值", "干熄炉入口温度", "30", "℃")); |
| | | put("8", Arrays.asList("2#", "影响因素2-偏差值", "H2含量", "4", "%")); |
| | | private static final HashMap<String, Object> steamSecondColoumMap = new HashMap<String, Object>() {{ |
| | | put("steamSecondColoum0", "一级指标-偏差值"); |
| | | put("steamSecondColoum1", "二级指标-偏差值"); |
| | | put("steamSecondColoum2", "影响因素1-偏差值"); |
| | | put("steamSecondColoum3", "影响因素2-偏差值"); |
| | | put("steamSecondColoum4", "影响因素3-偏差值"); |
| | | put("steamSecondColoum5", "影响因素n-偏差值"); |
| | | }}; |
| | | |
| | | private static final String jsonStr="{\"result\":{" + |
| | | " \"steamTotal1\":\"2#干熄焦蒸汽发生量因空气导入量偏高、锅炉入口温度偏低而减少13t,经模型计算,建议调整空气导入量,预计可使主蒸汽流量指标升高20m3/h\",\n" + |
| | | " \"steamTotal2\":\"2#干熄焦蒸汽发生量因空气导入量偏高、锅炉入口温度偏低而减少13m3/h,经模型计算,建议调整循环风机转速,预计可使主蒸汽流量指标升高32m3/h\",\n" + |
| | | " \"steamFirstColoum0\":[[14,20],[14,30],[14,35]],\n" + |
| | | " \"steamFirstColoum1\":[[10,5],[11,15],[21,20]],\n" + |
| | | " \"steamFirstColoum2\":[[74,8],[36,18],[35,34]],\n" + |
| | | " \"steamFirstColoum3\":[[24,67],[6,12],[19,21]],\n" + |
| | | " \"steamFirstColoum4\":[[21,19],[22,31],[8,42]],\n" + |
| | | " \"steamFirstColoum5\":[[11,45],[9,62],[18,34]],\n" + |
| | | " \"steamSecondColoum0\":[[14,20],[14,50],[14,13]],\n" + |
| | | " \"steamSecondColoum1\":[[11,27],[10,35],[22,16]],\n" + |
| | | " \"steamSecondColoum2\":[[36,90],[35,34],[74,55]],\n" + |
| | | " \"steamSecondColoum3\":[[6,66],[19,73],[21,31]],\n" + |
| | | " \"steamSecondColoum4\":[[22,65],[8,22],[21,67]],\n" + |
| | | " \"steamSecondColoum5\":[[9,29],[11,56],[18,61]],\n" + |
| | | " \"steamHomePage\":[[663,617],[66.5,68.9]],\n" + |
| | | " \"steamHomeIndex\":[[90.4,90.2],[80.3,78],[103,100],[280,270]],\n" + |
| | | " \"steamHomeIndexInfo\":\"2月18日甲班:干熄焦产蒸汽量异常\",\n" + |
| | | " \"steamHomeErr\":\"2月18日循环风机转速数据异常(无数据)\"}}"; |
| | | |
| | | @Override |
| | | public void run(String params) { |
| | | logger.info("RunCokingTraceModelTask,参数为:{}", params); |
| | | try { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | int hour = calendar.get(Calendar.HOUR_OF_DAY); |
| | | // int hour = calendar.get(Calendar.HOUR_OF_DAY); |
| | | String yesterday = DateUtils.format(DateUtils.addDateDays(new Date(), -1), DateUtils.FORMAT_YEAR_MONTH_DAY); |
| | | String clock = ""; |
| | | String analyClass = ""; |
| | | int hour = 8; |
| | | 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", "甲班"); |
| | | tMap.put("analyClass", analyClass); |
| | | tMap.put("clock", clock); |
| | | tMap.put("analyContent", "锅炉蒸汽产量异常"); |
| | | tMap.put("analyContent", "干熄焦产蒸汽量异常"); |
| | | |
| | | saveTraceReport(tMap); |
| | | saveTraceSuggest(tMap); |
| | | saveTraceDeviation(tMap); |
| | | saveTraceAnalyInd(tMap); |
| | | |
| | | 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); |
| | | } |
| | | } catch (Exception ex) { |
| | | logger.error("RunCokingTraceModelTask运行异常"); |
| | | ex.printStackTrace(); |
| | |
| | | |
| | | } |
| | | |
| | | private void saveTraceReport(Map<String, Object> tMap) { |
| | | private void saveTraceReport(Map<String, Object> tMap,JSONObject result) { |
| | | CokingTraceReportEntity reportEntity = new CokingTraceReportEntity(); |
| | | reportEntity.setId(tMap.get("relId").toString()); |
| | | reportEntity.setProcess(tMap.get("process").toString()); |
| | |
| | | cokingTraceReportService.save(reportEntity); |
| | | } |
| | | |
| | | private void saveTraceSuggest(Map<String, Object> tMap) { |
| | | for (Map.Entry<String, Object> entry : sugObjMap.entrySet()) { |
| | | CokingTraceSuggestEntity suggestEntity = new CokingTraceSuggestEntity(); |
| | | suggestEntity.setRelId(tMap.get("relId").toString()); |
| | | suggestEntity.setProcess(tMap.get("process").toString()); |
| | | suggestEntity.setSugObj(entry.getKey()); |
| | | suggestEntity.setClock(tMap.get("clock").toString()); |
| | | suggestEntity.setContent(entry.getValue().toString()); |
| | | cokingTraceSuggestService.save(suggestEntity); |
| | | private void saveTraceSuggest(Map<String, Object> tMap,JSONObject result) { |
| | | for(int i=1;i<=2;i++){ |
| | | String steamTotal = result.get("steamTotal"+i).toString(); |
| | | if(StringUtils.isNotBlank(steamTotal)){ |
| | | CokingTraceSuggestEntity suggestEntity = new CokingTraceSuggestEntity(); |
| | | suggestEntity.setRelId(tMap.get("relId").toString()); |
| | | suggestEntity.setProcess(tMap.get("process").toString()); |
| | | suggestEntity.setSugObj(i+"#"); |
| | | suggestEntity.setClock(tMap.get("clock").toString()); |
| | | suggestEntity.setContent(steamTotal); |
| | | suggestEntity.setCreateDate(new Date()); |
| | | cokingTraceSuggestService.save(suggestEntity); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void saveTraceDeviation(Map<String, Object> tMap) { |
| | | for (Map.Entry<String, List<String>> entry : deviationMap.entrySet()) { |
| | | CokingTraceDeviationEntity deviationEntity = new CokingTraceDeviationEntity(); |
| | | deviationEntity.setRelId(tMap.get("relId").toString()); |
| | | deviationEntity.setProcess(tMap.get("process").toString()); |
| | | deviationEntity.setSugObj(entry.getValue().get(0)); |
| | | deviationEntity.setClock(tMap.get("clock").toString()); |
| | | deviationEntity.setGroupName(entry.getValue().get(1)); |
| | | deviationEntity.setIndName(entry.getValue().get(2)); |
| | | deviationEntity.setIndValue(entry.getValue().get(3)); |
| | | deviationEntity.setIndUnit(entry.getValue().get(4)); |
| | | deviationEntity.setCreateDate(new Date()); |
| | | private void saveTraceDeviation(Map<String, Object> tMap,JSONObject result) { |
| | | List<ChartParamDTO> list = mcsApi.getChartParamList(CommonConstant.STEAM_INDEX_CHARTCODE); |
| | | Map<String, String> steamIndexMaps = list.stream().collect(Collectors.toMap(ChartParamDTO::getParamCode, e -> e.getParamValue())); |
| | | for(int i=0;i<=5;i++){ |
| | | String steamFirstColoum = result.get("steamFirstColoum"+i).toString(); |
| | | if(StringUtils.isNotBlank(steamFirstColoum)){ |
| | | JSONArray responseArr = JSON.parseArray(steamFirstColoum); |
| | | 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("1#"); |
| | | deviationEntity.setGroupName(steamFirstColoumMap.get("steamFirstColoum"+i).toString()); |
| | | deviationEntity.setIndName(steamIndexMaps.get(element.get(0).toString())); |
| | | deviationEntity.setIndValue(element.get(1).toString()); |
| | | deviationEntity.setCreateDate(new Date()); |
| | | cokingTraceDeviationService.save(deviationEntity); |
| | | } |
| | | } |
| | | } |
| | | for(int i=0;i<=5;i++){ |
| | | String steamSecondColoum = result.get("steamSecondColoum"+i).toString(); |
| | | if(StringUtils.isNotBlank(steamSecondColoum)){ |
| | | JSONArray responseArr = JSON.parseArray(steamSecondColoum); |
| | | |
| | | cokingTraceDeviationService.save(deviationEntity); |
| | | 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("2#"); |
| | | deviationEntity.setGroupName(steamSecondColoumMap.get("steamSecondColoum" + i).toString()); |
| | | deviationEntity.setIndName(element.get(0).toString()); |
| | | deviationEntity.setIndValue(element.get(1).toString()); |
| | | deviationEntity.setCreateDate(new Date()); |
| | | cokingTraceDeviationService.save(deviationEntity); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | private void saveAnalyInd(Map<String, Object> tMap,JSONObject result) { |
| | | String[] analyContent = tMap.get("analyContent").toString().split(";"); |
| | | 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); |
| | | cokingAnalyIndService.save(analyIndEntity); |
| | | } |
| | | } |
| | | |
| | | private void saveTraceAnalyInd(Map<String, Object> tMap) { |
| | | 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(tMap.get("analyContent").toString()); |
| | | cokingAnalyIndService.save(analyIndEntity); |
| | | private 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; |
| | | } |
| | | 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.setIndName(conf.getIndName()); |
| | | cokingTraceIndEntity.setIndValue(value); |
| | | cokingTraceIndEntity.setIndUnit(conf.getIndUnit()); |
| | | cokingTraceIndService.save(cokingTraceIndEntity); |
| | | |
| | | } |
| | | } |
| | | } |