PilotReport.java
6.24 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
package com.bsth.data.pilot80;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.bsth.data.BasicData;
import com.bsth.data.LineConfigData;
import com.bsth.data.gpsdata.GpsEntity;
import com.bsth.data.gpsdata.GpsRealData;
import com.bsth.data.schedule.DayOfSchedule;
import com.bsth.entity.Line;
import com.bsth.entity.directive.D80;
import com.bsth.entity.realcontrol.D80ReplyTemp;
import com.bsth.entity.realcontrol.LineConfig;
import com.bsth.entity.realcontrol.ScheduleRealInfo;
import com.bsth.repository.directive.D80Repository;
import com.bsth.service.directive.DirectiveService;
import com.bsth.websocket.handler.SendUtils;
import com.google.common.collect.ArrayListMultimap;
/**
*
* @ClassName: PilotReport
* @Description: TODO(驾驶员上报)
* @author PanZhao
* @date 2016年8月14日 下午11:37:51
*
*/
@Component
public class PilotReport {
@Autowired
D80Repository d80Repository;
@Autowired
DayOfSchedule dayOfSchedule;
@Autowired
LineConfigData lineConfigData;
@Autowired
DirectiveService directiveService;
@Autowired
GpsRealData gpsRealData;
@Autowired
SendUtils sendUtils;
//private static ScheduleComparator.FCNO schComp;
private static ArrayListMultimap<Integer, D80> d80MultiMap;
Logger logger = LoggerFactory.getLogger(PilotReport.class);
static{
d80MultiMap = ArrayListMultimap.create();
//schComp = new ScheduleComparator.FCNO();
}
public void report(D80 d80){
//入库
d80Repository.save(d80);
//入缓存
d80MultiMap.put(d80.getData().getLineId(), d80);
String nbbm = BasicData.deviceId2NbbmMap.get(d80.getDeviceId());
//处理
switch (d80.getData().getRequestCode()) {
case 0xA3:
//出场请求
ScheduleRealInfo outSch = dayOfSchedule.nextByBcType(nbbm, "out");
//如果有对应出场班次
if(outSch != null){
//下发调度指令
directiveService.send60Dispatch(outSch, dayOfSchedule.doneSum(nbbm), "系统");
//当前GPS位置
GpsEntity gps = gpsRealData.get(d80.getDeviceId());
d80.setRemarks("计划出场时间:" + outSch.getDfsj() + "<br> 位置:" + coordHtmlStr(gps));
}else
d80.setRemarks("没有出场计划");
break;
case 0xA5:
//进场请求
ScheduleRealInfo inSch = dayOfSchedule.nextByBcType(nbbm, "in");
//如果有对应出场班次
if(inSch != null){
//当前GPS位置
GpsEntity gps = gpsRealData.get(d80.getDeviceId());
d80.setRemarks("计划进场时间:" + inSch.getDfsj() + "<br> 位置:" + coordHtmlStr(gps));
}else
d80.setRemarks("没有进场计划");
break;
}
//推送到页面
sendUtils.send80ToPage(d80);
}
/**
*
* @Title: reply
* @Description: TODO(调度员回复)
*/
public void reply(D80 d80){
String nbbm = BasicData.deviceId2NbbmMap.get(d80.getDeviceId());
Short reqCode = d80.getData().getRequestCode();
//默认短语回复
defaultReply(nbbm, reqCode, d80.getConfirmRs() == 0?true:false);
switch (reqCode) {
case 0xA3:
//出场请求回复
applyOutReply(d80);
break;
case 0xA5:
//进场请求回复
applyInReply(d80);
break;
}
}
/**
*
* @Title: applyOutReply
* @Description: TODO(出场请求回复)
*/
public void applyOutReply(D80 d80){
//同意
if(d80.getConfirmRs() == 0){
String nbbm = BasicData.deviceId2NbbmMap.get(d80.getDeviceId());
ScheduleRealInfo sch = dayOfSchedule.nextByBcType(nbbm, "out");
if(null == sch)
return;
LineConfig conf = lineConfigData.get(sch.getXlBm());
if(conf.getOutConfig() == 1){
//为相关班次写入请求出场时间
sch.setFcsjActualAll(d80.getTimestamp());
//通知页面
sendUtils.refreshSch(sch);
}
}
}
/**
*
* @Title: applyInReply
* @Description: TODO(进场请求回复)
*/
public void applyInReply(D80 d80){
//同意
if(d80.getConfirmRs() == 0){
String nbbm = BasicData.deviceId2NbbmMap.get(d80.getDeviceId());
ScheduleRealInfo sch = dayOfSchedule.nextByBcType(nbbm, "in");
if(null == sch)
return;
LineConfig conf = lineConfigData.get(sch.getXlBm());
if(conf.getInConfig() == 1){
//为相关班次写入进场时间
sch.setZdsjActualAll(d80.getTimestamp());
//通知页面
sendUtils.refreshSch(sch);
}
}
}
public void defaultReply(String nbbm, short requestCode, boolean agree){
Line line = BasicData.nbbm2LineMap.get(nbbm);
String lineCode = null;
if(line != null)
lineCode = line.getLineCode();
else{
try{
lineCode = gpsRealData.get(BasicData.deviceId2NbbmMap.inverse().get(nbbm)).getLineId().toString();
}catch(Exception e){
logger.error("", e);
}
}
if(null == lineCode)
return;
LineConfig conf = lineConfigData.get(lineCode);
D80ReplyTemp temp = conf.findByCode(requestCode);
if(null == temp)
return;
String text;
if(agree)
text = temp.getAgreeText();
else
text = temp.getRejectText();
directiveService.send60Phrase(nbbm, text, "系统");
}
/**
*
* @Title: resumeOperation
* @Description: TODO(恢复营运)
*/
public void resumeOperation(D80 d80){
}
/**
*
* @Title: applyTiaodang
* @Description: TODO(申请调档)
*/
public void applyTiaodang(D80 d80){
}
/**
*
* @Title: unconfirmed80
* @Description: TODO(根据lineCode 获取未处理的80数据)
*/
public List<D80> unconfirmed80(Integer lineCode){
List<D80> lineAll = d80MultiMap.get(lineCode)
,rs = new ArrayList<>();
for(D80 d80 : lineAll)
if(!d80.isConfirm())
rs.add(d80);
return rs;
}
public D80 findById(int id){
Collection<D80> all = d80MultiMap.values();
for(D80 d80 : all){
if(d80.getId() == id)
return d80;
}
return null;
}
public String coordHtmlStr(GpsEntity gps){
return "<span class=\"nt-coord\" data-lon=\""+gps.getLon()+"\" data-lat=\""+gps.getLat()+"\"></span>";
}
}