From 732f97d740de606004cd19436ba19846bbd5b378 Mon Sep 17 00:00:00 2001
From: Junjie <540245094@qq.com>
Date: 星期四, 13 六月 2024 15:05:53 +0800
Subject: [PATCH] #

---
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/NavigateMapUtils.java                 |   63 ++++++++++++++++++++-
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/constant/DeviceRedisConstant.java            |    2 
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/map/entity/MapWsVo.java                     |    3 +
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/map/websocket/MapRealTimeDataScheduler.java |   25 ++++++++
 zy-asrs-flow/src/pages/map/utils.js                                                        |   37 ++++++++++++
 5 files changed, 127 insertions(+), 3 deletions(-)

diff --git a/zy-asrs-flow/src/pages/map/utils.js b/zy-asrs-flow/src/pages/map/utils.js
index 75532e5..62d5468 100644
--- a/zy-asrs-flow/src/pages/map/utils.js
+++ b/zy-asrs-flow/src/pages/map/utils.js
@@ -9,6 +9,7 @@
 import conveyor from '/public/img/map/conveyor.png'
 import point from '/public/img/map/point.svg'
 import shuttle from '/public/img/map/shuttle.svg'
+import { log } from 'three/examples/jsm/nodes/Nodes.js';
 
 let app = null;
 let mapContainer = null;
@@ -618,6 +619,8 @@
         // shuttle
         showShuttle(shuttleVo, curFloor, setCurSPrite);
     }
+
+    showLockPath(mapVo.lockPath, curFloor, setCurSPrite);
 }
 
 export const drawTravelPath = (shuttleVo, curFloor) => {
@@ -679,4 +682,38 @@
     }, 1000).onUpdate(() => {
         updateEffect(shuttle);
     }).start();
+}
+
+export const showLockPath = (nodes, curFloor, setCurSPrite) => {
+    const pathLineName = 'lockPath-' + curFloor;
+    let pathLine = mapContainer.getChildByName(pathLineName);
+    if (pathLine) {
+        mapContainer.removeChild(pathLine);
+    }
+
+    pathLine = new PIXI.Graphics();
+    pathLine.name = pathLineName;
+    pathLine.lineStyle(3 * (1 / mapContainer.scale.x), 0xff0000, 0.8);
+    pathLine.zIndex = SENSOR_ZINDEX.TRAVEL_PATH;
+    let firstNode = true;
+
+    for(let i = 0; i < nodes.length; i++) {
+        const node = nodes[i];
+        if (node.z !== curFloor) { continue }
+        const shelf = querySprite(SENSOR_TYPE.SHELF, node.x + '-' + node.y);
+        if (!shelf) { continue }
+
+        let position = shelf.position;
+        let x = position.x;
+        let y = position.y;
+        if (firstNode) {
+            pathLine.moveTo(x, y);
+            firstNode = false;
+        } else {
+            pathLine.lineTo(x, y);
+        }
+        
+    }
+
+    mapContainer.addChild(pathLine);
 }
\ No newline at end of file
diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/map/entity/MapWsVo.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/map/entity/MapWsVo.java
index 17cf170..65fe447 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/map/entity/MapWsVo.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/map/entity/MapWsVo.java
@@ -1,5 +1,6 @@
 package com.zy.asrs.wcs.core.map.entity;
 
+import com.zy.asrs.wcs.core.model.NavigateNode;
 import lombok.Data;
 
 import java.util.ArrayList;
@@ -13,4 +14,6 @@
 
     private List<MapWsShuttleVo> shuttleVos = new ArrayList<>();
 
+    private List<NavigateNode> lockPath = new ArrayList<>();
+
 }
diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/map/websocket/MapRealTimeDataScheduler.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/map/websocket/MapRealTimeDataScheduler.java
index c452134..7b30f2c 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/map/websocket/MapRealTimeDataScheduler.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/map/websocket/MapRealTimeDataScheduler.java
@@ -1,6 +1,7 @@
 package com.zy.asrs.wcs.core.map.websocket;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.zy.asrs.framework.common.Cools;
 import com.zy.asrs.wcs.core.entity.BasShuttle;
@@ -9,6 +10,7 @@
 import com.zy.asrs.wcs.core.model.NavigateNode;
 import com.zy.asrs.wcs.core.model.enums.DeviceCtgType;
 import com.zy.asrs.wcs.core.service.BasShuttleService;
+import com.zy.asrs.wcs.core.utils.NavigateMapUtils;
 import com.zy.asrs.wcs.core.utils.Utils;
 import com.zy.asrs.wcs.rcs.cache.SlaveConnection;
 import com.zy.asrs.wcs.rcs.entity.Device;
@@ -17,6 +19,8 @@
 import com.zy.asrs.wcs.rcs.service.DeviceService;
 import com.zy.asrs.wcs.rcs.service.DeviceTypeService;
 import com.zy.asrs.wcs.rcs.thread.ShuttleThread;
+import com.zy.asrs.wcs.system.entity.Dict;
+import com.zy.asrs.wcs.system.service.DictService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
@@ -38,12 +42,17 @@
     private DeviceService deviceService;
     @Autowired
     private BasShuttleService basShuttleService;
+    @Autowired
+    private DictService dictService;
+    @Autowired
+    private NavigateMapUtils navigateMapUtils;
 
     @Scheduled(cron = "0/1 * * * * ? ")
     public void sync() {
         MapWsVo wsVo = new MapWsVo();
         // shuttle
         wsVo.setShuttleVos(syncShuttle());
+        wsVo.setLockPath(getMapLocPath());
         MapWebSocket.broadcast(JSON.toJSONString(wsVo));
     }
 
@@ -92,4 +101,20 @@
         return shuttleVos;
     }
 
+    private List<NavigateNode> getMapLocPath() {
+        List<NavigateNode> navigateNodes = new ArrayList<>();
+        Dict dict = dictService.getOne(new LambdaQueryWrapper<Dict>()
+                .eq(Dict::getFlag, "floor-list")
+                .eq(Dict::getStatus, 1));
+        if (dict != null) {
+            for (Object o : JSON.parseArray(dict.getValue())) {
+                JSONObject jsonObject = JSON.parseObject(o.toString());
+                Integer lev = jsonObject.getInteger("value");
+                List<NavigateNode> path = navigateMapUtils.getLockPath(lev);
+                navigateNodes.addAll(path);
+            }
+        }
+        return navigateNodes;
+    }
+
 }
diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/NavigateMapUtils.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/NavigateMapUtils.java
index 26179cc..b6426ad 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/NavigateMapUtils.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/NavigateMapUtils.java
@@ -1,7 +1,10 @@
 package com.zy.asrs.wcs.core.utils;
 
 import com.alibaba.fastjson.JSON;
-import com.zy.asrs.framework.common.SpringUtils;
+import com.alibaba.fastjson.serializer.SerializerFeature;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import com.zy.asrs.wcs.core.domain.dto.RedisMapDto;
 import com.zy.asrs.wcs.core.model.MapNode;
 import com.zy.asrs.wcs.core.model.NavigateNode;
@@ -19,13 +22,16 @@
 
     @Autowired
     private NavigateMapData navigateMapData;
+    @Autowired
+    private RedisUtil redisUtil;
+    @Autowired
+    private ObjectMapper objectMapper;
 
     /**
      * 鍐欏叆璺緞鑺傜偣鏁版嵁鍒皉edis鍦板浘涓�
      * lock涓簍rue 绂佺敤搴撲綅锛宭ock涓篺alse鎭㈠搴撲綅
      */
     public synchronized boolean writeNavigateNodeToRedisMap(Integer lev, Integer shuttleNo, List<NavigateNode> nodes, boolean lock) {
-        RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class);
         try {
             if (nodes.isEmpty()) {
                 return true;
@@ -85,7 +91,10 @@
             redisMap.setData(JSON.toJSONString(lists));
             redisMap.setUpdateTime(new Date());
             //灏嗘暟鎹簱鍦板浘鏁版嵁瀛樺叆redis
-            redisUtil.set(DeviceRedisConstant.MAP + lev, JSON.toJSONString(redisMap));
+            redisUtil.set(DeviceRedisConstant.MAP + lev, JSON.toJSONString(redisMap, SerializerFeature.DisableCircularReferenceDetect));
+
+            //淇濆瓨璺緞閿佽妭鐐�
+            saveLockPath(lev, nodes, lock);
             return true;
         } catch (Exception e) {
             e.printStackTrace();
@@ -93,4 +102,52 @@
         return false;
     }
 
+    //淇濆瓨璺緞閿佽妭鐐�
+    public void saveLockPath(Integer lev, List<NavigateNode> nodes, boolean lock) {
+        Object o = redisUtil.get(DeviceRedisConstant.LOCK_PATH + lev);
+        List<NavigateNode> navigateNodes = new ArrayList<>();
+        if (o != null) {
+            navigateNodes = JSON.parseArray(o.toString(), NavigateNode.class);
+        }
+
+        if (lock) {
+            navigateNodes.addAll(nodes);
+            redisUtil.set(DeviceRedisConstant.LOCK_PATH + lev, JSON.toJSONString(navigateNodes, SerializerFeature.DisableCircularReferenceDetect));
+        }else {
+            List<NavigateNode> tmp = new ArrayList<>();
+            for (NavigateNode navigateNode : navigateNodes) {
+                boolean flag = true;
+                for (NavigateNode node : nodes) {
+                    if (navigateNode.getX() == node.getX()
+                            && navigateNode.getY() == node.getY()
+                            && navigateNode.getZ() == node.getZ()) {
+                        flag = false;
+                        break;
+                    }
+                }
+
+                if (flag) {
+                    tmp.add(navigateNode);
+                }
+            }
+
+            redisUtil.set(DeviceRedisConstant.LOCK_PATH + lev, JSON.toJSONString(tmp, SerializerFeature.DisableCircularReferenceDetect));
+        }
+    }
+
+    //鑾峰彇璺緞閿佽妭鐐�
+    public List<NavigateNode> getLockPath(Integer lev) {
+        Object obj = redisUtil.get(DeviceRedisConstant.LOCK_PATH + lev);
+        List<NavigateNode> navigateNodes = new ArrayList<>();
+        if (obj != null) {
+            try {
+                navigateNodes = objectMapper.readValue(obj.toString(), new TypeReference<List<NavigateNode>>() {});
+            } catch (JsonProcessingException e) {
+                throw new RuntimeException(e);
+            }
+        }
+
+        return navigateNodes;
+    }
+
 }
diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/constant/DeviceRedisConstant.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/constant/DeviceRedisConstant.java
index a4ab4df..327a493 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/constant/DeviceRedisConstant.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/constant/DeviceRedisConstant.java
@@ -15,6 +15,8 @@
 
     public static final String MAP = "realtimeBasMap_";
 
+    public static final String LOCK_PATH = "mapLockPath_";
+
     public static final String COMMAND_TMP = "command_tmp_";
 
 }

--
Gitblit v1.9.1