| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.SpringUtils; |
| | | import com.core.exception.CoolException; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.zy.asrs.entity.BasMap; |
| | | import com.zy.asrs.entity.DeviceConfig; |
| | | import com.zy.asrs.entity.LocMast; |
| | |
| | | import com.zy.asrs.service.LocMastService; |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.common.model.MapNode; |
| | | import com.zy.common.model.NavigateNode; |
| | | import com.zy.common.model.enums.NavigationMapType; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.enums.MapNodeType; |
| | | import com.zy.core.enums.RedisKeyType; |
| | | import com.zy.core.enums.ShuttleCommandModeType; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.model.TrafficControlDataModel; |
| | | import com.zy.core.model.command.ShuttleAssignCommand; |
| | | import com.zy.core.model.command.ShuttleCommand; |
| | | import com.zy.core.model.command.ShuttleRedisCommand; |
| | | import com.zy.core.model.protocol.ForkLiftStaProtocol; |
| | | import com.zy.core.thread.ForkLiftThread; |
| | | import com.zy.core.thread.TrafficControlThread; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * A*算法地图获取类 |
| | |
| | | public class NavigateMapData { |
| | | |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | @Autowired |
| | | private DeviceConfigService deviceConfigService; |
| | | @Autowired |
| | | private BasMapService basMapService; |
| | | @Autowired |
| | | private ObjectMapper objectMapper; |
| | | |
| | | public int[][] getData(Integer lev, Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) { |
| | | 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(mapType, arrayList, lev, whitePoints, shuttlePoints);//过滤地图数据 |
| | | List<List<MapNode>> lists = filterMap(mapTypes, arrayList, lev, whitePoints, shuttlePoints);//过滤地图数据 |
| | | int[][] map = new int[lists.size()][]; |
| | | int j = 0; |
| | | for (List<MapNode> list : lists) { |
| | |
| | | /** |
| | | * 尝试从redis获取数据 |
| | | */ |
| | | public int[][] getDataFromRedis(Integer lev, Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) { |
| | | RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class); |
| | | 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) { |
| | | return null; |
| | | } |
| | | |
| | | BasMap basMap = JSON.parseObject(o.toString(), BasMap.class); |
| | | return this.getDataFormString(lev, basMap.getData(), mapType, whitePoints, shuttlePoints); |
| | | return this.getDataFormString(lev, basMap.getData(), mapTypes, whitePoints, shuttlePoints); |
| | | } |
| | | |
| | | /** |
| | | * 从List数据中获取地图 |
| | | */ |
| | | public int[][] getDataFormString(Integer lev, String data, Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) { |
| | | public int[][] getDataFormString(Integer lev, String data, List<NavigationMapType> mapTypes, List<int[]> whitePoints, List<int[]> shuttlePoints) { |
| | | ArrayList arrayList = JSON.parseObject(data, ArrayList.class); |
| | | List<List<MapNode>> lists = filterMap(mapType, arrayList, lev, whitePoints, shuttlePoints);//过滤地图数据 |
| | | List<List<MapNode>> lists = filterMap(mapTypes, arrayList, lev, whitePoints, shuttlePoints);//过滤地图数据 |
| | | int[][] map = new int[lists.size()][]; |
| | | int j = 0; |
| | | for (List<MapNode> list : lists) { |
| | |
| | | return map; |
| | | } |
| | | |
| | | //获取JSON格式数据 |
| | | public List<List<MapNode>> getJsonData(Integer lev, Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) { |
| | | //获取实时地图-JSON格式数据 |
| | | public List<List<MapNode>> getJsonData(Integer lev, List<NavigationMapType> mapTypes, List<int[]> whitePoints, List<int[]> shuttlePoints) { |
| | | try { |
| | | Object data = redisUtil.get(RedisKeyType.MAP.key + lev); |
| | | if (data == null) { |
| | | return null; |
| | | } |
| | | |
| | | BasMap basMap = JSON.parseObject(data.toString(), BasMap.class); |
| | | //解析json地图数据 |
| | | ArrayList arrayList = JSON.parseObject(basMap.getData(), ArrayList.class); |
| | | List<List<MapNode>> lists = filterMap(mapTypes, arrayList, lev, whitePoints, shuttlePoints);//过滤地图数据 |
| | | return lists; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | //获取原始地图-JSON格式数据 |
| | | public List<List<MapNode>> getJsonOriginData(Integer lev, List<NavigationMapType> mapTypes, List<int[]> whitePoints, List<int[]> shuttlePoints) { |
| | | try { |
| | | BasMap basMap = basMapService.selectLatestMap(lev); |
| | | String originData = basMap.getOriginData(); |
| | |
| | | * @param whitePoints 白名单节点,不需要被过滤 |
| | | * @param shuttlePoints 穿梭车节点,需要加载进地图 |
| | | */ |
| | | public List<List<MapNode>> filterMap(Integer mapType, List arrayList, Integer lev, List<int[]> whitePoints, List<int[]> 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); |
| | | |
| | | //载入库位信息 |
| | | lists = loadLocMast(mapType, lists, lev, whitePoints); |
| | | List<NavigationMapType> locMapType = new ArrayList<>(); |
| | | locMapType.add(NavigationMapType.NONE); |
| | | locMapType.add(NavigationMapType.DFX); |
| | | locMapType.add(NavigationMapType.NORMAL); |
| | | for (NavigationMapType mapType : mapTypes) { |
| | | if(locMapType.contains(mapType)) { |
| | | //载入库位信息 |
| | | lists = loadLocMast(mapType.id, lists, lev, whitePoints); |
| | | } |
| | | |
| | | //加载车辆 |
| | | lists = loadShuttle(lists, shuttlePoints); |
| | | if (mapType.equals(NavigationMapType.SHUTTLE)) { |
| | | //加载车辆 |
| | | lists = loadShuttle(lists, shuttlePoints); |
| | | } |
| | | |
| | | //加载货叉提升机点位 |
| | | lists = loadForkLift(lists, mapType, lev); |
| | | if (mapType.equals(NavigationMapType.LIFT)) { |
| | | //加载货叉提升机点位 |
| | | lists = loadForkLift(lists, lev); |
| | | } |
| | | |
| | | if(mapType.equals(NavigationMapType.PATH_LOCK)) { |
| | | //加载路径锁 |
| | | lists = loadPathLock(lists, lev); |
| | | } |
| | | |
| | | if(mapType.equals(NavigationMapType.TRAFFIC_CONTROL)) { |
| | | //加载交通管制 |
| | | lists = loadTrafficControl(lists, lev); |
| | | } |
| | | } |
| | | |
| | | //加载白名单节点 |
| | | lists = loadWhite(lists, lev, whitePoints); |
| | |
| | | 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);//获取完整地图 |
| | | List<List<MapNode>> realMap = getJsonData(lev, NavigationMapType.getMapTypes(NavigationMapType.NONE), null, null);//获取完整地图 |
| | | for (int[] points : whitePoints) { |
| | | //获取原始节点数据 |
| | | int x = points[0]; |
| | |
| | | } |
| | | |
| | | //加载货叉提升机点位 |
| | | public List<List<MapNode>> loadForkLift(List<List<MapNode>> lists, Integer mapType, Integer lev) { |
| | | public List<List<MapNode>> loadForkLift(List<List<MapNode>> lists, Integer lev) { |
| | | try { |
| | | //加载货叉提升机放货点位数据 |
| | | List<DeviceConfig> forkliftList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>() |
| | |
| | | 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); |
| | | } |
| | | } |
| | | // 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); |
| | |
| | | return lists; |
| | | } |
| | | |
| | | //加载路径锁 |
| | | public List<List<MapNode>> loadPathLock(List<List<MapNode>> lists, Integer lev) { |
| | | try { |
| | | HashMap<String, Object> lockMap = new HashMap<>(); |
| | | Object o = redisUtil.get(RedisKeyType.LOCK_MAP_NODES.key + lev); |
| | | if (o != null) { |
| | | lockMap = (HashMap<String, Object>) o; |
| | | } |
| | | |
| | | for (Map.Entry<String, Object> entry : lockMap.entrySet()) { |
| | | String key = entry.getKey(); |
| | | int row = Utils.getRow(key); |
| | | int bay = Utils.getBay(key); |
| | | |
| | | List<MapNode> list = lists.get(row); |
| | | MapNode mapNode = list.get(bay); |
| | | |
| | | //节点设置成路径锁 |
| | | mapNode.setValue(MapNodeType.LOCK.id); |
| | | |
| | | //更新list |
| | | list.set(bay, mapNode); |
| | | lists.set(row, list); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return lists; |
| | | } |
| | | |
| | | //加载交通管制 |
| | | public List<List<MapNode>> loadTrafficControl(List<List<MapNode>> lists, Integer lev) { |
| | | try { |
| | | TrafficControlThread trafficControlThread = (TrafficControlThread) SlaveConnection.get(SlaveType.TrafficControl, 1); |
| | | if (trafficControlThread == null) { |
| | | throw new CoolException("init traffic control thread error"); |
| | | } |
| | | |
| | | List<TrafficControlDataModel> trafficList = trafficControlThread.getAllTrafficControl(); |
| | | for (TrafficControlDataModel trafficControlDataModel : trafficList) { |
| | | List<NavigateNode> totalNodeList = trafficControlDataModel.getTotalNodeList(); |
| | | NavigateNode startNode = totalNodeList.get(0); |
| | | if (startNode.getZ() != lev) { |
| | | continue; |
| | | } |
| | | |
| | | for (NavigateNode node : totalNodeList) { |
| | | 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(); |
| | | } |
| | | return lists; |
| | | } |
| | | |
| | | } |