GpsTask.java
1.75 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
package com.trash.quartz.task;
import java.util.Collection;
import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSONObject;
import com.trash.common.core.redis.RedisCache;
import com.trash.common.utils.DateUtils;
import com.trash.gps.domain.GpsOrientation;
import com.trash.gps.mapper.GpsOrientationMapper;
@Component("GpsTask")
public class GpsTask {
@Autowired
private RedisCache redisCache;
@Autowired
private GpsOrientationMapper gpsOrientationMapper;
//30秒执行一次
public void insertGps() {
Collection<String> keys = redisCache.keys("GPS:*");
for (String key : keys) {
for(int i=0;i<10;i++){
JSONObject jsonObject = redisCache.getCacheListRight(key);
if(jsonObject==null){
break;
}
String terminalNumber = key.replaceAll("GPS:","");
GpsOrientation gps = new GpsOrientation();
gps.setTerminalNumber(terminalNumber);
gps.setLongitude(jsonObject.getString("lng"));
gps.setLatitude(jsonObject.getString("lat"));
gps.setCreateTime(DateUtils.parseDate(jsonObject.getString("time").replaceAll("T"," ")));
gps.setYearMonth(jsonObject.getString("time").substring(0,7).replace("-",""));
gps.setCarCode(jsonObject.getString("carCode"));
gpsOrientationMapper.insertGpsOrientation(gps);
}
}
}
public void createGps(){
//获取下个月的年月yyyyMM
String nextMonth = DateUtils.getNextMonth(new Date());
gpsOrientationMapper.createGpsTable(nextMonth);
}
}