| | |
| | | package com.zy.common.utils; |
| | | |
| | | 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; |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | public int[][] getData() { |
| | | return getData(ShuttleTaskModeType.PAK_IN.id); |
| | | return getData(NavigationMapType.NONE.id, null, null);//默认读取无过滤的全部地图数据 |
| | | } |
| | | |
| | | public int[][] getData(Integer mapType) { |
| | | public int[][] getData(Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) { |
| | | try { |
| | | String mapFilename = "map_" + lev + ".json"; |
| | | |
| | |
| | | |
| | | //解析json地图数据 |
| | | ArrayList arrayList = JSON.parseObject(stringBuffer.toString(), ArrayList.class); |
| | | List<List<MapNode>> lists = filterMap(mapType, arrayList);//过滤地图数据 |
| | | List<List<MapNode>> lists = filterMap(mapType, arrayList, lev, whitePoints, shuttlePoints);//过滤地图数据 |
| | | int[][] map = new int[lists.size()][]; |
| | | int j = 0; |
| | | for (List<MapNode> list : lists) { |
| | |
| | | /** |
| | | * 尝试从redis获取数据 |
| | | */ |
| | | public int[][] getDataFromRedis(Integer mapType) { |
| | | 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); |
| | | return this.getDataFormString(basMap.getData(), mapType, whitePoints, shuttlePoints); |
| | | } |
| | | |
| | | /** |
| | | * 从List数据中获取地图 |
| | | */ |
| | | public int[][] getDataFormString(String data, Integer mapType) { |
| | | 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);//过滤地图数据 |
| | | List<List<MapNode>> lists = filterMap(mapType, arrayList, lev, whitePoints, shuttlePoints);//过滤地图数据 |
| | | int[][] map = new int[lists.size()][]; |
| | | int j = 0; |
| | | for (List<MapNode> list : lists) { |
| | |
| | | } |
| | | |
| | | //获取JSON格式数据 |
| | | public List<List<MapNode>> getJsonData(Integer mapType) { |
| | | public List<List<MapNode>> getJsonData(Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) { |
| | | try { |
| | | String mapFilename = "map_" + lev + ".json"; |
| | | |
| | |
| | | |
| | | //解析json地图数据 |
| | | ArrayList arrayList = JSON.parseObject(stringBuffer.toString(), ArrayList.class); |
| | | List<List<MapNode>> lists = filterMap(mapType, arrayList);//过滤地图数据 |
| | | 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(); |
| | | |
| | | //解析json地图数据 |
| | | ArrayList arrayList = JSON.parseObject(stringBuffer.toString(), ArrayList.class); |
| | | List<List<MapNode>> lists = filterMap(mapType, arrayList, lev, whitePoints, shuttlePoints);//过滤地图数据 |
| | | |
| | | return lists; |
| | | } else { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 过滤地图数据,入库操作则过滤出库的禁用库位,出库操作则过滤入库的禁用库位 |
| | | * 过滤地图数据 |
| | | * mapType -1=>无过滤,1=》过滤库位状态DFX,2=》过滤库位状态X |
| | | * |
| | | * @param whitePoints 白名单节点,不需要被过滤 |
| | | * @param shuttlePoints 穿梭车节点,需要加载进地图 |
| | | */ |
| | | public List<List<MapNode>> filterMap(Integer mapType,List arrayList) { |
| | | 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); |
| | | if (mapType == ShuttleTaskModeType.PAK_IN.id) { |
| | | //入库地图 |
| | | if (mapNode.getData().equals("IN_X")) { |
| | | //禁止使用的库位,设置为-1 |
| | | mapNode.setValue(-1); |
| | | } |
| | | }else if(mapType == ShuttleTaskModeType.PAK_OUT.id){ |
| | | //出库地图 |
| | | if (mapNode.getData().equals("OUT_X")) { |
| | | //禁止使用的库位,设置为-1 |
| | | mapNode.setValue(-1); |
| | | } |
| | | } |
| | | list.set(j, mapNode); |
| | | } |
| | | lists.add(list); |
| | | } |
| | | |
| | | return lists; |
| | | } |
| | | //过滤数据 |
| | | LocMastService locMastService = SpringUtils.getBean(LocMastService.class); |
| | | //获取当前楼层库位数据 |
| | | List<LocMast> locMasts = locMastService.selectLocByLev(lev); |
| | | for (LocMast locMast : locMasts) { |
| | | Integer row = locMast.getRow1(); |
| | | Integer bay = locMast.getBay1(); |
| | | |
| | | /** |
| | | * 写入路径节点数据到redis地图中 |
| | | * lock为true 禁用库位,lock为false恢复库位 |
| | | */ |
| | | 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(-1, arrayList);//获取全部地图数据 |
| | | |
| | | for (NavigateNode node : nodes) { |
| | | if (node.getZ() != lev) { |
| | | continue; |
| | | 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> 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);//恢复库位,普通库位 |
| | | |
| | | 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) { |
| | | //过滤库位状态X |
| | | if (locMast.getLocSts().equals("X")) { |
| | | mapNode.setValue(-1);//禁用节点 |
| | | } |
| | | } |
| | | |
| | | listX.set(node.getY(), mapNode); |
| | | lists.set(node.getX(), listX); |
| | | //更新list |
| | | list.set(bay, mapNode); |
| | | lists.set(row, list); |
| | | } |
| | | basMap.setData(JSON.toJSONString(lists)); |
| | | //将数据库地图数据存入redis |
| | | redisUtil.set("realtimeBasMap_" + lev, JSON.toJSONString(basMap)); |
| | | return true; |
| | | |
| | | //加载车辆坐标到地图中 |
| | | 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; |
| | | } |
| | | |
| | | } |