| | |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 压缩空气优化调度 |
| | |
| | | |
| | | @Autowired |
| | | private MdkApi mdkApi; |
| | | |
| | | /** |
| | | * 调度建议内容 |
| | | */ |
| | | private static Map<String, String> airAdjustMode = new HashMap<>(); |
| | | |
| | | /** |
| | | * 调度建议时间 |
| | | */ |
| | | private static Map<String, Date> airLastSugTime = new HashMap<>(); |
| | | |
| | | @Override |
| | | public void run(String params) { |
| | |
| | | logger.info("调度结果异常,STATUS=" + mdkScheduleRespDTO.getStatusCode()); |
| | | return; |
| | | } |
| | | |
| | | // 保存预警信息 |
| | | if (mdkScheduleRespDTO.getResult().get("pressureLWarning") != null && |
| | | StringUtils.isNotEmpty(mdkScheduleRespDTO.getResult().get("pressureLWarning").toString())) { |
| | | String pressureLWarning = mdkScheduleRespDTO.getResult().get("pressureLWarning").toString(); |
| | | AlarmMessageRespDTO alarm = new AlarmMessageRespDTO(); |
| | | alarm.setTitle("压力低于下限预警"); |
| | | alarm.setContent(pressureLWarning); |
| | | alarm.setAlarmObj(scheme.getScheduleObj()); |
| | | alarm.setAlarmType("低于下限"); |
| | | alarm.setAlarmTime(scheduleTime); |
| | | mcsApi.createAlarmMessage(alarm); |
| | | this.saveAlarmMessage("空压机预警", mdkScheduleRespDTO.getResult().get("pressureLWarning"), scheme.getScheduleObj(), "低于下限",scheduleTime, scheme.getWarningAdjustRate()); |
| | | } |
| | | |
| | | |
| | | if (mdkScheduleRespDTO.getResult().get("pressureHWarning") != null && |
| | | StringUtils.isNotEmpty(mdkScheduleRespDTO.getResult().get("pressureHWarning").toString())) { |
| | | String pressureHWarning = mdkScheduleRespDTO.getResult().get("pressureHWarning").toString(); |
| | | AlarmMessageRespDTO alarm = new AlarmMessageRespDTO(); |
| | | alarm.setTitle("空压机预警"); |
| | | alarm.setContent(pressureHWarning); |
| | | alarm.setAlarmObj(scheme.getScheduleObj()); |
| | | alarm.setAlarmType("高于上限"); |
| | | alarm.setAlarmTime(scheduleTime); |
| | | mcsApi.createAlarmMessage(alarm); |
| | | this.saveAlarmMessage("空压机预警", mdkScheduleRespDTO.getResult().get("pressureHWarning"), scheme.getScheduleObj(), "高于上限",scheduleTime, scheme.getWarningAdjustRate()); |
| | | } |
| | | |
| | | // 保存调度建议 |
| | | if (mdkScheduleRespDTO.getResult().get("dispatchStart") != null && |
| | | StringUtils.isNotEmpty(mdkScheduleRespDTO.getResult().get("dispatchStart").toString())) { |
| | | String dispatchStart = mdkScheduleRespDTO.getResult().get("dispatchStart").toString(); |
| | | ScheduleSuggestRespDTO suggest = new ScheduleSuggestRespDTO(); |
| | | suggest.setTitle("空压机启动调度建议"); |
| | | suggest.setContent(dispatchStart); |
| | | suggest.setScheduleObj(scheme.getScheduleObj()); |
| | | suggest.setScheduleTime(scheduleTime); |
| | | suggest.setSort(0); |
| | | mcsApi.createScheduleSuggest(suggest); |
| | | } |
| | | |
| | | if (mdkScheduleRespDTO.getResult().get("dispatchClose") != null && |
| | | StringUtils.isNotEmpty(mdkScheduleRespDTO.getResult().get("dispatchClose").toString())) { |
| | | String dispatchClose = mdkScheduleRespDTO.getResult().get("dispatchClose").toString(); |
| | | ScheduleSuggestRespDTO suggest = new ScheduleSuggestRespDTO(); |
| | | suggest.setTitle("空压机关停调度建议"); |
| | | suggest.setContent(dispatchClose); |
| | | suggest.setScheduleObj(scheme.getScheduleObj()); |
| | | suggest.setScheduleTime(scheduleTime); |
| | | suggest.setSort(0); |
| | | mcsApi.createScheduleSuggest(suggest); |
| | | } |
| | | |
| | | this.saveScheduleSuggest("空压机启动调度建议", mdkScheduleRespDTO.getResult().get("dispatchStart"), scheme.getScheduleObj(), |
| | | scheduleTime, scheme.getAdjustRate()); |
| | | this.saveScheduleSuggest("空压机关停调度建议", mdkScheduleRespDTO.getResult().get("dispatchClose"), scheme.getScheduleObj(), |
| | | scheduleTime, scheme.getAdjustRate()); |
| | | logger.info(params + "调度方案执行完成"); |
| | | } catch (Exception ex) { |
| | | logger.error("RunScheduleAirDispatchTask运行异常"); |
| | |
| | | } |
| | | logger.info("RunScheduleAirDispatchTask运行完成"); |
| | | } |
| | | |
| | | private void saveScheduleSuggest(String title, Object content, String scheduleObj, Date scheduleTime, int adjustRate) { |
| | | if (content == null) { |
| | | logger.info(title + "调整值为空,不产生建议"); |
| | | return; |
| | | } |
| | | String contentStr = content.toString(); |
| | | if (StringUtils.isBlank(contentStr)) { |
| | | logger.info(title + "调整值为空,不产生建议"); |
| | | return; |
| | | } |
| | | if (airAdjustMode.containsKey(title) && airAdjustMode.get(title).equals(contentStr) && |
| | | airLastSugTime.containsKey(title) && (scheduleTime.getTime() - airLastSugTime.get(title).getTime() <= Integer.valueOf(adjustRate).longValue() * 60 * 1000)) { |
| | | logger.info("调整建议在有效期内"); |
| | | return; |
| | | } |
| | | airAdjustMode.put(title, contentStr); |
| | | airLastSugTime.put(title, scheduleTime); |
| | | |
| | | ScheduleSuggestRespDTO suggest = new ScheduleSuggestRespDTO(); |
| | | suggest.setTitle(title); |
| | | suggest.setContent(content.toString()); |
| | | suggest.setScheduleObj(scheduleObj); |
| | | suggest.setScheduleTime(scheduleTime); |
| | | suggest.setSort(0); |
| | | mcsApi.createScheduleSuggest(suggest); |
| | | } |
| | | |
| | | private void saveAlarmMessage(String title, Object content, String scheduleObj,String alarmType, Date scheduleTime, int warningAdjustRate) { |
| | | if (content == null) { |
| | | logger.info(title + "预警信息为空,不产生预警"); |
| | | return; |
| | | } |
| | | String contentStr = content.toString(); |
| | | if (StringUtils.isBlank(contentStr)) { |
| | | logger.info(title + "预警信息为空,不产生预警"); |
| | | return; |
| | | } |
| | | if (airAdjustMode.containsKey(title) && airAdjustMode.get(title).equals(contentStr) && |
| | | airLastSugTime.containsKey(title) && (scheduleTime.getTime() - airLastSugTime.get(title).getTime() <= Integer.valueOf(warningAdjustRate).longValue() * 60 * 1000)) { |
| | | logger.info("预警信息在有效期内"); |
| | | return; |
| | | } |
| | | airAdjustMode.put(title, contentStr); |
| | | airLastSugTime.put(title, scheduleTime); |
| | | |
| | | AlarmMessageRespDTO alarm = new AlarmMessageRespDTO(); |
| | | alarm.setTitle(title); |
| | | alarm.setContent(contentStr); |
| | | alarm.setAlarmObj(scheduleObj); |
| | | alarm.setAlarmType(alarmType); |
| | | alarm.setAlarmTime(scheduleTime); |
| | | mcsApi.createAlarmMessage(alarm); |
| | | } |
| | | } |