MainTimer.java
2.4 KB
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
package com.myproject.webapp.controller.webService;
import com.myproject.bean.qisda.InquiryShelfBean;
import com.myproject.bean.update.DataLog;
import com.myproject.dao.mongo.IDataLogDao;
import com.myproject.webapp.controller.qisda.util.OutInfoCache;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/**
* Created by sunke on 2020/3/5.
* 主定时器
*/
@Service
public class MainTimer {
protected final transient Logger log = LogManager.getLogger(getClass());
ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(1);
@Autowired
private OutInfoCache outInfoCache;
@Autowired
private QisdaCache qisdaCache;
@Autowired
private IDataLogDao dataLogDao;
@Autowired
private ITaskService taskService;
public void init(){
String currentorderHSerial = qisdaCache.getCurrentOrderHSerial();
log.info("加载未完成的任务,当前执行需求单["+currentorderHSerial+"]");
List<DataLog> unExecuteTasks = dataLogDao.findUnFinishedTasks(currentorderHSerial);
for (DataLog unExecuteTask : unExecuteTasks) {
if(unExecuteTask.isExecuting() || unExecuteTask.isWait()){
taskService.addTaskToExecute(unExecuteTask);
}else{
taskService.updateFinishedTask(unExecuteTask);
}
}
log.info("加载DN单绑定信息和出库料架信息");
qisdaCache.initRfidDnMap();
InquiryShelfBean.initShelfMap();
QisdaCache.initApiRequestMap();
outInfoCache.loadUnEndOutInfos();
log.info("主定时器开启,60秒后开始执行, 每10s执行一次");
//1 分钟之后执行,每秒钟执行一次
scheduledThreadPool.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
timerTask();
}
}, 60, 10, TimeUnit.SECONDS);
}
private void timerTask(){
try{
QisdaCache.runTimer();
outInfoCache.runTimer();
}catch (Exception e){
log.error("定时器执行出错",e);
}finally {
}
}
}