#
Junjie
21 小时以前 b63790fa580ea78777f16bff6bc79373d675dd10
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
package com.zy.core.dispatcher;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zy.asrs.entity.DeviceConfig;
import com.zy.asrs.service.DeviceConfigService;
import com.zy.asrs.utils.Utils;
import com.zy.common.model.NavigateNode;
import com.zy.common.model.enums.NavigationMapType;
import com.zy.common.utils.ForkLiftUtils;
import com.zy.common.utils.NavigateUtils;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.SlaveType;
import com.zy.core.model.protocol.ForkLiftProtocol;
import com.zy.core.model.protocol.ForkLiftStaProtocol;
import com.zy.core.model.protocol.ShuttleProtocol;
import com.zy.core.thread.ForkLiftThread;
import com.zy.core.thread.ShuttleThread;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * 提升机调度工具
 */
@Component
public class ForkLiftDispatchUtils {
 
    @Autowired
    private DeviceConfigService deviceConfigService;
    @Autowired
    private NavigateUtils navigateUtils;
 
    /**
     * 获取穿梭车最近且空闲的提升机输送站点
     */
    public ForkLiftStaProtocol getRecentLiftStation(Integer shuttleNo, Integer targetLev) {
        //获取四向穿梭车线程
        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
        if (shuttleThread == null) {
            return null;
        }
        ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
        if (shuttleProtocol == null) {
            return null;
        }
 
        List<DeviceConfig> forkliftList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
                .eq("device_type", String.valueOf(SlaveType.ForkLift)));
 
        //获取小车同一楼层的站点
        ArrayList<ForkLiftStaProtocol> list = new ArrayList<>();
        int lev = Utils.getLev(shuttleProtocol.getCurrentLocNo());//小车楼层
        for (DeviceConfig device : forkliftList) {
            ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, device.getDeviceNo());
            if (forkLiftThread == null) {
                continue;
            }
            ForkLiftProtocol forkLiftProtocol = forkLiftThread.getStatus();
            if (forkLiftProtocol == null) {
                continue;
            }
            if (forkLiftProtocol.getErrorCode() > 0) {
                continue;
            }
 
            ForkLiftStaProtocol forkLiftStaProtocol = ForkLiftUtils.getLiftStaByLev(device.getDeviceNo(), lev);
            if (forkLiftStaProtocol == null) {
                continue;
            }
 
            //判断当前层是否无托盘
            if (forkLiftStaProtocol.getHasTray()) {
                continue;
            }
 
            if (forkLiftStaProtocol.getHasCar()) {
                continue;
            }
 
            //判断目标楼层站点是否无托盘
            ForkLiftStaProtocol targetLiftStaProtocol = ForkLiftUtils.getLiftStaByLev(device.getDeviceNo(), targetLev);
            if (targetLiftStaProtocol == null) {
                continue;
            }
 
            if (targetLiftStaProtocol.getHasTray()) {
                continue;//有托盘跳过
            }
 
            if (targetLiftStaProtocol.getHasCar()) {
                continue;
            }
 
            list.add(forkLiftStaProtocol);
        }
 
        if (list.isEmpty()) {
            return null;
        }
 
        String currentLocNo = shuttleProtocol.getCurrentLocNo();//小车位置
        Integer recentAllDistance = 9999999;
        ForkLiftStaProtocol recentSta = null;//最近站点
        //搜索距离小车最近的站点
        for (ForkLiftStaProtocol forkLiftStaProtocol : list) {
            Integer staNo = forkLiftStaProtocol.getStaNo();//站点号
            String locNo = forkLiftStaProtocol.getLocNo();//站点库位号
 
            //当前穿梭车线程到目标地点距离
            List<NavigateNode> currentShuttlePath = navigateUtils.calc(currentLocNo, locNo, NavigationMapType.getMapTypes(NavigationMapType.NORMAL), Utils.getShuttlePoints(shuttleNo, Utils.getLev(currentLocNo)), null);//使用正常通道地图
            if (currentShuttlePath == null) {
                continue;
            }
            Integer currentAllDistance = navigateUtils.getOriginPathAllDistance(currentShuttlePath);//计算当前路径行走总距离
            if (currentAllDistance < recentAllDistance) {
                //如果当前楼层的车路径更小,则更新最近站点
                recentSta = forkLiftStaProtocol;
                recentAllDistance = currentAllDistance;
            }
        }
 
        return recentSta;
    }
 
}