SendUtils.java
3.1 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package com.bsth.websocket.handler;
import com.bsth.data.abnormal.entity.AbnormalEntity;
import com.bsth.data.abnormal.rate_chart.RateNCalculator;
import com.bsth.data.schedule.dto.ScheduleInOut;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@Component
public class SendUtils{
@Autowired
private RealInoutSocketHandler socketHandler;
private static Logger logger = LoggerFactory.getLogger(SendUtils.class);
private static SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
public void sendCarIn(String nbbm, String berthName, Long t){
Map<String, Object> map = new HashMap<>();
map.put("fn", "carIn");
map.put("nbbm", nbbm);
map.put("berthName", berthName);
map.put("dataStr", sdf.format(new Date(t)));
ObjectMapper mapper = new ObjectMapper();
try {
socketHandler.sendMessage(mapper.writeValueAsString(map));
} catch (Exception e) {
logger.error("", e);
}
}
public void sendCarOut(String nbbm, Long t){
Map<String, Object> map = new HashMap<>();
map.put("fn", "carOut");
map.put("nbbm", nbbm);
map.put("dataStr", sdf.format(new Date(t)));
ObjectMapper mapper = new ObjectMapper();
try {
socketHandler.sendMessage(mapper.writeValueAsString(map));
} catch (Exception e) {
logger.error("", e);
}
}
/**
* 异常-应到未到
*/
public void abnormal_ydwd(AbnormalEntity ae){
Map<String, Object> map = new HashMap<>();
map.put("fn", "abnormal_ydwd");
map.put("entity", ae);
ObjectMapper mapper = new ObjectMapper();
try {
socketHandler.sendMessage(mapper.writeValueAsString(map));
} catch (Exception e) {
logger.error("", e);
}
}
/**
* 班次出场
* @param sio
*/
public void scheduleOut(ScheduleInOut sio, AbnormalEntity ae) {
Map<String, Object> map = new HashMap<>();
map.put("fn", "abnormal_out");
map.put("sio", sio);
if(null != ae)
map.put("ae", ae);
ObjectMapper mapper = new ObjectMapper();
try {
socketHandler.sendMessage(mapper.writeValueAsString(map));
} catch (Exception e) {
logger.error("", e);
}
}
/**
* 驾驶员报到
* @param sio
*/
public void scheduleAttendace(ScheduleInOut sio, AbnormalEntity ae) {
Map<String, Object> map = new HashMap<>();
map.put("fn", "abnormal_att");
map.put("sio", sio);
if(null != ae)
map.put("ae", ae);
ObjectMapper mapper = new ObjectMapper();
try {
socketHandler.sendMessage(mapper.writeValueAsString(map));
} catch (Exception e) {
logger.error("", e);
}
}
/**
* 全量推统计率值
*/
public void sendAllRates(){
Map<String, Object> map = new HashMap<>();
map.put("fn", "all_rate_val");
map.put("cczd", RateNCalculator.cczdRateNo);
map.put("bdzd", RateNCalculator.bdzdRateNo);
ObjectMapper mapper = new ObjectMapper();
try {
socketHandler.sendMessage(mapper.writeValueAsString(map));
} catch (Exception e) {
logger.error("", e);
}
}
}