#
Junjie
1 天以前 0b1cc54f62919c5face9794208a0d24da0f97293
#
5个文件已添加
3个文件已修改
724 ■■■■■ 已修改文件
src/main/java/com/zy/asrs/controller/ConsoleController.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/domain/vo/StationCycleCapacityVo.java 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/domain/vo/StationCycleLoopVo.java 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/service/StationCycleCapacityService.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/service/impl/StationCycleCapacityServiceImpl.java 466 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/task/StationCycleCapacityScheduler.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/ws/ConsoleWebSocket.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/components/MapCanvas.js 158 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/controller/ConsoleController.java
@@ -59,6 +59,8 @@
    private LocMastService locMastService;
    @Autowired
    private BasMapService basMapService;
    @Autowired
    private StationCycleCapacityService stationCycleCapacityService;
    @PostMapping("/system/running/status")
    @ManagerAuth(memo = "系统运行状态")
@@ -266,6 +268,11 @@
        return R.ok().add(vos);
    }
    @GetMapping("/latest/data/station/cycle/capacity")
    public R stationCycleCapacity() {
        return R.ok().add(stationCycleCapacityService.getLatestSnapshot());
    }
    // @PostMapping("/latest/data/barcode")
    // @ManagerAuth(memo = "条码扫描仪实时数据")
    // public R barcodeLatestData(){
src/main/java/com/zy/asrs/domain/vo/StationCycleCapacityVo.java
New file
@@ -0,0 +1,29 @@
package com.zy.asrs.domain.vo;
import lombok.Data;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Data
public class StationCycleCapacityVo {
    // 循环圈明细
    private List<StationCycleLoopVo> loopList = new ArrayList<>();
    // 循环圈数量
    private Integer loopCount = 0;
    // 循环圈站点总数
    private Integer totalStationCount = 0;
    // 循环圈中有任务站点总数
    private Integer taskStationCount = 0;
    // 当前承载量(0-1):当前任务数 / 循环圈总站点数
    private Double currentLoad = 0.0;
    // 最新刷新时间
    private Date refreshTime;
}
src/main/java/com/zy/asrs/domain/vo/StationCycleLoopVo.java
New file
@@ -0,0 +1,28 @@
package com.zy.asrs.domain.vo;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
@Data
public class StationCycleLoopVo {
    // 循环圈序号(从1开始)
    private Integer loopNo;
    // 循环圈内站点编号
    private List<Integer> stationIdList = new ArrayList<>();
    // 循环圈内存在的工作号
    private List<Integer> workNoList = new ArrayList<>();
    // 循环圈站点总数
    private Integer stationCount = 0;
    // 循环圈内有任务站点数
    private Integer taskCount = 0;
    // 当前承载量(0-1):当前任务数 / 当前循环圈总站点数
    private Double currentLoad = 0.0;
}
src/main/java/com/zy/asrs/service/StationCycleCapacityService.java
New file
@@ -0,0 +1,13 @@
package com.zy.asrs.service;
import com.zy.asrs.domain.vo.StationCycleCapacityVo;
public interface StationCycleCapacityService {
    // 立即刷新循环圈与承载量快照
    void refreshSnapshot();
    // 获取最新循环圈与承载量快照
    StationCycleCapacityVo getLatestSnapshot();
}
src/main/java/com/zy/asrs/service/impl/StationCycleCapacityServiceImpl.java
New file
@@ -0,0 +1,466 @@
package com.zy.asrs.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zy.asrs.domain.vo.StationCycleCapacityVo;
import com.zy.asrs.domain.vo.StationCycleLoopVo;
import com.zy.asrs.entity.BasDevp;
import com.zy.asrs.entity.DeviceConfig;
import com.zy.asrs.service.BasMapService;
import com.zy.asrs.service.BasDevpService;
import com.zy.asrs.service.DeviceConfigService;
import com.zy.asrs.service.StationCycleCapacityService;
import com.zy.common.model.NavigateNode;
import com.zy.common.utils.NavigateSolution;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.SlaveType;
import com.zy.core.model.StationObjModel;
import com.zy.core.model.protocol.StationProtocol;
import com.zy.core.thread.StationThread;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
@Service("stationCycleCapacityService")
@Slf4j
public class StationCycleCapacityServiceImpl implements StationCycleCapacityService {
    @Autowired
    private BasMapService basMapService;
    @Autowired
    private DeviceConfigService deviceConfigService;
    @Autowired
    private BasDevpService basDevpService;
    private final AtomicReference<StationCycleCapacityVo> snapshotRef = new AtomicReference<>(new StationCycleCapacityVo());
    @Override
    public synchronized void refreshSnapshot() {
        try {
            StationCycleCapacityVo snapshot = buildSnapshot();
            snapshotRef.set(snapshot);
        } catch (Exception e) {
            log.error("刷新循环圈承载量失败", e);
        }
    }
    @Override
    public StationCycleCapacityVo getLatestSnapshot() {
        StationCycleCapacityVo snapshot = snapshotRef.get();
        if (snapshot == null || snapshot.getRefreshTime() == null) {
            refreshSnapshot();
            snapshot = snapshotRef.get();
        }
        return snapshot == null ? new StationCycleCapacityVo() : snapshot;
    }
    private StationCycleCapacityVo buildSnapshot() {
        GraphContext context = buildStationGraph();
        Map<Integer, Integer> workNoMap = buildStationWorkNoMap();
        Set<Integer> availableStationSet = new HashSet<>(context.graph.keySet());
        availableStationSet.removeAll(context.excludeStationSet);
        Map<Integer, Set<Integer>> filteredGraph = new HashMap<>();
        for (Integer stationId : availableStationSet) {
            Set<Integer> nextSet = context.graph.getOrDefault(stationId, Collections.emptySet());
            Set<Integer> filteredNext = new HashSet<>();
            for (Integer nextId : nextSet) {
                if (availableStationSet.contains(nextId)) {
                    filteredNext.add(nextId);
                }
            }
            filteredGraph.put(stationId, filteredNext);
        }
        List<Set<Integer>> sccList = findStrongConnectedComponents(filteredGraph);
        List<StationCycleLoopVo> loopList = new ArrayList<>();
        int loopNo = 1;
        int totalStationCount = 0;
        int taskStationCount = 0;
        for (Set<Integer> scc : sccList) {
            if (!isCycleScc(scc, filteredGraph)) {
                continue;
            }
            // 对 SCC 再做一次“环核心”剥离,剔除枝杈/死胡同节点
            List<Set<Integer>> coreLoopList = extractCoreLoopComponents(scc, filteredGraph);
            for (Set<Integer> coreLoop : coreLoopList) {
                List<Integer> stationIdList = new ArrayList<>(coreLoop);
                Collections.sort(stationIdList);
                List<Integer> workNoList = new ArrayList<>();
                int currentLoopTaskCount = 0;
                for (Integer stationId : stationIdList) {
                    Integer workNo = workNoMap.get(stationId);
                    if (workNo != null && workNo > 0) {
                        workNoList.add(workNo);
                        currentLoopTaskCount++;
                    }
                }
                StationCycleLoopVo loopVo = new StationCycleLoopVo();
                loopVo.setLoopNo(loopNo++);
                loopVo.setStationIdList(stationIdList);
                loopVo.setWorkNoList(workNoList);
                loopVo.setStationCount(stationIdList.size());
                loopVo.setTaskCount(currentLoopTaskCount);
                loopVo.setCurrentLoad(calcCurrentLoad(currentLoopTaskCount, stationIdList.size()));
                loopList.add(loopVo);
                totalStationCount += stationIdList.size();
                taskStationCount += currentLoopTaskCount;
            }
        }
        StationCycleCapacityVo vo = new StationCycleCapacityVo();
        vo.setLoopList(loopList);
        vo.setLoopCount(loopList.size());
        vo.setTotalStationCount(totalStationCount);
        vo.setTaskStationCount(taskStationCount);
        vo.setCurrentLoad(calcCurrentLoad(taskStationCount, totalStationCount));
        vo.setRefreshTime(new Date());
        return vo;
    }
    private double calcCurrentLoad(int taskCount, int stationCount) {
        if (stationCount <= 0 || taskCount <= 0) {
            return 0.0;
        }
        double value = (double) taskCount / (double) stationCount;
        if (value < 0.0) {
            return 0.0;
        }
        if (value > 1.0) {
            return 1.0;
        }
        return value;
    }
    private GraphContext buildStationGraph() {
        GraphContext context = new GraphContext();
        List<Integer> levList = basMapService.getLevList();
        if (levList == null || levList.isEmpty()) {
            return context;
        }
        NavigateSolution navigateSolution = new NavigateSolution();
        List<Integer> sortedLevList = new ArrayList<>(levList);
        sortedLevList = new ArrayList<>(new HashSet<>(sortedLevList));
        Collections.sort(sortedLevList);
        for (Integer lev : sortedLevList) {
            List<List<NavigateNode>> stationMap;
            try {
                stationMap = navigateSolution.getStationMap(lev);
            } catch (Exception e) {
                log.warn("加载楼层{}地图失败,跳过循环圈计算", lev);
                continue;
            }
            if (stationMap == null || stationMap.isEmpty()) {
                continue;
            }
            for (List<NavigateNode> row : stationMap) {
                for (NavigateNode node : row) {
                    JSONObject valueObj = parseNodeValue(node.getNodeValue());
                    if (valueObj == null) {
                        continue;
                    }
                    Integer stationId = valueObj.getInteger("stationId");
                    if (stationId == null) {
                        continue;
                    }
                    context.graph.computeIfAbsent(stationId, k -> new HashSet<>());
                    if (isExcludeStation(valueObj)) {
                        context.excludeStationSet.add(stationId);
                    }
                    List<NavigateNode> nextNodeList = navigateSolution.extend_current_node(stationMap, node);
                    if (nextNodeList == null || nextNodeList.isEmpty()) {
                        continue;
                    }
                    for (NavigateNode nextNode : nextNodeList) {
                        JSONObject nextValueObj = parseNodeValue(nextNode.getNodeValue());
                        if (nextValueObj == null) {
                            continue;
                        }
                        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);
                    }
                }
            }
        }
        appendExcludeStationsFromDeviceConfig(context.excludeStationSet);
        return context;
    }
    private void appendExcludeStationsFromDeviceConfig(Set<Integer> excludeStationSet) {
        List<BasDevp> basDevpList = basDevpService.selectList(new EntityWrapper<>());
        if (basDevpList == null || basDevpList.isEmpty()) {
            return;
        }
        for (BasDevp basDevp : basDevpList) {
            List<StationObjModel> inStationList = basDevp.getInStationList$();
            for (StationObjModel stationObjModel : inStationList) {
                if (stationObjModel != null && stationObjModel.getStationId() != null) {
                    excludeStationSet.add(stationObjModel.getStationId());
                }
            }
            List<StationObjModel> barcodeStationList = basDevp.getBarcodeStationList$();
            for (StationObjModel stationObjModel : barcodeStationList) {
                if (stationObjModel != null && stationObjModel.getStationId() != null) {
                    excludeStationSet.add(stationObjModel.getStationId());
                }
            }
        }
    }
    private JSONObject parseNodeValue(String nodeValue) {
        if (nodeValue == null || nodeValue.trim().isEmpty()) {
            return null;
        }
        try {
            return JSON.parseObject(nodeValue);
        } catch (Exception ignore) {
            return null;
        }
    }
    private boolean isExcludeStation(JSONObject valueObj) {
        Integer isInStation = valueObj.getInteger("isInStation");
        Integer isBarcodeStation = valueObj.getInteger("isBarcodeStation");
        return (isInStation != null && isInStation == 1)
                || (isBarcodeStation != null && isBarcodeStation == 1);
    }
    private Map<Integer, Integer> buildStationWorkNoMap() {
        Map<Integer, Integer> workNoMap = new HashMap<>();
        List<DeviceConfig> devpList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
                .eq("device_type", String.valueOf(SlaveType.Devp)));
        if (devpList == null || devpList.isEmpty()) {
            return workNoMap;
        }
        for (DeviceConfig deviceConfig : devpList) {
            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, deviceConfig.getDeviceNo());
            if (stationThread == null) {
                continue;
            }
            Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap();
            if (statusMap == null || statusMap.isEmpty()) {
                continue;
            }
            for (StationProtocol protocol : statusMap.values()) {
                if (protocol == null || protocol.getStationId() == null) {
                    continue;
                }
                Integer taskNo = protocol.getTaskNo();
                if (taskNo != null && taskNo > 0) {
                    workNoMap.put(protocol.getStationId(), taskNo);
                }
            }
        }
        return workNoMap;
    }
    private List<Set<Integer>> findStrongConnectedComponents(Map<Integer, Set<Integer>> graph) {
        List<Set<Integer>> result = new ArrayList<>();
        if (graph == null || graph.isEmpty()) {
            return result;
        }
        Map<Integer, Integer> indexMap = new HashMap<>();
        Map<Integer, Integer> lowLinkMap = new HashMap<>();
        Deque<Integer> stack = new ArrayDeque<>();
        Set<Integer> inStack = new HashSet<>();
        int[] index = new int[]{0};
        List<Integer> nodeList = new ArrayList<>(graph.keySet());
        Collections.sort(nodeList);
        for (Integer node : nodeList) {
            if (!indexMap.containsKey(node)) {
                strongConnect(node, graph, indexMap, lowLinkMap, stack, inStack, index, result);
            }
        }
        return result;
    }
    private void strongConnect(Integer node,
                               Map<Integer, Set<Integer>> graph,
                               Map<Integer, Integer> indexMap,
                               Map<Integer, Integer> lowLinkMap,
                               Deque<Integer> stack,
                               Set<Integer> inStack,
                               int[] index,
                               List<Set<Integer>> result) {
        indexMap.put(node, index[0]);
        lowLinkMap.put(node, index[0]);
        index[0]++;
        stack.push(node);
        inStack.add(node);
        List<Integer> nextList = new ArrayList<>(graph.getOrDefault(node, Collections.emptySet()));
        Collections.sort(nextList);
        for (Integer next : nextList) {
            if (!indexMap.containsKey(next)) {
                strongConnect(next, graph, indexMap, lowLinkMap, stack, inStack, index, result);
                lowLinkMap.put(node, Math.min(lowLinkMap.get(node), lowLinkMap.get(next)));
            } else if (inStack.contains(next)) {
                lowLinkMap.put(node, Math.min(lowLinkMap.get(node), indexMap.get(next)));
            }
        }
        if (!lowLinkMap.get(node).equals(indexMap.get(node))) {
            return;
        }
        Set<Integer> scc = new HashSet<>();
        while (!stack.isEmpty()) {
            Integer top = stack.pop();
            inStack.remove(top);
            scc.add(top);
            if (top.equals(node)) {
                break;
            }
        }
        result.add(scc);
    }
    private boolean isCycleScc(Set<Integer> scc, Map<Integer, Set<Integer>> graph) {
        if (scc == null || scc.isEmpty()) {
            return false;
        }
        if (scc.size() > 1) {
            return true;
        }
        Integer onlyNode = scc.iterator().next();
        Set<Integer> nextSet = graph.getOrDefault(onlyNode, Collections.emptySet());
        return nextSet.contains(onlyNode);
    }
    /**
     * 从 SCC 中提取循环核心:
     * 1) 转无向图
     * 2) 递归剥离度数<2的节点(2-core)
     * 3) 将剩余节点拆成连通分量,每个分量>=3才认定为循环圈
     */
    private List<Set<Integer>> extractCoreLoopComponents(Set<Integer> scc, Map<Integer, Set<Integer>> graph) {
        List<Set<Integer>> result = new ArrayList<>();
        if (scc == null || scc.isEmpty()) {
            return result;
        }
        // 构建 SCC 内无向邻接
        Map<Integer, Set<Integer>> undirectedMap = new HashMap<>();
        for (Integer node : scc) {
            undirectedMap.put(node, new HashSet<>());
        }
        for (Integer from : scc) {
            Set<Integer> nextSet = graph.getOrDefault(from, Collections.emptySet());
            for (Integer to : nextSet) {
                if (!scc.contains(to) || from.equals(to)) {
                    continue;
                }
                undirectedMap.get(from).add(to);
                undirectedMap.get(to).add(from);
            }
        }
        // 2-core 剥离
        Set<Integer> alive = new HashSet<>(scc);
        Map<Integer, Integer> degreeMap = new HashMap<>();
        ArrayDeque<Integer> queue = new ArrayDeque<>();
        for (Integer node : scc) {
            int degree = undirectedMap.getOrDefault(node, Collections.emptySet()).size();
            degreeMap.put(node, degree);
            if (degree < 2) {
                queue.offer(node);
            }
        }
        while (!queue.isEmpty()) {
            Integer node = queue.poll();
            if (!alive.remove(node)) {
                continue;
            }
            for (Integer next : undirectedMap.getOrDefault(node, Collections.emptySet())) {
                if (!alive.contains(next)) {
                    continue;
                }
                int newDegree = degreeMap.getOrDefault(next, 0) - 1;
                degreeMap.put(next, newDegree);
                if (newDegree < 2) {
                    queue.offer(next);
                }
            }
        }
        if (alive.size() < 3) {
            return result;
        }
        // 拆分连通分量
        Set<Integer> visited = new HashSet<>();
        List<Integer> sortedAlive = new ArrayList<>(alive);
        Collections.sort(sortedAlive);
        for (Integer start : sortedAlive) {
            if (!visited.add(start)) {
                continue;
            }
            Set<Integer> component = new HashSet<>();
            ArrayDeque<Integer> bfs = new ArrayDeque<>();
            bfs.offer(start);
            component.add(start);
            while (!bfs.isEmpty()) {
                Integer node = bfs.poll();
                for (Integer next : undirectedMap.getOrDefault(node, Collections.emptySet())) {
                    if (!alive.contains(next) || !visited.add(next)) {
                        continue;
                    }
                    component.add(next);
                    bfs.offer(next);
                }
            }
            // 至少3个点才认为是真正“圈”
            if (component.size() >= 3) {
                result.add(component);
            }
        }
        return result;
    }
    private static class GraphContext {
        private final Map<Integer, Set<Integer>> graph = new HashMap<>();
        private final Set<Integer> excludeStationSet = new HashSet<>();
    }
}
src/main/java/com/zy/asrs/task/StationCycleCapacityScheduler.java
New file
@@ -0,0 +1,20 @@
package com.zy.asrs.task;
import com.zy.asrs.service.StationCycleCapacityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class StationCycleCapacityScheduler {
    @Autowired
    private StationCycleCapacityService stationCycleCapacityService;
    // 每秒刷新一次循环圈承载量
    @Scheduled(cron = "0/1 * * * * ? ")
    public void refreshStationCycleCapacity() {
        stationCycleCapacityService.refreshSnapshot();
    }
}
src/main/java/com/zy/asrs/ws/ConsoleWebSocket.java
@@ -103,6 +103,9 @@
            } else if ("/console/latest/data/dualcrn".equals(url)) {
                ConsoleController consoleController = SpringUtils.getBean(ConsoleController.class);
                resObj = consoleController.dualCrnLatestData();
            } else if ("/console/latest/data/station/cycle/capacity".equals(url)) {
                ConsoleController consoleController = SpringUtils.getBean(ConsoleController.class);
                resObj = consoleController.stationCycleCapacity();
            } else if ("/crn/table/crn/state".equals(url)) {
                resObj = SpringUtils.getBean(CrnController.class).crnStateTable();
            } else if ("/rgv/table/rgv/state".equals(url)) {
src/main/webapp/components/MapCanvas.js
@@ -2,6 +2,20 @@
  template: `
    <div style="width: 100%; height: 100%; position: relative;">
      <div ref="pixiView" style="position: absolute; inset: 0;"></div>
      <div style="position: absolute; top: 12px; left: 14px; z-index: 30; pointer-events: none; max-width: 52%;">
        <div style="display: flex; flex-direction: column; gap: 6px; align-items: flex-start;">
          <div v-for="item in cycleCapacity.loopList"
               :key="'loop-' + item.loopNo"
               @mouseenter="handleLoopCardEnter(item)"
               @mouseleave="handleLoopCardLeave(item)"
               style="padding: 6px 10px; border-radius: 4px; background: rgba(11, 35, 58, 0.72); color: #fff; font-size: 12px; line-height: 1.4; white-space: nowrap; pointer-events: auto;">
            圈{{ item.loopNo }} |
            站点: {{ item.stationCount || 0 }} |
            任务: {{ item.taskCount || 0 }} |
            承载: {{ formatLoadPercent(item.currentLoad) }}
          </div>
        </div>
      </div>
      <div v-show="shelfTooltip.visible"
           :style="shelfTooltipStyle()">
        {{ shelfTooltip.text }}
@@ -83,7 +97,16 @@
      containerResizeObserver: null,
      timer: null,
      adjustLabelTimer: null,
      isSwitchingFloor: false
      isSwitchingFloor: false,
      cycleCapacity: {
        loopList: [],
        totalStationCount: 0,
        taskStationCount: 0,
        currentLoad: 0
      },
      hoverLoopNo: null,
      hoverLoopStationIdSet: new Set(),
      loopHighlightColor: 0xfff34d
    }
  },
    mounted() {
@@ -102,6 +125,7 @@
      this.getCrnInfo();
      this.getDualCrnInfo();
      this.getSiteInfo();
      this.getCycleCapacityInfo();
      this.getRgvInfo();
    }, 1000);
  },
@@ -314,6 +338,7 @@
    },
    changeFloor(lev) {
      this.currentLev = lev;
      this.clearLoopStationHighlight();
      this.isSwitchingFloor = true;
      this.hideShelfTooltip();
      this.hoveredShelfCell = null;
@@ -338,6 +363,7 @@
      this.getMap();
    },
    createMapData(map) {
      this.clearLoopStationHighlight();
      this.hideShelfTooltip();
      this.hoveredShelfCell = null;
      this.mapRowOffsets = [];
@@ -652,21 +678,21 @@
          sta.statusObj = null;
          if (sta.textObj.parent !== sta) { sta.addChild(sta.textObj); sta.textObj.position.set(sta.width / 2, sta.height / 2); }
        }
        let baseColor = 0xb8b8b8;
        if (status === "site-auto") {
          this.updateColor(sta, 0x78ff81);
          baseColor = 0x78ff81;
        } else if (status === "site-auto-run" || status === "site-auto-id" || status === "site-auto-run-id") {
          this.updateColor(sta, 0xfa51f6);
          baseColor = 0xfa51f6;
        } else if (status === "site-unauto") {
          this.updateColor(sta, 0xb8b8b8);
          baseColor = 0xb8b8b8;
        } else if (status === "machine-pakin") {
          this.updateColor(sta, 0x30bffc);
          baseColor = 0x30bffc;
        } else if (status === "machine-pakout") {
          this.updateColor(sta, 0x97b400);
          baseColor = 0x97b400;
        } else if (status === "site-run-block") {
          this.updateColor(sta, 0xe69138);
        } else {
          this.updateColor(sta, 0xb8b8b8);
          baseColor = 0xe69138;
        }
        this.setStationBaseColor(sta, baseColor);
      });
    },
    getCrnInfo() {
@@ -684,6 +710,38 @@
    getRgvInfo() {
      if (this.isSwitchingFloor) { return; }
      this.sendWs(JSON.stringify({ url: "/console/latest/data/rgv", data: {} }));
    },
    getCycleCapacityInfo() {
      if (this.isSwitchingFloor) { return; }
      this.sendWs(JSON.stringify({ url: "/console/latest/data/station/cycle/capacity", data: {} }));
    },
    setCycleCapacityInfo(res) {
      const payload = res && res.code === 200 ? res.data : null;
      if (res && res.code === 403) { parent.location.href = baseUrl + "/login"; return; }
      if (!payload) { return; }
      const loopList = Array.isArray(payload.loopList) ? payload.loopList : [];
      this.cycleCapacity = {
        loopList: loopList,
        totalStationCount: payload.totalStationCount || 0,
        taskStationCount: payload.taskStationCount || 0,
        currentLoad: typeof payload.currentLoad === 'number' ? payload.currentLoad : parseFloat(payload.currentLoad || 0)
      };
      if (this.hoverLoopNo != null) {
        const targetLoop = loopList.find(v => v && v.loopNo === this.hoverLoopNo);
        if (targetLoop) {
          this.hoverLoopStationIdSet = this.buildStationIdSet(targetLoop.stationIdList);
          this.applyLoopStationHighlight();
        } else {
          this.clearLoopStationHighlight();
        }
      }
    },
    formatLoadPercent(load) {
      let value = typeof load === 'number' ? load : parseFloat(load || 0);
      if (!isFinite(value)) { value = 0; }
      if (value < 0) { value = 0; }
      if (value > 1) { value = 1; }
      return (value * 100).toFixed(1) + "%";
    },
    setCrnInfo(res) {
      let crns = Array.isArray(res) ? res : (res && res.code === 200 ? res.data : null);
@@ -839,6 +897,7 @@
      if (this.wsReconnectTimer) { clearTimeout(this.wsReconnectTimer); this.wsReconnectTimer = null; }
      this.wsReconnectAttempts = 0;
      this.getMap(this.currentLev);
      this.getCycleCapacityInfo();
    },
    webSocketOnError(e) {
      this.scheduleReconnect();
@@ -853,6 +912,8 @@
        this.setDualCrnInfo(JSON.parse(result.data));
      } else if (result.url === "/console/latest/data/rgv") {
        this.setRgvInfo(JSON.parse(result.data));
      } else if (result.url === "/console/latest/data/station/cycle/capacity") {
        this.setCycleCapacityInfo(JSON.parse(result.data));
      } else if (typeof result.url === "string" && result.url.indexOf("/basMap/lev/") === 0) {
        this.setMap(JSON.parse(result.data));
      }
@@ -1200,7 +1261,11 @@
        text.position.set(sprite.width / 2, sprite.height / 2);
        sprite.addChild(text);
        sprite.textObj = text;
        if (siteId != null && siteId !== -1) { this.pixiStaMap.set(parseInt(siteId), sprite); }
        const stationIdInt = parseInt(siteId, 10);
        if (!isNaN(stationIdInt)) { this.pixiStaMap.set(stationIdInt, sprite); }
        sprite._stationId = isNaN(stationIdInt) ? null : stationIdInt;
        sprite._baseColor = 0x00ff7f;
        sprite._loopHighlighted = false;
        sprite.interactive = true;
        sprite.buttonMode = true;
        sprite.on('pointerdown', () => {
@@ -1401,6 +1466,74 @@
        return;
      }
      sprite.tint = color;
    },
    setStationBaseColor(sprite, color) {
      if (!sprite) { return; }
      sprite._baseColor = color;
      if (this.isStationInHoverLoop(sprite)) {
        this.applyHighlightColor(sprite);
      } else {
        this.updateColor(sprite, color);
        sprite._loopHighlighted = false;
      }
    },
    applyHighlightColor(sprite) {
      if (!sprite) { return; }
      this.updateColor(sprite, this.loopHighlightColor);
      sprite._loopHighlighted = true;
    },
    isStationInHoverLoop(sprite) {
      if (!sprite || sprite._stationId == null || !this.hoverLoopStationIdSet) { return false; }
      return this.hoverLoopStationIdSet.has(sprite._stationId);
    },
    buildStationIdSet(stationIdList) {
      const set = new Set();
      if (!Array.isArray(stationIdList)) { return set; }
      stationIdList.forEach((id) => {
        const v = parseInt(id, 10);
        if (!isNaN(v)) { set.add(v); }
      });
      return set;
    },
    applyLoopStationHighlight() {
      if (!this.pixiStaMap) { return; }
      this.pixiStaMap.forEach((sprite) => {
        if (!sprite) { return; }
        if (this.isStationInHoverLoop(sprite)) {
          this.applyHighlightColor(sprite);
        } else if (sprite._loopHighlighted) {
          const baseColor = (typeof sprite._baseColor === 'number') ? sprite._baseColor : 0xb8b8b8;
          this.updateColor(sprite, baseColor);
          sprite._loopHighlighted = false;
        }
      });
    },
    clearLoopStationHighlight() {
      if (this.pixiStaMap) {
        this.pixiStaMap.forEach((sprite) => {
          if (!sprite || !sprite._loopHighlighted) { return; }
          const baseColor = (typeof sprite._baseColor === 'number') ? sprite._baseColor : 0xb8b8b8;
          this.updateColor(sprite, baseColor);
          sprite._loopHighlighted = false;
        });
      }
      this.hoverLoopNo = null;
      this.hoverLoopStationIdSet = new Set();
    },
    handleLoopCardEnter(loopItem) {
      if (!loopItem) { return; }
      this.hoverLoopNo = loopItem.loopNo;
      this.hoverLoopStationIdSet = this.buildStationIdSet(loopItem.stationIdList);
      this.applyLoopStationHighlight();
    },
    handleLoopCardLeave(loopItem) {
      if (!loopItem) {
        this.clearLoopStationHighlight();
        return;
      }
      if (this.hoverLoopNo === loopItem.loopNo) {
        this.clearLoopStationHighlight();
      }
    },
    isJson(str) {
      try { JSON.parse(str); return true; } catch (e) { return false; }
@@ -1883,11 +2016,6 @@
    }
  }
});