SendUtils.java
9.01 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
package com.bsth.websocket.handler;
import com.alibaba.fastjson.JSONObject;
import com.bsth.data.BasicData;
import com.bsth.data.LineConfigData;
import com.bsth.data.gpsdata_v2.entity.GpsEntity;
import com.bsth.data.maintenance_plan.MaintenancePlan;
import com.bsth.data.safe_driv.SafeDriv;
import com.bsth.data.schedule.DayOfSchedule;
import com.bsth.entity.directive.D80;
import com.bsth.entity.realcontrol.ScheduleRealInfo;
import com.bsth.message.entity.AlarmVo;
import com.bsth.message.entity.CarErrorStop;
import com.bsth.message.entity.InoutPark;
import com.bsth.websocket.dto.WsScheduleRealInfo;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.StringUtils;
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.*;
@Component
public class SendUtils{
@Autowired
private RealControlSocketHandler socketHandler;
@Autowired
LineConfigData lineConfigData;
private static SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
private static Logger logger = LoggerFactory.getLogger(SendUtils.class);
@Autowired
private DayOfSchedule dayOfSchedule;
/**
* @throws JsonProcessingException
* TODO(推送发车信息)
*/
public void sendFcsj(ScheduleRealInfo sch) {
Map<String, Object> map = new HashMap<>();
map.put("fn", "faChe");
map.put("t", WsScheduleRealInfo.getInstance(sch));
map.put("dataStr", sdf.format(new Date()));
ObjectMapper mapper = new ObjectMapper();
try {
socketHandler.sendMessageToLine(sch.getXlBm(), mapper.writeValueAsString(map));
} catch (Exception e) {
logger.error("", e);
}
}
/**
*
* @Title: sendFcsjArtificial
* @Description: TODO(要求页面刷新班次)
* @throws
*/
public void refreshSch(List<ScheduleRealInfo> list){
if(null == list || list.size() == 0)
return;
Map<String, Object> map = new HashMap<>();
map.put("fn", "refreshSch");
map.put("ts", WsScheduleRealInfo.getMultiInstance(list));
ObjectMapper mapper = new ObjectMapper();
try {
socketHandler.sendMessageToLine(list.get(0).getXlBm(), mapper.writeValueAsString(map));
} catch (Exception e) {
logger.error("", e);
}
}
/**
* @throws JsonProcessingException
* @throws NumberFormatException @Title: sendFcsj @Description:
* TODO(推送到达终点时间) @param @param schedule 班次 @throws
*/
public void sendZdsj(ScheduleRealInfo sch, ScheduleRealInfo nextSch, int finish) {
Map<String, Object> map = new HashMap<>();
map.put("fn", "zhongDian");
map.put("t", WsScheduleRealInfo.getInstance(sch));
map.put("nt", WsScheduleRealInfo.getInstance(nextSch));
map.put("finish", finish);
map.put("dataStr", sdf.format(new Date()));
ObjectMapper mapper = new ObjectMapper();
try {
socketHandler.sendMessageToLine(sch.getXlBm(), mapper.writeValueAsString(map));
} catch (Exception e) {
logger.error("", e);
}
}
/**
* 推送班次信号状态
* @param state
public void sendSignalState(SignalState state){
Map<String, Object> map = new HashMap<>();
map.put("fn", "signal_state");
map.put("data", state);
ObjectMapper mapper = new ObjectMapper();
try {
socketHandler.sendMessageToLine(state.getLineCode(), mapper.writeValueAsString(map));
} catch (Exception e) {
logger.error("", e);
}
}*/
/**
*
* @Title: sendDirectiveToPage
* @Description: TODO(调度指令状态推送)
*/
public void sendDirectiveToPage(ScheduleRealInfo sch) {
Map<String, Object> map = new HashMap<>();
map.put("fn", "directive");
map.put("t", WsScheduleRealInfo.getInstance(sch));;
ObjectMapper mapper = new ObjectMapper();
try {
socketHandler.sendMessageToLine(sch.getXlBm(), mapper.writeValueAsString(map));
} catch (JsonProcessingException e) {
logger.error("", e);
}
}
public void send80ToPage(D80 d80) {
d80.getData().setNbbm(BasicData.deviceId2NbbmMap.get(d80.getDeviceId()));
JSONObject json = JSONObject.parseObject(JSONObject.toJSONString(d80));
json.put("fn", "report80");
socketHandler.sendMessageToLine(d80.getData().getLineId().toString(), json.toJSONString());
}
public void refreshSch(ScheduleRealInfo sch) {
List<ScheduleRealInfo> list = new ArrayList<>();
list.add(sch);
refreshSch(list);
}
public void deviceOffline(GpsEntity gps){
Map<String, Object> map = new HashMap<>();
map.put("fn", "deviceOffline");
map.put("gps", gps);
ObjectMapper mapper = new ObjectMapper();
try {
socketHandler.sendMessageToLine(gps.getLineId().toString(), mapper.writeValueAsString(map));
} catch (JsonProcessingException e) {
logger.error("", e);
}
}
public void sendSafeDriv(SafeDriv sd){
Map<String, Object> map = new HashMap<>();
map.put("fn", "safeDriv");
map.put("t", sd);;
ObjectMapper mapper = new ObjectMapper();
try {
socketHandler.sendMessageToLine(sd.getXlbm(), mapper.writeValueAsString(map));
} catch (JsonProcessingException e) {
logger.error("", e);
}
}
/**
* 通知客户端,开始进行误点调整
* @param sch
*/
public void sendAutoWdtz(ScheduleRealInfo sch, ScheduleRealInfo cancel){
Map<String, Object> map = new HashMap<>();
map.put("fn", "auto_wdtz");
map.put("id", sch.getId());
if(cancel != null)
map.put("cancelId", cancel.getId());
map.put("lineCode", sch.getXlBm());
map.put("minute", sch.getLateMinute());
ObjectMapper mapper = new ObjectMapper();
try {
socketHandler.sendMessageToLine(sch.getXlBm() ,mapper.writeValueAsString(map));
} catch (JsonProcessingException e) {
logger.error("", e);
}
}
/**
* 对所有线调用户进行广播
* @param t
*/
public void sendRadioText(String t, String lineCode){
Map<String, Object> map = new HashMap<>();
map.put("fn", "admin_radio_text");
map.put("t", t);
ObjectMapper mapper = new ObjectMapper();
try {
if(StringUtils.isNotEmpty(lineCode))
socketHandler.sendMessageToLine(lineCode, mapper.writeValueAsString(map));
else
socketHandler.sendMessage(mapper.writeValueAsString(map));
} catch (JsonProcessingException e) {
logger.error("", e);
}
}
/**
* RFID有更新时发送数据至线调页面
* @param sch
*/
public void sendRfid(ScheduleRealInfo sch) {
Map<String, Object> map = new HashMap<>();
map.put("fn", "rfid");
map.put("data", WsScheduleRealInfo.getInstance(sch));
ObjectMapper mapper = new ObjectMapper();
try {
socketHandler.sendMessageToLine(sch.getXlBm(), mapper.writeValueAsString(map));
} catch (JsonProcessingException e) {
logger.error("sendRfid", e);
}
}
/**
* 将应急预案发送至线调页面
*/
public void sendContingencyPlan(Map<String, Object> cp) {
Map<String, Object> map = new HashMap<>();
map.put("fn", "contingencyPlan");
map.put("data", cp);
ObjectMapper mapper = new ObjectMapper();
try {
socketHandler.sendMessageToUser((String)cp.get("instructionsPeopleCode"), mapper.writeValueAsString(map));
} catch (JsonProcessingException e) {
logger.error("sendContingencyPlan", e);
}
}
/**
* 将维修保养计划发送至线调页面
*/
public void sendMaintenancePlan(MaintenancePlan maintenancePlan) {
Map<String, Object> map = new HashMap<>();
map.put("fn", "maintenancePlan");
map.put("data", maintenancePlan);
ObjectMapper mapper = new ObjectMapper();
try {
if (maintenancePlan.getLine() != null) {
socketHandler.sendMessageToLine(maintenancePlan.getLine(), mapper.writeValueAsString(map));
}
} catch (JsonProcessingException e) {
logger.error("sendMaintenancePlan", e);
}
}
/**
* 将车辆异常停车发送至线调页面
*/
public void sendCarErrorStop(CarErrorStop carErrorStop) {
Map<String, Object> map = new HashMap<>();
map.put("fn", "carErrorStop");
map.put("data", carErrorStop);
ObjectMapper mapper = new ObjectMapper();
try {
if (carErrorStop.getLineId() != null) {
socketHandler.sendMessageToLine(carErrorStop.getLineId(), mapper.writeValueAsString(map));
}
} catch (JsonProcessingException e) {
logger.error("sendCarErrorStop", e);
}
}
/**
* 将车辆进出场私自绕改道发送至线调页面
*/
public void sendInoutPark(InoutPark inoutPark) {
Map<String, Object> map = new HashMap<>();
map.put("fn", "inoutPark");
map.put("data", inoutPark);
ObjectMapper mapper = new ObjectMapper();
try {
if (inoutPark.getLineId() != null) {
socketHandler.sendMessageToLine(inoutPark.getLineId(), mapper.writeValueAsString(map));
}
} catch (JsonProcessingException e) {
logger.error("sendInoutPark", e);
}
}
/**
* 推送报警信息至线调页面
*/
public void sendAlarm(AlarmVo alarmVo) {
Map<String, Object> map = new HashMap<>();
map.put("fn", "alarm");
map.put("data", alarmVo);
ObjectMapper mapper = new ObjectMapper();
try {
socketHandler.sendMessageToLine(alarmVo.getLineCode(), mapper.writeValueAsString(map));
} catch (JsonProcessingException e) {
logger.error("sendAlarm", e);
}
}
}