SafeDrivCenter.java
2.3 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
package com.bsth.data.safe_driv;
import com.bsth.websocket.handler.SendUtils;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
* 安全驾驶
* Created by panzhao on 2017/4/6.
*/
@Component
public class SafeDrivCenter implements ApplicationContextAware {
private static Set<SafeDriv> data;
@Autowired
SafeDrivDataLoadThread safeDrivDataLoadThread;
static SendUtils sendUtils;
/**
* 车辆自编号 和 最新一条数据对照
*/
private static Map<String, SafeDriv> safeMap;
static Logger logger = LoggerFactory.getLogger(SafeDrivCenter.class);
static {
data = new HashSet<>();
safeMap = new HashMap<>();
}
private static DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.SSS");
public static void put(SafeDriv sd){
sd.setTs(fmt.parseMillis(sd.getStartime()));
if(Integer.parseInt(sd.getYczltype()) == 5 && Integer.parseInt(sd.getJctype()) == 4
|| Integer.parseInt(sd.getYczltype()) == 6 && Integer.parseInt(sd.getJctype()) == 4)
sd.setJctype("B" + sd.getJctype());
else if(sd.getYczltype().indexOf("A") == -1)
sd.setYczltype("A" + sd.getYczltype());
//SafeDriv old = safeMap.get(sd.getClzbh());
if(!data.contains(sd)){
//通知客户端
sendUtils.sendSafeDriv(sd);
data.add(sd);
safeMap.put(sd.getClzbh(), sd);
}
}
public static Set<SafeDriv> findAll(){
return data;
}
public static void clear(){
data = new HashSet<>();
safeMap = new HashMap<>();
logger.info("清除安全驾驶数据...");
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
sendUtils = applicationContext.getBean(SendUtils.class);
}
}