CZT
2023-09-14 db72a27d10fdc4de0926fb8c7cc411ec0d4ea51b
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
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 "子任务执行完成";
    }
 
}