| | |
| | | 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.data.api.ind.IndItemApi; |
| | | import com.iailab.module.data.api.point.DataPointApi; |
| | | 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 org.apache.commons.lang3.StringUtils; |
| | | 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 CokingTraceIndService cokingTraceIndService; |
| | | |
| | | @Autowired |
| | | private CokingTraceConfService cokingTraceConfService; |
| | | |
| | | @Autowired |
| | | private CokingTraceChartService cokingTraceChartService; |
| | | |
| | | @Autowired |
| | | private McsApi mcsApi; |
| | | |
| | | @Autowired |
| | | private DataPointApi dataPointApi; |
| | | private MdkApi mdkApi; |
| | | |
| | | @Autowired |
| | | private IndItemApi indItemApi; |
| | | |
| | | private final static String process = "备煤工序"; |
| | | private final static String process = TraceProcessTypeEnum.BM.getProcess(); |
| | | |
| | | private final static String reportName = "备煤工序异常溯源"; |
| | | |
| | |
| | | |
| | | private final static String indType = "备煤工序异常溯源"; |
| | | |
| | | private final static String coalRow = "coalRow"; |
| | | private final static String row = "coalRow"; |
| | | |
| | | private static final HashMap<String, Object> coalColoumMap = new HashMap<String, Object>() {{ |
| | | put("coalColoum0", "一级指标-偏差值"); |
| | | put("coalColoum1", "二级指标-偏差值"); |
| | | put("coalColoum2", "影响因素1-偏差值"); |
| | | }}; |
| | | |
| | | private static final HashMap<String, Object> historyPointMap = new HashMap<String, Object>() {{ |
| | | put("F0000101008", "备煤耗电"); |
| | | }}; |
| | | private final static String total = "coalPrepElecTotal1"; |
| | | |
| | | private static final String jsonStr = "{\n" + " " + |
| | | "\"result\": {\n" + |
| | | "\"coalPrepElec\":[1600.8,1613.5],\n" + |
| | | "\"coalPrepElecIndex\":[[0.8,0.73],[723,608],[1782,1782],[752,743],[729,783]],\n" + |
| | | "\"coalPrepElecTotal1\":\"1#粉碎机耗电因粉碎机偏高增加220KW/h,经模型计算,建建议调整单班用煤量,预计可使粉碎机耗电量指标降低170KW/h\",\n" + |
| | | "\"coalPrepElecTotal2\":\"1#粉碎机耗电量数据异常\",\n" + |
| | | "\"coalRow0\":[[0,450],[0,137],[0,342]],\n" + |
| | | "\"coalRow1\":[[0,450],[3,134],[1,142]],\n" + |
| | | "\"coalRow2\":[[4,142],[4,132],[4,349]],\n" + |
| | | "\"coalPrepElecHomePage\":[[50,42],[10,10]],\n" + |
| | | "\"coalHomeIndex\":[[90.4,90.2],[80.3,78],[103,100],[280,270]],\n" + |
| | | "\"coalIndexInfo\":\"2月18日甲班:备煤耗电异常\",\n" + |
| | | "\"coalErr\":\"2月18日粉碎机耗电数据异常(无数据)\"\n" + " }" + "}"; |
| | | "\"coalHomeIndexInfo\":\"备煤耗电偏高\"," + |
| | | "\"coalPrepElec\":[1600.8,1613.5]," + |
| | | "\"coalPrepElecTotal1\":\"备煤耗电量偏高,经模型计算,原因和调整建议如下:煤量异常,当前值2000, 建议调整煤量至区间[765.0,1020.0]\"," + |
| | | "\"coalPrepElecTime\":[[0.3,0.3],[1700.31,1900.2],[120.3]]," + |
| | | "\"coalPrepElecIndex\":[133527.2,283517.6,83451.5,233461.2,83564.4]," + |
| | | "\"coalRow0\":[[0.0,1000.3],[1.0,120.2],[7.0,1150.32]]," + |
| | | "\"coalRow1\":[[0.0,1000.5],[2.0,200.56],[7.0,120.2]]," + |
| | | "\"coalRow2\":[[0.0,1000.6],[3.0,261.7],[7.0,170.52]]," + |
| | | "\"coalPrepElecHomePage\":[503000.6,84.04]," + |
| | | "\"coalHomeIndex\":[30.0,4.6,523000.6]" + |
| | | " }" + |
| | | "}"; |
| | | |
| | | @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); |
| | | |
| | | // 调用模型 |
| | | /* MdkScheduleReqDTO dto = new MdkScheduleReqDTO(); |
| | | dto.setScheduleTime(calendar.getTime()); |
| | | dto.setScheduleCode(params); |
| | | MdkScheduleRespDTO mdkScheduleRespDTO = mdkApi.doSchedule(dto); |
| | | logger.info(params + "调度方案执行完成," + mdkScheduleRespDTO); |
| | | Map<String, Object> result = mdkScheduleRespDTO.getResult(); |
| | | |
| | | JSONObject jsonObject = new JSONObject(result); |
| | | JSONObject result2 = (JSONObject) JSON.toJSON(jsonObject.get("result"));*/ |
| | | |
| | | JSONObject jsonObject = JSONObject.parseObject(jsonStr); |
| | | JSONObject result = (JSONObject) JSON.toJSON(jsonObject.get("result")); |
| | | |
| | |
| | | |
| | | // 保存报告 |
| | | String analyDate = DateUtils.format(startDate); |
| | | String analyContent = result.getString("coalIndexInfo"); |
| | | String relId = cokingTraceReportService.save(process, reportName, analyDate, analyClass, clock, analyContent); |
| | | String analyContent = clock + " " + result.getString("coalHomeIndexInfo"); |
| | | 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("RunCokingTraceModelBMTask运行完成"); |
| | | } |
| | | |
| | | |
| | | public void saveTraceSuggest(String relId, String process, String clock, JSONObject result) { |
| | | String coalTotal = result.get("coalPrepElecTotal1").toString(); |
| | | if (StringUtils.isBlank(coalTotal)) { |
| | | logger.info("coalPrepElecTotal1 is null"); |
| | | return; |
| | | } |
| | | CokingTraceSuggestEntity suggestEntity = new CokingTraceSuggestEntity(); |
| | | suggestEntity.setRelId(relId); |
| | | suggestEntity.setProcess(process); |
| | | suggestEntity.setSugObj(SugObj); |
| | | suggestEntity.setClock(clock); |
| | | suggestEntity.setContent(coalTotal); |
| | | 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.COAL_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(coalRow)) { |
| | | 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); |
| | | } |
| | | } |