SendUtils.java
5.22 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
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.LineConfigData;
import com.bsth.data.schedule.DayOfSchedule;
import com.bsth.entity.directive.D80;
import com.bsth.entity.realcontrol.ScheduleRealInfo;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
@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);
/**
* @throws JsonProcessingException
* TODO(推送发车信息)
*/
public void sendFcsj(ScheduleRealInfo sch) {
//处理出站即出场的班次
connectOutSchTime(sch);
Map<String, Object> map = new HashMap<>();
map.put("fn", "faChe");
map.put("t", 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", 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) {
//处理进站即进场的班次
connectInSchTime(sch);
Map<String, Object> map = new HashMap<>();
map.put("fn", "zhongDian");
map.put("t", sch);
map.put("nt", 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);
}
}
/**
*
* @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) {
Map<String, Object> map = new HashMap<>();
map.put("fn", "directive");
map.put("t", 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 connectOutSchTime(ScheduleRealInfo sch){
try{
ScheduleRealInfo twins = sch.getTwinsSch();
if(twins != null
&& lineConfigData.get(sch.getXlBm()).getOutConfig() == 2
&& twins.getBcType().equals("out")){
twins.setFcsjActualAll(sch.getFcsjActualTime());
//刷新关联的出场班次
refreshSch(twins);
}
}catch(Exception e){
logger.error("", e);
}
}
//进站即出场
public void connectInSchTime(ScheduleRealInfo sch){
try{
ScheduleRealInfo twins = sch.getTwinsSch();
if(twins != null
&& lineConfigData.get(sch.getXlBm()).getOutConfig() == 2
&& twins.getBcType().equals("in")){
twins.setZdsjActualAll(sch.getZdsjActualTime());
//刷新关联的出场班次
refreshSch(twins);
}
}catch(Exception e){
logger.error("", e);
}
}
}