Commit 7b042a0153f7ca5c5d64f0b400eaa7b7c17e939e
1 parent
09374973
1.
Showing
1 changed file
with
370 additions
and
366 deletions
src/main/java/com/bsth/controller/realcontrol/ServiceDataInterface.java
| 1 | -package com.bsth.controller.realcontrol; | |
| 2 | - | |
| 3 | -import com.alibaba.fastjson.JSON; | |
| 4 | -import com.alibaba.fastjson.JSONArray; | |
| 5 | -import com.alibaba.fastjson.JSONObject; | |
| 6 | -import com.bsth.controller.realcontrol.dto.ChangePersonCar; | |
| 7 | -import com.bsth.controller.realcontrol.dto.DftzAndDestroy; | |
| 8 | -import com.bsth.data.BasicData; | |
| 9 | -import com.bsth.data.directive.DayOfDirectives; | |
| 10 | -import com.bsth.data.directive.DirectiveCreator; | |
| 11 | -import com.bsth.data.directive.GatewayHttpUtils; | |
| 12 | -import com.bsth.data.gpsdata_v2.GpsRealData; | |
| 13 | -import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 14 | -import com.bsth.data.schedule.DayOfSchedule; | |
| 15 | -import com.bsth.data.schedule.external.TccExternalService; | |
| 16 | -import com.bsth.entity.Line; | |
| 17 | -import com.bsth.entity.directive.D60; | |
| 18 | -import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 19 | -import com.bsth.repository.LineRepository; | |
| 20 | -import com.bsth.repository.directive.D60Repository; | |
| 21 | -import com.bsth.service.LineService; | |
| 22 | -import com.bsth.websocket.handler.SendUtils; | |
| 23 | -import com.fasterxml.jackson.databind.ObjectMapper; | |
| 24 | -import com.google.common.base.Splitter; | |
| 25 | -import org.apache.commons.lang3.StringEscapeUtils; | |
| 26 | -import org.apache.commons.lang3.StringUtils; | |
| 27 | -import org.slf4j.Logger; | |
| 28 | -import org.slf4j.LoggerFactory; | |
| 29 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 30 | -import org.springframework.web.bind.annotation.*; | |
| 31 | - | |
| 32 | -import java.io.IOException; | |
| 33 | -import java.util.*; | |
| 34 | - | |
| 35 | -/** | |
| 36 | - * 对外的营运数据接口 | |
| 37 | - * Created by panzhao on 2017/3/15. | |
| 38 | - */ | |
| 39 | -@RestController | |
| 40 | -@RequestMapping("/companyService") | |
| 41 | -public class ServiceDataInterface { | |
| 42 | - | |
| 43 | - private final static String SECRE_KEY = "dVPHJkWUt5FhMT7jrM2dLV7QvlHAmZFd42rs1P0usBx8A7HZki"; | |
| 44 | - | |
| 45 | - Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 46 | - | |
| 47 | - @Autowired | |
| 48 | - DayOfSchedule dayOfSchedule; | |
| 49 | - | |
| 50 | - @Autowired | |
| 51 | - DayOfDirectives dayOfDirectives; | |
| 52 | - | |
| 53 | - @Autowired | |
| 54 | - D60Repository d60Repository; | |
| 55 | - | |
| 56 | - @Autowired | |
| 57 | - GpsRealData gpsRealData; | |
| 58 | - | |
| 59 | - @Autowired | |
| 60 | - TccExternalService tccExternalService; | |
| 61 | - | |
| 62 | - @Autowired | |
| 63 | - private SendUtils sendUtils; | |
| 64 | - | |
| 65 | - | |
| 66 | - @Autowired | |
| 67 | - LineRepository lineRepository; | |
| 68 | - | |
| 69 | - @Autowired | |
| 70 | - private LineService service; | |
| 71 | - | |
| 72 | - /** | |
| 73 | - * 获取车辆 和 当前执行班次对照信息 | |
| 74 | - * | |
| 75 | - * @return | |
| 76 | - */ | |
| 77 | - @RequestMapping("/execSchList") | |
| 78 | - public List<Map<String, Object>> execSchList(@RequestParam String secretKey) { | |
| 79 | - if (StringUtils.isEmpty(secretKey) || !secretKey.equals(SECRE_KEY)) | |
| 80 | - return null; | |
| 81 | - | |
| 82 | - List<Map<String, Object>> rs = new ArrayList<>(); | |
| 83 | - Collection<ScheduleRealInfo> list = dayOfSchedule.execPlanMap().values(); | |
| 84 | - | |
| 85 | - Map<String, Object> map; | |
| 86 | - for (ScheduleRealInfo sch : list) { | |
| 87 | - if (null == sch) | |
| 88 | - continue; | |
| 89 | - map = new HashMap<>(); | |
| 90 | - map.put("clZbh", sch.getClZbh()); | |
| 91 | - map.put("jGh", sch.getjGh()); | |
| 92 | - map.put("jName", sch.getjName()); | |
| 93 | - map.put("sGh", sch.getsGh()); | |
| 94 | - map.put("sName", sch.getsName()); | |
| 95 | - map.put("lpName", sch.getLpName()); | |
| 96 | - map.put("xlBm", sch.getXlBm()); | |
| 97 | - map.put("xlName", sch.getXlName()); | |
| 98 | - map.put("xlDir", sch.getXlDir()); | |
| 99 | - map.put("qdzName", sch.getQdzName()); | |
| 100 | - map.put("zdzName", sch.getZdzName()); | |
| 101 | - map.put("fcsj", sch.getFcsj()); | |
| 102 | - map.put("dfsj", sch.getDfsj()); | |
| 103 | - map.put("zdsj", sch.getZdsj()); | |
| 104 | - map.put("bcType", sch.getBcType()); | |
| 105 | - map.put("remarks", sch.getRemark()); | |
| 106 | - map.put("status", sch.getStatus()); | |
| 107 | - | |
| 108 | - //放站班次,放到的站点 | |
| 109 | - map.put("majorStationName", sch.getMajorStationName()); | |
| 110 | - rs.add(map); | |
| 111 | - } | |
| 112 | - return rs; | |
| 113 | - } | |
| 114 | - | |
| 115 | - @RequestMapping("/getCurrentDayPlan") | |
| 116 | - public List<ScheduleRealInfo> getCurrentDayPlan( | |
| 117 | - @RequestParam String companyId, | |
| 118 | - @RequestParam String workId, | |
| 119 | - @RequestParam String secretKey) { | |
| 120 | - | |
| 121 | - if (StringUtils.isEmpty(secretKey) || !secretKey.equals(SECRE_KEY)) | |
| 122 | - return null; | |
| 123 | - | |
| 124 | - List<ScheduleRealInfo> all = new ArrayList<>(dayOfSchedule.findByGsbm(companyId)), rs = new ArrayList<>(); | |
| 125 | - for (ScheduleRealInfo sch : all) { | |
| 126 | - if (sch.getGsBm() != null | |
| 127 | - && sch.getGsBm().equals(companyId) | |
| 128 | - && sch.getjGh().equals(workId)) { | |
| 129 | - rs.add(sch); | |
| 130 | - } | |
| 131 | - } | |
| 132 | - return rs; | |
| 133 | - } | |
| 134 | - | |
| 135 | - @RequestMapping("/returnCCInfo") | |
| 136 | - public List<ScheduleRealInfo> returnCCInfo(@RequestParam String companyId, @RequestParam String secretKey) { | |
| 137 | - if (StringUtils.isEmpty(secretKey) || !secretKey.equals(SECRE_KEY)) | |
| 138 | - return null; | |
| 139 | - | |
| 140 | - | |
| 141 | - List<ScheduleRealInfo> all = new ArrayList<>(dayOfSchedule.findAll()), rs = new ArrayList<>(); | |
| 142 | - for (ScheduleRealInfo sch : all) { | |
| 143 | - | |
| 144 | - if (sch.getBcType().equals("out") | |
| 145 | - && sch.getGsBm() != null | |
| 146 | - && sch.getGsBm().equals(companyId)) { | |
| 147 | - rs.add(sch); | |
| 148 | - } | |
| 149 | - } | |
| 150 | - return rs; | |
| 151 | - } | |
| 152 | - | |
| 153 | - @RequestMapping("/returnJCInfo") | |
| 154 | - public List<ScheduleRealInfo> returnJCInfo(@RequestParam String companyId, @RequestParam String secretKey) { | |
| 155 | - if (StringUtils.isEmpty(secretKey) || !secretKey.equals(SECRE_KEY)) | |
| 156 | - return null; | |
| 157 | - | |
| 158 | - | |
| 159 | - List<ScheduleRealInfo> all = new ArrayList<>(dayOfSchedule.findAll()), rs = new ArrayList<>(); | |
| 160 | - for (ScheduleRealInfo sch : all) { | |
| 161 | - if (sch.getBcType().equals("in") | |
| 162 | - && sch.getGsBm() != null | |
| 163 | - && sch.getGsBm().equals(companyId)) { | |
| 164 | - rs.add(sch); | |
| 165 | - } | |
| 166 | - } | |
| 167 | - return rs; | |
| 168 | - } | |
| 169 | - | |
| 170 | - /** | |
| 171 | - * 获取全量的进出场数据, 仅供接口项目调用。 由接口项目负责对外所有场站输出 | |
| 172 | - * | |
| 173 | - * @return | |
| 174 | - */ | |
| 175 | - @RequestMapping("/findCurrInAndOut") | |
| 176 | - public List<ScheduleRealInfo> findCurrInAndOut(@RequestParam String secretKey) { | |
| 177 | - if (StringUtils.isEmpty(secretKey) || !secretKey.equals(SECRE_KEY)) | |
| 178 | - return null; | |
| 179 | - | |
| 180 | - | |
| 181 | - List<ScheduleRealInfo> all = new ArrayList<>(dayOfSchedule.findAll()), rs = new ArrayList<>(); | |
| 182 | - for (ScheduleRealInfo sch : all) { | |
| 183 | - if (sch.getBcType().equals("in") | |
| 184 | - || sch.getBcType().equals("out")) { | |
| 185 | - rs.add(sch); | |
| 186 | - } | |
| 187 | - } | |
| 188 | - return rs; | |
| 189 | - } | |
| 190 | - | |
| 191 | - /** | |
| 192 | - * 向指定的车辆下发消息短语 | |
| 193 | - * | |
| 194 | - * @return | |
| 195 | - */ | |
| 196 | - @RequestMapping(value = "/send60Phrase", method = RequestMethod.POST) | |
| 197 | - public int send60Phrase(@RequestBody Map<String, String> map, @RequestParam String secretKey) { | |
| 198 | - try { | |
| 199 | - String nbbm = map.get("nbbm"); | |
| 200 | - String txt = map.get("txt"); | |
| 201 | - String sender = map.get("sender"); | |
| 202 | - if (txt.length() > 50) | |
| 203 | - txt = txt.substring(0, 50); | |
| 204 | - if (StringUtils.isEmpty(secretKey) || !secretKey.equals(SECRE_KEY)) | |
| 205 | - return -500; | |
| 206 | - | |
| 207 | - //车辆和设备号对照 | |
| 208 | - String deviceId = BasicData.deviceId2NbbmMap.inverse().get(nbbm); | |
| 209 | - if (StringUtils.isEmpty(deviceId)) | |
| 210 | - return -404; | |
| 211 | - | |
| 212 | - //检查设备是否在线 | |
| 213 | - long t = System.currentTimeMillis(); | |
| 214 | - GpsEntity gps = gpsRealData.get(deviceId); | |
| 215 | - if (null == gps || (t - gps.getServerTimestamp()) > 1000 * 60 * 5) | |
| 216 | - return -405; | |
| 217 | - | |
| 218 | - Short dispatchInstruct = 0;//消息短语 | |
| 219 | - D60 d60 = new DirectiveCreator().createD60(nbbm, txt, dispatchInstruct, gps.getUpDown(), gps.getState(), gps.getLineId()); | |
| 220 | - d60.setSender(sender); | |
| 221 | - // 发送指令 | |
| 222 | - int code = GatewayHttpUtils.postJson(JSON.toJSONString(d60)); | |
| 223 | - d60.setHttpCode(code); | |
| 224 | - | |
| 225 | - if (code != 0) | |
| 226 | - d60.setErrorText("网关通讯失败, code: " + code); | |
| 227 | - | |
| 228 | - dayOfDirectives.put60(d60); | |
| 229 | - return d60.getMsgId(); | |
| 230 | - } catch (Exception e) { | |
| 231 | - logger.error("", e); | |
| 232 | - return -500; | |
| 233 | - } | |
| 234 | - } | |
| 235 | - | |
| 236 | - /** | |
| 237 | - * 根据msg id 查询指令响应情况 | |
| 238 | - * | |
| 239 | - * @param msgIds | |
| 240 | - * @return | |
| 241 | - */ | |
| 242 | - @RequestMapping("/findD60Reply") | |
| 243 | - public List<Map<String, Object>> findD60Reply(@RequestParam String msgIds) { | |
| 244 | - List<Map<String, Object>> rs = new ArrayList<>(); | |
| 245 | - try { | |
| 246 | - Map<String, Object> map = new HashMap(); | |
| 247 | - | |
| 248 | - List<String> ids = Splitter.on(",").splitToList(msgIds); | |
| 249 | - D60 d60; | |
| 250 | - for (String id : ids) { | |
| 251 | - if (StringUtils.isEmpty(id)) | |
| 252 | - continue; | |
| 253 | - | |
| 254 | - d60 = dayOfDirectives.get(Integer.parseInt(id)); | |
| 255 | - if (null == d60) | |
| 256 | - continue; | |
| 257 | - | |
| 258 | - map.put("msgId", d60.getMsgId()); | |
| 259 | - map.put("deviceReplyTime", d60.getReply46Time()); | |
| 260 | - map.put("jsyReplyTime", d60.getReply47Time()); | |
| 261 | - rs.add(map); | |
| 262 | - } | |
| 263 | - } catch (Exception e) { | |
| 264 | - logger.error("", e); | |
| 265 | - } | |
| 266 | - return rs; | |
| 267 | - } | |
| 268 | - | |
| 269 | - /** | |
| 270 | - * 获取路牌下所有班次 | |
| 271 | - * | |
| 272 | - * @param lineCode | |
| 273 | - * @param lpName | |
| 274 | - * @return | |
| 275 | - */ | |
| 276 | - @RequestMapping("/findByLpName") | |
| 277 | - public List<ScheduleRealInfo> findByLpName(@RequestParam String lineCode, @RequestParam String lpName, @RequestParam String secretKey) { | |
| 278 | - try { | |
| 279 | - if (StringUtils.isEmpty(secretKey) || !secretKey.equals(SECRE_KEY)) | |
| 280 | - return null; | |
| 281 | - | |
| 282 | - List<ScheduleRealInfo> list = dayOfSchedule.getLpScheduleMap().get(lineCode + "_" + lpName); | |
| 283 | - return list; | |
| 284 | - } catch (Exception e) { | |
| 285 | - logger.error("", e); | |
| 286 | - } | |
| 287 | - return null; | |
| 288 | - } | |
| 289 | - | |
| 290 | - /** | |
| 291 | - * 调整出场班次待发,并烂掉后续班次(调派用) | |
| 292 | - * | |
| 293 | - * @param dad | |
| 294 | - * @return | |
| 295 | - */ | |
| 296 | - @RequestMapping(value = "/dftzAndDestroy", method = RequestMethod.POST) | |
| 297 | - public Map<String, Object> dftzAndDestroy(@RequestBody DftzAndDestroy dad, @RequestParam String secretKey) { | |
| 298 | - if (StringUtils.isEmpty(secretKey) || !secretKey.equals(SECRE_KEY)) | |
| 299 | - return null; | |
| 300 | - return tccExternalService.dftz(dad); | |
| 301 | - } | |
| 302 | - | |
| 303 | - /** | |
| 304 | - * 换人换车,(调派用) | |
| 305 | - * @return | |
| 306 | - */ | |
| 307 | - @RequestMapping(value = "/tccHrhc", method = RequestMethod.POST) | |
| 308 | - public Map<String, Object> hrhc(@RequestBody String jsonStr, @RequestParam String secretKey){ | |
| 309 | - | |
| 310 | - if (StringUtils.isEmpty(secretKey) || !secretKey.equals(SECRE_KEY)) | |
| 311 | - return null; | |
| 312 | - | |
| 313 | - jsonStr = StringEscapeUtils.unescapeHtml4(jsonStr); | |
| 314 | - JSONObject rootObj = JSON.parseObject(jsonStr); | |
| 315 | - | |
| 316 | - List<ChangePersonCar> cpcs = JSONArray.parseArray(rootObj.getString("cpcs"), ChangePersonCar.class); | |
| 317 | - return tccExternalService.hrhc(cpcs, rootObj.getString("tccCode"), rootObj.getString("userId")); | |
| 318 | - } | |
| 319 | - | |
| 320 | - /** | |
| 321 | - * 接收应急预案信息 | |
| 322 | - * @return | |
| 323 | - */ | |
| 324 | - @RequestMapping(value = "/contingencyPlan", method = RequestMethod.POST) | |
| 325 | - public Map<String, Object> contingencyPlan(@RequestBody String jsonStr, @RequestParam String secretKey){ | |
| 326 | - Map<String, Object> result = new HashMap<>(); | |
| 327 | - result.put("errCode", 0); | |
| 328 | - if (StringUtils.isEmpty(secretKey) || !secretKey.equals(SECRE_KEY)) { | |
| 329 | - result.put("errCode", 501); | |
| 330 | - result.put("msg", "无效的key"); | |
| 331 | - | |
| 332 | - return result; | |
| 333 | - } | |
| 334 | - | |
| 335 | - ObjectMapper mapper = new ObjectMapper(); | |
| 336 | - try { | |
| 337 | - List<Map<String,String>> emergencyList = new ArrayList(); | |
| 338 | - List<Map<String,String>> emergencyListAll = new ArrayList(); | |
| 339 | - List<Map> maps = mapper.readValue(jsonStr,mapper.getTypeFactory().constructParametricType(List.class, Map.class)); | |
| 340 | - for (Map map : maps) { | |
| 341 | - sendUtils.sendContingencyPlan(map); | |
| 342 | - emergencyList.add((Map<String, String>) map.get("emergencyLine")); | |
| 343 | - } | |
| 344 | - | |
| 345 | - for (Map.Entry<String, String> m : BasicData.lineCode2NameMap.entrySet()){ | |
| 346 | - for (Map<String,String> emer : emergencyList){ | |
| 347 | - for (Map.Entry<String,String> t : emer.entrySet()){ | |
| 348 | - if (m.getKey().equals(t.getKey())) { | |
| 349 | - emergencyListAll.add(emer); | |
| 350 | - Line line = lineRepository.findById(Integer.parseInt(t.getKey())).get(); | |
| 351 | - line.setName(t.getValue()); | |
| 352 | - Map<String, Object> status = service.update(line); | |
| 353 | - logger.info("应急接口修改线路名称-----------------------"+status.get("status")); | |
| 354 | - } | |
| 355 | - } | |
| 356 | - } | |
| 357 | - } | |
| 358 | - } catch (IOException e) { | |
| 359 | - result.put("errCode", 502); | |
| 360 | - result.put("msg", "json数据格式异常"); | |
| 361 | - logger.info("", e); | |
| 362 | - } | |
| 363 | - | |
| 364 | - return result; | |
| 365 | - } | |
| 366 | -} | |
| 1 | +package com.bsth.controller.realcontrol; | |
| 2 | + | |
| 3 | +import com.alibaba.fastjson.JSON; | |
| 4 | +import com.alibaba.fastjson.JSONArray; | |
| 5 | +import com.alibaba.fastjson.JSONObject; | |
| 6 | +import com.bsth.controller.realcontrol.dto.ChangePersonCar; | |
| 7 | +import com.bsth.controller.realcontrol.dto.DftzAndDestroy; | |
| 8 | +import com.bsth.data.BasicData; | |
| 9 | +import com.bsth.data.directive.DayOfDirectives; | |
| 10 | +import com.bsth.data.directive.DirectiveCreator; | |
| 11 | +import com.bsth.data.directive.GatewayHttpUtils; | |
| 12 | +import com.bsth.data.gpsdata_v2.GpsRealData; | |
| 13 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 14 | +import com.bsth.data.schedule.DayOfSchedule; | |
| 15 | +import com.bsth.data.schedule.external.TccExternalService; | |
| 16 | +import com.bsth.entity.Line; | |
| 17 | +import com.bsth.entity.directive.D60; | |
| 18 | +import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 19 | +import com.bsth.repository.LineRepository; | |
| 20 | +import com.bsth.repository.directive.D60Repository; | |
| 21 | +import com.bsth.service.LineService; | |
| 22 | +import com.bsth.websocket.handler.SendUtils; | |
| 23 | +import com.fasterxml.jackson.databind.ObjectMapper; | |
| 24 | +import com.google.common.base.Splitter; | |
| 25 | +import org.apache.commons.lang3.StringEscapeUtils; | |
| 26 | +import org.apache.commons.lang3.StringUtils; | |
| 27 | +import org.slf4j.Logger; | |
| 28 | +import org.slf4j.LoggerFactory; | |
| 29 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 30 | +import org.springframework.web.bind.annotation.*; | |
| 31 | + | |
| 32 | +import java.io.IOException; | |
| 33 | +import java.util.*; | |
| 34 | + | |
| 35 | +/** | |
| 36 | + * 对外的营运数据接口 | |
| 37 | + * Created by panzhao on 2017/3/15. | |
| 38 | + */ | |
| 39 | +@RestController | |
| 40 | +@RequestMapping("/companyService") | |
| 41 | +public class ServiceDataInterface { | |
| 42 | + | |
| 43 | + private final static String SECRE_KEY = "dVPHJkWUt5FhMT7jrM2dLV7QvlHAmZFd42rs1P0usBx8A7HZki"; | |
| 44 | + | |
| 45 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 46 | + | |
| 47 | + @Autowired | |
| 48 | + DayOfSchedule dayOfSchedule; | |
| 49 | + | |
| 50 | + @Autowired | |
| 51 | + DayOfDirectives dayOfDirectives; | |
| 52 | + | |
| 53 | + @Autowired | |
| 54 | + D60Repository d60Repository; | |
| 55 | + | |
| 56 | + @Autowired | |
| 57 | + GpsRealData gpsRealData; | |
| 58 | + | |
| 59 | + @Autowired | |
| 60 | + TccExternalService tccExternalService; | |
| 61 | + | |
| 62 | + @Autowired | |
| 63 | + private SendUtils sendUtils; | |
| 64 | + | |
| 65 | + | |
| 66 | + @Autowired | |
| 67 | + LineRepository lineRepository; | |
| 68 | + | |
| 69 | + @Autowired | |
| 70 | + private LineService service; | |
| 71 | + | |
| 72 | + /** | |
| 73 | + * 获取车辆 和 当前执行班次对照信息 | |
| 74 | + * | |
| 75 | + * @return | |
| 76 | + */ | |
| 77 | + @RequestMapping("/execSchList") | |
| 78 | + public List<Map<String, Object>> execSchList(@RequestParam String secretKey) { | |
| 79 | + if (StringUtils.isEmpty(secretKey) || !secretKey.equals(SECRE_KEY)) | |
| 80 | + return null; | |
| 81 | + | |
| 82 | + List<Map<String, Object>> rs = new ArrayList<>(); | |
| 83 | + Collection<ScheduleRealInfo> list = dayOfSchedule.execPlanMap().values(); | |
| 84 | + | |
| 85 | + Map<String, Object> map; | |
| 86 | + for (ScheduleRealInfo sch : list) { | |
| 87 | + if (null == sch) | |
| 88 | + continue; | |
| 89 | + map = new HashMap<>(); | |
| 90 | + map.put("id", sch.getId()); | |
| 91 | + map.put("clZbh", sch.getClZbh()); | |
| 92 | + map.put("jGh", sch.getjGh()); | |
| 93 | + map.put("jName", sch.getjName()); | |
| 94 | + map.put("sGh", sch.getsGh()); | |
| 95 | + map.put("sName", sch.getsName()); | |
| 96 | + map.put("lpName", sch.getLpName()); | |
| 97 | + map.put("xlBm", sch.getXlBm()); | |
| 98 | + map.put("xlName", sch.getXlName()); | |
| 99 | + map.put("xlDir", sch.getXlDir()); | |
| 100 | + map.put("qdzName", sch.getQdzName()); | |
| 101 | + map.put("zdzName", sch.getZdzName()); | |
| 102 | + map.put("fcsj", sch.getFcsj()); | |
| 103 | + map.put("fcsjActualTime", sch.getFcsjActualTime()); | |
| 104 | + map.put("dfsj", sch.getDfsj()); | |
| 105 | + map.put("zdsj", sch.getZdsj()); | |
| 106 | + map.put("zdsjActualTime", sch.getZdsjActualTime()); | |
| 107 | + map.put("bcType", sch.getBcType()); | |
| 108 | + map.put("remarks", sch.getRemark()); | |
| 109 | + map.put("status", sch.getStatus()); | |
| 110 | + map.put("realExecDate", sch.getRealExecDate()); | |
| 111 | + | |
| 112 | + //放站班次,放到的站点 | |
| 113 | + map.put("majorStationName", sch.getMajorStationName()); | |
| 114 | + rs.add(map); | |
| 115 | + } | |
| 116 | + return rs; | |
| 117 | + } | |
| 118 | + | |
| 119 | + @RequestMapping("/getCurrentDayPlan") | |
| 120 | + public List<ScheduleRealInfo> getCurrentDayPlan( | |
| 121 | + @RequestParam String companyId, | |
| 122 | + @RequestParam String workId, | |
| 123 | + @RequestParam String secretKey) { | |
| 124 | + | |
| 125 | + if (StringUtils.isEmpty(secretKey) || !secretKey.equals(SECRE_KEY)) | |
| 126 | + return null; | |
| 127 | + | |
| 128 | + List<ScheduleRealInfo> all = new ArrayList<>(dayOfSchedule.findByGsbm(companyId)), rs = new ArrayList<>(); | |
| 129 | + for (ScheduleRealInfo sch : all) { | |
| 130 | + if (sch.getGsBm() != null | |
| 131 | + && sch.getGsBm().equals(companyId) | |
| 132 | + && sch.getjGh().equals(workId)) { | |
| 133 | + rs.add(sch); | |
| 134 | + } | |
| 135 | + } | |
| 136 | + return rs; | |
| 137 | + } | |
| 138 | + | |
| 139 | + @RequestMapping("/returnCCInfo") | |
| 140 | + public List<ScheduleRealInfo> returnCCInfo(@RequestParam String companyId, @RequestParam String secretKey) { | |
| 141 | + if (StringUtils.isEmpty(secretKey) || !secretKey.equals(SECRE_KEY)) | |
| 142 | + return null; | |
| 143 | + | |
| 144 | + | |
| 145 | + List<ScheduleRealInfo> all = new ArrayList<>(dayOfSchedule.findAll()), rs = new ArrayList<>(); | |
| 146 | + for (ScheduleRealInfo sch : all) { | |
| 147 | + | |
| 148 | + if (sch.getBcType().equals("out") | |
| 149 | + && sch.getGsBm() != null | |
| 150 | + && sch.getGsBm().equals(companyId)) { | |
| 151 | + rs.add(sch); | |
| 152 | + } | |
| 153 | + } | |
| 154 | + return rs; | |
| 155 | + } | |
| 156 | + | |
| 157 | + @RequestMapping("/returnJCInfo") | |
| 158 | + public List<ScheduleRealInfo> returnJCInfo(@RequestParam String companyId, @RequestParam String secretKey) { | |
| 159 | + if (StringUtils.isEmpty(secretKey) || !secretKey.equals(SECRE_KEY)) | |
| 160 | + return null; | |
| 161 | + | |
| 162 | + | |
| 163 | + List<ScheduleRealInfo> all = new ArrayList<>(dayOfSchedule.findAll()), rs = new ArrayList<>(); | |
| 164 | + for (ScheduleRealInfo sch : all) { | |
| 165 | + if (sch.getBcType().equals("in") | |
| 166 | + && sch.getGsBm() != null | |
| 167 | + && sch.getGsBm().equals(companyId)) { | |
| 168 | + rs.add(sch); | |
| 169 | + } | |
| 170 | + } | |
| 171 | + return rs; | |
| 172 | + } | |
| 173 | + | |
| 174 | + /** | |
| 175 | + * 获取全量的进出场数据, 仅供接口项目调用。 由接口项目负责对外所有场站输出 | |
| 176 | + * | |
| 177 | + * @return | |
| 178 | + */ | |
| 179 | + @RequestMapping("/findCurrInAndOut") | |
| 180 | + public List<ScheduleRealInfo> findCurrInAndOut(@RequestParam String secretKey) { | |
| 181 | + if (StringUtils.isEmpty(secretKey) || !secretKey.equals(SECRE_KEY)) | |
| 182 | + return null; | |
| 183 | + | |
| 184 | + | |
| 185 | + List<ScheduleRealInfo> all = new ArrayList<>(dayOfSchedule.findAll()), rs = new ArrayList<>(); | |
| 186 | + for (ScheduleRealInfo sch : all) { | |
| 187 | + if (sch.getBcType().equals("in") | |
| 188 | + || sch.getBcType().equals("out")) { | |
| 189 | + rs.add(sch); | |
| 190 | + } | |
| 191 | + } | |
| 192 | + return rs; | |
| 193 | + } | |
| 194 | + | |
| 195 | + /** | |
| 196 | + * 向指定的车辆下发消息短语 | |
| 197 | + * | |
| 198 | + * @return | |
| 199 | + */ | |
| 200 | + @RequestMapping(value = "/send60Phrase", method = RequestMethod.POST) | |
| 201 | + public int send60Phrase(@RequestBody Map<String, String> map, @RequestParam String secretKey) { | |
| 202 | + try { | |
| 203 | + String nbbm = map.get("nbbm"); | |
| 204 | + String txt = map.get("txt"); | |
| 205 | + String sender = map.get("sender"); | |
| 206 | + if (txt.length() > 50) | |
| 207 | + txt = txt.substring(0, 50); | |
| 208 | + if (StringUtils.isEmpty(secretKey) || !secretKey.equals(SECRE_KEY)) | |
| 209 | + return -500; | |
| 210 | + | |
| 211 | + //车辆和设备号对照 | |
| 212 | + String deviceId = BasicData.deviceId2NbbmMap.inverse().get(nbbm); | |
| 213 | + if (StringUtils.isEmpty(deviceId)) | |
| 214 | + return -404; | |
| 215 | + | |
| 216 | + //检查设备是否在线 | |
| 217 | + long t = System.currentTimeMillis(); | |
| 218 | + GpsEntity gps = gpsRealData.get(deviceId); | |
| 219 | + if (null == gps || (t - gps.getServerTimestamp()) > 1000 * 60 * 5) | |
| 220 | + return -405; | |
| 221 | + | |
| 222 | + Short dispatchInstruct = 0;//消息短语 | |
| 223 | + D60 d60 = new DirectiveCreator().createD60(nbbm, txt, dispatchInstruct, gps.getUpDown(), gps.getState(), gps.getLineId()); | |
| 224 | + d60.setSender(sender); | |
| 225 | + // 发送指令 | |
| 226 | + int code = GatewayHttpUtils.postJson(JSON.toJSONString(d60)); | |
| 227 | + d60.setHttpCode(code); | |
| 228 | + | |
| 229 | + if (code != 0) | |
| 230 | + d60.setErrorText("网关通讯失败, code: " + code); | |
| 231 | + | |
| 232 | + dayOfDirectives.put60(d60); | |
| 233 | + return d60.getMsgId(); | |
| 234 | + } catch (Exception e) { | |
| 235 | + logger.error("", e); | |
| 236 | + return -500; | |
| 237 | + } | |
| 238 | + } | |
| 239 | + | |
| 240 | + /** | |
| 241 | + * 根据msg id 查询指令响应情况 | |
| 242 | + * | |
| 243 | + * @param msgIds | |
| 244 | + * @return | |
| 245 | + */ | |
| 246 | + @RequestMapping("/findD60Reply") | |
| 247 | + public List<Map<String, Object>> findD60Reply(@RequestParam String msgIds) { | |
| 248 | + List<Map<String, Object>> rs = new ArrayList<>(); | |
| 249 | + try { | |
| 250 | + Map<String, Object> map = new HashMap(); | |
| 251 | + | |
| 252 | + List<String> ids = Splitter.on(",").splitToList(msgIds); | |
| 253 | + D60 d60; | |
| 254 | + for (String id : ids) { | |
| 255 | + if (StringUtils.isEmpty(id)) | |
| 256 | + continue; | |
| 257 | + | |
| 258 | + d60 = dayOfDirectives.get(Integer.parseInt(id)); | |
| 259 | + if (null == d60) | |
| 260 | + continue; | |
| 261 | + | |
| 262 | + map.put("msgId", d60.getMsgId()); | |
| 263 | + map.put("deviceReplyTime", d60.getReply46Time()); | |
| 264 | + map.put("jsyReplyTime", d60.getReply47Time()); | |
| 265 | + rs.add(map); | |
| 266 | + } | |
| 267 | + } catch (Exception e) { | |
| 268 | + logger.error("", e); | |
| 269 | + } | |
| 270 | + return rs; | |
| 271 | + } | |
| 272 | + | |
| 273 | + /** | |
| 274 | + * 获取路牌下所有班次 | |
| 275 | + * | |
| 276 | + * @param lineCode | |
| 277 | + * @param lpName | |
| 278 | + * @return | |
| 279 | + */ | |
| 280 | + @RequestMapping("/findByLpName") | |
| 281 | + public List<ScheduleRealInfo> findByLpName(@RequestParam String lineCode, @RequestParam String lpName, @RequestParam String secretKey) { | |
| 282 | + try { | |
| 283 | + if (StringUtils.isEmpty(secretKey) || !secretKey.equals(SECRE_KEY)) | |
| 284 | + return null; | |
| 285 | + | |
| 286 | + List<ScheduleRealInfo> list = dayOfSchedule.getLpScheduleMap().get(lineCode + "_" + lpName); | |
| 287 | + return list; | |
| 288 | + } catch (Exception e) { | |
| 289 | + logger.error("", e); | |
| 290 | + } | |
| 291 | + return null; | |
| 292 | + } | |
| 293 | + | |
| 294 | + /** | |
| 295 | + * 调整出场班次待发,并烂掉后续班次(调派用) | |
| 296 | + * | |
| 297 | + * @param dad | |
| 298 | + * @return | |
| 299 | + */ | |
| 300 | + @RequestMapping(value = "/dftzAndDestroy", method = RequestMethod.POST) | |
| 301 | + public Map<String, Object> dftzAndDestroy(@RequestBody DftzAndDestroy dad, @RequestParam String secretKey) { | |
| 302 | + if (StringUtils.isEmpty(secretKey) || !secretKey.equals(SECRE_KEY)) | |
| 303 | + return null; | |
| 304 | + return tccExternalService.dftz(dad); | |
| 305 | + } | |
| 306 | + | |
| 307 | + /** | |
| 308 | + * 换人换车,(调派用) | |
| 309 | + * @return | |
| 310 | + */ | |
| 311 | + @RequestMapping(value = "/tccHrhc", method = RequestMethod.POST) | |
| 312 | + public Map<String, Object> hrhc(@RequestBody String jsonStr, @RequestParam String secretKey){ | |
| 313 | + | |
| 314 | + if (StringUtils.isEmpty(secretKey) || !secretKey.equals(SECRE_KEY)) | |
| 315 | + return null; | |
| 316 | + | |
| 317 | + jsonStr = StringEscapeUtils.unescapeHtml4(jsonStr); | |
| 318 | + JSONObject rootObj = JSON.parseObject(jsonStr); | |
| 319 | + | |
| 320 | + List<ChangePersonCar> cpcs = JSONArray.parseArray(rootObj.getString("cpcs"), ChangePersonCar.class); | |
| 321 | + return tccExternalService.hrhc(cpcs, rootObj.getString("tccCode"), rootObj.getString("userId")); | |
| 322 | + } | |
| 323 | + | |
| 324 | + /** | |
| 325 | + * 接收应急预案信息 | |
| 326 | + * @return | |
| 327 | + */ | |
| 328 | + @RequestMapping(value = "/contingencyPlan", method = RequestMethod.POST) | |
| 329 | + public Map<String, Object> contingencyPlan(@RequestBody String jsonStr, @RequestParam String secretKey){ | |
| 330 | + Map<String, Object> result = new HashMap<>(); | |
| 331 | + result.put("errCode", 0); | |
| 332 | + if (StringUtils.isEmpty(secretKey) || !secretKey.equals(SECRE_KEY)) { | |
| 333 | + result.put("errCode", 501); | |
| 334 | + result.put("msg", "无效的key"); | |
| 335 | + | |
| 336 | + return result; | |
| 337 | + } | |
| 338 | + | |
| 339 | + ObjectMapper mapper = new ObjectMapper(); | |
| 340 | + try { | |
| 341 | + List<Map<String,String>> emergencyList = new ArrayList(); | |
| 342 | + List<Map<String,String>> emergencyListAll = new ArrayList(); | |
| 343 | + List<Map> maps = mapper.readValue(jsonStr,mapper.getTypeFactory().constructParametricType(List.class, Map.class)); | |
| 344 | + for (Map map : maps) { | |
| 345 | + sendUtils.sendContingencyPlan(map); | |
| 346 | + emergencyList.add((Map<String, String>) map.get("emergencyLine")); | |
| 347 | + } | |
| 348 | + | |
| 349 | + for (Map.Entry<String, String> m : BasicData.lineCode2NameMap.entrySet()){ | |
| 350 | + for (Map<String,String> emer : emergencyList){ | |
| 351 | + for (Map.Entry<String,String> t : emer.entrySet()){ | |
| 352 | + if (m.getKey().equals(t.getKey())) { | |
| 353 | + emergencyListAll.add(emer); | |
| 354 | + Line line = lineRepository.findById(Integer.parseInt(t.getKey())).get(); | |
| 355 | + line.setName(t.getValue()); | |
| 356 | + Map<String, Object> status = service.update(line); | |
| 357 | + logger.info("应急接口修改线路名称-----------------------"+status.get("status")); | |
| 358 | + } | |
| 359 | + } | |
| 360 | + } | |
| 361 | + } | |
| 362 | + } catch (IOException e) { | |
| 363 | + result.put("errCode", 502); | |
| 364 | + result.put("msg", "json数据格式异常"); | |
| 365 | + logger.info("", e); | |
| 366 | + } | |
| 367 | + | |
| 368 | + return result; | |
| 369 | + } | |
| 370 | +} | ... | ... |