#
Junjie
7 天以前 5cef428c0019b6455e35807a617f648840e9c65d
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
package com.zy.asrs.wcs.core.timer;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zy.asrs.wcs.core.action.LiftAction;
import com.zy.asrs.wcs.core.action.ShuttleAction;
import com.zy.asrs.wcs.core.model.enums.DeviceCtgType;
import com.zy.asrs.wcs.core.utils.RedisUtil;
import com.zy.asrs.wcs.rcs.constant.DeviceRedisConstant;
import com.zy.asrs.wcs.rcs.entity.Device;
import com.zy.asrs.wcs.rcs.service.DeviceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.util.List;
 
@Slf4j
@Component
public class DeviceTimer {
 
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private DeviceService deviceService;
    @Autowired
    private ShuttleAction shuttleAction;
    @Autowired
    private LiftAction liftAction;
 
    @Scheduled(cron = "0/1 * * * * ? ")
    public synchronized void executeShuttle() {
        List<Device> list = deviceService.list(new LambdaQueryWrapper<Device>()
                .eq(Device::getStatus, 1)
                .eq(Device::getDeviceType, DeviceCtgType.SHUTTLE.val()));
        for (Device device : list) {
            //小车空闲且有跑库程序
            shuttleAction.moveLoc(device);
 
            Object object = redisUtil.get(DeviceRedisConstant.SHUTTLE_FLAG + device.getDeviceNo());
            if (object == null) {
                continue;
            }
 
            Integer taskNo = Integer.valueOf(String.valueOf(object));
            if (taskNo != 0) {
                //存在任务需要执行
                boolean result = shuttleAction.executeWork(device, taskNo);
            }
        }
    }
 
    @Scheduled(cron = "0/1 * * * * ? ")
    public synchronized void executeLift() {
        List<Device> list = deviceService.list(new LambdaQueryWrapper<Device>()
                .eq(Device::getStatus, 1)
                .eq(Device::getDeviceType, DeviceCtgType.LIFT.val()));
        for (Device device : list) {
            Object object = redisUtil.get(DeviceRedisConstant.LIFT_FLAG + device.getDeviceNo());
            if (object == null) {
                continue;
            }
 
            Integer taskNo = Integer.valueOf(String.valueOf(object));
            if (taskNo != 0) {
                //存在任务需要执行
                boolean result = liftAction.executeWork(device, taskNo);
            }
        }
    }
 
    @Scheduled(cron = "0/1 * * * * ? ")
    public synchronized void executeConveyor() {
 
    }
 
}