| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.iailab.framework.common.util.date.DateUtils; |
| | | import com.iailab.module.ansteel.coking.entity.CokingTraceChartEntity; |
| | | import com.iailab.module.ansteel.coking.entity.CokingTraceConfEntity; |
| | | 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.mdk.MdkApi; |
| | | import com.iailab.module.model.api.mdk.dto.StScheduleRecordVO; |
| | | 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.Calendar; |
| | | import java.util.Date; |
| | | import java.util.Objects; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 化产工序异常溯源 |
| | |
| | | private CokingTraceChartService cokingTraceChartService; |
| | | |
| | | @Autowired |
| | | private McsApi mcsApi; |
| | | private CokingTraceConfService cokingTraceConfService; |
| | | |
| | | @Autowired |
| | | private MdkApi mdkApi; |
| | | private McsApi mcsApi; |
| | | |
| | | private final static String process = TraceProcessTypeEnum.HC.getProcess(); |
| | | |
| | |
| | | |
| | | private final static String indType = "化产工序异常溯源"; |
| | | |
| | | private final static String row = "chemProdRow"; |
| | | |
| | | private final static String total = "chemProdTotal"; |
| | | |
| | | private static final String jsonStr = "{\n" + |
| | | "\"result\":{\n" + |
| | | "\"chemProdHomePage\":[1782.7,0.8]," + |
| | | "\"chemProdElec\":[794680.52]," + |
| | | "\"chemProdIndex\":[16.3,2.57,0.017,0.745,658731.5]," + |
| | | "\"chemProdRow0\":[[0.0,42.3],[5.0,1342.5],[10.0,122.5]]," + |
| | | "\"chemProdRow1\":[[0.0,42.3],[7.0,12.5],[9.0,17.45]]," + |
| | | "\"chemProdRow2\":[[0.0,42.3],[12.0,23.5],[35.0,54.33]]," + |
| | | "\"chemProdSteam\":[46.3]," + |
| | | "\"chemProdTotal\":\"蒸汽消耗量异常,经模型计算,原因和调整建议如下:电捕绝缘箱温度异常,当前值190,建议调整电捕绝缘箱温度至区间[80,110], 蒸氨塔塔顶温度异常,当前值190,建议调整蒸氨塔塔顶温度至区间[101,103]\"," + |
| | | "\"chemProdHomeIndexInfo\":\"化产蒸汽消耗量异常\""+ |
| | | " }" + |
| | | "}"; |
| | | private String scheduleCode = "AnSteelChemProSteamTrack"; //焦化化产蒸汽消耗模型 |
| | | private final String finalResultStrKey = "finalResultStr"; |
| | | private final String resultListKey = "resultList"; |
| | | |
| | | @Override |
| | | public void run(String params) { |
| | |
| | | Date startDate = calendar.getTime(); |
| | | String clock = DateUtils.format(startDate); |
| | | |
| | | // 调用模型 |
| | | JSONObject jsonObject = JSONObject.parseObject(jsonStr); |
| | | JSONObject result = (JSONObject) JSON.toJSON(jsonObject.get("result")); |
| | | calendar.add(Calendar.DAY_OF_YEAR, 1); |
| | | calendar.add(Calendar.MINUTE, -3); |
| | | Date collectStartDate = calendar.getTime(); |
| | | |
| | | calendar.add(Calendar.DAY_OF_YEAR, -6); |
| | | calendar.set(Calendar.MINUTE, 0); |
| | | calendar.set(Calendar.HOUR_OF_DAY, 0);//化产折线图用的时间 前七天 |
| | | Date chartStartDate = calendar.getTime(); |
| | | |
| | | // 查询模型结果 |
| | | List<StScheduleRecordVO> lastScheduleData = mcsApi.getLastScheduleData(scheduleCode, 1); |
| | | if (CollectionUtils.isEmpty(lastScheduleData)) { |
| | | logger.info("模型结果为空"); |
| | | return; |
| | | } |
| | | StScheduleRecordVO stScheduleRecordVO = lastScheduleData.get(0); |
| | | if (stScheduleRecordVO == null) { |
| | | logger.info("模型结果为空"); |
| | | return; |
| | | } |
| | | String jsonStr = stScheduleRecordVO.getResultData(); |
| | | |
| | | JSONObject result = JSONObject.parseObject(jsonStr); |
| | | if (Objects.isNull(result)) { |
| | | logger.info("模型结果为空"); |
| | | return; |
| | |
| | | |
| | | // 保存报告 |
| | | String analyDate = DateUtils.format(startDate); |
| | | String analyContent = clock + " " + result.getString("chemProdHomeIndexInfo"); |
| | | String content = result.getString(total); |
| | | String analyContent = "化产异常"; |
| | | String relId = cokingTraceReportService.save(process, reportName, analyDate, clock, analyContent); |
| | | |
| | | // 保存一级分析指标 |
| | | cokingAnalyIndService.saveAnalyInd(relId, process, analyDate, analyContent); |
| | | |
| | | // 保存优化建议 |
| | | cokingTraceSuggestService.saveTraceSuggest(relId, process, clock, content, SugObj); |
| | | String suggest = result.getString(finalResultStrKey); |
| | | cokingTraceSuggestService.saveTraceSuggest(relId, process, clock, suggest, SugObj); |
| | | |
| | | // 保存偏差值 |
| | | cokingTraceDeviationService.saveTraceDeviation(relId, process, clock, result, CommonConstant.COKE_INDEX_CHARTCODE, row, SugObj); |
| | | String jsonString = result.getString(resultListKey); |
| | | cokingTraceDeviationService.saveTraceDeviation(relId, process, clock, jsonString, SugObj); |
| | | |
| | | // 保存溯源指标 |
| | | cokingTraceIndService.saveTraceInd(relId, indType, clock); |
| | | cokingTraceIndService.saveTraceInd(relId, indType, clock,collectStartDate,endDate); |
| | | |
| | | // 保存溯源折线图 |
| | | cokingTraceChartService.save(relId, clock, indType, startDate, endDate); |
| | | saveTraceChart(relId, clock, indType, chartStartDate, endDate); |
| | | |
| | | } catch (Exception ex) { |
| | | logger.error("RunCokingTraceModelHCTask运行异常"); |
| | |
| | | } |
| | | logger.info("RunCokingTraceModelHCTask运行完成"); |
| | | } |
| | | |
| | | public void saveTraceChart(String relId, String clock, String indType, Date startDate, Date endDate) { |
| | | logger.info("查询需要保存chart的配置"); |
| | | |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | | calendar.set(Calendar.SECOND, 0); |
| | | calendar.set(Calendar.MINUTE, 0); |
| | | calendar.set(Calendar.HOUR_OF_DAY, 0); |
| | | calendar.add(Calendar.DAY_OF_YEAR, -1); |
| | | Date start = calendar.getTime(); |
| | | |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("indType", indType); |
| | | map.put("ext1", "chart"); |
| | | List<CokingTraceConfEntity> list = cokingTraceConfService.list(map); |
| | | if (CollectionUtils.isEmpty(list)) { |
| | | return; |
| | | } |
| | | logger.info("list.size={}", list.size()); |
| | | |
| | | List<CokingTraceChartEntity> entityList = new ArrayList<>(); |
| | | |
| | | List<CokingTraceConfEntity> listMin = list.stream().filter(e -> !e.getIndCode().equals("HCSY032")).collect(Collectors.toList()); |
| | | |
| | | listMin.forEach(value -> { |
| | | CokingTraceChartEntity cokingTraceChartEntity = new CokingTraceChartEntity(); |
| | | cokingTraceChartEntity.setRelId(relId); |
| | | cokingTraceChartEntity.setName(value.getIndName()); |
| | | cokingTraceChartEntity.setClock(clock); |
| | | cokingTraceChartEntity.setDataType(value.getDataType()); |
| | | cokingTraceChartEntity.setDataNo(value.getPointNo()); |
| | | cokingTraceChartEntity.setStartTime(startDate); |
| | | cokingTraceChartEntity.setEndTime(endDate); |
| | | cokingTraceChartEntity.setCreateDate(new Date()); |
| | | entityList.add(cokingTraceChartEntity); |
| | | }); |
| | | |
| | | List<CokingTraceConfEntity> listMonth = list.stream().filter(e -> e.getIndCode().equals("HCSY032")).collect(Collectors.toList()); |
| | | |
| | | listMonth.forEach(value -> { |
| | | CokingTraceChartEntity cokingTraceChartEntity = new CokingTraceChartEntity(); |
| | | cokingTraceChartEntity.setRelId(relId); |
| | | cokingTraceChartEntity.setName(value.getIndName()); |
| | | cokingTraceChartEntity.setClock(clock); |
| | | cokingTraceChartEntity.setDataType(value.getDataType()); |
| | | cokingTraceChartEntity.setDataNo(value.getPointNo()); |
| | | cokingTraceChartEntity.setStartTime(start); |
| | | cokingTraceChartEntity.setEndTime(endDate); |
| | | cokingTraceChartEntity.setCreateDate(new Date()); |
| | | entityList.add(cokingTraceChartEntity); |
| | | }); |
| | | cokingTraceChartService.insert(entityList); |
| | | } |
| | | } |