ServiceDataInterface.java
8.18 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
package com.bsth.controller.realcontrol;
import com.alibaba.fastjson.JSON;
import com.bsth.data.BasicData;
import com.bsth.data.directive.DayOfDirectives;
import com.bsth.data.directive.DirectiveCreator;
import com.bsth.data.directive.GatewayHttpUtils;
import com.bsth.data.gpsdata_v2.GpsRealData;
import com.bsth.data.gpsdata_v2.entity.GpsEntity;
import com.bsth.data.schedule.DayOfSchedule;
import com.bsth.entity.directive.D60;
import com.bsth.entity.realcontrol.ScheduleRealInfo;
import com.bsth.repository.directive.D60Repository;
import com.google.common.base.Splitter;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.*;
/**
* 对外的营运数据接口
* Created by panzhao on 2017/3/15.
*/
@RestController
@RequestMapping("/companyService")
public class ServiceDataInterface {
private final static String SECRE_KEY = "dVPHJkWUt5FhMT7jrM2dLV7QvlHAmZFd42rs1P0usBx8A7HZki";
Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
DayOfSchedule dayOfSchedule;
@Autowired
DayOfDirectives dayOfDirectives;
@Autowired
D60Repository d60Repository;
@Autowired
GpsRealData gpsRealData;
/**
* 获取车辆 和 当前执行班次对照信息
* @return
*/
@RequestMapping("/execSchList")
public List<Map<String, Object>> execSchList(@RequestParam String secretKey){
if (StringUtils.isEmpty(secretKey) || !secretKey.equals(SECRE_KEY))
return null;
List<Map<String, Object>> rs = new ArrayList<>();
Collection<ScheduleRealInfo> list = dayOfSchedule.execPlanMap().values();
Map<String, Object> map;
for(ScheduleRealInfo sch : list){
if(null == sch)
continue;
map = new HashMap<>();
map.put("clZbh", sch.getClZbh());
map.put("jGh", sch.getjGh());
map.put("jName", sch.getjName());
map.put("sGh", sch.getsGh());
map.put("sName", sch.getsGh());
map.put("lpName", sch.getLpName());
map.put("xlBm", sch.getXlBm());
map.put("xlName", sch.getXlName());
map.put("xlDir", sch.getXlDir());
map.put("qdzName", sch.getQdzName());
map.put("zdzName", sch.getZdzName());
map.put("fcsj", sch.getFcsj());
map.put("dfsj", sch.getDfsj());
map.put("zdsj", sch.getZdsj());
map.put("bcType", sch.getBcType());
map.put("remarks", sch.getRemark());
map.put("status", sch.getStatus());
rs.add(map);
}
return rs;
}
@RequestMapping("/getCurrentDayPlan")
public List<ScheduleRealInfo> getCurrentDayPlan(
@RequestParam String companyId,
@RequestParam String workId,
@RequestParam String secretKey) {
if (StringUtils.isEmpty(secretKey) || !secretKey.equals(SECRE_KEY))
return null;
List<ScheduleRealInfo> all = new ArrayList<>(dayOfSchedule.findAll()), rs = new ArrayList<>();
for (ScheduleRealInfo sch : all) {
if (sch.getGsBm() != null
&& sch.getGsBm().equals(companyId)
&& sch.getjGh().equals(workId)) {
rs.add(sch);
}
}
return rs;
}
@RequestMapping("/returnCCInfo")
public List<ScheduleRealInfo> returnCCInfo(@RequestParam String companyId, @RequestParam String secretKey){
if (StringUtils.isEmpty(secretKey) || !secretKey.equals(SECRE_KEY))
return null;
List<ScheduleRealInfo> all = new ArrayList<>(dayOfSchedule.findAll()), rs = new ArrayList<>();
for (ScheduleRealInfo sch : all) {
if (sch.getBcType().equals("out")
&& sch.getGsBm() != null
&& sch.getGsBm().equals(companyId)) {
rs.add(sch);
}
}
return rs;
}
@RequestMapping("/returnJCInfo")
public List<ScheduleRealInfo> returnJCInfo(@RequestParam String companyId, @RequestParam String secretKey){
if (StringUtils.isEmpty(secretKey) || !secretKey.equals(SECRE_KEY))
return null;
List<ScheduleRealInfo> all = new ArrayList<>(dayOfSchedule.findAll()), rs = new ArrayList<>();
for (ScheduleRealInfo sch : all) {
if (sch.getBcType().equals("in")
&& sch.getGsBm() != null
&& sch.getGsBm().equals(companyId)) {
rs.add(sch);
}
}
return rs;
}
/**
* 获取全量的进出场数据, 仅供接口项目调用。 由接口项目负责对外所有场站输出
* @return
*/
@RequestMapping("/findCurrInAndOut")
public List<ScheduleRealInfo> findCurrInAndOut(@RequestParam String secretKey){
if (StringUtils.isEmpty(secretKey) || !secretKey.equals(SECRE_KEY))
return null;
List<ScheduleRealInfo> all = new ArrayList<>(dayOfSchedule.findAll()), rs = new ArrayList<>();
for (ScheduleRealInfo sch : all) {
if (sch.getBcType().equals("in")
|| sch.getBcType().equals("out")) {
rs.add(sch);
}
}
return rs;
}
/**
* 向指定的车辆下发消息短语
* @param nbbm
* @param txt
* @return
*/
@RequestMapping(value = "/send60Phrase", method = RequestMethod.POST)
public int send60Phrase(@RequestBody Map<String, String> map,@RequestParam String secretKey){
try{
String nbbm = map.get("nbbm");
String txt = map.get("txt");
String sender = map.get("sender");
if(txt.length() > 50)
txt = txt.substring(0, 50);
if (StringUtils.isEmpty(secretKey) || !secretKey.equals(SECRE_KEY))
return -500;
//车辆和设备号对照
String deviceId = BasicData.deviceId2NbbmMap.inverse().get(nbbm);
if(StringUtils.isEmpty(deviceId))
return -404;
//检查设备是否在线
long t = System.currentTimeMillis();
GpsEntity gps = gpsRealData.get(deviceId);
if(null == gps || (t - gps.getServerTimestamp()) > 1000 * 60 * 5)
return -405;
Short dispatchInstruct = 0;//消息短语
D60 d60 = new DirectiveCreator().createD60(nbbm, txt, dispatchInstruct, gps.getUpDown(), gps.getState(), gps.getLineId());
d60.setSender(sender);
// 发送指令
int code = GatewayHttpUtils.postJson(JSON.toJSONString(d60));
d60.setHttpCode(code);
if (code != 0)
d60.setErrorText("网关通讯失败, code: " + code);
dayOfDirectives.put60(d60);
return d60.getMsgId();
}catch (Exception e){
logger.error("", e);
return -500;
}
}
/**
* 根据msg id 查询指令响应情况
* @param msgIDs
* @return
*/
@RequestMapping("/findD60Reply")
public List<Map<String, Object>> findD60Reply(@RequestParam String msgIds){
List<Map<String, Object>> rs = new ArrayList<>();
try{
Map<String, Object> map = new HashMap();
List<String> ids = Splitter.on(",").splitToList(msgIds);
D60 d60;
for(String id : ids){
if(StringUtils.isEmpty(id))
continue;
d60 = dayOfDirectives.get(Integer.parseInt(id));
if(null == d60)
continue;
map.put("msgId", d60.getMsgId());
map.put("deviceReplyTime", d60.getReply46Time());
map.put("jsyReplyTime", d60.getReply47Time());
rs.add(map);
}
}catch (Exception e){
logger.error("", e);
}
return rs;
}
}