From c3a428f2ef9dec82c49e1c9d4f425d3950d79804 Mon Sep 17 00:00:00 2001
From: Junjie <540245094@qq.com>
Date: 星期四, 28 十一月 2024 09:23:47 +0800
Subject: [PATCH] #定时充电
---
src/main/java/com/zy/common/utils/NavigateMapData.java | 336 +++++++++++++++++++++++++++++++++++++------------------
1 files changed, 223 insertions(+), 113 deletions(-)
diff --git a/src/main/java/com/zy/common/utils/NavigateMapData.java b/src/main/java/com/zy/common/utils/NavigateMapData.java
index 6012be6..204f937 100644
--- a/src/main/java/com/zy/common/utils/NavigateMapData.java
+++ b/src/main/java/com/zy/common/utils/NavigateMapData.java
@@ -5,11 +5,15 @@
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;
import java.io.*;
@@ -25,56 +29,89 @@
private Integer lev;//鍦板浘妤煎眰
- public NavigateMapData() {
- this.lev = 1;
+ public Integer getLev() {
+ return lev;
}
- public NavigateMapData(Integer lev) {
+ public void setLev(Integer lev) {
this.lev = lev;
}
public int[][] getData() {
- return getData(NavigationMapType.NONE.id, null);//榛樿璇诲彇鏃犺繃婊ょ殑鍏ㄩ儴鍦板浘鏁版嵁
+ return getData(NavigationMapType.NONE.id, null, null);//榛樿璇诲彇鏃犺繃婊ょ殑鍏ㄩ儴鍦板浘鏁版嵁
}
- public int[][] getData(Integer mapType, List<int[]> whitePoints) {
+ public int[][] getData(Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) {
try {
- String mapFilename = "map_" + lev + ".json";
-
- 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");
- 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);//杩囨护鍦板浘鏁版嵁
- 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;
- } else {
- System.out.println("鏂囦欢涓嶅瓨鍦�!");
+ RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class);
+ Object object = redisUtil.get(RedisKeyType.BASIC_MAP.key + lev);
+ if (object == null) {
+ return null;
}
- } catch (IOException ioException) {
- ioException.printStackTrace();
+
+ //瑙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);
+// }
+//
+// 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("鏂囦欢涓嶅瓨鍦�!");
+// }
+ } catch (Exception e) {
+ e.printStackTrace();
}
return null;
}
@@ -82,23 +119,23 @@
/**
* 灏濊瘯浠巖edis鑾峰彇鏁版嵁
*/
- public int[][] getDataFromRedis(Integer mapType, List<int[]> whitePoints) {
+ 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;
}
BasMap basMap = JSON.parseObject(o.toString(), BasMap.class);
- return this.getDataFormString(basMap.getData(), mapType, whitePoints);
+ return this.getDataFormString(basMap.getData(), mapType, whitePoints, shuttlePoints);
}
/**
* 浠嶭ist鏁版嵁涓幏鍙栧湴鍥�
*/
- public int[][] getDataFormString(String data, Integer mapType, List<int[]> whitePoints) {
+ public int[][] getDataFormString(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);//杩囨护鍦板浘鏁版嵁
+ List<List<MapNode>> lists = filterMap(mapType, arrayList, lev, whitePoints, shuttlePoints);//杩囨护鍦板浘鏁版嵁
int[][] map = new int[lists.size()][];
int j = 0;
for (List<MapNode> list : lists) {
@@ -116,32 +153,106 @@
}
//鑾峰彇JSON鏍煎紡鏁版嵁
- public List<List<MapNode>> getJsonData(Integer mapType, List<int[]> whitePoints) {
+ public List<List<MapNode>> getJsonData(Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) {
try {
- String mapFilename = "map_" + lev + ".json";
-
- 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");
- 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);//杩囨护鍦板浘鏁版嵁
-
- return lists;
- } else {
- System.out.println("鏂囦欢涓嶅瓨鍦�!");
+ RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class);
+ Object object = redisUtil.get(RedisKeyType.BASIC_MAP.key + lev);
+ if (object == null) {
+ return null;
}
- } catch (IOException ioException) {
- ioException.printStackTrace();
+
+ //瑙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();
+// 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;
}
@@ -149,9 +260,11 @@
/**
* 杩囨护鍦板浘鏁版嵁
* mapType -1=>鏃犺繃婊わ紝1=銆嬭繃婊ゅ簱浣嶇姸鎬丏FX锛�2=銆嬭繃婊ゅ簱浣嶇姸鎬乆
+ *
* @param whitePoints 鐧藉悕鍗曡妭鐐癸紝涓嶉渶瑕佽杩囨护
+ * @param shuttlePoints 绌挎杞﹁妭鐐癸紝闇�瑕佸姞杞借繘鍦板浘
*/
- public List<List<MapNode>> filterMap(Integer mapType, List arrayList, Integer lev, List<int[]> whitePoints) {
+ public List<List<MapNode>> filterMap(Integer mapType, List arrayList, Integer lev, List<int[]> whitePoints, List<int[]> shuttlePoints) {
List<List<MapNode>> lists = new ArrayList<>();
//閲嶅缓鏁版嵁鏍煎紡
@@ -196,7 +309,12 @@
} else if (mapType == NavigationMapType.DFX.id) {
//杞﹁締鏈夎揣
//璇诲彇瀵瑰簲搴撲綅鏁版嵁锛屽皢DFX搴撲綅鐘舵�佺殑鑺傜偣缃负-1(闅滅鐗�)
- if (locMast.getLocSts().equals("F") || locMast.getLocSts().equals("D") || locMast.getLocSts().equals("X")) {
+ if (locMast.getLocSts().equals("F")
+ || locMast.getLocSts().equals("D")
+ || locMast.getLocSts().equals("X")
+ || locMast.getLocSts().equals("R")
+ || locMast.getLocSts().equals("P")
+ ) {
mapNode.setValue(-1);//绂佺敤鑺傜偣
}
} else if (mapType == NavigationMapType.NORMAL.id) {
@@ -211,49 +329,41 @@
lists.set(row, list);
}
+ //鍔犺浇杞﹁締鍧愭爣鍒板湴鍥句腑
+ if (shuttlePoints != null) {
+ for (int[] points : shuttlePoints) {
+ int x = points[0];
+ int y = points[1];
+ List<MapNode> list = lists.get(x);
+ MapNode mapNode = list.get(y);
+ mapNode.setValue(66);//璁剧疆涓鸿溅杈嗕唬鐮�66
+ //鏇存柊list
+ list.set(y, mapNode);
+ lists.set(x, list);
+ }
+ }
+
+ //鍔犺浇鐧藉悕鍗曡妭鐐�
+ 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
+ list.set(y, mapNode);
+ lists.set(x, list);
+ }
+ }
+
return lists;
- }
-
- /**
- * 鍐欏叆璺緞鑺傜偣鏁版嵁鍒皉edis鍦板浘涓�
- * lock涓簍rue 绂佺敤搴撲綅锛宭ock涓篺alse鎭㈠搴撲綅
- */
- public boolean writeNavigateNodeToRedisMap(List<NavigateNode> nodes, boolean lock) {
- RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class);
- Object o = redisUtil.get("realtimeBasMap_" + lev);
- if (o == null) {
- return false;
- }
-
- BasMap basMap = JSON.parseObject(o.toString(), BasMap.class);
- ArrayList arrayList = JSON.parseObject(basMap.getData(), ArrayList.class);
- List<List<MapNode>> lists = filterMap(NavigationMapType.NONE.id, arrayList, lev, null);//鑾峰彇鍏ㄩ儴鍦板浘鏁版嵁
-
- for (NavigateNode node : nodes) {
- if (node.getZ() != lev) {
- continue;
- }
-
- List<MapNode> listX = lists.get(node.getX());
- MapNode mapNode = listX.get(node.getY());
- if (lock) {
- mapNode.setValue(-999);//绂佺敤搴撲綅
- }else {
- if (node.getX() == 11 || node.getX() == 19) {
- mapNode.setValue(3);//鎭㈠搴撲綅锛屾瘝杞ㄩ亾
- }else {
- mapNode.setValue(0);//鎭㈠搴撲綅锛屾櫘閫氬簱浣�
- }
- }
-
- listX.set(node.getY(), mapNode);
- lists.set(node.getX(), listX);
- }
- basMap.setData(JSON.toJSONString(lists));
- basMap.setUpdateTime(new Date());
- //灏嗘暟鎹簱鍦板浘鏁版嵁瀛樺叆redis
- redisUtil.set("realtimeBasMap_" + lev, JSON.toJSONString(basMap));
- return true;
}
}
--
Gitblit v1.9.1