LaneSyncScheduled.java
3.56 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
package com.viontech.scheduled;
import com.viontech.constant.Gb1400Constants;
import com.viontech.constant.RedisConstants;
import com.viontech.constant.SystemConstants;
import com.viontech.handler.TrafficDataConvertHandler;
import com.viontech.service.Gb1400Service;
import com.viontech.service.TrafficEventService;
import com.viontech.utils.DateUtil;
import com.viontech.utils.JsonMessage;
import com.viontech.vo.gb1400.SubscribeNotificationsObj;
import com.viontech.vo.traffic.LaneModel;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
/**
* @author msl
* @date 2022/5/7
*/
@Slf4j
@Component
public class LaneSyncScheduled {
@Resource
private TrafficEventService trafficEventService;
@Resource
private Gb1400Service gb1400Service;
@Autowired
private RedisTemplate redisTemplate;
@Autowired
private TrafficDataConvertHandler trafficDataConvertHandler;
@Scheduled(cron = "0 */2 * * * ?")
public void handleIllegal() {
log.info("开始处理车道数据");
if (!Gb1400Constants.LinkStatus) {
return;
}
Object o = redisTemplate.opsForValue().get(RedisConstants.FANXING_TO_GB1400_LANE_LASTTIME);
//上次对接到的车道记录时间
String lastTimeUtc = "";
if (o == null) {
//初次查询一小时前的数据,-12,-8:转UTC时间,总-20
lastTimeUtc = DateUtil.formatDate(DateUtil.addHours(new Date(), -20), DateUtil.TIMESTAMP_FORMAT);
} else {
lastTimeUtc = (String) o;
}
String currentTimeUtc = DateUtil.formatDate(DateUtil.addHours(new Date(), -8), DateUtil.TIMESTAMP_FORMAT);
if (StringUtils.isBlank(lastTimeUtc) || StringUtils.isBlank(currentTimeUtc)) {
log.warn("lastTimeUtc or currentTimeUtc isBlank");
return;
}
//查询
LaneModel laneQry = new LaneModel();
laneQry.setModifyTime_gte(lastTimeUtc);
laneQry.setModifyTime_lte(currentTimeUtc);
laneQry.setOffset(0);
laneQry.setLimit(20);
List<LaneModel> laneModels = trafficEventService.selectLaneDatas(laneQry);
log.info("查询范围(lastTimeUtc,currentTimeUtc]=({},{}],本批次车道待同步数据总{}条。", lastTimeUtc, currentTimeUtc, laneModels.size());
if (!CollectionUtils.isEmpty(laneModels)) {
//List<LaneModel> 转 SubscribeNotificationsObj
SubscribeNotificationsObj subscribeNotificationsObj = trafficDataConvertHandler.laneToSubscribeNotifications(laneModels);
//将车道数据同步gb1400
if (subscribeNotificationsObj != null) {
JsonMessage resultVo = gb1400Service.subscribeNotifications(subscribeNotificationsObj);
if (SystemConstants.APP_CODE_SUCCESS == resultVo.getCode()) {
redisTemplate.opsForValue().set(RedisConstants.FANXING_TO_GB1400_LANE_LASTTIME, DateUtil.formatDate(laneModels.get(laneModels.size() - 1).getModifyTime(), DateUtil.TIMESTAMP_FORMAT));
}
} else {
log.error("trafficDataConvertHandler.laneToSubscribeNotifications is null");
}
}
log.info("结束处理车道数据");
}
}