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 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 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);
|
}
|
|
}
|
|
|
});
|
|
|
|
}
|
|
|
}
|