From 62b1f39e60f64ec4e05b21d11af3e36f5891a91a Mon Sep 17 00:00:00 2001 From: zc <zc@123> Date: 星期二, 29 四月 2025 20:10:27 +0800 Subject: [PATCH] # --- src/main/java/com/zy/common/utils/NavigateMapData.java | 377 ++++++++++++++++++++--------------------------------- 1 files changed, 146 insertions(+), 231 deletions(-) diff --git a/src/main/java/com/zy/common/utils/NavigateMapData.java b/src/main/java/com/zy/common/utils/NavigateMapData.java index 98cc5a1..94b016c 100644 --- a/src/main/java/com/zy/common/utils/NavigateMapData.java +++ b/src/main/java/com/zy/common/utils/NavigateMapData.java @@ -4,6 +4,7 @@ import com.core.common.SpringUtils; import com.zy.asrs.entity.BasMap; import com.zy.asrs.entity.LocMast; +import com.zy.asrs.service.BasMapService; import com.zy.asrs.service.LocMastService; import com.zy.asrs.utils.Utils; import com.zy.common.model.MapNode; @@ -17,7 +18,6 @@ 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.*; @@ -32,76 +32,31 @@ @Autowired private SlaveProperties slaveProperties; + @Autowired + private BasMapService basMapService; 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; + BasMap basMap = basMapService.selectLatestMap(lev); + String originData = basMap.getOriginData(); - 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(originData, 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; } - 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("鏂囦欢涓嶅瓨鍦�!"); - } + return map; } catch (Exception e) { e.printStackTrace(); } @@ -144,105 +99,16 @@ 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; -// -// -// 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("鏂囦欢涓嶅瓨鍦�!"); - } + BasMap basMap = basMapService.selectLatestMap(lev); + String originData = basMap.getOriginData(); + //瑙f瀽json鍦板浘鏁版嵁 + ArrayList arrayList = JSON.parseObject(originData, ArrayList.class); + //閲嶅缓鏁版嵁鏍煎紡 + List<List<MapNode>> lists = rebuildData(arrayList); + return lists; } catch (Exception e) { e.printStackTrace(); } @@ -257,6 +123,26 @@ * @param shuttlePoints 绌挎杞﹁妭鐐癸紝闇�瑕佸姞杞借繘鍦板浘 */ public List<List<MapNode>> filterMap(Integer mapType, List arrayList, Integer lev, List<int[]> whitePoints, List<int[]> shuttlePoints) { + //閲嶅缓鏁版嵁鏍煎紡 + List<List<MapNode>> lists = rebuildData(arrayList); + + //杞藉叆搴撲綅淇℃伅 + lists = loadLocMast(mapType, lists, lev, whitePoints); + + //鍔犺浇杞﹁締 + lists = loadShuttle(lists, shuttlePoints); + +// //鍔犺浇璐у弶鎻愬崌鏈虹偣浣� +// lists = loadForkLift(lists, mapType, lev); + + //鍔犺浇鐧藉悕鍗曡妭鐐� + lists = loadWhite(lists, lev, whitePoints); + + return lists; + } + + //閲嶅缓鏁版嵁鏍煎紡 + public List<List<MapNode>> rebuildData(List arrayList) { List<List<MapNode>> lists = new ArrayList<>(); //閲嶅缓鏁版嵁鏍煎紡 @@ -270,57 +156,71 @@ lists.add(list); } + return lists; + } + + //杞藉叆搴撲綅淇℃伅 + public List<List<MapNode>> loadLocMast(Integer mapType, List<List<MapNode>> lists, Integer lev, List<int[]> whitePoints) { //杩囨护鏁版嵁 LocMastService locMastService = SpringUtils.getBean(LocMastService.class); - //鑾峰彇褰撳墠妤煎眰搴撲綅鏁版嵁 - List<LocMast> locMasts = locMastService.selectLocByLev(lev); - for (LocMast locMast : locMasts) { - Integer row = locMast.getRow1(); - Integer bay = locMast.getBay1(); + try { + //鑾峰彇褰撳墠妤煎眰搴撲綅鏁版嵁 + List<LocMast> locMasts = locMastService.selectLocByLev(lev); + for (LocMast locMast : locMasts) { + Integer row = locMast.getRow1(); + Integer bay = locMast.getBay1(); - boolean whiteFlag = false;//榛樿涓嶅瓨鍦ㄧ櫧鍚嶅崟 - if (whitePoints != null) { - for (int[] whitePoint : whitePoints) { - if (whitePoint[0] == row && whitePoint[1] == bay) { - //瀛樺湪鐧藉悕鍗� - whiteFlag = true; - break; + boolean whiteFlag = false;//榛樿涓嶅瓨鍦ㄧ櫧鍚嶅崟 + if (whitePoints != null) { + for (int[] whitePoint : whitePoints) { + if (whitePoint[0] == row && whitePoint[1] == bay) { + //瀛樺湪鐧藉悕鍗� + whiteFlag = true; + break; + } } } - } - if (whiteFlag) { - continue;//瀛樺湪鐧藉悕鍗曪紝涓嶆墽琛屼笅鍒楄繃婊ゆ柟妗� - } - - - List<MapNode> list = lists.get(row); - MapNode mapNode = list.get(bay); - - if (mapType == NavigationMapType.NONE.id) { - //涓嶈繃婊や换浣曟暟鎹� - } else if (mapType == NavigationMapType.DFX.id) { - //杞﹁締鏈夎揣 - //璇诲彇瀵瑰簲搴撲綅鏁版嵁锛屽皢DFX搴撲綅鐘舵�佺殑鑺傜偣缃负-1(闅滅鐗�) - if (locMast.getLocSts().equals("F") - || locMast.getLocSts().equals("D") - || locMast.getLocSts().equals("X") - || locMast.getLocSts().equals("R") - || locMast.getLocSts().equals("P") - ) { - mapNode.setValue(MapNodeType.DISABLE.id);//绂佺敤鑺傜偣 + if (whiteFlag) { + continue;//瀛樺湪鐧藉悕鍗曪紝涓嶆墽琛屼笅鍒楄繃婊ゆ柟妗� } - } else if (mapType == NavigationMapType.NORMAL.id) { - //杩囨护搴撲綅鐘舵�乆 - if (locMast.getLocSts().equals("X")) { - mapNode.setValue(MapNodeType.DISABLE.id);//绂佺敤鑺傜偣 - } - } - //鏇存柊list - list.set(bay, mapNode); - lists.set(row, list); + + List<MapNode> list = lists.get(row); + MapNode mapNode = list.get(bay); + + if (mapType == NavigationMapType.NONE.id) { + //涓嶈繃婊や换浣曟暟鎹� + } else if (mapType == NavigationMapType.DFX.id) { + //杞﹁締鏈夎揣 + //璇诲彇瀵瑰簲搴撲綅鏁版嵁锛屽皢DFX搴撲綅鐘舵�佺殑鑺傜偣缃负-1(闅滅鐗�) + if (locMast.getLocSts().equals("F") + || locMast.getLocSts().equals("D") + || locMast.getLocSts().equals("X") + || locMast.getLocSts().equals("R") + || locMast.getLocSts().equals("P") + ) { + mapNode.setValue(MapNodeType.DISABLE.id);//绂佺敤鑺傜偣 + } + } else if (mapType == NavigationMapType.NORMAL.id) { + //杩囨护搴撲綅鐘舵�乆 + if (locMast.getLocSts().equals("X")) { + mapNode.setValue(MapNodeType.DISABLE.id);//绂佺敤鑺傜偣 + } + } + + //鏇存柊list + list.set(bay, mapNode); + lists.set(row, list); + } + }catch (Exception e) { + e.printStackTrace(); } + return lists; + } + + //鍔犺浇杞﹁締 + public List<List<MapNode>> loadShuttle(List<List<MapNode>> lists, List<int[]> shuttlePoints) { //鍔犺浇杞﹁締鍧愭爣鍒板湴鍥句腑 if (shuttlePoints != null) { for (int[] points : shuttlePoints) { @@ -335,6 +235,11 @@ } } + return lists; + } + + //鍔犺浇鐧藉悕鍗曡妭鐐� + public List<List<MapNode>> loadWhite(List<List<MapNode>> lists, Integer lev, List<int[]> whitePoints) { //鍔犺浇鐧藉悕鍗曡妭鐐� if (whitePoints != null) { List<List<MapNode>> realMap = getJsonData(lev, -1, null, null);//鑾峰彇瀹屾暣鍦板浘 @@ -354,39 +259,49 @@ lists.set(x, list); } } + return lists; + } - //鍔犺浇璐у弶鎻愬崌鏈烘斁璐х偣浣嶆暟鎹� - 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); - } + //鍔犺浇璐у弶鎻愬崌鏈虹偣浣� + public List<List<MapNode>> loadForkLift(List<List<MapNode>> lists, Integer mapType, Integer lev) { + try { + //鍔犺浇璐у弶鎻愬崌鏈烘斁璐х偣浣嶆暟鎹� + for (ForkLiftSlave forkLiftSlave : slaveProperties.getForkLift()) { + ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, forkLiftSlave.getId()); + if (forkLiftThread == null) { + continue; } - //鏇存柊list - list.set(bay, mapNode); - lists.set(row, list); + for (ForkLiftStaProtocol staProtocol : forkLiftThread.getForkLiftStaProtocols()) { + if (staProtocol.getLev() != lev) { + continue; + } + 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() != null && staProtocol.getHasTray()) { + mapNode.setValue(MapNodeType.DISABLE.id); + } + } else { + if (staProtocol.getHasCar() != null && staProtocol.getHasCar()) { + mapNode.setValue(MapNodeType.CAR.id); + } + } + + //鏇存柊list + list.set(bay, mapNode); + lists.set(row, list); + } + } - + } catch (Exception e) { + e.printStackTrace(); } - return lists; } -- Gitblit v1.9.1