| | |
| | | @Autowired |
| | | private ObjectMapper objectMapper; |
| | | |
| | | public int[][] getData(Integer lev, List<NavigationMapType> mapTypes, List<int[]> whitePoints, List<int[]> shuttlePoints) { |
| | | try { |
| | | BasMap basMap = basMapService.selectLatestMap(lev); |
| | | String originData = basMap.getOriginData(); |
| | | |
| | | //解析json地图数据 |
| | | ArrayList arrayList = JSON.parseObject(originData, ArrayList.class); |
| | | List<List<MapNode>> lists = filterMap(mapTypes, 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; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 尝试从redis获取数据 |
| | | */ |
| | | public int[][] getDataFromRedis(Integer lev, List<NavigationMapType> mapTypes, List<int[]> whitePoints, List<int[]> shuttlePoints) { |
| | | Object o = redisUtil.get(RedisKeyType.MAP.key + lev); |
| | | if (o == null) { |
| | | Object data = redisUtil.get(RedisKeyType.MAP.key + lev); |
| | | if (data == null) { |
| | | return null; |
| | | } |
| | | |
| | | BasMap basMap = JSON.parseObject(o.toString(), BasMap.class); |
| | | return this.getDataFormString(lev, basMap.getData(), mapTypes, whitePoints, shuttlePoints); |
| | | List<List<MapNode>> arrayList = (List<List<MapNode>>) data; |
| | | return this.getDataFormString(lev, arrayList, mapTypes, whitePoints, shuttlePoints); |
| | | } |
| | | |
| | | /** |
| | | * 从List数据中获取地图 |
| | | */ |
| | | public int[][] getDataFormString(Integer lev, String data, List<NavigationMapType> mapTypes, List<int[]> whitePoints, List<int[]> shuttlePoints) { |
| | | ArrayList arrayList = JSON.parseObject(data, ArrayList.class); |
| | | public int[][] getDataFormString(Integer lev, List<List<MapNode>> arrayList, List<NavigationMapType> mapTypes, List<int[]> whitePoints, List<int[]> shuttlePoints) { |
| | | List<List<MapNode>> lists = filterMap(mapTypes, arrayList, lev, whitePoints, shuttlePoints);//过滤地图数据 |
| | | int[][] map = new int[lists.size()][]; |
| | | int j = 0; |
| | |
| | | return null; |
| | | } |
| | | |
| | | BasMap basMap = JSON.parseObject(data.toString(), BasMap.class); |
| | | //解析json地图数据 |
| | | ArrayList arrayList = JSON.parseObject(basMap.getData(), ArrayList.class); |
| | | List<List<MapNode>> arrayList = (List<List<MapNode>>) data; |
| | | List<List<MapNode>> lists = filterMap(mapTypes, arrayList, lev, whitePoints, shuttlePoints);//过滤地图数据 |
| | | return lists; |
| | | } catch (Exception e) { |
| | |
| | | * @param whitePoints 白名单节点,不需要被过滤 |
| | | * @param shuttlePoints 穿梭车节点,需要加载进地图 |
| | | */ |
| | | public List<List<MapNode>> filterMap(List<NavigationMapType> mapTypes, List arrayList, Integer lev, List<int[]> whitePoints, List<int[]> shuttlePoints) { |
| | | //重建数据格式 |
| | | List<List<MapNode>> lists = rebuildData(arrayList); |
| | | |
| | | public List<List<MapNode>> filterMap(List<NavigationMapType> mapTypes, List<List<MapNode>> lists, Integer lev, List<int[]> whitePoints, List<int[]> shuttlePoints) { |
| | | List<NavigationMapType> locMapType = new ArrayList<>(); |
| | | locMapType.add(NavigationMapType.NONE); |
| | | locMapType.add(NavigationMapType.DFX); |
| | | locMapType.add(NavigationMapType.NORMAL); |
| | | for (NavigationMapType mapType : mapTypes) { |
| | |
| | | lists.set(row, list); |
| | | } |
| | | } |
| | | |
| | | // HashMap<String, Integer> deviceMap = trafficControlThread.getDeviceMap(); |
| | | // if(deviceMap == null) { |
| | | // throw new CoolException("get traffic control device map error"); |
| | | // } |
| | | // |
| | | // for (Map.Entry<String, Integer> entry : deviceMap.entrySet()) { |
| | | // String key = entry.getKey(); |
| | | // Integer shuttleNo = entry.getValue(); |
| | | // if (shuttleNo <= 0) { |
| | | // continue; |
| | | // } |
| | | // |
| | | // Object object = redisUtil.get(RedisKeyType.SHUTTLE_FLAG.key + shuttleNo); |
| | | // if (object == null) { |
| | | // continue; |
| | | // } |
| | | // |
| | | // int taskNo = Integer.parseInt(String.valueOf(object)); |
| | | // |
| | | // Object obj = redisUtil.get(RedisKeyType.SHUTTLE_WORK_FLAG.key + taskNo); |
| | | // if (obj == null) { |
| | | // continue; |
| | | // } |
| | | // |
| | | // ShuttleRedisCommand redisCommand = null; |
| | | // try { |
| | | // redisCommand = objectMapper.readValue(String.valueOf(obj), ShuttleRedisCommand.class); |
| | | // } catch (IOException e) { |
| | | // throw new RuntimeException(e); |
| | | // } |
| | | // |
| | | // if (redisCommand == null) { |
| | | // continue; |
| | | // } |
| | | // |
| | | // ShuttleAssignCommand assignCommand = redisCommand.getAssignCommand(); |
| | | // List<ShuttleCommand> commands = assignCommand.getCommands(); |
| | | // |
| | | // List<NavigateNode> controlLocList = new ArrayList<>(); |
| | | // for (ShuttleCommand command : commands) { |
| | | // if (command.getComplete()) { |
| | | // continue; |
| | | // } |
| | | // |
| | | // if (command.getMode() == ShuttleCommandModeType.MOVE.id) { |
| | | // List<NavigateNode> nodes = command.getNodes(); |
| | | // for (NavigateNode node : nodes) { |
| | | // if(!controlLocList.contains(node)) { |
| | | // controlLocList.add(node); |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | // |
| | | // for (NavigateNode node : controlLocList) { |
| | | // int row = node.getX(); |
| | | // int bay = node.getY(); |
| | | // |
| | | // List<MapNode> list = lists.get(row); |
| | | // MapNode mapNode = list.get(bay); |
| | | // |
| | | // //节点设置成Disable |
| | | // mapNode.setValue(MapNodeType.DISABLE.id); |
| | | // |
| | | // //更新list |
| | | // list.set(bay, mapNode); |
| | | // lists.set(row, list); |
| | | // } |
| | | // |
| | | // } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |