#
Junjie
2024-10-17 d835d1b51f832889929cdf69010034a30ef44d02
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
package com.zy.asrs.wcs.asrs.execute;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zy.asrs.framework.exception.CoolException;
import com.zy.asrs.wcs.core.entity.Task;
import com.zy.asrs.wcs.core.utils.RedisUtil;
import com.zy.asrs.wcs.core.utils.ShuttleDispatcher;
import com.zy.asrs.wcs.core.utils.Utils;
import com.zy.asrs.wcs.rcs.cache.SlaveConnection;
import com.zy.asrs.wcs.rcs.entity.Device;
import com.zy.asrs.wcs.rcs.model.enums.SlaveType;
import com.zy.asrs.wcs.rcs.model.protocol.ShuttleProtocol;
import com.zy.asrs.wcs.rcs.thread.ShuttleThread;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
@Component
public class ShuttleExecute extends BaseExecute {
 
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private ShuttleDispatcher shuttleDispatcher;
 
    public boolean execute(Task task, JSONObject data, String redisKey) {
        JSONObject shuttleType = data.getJSONObject("shuttleType");
        String oper = shuttleType.getString("shuttleOper");
        if (oper.equals("searchIdleShuttle")) {
            //搜索空闲车
            ShuttleThread shuttleThread = shuttleDispatcher.searchIdleShuttle(task);
            if (shuttleThread == null) {
                throw new CoolException("穿梭车不存在");
            }
            //存入缓存
            redisSet(redisKey, "shuttleDevice", shuttleThread.getDevice());
            return true;
        } else if (oper.equals("judgeShuttleCurrentTaskLev")) {
            //判断小车是否在任务楼层
            //取出缓存小车
            Object shuttleDeviceObj = redisGet(redisKey, "shuttleDevice");
            if (shuttleDeviceObj == null) {
                throw new CoolException("穿梭车缓存为空");
            }
            Device device = JSON.parseObject(String.valueOf(shuttleDeviceObj), Device.class);
            if (device == null) {
                throw new CoolException("穿梭车设备不存在");
            }
 
            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue());
            if (shuttleThread == null) {
                throw new CoolException("穿梭车不存在");
            }
 
            ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
            if (shuttleProtocol == null) {
                throw new CoolException("穿梭车不存在");
            }
 
            //小车坐标
            String shuttleLocNo = shuttleProtocol.getCurrentLocNo();
            String taskLocNo = null;
            if (task.getTaskSts() < 100) {
                taskLocNo = task.getDestLoc();
            } else if (task.getTaskSts() > 100 && task.getTaskSts() < 200) {
                taskLocNo = task.getOriginLoc();
            }
 
            // 小车和任务楼层一致
            if (Utils.getLev(shuttleLocNo) == Utils.getLev(taskLocNo)) {
                return true;
            } else {
                return false;
            }
        }
 
        return true;
    }
 
}