Commit 0e0673d249760c2bb53905378545d620f04ceff2

Authored by 潘钊
2 parents f2304992 612f7eea

Merge branch 'minhang' into qingpu

Showing 54 changed files with 2824 additions and 1281 deletions

Too many changes to show.

To preserve performance only 54 of 713 files are displayed.

@@ -225,6 +225,12 @@ @@ -225,6 +225,12 @@
225 <artifactId>spring-boot-devtools</artifactId> 225 <artifactId>spring-boot-devtools</artifactId>
226 <optional>true</optional> 226 <optional>true</optional>
227 </dependency>--> 227 </dependency>-->
  228 + <dependency>
  229 + <groupId>com.vividsolutions</groupId>
  230 + <artifactId>jts</artifactId>
  231 + <version>1.13</version>
  232 + </dependency>
  233 +
228 </dependencies> 234 </dependencies>
229 235
230 <dependencyManagement> 236 <dependencyManagement>
src/main/java/com/bsth/controller/BaseController2.java
@@ -187,9 +187,11 @@ public class BaseController2&lt;T, ID extends Serializable&gt; { @@ -187,9 +187,11 @@ public class BaseController2&lt;T, ID extends Serializable&gt; {
187 } 187 }
188 188
189 System.out.println(outputfile.getName()); 189 System.out.println(outputfile.getName());
  190 + System.out.println(outputfile.getAbsolutePath());
  191 +
190 String filePath = outputfile.getAbsolutePath(); 192 String filePath = outputfile.getAbsolutePath();
191 - String fp[] = filePath.split(File.separator);  
192 - String fileName = fp[fp.length - 1]; 193 +// String fp[] = filePath.split(File.separator);
  194 +// String fileName = fp[fp.length - 1];
193 195
194 // TODO:使用ktr获取导出数据 196 // TODO:使用ktr获取导出数据
195 197
src/main/java/com/bsth/controller/BusIntervalController.java
@@ -22,6 +22,11 @@ public class BusIntervalController { @@ -22,6 +22,11 @@ public class BusIntervalController {
22 public List<Map<String,Object>> getDir(@RequestParam Map<String, Object> map){ 22 public List<Map<String,Object>> getDir(@RequestParam Map<String, Object> map){
23 return busIntervalService.getDir(map); 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 @RequestMapping(value = "/interval", method = RequestMethod.GET) 31 @RequestMapping(value = "/interval", method = RequestMethod.GET)
27 public List<Map<String,Object>> interval(@RequestParam Map<String, Object> map){ 32 public List<Map<String,Object>> interval(@RequestParam Map<String, Object> map){
src/main/java/com/bsth/controller/forms/ExportController.java
@@ -65,10 +65,12 @@ public class ExportController { @@ -65,10 +65,12 @@ public class ExportController {
65 i++; 65 i++;
66 } 66 }
67 67
  68 +
  69 +
68 try { 70 try {
69 listI.add(resList.iterator()); 71 listI.add(resList.iterator());
70 String path = this.getClass().getResource("/").getPath() + "static\\pages\\forms\\"; 72 String path = this.getClass().getResource("/").getPath() + "static\\pages\\forms\\";
71 - ee.excelReplace(listI, new Object[] { map }, path + "mould\\linepassengerflow.xls", 73 + ee.excelReplace(listI, new Object[] { map }, path + "mould\\linepasswengerflow.xls",
72 path + "export\\线路客流量报表" + sdfSimple.format(sdfMonth.parse(map.get("date").toString())) + ".xls"); 74 path + "export\\线路客流量报表" + sdfSimple.format(sdfMonth.parse(map.get("date").toString())) + ".xls");
73 } catch (Exception e) { 75 } catch (Exception e) {
74 e.printStackTrace(); 76 e.printStackTrace();
@@ -189,7 +191,7 @@ public class ExportController { @@ -189,7 +191,7 @@ public class ExportController {
189 listI.add(resList.iterator()); 191 listI.add(resList.iterator());
190 String path = this.getClass().getResource("/").getPath() + "static\\pages\\forms\\"; 192 String path = this.getClass().getResource("/").getPath() + "static\\pages\\forms\\";
191 ee.excelReplace(listI, new Object[] { map }, path + "mould\\singledata.xls", 193 ee.excelReplace(listI, new Object[] { map }, path + "mould\\singledata.xls",
192 - path + "export\\路单报表" + sdfSimple.format(sdfMonth.parse(map.get("startDate").toString())) + ".xls"); 194 + path + "export\\路单数据" + sdfSimple.format(sdfMonth.parse(map.get("startDate").toString())) + ".xls");
193 } catch (Exception e) { 195 } catch (Exception e) {
194 e.printStackTrace(); 196 e.printStackTrace();
195 } 197 }
@@ -203,8 +205,8 @@ public class ExportController { @@ -203,8 +205,8 @@ public class ExportController {
203 SimpleDateFormat sdfMonth = new SimpleDateFormat("yyyy-MM-dd"), sdfSimple = new SimpleDateFormat("yyyyMMdd"); 205 SimpleDateFormat sdfMonth = new SimpleDateFormat("yyyy-MM-dd"), sdfSimple = new SimpleDateFormat("yyyyMMdd");
204 List<Iterator<?>> listI = new ArrayList<Iterator<?>>(); 206 List<Iterator<?>> listI = new ArrayList<Iterator<?>>();
205 ReportUtils ee = new ReportUtils(); 207 ReportUtils ee = new ReportUtils();
206 - List<Vehicleloading> vehicleloading = formsService.vehicleloading(/*map.get("gsdmVehic").toString(),map.get("fgsdmVehic").toString(),*/map.get("line").toString(),  
207 - map.get("date").toString()); 208 + List<Vehicleloading> vehicleloading = formsService.vehicleloading(map.get("gsdmVehic").toString(),map.get("fgsdmVehic").toString(),map.get("line").toString(),
  209 + map.get("data").toString());
208 List<Map<String, Object>> resList = new ArrayList<Map<String, Object>>(); 210 List<Map<String, Object>> resList = new ArrayList<Map<String, Object>>();
209 int i = 1; 211 int i = 1;
210 for (Vehicleloading l : vehicleloading) { 212 for (Vehicleloading l : vehicleloading) {
@@ -214,8 +216,8 @@ public class ExportController { @@ -214,8 +216,8 @@ public class ExportController {
214 m.put("gS", l.getgS()); 216 m.put("gS", l.getgS());
215 m.put("xL", l.getxL()); 217 m.put("xL", l.getxL());
216 m.put("clzbh", l.getClzbh()); 218 m.put("clzbh", l.getClzbh());
217 - m.put("hyl", l.getHyl());  
218 m.put("jzl", l.getJzl()); 219 m.put("jzl", l.getJzl());
  220 + m.put("hyl", l.getHyl());
219 m.put("ls", l.getLs()); 221 m.put("ls", l.getLs());
220 m.put("jhlc", l.getJhlc()); 222 m.put("jhlc", l.getJhlc());
221 m.put("unyyyl", l.getUnyyyl()); 223 m.put("unyyyl", l.getUnyyyl());
@@ -229,7 +231,7 @@ public class ExportController { @@ -229,7 +231,7 @@ public class ExportController {
229 listI.add(resList.iterator()); 231 listI.add(resList.iterator());
230 String path = this.getClass().getResource("/").getPath() + "static\\pages\\forms\\"; 232 String path = this.getClass().getResource("/").getPath() + "static\\pages\\forms\\";
231 ee.excelReplace(listI, new Object[] { map }, path + "mould\\vehicleloading.xls", 233 ee.excelReplace(listI, new Object[] { map }, path + "mould\\vehicleloading.xls",
232 - path + "export\\车辆加注" + sdfSimple.format(sdfMonth.parse(map.get("date").toString())) + ".xls"); 234 + path + "export\\车辆加注" + sdfSimple.format(sdfMonth.parse(map.get("dat").toString())) + ".xls");
233 } catch (Exception e) { 235 } catch (Exception e) {
234 e.printStackTrace(); 236 e.printStackTrace();
235 } 237 }
@@ -417,5 +419,9 @@ public class ExportController { @@ -417,5 +419,9 @@ public class ExportController {
417 } 419 }
418 return resList; 420 return resList;
419 } 421 }
  422 +
  423 +
  424 +
  425 +
420 426
421 } 427 }
src/main/java/com/bsth/controller/forms/MCY_FormsController.java
@@ -80,9 +80,9 @@ public class MCY_FormsController { @@ -80,9 +80,9 @@ public class MCY_FormsController {
80 80
81 // 车辆加注 81 // 车辆加注
82 @RequestMapping(value = "/vehicleloading", method = RequestMethod.POST) 82 @RequestMapping(value = "/vehicleloading", method = RequestMethod.POST)
83 - public List<Vehicleloading> vehicleloading(/*@RequestParam String gsdmVehic, @RequestParam String fgsdmVehic,*/ 83 + public List<Vehicleloading> vehicleloading(@RequestParam String gsdmVehic, @RequestParam String fgsdmVehic,
84 @RequestParam String line, @RequestParam String data) { 84 @RequestParam String line, @RequestParam String data) {
85 - return formsService.vehicleloading(/*gsdmVehic, fgsdmVehic, */line, data); 85 + return formsService.vehicleloading(gsdmVehic, fgsdmVehic, line, data);
86 } 86 }
87 87
88 // 运营服务阶段报表 88 // 运营服务阶段报表
src/main/java/com/bsth/controller/gps/GpsController.java
1 package com.bsth.controller.gps; 1 package com.bsth.controller.gps;
2 2
3 -import java.util.List;  
4 -import java.util.Map;  
5 -  
6 -import org.springframework.beans.factory.annotation.Autowired;  
7 -import org.springframework.web.bind.annotation.*;  
8 -  
9 import com.bsth.data.BasicData; 3 import com.bsth.data.BasicData;
10 import com.bsth.data.gpsdata.GpsEntity; 4 import com.bsth.data.gpsdata.GpsEntity;
11 import com.bsth.data.gpsdata.GpsRealData; 5 import com.bsth.data.gpsdata.GpsRealData;
12 import com.bsth.service.gps.GpsService; 6 import com.bsth.service.gps.GpsService;
13 import com.google.common.base.Splitter; 7 import com.google.common.base.Splitter;
  8 +import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.web.bind.annotation.*;
  10 +
  11 +import java.util.List;
  12 +import java.util.Map;
14 13
15 @RestController 14 @RestController
16 @RequestMapping("gps") 15 @RequestMapping("gps")
@@ -70,7 +69,7 @@ public class GpsController { @@ -70,7 +69,7 @@ public class GpsController {
70 return gpsService.history(nbbmArray, st, et); 69 return gpsService.history(nbbmArray, st, et);
71 } 70 }
72 71
73 - /*@RequestMapping(value = "/arrival/ram") 72 + /*@RequestMapping(value = "/analyse/ram")
74 public List<ArrivalInfo> ramData(@RequestParam String nbbm) { 73 public List<ArrivalInfo> ramData(@RequestParam String nbbm) {
75 return ArrivalDataBuffer.allMap.get(nbbm); 74 return ArrivalDataBuffer.allMap.get(nbbm);
76 }*/ 75 }*/
@@ -84,4 +83,9 @@ public class GpsController { @@ -84,4 +83,9 @@ public class GpsController {
84 public Map<String, Object> findBuffAeraByCode(@RequestParam String code,@RequestParam String type){ 83 public Map<String, Object> findBuffAeraByCode(@RequestParam String code,@RequestParam String type){
85 return gpsService.findBuffAeraByCode(code, type); 84 return gpsService.findBuffAeraByCode(code, type);
86 } 85 }
  86 +
  87 + @RequestMapping(value = "/findRoadSpeed")
  88 + public Map<String, Object> findRoadSpeed(@RequestParam String lineCode){
  89 + return gpsService.findRoadSpeed(lineCode);
  90 + }
87 } 91 }
src/main/java/com/bsth/controller/oil/YlbController.java
@@ -3,7 +3,9 @@ package com.bsth.controller.oil; @@ -3,7 +3,9 @@ package com.bsth.controller.oil;
3 import java.text.ParseException; 3 import java.text.ParseException;
4 import java.text.SimpleDateFormat; 4 import java.text.SimpleDateFormat;
5 import java.util.ArrayList; 5 import java.util.ArrayList;
  6 +import java.util.Calendar;
6 import java.util.Date; 7 import java.util.Date;
  8 +import java.util.GregorianCalendar;
7 import java.util.HashMap; 9 import java.util.HashMap;
8 import java.util.Iterator; 10 import java.util.Iterator;
9 import java.util.List; 11 import java.util.List;
@@ -107,8 +109,16 @@ public class YlbController extends BaseController&lt;Ylb, Integer&gt;{ @@ -107,8 +109,16 @@ public class YlbController extends BaseController&lt;Ylb, Integer&gt;{
107 try { 109 try {
108 String rq=map.get("rq").toString(); 110 String rq=map.get("rq").toString();
109 if(!(rq=="")){ 111 if(!(rq=="")){
  112 +
110 SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); 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 } catch (ParseException e) { 123 } catch (ParseException e) {
114 // TODO Auto-generated catch block 124 // TODO Auto-generated catch block
src/main/java/com/bsth/controller/realcontrol/ScheduleRealInfoController.java
@@ -131,13 +131,13 @@ public class ScheduleRealInfoController extends BaseController&lt;ScheduleRealInfo, @@ -131,13 +131,13 @@ public class ScheduleRealInfoController extends BaseController&lt;ScheduleRealInfo,
131 * @Title: adjust @Description: TODO(调整人车) @param @param id 131 * @Title: adjust @Description: TODO(调整人车) @param @param id
132 * 班次ID @param @param nbbm 内部编码 @param @param jsy 驾驶员 @param @param spy 132 * 班次ID @param @param nbbm 内部编码 @param @param jsy 驾驶员 @param @param spy
133 * 售票员 @throws 133 * 售票员 @throws
134 - */ 134 +
135 @RequestMapping(value = "/adjust", method = RequestMethod.POST) 135 @RequestMapping(value = "/adjust", method = RequestMethod.POST)
136 public Map<String, Object> adjust(@RequestParam Long id, String nbbm, String jsy, 136 public Map<String, Object> adjust(@RequestParam Long id, String nbbm, String jsy,
137 String spy, Integer revertLine, Integer borrowLine, String borrowTimeStr, String revertTimeStr) { 137 String spy, Integer revertLine, Integer borrowLine, String borrowTimeStr, String revertTimeStr) {
138 return scheduleRealInfoService.adjust(id, nbbm, jsy, spy, revertLine, borrowLine, borrowTimeStr, revertTimeStr); 138 return scheduleRealInfoService.adjust(id, nbbm, jsy, spy, revertLine, borrowLine, borrowTimeStr, revertTimeStr);
139 } 139 }
140 - 140 + */
141 /** 141 /**
142 * 142 *
143 * @Title: realOutAdjust 143 * @Title: realOutAdjust
@@ -292,8 +292,9 @@ public class ScheduleRealInfoController extends BaseController&lt;ScheduleRealInfo, @@ -292,8 +292,9 @@ public class ScheduleRealInfoController extends BaseController&lt;ScheduleRealInfo,
292 } 292 }
293 293
294 @RequestMapping(value = "/queryUserInfo") 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 @RequestMapping(value = "/exportWaybill") 300 @RequestMapping(value = "/exportWaybill")
src/main/java/com/bsth/controller/report/ReportController.java
@@ -50,23 +50,28 @@ public class ReportController { @@ -50,23 +50,28 @@ public class ReportController {
50 } 50 }
51 51
52 @RequestMapping(value = "/tbodyTime1", method = RequestMethod.GET) 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 @RequestMapping(value = "/tbodyTime2", method = RequestMethod.GET) 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 @RequestMapping(value = "/tbodyTime3", method = RequestMethod.GET) 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 } 65 }
66 66
67 @RequestMapping(value = "/tbodyTime5", method = RequestMethod.GET) 67 @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); 68 + public List<Map<String, Object>> tbodyTime5(@RequestParam String line,@RequestParam String ttinfo) {
  69 + return service.tbodyTime5(line, ttinfo);
  70 + }
  71 +
  72 + @RequestMapping(value="/getTtinfo", method = RequestMethod.GET)
  73 + public List<Map<String,Object>> getTtinfo(@RequestParam Map<String, Object> map){
  74 + return service.getTtinfo(map);
70 } 75 }
71 76
72 } 77 }
src/main/java/com/bsth/controller/schedule/RerunController.java deleted 100644 → 0
1 -package com.bsth.controller.schedule;  
2 -  
3 -import com.bsth.controller.BaseController;  
4 -import com.bsth.entity.schedule.rule.RerunRule;  
5 -import com.bsth.repository.schedule.RerunRuleRepository;  
6 -import org.springframework.beans.factory.annotation.Autowired;  
7 -import org.springframework.web.bind.annotation.*;  
8 -  
9 -import java.util.Map;  
10 -  
11 -/**  
12 - * Created by xu on 16/10/20.  
13 - */  
14 -@RestController  
15 -@RequestMapping("rms")  
16 -public class RerunController extends BaseController<RerunRule, Long> {  
17 -  
18 - @Autowired  
19 - private RerunRuleRepository rerunRuleRepository;  
20 -  
21 - @Override  
22 - public RerunRule findById(@PathVariable("id") Long aLong) {  
23 - return rerunRuleRepository.findOneExtend(aLong);  
24 - }  
25 -  
26 - /**  
27 - * 覆写方法,因为form提交的方式参数不全,改用 json形式提交 @RequestBody  
28 - * @Title: save  
29 - * @Description: TODO(持久化对象)  
30 - * @param @param t  
31 - * @param @return 设定文件  
32 - * @return Map<String,Object> {status: 1(成功),-1(失败)}  
33 - * @throws  
34 - */  
35 - @RequestMapping(method = RequestMethod.POST)  
36 - public Map<String, Object> save(@RequestBody RerunRule t){  
37 - return baseService.save(t);  
38 - }  
39 -  
40 -  
41 -}  
src/main/java/com/bsth/controller/schedule/TTInfoController.java deleted 100644 → 0
1 -package com.bsth.controller.schedule;  
2 -  
3 -import com.bsth.controller.BaseController2;  
4 -import com.bsth.entity.schedule.TTInfo;  
5 -import com.bsth.repository.schedule.TTInfoDetailRepository;  
6 -import com.bsth.repository.schedule.TTInfoRepository;  
7 -import com.bsth.service.schedule.utils.DataToolsProperties;  
8 -import org.springframework.beans.factory.annotation.Autowired;  
9 -import org.springframework.boot.context.properties.EnableConfigurationProperties;  
10 -import org.springframework.data.domain.Page;  
11 -import org.springframework.web.bind.annotation.*;  
12 -  
13 -import java.util.Map;  
14 -  
15 -/**  
16 - * Created by xu on 16/5/12.  
17 - */  
18 -@RestController  
19 -@RequestMapping("tic")  
20 -@EnableConfigurationProperties(DataToolsProperties.class)  
21 -public class TTInfoController extends BaseController2<TTInfo, Long> {  
22 - @Autowired  
23 - private DataToolsProperties dataToolsProperties;  
24 - @Autowired  
25 - private TTInfoRepository ttInfoRepository;  
26 - @Autowired  
27 - private TTInfoDetailRepository ttInfoDetailRepository;  
28 -  
29 - @Override  
30 - protected String getDataImportKtrClasspath() {  
31 - return dataToolsProperties.getTtinfoDatainputktr();  
32 - }  
33 -  
34 - @Override  
35 - public TTInfo findById(@PathVariable("id") Long aLong) {  
36 - return ttInfoRepository.findOneExtend(aLong);  
37 - }  
38 -  
39 - /**  
40 - * 验证。  
41 - * @param map  
42 - * @return  
43 - */  
44 - @RequestMapping(value = "/validate/equale", method = RequestMethod.GET)  
45 - public Map<String, Object> validateData(@RequestParam Map<String, Object> map) {  
46 - // 一般比较自编号是否重复  
47 - return baseService.validateEquale(map);  
48 - }  
49 -  
50 - @Override  
51 - public Page<TTInfo> list(@RequestParam Map<String, Object> map, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size, @RequestParam(defaultValue = "id") String order, @RequestParam(defaultValue = "DESC") String direction) {  
52 - // 如果有isCancel键值,将其值变成boolean  
53 - if (map.get("isCancel_eq") != null)  
54 - map.put("isCancel_eq", new Boolean(map.get("isCancel_eq").toString()));  
55 -  
56 - return super.list(map, page, size, order, direction);  
57 - }  
58 -}  
src/main/java/com/bsth/controller/schedule/TTInfoDetailController.java
@@ -113,6 +113,9 @@ public class TTInfoDetailController extends BaseController2&lt;TTInfoDetail, Long&gt; @@ -113,6 +113,9 @@ public class TTInfoDetailController extends BaseController2&lt;TTInfoDetail, Long&gt;
113 p1.put("stationName_eq", cell_con.trim()); 113 p1.put("stationName_eq", cell_con.trim());
114 p1.put("stationMark_eq", "B"); 114 p1.put("stationMark_eq", "B");
115 115
  116 +
  117 + // TODO:这里要修改(起点站有启用撤销的标志的)
  118 +
116 List<StationRoute> stationRouteList = (List<StationRoute>) stationRouteService.list(p1); 119 List<StationRoute> stationRouteList = (List<StationRoute>) stationRouteService.list(p1);
117 if (CollectionUtils.isEmpty(stationRouteList)) { 120 if (CollectionUtils.isEmpty(stationRouteList)) {
118 rtn.put("status", ResponseCode.ERROR); 121 rtn.put("status", ResponseCode.ERROR);
src/main/java/com/bsth/controller/schedule/core/RerunController.java 0 → 100644
  1 +package com.bsth.controller.schedule.core;
  2 +
  3 +import com.bsth.controller.schedule.BController;
  4 +import com.bsth.entity.schedule.rule.RerunRule;
  5 +import org.springframework.web.bind.annotation.RequestMapping;
  6 +import org.springframework.web.bind.annotation.RestController;
  7 +
  8 +/**
  9 + * Created by xu on 16/10/20.
  10 + */
  11 +@RestController
  12 +@RequestMapping("rms")
  13 +public class RerunController extends BController<RerunRule, Long> {
  14 +
  15 +
  16 +}
src/main/java/com/bsth/controller/schedule/core/TTInfoController.java 0 → 100644
  1 +package com.bsth.controller.schedule.core;
  2 +
  3 +import com.bsth.common.ResponseCode;
  4 +import com.bsth.controller.schedule.BController;
  5 +import com.bsth.entity.schedule.TTInfo;
  6 +import com.bsth.service.schedule.ScheduleException;
  7 +import com.bsth.service.schedule.TTInfoService;
  8 +import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.web.bind.annotation.RequestMapping;
  10 +import org.springframework.web.bind.annotation.RequestMethod;
  11 +import org.springframework.web.bind.annotation.RequestParam;
  12 +import org.springframework.web.bind.annotation.RestController;
  13 +
  14 +import java.util.HashMap;
  15 +import java.util.Map;
  16 +
  17 +/**
  18 + * Created by xu on 16/12/20.
  19 + */
  20 +@RestController(value = "tTInfoController_ec")
  21 +@RequestMapping(value = "tic_ec")
  22 +public class TTInfoController extends BController<TTInfo, Long> {
  23 + @Autowired
  24 + private TTInfoService ttInfoService;
  25 +
  26 + @RequestMapping(value = "/validate_name", method = RequestMethod.GET)
  27 + public Map<String, Object> validate_name(@RequestParam Map<String, Object> param) {
  28 + Map<String, Object> rtn = new HashMap<>();
  29 + try {
  30 + // 名字重复验证
  31 + TTInfo ttInfo = new TTInfo(
  32 + param.get("id_eq"),
  33 + param.get("xl.id_eq"),
  34 + param.get("name_eq"),
  35 + param.get("rule_days_eq"),
  36 + param.get("special_days_eq")
  37 + );
  38 + ttInfoService.validate_name(ttInfo);
  39 + rtn.put("status", ResponseCode.SUCCESS);
  40 + } catch (ScheduleException exp) {
  41 + rtn.put("status", ResponseCode.ERROR);
  42 + rtn.put("msg", exp.getMessage());
  43 + }
  44 +
  45 + return rtn;
  46 + }
  47 +
  48 + @RequestMapping(value = "/validate_n_d", method = RequestMethod.GET)
  49 + public Map<String, Object> validate_n_d(@RequestParam Map<String, Object> param) {
  50 + Map<String, Object> rtn = new HashMap<>();
  51 + try {
  52 + // 常规有效日重复验证
  53 + TTInfo ttInfo = new TTInfo(
  54 + param.get("id_eq"),
  55 + param.get("xl.id_eq"),
  56 + param.get("name_eq"),
  57 + param.get("rule_days_eq"),
  58 + param.get("special_days_eq")
  59 + );
  60 + ttInfoService.validate_n_d(ttInfo);
  61 + rtn.put("status", ResponseCode.SUCCESS);
  62 + } catch (ScheduleException exp) {
  63 + rtn.put("status", ResponseCode.ERROR);
  64 + rtn.put("msg", exp.getMessage());
  65 + }
  66 + return rtn;
  67 + }
  68 +
  69 + @RequestMapping(value = "/validate_s_d", method = RequestMethod.GET)
  70 + public Map<String, Object> validate_s_d(@RequestParam Map<String, Object> param) {
  71 + Map<String, Object> rtn = new HashMap<>();
  72 + try {
  73 + // 特殊有效日重复判定
  74 + TTInfo ttInfo = new TTInfo(
  75 + param.get("id_eq"),
  76 + param.get("xl.id_eq"),
  77 + param.get("name_eq"),
  78 + param.get("rule_days_eq"),
  79 + param.get("special_days_eq")
  80 + );
  81 + ttInfoService.validate_s_d(ttInfo);
  82 + rtn.put("status", ResponseCode.SUCCESS);
  83 + } catch (ScheduleException exp) {
  84 + rtn.put("status", ResponseCode.ERROR);
  85 + rtn.put("msg", exp.getMessage());
  86 + }
  87 + return rtn;
  88 + }
  89 +
  90 +}
  91 +
  92 +//
  93 +//@Autowired
  94 +//private DataToolsProperties dataToolsProperties;
  95 +//@Autowired
  96 +//private TTInfoRepository ttInfoRepository;
  97 +//@Autowired
  98 +//private TTInfoDetailRepository ttInfoDetailRepository;
  99 +//
  100 +// @Override
  101 +// protected String getDataImportKtrClasspath() {
  102 +// return dataToolsProperties.getTtinfoDatainputktr();
  103 +// }
  104 +//
  105 +// @Override
  106 +// public TTInfo findById(@PathVariable("id") Long aLong) {
  107 +// return ttInfoRepository.findOneExtend(aLong);
  108 +// }
  109 +//
  110 +// /**
  111 +// * 验证。
  112 +// * @param map
  113 +// * @return
  114 +// */
  115 +// @RequestMapping(value = "/validate/equale", method = RequestMethod.GET)
  116 +// public Map<String, Object> validateData(@RequestParam Map<String, Object> map) {
  117 +// // 一般比较自编号是否重复
  118 +// return baseService.validateEquale(map);
  119 +// }
  120 +//
  121 +// @Override
  122 +// public Page<TTInfo> list(@RequestParam Map<String, Object> map, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size, @RequestParam(defaultValue = "id") String order, @RequestParam(defaultValue = "DESC") String direction) {
  123 +// // 如果有isCancel键值,将其值变成boolean
  124 +// if (map.get("isCancel_eq") != null)
  125 +// map.put("isCancel_eq", new Boolean(map.get("isCancel_eq").toString()));
  126 +//
  127 +// return super.list(map, page, size, order, direction);
  128 +// }
0 \ No newline at end of file 129 \ No newline at end of file
src/main/java/com/bsth/data/BasicData.java
1 package com.bsth.data; 1 package com.bsth.data;
2 2
3 import com.bsth.Application; 3 import com.bsth.Application;
  4 +import com.bsth.data.gpsdata.arrival.GeoCacheData;
4 import com.bsth.entity.*; 5 import com.bsth.entity.*;
5 import com.bsth.entity.schedule.CarConfigInfo; 6 import com.bsth.entity.schedule.CarConfigInfo;
6 import com.bsth.repository.*; 7 import com.bsth.repository.*;
@@ -57,7 +58,7 @@ public class BasicData implements CommandLineRunner { @@ -57,7 +58,7 @@ public class BasicData implements CommandLineRunner {
57 public static Map<String, String> lineCode2NameMap; 58 public static Map<String, String> lineCode2NameMap;
58 59
59 //线路编码_站点编码 == 0|1 上下行 60 //线路编码_站点编码 == 0|1 上下行
60 - public static Map<String, Integer> lineStationUpDownMap; 61 + //public static Map<String, Integer> lineStationUpDownMap;
61 62
62 //停车场 63 //停车场
63 public static List<String> parkCodeList; 64 public static List<String> parkCodeList;
@@ -86,7 +87,7 @@ public class BasicData implements CommandLineRunner { @@ -86,7 +87,7 @@ public class BasicData implements CommandLineRunner {
86 87
87 @Override 88 @Override
88 public void run(String... arg0) throws Exception { 89 public void run(String... arg0) throws Exception {
89 - Application.mainServices.scheduleWithFixedDelay(dataLoader, 0, 1, TimeUnit.HOURS); 90 + Application.mainServices.scheduleWithFixedDelay(dataLoader, 2, 2, TimeUnit.HOURS);
90 } 91 }
91 92
92 93
@@ -117,6 +118,9 @@ public class BasicData implements CommandLineRunner { @@ -117,6 +118,9 @@ public class BasicData implements CommandLineRunner {
117 @Autowired 118 @Autowired
118 BusinessRepository businessRepository; 119 BusinessRepository businessRepository;
119 120
  121 + @Autowired
  122 + GeoCacheData geoCacheData;
  123 +
120 124
121 @Override 125 @Override
122 public void run() { 126 public void run() {
@@ -138,11 +142,13 @@ public class BasicData implements CommandLineRunner { @@ -138,11 +142,13 @@ public class BasicData implements CommandLineRunner {
138 //车辆和线路映射信息 142 //车辆和线路映射信息
139 loadNbbm2LineInfo(); 143 loadNbbm2LineInfo();
140 //站点路由信息 144 //站点路由信息
141 - loadStationRouteInfo(); 145 + //loadStationRouteInfo();
142 //人员信息 146 //人员信息
143 loadPersonnelInfo(); 147 loadPersonnelInfo();
144 //公司信息 148 //公司信息
145 loadBusinessInfo(); 149 loadBusinessInfo();
  150 +
  151 + geoCacheData.loadData();
146 logger.info("加载基础数据成功!,"); 152 logger.info("加载基础数据成功!,");
147 } catch (Exception e) { 153 } catch (Exception e) {
148 logger.error("加载基础数据时出现异常,", e); 154 logger.error("加载基础数据时出现异常,", e);
@@ -151,7 +157,7 @@ public class BasicData implements CommandLineRunner { @@ -151,7 +157,7 @@ public class BasicData implements CommandLineRunner {
151 } 157 }
152 158
153 159
154 - private void loadStationRouteInfo() { 160 +/* private void loadStationRouteInfo() {
155 Iterator<StationRoute> iterator = stationRouteRepository.findAllEffective().iterator(); 161 Iterator<StationRoute> iterator = stationRouteRepository.findAllEffective().iterator();
156 162
157 Map<String, String> sePointMap = new HashMap<>(); 163 Map<String, String> sePointMap = new HashMap<>();
@@ -172,7 +178,7 @@ public class BasicData implements CommandLineRunner { @@ -172,7 +178,7 @@ public class BasicData implements CommandLineRunner {
172 } 178 }
173 lineStationUpDownMap = map; 179 lineStationUpDownMap = map;
174 lineSEPointMap = sePointMap; 180 lineSEPointMap = sePointMap;
175 - } 181 + }*/
176 182
177 /** 183 /**
178 * loadBusinessInfo 184 * loadBusinessInfo
@@ -280,7 +286,7 @@ public class BasicData implements CommandLineRunner { @@ -280,7 +286,7 @@ public class BasicData implements CommandLineRunner {
280 /** 286 /**
281 * 加载运管处的站点及序号 287 * 加载运管处的站点及序号
282 * 上行从1开始,下行顺序续编 288 * 上行从1开始,下行顺序续编
283 - */ 289 +
284 List<Object[]> ygcLines = stationRouteRepository.findAllLineWithYgc(); 290 List<Object[]> ygcLines = stationRouteRepository.findAllLineWithYgc();
285 if(ygcLines != null && ygcLines.size() > 0){ 291 if(ygcLines != null && ygcLines.size() > 0){
286 int size = ygcLines.size(); 292 int size = ygcLines.size();
@@ -299,7 +305,7 @@ public class BasicData implements CommandLineRunner { @@ -299,7 +305,7 @@ public class BasicData implements CommandLineRunner {
299 key = tempArray[0] + "_"+tempArray[1] + "_"+tempArray[2]; 305 key = tempArray[0] + "_"+tempArray[1] + "_"+tempArray[2];
300 tempStationName2YgcNumber.put(key,num++); 306 tempStationName2YgcNumber.put(key,num++);
301 } 307 }
302 - } 308 + }*/
303 } 309 }
304 310
305 lineId2CodeMap = biMap; 311 lineId2CodeMap = biMap;
src/main/java/com/bsth/data/LineConfigData.java
1 package com.bsth.data; 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 import com.bsth.entity.Line; 3 import com.bsth.entity.Line;
16 import com.bsth.entity.realcontrol.D80ReplyTemp; 4 import com.bsth.entity.realcontrol.D80ReplyTemp;
17 import com.bsth.entity.realcontrol.LineConfig; 5 import com.bsth.entity.realcontrol.LineConfig;
18 import com.bsth.oplog.normal.OpLogger; 6 import com.bsth.oplog.normal.OpLogger;
19 import com.bsth.service.LineService; 7 import com.bsth.service.LineService;
20 import com.bsth.service.realcontrol.LineConfigService; 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.stereotype.Component;
  14 +
  15 +import java.util.*;
21 16
22 /** 17 /**
23 * 18 *
@@ -92,7 +87,7 @@ public class LineConfigData implements CommandLineRunner { @@ -92,7 +87,7 @@ public class LineConfigData implements CommandLineRunner {
92 //出场时间类型 87 //出场时间类型
93 conf.setOutConfig(1); 88 conf.setOutConfig(1);
94 //进场时间类型 89 //进场时间类型
95 - conf.setInConfig(1); 90 + //conf.setInConfig(1);
96 //短语模板 91 //短语模板
97 conf.setPhraseTemps(""); 92 conf.setPhraseTemps("");
98 //调度指令模板 93 //调度指令模板
src/main/java/com/bsth/data/arrival/AnalyseData.java
1 package com.bsth.data.arrival; 1 package com.bsth.data.arrival;
2 2
3 -import java.util.ArrayList;  
4 -import java.util.Collections;  
5 -import java.util.List;  
6 -import java.util.Set;  
7 -  
8 import org.slf4j.Logger; 3 import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory; 4 import org.slf4j.LoggerFactory;
10 import org.springframework.stereotype.Component; 5 import org.springframework.stereotype.Component;
11 6
12 -import com.bsth.data.BasicData; 7 +import java.util.ArrayList;
  8 +import java.util.Collections;
  9 +import java.util.List;
  10 +import java.util.Set;
13 11
14 /** 12 /**
15 * 13 *
@@ -98,14 +96,15 @@ public class AnalyseData { @@ -98,14 +96,15 @@ public class AnalyseData {
98 } 96 }
99 97
100 private boolean effective(ArrivalEntity arr){ 98 private boolean effective(ArrivalEntity arr){
101 - //停车场 99 + /*//停车场
102 if(BasicData.parkCodeList.contains(arr.getStopNo())){ 100 if(BasicData.parkCodeList.contains(arr.getStopNo())){
103 arr.setTcc(true); 101 arr.setTcc(true);
104 return true; 102 return true;
105 } 103 }
106 - 104 +
107 Integer upDown = BasicData.lineStationUpDownMap.get(arr.getLineCode() + "_" + arr.getStopNo()); 105 Integer upDown = BasicData.lineStationUpDownMap.get(arr.getLineCode() + "_" + arr.getStopNo());
108 -  
109 - return arr.getUpDown() == upDown || BasicData.parkCodeList.contains(arr.getStopNo()); 106 +
  107 + return arr.getUpDown() == upDown || BasicData.parkCodeList.contains(arr.getStopNo());*/
  108 + return false;
110 } 109 }
111 } 110 }
src/main/java/com/bsth/data/forecast/ForecastRealServer.java
@@ -70,7 +70,7 @@ public class ForecastRealServer implements CommandLineRunner { @@ -70,7 +70,7 @@ public class ForecastRealServer implements CommandLineRunner {
70 /* public void forecast(String nbbm){ 70 /* public void forecast(String nbbm){
71 logger.info("预测," + nbbm); 71 logger.info("预测," + nbbm);
72 //当前执行班次 72 //当前执行班次
73 - ScheduleRealInfo sch = dayOfSchedule.execPlamMap().get(nbbm); 73 + ScheduleRealInfo sch = dayOfSchedule.execPlanMap().get(nbbm);
74 if(null == sch) 74 if(null == sch)
75 return; 75 return;
76 76
@@ -86,7 +86,7 @@ public class ForecastRealServer implements CommandLineRunner { @@ -86,7 +86,7 @@ public class ForecastRealServer implements CommandLineRunner {
86 //终点站 86 //终点站
87 String eStation = null; 87 String eStation = null;
88 //当前执行班次 88 //当前执行班次
89 - ScheduleRealInfo sch = dayOfSchedule.execPlamMap().get(nbbm); 89 + ScheduleRealInfo sch = dayOfSchedule.execPlanMap().get(nbbm);
90 if(null != sch) 90 if(null != sch)
91 eStation = sch.getZdzCode(); 91 eStation = sch.getZdzCode();
92 92
src/main/java/com/bsth/data/gpsdata/GpsEntity.java
1 package com.bsth.data.gpsdata; 1 package com.bsth.data.gpsdata;
2 2
  3 +import com.bsth.data.gpsdata.arrival.entity.StationRoute;
  4 +import com.fasterxml.jackson.annotation.JsonIgnore;
  5 +
3 /** 6 /**
4 * 7 *
5 * @ClassName: GpsRealData 8 * @ClassName: GpsRealData
@@ -58,21 +61,32 @@ public class GpsEntity { @@ -58,21 +61,32 @@ public class GpsEntity {
58 /** 预计到达终点时间 */ 61 /** 预计到达终点时间 */
59 private Float expectStopTime; 62 private Float expectStopTime;
60 63
61 - /** 设备是否在线 */ 64 + /** 设备是否在线
62 private boolean online; 65 private boolean online;
63 - 66 + */
64 /** 当前执行班次ID */ 67 /** 当前执行班次ID */
65 private Long schId; 68 private Long schId;
66 69
67 /** 是否异常数据 */ 70 /** 是否异常数据 */
68 private boolean abnormal; 71 private boolean abnormal;
69 -  
70 - private int valid; 72 +/*
  73 + private int valid;*/
71 74
72 private int version; 75 private int version;
73 76
74 - /** 是否起终点站 */ 77 + /** 是否起终点站
75 private boolean sEPoint; 78 private boolean sEPoint;
  79 + */
  80 +
  81 + /** 0: 站外 1:站内 2:场内 */
  82 + private int instation;
  83 +
  84 + /** 站点信息,站内时有值 */
  85 + @JsonIgnore
  86 + private StationRoute station;
  87 +
  88 + /** 状态 */
  89 + private String signalState;
76 90
77 public Integer getCompanyCode() { 91 public Integer getCompanyCode() {
78 return companyCode; 92 return companyCode;
@@ -178,14 +192,6 @@ public class GpsEntity { @@ -178,14 +192,6 @@ public class GpsEntity {
178 this.stationName = stationName; 192 this.stationName = stationName;
179 } 193 }
180 194
181 - public boolean isOnline() {  
182 - return online;  
183 - }  
184 -  
185 - public void setOnline(boolean online) {  
186 - this.online = online;  
187 - }  
188 -  
189 public long getArrTime() { 195 public long getArrTime() {
190 return arrTime; 196 return arrTime;
191 } 197 }
@@ -218,35 +224,44 @@ public class GpsEntity { @@ -218,35 +224,44 @@ public class GpsEntity {
218 this.schId = schId; 224 this.schId = schId;
219 } 225 }
220 226
221 - public boolean isAbnormal() {  
222 - return abnormal; 227 +
  228 + public int getVersion() {
  229 + return version;
223 } 230 }
224 231
225 - public void setAbnormal(boolean abnormal) {  
226 - this.abnormal = abnormal; 232 + public void setVersion(int version) {
  233 + this.version = version;
227 } 234 }
228 235
229 - public int getValid() {  
230 - return valid; 236 + public StationRoute getStation() {
  237 + return station;
231 } 238 }
232 239
233 - public void setValid(int valid) {  
234 - this.valid = valid; 240 + public void setStation(StationRoute station) {
  241 + this.station = station;
235 } 242 }
236 243
237 - public int getVersion() {  
238 - return version; 244 + public boolean isAbnormal() {
  245 + return abnormal;
239 } 246 }
240 247
241 - public void setVersion(int version) {  
242 - this.version = version; 248 + public void setAbnormal(boolean abnormal) {
  249 + this.abnormal = abnormal;
  250 + }
  251 +
  252 + public String getSignalState() {
  253 + return signalState;
  254 + }
  255 +
  256 + public void setSignalState(String signalState) {
  257 + this.signalState = signalState;
243 } 258 }
244 259
245 - public boolean issEPoint() {  
246 - return sEPoint; 260 + public int getInstation() {
  261 + return instation;
247 } 262 }
248 263
249 - public void setsEPoint(boolean sEPoint) {  
250 - this.sEPoint = sEPoint; 264 + public void setInstation(int instation) {
  265 + this.instation = instation;
251 } 266 }
252 } 267 }
src/main/java/com/bsth/data/gpsdata/GpsRealData.java
@@ -5,6 +5,8 @@ import com.alibaba.fastjson.JSONObject; @@ -5,6 +5,8 @@ import com.alibaba.fastjson.JSONObject;
5 import com.bsth.Application; 5 import com.bsth.Application;
6 import com.bsth.data.BasicData; 6 import com.bsth.data.BasicData;
7 import com.bsth.data.forecast.ForecastRealServer; 7 import com.bsth.data.forecast.ForecastRealServer;
  8 +import com.bsth.data.gpsdata.arrival.GpsRealAnalyse;
  9 +import com.bsth.data.gpsdata.recovery.GpsDataRecovery;
8 import com.bsth.data.schedule.DayOfSchedule; 10 import com.bsth.data.schedule.DayOfSchedule;
9 import com.bsth.entity.realcontrol.ScheduleRealInfo; 11 import com.bsth.entity.realcontrol.ScheduleRealInfo;
10 import com.bsth.util.ConfigUtil; 12 import com.bsth.util.ConfigUtil;
@@ -27,263 +29,187 @@ import java.util.*; @@ -27,263 +29,187 @@ import java.util.*;
27 import java.util.concurrent.TimeUnit; 29 import java.util.concurrent.TimeUnit;
28 30
29 /** 31 /**
30 - * 32 + * @author PanZhao
31 * @ClassName: GpsRealData 33 * @ClassName: GpsRealData
32 * @Description: TODO(实时GPS数据集合) 34 * @Description: TODO(实时GPS数据集合)
33 - * @author PanZhao  
34 * @date 2016年8月12日 下午2:04:41 35 * @date 2016年8月12日 下午2:04:41
35 - *  
36 */ 36 */
37 @Component 37 @Component
38 -public class GpsRealData implements CommandLineRunner{  
39 -  
40 - static Logger logger = LoggerFactory.getLogger(GpsRealData.class);  
41 -  
42 - private static Map<String, GpsEntity> gpsMap;  
43 -  
44 - //按线路分组设备号  
45 - private static TreeMultimap<String, String> lineCode2Devices;  
46 -  
47 - // 网关数据接口地址  
48 - private static String url;  
49 -  
50 - @Autowired  
51 - GpsDataLoader gpsDataLoader;  
52 -  
53 - @Autowired  
54 - DayOfSchedule dayOfSchedule;  
55 -  
56 - @Autowired  
57 - ForecastRealServer forecastRealServer;  
58 - /**  
59 - * 构造函数  
60 - */  
61 - public GpsRealData(){  
62 - gpsMap = new HashMap<>();  
63 - lineCode2Devices = TreeMultimap.create();  
64 - url = ConfigUtil.get("http.gps.real.url");  
65 - }  
66 -  
67 - @Override  
68 - public void run(String... arg0) throws Exception {  
69 - logger.info("gpsDataLoader,20,6");  
70 - Application.mainServices.scheduleWithFixedDelay(gpsDataLoader, 20, 5, TimeUnit.SECONDS);  
71 - }  
72 -  
73 - public GpsEntity add(GpsEntity gps) {  
74 - String device = gps.getDeviceId();  
75 - GpsEntity old = gpsMap.get(device);  
76 -  
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 - }  
84 - else{  
85 - gps.setArrTime(old.getArrTime());  
86 - //不预测, 重新计算终点时间  
87 - gps.setExpectStopTime(forecastRealServer.expectStopTime(gps.getNbbm()));  
88 - }  
89 - }  
90 -  
91 - gpsMap.put(device, gps);  
92 - if(StringUtils.isNotBlank(gps.getLineId()))  
93 - lineCode2Devices.put(gps.getLineId(), device);  
94 - return gps;  
95 - }  
96 -  
97 - /**  
98 - *  
99 - * @Title: get @Description: TODO(设备号获取GPS)  
100 - */  
101 - public GpsEntity get(String deviceId) {  
102 - return gpsMap.get(deviceId);  
103 - }  
104 -  
105 - /**  
106 - *  
107 - * @Title: get @Description: TODO(线路编码获取GPS集合) @throws  
108 - */  
109 - public List<GpsEntity> getByLine(String lineCode) {  
110 - NavigableSet<String> set = lineCode2Devices.get(lineCode);  
111 -  
112 - List<GpsEntity> rs = new ArrayList<>();  
113 - GpsEntity gps;  
114 - ScheduleRealInfo sch;  
115 - for(String device : set){  
116 - gps = gpsMap.get(device);  
117 - //过滤异常GPS数据  
118 - if(gps.isAbnormal())  
119 - continue;  
120 -  
121 - sch = dayOfSchedule.execPlamMap().get(gps.getNbbm());  
122 - if(null != sch)  
123 - gps.setSchId(sch.getId());  
124 - rs.add(gps);  
125 - }  
126 -  
127 - return rs;  
128 - }  
129 -  
130 - public List<GpsEntity> get(List<String> pArray){  
131 - List<GpsEntity> list = new ArrayList<>();  
132 -  
133 - for(String code : pArray)  
134 - list.addAll(getByLine(code));  
135 - return list;  
136 - }  
137 -  
138 - public Set<String> allDevices(){  
139 - return gpsMap.keySet();  
140 - }  
141 -  
142 - public GpsEntity findByDeviceId(String deviceId) {  
143 - return gpsMap.get(deviceId);  
144 - }  
145 -  
146 - public Collection<GpsEntity> all(){  
147 - return gpsMap.values();  
148 - }  
149 -  
150 - public void remove(String device){  
151 - gpsMap.remove(device);  
152 - }  
153 - @Component  
154 - public static class GpsDataLoader extends Thread{  
155 -  
156 - Logger logger = LoggerFactory.getLogger(GpsDataLoader.class);  
157 -  
158 - @Autowired  
159 - GpsRealData gpsRealData;  
160 -  
161 - @Override  
162 - public void run() {  
163 - try{  
164 - load();  
165 - }catch(Exception e){  
166 - logger.error("", e);  
167 - }  
168 - }  
169 -  
170 - public void load() throws Exception {  
171 - List<GpsEntity> list = new ArrayList<>();  
172 - CloseableHttpClient httpClient = null;  
173 - CloseableHttpResponse response = null;  
174 - try {  
175 - httpClient = HttpClients.createDefault();  
176 - HttpGet get = new HttpGet(url);  
177 -  
178 - response = httpClient.execute(get);  
179 -  
180 - HttpEntity entity = response.getEntity();  
181 - if (null != entity) {  
182 - // 返回数据量比较大,建议以流的形式读取  
183 - BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));  
184 - StringBuffer stringBuffer = new StringBuffer();  
185 - String str = "";  
186 - while ((str = br.readLine()) != null)  
187 - stringBuffer.append(str);  
188 -  
189 - JSONObject jsonObj = JSON.parseObject(stringBuffer.toString());  
190 -  
191 - if (jsonObj != null)  
192 - list = JSON.parseArray(jsonObj.getString("data"), GpsEntity.class);  
193 -  
194 - String nbbm;  
195 - for(GpsEntity gps : list){  
196 - //没有设备号  
197 - if(StringUtils.isBlank(gps.getDeviceId()))  
198 - continue;  
199 -  
200 - nbbm = BasicData.deviceId2NbbmMap.get(gps.getDeviceId());  
201 - if(StringUtils.isBlank(nbbm))  
202 - gps.setAbnormal(true);//标记为异常数据  
203 - else  
204 - gps.setNbbm(nbbm);  
205 -  
206 - gps.setStationName(BasicData.stationCode2NameMap.get(gps.getStopNo()));  
207 - gpsRealData.add(gps);  
208 -  
209 - //纠正走向  
210 - correctUpdown(gps);  
211 - /*if(issEPoint(gps))  
212 - continue;  
213 -  
214 - //如果走向未知,尝试根据站点纠正走向  
215 - if(gps.getUpDown() == -1){  
216 - updown=stationUpDownMap.get(gps.getLineId()+"_"+gps.getStopNo());  
217 - if(updown != null)  
218 - gps.setUpDown(updown);  
219 - }  
220 - //如果站点编码和走向相反(即上行站点ID,走向为下行),尝试根据站点纠正走向  
221 - updown=stationUpDownMap.get(gps.getLineId()+"_"+gps.getStopNo());  
222 - if(updown != null && !gps.getUpDown().equals(updown)){  
223 - gps.setUpDown(updown);  
224 - }*/  
225 - }  
226 - } else  
227 - logger.error("result is null");  
228 - } catch(Exception e){  
229 - logger.error("", e);  
230 - }  
231 - finally {  
232 - if (null != httpClient)  
233 - httpClient.close();  
234 - if(null != response)  
235 - response.close();  
236 - }  
237 - }  
238 -  
239 - /**  
240 - * 是否是起终点  
241 - * @param gps  
242 - * @return  
243 - */  
244 - public boolean isSEPoint(GpsEntity gps){  
245 - String key = gps.getLineId()+"_"+gps.getUpDown()+"_"  
246 - ,stationCode;  
247 -  
248 - if(BasicData.lineSEPointMap.containsKey(key+"B")){  
249 - stationCode = BasicData.lineSEPointMap.get(key+"B");  
250 - if(gps.getStopNo().equals(stationCode)){  
251 - gps.setsEPoint(true);  
252 - return true;  
253 - }  
254 - }  
255 -  
256 - if(BasicData.lineSEPointMap.containsKey(key+"E")){  
257 - stationCode = BasicData.lineSEPointMap.get(key+"E");  
258 - if(gps.getStopNo().equals(stationCode)){  
259 - gps.setsEPoint(true);  
260 - return true;  
261 - }  
262 - }  
263 - return false;  
264 - }  
265 -  
266 - /**  
267 - * 纠正上下行  
268 - * @param gps  
269 - */  
270 - public void correctUpdown(GpsEntity gps){  
271 - Integer updown=BasicData.lineStationUpDownMap.get(gps.getLineId()+"_"+gps.getStopNo());  
272 - if(updown != null && !updown.equals(gps.getUpDown()))  
273 - gps.setUpDown(updown);  
274 - /*//如果走向未知,尝试根据站点纠正走向  
275 - if(gps.getUpDown() == -1){  
276 -  
277 - }*/  
278 -  
279 - if(isSEPoint(gps))  
280 - return;  
281 -  
282 - /*//如果站点编码和走向相反(即上行站点ID,走向为下行),尝试根据站点纠正走向  
283 - updown=BasicData.lineStationUpDownMap.get(gps.getLineId()+"_"+gps.getStopNo());  
284 - if(updown != null && !gps.getUpDown().equals(updown)){  
285 - gps.setUpDown(updown);  
286 - }*/  
287 - }  
288 - }  
289 -} 38 +public class GpsRealData implements CommandLineRunner {
  39 +
  40 + static Logger logger = LoggerFactory.getLogger(GpsRealData.class);
  41 +
  42 + private static Map<String, GpsEntity> gpsMap;
  43 +
  44 + //按线路分组设备号
  45 + private static TreeMultimap<String, String> lineCode2Devices;
  46 +
  47 + // 网关数据接口地址
  48 + private static String url;
  49 +
  50 + @Autowired
  51 + GpsDataLoader gpsDataLoader;
  52 +
  53 + @Autowired
  54 + DayOfSchedule dayOfSchedule;
  55 +
  56 + @Autowired
  57 + ForecastRealServer forecastRealServer;
  58 +
  59 + /**
  60 + * 构造函数
  61 + */
  62 + public GpsRealData() {
  63 + gpsMap = new HashMap<>();
  64 + lineCode2Devices = TreeMultimap.create();
  65 + url = ConfigUtil.get("http.gps.real.url");
  66 + }
  67 +
  68 + @Override
  69 + public void run(String... arg0) throws Exception {
  70 + logger.info("gpsDataLoader,40,6");
  71 + Application.mainServices.scheduleWithFixedDelay(gpsDataLoader, 40, 6, TimeUnit.SECONDS);
  72 + }
  73 +
  74 + public void put(GpsEntity gps) {
  75 + gpsMap.put(gps.getDeviceId(), gps);
  76 + }
  77 +
  78 + /**
  79 + * @Title: get @Description: TODO(设备号获取GPS)
  80 + */
  81 + public GpsEntity get(String deviceId) {
  82 + return gpsMap.get(deviceId);
  83 + }
  84 +
  85 + /**
  86 + * @Title: get @Description: TODO(线路编码获取GPS集合) @throws
  87 + */
  88 + public List<GpsEntity> getByLine(String lineCode) {
  89 + NavigableSet<String> set = lineCode2Devices.get(lineCode);
  90 +
  91 + List<GpsEntity> rs = new ArrayList<>();
  92 + GpsEntity gps;
  93 + ScheduleRealInfo sch;
  94 + for (String device : set) {
  95 + gps = gpsMap.get(device);
  96 + //过滤异常GPS数据
  97 + if (gps.isAbnormal())
  98 + continue;
  99 +
  100 + sch = dayOfSchedule.execPlanMap().get(gps.getNbbm());
  101 + if (null != sch)
  102 + gps.setSchId(sch.getId());
  103 + rs.add(gps);
  104 + }
  105 +
  106 + return rs;
  107 + }
  108 +
  109 + public List<GpsEntity> get(List<String> pArray) {
  110 + List<GpsEntity> list = new ArrayList<>();
  111 +
  112 + for (String code : pArray)
  113 + list.addAll(getByLine(code));
  114 + return list;
  115 + }
  116 +
  117 + public Set<String> allDevices() {
  118 + return gpsMap.keySet();
  119 + }
  120 +
  121 + public GpsEntity findByDeviceId(String deviceId) {
  122 + return gpsMap.get(deviceId);
  123 + }
  124 +
  125 + public Collection<GpsEntity> all() {
  126 + return gpsMap.values();
  127 + }
  128 +
  129 + public void remove(String device) {
  130 + gpsMap.remove(device);
  131 + }
  132 +
  133 + @Component
  134 + public static class GpsDataLoader extends Thread {
  135 +
  136 + Logger logger = LoggerFactory.getLogger(GpsDataLoader.class);
  137 +
  138 + @Autowired
  139 + GpsRealData gpsRealData;
  140 +
  141 + @Autowired
  142 + GpsRealAnalyse gpsRealAnalyse;
  143 +
  144 + @Override
  145 + public void run() {
  146 + try {
  147 + //如果正在恢复数据
  148 + if (GpsDataRecovery.run)
  149 + return;
  150 +
  151 + load();
  152 + } catch (Exception e) {
  153 + logger.error("", e);
  154 + }
  155 + }
  156 +
  157 + public void load() throws Exception {
  158 + List<GpsEntity> list = null;
  159 + List<GpsEntity> updateList = new ArrayList<>();
  160 + CloseableHttpClient httpClient = null;
  161 + CloseableHttpResponse response = null;
  162 + try {
  163 + httpClient = HttpClients.createDefault();
  164 + HttpGet get = new HttpGet(url);
  165 +
  166 + response = httpClient.execute(get);
  167 +
  168 + HttpEntity entity = response.getEntity();
  169 + if (null != entity) {
  170 + BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));
  171 + StringBuffer stringBuffer = new StringBuffer();
  172 + String str = "";
  173 + while ((str = br.readLine()) != null)
  174 + stringBuffer.append(str);
  175 +
  176 + JSONObject jsonObj = JSON.parseObject(stringBuffer.toString());
  177 +
  178 + if (jsonObj != null)
  179 + list = JSON.parseArray(jsonObj.getString("data"), GpsEntity.class);
  180 +
  181 + String nbbm;
  182 + GpsEntity old;
  183 + for (GpsEntity gps : list) {
  184 + //没有设备号
  185 + if (StringUtils.isBlank(gps.getDeviceId()))
  186 + continue;
  187 +
  188 + old = gpsMap.get(gps.getDeviceId());
  189 + if (old != null &&
  190 + old.getTimestamp() == gps.getTimestamp())
  191 + continue;
  192 +
  193 + nbbm = BasicData.deviceId2NbbmMap.get(gps.getDeviceId());
  194 + if (StringUtils.isBlank(nbbm))
  195 + gps.setAbnormal(true);//标记为异常数据
  196 + else
  197 + gps.setNbbm(nbbm);
  198 + //有更新的点位
  199 + updateList.add(gps);
  200 + }
  201 + //分析数据
  202 + gpsRealAnalyse.analyse(updateList);
  203 + } else
  204 + logger.error("real gps result is null");
  205 + } catch (Exception e) {
  206 + logger.error("", e);
  207 + } finally {
  208 + if (null != httpClient)
  209 + httpClient.close();
  210 + if (null != response)
  211 + response.close();
  212 + }
  213 + }
  214 + }
  215 +}
290 \ No newline at end of file 216 \ No newline at end of file
src/main/java/com/bsth/data/gpsdata/arrival/GeoCacheData.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.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 + //每辆车缓存最后500条gps
  33 + private static final int CACHE_SIZE = 500;
  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 Polygon getTccPolygon(String code) {
  98 + return tccMap.get(code);
  99 + }
  100 +
  101 + public void loadData() {
  102 + final GeometryFactory geometryFactory = new GeometryFactory();
  103 + //加载站点路由
  104 + 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";
  105 + List<StationRoute> routeList = jdbcTemplate.query(sql, new RowMapper<StationRoute>() {
  106 + @Override
  107 + public StationRoute mapRow(ResultSet rs, int rowNum) throws SQLException {
  108 + StationRoute sRoute = new StationRoute();
  109 + sRoute.setCode(rs.getString("STATION_CODE"));
  110 + sRoute.setLineCode(rs.getString("LINE_CODE"));
  111 + sRoute.setDirections(rs.getInt("DIRECTIONS"));
  112 + sRoute.setPoint(geometryFactory.createPoint(new Coordinate(rs.getFloat("G_LATY"), rs.getFloat("G_LONX"))));
  113 + sRoute.setRadius(rs.getFloat("RADIUS"));
  114 + sRoute.setRouteSort(rs.getInt("STATION_ROUTE_CODE"));
  115 + sRoute.setMark(rs.getString("STATION_MARK"));
  116 + sRoute.setName(rs.getString("STATION_NAME"));
  117 +
  118 + String shapesType = rs.getString("SHAPES_TYPE");
  119 + //多边形电子围栏
  120 + if (StringUtils.isNotEmpty(shapesType) && shapesType.equals("d")) {
  121 + sRoute.setPolygon(geometryFactory.createPolygon(parsePolygon(rs.getString("G_POLYGON_GRID"))));
  122 + }
  123 + return sRoute;
  124 + }
  125 + });
  126 + //按线路和走向分组
  127 + if (routeList.size() > 0) {
  128 + ArrayListMultimap<String, StationRoute> tempMap = ArrayListMultimap.create();
  129 + Map<String, StationRoute> codeMap = new HashMap<>(routeList.size());
  130 + for (StationRoute sr : routeList) {
  131 + tempMap.put(sr.getLineCode() + "_" + sr.getDirections(), sr);
  132 + //站点编码 ——> 和路由顺序对照
  133 + codeMap.put(sr.getLineCode() + "_" + sr.getDirections() + "_" + sr.getCode(), sr);
  134 + }
  135 +
  136 + StationRouteComp srCom = new StationRouteComp();
  137 + //连接路由
  138 + Set<String> set = tempMap.keySet();
  139 + for (String key : set) {
  140 + Collections.sort(tempMap.get(key), srCom);
  141 + connectStationRoute(tempMap.get(key));
  142 + }
  143 +
  144 + stationCacheMap = tempMap;
  145 + routeCodeMap = codeMap;
  146 + }
  147 +
  148 + //加载停车场数据
  149 + 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";
  150 + List<Map<String, Object>> tccList = jdbcTemplate.queryForList(sql);
  151 + Map<String, Polygon> tccTempMap = new HashMap<>();
  152 +
  153 + Polygon polygon;
  154 + for (Map<String, Object> tMap : tccList) {
  155 +
  156 + try {
  157 + polygon = geometryFactory.createPolygon(parsePolygon(tMap.get("G_PARK_POINT").toString()));
  158 + tccTempMap.put(tMap.get("PARK_CODE").toString()
  159 + , polygon);
  160 + } catch (Exception e) {
  161 + logger.error("停车场:" + tMap.get("PARK_CODE"), e);
  162 + }
  163 + }
  164 +
  165 + if (tccTempMap.size() > 0)
  166 + tccMap = tccTempMap;
  167 + }
  168 +
  169 + private void connectStationRoute(List<StationRoute> list) {
  170 + int size = list.size();
  171 + StationRoute sr = null;
  172 + for (int i = 0; i < size; i++) {
  173 + sr = list.get(i);
  174 + //上一个
  175 + if (i > 0)
  176 + sr.setPrve(list.get(i - 1));
  177 + //下一个
  178 + if (i < size - 1)
  179 + sr.setNext(list.get(i + 1));
  180 + }
  181 + }
  182 +
  183 + public Coordinate[] parsePolygon(String polygonStr) {
  184 + String[] coords = polygonStr.substring(9, polygonStr.length() - 2).split(","), temps;
  185 +
  186 + Coordinate[] cds = new Coordinate[coords.length];
  187 + int len = coords.length;
  188 + for (int i = 0; i < len; i++) {
  189 + temps = coords[i].split(" ");
  190 + cds[i] = new Coordinate(Float.parseFloat(temps[1]), Float.parseFloat(temps[0]));
  191 + }
  192 + return cds;
  193 + }
  194 +}
0 \ No newline at end of file 195 \ 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.arrival.handlers.*;
  5 +import com.bsth.data.gpsdata.arrival.utils.CircleQueue;
  6 +import org.slf4j.Logger;
  7 +import org.slf4j.LoggerFactory;
  8 +import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.stereotype.Component;
  10 +
  11 +import java.util.List;
  12 +import java.util.concurrent.CountDownLatch;
  13 +import java.util.concurrent.ExecutorService;
  14 +import java.util.concurrent.Executors;
  15 +
  16 +/**
  17 + * gps 实时数据分析
  18 + * Created by panzhao on 2016/12/27.
  19 + */
  20 +@Component
  21 +public class GpsRealAnalyse {
  22 +
  23 + Logger logger = LoggerFactory.getLogger(this.getClass());
  24 +
  25 + @Autowired
  26 + OfflineSignalHandle offlineSignalHandle;
  27 + @Autowired
  28 + CorrectSignalHandle correctSignalHandle;
  29 + @Autowired
  30 + StationInsideHandle stationInsideHandle;
  31 + @Autowired
  32 + InOutStationSignalHandle inOutStationSignalHandle;
  33 + @Autowired
  34 + ReverseSignalHandle reverseSignalHandle;
  35 +
  36 + //50个线程
  37 + static ExecutorService threadPool = Executors.newFixedThreadPool(50);
  38 +
  39 + public void analyse(List<GpsEntity> list) {
  40 + CountDownLatch count = new CountDownLatch(list.size());
  41 +
  42 + for(GpsEntity gps : list)
  43 + threadPool.execute(new SignalHandleThread(gps, count));
  44 +
  45 + try {
  46 + //等待子线程结束
  47 + count.await();
  48 + } catch (InterruptedException e) {
  49 + logger.error("", e);
  50 + }
  51 + }
  52 +
  53 + public class SignalHandleThread implements Runnable {
  54 +
  55 + GpsEntity gps;
  56 + CountDownLatch count;
  57 +
  58 + SignalHandleThread(GpsEntity gps, CountDownLatch count) {
  59 + this.gps = gps;
  60 + this.count = count;
  61 + }
  62 +
  63 + @Override
  64 + public void run() {
  65 +
  66 + try {
  67 + CircleQueue<GpsEntity> prevs = GeoCacheData.getGps(gps.getNbbm());
  68 + //掉线处理
  69 + offlineSignalHandle.handle(gps, prevs);
  70 + //状态处理
  71 + if(!correctSignalHandle.handle(gps, prevs))
  72 + return;
  73 + //场,站内外判断
  74 + stationInsideHandle.handle(gps, prevs);
  75 + //反向处理
  76 + reverseSignalHandle.handle(gps, prevs);
  77 + //进出站动作处理
  78 + inOutStationSignalHandle.handle(gps, prevs);
  79 + GeoCacheData.putGps(gps);
  80 +
  81 + } catch (Exception e) {
  82 + logger.error("", e);
  83 + } finally {
  84 + count.countDown();
  85 + }
  86 + }
  87 + }
  88 +}
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.utils.CircleQueue;
  5 +
  6 +/**
  7 + * Created by panzhao on 2016/12/27.
  8 + */
  9 +public abstract class SignalHandle {
  10 +
  11 + public abstract boolean handle(GpsEntity gps, CircleQueue<GpsEntity> prevs);
  12 +
  13 + protected boolean isNotEmpty(CircleQueue<GpsEntity> prevs) {
  14 + return prevs != null && prevs.size() > 0 && prevs.getTail() != null;
  15 + }
  16 +
  17 + /**
  18 + * 是不是异常信号
  19 + *
  20 + * @param gps
  21 + * @return
  22 + */
  23 + protected boolean isAbnormal(GpsEntity gps) {
  24 + return gps.getLat() == 0 || gps.getLon() == 0;
  25 + }
  26 +
  27 + /**
  28 + * 连续异常信号个数统计
  29 + *
  30 + * @param prevs
  31 + * @return
  32 + */
  33 + protected int abnormalCount(CircleQueue<GpsEntity> prevs) {
  34 + int count = 0;
  35 +
  36 + if (!isNotEmpty(prevs))
  37 + return count;
  38 +
  39 + GpsEntity[] array = (GpsEntity[]) prevs.getQueue();
  40 + GpsEntity gps;
  41 + for (int i = array.length - 1; i > 0; i--) {
  42 + gps = array[i];
  43 +
  44 + if (isAbnormal(gps))
  45 + count++;
  46 + else
  47 + break;
  48 + }
  49 +
  50 + return count;
  51 + }
  52 +
  53 + /**
  54 + * 车辆运行轨迹(最近20分钟)
  55 + * 0:上行 1:下行 -1:未知
  56 + *
  57 + * @param gps
  58 + * @return
  59 + */
  60 + protected int runTrack(GpsEntity gps, CircleQueue<GpsEntity> prevs) {
  61 + int rs = -1, count = 0;
  62 +
  63 + long et = gps.getTimestamp() - (1000 * 60 * 20);
  64 + Object[] array = prevs.getQueue();
  65 + GpsEntity prev;
  66 + for(Object obj : array){
  67 + prev = (GpsEntity) obj;
  68 + if(prev.getTimestamp() < et)
  69 + break;
  70 +
  71 +
  72 + }
  73 + //for()
  74 + return 0;
  75 + }
  76 +
  77 +}
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 + //反转个数
  9 + private int count;
  10 +
  11 + //详细 1,2,3,2,1
  12 + private String detail;
  13 +
  14 + //掉头站点
  15 + private String turned;
  16 +
  17 + //开始时间
  18 + private long st;
  19 +
  20 + //掉头时间
  21 + private long zt;
  22 +
  23 + //结束时间
  24 + private long et;
  25 +
  26 + //是否闭合
  27 + private boolean close;
  28 +
  29 + public int getCount() {
  30 + return count;
  31 + }
  32 +
  33 + public void setCount(int count) {
  34 + this.count = count;
  35 + }
  36 +
  37 + public String getDetail() {
  38 + return detail;
  39 + }
  40 +
  41 + public void setDetail(String detail) {
  42 + this.detail = detail;
  43 + }
  44 +
  45 + public String getTurned() {
  46 + return turned;
  47 + }
  48 +
  49 + public void setTurned(String turned) {
  50 + this.turned = turned;
  51 + }
  52 +
  53 + public long getSt() {
  54 + return st;
  55 + }
  56 +
  57 + public void setSt(long st) {
  58 + this.st = st;
  59 + }
  60 +
  61 + public long getEt() {
  62 + return et;
  63 + }
  64 +
  65 + public void setEt(long et) {
  66 + this.et = et;
  67 + }
  68 +
  69 + public boolean isClose() {
  70 + return close;
  71 + }
  72 +
  73 + public void setClose(boolean close) {
  74 + this.close = close;
  75 + }
  76 +
  77 + public long getZt() {
  78 + return zt;
  79 + }
  80 +
  81 + public void setZt(long zt) {
  82 + this.zt = zt;
  83 + }
  84 +}
src/main/java/com/bsth/data/gpsdata/arrival/entity/StationRoute.java 0 → 100644
  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.GeoCacheData;
  6 +import com.bsth.data.gpsdata.arrival.SignalHandle;
  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.GeoUtils;
  10 +import com.bsth.data.schedule.DayOfSchedule;
  11 +import com.bsth.entity.realcontrol.LineConfig;
  12 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  13 +import com.bsth.service.directive.DirectiveService;
  14 +import com.bsth.websocket.handler.SendUtils;
  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 +import java.util.List;
  21 +
  22 +/**
  23 + * 进出站动作处理
  24 + * Created by panzhao on 2016/12/27.
  25 + */
  26 +@Component
  27 +public class InOutStationSignalHandle extends SignalHandle{
  28 +
  29 + Logger logger = LoggerFactory.getLogger(this.getClass());
  30 +
  31 + @Autowired
  32 + DayOfSchedule dayOfSchedule;
  33 +
  34 + @Autowired
  35 + LineConfigData lineConfigData;
  36 +
  37 + @Autowired
  38 + SendUtils sendUtils;
  39 +
  40 + @Autowired
  41 + DirectiveService directiveService;
  42 +
  43 + @Override
  44 + public boolean handle(GpsEntity gps, CircleQueue<GpsEntity> prevs) {
  45 +
  46 + if(isNotEmpty(prevs)){
  47 + GpsEntity prev = prevs.getTail();
  48 + if(isOutStation(gps, prev))
  49 + outStation(gps, prev);
  50 +
  51 +
  52 + if(isInStation(gps, prev))
  53 + inStation(gps, prev);
  54 + }
  55 +
  56 + return true;
  57 + }
  58 +
  59 + private boolean isOutStation(GpsEntity gps, GpsEntity prev){
  60 + //从站内到站外
  61 + if(prev.getInstation() > 0 && gps.getInstation() == 0)
  62 + return true;
  63 +
  64 + //从站内到另一个站内
  65 + if(prev.getInstation() > 0 && gps.getInstation() > 0
  66 + && !prev.getStopNo().equals(gps.getStopNo()))
  67 + return true;
  68 + return false;
  69 + }
  70 +
  71 + private boolean isInStation(GpsEntity gps, GpsEntity prev){
  72 + //从站外到站内
  73 + if(prev.getInstation() == 0 && gps.getInstation() > 0
  74 + /*&& !prev.getStopNo().equals(gps.getStopNo())*/){
  75 + return true;
  76 + }
  77 +
  78 + //从站内到另一个站内
  79 + if(prev.getInstation() > 0 && gps.getInstation() > 0
  80 + && !prev.getStopNo().equals(gps.getStopNo()))
  81 + return true;
  82 + return false;
  83 + }
  84 +
  85 + /**
  86 + * 出站
  87 + * @param gps 当前点
  88 + * @param prev 上一个点
  89 + */
  90 + private void outStation(GpsEntity gps, GpsEntity prev) {
  91 + ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm());
  92 + String qdzCode = sch.getQdzCode();
  93 +
  94 +
  95 + //if(sch.getFcsjActual() != )
  96 +
  97 + //起点发车
  98 + if(qdzCode != null && prev.getStopNo().equals(qdzCode)
  99 + && !willDepart(gps, prev, sch)){
  100 +
  101 + sch.setFcsjActualAll(gps.getTimestamp());
  102 + //通知客户端
  103 + sendUtils.sendFcsj(sch);
  104 + //持久化
  105 + dayOfSchedule.save(sch);
  106 +
  107 + //出站既出场
  108 + outStationAndOutPark(sch);
  109 + logger.info("班次:" + sch.getDfsj() + "发车, 时间:" + sch.getFcsjActual());
  110 + }
  111 + }
  112 +
  113 + private void outStationAndOutPark(ScheduleRealInfo sch){
  114 + LineConfig config = lineConfigData.get(sch.getXlBm());
  115 + if (config != null && config.getOutConfig() == 2) {
  116 + //出站既出场
  117 + ScheduleRealInfo schPrev = dayOfSchedule.prev(sch);
  118 + if (schPrev != null && schPrev.getBcType().equals("out")) {
  119 + schPrev.setFcsjActualAll(sch.getFcsjActual());
  120 + schPrev.setZdsjActualAll(sch.getFcsjActual());
  121 + }
  122 + }
  123 + }
  124 +
  125 + /**
  126 + * 进站
  127 + * @param gps 当前点
  128 + * @param prev 上一个点
  129 + */
  130 + private void inStation(GpsEntity gps, GpsEntity prev){
  131 + ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm());
  132 + String zdzCode = sch.getZdzCode();
  133 +
  134 + if(zdzCode != null && gps.getStopNo().equals(zdzCode)){
  135 +
  136 + sch.setZdsjActualAll(gps.getTimestamp());
  137 + //已完成班次数
  138 + int doneSum = dayOfSchedule.doneSum(sch.getClZbh());
  139 + ScheduleRealInfo next = dayOfSchedule.next(sch);
  140 + //通知客户端
  141 + sendUtils.sendZdsj(sch, next, doneSum);
  142 + //持久化
  143 + dayOfSchedule.save(sch);
  144 + //下发调度指令
  145 + //directiveService.send60Dispatch(next, doneSum, "到站@系统");
  146 +
  147 + //准备执行下一个班次
  148 + if (next != null) {
  149 + next.setQdzArrDatesj(sch.getZdsjActual());
  150 + dayOfSchedule.addExecPlan(next);
  151 +
  152 + //进站既进场
  153 + inStationAndInPark(sch, next);
  154 +
  155 + //将gps转换为下一个班次走向的站内信号
  156 + int updown = Integer.parseInt(next.getXlDir());
  157 + List<StationRoute> srs = GeoCacheData.getStationRoute(next.getXlBm(), updown);
  158 + StationRoute station = GeoUtils.gpsInStation(gps, srs);
  159 + if (station != null) {
  160 + gps.setUpDown(updown);
  161 + gps.setStopNo(station.getCode());
  162 + }
  163 + }
  164 + }
  165 + /* //如果出场班次计划终点时间5分钟后还未完成,检查一下车辆轨迹,是否已经在执行线路上班次
  166 + else if(sch.getBcType().equals("out")
  167 + && sch.getZdsj() != null
  168 + && gps.getTimestamp() - sch.getZdsjT() >= 1000 * 60 * 5){
  169 + logger.info("出场班次计划终点时间5分钟后还未完成");
  170 +
  171 + }*/
  172 + }
  173 +
  174 + /**
  175 + * 进站既进场
  176 + * @param sch
  177 + */
  178 + private void inStationAndInPark(ScheduleRealInfo sch, ScheduleRealInfo next){
  179 + LineConfig config = lineConfigData.get(sch.getXlBm());
  180 + if (next.getBcType().equals("in") &&
  181 + config != null && config.getOutConfig() == 2) {
  182 + next.setFcsjActualAll(sch.getZdsjActual());
  183 + next.setZdsjActualAll(sch.getZdsjActual());
  184 + }
  185 + }
  186 +
  187 + /**
  188 + * 发车漂移判定(这里出现的误判,由车辆到达中途站的时候补偿)
  189 + * @param gps
  190 + * @param prev
  191 + * @param task
  192 + * @return
  193 + */
  194 + private boolean willDepart(GpsEntity gps, GpsEntity prev, Object task){
  195 +
  196 +/* ScheduleRealInfo sch = (ScheduleRealInfo) task;
  197 + ScheduleRealInfo prevTask = dayOfSchedule.prev(sch);
  198 + if(prevTask == null || prevTask.getBcType().equals("out"))
  199 + return false;
  200 +
  201 + //计划停站时间
  202 + int stopTimePlan = (int) (sch.getDfsjT() - prevTask.getZdsjT());
  203 +
  204 + if(stopTimePlan < 1000 * 60 * 10)
  205 + return false;
  206 +
  207 + //实际停站时间
  208 + if(prevTask.getZdsjActual() != null){
  209 + int actualTime = (int) (gps.getTimestamp() - prevTask.getZdsjActualTime());
  210 +
  211 + if(actualTime < stopTimePlan * 0.8){
  212 + logger.info("漂移判定");
  213 +
  214 + return true;
  215 + }
  216 + }*/
  217 + return false;
  218 + }
  219 +}
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 + //断开3分钟,标记为重连信号
  17 + private final static int OFFLINE_TIME = 1000 * 60 * 3;
  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(isAbnormal(gps)){
  26 + return true;
  27 + }
  28 +
  29 + if(isNotEmpty(prevs)){
  30 + GpsEntity prev = prevs.getTail();
  31 + int space = (int) (gps.getTimestamp() - prev.getTimestamp());
  32 + if(space > OFFLINE_TIME)
  33 + gps.setSignalState("reconnection");
  34 +
  35 + if(space > CLEAR_TIME){
  36 + //清理缓存的信号
  37 + GeoCacheData.clear(gps.getNbbm());
  38 + }
  39 + }
  40 + return true;
  41 + }
  42 +}
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.alibaba.fastjson.JSON;
  4 +import com.bsth.data.gpsdata.GpsEntity;
  5 +import com.bsth.data.gpsdata.arrival.GeoCacheData;
  6 +import com.bsth.data.gpsdata.arrival.SignalHandle;
  7 +import com.bsth.data.gpsdata.arrival.entity.RouteReverse;
  8 +import com.bsth.data.gpsdata.arrival.entity.StationRoute;
  9 +import com.bsth.data.gpsdata.arrival.utils.CircleQueue;
  10 +import com.bsth.data.schedule.DayOfSchedule;
  11 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  12 +import org.slf4j.Logger;
  13 +import org.slf4j.LoggerFactory;
  14 +import org.springframework.beans.factory.annotation.Autowired;
  15 +import org.springframework.stereotype.Component;
  16 +
  17 +/**
  18 + * 路由反向信号处理
  19 + * Created by panzhao on 2016/12/28.
  20 + */
  21 +@Component
  22 +public class ReverseSignalHandle extends SignalHandle {
  23 +
  24 + Logger logger = LoggerFactory.getLogger(this.getClass());
  25 +
  26 + @Autowired
  27 + DayOfSchedule dayOfSchedule;
  28 +
  29 + @Override
  30 + public boolean handle(GpsEntity gps, CircleQueue<GpsEntity> prevs) {
  31 + if (!isNotEmpty(prevs))
  32 + return false;
  33 +
  34 + GpsEntity prev = prevs.getTail();
  35 +
  36 + if (isReverse(gps, prev)) {
  37 + RouteReverse reverse = reverseSearch(prevs, gps);
  38 +
  39 + if (reverse.getCount() >= 2) {
  40 + //切换到下一个班次
  41 + ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm());
  42 + if (sch.getBcType().equals("out") && sch.getZdsjT() != null && sch.getZdsjT() > gps.getTimestamp()) {
  43 + return false;
  44 + }
  45 + dayOfSchedule.addExecPlan(dayOfSchedule.next(sch));
  46 +
  47 + if (reverse.isClose()) {
  48 + logger.info("区间掉头,车辆:" + gps.getNbbm() + " -" + JSON.toJSONString(reverse));
  49 + }
  50 + }
  51 + }
  52 + return false;
  53 + }
  54 +
  55 + /**
  56 + * 搜索路由反向详细
  57 + *
  58 + * @param prevs
  59 + * @param gps
  60 + * @return
  61 + */
  62 + public RouteReverse reverseSearch(CircleQueue<GpsEntity> prevs, GpsEntity gps) {
  63 + RouteReverse routeReverse = new RouteReverse();
  64 + int count = 0;
  65 + String path = "";
  66 + String turned = null;
  67 +
  68 + //当前站点
  69 + StationRoute curr = GeoCacheData.getRouteCode(gps), sr;
  70 + GpsEntity prev;
  71 + Object[] array = prevs.getQueue();
  72 + for (int i = array.length - 1; i > 0; i--) {
  73 + prev = (GpsEntity) array[i];
  74 +
  75 + if(!prev.getUpDown().equals(gps.getUpDown()))
  76 + break;
  77 +
  78 + if (prev.getInstation() == 1) {
  79 + sr = GeoCacheData.getRouteCode(prev);
  80 +
  81 + if (sr.getRouteSort() > curr.getRouteSort()) {
  82 + path += (curr.getCode() + ",");
  83 + count++;
  84 + } else if (sr.getRouteSort() < curr.getRouteSort()) {
  85 + path += (curr.getCode() + ",");
  86 + //掉头点
  87 + if (turned == null)
  88 + turned = prev.getStopNo();
  89 +
  90 + //路径闭合
  91 + if (sr.getCode().equals(gps.getStopNo())) {
  92 + routeReverse.setClose(true);
  93 + path += sr.getCode();
  94 + break;
  95 + }
  96 + }
  97 +
  98 + curr = sr;
  99 + }
  100 + }
  101 +
  102 + routeReverse.setCount(count);
  103 + routeReverse.setDetail(path);
  104 + routeReverse.setTurned(turned);
  105 + return routeReverse;
  106 + }
  107 +
  108 + /**
  109 + * 是否反向
  110 + *
  111 + * @param gps
  112 + * @param prev
  113 + * @return
  114 + */
  115 + public boolean isReverse(GpsEntity gps, GpsEntity prev) {
  116 + if (gps.getInstation() == 1
  117 + &&
  118 + gps.getUpDown().equals(prev.getUpDown())
  119 + && !gps.getStopNo().equals(prev.getStopNo())) {
  120 +
  121 + StationRoute currStation = GeoCacheData.getRouteCode(gps);
  122 + StationRoute prevStation = GeoCacheData.getRouteCode(prev);
  123 +
  124 + if (currStation == null || prevStation == null)
  125 + return false;
  126 +
  127 + if (currStation.getRouteSort() < prevStation.getRouteSort())
  128 + return true;
  129 + }
  130 + return false;
  131 + }
  132 +}
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/arrival/utils/CircleQueue.java 0 → 100644
  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];
  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 + }
  123 +}
0 \ No newline at end of file 124 \ No newline at end of file
src/main/java/com/bsth/data/gpsdata/arrival/utils/GeoUtils.java 0 → 100644
  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/StationRouteComp.java 0 → 100644
  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 0 → 100644
  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 + }
  64 +
  65 + try {
  66 + count.await();
  67 + run = false;
  68 + logger.info("数据恢复完成....");
  69 + } catch (InterruptedException e) {
  70 + logger.error("", e);
  71 + }
  72 + }
  73 +
  74 + /**
  75 + * 加载当天的gps数据
  76 + *
  77 + * @return
  78 + */
  79 + public List<GpsEntity> loadData() {
  80 + Calendar calendar = Calendar.getInstance();
  81 + int dayOfYear = calendar.get(Calendar.DAY_OF_YEAR);
  82 +
  83 + String sql = "select DEVICE_ID,LAT,LON,TS,SPEED_GPS,LINE_ID,SERVICE_STATE from bsth_c_gps_info where days_year=" + dayOfYear;
  84 + JdbcTemplate jdbcTemplate = new JdbcTemplate(DBUtils_MS.getDataSource());
  85 +
  86 + List<GpsEntity> list =
  87 + jdbcTemplate.query(sql, new RowMapper<GpsEntity>() {
  88 + @Override
  89 + public GpsEntity mapRow(ResultSet rs, int rowNum) throws SQLException {
  90 + GpsEntity gps = new GpsEntity();
  91 +
  92 + gps.setDeviceId(rs.getString("DEVICE_ID"));
  93 + gps.setNbbm(BasicData.deviceId2NbbmMap.get(gps.getDeviceId()));
  94 + gps.setSpeed(rs.getFloat("SPEED_GPS"));
  95 + gps.setLat(rs.getFloat("LAT"));
  96 + gps.setLon(rs.getFloat("LON"));
  97 + gps.setLineId(rs.getString("LINE_ID"));
  98 + gps.setTimestamp(rs.getLong("TS"));
  99 + gps.setUpDown(getUpOrDown(rs.getLong("SERVICE_STATE")));
  100 + return gps;
  101 + }
  102 + });
  103 + return list;
  104 + }
  105 +
  106 + /**
  107 + * 王通 2016/6/29 9:23:24 获取车辆线路上下行
  108 + *
  109 + * @return -1无效 0上行 1下行
  110 + */
  111 + public static int getUpOrDown(long serviceState) {
  112 + if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000
  113 + || (serviceState & 0x01000000) == 0x01000000 || (serviceState & 0x08000000) == 0x08000000)
  114 + return -1;
  115 + return (((serviceState & 0x10000000) == 0x10000000) ? 1 : 0);
  116 + }
  117 +
  118 + @Override
  119 + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
  120 + offlineSignalHandle = applicationContext.getBean(OfflineSignalHandle.class);
  121 + correctSignalHandle = applicationContext.getBean(CorrectSignalHandle.class);
  122 + stationInsideHandle = applicationContext.getBean(StationInsideHandle.class);
  123 + inOutStationSignalHandle = applicationContext.getBean(InOutStationSignalHandle.class);
  124 + reverseSignalHandle = applicationContext.getBean(ReverseSignalHandle.class);
  125 + }
  126 +
  127 + public static class GpsComp implements Comparator<GpsEntity>{
  128 +
  129 + @Override
  130 + public int compare(GpsEntity g1, GpsEntity g2) {
  131 + return g1.getTimestamp().compareTo(g2.getTimestamp());
  132 + }
  133 + }
  134 +
  135 + public static class RecoveryThread implements Runnable{
  136 + List<GpsEntity> list;
  137 + CountDownLatch count;
  138 +
  139 + RecoveryThread(List<GpsEntity> list, CountDownLatch count){
  140 + this.list = list;
  141 + this.count = count;
  142 + }
  143 + @Override
  144 + public void run() {
  145 + try {
  146 + //循环gps恢复数据
  147 + CircleQueue<GpsEntity> prevs;
  148 +
  149 + for(GpsEntity gps : list){
  150 + prevs = GeoCacheData.getGps(gps.getNbbm());
  151 + //掉线处理
  152 + offlineSignalHandle.handle(gps, prevs);
  153 + //状态处理
  154 + if(!correctSignalHandle.handle(gps, prevs))
  155 + continue;
  156 + //场,站内外判断
  157 + stationInsideHandle.handle(gps, prevs);
  158 + //反向处理
  159 + reverseSignalHandle.handle(gps, prevs);
  160 + //进出站动作处理
  161 + inOutStationSignalHandle.handle(gps, prevs);
  162 + GeoCacheData.putGps(gps);
  163 + }
  164 + }catch (Exception e){
  165 + logger.error("", e);
  166 + }
  167 + finally {
  168 + count.countDown();
  169 + }
  170 + }
  171 + }
  172 +}
0 \ No newline at end of file 173 \ No newline at end of file
src/main/java/com/bsth/data/pilot80/PilotReport.java
1 package com.bsth.data.pilot80; 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 import com.bsth.data.BasicData; 3 import com.bsth.data.BasicData;
13 import com.bsth.data.LineConfigData; 4 import com.bsth.data.LineConfigData;
14 import com.bsth.data.gpsdata.GpsEntity; 5 import com.bsth.data.gpsdata.GpsEntity;
@@ -23,6 +14,14 @@ import com.bsth.repository.directive.D80Repository; @@ -23,6 +14,14 @@ import com.bsth.repository.directive.D80Repository;
23 import com.bsth.service.directive.DirectiveService; 14 import com.bsth.service.directive.DirectiveService;
24 import com.bsth.websocket.handler.SendUtils; 15 import com.bsth.websocket.handler.SendUtils;
25 import com.google.common.collect.ArrayListMultimap; 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 *
@@ -180,7 +179,7 @@ public class PilotReport { @@ -180,7 +179,7 @@ public class PilotReport {
180 return; 179 return;
181 180
182 LineConfig conf = lineConfigData.get(sch.getXlBm()); 181 LineConfig conf = lineConfigData.get(sch.getXlBm());
183 - if(conf.getInConfig() == 1){ 182 + if(conf.getOutConfig() == 1){
184 //为相关班次写入进场时间 183 //为相关班次写入进场时间
185 sch.setZdsjActualAll(d80.getTimestamp()); 184 sch.setZdsjActualAll(d80.getTimestamp());
186 185
src/main/java/com/bsth/data/schedule/DayOfSchedule.java
@@ -3,9 +3,11 @@ package com.bsth.data.schedule; @@ -3,9 +3,11 @@ package com.bsth.data.schedule;
3 import com.alibaba.fastjson.JSON; 3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.JSONArray; 4 import com.alibaba.fastjson.JSONArray;
5 import com.bsth.Application; 5 import com.bsth.Application;
  6 +import com.bsth.data.BasicData;
6 import com.bsth.data.LineConfigData; 7 import com.bsth.data.LineConfigData;
7 import com.bsth.data.directive.FirstScheduleCheckThread; 8 import com.bsth.data.directive.FirstScheduleCheckThread;
8 import com.bsth.data.gpsdata.GpsRealData; 9 import com.bsth.data.gpsdata.GpsRealData;
  10 +import com.bsth.data.gpsdata.recovery.GpsDataRecovery;
9 import com.bsth.data.schedule.thread.ScheduleLateThread; 11 import com.bsth.data.schedule.thread.ScheduleLateThread;
10 import com.bsth.data.schedule.thread.SchedulePstThread; 12 import com.bsth.data.schedule.thread.SchedulePstThread;
11 import com.bsth.data.schedule.thread.ScheduleRefreshThread; 13 import com.bsth.data.schedule.thread.ScheduleRefreshThread;
@@ -35,484 +37,538 @@ import java.util.*; @@ -35,484 +37,538 @@ import java.util.*;
35 import java.util.concurrent.TimeUnit; 37 import java.util.concurrent.TimeUnit;
36 38
37 /** 39 /**
38 - * 40 + * @author PanZhao
39 * @ClassName: DayOfSchedule 41 * @ClassName: DayOfSchedule
40 * @Description: TODO(当日实际排班) 42 * @Description: TODO(当日实际排班)
41 - * @author PanZhao  
42 * @date 2016年8月15日 上午10:16:12 43 * @date 2016年8月15日 上午10:16:12
43 - *  
44 */ 44 */
45 @Component 45 @Component
46 public class DayOfSchedule implements CommandLineRunner { 46 public class DayOfSchedule implements CommandLineRunner {
47 47
48 - Logger logger = LoggerFactory.getLogger(this.getClass());  
49 -  
50 - // 按车辆分组的班次数据  
51 - private static ArrayListMultimap<String, ScheduleRealInfo> nbbmScheduleMap;  
52 -  
53 - // 班次主键映射  
54 - private static Map<Long, ScheduleRealInfo> id2SchedulMap;  
55 -  
56 - // 车辆和排班起终点站对照(包括进出的停车场,区间起终点)  
57 - private static TreeMultimap<String, String> nbbm2SEStationMap;  
58 -  
59 - //车辆 ——> 当前执行班次  
60 - private static Map<String, ScheduleRealInfo> carExecutePlanMap;  
61 -  
62 - // 持久化缓冲区  
63 - public static LinkedList<ScheduleRealInfo> pstBuffer;  
64 -  
65 - // 排序器  
66 - private static ScheduleComparator.FCSJ schFCSJComparator;  
67 -  
68 - @Autowired  
69 - LineConfigData lineConfigData;  
70 -  
71 - @Autowired  
72 - ScheduleRealInfoRepository schRepository;  
73 -  
74 - @Autowired  
75 - SchedulePlanInfoService schPlanService;  
76 -  
77 - @Autowired  
78 - SchAttrCalculator schAttrCalculator;  
79 -  
80 - @Autowired  
81 - SendUtils sendUtils;  
82 -  
83 - @Autowired  
84 - GpsRealData gpsRealData;  
85 -  
86 - /** 线路当前使用的排班的日期 */  
87 - public static Map<String, String> currSchDateMap;  
88 -  
89 - static {  
90 - nbbmScheduleMap = ArrayListMultimap.create();  
91 - id2SchedulMap = new HashMap<>();  
92 - pstBuffer = new LinkedList<>();  
93 - schFCSJComparator = new ScheduleComparator.FCSJ();  
94 - currSchDateMap = new HashMap<>();  
95 - nbbm2SEStationMap = TreeMultimap.create();  
96 - carExecutePlanMap = new HashMap<>();  
97 - }  
98 -  
99 - @Autowired  
100 - ScheduleRefreshThread scheduleRefreshThread;  
101 -  
102 - @Autowired  
103 - SchedulePstThread schedulePstThread;  
104 -  
105 - @Autowired  
106 - FirstScheduleCheckThread firstScheduleCheckThread;  
107 -  
108 - @Autowired  
109 - ScheduleLateThread scheduleLateThread;  
110 -  
111 - @Autowired  
112 - SubmitToTrafficManage submitToTrafficManage;  
113 -  
114 - private static DateTimeFormatter fmtyyyyMMdd = DateTimeFormat.forPattern("yyyy-MM-dd")  
115 - ,fmtHHmm = DateTimeFormat.forPattern("HH:mm");  
116 -  
117 - @Override  
118 - public void run(String... arg0) throws Exception {  
119 - //翻班线程  
120 - Application.mainServices.scheduleWithFixedDelay(scheduleRefreshThread, 15, 240, TimeUnit.SECONDS);  
121 - //入库  
122 -// Application.mainServices.scheduleWithFixedDelay(schedulePstThread, 60, 60, TimeUnit.SECONDS);  
123 - //首班出场指令补发器  
124 -// Application.mainServices.scheduleWithFixedDelay(firstScheduleCheckThread, 30, 240, TimeUnit.SECONDS);  
125 - //班次误点扫描  
126 -// Application.mainServices.scheduleWithFixedDelay(scheduleLateThread, 60, 60, TimeUnit.SECONDS);  
127 -  
128 - //每天凌晨2点20提交数据到运管处  
129 - long diff = (DateUtils.getTimestamp() + 1000*60*140) - System.currentTimeMillis();  
130 - if(diff < 0)  
131 - diff+=(1000*60*60*24);  
132 -  
133 - logger.info(diff/1000/60 + "分钟之后提交到运管处");  
134 - //Application.mainServices.scheduleWithFixedDelay(submitToTrafficManage, diff / 1000, 60 * 60 * 24, TimeUnit.SECONDS);  
135 - }  
136 -  
137 - public Map<String, String> getCurrSchDate() {  
138 - return currSchDateMap;  
139 - }  
140 -  
141 - /**  
142 - *  
143 - * @Title: calcSchDateB  
144 - * @Description: TODO(计算线路当前应该使用的排班日期)  
145 - */  
146 - public String calcSchDate(String lineCode) {  
147 - LineConfig conf = lineConfigData.get(lineCode);  
148 - long ct = System.currentTimeMillis();  
149 -  
150 - String schDate = fmtyyyyMMdd.print(ct);  
151 - // 小于当天起始运营时间,则取前一天的排班  
152 - if (ct < conf.getCurrStartTime())  
153 - schDate = DateUtils.subtractDay(schDate, 1);  
154 -  
155 - return schDate;  
156 - }  
157 -  
158 - /**  
159 - * @Title: reloadSch  
160 - * @Title: reloadSch  
161 - * @Description: TODO(重新载入排班)  
162 - * @param @param  
163 - * lineCode 线路编码  
164 - * @param @param  
165 - * schDate 班次日期 yyyy-MM-dd  
166 - * @param @param  
167 - * forcePlan 强制从计划调度重新抓取  
168 - */  
169 - public int reloadSch(String lineCode, String schDate, boolean forcePlan) {  
170 - try {  
171 - List<ScheduleRealInfo> list;  
172 -  
173 - if (forcePlan)  
174 - removeRealSch(lineCode, schDate);  
175 - else  
176 - clearRAMData(lineCode);  
177 -  
178 - if (existRealSch(lineCode, schDate))  
179 - list = loadRealSch(lineCode, schDate);// 从实际排班表加载  
180 - else {  
181 - list = loadPlanSch(lineCode, schDate);// 从计划排班表加载  
182 - // 写入数据库  
183 - batchSave(list);  
184 - }  
185 -  
186 - //更新线路和班次日期对照  
187 - currSchDateMap.put(lineCode, schDate);  
188 - //添加到缓存  
189 - putAll(list);  
190 -  
191 - Set<String> cars = searchAllCars(list);  
192 - //计算“起点站应到”时间  
193 - for(String nbbm : cars)  
194 - schAttrCalculator.calcQdzTimePlan(nbbmScheduleMap.get(nbbm));  
195 -  
196 - //是否是出站即出场  
197 - LineConfig conf = lineConfigData.get(lineCode);  
198 - if(conf.getOutConfig() == 2){  
199 - for(String nbbm : cars)  
200 - schAttrCalculator.connectOutSchedule(nbbmScheduleMap.get(nbbm));  
201 - }  
202 -  
203 - // 页面 翻班通知  
204 - sendUtils.shiftSchedule(lineCode);  
205 - } catch (Exception e) {  
206 - logger.error("", e);  
207 - return -1;  
208 - } 48 + Logger logger = LoggerFactory.getLogger(this.getClass());
209 49
210 - return 0;  
211 - }  
212 -  
213 - /**  
214 - *  
215 - * @Title: searchAllCars  
216 - * @Description: TODO(搜索班次集合中的车辆)  
217 - */  
218 - private Set<String> searchAllCars(List<ScheduleRealInfo> list) {  
219 - Set<String> cars = new HashSet<>();  
220 - for(ScheduleRealInfo sch : list)  
221 - cars.add(sch.getClZbh());  
222 -  
223 - return cars;  
224 - }  
225 -  
226 - private void putAll(List<ScheduleRealInfo> list) {  
227 - for (ScheduleRealInfo sch : list)  
228 - put(sch);  
229 - }  
230 -  
231 - /**  
232 - * @Title: removeRealSch  
233 - * @Description: TODO(清除实际排班,包括数据库和内存数据)  
234 - * @param @param  
235 - * lineCode 线路编码  
236 - * @param @param  
237 - * schDate 班次日期 yyyy-MM-dd  
238 - */  
239 - public void removeRealSch(String lineCode, String schDate) throws Exception {  
240 - try {  
241 - // 清理数据库数据  
242 - schRepository.deleteByLineCodeAndDate(lineCode + "", schDate);  
243 -  
244 - // 清理内存数据  
245 - clearRAMData(lineCode + "");  
246 - } catch (Exception e) {  
247 - logger.error("removeRealSch error, " + lineCode + " -" + schDate, e);  
248 - throw e;  
249 - }  
250 - }  
251 -  
252 - /**  
253 - *  
254 - * @Title: clearRAMData  
255 - * @Description: TODO(清理内存数据)  
256 - */  
257 - public void clearRAMData(String lineCode) {  
258 - int count = 0;  
259 - List<ScheduleRealInfo> remList = new ArrayList<>();  
260 - Collection<ScheduleRealInfo> schs = nbbmScheduleMap.values();  
261 - for (ScheduleRealInfo sch : schs) {  
262 - if (sch.getXlBm().equals(lineCode))  
263 - remList.add(sch);  
264 - }  
265 -  
266 - for(ScheduleRealInfo sch : remList){  
267 - if(null != sch){  
268 - nbbmScheduleMap.remove(sch.getClZbh(), sch);  
269 - id2SchedulMap.remove(sch.getId());  
270 - count ++;  
271 - }  
272 - }  
273 -  
274 - logger.info(lineCode + "排班清理 " + count);  
275 - }  
276 -  
277 - /**  
278 - * @Title: existRealSch  
279 - * @Description: TODO(实际排班是否已存在)  
280 - */  
281 - public boolean existRealSch(String lineCode, String schDate) {  
282 - int count = schRepository.countByLineCodeAndDate(lineCode, schDate);  
283 - return count > 0;  
284 - }  
285 -  
286 - /**  
287 - * @Title: loadRealSch  
288 - * @Description: TODO(从实际排班表加载数据)  
289 - */  
290 - public List<ScheduleRealInfo> loadRealSch(String lineCode, String schDate) {  
291 - return schRepository.findByLineCodeAndDate(lineCode, schDate);  
292 - }  
293 -  
294 - /**  
295 - * @Title: loadPlanSch  
296 - * @Description: TODO(从计划排班表加载数据)  
297 - */  
298 - public List<ScheduleRealInfo> loadPlanSch(String lineCode, String schDate) {  
299 - logger.info("从计划排班表恢复排班,lineCode: " + lineCode + ", schDate: " + schDate);  
300 - List<ScheduleRealInfo> realList = new ArrayList<>();  
301 -  
302 - try {  
303 - Map<String, Object> data = new HashMap<>();  
304 -  
305 - data.put("scheduleDate_eq", fmtyyyyMMdd.parseDateTime(schDate).toDate());  
306 - data.put("xlBm_eq", lineCode);  
307 -  
308 - // 查询计划排班  
309 - List<SchedulePlanInfo> planItr = cleanSchPlanItr(schPlanService.list(data).iterator());  
310 -  
311 - // 转换为实际排班  
312 - realList = JSONArray.parseArray(JSON.toJSONString(planItr), ScheduleRealInfo.class);  
313 -  
314 - SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");  
315 - String fcsj;  
316 - for (ScheduleRealInfo sch : realList) {  
317 - sch.setScheduleDateStr(fmtyyyyMMdd.print(sch.getScheduleDate().getTime()));  
318 - sch.setRealExecDate(sch.getScheduleDateStr());  
319 -  
320 - if(StringUtils.isEmpty(sch.getFcsj()))  
321 - sch.setFcsj("00:00");  
322 -  
323 - fcsj=sch.getFcsj().trim();  
324 - //处理一下发车时间格式没有:号的问题  
325 - if(fcsj.indexOf(":") == -1 && fcsj.length() >= 4){  
326 - sch.setFcsj(fcsj.substring(0, 2) + ":" + fcsj.substring(2, 4));  
327 - }  
328 -  
329 - try {  
330 - sdf.parse(sch.getFcsj());  
331 - } catch (ParseException e) {  
332 - //发车时间仍然校验不过的,直接写成00:00  
333 - sch.setFcsj("00:00");  
334 - }  
335 - sch.setDfsj(sch.getFcsj());  
336 -  
337 - // 计划终点时间  
338 - if (sch.getBcsj() != null) {  
339 - sch.setZdsj(fmtHHmm.print(fmtHHmm.parseMillis(sch.getFcsj()) + (sch.getBcsj() * 60 * 1000)));  
340 - sch.setLate(false);  
341 - }  
342 - //计划里程为0,设置NULL  
343 - if(sch.getJhlc() != null && sch.getJhlc() == 0)  
344 - sch.setJhlc(null);  
345 - }  
346 - } catch (Exception e) {  
347 - logger.error("", e);  
348 - }  
349 - return realList;  
350 - }  
351 -  
352 - /**  
353 - * @Title: batchSave  
354 - * @Description: TODO(批量入库)  
355 - */  
356 - private void batchSave(List<ScheduleRealInfo> list) {  
357 - // 查询数据库最大ID  
358 - Long id = schRepository.getMaxId();  
359 - if (null == id)  
360 - id = 0L;  
361 - id++;  
362 -  
363 - SimpleDateFormat sdfyyyyMMdd = new SimpleDateFormat("yyyy-MM-dd");  
364 - for (ScheduleRealInfo item : list) {  
365 - item.setSpId(item.getId());// 保留原始的计划ID  
366 - item.setId(id++);// 设置ID  
367 - item.setScheduleDateStr(sdfyyyyMMdd.format(item.getScheduleDate()));  
368 - } 50 + // 按车辆分组的班次数据
  51 + private static ArrayListMultimap<String, ScheduleRealInfo> nbbmScheduleMap;
369 52
370 - // 入库  
371 - new BatchSaveUtils<ScheduleRealInfo>().saveList(list, ScheduleRealInfo.class);  
372 - } 53 + // 班次主键映射
  54 + private static Map<Long, ScheduleRealInfo> id2SchedulMap;
373 55
374 - private List<SchedulePlanInfo> cleanSchPlanItr(Iterator<SchedulePlanInfo> itrab) {  
375 - List<SchedulePlanInfo> list = new ArrayList<>(); 56 + // 车辆和排班起终点站对照(包括进出的停车场,区间起终点)
  57 + private static TreeMultimap<String, String> nbbm2SEStationMap;
376 58
377 - SchedulePlanInfo sp;  
378 - while (itrab.hasNext()) {  
379 - sp = itrab.next();  
380 - sp.setSchedulePlan(null);  
381 - list.add(sp);  
382 - }  
383 - return list;  
384 - }  
385 -  
386 - /**  
387 - *  
388 - * @Title: findByLineCode  
389 - * @Description: TODO(lineCode 获取班次)  
390 - */  
391 - public List<ScheduleRealInfo> findByLineCode(String lineCode) {  
392 - List<ScheduleRealInfo> rs = new ArrayList<>(); 59 + //车辆 ——> 当前执行班次
  60 + private static Map<String, ScheduleRealInfo> carExecutePlanMap;
393 61
394 - Collection<ScheduleRealInfo> schs = nbbmScheduleMap.values();  
395 - for (ScheduleRealInfo sch : schs) {  
396 - if (sch.getXlBm().equals(lineCode))  
397 - rs.add(sch);  
398 - }  
399 - return rs;  
400 - }  
401 -  
402 - /**  
403 - *  
404 - * @Title: findCarByLineCode  
405 - * @Description: TODO(线路下运营的车辆)  
406 - */  
407 - public Set<String> findCarByLineCode(String lineCode){  
408 - Set<String> rs = new HashSet<>();  
409 -  
410 - Collection<ScheduleRealInfo> schs = nbbmScheduleMap.values();  
411 - for (ScheduleRealInfo sch : schs) {  
412 - if (sch.getXlBm().equals(lineCode))  
413 - rs.add(sch.getClZbh());  
414 - }  
415 -  
416 - return rs;  
417 - }  
418 -  
419 - public List<ScheduleRealInfo> findByNbbm(String nbbm) {  
420 - return nbbmScheduleMap.get(nbbm);  
421 - }  
422 -  
423 - /**  
424 - *  
425 - * @Title: findByLineAndUpDown  
426 - * @Description: TODO(lineCode 和走向获取班次)  
427 - */  
428 - public List<ScheduleRealInfo> findByLineAndUpDown(String lineCode, Integer upDown) {  
429 - List<ScheduleRealInfo> list = findByLineCode(lineCode), rs = new ArrayList<>();  
430 -  
431 - for (ScheduleRealInfo sch : list) {  
432 - if (sch.getXlDir().equals(upDown + ""))  
433 - rs.add(sch);  
434 - }  
435 - return rs;  
436 - } 62 + // 持久化缓冲区
  63 + public static LinkedList<ScheduleRealInfo> pstBuffer;
437 64
438 - public ScheduleRealInfo get(long id) {  
439 - return id2SchedulMap.get(id);  
440 - } 65 + // 排序器
  66 + private static ScheduleComparator.FCSJ schFCSJComparator;
441 67
442 - public Set<String> getSEStationList(String nbbm) {  
443 - return nbbm2SEStationMap.get(nbbm);  
444 - } 68 + @Autowired
  69 + LineConfigData lineConfigData;
445 70
446 - /**  
447 - *  
448 - * @Title: next  
449 - * @Description: TODO(下一个班次)  
450 - */  
451 - public ScheduleRealInfo next(ScheduleRealInfo sch) { 71 + @Autowired
  72 + ScheduleRealInfoRepository schRepository;
  73 +
  74 + @Autowired
  75 + SchedulePlanInfoService schPlanService;
  76 +
  77 + @Autowired
  78 + SchAttrCalculator schAttrCalculator;
  79 +
  80 + @Autowired
  81 + SendUtils sendUtils;
  82 +
  83 + @Autowired
  84 + GpsRealData gpsRealData;
  85 +
  86 + /**
  87 + * 线路当前使用的排班的日期
  88 + */
  89 + public static Map<String, String> currSchDateMap;
  90 +
  91 + static {
  92 + nbbmScheduleMap = ArrayListMultimap.create();
  93 + id2SchedulMap = new HashMap<>();
  94 + pstBuffer = new LinkedList<>();
  95 + schFCSJComparator = new ScheduleComparator.FCSJ();
  96 + currSchDateMap = new HashMap<>();
  97 + nbbm2SEStationMap = TreeMultimap.create();
  98 + carExecutePlanMap = new HashMap<>();
  99 + }
  100 +
  101 + @Autowired
  102 + ScheduleRefreshThread scheduleRefreshThread;
  103 +
  104 + @Autowired
  105 + SchedulePstThread schedulePstThread;
  106 +
  107 + @Autowired
  108 + FirstScheduleCheckThread firstScheduleCheckThread;
  109 +
  110 + @Autowired
  111 + ScheduleLateThread scheduleLateThread;
  112 +
  113 + @Autowired
  114 + SubmitToTrafficManage submitToTrafficManage;
  115 +
  116 + @Autowired
  117 + LineConfigData lineConfigs;
  118 +
  119 + @Autowired
  120 + BasicData.BasicDataLoader dataLoader;
  121 +
  122 + @Autowired
  123 + GpsDataRecovery gpsDataRecovery;
  124 +
  125 + private static DateTimeFormatter fmtyyyyMMdd = DateTimeFormat.forPattern("yyyy-MM-dd"), fmtHHmm = DateTimeFormat.forPattern("HH:mm");
  126 +
  127 + @Override
  128 + public void run(String... arg0) throws Exception {
  129 + //加载基础数据
  130 + dataLoader.loadAllData();
  131 + //从数据库恢复排班
  132 + dataRecovery();
  133 +
  134 + //翻班线程
  135 +// Application.mainServices.scheduleWithFixedDelay(scheduleRefreshThread, 15, 240, TimeUnit.SECONDS);
  136 + //入库
  137 +// Application.mainServices.scheduleWithFixedDelay(schedulePstThread, 60, 60, TimeUnit.SECONDS);
  138 + //首班出场指令补发器
  139 +// Application.mainServices.scheduleWithFixedDelay(firstScheduleCheckThread, 30, 240, TimeUnit.SECONDS);
  140 + //班次误点扫描
  141 + Application.mainServices.scheduleWithFixedDelay(scheduleLateThread, 60, 60, TimeUnit.SECONDS);
  142 +
  143 + //每天凌晨2点20提交数据到运管处
  144 + long diff = (DateUtils.getTimestamp() + 1000 * 60 * 140) - System.currentTimeMillis();
  145 + if (diff < 0)
  146 + diff += (1000 * 60 * 60 * 24);
  147 +
  148 + logger.info(diff / 1000 / 60 + "分钟之后提交到运管处");
  149 + //Application.mainServices.scheduleWithFixedDelay(submitToTrafficManage, diff / 1000, 60 * 60 * 24, TimeUnit.SECONDS);
  150 + }
  151 +
  152 + //数据恢复
  153 + private void dataRecovery() {
  154 + GpsDataRecovery.run = true;
  155 +
  156 + Collection<LineConfig> confs = lineConfigs.getAll();
  157 + String lineCode, currSchDate;
  158 + for (LineConfig conf : confs) {
  159 + lineCode = conf.getLine().getLineCode();
  160 + currSchDate = calcSchDate(lineCode);
  161 + //加载班次数据
  162 + reloadSch(lineCode, currSchDate, false);
  163 + }
  164 +
  165 + //恢复gps数据
  166 + gpsDataRecovery.recovery();
  167 + }
  168 +
  169 + public Map<String, String> getCurrSchDate() {
  170 + return currSchDateMap;
  171 + }
  172 +
  173 + /**
  174 + * @Title: calcSchDateB
  175 + * @Description: TODO(计算线路当前应该使用的排班日期)
  176 + */
  177 + public String calcSchDate(String lineCode) {
  178 + LineConfig conf = lineConfigData.get(lineCode);
  179 + long ct = System.currentTimeMillis();
  180 +
  181 + String schDate = fmtyyyyMMdd.print(ct);
  182 + // 小于当天起始运营时间,则取前一天的排班
  183 + if (ct < conf.getCurrStartTime())
  184 + schDate = DateUtils.subtractDay(schDate, 1);
  185 +
  186 + return schDate;
  187 + }
  188 +
  189 + /**
  190 + * @param @param lineCode 线路编码
  191 + * @param @param schDate 班次日期 yyyy-MM-dd
  192 + * @param @param forcePlan 强制从计划调度重新抓取
  193 + * @Title: reloadSch
  194 + * @Title: reloadSch
  195 + * @Description: TODO(重新载入排班)
  196 + */
  197 + public int reloadSch(String lineCode, String schDate, boolean forcePlan) {
  198 + try {
  199 + List<ScheduleRealInfo> list;
  200 +
  201 + if (forcePlan)
  202 + removeRealSch(lineCode, schDate);
  203 + else
  204 + clearRAMData(lineCode);
  205 +
  206 + if (existRealSch(lineCode, schDate))
  207 + list = loadRealSch(lineCode, schDate);// 从实际排班表加载
  208 + else {
  209 + list = loadPlanSch(lineCode, schDate);// 从计划排班表加载
  210 + // 写入数据库
  211 + batchSave(list);
  212 + }
  213 +
  214 + //更新线路和班次日期对照
  215 + currSchDateMap.put(lineCode, schDate);
  216 + //添加到缓存
  217 + putAll(list);
  218 +
  219 + Set<String> cars = searchAllCars(list);
  220 + for (String nbbm : cars) {
  221 + //计算“起点站应到”时间
  222 + schAttrCalculator.calcQdzTimePlan(nbbmScheduleMap.get(nbbm));
  223 + //车辆 ——> 要执行的班次对照
  224 + reCalcExecPlan(nbbm);
  225 + }
  226 +
  227 + //是否是出站即出场
  228 + LineConfig conf = lineConfigData.get(lineCode);
  229 + if (conf.getOutConfig() == 2) {
  230 + for (String nbbm : cars)
  231 + schAttrCalculator.connectOutSchedule(nbbmScheduleMap.get(nbbm));
  232 + }
  233 +
  234 + // 页面 翻班通知
  235 + sendUtils.shiftSchedule(lineCode);
  236 + } catch (Exception e) {
  237 + logger.error("", e);
  238 + return -1;
  239 + }
  240 +
  241 + return 0;
  242 + }
  243 +
  244 + /**
  245 + * @Title: searchAllCars
  246 + * @Description: TODO(搜索班次集合中的车辆)
  247 + */
  248 + private Set<String> searchAllCars(List<ScheduleRealInfo> list) {
  249 + Set<String> cars = new HashSet<>();
  250 + for (ScheduleRealInfo sch : list)
  251 + cars.add(sch.getClZbh());
  252 +
  253 + return cars;
  254 + }
  255 +
  256 + private void putAll(List<ScheduleRealInfo> list) {
  257 + for (ScheduleRealInfo sch : list)
  258 + put(sch);
  259 + }
  260 +
  261 + /**
  262 + * @param @param lineCode 线路编码
  263 + * @param @param schDate 班次日期 yyyy-MM-dd
  264 + * @Title: removeRealSch
  265 + * @Description: TODO(清除实际排班,包括数据库和内存数据)
  266 + */
  267 + public void removeRealSch(String lineCode, String schDate) throws Exception {
  268 + try {
  269 + // 清理数据库数据
  270 + schRepository.deleteByLineCodeAndDate(lineCode + "", schDate);
  271 +
  272 + // 清理内存数据
  273 + clearRAMData(lineCode + "");
  274 + } catch (Exception e) {
  275 + logger.error("removeRealSch error, " + lineCode + " -" + schDate, e);
  276 + throw e;
  277 + }
  278 + }
  279 +
  280 + /**
  281 + * @Title: clearRAMData
  282 + * @Description: TODO(清理内存数据)
  283 + */
  284 + public void clearRAMData(String lineCode) {
  285 + int count = 0;
  286 + List<ScheduleRealInfo> remList = new ArrayList<>();
  287 + Collection<ScheduleRealInfo> schs = nbbmScheduleMap.values();
  288 + for (ScheduleRealInfo sch : schs) {
  289 + if (sch.getXlBm().equals(lineCode))
  290 + remList.add(sch);
  291 + }
  292 +
  293 + for (ScheduleRealInfo sch : remList) {
  294 + if (null != sch) {
  295 + nbbmScheduleMap.remove(sch.getClZbh(), sch);
  296 + id2SchedulMap.remove(sch.getId());
  297 + count++;
  298 + }
  299 + }
  300 +
  301 + logger.info(lineCode + "排班清理 " + count);
  302 + }
  303 +
  304 + /**
  305 + * @Title: existRealSch
  306 + * @Description: TODO(实际排班是否已存在)
  307 + */
  308 + public boolean existRealSch(String lineCode, String schDate) {
  309 + int count = schRepository.countByLineCodeAndDate(lineCode, schDate);
  310 + return count > 0;
  311 + }
  312 +
  313 + /**
  314 + * @Title: loadRealSch
  315 + * @Description: TODO(从实际排班表加载数据)
  316 + */
  317 + public List<ScheduleRealInfo> loadRealSch(String lineCode, String schDate) {
  318 + return schRepository.findByLineCodeAndDate(lineCode, schDate);
  319 + }
  320 +
  321 + /**
  322 + * @Title: loadPlanSch
  323 + * @Description: TODO(从计划排班表加载数据)
  324 + */
  325 + public List<ScheduleRealInfo> loadPlanSch(String lineCode, String schDate) {
  326 + logger.info("从计划排班表恢复排班,lineCode: " + lineCode + ", schDate: " + schDate);
  327 + List<ScheduleRealInfo> realList = new ArrayList<>();
  328 +
  329 + try {
  330 + Map<String, Object> data = new HashMap<>();
  331 +
  332 + data.put("scheduleDate_eq", fmtyyyyMMdd.parseDateTime(schDate).toDate());
  333 + data.put("xlBm_eq", lineCode);
  334 +
  335 + // 查询计划排班
  336 + List<SchedulePlanInfo> planItr = cleanSchPlanItr(schPlanService.list(data).iterator());
  337 +
  338 + // 转换为实际排班
  339 + realList = JSONArray.parseArray(JSON.toJSONString(planItr), ScheduleRealInfo.class);
  340 +
  341 + SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
  342 + String fcsj;
  343 + for (ScheduleRealInfo sch : realList) {
  344 + sch.setScheduleDateStr(fmtyyyyMMdd.print(sch.getScheduleDate().getTime()));
  345 + sch.setRealExecDate(sch.getScheduleDateStr());
  346 +
  347 + if (StringUtils.isEmpty(sch.getFcsj()))
  348 + sch.setFcsj("00:00");
  349 +
  350 + fcsj = sch.getFcsj().trim();
  351 + //处理一下发车时间格式没有:号的问题
  352 + if (fcsj.indexOf(":") == -1 && fcsj.length() >= 4) {
  353 + sch.setFcsj(fcsj.substring(0, 2) + ":" + fcsj.substring(2, 4));
  354 + }
  355 +
  356 + try {
  357 + sdf.parse(sch.getFcsj());
  358 + } catch (ParseException e) {
  359 + //发车时间仍然校验不过的,直接写成00:00
  360 + sch.setFcsj("00:00");
  361 + }
  362 + sch.setDfsj(sch.getFcsj());
  363 +
  364 + // 计划终点时间
  365 + if (sch.getBcsj() != null) {
  366 + sch.setZdsj(fmtHHmm.print(fmtHHmm.parseMillis(sch.getFcsj()) + (sch.getBcsj() * 60 * 1000)));
  367 + sch.setLate(false);
  368 + }
  369 + //计划里程为0,设置NULL
  370 + if (sch.getJhlc() != null && sch.getJhlc() == 0)
  371 + sch.setJhlc(null);
  372 + }
  373 + } catch (Exception e) {
  374 + logger.error("", e);
  375 + }
  376 + return realList;
  377 + }
  378 +
  379 + /**
  380 + * @Title: batchSave
  381 + * @Description: TODO(批量入库)
  382 + */
  383 + private void batchSave(List<ScheduleRealInfo> list) {
  384 + // 查询数据库最大ID
  385 + Long id = schRepository.getMaxId();
  386 + if (null == id)
  387 + id = 0L;
  388 + id++;
  389 +
  390 + SimpleDateFormat sdfyyyyMMdd = new SimpleDateFormat("yyyy-MM-dd");
  391 + for (ScheduleRealInfo item : list) {
  392 + item.setSpId(item.getId());// 保留原始的计划ID
  393 + item.setId(id++);// 设置ID
  394 + item.setScheduleDateStr(sdfyyyyMMdd.format(item.getScheduleDate()));
  395 + }
  396 +
  397 + // 入库
  398 + new BatchSaveUtils<ScheduleRealInfo>().saveList(list, ScheduleRealInfo.class);
  399 + }
  400 +
  401 + private List<SchedulePlanInfo> cleanSchPlanItr(Iterator<SchedulePlanInfo> itrab) {
  402 + List<SchedulePlanInfo> list = new ArrayList<>();
  403 +
  404 + SchedulePlanInfo sp;
  405 + while (itrab.hasNext()) {
  406 + sp = itrab.next();
  407 + sp.setSchedulePlan(null);
  408 + list.add(sp);
  409 + }
  410 + return list;
  411 + }
  412 +
  413 + /**
  414 + * @Title: findByLineCode
  415 + * @Description: TODO(lineCode 获取班次)
  416 + */
  417 + public List<ScheduleRealInfo> findByLineCode(String lineCode) {
  418 + List<ScheduleRealInfo> rs = new ArrayList<>();
  419 +
  420 + Collection<ScheduleRealInfo> schs = nbbmScheduleMap.values();
  421 + for (ScheduleRealInfo sch : schs) {
  422 + if (sch.getXlBm().equals(lineCode))
  423 + rs.add(sch);
  424 + }
  425 + return rs;
  426 + }
  427 +
  428 + /**
  429 + * @Title: findCarByLineCode
  430 + * @Description: TODO(线路下运营的车辆)
  431 + */
  432 + public Set<String> findCarByLineCode(String lineCode) {
  433 + Set<String> rs = new HashSet<>();
  434 +
  435 + Collection<ScheduleRealInfo> schs = nbbmScheduleMap.values();
  436 + for (ScheduleRealInfo sch : schs) {
  437 + if (sch.getXlBm().equals(lineCode))
  438 + rs.add(sch.getClZbh());
  439 + }
  440 +
  441 + return rs;
  442 + }
  443 +
  444 + public List<ScheduleRealInfo> findByNbbm(String nbbm) {
  445 + return nbbmScheduleMap.get(nbbm);
  446 + }
  447 +
  448 + /**
  449 + * @Title: findByLineAndUpDown
  450 + * @Description: TODO(lineCode 和走向获取班次)
  451 + */
  452 + public List<ScheduleRealInfo> findByLineAndUpDown(String lineCode, Integer upDown) {
  453 + List<ScheduleRealInfo> list = findByLineCode(lineCode), rs = new ArrayList<>();
  454 +
  455 + for (ScheduleRealInfo sch : list) {
  456 + if (sch.getXlDir().equals(upDown + ""))
  457 + rs.add(sch);
  458 + }
  459 + return rs;
  460 + }
  461 +
  462 + public ScheduleRealInfo get(long id) {
  463 + return id2SchedulMap.get(id);
  464 + }
  465 +
  466 + public Set<String> getSEStationList(String nbbm) {
  467 + return nbbm2SEStationMap.get(nbbm);
  468 + }
  469 +
  470 + /**
  471 + * @Title: next
  472 + * @Description: TODO(下一个班次)
  473 + */
  474 + public ScheduleRealInfo next(ScheduleRealInfo sch) {
  475 +
  476 + List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());
  477 + int outConfig = -1;
  478 + LineConfig config = lineConfigData.get(sch.getXlBm());
  479 + if (config != null)
  480 + outConfig = config.getOutConfig();
  481 +
  482 + boolean flag = false;
  483 + ScheduleRealInfo next = null;
  484 + for (ScheduleRealInfo temp : list) {
  485 + if (temp.getId() == sch.getId()) {
  486 + flag = true;
  487 + continue;
  488 + }
  489 + //忽略烂班
  490 + if (temp.isDestroy())
  491 + continue;
  492 +
  493 + //出站既出场,忽略出场班次
  494 + if (outConfig == 2 && temp.getBcType().equals("out"))
  495 + continue;
  496 +
  497 + if (flag) {
  498 + next = temp;
  499 + break;
  500 + }
  501 + }
  502 + return next;
  503 + }
  504 +
  505 + /**
  506 + * 上一个班次
  507 + *
  508 + * @param sch
  509 + * @return
  510 + */
  511 + public ScheduleRealInfo prev(ScheduleRealInfo sch) {
  512 + List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());
  513 +
  514 + //boolean flag = false;
  515 + ScheduleRealInfo prev = null;
  516 + int size = list.size();
  517 +
  518 + for (int i = 0; i < size; i++) {
  519 + if (list.get(i).isDestroy())
  520 + continue;
  521 +
  522 + if (list.get(i).getId().equals(sch.getId())) {
  523 + return prev;
  524 + }
  525 + prev = list.get(i);
  526 + }
  527 + return prev;
  528 + }
  529 +
  530 + public void put(ScheduleRealInfo sch) {
  531 + schAttrCalculator
  532 + .calcRealDate(sch)
  533 + .calcAllTimeByFcsj(sch);
  534 +
  535 + String nbbm = sch.getClZbh();
  536 + nbbmScheduleMap.put(nbbm, sch);
  537 + nbbm2SEStationMap.put(nbbm, sch.getQdzCode());
  538 + nbbm2SEStationMap.put(nbbm, sch.getZdzCode());
  539 +
  540 + //主键索引
  541 + id2SchedulMap.put(sch.getId(), sch);
  542 + //跨24点的,再save一次
  543 + if (!sch.getRealExecDate().equals(sch.getScheduleDateStr()))
  544 + save(sch);
  545 + }
  546 +
  547 + public void delete(ScheduleRealInfo sch) {
  548 + //ScheduleRealInfo sch = id2SchedulMap.get(id);
  549 + if (!sch.isSflj())
  550 + return;
  551 +
  552 + nbbmScheduleMap.remove(sch.getClZbh(), sch);
  553 + id2SchedulMap.remove(sch.getId());
  554 + //return sch;
  555 + }
452 556
453 - List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());  
454 -  
455 - boolean flag = false;  
456 - ScheduleRealInfo next = null;  
457 - for(ScheduleRealInfo temp : list){  
458 - if(temp.getId() == sch.getId()){  
459 - flag = true;  
460 - continue;  
461 - }  
462 - //忽略烂班  
463 - if(temp.isDestroy())  
464 - continue;  
465 -  
466 - if(flag){  
467 - next = temp;  
468 - break;  
469 - }  
470 - }  
471 - return next;  
472 - }  
473 -  
474 - public void put(ScheduleRealInfo sch) {  
475 - schAttrCalculator  
476 - .calcRealDate(sch)  
477 - .calcAllTimeByFcsj(sch);  
478 -  
479 - String nbbm = sch.getClZbh();  
480 - nbbmScheduleMap.put(nbbm, sch);  
481 - nbbm2SEStationMap.put(nbbm, sch.getQdzCode());  
482 - nbbm2SEStationMap.put(nbbm, sch.getZdzCode());  
483 -  
484 - //主键索引  
485 - id2SchedulMap.put(sch.getId(), sch);  
486 - //跨24点的,再save一次  
487 - if(!sch.getRealExecDate().equals(sch.getScheduleDateStr()))  
488 - save(sch);  
489 - }  
490 -  
491 - public void delete(ScheduleRealInfo sch) {  
492 - //ScheduleRealInfo sch = id2SchedulMap.get(id);  
493 - if(!sch.isSflj())  
494 - return;  
495 -  
496 - nbbmScheduleMap.remove(sch.getClZbh(), sch);  
497 - id2SchedulMap.remove(sch.getId());  
498 - //return sch;  
499 - }  
500 -  
501 // public void calcQdzTimePlan(String nbbm){ 557 // public void calcQdzTimePlan(String nbbm){
502 // schAttrCalculator.calcQdzTimePlan(nbbmScheduleMap.get(nbbm)); 558 // schAttrCalculator.calcQdzTimePlan(nbbmScheduleMap.get(nbbm));
503 // } 559 // }
504 -  
505 - public List<ScheduleRealInfo> updateQdzTimePlan(String nbbm){  
506 - return schAttrCalculator.updateQdzTimePlan(nbbmScheduleMap.get(nbbm));  
507 - }  
508 -  
509 - /**  
510 - *  
511 - * @Title: nextAll  
512 - * @Description: TODO(之后的所有班次)  
513 - */ 560 +
  561 + public List<ScheduleRealInfo> updateQdzTimePlan(String nbbm) {
  562 + return schAttrCalculator.updateQdzTimePlan(nbbmScheduleMap.get(nbbm));
  563 + }
  564 +
  565 + /**
  566 + *
  567 + * @Title: nextAll
  568 + * @Description: TODO(之后的所有班次)
  569 + */
514 /* public List<ScheduleRealInfo> nextAll(ScheduleRealInfo sch) { 570 /* public List<ScheduleRealInfo> nextAll(ScheduleRealInfo sch) {
515 - List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh()); 571 + List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());
516 // 排序 572 // 排序
517 Collections.sort(list, schFCSJComparator); 573 Collections.sort(list, schFCSJComparator);
518 574
@@ -527,181 +583,229 @@ public class DayOfSchedule implements CommandLineRunner { @@ -527,181 +583,229 @@ public class DayOfSchedule implements CommandLineRunner {
527 return rs; 583 return rs;
528 }*/ 584 }*/
529 585
530 - /**  
531 - *  
532 - * @Title: doneSum  
533 - * @Description: TODO(已完成班次总数)  
534 - */  
535 - public int doneSum(String clZbh) {  
536 - List<ScheduleRealInfo> list = nbbmScheduleMap.get(clZbh);  
537 - int rs = 0;  
538 -  
539 - for(ScheduleRealInfo sch : list){  
540 - if(sch.getStatus() == 2 && !sch.isDestroy())  
541 - rs ++;  
542 - }  
543 - return rs;  
544 - }  
545 -  
546 - /**  
547 - *  
548 - * @Title: prveNotExecNum  
549 - * @Description: TODO(班次之前未执行班次数量)  
550 - */  
551 - public int prveNotExecNum(ScheduleRealInfo sch){  
552 - int n = 0;  
553 - List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());  
554 - for(ScheduleRealInfo s : list){  
555 - if(s.getFcsjActual() == null && !s.isDestroy())  
556 - n ++;  
557 -  
558 - if(s.getId().equals(sch.getId()))  
559 - break;  
560 - }  
561 - return n;  
562 - }  
563 -  
564 - /**  
565 - *  
566 - * @Title: validEndTime  
567 - * @Description: TODO(是否是有效的到达时间)  
568 - */  
569 - public boolean validEndTime(ScheduleRealInfo sch, Long ts) {  
570 - if(sch.getFcsjActualTime() != null && sch.getFcsjActualTime() > ts)  
571 - return false;  
572 -  
573 - return validTime(sch, ts);  
574 - }  
575 -  
576 - /**  
577 - *  
578 - * @Title: validStartTime  
579 - * @Description: TODO(是否是合适的发车时间)  
580 - */  
581 - public boolean validStartTime(ScheduleRealInfo sch, Long ts) {  
582 - if(sch.getZdsjActualTime() != null && sch.getZdsjActualTime() < ts)  
583 - return false;  
584 -  
585 - return validTime(sch, ts);  
586 - }  
587 -  
588 - public boolean validTime(ScheduleRealInfo sch, Long ts){  
589 - List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());  
590 - int ci = list.indexOf(sch);  
591 - ScheduleRealInfo prve, next;  
592 - if(ci > 0){  
593 - //之前班次实际时间不能大于该时间  
594 - for(int i = ci - 1; i >= 0; i --){  
595 - prve = list.get(i);  
596 - if(prve.getZdsjActualTime() != null && prve.getZdsjActualTime() > ts )  
597 - return false;  
598 -  
599 - if(prve.getFcsjActualTime() != null && prve.getFcsjActualTime() > ts)  
600 - return false;  
601 - }  
602 - }  
603 -  
604 - if(ci < list.size() - 1){  
605 - //之后班次实际时间不能小于该时间  
606 - for(int i = ci + 1; i < list.size(); i ++){  
607 - next = list.get(i);  
608 - if(next.getFcsjActualTime() != null && next.getFcsjActualTime() < ts)  
609 - return false;  
610 -  
611 - if(next.getZdsjActualTime() != null && next.getZdsjActualTime() < ts)  
612 - return false;  
613 - }  
614 - }  
615 - return true;  
616 - }  
617 -  
618 - public void save(ScheduleRealInfo sch){  
619 - //schRepository.save(sch);  
620 - pstBuffer.add(sch);  
621 - }  
622 -  
623 -  
624 - /**  
625 - *  
626 - * @Title: nextByBcType  
627 - * @Description: TODO(获取下一个指定班次类型的班次)  
628 - */  
629 - public ScheduleRealInfo nextByBcType(String nbbm, String bcType){  
630 - List<ScheduleRealInfo> list = findByBcType(nbbm, bcType);  
631 -  
632 - Collections.sort(list, schFCSJComparator);  
633 - ScheduleRealInfo sch = null;  
634 - for(ScheduleRealInfo temp : list){  
635 - if(temp.getFcsjActual() == null)  
636 - sch = temp;  
637 - }  
638 -  
639 - return sch;  
640 - }  
641 -  
642 - public List<ScheduleRealInfo> findByBcType(String nbbm, String bcType){  
643 - List<ScheduleRealInfo> all = nbbmScheduleMap.get(nbbm)  
644 - ,outList = new ArrayList<>();  
645 -  
646 - for(ScheduleRealInfo sch : all){  
647 - if(sch.getBcType().equals(bcType))  
648 - outList.add(sch);  
649 - }  
650 - return outList;  
651 - }  
652 -  
653 - public Set<String> allCar(){  
654 - return nbbmScheduleMap.keySet();  
655 - }  
656 -  
657 - public Collection<ScheduleRealInfo> findAll(){  
658 - return nbbmScheduleMap.values();  
659 - }  
660 -  
661 - public void addExecPlan(ScheduleRealInfo sch){  
662 - carExecutePlanMap.put(sch.getClZbh(), sch);  
663 - }  
664 -  
665 - public void removeExecPlan(String clzbh){  
666 - carExecutePlanMap.remove(clzbh);  
667 - }  
668 -  
669 - public Map<String, ScheduleRealInfo> execPlamMap(){  
670 - return carExecutePlanMap;  
671 - }  
672 -  
673 - /**  
674 - * @Title: changeCar  
675 - * @Description: TODO(班次换车) 返回有更新的班次  
676 - * @param @param sch  
677 - * @param @param newClZbh 新的车辆自编号  
678 - */  
679 - public List<ScheduleRealInfo> changeCar(ScheduleRealInfo sch , String newClZbh){  
680 - List<ScheduleRealInfo> ups = new ArrayList<>();  
681 - String oldClzbh = sch.getClZbh();  
682 - if(oldClzbh.equals(newClZbh))  
683 - return ups;  
684 -  
685 -  
686 - //变更相关映射信息  
687 - nbbmScheduleMap.remove(sch.getClZbh(), sch);  
688 -  
689 - sch.setClZbh(newClZbh);  
690 - nbbmScheduleMap.put(newClZbh, sch);  
691 - nbbm2SEStationMap.put(newClZbh, sch.getQdzCode());  
692 - nbbm2SEStationMap.put(newClZbh, sch.getZdzCode());  
693 -  
694 - //重新计算班次应到时间  
695 - ups.addAll(updateQdzTimePlan(oldClzbh));  
696 - ups.addAll(updateQdzTimePlan(newClZbh));  
697 - return ups;  
698 - }  
699 -  
700 - /**  
701 - *  
702 - * @Title: linkToSchPlan  
703 - * @Description: TODO(车辆关联到班次)  
704 - */ 586 + /**
  587 + * @Title: doneSum
  588 + * @Description: TODO(已完成班次总数)
  589 + */
  590 + public int doneSum(String clZbh) {
  591 + List<ScheduleRealInfo> list = nbbmScheduleMap.get(clZbh);
  592 + int rs = 0;
  593 +
  594 + for (ScheduleRealInfo sch : list) {
  595 + if (sch.getStatus() == 2 && !sch.isDestroy())
  596 + rs++;
  597 + }
  598 + return rs;
  599 + }
  600 +
  601 + /**
  602 + * @Title: prveNotExecNum
  603 + * @Description: TODO(班次之前未执行班次数量)
  604 + */
  605 + public int prveNotExecNum(ScheduleRealInfo sch) {
  606 + int n = 0;
  607 + List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());
  608 + for (ScheduleRealInfo s : list) {
  609 + if (s.getFcsjActual() == null && !s.isDestroy())
  610 + n++;
  611 +
  612 + if (s.getId().equals(sch.getId()))
  613 + break;
  614 + }
  615 + return n;
  616 + }
  617 +
  618 + /**
  619 + * @Title: validEndTime
  620 + * @Description: TODO(是否是有效的到达时间)
  621 + */
  622 + public boolean validEndTime(ScheduleRealInfo sch, Long ts) {
  623 + if (sch.getFcsjActualTime() != null && sch.getFcsjActualTime() > ts)
  624 + return false;
  625 +
  626 + return validTime(sch, ts);
  627 + }
  628 +
  629 + /**
  630 + * @Title: validStartTime
  631 + * @Description: TODO(是否是合适的发车时间)
  632 + */
  633 + public boolean validStartTime(ScheduleRealInfo sch, Long ts) {
  634 + if (sch.getZdsjActualTime() != null && sch.getZdsjActualTime() < ts)
  635 + return false;
  636 +
  637 + return validTime(sch, ts);
  638 + }
  639 +
  640 + public boolean validTime(ScheduleRealInfo sch, Long ts) {
  641 + List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());
  642 + int ci = list.indexOf(sch);
  643 + ScheduleRealInfo prve, next;
  644 + if (ci > 0) {
  645 + //之前班次实际时间不能大于该时间
  646 + for (int i = ci - 1; i >= 0; i--) {
  647 + prve = list.get(i);
  648 + if (prve.getZdsjActualTime() != null && prve.getZdsjActualTime() > ts)
  649 + return false;
  650 +
  651 + if (prve.getFcsjActualTime() != null && prve.getFcsjActualTime() > ts)
  652 + return false;
  653 + }
  654 + }
  655 +
  656 + if (ci < list.size() - 1) {
  657 + //之后班次实际时间不能小于该时间
  658 + for (int i = ci + 1; i < list.size(); i++) {
  659 + next = list.get(i);
  660 + if (next.getFcsjActualTime() != null && next.getFcsjActualTime() < ts)
  661 + return false;
  662 +
  663 + if (next.getZdsjActualTime() != null && next.getZdsjActualTime() < ts)
  664 + return false;
  665 + }
  666 + }
  667 + return true;
  668 + }
  669 +
  670 + public void save(ScheduleRealInfo sch) {
  671 + //schRepository.save(sch);
  672 + pstBuffer.add(sch);
  673 + }
  674 +
  675 +
  676 + /**
  677 + * @Title: nextByBcType
  678 + * @Description: TODO(获取下一个指定班次类型的班次)
  679 + */
  680 + public ScheduleRealInfo nextByBcType(String nbbm, String bcType) {
  681 + List<ScheduleRealInfo> list = findByBcType(nbbm, bcType);
  682 +
  683 + Collections.sort(list, schFCSJComparator);
  684 + ScheduleRealInfo sch = null;
  685 + for (ScheduleRealInfo temp : list) {
  686 + if (temp.getFcsjActual() == null)
  687 + sch = temp;
  688 + }
  689 +
  690 + return sch;
  691 + }
  692 +
  693 + public List<ScheduleRealInfo> findByBcType(String nbbm, String bcType) {
  694 + List<ScheduleRealInfo> all = nbbmScheduleMap.get(nbbm), outList = new ArrayList<>();
  695 +
  696 + for (ScheduleRealInfo sch : all) {
  697 + if (sch.getBcType().equals(bcType))
  698 + outList.add(sch);
  699 + }
  700 + return outList;
  701 + }
  702 +
  703 + public Set<String> allCar() {
  704 + return nbbmScheduleMap.keySet();
  705 + }
  706 +
  707 + public Collection<ScheduleRealInfo> findAll() {
  708 + return nbbmScheduleMap.values();
  709 + }
  710 +
  711 + public void addExecPlan(ScheduleRealInfo sch) {
  712 + if(sch != null)
  713 + carExecutePlanMap.put(sch.getClZbh(), sch);
  714 + }
  715 +
  716 + public void removeExecPlan(String clzbh) {
  717 + carExecutePlanMap.remove(clzbh);
  718 + }
  719 +
  720 + public Map<String, ScheduleRealInfo> execPlanMap() {
  721 + return carExecutePlanMap;
  722 + }
  723 +
  724 + /**
  725 + * 车辆当前执行的班次
  726 + *
  727 + * @param nbbm
  728 + * @return
  729 + */
  730 + public ScheduleRealInfo executeCurr(String nbbm) {
  731 + return carExecutePlanMap.get(nbbm);
  732 + }
  733 +
  734 + /**
  735 + * @param @param sch
  736 + * @param @param newClZbh 新的车辆自编号
  737 + * @Title: changeCar
  738 + * @Description: TODO(班次换车) 返回有更新的班次
  739 + */
  740 + public List<ScheduleRealInfo> changeCar(ScheduleRealInfo sch, String newClZbh) {
  741 + List<ScheduleRealInfo> ups = new ArrayList<>();
  742 + String oldClzbh = sch.getClZbh();
  743 + if (oldClzbh.equals(newClZbh))
  744 + return ups;
  745 +
  746 +
  747 + //变更相关映射信息
  748 + nbbmScheduleMap.remove(sch.getClZbh(), sch);
  749 +
  750 + sch.setClZbh(newClZbh);
  751 + nbbmScheduleMap.put(newClZbh, sch);
  752 + nbbm2SEStationMap.put(newClZbh, sch.getQdzCode());
  753 + nbbm2SEStationMap.put(newClZbh, sch.getZdzCode());
  754 +
  755 + //重新计算班次应到时间
  756 + ups.addAll(updateQdzTimePlan(oldClzbh));
  757 + ups.addAll(updateQdzTimePlan(newClZbh));
  758 +
  759 + //重新计算车辆当前执行班次
  760 + reCalcExecPlan(newClZbh);
  761 + reCalcExecPlan(sch.getClZbh());
  762 + return ups;
  763 + }
  764 +
  765 + public void reCalcExecPlan(String nbbm){
  766 + carExecutePlanMap.put(nbbm, schAttrCalculator.calcCurrentExecSch(nbbmScheduleMap.get(nbbm)));
  767 + }
  768 +
  769 + /**
  770 + * 是否在执行首班出场
  771 + * @param nbbm
  772 + * @return
  773 + */
  774 + public boolean isExecFirstOut(String nbbm, long time){
  775 + try {
  776 + List<ScheduleRealInfo> list = nbbmScheduleMap.get(nbbm);
  777 + ScheduleRealInfo second = list.get(2),
  778 + first = executeCurr(nbbm);
  779 +
  780 + if(first.getBcType().equals("out")
  781 + && first.getDfsjT() < second.getDfsjT()
  782 + && doneSum(nbbm) == 0 && second.getDfsjT() > time)
  783 + return true;
  784 + } catch (Exception e) {
  785 + logger.error("", e);
  786 + }
  787 +
  788 + return false;
  789 + }
  790 +
  791 + /**
  792 + * 获取班次的计划停站时间
  793 + * @param sch
  794 + * @return
  795 +
  796 + public int stopTimePlan(Object task) {
  797 +
  798 + ScheduleRealInfo sch = prev((ScheduleRealInfo) task);
  799 +
  800 + sch.getzdsj
  801 + return -1;
  802 + }*/
  803 +
  804 + /**
  805 + *
  806 + * @Title: linkToSchPlan
  807 + * @Description: TODO(车辆关联到班次)
  808 + */
705 /* public void linkToSchPlan(String nbbm) { 809 /* public void linkToSchPlan(String nbbm) {
706 //当前GPS状态 810 //当前GPS状态
707 GpsEntity gps = gpsRealData.get(BasicData.deviceId2NbbmMap.inverse().get(nbbm)); 811 GpsEntity gps = gpsRealData.get(BasicData.deviceId2NbbmMap.inverse().get(nbbm));
src/main/java/com/bsth/data/schedule/SchAttrCalculator.java
@@ -215,4 +215,30 @@ public class SchAttrCalculator { @@ -215,4 +215,30 @@ public class SchAttrCalculator {
215 if(sch.getZdsjActualTime() == null && sch.getZdsjActual() != null) 215 if(sch.getZdsjActualTime() == null && sch.getZdsjActual() != null)
216 sch.setZdsjActualAll(sch.getZdsjActual()); 216 sch.setZdsjActualAll(sch.getZdsjActual());
217 } 217 }
  218 +
  219 + /**
  220 + * 计算当前要执行的班次
  221 + * @param list
  222 + * @return
  223 + */
  224 + public ScheduleRealInfo calcCurrentExecSch(List<ScheduleRealInfo> list){
  225 + String lineCode = list.get(0).getXlBm();
  226 + LineConfig conf = lineConfigData.get(lineCode);
  227 + int outConfig = -1;
  228 + if(conf != null)
  229 + outConfig = conf.getOutConfig();
  230 +
  231 + for(ScheduleRealInfo sch : list){
  232 + //如果是出站既出场,忽略出场班次
  233 + if(outConfig == 2 && sch.getBcType().equals("out"))
  234 + continue;
  235 +
  236 + //已执行
  237 + if(StringUtils.isNotEmpty(sch.getZdsjActual()))
  238 + continue;
  239 +
  240 + return sch;
  241 + }
  242 + return null;
  243 + }
218 } 244 }
src/main/java/com/bsth/data/schedule/thread/ScheduleRefreshThread.java
1 package com.bsth.data.schedule.thread; 1 package com.bsth.data.schedule.thread;
2 2
3 -import java.util.Collection;  
4 -import java.util.Set;  
5 -  
6 -import org.slf4j.Logger;  
7 -import org.slf4j.LoggerFactory;  
8 -import org.springframework.beans.factory.annotation.Autowired;  
9 -import org.springframework.stereotype.Component;  
10 -  
11 import com.bsth.data.BasicData; 3 import com.bsth.data.BasicData;
12 import com.bsth.data.LineConfigData; 4 import com.bsth.data.LineConfigData;
13 import com.bsth.data.arrival.ArrivalData_GPS; 5 import com.bsth.data.arrival.ArrivalData_GPS;
@@ -15,6 +7,13 @@ import com.bsth.data.directive.DayOfDirectives; @@ -15,6 +7,13 @@ import com.bsth.data.directive.DayOfDirectives;
15 import com.bsth.data.pilot80.PilotReport; 7 import com.bsth.data.pilot80.PilotReport;
16 import com.bsth.data.schedule.DayOfSchedule; 8 import com.bsth.data.schedule.DayOfSchedule;
17 import com.bsth.entity.realcontrol.LineConfig; 9 import com.bsth.entity.realcontrol.LineConfig;
  10 +import org.slf4j.Logger;
  11 +import org.slf4j.LoggerFactory;
  12 +import org.springframework.beans.factory.annotation.Autowired;
  13 +import org.springframework.stereotype.Component;
  14 +
  15 +import java.util.Collection;
  16 +import java.util.Set;
18 17
19 /** 18 /**
20 * 19 *
@@ -57,6 +56,7 @@ public class ScheduleRefreshThread extends Thread{ @@ -57,6 +56,7 @@ public class ScheduleRefreshThread extends Thread{
57 currSchDate = dayOfSchedule.calcSchDate(lineCode); 56 currSchDate = dayOfSchedule.calcSchDate(lineCode);
58 57
59 if(oldSchDate == null || !oldSchDate.equals(currSchDate)){ 58 if(oldSchDate == null || !oldSchDate.equals(currSchDate)){
  59 +
60 logger.info(lineCode + "开始翻班, " + currSchDate); 60 logger.info(lineCode + "开始翻班, " + currSchDate);
61 //清除进出站数据 61 //清除进出站数据
62 arrivalData.clearRAMData(lineCode); 62 arrivalData.clearRAMData(lineCode);
src/main/java/com/bsth/entity/Cars.java
@@ -23,7 +23,7 @@ import java.util.Date; @@ -23,7 +23,7 @@ import java.util.Date;
23 23
24 @Entity 24 @Entity
25 @Table(name = "bsth_c_cars") 25 @Table(name = "bsth_c_cars")
26 -@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler"}) 26 +@JsonIgnoreProperties(value={"hibernateLazyInitializer","handlers","fieldHandler"})
27 public class Cars extends BEntity implements Serializable { 27 public class Cars extends BEntity implements Serializable {
28 28
29 /** 主键Id */ 29 /** 主键Id */
src/main/java/com/bsth/entity/Line.java
@@ -24,7 +24,7 @@ import java.util.Date; @@ -24,7 +24,7 @@ import java.util.Date;
24 24
25 @Entity 25 @Entity
26 @Table(name = "bsth_c_line") 26 @Table(name = "bsth_c_line")
27 -@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler"}) 27 +@JsonIgnoreProperties(value={"hibernateLazyInitializer","handlers","fieldHandler"})
28 public class Line implements Serializable { 28 public class Line implements Serializable {
29 29
30 @Id 30 @Id
src/main/java/com/bsth/entity/Personnel.java
@@ -21,7 +21,7 @@ import javax.persistence.*; @@ -21,7 +21,7 @@ import javax.persistence.*;
21 21
22 @Entity 22 @Entity
23 @Table(name = "bsth_c_personnel") 23 @Table(name = "bsth_c_personnel")
24 -@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler"}) 24 +@JsonIgnoreProperties(value={"hibernateLazyInitializer","handlers","fieldHandler"})
25 public class Personnel extends BEntity { 25 public class Personnel extends BEntity {
26 26
27 /** 主键Id */ 27 /** 主键Id */
src/main/java/com/bsth/entity/mcy_forms/Changetochange.java
1 package com.bsth.entity.mcy_forms; 1 package com.bsth.entity.mcy_forms;
2 2
3 -import java.util.Date;  
4 -  
5 import javax.persistence.Entity; 3 import javax.persistence.Entity;
6 import javax.persistence.GeneratedValue; 4 import javax.persistence.GeneratedValue;
7 import javax.persistence.Id; 5 import javax.persistence.Id;
src/main/java/com/bsth/entity/realcontrol/LineConfig.java
1 package com.bsth.entity.realcontrol; 1 package com.bsth.entity.realcontrol;
2 2
  3 +import com.bsth.entity.Line;
  4 +
  5 +import javax.persistence.*;
3 import java.text.ParseException; 6 import java.text.ParseException;
4 import java.text.SimpleDateFormat; 7 import java.text.SimpleDateFormat;
5 import java.util.Date; 8 import java.util.Date;
6 import java.util.HashSet; 9 import java.util.HashSet;
7 import java.util.Set; 10 import java.util.Set;
8 11
9 -import javax.persistence.CascadeType;  
10 -import javax.persistence.Entity;  
11 -import javax.persistence.GeneratedValue;  
12 -import javax.persistence.Id;  
13 -import javax.persistence.NamedAttributeNode;  
14 -import javax.persistence.NamedEntityGraph;  
15 -import javax.persistence.NamedEntityGraphs;  
16 -import javax.persistence.OneToMany;  
17 -import javax.persistence.OneToOne;  
18 -import javax.persistence.Table;  
19 -import javax.persistence.Transient;  
20 -  
21 -import com.bsth.entity.Line;  
22 -import com.bsth.util.DateUtils;  
23 -  
24 /** 12 /**
25 * 13 *
26 * @ClassName: LineConfig 14 * @ClassName: LineConfig
@@ -59,9 +47,6 @@ public class LineConfig { @@ -59,9 +47,6 @@ public class LineConfig {
59 /** 出场时间设置 0:真实出场(设备离开缓冲区时间) 1:请求出场时间 2:出站即出场 */ 47 /** 出场时间设置 0:真实出场(设备离开缓冲区时间) 1:请求出场时间 2:出站即出场 */
60 private int outConfig; 48 private int outConfig;
61 49
62 - /** 进场时间设置 0:真实进场(设备进入缓冲区时间) 1:请求进场时间 2:出站即出场*/  
63 - private int inConfig;  
64 -  
65 /** 短语模板 , 号分隔多个 */ 50 /** 短语模板 , 号分隔多个 */
66 private String phraseTemps; 51 private String phraseTemps;
67 52
@@ -111,14 +96,6 @@ public class LineConfig { @@ -111,14 +96,6 @@ public class LineConfig {
111 this.outConfig = outConfig; 96 this.outConfig = outConfig;
112 } 97 }
113 98
114 - public int getInConfig() {  
115 - return inConfig;  
116 - }  
117 -  
118 - public void setInConfig(int inConfig) {  
119 - this.inConfig = inConfig;  
120 - }  
121 -  
122 public String getPhraseTemps() { 99 public String getPhraseTemps() {
123 return phraseTemps; 100 return phraseTemps;
124 } 101 }
src/main/java/com/bsth/entity/realcontrol/ScheduleType.java 0 → 100644
  1 +package com.bsth.entity.realcontrol;
  2 +
  3 +/**
  4 + * 班次类型
  5 + * Created by panzhao on 2016/12/23.
  6 + */
  7 +public enum ScheduleType {
  8 +
  9 + normal, //正常班次
  10 + out, //出场
  11 + in, //进场
  12 + region, //区间
  13 + venting,//直放
  14 + major //放站
  15 +}
src/main/java/com/bsth/entity/schedule/CarConfigInfo.java
@@ -19,7 +19,7 @@ import java.util.Date; @@ -19,7 +19,7 @@ import java.util.Date;
19 @NamedAttributeNode("cl") 19 @NamedAttributeNode("cl")
20 }) 20 })
21 }) 21 })
22 -@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler"}) 22 +@JsonIgnoreProperties(value={"hibernateLazyInitializer","handlers","fieldHandler"})
23 public class CarConfigInfo extends BEntity implements Serializable { 23 public class CarConfigInfo extends BEntity implements Serializable {
24 24
25 /** 主健Id */ 25 /** 主健Id */
src/main/java/com/bsth/entity/schedule/EmployeeConfigInfo.java
@@ -22,7 +22,7 @@ import java.io.Serializable; @@ -22,7 +22,7 @@ import java.io.Serializable;
22 @NamedAttributeNode("xl") 22 @NamedAttributeNode("xl")
23 }) 23 })
24 }) 24 })
25 -@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler"}) 25 +@JsonIgnoreProperties(value={"hibernateLazyInitializer","handlers","fieldHandler"})
26 public class EmployeeConfigInfo extends BEntity implements Serializable { 26 public class EmployeeConfigInfo extends BEntity implements Serializable {
27 27
28 /** 主键Id */ 28 /** 主键Id */
src/main/java/com/bsth/entity/schedule/GuideboardInfo.java
@@ -15,7 +15,7 @@ import javax.persistence.*; @@ -15,7 +15,7 @@ import javax.persistence.*;
15 @NamedAttributeNode("xl") 15 @NamedAttributeNode("xl")
16 }) 16 })
17 }) 17 })
18 -@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler"}) 18 +@JsonIgnoreProperties(value={"hibernateLazyInitializer","handlers","fieldHandler"})
19 public class GuideboardInfo extends BEntity { 19 public class GuideboardInfo extends BEntity {
20 20
21 /** 主键Id */ 21 /** 主键Id */
src/main/java/com/bsth/entity/schedule/TTInfo.java
1 package com.bsth.entity.schedule; 1 package com.bsth.entity.schedule;
2 2
3 import com.bsth.entity.Line; 3 import com.bsth.entity.Line;
4 -import com.bsth.entity.sys.SysUser;  
5 4
6 import javax.persistence.*; 5 import javax.persistence.*;
7 import java.util.Date; 6 import java.util.Date;
@@ -18,7 +17,7 @@ import java.util.Date; @@ -18,7 +17,7 @@ import java.util.Date;
18 @NamedAttributeNode("updateBy") 17 @NamedAttributeNode("updateBy")
19 }) 18 })
20 }) 19 })
21 -public class TTInfo { 20 +public class TTInfo extends BEntity {
22 21
23 /** 主键Id */ 22 /** 主键Id */
24 @Id 23 @Id
@@ -50,9 +49,9 @@ public class TTInfo { @@ -50,9 +49,9 @@ public class TTInfo {
50 49
51 // TODO:还有很多判定条件,这里先不放 50 // TODO:还有很多判定条件,这里先不放
52 51
53 - /** 路牌数 */ 52 + /** 路牌数(这两个字段暂时不用) */
54 private int lpCount; 53 private int lpCount;
55 - /** 圈数 */ 54 + /** 圈数(这两个字段暂时不倒) */
56 private int loopCount; 55 private int loopCount;
57 56
58 // TODO:原系统里的分别在,圈后圈进场,意思不知道,再议 57 // TODO:原系统里的分别在,圈后圈进场,意思不知道,再议
@@ -62,19 +61,25 @@ public class TTInfo { @@ -62,19 +61,25 @@ public class TTInfo {
62 /** 特殊有效日期(格式:2001-01-01,多个用逗号隔开) */ 61 /** 特殊有效日期(格式:2001-01-01,多个用逗号隔开) */
63 private String special_days; 62 private String special_days;
64 63
65 - /** 操作人员关联 */  
66 - @ManyToOne(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)  
67 - private SysUser createBy;  
68 - /** 更新人员关联 */  
69 - @ManyToOne(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)  
70 - private SysUser updateBy;  
71 - // 创建日期  
72 - @Column(updatable = false, name = "create_date", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")  
73 - private Date createDate;  
74 - // 修改日期  
75 - @Column(name = "update_date", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")  
76 - private Date updateDate;  
77 - 64 + public TTInfo() {}
  65 + public TTInfo(Object id, Object xlid, Object name, Object nds, Object sds) {
  66 + if (id != null) {
  67 + this.id = Long.parseLong(id.toString());
  68 + }
  69 + if (xlid != null) {
  70 + this.xl = new Line();
  71 + this.xl.setId(Integer.valueOf(xlid.toString()));
  72 + }
  73 + if (name != null) {
  74 + this.name = String.valueOf(name);
  75 + }
  76 + if (nds != null) {
  77 + this.rule_days = String.valueOf(nds);
  78 + }
  79 + if (sds != null) {
  80 + this.special_days = String.valueOf(sds);
  81 + }
  82 + }
78 83
79 public Long getId() { 84 public Long getId() {
80 return id; 85 return id;
@@ -164,38 +169,6 @@ public class TTInfo { @@ -164,38 +169,6 @@ public class TTInfo {
164 this.special_days = special_days; 169 this.special_days = special_days;
165 } 170 }
166 171
167 - public SysUser getCreateBy() {  
168 - return createBy;  
169 - }  
170 -  
171 - public void setCreateBy(SysUser createBy) {  
172 - this.createBy = createBy;  
173 - }  
174 -  
175 - public SysUser getUpdateBy() {  
176 - return updateBy;  
177 - }  
178 -  
179 - public void setUpdateBy(SysUser updateBy) {  
180 - this.updateBy = updateBy;  
181 - }  
182 -  
183 - public Date getCreateDate() {  
184 - return createDate;  
185 - }  
186 -  
187 - public void setCreateDate(Date createDate) {  
188 - this.createDate = createDate;  
189 - }  
190 -  
191 - public Date getUpdateDate() {  
192 - return updateDate;  
193 - }  
194 -  
195 - public void setUpdateDate(Date updateDate) {  
196 - this.updateDate = updateDate;  
197 - }  
198 -  
199 public Boolean getIsCancel() { 172 public Boolean getIsCancel() {
200 return isCancel; 173 return isCancel;
201 } 174 }
src/main/java/com/bsth/entity/schedule/TTInfoDetail.java
@@ -3,10 +3,8 @@ package com.bsth.entity.schedule; @@ -3,10 +3,8 @@ package com.bsth.entity.schedule;
3 import com.bsth.entity.CarPark; 3 import com.bsth.entity.CarPark;
4 import com.bsth.entity.Line; 4 import com.bsth.entity.Line;
5 import com.bsth.entity.Station; 5 import com.bsth.entity.Station;
6 -import com.bsth.entity.sys.SysUser;  
7 6
8 import javax.persistence.*; 7 import javax.persistence.*;
9 -import java.util.Date;  
10 8
11 /** 9 /**
12 * 时刻表明细 10 * 时刻表明细
@@ -23,7 +21,7 @@ import java.util.Date; @@ -23,7 +21,7 @@ import java.util.Date;
23 @NamedAttributeNode("tcc") 21 @NamedAttributeNode("tcc")
24 }) 22 })
25 }) 23 })
26 -public class TTInfoDetail { 24 +public class TTInfoDetail extends BEntity {
27 25
28 /** 主健Id */ 26 /** 主健Id */
29 @Id 27 @Id
@@ -85,20 +83,6 @@ public class TTInfoDetail { @@ -85,20 +83,6 @@ public class TTInfoDetail {
85 /** 备注 */ 83 /** 备注 */
86 private String remark; 84 private String remark;
87 85
88 - /** 创建人 */  
89 - @ManyToOne(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)  
90 - private SysUser createBy;  
91 - /** 修改人 */  
92 - @ManyToOne(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)  
93 - private SysUser updateBy;  
94 -  
95 - /** 创建日期 */  
96 - @Column(updatable = false, name = "create_date", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")  
97 - private Date createDate;  
98 - /** 修改日期 */  
99 - @Column(name = "update_date", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")  
100 - private Date updateDate;  
101 -  
102 public Long getId() { 86 public Long getId() {
103 return id; 87 return id;
104 } 88 }
@@ -235,38 +219,6 @@ public class TTInfoDetail { @@ -235,38 +219,6 @@ public class TTInfoDetail {
235 this.remark = remark; 219 this.remark = remark;
236 } 220 }
237 221
238 - public SysUser getCreateBy() {  
239 - return createBy;  
240 - }  
241 -  
242 - public void setCreateBy(SysUser createBy) {  
243 - this.createBy = createBy;  
244 - }  
245 -  
246 - public SysUser getUpdateBy() {  
247 - return updateBy;  
248 - }  
249 -  
250 - public void setUpdateBy(SysUser updateBy) {  
251 - this.updateBy = updateBy;  
252 - }  
253 -  
254 - public Date getCreateDate() {  
255 - return createDate;  
256 - }  
257 -  
258 - public void setCreateDate(Date createDate) {  
259 - this.createDate = createDate;  
260 - }  
261 -  
262 - public Date getUpdateDate() {  
263 - return updateDate;  
264 - }  
265 -  
266 - public void setUpdateDate(Date updateDate) {  
267 - this.updateDate = updateDate;  
268 - }  
269 -  
270 public CarPark getTcc() { 222 public CarPark getTcc() {
271 return tcc; 223 return tcc;
272 } 224 }
src/main/java/com/bsth/entity/schedule/rule/RerunRule.java
1 package com.bsth.entity.schedule.rule; 1 package com.bsth.entity.schedule.rule;
2 2
3 import com.bsth.entity.Line; 3 import com.bsth.entity.Line;
4 -import com.bsth.entity.schedule.CarConfigInfo;  
5 -import com.bsth.entity.schedule.EmployeeConfigInfo;  
6 -import com.bsth.entity.schedule.GuideboardInfo;  
7 -import com.bsth.entity.schedule.TTInfo;  
8 -import com.bsth.entity.sys.SysUser; 4 +import com.bsth.entity.schedule.*;
9 5
10 import javax.persistence.*; 6 import javax.persistence.*;
11 -import java.util.Date;  
12 7
13 /** 8 /**
14 * 套跑规则。 9 * 套跑规则。
@@ -41,7 +36,7 @@ import java.util.Date; @@ -41,7 +36,7 @@ import java.util.Date;
41 }) 36 })
42 37
43 38
44 -public class RerunRule { 39 +public class RerunRule extends BEntity {
45 /** 主键Id */ 40 /** 主键Id */
46 @Id 41 @Id
47 @GeneratedValue 42 @GeneratedValue
@@ -84,19 +79,6 @@ public class RerunRule { @@ -84,19 +79,6 @@ public class RerunRule {
84 @Column(nullable = false) 79 @Column(nullable = false)
85 private Boolean isCancel = false; 80 private Boolean isCancel = false;
86 81
87 - /** 创建人 */  
88 - @ManyToOne(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)  
89 - private SysUser createBy;  
90 - /** 修改人 */  
91 - @ManyToOne(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)  
92 - private SysUser updateBy;  
93 - /** 创建日期 */  
94 - @Column(updatable = false, name = "create_date", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")  
95 - private Date createDate;  
96 - /** 修改日期 */  
97 - @Column(name = "update_date", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")  
98 - private Date updateDate;  
99 -  
100 public Long getId() { 82 public Long getId() {
101 return id; 83 return id;
102 } 84 }
@@ -177,34 +159,6 @@ public class RerunRule { @@ -177,34 +159,6 @@ public class RerunRule {
177 this.useEmployeeConfig = useEmployeeConfig; 159 this.useEmployeeConfig = useEmployeeConfig;
178 } 160 }
179 161
180 - public SysUser getCreateBy() {  
181 - return createBy;  
182 - }  
183 -  
184 - public void setCreateBy(SysUser createBy) {  
185 - this.createBy = createBy;  
186 - }  
187 -  
188 - public SysUser getUpdateBy() {  
189 - return updateBy;  
190 - }  
191 -  
192 - public void setUpdateBy(SysUser updateBy) {  
193 - this.updateBy = updateBy;  
194 - }  
195 -  
196 - public Date getCreateDate() {  
197 - return createDate;  
198 - }  
199 -  
200 - public void setCreateDate(Date createDate) {  
201 - this.createDate = createDate;  
202 - }  
203 -  
204 - public Date getUpdateDate() {  
205 - return updateDate;  
206 - }  
207 -  
208 public Boolean getIsCancel() { 162 public Boolean getIsCancel() {
209 return isCancel; 163 return isCancel;
210 } 164 }
@@ -213,7 +167,4 @@ public class RerunRule { @@ -213,7 +167,4 @@ public class RerunRule {
213 this.isCancel = isCancel; 167 this.isCancel = isCancel;
214 } 168 }
215 169
216 - public void setUpdateDate(Date updateDate) {  
217 - this.updateDate = updateDate;  
218 - }  
219 } 170 }
src/main/java/com/bsth/entity/sys/SysUser.java
@@ -9,7 +9,7 @@ import java.util.Set; @@ -9,7 +9,7 @@ import java.util.Set;
9 9
10 @Entity 10 @Entity
11 @Table(name = "bsth_c_sys_user") 11 @Table(name = "bsth_c_sys_user")
12 -@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler"}) 12 +@JsonIgnoreProperties(value={"hibernateLazyInitializer","handlers","fieldHandler"})
13 public class SysUser { 13 public class SysUser {
14 14
15 @Id 15 @Id
src/main/java/com/bsth/repository/realcontrol/ScheduleRealInfoRepository.java
@@ -24,6 +24,9 @@ public interface ScheduleRealInfoRepository extends BaseRepository&lt;ScheduleRealI @@ -24,6 +24,9 @@ public interface ScheduleRealInfoRepository extends BaseRepository&lt;ScheduleRealI
24 @Query(value="select min(s.id), s.jGh,s.clZbh,s.lpName,s.jName from ScheduleRealInfo s where s.xlBm = ?1 and DATE_FORMAT(s.scheduleDate,'%Y-%m-%d') = ?2 GROUP BY s.jGh,s.clZbh,s.lpName ,s.jName order by (lpName+1)") 24 @Query(value="select min(s.id), s.jGh,s.clZbh,s.lpName,s.jName from ScheduleRealInfo s where s.xlBm = ?1 and DATE_FORMAT(s.scheduleDate,'%Y-%m-%d') = ?2 GROUP BY s.jGh,s.clZbh,s.lpName ,s.jName order by (lpName+1)")
25 List<ScheduleRealInfo> queryUserInfo2(String line,String date); 25 List<ScheduleRealInfo> queryUserInfo2(String line,String date);
26 26
  27 + @Query(value="select min(s.id), s.jGh,s.clZbh,s.lpName,s.jName from ScheduleRealInfo s where s.xlBm = ?1 and DATE_FORMAT(s.scheduleDate,'%Y-%m-%d') = ?2 GROUP BY s.jGh,s.clZbh,s.lpName ,s.jName order by (lpName+1)")
  28 + List<ScheduleRealInfo> queryUserInfo3(String line,String date);
  29 +
27 @Query(value="select s from ScheduleRealInfo s where s.jName = ?1 and s.clZbh = ?2 and s.lpName = ?3 order by bcs") 30 @Query(value="select s from ScheduleRealInfo s where s.jName = ?1 and s.clZbh = ?2 and s.lpName = ?3 order by bcs")
28 List<ScheduleRealInfo> exportWaybill(String jName,String clZbh,String lpName); 31 List<ScheduleRealInfo> exportWaybill(String jName,String clZbh,String lpName);
29 32
src/main/java/com/bsth/service/BusIntervalService.java
@@ -8,6 +8,8 @@ public interface BusIntervalService { @@ -8,6 +8,8 @@ public interface BusIntervalService {
8 8
9 List<Map<String, Object>> getDir(Map<String, Object> map); 9 List<Map<String, Object>> getDir(Map<String, Object> map);
10 10
  11 + List<Map<String, Object>> getLp(Map<String, Object> map);
  12 +
11 List<Map<String, Object>> interval(Map<String, Object> map); 13 List<Map<String, Object>> interval(Map<String, Object> map);
12 14
13 Map<String, Object> timeAndSpeed(Map<String, Object> map); 15 Map<String, Object> timeAndSpeed(Map<String, Object> map);
src/main/java/com/bsth/service/forms/FormsService.java
@@ -30,7 +30,7 @@ public interface FormsService { @@ -30,7 +30,7 @@ public interface FormsService {
30 30
31 public List<Singledata> singledata(Map<String, Object> map); 31 public List<Singledata> singledata(Map<String, Object> map);
32 32
33 - public List<Vehicleloading> vehicleloading(/*String gsdmVehic,String fgsdmVehic,*/String line,String data); 33 + public List<Vehicleloading> vehicleloading(String gsdmVehic,String fgsdmVehic,String line,String data);
34 34
35 public List<Operationservice> operationservice(Map<String, Object> map); 35 public List<Operationservice> operationservice(Map<String, Object> map);
36 36