SendUtils.java
4.02 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
package com.bsth.websocket.handler;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
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.alibaba.fastjson.JSONObject;
import com.bsth.data.BasicData;
import com.bsth.data.schedule.DayOfSchedule;
import com.bsth.entity.directive.D80;
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(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(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(schedule.getXlBm(), mapper.writeValueAsString(map));
} catch (Exception e) {
logger.error("", e);
}
}
/**
*
* @Title: shiftSchedule
* @Description: TODO(线路翻班通知)
*/
public void shiftSchedule(String lineCode){
Map<String, Object> map = new HashMap<>();
map.put("fn", "systemNotice");
map.put("type", "info");
map.put("text", BasicData.lineCode2NameMap.get(lineCode) + "切换至 "
+ DayOfSchedule.currSchDateMap.get(lineCode) + " 日排班");
ObjectMapper mapper = new ObjectMapper();
try {
socketHandler.sendMessageToLine(lineCode, mapper.writeValueAsString(map));
} catch (Exception e) {
logger.error("", e);
}
}
/**
*
* @Title: sendDirectiveToPage
* @Description: TODO(调度指令状态推送)
*/
public void sendDirectiveToPage(ScheduleRealInfo sch) {
JSONObject json = new JSONObject();
json.put("fn", "directive");
json.put("t", sch);
socketHandler.sendMessageToLine(sch.getXlBm(), json.toJSONString());
}
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 sendReportOutTime(ScheduleRealInfo sch)
}