ScheduleRefreshThread.java
2.91 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
87
88
89
90
91
92
93
94
95
96
97
package com.bsth.data.schedule.thread;
import com.bsth.data.BasicData;
import com.bsth.data.LineConfigData;
import com.bsth.data.directive.DayOfDirectives;
import com.bsth.data.gpsdata_v2.cache.GpsCacheData;
import com.bsth.data.pilot80.PilotReport;
import com.bsth.data.schedule.DayOfSchedule;
import com.bsth.data.schedule.f_a_l.FirstAndLastHandler;
import com.bsth.entity.realcontrol.LineConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Collection;
import java.util.Set;
/**
*
* @ClassName: ScheduleRefreshThread
* @Description: TODO(班次刷新线程,用于在营运开始时间切换到当日排班)
* @author PanZhao
* @date 2016年8月17日 下午1:23:34
*
*/
@Component
public class ScheduleRefreshThread extends Thread{
@Autowired
DayOfSchedule dayOfSchedule;
@Autowired
LineConfigData lineConfs;
@Autowired
DayOfDirectives dayOfDirectives;
@Autowired
PilotReport pilotReport;
Logger logger = LoggerFactory.getLogger(ScheduleRefreshThread.class);
@Override
public void run() {
try {
Collection<LineConfig> confs = lineConfs.getAll();
String currSchDate, oldSchDate;
String lineCode = null;
for(LineConfig conf : confs){
try{
lineCode = conf.getLine().getLineCode();
oldSchDate = dayOfSchedule.getCurrSchDate().get(lineCode);
currSchDate = dayOfSchedule.calcSchDate(lineCode);
if(oldSchDate == null || !oldSchDate.equals(currSchDate)){
//logger.info(lineCode + "开始翻班, " + currSchDate);
try{
//清除指令数据
Set<String> cars = dayOfSchedule.findCarByLineCode(lineCode);
for(String car : cars){
dayOfDirectives.clear(BasicData.deviceId2NbbmMap.inverse().get(car));
GpsCacheData.remove(car);
}
//清除驾驶员上报数据
pilotReport.clear(lineCode);
}catch (Exception e){
logger.error("清理 60 和 80出现问题", e);
}
//重载排班数据
dayOfSchedule.reloadSch(lineCode, currSchDate, false);
logger.info(lineCode + "翻班完成, " + currSchDate + " -班次数量:" + dayOfSchedule.findByLineCode(lineCode).size());
//校验一下数据库和缓存的数据
int dbCount = dayOfSchedule.dbCount(lineCode, currSchDate);
logger.info(lineCode + " 数据库数量:" + dbCount);
if(dbCount != dayOfSchedule.findByLineCode(lineCode).size()){
logger.error("异常异常异常,,数据库和缓存数量不一致," + lineCode);
}
}
}catch (Exception e){
logger.error("班次更新失败!! -" + lineCode, e);
}
}
//首末班入库(给网关用的数据)
FirstAndLastHandler.saveAll();
} catch (Exception e) {
logger.error("", e);
}
}
}