|  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONArray; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.zy.asrs.common.wms.entity.BasMap; | 
|---|
|  |  |  | import com.zy.asrs.framework.common.SpringUtils; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.domain.dto.BasMapDto; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.domain.dto.RedisMapDto; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.entity.Loc; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.model.MapNode; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.model.enums.MapNodeType; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.model.enums.NavigationMapType; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.service.LocService; | 
|---|
|  |  |  | import com.zy.asrs.wcs.rcs.constant.DeviceRedisConstant; | 
|---|
|  |  |  | 
|---|
|  |  |  | private LocService locService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private DictService dictService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private NavigateMapData navigateMapData; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private Integer 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 = "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);//过滤地图数据 | 
|---|
|  |  |  | 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("文件不存在!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (IOException ioException) { | 
|---|
|  |  |  | ioException.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | return getDataFromRedis(NavigationMapType.NONE.id, null, null);//默认读取无过滤的全部地图数据 | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 尝试从redis获取数据 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public int[][] getDataFromRedis(Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) { | 
|---|
|  |  |  | String constantMap = DeviceRedisConstant.MAP; | 
|---|
|  |  |  | if(mapType == NavigationMapType.NONE_LOCK.id){ | 
|---|
|  |  |  | constantMap = DeviceRedisConstant.BASE_MAP; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class); | 
|---|
|  |  |  | Object o = redisUtil.get(DeviceRedisConstant.MAP + lev); | 
|---|
|  |  |  | Object o = redisUtil.get(constantMap + lev); | 
|---|
|  |  |  | if (o == null) { | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BasMap basMap = JSON.parseObject(o.toString(), BasMap.class); | 
|---|
|  |  |  | return this.getDataFormString(basMap.getData(), mapType, whitePoints, shuttlePoints); | 
|---|
|  |  |  | BasMapDto basMap = JSON.parseObject(o.toString(), BasMapDto.class); | 
|---|
|  |  |  | String mapData = basMap.getData(); | 
|---|
|  |  |  | return this.getDataFormString(mapData, mapType, whitePoints, shuttlePoints); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | mapNode.setNo(object.getString("row") + "-" + object.getString("bay")); | 
|---|
|  |  |  | mapNode.setXBase(object.getInteger("refx")); | 
|---|
|  |  |  | mapNode.setYBase(object.getInteger("refy")); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(mapNode.getValue() == MapNodeType.CONVEYOR.id) { | 
|---|
|  |  |  | //输送线,判断小车是否可走 | 
|---|
|  |  |  | if (object.containsKey("conveyorHasGo")) { | 
|---|
|  |  |  | if(object.getBoolean("conveyorHasGo")) { | 
|---|
|  |  |  | //小车可走 | 
|---|
|  |  |  | mapNode.setValue(MapNodeType.CONVEYOR_CAR_GO.id); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | nodes.add(mapNode); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | //存在空缺节点,自动补足 | 
|---|
|  |  |  | for (int i = defaultBay; i < node.getBay(); i++) { | 
|---|
|  |  |  | MapNode mapNode = new MapNode(); | 
|---|
|  |  |  | mapNode.setValue(-1); | 
|---|
|  |  |  | mapNode.setValue(MapNodeType.DISABLE.id); | 
|---|
|  |  |  | mapNode.setTop(1000); | 
|---|
|  |  |  | mapNode.setBottom(1000); | 
|---|
|  |  |  | mapNode.setLeft(1000); | 
|---|
|  |  |  | 
|---|
|  |  |  | ArrayList<ArrayList<MapNode>> lists = entry.getValue();//获取地图 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MapNode mapNode = new MapNode(); | 
|---|
|  |  |  | mapNode.setValue(-1); | 
|---|
|  |  |  | mapNode.setValue(MapNodeType.DISABLE.id); | 
|---|
|  |  |  | mapNode.setTop(1000); | 
|---|
|  |  |  | mapNode.setBottom(1000); | 
|---|
|  |  |  | mapNode.setLeft(1000); | 
|---|
|  |  |  | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BasMap basMap = JSON.parseObject(o.toString(), BasMap.class); | 
|---|
|  |  |  | BasMapDto basMap = JSON.parseObject(o.toString(), BasMapDto.class); | 
|---|
|  |  |  | ArrayList arrayList = JSON.parseObject(basMap.getData(), ArrayList.class); | 
|---|
|  |  |  | List<List<MapNode>> lists = filterMap(mapType, arrayList, lev, whitePoints, shuttlePoints);//过滤地图数据 | 
|---|
|  |  |  | return lists; | 
|---|
|  |  |  | 
|---|
|  |  |  | //获取当前楼层库位数据 | 
|---|
|  |  |  | List<Loc> locs = locService.list(new LambdaQueryWrapper<Loc>() | 
|---|
|  |  |  | .eq(Loc::getLev, lev) | 
|---|
|  |  |  | .eq(Loc::getStatus, 1) | 
|---|
|  |  |  | .orderByAsc(Loc::getRow, Loc::getBay)); | 
|---|
|  |  |  | for (Loc loc : locs) { | 
|---|
|  |  |  | Integer row = loc.getRow(); | 
|---|
|  |  |  | 
|---|
|  |  |  | } else if (mapType == NavigationMapType.DFX.id) { | 
|---|
|  |  |  | //车辆有货 | 
|---|
|  |  |  | //读取对应库位数据,将DFX库位状态的节点置为-1(障碍物) | 
|---|
|  |  |  | if (loc.getLocSts$().equals("F") | 
|---|
|  |  |  | || loc.getLocSts$().equals("D") | 
|---|
|  |  |  | || loc.getLocSts$().equals("X") | 
|---|
|  |  |  | if (loc.getLocStsFlag().equals("F") | 
|---|
|  |  |  | || loc.getLocStsFlag().equals("D") | 
|---|
|  |  |  | || loc.getLocStsFlag().equals("X") | 
|---|
|  |  |  | ) { | 
|---|
|  |  |  | mapNode.setValue(-1);//禁用节点 | 
|---|
|  |  |  | mapNode.setValue(MapNodeType.DISABLE.id);//禁用节点 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else if (mapType == NavigationMapType.NORMAL.id) { | 
|---|
|  |  |  | } else if (mapType == NavigationMapType.NORMAL.id || mapType == NavigationMapType.NONE_LOCK.id) { | 
|---|
|  |  |  | //过滤库位状态X | 
|---|
|  |  |  | if (loc.getLocSts$().equals("X")) { | 
|---|
|  |  |  | mapNode.setValue(-1);//禁用节点 | 
|---|
|  |  |  | if (loc.getLocStsFlag().equals("X")) { | 
|---|
|  |  |  | mapNode.setValue(MapNodeType.DISABLE.id);//禁用节点 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | int y = points[1]; | 
|---|
|  |  |  | List<MapNode> list = lists.get(x); | 
|---|
|  |  |  | MapNode mapNode = list.get(y); | 
|---|
|  |  |  | mapNode.setValue(66);//设置为车辆代码66 | 
|---|
|  |  |  | mapNode.setValue(MapNodeType.CAR.id);//设置为车辆代码66 | 
|---|
|  |  |  | //更新list | 
|---|
|  |  |  | list.set(y, mapNode); | 
|---|
|  |  |  | lists.set(x, list); | 
|---|