MtPlanCenter.java
2.44 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.maintenance_plan;
import com.bsth.data.schedule.DayOfSchedule;
import com.bsth.entity.realcontrol.ScheduleRealInfo;
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;
/**
* 维修保养计划推送
* @author Hill
*/
@Component
public class MtPlanCenter implements ApplicationContextAware {
private static Set<MaintenancePlan> data;
private static SendUtils sendUtils;
@Autowired
private static DayOfSchedule dayOfSchedule;
/**
* 车辆自编号 和 最新一条数据对照
*/
private static Map<String, MaintenancePlan> safeMap;
private static Logger logger = LoggerFactory.getLogger(MtPlanCenter.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(MaintenancePlan maintenancePlan){
if(!data.contains(maintenancePlan)){
ScheduleRealInfo scheduleRealInfo = dayOfSchedule.executeCurr(maintenancePlan.getZbh());
if (scheduleRealInfo != null) {
maintenancePlan.setLine(scheduleRealInfo.getXlBm());
maintenancePlan.setLineName(scheduleRealInfo.getXlName());
}
//通知客户端
sendUtils.sendMaintenancePlan(maintenancePlan);
data.add(maintenancePlan);
safeMap.put(maintenancePlan.getZbh(), maintenancePlan);
}
}
public static Set<MaintenancePlan> 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);
dayOfSchedule = applicationContext.getBean(DayOfSchedule.class);
}
}