From e80cb83c601a9a9a0b3db6d848ea605800d22bc7 Mon Sep 17 00:00:00 2001 From: Junjie <540245094@qq.com> Date: 星期五, 01 十二月 2023 13:44:39 +0800 Subject: [PATCH] #盘点逻辑 --- src/main/java/com/zy/common/utils/NavigateMapData.java | 254 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 239 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/zy/common/utils/NavigateMapData.java b/src/main/java/com/zy/common/utils/NavigateMapData.java index 7ffae0e..7628bce 100644 --- a/src/main/java/com/zy/common/utils/NavigateMapData.java +++ b/src/main/java/com/zy/common/utils/NavigateMapData.java @@ -2,27 +2,45 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.core.common.SpringUtils; +import com.zy.asrs.entity.BasMap; +import com.zy.asrs.entity.LocMast; +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.stereotype.Component; import java.io.*; import java.util.ArrayList; +import java.util.Date; +import java.util.List; /** * A*绠楁硶鍦板浘鑾峰彇绫� */ +@Component public class NavigateMapData { - public int[][] getData() { - return getData("in"); + private Integer lev;//鍦板浘妤煎眰 + + public NavigateMapData() { + this.lev = 1; } - public int[][] getData(String mapType) { + 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) { try { - String mapFilename = ""; - if (mapType.equals("in")) { - mapFilename = "mapIn.json"; - }else { - mapFilename = "mapOut.json"; - } + String mapFilename = "map_" + lev + ".json"; String fileName = this.getClass().getClassLoader().getResource(mapFilename).getPath();//鑾峰彇鏂囦欢璺緞 File file = new File(fileName); @@ -38,16 +56,15 @@ //瑙f瀽json鍦板浘鏁版嵁 ArrayList arrayList = JSON.parseObject(stringBuffer.toString(), ArrayList.class); - int[][] map = new int[arrayList.size()][]; + List<List<MapNode>> lists = filterMap(mapType, arrayList, lev, whitePoints, shuttlePoints);//杩囨护鍦板浘鏁版嵁 + int[][] map = new int[lists.size()][]; int j = 0; - for (Object obj : arrayList) { - ArrayList list = JSON.parseObject(obj.toString(), ArrayList.class); + for (List<MapNode> list : lists) { int[] tmp = new int[list.size()]; int i = 0; - for (Object o : list) { - JSONObject jsonObject = JSON.parseObject(o.toString()); + for (MapNode mapNode : list) { //灏嗘暟鎹坊鍔犺繘浜岀淮鏁扮粍 - tmp[i++] = Integer.parseInt(jsonObject.get("value").toString()); + tmp[i++] = mapNode.getValue(); } //鏁版嵁娣诲姞杩涗竴缁存暟缁� map[j++] = tmp; @@ -63,4 +80,211 @@ return null; } + /** + * 灏濊瘯浠巖edis鑾峰彇鏁版嵁 + */ + public int[][] getDataFromRedis(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) { + return null; + } + + BasMap basMap = JSON.parseObject(o.toString(), BasMap.class); + return this.getDataFormString(basMap.getData(), mapType, whitePoints, shuttlePoints); + } + + /** + * 浠嶭ist鏁版嵁涓幏鍙栧湴鍥� + */ + 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, 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; + } + + //鑾峰彇JSON鏍煎紡鏁版嵁 + 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, shuttlePoints);//杩囨护鍦板浘鏁版嵁 + + return lists; + } else { + System.out.println("鏂囦欢涓嶅瓨鍦�!"); + } + } catch (IOException ioException) { + ioException.printStackTrace(); + } + return null; + } + + //鑾峰彇JSON鏍煎紡鏁版嵁 + public List<List<MapNode>> getJsonData(Integer lev, 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, shuttlePoints);//杩囨护鍦板浘鏁版嵁 + + return lists; + } else { + System.out.println("鏂囦欢涓嶅瓨鍦�!"); + } + } catch (IOException ioException) { + ioException.printStackTrace(); + } + return null; + } + + /** + * 杩囨护鍦板浘鏁版嵁 + * mapType -1=>鏃犺繃婊わ紝1=銆嬭繃婊ゅ簱浣嶇姸鎬丏FX锛�2=銆嬭繃婊ゅ簱浣嶇姸鎬乆 + * + * @param whitePoints 鐧藉悕鍗曡妭鐐癸紝涓嶉渶瑕佽杩囨护 + * @param shuttlePoints 绌挎杞﹁妭鐐癸紝闇�瑕佸姞杞借繘鍦板浘 + */ + public List<List<MapNode>> filterMap(Integer mapType, List arrayList, Integer lev, List<int[]> whitePoints, List<int[]> shuttlePoints) { + List<List<MapNode>> lists = new ArrayList<>(); + + //閲嶅缓鏁版嵁鏍煎紡 + for (int i = 0; i < arrayList.size(); i++) { + Object obj = arrayList.get(i); + List<MapNode> list = JSON.parseArray(obj.toString(), MapNode.class); + for (int j = 0; j < list.size(); j++) { + MapNode mapNode = list.get(j); + list.set(j, mapNode); + } + lists.add(list); + } + + //杩囨护鏁版嵁 + LocMastService locMastService = SpringUtils.getBean(LocMastService.class); + //鑾峰彇褰撳墠妤煎眰搴撲綅鏁版嵁 + 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; + } + } + } + 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(-1);//绂佺敤鑺傜偣 + } + } else if (mapType == NavigationMapType.NORMAL.id) { + //杩囨护搴撲綅鐘舵�乆 + if (locMast.getLocSts().equals("X")) { + mapNode.setValue(-1);//绂佺敤鑺傜偣 + } + } + + //鏇存柊list + list.set(bay, mapNode); + 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; + } + } -- Gitblit v1.9.1