luxiaotao1123
2024-09-09 ea7e27ff897da58be02c14a6f18adbf387a56ee1
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
package com.zy.acs.gateway.process;
 
import com.zy.acs.common.constant.RedisConstant;
import com.zy.acs.gateway.Executors;
import com.zy.acs.gateway.cache.ChannelCache;
import com.zy.acs.gateway.constant.AgvConstant;
import com.zy.acs.gateway.constant.ProtocolType;
import com.zy.acs.gateway.domain.AgvPackage;
import com.zy.acs.gateway.job.DispatcherPublisher;
import com.zy.acs.gateway.utils.ProtocolUtils;
import com.zy.acs.common.utils.RedisSupport;
import com.zy.acs.rpc.gateway.control.AgvCmdFeignApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
 
/**
 * Created by vincent on 2023/3/17
 */
@Component
public class ActivateLauncher {
 
    private final RedisSupport redis = RedisSupport.defaultRedisSupport;
 
    @Autowired
    private AgvCmdFeignApi agvCmdFeignApi;
    @Autowired
    private Executors executors;
    @Autowired
    private DispatcherPublisher publisher;
 
    {
 
        Timer timer = new Timer();
 
        timer.schedule( new TimerTask() {
 
            @Override
            public void run() {
 
 
                String[] uniqueNoList =
                        redis.getKeys("*" + RedisConstant.AGV_ONLINE_FLAG + "*");
 
                for (String uniqueno : uniqueNoList) {
 
 
                    uniqueno = uniqueno.substring(uniqueno.lastIndexOf(".") + 1);
 
                    AgvPackage agvPackage
                            = ProtocolUtils.installDownProtocol(uniqueno, ProtocolType.HEARTBEAT_COMMAND);
 
 
                    if (null != publisher) {
 
 
                        publisher.publish(agvPackage);
                    }
 
 
                }
 
            }
 
        }, 0, 5000);
 
    }
 
    @PostConstruct
    public void launch() {
 
//        List<String> allAgv = agvFeignApi.findAllAgv();
        List<String> allAgv = new ArrayList<String>() {{
            add("1");
        }};
 
        executors.getInstance().execute(
                () -> {
 
            try {
 
 
                Thread.sleep(5000);
            } catch (Exception ignore) {}
 
            for (String uniqueNo : allAgv) {
 
                AgvPackage agvPackage = null;
 
                if (ChannelCache.hasChannel(uniqueNo)) {
 
                    agvPackage = ProtocolUtils.installDownProtocol(uniqueNo, ProtocolType.ACTIVATION_COMMAND);
 
 
 
                }
 
 
                if (null !=  agvPackage) {
 
                    publisher.publish(agvPackage);
                }
 
            }
 
 
        });
 
 
 
    }
 
 
}