From 5ca9753118a262a7bb2448efde80fb3b2262191c Mon Sep 17 00:00:00 2001
From: 潘志宝 <979469083@qq.com>
Date: 星期二, 07 一月 2025 10:27:03 +0800
Subject: [PATCH] 压缩空气优化调度

---
 shasteel-biz/src/main/java/com/iailab/module/shasteel/job/task/RunScheduleAirDispatchTask.java |  128 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 128 insertions(+), 0 deletions(-)

diff --git a/shasteel-biz/src/main/java/com/iailab/module/shasteel/job/task/RunScheduleAirDispatchTask.java b/shasteel-biz/src/main/java/com/iailab/module/shasteel/job/task/RunScheduleAirDispatchTask.java
new file mode 100644
index 0000000..6d424e8
--- /dev/null
+++ b/shasteel-biz/src/main/java/com/iailab/module/shasteel/job/task/RunScheduleAirDispatchTask.java
@@ -0,0 +1,128 @@
+package com.iailab.module.shasteel.job.task;
+
+import com.iailab.module.model.api.mcs.McsApi;
+import com.iailab.module.model.api.mcs.dto.AlarmMessageRespDTO;
+import com.iailab.module.model.api.mcs.dto.ScheduleSuggestRespDTO;
+import com.iailab.module.model.api.mcs.dto.StScheduleSchemeDTO;
+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.enums.CommonConstant;
+import com.iailab.module.model.enums.ScheduleTriggerMethodEnum;
+import org.apache.commons.lang3.StringUtils;
+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.List;
+
+/**
+ * 压缩空气优化调度
+ * 定时触发 30 0/2 * * * ?
+ * 压力低于下限预警信息	pressureLWarning
+ * 压力高于上限预警信息	pressureHWarning
+ * 空压机启动调度建议	dispatchStart
+ * 空压机关停调度建议	dispatchClose
+ *
+ * @author PanZhibao
+ * @Description
+ * @createTime 2025年01月07日
+ */
+@Component("runScheduleAirDispatchTask")
+public class RunScheduleAirDispatchTask implements ITask {
+    private Logger logger = LoggerFactory.getLogger(getClass());
+
+    @Autowired
+    private McsApi mcsApi;
+
+    @Autowired
+    private MdkApi mdkApi;
+
+    @Override
+    public void run(String params) {
+        logger.info("RunScheduleAirDispatchTask,参数为:{}", params);
+        try {
+            Calendar calendar = Calendar.getInstance();
+            calendar.set(Calendar.MILLISECOND, 0);
+            calendar.set(Calendar.SECOND, 0);
+            Date scheduleTime = calendar.getTime();
+            if (StringUtils.isEmpty(params)) {
+                logger.info("参数为空");
+                return;
+            }
+
+            // 根据条件查找方案
+            List<StScheduleSchemeDTO> schemeList = mcsApi.listScheduleScheme(ScheduleTriggerMethodEnum.JOB.getCode(), params);
+            if (CollectionUtils.isEmpty(schemeList)) {
+                logger.info("方案为空");
+                return;
+            }
+
+            StScheduleSchemeDTO scheme = schemeList.get(0);
+            MdkScheduleReqDTO dto = new MdkScheduleReqDTO();
+            dto.setScheduleTime(scheduleTime);
+            dto.setScheduleCode(scheme.getCode());
+            MdkScheduleRespDTO mdkScheduleRespDTO = mdkApi.doSchedule(dto);
+            if (CommonConstant.MDK_STATUS_100.equals(mdkScheduleRespDTO.getStatusCode())) {
+                logger.info("调度结果异常,STATUS=" + mdkScheduleRespDTO.getStatusCode());
+                return;
+            }
+
+            // 保存预警信息
+            String pressureLWarning = mdkScheduleRespDTO.getResult().get("pressureLWarning").toString();
+            if (StringUtils.isNotBlank(pressureLWarning)) {
+                AlarmMessageRespDTO alarm = new AlarmMessageRespDTO();
+                alarm.setTitle("压力低于下限预警");
+                alarm.setContent(pressureLWarning);
+                alarm.setAlarmObj(scheme.getScheduleObj());
+                alarm.setAlarmType("低于下限");
+                alarm.setAlarmTime(scheduleTime);
+                mcsApi.createAlarmMessage(alarm);
+            }
+
+            String pressureHWarning = mdkScheduleRespDTO.getResult().get("pressureHWarning").toString();
+            if (StringUtils.isNotBlank(pressureHWarning)) {
+                AlarmMessageRespDTO alarm = new AlarmMessageRespDTO();
+                alarm.setTitle("压力高于上限预警");
+                alarm.setContent(pressureHWarning);
+                alarm.setAlarmObj(scheme.getScheduleObj());
+                alarm.setAlarmType("高于上限");
+                alarm.setAlarmTime(scheduleTime);
+                mcsApi.createAlarmMessage(alarm);
+            }
+
+            // 保存调度建议
+            String dispatchStart = mdkScheduleRespDTO.getResult().get("dispatchStart").toString();
+            if (StringUtils.isNotBlank(pressureHWarning)) {
+                ScheduleSuggestRespDTO suggest = new ScheduleSuggestRespDTO();
+                suggest.setTitle("空压机启动调度建议");
+                suggest.setContent(dispatchStart);
+                suggest.setScheduleObj(scheme.getScheduleObj());
+                suggest.setScheduleTime(scheduleTime);
+                suggest.setSort(0);
+                mcsApi.createScheduleSuggest(suggest);
+            }
+
+            String dispatchClose = mdkScheduleRespDTO.getResult().get("dispatchClose").toString();
+            if (StringUtils.isNotBlank(dispatchClose)) {
+                ScheduleSuggestRespDTO suggest = new ScheduleSuggestRespDTO();
+                suggest.setTitle("空压机关停调度建议");
+                suggest.setContent(dispatchClose);
+                suggest.setScheduleObj(scheme.getScheduleObj());
+                suggest.setScheduleTime(scheduleTime);
+                suggest.setSort(0);
+                mcsApi.createScheduleSuggest(suggest);
+            }
+
+            logger.info(params + "调度方案执行完成");
+        } catch (Exception ex) {
+            logger.error("RunScheduleAirDispatchTask运行异常");
+            ex.printStackTrace();
+        }
+        logger.info("RunScheduleAirDispatchTask运行完成");
+    }
+}
\ No newline at end of file

--
Gitblit v1.9.3