package com.ld.igds.protocol.zldz.task;
|
|
import com.ld.igds.protocol.zldz.command.BaseRemoteImpl;
|
import com.ld.igds.util.RedisUtil;
|
import lombok.extern.slf4j.Slf4j;
|
|
import java.util.concurrent.Callable;
|
|
/**
|
* 粮情子任务,粮情子任务,忽略8815的回复和8817的回复,直接等结果包的到达,如果结果包没有到达,就重复发送粮情请求
|
*
|
* @author andy.jia
|
*/
|
@Slf4j
|
public class ReSendGrainTask extends BaseRemoteImpl implements Callable<String> {
|
|
private CommandTask commandData;
|
|
private RedisUtil redisUtil;
|
|
private String redisKey;
|
|
public RedisUtil getRedisUtil() {
|
return redisUtil;
|
}
|
|
public void setRedisUtil(RedisUtil redisUtil) {
|
this.redisUtil = redisUtil;
|
}
|
|
public String getRedisKey() {
|
return redisKey;
|
}
|
|
public void setRedisKey(String redisKey) {
|
this.redisKey = redisKey;
|
}
|
|
public void setCommandData(CommandTask commandData) {
|
this.commandData = commandData;
|
}
|
|
public CommandTask getCommandData() {
|
return commandData;
|
}
|
|
public ReSendGrainTask() {
|
super();
|
}
|
|
public ReSendGrainTask(CommandTask commandData, RedisUtil redisUtil, String redisKey) {
|
super();
|
this.commandData = commandData;
|
this.redisUtil = redisUtil;
|
this.redisKey = redisKey;
|
}
|
|
@Override
|
public String call() throws Exception {
|
|
String[] attCable = commandData.getCableRule().split("-");
|
int cableZ = Integer.valueOf(attCable[0]);
|
int cableY = Integer.valueOf(attCable[1]);
|
int cableX = Integer.valueOf(attCable[2]);
|
|
int point = cableX * cableY * cableZ;
|
long time = point * 100 + (point / 100) * 500;
|
|
//1,粮情第1次等待时间为采集点个数* 0.1 秒 + 20秒,如果没有正常返回则发送第二次命令。
|
Thread.sleep(time);
|
CommandTask redisData = (CommandTask) redisUtil.get(redisKey);
|
if (null == redisData) {
|
return "命令第1次等待,终端已经正常返回";
|
} else {
|
String msg = commandData.getSerName() + " 第1次补发命令=" + commandData.getCommand();
|
log.info(msg);
|
|
super.send(commandData.getIp(), commandData.getPort(), commandData.getByteCommand());
|
}
|
|
//2
|
Thread.sleep(time);
|
redisData = (CommandTask) redisUtil.get(redisKey);
|
if (null == redisData) {
|
return "命令第2次等等,终端已经正常返回";
|
} else {
|
String msg = commandData.getSerName() + " 第2次补发粮情命令,没有返回,系统断开当前连接。";
|
log.info(msg);
|
|
// ExeOrderService orderService = SpringUtil.getBean(ExeOrderService.class);
|
// orderService.progressError(commandData.getCompanyId(), BizType.GRAIN, commandData.getDepotId(), msg);
|
|
//2021年6月5日 07:30:22 取消超时踢出连接
|
// super.destory(commandData.getIp(), commandData.getPort());
|
}
|
return "子任务执行完成";
|
}
|
|
}
|