| | |
| | | //package com.zy.asrs.wcs.core.utils; |
| | | // |
| | | //import com.alibaba.fastjson.JSON; |
| | | //import com.zy.asrs.common.wms.entity.BasMap; |
| | | //import com.zy.asrs.framework.common.SpringUtils; |
| | | //import com.zy.asrs.wcs.core.model.MapNode; |
| | | //import com.zy.asrs.wcs.core.model.NavigateNode; |
| | | //import com.zy.asrs.wcs.core.model.enums.NavigationMapType; |
| | | //import com.zy.asrs.wcs.rcs.constant.DeviceRedisConstant; |
| | | //import org.springframework.stereotype.Component; |
| | | // |
| | | //import java.util.ArrayList; |
| | | //import java.util.Date; |
| | | //import java.util.List; |
| | | // |
| | | //@Component |
| | | //public class NavigateMapUtils { |
| | | // |
| | | // /** |
| | | // * 写入路径节点数据到redis地图中 |
| | | // * lock为true 禁用库位,lock为false恢复库位 |
| | | // */ |
| | | // public synchronized boolean writeNavigateNodeToRedisMap(Integer lev, Integer shuttleNo, List<NavigateNode> nodes, boolean lock) { |
| | | // RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class); |
| | | // try { |
| | | // if (nodes.isEmpty()) { |
| | | // return true; |
| | | // } |
| | | // |
| | | // NavigateMapData navigateMapData = new NavigateMapData(lev); |
| | | // |
| | | // Object o = redisUtil.get(DeviceRedisConstant.MAP + lev); |
| | | // if (o == null) { |
| | | // return false; |
| | | // } |
| | | // |
| | | // //获取小车节点 |
| | | // List<int[]> shuttlePoints = Utils.getShuttlePoints(shuttleNo, lev); |
| | | // |
| | | // BasMap basMap = JSON.parseObject(o.toString(), BasMap.class); |
| | | // ArrayList arrayList = JSON.parseObject(basMap.getData(), ArrayList.class); |
| | | // //带小车地图 |
| | | // List<List<MapNode>> listsHasShuttle = navigateMapData.filterMap(NavigationMapType.NONE.id, arrayList, lev, null, shuttlePoints);//获取带小车地图数据 |
| | | // List<List<MapNode>> lists = navigateMapData.filterMap(NavigationMapType.NONE.id, arrayList, lev, null, null);//获取全部地图数据 |
| | | // |
| | | // //检测路径是否被锁定 |
| | | // if (lock) { |
| | | // for (NavigateNode node : nodes) { |
| | | // List<MapNode> listX = listsHasShuttle.get(node.getX()); |
| | | // MapNode mapNode = listX.get(node.getY()); |
| | | // if (mapNode.getValue() == -999) { |
| | | // return false;//路径被锁定过,禁止再次锁定 |
| | | // } |
| | | // if (mapNode.getValue() == 66) { |
| | | // return false;//路径存在小车,禁止锁定 |
| | | // } |
| | | // } |
| | | // } |
| | | // |
| | | // //尝试锁定/解锁路径 |
| | | // NavigateMapData mapData = new NavigateMapData(nodes.get(0).getZ()); |
| | | // List<List<MapNode>> realMap = mapData.getJsonData(-1, null, null);//获取完整地图(包括入库出库) |
| | | // for (NavigateNode node : nodes) { |
| | | // if (node.getZ() != lev) { |
| | | // continue; |
| | | // } |
| | | // |
| | | // List<MapNode> listX = lists.get(node.getX()); |
| | | // MapNode mapNode = listX.get(node.getY()); |
| | | // if (lock) { |
| | | // mapNode.setValue(-999);//禁用库位 |
| | | // } else { |
| | | // //获取原始节点数据 |
| | | // List<MapNode> rows = realMap.get(node.getX()); |
| | | // MapNode col = rows.get(node.getY()); |
| | | // mapNode.setValue(col.getValue());//恢复库位 |
| | | // } |
| | | // |
| | | // listX.set(node.getY(), mapNode); |
| | | // lists.set(node.getX(), listX); |
| | | // } |
| | | // basMap.setData(JSON.toJSONString(lists)); |
| | | // basMap.setUpdateTime(new Date()); |
| | | // //将数据库地图数据存入redis |
| | | // redisUtil.set(DeviceRedisConstant.MAP + lev, JSON.toJSONString(basMap)); |
| | | // return true; |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // return false; |
| | | // } |
| | | // |
| | | //} |
| | | package com.zy.asrs.wcs.core.utils; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.serializer.SerializerFeature; |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.core.type.TypeReference; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.zy.asrs.wcs.core.domain.dto.RedisMapDto; |
| | | import com.zy.asrs.wcs.core.model.MapNode; |
| | | import com.zy.asrs.wcs.core.model.NavigateNode; |
| | | import com.zy.asrs.wcs.core.model.enums.NavigationMapType; |
| | | import com.zy.asrs.wcs.rcs.constant.DeviceRedisConstant; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Component |
| | | public class NavigateMapUtils { |
| | | |
| | | @Autowired |
| | | private NavigateMapData navigateMapData; |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | @Autowired |
| | | private ObjectMapper objectMapper; |
| | | |
| | | /** |
| | | * 写入路径节点数据到redis地图中 |
| | | * lock为true 禁用库位,lock为false恢复库位 |
| | | */ |
| | | public synchronized boolean writeNavigateNodeToRedisMap(Integer lev, Integer shuttleNo, List<NavigateNode> nodes, boolean lock) { |
| | | try { |
| | | if (nodes.isEmpty()) { |
| | | return true; |
| | | } |
| | | |
| | | navigateMapData.setLev(lev); |
| | | Object o = redisUtil.get(DeviceRedisConstant.MAP + lev); |
| | | if (o == null) { |
| | | return false; |
| | | } |
| | | |
| | | //获取小车节点 |
| | | List<int[]> shuttlePoints = Utils.getShuttlePoints(shuttleNo, lev); |
| | | |
| | | RedisMapDto redisMap = JSON.parseObject(o.toString(), RedisMapDto.class); |
| | | ArrayList arrayList = JSON.parseObject(redisMap.getData(), ArrayList.class); |
| | | //带小车地图 |
| | | List<List<MapNode>> listsHasShuttle = navigateMapData.filterMap(NavigationMapType.NONE.id, arrayList, lev, null, shuttlePoints);//获取带小车地图数据 |
| | | List<List<MapNode>> lists = navigateMapData.filterMap(NavigationMapType.NONE.id, arrayList, lev, null, null);//获取全部地图数据 |
| | | |
| | | //检测路径是否被锁定 |
| | | if (lock) { |
| | | for (NavigateNode node : nodes) { |
| | | List<MapNode> listX = listsHasShuttle.get(node.getX()); |
| | | MapNode mapNode = listX.get(node.getY()); |
| | | if (mapNode.getValue() == -999) { |
| | | return false;//路径被锁定过,禁止再次锁定 |
| | | } |
| | | if (mapNode.getValue() == 66) { |
| | | return false;//路径存在小车,禁止锁定 |
| | | } |
| | | } |
| | | } |
| | | |
| | | //尝试锁定/解锁路径 |
| | | navigateMapData.setLev(nodes.get(0).getZ()); |
| | | List<List<MapNode>> realMap = navigateMapData.getJsonDataFromDict(-1, null, null);//获取完整地图(包括入库出库) |
| | | for (NavigateNode node : nodes) { |
| | | if (node.getZ() != lev) { |
| | | continue; |
| | | } |
| | | |
| | | List<MapNode> listX = lists.get(node.getX()); |
| | | MapNode mapNode = listX.get(node.getY()); |
| | | if (lock) { |
| | | mapNode.setValue(-999);//禁用库位 |
| | | } else { |
| | | //获取原始节点数据 |
| | | List<MapNode> rows = realMap.get(node.getX()); |
| | | MapNode col = rows.get(node.getY()); |
| | | mapNode.setValue(col.getValue());//恢复库位 |
| | | } |
| | | |
| | | listX.set(node.getY(), mapNode); |
| | | lists.set(node.getX(), listX); |
| | | } |
| | | redisMap.setData(JSON.toJSONString(lists)); |
| | | redisMap.setUpdateTime(new Date()); |
| | | //将数据库地图数据存入redis |
| | | redisUtil.set(DeviceRedisConstant.MAP + lev, JSON.toJSONString(redisMap, SerializerFeature.DisableCircularReferenceDetect)); |
| | | |
| | | //保存路径锁节点 |
| | | saveLockPath(lev, nodes, lock); |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | //保存路径锁节点 |
| | | public void saveLockPath(Integer lev, List<NavigateNode> nodes, boolean lock) { |
| | | Object o = redisUtil.get(DeviceRedisConstant.LOCK_PATH + lev); |
| | | List<NavigateNode> navigateNodes = new ArrayList<>(); |
| | | if (o != null) { |
| | | navigateNodes = JSON.parseArray(o.toString(), NavigateNode.class); |
| | | } |
| | | |
| | | if (lock) { |
| | | navigateNodes.addAll(nodes); |
| | | redisUtil.set(DeviceRedisConstant.LOCK_PATH + lev, JSON.toJSONString(navigateNodes, SerializerFeature.DisableCircularReferenceDetect)); |
| | | }else { |
| | | List<NavigateNode> tmp = new ArrayList<>(); |
| | | for (NavigateNode navigateNode : navigateNodes) { |
| | | boolean flag = true; |
| | | for (NavigateNode node : nodes) { |
| | | if (navigateNode.getX() == node.getX() |
| | | && navigateNode.getY() == node.getY() |
| | | && navigateNode.getZ() == node.getZ()) { |
| | | flag = false; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (flag) { |
| | | tmp.add(navigateNode); |
| | | } |
| | | } |
| | | |
| | | redisUtil.set(DeviceRedisConstant.LOCK_PATH + lev, JSON.toJSONString(tmp, SerializerFeature.DisableCircularReferenceDetect)); |
| | | } |
| | | } |
| | | |
| | | //获取路径锁节点 |
| | | public List<NavigateNode> getLockPath(Integer lev) { |
| | | Object obj = redisUtil.get(DeviceRedisConstant.LOCK_PATH + lev); |
| | | List<NavigateNode> navigateNodes = new ArrayList<>(); |
| | | if (obj != null) { |
| | | try { |
| | | navigateNodes = objectMapper.readValue(obj.toString(), new TypeReference<List<NavigateNode>>() {}); |
| | | } catch (JsonProcessingException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | |
| | | return navigateNodes; |
| | | } |
| | | |
| | | } |