From e0cee09916a315d6012b8d44b4c493c4f3adc5d1 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期二, 31 三月 2026 17:05:49 +0800
Subject: [PATCH] #出入库模式

---
 src/main/java/com/zy/asrs/service/impl/StationCycleCapacityServiceImpl.java |   83 ++++++++++++++++++++++++++++++++---------
 1 files changed, 64 insertions(+), 19 deletions(-)

diff --git a/src/main/java/com/zy/asrs/service/impl/StationCycleCapacityServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/StationCycleCapacityServiceImpl.java
index f06ff9a..cb9a719 100644
--- a/src/main/java/com/zy/asrs/service/impl/StationCycleCapacityServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/StationCycleCapacityServiceImpl.java
@@ -1,6 +1,7 @@
 package com.zy.asrs.service.impl;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.zy.asrs.domain.vo.StationCycleCapacityVo;
@@ -74,7 +75,9 @@
 
     private StationCycleCapacityVo buildSnapshot() {
         GraphContext context = buildStationGraph();
-        Map<Integer, Integer> workNoMap = buildStationWorkNoMap();
+        StationOccupancyContext occupancyContext = buildStationOccupancyContext();
+        Map<Integer, Integer> workNoMap = occupancyContext.workNoMap;
+        Set<Integer> manualStationSet = occupancyContext.manualStationSet;
 
         Set<Integer> availableStationSet = new HashSet<>(context.graph.keySet());
         availableStationSet.removeAll(context.excludeStationSet);
@@ -97,6 +100,8 @@
         int loopNo = 1;
         int totalStationCount = 0;
         int taskStationCount = 0;
+        int manualStationCount = 0;
+        int occupiedStationCount = 0;
         Set<Integer> actualWorkNoSet = new HashSet<>();
 
         for (Set<Integer> scc : sccList) {
@@ -112,12 +117,17 @@
 
                 List<Integer> workNoList = new ArrayList<>();
                 int currentLoopTaskCount = 0;
+                int currentLoopManualStationCount = 0;
                 for (Integer stationId : stationIdList) {
                     Integer workNo = workNoMap.get(stationId);
                     if (workNo != null && workNo > 0) {
                         workNoList.add(workNo);
                         currentLoopTaskCount++;
                         actualWorkNoSet.add(workNo);
+                        continue;
+                    }
+                    if (manualStationSet.contains(stationId)) {
+                        currentLoopManualStationCount++;
                     }
                 }
 
@@ -127,23 +137,30 @@
                 loopVo.setWorkNoList(workNoList);
                 loopVo.setStationCount(stationIdList.size());
                 loopVo.setTaskCount(currentLoopTaskCount);
-                loopVo.setCurrentLoad(calcCurrentLoad(currentLoopTaskCount, stationIdList.size()));
+                loopVo.setManualStationCount(currentLoopManualStationCount);
+                loopVo.setOccupiedStationCount(currentLoopTaskCount + currentLoopManualStationCount);
+                loopVo.setCurrentLoad(calcCurrentLoad(toNonNegative(loopVo.getOccupiedStationCount()), stationIdList.size()));
                 loopList.add(loopVo);
 
                 totalStationCount += stationIdList.size();
                 taskStationCount += currentLoopTaskCount;
+                manualStationCount += currentLoopManualStationCount;
+                occupiedStationCount += toNonNegative(loopVo.getOccupiedStationCount());
             }
         }
 
         int reserveTaskCount = mergeReserveTaskCount(loopList, actualWorkNoSet);
         taskStationCount += reserveTaskCount;
+        occupiedStationCount += reserveTaskCount;
 
         StationCycleCapacityVo vo = new StationCycleCapacityVo();
         vo.setLoopList(loopList);
         vo.setLoopCount(loopList.size());
         vo.setTotalStationCount(totalStationCount);
         vo.setTaskStationCount(taskStationCount);
-        vo.setCurrentLoad(calcCurrentLoad(taskStationCount, totalStationCount));
+        vo.setManualStationCount(manualStationCount);
+        vo.setOccupiedStationCount(occupiedStationCount);
+        vo.setCurrentLoad(calcCurrentLoad(occupiedStationCount, totalStationCount));
         vo.setRefreshTime(new Date());
         return vo;
     }
@@ -217,8 +234,10 @@
             Collections.sort(workNoList);
 
             int mergedTaskCount = toNonNegative(loopVo.getTaskCount()) + 1;
+            int mergedOccupiedCount = toNonNegative(loopVo.getOccupiedStationCount()) + 1;
             loopVo.setTaskCount(mergedTaskCount);
-            loopVo.setCurrentLoad(calcCurrentLoad(mergedTaskCount, toNonNegative(loopVo.getStationCount())));
+            loopVo.setOccupiedStationCount(mergedOccupiedCount);
+            loopVo.setCurrentLoad(calcCurrentLoad(mergedOccupiedCount, toNonNegative(loopVo.getStationCount())));
             mergedCount++;
         }
 
@@ -354,17 +373,13 @@
                         continue;
                     }
                     for (NavigateNode nextNode : nextNodeList) {
-                        JSONObject nextValueObj = parseNodeValue(nextNode.getNodeValue());
-                        if (nextValueObj == null) {
-                            continue;
+                        for (Integer nextStationId : resolveConnectedStationIds(stationId, nextNode)) {
+                            if (nextStationId == null || stationId.equals(nextStationId)) {
+                                continue;
+                            }
+                            context.graph.computeIfAbsent(nextStationId, k -> new HashSet<>());
+                            context.graph.get(stationId).add(nextStationId);
                         }
-                        Integer nextStationId = nextValueObj.getInteger("stationId");
-                        if (nextStationId == null || stationId.equals(nextStationId)) {
-                            continue;
-                        }
-
-                        context.graph.computeIfAbsent(nextStationId, k -> new HashSet<>());
-                        context.graph.get(stationId).add(nextStationId);
                     }
                 }
             }
@@ -416,12 +431,33 @@
                 || (isBarcodeStation != null && isBarcodeStation == 1);
     }
 
-    private Map<Integer, Integer> buildStationWorkNoMap() {
-        Map<Integer, Integer> workNoMap = new HashMap<>();
+    private Set<Integer> resolveConnectedStationIds(Integer currentStationId, NavigateNode nextNode) {
+        Set<Integer> stationIdSet = new HashSet<>();
+        JSONObject nextValueObj = parseNodeValue(nextNode == null ? null : nextNode.getNodeValue());
+        if (nextValueObj == null) {
+            return stationIdSet;
+        }
+        Integer directStationId = nextValueObj.getInteger("stationId");
+        if (directStationId != null && !directStationId.equals(currentStationId)) {
+            stationIdSet.add(directStationId);
+        }
+        JSONArray bridgeStationIds = nextValueObj.getJSONArray("bridgeStationIds");
+        if (bridgeStationIds != null) {
+            for (Integer bridgeStationId : bridgeStationIds.toJavaList(Integer.class)) {
+                if (bridgeStationId != null && !bridgeStationId.equals(currentStationId)) {
+                    stationIdSet.add(bridgeStationId);
+                }
+            }
+        }
+        return stationIdSet;
+    }
+
+    private StationOccupancyContext buildStationOccupancyContext() {
+        StationOccupancyContext context = new StationOccupancyContext();
         List<DeviceConfig> devpList = deviceConfigService.list(new QueryWrapper<DeviceConfig>()
                 .eq("device_type", String.valueOf(SlaveType.Devp)));
         if (devpList == null || devpList.isEmpty()) {
-            return workNoMap;
+            return context;
         }
 
         for (DeviceConfig deviceConfig : devpList) {
@@ -440,11 +476,15 @@
                 }
                 Integer taskNo = protocol.getTaskNo();
                 if (taskNo != null && taskNo > 0) {
-                    workNoMap.put(protocol.getStationId(), taskNo);
+                    context.workNoMap.put(protocol.getStationId(), taskNo);
+                    continue;
+                }
+                if (!protocol.isAutoing()) {
+                    context.manualStationSet.add(protocol.getStationId());
                 }
             }
         }
-        return workNoMap;
+        return context;
     }
 
     private List<Set<Integer>> findStrongConnectedComponents(Map<Integer, Set<Integer>> graph) {
@@ -620,4 +660,9 @@
         private final Map<Integer, Set<Integer>> graph = new HashMap<>();
         private final Set<Integer> excludeStationSet = new HashSet<>();
     }
+
+    private static class StationOccupancyContext {
+        private final Map<Integer, Integer> workNoMap = new HashMap<>();
+        private final Set<Integer> manualStationSet = new HashSet<>();
+    }
 }

--
Gitblit v1.9.1