From a6419abb1e5dc63f8957da5eb45c82d49b86cbc9 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期二, 07 一月 2025 16:38:47 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/common/utils/NavigateMapData.java |  318 ++++++++++++++++++++++++++++------------------------
 1 files changed, 172 insertions(+), 146 deletions(-)

diff --git a/src/main/java/com/zy/common/utils/NavigateMapData.java b/src/main/java/com/zy/common/utils/NavigateMapData.java
index 77a8562..98cc5a1 100644
--- a/src/main/java/com/zy/common/utils/NavigateMapData.java
+++ b/src/main/java/com/zy/common/utils/NavigateMapData.java
@@ -1,24 +1,27 @@
 package com.zy.common.utils;
 
 import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
 import com.core.common.SpringUtils;
 import com.zy.asrs.entity.BasMap;
 import com.zy.asrs.entity.LocMast;
-import com.zy.asrs.service.BasShuttleService;
 import com.zy.asrs.service.LocMastService;
+import com.zy.asrs.utils.Utils;
 import com.zy.common.model.MapNode;
-import com.zy.common.model.NavigateNode;
 import com.zy.common.model.enums.NavigationMapType;
+import com.zy.core.cache.SlaveConnection;
+import com.zy.core.enums.MapNodeType;
 import com.zy.core.enums.RedisKeyType;
-import com.zy.core.enums.ShuttleTaskModeType;
+import com.zy.core.enums.SlaveType;
+import com.zy.core.model.ForkLiftSlave;
+import com.zy.core.model.protocol.ForkLiftStaProtocol;
+import com.zy.core.properties.SlaveProperties;
+import com.zy.core.thread.ForkLiftThread;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.core.io.ClassPathResource;
 import org.springframework.stereotype.Component;
 
 import java.io.*;
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 
 /**
@@ -27,87 +30,78 @@
 @Component
 public class NavigateMapData {
 
-    private Integer lev;//鍦板浘妤煎眰
+    @Autowired
+    private SlaveProperties slaveProperties;
 
-    public NavigateMapData() {
-        this.lev = 1;
-    }
-
-    public NavigateMapData(Integer lev) {
-        this.lev = lev;
-    }
-
-    public int[][] getData() {
-        return getData(NavigationMapType.NONE.id, null, null);//榛樿璇诲彇鏃犺繃婊ょ殑鍏ㄩ儴鍦板浘鏁版嵁
-    }
-
-    public int[][] getData(Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) {
+    public int[][] getData(Integer lev, Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) {
         try {
-            RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class);
-            Object object = redisUtil.get(RedisKeyType.BASIC_MAP.key + lev);
-            if (object == null) {
-                return null;
+//            RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class);
+//            Object object = redisUtil.get(RedisKeyType.BASIC_MAP.key + lev);
+//            if (object == null) {
+//                return null;
+//            }
+//
+//            //瑙f瀽json鍦板浘鏁版嵁
+//            ArrayList arrayList = JSON.parseObject(object.toString(), ArrayList.class);
+//            List<List<MapNode>> lists = filterMap(mapType, arrayList, lev, whitePoints, shuttlePoints);//杩囨护鍦板浘鏁版嵁
+//            int[][] map = new int[lists.size()][];
+//            int j = 0;
+//            for (List<MapNode> list : lists) {
+//                int[] tmp = new int[list.size()];
+//                int i = 0;
+//                for (MapNode mapNode : list) {
+//                    //灏嗘暟鎹坊鍔犺繘浜岀淮鏁扮粍
+//                    tmp[i++] = mapNode.getValue();
+//                }
+//                //鏁版嵁娣诲姞杩涗竴缁存暟缁�
+//                map[j++] = tmp;
+//            }
+//
+//            return map;
+
+            String mapFilename = "map_" + lev + ".json";
+            ClassPathResource classPathResource = new ClassPathResource(mapFilename);
+            InputStream inputStream = classPathResource.getInputStream();
+            byte[] buffer = new byte[inputStream.available()];
+            inputStream.read(buffer);
+            File file = File.createTempFile("prefix", "suffix");
+            try (OutputStream outStream = new FileOutputStream(file)) {
+                outStream.write(buffer);
             }
 
-            //瑙f瀽json鍦板浘鏁版嵁
-            ArrayList arrayList = JSON.parseObject(object.toString(), ArrayList.class);
-            List<List<MapNode>> lists = filterMap(mapType, arrayList, lev, whitePoints, shuttlePoints);//杩囨护鍦板浘鏁版嵁
-            int[][] map = new int[lists.size()][];
-            int j = 0;
-            for (List<MapNode> list : lists) {
-                int[] tmp = new int[list.size()];
-                int i = 0;
-                for (MapNode mapNode : list) {
-                    //灏嗘暟鎹坊鍔犺繘浜岀淮鏁扮粍
-                    tmp[i++] = mapNode.getValue();
+            StringBuffer stringBuffer = new StringBuffer();
+            if (file.isFile() && file.exists()) {
+                InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "GBK");
+                BufferedReader br = new BufferedReader(isr);
+                String lineTxt = null;
+                while ((lineTxt = br.readLine()) != null) {
+                    stringBuffer.append(lineTxt);
                 }
-                //鏁版嵁娣诲姞杩涗竴缁存暟缁�
-                map[j++] = tmp;
-            }
+                br.close();
 
-//            String mapFilename = "map_" + lev + ".json";
-//            ClassPathResource classPathResource = new ClassPathResource(mapFilename);
-//            InputStream inputStream = classPathResource.getInputStream();
-//            byte[] buffer = new byte[inputStream.available()];
-//            inputStream.read(buffer);
-//            File file = File.createTempFile("prefix","suffix");
-//            try (OutputStream outStream = new FileOutputStream(file)) {
-//                outStream.write(buffer);
-//            }
-//
-//            StringBuffer stringBuffer = new StringBuffer();
-//            if (file.isFile() && file.exists()) {
-//                InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "GBK");
-//                BufferedReader br = new BufferedReader(isr);
-//                String lineTxt = null;
-//                while ((lineTxt = br.readLine()) != null) {
-//                    stringBuffer.append(lineTxt);
-//                }
-//                br.close();
-//
-//                //瑙f瀽json鍦板浘鏁版嵁
-//                ArrayList arrayList = JSON.parseObject(stringBuffer.toString(), ArrayList.class);
-//                List<List<MapNode>> lists = filterMap(mapType, arrayList, lev, whitePoints, shuttlePoints);//杩囨护鍦板浘鏁版嵁
-//                int[][] map = new int[lists.size()][];
-//                int j = 0;
-//                for (List<MapNode> list : lists) {
-//                    int[] tmp = new int[list.size()];
-//                    int i = 0;
-//                    for (MapNode mapNode : list) {
-//                        //灏嗘暟鎹坊鍔犺繘浜岀淮鏁扮粍
-//                        tmp[i++] = mapNode.getValue();
-//                    }
-//                    //鏁版嵁娣诲姞杩涗竴缁存暟缁�
-//                    map[j++] = tmp;
-//                }
-//
-//                if (!file.delete()) {
-//                    System.out.println("涓存椂鏂囦欢鍒犻櫎澶辫触");
-//                }
-//                return map;
-//            } else {
-//                System.out.println("鏂囦欢涓嶅瓨鍦�!");
-//            }
+                //瑙f瀽json鍦板浘鏁版嵁
+                ArrayList arrayList = JSON.parseObject(stringBuffer.toString(), ArrayList.class);
+                List<List<MapNode>> lists = filterMap(mapType, arrayList, lev, whitePoints, shuttlePoints);//杩囨护鍦板浘鏁版嵁
+                int[][] map = new int[lists.size()][];
+                int j = 0;
+                for (List<MapNode> list : lists) {
+                    int[] tmp = new int[list.size()];
+                    int i = 0;
+                    for (MapNode mapNode : list) {
+                        //灏嗘暟鎹坊鍔犺繘浜岀淮鏁扮粍
+                        tmp[i++] = mapNode.getValue();
+                    }
+                    //鏁版嵁娣诲姞杩涗竴缁存暟缁�
+                    map[j++] = tmp;
+                }
+
+                if (!file.delete()) {
+                    System.out.println("涓存椂鏂囦欢鍒犻櫎澶辫触");
+                }
+                return map;
+            } else {
+                System.out.println("鏂囦欢涓嶅瓨鍦�!");
+            }
         } catch (Exception e) {
             e.printStackTrace();
         }
@@ -117,7 +111,7 @@
     /**
      * 灏濊瘯浠巖edis鑾峰彇鏁版嵁
      */
-    public int[][] getDataFromRedis(Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) {
+    public int[][] getDataFromRedis(Integer lev, Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) {
         RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class);
         Object o = redisUtil.get(RedisKeyType.MAP.key + lev);
         if (o == null) {
@@ -125,13 +119,13 @@
         }
 
         BasMap basMap = JSON.parseObject(o.toString(), BasMap.class);
-        return this.getDataFormString(basMap.getData(), mapType, whitePoints, shuttlePoints);
+        return this.getDataFormString(lev, basMap.getData(), mapType, whitePoints, shuttlePoints);
     }
 
     /**
      * 浠嶭ist鏁版嵁涓幏鍙栧湴鍥�
      */
-    public int[][] getDataFormString(String data, Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) {
+    public int[][] getDataFormString(Integer lev, String data, Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) {
         ArrayList arrayList = JSON.parseObject(data, ArrayList.class);
         List<List<MapNode>> lists = filterMap(mapType, arrayList, lev, whitePoints, shuttlePoints);//杩囨护鍦板浘鏁版嵁
         int[][] map = new int[lists.size()][];
@@ -150,21 +144,21 @@
         return map;
     }
 
-    //鑾峰彇JSON鏍煎紡鏁版嵁
-    public List<List<MapNode>> getJsonData(Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) {
-        try {
-            RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class);
-            Object object = redisUtil.get(RedisKeyType.BASIC_MAP.key + lev);
-            if (object == null) {
-                return null;
-            }
-
-            //瑙f瀽json鍦板浘鏁版嵁
-            ArrayList arrayList = JSON.parseObject(object.toString(), ArrayList.class);
-            List<List<MapNode>> lists = filterMap(mapType, arrayList, lev, whitePoints, shuttlePoints);//杩囨护鍦板浘鏁版嵁
-            return lists;
-
-
+//    //鑾峰彇JSON鏍煎紡鏁版嵁
+//    public List<List<MapNode>> getJsonData(Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) {
+//        try {
+////            RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class);
+////            Object object = redisUtil.get(RedisKeyType.BASIC_MAP.key + lev);
+////            if (object == null) {
+////                return null;
+////            }
+////
+////            //瑙f瀽json鍦板浘鏁版嵁
+////            ArrayList arrayList = JSON.parseObject(object.toString(), ArrayList.class);
+////            List<List<MapNode>> lists = filterMap(mapType, arrayList, lev, whitePoints, shuttlePoints);//杩囨护鍦板浘鏁版嵁
+////            return lists;
+//
+//
 //            String mapFilename = "map_" + lev + ".json";
 //            ClassPathResource classPathResource = new ClassPathResource(mapFilename);
 //            InputStream inputStream = classPathResource.getInputStream();
@@ -197,58 +191,58 @@
 //            } else {
 //                System.out.println("鏂囦欢涓嶅瓨鍦�!");
 //            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        return null;
-    }
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//        }
+//        return null;
+//    }
 
     //鑾峰彇JSON鏍煎紡鏁版嵁
     public List<List<MapNode>> getJsonData(Integer lev, Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) {
         try {
-            RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class);
-            Object object = redisUtil.get(RedisKeyType.BASIC_MAP.key + lev);
-            if (object == null) {
-                return null;
+//            RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class);
+//            Object object = redisUtil.get(RedisKeyType.BASIC_MAP.key + lev);
+//            if (object == null) {
+//                return null;
+//            }
+//
+//            //瑙f瀽json鍦板浘鏁版嵁
+//            ArrayList arrayList = JSON.parseObject(object.toString(), ArrayList.class);
+//            List<List<MapNode>> lists = filterMap(mapType, arrayList, lev, whitePoints, shuttlePoints);//杩囨护鍦板浘鏁版嵁
+//            return lists;
+
+            String mapFilename = "map_" + lev + ".json";
+            ClassPathResource classPathResource = new ClassPathResource(mapFilename);
+            InputStream inputStream = classPathResource.getInputStream();
+            byte[] buffer = new byte[inputStream.available()];
+            inputStream.read(buffer);
+            File file = File.createTempFile("prefix","suffix");
+            try (OutputStream outStream = new FileOutputStream(file)) {
+                outStream.write(buffer);
             }
 
-            //瑙f瀽json鍦板浘鏁版嵁
-            ArrayList arrayList = JSON.parseObject(object.toString(), ArrayList.class);
-            List<List<MapNode>> lists = filterMap(mapType, arrayList, lev, whitePoints, shuttlePoints);//杩囨护鍦板浘鏁版嵁
-            return lists;
+            StringBuffer stringBuffer = new StringBuffer();
+            if (file.isFile() && file.exists()) {
+                InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "GBK");
+                BufferedReader br = new BufferedReader(isr);
+                String lineTxt = null;
+                while ((lineTxt = br.readLine()) != null) {
+                    stringBuffer.append(lineTxt);
+                }
+                br.close();
 
-//            String mapFilename = "map_" + lev + ".json";
-//            ClassPathResource classPathResource = new ClassPathResource(mapFilename);
-//            InputStream inputStream = classPathResource.getInputStream();
-//            byte[] buffer = new byte[inputStream.available()];
-//            inputStream.read(buffer);
-//            File file = File.createTempFile("prefix","suffix");
-//            try (OutputStream outStream = new FileOutputStream(file)) {
-//                outStream.write(buffer);
-//            }
-//
-//            StringBuffer stringBuffer = new StringBuffer();
-//            if (file.isFile() && file.exists()) {
-//                InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "GBK");
-//                BufferedReader br = new BufferedReader(isr);
-//                String lineTxt = null;
-//                while ((lineTxt = br.readLine()) != null) {
-//                    stringBuffer.append(lineTxt);
-//                }
-//                br.close();
-//
-//                //瑙f瀽json鍦板浘鏁版嵁
-//                ArrayList arrayList = JSON.parseObject(stringBuffer.toString(), ArrayList.class);
-//                List<List<MapNode>> lists = filterMap(mapType, arrayList, lev, whitePoints, shuttlePoints);//杩囨护鍦板浘鏁版嵁
-//
-//                if (!file.delete()) {
-//                    System.out.println("涓存椂鏂囦欢鍒犻櫎澶辫触");
-//                }
-//
-//                return lists;
-//            } else {
-//                System.out.println("鏂囦欢涓嶅瓨鍦�!");
-//            }
+                //瑙f瀽json鍦板浘鏁版嵁
+                ArrayList arrayList = JSON.parseObject(stringBuffer.toString(), ArrayList.class);
+                List<List<MapNode>> lists = filterMap(mapType, arrayList, lev, whitePoints, shuttlePoints);//杩囨护鍦板浘鏁版嵁
+
+                if (!file.delete()) {
+                    System.out.println("涓存椂鏂囦欢鍒犻櫎澶辫触");
+                }
+
+                return lists;
+            } else {
+                System.out.println("鏂囦欢涓嶅瓨鍦�!");
+            }
         } catch (Exception e) {
             e.printStackTrace();
         }
@@ -313,12 +307,12 @@
                         || locMast.getLocSts().equals("R")
                         || locMast.getLocSts().equals("P")
                 ) {
-                    mapNode.setValue(-1);//绂佺敤鑺傜偣
+                    mapNode.setValue(MapNodeType.DISABLE.id);//绂佺敤鑺傜偣
                 }
             } else if (mapType == NavigationMapType.NORMAL.id) {
                 //杩囨护搴撲綅鐘舵�乆
                 if (locMast.getLocSts().equals("X")) {
-                    mapNode.setValue(-1);//绂佺敤鑺傜偣
+                    mapNode.setValue(MapNodeType.DISABLE.id);//绂佺敤鑺傜偣
                 }
             }
 
@@ -334,7 +328,7 @@
                 int y = points[1];
                 List<MapNode> list = lists.get(x);
                 MapNode mapNode = list.get(y);
-                mapNode.setValue(66);//璁剧疆涓鸿溅杈嗕唬鐮�66
+                mapNode.setValue(MapNodeType.CAR.id);//璁剧疆涓鸿溅杈嗕唬鐮�66
                 //鏇存柊list
                 list.set(y, mapNode);
                 lists.set(x, list);
@@ -361,6 +355,38 @@
             }
         }
 
+        //鍔犺浇璐у弶鎻愬崌鏈烘斁璐х偣浣嶆暟鎹�
+        for (ForkLiftSlave forkLiftSlave : slaveProperties.getForkLift()) {
+            ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, forkLiftSlave.getId());
+            if (forkLiftThread == null) {
+                continue;
+            }
+
+            for (ForkLiftStaProtocol staProtocol : forkLiftThread.getForkLiftStaProtocols()) {
+                int row = Utils.getRow(staProtocol.getLocNo());
+                int bay = Utils.getBay(staProtocol.getLocNo());
+
+                List<MapNode> list = lists.get(row);
+                MapNode mapNode = list.get(bay);
+
+                if (mapType == NavigationMapType.DFX.id) {
+                    //杞﹁締鏈夎揣
+                    if (staProtocol.getHasTray()) {
+                        mapNode.setValue(MapNodeType.DISABLE.id);
+                    }
+                }else {
+                    if (staProtocol.getHasCar()) {
+                        mapNode.setValue(MapNodeType.CAR.id);
+                    }
+                }
+
+                //鏇存柊list
+                list.set(bay, mapNode);
+                lists.set(row, list);
+            }
+
+        }
+
         return lists;
     }
 

--
Gitblit v1.9.1