From fd0ab28fe906d3328ee1170c1a7daa203935ffc9 Mon Sep 17 00:00:00 2001
From: tzsk <Administrator@qq.com>
Date: 星期四, 14 十一月 2024 23:18:11 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/common/utils/NavigateMapData.java |   34 ++++++++++++++++++++++++++++------
 1 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/src/main/java/com/zy/common/utils/NavigateMapData.java b/src/main/java/com/zy/common/utils/NavigateMapData.java
index fcc7422..c605d39 100644
--- a/src/main/java/com/zy/common/utils/NavigateMapData.java
+++ b/src/main/java/com/zy/common/utils/NavigateMapData.java
@@ -11,6 +11,7 @@
 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.*;
@@ -41,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");
@@ -70,6 +77,9 @@
                     map[j++] = tmp;
                 }
 
+                if (!file.delete()) {
+                    System.out.println("涓存椂鏂囦欢鍒犻櫎澶辫触");
+                }
                 return map;
             } else {
                 System.out.println("鏂囦欢涓嶅瓨鍦�!");
@@ -120,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");
@@ -151,9 +167,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");

--
Gitblit v1.9.1