From e9b531edd2917b01a80dfa14e917ec21ddad8882 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期四, 19 三月 2026 20:26:13 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/asrs/controller/ConsoleController.java |  171 +++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 149 insertions(+), 22 deletions(-)

diff --git a/src/main/java/com/zy/asrs/controller/ConsoleController.java b/src/main/java/com/zy/asrs/controller/ConsoleController.java
index 51b7777..13029ed 100644
--- a/src/main/java/com/zy/asrs/controller/ConsoleController.java
+++ b/src/main/java/com/zy/asrs/controller/ConsoleController.java
@@ -3,8 +3,8 @@
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import com.baomidou.mybatisplus.mapper.EntityWrapper;
-import com.baomidou.mybatisplus.plugins.Page;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.core.annotations.ManagerAuth;
 import com.core.common.Cools;
 import com.core.common.R;
@@ -13,8 +13,10 @@
 import com.zy.asrs.domain.param.SystemSwitchParam;
 import com.zy.asrs.domain.vo.CrnDetailVo;
 import com.zy.asrs.domain.vo.CrnLatestDataVo;
+import com.zy.asrs.domain.vo.FakeTaskTraceVo;
 import com.zy.asrs.domain.vo.StationLatestDataVo;
 import com.zy.asrs.domain.vo.RgvLatestDataVo;
+import com.zy.asrs.domain.vo.StationTaskTraceVo;
 import com.zy.asrs.entity.*;
 import com.zy.asrs.service.*;
 import com.zy.common.CodeRes;
@@ -30,6 +32,8 @@
 import com.zy.core.thread.StationThread;
 import com.zy.core.thread.RgvThread;
 import com.zy.core.model.protocol.RgvProtocol;
+import com.zy.core.network.fake.FakeTaskTraceRegistry;
+import com.zy.core.trace.StationTaskTraceRegistry;
 
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -61,6 +65,10 @@
     private BasMapService basMapService;
     @Autowired
     private StationCycleCapacityService stationCycleCapacityService;
+    @Autowired
+    private FakeTaskTraceRegistry fakeTaskTraceRegistry;
+    @Autowired
+    private StationTaskTraceRegistry stationTaskTraceRegistry;
 
     @PostMapping("/system/running/status")
     @ManagerAuth(memo = "绯荤粺杩愯鐘舵��")
@@ -92,10 +100,10 @@
     public R stationLatestData() {
         List<StationLatestDataVo> vos = new ArrayList<>();
 
-        WrkLastno inTaskRange = wrkLastnoService.selectById(WrkIoType.IN.id);
-        WrkLastno outTaskRange = wrkLastnoService.selectById(WrkIoType.OUT.id);
+        WrkLastno inTaskRange = wrkLastnoService.getById(WrkIoType.IN.id);
+        WrkLastno outTaskRange = wrkLastnoService.getById(WrkIoType.OUT.id);
 
-        List<DeviceConfig> devpList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
+        List<DeviceConfig> devpList = deviceConfigService.list(new QueryWrapper<DeviceConfig>()
                 .eq("device_type", String.valueOf(SlaveType.Devp)));
         for (DeviceConfig deviceConfig : devpList) {
             StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp,
@@ -156,10 +164,10 @@
     }
 
     private boolean isInRange(Integer taskNo, WrkLastno taskRange) {
-        if (taskRange == null || taskRange.getSNo() == null || taskRange.getENo() == null) {
+        if (taskRange == null || taskRange.getsNo() == null || taskRange.geteNo() == null) {
             return false;
         }
-        return taskNo >= taskRange.getSNo() && taskNo <= taskRange.getENo();
+        return taskNo >= taskRange.getsNo() && taskNo <= taskRange.geteNo();
     }
 
     @PostMapping("/latest/data/crn")
@@ -167,7 +175,7 @@
     public R crnLatestData() {
         List<CrnLatestDataVo> vos = new ArrayList<>();
 
-        List<DeviceConfig> crnList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
+        List<DeviceConfig> crnList = deviceConfigService.list(new QueryWrapper<DeviceConfig>()
                 .eq("device_type", String.valueOf(SlaveType.Crn)));
         for (DeviceConfig deviceConfig : crnList) {
             // 鑾峰彇鍫嗗灈鏈轰俊鎭�
@@ -194,7 +202,7 @@
                 vo.setCrnStatus(CrnStatusType.MACHINE_ERROR);
             } else {
                 if (crnProtocol.getTaskNo() > 0) {
-                    WrkMast wrkMast = wrkMastService.selectById(crnProtocol.getTaskNo());
+                    WrkMast wrkMast = wrkMastService.getById(crnProtocol.getTaskNo());
                     if (wrkMast != null) {
                         vo.setCrnStatus(CrnStatusType.process(wrkMast.getIoType()));
                     } else {
@@ -215,7 +223,7 @@
     @ManagerAuth(memo = "鍙屽伐浣嶅爢鍨涙満瀹炴椂鏁版嵁")
     public R dualCrnLatestData() {
         List<CrnLatestDataVo> vos = new ArrayList<>();
-        List<DeviceConfig> dualCrnList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
+        List<DeviceConfig> dualCrnList = deviceConfigService.list(new QueryWrapper<DeviceConfig>()
                 .eq("device_type", String.valueOf(SlaveType.DualCrn)));
         for (DeviceConfig deviceConfig : dualCrnList) {
             DualCrnThread crnThread = (DualCrnThread) SlaveConnection.get(SlaveType.DualCrn, deviceConfig.getDeviceNo());
@@ -248,7 +256,7 @@
     @ManagerAuth(memo = "RGV瀹炴椂鏁版嵁")
     public R rgvLatestData(){
         List<RgvLatestDataVo> vos = new ArrayList<>();
-        List<DeviceConfig> rgvList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
+        List<DeviceConfig> rgvList = deviceConfigService.list(new QueryWrapper<DeviceConfig>()
                 .eq("device_type", String.valueOf(SlaveType.Rgv)));
         for (DeviceConfig deviceConfig : rgvList) {
             RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, deviceConfig.getDeviceNo());
@@ -272,6 +280,20 @@
     @GetMapping("/latest/data/station/cycle/capacity")
     public R stationCycleCapacity() {
         return R.ok().add(stationCycleCapacityService.getLatestSnapshot());
+    }
+
+    @PostMapping("/latest/data/fake/trace")
+    @ManagerAuth(memo = "浠跨湡浠诲姟杞ㄨ抗瀹炴椂鏁版嵁")
+    public R fakeTaskTraceLatestData() {
+        List<FakeTaskTraceVo> traceList = fakeTaskTraceRegistry.listActiveTraces();
+        return R.ok().add(traceList);
+    }
+
+    @PostMapping("/latest/data/station/trace")
+    @ManagerAuth(memo = "杈撻�佷换鍔¤建杩瑰疄鏃舵暟鎹�")
+    public R stationTaskTraceLatestData() {
+        List<StationTaskTraceVo> traceList = stationTaskTraceRegistry.listLatestTraces();
+        return R.ok().add(traceList);
     }
 
     // @PostMapping("/latest/data/barcode")
@@ -300,7 +322,7 @@
         }
         CrnDetailVo vo = new CrnDetailVo();
 
-        DeviceConfig deviceConfig = deviceConfigService.selectOne(new EntityWrapper<DeviceConfig>()
+        DeviceConfig deviceConfig = deviceConfigService.getOne(new QueryWrapper<DeviceConfig>()
                 .eq("device_type", String.valueOf(SlaveType.Crn))
                 .eq("device_no", crnNo));
 
@@ -315,12 +337,12 @@
         vo.setCrnStatus(crnProtocol.getStatusType().desc);
 
         if (crnProtocol.getAlarm() > 0) {
-            BasCrnpErr crnError = basCrnpErrService.selectById(crnProtocol.getAlarm());
+            BasCrnpErr crnError = basCrnpErrService.getById(crnProtocol.getAlarm());
             vo.setError(crnError == null ? "鏈煡寮傚父" : crnError.getErrName());
         }
 
         if (crnProtocol.getTaskNo() > 0) {
-            WrkMast wrkMast = wrkMastService.selectById(crnProtocol.getTaskNo());
+            WrkMast wrkMast = wrkMastService.getById(crnProtocol.getTaskNo());
             if (wrkMast != null) {
                 vo.setSourceStaNo(String.valueOf(wrkMast.getSourceStaNo()));
                 vo.setStaNo(String.valueOf(wrkMast.getStaNo()));
@@ -350,19 +372,124 @@
      */
     @GetMapping("/map/{lev}/auth")
     public R getLocMap(@PathVariable Integer lev) {
-        Object object = redisUtil.get(RedisKeyType.LOC_MAP_BASE.key);
-        List<List<HashMap<String, Object>>> mapNodeList = null;
-        if (object != null) {
-            mapNodeList = (List<List<HashMap<String, Object>>>) object;
+        List<List<HashMap<String, Object>>> mapNodeList = getLocMapBaseSnapshot();
+        if (mapNodeList == null || mapNodeList.isEmpty()) {
+            return R.error("璇峰厛鍒濆鍖栧湴鍥�");
         }
         List<LocMast> locMastList = locMastService.selectLocByLev(lev);
+        boolean needRefreshBase = false;
         for (LocMast locMast : locMastList) {
-            String[] locType = locMast.getLocType().split("-");
-            HashMap<String, Object> mapNode = mapNodeList.get(Integer.parseInt(locType[0])).get(Integer.parseInt(locType[1]));
+            Integer[] pos = parseLocTypePos(locMast.getLocType());
+            if (pos == null || !isValidMapNodeIndex(mapNodeList, pos[0], pos[1])) {
+                needRefreshBase = true;
+                break;
+            }
+        }
+
+        if (needRefreshBase) {
+            refreshLocMapBaseCache();
+            mapNodeList = getLocMapBaseSnapshot();
+        }
+
+        for (LocMast locMast : locMastList) {
+            Integer[] pos = parseLocTypePos(locMast.getLocType());
+            if (pos == null || !isValidMapNodeIndex(mapNodeList, pos[0], pos[1])) {
+                log.warn("locMap skip invalid locType, locNo={}, locType={}", locMast.getLocNo(), locMast.getLocType());
+                continue;
+            }
+            HashMap<String, Object> mapNode = mapNodeList.get(pos[0]).get(pos[1]);
             mapNode.put("locSts", locMast.getLocSts());
             mapNode.put("locNo", locMast.getLocNo());
         }
         return R.ok().add(mapNodeList);
+    }
+
+    private List<List<HashMap<String, Object>>> getLocMapBaseSnapshot() {
+        Object object = redisUtil.get(RedisKeyType.LOC_MAP_BASE.key);
+        if (!(object instanceof List)) {
+            return buildLocMapBase();
+        }
+        return cloneMapNodeList((List<List<HashMap<String, Object>>>) object);
+    }
+
+    private void refreshLocMapBaseCache() {
+        List<List<HashMap<String, Object>>> base = buildLocMapBase();
+        if (base != null && !base.isEmpty()) {
+            redisUtil.set(RedisKeyType.LOC_MAP_BASE.key, base);
+        }
+    }
+
+    private List<List<HashMap<String, Object>>> buildLocMapBase() {
+        BasMap basMap = basMapService.getOne(new QueryWrapper<BasMap>().eq("lev", 1));
+        if (Cools.isEmpty(basMap) || Cools.isEmpty(basMap.getData())) {
+            return null;
+        }
+
+        List<List<JSONObject>> dataList = JSON.parseObject(basMap.getData(), List.class);
+        List<List<HashMap<String, Object>>> mapNodeList = new ArrayList<>();
+        for (int i = 0; i < dataList.size(); i++) {
+            List<JSONObject> row = dataList.get(i);
+            List<HashMap<String, Object>> mapNodeRow = new ArrayList<>();
+            for (int j = 0; j < row.size(); j++) {
+                JSONObject map = row.get(j);
+                HashMap<String, Object> mapNode = new HashMap<>();
+                mapNode.put("id", i + "-" + j);
+
+                String nodeType = map.getString("type");
+                mapNode.put("type", nodeType);
+                if ("shelf".equals(nodeType)) {
+                    mapNode.put("value", MapNodeType.NORMAL_PATH.id);
+                } else if ("devp".equals(nodeType)) {
+                    mapNode.put("value", MapNodeType.DISABLE.id);
+                } else if ("crn".equals(nodeType) || "dualCrn".equals(nodeType) || "rgv".equals(nodeType)) {
+                    mapNode.put("value", MapNodeType.MAIN_PATH.id);
+                } else {
+                    mapNode.put("value", MapNodeType.DISABLE.id);
+                }
+
+                mapNodeRow.add(mapNode);
+            }
+            mapNodeList.add(mapNodeRow);
+        }
+        return mapNodeList;
+    }
+
+    private List<List<HashMap<String, Object>>> cloneMapNodeList(List<List<HashMap<String, Object>>> source) {
+        List<List<HashMap<String, Object>>> copy = new ArrayList<>();
+        for (List<HashMap<String, Object>> row : source) {
+            List<HashMap<String, Object>> rowCopy = new ArrayList<>();
+            if (row != null) {
+                for (HashMap<String, Object> item : row) {
+                    rowCopy.add(item == null ? new HashMap<>() : new HashMap<>(item));
+                }
+            }
+            copy.add(rowCopy);
+        }
+        return copy;
+    }
+
+    private Integer[] parseLocTypePos(String locType) {
+        if (Cools.isEmpty(locType)) {
+            return null;
+        }
+        String[] parts = locType.split("-");
+        if (parts.length < 2) {
+            return null;
+        }
+        try {
+            return new Integer[]{Integer.parseInt(parts[0]), Integer.parseInt(parts[1])};
+        } catch (NumberFormatException e) {
+            log.warn("parse locType fail, locType={}", locType, e);
+            return null;
+        }
+    }
+
+    private boolean isValidMapNodeIndex(List<List<HashMap<String, Object>>> mapNodeList, Integer rowIdx, Integer colIdx) {
+        if (mapNodeList == null || rowIdx == null || colIdx == null || rowIdx < 0 || colIdx < 0 || rowIdx >= mapNodeList.size()) {
+            return false;
+        }
+        List<HashMap<String, Object>> row = mapNodeList.get(rowIdx);
+        return row != null && colIdx < row.size();
     }
 
     @RequestMapping(value = "/map/locList")
@@ -372,9 +499,9 @@
             JSONArray data = JSON.parseArray(object.toString());
             return R.ok().add(data);
         }
-        EntityWrapper<LocMast> wrapper = new EntityWrapper<>();
+        QueryWrapper<LocMast> wrapper = new QueryWrapper<>();
         wrapper.eq("lev1", 1);
-        List<LocMast> locMasts = locMastService.selectList(wrapper);
+        List<LocMast> locMasts = locMastService.list(wrapper);
         redisUtil.set(RedisKeyType.LOC_MAST_MAP_LIST.key, JSON.toJSONString(locMasts), 60 * 60 * 24);
         return R.ok().add(locMasts);
     }

--
Gitblit v1.9.1