From d32f016668b2131c4e92f2b2ef11e3b7b1e0c22a Mon Sep 17 00:00:00 2001
From: dengzedong <dengzedong@email>
Date: 星期三, 26 三月 2025 17:52:54 +0800
Subject: [PATCH] advicevalues

---
 shasteel-biz/src/main/java/com/iailab/module/shasteel/job/task/RunScheduleOnaOptTask.java |  125 ++++++++++++++++++++++++++++++++++++-----
 1 files changed, 108 insertions(+), 17 deletions(-)

diff --git a/shasteel-biz/src/main/java/com/iailab/module/shasteel/job/task/RunScheduleOnaOptTask.java b/shasteel-biz/src/main/java/com/iailab/module/shasteel/job/task/RunScheduleOnaOptTask.java
index ecd2927..18734fe 100644
--- a/shasteel-biz/src/main/java/com/iailab/module/shasteel/job/task/RunScheduleOnaOptTask.java
+++ b/shasteel-biz/src/main/java/com/iailab/module/shasteel/job/task/RunScheduleOnaOptTask.java
@@ -1,5 +1,6 @@
 package com.iailab.module.shasteel.job.task;
 
+import com.alibaba.fastjson.JSONArray;
 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;
@@ -16,6 +17,7 @@
 import org.springframework.stereotype.Component;
 import org.springframework.util.CollectionUtils;
 
+import java.math.BigDecimal;
 import java.util.*;
 
 /**
@@ -55,6 +57,17 @@
 
     private Map<String, StScheduleSchemeDTO> schemeMap = new HashMap<>();
 
+    /**
+     * 调度调整方向
+     * 1:调整值为正数;-1:调整值为负数
+     */
+    private static Map<String, Integer> gasAdjustMode = new HashMap<>();
+
+    /**
+     * 调度建议时间
+     */
+    private static Map<String, Date> gasLastSugTime = new HashMap<>();
+
     private static final String CODE06 = "06";
 
     private static final String CODE05 = "05";
@@ -82,21 +95,20 @@
             }
             schemeMap.clear();
             Map<String, MdkScheduleRespDTO> resultMap = new HashMap<String, MdkScheduleRespDTO>();
-            schemeList.forEach(item -> {
-                schemeMap.put(item.getCode(), item);
-                StScheduleSchemeDTO scheme = schemeList.get(0);
+            schemeList.forEach(scheme -> {
+                schemeMap.put(scheme.getCode(), scheme);
                 MdkScheduleReqDTO dto = new MdkScheduleReqDTO();
                 dto.setScheduleTime(scheduleTime);
                 dto.setScheduleCode(scheme.getCode());
                 MdkScheduleRespDTO mdkScheduleRespDTO = mdkApi.doSchedule(dto);
-                resultMap.put(item.getCode(), mdkScheduleRespDTO);
+                resultMap.put(scheme.getCode(), mdkScheduleRespDTO);
             });
             if (CollectionUtils.isEmpty(resultMap)) {
                 logger.info("resultMap为空");
                 return;
             }
             for (Map.Entry<String, MdkScheduleRespDTO> entry : resultMap.entrySet()) {
-                if (CommonConstant.MDK_STATUS_100.equals(entry.getValue().getStatusCode())) {
+                if (!CommonConstant.MDK_STATUS_100.equals(entry.getValue().getStatusCode())) {
                     logger.info("调度结果异常,STATUS=" + entry.getValue().getStatusCode());
                     continue;
                 }
@@ -104,26 +116,52 @@
                 if (entry.getKey().equals(CODE06)) {
                     // 氧气班平衡计划,建议值写入测点
                     mdkApi.scheduleModelOut(entry.getValue());
+                    logger.info("氧气班平衡计划下发参数: {}", entry.getValue());
                 } else if (entry.getKey().equals(CODE05)) {
-                    String scheduleObj = schemeMap.get(CODE05).getScheduleObj();
-                    // double[] adviceValues = (double[]) entry.getValue().getResult().get("adviceValues");
-                    String yingdiAdvice = entry.getValue().getResult().get("yingdiAdvice").toString();
-                    saveScheduleSuggest("盈德中压建议调整量", yingdiAdvice, scheduleObj, scheduleTime);
+                    // 氧气系统优化调度决策
+                    StScheduleSchemeDTO scheduleScheme = schemeMap.get(CODE05);
+                    String scheduleObj = scheduleScheme.getScheduleObj();
+                    /*String yingdiAdvice = entry.getValue().getResult().get("yingdiAdvice").toString();
                     String faAdvice = entry.getValue().getResult().get("faAdvice").toString();
-                    saveScheduleSuggest("法夜空建议调整量", faAdvice, scheduleObj, scheduleTime);
                     String hongAdvice = entry.getValue().getResult().get("hongAdvice").toString();
-                    saveScheduleSuggest("宏昌建议调整量", hongAdvice, scheduleObj, scheduleTime);
-                    String runAdvice = entry.getValue().getResult().get("RunAdvice").toString();
-                    saveScheduleSuggest("宏昌建议调整量", runAdvice, scheduleObj, scheduleTime);
-                } else if (entry.getKey().equals(CODE01)) {
-                    String scheduleObj = schemeMap.get(CODE01).getScheduleObj();
+                    String runAdvice = entry.getValue().getResult().get("runAdvice").toString();
+                    if(!yingdiAdvice.equals("压力正常")){
+                        saveScheduleSuggest("盈德中压调整建议", yingdiAdvice, scheduleObj, scheduleTime);
+                    }
+                    if(!faAdvice.equals("压力正常")){
+                        saveScheduleSuggest("法夜空调整建议", faAdvice, scheduleObj, scheduleTime);
+                    }
+                    if(!hongAdvice.equals("压力正常")){
+                        saveScheduleSuggest("宏昌调整建议", hongAdvice, scheduleObj, scheduleTime);
+                    }
+                    if(!runAdvice.equals("压力正常")){
+                        saveScheduleSuggest("润忠调整建议", runAdvice, scheduleObj, scheduleTime);
+                    }*/
+
+                    BigDecimal adviceValues = new BigDecimal(entry.getValue().getResult().get("adviceValues").toString());
+                    logger.info("各制氧机组建议 adviceValues=" + adviceValues);
+
+
                     String advice = entry.getValue().getResult().get("advice").toString();
-                    saveScheduleSuggest("氮气预警", advice, scheduleObj, scheduleTime);
+                    if(adviceValues.compareTo(BigDecimal.ZERO) != 0){
+                        saveScheduleSuggest("各制氧机组建议", advice, scheduleObj, scheduleTime, adviceValues, scheduleScheme.getAdjustRate());
+                    }
+
+                } else if (entry.getKey().equals(CODE01)) {
+                    StScheduleSchemeDTO scheduleScheme = schemeMap.get(CODE01);
+                    String scheduleObj = scheduleScheme.getScheduleObj();
+                    BigDecimal adviceValues = new BigDecimal(entry.getValue().getResult().get("advicevalues").toString());
+                    logger.info("氮气预警 adviceValues=" + adviceValues);
+
+                    String advice = entry.getValue().getResult().get("advice").toString();
+                    if(adviceValues.compareTo(BigDecimal.ZERO) != 0){
+                        saveAlarmMessage("氮气预警", advice, scheduleObj, scheduleTime,adviceValues,scheduleScheme.getAdjustRate());
+                    }
                 }
             }
             logger.info(params + "调度方案执行完成");
         } catch (Exception ex) {
-            logger.error("RunScheduleOnaOptTask运行异常");
+            logger.error("RunScheduleOnaOptTask运行异常",ex);
             ex.printStackTrace();
         }
         logger.info("RunScheduleOnaOptTask运行完成");
@@ -131,8 +169,10 @@
 
     private void saveScheduleSuggest(String title, String content, String scheduleObj, Date scheduleTime) {
         if (StringUtils.isBlank(content)) {
+            logger.info(title + "调整值为空,不产生建议");
             return;
         }
+
         ScheduleSuggestRespDTO suggest = new ScheduleSuggestRespDTO();
         suggest.setTitle(title);
         suggest.setContent(content);
@@ -141,4 +181,55 @@
         suggest.setSort(0);
         mcsApi.createScheduleSuggest(suggest);
     }
+
+    private void saveScheduleSuggest(String title, String content, String scheduleObj, Date scheduleTime, BigDecimal adjustValue, int adjustRate) {
+        if (StringUtils.isBlank(content)) {
+            logger.info(title + "调整值为空,不产生建议");
+            return;
+        }
+        if (adjustValue == null || adjustValue.doubleValue() == 0) {
+            logger.info(title + "调整值为空,不产生建议");
+            return;
+        }
+        if (gasAdjustMode.containsKey(title) && gasAdjustMode.get(title).equals(adjustValue.compareTo(BigDecimal.ZERO)) &&
+                gasLastSugTime.containsKey(title) && (scheduleTime.getTime() - gasLastSugTime.get(title).getTime() <= Integer.valueOf(adjustRate).longValue() * 60 * 1000)) {
+            logger.info("调整建议在有效期内");
+            return;
+        }
+        gasAdjustMode.put(title,  adjustValue.compareTo(BigDecimal.ZERO));
+        gasLastSugTime.put(title, scheduleTime);
+
+        ScheduleSuggestRespDTO suggest = new ScheduleSuggestRespDTO();
+        suggest.setTitle(title);
+        suggest.setContent(content);
+        suggest.setScheduleObj(scheduleObj);
+        suggest.setScheduleTime(scheduleTime);
+        suggest.setSort(0);
+        mcsApi.createScheduleSuggest(suggest);
+    }
+    private void saveAlarmMessage(String title, String content, String scheduleObj, Date scheduleTime, BigDecimal adjustValue, int adjustRate) {
+        if (StringUtils.isBlank(content)) {
+            logger.info(title + "预警值为空,不产生预警");
+            return;
+        }
+        if (adjustValue == null || adjustValue.doubleValue() == 0) {
+            logger.info(title + "预警值为空,不产生预警");
+            return;
+        }
+        if (gasAdjustMode.containsKey(title) && gasAdjustMode.get(title).equals(adjustValue.compareTo(BigDecimal.ZERO)) &&
+                gasLastSugTime.containsKey(title) && (scheduleTime.getTime() - gasLastSugTime.get(title).getTime() <= Integer.valueOf(adjustRate).longValue() * 60 * 1000)) {
+            logger.info("预警在有效期内");
+            return;
+        }
+        gasAdjustMode.put(title,  adjustValue.compareTo(BigDecimal.ZERO));
+        gasLastSugTime.put(title, scheduleTime);
+
+        AlarmMessageRespDTO alarm = new AlarmMessageRespDTO();
+        alarm.setTitle(title);
+        alarm.setContent(content);
+        alarm.setAlarmObj(scheduleObj);
+        alarm.setAlarmType(adjustValue.compareTo(BigDecimal.ZERO) > 0 ? "超上限" : "超下限");
+        alarm.setAlarmTime(scheduleTime);
+        mcsApi.createAlarmMessage(alarm);
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3