*
lsh
2025-10-24 209626ba2b4797f7d1c003a2876026ffcd39928a
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
package com.zy.core;
 
import com.zy.asrs.service.impl.MainServiceImpl;
import com.zy.core.properties.SystemProperties;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import javax.annotation.PreDestroy;
 
/**
 * WCS主流程
 * Created by vincent on 2020/8/6
 */
@Data
@Slf4j
@Component
public class MainProcess {
 
    @Autowired
    private MainServiceImpl mainService;
    // 所属线程
    private Thread thread;
    private Thread licenseThread;
    // 频率
    private int[] autoZ = new int[]{0,0,0,0,0,0,0};
 
    /**
     * =====>>  开始工作
     */
    public void start(){
        thread = new Thread(this::mainThread);
        thread.start();
        licenseThread = new Thread(this::licenseThreadRun);
        licenseThread.start();
    }
 
    private void mainThread(){
        try{
            Thread.sleep(200);
            log.info("++++++++ 开始验证许可证 ++++++++");
            if (!mainService.licenseVerify()){
                SystemProperties.WCS_RUNNING_STATUS.set(Boolean.FALSE);
                log.info("++++++++ 验证许可证失败 ++++++++");
            } else {
                SystemProperties.WCS_RUNNING_STATUS.set(Boolean.TRUE);
                log.info("++++++++ 验证许可证成功 ++++++++");
            }
        } catch (Exception e) {}
        while (!Thread.currentThread().isInterrupted()) {
            try {
                // 间隔
                Thread.sleep(200);
 
                // 系统运行状态判断
                if (!SystemProperties.WCS_RUNNING_STATUS.get()) {
                    continue;
                }
 
                //更新位置信息
                mainService.updateStePosition();
                // 任务下发
                mainService.DevpTaskNoRun();
                // 任务完成
                mainService.rgvCompleteWrkMastSta(autoZ);
                // 任务取消
                mainService.rgvCancelWrkMastSta();
 
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
 
    private void licenseThreadRun(){
        int i = 0;
        while (true) {
            try{
                Thread.sleep(60*60*1000L);
 
                // 系统运行状态判断
                if (!SystemProperties.WCS_RUNNING_STATUS.get()) {
                    continue;
                }
 
                log.info("++++++++ 开始验证许可证 ++++++++");
                if (!mainService.licenseVerify()){
                    if (i>6){
                        SystemProperties.WCS_RUNNING_STATUS.set(Boolean.FALSE);
                        log.info("++++++++ 验证许可证失败 ++++++++");
                        i = 0;
                    } else {
                        i++;
                    }
                } else {
//                    SystemProperties.WCS_RUNNING_STATUS.set(Boolean.TRUE);
                    log.info("++++++++ 验证许可证成功 ++++++++");
                }
            } catch (Exception e) {}
        }
    }
 
    @PreDestroy
    public void shutDown(){
        if (thread != null) thread.interrupt();
        if (licenseThread != null) licenseThread.interrupt();
    }
 
}