自动化立体仓库 - WCS系统
Junjie
2024-12-21 42f3380a98fff04674cf4ef95ea5e99f5c54f1fd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package com.zy.common.utils;
 
import com.alibaba.fastjson.JSON;
import com.core.common.SpringUtils;
import com.zy.asrs.entity.BasMap;
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.enums.RedisKeyType;
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);
        NavigateMapData navigateMapData = SpringUtils.getBean(NavigateMapData.class);
        try {
            if (nodes.isEmpty()) {
                return true;
            }
 
            Object o = redisUtil.get(RedisKeyType.MAP.key + 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;//路径存在小车,禁止锁定
                    }
                }
            }
 
            //尝试锁定/解锁路径
            List<List<MapNode>> realMap = navigateMapData.getJsonData(nodes.get(0).getZ(), -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(RedisKeyType.MAP.key + lev, JSON.toJSONString(basMap));
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
 
}