Commit 16e5de2a6bd8ef94ccfe938da49685006db4259e
Update
Showing
38 changed files
with
2747 additions
and
1565 deletions
Too many changes to show.
To preserve performance only 38 of 192 files are displayed.
src/main/java/com/bsth/controller/BusIntervalController.java
| ... | ... | @@ -22,6 +22,11 @@ public class BusIntervalController { |
| 22 | 22 | public List<Map<String,Object>> getDir(@RequestParam Map<String, Object> map){ |
| 23 | 23 | return busIntervalService.getDir(map); |
| 24 | 24 | } |
| 25 | + | |
| 26 | + @RequestMapping(value = "/getLp", method = RequestMethod.GET) | |
| 27 | + public List<Map<String,Object>> getLp(@RequestParam Map<String, Object> map){ | |
| 28 | + return busIntervalService.getLp(map); | |
| 29 | + } | |
| 25 | 30 | |
| 26 | 31 | @RequestMapping(value = "/interval", method = RequestMethod.GET) |
| 27 | 32 | public List<Map<String,Object>> interval(@RequestParam Map<String, Object> map){ | ... | ... |
src/main/java/com/bsth/controller/DownloadController.java
| ... | ... | @@ -2,6 +2,7 @@ package com.bsth.controller; |
| 2 | 2 | |
| 3 | 3 | import java.io.File; |
| 4 | 4 | import java.io.IOException; |
| 5 | +import java.net.URLDecoder; | |
| 5 | 6 | |
| 6 | 7 | import org.apache.commons.io.FileUtils; |
| 7 | 8 | import org.springframework.context.annotation.Scope; |
| ... | ... | @@ -35,7 +36,7 @@ public class DownloadController |
| 35 | 36 | File file=new File(moudelPath); |
| 36 | 37 | HttpHeaders headers = new HttpHeaders(); |
| 37 | 38 | String realFileName=new String(fileName.getBytes("UTF-8"),"iso-8859-1");//为了解决中文名称乱码问题 |
| 38 | - headers.setContentDispositionFormData("attachment", realFileName); | |
| 39 | + headers.setContentDispositionFormData("attachment", URLDecoder.decode(realFileName,"utf-8")); | |
| 39 | 40 | headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); |
| 40 | 41 | return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file), |
| 41 | 42 | headers, HttpStatus.CREATED); | ... | ... |
src/main/java/com/bsth/controller/forms/ExportController.java
| ... | ... | @@ -13,8 +13,10 @@ import org.springframework.web.bind.annotation.RequestMethod; |
| 13 | 13 | import org.springframework.web.bind.annotation.RequestParam; |
| 14 | 14 | import org.springframework.web.bind.annotation.RestController; |
| 15 | 15 | |
| 16 | +import com.bsth.data.BasicData; | |
| 16 | 17 | import com.bsth.entity.mcy_forms.Allline; |
| 17 | 18 | import com.bsth.entity.mcy_forms.Changetochange; |
| 19 | +import com.bsth.entity.mcy_forms.Daily; | |
| 18 | 20 | import com.bsth.entity.mcy_forms.Executionrate; |
| 19 | 21 | import com.bsth.entity.mcy_forms.Linepasswengerflow; |
| 20 | 22 | import com.bsth.entity.mcy_forms.Operationservice; |
| ... | ... | @@ -231,7 +233,7 @@ public class ExportController { |
| 231 | 233 | listI.add(resList.iterator()); |
| 232 | 234 | String path = this.getClass().getResource("/").getPath() + "static\\pages\\forms\\"; |
| 233 | 235 | ee.excelReplace(listI, new Object[] { map }, path + "mould\\vehicleloading.xls", |
| 234 | - path + "export\\车辆加注" + sdfSimple.format(sdfMonth.parse(map.get("dat").toString())) + ".xls"); | |
| 236 | + path + "export\\车辆加注" + sdfSimple.format(sdfMonth.parse(map.get("data").toString())) + ".xls"); | |
| 235 | 237 | } catch (Exception e) { |
| 236 | 238 | e.printStackTrace(); |
| 237 | 239 | } |
| ... | ... | @@ -319,8 +321,34 @@ public class ExportController { |
| 319 | 321 | List<Turnoutrate> turnoutrate = formsService.turnoutrate(map); |
| 320 | 322 | Map<String, Object> map1 = new HashMap<String, Object>(); |
| 321 | 323 | List<Map<String, Object>> resList = new ArrayList<Map<String, Object>>(); |
| 324 | + String xlts=""; | |
| 325 | + String zsgs=""; | |
| 326 | + String jh=""; | |
| 327 | + Float j=0f; | |
| 328 | + Float sj=0f; | |
| 329 | + Float qz=0f; | |
| 330 | + Float ccl=0f; | |
| 331 | + Float bcjh=0f; | |
| 332 | + String bcsj=""; | |
| 333 | + Float bczxl=0f; | |
| 334 | + String gs=""; | |
| 335 | + String zhgs=""; | |
| 336 | + | |
| 322 | 337 | for (Turnoutrate l : turnoutrate) { |
| 323 | 338 | Map<String, Object> m = new HashMap<String, Object>(); |
| 339 | + | |
| 340 | + xlts +=l.getGsgs()==""?0:String.valueOf(l.getGsgs()); | |
| 341 | + zsgs +=l.getFgsgs()==""?0:String.valueOf(l.getFgsgs()); | |
| 342 | + jh +=l.getXl()==""?0:String.valueOf(l.getXl()); | |
| 343 | + sj +=l.getCchjh()==""?0f:Float.valueOf(l.getCchjh()); | |
| 344 | + ccl +=l.getCchsj()==""?0f:Float.valueOf(l.getCchsj()); | |
| 345 | + bcjh +=l.getCchqz()==""?0f:Float.valueOf(l.getCchqz()); | |
| 346 | + bcsj +=l.getChl()==""?0:String.valueOf(l.getChl()); | |
| 347 | + bczxl +=l.getBcjh()==""?0f:Float.valueOf(l.getBcjh()); | |
| 348 | + gs +=l.getBcsj()==""?0:String.valueOf(l.getBcsj()); | |
| 349 | + zhgs +=l.getBbzxl()==""?0:String.valueOf(l.getBbzxl()); | |
| 350 | + | |
| 351 | + | |
| 324 | 352 | m.put("rq", l.getRq()); |
| 325 | 353 | m.put("gs", l.getGs()); |
| 326 | 354 | m.put("zhgs", l.getZhgs()); |
| ... | ... | @@ -330,10 +358,27 @@ public class ExportController { |
| 330 | 358 | m.put("cchqz", l.getCchqz()); |
| 331 | 359 | m.put("chl", l.getChl()); |
| 332 | 360 | m.put("bcjh", l.getBcjh()); |
| 333 | - m.put("bcsj", l.getBbzxl()); | |
| 361 | + m.put("bcsj", l.getBcsj()); | |
| 334 | 362 | m.put("bbzxl", l.getBbzxl()); |
| 335 | 363 | m.put("sm", l.getSm()); |
| 336 | 364 | resList.add(m); |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + m=new HashMap<String,Object>(); | |
| 369 | + m.put("total_xlts", xlts); | |
| 370 | + m.put("total_zhgs", zsgs); | |
| 371 | + m.put("total_jh", jh); | |
| 372 | + m.put("total_sj", sj); | |
| 373 | + m.put("total_qz", ccl); | |
| 374 | + m.put("total_ccl", bcjh); | |
| 375 | + m.put("total_bcjh",bcsj); | |
| 376 | + m.put("total_bcsj", bczxl); | |
| 377 | + m.put("total_bczxl", bczxl); | |
| 378 | + m.put("total_gs", zhgs); | |
| 379 | + | |
| 380 | + | |
| 381 | + map1 = m; | |
| 337 | 382 | } |
| 338 | 383 | |
| 339 | 384 | try { |
| ... | ... | @@ -347,7 +392,7 @@ public class ExportController { |
| 347 | 392 | return resList; |
| 348 | 393 | } |
| 349 | 394 | |
| 350 | - //营运线路出车率统计表 | |
| 395 | + //班次执行率统计表 | |
| 351 | 396 | @RequestMapping(value = "/executionrateExport", method = RequestMethod.POST) |
| 352 | 397 | public List<Map<String, Object>> executionrateExport(@RequestParam Map<String, Object> map) { |
| 353 | 398 | SimpleDateFormat sdfMonth = new SimpleDateFormat("yyyy-MM-dd"), sdfSimple = new SimpleDateFormat("yyyyMMdd"); |
| ... | ... | @@ -356,8 +401,33 @@ public class ExportController { |
| 356 | 401 | List<Executionrate> executionrate = formsService.executionrate(map); |
| 357 | 402 | Map<String, Object> map1 = new HashMap<String, Object>(); |
| 358 | 403 | List<Map<String, Object>> resList = new ArrayList<Map<String, Object>>(); |
| 404 | + String xlts=""; | |
| 405 | + String zsgs=""; | |
| 406 | + String jh=""; | |
| 407 | + Float sj=0f; | |
| 408 | + Float ccl=0f; | |
| 409 | + Float bcjh=0f; | |
| 410 | + String bcsj=""; | |
| 411 | + Float bczxl=0f; | |
| 412 | + String gs=""; | |
| 413 | + String zhgs=""; | |
| 414 | + | |
| 415 | + Map<String, Object> m = new HashMap<String, Object>(); | |
| 416 | + | |
| 359 | 417 | for (Executionrate l : executionrate) { |
| 360 | - Map<String, Object> m = new HashMap<String, Object>(); | |
| 418 | + | |
| 419 | + xlts +=l.getGsgs()==""?0:String.valueOf(l.getGsgs()); | |
| 420 | + zsgs +=l.getFgsgs()==""?0:String.valueOf(l.getFgsgs()); | |
| 421 | + jh +=l.getXl()==""?0:String.valueOf(l.getXl()); | |
| 422 | + sj +=l.getCchjh()==""?0f:Float.valueOf(l.getCchjh()); | |
| 423 | + ccl +=l.getCchsj()==""?0f:Float.valueOf(l.getCchsj()); | |
| 424 | + bcsj +=l.getChl()==""?0:String.valueOf(l.getChl()); | |
| 425 | + bczxl +=l.getBcjh()==""?0f:Float.valueOf(l.getBcjh()); | |
| 426 | + gs +=l.getBcsj()==""?0:String.valueOf(l.getBcsj()); | |
| 427 | + zhgs +=l.getBbzxl()==""?0:String.valueOf(l.getBbzxl()); | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 361 | 431 | m.put("rq", l.getRq()); |
| 362 | 432 | m.put("gs", l.getGs()); |
| 363 | 433 | m.put("zhgs", l.getZhgs()); |
| ... | ... | @@ -366,10 +436,24 @@ public class ExportController { |
| 366 | 436 | m.put("cchsj", l.getCchsj()); |
| 367 | 437 | m.put("chl", l.getChl()); |
| 368 | 438 | m.put("bcjh", l.getBcjh()); |
| 369 | - m.put("bcsj", l.getBbzxl()); | |
| 439 | + m.put("bcsj", l.getBcsj()); | |
| 370 | 440 | m.put("bbzxl", l.getBbzxl()); |
| 371 | 441 | m.put("sm", l.getSm()); |
| 372 | 442 | resList.add(m); |
| 443 | + | |
| 444 | + | |
| 445 | + m=new HashMap<String,Object>(); | |
| 446 | + m.put("total_gs", xlts); | |
| 447 | + m.put("total_zhgs", zsgs); | |
| 448 | + m.put("total_xlts", jh); | |
| 449 | + m.put("total_jh", sj); | |
| 450 | + m.put("total_sj", ccl); | |
| 451 | + m.put("total_ccl",bcsj); | |
| 452 | + m.put("total_bcjh", bczxl); | |
| 453 | + m.put("total_bcsj", gs); | |
| 454 | + m.put("total_bczxl", zhgs); | |
| 455 | + | |
| 456 | + map1 = m; | |
| 373 | 457 | } |
| 374 | 458 | |
| 375 | 459 | try { |
| ... | ... | @@ -393,8 +477,28 @@ public class ExportController { |
| 393 | 477 | List<Allline> allline = formsService.allline(map); |
| 394 | 478 | Map<String, Object> map1 = new HashMap<String, Object>(); |
| 395 | 479 | List<Map<String, Object>> resList = new ArrayList<Map<String, Object>>(); |
| 480 | + Integer jh=0; | |
| 481 | + Integer sj=0; | |
| 482 | + Integer ccl=0; | |
| 483 | + Double bcjh=0.0; | |
| 484 | + String bcsj=""; | |
| 485 | + Integer bczxl=0; | |
| 486 | + String gs=""; | |
| 487 | + String zhgs=""; | |
| 488 | + Map<String, Object> m ; | |
| 396 | 489 | for (Allline l : allline) { |
| 397 | - Map<String, Object> m = new HashMap<String, Object>(); | |
| 490 | + m = new HashMap<String, Object>(); | |
| 491 | + | |
| 492 | + jh +=l.getGsgs()=="" ? 0: Integer.valueOf(l.getGsgs()); | |
| 493 | + sj +=l.getFgsgs()==""?0: Integer.valueOf(l.getFgsgs()); | |
| 494 | + ccl +=l.getCchjh()==""?0: Integer.valueOf(l.getCchjh()); | |
| 495 | + bcjh +=l.getCchsj()==""?0: Double.valueOf(l.getCchsj()); | |
| 496 | + | |
| 497 | + bcsj +=l.getChl()==""? 0:String.valueOf(l.getChl()); | |
| 498 | + bczxl +=l.getBcjh()==""?0: Integer.valueOf(l.getBcjh()); | |
| 499 | + gs +=l.getBcsj()==""?0: String.valueOf(l.getBcsj()); | |
| 500 | + zhgs +=l.getBbzxl()==""?0:String.valueOf(l.getBbzxl()); | |
| 501 | + | |
| 398 | 502 | m.put("rq", l.getRq()); |
| 399 | 503 | m.put("gs", l.getGs()); |
| 400 | 504 | m.put("zhgs", l.getZhgs()); |
| ... | ... | @@ -403,10 +507,22 @@ public class ExportController { |
| 403 | 507 | m.put("cchsj", l.getCchsj()); |
| 404 | 508 | m.put("chl", l.getChl()); |
| 405 | 509 | m.put("bcjh", l.getBcjh()); |
| 406 | - m.put("bcsj", l.getBbzxl()); | |
| 510 | + m.put("bcsj", l.getBcsj()); | |
| 407 | 511 | m.put("bbzxl", l.getBbzxl()); |
| 408 | 512 | m.put("sm", l.getSm()); |
| 409 | 513 | resList.add(m); |
| 514 | + | |
| 515 | + m=new HashMap<String,Object>(); | |
| 516 | + m.put("total_jh", jh); | |
| 517 | + m.put("total_sj", sj); | |
| 518 | + m.put("total_ccl", ccl); | |
| 519 | + m.put("total_bcjh", bcjh); | |
| 520 | + m.put("total_bcsj", bcsj); | |
| 521 | + m.put("total_bczxl", bczxl); | |
| 522 | + m.put("total_gs", gs); | |
| 523 | + m.put("total_zhgs", zhgs); | |
| 524 | + map1 = m; | |
| 525 | + | |
| 410 | 526 | } |
| 411 | 527 | |
| 412 | 528 | try { |
| ... | ... | @@ -422,6 +538,56 @@ public class ExportController { |
| 422 | 538 | |
| 423 | 539 | |
| 424 | 540 | |
| 541 | + //班次日报表 | |
| 542 | + @RequestMapping(value = "/dailyExport", method = RequestMethod.POST) | |
| 543 | + public List<Map<String, Object>> dailyExport(@RequestParam Map<String, Object> map) { | |
| 544 | + SimpleDateFormat sdfMonth = new SimpleDateFormat("yyyy-MM-dd"), sdfSimple = new SimpleDateFormat("yyyyMMdd"); | |
| 545 | + List<Iterator<?>> listI = new ArrayList<Iterator<?>>(); | |
| 546 | + ReportUtils ee = new ReportUtils(); | |
| 547 | + List<Daily> allline = formsService.daily(map); | |
| 548 | + | |
| 549 | + List<Map<String, Object>> resList = new ArrayList<Map<String, Object>>(); | |
| 550 | + Float zgl=0f; | |
| 551 | + Float ks=0f; | |
| 552 | + Float yh=0f; | |
| 553 | + Float bc=0f; | |
| 554 | + Map<String, Object> m ; | |
| 555 | + for (Daily d : allline) { | |
| 556 | + m = new HashMap<String, Object>(); | |
| 557 | + zgl +=d.getZlc()==""?0f:Float.valueOf(d.getZlc()); | |
| 558 | + ks +=d.getJzl1()==""?0f:Float.valueOf(d.getJzl1()); | |
| 559 | + yh +=d.getYh()==""?0f:Float.valueOf(d.getYh()); | |
| 560 | + bc +=d.getBc()==""?0f:Float.valueOf(d.getBc()); | |
| 561 | + m.put("zbh", d.getZbh()); | |
| 562 | + m.put("jgh",d.getJgh()); | |
| 563 | + m.put("jName", d.getjName()); | |
| 564 | + m.put("zlc", d.getZlc()); | |
| 565 | + m.put("jzl1", d.getJzl1()); | |
| 566 | + m.put("yh", d.getYh()); | |
| 567 | + m.put("bc", d.getBc()); | |
| 568 | + | |
| 569 | + resList.add(m); | |
| 570 | + } | |
| 571 | + | |
| 572 | + m=new HashMap<String,Object>(); | |
| 573 | + m.put("total_zgl", zgl); | |
| 574 | + m.put("total_ks", ks); | |
| 575 | + m.put("total_yh", yh); | |
| 576 | + m.put("total_bc", bc); | |
| 577 | + | |
| 578 | + m.put("line", BasicData.lineCode2NameMap.get(map.get("line").toString())); | |
| 579 | + m.put("date", map.get("date").toString()); | |
| 580 | + try { | |
| 581 | + listI.add(resList.iterator()); | |
| 582 | + String path = this.getClass().getResource("/").getPath() + "static\\pages\\forms\\"; | |
| 583 | + ee.excelReplace(listI, new Object[] { m }, path + "mould\\daily.xls", path + "export\\班次日报表" | |
| 584 | + + sdfSimple.format(sdfMonth.parse(map.get("date").toString())) + ".xls"); | |
| 585 | + } catch (Exception e) { | |
| 586 | + e.printStackTrace(); | |
| 587 | + } | |
| 588 | + return resList; | |
| 589 | + } | |
| 590 | + | |
| 425 | 591 | |
| 426 | 592 | |
| 427 | 593 | } | ... | ... |
src/main/java/com/bsth/controller/forms/MCY_FormsController.java
| ... | ... | @@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.RestController; |
| 11 | 11 | |
| 12 | 12 | import com.bsth.entity.mcy_forms.Allline; |
| 13 | 13 | import com.bsth.entity.mcy_forms.Changetochange; |
| 14 | +import com.bsth.entity.mcy_forms.Daily; | |
| 14 | 15 | import com.bsth.entity.mcy_forms.Executionrate; |
| 15 | 16 | import com.bsth.entity.mcy_forms.Linepasswengerflow; |
| 16 | 17 | import com.bsth.entity.mcy_forms.Operationservice; |
| ... | ... | @@ -112,4 +113,12 @@ public class MCY_FormsController { |
| 112 | 113 | |
| 113 | 114 | return formsService.allline(map); |
| 114 | 115 | } |
| 116 | + | |
| 117 | + // 营运线路名称统计表 | |
| 118 | + @RequestMapping(value = "/daily", method = RequestMethod.POST) | |
| 119 | + public List<Daily> daily(@RequestParam Map<String, Object> map) { | |
| 120 | + | |
| 121 | + return formsService.daily(map); | |
| 122 | + } | |
| 123 | + | |
| 115 | 124 | } | ... | ... |
src/main/java/com/bsth/controller/oil/YlbController.java
| ... | ... | @@ -3,7 +3,9 @@ package com.bsth.controller.oil; |
| 3 | 3 | import java.text.ParseException; |
| 4 | 4 | import java.text.SimpleDateFormat; |
| 5 | 5 | import java.util.ArrayList; |
| 6 | +import java.util.Calendar; | |
| 6 | 7 | import java.util.Date; |
| 8 | +import java.util.GregorianCalendar; | |
| 7 | 9 | import java.util.HashMap; |
| 8 | 10 | import java.util.Iterator; |
| 9 | 11 | import java.util.List; |
| ... | ... | @@ -107,8 +109,16 @@ public class YlbController extends BaseController<Ylb, Integer>{ |
| 107 | 109 | try { |
| 108 | 110 | String rq=map.get("rq").toString(); |
| 109 | 111 | if(!(rq=="")){ |
| 112 | + | |
| 110 | 113 | SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); |
| 111 | - map.put("rq_eq", sdf.parse(rq)); | |
| 114 | + Calendar calendar = new GregorianCalendar(); | |
| 115 | + calendar.setTime(sdf.parse(rq)); | |
| 116 | + calendar.add(calendar.DATE,1); | |
| 117 | + Date date=calendar.getTime(); | |
| 118 | + map.put("rq_ge", rq); | |
| 119 | + map.put("rq_le", sdf.format(date)); | |
| 120 | + System.out.println(rq); | |
| 121 | + System.out.println(sdf.format(date)); | |
| 112 | 122 | } |
| 113 | 123 | } catch (ParseException e) { |
| 114 | 124 | // TODO Auto-generated catch block | ... | ... |
src/main/java/com/bsth/controller/realcontrol/ScheduleRealInfoController.java
| ... | ... | @@ -131,13 +131,13 @@ public class ScheduleRealInfoController extends BaseController<ScheduleRealInfo, |
| 131 | 131 | * @Title: adjust @Description: TODO(调整人车) @param @param id |
| 132 | 132 | * 班次ID @param @param nbbm 内部编码 @param @param jsy 驾驶员 @param @param spy |
| 133 | 133 | * 售票员 @throws |
| 134 | - */ | |
| 134 | + | |
| 135 | 135 | @RequestMapping(value = "/adjust", method = RequestMethod.POST) |
| 136 | 136 | public Map<String, Object> adjust(@RequestParam Long id, String nbbm, String jsy, |
| 137 | 137 | String spy, Integer revertLine, Integer borrowLine, String borrowTimeStr, String revertTimeStr) { |
| 138 | 138 | return scheduleRealInfoService.adjust(id, nbbm, jsy, spy, revertLine, borrowLine, borrowTimeStr, revertTimeStr); |
| 139 | 139 | } |
| 140 | - | |
| 140 | + */ | |
| 141 | 141 | /** |
| 142 | 142 | * |
| 143 | 143 | * @Title: realOutAdjust |
| ... | ... | @@ -292,8 +292,9 @@ public class ScheduleRealInfoController extends BaseController<ScheduleRealInfo, |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | @RequestMapping(value = "/queryUserInfo") |
| 295 | - public List<ScheduleRealInfo> queryUserInfo(@RequestParam String line, @RequestParam String date) { | |
| 296 | - return scheduleRealInfoService.queryUserInfo(line, date); | |
| 295 | + public List<ScheduleRealInfo> queryUserInfo(@RequestParam String line, | |
| 296 | + @RequestParam String date,@RequestParam String state) { | |
| 297 | + return scheduleRealInfoService.queryUserInfo(line, date,state); | |
| 297 | 298 | } |
| 298 | 299 | |
| 299 | 300 | @RequestMapping(value = "/exportWaybill") |
| ... | ... | @@ -309,8 +310,8 @@ public class ScheduleRealInfoController extends BaseController<ScheduleRealInfo, |
| 309 | 310 | |
| 310 | 311 | @RequestMapping(value = "/historyMessage") |
| 311 | 312 | public List<Object[]> historyMessage(@RequestParam String line, @RequestParam String date, |
| 312 | - @RequestParam String code) { | |
| 313 | - return scheduleRealInfoService.historyMessage(line, date, code); | |
| 313 | + @RequestParam String code, @RequestParam String type) { | |
| 314 | + return scheduleRealInfoService.historyMessage(line, date, code, type); | |
| 314 | 315 | } |
| 315 | 316 | |
| 316 | 317 | @RequestMapping(value="/findLine") |
| ... | ... | @@ -331,14 +332,14 @@ public class ScheduleRealInfoController extends BaseController<ScheduleRealInfo, |
| 331 | 332 | |
| 332 | 333 | @RequestMapping(value = "/account") |
| 333 | 334 | public List<Map<String,Object>> account(@RequestParam String line, @RequestParam String date, |
| 334 | - @RequestParam String code,@RequestParam String xlName) { | |
| 335 | - return scheduleRealInfoService.account(line, date, code,xlName); | |
| 335 | + @RequestParam String code,@RequestParam String xlName, @RequestParam String type) { | |
| 336 | + return scheduleRealInfoService.account(line, date, code, xlName, type); | |
| 336 | 337 | } |
| 337 | 338 | |
| 338 | 339 | @RequestMapping(value = "/correctForm") |
| 339 | 340 | public List<ScheduleRealInfo> correctForm(@RequestParam String line, @RequestParam String startDate, |
| 340 | - @RequestParam String endDate,@RequestParam String lpName,@RequestParam String code) { | |
| 341 | - return scheduleRealInfoService.correctForm(line, startDate, endDate, lpName, code); | |
| 341 | + @RequestParam String endDate, @RequestParam String lpName, @RequestParam String code, @RequestParam String type) { | |
| 342 | + return scheduleRealInfoService.correctForm(line, startDate, endDate, lpName, code, type); | |
| 342 | 343 | } |
| 343 | 344 | /** |
| 344 | 345 | * @Title queryListWaybill | ... | ... |
src/main/java/com/bsth/controller/realcontrol/SignalStateController.java
0 → 100644
| 1 | +package com.bsth.controller.realcontrol; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata.SignalStateData; | |
| 4 | +import com.bsth.data.gpsdata.arrival.entity.SignalState; | |
| 5 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 6 | +import org.springframework.web.bind.annotation.RequestMapping; | |
| 7 | +import org.springframework.web.bind.annotation.RequestParam; | |
| 8 | +import org.springframework.web.bind.annotation.RestController; | |
| 9 | + | |
| 10 | +import java.util.List; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * Created by panzhao on 2016/12/30. | |
| 14 | + */ | |
| 15 | +@RestController | |
| 16 | +@RequestMapping("signalState") | |
| 17 | +public class SignalStateController { | |
| 18 | + | |
| 19 | + @Autowired | |
| 20 | + SignalStateData signalStateData; | |
| 21 | + | |
| 22 | + @RequestMapping("/multi") | |
| 23 | + public List<SignalState> findByMultiLine(@RequestParam String idx){ | |
| 24 | + return signalStateData.get(idx); | |
| 25 | + } | |
| 26 | +} | ... | ... |
src/main/java/com/bsth/controller/report/ReportController.java
| ... | ... | @@ -50,23 +50,33 @@ public class ReportController { |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | @RequestMapping(value = "/tbodyTime1", method = RequestMethod.GET) |
| 53 | - public Map<String, Object> tbodyTime1(@RequestParam String line,@RequestParam String date) { | |
| 54 | - return service.tbodyTime1(line, date); | |
| 53 | + public Map<String, Object> tbodyTime1(@RequestParam String line,@RequestParam String ttinfo) { | |
| 54 | + return service.tbodyTime1(line, ttinfo); | |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | @RequestMapping(value = "/tbodyTime2", method = RequestMethod.GET) |
| 58 | - public Map<String, Object> tbodyTime2(@RequestParam String line,@RequestParam String date) { | |
| 59 | - return service.tbodyTime2(line, date); | |
| 58 | + public Map<String, Object> tbodyTime2(@RequestParam String line,@RequestParam String ttinfo) { | |
| 59 | + return service.tbodyTime2(line, ttinfo); | |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | @RequestMapping(value = "/tbodyTime3", method = RequestMethod.GET) |
| 63 | - public List<Map<String, Object>> tbodyTime3(@RequestParam String line,@RequestParam String date) { | |
| 64 | - return service.tbodyTime3(line, date); | |
| 63 | + public List<Map<String, Object>> tbodyTime3(@RequestParam String line,@RequestParam String ttinfo) { | |
| 64 | + return service.tbodyTime3(line, ttinfo); | |
| 65 | + } | |
| 66 | + | |
| 67 | + @RequestMapping(value = "/tbodyTime4", method = RequestMethod.GET) | |
| 68 | + public List<Map<String, Object>> tbodyTime4(@RequestParam String line,@RequestParam String ttinfo) { | |
| 69 | + return service.tbodyTime4(line, ttinfo); | |
| 65 | 70 | } |
| 66 | 71 | |
| 67 | 72 | @RequestMapping(value = "/tbodyTime5", method = RequestMethod.GET) |
| 68 | - public List<Map<String, Object>> tbodyTime5(@RequestParam String line,@RequestParam String date) { | |
| 69 | - return service.tbodyTime5(line, date); | |
| 73 | + public List<Map<String, Object>> tbodyTime5(@RequestParam String line,@RequestParam String ttinfo) { | |
| 74 | + return service.tbodyTime5(line, ttinfo); | |
| 75 | + } | |
| 76 | + | |
| 77 | + @RequestMapping(value="/getTtinfo", method = RequestMethod.GET) | |
| 78 | + public List<Map<String,Object>> getTtinfo(@RequestParam Map<String, Object> map){ | |
| 79 | + return service.getTtinfo(map); | |
| 70 | 80 | } |
| 71 | 81 | |
| 72 | 82 | } | ... | ... |
src/main/java/com/bsth/controller/sys/DutyEmployeeController.java
0 → 100644
| 1 | +package com.bsth.controller.sys; | |
| 2 | + | |
| 3 | +import com.bsth.controller.BaseController; | |
| 4 | +import com.bsth.entity.sys.DutyEmployee; | |
| 5 | +import com.bsth.service.sys.DutyEmployeeService; | |
| 6 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 7 | +import org.springframework.web.bind.annotation.RequestMapping; | |
| 8 | +import org.springframework.web.bind.annotation.RequestParam; | |
| 9 | +import org.springframework.web.bind.annotation.RestController; | |
| 10 | + | |
| 11 | +import java.util.List; | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * Created by panzhao on 2017/1/5. | |
| 15 | + */ | |
| 16 | +@RestController | |
| 17 | +@RequestMapping("dutyEmployee") | |
| 18 | +public class DutyEmployeeController extends BaseController<DutyEmployee, Long> { | |
| 19 | + | |
| 20 | + @Autowired | |
| 21 | + DutyEmployeeService dutyEmployeeService; | |
| 22 | + | |
| 23 | + @RequestMapping(value = "queryByLineAndTime") | |
| 24 | + public List<DutyEmployee> getDutyEmployee(@RequestParam String lineCode, @RequestParam String startTime, @RequestParam String endTime) { | |
| 25 | + return dutyEmployeeService.getDutyEmployee(lineCode, startTime, endTime); | |
| 26 | + } | |
| 27 | +} | ... | ... |
src/main/java/com/bsth/data/BasicData.java
| 1 | 1 | package com.bsth.data; |
| 2 | 2 | |
| 3 | 3 | import com.bsth.Application; |
| 4 | -import com.bsth.data.gpsdata.analyse.GeoCacheData; | |
| 4 | +import com.bsth.data.gpsdata.arrival.GeoCacheData; | |
| 5 | 5 | import com.bsth.entity.*; |
| 6 | 6 | import com.bsth.entity.schedule.CarConfigInfo; |
| 7 | 7 | import com.bsth.repository.*; |
| ... | ... | @@ -26,12 +26,12 @@ import java.util.concurrent.TimeUnit; |
| 26 | 26 | */ |
| 27 | 27 | @Component |
| 28 | 28 | public class BasicData implements CommandLineRunner { |
| 29 | - | |
| 30 | - //公司代码和公司名对照(K: 公司编码,V:公司名) | |
| 31 | - public static Map<String, String> businessCodeNameMap; | |
| 32 | - | |
| 33 | - //分公司公司代码和分公司公司名对照(K: 公司编码+分公司编码,V:分公司公司名) | |
| 34 | - public static Map<String, String> businessFgsCodeNameMap; | |
| 29 | + | |
| 30 | + //公司代码和公司名对照(K: 公司编码,V:公司名) | |
| 31 | + public static Map<String, String> businessCodeNameMap; | |
| 32 | + | |
| 33 | + //分公司公司代码和分公司公司名对照(K: 公司编码+分公司编码,V:分公司公司名) | |
| 34 | + public static Map<String, String> businessFgsCodeNameMap; | |
| 35 | 35 | |
| 36 | 36 | //设备号和车辆自编号 (K: 设备编码 ,V:车辆自编号) |
| 37 | 37 | public static BiMap<String, String> deviceId2NbbmMap; |
| ... | ... | @@ -39,27 +39,21 @@ public class BasicData implements CommandLineRunner { |
| 39 | 39 | //车辆自编号和公司代码对照 (K: 车辆自编号 ,V:公司代码) |
| 40 | 40 | public static Map<String, String> nbbm2CompanyCodeMap; |
| 41 | 41 | |
| 42 | - //站点编码和名称对照,包括停车场 (K: 站点编码 ,V:站点名称) | |
| 42 | + //站点编码和名称对照,包括停车场 (K: lineCode_updown_stationCode ,V:站点名称) | |
| 43 | 43 | public static Map<String, String> stationCode2NameMap; |
| 44 | 44 | |
| 45 | 45 | //线路起终点对照(线路编码_上下行_起终点) 1024_0_B (1024上行起点) |
| 46 | - public static Map<String, String> lineSEPointMap; | |
| 46 | + //public static Map<String, String> lineSEPointMap; | |
| 47 | 47 | |
| 48 | 48 | //车辆和线路对照 |
| 49 | 49 | public static Map<String, Line> nbbm2LineMap; |
| 50 | 50 | |
| 51 | - //线路和用户对照 用于webSocket定向推送消息(用户进入线调时写入数据) | |
| 52 | - //public static TreeMultimap<String, String> lineCode2SocketUserMap = TreeMultimap.create(); | |
| 53 | - | |
| 54 | 51 | //线路ID和code 对照 |
| 55 | 52 | public static BiMap<Integer, String> lineId2CodeMap; |
| 56 | 53 | |
| 57 | 54 | //线路编码和名称对照 |
| 58 | 55 | public static Map<String, String> lineCode2NameMap; |
| 59 | 56 | |
| 60 | - //线路编码_站点编码 == 0|1 上下行 | |
| 61 | - //public static Map<String, Integer> lineStationUpDownMap; | |
| 62 | - | |
| 63 | 57 | //停车场 |
| 64 | 58 | public static List<String> parkCodeList; |
| 65 | 59 | |
| ... | ... | @@ -77,7 +71,7 @@ public class BasicData implements CommandLineRunner { |
| 77 | 71 | public static Map<String, String> allPerson; |
| 78 | 72 | |
| 79 | 73 | //站点名和运管处编号 对照 |
| 80 | - public static Map<String,Integer> stationName2YgcNumber; | |
| 74 | + public static Map<String, Integer> stationName2YgcNumber; | |
| 81 | 75 | |
| 82 | 76 | |
| 83 | 77 | static Logger logger = LoggerFactory.getLogger(BasicData.class); |
| ... | ... | @@ -90,6 +84,10 @@ public class BasicData implements CommandLineRunner { |
| 90 | 84 | Application.mainServices.scheduleWithFixedDelay(dataLoader, 2, 2, TimeUnit.HOURS); |
| 91 | 85 | } |
| 92 | 86 | |
| 87 | + public static String getStationNameByCode(String code, String prefix){ | |
| 88 | + String name = stationCode2NameMap.get(code); | |
| 89 | + return name != null? name: stationCode2NameMap.get(prefix + code); | |
| 90 | + } | |
| 93 | 91 | |
| 94 | 92 | @Component |
| 95 | 93 | public static class BasicDataLoader extends Thread { |
| ... | ... | @@ -114,7 +112,7 @@ public class BasicData implements CommandLineRunner { |
| 114 | 112 | |
| 115 | 113 | @Autowired |
| 116 | 114 | PersonnelRepository personnelRepository; |
| 117 | - | |
| 115 | + | |
| 118 | 116 | @Autowired |
| 119 | 117 | BusinessRepository businessRepository; |
| 120 | 118 | |
| ... | ... | @@ -156,47 +154,24 @@ public class BasicData implements CommandLineRunner { |
| 156 | 154 | return 0; |
| 157 | 155 | } |
| 158 | 156 | |
| 159 | - | |
| 160 | -/* private void loadStationRouteInfo() { | |
| 161 | - Iterator<StationRoute> iterator = stationRouteRepository.findAllEffective().iterator(); | |
| 162 | - | |
| 163 | - Map<String, String> sePointMap = new HashMap<>(); | |
| 164 | - //lineSEPointMap | |
| 165 | - Map<String, Integer> map = new HashMap<>(); | |
| 166 | - | |
| 167 | - StationRoute route; | |
| 168 | - while (iterator.hasNext()) { | |
| 169 | - route = iterator.next(); | |
| 170 | - map.put(route.getLineCode() + "_" + route.getStationCode(), route.getDirections()); | |
| 171 | - | |
| 172 | - if (route.getStationMark() != null && | |
| 173 | - (route.getStationMark().equals("B") || route.getStationMark().equals("E"))) { | |
| 174 | - sePointMap.put(route.getLineCode() + "_" | |
| 175 | - + route.getDirections() | |
| 176 | - + "_" + route.getStationMark(), route.getStationCode()); | |
| 177 | - } | |
| 178 | - } | |
| 179 | - lineStationUpDownMap = map; | |
| 180 | - lineSEPointMap = sePointMap; | |
| 181 | - }*/ | |
| 182 | - | |
| 183 | 157 | /** |
| 184 | 158 | * loadBusinessInfo |
| 185 | 159 | * (公司代码公司名对照) |
| 186 | 160 | */ |
| 187 | - public void loadBusinessInfo(){ | |
| 188 | - Map<String, String> businessMap=new HashMap<String,String>(); | |
| 189 | - Map<String, String> businessFgsMap=new HashMap<String,String>(); | |
| 190 | - Iterator<Business> busIter=businessRepository.findAll().iterator(); | |
| 191 | - Business t; | |
| 192 | - while(busIter.hasNext()){ | |
| 193 | - t=busIter.next(); | |
| 194 | - businessMap.put(t.getBusinessCode(), t.getBusinessName()); | |
| 195 | - businessFgsMap.put(t.getBusinessCode()+"_"+t.getUpCode(), t.getBusinessName()); | |
| 196 | - } | |
| 197 | - businessCodeNameMap=businessMap; | |
| 198 | - businessFgsCodeNameMap=businessFgsMap; | |
| 161 | + public void loadBusinessInfo() { | |
| 162 | + Map<String, String> businessMap = new HashMap<String, String>(); | |
| 163 | + Map<String, String> businessFgsMap = new HashMap<String, String>(); | |
| 164 | + Iterator<Business> busIter = businessRepository.findAll().iterator(); | |
| 165 | + Business t; | |
| 166 | + while (busIter.hasNext()) { | |
| 167 | + t = busIter.next(); | |
| 168 | + businessMap.put(t.getBusinessCode(), t.getBusinessName()); | |
| 169 | + businessFgsMap.put(t.getBusinessCode() + "_" + t.getUpCode(), t.getBusinessName()); | |
| 170 | + } | |
| 171 | + businessCodeNameMap = businessMap; | |
| 172 | + businessFgsCodeNameMap = businessFgsMap; | |
| 199 | 173 | } |
| 174 | + | |
| 200 | 175 | /** |
| 201 | 176 | * @Title: loadDeviceInfo |
| 202 | 177 | * @Description: TODO(加载设备相关信息) |
| ... | ... | @@ -223,13 +198,13 @@ public class BasicData implements CommandLineRunner { |
| 223 | 198 | */ |
| 224 | 199 | public void loadStationInfo() { |
| 225 | 200 | Map<String, String> stationCode2Name = new HashMap<>(); |
| 226 | - Iterator<Station> iterator = stationRepository.findAll().iterator(); | |
| 227 | - //站点 | |
| 228 | - Station station; | |
| 201 | + Iterator<StationRoute> iterator = stationRouteRepository.findAll().iterator(); | |
| 202 | + StationRoute sroute; | |
| 229 | 203 | while (iterator.hasNext()) { |
| 230 | - station = iterator.next(); | |
| 231 | - stationCode2Name.put(station.getStationCod(), station.getStationName()); | |
| 204 | + sroute = iterator.next(); | |
| 205 | + stationCode2Name.put(sroute.getLineCode() + "_" + sroute.getDirections() + "_" + sroute.getStationCode(), sroute.getStationName()); | |
| 232 | 206 | } |
| 207 | + | |
| 233 | 208 | //停车场 |
| 234 | 209 | Iterator<CarPark> iterator2 = carParkRepository.findAll().iterator(); |
| 235 | 210 | |
| ... | ... | @@ -266,7 +241,7 @@ public class BasicData implements CommandLineRunner { |
| 266 | 241 | * @Title: loadLineInfo |
| 267 | 242 | * @Description: TODO(加载线路相关信息) |
| 268 | 243 | */ |
| 269 | - public void loadLineInfo(){ | |
| 244 | + public void loadLineInfo() { | |
| 270 | 245 | Iterator<Line> iterator = lineRepository.findAll().iterator(); |
| 271 | 246 | |
| 272 | 247 | Line line; |
| ... | ... | @@ -276,36 +251,36 @@ public class BasicData implements CommandLineRunner { |
| 276 | 251 | Map<String, String> code2SHcode = new HashMap<String, String>(); |
| 277 | 252 | Map<String, Integer> tempStationName2YgcNumber = new HashMap<String, Integer>(); |
| 278 | 253 | |
| 279 | - while(iterator.hasNext()){ | |
| 254 | + while (iterator.hasNext()) { | |
| 280 | 255 | line = iterator.next(); |
| 281 | 256 | biMap.put(line.getId(), line.getLineCode()); |
| 282 | 257 | code2name.put(line.getLineCode(), line.getName()); |
| 283 | - id2SHcode.put(line.getId(),line.getShanghaiLinecode()); | |
| 258 | + id2SHcode.put(line.getId(), line.getShanghaiLinecode()); | |
| 284 | 259 | code2SHcode.put(line.getLineCode(), line.getShanghaiLinecode()); |
| 285 | 260 | |
| 286 | 261 | /** |
| 287 | 262 | * 加载运管处的站点及序号 |
| 288 | 263 | * 上行从1开始,下行顺序续编 |
| 289 | 264 | |
| 290 | - List<Object[]> ygcLines = stationRouteRepository.findAllLineWithYgc(); | |
| 291 | - if(ygcLines != null && ygcLines.size() > 0){ | |
| 292 | - int size = ygcLines.size(); | |
| 293 | - Object[] tempArray ; | |
| 294 | - int num = 1; | |
| 295 | - String key; | |
| 296 | - String lineCode = ""; | |
| 297 | - for (int i = 0; i < size; i ++){ | |
| 298 | - tempArray = ygcLines.get(i); | |
| 299 | - if(lineCode.equals("")){ | |
| 300 | - lineCode = tempArray[0]+""; | |
| 301 | - }else if(!lineCode.equals(tempArray[0]+"")){ | |
| 302 | - num = 1; | |
| 303 | - lineCode = tempArray[0]+""; | |
| 304 | - } | |
| 305 | - key = tempArray[0] + "_"+tempArray[1] + "_"+tempArray[2]; | |
| 306 | - tempStationName2YgcNumber.put(key,num++); | |
| 307 | - } | |
| 308 | - }*/ | |
| 265 | + List<Object[]> ygcLines = stationRouteRepository.findAllLineWithYgc(); | |
| 266 | + if(ygcLines != null && ygcLines.size() > 0){ | |
| 267 | + int size = ygcLines.size(); | |
| 268 | + Object[] tempArray ; | |
| 269 | + int num = 1; | |
| 270 | + String key; | |
| 271 | + String lineCode = ""; | |
| 272 | + for (int i = 0; i < size; i ++){ | |
| 273 | + tempArray = ygcLines.get(i); | |
| 274 | + if(lineCode.equals("")){ | |
| 275 | + lineCode = tempArray[0]+""; | |
| 276 | + }else if(!lineCode.equals(tempArray[0]+"")){ | |
| 277 | + num = 1; | |
| 278 | + lineCode = tempArray[0]+""; | |
| 279 | + } | |
| 280 | + key = tempArray[0] + "_"+tempArray[1] + "_"+tempArray[2]; | |
| 281 | + tempStationName2YgcNumber.put(key,num++); | |
| 282 | + } | |
| 283 | + }*/ | |
| 309 | 284 | } |
| 310 | 285 | |
| 311 | 286 | lineId2CodeMap = biMap; | ... | ... |
src/main/java/com/bsth/data/LineConfigData.java
| 1 | 1 | package com.bsth.data; |
| 2 | 2 | |
| 3 | -import java.util.Collection; | |
| 4 | -import java.util.HashMap; | |
| 5 | -import java.util.Iterator; | |
| 6 | -import java.util.Map; | |
| 7 | -import java.util.Set; | |
| 8 | - | |
| 9 | -import org.slf4j.Logger; | |
| 10 | -import org.slf4j.LoggerFactory; | |
| 11 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 12 | -import org.springframework.boot.CommandLineRunner; | |
| 13 | -import org.springframework.stereotype.Component; | |
| 14 | - | |
| 15 | 3 | import com.bsth.entity.Line; |
| 16 | 4 | import com.bsth.entity.realcontrol.D80ReplyTemp; |
| 17 | 5 | import com.bsth.entity.realcontrol.LineConfig; |
| 18 | 6 | import com.bsth.oplog.normal.OpLogger; |
| 19 | 7 | import com.bsth.service.LineService; |
| 20 | 8 | import com.bsth.service.realcontrol.LineConfigService; |
| 9 | +import org.slf4j.Logger; | |
| 10 | +import org.slf4j.LoggerFactory; | |
| 11 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 12 | +import org.springframework.boot.CommandLineRunner; | |
| 13 | +import org.springframework.core.annotation.Order; | |
| 14 | +import org.springframework.stereotype.Component; | |
| 15 | + | |
| 16 | +import java.util.*; | |
| 21 | 17 | |
| 22 | 18 | /** |
| 23 | 19 | * |
| ... | ... | @@ -28,6 +24,7 @@ import com.bsth.service.realcontrol.LineConfigService; |
| 28 | 24 | * |
| 29 | 25 | */ |
| 30 | 26 | @Component |
| 27 | +@Order(value = 2) | |
| 31 | 28 | public class LineConfigData implements CommandLineRunner { |
| 32 | 29 | |
| 33 | 30 | Logger logger = LoggerFactory.getLogger(this.getClass()); |
| ... | ... | @@ -92,7 +89,7 @@ public class LineConfigData implements CommandLineRunner { |
| 92 | 89 | //出场时间类型 |
| 93 | 90 | conf.setOutConfig(1); |
| 94 | 91 | //进场时间类型 |
| 95 | - conf.setInConfig(1); | |
| 92 | + //conf.setInConfig(1); | |
| 96 | 93 | //短语模板 |
| 97 | 94 | conf.setPhraseTemps(""); |
| 98 | 95 | //调度指令模板 | ... | ... |
src/main/java/com/bsth/data/arrival/ArrivalData_GPS.java
| 1 | 1 | package com.bsth.data.arrival; |
| 2 | 2 | |
| 3 | -import com.bsth.data.match.Arrival2Schedule; | |
| 4 | 3 | import com.bsth.data.schedule.DayOfSchedule; |
| 5 | 4 | import com.google.common.collect.ArrayListMultimap; |
| 6 | 5 | import com.google.common.collect.ListMultimap; |
| ... | ... | @@ -59,7 +58,7 @@ public class ArrivalData_GPS implements CommandLineRunner{ |
| 59 | 58 | |
| 60 | 59 | @Override |
| 61 | 60 | public void run() { |
| 62 | - try{ | |
| 61 | + /*try{ | |
| 63 | 62 | logger.info("开始加载到离站数据, " + System.currentTimeMillis()); |
| 64 | 63 | List<ArrivalEntity> arrSets = dataLoader.load(); |
| 65 | 64 | if(null == arrSets || arrSets.size() == 0) |
| ... | ... | @@ -86,7 +85,7 @@ public class ArrivalData_GPS implements CommandLineRunner{ |
| 86 | 85 | Arrival2Schedule.start(carSet); |
| 87 | 86 | }catch(Exception e){ |
| 88 | 87 | logger.error("", e); |
| 89 | - } | |
| 88 | + }*/ | |
| 90 | 89 | } |
| 91 | 90 | } |
| 92 | 91 | ... | ... |
src/main/java/com/bsth/data/forecast/ForecastRealServer.java
| 1 | 1 | package com.bsth.data.forecast; |
| 2 | 2 | |
| 3 | +import com.bsth.Application; | |
| 3 | 4 | import com.bsth.data.forecast.entity.ForecastResult; |
| 4 | 5 | import com.bsth.data.forecast.entity.ForecastResult.ForecastResultItem; |
| 5 | 6 | import com.bsth.data.forecast.entity.SimpleRoute; |
| ... | ... | @@ -20,6 +21,7 @@ import java.util.ArrayList; |
| 20 | 21 | import java.util.HashMap; |
| 21 | 22 | import java.util.List; |
| 22 | 23 | import java.util.Map; |
| 24 | +import java.util.concurrent.TimeUnit; | |
| 23 | 25 | |
| 24 | 26 | /** |
| 25 | 27 | * |
| ... | ... | @@ -58,7 +60,7 @@ public class ForecastRealServer implements CommandLineRunner { |
| 58 | 60 | @Override |
| 59 | 61 | public void run(String... arg0) throws Exception { |
| 60 | 62 | //2小时更新一次站点间耗时数据 |
| 61 | - //Application.mainServices.scheduleWithFixedDelay(dataLoader, 12, 120 * 60, TimeUnit.SECONDS); | |
| 63 | + Application.mainServices.scheduleWithFixedDelay(dataLoader, 12, 120 * 60, TimeUnit.SECONDS); | |
| 62 | 64 | } |
| 63 | 65 | |
| 64 | 66 | /** |
| ... | ... | @@ -86,7 +88,7 @@ public class ForecastRealServer implements CommandLineRunner { |
| 86 | 88 | //终点站 |
| 87 | 89 | String eStation = null; |
| 88 | 90 | //当前执行班次 |
| 89 | - ScheduleRealInfo sch = dayOfSchedule.execPlanMap().get(nbbm); | |
| 91 | + ScheduleRealInfo sch = dayOfSchedule.executeCurr(nbbm); | |
| 90 | 92 | if(null != sch) |
| 91 | 93 | eStation = sch.getZdzCode(); |
| 92 | 94 | ... | ... |
src/main/java/com/bsth/data/gpsdata/GpsEntity.java
| 1 | 1 | package com.bsth.data.gpsdata; |
| 2 | 2 | |
| 3 | -import com.bsth.data.gpsdata.analyse.StationRoute; | |
| 3 | +import com.bsth.data.gpsdata.arrival.entity.StationRoute; | |
| 4 | 4 | import com.fasterxml.jackson.annotation.JsonIgnore; |
| 5 | 5 | |
| 6 | 6 | /** |
| ... | ... | @@ -78,15 +78,15 @@ public class GpsEntity { |
| 78 | 78 | private boolean sEPoint; |
| 79 | 79 | */ |
| 80 | 80 | |
| 81 | - /** 站内 */ | |
| 82 | - private boolean instation; | |
| 81 | + /** 0: 站外 1:站内 2:场内 */ | |
| 82 | + private int instation; | |
| 83 | 83 | |
| 84 | 84 | /** 站点信息,站内时有值 */ |
| 85 | 85 | @JsonIgnore |
| 86 | 86 | private StationRoute station; |
| 87 | 87 | |
| 88 | 88 | /** 状态 */ |
| 89 | - private String state2; | |
| 89 | + private String signalState = "normal"; | |
| 90 | 90 | |
| 91 | 91 | public Integer getCompanyCode() { |
| 92 | 92 | return companyCode; |
| ... | ... | @@ -233,14 +233,6 @@ public class GpsEntity { |
| 233 | 233 | this.version = version; |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - public boolean isInstation() { | |
| 237 | - return instation; | |
| 238 | - } | |
| 239 | - | |
| 240 | - public void setInstation(boolean instation) { | |
| 241 | - this.instation = instation; | |
| 242 | - } | |
| 243 | - | |
| 244 | 236 | public StationRoute getStation() { |
| 245 | 237 | return station; |
| 246 | 238 | } |
| ... | ... | @@ -257,11 +249,19 @@ public class GpsEntity { |
| 257 | 249 | this.abnormal = abnormal; |
| 258 | 250 | } |
| 259 | 251 | |
| 260 | - public String getState2() { | |
| 261 | - return state2; | |
| 252 | + public String getSignalState() { | |
| 253 | + return signalState; | |
| 262 | 254 | } |
| 263 | 255 | |
| 264 | - public void setState2(String state2) { | |
| 265 | - this.state2 = state2; | |
| 256 | + public void setSignalState(String signalState) { | |
| 257 | + this.signalState = signalState; | |
| 258 | + } | |
| 259 | + | |
| 260 | + public int getInstation() { | |
| 261 | + return instation; | |
| 262 | + } | |
| 263 | + | |
| 264 | + public void setInstation(int instation) { | |
| 265 | + this.instation = instation; | |
| 266 | 266 | } |
| 267 | 267 | } | ... | ... |
src/main/java/com/bsth/data/gpsdata/GpsRealData.java
| ... | ... | @@ -2,10 +2,9 @@ package com.bsth.data.gpsdata; |
| 2 | 2 | |
| 3 | 3 | import com.alibaba.fastjson.JSON; |
| 4 | 4 | import com.alibaba.fastjson.JSONObject; |
| 5 | -import com.bsth.Application; | |
| 6 | 5 | import com.bsth.data.BasicData; |
| 7 | 6 | import com.bsth.data.forecast.ForecastRealServer; |
| 8 | -import com.bsth.data.gpsdata.analyse.GpsAnalyse; | |
| 7 | +import com.bsth.data.gpsdata.arrival.GpsRealAnalyse; | |
| 9 | 8 | import com.bsth.data.gpsdata.recovery.GpsDataRecovery; |
| 10 | 9 | import com.bsth.data.schedule.DayOfSchedule; |
| 11 | 10 | import com.bsth.entity.realcontrol.ScheduleRealInfo; |
| ... | ... | @@ -26,259 +25,219 @@ import org.springframework.stereotype.Component; |
| 26 | 25 | import java.io.BufferedReader; |
| 27 | 26 | import java.io.InputStreamReader; |
| 28 | 27 | import java.util.*; |
| 29 | -import java.util.concurrent.TimeUnit; | |
| 30 | 28 | |
| 31 | 29 | /** |
| 32 | - * | |
| 30 | + * @author PanZhao | |
| 33 | 31 | * @ClassName: GpsRealData |
| 34 | 32 | * @Description: TODO(实时GPS数据集合) |
| 35 | - * @author PanZhao | |
| 36 | 33 | * @date 2016年8月12日 下午2:04:41 |
| 37 | - * | |
| 38 | 34 | */ |
| 39 | 35 | @Component |
| 40 | -public class GpsRealData implements CommandLineRunner{ | |
| 41 | - | |
| 42 | - static Logger logger = LoggerFactory.getLogger(GpsRealData.class); | |
| 43 | - | |
| 44 | - private static Map<String, GpsEntity> gpsMap; | |
| 45 | - | |
| 46 | - //按线路分组设备号 | |
| 47 | - private static TreeMultimap<String, String> lineCode2Devices; | |
| 48 | - | |
| 49 | - // 网关数据接口地址 | |
| 50 | - private static String url; | |
| 51 | - | |
| 52 | - @Autowired | |
| 53 | - GpsDataLoader gpsDataLoader; | |
| 54 | - | |
| 55 | - @Autowired | |
| 56 | - DayOfSchedule dayOfSchedule; | |
| 57 | - | |
| 58 | - @Autowired | |
| 59 | - ForecastRealServer forecastRealServer; | |
| 60 | - | |
| 61 | - | |
| 62 | - | |
| 63 | - /** | |
| 64 | - * 构造函数 | |
| 65 | - */ | |
| 66 | - public GpsRealData(){ | |
| 67 | - gpsMap = new HashMap<>(); | |
| 68 | - lineCode2Devices = TreeMultimap.create(); | |
| 69 | - url = ConfigUtil.get("http.gps.real.url"); | |
| 70 | - } | |
| 71 | - | |
| 72 | - @Override | |
| 73 | - public void run(String... arg0) throws Exception { | |
| 74 | - logger.info("gpsDataLoader,20,6"); | |
| 75 | - Application.mainServices.scheduleWithFixedDelay(gpsDataLoader, 40, 20, TimeUnit.SECONDS); | |
| 76 | - } | |
| 77 | - | |
| 78 | - public GpsEntity add(GpsEntity gps) { | |
| 79 | - String device = gps.getDeviceId(); | |
| 80 | - GpsEntity old = gpsMap.get(device); | |
| 81 | - | |
| 82 | - //分析gps | |
| 83 | - if(isAvailable(gps) && (old == null || old.getTimestamp() != gps.getTimestamp())) | |
| 84 | - GpsAnalyse.start(gps); | |
| 85 | - | |
| 86 | - if(!StringUtils.isEmpty(gps.getStopNo())){ | |
| 87 | - //定时定距数据附带站点编码改变 | |
| 88 | - if(null == old || !gps.getStopNo().equals(old.getStopNo())){ | |
| 89 | - gps.setArrTime(gps.getTimestamp()); | |
| 90 | - //预测到达终点时间 | |
| 91 | - forecastRealServer.forecast(gps.getNbbm(), gps); | |
| 92 | - } | |
| 93 | - else{ | |
| 94 | - gps.setArrTime(old.getArrTime()); | |
| 95 | - //不预测, 重新计算终点时间 | |
| 96 | - gps.setExpectStopTime(forecastRealServer.expectStopTime(gps.getNbbm())); | |
| 97 | - } | |
| 98 | - } | |
| 99 | - | |
| 100 | - gpsMap.put(device, gps); | |
| 101 | - if(StringUtils.isNotBlank(gps.getLineId())) | |
| 102 | - lineCode2Devices.put(gps.getLineId(), device); | |
| 103 | - return gps; | |
| 104 | - } | |
| 105 | - | |
| 106 | - public boolean isAvailable(GpsEntity gps){ | |
| 107 | - return StringUtils.isNotEmpty(gps.getLineId()) && | |
| 108 | - dayOfSchedule.getCurrSchDate().containsKey(gps.getLineId()); | |
| 109 | - } | |
| 110 | - | |
| 111 | - /** | |
| 112 | - * | |
| 113 | - * @Title: get @Description: TODO(设备号获取GPS) | |
| 114 | - */ | |
| 115 | - public GpsEntity get(String deviceId) { | |
| 116 | - return gpsMap.get(deviceId); | |
| 117 | - } | |
| 118 | - | |
| 119 | - /** | |
| 120 | - * | |
| 121 | - * @Title: get @Description: TODO(线路编码获取GPS集合) @throws | |
| 122 | - */ | |
| 123 | - public List<GpsEntity> getByLine(String lineCode) { | |
| 124 | - NavigableSet<String> set = lineCode2Devices.get(lineCode); | |
| 125 | - | |
| 126 | - List<GpsEntity> rs = new ArrayList<>(); | |
| 127 | - GpsEntity gps; | |
| 128 | - ScheduleRealInfo sch; | |
| 129 | - for(String device : set){ | |
| 130 | - gps = gpsMap.get(device); | |
| 131 | - //过滤异常GPS数据 | |
| 132 | - if(gps.isAbnormal()) | |
| 133 | - continue; | |
| 134 | - | |
| 135 | - sch = dayOfSchedule.execPlanMap().get(gps.getNbbm()); | |
| 136 | - if(null != sch) | |
| 137 | - gps.setSchId(sch.getId()); | |
| 138 | - rs.add(gps); | |
| 139 | - } | |
| 140 | - | |
| 141 | - return rs; | |
| 142 | - } | |
| 143 | - | |
| 144 | - public List<GpsEntity> get(List<String> pArray){ | |
| 145 | - List<GpsEntity> list = new ArrayList<>(); | |
| 146 | - | |
| 147 | - for(String code : pArray) | |
| 148 | - list.addAll(getByLine(code)); | |
| 149 | - return list; | |
| 150 | - } | |
| 151 | - | |
| 152 | - public Set<String> allDevices(){ | |
| 153 | - return gpsMap.keySet(); | |
| 154 | - } | |
| 155 | - | |
| 156 | - public GpsEntity findByDeviceId(String deviceId) { | |
| 157 | - return gpsMap.get(deviceId); | |
| 158 | - } | |
| 159 | - | |
| 160 | - public Collection<GpsEntity> all(){ | |
| 161 | - return gpsMap.values(); | |
| 162 | - } | |
| 163 | - | |
| 164 | - public void remove(String device){ | |
| 165 | - gpsMap.remove(device); | |
| 166 | - } | |
| 167 | - @Component | |
| 168 | - public static class GpsDataLoader extends Thread{ | |
| 169 | - | |
| 170 | - Logger logger = LoggerFactory.getLogger(GpsDataLoader.class); | |
| 171 | - | |
| 172 | - @Autowired | |
| 173 | - GpsRealData gpsRealData; | |
| 174 | - | |
| 175 | - @Override | |
| 176 | - public void run() { | |
| 177 | - try{ | |
| 178 | - //如果正在恢复数据 | |
| 179 | - if(GpsDataRecovery.run){ | |
| 180 | - return; | |
| 181 | - } | |
| 182 | - | |
| 183 | - load(); | |
| 184 | - }catch(Exception e){ | |
| 185 | - logger.error("", e); | |
| 186 | - } | |
| 187 | - } | |
| 188 | - | |
| 189 | - public void load() throws Exception { | |
| 190 | - List<GpsEntity> list = new ArrayList<>(); | |
| 191 | - CloseableHttpClient httpClient = null; | |
| 192 | - CloseableHttpResponse response = null; | |
| 193 | - try { | |
| 194 | - httpClient = HttpClients.createDefault(); | |
| 195 | - HttpGet get = new HttpGet(url); | |
| 196 | - | |
| 197 | - response = httpClient.execute(get); | |
| 198 | - | |
| 199 | - HttpEntity entity = response.getEntity(); | |
| 200 | - if (null != entity) { | |
| 201 | - // 返回数据量比较大,建议以流的形式读取 | |
| 202 | - BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent())); | |
| 203 | - StringBuffer stringBuffer = new StringBuffer(); | |
| 204 | - String str = ""; | |
| 205 | - while ((str = br.readLine()) != null) | |
| 206 | - stringBuffer.append(str); | |
| 207 | - | |
| 208 | - JSONObject jsonObj = JSON.parseObject(stringBuffer.toString()); | |
| 209 | - | |
| 210 | - if (jsonObj != null) | |
| 211 | - list = JSON.parseArray(jsonObj.getString("data"), GpsEntity.class); | |
| 212 | - | |
| 213 | - String nbbm; | |
| 214 | - for(GpsEntity gps : list){ | |
| 215 | - //没有设备号 | |
| 216 | - if(StringUtils.isBlank(gps.getDeviceId())) | |
| 217 | - continue; | |
| 218 | - | |
| 219 | - nbbm = BasicData.deviceId2NbbmMap.get(gps.getDeviceId()); | |
| 220 | - if(StringUtils.isBlank(nbbm)) | |
| 221 | - gps.setAbnormal(true);//标记为异常数据 | |
| 222 | - else | |
| 223 | - gps.setNbbm(nbbm); | |
| 224 | - | |
| 225 | - gps.setStationName(BasicData.stationCode2NameMap.get(gps.getStopNo())); | |
| 226 | - gpsRealData.add(gps); | |
| 227 | - | |
| 228 | - //纠正走向 | |
| 229 | - //correctUpdown(gps); | |
| 230 | - } | |
| 231 | - } else | |
| 232 | - logger.error("result is null"); | |
| 233 | - } catch(Exception e){ | |
| 234 | - logger.error("", e); | |
| 235 | - } | |
| 236 | - finally { | |
| 237 | - if (null != httpClient) | |
| 238 | - httpClient.close(); | |
| 239 | - if(null != response) | |
| 240 | - response.close(); | |
| 241 | - } | |
| 242 | - } | |
| 243 | - | |
| 244 | - /** | |
| 245 | - * 是否是起终点 | |
| 246 | - * @param gps | |
| 247 | - * @return | |
| 248 | - | |
| 249 | - public boolean isSEPoint(GpsEntity gps){ | |
| 250 | - String key = gps.getLineId()+"_"+gps.getUpDown()+"_" | |
| 251 | - ,stationCode; | |
| 252 | - | |
| 253 | - if(BasicData.lineSEPointMap.containsKey(key+"B")){ | |
| 254 | - stationCode = BasicData.lineSEPointMap.get(key+"B"); | |
| 255 | - if(gps.getStopNo().equals(stationCode)){ | |
| 256 | - gps.setsEPoint(true); | |
| 257 | - return true; | |
| 258 | - } | |
| 259 | - } | |
| 260 | - | |
| 261 | - if(BasicData.lineSEPointMap.containsKey(key+"E")){ | |
| 262 | - stationCode = BasicData.lineSEPointMap.get(key+"E"); | |
| 263 | - if(gps.getStopNo().equals(stationCode)){ | |
| 264 | - gps.setsEPoint(true); | |
| 265 | - return true; | |
| 266 | - } | |
| 267 | - } | |
| 268 | - return false; | |
| 269 | - }*/ | |
| 270 | - | |
| 271 | - /** | |
| 272 | - * 纠正上下行 | |
| 273 | - * @param gps | |
| 274 | - | |
| 275 | - public void correctUpdown(GpsEntity gps){ | |
| 276 | - Integer updown=BasicData.lineStationUpDownMap.get(gps.getLineId()+"_"+gps.getStopNo()); | |
| 277 | - if(updown != null && !updown.equals(gps.getUpDown())) | |
| 278 | - gps.setUpDown(updown); | |
| 279 | - | |
| 280 | - if(isSEPoint(gps)) | |
| 281 | - return; | |
| 282 | - }*/ | |
| 283 | - } | |
| 284 | -} | |
| 36 | +public class GpsRealData implements CommandLineRunner { | |
| 37 | + | |
| 38 | + static Logger logger = LoggerFactory.getLogger(GpsRealData.class); | |
| 39 | + | |
| 40 | + private static Map<String, GpsEntity> gpsMap; | |
| 41 | + | |
| 42 | + //按线路分组设备号 | |
| 43 | + private static TreeMultimap<String, String> lineCode2Devices; | |
| 44 | + | |
| 45 | + // 网关数据接口地址 | |
| 46 | + private static String url; | |
| 47 | + | |
| 48 | + @Autowired | |
| 49 | + GpsDataLoader gpsDataLoader; | |
| 50 | + | |
| 51 | + @Autowired | |
| 52 | + DayOfSchedule dayOfSchedule; | |
| 53 | + | |
| 54 | + @Autowired | |
| 55 | + ForecastRealServer forecastRealServer; | |
| 56 | + | |
| 57 | + /** | |
| 58 | + * 构造函数 | |
| 59 | + */ | |
| 60 | + public GpsRealData() { | |
| 61 | + gpsMap = new HashMap<>(); | |
| 62 | + lineCode2Devices = TreeMultimap.create(); | |
| 63 | + url = ConfigUtil.get("http.gps.real.url"); | |
| 64 | + } | |
| 65 | + | |
| 66 | + @Override | |
| 67 | + public void run(String... arg0) throws Exception { | |
| 68 | + logger.info("gpsDataLoader,20,5"); | |
| 69 | + //Application.mainServices.scheduleWithFixedDelay(gpsDataLoader, 20, 5, TimeUnit.SECONDS); | |
| 70 | + } | |
| 71 | + | |
| 72 | + public void put(GpsEntity gps) { | |
| 73 | + String device = gps.getDeviceId(); | |
| 74 | + GpsEntity old = gpsMap.get(device); | |
| 75 | + | |
| 76 | + try { | |
| 77 | + if (!StringUtils.isEmpty(gps.getStopNo())) { | |
| 78 | + //站点编码改变 | |
| 79 | + if (null == old || !gps.getStopNo().equals(old.getStopNo())) { | |
| 80 | + gps.setArrTime(gps.getTimestamp()); | |
| 81 | + //预测到达终点时间 | |
| 82 | + forecastRealServer.forecast(gps.getNbbm(), gps); | |
| 83 | + } else { | |
| 84 | + gps.setArrTime(old.getArrTime()); | |
| 85 | + //不预测, 重新计算终点时间 | |
| 86 | + gps.setExpectStopTime(forecastRealServer.expectStopTime(gps.getNbbm())); | |
| 87 | + } | |
| 88 | + } | |
| 89 | + } catch (Exception e) { | |
| 90 | + logger.error("", e); | |
| 91 | + } | |
| 92 | + | |
| 93 | + //刷新对照 | |
| 94 | + gpsMap.put(device, gps); | |
| 95 | + if (StringUtils.isNotBlank(gps.getLineId())) { | |
| 96 | + //站点名称 | |
| 97 | + gps.setStationName(getStationName(gps)); | |
| 98 | + lineCode2Devices.put(gps.getLineId(), device); | |
| 99 | + } | |
| 100 | + } | |
| 101 | + | |
| 102 | + public String getStationName(GpsEntity gps) { | |
| 103 | + return BasicData.getStationNameByCode(gps.getStopNo(), gps.getLineId() + "_" + gps.getUpDown() + "_"); | |
| 104 | + } | |
| 105 | + | |
| 106 | + /** | |
| 107 | + * @Title: get @Description: TODO(设备号获取GPS) | |
| 108 | + */ | |
| 109 | + public GpsEntity get(String deviceId) { | |
| 110 | + return gpsMap.get(deviceId); | |
| 111 | + } | |
| 112 | + | |
| 113 | + /** | |
| 114 | + * @Title: get @Description: TODO(线路编码获取GPS集合) @throws | |
| 115 | + */ | |
| 116 | + public List<GpsEntity> getByLine(String lineCode) { | |
| 117 | + NavigableSet<String> set = lineCode2Devices.get(lineCode); | |
| 118 | + | |
| 119 | + List<GpsEntity> rs = new ArrayList<>(); | |
| 120 | + GpsEntity gps; | |
| 121 | + ScheduleRealInfo sch; | |
| 122 | + for (String device : set) { | |
| 123 | + gps = gpsMap.get(device); | |
| 124 | + //过滤异常GPS数据 | |
| 125 | + if (gps == null || gps.isAbnormal()) | |
| 126 | + continue; | |
| 127 | + | |
| 128 | + sch = dayOfSchedule.execPlanMap().get(gps.getNbbm()); | |
| 129 | + if (null != sch) | |
| 130 | + gps.setSchId(sch.getId()); | |
| 131 | + rs.add(gps); | |
| 132 | + } | |
| 133 | + | |
| 134 | + return rs; | |
| 135 | + } | |
| 136 | + | |
| 137 | + public List<GpsEntity> get(List<String> pArray) { | |
| 138 | + List<GpsEntity> list = new ArrayList<>(); | |
| 139 | + | |
| 140 | + for (String code : pArray) | |
| 141 | + list.addAll(getByLine(code)); | |
| 142 | + return list; | |
| 143 | + } | |
| 144 | + | |
| 145 | + public Set<String> allDevices() { | |
| 146 | + return gpsMap.keySet(); | |
| 147 | + } | |
| 148 | + | |
| 149 | + public GpsEntity findByDeviceId(String deviceId) { | |
| 150 | + return gpsMap.get(deviceId); | |
| 151 | + } | |
| 152 | + | |
| 153 | + public Collection<GpsEntity> all() { | |
| 154 | + return gpsMap.values(); | |
| 155 | + } | |
| 156 | + | |
| 157 | + public void remove(String device) { | |
| 158 | + gpsMap.remove(device); | |
| 159 | + } | |
| 160 | + | |
| 161 | + @Component | |
| 162 | + public static class GpsDataLoader extends Thread { | |
| 163 | + | |
| 164 | + Logger logger = LoggerFactory.getLogger(GpsDataLoader.class); | |
| 165 | + | |
| 166 | + @Autowired | |
| 167 | + GpsRealData gpsRealData; | |
| 168 | + | |
| 169 | + @Autowired | |
| 170 | + GpsRealAnalyse gpsRealAnalyse; | |
| 171 | + | |
| 172 | + @Override | |
| 173 | + public void run() { | |
| 174 | + try { | |
| 175 | + //如果正在恢复数据 | |
| 176 | + if (GpsDataRecovery.run) | |
| 177 | + return; | |
| 178 | + | |
| 179 | + load(); | |
| 180 | + } catch (Exception e) { | |
| 181 | + logger.error("", e); | |
| 182 | + } | |
| 183 | + } | |
| 184 | + | |
| 185 | + public void load() throws Exception { | |
| 186 | + List<GpsEntity> list = null; | |
| 187 | + List<GpsEntity> updateList = new ArrayList<>(); | |
| 188 | + CloseableHttpClient httpClient = null; | |
| 189 | + CloseableHttpResponse response = null; | |
| 190 | + try { | |
| 191 | + httpClient = HttpClients.createDefault(); | |
| 192 | + HttpGet get = new HttpGet(url); | |
| 193 | + | |
| 194 | + response = httpClient.execute(get); | |
| 195 | + | |
| 196 | + HttpEntity entity = response.getEntity(); | |
| 197 | + if (null != entity) { | |
| 198 | + BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent())); | |
| 199 | + StringBuffer stringBuffer = new StringBuffer(); | |
| 200 | + String str = ""; | |
| 201 | + while ((str = br.readLine()) != null) | |
| 202 | + stringBuffer.append(str); | |
| 203 | + | |
| 204 | + JSONObject jsonObj = JSON.parseObject(stringBuffer.toString()); | |
| 205 | + | |
| 206 | + if (jsonObj != null) | |
| 207 | + list = JSON.parseArray(jsonObj.getString("data"), GpsEntity.class); | |
| 208 | + | |
| 209 | + String nbbm; | |
| 210 | + GpsEntity old; | |
| 211 | + for (GpsEntity gps : list) { | |
| 212 | + //没有设备号 | |
| 213 | + if (StringUtils.isBlank(gps.getDeviceId())) | |
| 214 | + continue; | |
| 215 | + | |
| 216 | + old = gpsMap.get(gps.getDeviceId()); | |
| 217 | + if (old != null && | |
| 218 | + old.getTimestamp() == gps.getTimestamp()) | |
| 219 | + continue; | |
| 220 | + | |
| 221 | + nbbm = BasicData.deviceId2NbbmMap.get(gps.getDeviceId()); | |
| 222 | + if (StringUtils.isBlank(nbbm)) | |
| 223 | + gps.setAbnormal(true);//标记为异常数据 | |
| 224 | + else | |
| 225 | + gps.setNbbm(nbbm); | |
| 226 | + //有更新的点位 | |
| 227 | + updateList.add(gps); | |
| 228 | + } | |
| 229 | + //分析数据 | |
| 230 | + gpsRealAnalyse.analyse(updateList); | |
| 231 | + } else | |
| 232 | + logger.error("real gps result is null"); | |
| 233 | + } catch (Exception e) { | |
| 234 | + logger.error("", e); | |
| 235 | + } finally { | |
| 236 | + if (null != httpClient) | |
| 237 | + httpClient.close(); | |
| 238 | + if (null != response) | |
| 239 | + response.close(); | |
| 240 | + } | |
| 241 | + } | |
| 242 | + } | |
| 243 | +} | |
| 285 | 244 | \ No newline at end of file | ... | ... |
src/main/java/com/bsth/data/gpsdata/SignalStateData.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata.arrival.entity.SignalState; | |
| 4 | +import com.bsth.websocket.handler.SendUtils; | |
| 5 | +import com.google.common.base.Splitter; | |
| 6 | +import com.google.common.collect.ArrayListMultimap; | |
| 7 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 8 | +import org.springframework.stereotype.Component; | |
| 9 | + | |
| 10 | +import java.util.ArrayList; | |
| 11 | +import java.util.List; | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * 信号状态数据 | |
| 15 | + * Created by panzhao on 2016/12/30. | |
| 16 | + */ | |
| 17 | +@Component | |
| 18 | +public class SignalStateData { | |
| 19 | + | |
| 20 | + @Autowired | |
| 21 | + SendUtils sendUtils; | |
| 22 | + | |
| 23 | + private static ArrayListMultimap<String, SignalState> listMultimap = ArrayListMultimap.create(); | |
| 24 | + | |
| 25 | + public void put(SignalState state){ | |
| 26 | + listMultimap.put(state.getLineCode(), state); | |
| 27 | + //推送到客户端 | |
| 28 | + sendUtils.sendSignalState(state); | |
| 29 | + } | |
| 30 | + | |
| 31 | + public List<SignalState> get(String idx){ | |
| 32 | + List<SignalState> rs = new ArrayList<>(); | |
| 33 | + List<String> ids = Splitter.on(",").splitToList(idx); | |
| 34 | + | |
| 35 | + for(String lineCode : ids){ | |
| 36 | + rs.addAll(listMultimap.get(lineCode)); | |
| 37 | + } | |
| 38 | + return rs; | |
| 39 | + } | |
| 40 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata/analyse/GpsAnalyse.java deleted
100644 → 0
| 1 | -package com.bsth.data.gpsdata.analyse; | |
| 2 | - | |
| 3 | -import com.bsth.data.gpsdata.GpsEntity; | |
| 4 | -import com.bsth.data.gpsdata.analyse.components.GpsArrival; | |
| 5 | -import org.slf4j.Logger; | |
| 6 | -import org.slf4j.LoggerFactory; | |
| 7 | - | |
| 8 | -import java.util.concurrent.ExecutorService; | |
| 9 | -import java.util.concurrent.Executors; | |
| 10 | - | |
| 11 | -/** | |
| 12 | - * 分析gps状态信息 | |
| 13 | - * Created by panzhao on 2016/12/23. | |
| 14 | - */ | |
| 15 | -public class GpsAnalyse { | |
| 16 | - | |
| 17 | - static Logger logger = LoggerFactory.getLogger(GpsAnalyse.class); | |
| 18 | - | |
| 19 | - //线程池 | |
| 20 | - static ExecutorService threadPool = Executors.newFixedThreadPool(50); | |
| 21 | - | |
| 22 | - public static void start(GpsEntity gps) { | |
| 23 | - threadPool.execute(new ArrivalMatchThread(gps)); | |
| 24 | - } | |
| 25 | - | |
| 26 | - public static class ArrivalMatchThread implements Runnable { | |
| 27 | - | |
| 28 | - private GpsEntity gps; | |
| 29 | - | |
| 30 | - public ArrivalMatchThread(GpsEntity gps) { | |
| 31 | - this.gps = gps; | |
| 32 | - } | |
| 33 | - | |
| 34 | - @Override | |
| 35 | - public void run() { | |
| 36 | - GpsArrival.arrival(gps); | |
| 37 | - } | |
| 38 | - } | |
| 39 | -} | |
| 40 | 0 | \ No newline at end of file |
src/main/java/com/bsth/data/gpsdata/analyse/components/GpsArrival.java deleted
100644 → 0
| 1 | -package com.bsth.data.gpsdata.analyse.components; | |
| 2 | - | |
| 3 | -import com.bsth.data.LineConfigData; | |
| 4 | -import com.bsth.data.gpsdata.GpsEntity; | |
| 5 | -import com.bsth.data.gpsdata.analyse.CircleQueue; | |
| 6 | -import com.bsth.data.gpsdata.analyse.GeoCacheData; | |
| 7 | -import com.bsth.data.gpsdata.analyse.StationRoute; | |
| 8 | -import com.bsth.data.gpsdata.analyse.util.GeoUtils; | |
| 9 | -import com.bsth.data.schedule.DayOfSchedule; | |
| 10 | -import com.bsth.entity.realcontrol.LineConfig; | |
| 11 | -import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 12 | -import org.slf4j.Logger; | |
| 13 | -import org.slf4j.LoggerFactory; | |
| 14 | -import org.springframework.beans.BeansException; | |
| 15 | -import org.springframework.context.ApplicationContext; | |
| 16 | -import org.springframework.context.ApplicationContextAware; | |
| 17 | -import org.springframework.stereotype.Component; | |
| 18 | - | |
| 19 | -import java.util.List; | |
| 20 | - | |
| 21 | -/** | |
| 22 | - * gps 到离站判断 | |
| 23 | - * Created by panzhao on 2016/12/24. | |
| 24 | - */ | |
| 25 | -@Component | |
| 26 | -public class GpsArrival implements ApplicationContextAware { | |
| 27 | - | |
| 28 | - static Logger logger = LoggerFactory.getLogger(GpsArrival.class); | |
| 29 | - | |
| 30 | - static DayOfSchedule dayOfSchedule; | |
| 31 | - | |
| 32 | - static LineConfigData lineConfigData; | |
| 33 | - | |
| 34 | - public static void arrival(GpsEntity gps) { | |
| 35 | - | |
| 36 | - if (gps.getLat() == 0 || gps.getLon() == 0) { | |
| 37 | - //logger.error("无效的gps"); | |
| 38 | - return; | |
| 39 | - } | |
| 40 | - | |
| 41 | - Object task = DayOfSchedule.executeCurr(gps.getNbbm()); | |
| 42 | - if (task == null) | |
| 43 | - return; | |
| 44 | - if (task.getClass().isAssignableFrom(ScheduleRealInfo.class)) { | |
| 45 | - ScheduleRealInfo sch = (ScheduleRealInfo) task; | |
| 46 | - //和班次同步走向 | |
| 47 | - gps.setUpDown(Integer.parseInt(sch.getXlDir())); | |
| 48 | - | |
| 49 | - //出场 | |
| 50 | - if (sch.getBcType().equals("out")) { | |
| 51 | - outCarpark(gps, sch); | |
| 52 | - } | |
| 53 | - else if (sch.getBcType().equals("normal")) | |
| 54 | - normalInOut(gps, sch); | |
| 55 | - else if(sch.getBcType().equals("in")){ | |
| 56 | - inCarpark(gps, sch); | |
| 57 | - } | |
| 58 | - } | |
| 59 | - | |
| 60 | - GeoCacheData.putGps(gps); | |
| 61 | - } | |
| 62 | - | |
| 63 | - /** | |
| 64 | - * 正常班次 | |
| 65 | - * | |
| 66 | - * @param gps | |
| 67 | - * @param sch | |
| 68 | - */ | |
| 69 | - private static void normalInOut(GpsEntity gps, ScheduleRealInfo sch) { | |
| 70 | - CircleQueue<GpsEntity> queue = GeoCacheData.getGps(gps.getNbbm()); | |
| 71 | - GpsEntity prev = null; | |
| 72 | - if (queue != null) | |
| 73 | - prev = queue.getTail(); | |
| 74 | - | |
| 75 | - List<StationRoute> srs = GeoCacheData.getStationRoute(sch.getXlBm(), gps.getUpDown()); | |
| 76 | - StationRoute station = GeoUtils.gpsInStation(gps, srs); | |
| 77 | - | |
| 78 | - if (station != null) { | |
| 79 | - //站内 | |
| 80 | - gps.setStopNo(station.getCode()); | |
| 81 | - gps.setInstation(true); | |
| 82 | - stationInside(gps, prev, sch); | |
| 83 | - } else { | |
| 84 | - //站外 | |
| 85 | - stationOutside(gps, prev, sch); | |
| 86 | - } | |
| 87 | - } | |
| 88 | - | |
| 89 | - /** | |
| 90 | - * GPS在站点内 | |
| 91 | - * | |
| 92 | - * @param gps | |
| 93 | - * @param prev | |
| 94 | - * @param sch | |
| 95 | - */ | |
| 96 | - private static void stationInside(GpsEntity gps, GpsEntity prev, ScheduleRealInfo sch) { | |
| 97 | - if(prev == null) | |
| 98 | - return; | |
| 99 | - | |
| 100 | - if (gps.getStopNo().equals(sch.getZdzCode()) && sch.getZdsjActual() == null) { | |
| 101 | - //到终点站 | |
| 102 | - arriveEnd(sch, gps); | |
| 103 | - return; | |
| 104 | - } | |
| 105 | - | |
| 106 | - //上一个点在站外 | |
| 107 | - if(!prev.isInstation()) | |
| 108 | - return; | |
| 109 | - //超过 (待发时间 + 90%的单程运送时间),还在起点站。默认烂一圈 | |
| 110 | - if (prev.getStopNo().equals(gps.getStopNo())){ | |
| 111 | - if(gps.getStopNo().equals(sch.getQdzCode()) | |
| 112 | - && gps.getTimestamp() > sch.getDfsjT() + (sch.getBcsj() * 60 * 1000 * 0.9)){ | |
| 113 | - | |
| 114 | - ScheduleRealInfo next = dayOfSchedule.next(dayOfSchedule.next(sch)); | |
| 115 | - dayOfSchedule.addExecPlan(next); | |
| 116 | - } | |
| 117 | - return; | |
| 118 | - } | |
| 119 | - | |
| 120 | - //发车 | |
| 121 | - if (prev.getStopNo().equals(sch.getQdzCode())) { | |
| 122 | - busWillDepart(sch, gps); | |
| 123 | - return; | |
| 124 | - } | |
| 125 | - | |
| 126 | - //中途站 | |
| 127 | - StationRoute prevStation = GeoCacheData.getStation(prev.getLineId(), prev.getUpDown(), prev.getStopNo()); | |
| 128 | - StationRoute currStation = GeoCacheData.getStation(gps.getLineId(), gps.getUpDown(), gps.getStopNo()); | |
| 129 | - if (currStation.getRouteSort() < prevStation.getRouteSort()) { | |
| 130 | - //开始下一个班次 | |
| 131 | - finishPlan(sch); | |
| 132 | - | |
| 133 | - logger.info("路由反向。。。。。。:" + gps.getTimestamp()); | |
| 134 | - //为班次补上实际时间 | |
| 135 | - | |
| 136 | - } | |
| 137 | - } | |
| 138 | - | |
| 139 | - /** | |
| 140 | - * GPS在站点外 | |
| 141 | - * | |
| 142 | - * @param gps | |
| 143 | - * @param prev | |
| 144 | - * @param sch | |
| 145 | - */ | |
| 146 | - private static void stationOutside(GpsEntity gps, GpsEntity prev, ScheduleRealInfo sch) { | |
| 147 | - if(prev == null) | |
| 148 | - return; | |
| 149 | - | |
| 150 | - gps.setStopNo(prev.getStopNo()); | |
| 151 | - if (prev.isInstation() && prev.getStopNo().equals(sch.getQdzCode())) { | |
| 152 | - //发车 | |
| 153 | - busWillDepart(sch, gps); | |
| 154 | - return; | |
| 155 | - } | |
| 156 | - } | |
| 157 | - | |
| 158 | - /** | |
| 159 | - * 公交车起点发出 | |
| 160 | - */ | |
| 161 | - final static long DRIFT_VAL_TIME = 1000 * 60 * 10; | |
| 162 | - //班次最大差值1小时 | |
| 163 | - final static long MAX_DIFF = 1000 * 60 * 60; | |
| 164 | - private static void busWillDepart(ScheduleRealInfo sch, GpsEntity gps) { | |
| 165 | - //实发时间不覆盖 | |
| 166 | - if (sch.getFcsjActual() == null && Math.abs(gps.getTimestamp() - sch.getDfsjT()) < MAX_DIFF) { | |
| 167 | - | |
| 168 | - //提前10分钟以上发出,判断一下是否是漂移 | |
| 169 | - if(sch.getDfsjT() - gps.getTimestamp() > DRIFT_VAL_TIME){ | |
| 170 | - ScheduleRealInfo schPrev = dayOfSchedule.prev(sch); | |
| 171 | - if(schPrev != null && schPrev.getZdsjActual() != null){ | |
| 172 | - //计划停站时间 | |
| 173 | - long stopTimeJH = sch.getDfsjT() - schPrev.getZdsjT(); | |
| 174 | - //实际停站时间 | |
| 175 | - long actualStopTime = gps.getTimestamp() - schPrev.getZdsjActualTime(); | |
| 176 | - /* | |
| 177 | - 没停够计划百分之60的,算漂移 | |
| 178 | - (这里出现的误判,由程序在车辆到中途站的时候进行补偿) | |
| 179 | - */ | |
| 180 | - if(stopTimeJH * 0.6 < actualStopTime){ | |
| 181 | - logger.info("漂移.... 车辆:" + gps.getNbbm() + " ts: " + gps.getTimestamp()); | |
| 182 | - return; | |
| 183 | - } | |
| 184 | - } | |
| 185 | - } | |
| 186 | - | |
| 187 | - LineConfig config = lineConfigData.get(sch.getXlBm()); | |
| 188 | - if(config != null && config.getOutConfig() == 2){ | |
| 189 | - //出站既出场 | |
| 190 | - ScheduleRealInfo schPrev = dayOfSchedule.prev(sch); | |
| 191 | - if(schPrev.getBcType().equals("out")){ | |
| 192 | - schPrev.setFcsjActualAll(schPrev.getDfsjT()); | |
| 193 | - schPrev.setZdsjActualAll(schPrev.getZdsjT()); | |
| 194 | - } | |
| 195 | - } | |
| 196 | - | |
| 197 | - sch.setFcsjActualAll(gps.getTimestamp()); | |
| 198 | - logger.info("(站外)班次:" + sch.getDfsj() + "发车, 时间:" + sch.getFcsjActual()); | |
| 199 | - } | |
| 200 | - } | |
| 201 | - | |
| 202 | - /** | |
| 203 | - * 公交车到达终点 | |
| 204 | - * | |
| 205 | - * @param sch | |
| 206 | - * @param gps | |
| 207 | - */ | |
| 208 | - private static void arriveEnd(ScheduleRealInfo sch, GpsEntity gps) { | |
| 209 | - sch.setZdsjActualAll(gps.getTimestamp()); | |
| 210 | - ScheduleRealInfo next = finishPlan(sch); | |
| 211 | - logger.info("班次:" + sch.getDfsj() + "到达终点, 时间:" + sch.getZdsjActual()); | |
| 212 | - | |
| 213 | - if (next == null) | |
| 214 | - return; | |
| 215 | - | |
| 216 | - //将gps转换为下一个班次走向的站内信号 | |
| 217 | - int updown = Integer.parseInt(next.getXlDir()); | |
| 218 | - List<StationRoute> srs = GeoCacheData.getStationRoute(next.getXlBm(), updown); | |
| 219 | - StationRoute station = GeoUtils.gpsInStation(gps, srs); | |
| 220 | - if (station != null) { | |
| 221 | - gps.setUpDown(updown); | |
| 222 | - gps.setStopNo(station.getCode()); | |
| 223 | - } | |
| 224 | - } | |
| 225 | - | |
| 226 | - /** | |
| 227 | - * 出场班次 | |
| 228 | - * | |
| 229 | - * @param gps | |
| 230 | - * @param sch | |
| 231 | - */ | |
| 232 | - private static void outCarpark(GpsEntity gps, ScheduleRealInfo sch) { | |
| 233 | - String carpark = GeoUtils.gpsInCarpark(gps); | |
| 234 | - if (carpark != null) { | |
| 235 | - gps.setInstation(true); | |
| 236 | - gps.setStopNo(carpark); | |
| 237 | - return; // 还在场内 | |
| 238 | - } | |
| 239 | - | |
| 240 | - CircleQueue<GpsEntity> queue = GeoCacheData.getGps(gps.getNbbm()); | |
| 241 | - if (queue == null) | |
| 242 | - return; | |
| 243 | - //上一个gps | |
| 244 | - GpsEntity prev = queue.getTail(); | |
| 245 | - | |
| 246 | - if (carpark == null && prev.isInstation() && prev.getStopNo().equals(sch.getQdzCode())) { | |
| 247 | - gps.setStopNo(prev.getStopNo()); | |
| 248 | - //停车场发出 | |
| 249 | - busWillDepart(sch, gps); | |
| 250 | - return; | |
| 251 | - } | |
| 252 | - | |
| 253 | - List<StationRoute> srs = GeoCacheData.getStationRoute(sch.getXlBm(), gps.getUpDown()); | |
| 254 | - StationRoute station = GeoUtils.gpsInStation(gps, srs); | |
| 255 | - | |
| 256 | - if (station != null && station.getCode().equals(sch.getZdzCode())) { | |
| 257 | - gps.setStopNo(station.getCode()); | |
| 258 | - //到达终点 | |
| 259 | - arriveEnd(sch, gps); | |
| 260 | - } | |
| 261 | - } | |
| 262 | - | |
| 263 | - | |
| 264 | - /** | |
| 265 | - * 进场班次 | |
| 266 | - * @param gps | |
| 267 | - * @param sch | |
| 268 | - */ | |
| 269 | - private static void inCarpark(GpsEntity gps, ScheduleRealInfo sch) { | |
| 270 | - String carpark = GeoUtils.gpsInCarpark(gps); | |
| 271 | - if (carpark != null && carpark.equals(sch.getZdzCode())) { | |
| 272 | - //进场班次取第一个实际进场时间 | |
| 273 | - if(sch.getZdsjActual() != null) | |
| 274 | - return; | |
| 275 | - | |
| 276 | - //进场 | |
| 277 | - arriveEnd(sch, gps); | |
| 278 | - return; | |
| 279 | - } | |
| 280 | - | |
| 281 | - CircleQueue<GpsEntity> queue = GeoCacheData.getGps(gps.getNbbm()); | |
| 282 | - if (queue == null) | |
| 283 | - return; | |
| 284 | - //上一个gps | |
| 285 | - GpsEntity prev = queue.getTail(); | |
| 286 | - | |
| 287 | - if (carpark == null && prev.isInstation() && prev.getStopNo().equals(sch.getQdzCode())) { | |
| 288 | - gps.setStopNo(prev.getStopNo()); | |
| 289 | - //进场班次发出 | |
| 290 | - busWillDepart(sch, gps); | |
| 291 | - return; | |
| 292 | - } | |
| 293 | - } | |
| 294 | - | |
| 295 | - /** | |
| 296 | - * 完成班次 -返回下一个班次 | |
| 297 | - * | |
| 298 | - * @param sch | |
| 299 | - */ | |
| 300 | - private static ScheduleRealInfo finishPlan(ScheduleRealInfo sch) { | |
| 301 | - ScheduleRealInfo next = dayOfSchedule.next(sch); | |
| 302 | - if (next != null) { | |
| 303 | - next.setQdzArrDatesj(sch.getZdsjActual()); | |
| 304 | - dayOfSchedule.addExecPlan(next); | |
| 305 | - } | |
| 306 | - return next; | |
| 307 | - } | |
| 308 | - | |
| 309 | - @Override | |
| 310 | - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | |
| 311 | - dayOfSchedule = applicationContext.getBean(DayOfSchedule.class); | |
| 312 | - lineConfigData = applicationContext.getBean(LineConfigData.class); | |
| 313 | - } | |
| 314 | -} |
src/main/java/com/bsth/data/gpsdata/analyse/components/GpsStateCorrective.java deleted
100644 → 0
| 1 | -package com.bsth.data.gpsdata.analyse.components; | |
| 2 | - | |
| 3 | -import com.bsth.data.gpsdata.GpsEntity; | |
| 4 | -import com.bsth.data.schedule.DayOfSchedule; | |
| 5 | -import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 6 | -import com.vividsolutions.jts.geom.GeometryFactory; | |
| 7 | -import org.joda.time.format.DateTimeFormat; | |
| 8 | -import org.joda.time.format.DateTimeFormatter; | |
| 9 | -import org.slf4j.Logger; | |
| 10 | -import org.slf4j.LoggerFactory; | |
| 11 | -import org.springframework.beans.BeansException; | |
| 12 | -import org.springframework.context.ApplicationContext; | |
| 13 | -import org.springframework.context.ApplicationContextAware; | |
| 14 | -import org.springframework.stereotype.Component; | |
| 15 | - | |
| 16 | -/** | |
| 17 | - * GPS状态纠正 | |
| 18 | - * Created by panzhao on 2016/12/23. | |
| 19 | - */ | |
| 20 | -@Component | |
| 21 | -public class GpsStateCorrective implements ApplicationContextAware { | |
| 22 | - | |
| 23 | - static Logger logger = LoggerFactory.getLogger(GpsStateCorrective.class); | |
| 24 | - | |
| 25 | - static DayOfSchedule dayOfSchedule; | |
| 26 | - | |
| 27 | - private static GeometryFactory geometryFactory = new GeometryFactory(); | |
| 28 | - | |
| 29 | - public static void correct(GpsEntity gps, ScheduleRealInfo sch){ | |
| 30 | -/* int upDown = Integer.parseInt(sch.getXlDir()); | |
| 31 | - gps.setUpDown(upDown); | |
| 32 | - List<StationRoute> srs = GeoCacheData.getStationRoute(sch.getXlBm(), upDown); | |
| 33 | - | |
| 34 | - Point point = geometryFactory.createPoint(new Coordinate(gps.getLat(), gps.getLon())); | |
| 35 | - | |
| 36 | - //之前的点位 | |
| 37 | - CircleQueue<GpsEntity> queue = GeoCacheData.getGps(gps.getNbbm()); | |
| 38 | - GpsEntity prev = null; | |
| 39 | - if(queue != null) | |
| 40 | - prev = queue.getTail(); | |
| 41 | - | |
| 42 | - //线路上,站点间 | |
| 43 | - StationRoute station = GeoUtils.pointInStation(point, srs); | |
| 44 | - //在站内 | |
| 45 | - if(station != null){ | |
| 46 | - gps.setStopNo(station.getCode()); | |
| 47 | - gps.setInstation(true); | |
| 48 | - gps.setStation(station); | |
| 49 | - | |
| 50 | - if(prev != null && prev.getUpDown() == upDown){ | |
| 51 | - StationRoute prevStation = GeoCacheData.getStation(prev.getLineId(), upDown, prev.getStopNo()); | |
| 52 | - | |
| 53 | - //倒着开?? | |
| 54 | - if(prevStation.getRouteSort() > station.getRouteSort()){ | |
| 55 | - reversalHandle(gps, prev, sch); | |
| 56 | - } | |
| 57 | - } | |
| 58 | - } | |
| 59 | - else{ | |
| 60 | - if(prev != null) | |
| 61 | - gps.setStopNo(prev.getStopNo()); | |
| 62 | - } | |
| 63 | - | |
| 64 | - //是否在停车场内 | |
| 65 | - Map<String, Polygon> carparkMap = GeoCacheData.tccMap; | |
| 66 | - Set<String> codes = carparkMap.keySet(); | |
| 67 | - Polygon p; | |
| 68 | - for(String code : codes){ | |
| 69 | - p = carparkMap.get(code); | |
| 70 | - //场内 | |
| 71 | - if(p.contains(point)){ | |
| 72 | - gps.setCarparkNo(code); | |
| 73 | - if(sch.getBcType().equals("out")){ | |
| 74 | - gps.setInstation(true); | |
| 75 | - gps.setStopNo(code); | |
| 76 | - } | |
| 77 | - } | |
| 78 | - }*/ | |
| 79 | - } | |
| 80 | - | |
| 81 | - private static DateTimeFormatter fmt = DateTimeFormat.forPattern("HH:mm"); | |
| 82 | - | |
| 83 | - private static void reversalHandle(GpsEntity gps, GpsEntity prev, ScheduleRealInfo sch){ | |
| 84 | - /*if(sch.getBcType().equals("out") && gps.getTimestamp() < sch.getZdsjT()) | |
| 85 | - return; | |
| 86 | - | |
| 87 | - //先假设没到终点,直接开始了下一个班次 | |
| 88 | - ScheduleRealInfo next = dayOfSchedule.next(sch); | |
| 89 | - String log = "倒着开??? nbbm: " + gps.getNbbm() + " 当前:" + gps.getStopNo() + " 上一站:" + prev.getStopNo() + " 当前班次:" + sch.getDfsj(); | |
| 90 | - if(next != null){ | |
| 91 | - dayOfSchedule.addExecPlan(next); | |
| 92 | - | |
| 93 | - log += (" 下一个班次:" + next.getDfsj()); | |
| 94 | - } | |
| 95 | - | |
| 96 | - log += (" GPS时间:" + fmt.print(gps.getTimestamp())); | |
| 97 | - | |
| 98 | - logger.info(log);*/ | |
| 99 | - } | |
| 100 | - | |
| 101 | - @Override | |
| 102 | - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | |
| 103 | - dayOfSchedule = applicationContext.getBean(DayOfSchedule.class); | |
| 104 | - } | |
| 105 | -} |
src/main/java/com/bsth/data/gpsdata/analyse/GeoCacheData.java renamed to src/main/java/com/bsth/data/gpsdata/arrival/GeoCacheData.java
| 1 | -package com.bsth.data.gpsdata.analyse; | |
| 2 | - | |
| 3 | -import com.bsth.data.gpsdata.GpsEntity; | |
| 4 | -import com.google.common.collect.ArrayListMultimap; | |
| 5 | -import com.vividsolutions.jts.geom.Coordinate; | |
| 6 | -import com.vividsolutions.jts.geom.GeometryFactory; | |
| 7 | -import com.vividsolutions.jts.geom.LineString; | |
| 8 | -import com.vividsolutions.jts.geom.Polygon; | |
| 9 | -import org.apache.commons.lang3.StringUtils; | |
| 10 | -import org.slf4j.Logger; | |
| 11 | -import org.slf4j.LoggerFactory; | |
| 12 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 13 | -import org.springframework.jdbc.core.JdbcTemplate; | |
| 14 | -import org.springframework.jdbc.core.RowMapper; | |
| 15 | -import org.springframework.stereotype.Component; | |
| 16 | - | |
| 17 | -import java.sql.ResultSet; | |
| 18 | -import java.sql.SQLException; | |
| 19 | -import java.util.*; | |
| 20 | - | |
| 21 | -/** | |
| 22 | - * Created by panzhao on 2016/12/23. | |
| 23 | - */ | |
| 24 | -@Component | |
| 25 | -public class GeoCacheData { | |
| 26 | - | |
| 27 | - static Logger logger = LoggerFactory.getLogger(GeoCacheData.class); | |
| 28 | - | |
| 29 | - //每辆车缓存最后200条gps | |
| 30 | - private static final int CACHE_SIZE = 200; | |
| 31 | - private static Map<String, CircleQueue<GpsEntity>> gpsCacheMap = new HashMap<>(); | |
| 32 | - | |
| 33 | - //线路路段走向 | |
| 34 | - private static ArrayListMultimap<String, LineString> sectionCacheMap; | |
| 35 | - | |
| 36 | - //线路站点路由 | |
| 37 | - private static ArrayListMultimap<String, StationRoute> stationCacheMap; | |
| 38 | - | |
| 39 | - //停车场 | |
| 40 | - public static Map<String, Polygon> tccMap; | |
| 41 | - | |
| 42 | - @Autowired | |
| 43 | - JdbcTemplate jdbcTemplate; | |
| 44 | - | |
| 45 | - public static CircleQueue<GpsEntity> getGps(String nbbm) { | |
| 46 | - return gpsCacheMap.get(nbbm); | |
| 47 | - } | |
| 48 | - | |
| 49 | - public static void putGps(GpsEntity gps) { | |
| 50 | - CircleQueue<GpsEntity> queue = gpsCacheMap.get(gps.getNbbm()); | |
| 51 | - if (queue == null) { | |
| 52 | - //第一个点从站内开始 | |
| 53 | - if(!gps.isInstation()) | |
| 54 | - return; | |
| 55 | - | |
| 56 | - queue = new CircleQueue<>(CACHE_SIZE); | |
| 57 | - gpsCacheMap.put(gps.getNbbm(), queue); | |
| 58 | - } | |
| 59 | - queue.add(gps); | |
| 60 | - } | |
| 61 | - | |
| 62 | - public static List<StationRoute> getStationRoute(String lineCode, int directions) { | |
| 63 | - return stationCacheMap.get(lineCode + "_" + directions); | |
| 64 | - } | |
| 65 | - | |
| 66 | - public static StationRoute getStation(String lineCode, int directions, String code) { | |
| 67 | - List<StationRoute> list = getStationRoute(lineCode, directions); | |
| 68 | - | |
| 69 | - for (StationRoute sr : list) { | |
| 70 | - if (sr.getCode().equals(code)) { | |
| 71 | - return sr; | |
| 72 | - } | |
| 73 | - } | |
| 74 | - return null; | |
| 75 | - } | |
| 76 | - | |
| 77 | - public static Polygon getTccPolygon(String code){ | |
| 78 | - return tccMap.get(code); | |
| 79 | - } | |
| 80 | - | |
| 81 | - public void loadData() { | |
| 82 | - final GeometryFactory geometryFactory = new GeometryFactory(); | |
| 83 | - //加载站点路由 | |
| 84 | - String sql = "select r.LINE_CODE,r.DIRECTIONS,r.STATION_CODE,r.STATION_MARK,s.SHAPES_TYPE,s.G_LONX,s.G_LATY,ST_AsText(s.G_POLYGON_GRID) as G_POLYGON_GRID,s.RADIUS, r.STATION_ROUTE_CODE from bsth_c_stationroute r left join bsth_c_station s on r.station=s.id where r.destroy=0 order by r.station_route_code"; | |
| 85 | - List<StationRoute> routeList = jdbcTemplate.query(sql, new RowMapper<StationRoute>() { | |
| 86 | - @Override | |
| 87 | - public StationRoute mapRow(ResultSet rs, int rowNum) throws SQLException { | |
| 88 | - StationRoute sRoute = new StationRoute(); | |
| 89 | - sRoute.setCode(rs.getString("STATION_CODE")); | |
| 90 | - sRoute.setLineCode(rs.getString("LINE_CODE")); | |
| 91 | - sRoute.setDirections(rs.getInt("DIRECTIONS")); | |
| 92 | - sRoute.setPoint(geometryFactory.createPoint(new Coordinate(rs.getFloat("G_LATY"), rs.getFloat("G_LONX")))); | |
| 93 | - sRoute.setRadius(rs.getFloat("RADIUS")); | |
| 94 | - sRoute.setRouteSort(rs.getInt("STATION_ROUTE_CODE")); | |
| 95 | - sRoute.setMark(rs.getString("STATION_MARK")); | |
| 96 | - | |
| 97 | - String shapesType = rs.getString("SHAPES_TYPE"); | |
| 98 | - //多边形电子围栏 | |
| 99 | - if (StringUtils.isNotEmpty(shapesType) && shapesType.equals("d")) { | |
| 100 | - geometryFactory.createPolygon(parsePolygon(rs.getString("G_POLYGON_GRID"))); | |
| 101 | - } | |
| 102 | - return sRoute; | |
| 103 | - } | |
| 104 | - }); | |
| 105 | - //按线路和走向分组 | |
| 106 | - if (routeList.size() > 0) { | |
| 107 | - ArrayListMultimap<String, StationRoute> tempMap = ArrayListMultimap.create(); | |
| 108 | - for (StationRoute sr : routeList) { | |
| 109 | - tempMap.put(sr.getLineCode() + "_" + sr.getDirections(), sr); | |
| 110 | - } | |
| 111 | - | |
| 112 | - StationRouteComp srCom = new StationRouteComp(); | |
| 113 | - //连接路由 | |
| 114 | - Set<String> set = tempMap.keySet(); | |
| 115 | - for (String key : set) { | |
| 116 | - Collections.sort(tempMap.get(key), srCom); | |
| 117 | - connectStationRoute(tempMap.get(key)); | |
| 118 | - } | |
| 119 | - | |
| 120 | - stationCacheMap = tempMap; | |
| 121 | - } | |
| 122 | - | |
| 123 | - //加载停车场数据 | |
| 124 | - sql = "select PARK_CODE, ST_AsText(G_PARK_POINT) as G_PARK_POINT from bsth_c_car_park where park_code is not null and b_park_point is not null"; | |
| 125 | - List<Map<String, Object>> tccList = jdbcTemplate.queryForList(sql); | |
| 126 | - Map<String, Polygon> tccTempMap = new HashMap<>(); | |
| 127 | - | |
| 128 | - Polygon polygon; | |
| 129 | - for (Map<String, Object> tMap : tccList) { | |
| 130 | - | |
| 131 | - try { | |
| 132 | - polygon = geometryFactory.createPolygon(parsePolygon(tMap.get("G_PARK_POINT").toString())); | |
| 133 | - tccTempMap.put(tMap.get("PARK_CODE").toString() | |
| 134 | - , polygon); | |
| 135 | - } catch (Exception e) { | |
| 136 | - logger.error("停车场:" + tMap.get("PARK_CODE") , e); | |
| 137 | - } | |
| 138 | - } | |
| 139 | - | |
| 140 | - if(tccTempMap.size() > 0) | |
| 141 | - tccMap = tccTempMap; | |
| 142 | - } | |
| 143 | - | |
| 144 | - private void connectStationRoute(List<StationRoute> list) { | |
| 145 | - int size = list.size(); | |
| 146 | - StationRoute sr = null; | |
| 147 | - for (int i = 0; i < size; i++) { | |
| 148 | - sr = list.get(i); | |
| 149 | - //上一个 | |
| 150 | - if (i > 0) | |
| 151 | - sr.setPrve(list.get(i - 1)); | |
| 152 | - //下一个 | |
| 153 | - if (i < size - 1) | |
| 154 | - sr.setNext(list.get(i + 1)); | |
| 155 | - } | |
| 156 | - } | |
| 157 | - | |
| 158 | - public Coordinate[] parsePolygon(String polygonStr) { | |
| 159 | - String[] coords = polygonStr.substring(9, polygonStr.length() - 2).split(","), temps; | |
| 160 | - | |
| 161 | - Coordinate[] cds = new Coordinate[coords.length]; | |
| 162 | - int len = coords.length; | |
| 163 | - for (int i = 0; i < len; i++) { | |
| 164 | - temps = coords[i].split(" "); | |
| 165 | - cds[i] = new Coordinate(Float.parseFloat(temps[1]), Float.parseFloat(temps[0])); | |
| 166 | - } | |
| 167 | - return cds; | |
| 168 | - } | |
| 169 | - | |
| 1 | +package com.bsth.data.gpsdata.arrival; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata.GpsEntity; | |
| 4 | +import com.bsth.data.gpsdata.arrival.entity.StationRoute; | |
| 5 | +import com.bsth.data.gpsdata.arrival.utils.CircleQueue; | |
| 6 | +import com.bsth.data.gpsdata.arrival.utils.StationRouteComp; | |
| 7 | +import com.google.common.collect.ArrayListMultimap; | |
| 8 | +import com.vividsolutions.jts.geom.Coordinate; | |
| 9 | +import com.vividsolutions.jts.geom.GeometryFactory; | |
| 10 | +import com.vividsolutions.jts.geom.LineString; | |
| 11 | +import com.vividsolutions.jts.geom.Polygon; | |
| 12 | +import org.apache.commons.lang3.StringUtils; | |
| 13 | +import org.slf4j.Logger; | |
| 14 | +import org.slf4j.LoggerFactory; | |
| 15 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 16 | +import org.springframework.jdbc.core.JdbcTemplate; | |
| 17 | +import org.springframework.jdbc.core.RowMapper; | |
| 18 | +import org.springframework.stereotype.Component; | |
| 19 | + | |
| 20 | +import java.sql.ResultSet; | |
| 21 | +import java.sql.SQLException; | |
| 22 | +import java.util.*; | |
| 23 | + | |
| 24 | +/** | |
| 25 | + * Created by panzhao on 2016/12/23. | |
| 26 | + */ | |
| 27 | +@Component | |
| 28 | +public class GeoCacheData { | |
| 29 | + | |
| 30 | + static Logger logger = LoggerFactory.getLogger(GeoCacheData.class); | |
| 31 | + | |
| 32 | + //每辆车缓存最后1000条gps | |
| 33 | + private static final int CACHE_SIZE = 1000; | |
| 34 | + private static Map<String, CircleQueue<GpsEntity>> gpsCacheMap = new HashMap<>(); | |
| 35 | + | |
| 36 | + //线路路段走向 | |
| 37 | + private static ArrayListMultimap<String, LineString> sectionCacheMap; | |
| 38 | + | |
| 39 | + //线路站点路由 | |
| 40 | + private static ArrayListMultimap<String, StationRoute> stationCacheMap; | |
| 41 | + | |
| 42 | + //线路_上下行_站点编码 ——> 站点 | |
| 43 | + private static Map<String, StationRoute> routeCodeMap; | |
| 44 | + | |
| 45 | + //停车场 | |
| 46 | + public static Map<String, Polygon> tccMap; | |
| 47 | + | |
| 48 | + @Autowired | |
| 49 | + JdbcTemplate jdbcTemplate; | |
| 50 | + | |
| 51 | + public static CircleQueue<GpsEntity> getGps(String nbbm) { | |
| 52 | + return gpsCacheMap.get(nbbm); | |
| 53 | + } | |
| 54 | + | |
| 55 | + public static void putGps(GpsEntity gps) { | |
| 56 | + CircleQueue<GpsEntity> queue = gpsCacheMap.get(gps.getNbbm()); | |
| 57 | + if (queue == null) { | |
| 58 | + /*//第一个点从站内开始 | |
| 59 | + if (gps.getInstation() == 0) | |
| 60 | + return;*/ | |
| 61 | + | |
| 62 | + queue = new CircleQueue<>(CACHE_SIZE); | |
| 63 | + gpsCacheMap.put(gps.getNbbm(), queue); | |
| 64 | + } | |
| 65 | + queue.add(gps); | |
| 66 | + } | |
| 67 | + | |
| 68 | + public static void clear(String nbbm) { | |
| 69 | + try { | |
| 70 | + CircleQueue<GpsEntity> queue = gpsCacheMap.get(nbbm); | |
| 71 | + if (queue != null) | |
| 72 | + queue.clear(); | |
| 73 | + } catch (Exception e) { | |
| 74 | + logger.error("", e); | |
| 75 | + } | |
| 76 | + } | |
| 77 | + | |
| 78 | + public static StationRoute getRouteCode(GpsEntity gps) { | |
| 79 | + return routeCodeMap.get(gps.getLineId() + "_" + gps.getUpDown() + "_" + gps.getStopNo()); | |
| 80 | + } | |
| 81 | + | |
| 82 | + public static List<StationRoute> getStationRoute(String lineCode, int directions) { | |
| 83 | + return stationCacheMap.get(lineCode + "_" + directions); | |
| 84 | + } | |
| 85 | + | |
| 86 | + public static StationRoute getStation(String lineCode, int directions, String code) { | |
| 87 | + List<StationRoute> list = getStationRoute(lineCode, directions); | |
| 88 | + | |
| 89 | + for (StationRoute sr : list) { | |
| 90 | + if (sr.getCode().equals(code)) { | |
| 91 | + return sr; | |
| 92 | + } | |
| 93 | + } | |
| 94 | + return null; | |
| 95 | + } | |
| 96 | + | |
| 97 | + public static List<StationRoute> midwayStation(String lineCode, int directions, String sCode, String eCode) { | |
| 98 | + List<StationRoute> list = getStationRoute(lineCode, directions), rs = new ArrayList<>(); | |
| 99 | + | |
| 100 | + boolean flag = false; | |
| 101 | + for (StationRoute sr : list) { | |
| 102 | + if (flag) | |
| 103 | + rs.add(sr); | |
| 104 | + if (sr.getCode().equals(sCode)) | |
| 105 | + flag = true; | |
| 106 | + else if (sr.getCode().equals(eCode)) | |
| 107 | + break; | |
| 108 | + } | |
| 109 | + return rs; | |
| 110 | + } | |
| 111 | + | |
| 112 | + public static Polygon getTccPolygon(String code) { | |
| 113 | + return tccMap.get(code); | |
| 114 | + } | |
| 115 | + | |
| 116 | + public void loadData() { | |
| 117 | + final GeometryFactory geometryFactory = new GeometryFactory(); | |
| 118 | + //加载站点路由 | |
| 119 | + String sql = "select r.LINE_CODE,r.DIRECTIONS,r.STATION_CODE,r.STATION_MARK,s.SHAPES_TYPE,s.G_LONX,s.G_LATY,ST_AsText(s.G_POLYGON_GRID) as G_POLYGON_GRID,s.RADIUS, r.STATION_ROUTE_CODE,s.STATION_NAME from bsth_c_stationroute r left join bsth_c_station s on r.station=s.id where r.destroy=0 order by r.station_route_code"; | |
| 120 | + List<StationRoute> routeList = jdbcTemplate.query(sql, new RowMapper<StationRoute>() { | |
| 121 | + @Override | |
| 122 | + public StationRoute mapRow(ResultSet rs, int rowNum) throws SQLException { | |
| 123 | + StationRoute sRoute = new StationRoute(); | |
| 124 | + sRoute.setCode(rs.getString("STATION_CODE")); | |
| 125 | + sRoute.setLineCode(rs.getString("LINE_CODE")); | |
| 126 | + sRoute.setDirections(rs.getInt("DIRECTIONS")); | |
| 127 | + sRoute.setPoint(geometryFactory.createPoint(new Coordinate(rs.getFloat("G_LATY"), rs.getFloat("G_LONX")))); | |
| 128 | + sRoute.setRadius(rs.getFloat("RADIUS")); | |
| 129 | + sRoute.setRouteSort(rs.getInt("STATION_ROUTE_CODE")); | |
| 130 | + sRoute.setMark(rs.getString("STATION_MARK")); | |
| 131 | + sRoute.setName(rs.getString("STATION_NAME")); | |
| 132 | + | |
| 133 | + String shapesType = rs.getString("SHAPES_TYPE"); | |
| 134 | + //多边形电子围栏 | |
| 135 | + if (StringUtils.isNotEmpty(shapesType) && shapesType.equals("d")) { | |
| 136 | + sRoute.setPolygon(geometryFactory.createPolygon(parsePolygon(rs.getString("G_POLYGON_GRID")))); | |
| 137 | + } | |
| 138 | + return sRoute; | |
| 139 | + } | |
| 140 | + }); | |
| 141 | + //按线路和走向分组 | |
| 142 | + if (routeList.size() > 0) { | |
| 143 | + ArrayListMultimap<String, StationRoute> tempMap = ArrayListMultimap.create(); | |
| 144 | + Map<String, StationRoute> codeMap = new HashMap<>(routeList.size()); | |
| 145 | + for (StationRoute sr : routeList) { | |
| 146 | + tempMap.put(sr.getLineCode() + "_" + sr.getDirections(), sr); | |
| 147 | + //站点编码 ——> 和路由顺序对照 | |
| 148 | + codeMap.put(sr.getLineCode() + "_" + sr.getDirections() + "_" + sr.getCode(), sr); | |
| 149 | + } | |
| 150 | + | |
| 151 | + StationRouteComp srCom = new StationRouteComp(); | |
| 152 | + //连接路由 | |
| 153 | + Set<String> set = tempMap.keySet(); | |
| 154 | + for (String key : set) { | |
| 155 | + Collections.sort(tempMap.get(key), srCom); | |
| 156 | + connectStationRoute(tempMap.get(key)); | |
| 157 | + } | |
| 158 | + | |
| 159 | + stationCacheMap = tempMap; | |
| 160 | + routeCodeMap = codeMap; | |
| 161 | + } | |
| 162 | + | |
| 163 | + //加载停车场数据 | |
| 164 | + sql = "select PARK_CODE, ST_AsText(G_PARK_POINT) as G_PARK_POINT from bsth_c_car_park where park_code is not null and b_park_point is not null"; | |
| 165 | + List<Map<String, Object>> tccList = jdbcTemplate.queryForList(sql); | |
| 166 | + Map<String, Polygon> tccTempMap = new HashMap<>(); | |
| 167 | + | |
| 168 | + Polygon polygon; | |
| 169 | + for (Map<String, Object> tMap : tccList) { | |
| 170 | + | |
| 171 | + try { | |
| 172 | + polygon = geometryFactory.createPolygon(parsePolygon(tMap.get("G_PARK_POINT").toString())); | |
| 173 | + tccTempMap.put(tMap.get("PARK_CODE").toString() | |
| 174 | + , polygon); | |
| 175 | + } catch (Exception e) { | |
| 176 | + logger.error("停车场:" + tMap.get("PARK_CODE"), e); | |
| 177 | + } | |
| 178 | + } | |
| 179 | + | |
| 180 | + if (tccTempMap.size() > 0) | |
| 181 | + tccMap = tccTempMap; | |
| 182 | + } | |
| 183 | + | |
| 184 | + private void connectStationRoute(List<StationRoute> list) { | |
| 185 | + int size = list.size(); | |
| 186 | + StationRoute sr = null; | |
| 187 | + for (int i = 0; i < size; i++) { | |
| 188 | + sr = list.get(i); | |
| 189 | + //上一个 | |
| 190 | + if (i > 0) | |
| 191 | + sr.setPrve(list.get(i - 1)); | |
| 192 | + //下一个 | |
| 193 | + if (i < size - 1) | |
| 194 | + sr.setNext(list.get(i + 1)); | |
| 195 | + } | |
| 196 | + } | |
| 197 | + | |
| 198 | + public Coordinate[] parsePolygon(String polygonStr) { | |
| 199 | + String[] coords = polygonStr.substring(9, polygonStr.length() - 2).split(","), temps; | |
| 200 | + | |
| 201 | + Coordinate[] cds = new Coordinate[coords.length]; | |
| 202 | + int len = coords.length; | |
| 203 | + for (int i = 0; i < len; i++) { | |
| 204 | + temps = coords[i].split(" "); | |
| 205 | + cds[i] = new Coordinate(Float.parseFloat(temps[1]), Float.parseFloat(temps[0])); | |
| 206 | + } | |
| 207 | + return cds; | |
| 208 | + } | |
| 209 | + | |
| 210 | + /** | |
| 211 | + * 是不是终点站 | |
| 212 | + * @param lineId | |
| 213 | + * @param upDown | |
| 214 | + * @param stationCode | |
| 215 | + * @return | |
| 216 | + */ | |
| 217 | + public static boolean isEndStation(String lineId, Integer upDown, String stationCode) { | |
| 218 | + StationRoute station = routeCodeMap.get(lineId + "_" + upDown + "_" + stationCode); | |
| 219 | + return station != null && station.getMark().equals("E"); | |
| 220 | + } | |
| 170 | 221 | } |
| 171 | 222 | \ No newline at end of file | ... | ... |
src/main/java/com/bsth/data/gpsdata/arrival/GpsRealAnalyse.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata.arrival; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata.GpsEntity; | |
| 4 | +import com.bsth.data.gpsdata.GpsRealData; | |
| 5 | +import com.bsth.data.gpsdata.arrival.handlers.*; | |
| 6 | +import com.bsth.data.gpsdata.arrival.utils.CircleQueue; | |
| 7 | +import org.slf4j.Logger; | |
| 8 | +import org.slf4j.LoggerFactory; | |
| 9 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 10 | +import org.springframework.stereotype.Component; | |
| 11 | + | |
| 12 | +import java.util.List; | |
| 13 | +import java.util.concurrent.CountDownLatch; | |
| 14 | +import java.util.concurrent.ExecutorService; | |
| 15 | +import java.util.concurrent.Executors; | |
| 16 | + | |
| 17 | +/** | |
| 18 | + * gps 实时数据分析 | |
| 19 | + * Created by panzhao on 2016/12/27. | |
| 20 | + */ | |
| 21 | +@Component | |
| 22 | +public class GpsRealAnalyse { | |
| 23 | + | |
| 24 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 25 | + | |
| 26 | + @Autowired | |
| 27 | + OfflineSignalHandle offlineSignalHandle; | |
| 28 | + @Autowired | |
| 29 | + CorrectSignalHandle correctSignalHandle; | |
| 30 | + @Autowired | |
| 31 | + StationInsideHandle stationInsideHandle; | |
| 32 | + @Autowired | |
| 33 | + InOutStationSignalHandle inOutStationSignalHandle; | |
| 34 | + @Autowired | |
| 35 | + ReverseSignalHandle reverseSignalHandle; | |
| 36 | + | |
| 37 | + @Autowired | |
| 38 | + GpsRealData gpsRealData; | |
| 39 | + | |
| 40 | + //50个线程 | |
| 41 | + static ExecutorService threadPool = Executors.newFixedThreadPool(50); | |
| 42 | + | |
| 43 | + public void analyse(List<GpsEntity> list) { | |
| 44 | + CountDownLatch count = new CountDownLatch(list.size()); | |
| 45 | + | |
| 46 | + for(GpsEntity gps : list) | |
| 47 | + threadPool.execute(new SignalHandleThread(gps, count)); | |
| 48 | + | |
| 49 | + try { | |
| 50 | + //等待子线程结束 | |
| 51 | + count.await(); | |
| 52 | + | |
| 53 | + //加入实时gps对照 | |
| 54 | + for(GpsEntity gps: list) | |
| 55 | + gpsRealData.put(gps); | |
| 56 | + } catch (InterruptedException e) { | |
| 57 | + logger.error("", e); | |
| 58 | + } | |
| 59 | + } | |
| 60 | + | |
| 61 | + public class SignalHandleThread implements Runnable { | |
| 62 | + | |
| 63 | + GpsEntity gps; | |
| 64 | + CountDownLatch count; | |
| 65 | + | |
| 66 | + SignalHandleThread(GpsEntity gps, CountDownLatch count) { | |
| 67 | + this.gps = gps; | |
| 68 | + this.count = count; | |
| 69 | + } | |
| 70 | + | |
| 71 | + @Override | |
| 72 | + public void run() { | |
| 73 | + | |
| 74 | + try { | |
| 75 | + CircleQueue<GpsEntity> prevs = GeoCacheData.getGps(gps.getNbbm()); | |
| 76 | + //掉线处理 | |
| 77 | + offlineSignalHandle.handle(gps, prevs); | |
| 78 | + //状态处理 | |
| 79 | + if(!correctSignalHandle.handle(gps, prevs)) | |
| 80 | + return; | |
| 81 | + //场,站内外判断 | |
| 82 | + stationInsideHandle.handle(gps, prevs); | |
| 83 | + //反向处理 | |
| 84 | + reverseSignalHandle.handle(gps, prevs); | |
| 85 | + //进出站动作处理 | |
| 86 | + inOutStationSignalHandle.handle(gps, prevs); | |
| 87 | + GeoCacheData.putGps(gps); | |
| 88 | + | |
| 89 | + } catch (Exception e) { | |
| 90 | + logger.error("", e); | |
| 91 | + } finally { | |
| 92 | + count.countDown(); | |
| 93 | + } | |
| 94 | + } | |
| 95 | + } | |
| 96 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata/arrival/SignalHandle.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata.arrival; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata.GpsEntity; | |
| 4 | +import com.bsth.data.gpsdata.arrival.entity.StationRoute; | |
| 5 | +import com.bsth.data.gpsdata.arrival.utils.CircleQueue; | |
| 6 | +import com.bsth.data.gpsdata.arrival.utils.GeoUtils; | |
| 7 | +import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 8 | + | |
| 9 | +import java.util.List; | |
| 10 | + | |
| 11 | +/** | |
| 12 | + * Created by panzhao on 2016/12/27. | |
| 13 | + */ | |
| 14 | +public abstract class SignalHandle { | |
| 15 | + | |
| 16 | + public abstract boolean handle(GpsEntity gps, CircleQueue<GpsEntity> prevs); | |
| 17 | + | |
| 18 | + protected boolean isNotEmpty(CircleQueue<GpsEntity> prevs) { | |
| 19 | + return prevs != null && prevs.size() > 0 && prevs.getTail() != null; | |
| 20 | + } | |
| 21 | + | |
| 22 | + protected boolean isDriftSignal(GpsEntity gps) { | |
| 23 | + return gps.getLat() == 0 || gps.getLon() == 0; | |
| 24 | + } | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * 是不是异常信号 | |
| 28 | + * | |
| 29 | + * @param gps | |
| 30 | + * @return protected boolean isAbnormal(GpsEntity gps) { | |
| 31 | + return gps.getLat() == 0 || gps.getLon() == 0; | |
| 32 | + }*/ | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * 连续异常信号个数统计 | |
| 36 | + * | |
| 37 | + * @param prevs | |
| 38 | + * @return protected int abnormalCount(CircleQueue<GpsEntity> prevs) { | |
| 39 | + * int count = 0; | |
| 40 | + * <p> | |
| 41 | + * if (!isNotEmpty(prevs)) | |
| 42 | + * return count; | |
| 43 | + * <p> | |
| 44 | + * GpsEntity[] array = (GpsEntity[]) prevs.getQueue(); | |
| 45 | + * GpsEntity gps; | |
| 46 | + * for (int i = array.length - 1; i > 0; i--) { | |
| 47 | + * gps = array[i]; | |
| 48 | + * <p> | |
| 49 | + * if (isAbnormal(gps)) | |
| 50 | + * count++; | |
| 51 | + * else | |
| 52 | + * break; | |
| 53 | + * } | |
| 54 | + * <p> | |
| 55 | + * return count; | |
| 56 | + * } | |
| 57 | + */ | |
| 58 | + | |
| 59 | + protected void transformUpdown(GpsEntity gps, ScheduleRealInfo sch) { | |
| 60 | + int updown = Integer.parseInt(sch.getXlDir()); | |
| 61 | + List<StationRoute> srs = GeoCacheData.getStationRoute(sch.getXlBm(), updown); | |
| 62 | + StationRoute station = GeoUtils.gpsInStation(gps, srs); | |
| 63 | + if (station != null) { | |
| 64 | + gps.setUpDown(updown); | |
| 65 | + gps.setStopNo(station.getCode()); | |
| 66 | + } | |
| 67 | + } | |
| 68 | + | |
| 69 | + /** | |
| 70 | + * 是否是从异常状态恢复的第一个信号 | |
| 71 | + * | |
| 72 | + * @param gps | |
| 73 | + * @param prevs | |
| 74 | + * @return | |
| 75 | + */ | |
| 76 | + protected boolean abnormalRecovery(GpsEntity gps, CircleQueue<GpsEntity> prevs) { | |
| 77 | + if (prevs == null || prevs.size() == 0) | |
| 78 | + return false; | |
| 79 | + | |
| 80 | + GpsEntity prev = prevs.getTail(); | |
| 81 | + //从漂移状态恢复 | |
| 82 | + if (isDriftSignal(prev) | |
| 83 | + && !isDriftSignal(gps)) { | |
| 84 | + return true; | |
| 85 | + } | |
| 86 | + | |
| 87 | + return false; | |
| 88 | + } | |
| 89 | +} | |
| 0 | 90 | \ No newline at end of file | ... | ... |
src/main/java/com/bsth/data/gpsdata/arrival/entity/RouteReverse.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata.arrival.entity; | |
| 2 | + | |
| 3 | +/** 路由反转 | |
| 4 | + * Created by panzhao on 2016/12/28. | |
| 5 | + */ | |
| 6 | +public class RouteReverse { | |
| 7 | + | |
| 8 | + private String nbbm; | |
| 9 | + //反转个数 | |
| 10 | + private int count; | |
| 11 | + | |
| 12 | + //详细 1,2,3,2,1 | |
| 13 | + private String detail; | |
| 14 | + | |
| 15 | + //掉头站点 | |
| 16 | + private String turned; | |
| 17 | + | |
| 18 | + //掉头时间 | |
| 19 | + private long zt; | |
| 20 | + | |
| 21 | + //检测时间 | |
| 22 | + private long ct; | |
| 23 | + | |
| 24 | + //是否闭合 | |
| 25 | + private boolean close; | |
| 26 | + | |
| 27 | + //信号不明确 | |
| 28 | + private boolean vague; | |
| 29 | + | |
| 30 | + public int getCount() { | |
| 31 | + return count; | |
| 32 | + } | |
| 33 | + | |
| 34 | + public void setCount(int count) { | |
| 35 | + this.count = count; | |
| 36 | + } | |
| 37 | + | |
| 38 | + public String getDetail() { | |
| 39 | + return detail; | |
| 40 | + } | |
| 41 | + | |
| 42 | + public void setDetail(String detail) { | |
| 43 | + this.detail = detail; | |
| 44 | + } | |
| 45 | + | |
| 46 | + public String getTurned() { | |
| 47 | + return turned; | |
| 48 | + } | |
| 49 | + | |
| 50 | + public void setTurned(String turned) { | |
| 51 | + this.turned = turned; | |
| 52 | + } | |
| 53 | + | |
| 54 | + public boolean isClose() { | |
| 55 | + return close; | |
| 56 | + } | |
| 57 | + | |
| 58 | + public void setClose(boolean close) { | |
| 59 | + this.close = close; | |
| 60 | + } | |
| 61 | + | |
| 62 | + public long getZt() { | |
| 63 | + return zt; | |
| 64 | + } | |
| 65 | + | |
| 66 | + public void setZt(long zt) { | |
| 67 | + this.zt = zt; | |
| 68 | + } | |
| 69 | + | |
| 70 | + public long getCt() { | |
| 71 | + return ct; | |
| 72 | + } | |
| 73 | + | |
| 74 | + public void setCt(long ct) { | |
| 75 | + this.ct = ct; | |
| 76 | + } | |
| 77 | + | |
| 78 | + public String getNbbm() { | |
| 79 | + return nbbm; | |
| 80 | + } | |
| 81 | + | |
| 82 | + public void setNbbm(String nbbm) { | |
| 83 | + this.nbbm = nbbm; | |
| 84 | + } | |
| 85 | + | |
| 86 | + public boolean isVague() { | |
| 87 | + return vague; | |
| 88 | + } | |
| 89 | + | |
| 90 | + public void setVague(boolean vague) { | |
| 91 | + this.vague = vague; | |
| 92 | + } | |
| 93 | +} | |
| 0 | 94 | \ No newline at end of file | ... | ... |
src/main/java/com/bsth/data/gpsdata/arrival/entity/SignalAbnormal.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata.arrival.entity; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * 班次信号异常(漂移 或 断线) | |
| 5 | + * Created by panzhao on 2016/12/31. | |
| 6 | + */ | |
| 7 | +public class SignalAbnormal { | |
| 8 | + | |
| 9 | + private Long et; | |
| 10 | + | |
| 11 | + /** drift or reconnection */ | |
| 12 | + private String abnormalType; | |
| 13 | + | |
| 14 | + private Long st; | |
| 15 | + | |
| 16 | + private String nearPoint; | |
| 17 | + | |
| 18 | + private String destCode; | |
| 19 | + | |
| 20 | + private Long ct; | |
| 21 | + | |
| 22 | + //0: 发车 1:到站 | |
| 23 | + private int outOrIn; | |
| 24 | + | |
| 25 | + public Long getEt() { | |
| 26 | + return et; | |
| 27 | + } | |
| 28 | + | |
| 29 | + public void setEt(Long et) { | |
| 30 | + this.et = et; | |
| 31 | + } | |
| 32 | + | |
| 33 | + public String getAbnormalType() { | |
| 34 | + return abnormalType; | |
| 35 | + } | |
| 36 | + | |
| 37 | + public void setAbnormalType(String abnormalType) { | |
| 38 | + this.abnormalType = abnormalType; | |
| 39 | + } | |
| 40 | + | |
| 41 | + public Long getSt() { | |
| 42 | + return st; | |
| 43 | + } | |
| 44 | + | |
| 45 | + public void setSt(Long st) { | |
| 46 | + this.st = st; | |
| 47 | + } | |
| 48 | + | |
| 49 | + public String getNearPoint() { | |
| 50 | + return nearPoint; | |
| 51 | + } | |
| 52 | + | |
| 53 | + public void setNearPoint(String nearPoint) { | |
| 54 | + this.nearPoint = nearPoint; | |
| 55 | + } | |
| 56 | + | |
| 57 | + public Long getCt() { | |
| 58 | + return ct; | |
| 59 | + } | |
| 60 | + | |
| 61 | + public void setCt(Long ct) { | |
| 62 | + this.ct = ct; | |
| 63 | + } | |
| 64 | + | |
| 65 | + public int getOutOrIn() { | |
| 66 | + return outOrIn; | |
| 67 | + } | |
| 68 | + | |
| 69 | + public void setOutOrIn(int outOrIn) { | |
| 70 | + this.outOrIn = outOrIn; | |
| 71 | + } | |
| 72 | + | |
| 73 | + public String getDestCode() { | |
| 74 | + return destCode; | |
| 75 | + } | |
| 76 | + | |
| 77 | + public void setDestCode(String destCode) { | |
| 78 | + this.destCode = destCode; | |
| 79 | + } | |
| 80 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata/arrival/entity/SignalState.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata.arrival.entity; | |
| 2 | + | |
| 3 | +import com.bsth.data.BasicData; | |
| 4 | +import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 5 | +import org.joda.time.format.DateTimeFormat; | |
| 6 | +import org.joda.time.format.DateTimeFormatter; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * 信号状态 | |
| 10 | + * Created by panzhao on 2016/12/30. | |
| 11 | + */ | |
| 12 | +public class SignalState { | |
| 13 | + | |
| 14 | + private String type; | |
| 15 | + | |
| 16 | + private Long st; | |
| 17 | + | |
| 18 | + //private Long checkTime; | |
| 19 | + | |
| 20 | + private Long schId; | |
| 21 | + | |
| 22 | + private String lineCode; | |
| 23 | + | |
| 24 | + private String text; | |
| 25 | + | |
| 26 | + private RouteReverse reverse; | |
| 27 | + | |
| 28 | + private SignalAbnormal signalAbnormal; | |
| 29 | + | |
| 30 | + private static DateTimeFormatter fmtHHmm = DateTimeFormat.forPattern("HH:mm"); | |
| 31 | + | |
| 32 | + /** | |
| 33 | + * 记录区间调头 | |
| 34 | + * | |
| 35 | + * @param sch | |
| 36 | + * @param reverse | |
| 37 | + * @return | |
| 38 | + */ | |
| 39 | + public static SignalState reverseSignalSTate(ScheduleRealInfo sch, RouteReverse reverse) { | |
| 40 | + /*if(reverse.isVague()) | |
| 41 | + return null;*/ | |
| 42 | + | |
| 43 | + SignalState state = new SignalState(); | |
| 44 | + state.setSchId(sch.getId()); | |
| 45 | + state.setType("route_reverse"); | |
| 46 | + //state.setCheckTime(System.currentTimeMillis()); | |
| 47 | + | |
| 48 | + String stationName = BasicData.stationCode2NameMap.get(sch.getXlBm() + "_" + sch.getXlDir() + "_" + reverse.getTurned()); | |
| 49 | + state.setText(fmtHHmm.print(reverse.getZt()) + " 从 " + stationName + " 站掉头"); | |
| 50 | + state.setSt(sch.getFcsjActualTime()); | |
| 51 | + state.setLineCode(sch.getXlBm()); | |
| 52 | + state.setReverse(reverse); | |
| 53 | + return state; | |
| 54 | + } | |
| 55 | + | |
| 56 | + public static SignalState abnormalSignalSTate(ScheduleRealInfo sch, SignalAbnormal signalAbnormal) { | |
| 57 | + SignalState state = new SignalState(); | |
| 58 | + state.setSchId(sch.getId()); | |
| 59 | + state.setType("abnormal_signal"); | |
| 60 | + //state.setCheckTime(signalAbnormal.getCt()); | |
| 61 | + state.setLineCode(sch.getXlBm()); | |
| 62 | + | |
| 63 | + String text = (fmtHHmm.print(signalAbnormal.getSt()) + " ~ " + fmtHHmm.print(signalAbnormal.getEt())); | |
| 64 | + String abnormType = signalAbnormal.getAbnormalType(); | |
| 65 | + if (abnormType.equals("drift")) | |
| 66 | + text += "(GPS无效)"; | |
| 67 | + else if (abnormType.equals("reconnection")) | |
| 68 | + text += "(信号丢失)"; | |
| 69 | + | |
| 70 | + state.setText(text); | |
| 71 | + state.setSignalAbnormal(signalAbnormal); | |
| 72 | + return state; | |
| 73 | + } | |
| 74 | + | |
| 75 | + public String getType() { | |
| 76 | + return type; | |
| 77 | + } | |
| 78 | + | |
| 79 | + public void setType(String type) { | |
| 80 | + this.type = type; | |
| 81 | + } | |
| 82 | + | |
| 83 | + public long getSchId() { | |
| 84 | + return schId; | |
| 85 | + } | |
| 86 | + | |
| 87 | + public void setSchId(long schId) { | |
| 88 | + this.schId = schId; | |
| 89 | + } | |
| 90 | + | |
| 91 | + public String getLineCode() { | |
| 92 | + return lineCode; | |
| 93 | + } | |
| 94 | + | |
| 95 | + public void setLineCode(String lineCode) { | |
| 96 | + this.lineCode = lineCode; | |
| 97 | + } | |
| 98 | + | |
| 99 | + public Long getSt() { | |
| 100 | + return st; | |
| 101 | + } | |
| 102 | + | |
| 103 | + public void setSt(Long st) { | |
| 104 | + this.st = st; | |
| 105 | + } | |
| 106 | + | |
| 107 | + public String getText() { | |
| 108 | + return text; | |
| 109 | + } | |
| 110 | + | |
| 111 | + public void setText(String text) { | |
| 112 | + this.text = text; | |
| 113 | + } | |
| 114 | + | |
| 115 | + public RouteReverse getReverse() { | |
| 116 | + return reverse; | |
| 117 | + } | |
| 118 | + | |
| 119 | + public void setReverse(RouteReverse reverse) { | |
| 120 | + this.reverse = reverse; | |
| 121 | + } | |
| 122 | + | |
| 123 | + public SignalAbnormal getSignalAbnormal() { | |
| 124 | + return signalAbnormal; | |
| 125 | + } | |
| 126 | + | |
| 127 | + public void setSignalAbnormal(SignalAbnormal signalAbnormal) { | |
| 128 | + this.signalAbnormal = signalAbnormal; | |
| 129 | + } | |
| 130 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata/analyse/StationRoute.java renamed to src/main/java/com/bsth/data/gpsdata/arrival/entity/StationRoute.java
| 1 | -package com.bsth.data.gpsdata.analyse; | |
| 2 | - | |
| 3 | -import com.vividsolutions.jts.geom.Point; | |
| 4 | -import com.vividsolutions.jts.geom.Polygon; | |
| 5 | - | |
| 6 | -/** | |
| 7 | - * Created by panzhao on 2016/12/23. | |
| 8 | - */ | |
| 9 | -public class StationRoute { | |
| 10 | - | |
| 11 | - /** | |
| 12 | - * 线路编码 | |
| 13 | - */ | |
| 14 | - private String lineCode; | |
| 15 | - | |
| 16 | - /** | |
| 17 | - * 上下行 | |
| 18 | - */ | |
| 19 | - private int directions; | |
| 20 | - | |
| 21 | - /** | |
| 22 | - * 站点编码 | |
| 23 | - */ | |
| 24 | - private String code; | |
| 25 | - | |
| 26 | - /** | |
| 27 | - * 路由顺序 | |
| 28 | - */ | |
| 29 | - private int routeSort; | |
| 30 | - | |
| 31 | - /** | |
| 32 | - * 站点位置 | |
| 33 | - */ | |
| 34 | - private Point point; | |
| 35 | - | |
| 36 | - /** | |
| 37 | - * 圆形半径 | |
| 38 | - */ | |
| 39 | - private Float radius; | |
| 40 | - | |
| 41 | - /** | |
| 42 | - * 多边形电子围栏 | |
| 43 | - */ | |
| 44 | - private Polygon polygon; | |
| 45 | - | |
| 46 | - /** | |
| 47 | - * 站点标记 | |
| 48 | - */ | |
| 49 | - private String mark; | |
| 50 | - | |
| 51 | - /** | |
| 52 | - * 下一站 | |
| 53 | - */ | |
| 54 | - private StationRoute next; | |
| 55 | - | |
| 56 | - /** | |
| 57 | - * 上一站 | |
| 58 | - */ | |
| 59 | - private StationRoute prve; | |
| 60 | - | |
| 61 | - public String getCode() { | |
| 62 | - return code; | |
| 63 | - } | |
| 64 | - | |
| 65 | - public void setCode(String code) { | |
| 66 | - this.code = code; | |
| 67 | - } | |
| 68 | - | |
| 69 | - public int getRouteSort() { | |
| 70 | - return routeSort; | |
| 71 | - } | |
| 72 | - | |
| 73 | - public void setRouteSort(int routeSort) { | |
| 74 | - this.routeSort = routeSort; | |
| 75 | - } | |
| 76 | - | |
| 77 | - public Point getPoint() { | |
| 78 | - return point; | |
| 79 | - } | |
| 80 | - | |
| 81 | - public void setPoint(Point point) { | |
| 82 | - this.point = point; | |
| 83 | - } | |
| 84 | - | |
| 85 | - public Float getRadius() { | |
| 86 | - return radius; | |
| 87 | - } | |
| 88 | - | |
| 89 | - public void setRadius(Float radius) { | |
| 90 | - this.radius = radius; | |
| 91 | - } | |
| 92 | - | |
| 93 | - public Polygon getPolygon() { | |
| 94 | - return polygon; | |
| 95 | - } | |
| 96 | - | |
| 97 | - public void setPolygon(Polygon polygon) { | |
| 98 | - this.polygon = polygon; | |
| 99 | - } | |
| 100 | - | |
| 101 | - public String getLineCode() { | |
| 102 | - return lineCode; | |
| 103 | - } | |
| 104 | - | |
| 105 | - public void setLineCode(String lineCode) { | |
| 106 | - this.lineCode = lineCode; | |
| 107 | - } | |
| 108 | - | |
| 109 | - public int getDirections() { | |
| 110 | - return directions; | |
| 111 | - } | |
| 112 | - | |
| 113 | - public void setDirections(int directions) { | |
| 114 | - this.directions = directions; | |
| 115 | - } | |
| 116 | - | |
| 117 | - public StationRoute getNext() { | |
| 118 | - return next; | |
| 119 | - } | |
| 120 | - | |
| 121 | - public void setNext(StationRoute next) { | |
| 122 | - this.next = next; | |
| 123 | - } | |
| 124 | - | |
| 125 | - public StationRoute getPrve() { | |
| 126 | - return prve; | |
| 127 | - } | |
| 128 | - | |
| 129 | - public void setPrve(StationRoute prve) { | |
| 130 | - this.prve = prve; | |
| 131 | - } | |
| 132 | - | |
| 133 | - public String getMark() { | |
| 134 | - return mark; | |
| 135 | - } | |
| 136 | - | |
| 137 | - public void setMark(String mark) { | |
| 138 | - this.mark = mark; | |
| 139 | - } | |
| 140 | -} | |
| 141 | - | |
| 1 | +package com.bsth.data.gpsdata.arrival.entity; | |
| 2 | + | |
| 3 | +import com.vividsolutions.jts.geom.Point; | |
| 4 | +import com.vividsolutions.jts.geom.Polygon; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * Created by panzhao on 2016/12/23. | |
| 8 | + */ | |
| 9 | +public class StationRoute { | |
| 10 | + | |
| 11 | + /** | |
| 12 | + * 线路编码 | |
| 13 | + */ | |
| 14 | + private String lineCode; | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * 上下行 | |
| 18 | + */ | |
| 19 | + private int directions; | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * 站点编码 | |
| 23 | + */ | |
| 24 | + private String code; | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * 路由顺序 | |
| 28 | + */ | |
| 29 | + private int routeSort; | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * 站点位置 | |
| 33 | + */ | |
| 34 | + private Point point; | |
| 35 | + | |
| 36 | + /** | |
| 37 | + * 圆形半径 | |
| 38 | + */ | |
| 39 | + private Float radius; | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * 多边形电子围栏 | |
| 43 | + */ | |
| 44 | + private Polygon polygon; | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * 站点标记 | |
| 48 | + */ | |
| 49 | + private String mark; | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * 下一站 | |
| 53 | + */ | |
| 54 | + private StationRoute next; | |
| 55 | + | |
| 56 | + /** | |
| 57 | + * 上一站 | |
| 58 | + */ | |
| 59 | + private StationRoute prve; | |
| 60 | + | |
| 61 | + private String name; | |
| 62 | + | |
| 63 | + public String getCode() { | |
| 64 | + return code; | |
| 65 | + } | |
| 66 | + | |
| 67 | + public void setCode(String code) { | |
| 68 | + this.code = code; | |
| 69 | + } | |
| 70 | + | |
| 71 | + public int getRouteSort() { | |
| 72 | + return routeSort; | |
| 73 | + } | |
| 74 | + | |
| 75 | + public void setRouteSort(int routeSort) { | |
| 76 | + this.routeSort = routeSort; | |
| 77 | + } | |
| 78 | + | |
| 79 | + public Point getPoint() { | |
| 80 | + return point; | |
| 81 | + } | |
| 82 | + | |
| 83 | + public void setPoint(Point point) { | |
| 84 | + this.point = point; | |
| 85 | + } | |
| 86 | + | |
| 87 | + public Float getRadius() { | |
| 88 | + return radius; | |
| 89 | + } | |
| 90 | + | |
| 91 | + public void setRadius(Float radius) { | |
| 92 | + this.radius = radius; | |
| 93 | + } | |
| 94 | + | |
| 95 | + public Polygon getPolygon() { | |
| 96 | + return polygon; | |
| 97 | + } | |
| 98 | + | |
| 99 | + public void setPolygon(Polygon polygon) { | |
| 100 | + this.polygon = polygon; | |
| 101 | + } | |
| 102 | + | |
| 103 | + public String getLineCode() { | |
| 104 | + return lineCode; | |
| 105 | + } | |
| 106 | + | |
| 107 | + public void setLineCode(String lineCode) { | |
| 108 | + this.lineCode = lineCode; | |
| 109 | + } | |
| 110 | + | |
| 111 | + public int getDirections() { | |
| 112 | + return directions; | |
| 113 | + } | |
| 114 | + | |
| 115 | + public void setDirections(int directions) { | |
| 116 | + this.directions = directions; | |
| 117 | + } | |
| 118 | + | |
| 119 | + public StationRoute getNext() { | |
| 120 | + return next; | |
| 121 | + } | |
| 122 | + | |
| 123 | + public void setNext(StationRoute next) { | |
| 124 | + this.next = next; | |
| 125 | + } | |
| 126 | + | |
| 127 | + public StationRoute getPrve() { | |
| 128 | + return prve; | |
| 129 | + } | |
| 130 | + | |
| 131 | + public void setPrve(StationRoute prve) { | |
| 132 | + this.prve = prve; | |
| 133 | + } | |
| 134 | + | |
| 135 | + public String getMark() { | |
| 136 | + return mark; | |
| 137 | + } | |
| 138 | + | |
| 139 | + public void setMark(String mark) { | |
| 140 | + this.mark = mark; | |
| 141 | + } | |
| 142 | + | |
| 143 | + public String getName() { | |
| 144 | + return name; | |
| 145 | + } | |
| 146 | + | |
| 147 | + public void setName(String name) { | |
| 148 | + this.name = name; | |
| 149 | + } | |
| 150 | +} | |
| 151 | + | ... | ... |
src/main/java/com/bsth/data/gpsdata/arrival/handlers/CorrectSignalHandle.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata.arrival.handlers; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata.GpsEntity; | |
| 4 | +import com.bsth.data.gpsdata.arrival.SignalHandle; | |
| 5 | +import com.bsth.data.gpsdata.arrival.utils.CircleQueue; | |
| 6 | +import com.bsth.data.schedule.DayOfSchedule; | |
| 7 | +import com.bsth.entity.realcontrol.ChildTaskPlan; | |
| 8 | +import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 9 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 10 | +import org.springframework.stereotype.Component; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 信号状态纠正 | |
| 14 | + * Created by panzhao on 2016/12/27. | |
| 15 | + */ | |
| 16 | +@Component | |
| 17 | +public class CorrectSignalHandle extends SignalHandle { | |
| 18 | + | |
| 19 | + @Autowired | |
| 20 | + DayOfSchedule dayOfSchedule; | |
| 21 | + | |
| 22 | + @Override | |
| 23 | + public boolean handle(GpsEntity gps, CircleQueue<GpsEntity> prevs) { | |
| 24 | + Object task = dayOfSchedule.executeCurr(gps.getNbbm()); | |
| 25 | + if(task == null) | |
| 26 | + return false; | |
| 27 | + ScheduleRealInfo sch; | |
| 28 | + | |
| 29 | + //子任务 | |
| 30 | + if(task.getClass().isAssignableFrom(ChildTaskPlan.class)){ | |
| 31 | + ChildTaskPlan childTask = (ChildTaskPlan) task; | |
| 32 | + sch = childTask.getSchedule(); | |
| 33 | + } | |
| 34 | + else | |
| 35 | + sch = (ScheduleRealInfo) task; | |
| 36 | + | |
| 37 | + int updown = Integer.parseInt(sch.getXlDir()); | |
| 38 | + //走向 | |
| 39 | + if(gps.getUpDown() != updown){ | |
| 40 | + gps.setUpDown(updown); | |
| 41 | + gps.setState(0); | |
| 42 | + } | |
| 43 | + | |
| 44 | + | |
| 45 | + return true; | |
| 46 | + } | |
| 47 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata/arrival/handlers/InOutStationSignalHandle.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata.arrival.handlers; | |
| 2 | + | |
| 3 | +import com.bsth.data.LineConfigData; | |
| 4 | +import com.bsth.data.gpsdata.GpsEntity; | |
| 5 | +import com.bsth.data.gpsdata.arrival.SignalHandle; | |
| 6 | +import com.bsth.data.gpsdata.arrival.utils.CircleQueue; | |
| 7 | +import com.bsth.data.gpsdata.arrival.utils.ScheduleSignalState; | |
| 8 | +import com.bsth.data.gpsdata.arrival.utils.SignalSchPlanMatcher; | |
| 9 | +import com.bsth.data.schedule.DayOfSchedule; | |
| 10 | +import com.bsth.entity.realcontrol.LineConfig; | |
| 11 | +import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 12 | +import com.bsth.service.directive.DirectiveService; | |
| 13 | +import com.bsth.websocket.handler.SendUtils; | |
| 14 | +import org.apache.commons.lang3.StringUtils; | |
| 15 | +import org.slf4j.Logger; | |
| 16 | +import org.slf4j.LoggerFactory; | |
| 17 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 18 | +import org.springframework.stereotype.Component; | |
| 19 | + | |
| 20 | +/** | |
| 21 | + * 进出站动作处理 | |
| 22 | + * Created by panzhao on 2016/12/27. | |
| 23 | + */ | |
| 24 | +@Component | |
| 25 | +public class InOutStationSignalHandle extends SignalHandle{ | |
| 26 | + | |
| 27 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 28 | + | |
| 29 | + @Autowired | |
| 30 | + DayOfSchedule dayOfSchedule; | |
| 31 | + | |
| 32 | + @Autowired | |
| 33 | + LineConfigData lineConfigData; | |
| 34 | + | |
| 35 | + @Autowired | |
| 36 | + SendUtils sendUtils; | |
| 37 | + | |
| 38 | + @Autowired | |
| 39 | + DirectiveService directiveService; | |
| 40 | + | |
| 41 | + @Autowired | |
| 42 | + ScheduleSignalState scheduleSignalState; | |
| 43 | + | |
| 44 | + @Autowired | |
| 45 | + SignalSchPlanMatcher signalSchPlanMatcher; | |
| 46 | + | |
| 47 | + private final static int MAX_BEFORE_TIME = 1000 * 60 * 72; | |
| 48 | + | |
| 49 | + @Override | |
| 50 | + public boolean handle(GpsEntity gps, CircleQueue<GpsEntity> prevs) { | |
| 51 | + //忽略漂移信号 | |
| 52 | + if(isDriftSignal(gps)) | |
| 53 | + return false; | |
| 54 | + | |
| 55 | + //从异常状态恢复的第一个信号 | |
| 56 | + if(abnormalRecovery(gps, prevs)){ | |
| 57 | + //回溯一下之前的轨迹 | |
| 58 | + scheduleSignalState.signalRetrospect(gps); | |
| 59 | + } | |
| 60 | + | |
| 61 | + if(isNotEmpty(prevs)){ | |
| 62 | + GpsEntity prev = prevs.getTail(); | |
| 63 | + if(isOutStation(gps, prev)) | |
| 64 | + outStation(gps, prev); | |
| 65 | + | |
| 66 | + | |
| 67 | + if(isInStation(gps, prev)) | |
| 68 | + inStation(gps, prev); | |
| 69 | + } | |
| 70 | + | |
| 71 | + return true; | |
| 72 | + } | |
| 73 | + | |
| 74 | + private boolean isOutStation(GpsEntity gps, GpsEntity prev){ | |
| 75 | + //从站内到站外 | |
| 76 | + if(prev.getInstation() > 0 && gps.getInstation() == 0) | |
| 77 | + return true; | |
| 78 | + | |
| 79 | + //从站内到另一个站内 | |
| 80 | + if(prev.getInstation() > 0 && gps.getInstation() > 0 | |
| 81 | + && !prev.getStopNo().equals(gps.getStopNo())) | |
| 82 | + return true; | |
| 83 | + return false; | |
| 84 | + } | |
| 85 | + | |
| 86 | + private boolean isInStation(GpsEntity gps, GpsEntity prev){ | |
| 87 | + //从站外到站内 | |
| 88 | + if(prev.getInstation() == 0 && gps.getInstation() > 0 | |
| 89 | + /*&& !prev.getStopNo().equals(gps.getStopNo())*/){ | |
| 90 | + return true; | |
| 91 | + } | |
| 92 | + | |
| 93 | + //从站内到另一个站内 | |
| 94 | + if(prev.getInstation() > 0 && gps.getInstation() > 0 | |
| 95 | + && !prev.getStopNo().equals(gps.getStopNo())) | |
| 96 | + return true; | |
| 97 | + return false; | |
| 98 | + } | |
| 99 | + | |
| 100 | + /** | |
| 101 | + * 出站 | |
| 102 | + * @param gps 当前点 | |
| 103 | + * @param prev 上一个点 | |
| 104 | + */ | |
| 105 | + private void outStation(GpsEntity gps, GpsEntity prev) { | |
| 106 | + ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm()); | |
| 107 | + String qdzCode = sch.getQdzCode(); | |
| 108 | + | |
| 109 | + //首班出场最多提前1.2小时 | |
| 110 | + if(dayOfSchedule.isFirstOut(sch) && sch.getDfsjT() - gps.getTimestamp() > MAX_BEFORE_TIME) | |
| 111 | + return; | |
| 112 | + | |
| 113 | + //起点发车 | |
| 114 | + if(qdzCode != null && prev.getStopNo().equals(qdzCode) | |
| 115 | + && !willDepart(gps, prev, sch)){ | |
| 116 | + | |
| 117 | + //发车班次匹配 | |
| 118 | + signalSchPlanMatcher.outMatch(gps, sch); | |
| 119 | + sch = dayOfSchedule.executeCurr(gps.getNbbm()); | |
| 120 | + | |
| 121 | + //实发时间不覆盖 | |
| 122 | + if(StringUtils.isNotEmpty(sch.getFcsjActual())) | |
| 123 | + return; | |
| 124 | + | |
| 125 | + //实发时间 | |
| 126 | + sch.setFcsjActualAll(gps.getTimestamp()); | |
| 127 | + //通知客户端 | |
| 128 | + sendUtils.sendFcsj(sch); | |
| 129 | + //持久化 | |
| 130 | + dayOfSchedule.save(sch); | |
| 131 | + | |
| 132 | + //出站既出场 | |
| 133 | + outStationAndOutPark(sch); | |
| 134 | + logger.info("班次:" + sch.getDfsj() + "发车, 时间:" + sch.getFcsjActual()); | |
| 135 | + } | |
| 136 | + else if(sch.getBcType().equals("out")){ | |
| 137 | + ScheduleRealInfo next = dayOfSchedule.nextSame(sch); | |
| 138 | + if(prev.getStopNo().equals(next.getQdzCode())){ | |
| 139 | + //发下一个班次 | |
| 140 | + dayOfSchedule.addExecPlan(next); | |
| 141 | + outStation(gps, prev); | |
| 142 | + } | |
| 143 | + } | |
| 144 | + } | |
| 145 | + | |
| 146 | + | |
| 147 | + private void outStationAndOutPark(ScheduleRealInfo sch){ | |
| 148 | + LineConfig config = lineConfigData.get(sch.getXlBm()); | |
| 149 | + if (config != null && config.getOutConfig() == 2) { | |
| 150 | + //出站既出场 | |
| 151 | + ScheduleRealInfo schPrev = dayOfSchedule.prev(sch); | |
| 152 | + if (schPrev != null && schPrev.getBcType().equals("out")) { | |
| 153 | + schPrev.setFcsjActualAll(sch.getFcsjActualTime()); | |
| 154 | + schPrev.setZdsjActualAll(sch.getFcsjActualTime()); | |
| 155 | + | |
| 156 | + sendUtils.refreshSch(schPrev); | |
| 157 | + dayOfSchedule.save(schPrev); | |
| 158 | + } | |
| 159 | + } | |
| 160 | + } | |
| 161 | + | |
| 162 | + /** | |
| 163 | + * 进站 | |
| 164 | + * @param gps 当前点 | |
| 165 | + * @param prev 上一个点 | |
| 166 | + */ | |
| 167 | + private void inStation(GpsEntity gps, GpsEntity prev){ | |
| 168 | + ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm()); | |
| 169 | + | |
| 170 | + if(gps.getStopNo().equals(sch.getZdzCode())){ | |
| 171 | + | |
| 172 | + //实达时间不覆盖 | |
| 173 | + if(StringUtils.isNotEmpty(sch.getZdsjActual())) | |
| 174 | + return; | |
| 175 | + | |
| 176 | + sch.setZdsjActualAll(gps.getTimestamp()); | |
| 177 | + //已完成班次数 | |
| 178 | + int doneSum = dayOfSchedule.doneSum(sch.getClZbh()); | |
| 179 | + ScheduleRealInfo next = dayOfSchedule.next(sch); | |
| 180 | + //通知客户端 | |
| 181 | + sendUtils.sendZdsj(sch, next, doneSum); | |
| 182 | + //持久化 | |
| 183 | + dayOfSchedule.save(sch); | |
| 184 | + //下发调度指令 | |
| 185 | + directiveService.send60Dispatch(next, doneSum, "到站@系统"); | |
| 186 | + | |
| 187 | + //准备执行下一个班次 | |
| 188 | + if (next != null) { | |
| 189 | + next.setQdzArrDatesj(sch.getZdsjActual()); | |
| 190 | + dayOfSchedule.addExecPlan(next); | |
| 191 | + //进站既进场 | |
| 192 | + inStationAndInPark(sch, next); | |
| 193 | + //将gps转换为下一个班次走向的站内信号 | |
| 194 | + transformUpdown(gps, sch); | |
| 195 | + } | |
| 196 | + } | |
| 197 | + else if(sch.getFcsjActual() == null){ | |
| 198 | + //有进站,但班次没有实发,向前追溯一下信号 | |
| 199 | + scheduleSignalState.signalRetrospect(gps, sch); | |
| 200 | + } | |
| 201 | + } | |
| 202 | + | |
| 203 | + /** | |
| 204 | + * 进站既进场 | |
| 205 | + * @param sch | |
| 206 | + */ | |
| 207 | + private void inStationAndInPark(ScheduleRealInfo sch, ScheduleRealInfo next){ | |
| 208 | + LineConfig config = lineConfigData.get(sch.getXlBm()); | |
| 209 | + if (next.getBcType().equals("in") && | |
| 210 | + config != null && config.getOutConfig() == 2) { | |
| 211 | + next.setFcsjActualAll(sch.getZdsjActualTime()); | |
| 212 | + next.setZdsjActualAll(sch.getZdsjActualTime()); | |
| 213 | + | |
| 214 | + sendUtils.refreshSch(next); | |
| 215 | + dayOfSchedule.save(next); | |
| 216 | + } | |
| 217 | + } | |
| 218 | + | |
| 219 | + /** | |
| 220 | + * 发车漂移判定(这里出现的误判,由车辆到达中途站的时候补偿) | |
| 221 | + * @param gps | |
| 222 | + * @param prev | |
| 223 | + * @param task | |
| 224 | + * @return | |
| 225 | + */ | |
| 226 | + private boolean willDepart(GpsEntity gps, GpsEntity prev, Object task){ | |
| 227 | + | |
| 228 | + /*ScheduleRealInfo sch = (ScheduleRealInfo) task; | |
| 229 | + ScheduleRealInfo prevTask = dayOfSchedule.prev(sch); | |
| 230 | + if(prevTask == null || prevTask.getBcType().equals("out")) | |
| 231 | + return false; | |
| 232 | + | |
| 233 | + //计划停站时间 | |
| 234 | + int stopTimePlan = (int) (sch.getDfsjT() - prevTask.getZdsjT()); | |
| 235 | + | |
| 236 | + if(stopTimePlan < 1000 * 60 * 10) | |
| 237 | + return false; | |
| 238 | + | |
| 239 | + //实际停站时间 | |
| 240 | + if(prevTask.getZdsjActual() != null){ | |
| 241 | + int actualTime = (int) (gps.getTimestamp() - prevTask.getZdsjActualTime()); | |
| 242 | + | |
| 243 | + if(actualTime < stopTimePlan * 0.8){ | |
| 244 | + logger.info("漂移判定"); | |
| 245 | + | |
| 246 | + return true; | |
| 247 | + } | |
| 248 | + }*/ | |
| 249 | + return false; | |
| 250 | + } | |
| 251 | +} | |
| 0 | 252 | \ No newline at end of file | ... | ... |
src/main/java/com/bsth/data/gpsdata/arrival/handlers/OfflineSignalHandle.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata.arrival.handlers; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata.GpsEntity; | |
| 4 | +import com.bsth.data.gpsdata.arrival.GeoCacheData; | |
| 5 | +import com.bsth.data.gpsdata.arrival.SignalHandle; | |
| 6 | +import com.bsth.data.gpsdata.arrival.utils.CircleQueue; | |
| 7 | +import org.springframework.stereotype.Component; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * 信号断线重连处理 | |
| 11 | + * Created by panzhao on 2016/12/27. | |
| 12 | + */ | |
| 13 | +@Component | |
| 14 | +public class OfflineSignalHandle extends SignalHandle{ | |
| 15 | + | |
| 16 | + //断开2分钟,标记为重连信号 | |
| 17 | + private final static int OFFLINE_TIME = 1000 * 60 * 2; | |
| 18 | + | |
| 19 | + //断开70分钟,之前的信号不再有参考价值 | |
| 20 | + private final static int CLEAR_TIME = 1000 * 60 * 70; | |
| 21 | + | |
| 22 | + @Override | |
| 23 | + public boolean handle(GpsEntity gps, CircleQueue<GpsEntity> prevs) { | |
| 24 | + //漂移信号不管 | |
| 25 | + if(isDriftSignal(gps)){ | |
| 26 | + gps.setSignalState("drift"); | |
| 27 | + return true; | |
| 28 | + } | |
| 29 | + | |
| 30 | + if(isNotEmpty(prevs)){ | |
| 31 | + GpsEntity prev = prevs.getTail(); | |
| 32 | + int space = (int) (gps.getTimestamp() - prev.getTimestamp()); | |
| 33 | + if(space > OFFLINE_TIME) | |
| 34 | + gps.setSignalState("reconnection"); | |
| 35 | + | |
| 36 | + if(space > CLEAR_TIME){ | |
| 37 | + //清理缓存的信号 | |
| 38 | + GeoCacheData.clear(gps.getNbbm()); | |
| 39 | + } | |
| 40 | + } | |
| 41 | + return true; | |
| 42 | + } | |
| 43 | +} | |
| 0 | 44 | \ No newline at end of file | ... | ... |
src/main/java/com/bsth/data/gpsdata/arrival/handlers/ReverseSignalHandle.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata.arrival.handlers; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata.GpsEntity; | |
| 4 | +import com.bsth.data.gpsdata.arrival.GeoCacheData; | |
| 5 | +import com.bsth.data.gpsdata.arrival.SignalHandle; | |
| 6 | +import com.bsth.data.gpsdata.arrival.entity.RouteReverse; | |
| 7 | +import com.bsth.data.gpsdata.arrival.entity.StationRoute; | |
| 8 | +import com.bsth.data.gpsdata.arrival.utils.CircleQueue; | |
| 9 | +import com.bsth.data.gpsdata.arrival.utils.ScheduleSignalState; | |
| 10 | +import com.bsth.data.schedule.DayOfSchedule; | |
| 11 | +import org.slf4j.Logger; | |
| 12 | +import org.slf4j.LoggerFactory; | |
| 13 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 14 | +import org.springframework.stereotype.Component; | |
| 15 | + | |
| 16 | +/** | |
| 17 | + * 路由反向信号处理 | |
| 18 | + * Created by panzhao on 2016/12/28. | |
| 19 | + */ | |
| 20 | +@Component | |
| 21 | +public class ReverseSignalHandle extends SignalHandle { | |
| 22 | + | |
| 23 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 24 | + | |
| 25 | + @Autowired | |
| 26 | + DayOfSchedule dayOfSchedule; | |
| 27 | + | |
| 28 | + @Autowired | |
| 29 | + ScheduleSignalState scheduleSignalState; | |
| 30 | + | |
| 31 | + @Override | |
| 32 | + public boolean handle(GpsEntity gps, CircleQueue<GpsEntity> prevs) { | |
| 33 | + if (!isNotEmpty(prevs)) | |
| 34 | + return false; | |
| 35 | + | |
| 36 | + GpsEntity prev = prevs.getTail(); | |
| 37 | + | |
| 38 | + if (isReverse(gps, prev)) { | |
| 39 | + RouteReverse reverse = reverseSearch(prevs, gps); | |
| 40 | + | |
| 41 | + if (reverse.getCount() >= 3 | |
| 42 | + && reverse.isClose() | |
| 43 | + && !GeoCacheData.isEndStation(gps.getLineId(), gps.getUpDown(), reverse.getTurned())) { | |
| 44 | + scheduleSignalState.reverseAnalyse(reverse); | |
| 45 | + } | |
| 46 | + } | |
| 47 | + return false; | |
| 48 | + } | |
| 49 | + | |
| 50 | + /** | |
| 51 | + * 搜索路由反向详细 | |
| 52 | + * | |
| 53 | + * @param prevs | |
| 54 | + * @param gps | |
| 55 | + * @return | |
| 56 | + */ | |
| 57 | + public RouteReverse reverseSearch(CircleQueue<GpsEntity> prevs, GpsEntity gps) { | |
| 58 | + RouteReverse routeReverse = new RouteReverse(); | |
| 59 | + int count = 0; | |
| 60 | + String path = ""; | |
| 61 | + long zt = 0L; | |
| 62 | + boolean half = false; | |
| 63 | + | |
| 64 | + //当前站点 | |
| 65 | + StationRoute curr = GeoCacheData.getRouteCode(gps), sr; | |
| 66 | + GpsEntity prev; | |
| 67 | + Object[] array = prevs.getQueue(); | |
| 68 | + for (int i = array.length - 1; i > 0; i--) { | |
| 69 | + prev = (GpsEntity) array[i]; | |
| 70 | + | |
| 71 | + if (!prev.getUpDown().equals(gps.getUpDown()) | |
| 72 | + || prev.getSignalState().equals("reconnection")) | |
| 73 | + break; | |
| 74 | + | |
| 75 | + if (prev.getInstation() == 1) { | |
| 76 | + sr = GeoCacheData.getRouteCode(prev); | |
| 77 | + | |
| 78 | + if (sr.getRouteSort() > curr.getRouteSort()) { | |
| 79 | + if(half){ | |
| 80 | + routeReverse.setVague(true); | |
| 81 | + } | |
| 82 | + | |
| 83 | + path += (curr.getCode() + ","); | |
| 84 | + count++; | |
| 85 | + zt = prev.getTimestamp(); | |
| 86 | + } else if (sr.getRouteSort() < curr.getRouteSort()) { | |
| 87 | + if (routeReverse.getTurned() == null) { | |
| 88 | + routeReverse.setTurned(curr.getCode()); | |
| 89 | + half = true; | |
| 90 | + } | |
| 91 | + | |
| 92 | + path += (curr.getCode() + ","); | |
| 93 | + //掉头前当前站 | |
| 94 | + if (sr.getCode().equals(gps.getStopNo())) { | |
| 95 | + routeReverse.setClose(true); | |
| 96 | + path += sr.getCode(); | |
| 97 | + break; | |
| 98 | + } | |
| 99 | + } | |
| 100 | + | |
| 101 | + curr = sr; | |
| 102 | + } | |
| 103 | + } | |
| 104 | + | |
| 105 | + routeReverse.setZt(zt); | |
| 106 | + routeReverse.setCount(count); | |
| 107 | + routeReverse.setDetail(path); | |
| 108 | + routeReverse.setCt(gps.getTimestamp()); | |
| 109 | + routeReverse.setNbbm(gps.getNbbm()); | |
| 110 | + return routeReverse; | |
| 111 | + } | |
| 112 | + | |
| 113 | + /** | |
| 114 | + * 是否反向 | |
| 115 | + * | |
| 116 | + * @param gps | |
| 117 | + * @param prev | |
| 118 | + * @return | |
| 119 | + */ | |
| 120 | + public boolean isReverse(GpsEntity gps, GpsEntity prev) { | |
| 121 | + if (gps.getInstation() == 1 | |
| 122 | + && | |
| 123 | + gps.getUpDown().equals(prev.getUpDown()) | |
| 124 | + && !gps.getStopNo().equals(prev.getStopNo())) { | |
| 125 | + | |
| 126 | + StationRoute currStation = GeoCacheData.getRouteCode(gps); | |
| 127 | + StationRoute prevStation = GeoCacheData.getRouteCode(prev); | |
| 128 | + | |
| 129 | + if (currStation == null || prevStation == null) | |
| 130 | + return false; | |
| 131 | + | |
| 132 | + if (currStation.getRouteSort() < prevStation.getRouteSort()) | |
| 133 | + return true; | |
| 134 | + } | |
| 135 | + return false; | |
| 136 | + } | |
| 137 | +} | |
| 0 | 138 | \ No newline at end of file | ... | ... |
src/main/java/com/bsth/data/gpsdata/arrival/handlers/StationInsideHandle.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata.arrival.handlers; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata.GpsEntity; | |
| 4 | +import com.bsth.data.gpsdata.arrival.GeoCacheData; | |
| 5 | +import com.bsth.data.gpsdata.arrival.SignalHandle; | |
| 6 | +import com.bsth.data.gpsdata.arrival.entity.StationRoute; | |
| 7 | +import com.bsth.data.gpsdata.arrival.utils.CircleQueue; | |
| 8 | +import com.bsth.data.gpsdata.arrival.utils.GeoUtils; | |
| 9 | +import org.springframework.stereotype.Component; | |
| 10 | + | |
| 11 | +import java.util.List; | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * 站内站外判定 | |
| 15 | + * Created by panzhao on 2016/12/27. | |
| 16 | + */ | |
| 17 | +@Component | |
| 18 | +public class StationInsideHandle extends SignalHandle { | |
| 19 | + | |
| 20 | + | |
| 21 | + @Override | |
| 22 | + public boolean handle(GpsEntity gps, CircleQueue<GpsEntity> prevs) { | |
| 23 | + //是否在场内 | |
| 24 | + String parkCode = GeoUtils.gpsInCarpark(gps); | |
| 25 | + if (parkCode != null) { | |
| 26 | + gps.setInstation(2); | |
| 27 | + gps.setStopNo(parkCode); | |
| 28 | + } | |
| 29 | + | |
| 30 | + //是否在站内 | |
| 31 | + List<StationRoute> srs = GeoCacheData.getStationRoute(gps.getLineId(), gps.getUpDown()); | |
| 32 | + StationRoute station = GeoUtils.gpsInStation(gps, srs); | |
| 33 | + if (station != null) { | |
| 34 | + gps.setInstation(1); | |
| 35 | + gps.setStopNo(station.getCode()); | |
| 36 | + gps.setStation(station); | |
| 37 | + } | |
| 38 | + | |
| 39 | + //在场,站外 | |
| 40 | + if(gps.getInstation() == 0 && isNotEmpty(prevs)){ | |
| 41 | + //继承上一个点的站点编码 | |
| 42 | + GpsEntity prev = prevs.getTail(); | |
| 43 | + gps.setStopNo(prev.getStopNo()); | |
| 44 | + } | |
| 45 | + | |
| 46 | + return true; | |
| 47 | + } | |
| 48 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata/analyse/CircleQueue.java renamed to src/main/java/com/bsth/data/gpsdata/arrival/utils/CircleQueue.java
| 1 | -package com.bsth.data.gpsdata.analyse; | |
| 2 | - | |
| 3 | -import java.util.Arrays; | |
| 4 | - | |
| 5 | -/** | |
| 6 | - * 循环队列 | |
| 7 | - * Created by panzhao on 2016/12/23. | |
| 8 | - */ | |
| 9 | -public class CircleQueue<T> { | |
| 10 | - | |
| 11 | - /** | |
| 12 | - * (循环队列)数组的容量 | |
| 13 | - */ | |
| 14 | - public int capacity; | |
| 15 | - | |
| 16 | - /** | |
| 17 | - * 数组:保存循环队列的元素 | |
| 18 | - */ | |
| 19 | - public Object[] elementData; | |
| 20 | - | |
| 21 | - /** | |
| 22 | - * 队头(先进先出) | |
| 23 | - */ | |
| 24 | - public int head = 0; | |
| 25 | - | |
| 26 | - /** | |
| 27 | - * 队尾 | |
| 28 | - */ | |
| 29 | - public int tail = 0; | |
| 30 | - | |
| 31 | - /** | |
| 32 | - * 以指定长度的数组来创建循环队列 | |
| 33 | - * | |
| 34 | - * @param initSize | |
| 35 | - */ | |
| 36 | - public CircleQueue(final int initSize) { | |
| 37 | - capacity = initSize; | |
| 38 | - elementData = new Object[capacity]; | |
| 39 | - } | |
| 40 | - | |
| 41 | - /** | |
| 42 | - * 获取循环队列的大小(包含元素的个数) | |
| 43 | - */ | |
| 44 | - public int size() { | |
| 45 | - if (isEmpty()) { | |
| 46 | - return 0; | |
| 47 | - } else if (isFull()) { | |
| 48 | - return capacity; | |
| 49 | - } else { | |
| 50 | - return tail + 1; | |
| 51 | - } | |
| 52 | - } | |
| 53 | - | |
| 54 | - /** | |
| 55 | - * 插入队尾一个元素 | |
| 56 | - */ | |
| 57 | - public void add(final T element) { | |
| 58 | - if (isEmpty()) { | |
| 59 | - elementData[0] = element; | |
| 60 | - } else if (isFull()) { | |
| 61 | - elementData[head] = element; | |
| 62 | - head++; | |
| 63 | - tail++; | |
| 64 | - head = head == capacity ? 0 : head; | |
| 65 | - tail = tail == capacity ? 0 : tail; | |
| 66 | - } else { | |
| 67 | - elementData[tail + 1] = element; | |
| 68 | - tail++; | |
| 69 | - } | |
| 70 | - } | |
| 71 | - | |
| 72 | - public boolean isEmpty() { | |
| 73 | - return tail == head && tail == 0 && elementData[tail] == null; | |
| 74 | - } | |
| 75 | - | |
| 76 | - public boolean isFull() { | |
| 77 | - return head != 0 && head - tail == 1 || head == 0 && tail == capacity - 1; | |
| 78 | - } | |
| 79 | - | |
| 80 | - public void clear() { | |
| 81 | - Arrays.fill(elementData, null); | |
| 82 | - head = 0; | |
| 83 | - tail = 0; | |
| 84 | - } | |
| 85 | - | |
| 86 | - /** | |
| 87 | - * @return 取 循环队列里的值(先进的index=0) | |
| 88 | - */ | |
| 89 | - public Object[] getQueue() { | |
| 90 | - final Object[] elementDataSort = new Object[capacity]; | |
| 91 | - final Object[] elementDataCopy = elementData.clone(); | |
| 92 | - if (isEmpty()) { | |
| 93 | - } else if (isFull()) { | |
| 94 | - int indexMax = capacity; | |
| 95 | - int indexSort = 0; | |
| 96 | - for (int i = head; i < indexMax;) { | |
| 97 | - elementDataSort[indexSort] = elementDataCopy[i]; | |
| 98 | - indexSort++; | |
| 99 | - i++; | |
| 100 | - if (i == capacity) { | |
| 101 | - i = 0; | |
| 102 | - indexMax = head; | |
| 103 | - } | |
| 104 | - } | |
| 105 | - } else { | |
| 106 | - for (int i = 0; i < tail; i++) { | |
| 107 | - elementDataSort[i] = elementDataCopy[i]; | |
| 108 | - } | |
| 109 | - } | |
| 110 | - return elementDataSort; | |
| 111 | - } | |
| 112 | - | |
| 113 | - public T getTail(){ | |
| 114 | - return elementData[tail] == null?null:(T)elementData[tail]; | |
| 115 | - } | |
| 1 | +package com.bsth.data.gpsdata.arrival.utils; | |
| 2 | + | |
| 3 | +import java.util.Arrays; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * 循环队列 | |
| 7 | + * Created by panzhao on 2016/12/23. | |
| 8 | + */ | |
| 9 | +public class CircleQueue<T> { | |
| 10 | + | |
| 11 | + /** | |
| 12 | + * (循环队列)数组的容量 | |
| 13 | + */ | |
| 14 | + public int capacity; | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * 数组:保存循环队列的元素 | |
| 18 | + */ | |
| 19 | + public Object[] elementData; | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * 头 | |
| 23 | + */ | |
| 24 | + public int head = 0; | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * 尾 | |
| 28 | + */ | |
| 29 | + public int tail = 0; | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * 以指定长度的数组来创建循环队列 | |
| 33 | + * | |
| 34 | + * @param initSize | |
| 35 | + */ | |
| 36 | + public CircleQueue(final int initSize) { | |
| 37 | + capacity = initSize; | |
| 38 | + elementData = new Object[capacity]; | |
| 39 | + } | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * 获取循环队列的大小 | |
| 43 | + */ | |
| 44 | + public int size() { | |
| 45 | + if (isEmpty()) { | |
| 46 | + return 0; | |
| 47 | + } else if (isFull()) { | |
| 48 | + return capacity; | |
| 49 | + } else { | |
| 50 | + return tail + 1; | |
| 51 | + } | |
| 52 | + } | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * 插入队尾一个元素 | |
| 56 | + */ | |
| 57 | + public void add(final T element) { | |
| 58 | + if (isEmpty()) { | |
| 59 | + elementData[0] = element; | |
| 60 | + } else if (isFull()) { | |
| 61 | + elementData[head] = element; | |
| 62 | + head++; | |
| 63 | + tail++; | |
| 64 | + head = head == capacity ? 0 : head; | |
| 65 | + tail = tail == capacity ? 0 : tail; | |
| 66 | + } else { | |
| 67 | + elementData[tail + 1] = element; | |
| 68 | + tail++; | |
| 69 | + } | |
| 70 | + } | |
| 71 | + | |
| 72 | + public boolean isEmpty() { | |
| 73 | + return tail == head && tail == 0 && elementData[tail] == null; | |
| 74 | + } | |
| 75 | + | |
| 76 | + public boolean isFull() { | |
| 77 | + return head != 0 && head - tail == 1 || head == 0 && tail == capacity - 1; | |
| 78 | + } | |
| 79 | + | |
| 80 | + public void clear() { | |
| 81 | + Arrays.fill(elementData, null); | |
| 82 | + head = 0; | |
| 83 | + tail = 0; | |
| 84 | + } | |
| 85 | + | |
| 86 | + /** | |
| 87 | + * @return 取 循环队列里的值(先进的index=0) | |
| 88 | + */ | |
| 89 | + public Object[] getQueue() { | |
| 90 | + final Object[] elementDataSort; | |
| 91 | + final Object[] elementDataCopy = elementData.clone(); | |
| 92 | + if (isEmpty()) { | |
| 93 | + elementDataSort = new Object[0]; | |
| 94 | + } else if (isFull()) { | |
| 95 | + elementDataSort = new Object[capacity]; | |
| 96 | + int indexMax = capacity; | |
| 97 | + int indexSort = 0; | |
| 98 | + for (int i = head; i < indexMax;) { | |
| 99 | + elementDataSort[indexSort] = elementDataCopy[i]; | |
| 100 | + indexSort++; | |
| 101 | + i++; | |
| 102 | + if (i == capacity) { | |
| 103 | + i = 0; | |
| 104 | + indexMax = head; | |
| 105 | + } | |
| 106 | + } | |
| 107 | + } else { | |
| 108 | + elementDataSort = new Object[tail + 1]; | |
| 109 | + for (int i = 0; i <= tail; i++) { | |
| 110 | + elementDataSort[i] = elementDataCopy[i]; | |
| 111 | + } | |
| 112 | + } | |
| 113 | + return elementDataSort; | |
| 114 | + } | |
| 115 | + | |
| 116 | + /** | |
| 117 | + * 取最后一个值 | |
| 118 | + * @return | |
| 119 | + */ | |
| 120 | + public T getTail(){ | |
| 121 | + return elementData[tail] == null?null:(T)elementData[tail]; | |
| 122 | + } | |
| 116 | 123 | } |
| 117 | 124 | \ No newline at end of file | ... | ... |
src/main/java/com/bsth/data/gpsdata/analyse/util/GeoUtils.java renamed to src/main/java/com/bsth/data/gpsdata/arrival/utils/GeoUtils.java
| 1 | -package com.bsth.data.gpsdata.analyse.util; | |
| 2 | - | |
| 3 | -import com.bsth.data.gpsdata.GpsEntity; | |
| 4 | -import com.bsth.data.gpsdata.analyse.GeoCacheData; | |
| 5 | -import com.bsth.data.gpsdata.analyse.StationRoute; | |
| 6 | -import com.vividsolutions.jts.geom.Coordinate; | |
| 7 | -import com.vividsolutions.jts.geom.GeometryFactory; | |
| 8 | -import com.vividsolutions.jts.geom.Point; | |
| 9 | -import com.vividsolutions.jts.geom.Polygon; | |
| 10 | - | |
| 11 | -import java.util.List; | |
| 12 | -import java.util.Map; | |
| 13 | -import java.util.Set; | |
| 14 | - | |
| 15 | -/** | |
| 16 | - * Created by panzhao on 2016/12/23. | |
| 17 | - */ | |
| 18 | -public class GeoUtils { | |
| 19 | - | |
| 20 | - private final static double EARTHRADIUS = 6378137; | |
| 21 | - | |
| 22 | - private static GeometryFactory geometryFactory = new GeometryFactory(); | |
| 23 | - /** | |
| 24 | - * gps是否在路由上的某个站内 | |
| 25 | - * | |
| 26 | - * @param gps | |
| 27 | - * @param srs | |
| 28 | - * @return | |
| 29 | - */ | |
| 30 | - public static StationRoute gpsInStation(GpsEntity gps, List<StationRoute> srs) { | |
| 31 | - Point point = geometryFactory.createPoint(new Coordinate(gps.getLat(), gps.getLon())); | |
| 32 | - double min = -1, distance, distance2; | |
| 33 | - StationRoute stationRoute = null; | |
| 34 | - | |
| 35 | - for (StationRoute sr : srs) { | |
| 36 | - if (sr.getPolygon() == null) { | |
| 37 | - //圆形 | |
| 38 | - distance = getDistance(sr.getPoint(), point);//sr.getPoint().distance(point); | |
| 39 | - | |
| 40 | - if (distance > sr.getRadius()) | |
| 41 | - continue; | |
| 42 | - | |
| 43 | - if (min > distance || min == -1) { | |
| 44 | - min = distance; | |
| 45 | - stationRoute = sr; | |
| 46 | - } | |
| 47 | - } else { | |
| 48 | - //多边形 | |
| 49 | - if (sr.getPolygon().contains(point)) { | |
| 50 | - stationRoute = sr; | |
| 51 | - break; | |
| 52 | - } | |
| 53 | - } | |
| 54 | - } | |
| 55 | - return stationRoute; | |
| 56 | - } | |
| 57 | - | |
| 58 | - public static double getDistance(Point p1, Point p2) { | |
| 59 | - double lng1 = getLoop(p1.getY(), -180, 180), lat1 = getRange( | |
| 60 | - p1.getX(), -74, 74); | |
| 61 | - double lng2 = getLoop(p2.getY(), -180, 180), lat2 = getRange( | |
| 62 | - p2.getX(), -74, 74); | |
| 63 | - | |
| 64 | - double x1, x2, y1, y2; | |
| 65 | - x1 = degreeToRad(lng1); | |
| 66 | - y1 = degreeToRad(lat1); | |
| 67 | - x2 = degreeToRad(lng2); | |
| 68 | - y2 = degreeToRad(lat2); | |
| 69 | - return EARTHRADIUS | |
| 70 | - * Math.acos((Math.sin(y1) * Math.sin(y2) + Math.cos(y1) | |
| 71 | - * Math.cos(y2) * Math.cos(x2 - x1))); | |
| 72 | - } | |
| 73 | - | |
| 74 | - private static double getLoop(double v, double a, double b) { | |
| 75 | - while (v > b) { | |
| 76 | - v -= b - a; | |
| 77 | - } | |
| 78 | - while (v < a) { | |
| 79 | - v += b - a; | |
| 80 | - } | |
| 81 | - return v; | |
| 82 | - } | |
| 83 | - | |
| 84 | - private static double getRange(double v, double a, double b) { | |
| 85 | - v = Math.min(Math.max(v, a), b); | |
| 86 | - return v; | |
| 87 | - } | |
| 88 | - | |
| 89 | - private static double degreeToRad(double degree) { | |
| 90 | - return Math.PI * degree / 180; | |
| 91 | - } | |
| 92 | - | |
| 93 | - | |
| 94 | - /** | |
| 95 | - * gps 是否在某个停车场内 | |
| 96 | - * @param gps | |
| 97 | - * @return | |
| 98 | - */ | |
| 99 | - public static String gpsInCarpark(GpsEntity gps){ | |
| 100 | - Point point = geometryFactory.createPoint(new Coordinate(gps.getLat(), gps.getLon())); | |
| 101 | - | |
| 102 | - Map<String, Polygon> carparkMap = GeoCacheData.tccMap; | |
| 103 | - Set<String> codes = carparkMap.keySet(); | |
| 104 | - Polygon polygon; | |
| 105 | - for(String code : codes){ | |
| 106 | - polygon = carparkMap.get(code); | |
| 107 | - if(point.within(polygon)){ | |
| 108 | - return code; | |
| 109 | - } | |
| 110 | - } | |
| 111 | - return null; | |
| 112 | - } | |
| 113 | - | |
| 114 | - /** | |
| 115 | - * 是否是有效的连续点 | |
| 116 | - * @param prevGps | |
| 117 | - * @param gps | |
| 118 | - * @return | |
| 119 | - */ | |
| 120 | - public static boolean overdue(GpsEntity prevGps, GpsEntity gps) { | |
| 121 | - return gps.getTimestamp() - prevGps.getTimestamp() < 120000; | |
| 122 | - } | |
| 123 | -} | |
| 1 | +package com.bsth.data.gpsdata.arrival.utils; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata.GpsEntity; | |
| 4 | +import com.bsth.data.gpsdata.arrival.GeoCacheData; | |
| 5 | +import com.bsth.data.gpsdata.arrival.entity.StationRoute; | |
| 6 | +import com.vividsolutions.jts.geom.Coordinate; | |
| 7 | +import com.vividsolutions.jts.geom.GeometryFactory; | |
| 8 | +import com.vividsolutions.jts.geom.Point; | |
| 9 | +import com.vividsolutions.jts.geom.Polygon; | |
| 10 | + | |
| 11 | +import java.util.List; | |
| 12 | +import java.util.Map; | |
| 13 | +import java.util.Set; | |
| 14 | + | |
| 15 | +/** | |
| 16 | + * Created by panzhao on 2016/12/23. | |
| 17 | + */ | |
| 18 | +public class GeoUtils { | |
| 19 | + | |
| 20 | + private final static double EARTHRADIUS = 6378137; | |
| 21 | + | |
| 22 | + private static GeometryFactory geometryFactory = new GeometryFactory(); | |
| 23 | + /** | |
| 24 | + * gps是否在路由上的某个站内 | |
| 25 | + * | |
| 26 | + * @param gps | |
| 27 | + * @param srs | |
| 28 | + * @return | |
| 29 | + */ | |
| 30 | + public static StationRoute gpsInStation(GpsEntity gps, List<StationRoute> srs) { | |
| 31 | + Point point = geometryFactory.createPoint(new Coordinate(gps.getLat(), gps.getLon())); | |
| 32 | + double min = -1, distance, distance2; | |
| 33 | + StationRoute stationRoute = null; | |
| 34 | + | |
| 35 | + for (StationRoute sr : srs) { | |
| 36 | + if (sr.getPolygon() == null) { | |
| 37 | + //圆形 | |
| 38 | + distance = getDistance(sr.getPoint(), point);//sr.getPoint().distance(point); | |
| 39 | + | |
| 40 | + if (distance > sr.getRadius()) | |
| 41 | + continue; | |
| 42 | + | |
| 43 | + if (min > distance || min == -1) { | |
| 44 | + min = distance; | |
| 45 | + stationRoute = sr; | |
| 46 | + } | |
| 47 | + } else { | |
| 48 | + //多边形 | |
| 49 | + if (sr.getPolygon().contains(point)) { | |
| 50 | + stationRoute = sr; | |
| 51 | + break; | |
| 52 | + } | |
| 53 | + } | |
| 54 | + } | |
| 55 | + return stationRoute; | |
| 56 | + } | |
| 57 | + | |
| 58 | + public static double getDistance(Point p1, Point p2) { | |
| 59 | + double lng1 = getLoop(p1.getY(), -180, 180), lat1 = getRange( | |
| 60 | + p1.getX(), -74, 74); | |
| 61 | + double lng2 = getLoop(p2.getY(), -180, 180), lat2 = getRange( | |
| 62 | + p2.getX(), -74, 74); | |
| 63 | + | |
| 64 | + double x1, x2, y1, y2; | |
| 65 | + x1 = degreeToRad(lng1); | |
| 66 | + y1 = degreeToRad(lat1); | |
| 67 | + x2 = degreeToRad(lng2); | |
| 68 | + y2 = degreeToRad(lat2); | |
| 69 | + return EARTHRADIUS | |
| 70 | + * Math.acos((Math.sin(y1) * Math.sin(y2) + Math.cos(y1) | |
| 71 | + * Math.cos(y2) * Math.cos(x2 - x1))); | |
| 72 | + } | |
| 73 | + | |
| 74 | + private static double getLoop(double v, double a, double b) { | |
| 75 | + while (v > b) { | |
| 76 | + v -= b - a; | |
| 77 | + } | |
| 78 | + while (v < a) { | |
| 79 | + v += b - a; | |
| 80 | + } | |
| 81 | + return v; | |
| 82 | + } | |
| 83 | + | |
| 84 | + private static double getRange(double v, double a, double b) { | |
| 85 | + v = Math.min(Math.max(v, a), b); | |
| 86 | + return v; | |
| 87 | + } | |
| 88 | + | |
| 89 | + private static double degreeToRad(double degree) { | |
| 90 | + return Math.PI * degree / 180; | |
| 91 | + } | |
| 92 | + | |
| 93 | + | |
| 94 | + /** | |
| 95 | + * gps 是否在某个停车场内 | |
| 96 | + * @param gps | |
| 97 | + * @return | |
| 98 | + */ | |
| 99 | + public static String gpsInCarpark(GpsEntity gps){ | |
| 100 | + Point point = geometryFactory.createPoint(new Coordinate(gps.getLat(), gps.getLon())); | |
| 101 | + | |
| 102 | + Map<String, Polygon> carparkMap = GeoCacheData.tccMap; | |
| 103 | + Set<String> codes = carparkMap.keySet(); | |
| 104 | + Polygon polygon; | |
| 105 | + for(String code : codes){ | |
| 106 | + polygon = carparkMap.get(code); | |
| 107 | + if(point.within(polygon)){ | |
| 108 | + return code; | |
| 109 | + } | |
| 110 | + } | |
| 111 | + return null; | |
| 112 | + } | |
| 113 | + | |
| 114 | + /** | |
| 115 | + * 是否是有效的连续点 | |
| 116 | + * @param prevGps | |
| 117 | + * @param gps | |
| 118 | + * @return | |
| 119 | + */ | |
| 120 | + public static boolean overdue(GpsEntity prevGps, GpsEntity gps) { | |
| 121 | + return gps.getTimestamp() - prevGps.getTimestamp() < 120000; | |
| 122 | + } | |
| 123 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata/arrival/utils/ScheduleSignalState.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata.arrival.utils; | |
| 2 | + | |
| 3 | +import com.bsth.data.LineConfigData; | |
| 4 | +import com.bsth.data.gpsdata.GpsEntity; | |
| 5 | +import com.bsth.data.gpsdata.SignalStateData; | |
| 6 | +import com.bsth.data.gpsdata.arrival.GeoCacheData; | |
| 7 | +import com.bsth.data.gpsdata.arrival.entity.RouteReverse; | |
| 8 | +import com.bsth.data.gpsdata.arrival.entity.SignalAbnormal; | |
| 9 | +import com.bsth.data.gpsdata.arrival.entity.SignalState; | |
| 10 | +import com.bsth.data.schedule.DayOfSchedule; | |
| 11 | +import com.bsth.entity.realcontrol.LineConfig; | |
| 12 | +import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 13 | +import org.slf4j.Logger; | |
| 14 | +import org.slf4j.LoggerFactory; | |
| 15 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 16 | +import org.springframework.stereotype.Component; | |
| 17 | + | |
| 18 | +/** | |
| 19 | + * 班次信号状态分析 | |
| 20 | + * Created by panzhao on 2016/12/29. | |
| 21 | + */ | |
| 22 | +@Component | |
| 23 | +public class ScheduleSignalState { | |
| 24 | + | |
| 25 | + @Autowired | |
| 26 | + DayOfSchedule dayOfSchedule; | |
| 27 | + | |
| 28 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 29 | + | |
| 30 | + @Autowired | |
| 31 | + LineConfigData lineConfigData; | |
| 32 | + | |
| 33 | + @Autowired | |
| 34 | + SignalStateData signalStateData; | |
| 35 | + | |
| 36 | + /** | |
| 37 | + * 路由反向分析 | |
| 38 | + */ | |
| 39 | + public void reverseAnalyse(RouteReverse reverse) { | |
| 40 | + ScheduleRealInfo sch = dayOfSchedule.executeCurr(reverse.getNbbm()); | |
| 41 | + | |
| 42 | + String bcType = sch.getBcType(); | |
| 43 | + | |
| 44 | + switch (bcType) { | |
| 45 | + case "out": | |
| 46 | + outReverseAnalyse(sch, reverse); | |
| 47 | + break; | |
| 48 | + case "normal": | |
| 49 | + normalReverseAnalyse(sch, reverse); | |
| 50 | + break; | |
| 51 | + } | |
| 52 | + } | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * 出场班次路由反向分析 | |
| 56 | + * | |
| 57 | + * @param sch | |
| 58 | + */ | |
| 59 | + private void outReverseAnalyse(ScheduleRealInfo sch, RouteReverse reverse) { | |
| 60 | + long t = reverse.getCt(); | |
| 61 | + //出场班次终点时间前,允许反向轨迹 | |
| 62 | + if (sch.getZdsjT() != null && sch.getZdsjT() > t) { | |
| 63 | + return; | |
| 64 | + } | |
| 65 | + | |
| 66 | + int rt; | |
| 67 | + //从实发 到 当前时间 < 计划运送时间 * 0.9 | |
| 68 | + if (sch.getFcsjActual() != null && sch.getBcsj() != null) { | |
| 69 | + rt = (int) (t - sch.getFcsjActualTime()); | |
| 70 | + if (rt < sch.getBcsj() * 0.9) | |
| 71 | + return; | |
| 72 | + } | |
| 73 | + | |
| 74 | + ScheduleRealInfo next = dayOfSchedule.next(sch); | |
| 75 | + if (next.getXlDir().equals(sch.getXlDir())) | |
| 76 | + return; | |
| 77 | + | |
| 78 | + //时间足够下一个班次待发时间运行到当前站 | |
| 79 | + int runTime = reverse.getCount() * 1500 * 60; | |
| 80 | + if (next.getDfsjT() + runTime < t) { | |
| 81 | + //跳到下一个班次 | |
| 82 | + dayOfSchedule.addExecPlan(next); | |
| 83 | + } | |
| 84 | + } | |
| 85 | + | |
| 86 | + /** | |
| 87 | + * 正常班次路由反向分析 | |
| 88 | + * | |
| 89 | + * @param sch | |
| 90 | + * @param reverse | |
| 91 | + */ | |
| 92 | + private void normalReverseAnalyse(ScheduleRealInfo sch, RouteReverse reverse) { | |
| 93 | + LineConfig conf = lineConfigData.get(sch.getXlBm()); | |
| 94 | + | |
| 95 | + if (conf.isReadReverse()) { | |
| 96 | + //跳下一个班次 | |
| 97 | + ScheduleRealInfo next = dayOfSchedule.next(sch); | |
| 98 | + if (next != null) | |
| 99 | + dayOfSchedule.addExecPlan(next); | |
| 100 | + | |
| 101 | + //记录信号状态 | |
| 102 | + SignalState signalState = SignalState.reverseSignalSTate(sch, reverse); | |
| 103 | + if(signalState != null) | |
| 104 | + signalStateData.put(signalState); | |
| 105 | + } | |
| 106 | + } | |
| 107 | + | |
| 108 | + public void signalRetrospect(GpsEntity gps) { | |
| 109 | + signalRetrospect(gps, dayOfSchedule.executeCurr(gps.getNbbm())); | |
| 110 | + } | |
| 111 | + | |
| 112 | + /** | |
| 113 | + * 信号追溯 | |
| 114 | + * | |
| 115 | + * @param gps | |
| 116 | + * @param sch | |
| 117 | + */ | |
| 118 | + public void signalRetrospect(GpsEntity gps, ScheduleRealInfo sch) { | |
| 119 | + //回放数据,是否有掉线或者漂移 | |
| 120 | + CircleQueue<GpsEntity> queue = GeoCacheData.getGps(gps.getNbbm()); | |
| 121 | + if (queue == null || queue.size() == 0 /*|| gps.getInstation() == 0*/) | |
| 122 | + return; | |
| 123 | + | |
| 124 | + //起始时间点 | |
| 125 | + long st = 0; | |
| 126 | + ScheduleRealInfo prev = dayOfSchedule.prev(sch); | |
| 127 | + | |
| 128 | + if (prev != null) { | |
| 129 | + if (prev.getZdsjActual() != null) | |
| 130 | + st = prev.getZdsjActualTime(); | |
| 131 | + else | |
| 132 | + st = (GeoCacheData.midwayStation(gps.getLineId(), gps.getUpDown(), sch.getQdzCode(), gps.getStopNo()).size() + 1) * (1000 * 60 * 5); | |
| 133 | + } | |
| 134 | + | |
| 135 | + Object[] tempArray = queue.getQueue(); | |
| 136 | + int len = tempArray.length; | |
| 137 | + | |
| 138 | + Object[] array = new Object[len + 1]; | |
| 139 | + System.arraycopy(tempArray, 0, array, 0, len); | |
| 140 | + array[len] = gps; | |
| 141 | + | |
| 142 | + String gpsState = ""; | |
| 143 | + GpsEntity tempGps, nearGps = null; | |
| 144 | + int i = len - 1; | |
| 145 | + for (; i >= 0; i--) { | |
| 146 | + tempGps = (GpsEntity) array[i]; | |
| 147 | + | |
| 148 | + gpsState = tempGps.getSignalState(); | |
| 149 | + if (gpsState.equals("truncation")) | |
| 150 | + break; | |
| 151 | + else if (gpsState.equals("drift")) { | |
| 152 | + nearGps = (GpsEntity) array[i + 1]; | |
| 153 | + break; | |
| 154 | + } else if (gpsState.equals("reconnection")) { | |
| 155 | + nearGps = tempGps; | |
| 156 | + break; | |
| 157 | + } | |
| 158 | + | |
| 159 | + if (tempGps.getTimestamp() < st) | |
| 160 | + break; | |
| 161 | + } | |
| 162 | + | |
| 163 | + if (nearGps != null && i > 0) { | |
| 164 | + createSignalAbnormal(gpsState, nearGps, i, array, sch); | |
| 165 | + } | |
| 166 | + } | |
| 167 | + | |
| 168 | + private void createSignalAbnormal(String gpsState, GpsEntity nearGps, int i, Object[] array, ScheduleRealInfo sch) { | |
| 169 | + switch (gpsState) { | |
| 170 | + case "drift": | |
| 171 | + driftSignalAbnormal(nearGps, i, array, sch); | |
| 172 | + break; | |
| 173 | + case "reconnection": | |
| 174 | + offlineSignalAbnormal(nearGps, ((GpsEntity) array[i - 1]), sch); | |
| 175 | + break; | |
| 176 | + } | |
| 177 | + } | |
| 178 | + | |
| 179 | + /** | |
| 180 | + * 掉线异常状态记录 | |
| 181 | + * | |
| 182 | + * @param e | |
| 183 | + * @param s | |
| 184 | + */ | |
| 185 | + private void offlineSignalAbnormal(GpsEntity e, GpsEntity s, ScheduleRealInfo sch) { | |
| 186 | + long st = s.getTimestamp(), et = e.getTimestamp(); | |
| 187 | + | |
| 188 | + //掉线超过10分钟才记录 | |
| 189 | + if (et - st < (1000 * 60 * 10)) | |
| 190 | + return; | |
| 191 | + | |
| 192 | + SignalAbnormal signalAbnormal = new SignalAbnormal(); | |
| 193 | + signalAbnormal.setSt(st); | |
| 194 | + signalAbnormal.setEt(et); | |
| 195 | + signalAbnormal.setAbnormalType("reconnection"); | |
| 196 | + signalAbnormal.setDestCode(sch.getQdzCode()); | |
| 197 | + signalAbnormal.setOutOrIn(0); | |
| 198 | + | |
| 199 | + //截断GPS | |
| 200 | + e.setSignalState("truncation"); | |
| 201 | + | |
| 202 | + //记录信号状态 | |
| 203 | + SignalState signalState = SignalState.abnormalSignalSTate(sch, signalAbnormal); | |
| 204 | + signalStateData.put(signalState); | |
| 205 | + } | |
| 206 | + | |
| 207 | + /** | |
| 208 | + * 漂移异常状态记录 | |
| 209 | + * | |
| 210 | + * @param nearGps | |
| 211 | + * @param i | |
| 212 | + * @param array | |
| 213 | + */ | |
| 214 | + private void driftSignalAbnormal(GpsEntity nearGps, int i, Object[] array, ScheduleRealInfo sch) { | |
| 215 | + GpsEntity gps, s = null; | |
| 216 | + //找到漂移开始时间 | |
| 217 | + for (; i >= 0; i--) { | |
| 218 | + gps = (GpsEntity) array[i]; | |
| 219 | + | |
| 220 | + if (!gps.getSignalState().equals("drift") || i == 0 | |
| 221 | + || gps.getSignalState().equals("truncation")) { | |
| 222 | + s = gps; | |
| 223 | + break; | |
| 224 | + } | |
| 225 | + } | |
| 226 | + | |
| 227 | + long st = s.getTimestamp(), et = nearGps.getTimestamp(); | |
| 228 | + if (et - st < (1000 * 60 * 3)) | |
| 229 | + return; | |
| 230 | + /*if (s != null){ | |
| 231 | + st = s.getTimestamp(); | |
| 232 | + //漂移小于3分钟 | |
| 233 | + if(et - st < (1000 * 60 * 3)) | |
| 234 | + return; | |
| 235 | + }*/ | |
| 236 | + | |
| 237 | + | |
| 238 | + SignalAbnormal signalAbnormal = new SignalAbnormal(); | |
| 239 | + signalAbnormal.setSt(st); | |
| 240 | + signalAbnormal.setEt(et); | |
| 241 | + signalAbnormal.setAbnormalType("drift"); | |
| 242 | + signalAbnormal.setDestCode(sch.getQdzCode()); | |
| 243 | + signalAbnormal.setOutOrIn(0); | |
| 244 | + | |
| 245 | + //截断GPS | |
| 246 | + nearGps.setSignalState("truncation"); | |
| 247 | + | |
| 248 | + //记录信号状态 | |
| 249 | + SignalState signalState = SignalState.abnormalSignalSTate(sch, signalAbnormal); | |
| 250 | + signalStateData.put(signalState); | |
| 251 | + } | |
| 252 | +} | |
| 0 | 253 | \ No newline at end of file | ... | ... |
src/main/java/com/bsth/data/gpsdata/arrival/utils/SignalSchPlanMatcher.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata.arrival.utils; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata.GpsEntity; | |
| 4 | +import com.bsth.data.schedule.DayOfSchedule; | |
| 5 | +import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 6 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 7 | +import org.springframework.stereotype.Component; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * 班次匹配器 | |
| 11 | + * Created by panzhao on 2016/12/31. | |
| 12 | + */ | |
| 13 | +@Component | |
| 14 | +public class SignalSchPlanMatcher { | |
| 15 | + | |
| 16 | + @Autowired | |
| 17 | + DayOfSchedule dayOfSchedule; | |
| 18 | + | |
| 19 | + /** | |
| 20 | + * 发车信号匹配 | |
| 21 | + * @param outSigal | |
| 22 | + * @param sch | |
| 23 | + * @return | |
| 24 | + */ | |
| 25 | + public void outMatch(GpsEntity outSigal, ScheduleRealInfo sch){ | |
| 26 | + long t = outSigal.getTimestamp(); | |
| 27 | + if(t < sch.getDfsjT()) | |
| 28 | + return; | |
| 29 | + | |
| 30 | + //下一个相同走向的班次 | |
| 31 | + ScheduleRealInfo next = dayOfSchedule.nextSame(sch); | |
| 32 | + if(next == null || !next.getQdzCode().equals(sch.getQdzCode())) | |
| 33 | + return; | |
| 34 | + | |
| 35 | + //晚于班次间隔百分之70,跳下一个班次 | |
| 36 | + double s = (int) (next.getDfsjT() - sch.getDfsjT()); | |
| 37 | + double r = (int) (t - sch.getDfsjT()); | |
| 38 | + if(r / s > 0.7){ | |
| 39 | + dayOfSchedule.addExecPlan(next); | |
| 40 | + outMatch(outSigal, next); | |
| 41 | + } | |
| 42 | + } | |
| 43 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata/analyse/StationRouteComp.java renamed to src/main/java/com/bsth/data/gpsdata/arrival/utils/StationRouteComp.java
| 1 | -package com.bsth.data.gpsdata.analyse; | |
| 2 | - | |
| 3 | -import java.util.Comparator; | |
| 4 | - | |
| 5 | -/** | |
| 6 | - * Created by panzhao on 2016/12/24. | |
| 7 | - */ | |
| 8 | -public class StationRouteComp implements Comparator<StationRoute>{ | |
| 9 | - @Override | |
| 10 | - public int compare(StationRoute s1, StationRoute s2) { | |
| 11 | - return s1.getRouteSort() - s2.getRouteSort(); | |
| 12 | - } | |
| 13 | -} | |
| 1 | +package com.bsth.data.gpsdata.arrival.utils; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata.arrival.entity.StationRoute; | |
| 4 | + | |
| 5 | +import java.util.Comparator; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * Created by panzhao on 2016/12/24. | |
| 9 | + */ | |
| 10 | +public class StationRouteComp implements Comparator<StationRoute>{ | |
| 11 | + @Override | |
| 12 | + public int compare(StationRoute s1, StationRoute s2) { | |
| 13 | + return s1.getRouteSort() - s2.getRouteSort(); | |
| 14 | + } | |
| 15 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata/recovery/GpsDataRecovery.java
| 1 | -package com.bsth.data.gpsdata.recovery; | |
| 2 | - | |
| 3 | -import com.bsth.data.BasicData; | |
| 4 | -import com.bsth.data.gpsdata.GpsEntity; | |
| 5 | -import com.bsth.data.gpsdata.analyse.components.GpsArrival; | |
| 6 | -import com.bsth.util.db.DBUtils_MS; | |
| 7 | -import com.google.common.collect.ArrayListMultimap; | |
| 8 | -import org.slf4j.Logger; | |
| 9 | -import org.slf4j.LoggerFactory; | |
| 10 | -import org.springframework.jdbc.core.JdbcTemplate; | |
| 11 | -import org.springframework.jdbc.core.RowMapper; | |
| 12 | - | |
| 13 | -import java.sql.ResultSet; | |
| 14 | -import java.sql.SQLException; | |
| 15 | -import java.util.*; | |
| 16 | -import java.util.concurrent.CountDownLatch; | |
| 17 | -import java.util.concurrent.ExecutorService; | |
| 18 | -import java.util.concurrent.Executors; | |
| 19 | - | |
| 20 | -/** | |
| 21 | - * 数据恢复 | |
| 22 | - * Created by panzhao on 2016/12/24. | |
| 23 | - */ | |
| 24 | -public class GpsDataRecovery { | |
| 25 | - | |
| 26 | - static Logger logger = LoggerFactory.getLogger(GpsDataRecovery.class); | |
| 27 | - | |
| 28 | - public static boolean run; | |
| 29 | - | |
| 30 | - static ExecutorService threadPool = Executors.newFixedThreadPool(50); | |
| 31 | - | |
| 32 | - private static CountDownLatch count; | |
| 33 | - | |
| 34 | - public static void recovery() { | |
| 35 | - List<GpsEntity> list = loadData(); | |
| 36 | - | |
| 37 | - //按车辆分组数据 | |
| 38 | - ArrayListMultimap<String, GpsEntity> listMap = ArrayListMultimap.create(); | |
| 39 | - for (GpsEntity gps : list) { | |
| 40 | - if(gps.getNbbm() != null) | |
| 41 | - listMap.put(gps.getNbbm(), gps); | |
| 42 | - } | |
| 43 | - | |
| 44 | - count = new CountDownLatch(listMap.keySet().size()); | |
| 45 | - | |
| 46 | - Set<String> keys = listMap.keySet(); | |
| 47 | - for (String nbbm : keys) { | |
| 48 | - threadPool.execute(new RecoveryDataThread(listMap.get(nbbm), count)); | |
| 49 | - /*if(nbbm.equals("W9A-250")) | |
| 50 | - new RecoveryDataThread(listMap.get(nbbm), count).run();*/ | |
| 51 | - } | |
| 52 | - try { | |
| 53 | - //等待子线程结束 | |
| 54 | - count.await(); | |
| 55 | - logger.info("GPS 数据恢复完成...."); | |
| 56 | - } catch (InterruptedException e) { | |
| 57 | - logger.error("", e); | |
| 58 | - } | |
| 59 | - } | |
| 60 | - | |
| 61 | - /** | |
| 62 | - * 加载当天的gps数据 | |
| 63 | - * | |
| 64 | - * @return | |
| 65 | - */ | |
| 66 | - public static List<GpsEntity> loadData() { | |
| 67 | - Calendar calendar = Calendar.getInstance(); | |
| 68 | - int dayOfYear = calendar.get(Calendar.DAY_OF_YEAR); | |
| 69 | - | |
| 70 | - String sql = "select DEVICE_ID,LAT,LON,TS,SPEED_GPS,LINE_ID,SERVICE_STATE from BSTH_C_GPS_INFO where days_year=" + dayOfYear; | |
| 71 | - JdbcTemplate jdbcTemplate = new JdbcTemplate(DBUtils_MS.getDataSource()); | |
| 72 | - | |
| 73 | - List<GpsEntity> list = | |
| 74 | - jdbcTemplate.query(sql, new RowMapper<GpsEntity>() { | |
| 75 | - @Override | |
| 76 | - public GpsEntity mapRow(ResultSet rs, int rowNum) throws SQLException { | |
| 77 | - GpsEntity gps = new GpsEntity(); | |
| 78 | - | |
| 79 | - gps.setDeviceId(rs.getString("DEVICE_ID")); | |
| 80 | - gps.setNbbm(BasicData.deviceId2NbbmMap.get(gps.getDeviceId())); | |
| 81 | - gps.setSpeed(rs.getFloat("SPEED_GPS")); | |
| 82 | - gps.setLat(rs.getFloat("LAT")); | |
| 83 | - gps.setLon(rs.getFloat("LON")); | |
| 84 | - gps.setLineId(rs.getString("LINE_ID")); | |
| 85 | - gps.setTimestamp(rs.getLong("TS")); | |
| 86 | - gps.setUpDown(getUpOrDown(rs.getLong("SERVICE_STATE"))); | |
| 87 | - return gps; | |
| 88 | - } | |
| 89 | - }); | |
| 90 | - return list; | |
| 91 | - } | |
| 92 | - | |
| 93 | - /** | |
| 94 | - * 王通 2016/6/29 9:23:24 获取车辆线路上下行 | |
| 95 | - * | |
| 96 | - * @return -1无效 0上行 1下行 | |
| 97 | - */ | |
| 98 | - public static int getUpOrDown(long serviceState) { | |
| 99 | - if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000 | |
| 100 | - || (serviceState & 0x01000000) == 0x01000000 || (serviceState & 0x08000000) == 0x08000000) | |
| 101 | - return -1; | |
| 102 | - return (((serviceState & 0x10000000) == 0x10000000) ? 1 : 0); | |
| 103 | - } | |
| 104 | - | |
| 105 | - public static class RecoveryDataThread implements Runnable { | |
| 106 | - | |
| 107 | - List<GpsEntity> list; | |
| 108 | - CountDownLatch count; | |
| 109 | - | |
| 110 | - public RecoveryDataThread(List<GpsEntity> list, CountDownLatch count) { | |
| 111 | - this.list = list; | |
| 112 | - this.count = count; | |
| 113 | - } | |
| 114 | - | |
| 115 | - @Override | |
| 116 | - public void run() { | |
| 117 | - try { | |
| 118 | - //排序 | |
| 119 | - Collections.sort(list, new GpsComp()); | |
| 120 | - //依次跑完gps | |
| 121 | - //int i = 0; | |
| 122 | - for(GpsEntity gps : list){ | |
| 123 | - /* i++; | |
| 124 | - if(i == 383){ | |
| 125 | - System.out.println("aaa"); | |
| 126 | - }*/ | |
| 127 | - GpsArrival.arrival(gps); | |
| 128 | - } | |
| 129 | - } catch (Exception e) { | |
| 130 | - logger.error("", e); | |
| 131 | - } finally { | |
| 132 | - count.countDown(); | |
| 133 | - } | |
| 134 | - } | |
| 135 | - } | |
| 136 | - | |
| 137 | - public static class GpsComp implements Comparator<GpsEntity>{ | |
| 138 | - | |
| 139 | - @Override | |
| 140 | - public int compare(GpsEntity g1, GpsEntity g2) { | |
| 141 | - return (int) (g1.getTimestamp() - g2.getTimestamp()); | |
| 142 | - } | |
| 143 | - } | |
| 144 | -} | |
| 1 | +package com.bsth.data.gpsdata.recovery; | |
| 2 | + | |
| 3 | +import com.bsth.data.BasicData; | |
| 4 | +import com.bsth.data.gpsdata.GpsEntity; | |
| 5 | +import com.bsth.data.gpsdata.arrival.GeoCacheData; | |
| 6 | +import com.bsth.data.gpsdata.arrival.handlers.*; | |
| 7 | +import com.bsth.data.gpsdata.arrival.utils.CircleQueue; | |
| 8 | +import com.bsth.util.db.DBUtils_MS; | |
| 9 | +import com.google.common.collect.ArrayListMultimap; | |
| 10 | +import org.slf4j.Logger; | |
| 11 | +import org.slf4j.LoggerFactory; | |
| 12 | +import org.springframework.beans.BeansException; | |
| 13 | +import org.springframework.context.ApplicationContext; | |
| 14 | +import org.springframework.context.ApplicationContextAware; | |
| 15 | +import org.springframework.jdbc.core.JdbcTemplate; | |
| 16 | +import org.springframework.jdbc.core.RowMapper; | |
| 17 | +import org.springframework.stereotype.Component; | |
| 18 | + | |
| 19 | +import java.sql.ResultSet; | |
| 20 | +import java.sql.SQLException; | |
| 21 | +import java.util.*; | |
| 22 | +import java.util.concurrent.CountDownLatch; | |
| 23 | +import java.util.concurrent.ExecutorService; | |
| 24 | +import java.util.concurrent.Executors; | |
| 25 | + | |
| 26 | +/** | |
| 27 | + * gps数据恢复 | |
| 28 | + * Created by panzhao on 2016/12/24. | |
| 29 | + */ | |
| 30 | +@Component | |
| 31 | +public class GpsDataRecovery implements ApplicationContextAware { | |
| 32 | + | |
| 33 | + static Logger logger = LoggerFactory.getLogger(GpsDataRecovery.class); | |
| 34 | + | |
| 35 | + public static boolean run; | |
| 36 | + | |
| 37 | + static ExecutorService threadPool = Executors.newFixedThreadPool(10); | |
| 38 | + | |
| 39 | + static OfflineSignalHandle offlineSignalHandle; | |
| 40 | + static CorrectSignalHandle correctSignalHandle; | |
| 41 | + static StationInsideHandle stationInsideHandle; | |
| 42 | + static InOutStationSignalHandle inOutStationSignalHandle; | |
| 43 | + static ReverseSignalHandle reverseSignalHandle; | |
| 44 | + | |
| 45 | + public void recovery() { | |
| 46 | + List<GpsEntity> list = loadData(); | |
| 47 | + | |
| 48 | + //按车辆分组数据 | |
| 49 | + ArrayListMultimap<String, GpsEntity> listMap = ArrayListMultimap.create(); | |
| 50 | + for (GpsEntity gps : list) { | |
| 51 | + if (gps.getNbbm() != null) | |
| 52 | + listMap.put(gps.getNbbm(), gps); | |
| 53 | + } | |
| 54 | + | |
| 55 | + | |
| 56 | + Set<String> keys = listMap.keySet(); | |
| 57 | + | |
| 58 | + CountDownLatch count = new CountDownLatch(keys.size()); | |
| 59 | + GpsComp comp = new GpsComp(); | |
| 60 | + for (String nbbm : keys) { | |
| 61 | + Collections.sort(listMap.get(nbbm), comp); | |
| 62 | + threadPool.execute(new RecoveryThread(listMap.get(nbbm), count)); | |
| 63 | + /*if(nbbm.equals("W9H-003")) | |
| 64 | + new RecoveryThread(listMap.get(nbbm), count).run();*/ | |
| 65 | + } | |
| 66 | + | |
| 67 | + try { | |
| 68 | + count.await(); | |
| 69 | + run = false; | |
| 70 | + logger.info("数据恢复完成...."); | |
| 71 | + } catch (InterruptedException e) { | |
| 72 | + logger.error("", e); | |
| 73 | + } | |
| 74 | + } | |
| 75 | + | |
| 76 | + /** | |
| 77 | + * 加载当天的gps数据 | |
| 78 | + * | |
| 79 | + * @return | |
| 80 | + */ | |
| 81 | + public List<GpsEntity> loadData() { | |
| 82 | + Calendar calendar = Calendar.getInstance(); | |
| 83 | + int dayOfYear = calendar.get(Calendar.DAY_OF_YEAR); | |
| 84 | + | |
| 85 | + String sql = "select DEVICE_ID,LAT,LON,TS,SPEED_GPS,LINE_ID,SERVICE_STATE from bsth_c_gps_info where days_year=" + dayOfYear; | |
| 86 | + JdbcTemplate jdbcTemplate = new JdbcTemplate(DBUtils_MS.getDataSource()); | |
| 87 | + | |
| 88 | + List<GpsEntity> list = | |
| 89 | + jdbcTemplate.query(sql, new RowMapper<GpsEntity>() { | |
| 90 | + @Override | |
| 91 | + public GpsEntity mapRow(ResultSet rs, int rowNum) throws SQLException { | |
| 92 | + GpsEntity gps = new GpsEntity(); | |
| 93 | + | |
| 94 | + gps.setDeviceId(rs.getString("DEVICE_ID")); | |
| 95 | + gps.setNbbm(BasicData.deviceId2NbbmMap.get(gps.getDeviceId())); | |
| 96 | + gps.setSpeed(rs.getFloat("SPEED_GPS")); | |
| 97 | + gps.setLat(rs.getFloat("LAT")); | |
| 98 | + gps.setLon(rs.getFloat("LON")); | |
| 99 | + gps.setLineId(rs.getString("LINE_ID")); | |
| 100 | + gps.setTimestamp(rs.getLong("TS")); | |
| 101 | + gps.setUpDown(getUpOrDown(rs.getLong("SERVICE_STATE"))); | |
| 102 | + return gps; | |
| 103 | + } | |
| 104 | + }); | |
| 105 | + return list; | |
| 106 | + } | |
| 107 | + | |
| 108 | + /** | |
| 109 | + * 王通 2016/6/29 9:23:24 获取车辆线路上下行 | |
| 110 | + * | |
| 111 | + * @return -1无效 0上行 1下行 | |
| 112 | + */ | |
| 113 | + public static int getUpOrDown(long serviceState) { | |
| 114 | + if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000 | |
| 115 | + || (serviceState & 0x01000000) == 0x01000000 || (serviceState & 0x08000000) == 0x08000000) | |
| 116 | + return -1; | |
| 117 | + return (((serviceState & 0x10000000) == 0x10000000) ? 1 : 0); | |
| 118 | + } | |
| 119 | + | |
| 120 | + @Override | |
| 121 | + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | |
| 122 | + offlineSignalHandle = applicationContext.getBean(OfflineSignalHandle.class); | |
| 123 | + correctSignalHandle = applicationContext.getBean(CorrectSignalHandle.class); | |
| 124 | + stationInsideHandle = applicationContext.getBean(StationInsideHandle.class); | |
| 125 | + inOutStationSignalHandle = applicationContext.getBean(InOutStationSignalHandle.class); | |
| 126 | + reverseSignalHandle = applicationContext.getBean(ReverseSignalHandle.class); | |
| 127 | + } | |
| 128 | + | |
| 129 | + public static class GpsComp implements Comparator<GpsEntity> { | |
| 130 | + | |
| 131 | + @Override | |
| 132 | + public int compare(GpsEntity g1, GpsEntity g2) { | |
| 133 | + return g1.getTimestamp().compareTo(g2.getTimestamp()); | |
| 134 | + } | |
| 135 | + } | |
| 136 | + | |
| 137 | + public static class RecoveryThread implements Runnable { | |
| 138 | + List<GpsEntity> list; | |
| 139 | + CountDownLatch count; | |
| 140 | + | |
| 141 | + RecoveryThread(List<GpsEntity> list, CountDownLatch count) { | |
| 142 | + this.list = list; | |
| 143 | + this.count = count; | |
| 144 | + } | |
| 145 | + | |
| 146 | + @Override | |
| 147 | + public void run() { | |
| 148 | + try { | |
| 149 | + //循环gps恢复数据 | |
| 150 | + CircleQueue<GpsEntity> prevs; | |
| 151 | + | |
| 152 | + for (GpsEntity gps : list) { | |
| 153 | + | |
| 154 | + prevs = GeoCacheData.getGps(gps.getNbbm()); | |
| 155 | + //掉线处理 | |
| 156 | + offlineSignalHandle.handle(gps, prevs); | |
| 157 | + //状态处理 | |
| 158 | + if (!correctSignalHandle.handle(gps, prevs)) | |
| 159 | + continue; | |
| 160 | + //场,站内外判断 | |
| 161 | + stationInsideHandle.handle(gps, prevs); | |
| 162 | + //反向处理 | |
| 163 | + reverseSignalHandle.handle(gps, prevs); | |
| 164 | + //进出站动作处理 | |
| 165 | + inOutStationSignalHandle.handle(gps, prevs); | |
| 166 | + GeoCacheData.putGps(gps); | |
| 167 | + | |
| 168 | + //Thread.sleep(50); | |
| 169 | + } | |
| 170 | + } catch (Exception e) { | |
| 171 | + logger.error("", e); | |
| 172 | + } finally { | |
| 173 | + count.countDown(); | |
| 174 | + } | |
| 175 | + } | |
| 176 | + } | |
| 177 | +} | |
| 145 | 178 | \ No newline at end of file | ... | ... |
src/main/java/com/bsth/data/pilot80/PilotReport.java
| 1 | 1 | package com.bsth.data.pilot80; |
| 2 | 2 | |
| 3 | -import java.util.ArrayList; | |
| 4 | -import java.util.Collection; | |
| 5 | -import java.util.List; | |
| 6 | - | |
| 7 | -import org.slf4j.Logger; | |
| 8 | -import org.slf4j.LoggerFactory; | |
| 9 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 10 | -import org.springframework.stereotype.Component; | |
| 11 | - | |
| 12 | 3 | import com.bsth.data.BasicData; |
| 13 | 4 | import com.bsth.data.LineConfigData; |
| 14 | 5 | import com.bsth.data.gpsdata.GpsEntity; |
| ... | ... | @@ -23,6 +14,14 @@ import com.bsth.repository.directive.D80Repository; |
| 23 | 14 | import com.bsth.service.directive.DirectiveService; |
| 24 | 15 | import com.bsth.websocket.handler.SendUtils; |
| 25 | 16 | import com.google.common.collect.ArrayListMultimap; |
| 17 | +import org.slf4j.Logger; | |
| 18 | +import org.slf4j.LoggerFactory; | |
| 19 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 20 | +import org.springframework.stereotype.Component; | |
| 21 | + | |
| 22 | +import java.util.ArrayList; | |
| 23 | +import java.util.Collection; | |
| 24 | +import java.util.List; | |
| 26 | 25 | |
| 27 | 26 | /** |
| 28 | 27 | * |
| ... | ... | @@ -85,6 +84,8 @@ public class PilotReport { |
| 85 | 84 | |
| 86 | 85 | //下发调度指令 |
| 87 | 86 | directiveService.send60Dispatch(outSch, dayOfSchedule.doneSum(nbbm), "请出@系统"); |
| 87 | + //下发线路切换指令 | |
| 88 | + directiveService.lineChange(outSch.getClZbh(), outSch.getXlBm(), "请出@系统"); | |
| 88 | 89 | /* d80.setRemarks("计划出场时间:" + outSch.getDfsj()); |
| 89 | 90 | //当前GPS位置 |
| 90 | 91 | GpsEntity gps = gpsRealData.get(d80.getDeviceId()); |
| ... | ... | @@ -180,7 +181,7 @@ public class PilotReport { |
| 180 | 181 | return; |
| 181 | 182 | |
| 182 | 183 | LineConfig conf = lineConfigData.get(sch.getXlBm()); |
| 183 | - if(conf.getInConfig() == 1){ | |
| 184 | + if(conf.getOutConfig() == 1){ | |
| 184 | 185 | //为相关班次写入进场时间 |
| 185 | 186 | sch.setZdsjActualAll(d80.getTimestamp()); |
| 186 | 187 | ... | ... |