| | |
| | | package com.iailab.module.shasteel.mq.consumer; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.iailab.framework.common.util.date.DateUtils; |
| | | import com.iailab.module.model.api.mcs.McsApi; |
| | |
| | | // 最早调度时间 |
| | | private static Date earliestScheduleTime = null; |
| | | |
| | | private static Date lastScheduleTime = null; |
| | | |
| | | /** |
| | | * 监听报警信息,执行调度 |
| | | * 监听报警信息,执行煤气调度 |
| | | * |
| | | * @param message |
| | | */ |
| | | @RabbitListener(queues = QueueModelAlarmConfig.QUEUE_NAME) |
| | | public void listen(Message message) { |
| | | log.info("监听报警信息,执行煤气调度"); |
| | | String routingKey = message.getMessageProperties().getReceivedRoutingKey(); |
| | | log.info("routingKey:" + routingKey); |
| | | String messageBody = new String(message.getBody()); |
| | |
| | | log.info("过滤旧消息"); |
| | | return; |
| | | } |
| | | |
| | | // 判断predictTime 是否大于outTime,否则不执行调度 |
| | | if (earliestScheduleTime != null && predictTime.compareTo(earliestScheduleTime) < 0) { |
| | | if (!ModelPredictFinishConsumer.finishModuleMap.containsKey(predictTime.getTime())) { |
| | | log.info("finishModuleMap not containsKey:" + predictTime.getTime()); |
| | | return; |
| | | } |
| | | List<String> finishModuleList = ModelPredictFinishConsumer.finishModuleMap.get(predictTime.getTime()); |
| | | if (CollectionUtils.isEmpty(finishModuleList)) { |
| | | log.info("finishModuleList is empty"); |
| | | return; |
| | | } |
| | | if (!finishModuleList.contains(CommonConstant.NET_BFG) || !finishModuleList.contains(CommonConstant.NET_COG) || |
| | | !finishModuleList.contains(CommonConstant.NET_LDG)) { |
| | | log.info("finishModuleList:" + JSONArray.toJSONString(finishModuleList)); |
| | | log.info("等待全部预测完成"); |
| | | return; |
| | | } |
| | | log.info("已全部预测完成,清空finishModuleMap"); |
| | | ModelPredictFinishConsumer.finishModuleMap.clear(); |
| | | |
| | | List<AlarmMessageRespDTO> alarmList = JSONObject.parseArray(messageJson.get("alarmList").toString(),AlarmMessageRespDTO.class); |
| | | // 取出最小outTime |
| | | Date minOutTime = alarmList.stream().filter(e -> e.getOutTime() != null).map(AlarmMessageRespDTO::getOutTime).min(Date::compareTo).get(); |
| | | earliestScheduleTime = minOutTime; |
| | | |
| | | |
| | | // 查找需要执行的调度方案 |
| | | log.info("查找需要执行的调度方案"); |
| | | List<StScheduleSchemeDTO> scheduleSchemeList = mcsApi.listScheduleScheme(ScheduleTriggerMethodEnum.EVENT.getCode(), routingKey); |
| | | if (CollectionUtils.isEmpty(scheduleSchemeList)) { |
| | | log.info("routingKey:" + routingKey + ",调度方案为空。"); |
| | | return; |
| | | } |
| | | for (StScheduleSchemeDTO stScheduleSchemeDTO : scheduleSchemeList) { |
| | | String runKey = "GasSchedule_" + stScheduleSchemeDTO.getCode() + "_" + predictTime.getTime(); |
| | | if (lastScheduleTime != null && stScheduleSchemeDTO.getAdjustRate() != null && stScheduleSchemeDTO.getAdjustRate() > 0 && |
| | | (predictTime.getTime() - lastScheduleTime.getTime() > 1000 * 60 * stScheduleSchemeDTO.getAdjustRate().longValue()) ) { |
| | | log.info("调整速率有效期内,跳过执行"); |
| | | continue; |
| | | } |
| | | String runKey = "GasSchedule_" + stScheduleSchemeDTO.getCode() + "_" + predictTime.getTime(); |
| | | log.info("runKey:" + runKey); |
| | | log.info("lastRunGasSchedule:" + lastRunGasSchedule); |
| | | if (lastRunGasSchedule.equals(runKey)) { |
| | | log.info("lastRunGasSchedule:" + lastRunGasSchedule + "已执行完成"); |
| | | continue; |
| | | } |
| | | lastRunGasSchedule = runKey; |
| | |
| | | Boolean simAdjustFlag = mdkApi.predictSimAdjust(simAdjustReqDTO); |
| | | if (simAdjustFlag) { |
| | | log.info("模拟调整成功,ScheduleCode:" + CommonConstant.GAS_MODEL_CODE); |
| | | }else { |
| | | } else { |
| | | log.error("模拟调整失败,simAdjustReqDTO:" + simAdjustReqDTO); |
| | | } |
| | | |
| | |
| | | break; |
| | | } |
| | | } |
| | | |
| | | lastScheduleTime = predictTime; |
| | | } |
| | | |
| | | private void saveScheduleSuggest(String title, Object content, String scheduleObj, Date scheduleTime) { |