From 15f34a34c9588bc7b46dce8ee217e274adee38fa Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期一, 23 十二月 2024 12:41:36 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/common/utils/NavigateMapData.java | 169 +++++++++++++++++++++++++++++++++++++-------------------
1 files changed, 111 insertions(+), 58 deletions(-)
diff --git a/src/main/java/com/zy/common/utils/NavigateMapData.java b/src/main/java/com/zy/common/utils/NavigateMapData.java
index c605d39..a81489e 100644
--- a/src/main/java/com/zy/common/utils/NavigateMapData.java
+++ b/src/main/java/com/zy/common/utils/NavigateMapData.java
@@ -5,12 +5,14 @@
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.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.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Component;
@@ -25,28 +27,48 @@
@Component
public class NavigateMapData {
- private Integer lev;//鍦板浘妤煎眰
+// private Integer lev;//鍦板浘妤煎眰
+//
+// public Integer getLev() {
+// return lev;
+// }
+//
+// public void setLev(Integer lev) {
+// this.lev = lev;
+// }
- 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;
+// }
+//
+// //瑙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");
+ File file = File.createTempFile("prefix", "suffix");
try (OutputStream outStream = new FileOutputStream(file)) {
outStream.write(buffer);
}
@@ -84,8 +106,8 @@
} else {
System.out.println("鏂囦欢涓嶅瓨鍦�!");
}
- } catch (IOException ioException) {
- ioException.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
}
return null;
}
@@ -93,7 +115,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) {
@@ -101,13 +123,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()][];
@@ -126,46 +148,73 @@
return map;
}
- //鑾峰彇JSON鏍煎紡鏁版嵁
- 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);
- }
-
- 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);//杩囨护鍦板浘鏁版嵁
-
- return lists;
- } else {
- System.out.println("鏂囦欢涓嶅瓨鍦�!");
- }
- } catch (IOException ioException) {
- ioException.printStackTrace();
- }
- return null;
- }
+// //鑾峰彇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();
+// 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("鏂囦欢涓嶅瓨鍦�!");
+// }
+// } 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;
+// }
+//
+// //瑙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();
@@ -190,12 +239,16 @@
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 (IOException ioException) {
- ioException.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
}
return null;
}
--
Gitblit v1.9.1