DirectivesPstThread.java
1.96 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
package com.bsth.data.directive;
import com.bsth.data.schedule.DayOfSchedule;
import com.bsth.entity.directive.D60;
import com.bsth.entity.directive.D64;
import com.bsth.entity.directive.Directive;
import com.bsth.entity.realcontrol.ScheduleRealInfo;
import com.bsth.repository.directive.D60Repository;
import com.bsth.repository.directive.D64Repository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.LinkedList;
/**
* 指令持久化线程
* Created by panzhao on 2017/3/6.
*/
@Component
public class DirectivesPstThread extends Thread {
Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
D60Repository d60Repository;
@Autowired
D64Repository d64Repository;
@Autowired
DayOfSchedule dayOfSchedule;
@Override
public void run() {
LinkedList<Directive> list = DayOfDirectives.pstDirectives;
Directive directive;
for (int i = 0; i < 1000; i++) {
try {
directive = list.poll();
if (directive instanceof D60) {
D60 d60 = (D60) directive;
if(d60.isDispatch()){
ScheduleRealInfo sch = d60.getSch();
//如果关联的班次已经不存在了,放弃入库
if(sch.isDeleted()){
logger.warn("save 指令,发现 deleted=true 的班次,id=" + sch.getId());
continue;
}
}
d60Repository.save(d60);
}
if (directive instanceof D64) {
d64Repository.save((D64) directive);
}
} catch (Exception e) {
logger.error("", e);
}
}
}
}