| | |
| | | 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.MdkScheduleReqDTO; |
| | | import com.iailab.module.model.api.mdk.dto.MdkScheduleRespDTO; |
| | | 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 CokingTraceConfService cokingTraceConfService; |
| | | |
| | | |
| | | @Autowired |
| | | private McsApi mcsApi; |
| | | |
| | | @Autowired |
| | | private MdkApi mdkApi; |
| | | |
| | | 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 row = "coalRow"; |
| | | |
| | | private final static String total = "coalPrepElecTotal1"; |
| | | |
| | | private static final String jsonStr = "{\n" + " " + |
| | | "\"result\": {\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]" + |
| | | " }" + |
| | | "}"; |
| | | private String scheduleCode = ""; |
| | | 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); |
| | | |
| | | // 调用模型 |
| | | /* 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(); |
| | | calendar.add(Calendar.DAY_OF_YEAR, 1); |
| | | calendar.add(Calendar.MINUTE, -3); |
| | | Date collectStartDate = calendar.getTime(); |
| | | |
| | | JSONObject jsonObject = new JSONObject(result); |
| | | JSONObject result2 = (JSONObject) JSON.toJSON(jsonObject.get("result"));*/ |
| | | // 查询模型结果 |
| | | 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 jsonObject = JSONObject.parseObject(jsonStr); |
| | | JSONObject result = (JSONObject) JSON.toJSON(jsonObject.get("result")); |
| | | |
| | | JSONObject result = JSONObject.parseObject(jsonStr); |
| | | if (Objects.isNull(result)) { |
| | | logger.info("模型结果为空"); |
| | | return; |
| | |
| | | |
| | | // 保存报告 |
| | | String analyDate = DateUtils.format(startDate); |
| | | String analyContent = clock + " " + result.getString("coalHomeIndexInfo"); |
| | | 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, startDate, endDate); |
| | | |
| | | } catch (Exception ex) { |
| | | logger.error("RunCokingTraceModelBMTask运行异常"); |
| | |
| | | } |
| | | logger.info("RunCokingTraceModelBMTask运行完成"); |
| | | } |
| | | |
| | | 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.set(Calendar.DAY_OF_MONTH, 1); |
| | | Date monthStartDate = 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("BMSY025")).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("BMSY026")).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(monthStartDate); |
| | | cokingTraceChartEntity.setEndTime(endDate); |
| | | cokingTraceChartEntity.setCreateDate(new Date()); |
| | | entityList.add(cokingTraceChartEntity); |
| | | }); |
| | | cokingTraceChartService.insert(entityList); |
| | | } |
| | | } |