From dc3f9cc91759823ce59486f19b138be4b296a0f1 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期二, 28 四月 2026 09:43:28 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/ai/service/impl/AutoTuneSnapshotServiceImpl.java |   74 ++++++++++++++++++++++++++++---------
 1 files changed, 56 insertions(+), 18 deletions(-)

diff --git a/src/main/java/com/zy/ai/service/impl/AutoTuneSnapshotServiceImpl.java b/src/main/java/com/zy/ai/service/impl/AutoTuneSnapshotServiceImpl.java
index 781710b..a609520 100644
--- a/src/main/java/com/zy/ai/service/impl/AutoTuneSnapshotServiceImpl.java
+++ b/src/main/java/com/zy/ai/service/impl/AutoTuneSnapshotServiceImpl.java
@@ -2,6 +2,8 @@
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.zy.ai.domain.autotune.AutoTuneParameterSnapshot;
+import com.zy.ai.domain.autotune.AutoTuneRuleDefinition;
+import com.zy.ai.domain.autotune.AutoTuneRuleSnapshotItem;
 import com.zy.ai.domain.autotune.AutoTuneSnapshot;
 import com.zy.ai.domain.autotune.AutoTuneStationRuntimeItem;
 import com.zy.ai.domain.autotune.AutoTuneTaskSnapshot;
@@ -10,21 +12,22 @@
 import com.zy.asrs.domain.vo.StationCycleCapacityVo;
 import com.zy.asrs.domain.vo.StationCycleLoopVo;
 import com.zy.asrs.entity.BasCrnp;
+import com.zy.asrs.entity.BasDevp;
 import com.zy.asrs.entity.BasDualCrnp;
 import com.zy.asrs.entity.BasStation;
 import com.zy.asrs.entity.DeviceConfig;
-import com.zy.asrs.entity.StationFlowCapacity;
 import com.zy.asrs.entity.WrkMast;
 import com.zy.asrs.service.BasCrnpService;
+import com.zy.asrs.service.BasDevpService;
 import com.zy.asrs.service.BasDualCrnpService;
 import com.zy.asrs.service.BasStationService;
 import com.zy.asrs.service.DeviceConfigService;
 import com.zy.asrs.service.StationCycleCapacityService;
-import com.zy.asrs.service.StationFlowCapacityService;
 import com.zy.asrs.service.WrkMastService;
 import com.zy.core.cache.SlaveConnection;
 import com.zy.core.enums.SlaveType;
 import com.zy.core.enums.WrkStsType;
+import com.zy.core.model.StationObjModel;
 import com.zy.core.model.protocol.StationProtocol;
 import com.zy.core.thread.StationThread;
 import com.zy.system.service.ConfigService;
@@ -47,7 +50,6 @@
     private static final int DEFAULT_CRN_OUT_BATCH_RUNNING_LIMIT = 5;
     private static final int DEFAULT_CONVEYOR_STATION_TASK_LIMIT = 30;
     private static final int DEFAULT_AI_AUTO_TUNE_INTERVAL_MINUTES = 10;
-    private static final String DIRECTION_OUT = "OUT";
 
     @Autowired
     private WrkMastService wrkMastService;
@@ -68,7 +70,7 @@
     private BasStationService basStationService;
 
     @Autowired
-    private StationFlowCapacityService stationFlowCapacityService;
+    private BasDevpService basDevpService;
 
     @Autowired
     private BasCrnpService basCrnpService;
@@ -86,8 +88,27 @@
         snapshot.setCycleLoadSnapshot(buildCycleLoadSnapshot());
         snapshot.setFlowTopologySnapshot(flowTopologySnapshotService.buildSnapshot(stationRuntimeSnapshot));
         snapshot.setCurrentParameterSnapshot(buildCurrentParameterSnapshot());
+        snapshot.setRuleSnapshot(buildRuleSnapshot());
         snapshot.setSnapshotTime(new Date());
         return snapshot;
+    }
+
+    List<AutoTuneRuleSnapshotItem> buildRuleSnapshot() {
+        List<AutoTuneRuleSnapshotItem> result = new ArrayList<>();
+        for (AutoTuneRuleDefinition.Rule rule : AutoTuneRuleDefinition.rules().values()) {
+            AutoTuneRuleSnapshotItem item = new AutoTuneRuleSnapshotItem();
+            item.setTargetType(rule.getTargetType().getCode());
+            item.setTargetKey(rule.getTargetKey());
+            item.setMinValue(rule.getMinValue());
+            item.setMaxValue(rule.getMaxValue());
+            item.setMaxStep(rule.getMaxStep());
+            item.setCooldownMinutes(rule.getCooldownMinutes());
+            item.setDynamicMaxValue(rule.isDynamicMaxValue());
+            item.setDynamicMaxSource(rule.getDynamicMaxSource());
+            item.setNote(rule.getNote());
+            result.add(item);
+        }
+        return result;
     }
 
     private AutoTuneTaskSnapshot buildTaskSnapshot() {
@@ -224,7 +245,9 @@
         ));
         List<BasCrnp> crnList = loadCrnList();
         List<BasDualCrnp> dualCrnList = loadDualCrnList();
-        snapshot.setStationOutTaskLimits(loadStationOutTaskLimits());
+        List<BasStation> outStationList = loadOutStationList();
+        snapshot.setStationOutTaskLimits(buildStationOutTaskLimitMap(outStationList));
+        snapshot.setStationOutBufferCapacities(buildStationOutBufferCapacityMap(outStationList));
         snapshot.setCrnMaxOutTask(buildCrnMaxOutTask(crnList));
         snapshot.setCrnMaxInTask(buildCrnMaxInTask(crnList));
         snapshot.setDualCrnMaxOutTask(buildDualCrnMaxOutTask(dualCrnList));
@@ -247,33 +270,38 @@
         }
     }
 
-    private Map<String, Integer> loadStationOutTaskLimits() {
-        Map<String, Integer> result = new LinkedHashMap<>();
+    private List<BasStation> loadOutStationList() {
         if (basStationService == null) {
-            return result;
+            return Collections.emptyList();
         }
         Set<Integer> outStationIds = loadOutStationIds();
         if (outStationIds.isEmpty()) {
-            return result;
+            return Collections.emptyList();
         }
         QueryWrapper<BasStation> wrapper = new QueryWrapper<>();
         wrapper.in("station_id", outStationIds);
         wrapper.orderByAsc("station_id");
-        return buildStationOutTaskLimitMap(basStationService.list(wrapper));
+        return safeList(basStationService.list(wrapper));
     }
 
     private Set<Integer> loadOutStationIds() {
         LinkedHashSet<Integer> stationIds = new LinkedHashSet<>();
-        if (stationFlowCapacityService == null) {
+        if (basDevpService == null) {
             return stationIds;
         }
-        QueryWrapper<StationFlowCapacity> wrapper = new QueryWrapper<>();
-        wrapper.eq("direction_code", DIRECTION_OUT);
-        wrapper.orderByAsc("station_id");
-        List<StationFlowCapacity> capacityList = safeList(stationFlowCapacityService.list(wrapper));
-        for (StationFlowCapacity capacity : capacityList) {
-            if (capacity != null && capacity.getStationId() != null) {
-                stationIds.add(capacity.getStationId());
+        QueryWrapper<BasDevp> wrapper = new QueryWrapper<>();
+        wrapper.eq("status", 1);
+        wrapper.orderByAsc("devp_no");
+        List<BasDevp> basDevpList = safeList(basDevpService.list(wrapper));
+        for (BasDevp basDevp : basDevpList) {
+            if (basDevp == null) {
+                continue;
+            }
+            List<StationObjModel> outStationList = safeList(basDevp.getOutStationList$());
+            for (StationObjModel stationObjModel : outStationList) {
+                if (stationObjModel != null && stationObjModel.getStationId() != null) {
+                    stationIds.add(stationObjModel.getStationId());
+                }
             }
         }
         return stationIds;
@@ -289,6 +317,16 @@
         return result;
     }
 
+    Map<String, Integer> buildStationOutBufferCapacityMap(List<BasStation> stationList) {
+        Map<String, Integer> result = new LinkedHashMap<>();
+        for (BasStation station : safeList(stationList)) {
+            if (station != null && station.getStationId() != null) {
+                result.put(String.valueOf(station.getStationId()), station.getOutBufferCapacity());
+            }
+        }
+        return result;
+    }
+
     private Map<String, Integer> buildCrnMaxOutTask(List<BasCrnp> crnList) {
         Map<String, Integer> result = new LinkedHashMap<>();
         for (BasCrnp crn : safeList(crnList)) {

--
Gitblit v1.9.1