#
Junjie
2024-04-12 684484fb93775edcfa19cfc7a43d0a748c8362be
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
package com.zy.asrs.wcs.core.map.websocket;
 
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zy.asrs.wcs.core.map.entity.MapWsShuttleVo;
import com.zy.asrs.wcs.core.map.entity.MapWsVo;
import com.zy.asrs.wcs.core.model.enums.DeviceCtgType;
import com.zy.asrs.wcs.core.service.BasShuttleService;
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.service.DeviceService;
import com.zy.asrs.wcs.rcs.service.DeviceTypeService;
import com.zy.asrs.wcs.rcs.thread.ShuttleThread;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * Created by vincent on 4/11/2024
 */
@Component
public class MapRealTimeDataScheduler {
 
    @Autowired
    private DeviceTypeService deviceTypeService;
    @Autowired
    private DeviceService deviceService;
    @Autowired
    private BasShuttleService basShuttleService;
 
    @Scheduled(cron = "0/1 * * * * ? ")
    public void sync() {
        MapWsVo wsVo = new MapWsVo();
        // shuttle
        wsVo.setShuttleVos(syncShuttle());
        MapWebSocket.broadcast(JSON.toJSONString(wsVo));
    }
 
    private List<MapWsShuttleVo> syncShuttle() {
        List<MapWsShuttleVo> shuttleVos = new ArrayList<>();
 
        List<Device> deviceList = deviceService.list(new LambdaQueryWrapper<Device>().eq(Device::getDeviceType, DeviceCtgType.SHUTTLE.val()));
        for (Device device : deviceList) {
//            basShuttleService.
            ShuttleThread thread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue());
            if (null == thread) {
                continue;
            }
            ShuttleProtocol protocol = thread.getStatus();
            if (null == protocol) {
                continue;
            }
 
            MapWsShuttleVo shuttleVo = new MapWsShuttleVo();
//            shuttleVo.setShuttleNo();
 
 
            shuttleVos.add(shuttleVo);
        }
 
        return shuttleVos;
    }
 
}