SendUtils.java
2.47 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
package com.bsth.websocket.handler;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.bsth.entity.realcontrol.ScheduleRealInfo;
import com.fasterxml.jackson.databind.ObjectMapper;
@Component
public class SendUtils{
@Autowired
private RealControlSocketHandler socketHandler;
private static SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
private static Logger logger = LoggerFactory.getLogger(SendUtils.class);
/**
* @throws JsonProcessingException
* TODO(推送发车信息)
*/
public void sendFcsj(ScheduleRealInfo schedule) {
Map<String, Object> map = new HashMap<>();
map.put("fn", "faChe");
map.put("t", schedule);
map.put("dataStr", sdf.format(new Date()));
ObjectMapper mapper = new ObjectMapper();
try {
socketHandler.sendMessageToLine(Integer.parseInt(schedule.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", list);
ObjectMapper mapper = new ObjectMapper();
try {
socketHandler.sendMessageToLine(Integer.parseInt(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 schedule, ScheduleRealInfo nextSch, int finish) {
Map<String, Object> map = new HashMap<>();
map.put("fn", "zhongDian");
map.put("t", schedule);
map.put("nt", nextSch);
map.put("finish", finish);
map.put("dataStr", sdf.format(new Date()));
ObjectMapper mapper = new ObjectMapper();
try {
socketHandler.sendMessageToLine(Integer.parseInt(schedule.getXlBm()), mapper.writeValueAsString(map));
} catch (Exception e) {
logger.error("", e);
}
}
}