自动化立体仓库 - WCS系统
#
Junjie
2023-12-01 d500950add4a43fbd02135a5cb59de0493a8261a
src/main/java/com/zy/common/utils/NavigateMapData.java
@@ -9,6 +9,7 @@
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;
@@ -84,7 +85,7 @@
     */
    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;
        }
@@ -117,6 +118,37 @@
    //获取JSON格式数据
    public List<List<MapNode>> getJsonData(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 {
                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";
@@ -202,7 +234,7 @@
                        || locMast.getLocSts().equals("D")
                        || locMast.getLocSts().equals("X")
                        || locMast.getLocSts().equals("R")
                        || locMast.getLocSts().equals("P")
//                        || locMast.getLocSts().equals("P")
                ) {
                    mapNode.setValue(-1);//禁用节点
                }
@@ -232,61 +264,27 @@
            }
        }
        return lists;
    }
        //加载白名单节点
        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);
    /**
     * 写入路径节点数据到redis地图中
     * lock为true 禁用库位,lock为false恢复库位
     */
    public boolean writeNavigateNodeToRedisMap(List<NavigateNode> nodes, boolean lock) {
        RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class);
        try {
            if (!redisUtil.tryLock("realtimeBasMap_" + lev)) {
                return false;//加锁失败
                List<MapNode> list = lists.get(x);
                MapNode mapNode = list.get(y);
                mapNode.setValue(col.getValue());//恢复原始节点
                //更新list
                list.set(y, mapNode);
                lists.set(x, list);
            }
            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(NavigationMapType.NONE.id, arrayList, lev, null, null);//获取全部地图数据
            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("realtimeBasMap_" + lev, JSON.toJSONString(basMap));
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            //解锁
            redisUtil.unlock("realtimeBasMap_" + lev);
        }
        return true;
        return lists;
    }
}