From dc09d42b89d8f17d85b45e88ca4b8f220b735ada Mon Sep 17 00:00:00 2001
From: Junjie <xjj@123>
Date: 星期三, 20 十一月 2024 16:27:28 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/common/utils/NavigateMapData.java |   74 ++++++++++++++++++++++++++----------
 1 files changed, 53 insertions(+), 21 deletions(-)

diff --git a/src/main/java/com/zy/common/utils/NavigateMapData.java b/src/main/java/com/zy/common/utils/NavigateMapData.java
index 62b43e6..b843053 100644
--- a/src/main/java/com/zy/common/utils/NavigateMapData.java
+++ b/src/main/java/com/zy/common/utils/NavigateMapData.java
@@ -9,7 +9,9 @@
 import com.zy.common.model.MapNode;
 import com.zy.common.model.NavigateNode;
 import com.zy.common.model.enums.NavigationMapType;
+import com.zy.core.enums.RedisKeyType;
 import com.zy.core.enums.ShuttleTaskModeType;
+import org.springframework.core.io.ClassPathResource;
 import org.springframework.stereotype.Component;
 
 import java.io.*;
@@ -40,9 +42,15 @@
     public int[][] getData(Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) {
         try {
             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);
+            }
 
-            String fileName = this.getClass().getClassLoader().getResource(mapFilename).getPath();//鑾峰彇鏂囦欢璺緞
-            File file = new File(fileName);
             StringBuffer stringBuffer = new StringBuffer();
             if (file.isFile() && file.exists()) {
                 InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "GBK");
@@ -69,6 +77,9 @@
                     map[j++] = tmp;
                 }
 
+                if (!file.delete()) {
+                    System.out.println("涓存椂鏂囦欢鍒犻櫎澶辫触");
+                }
                 return map;
             } else {
                 System.out.println("鏂囦欢涓嶅瓨鍦�!");
@@ -84,7 +95,7 @@
      */
     public int[][] getDataFromRedis(Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) {
         RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class);
-        Object o = redisUtil.get("realtimeBasMap_" + lev);
+        Object o = redisUtil.get(RedisKeyType.MAP.key + lev);
         if (o == null) {
             return null;
         }
@@ -119,9 +130,15 @@
     public List<List<MapNode>> getJsonData(Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) {
         try {
             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);
+            }
 
-            String fileName = this.getClass().getClassLoader().getResource(mapFilename).getPath();//鑾峰彇鏂囦欢璺緞
-            File file = new File(fileName);
             StringBuffer stringBuffer = new StringBuffer();
             if (file.isFile() && file.exists()) {
                 InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "GBK");
@@ -135,6 +152,10 @@
                 //瑙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 {
@@ -150,9 +171,15 @@
     public List<List<MapNode>> getJsonData(Integer lev, Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) {
         try {
             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);
+            }
 
-            String fileName = this.getClass().getClassLoader().getResource(mapFilename).getPath();//鑾峰彇鏂囦欢璺緞
-            File file = new File(fileName);
             StringBuffer stringBuffer = new StringBuffer();
             if (file.isFile() && file.exists()) {
                 InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "GBK");
@@ -166,6 +193,10 @@
                 //瑙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 {
@@ -264,23 +295,24 @@
         }
 
         //鍔犺浇鐧藉悕鍗曡妭鐐�
-        List<List<MapNode>> realMap = getJsonData(lev, -1, null, null);//鑾峰彇瀹屾暣鍦板浘
-        for (int[] points : whitePoints) {
-            //鑾峰彇鍘熷鑺傜偣鏁版嵁
-            int x = points[0];
-            int y = points[1];
-            List<MapNode> rows = realMap.get(x);
-            MapNode col = rows.get(y);
+        if (whitePoints != null) {
+            List<List<MapNode>> realMap = getJsonData(lev, -1, null, null);//鑾峰彇瀹屾暣鍦板浘
+            for (int[] points : whitePoints) {
+                //鑾峰彇鍘熷鑺傜偣鏁版嵁
+                int x = points[0];
+                int y = points[1];
+                List<MapNode> rows = realMap.get(x);
+                MapNode col = rows.get(y);
 
-            List<MapNode> list = lists.get(x);
-            MapNode mapNode = list.get(y);
-            mapNode.setValue(col.getValue());//鎭㈠鍘熷鑺傜偣
+                List<MapNode> list = lists.get(x);
+                MapNode mapNode = list.get(y);
+                mapNode.setValue(col.getValue());//鎭㈠鍘熷鑺傜偣
 
-            //鏇存柊list
-            list.set(y, mapNode);
-            lists.set(x, list);
+                //鏇存柊list
+                list.set(y, mapNode);
+                lists.set(x, list);
+            }
         }
-
 
         return lists;
     }

--
Gitblit v1.9.1