DataCacheScheduled.java
2.55 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
package com.viontech.scheduled;
import com.viontech.service.TrafficEventService;
import com.viontech.vo.traffic.LaneModel;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.boot.CommandLineRunner;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@Slf4j
@Component
public class DataCacheScheduled implements CommandLineRunner {
//key:apeid,value:TollgateId
public static Map<String, String> deviceTollgateMap = new ConcurrentHashMap<>();
@Resource
private TrafficEventService trafficEventService;
@Scheduled(cron = "0 0 2 * * ?")
public void flushCache() {
updateDeviceTollgateCache();
}
@Override
public void run(String... args) throws Exception {
updateDeviceTollgateCache();
}
private void updateDeviceTollgateCache() {
log.info("开始更新设备与卡口关系缓存数据");
//查询
LaneModel laneQry = new LaneModel();
List<LaneModel> laneModels = trafficEventService.selectLaneDatas(laneQry);
if (!CollectionUtils.isEmpty(laneModels)) {
for (LaneModel laneModel : laneModels) {
try {
deviceTollgateMap.put(laneModel.getApeID(), laneModel.getTollgateID());
} catch (Exception e) {
log.error("deviceTollgateMap.put Exception", e);
}
}
}
/*int offset = 0;
int limit = 50;
int selectSize = 0;
int num = 0;
do {
LaneModel laneQry = new LaneModel();
laneQry.setOffset(offset);
laneQry.setLimit(limit);
List<LaneModel> laneModels = trafficEventService.selectLaneDatas(laneQry);
selectSize = laneModels.size();
num = num + 1;
offset = limit*num;
if (!CollectionUtils.isEmpty(laneModels)) {
for (LaneModel laneModel : laneModels) {
try {
deviceTollgateMap.put(laneModel.getApeID(), laneModel.getTollgateID());
} catch (Exception e) {
log.error("deviceTollgateMap.put Exception", e);
}
}
}
} while (selectSize >= limit);*/
log.info("结束更新设备与卡口关系缓存,共更新{}条", deviceTollgateMap.size());
}
}