自动化立体仓库 - WCS系统
#
Junjie
2025-04-10 1d624dfdb040825ffecba6c792c480be662b2dbc
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
package com.zy.common.utils;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.SpringUtils;
import com.zy.asrs.utils.Utils;
import com.zy.common.model.NavigateNode;
import com.zy.common.model.enums.NavigationMapType;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.SlaveType;
import com.zy.core.model.ForkLiftSlave;
import com.zy.core.model.LiftSlave;
import com.zy.core.model.protocol.ForkLiftStaProtocol;
import com.zy.core.model.protocol.LiftProtocol;
import com.zy.core.model.protocol.LiftStaProtocol;
import com.zy.core.model.protocol.ShuttleProtocol;
import com.zy.core.properties.SlaveProperties;
import com.zy.core.thread.ForkLiftThread;
import com.zy.core.thread.LiftThread;
import com.zy.core.thread.ShuttleThread;
import com.zy.core.thread.impl.NyLiftThread;
import com.zy.system.entity.Config;
import com.zy.system.service.ConfigService;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
 
/**
 * 提升机工具类
 */
public class LiftUtils {
 
    //获取提升机站点
    public static LiftStaProtocol getLiftStaByStaNo(Integer staNo) {
        SlaveProperties slaveProperties = SpringUtils.getBean(SlaveProperties.class);
        for (LiftSlave liftSlave : slaveProperties.getLift()) {
            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, liftSlave.getId());
            if (liftThread == null) {
                return null;
            }
 
            for (LiftStaProtocol liftStaProtocol : liftThread.getLiftStaProtocols()) {
                if (liftStaProtocol.getStaNo().equals(staNo)) {
                    return liftStaProtocol;
                }
            }
        }
 
        return null;
    }
 
    //获取提升机站点
    public static LiftStaProtocol getLiftStaByLev(Integer liftNo, Integer lev) {
        LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, liftNo);
        if (liftThread == null) {
            return null;
        }
 
        for (LiftStaProtocol liftStaProtocol : liftThread.getLiftStaProtocols()) {
            if (liftStaProtocol.getLev().equals(lev)) {
                return liftStaProtocol;
            }
        }
 
        return null;
    }
 
    //获取提升机输送站及其前一站节点
    public static List<NavigateNode> getLiftStaNodes(Integer staNo) {
        List<NavigateNode> targetNodes = new ArrayList<>();
        //获取目标站
        LiftStaProtocol targetLiftSta = LiftUtils.getLiftStaByStaNo(staNo);
        if (targetLiftSta == null) {
            return null;//找不到站点
        }
        NavigateNode targetNode = NavigatePositionConvert.locNoToNode(targetLiftSta.getLocNo());//目标节点
        String targetLastLocNo = Utils.getLocNo(Utils.getRow(targetLiftSta.getLocNo()) - 1, Utils.getBay(targetLiftSta.getLocNo()), Utils.getLev(targetLiftSta.getLocNo()));//目标节点前一站
        NavigateNode targetLastNode = NavigatePositionConvert.locNoToNode(targetLastLocNo);//目标节点前一站
        targetNodes.add(targetNode);
        targetNodes.add(targetLastNode);
 
        return targetNodes;
    }
 
    //通过输送线站号获取对应提升机号
    public static Integer getConveyorBindLiftNo(Integer staNo) {
        ConfigService configService = SpringUtils.getBean(ConfigService.class);
        if (configService == null) {
            return null;
        }
 
        Config conveyorLiftBindConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "conveyorLiftBind"));
        if(conveyorLiftBindConfig == null) {
            return null;
        }
 
        List<JSONObject> list = JSON.parseArray(conveyorLiftBindConfig.getValue(), JSONObject.class);
        if (list.isEmpty()) {
            return null;
        }
 
        for (JSONObject data : list) {
            if(data.getInteger("staNo").equals(staNo)) {
                return data.getInteger("liftNo");
            }
        }
 
        return null;
    }
 
    //请求上级系统,是否允许出库
    //查询是否有出库权限
    public static boolean queryOutMission(Integer staNo) {
        ConfigService configService = SpringUtils.getBean(ConfigService.class);
        if (configService == null) {
            return false;
        }
 
        Config queryOutMissionPathEnableConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "queryOutMissionPathEnable"));
        if (queryOutMissionPathEnableConfig != null) {
            String queryOutMissionPathEnable = queryOutMissionPathEnableConfig.getValue();
            if (!queryOutMissionPathEnable.equals("Y")) {
                return true;//关闭查询出库权限功能
            }
        }
 
        Config superSystemUriConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "superSystemUri"));
        if (superSystemUriConfig == null) {
            return false;
        }
        String superSystemUri = superSystemUriConfig.getValue();
 
        Config queryOutMissionPathConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "queryOutMissionPath"));
        if (queryOutMissionPathConfig == null) {
            return false;
        }
        String missionPath = queryOutMissionPathConfig.getValue();
 
        try {
            HashMap<String, Object> data = new HashMap<>();
            data.put("staNo", staNo);
 
            String response = new HttpHandler.Builder()
                    .setUri(superSystemUri)
                    .setPath(missionPath)
                    .setJson(JSON.toJSONString(data))
                    .build()
                    .doPost();
            if (response.equals("ok")) {
                return true;//有出库权限
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return false;
    }
 
    //请求上级系统,是否允许入库
    //查询是否有入库权限
    public static boolean queryInMission(Integer sourceStaNo, Integer liftNo, String superTaskNo) {
        ConfigService configService = SpringUtils.getBean(ConfigService.class);
        if (configService == null) {
            return false;
        }
 
        Config queryInMissionPathEnableConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "queryInMissionPathEnable"));
        if (queryInMissionPathEnableConfig != null) {
            String queryInMissionPathEnable = queryInMissionPathEnableConfig.getValue();
            if (!queryInMissionPathEnable.equals("Y")) {
                return true;//关闭查询入库权限功能
            }
        }
 
        Config superSystemUriConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "superSystemUri"));
        if (superSystemUriConfig == null) {
            return false;
        }
        String superSystemUri = superSystemUriConfig.getValue();
 
        Config queryInMissionPathConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "queryInMissionPath"));
        if (queryInMissionPathConfig == null) {
            return false;
        }
        String missionPath = queryInMissionPathConfig.getValue();
 
        try {
            HashMap<String, Object> data = new HashMap<>();
            data.put("staNo", sourceStaNo);
            data.put("liftNo", liftNo);
            data.put("superTaskNo", superTaskNo);
 
            String response = new HttpHandler.Builder()
                    .setUri(superSystemUri)
                    .setPath(missionPath)
                    .setJson(JSON.toJSONString(data))
                    .build()
                    .doPost();
            if (response.equals("ok")) {
                return true;//有入库权限
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
 
    /**
     * 获取坐标最近且正常的提升机
     */
    public static LiftThread getRecentLift(String locNo) {
        SlaveProperties slaveProperties = SpringUtils.getBean(SlaveProperties.class);
        NavigateUtils navigateUtils = SpringUtils.getBean(NavigateUtils.class);
 
        String currentLocNo = locNo;
        Integer recentAllDistance = 9999999;
        LiftThread recentLift = null;//最近站点
        for (LiftSlave slave : slaveProperties.getLift()) {
            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, slave.getId());
            if (liftThread == null) {
                continue;
            }
            LiftProtocol liftProtocol = liftThread.getStatus();
            if (liftProtocol == null) {
                continue;
            }
 
            if (!liftThread.isDeviceIdle()) {
                continue;
            }
 
            //搜索距离小车最近的提升机
            String liftLocNo = liftThread.getLiftLocNo(Utils.getLev(locNo));
            if (locNo.equals(liftLocNo)) {
                return liftThread;
            }
 
            //目标地点距离
            List<NavigateNode> currentShuttlePath = navigateUtils.calc(currentLocNo, liftLocNo, NavigationMapType.NORMAL.id, null, null);//使用正常通道地图
            if (currentShuttlePath == null) {
                continue;
            }
            Integer currentAllDistance = navigateUtils.getOriginPathAllDistance(currentShuttlePath);//计算当前路径行走总距离
            if (currentAllDistance < recentAllDistance) {
                //如果当前楼层的路径更小,则更新最近站点
                recentLift = liftThread;
                recentAllDistance = currentAllDistance;
            }
        }
 
        return recentLift;
    }
 
}