Commit 036092a18563787111e19e4188e5e0f52a8bf9c6

Authored by 徐烜
2 parents 9bf3ddff 7f3e723b

Update

Showing 31 changed files with 1845 additions and 480 deletions

Too many changes to show.

To preserve performance only 31 of 600 files are displayed.

... ... @@ -225,6 +225,12 @@
225 225 <artifactId>spring-boot-devtools</artifactId>
226 226 <optional>true</optional>
227 227 </dependency>-->
  228 + <dependency>
  229 + <groupId>com.vividsolutions</groupId>
  230 + <artifactId>jts</artifactId>
  231 + <version>1.13</version>
  232 + </dependency>
  233 +
228 234 </dependencies>
229 235  
230 236 <dependencyManagement>
... ...
src/main/java/com/bsth/controller/forms/ExportController.java
... ... @@ -65,10 +65,12 @@ public class ExportController {
65 65 i++;
66 66 }
67 67  
  68 +
  69 +
68 70 try {
69 71 listI.add(resList.iterator());
70 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 74 path + "export\\线路客流量报表" + sdfSimple.format(sdfMonth.parse(map.get("date").toString())) + ".xls");
73 75 } catch (Exception e) {
74 76 e.printStackTrace();
... ... @@ -189,7 +191,7 @@ public class ExportController {
189 191 listI.add(resList.iterator());
190 192 String path = this.getClass().getResource("/").getPath() + "static\\pages\\forms\\";
191 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 195 } catch (Exception e) {
194 196 e.printStackTrace();
195 197 }
... ... @@ -203,8 +205,8 @@ public class ExportController {
203 205 SimpleDateFormat sdfMonth = new SimpleDateFormat("yyyy-MM-dd"), sdfSimple = new SimpleDateFormat("yyyyMMdd");
204 206 List<Iterator<?>> listI = new ArrayList<Iterator<?>>();
205 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 210 List<Map<String, Object>> resList = new ArrayList<Map<String, Object>>();
209 211 int i = 1;
210 212 for (Vehicleloading l : vehicleloading) {
... ... @@ -214,8 +216,8 @@ public class ExportController {
214 216 m.put("gS", l.getgS());
215 217 m.put("xL", l.getxL());
216 218 m.put("clzbh", l.getClzbh());
217   - m.put("hyl", l.getHyl());
218 219 m.put("jzl", l.getJzl());
  220 + m.put("hyl", l.getHyl());
219 221 m.put("ls", l.getLs());
220 222 m.put("jhlc", l.getJhlc());
221 223 m.put("unyyyl", l.getUnyyyl());
... ... @@ -229,7 +231,7 @@ public class ExportController {
229 231 listI.add(resList.iterator());
230 232 String path = this.getClass().getResource("/").getPath() + "static\\pages\\forms\\";
231 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 235 } catch (Exception e) {
234 236 e.printStackTrace();
235 237 }
... ... @@ -417,5 +419,9 @@ public class ExportController {
417 419 }
418 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 80  
81 81 // 车辆加注
82 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 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 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 3 import com.bsth.data.BasicData;
10 4 import com.bsth.data.gpsdata.GpsEntity;
11 5 import com.bsth.data.gpsdata.GpsRealData;
12 6 import com.bsth.service.gps.GpsService;
13 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 14 @RestController
16 15 @RequestMapping("gps")
... ... @@ -70,7 +69,7 @@ public class GpsController {
70 69 return gpsService.history(nbbmArray, st, et);
71 70 }
72 71  
73   - /*@RequestMapping(value = "/arrival/ram")
  72 + /*@RequestMapping(value = "/analyse/ram")
74 73 public List<ArrivalInfo> ramData(@RequestParam String nbbm) {
75 74 return ArrivalDataBuffer.allMap.get(nbbm);
76 75 }*/
... ... @@ -84,4 +83,9 @@ public class GpsController {
84 83 public Map<String, Object> findBuffAeraByCode(@RequestParam String code,@RequestParam String type){
85 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/schedule/core/TTInfoController.java
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);
  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 128 // }
129 129 \ No newline at end of file
... ...
src/main/java/com/bsth/data/BasicData.java
1 1 package com.bsth.data;
2 2  
3 3 import com.bsth.Application;
  4 +import com.bsth.data.gpsdata.analyse.GeoCacheData;
4 5 import com.bsth.entity.*;
5 6 import com.bsth.entity.schedule.CarConfigInfo;
6 7 import com.bsth.repository.*;
... ... @@ -57,7 +58,7 @@ public class BasicData implements CommandLineRunner {
57 58 public static Map<String, String> lineCode2NameMap;
58 59  
59 60 //线路编码_站点编码 == 0|1 上下行
60   - public static Map<String, Integer> lineStationUpDownMap;
  61 + //public static Map<String, Integer> lineStationUpDownMap;
61 62  
62 63 //停车场
63 64 public static List<String> parkCodeList;
... ... @@ -86,7 +87,7 @@ public class BasicData implements CommandLineRunner {
86 87  
87 88 @Override
88 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 118 @Autowired
118 119 BusinessRepository businessRepository;
119 120  
  121 + @Autowired
  122 + GeoCacheData geoCacheData;
  123 +
120 124  
121 125 @Override
122 126 public void run() {
... ... @@ -138,11 +142,13 @@ public class BasicData implements CommandLineRunner {
138 142 //车辆和线路映射信息
139 143 loadNbbm2LineInfo();
140 144 //站点路由信息
141   - loadStationRouteInfo();
  145 + //loadStationRouteInfo();
142 146 //人员信息
143 147 loadPersonnelInfo();
144 148 //公司信息
145 149 loadBusinessInfo();
  150 +
  151 + geoCacheData.loadData();
146 152 logger.info("加载基础数据成功!,");
147 153 } catch (Exception e) {
148 154 logger.error("加载基础数据时出现异常,", e);
... ... @@ -151,7 +157,7 @@ public class BasicData implements CommandLineRunner {
151 157 }
152 158  
153 159  
154   - private void loadStationRouteInfo() {
  160 +/* private void loadStationRouteInfo() {
155 161 Iterator<StationRoute> iterator = stationRouteRepository.findAllEffective().iterator();
156 162  
157 163 Map<String, String> sePointMap = new HashMap<>();
... ... @@ -172,7 +178,7 @@ public class BasicData implements CommandLineRunner {
172 178 }
173 179 lineStationUpDownMap = map;
174 180 lineSEPointMap = sePointMap;
175   - }
  181 + }*/
176 182  
177 183 /**
178 184 * loadBusinessInfo
... ... @@ -280,7 +286,7 @@ public class BasicData implements CommandLineRunner {
280 286 /**
281 287 * 加载运管处的站点及序号
282 288 * 上行从1开始,下行顺序续编
283   - */
  289 +
284 290 List<Object[]> ygcLines = stationRouteRepository.findAllLineWithYgc();
285 291 if(ygcLines != null && ygcLines.size() > 0){
286 292 int size = ygcLines.size();
... ... @@ -299,7 +305,7 @@ public class BasicData implements CommandLineRunner {
299 305 key = tempArray[0] + "_"+tempArray[1] + "_"+tempArray[2];
300 306 tempStationName2YgcNumber.put(key,num++);
301 307 }
302   - }
  308 + }*/
303 309 }
304 310  
305 311 lineId2CodeMap = biMap;
... ...
src/main/java/com/bsth/data/arrival/AnalyseData.java
1 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 3 import org.slf4j.Logger;
9 4 import org.slf4j.LoggerFactory;
10 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 96 }
99 97  
100 98 private boolean effective(ArrivalEntity arr){
101   - //停车场
  99 + /*//停车场
102 100 if(BasicData.parkCodeList.contains(arr.getStopNo())){
103 101 arr.setTcc(true);
104 102 return true;
105 103 }
106   -
  104 +
107 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 70 /* public void forecast(String nbbm){
71 71 logger.info("预测," + nbbm);
72 72 //当前执行班次
73   - ScheduleRealInfo sch = dayOfSchedule.execPlamMap().get(nbbm);
  73 + ScheduleRealInfo sch = dayOfSchedule.execPlanMap().get(nbbm);
74 74 if(null == sch)
75 75 return;
76 76  
... ... @@ -86,7 +86,7 @@ public class ForecastRealServer implements CommandLineRunner {
86 86 //终点站
87 87 String eStation = null;
88 88 //当前执行班次
89   - ScheduleRealInfo sch = dayOfSchedule.execPlamMap().get(nbbm);
  89 + ScheduleRealInfo sch = dayOfSchedule.execPlanMap().get(nbbm);
90 90 if(null != sch)
91 91 eStation = sch.getZdzCode();
92 92  
... ...
src/main/java/com/bsth/data/gpsdata/GpsEntity.java
1 1 package com.bsth.data.gpsdata;
2 2  
  3 +import com.bsth.data.gpsdata.analyse.StationRoute;
  4 +import com.fasterxml.jackson.annotation.JsonIgnore;
  5 +
3 6 /**
4 7 *
5 8 * @ClassName: GpsRealData
... ... @@ -58,21 +61,32 @@ public class GpsEntity {
58 61 /** 预计到达终点时间 */
59 62 private Float expectStopTime;
60 63  
61   - /** 设备是否在线 */
  64 + /** 设备是否在线
62 65 private boolean online;
63   -
  66 + */
64 67 /** 当前执行班次ID */
65 68 private Long schId;
66 69  
67 70 /** 是否异常数据 */
68 71 private boolean abnormal;
69   -
70   - private int valid;
  72 +/*
  73 + private int valid;*/
71 74  
72 75 private int version;
73 76  
74   - /** 是否起终点站 */
  77 + /** 是否起终点站
75 78 private boolean sEPoint;
  79 + */
  80 +
  81 + /** 站内 */
  82 + private boolean instation;
  83 +
  84 + /** 站点信息,站内时有值 */
  85 + @JsonIgnore
  86 + private StationRoute station;
  87 +
  88 + /** 状态 */
  89 + private String state2;
76 90  
77 91 public Integer getCompanyCode() {
78 92 return companyCode;
... ... @@ -178,14 +192,6 @@ public class GpsEntity {
178 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 195 public long getArrTime() {
190 196 return arrTime;
191 197 }
... ... @@ -218,35 +224,44 @@ public class GpsEntity {
218 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 boolean isInstation() {
  237 + return instation;
231 238 }
232 239  
233   - public void setValid(int valid) {
234   - this.valid = valid;
  240 + public void setInstation(boolean instation) {
  241 + this.instation = instation;
235 242 }
236 243  
237   - public int getVersion() {
238   - return version;
  244 + public StationRoute getStation() {
  245 + return station;
239 246 }
240 247  
241   - public void setVersion(int version) {
242   - this.version = version;
  248 + public void setStation(StationRoute station) {
  249 + this.station = station;
  250 + }
  251 +
  252 + public boolean isAbnormal() {
  253 + return abnormal;
  254 + }
  255 +
  256 + public void setAbnormal(boolean abnormal) {
  257 + this.abnormal = abnormal;
243 258 }
244 259  
245   - public boolean issEPoint() {
246   - return sEPoint;
  260 + public String getState2() {
  261 + return state2;
247 262 }
248 263  
249   - public void setsEPoint(boolean sEPoint) {
250   - this.sEPoint = sEPoint;
  264 + public void setState2(String state2) {
  265 + this.state2 = state2;
251 266 }
252 267 }
... ...
src/main/java/com/bsth/data/gpsdata/GpsRealData.java
... ... @@ -5,6 +5,8 @@ import com.alibaba.fastjson.JSONObject;
5 5 import com.bsth.Application;
6 6 import com.bsth.data.BasicData;
7 7 import com.bsth.data.forecast.ForecastRealServer;
  8 +import com.bsth.data.gpsdata.analyse.GpsAnalyse;
  9 +import com.bsth.data.gpsdata.recovery.GpsDataRecovery;
8 10 import com.bsth.data.schedule.DayOfSchedule;
9 11 import com.bsth.entity.realcontrol.ScheduleRealInfo;
10 12 import com.bsth.util.ConfigUtil;
... ... @@ -55,6 +57,9 @@ public class GpsRealData implements CommandLineRunner{
55 57  
56 58 @Autowired
57 59 ForecastRealServer forecastRealServer;
  60 +
  61 +
  62 +
58 63 /**
59 64 * 构造函数
60 65 */
... ... @@ -67,13 +72,17 @@ public class GpsRealData implements CommandLineRunner{
67 72 @Override
68 73 public void run(String... arg0) throws Exception {
69 74 logger.info("gpsDataLoader,20,6");
70   - Application.mainServices.scheduleWithFixedDelay(gpsDataLoader, 20, 5, TimeUnit.SECONDS);
  75 + Application.mainServices.scheduleWithFixedDelay(gpsDataLoader, 40, 20, TimeUnit.SECONDS);
71 76 }
72 77  
73 78 public GpsEntity add(GpsEntity gps) {
74 79 String device = gps.getDeviceId();
75 80 GpsEntity old = gpsMap.get(device);
76 81  
  82 + //分析gps
  83 + if(isAvailable(gps) && (old == null || old.getTimestamp() != gps.getTimestamp()))
  84 + GpsAnalyse.start(gps);
  85 +
77 86 if(!StringUtils.isEmpty(gps.getStopNo())){
78 87 //定时定距数据附带站点编码改变
79 88 if(null == old || !gps.getStopNo().equals(old.getStopNo())){
... ... @@ -94,6 +103,11 @@ public class GpsRealData implements CommandLineRunner{
94 103 return gps;
95 104 }
96 105  
  106 + public boolean isAvailable(GpsEntity gps){
  107 + return StringUtils.isNotEmpty(gps.getLineId()) &&
  108 + dayOfSchedule.getCurrSchDate().containsKey(gps.getLineId());
  109 + }
  110 +
97 111 /**
98 112 *
99 113 * @Title: get @Description: TODO(设备号获取GPS)
... ... @@ -118,7 +132,7 @@ public class GpsRealData implements CommandLineRunner{
118 132 if(gps.isAbnormal())
119 133 continue;
120 134  
121   - sch = dayOfSchedule.execPlamMap().get(gps.getNbbm());
  135 + sch = dayOfSchedule.execPlanMap().get(gps.getNbbm());
122 136 if(null != sch)
123 137 gps.setSchId(sch.getId());
124 138 rs.add(gps);
... ... @@ -161,6 +175,11 @@ public class GpsRealData implements CommandLineRunner{
161 175 @Override
162 176 public void run() {
163 177 try{
  178 + //如果正在恢复数据
  179 + if(GpsDataRecovery.run){
  180 + return;
  181 + }
  182 +
164 183 load();
165 184 }catch(Exception e){
166 185 logger.error("", e);
... ... @@ -207,21 +226,7 @@ public class GpsRealData implements CommandLineRunner{
207 226 gpsRealData.add(gps);
208 227  
209 228 //纠正走向
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   - }*/
  229 + //correctUpdown(gps);
225 230 }
226 231 } else
227 232 logger.error("result is null");
... ... @@ -240,7 +245,7 @@ public class GpsRealData implements CommandLineRunner{
240 245 * 是否是起终点
241 246 * @param gps
242 247 * @return
243   - */
  248 +
244 249 public boolean isSEPoint(GpsEntity gps){
245 250 String key = gps.getLineId()+"_"+gps.getUpDown()+"_"
246 251 ,stationCode;
... ... @@ -261,29 +266,19 @@ public class GpsRealData implements CommandLineRunner{
261 266 }
262 267 }
263 268 return false;
264   - }
  269 + }*/
265 270  
266 271 /**
267 272 * 纠正上下行
268 273 * @param gps
269   - */
  274 +
270 275 public void correctUpdown(GpsEntity gps){
271 276 Integer updown=BasicData.lineStationUpDownMap.get(gps.getLineId()+"_"+gps.getStopNo());
272 277 if(updown != null && !updown.equals(gps.getUpDown()))
273 278 gps.setUpDown(updown);
274   - /*//如果走向未知,尝试根据站点纠正走向
275   - if(gps.getUpDown() == -1){
276   -
277   - }*/
278 279  
279 280 if(isSEPoint(gps))
280 281 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   - }
  282 + }*/
288 283 }
289 284 }
... ...
src/main/java/com/bsth/data/gpsdata/analyse/CircleQueue.java 0 → 100644
  1 +package com.bsth.data.gpsdata.analyse;
  2 +
  3 +import java.util.Arrays;
  4 +
  5 +/**
  6 + * 循环队列
  7 + * Created by panzhao on 2016/12/23.
  8 + */
  9 +public class CircleQueue<T> {
  10 +
  11 + /**
  12 + * (循环队列)数组的容量
  13 + */
  14 + public int capacity;
  15 +
  16 + /**
  17 + * 数组:保存循环队列的元素
  18 + */
  19 + public Object[] elementData;
  20 +
  21 + /**
  22 + * 队头(先进先出)
  23 + */
  24 + public int head = 0;
  25 +
  26 + /**
  27 + * 队尾
  28 + */
  29 + public int tail = 0;
  30 +
  31 + /**
  32 + * 以指定长度的数组来创建循环队列
  33 + *
  34 + * @param initSize
  35 + */
  36 + public CircleQueue(final int initSize) {
  37 + capacity = initSize;
  38 + elementData = new Object[capacity];
  39 + }
  40 +
  41 + /**
  42 + * 获取循环队列的大小(包含元素的个数)
  43 + */
  44 + public int size() {
  45 + if (isEmpty()) {
  46 + return 0;
  47 + } else if (isFull()) {
  48 + return capacity;
  49 + } else {
  50 + return tail + 1;
  51 + }
  52 + }
  53 +
  54 + /**
  55 + * 插入队尾一个元素
  56 + */
  57 + public void add(final T element) {
  58 + if (isEmpty()) {
  59 + elementData[0] = element;
  60 + } else if (isFull()) {
  61 + elementData[head] = element;
  62 + head++;
  63 + tail++;
  64 + head = head == capacity ? 0 : head;
  65 + tail = tail == capacity ? 0 : tail;
  66 + } else {
  67 + elementData[tail + 1] = element;
  68 + tail++;
  69 + }
  70 + }
  71 +
  72 + public boolean isEmpty() {
  73 + return tail == head && tail == 0 && elementData[tail] == null;
  74 + }
  75 +
  76 + public boolean isFull() {
  77 + return head != 0 && head - tail == 1 || head == 0 && tail == capacity - 1;
  78 + }
  79 +
  80 + public void clear() {
  81 + Arrays.fill(elementData, null);
  82 + head = 0;
  83 + tail = 0;
  84 + }
  85 +
  86 + /**
  87 + * @return 取 循环队列里的值(先进的index=0)
  88 + */
  89 + public Object[] getQueue() {
  90 + final Object[] elementDataSort = new Object[capacity];
  91 + final Object[] elementDataCopy = elementData.clone();
  92 + if (isEmpty()) {
  93 + } else if (isFull()) {
  94 + int indexMax = capacity;
  95 + int indexSort = 0;
  96 + for (int i = head; i < indexMax;) {
  97 + elementDataSort[indexSort] = elementDataCopy[i];
  98 + indexSort++;
  99 + i++;
  100 + if (i == capacity) {
  101 + i = 0;
  102 + indexMax = head;
  103 + }
  104 + }
  105 + } else {
  106 + for (int i = 0; i < tail; i++) {
  107 + elementDataSort[i] = elementDataCopy[i];
  108 + }
  109 + }
  110 + return elementDataSort;
  111 + }
  112 +
  113 + public T getTail(){
  114 + return elementData[tail] == null?null:(T)elementData[tail];
  115 + }
  116 +}
0 117 \ No newline at end of file
... ...
src/main/java/com/bsth/data/gpsdata/analyse/GeoCacheData.java 0 → 100644
  1 +package com.bsth.data.gpsdata.analyse;
  2 +
  3 +import com.bsth.data.gpsdata.GpsEntity;
  4 +import com.google.common.collect.ArrayListMultimap;
  5 +import com.vividsolutions.jts.geom.Coordinate;
  6 +import com.vividsolutions.jts.geom.GeometryFactory;
  7 +import com.vividsolutions.jts.geom.LineString;
  8 +import com.vividsolutions.jts.geom.Polygon;
  9 +import org.apache.commons.lang3.StringUtils;
  10 +import org.slf4j.Logger;
  11 +import org.slf4j.LoggerFactory;
  12 +import org.springframework.beans.factory.annotation.Autowired;
  13 +import org.springframework.jdbc.core.JdbcTemplate;
  14 +import org.springframework.jdbc.core.RowMapper;
  15 +import org.springframework.stereotype.Component;
  16 +
  17 +import java.sql.ResultSet;
  18 +import java.sql.SQLException;
  19 +import java.util.*;
  20 +
  21 +/**
  22 + * Created by panzhao on 2016/12/23.
  23 + */
  24 +@Component
  25 +public class GeoCacheData {
  26 +
  27 + static Logger logger = LoggerFactory.getLogger(GeoCacheData.class);
  28 +
  29 + //每辆车缓存最后200条gps
  30 + private static final int CACHE_SIZE = 200;
  31 + private static Map<String, CircleQueue<GpsEntity>> gpsCacheMap = new HashMap<>();
  32 +
  33 + //线路路段走向
  34 + private static ArrayListMultimap<String, LineString> sectionCacheMap;
  35 +
  36 + //线路站点路由
  37 + private static ArrayListMultimap<String, StationRoute> stationCacheMap;
  38 +
  39 + //停车场
  40 + public static Map<String, Polygon> tccMap;
  41 +
  42 + @Autowired
  43 + JdbcTemplate jdbcTemplate;
  44 +
  45 + public static CircleQueue<GpsEntity> getGps(String nbbm) {
  46 + return gpsCacheMap.get(nbbm);
  47 + }
  48 +
  49 + public static void putGps(GpsEntity gps) {
  50 + CircleQueue<GpsEntity> queue = gpsCacheMap.get(gps.getNbbm());
  51 + if (queue == null) {
  52 + //第一个点从站内开始
  53 + if(!gps.isInstation())
  54 + return;
  55 +
  56 + queue = new CircleQueue<>(CACHE_SIZE);
  57 + gpsCacheMap.put(gps.getNbbm(), queue);
  58 + }
  59 + queue.add(gps);
  60 + }
  61 +
  62 + public static List<StationRoute> getStationRoute(String lineCode, int directions) {
  63 + return stationCacheMap.get(lineCode + "_" + directions);
  64 + }
  65 +
  66 + public static StationRoute getStation(String lineCode, int directions, String code) {
  67 + List<StationRoute> list = getStationRoute(lineCode, directions);
  68 +
  69 + for (StationRoute sr : list) {
  70 + if (sr.getCode().equals(code)) {
  71 + return sr;
  72 + }
  73 + }
  74 + return null;
  75 + }
  76 +
  77 + public static Polygon getTccPolygon(String code){
  78 + return tccMap.get(code);
  79 + }
  80 +
  81 + public void loadData() {
  82 + final GeometryFactory geometryFactory = new GeometryFactory();
  83 + //加载站点路由
  84 + String sql = "select r.LINE_CODE,r.DIRECTIONS,r.STATION_CODE,r.STATION_MARK,s.SHAPES_TYPE,s.G_LONX,s.G_LATY,ST_AsText(s.G_POLYGON_GRID) as G_POLYGON_GRID,s.RADIUS, r.STATION_ROUTE_CODE from bsth_c_stationroute r left join bsth_c_station s on r.station=s.id where r.destroy=0 order by r.station_route_code";
  85 + List<StationRoute> routeList = jdbcTemplate.query(sql, new RowMapper<StationRoute>() {
  86 + @Override
  87 + public StationRoute mapRow(ResultSet rs, int rowNum) throws SQLException {
  88 + StationRoute sRoute = new StationRoute();
  89 + sRoute.setCode(rs.getString("STATION_CODE"));
  90 + sRoute.setLineCode(rs.getString("LINE_CODE"));
  91 + sRoute.setDirections(rs.getInt("DIRECTIONS"));
  92 + sRoute.setPoint(geometryFactory.createPoint(new Coordinate(rs.getFloat("G_LATY"), rs.getFloat("G_LONX"))));
  93 + sRoute.setRadius(rs.getFloat("RADIUS"));
  94 + sRoute.setRouteSort(rs.getInt("STATION_ROUTE_CODE"));
  95 + sRoute.setMark(rs.getString("STATION_MARK"));
  96 +
  97 + String shapesType = rs.getString("SHAPES_TYPE");
  98 + //多边形电子围栏
  99 + if (StringUtils.isNotEmpty(shapesType) && shapesType.equals("d")) {
  100 + geometryFactory.createPolygon(parsePolygon(rs.getString("G_POLYGON_GRID")));
  101 + }
  102 + return sRoute;
  103 + }
  104 + });
  105 + //按线路和走向分组
  106 + if (routeList.size() > 0) {
  107 + ArrayListMultimap<String, StationRoute> tempMap = ArrayListMultimap.create();
  108 + for (StationRoute sr : routeList) {
  109 + tempMap.put(sr.getLineCode() + "_" + sr.getDirections(), sr);
  110 + }
  111 +
  112 + StationRouteComp srCom = new StationRouteComp();
  113 + //连接路由
  114 + Set<String> set = tempMap.keySet();
  115 + for (String key : set) {
  116 + Collections.sort(tempMap.get(key), srCom);
  117 + connectStationRoute(tempMap.get(key));
  118 + }
  119 +
  120 + stationCacheMap = tempMap;
  121 + }
  122 +
  123 + //加载停车场数据
  124 + sql = "select PARK_CODE, ST_AsText(G_PARK_POINT) as G_PARK_POINT from bsth_c_car_park where park_code is not null and b_park_point is not null";
  125 + List<Map<String, Object>> tccList = jdbcTemplate.queryForList(sql);
  126 + Map<String, Polygon> tccTempMap = new HashMap<>();
  127 +
  128 + Polygon polygon;
  129 + for (Map<String, Object> tMap : tccList) {
  130 +
  131 + try {
  132 + polygon = geometryFactory.createPolygon(parsePolygon(tMap.get("G_PARK_POINT").toString()));
  133 + tccTempMap.put(tMap.get("PARK_CODE").toString()
  134 + , polygon);
  135 + } catch (Exception e) {
  136 + logger.error("停车场:" + tMap.get("PARK_CODE") , e);
  137 + }
  138 + }
  139 +
  140 + if(tccTempMap.size() > 0)
  141 + tccMap = tccTempMap;
  142 + }
  143 +
  144 + private void connectStationRoute(List<StationRoute> list) {
  145 + int size = list.size();
  146 + StationRoute sr = null;
  147 + for (int i = 0; i < size; i++) {
  148 + sr = list.get(i);
  149 + //上一个
  150 + if (i > 0)
  151 + sr.setPrve(list.get(i - 1));
  152 + //下一个
  153 + if (i < size - 1)
  154 + sr.setNext(list.get(i + 1));
  155 + }
  156 + }
  157 +
  158 + public Coordinate[] parsePolygon(String polygonStr) {
  159 + String[] coords = polygonStr.substring(9, polygonStr.length() - 2).split(","), temps;
  160 +
  161 + Coordinate[] cds = new Coordinate[coords.length];
  162 + int len = coords.length;
  163 + for (int i = 0; i < len; i++) {
  164 + temps = coords[i].split(" ");
  165 + cds[i] = new Coordinate(Float.parseFloat(temps[1]), Float.parseFloat(temps[0]));
  166 + }
  167 + return cds;
  168 + }
  169 +
  170 +}
0 171 \ No newline at end of file
... ...
src/main/java/com/bsth/data/gpsdata/analyse/GpsAnalyse.java 0 → 100644
  1 +package com.bsth.data.gpsdata.analyse;
  2 +
  3 +import com.bsth.data.gpsdata.GpsEntity;
  4 +import com.bsth.data.gpsdata.analyse.components.GpsArrival;
  5 +import org.slf4j.Logger;
  6 +import org.slf4j.LoggerFactory;
  7 +
  8 +import java.util.concurrent.ExecutorService;
  9 +import java.util.concurrent.Executors;
  10 +
  11 +/**
  12 + * 分析gps状态信息
  13 + * Created by panzhao on 2016/12/23.
  14 + */
  15 +public class GpsAnalyse {
  16 +
  17 + static Logger logger = LoggerFactory.getLogger(GpsAnalyse.class);
  18 +
  19 + //线程池
  20 + static ExecutorService threadPool = Executors.newFixedThreadPool(50);
  21 +
  22 + public static void start(GpsEntity gps) {
  23 + threadPool.execute(new ArrivalMatchThread(gps));
  24 + }
  25 +
  26 + public static class ArrivalMatchThread implements Runnable {
  27 +
  28 + private GpsEntity gps;
  29 +
  30 + public ArrivalMatchThread(GpsEntity gps) {
  31 + this.gps = gps;
  32 + }
  33 +
  34 + @Override
  35 + public void run() {
  36 + GpsArrival.arrival(gps);
  37 + }
  38 + }
  39 +}
0 40 \ No newline at end of file
... ...
src/main/java/com/bsth/data/gpsdata/analyse/StationRoute.java 0 → 100644
  1 +package com.bsth.data.gpsdata.analyse;
  2 +
  3 +import com.vividsolutions.jts.geom.Point;
  4 +import com.vividsolutions.jts.geom.Polygon;
  5 +
  6 +/**
  7 + * Created by panzhao on 2016/12/23.
  8 + */
  9 +public class StationRoute {
  10 +
  11 + /**
  12 + * 线路编码
  13 + */
  14 + private String lineCode;
  15 +
  16 + /**
  17 + * 上下行
  18 + */
  19 + private int directions;
  20 +
  21 + /**
  22 + * 站点编码
  23 + */
  24 + private String code;
  25 +
  26 + /**
  27 + * 路由顺序
  28 + */
  29 + private int routeSort;
  30 +
  31 + /**
  32 + * 站点位置
  33 + */
  34 + private Point point;
  35 +
  36 + /**
  37 + * 圆形半径
  38 + */
  39 + private Float radius;
  40 +
  41 + /**
  42 + * 多边形电子围栏
  43 + */
  44 + private Polygon polygon;
  45 +
  46 + /**
  47 + * 站点标记
  48 + */
  49 + private String mark;
  50 +
  51 + /**
  52 + * 下一站
  53 + */
  54 + private StationRoute next;
  55 +
  56 + /**
  57 + * 上一站
  58 + */
  59 + private StationRoute prve;
  60 +
  61 + public String getCode() {
  62 + return code;
  63 + }
  64 +
  65 + public void setCode(String code) {
  66 + this.code = code;
  67 + }
  68 +
  69 + public int getRouteSort() {
  70 + return routeSort;
  71 + }
  72 +
  73 + public void setRouteSort(int routeSort) {
  74 + this.routeSort = routeSort;
  75 + }
  76 +
  77 + public Point getPoint() {
  78 + return point;
  79 + }
  80 +
  81 + public void setPoint(Point point) {
  82 + this.point = point;
  83 + }
  84 +
  85 + public Float getRadius() {
  86 + return radius;
  87 + }
  88 +
  89 + public void setRadius(Float radius) {
  90 + this.radius = radius;
  91 + }
  92 +
  93 + public Polygon getPolygon() {
  94 + return polygon;
  95 + }
  96 +
  97 + public void setPolygon(Polygon polygon) {
  98 + this.polygon = polygon;
  99 + }
  100 +
  101 + public String getLineCode() {
  102 + return lineCode;
  103 + }
  104 +
  105 + public void setLineCode(String lineCode) {
  106 + this.lineCode = lineCode;
  107 + }
  108 +
  109 + public int getDirections() {
  110 + return directions;
  111 + }
  112 +
  113 + public void setDirections(int directions) {
  114 + this.directions = directions;
  115 + }
  116 +
  117 + public StationRoute getNext() {
  118 + return next;
  119 + }
  120 +
  121 + public void setNext(StationRoute next) {
  122 + this.next = next;
  123 + }
  124 +
  125 + public StationRoute getPrve() {
  126 + return prve;
  127 + }
  128 +
  129 + public void setPrve(StationRoute prve) {
  130 + this.prve = prve;
  131 + }
  132 +
  133 + public String getMark() {
  134 + return mark;
  135 + }
  136 +
  137 + public void setMark(String mark) {
  138 + this.mark = mark;
  139 + }
  140 +}
  141 +
... ...
src/main/java/com/bsth/data/gpsdata/analyse/StationRouteComp.java 0 → 100644
  1 +package com.bsth.data.gpsdata.analyse;
  2 +
  3 +import java.util.Comparator;
  4 +
  5 +/**
  6 + * Created by panzhao on 2016/12/24.
  7 + */
  8 +public class StationRouteComp implements Comparator<StationRoute>{
  9 + @Override
  10 + public int compare(StationRoute s1, StationRoute s2) {
  11 + return s1.getRouteSort() - s2.getRouteSort();
  12 + }
  13 +}
... ...
src/main/java/com/bsth/data/gpsdata/analyse/components/GpsArrival.java 0 → 100644
  1 +package com.bsth.data.gpsdata.analyse.components;
  2 +
  3 +import com.bsth.data.LineConfigData;
  4 +import com.bsth.data.gpsdata.GpsEntity;
  5 +import com.bsth.data.gpsdata.analyse.CircleQueue;
  6 +import com.bsth.data.gpsdata.analyse.GeoCacheData;
  7 +import com.bsth.data.gpsdata.analyse.StationRoute;
  8 +import com.bsth.data.gpsdata.analyse.util.GeoUtils;
  9 +import com.bsth.data.schedule.DayOfSchedule;
  10 +import com.bsth.entity.realcontrol.LineConfig;
  11 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  12 +import org.slf4j.Logger;
  13 +import org.slf4j.LoggerFactory;
  14 +import org.springframework.beans.BeansException;
  15 +import org.springframework.context.ApplicationContext;
  16 +import org.springframework.context.ApplicationContextAware;
  17 +import org.springframework.stereotype.Component;
  18 +
  19 +import java.util.List;
  20 +
  21 +/**
  22 + * gps 到离站判断
  23 + * Created by panzhao on 2016/12/24.
  24 + */
  25 +@Component
  26 +public class GpsArrival implements ApplicationContextAware {
  27 +
  28 + static Logger logger = LoggerFactory.getLogger(GpsArrival.class);
  29 +
  30 + static DayOfSchedule dayOfSchedule;
  31 +
  32 + static LineConfigData lineConfigData;
  33 +
  34 + public static void arrival(GpsEntity gps) {
  35 +
  36 + if (gps.getLat() == 0 || gps.getLon() == 0) {
  37 + //logger.error("无效的gps");
  38 + return;
  39 + }
  40 +
  41 + Object task = DayOfSchedule.executeCurr(gps.getNbbm());
  42 + if (task == null)
  43 + return;
  44 + if (task.getClass().isAssignableFrom(ScheduleRealInfo.class)) {
  45 + ScheduleRealInfo sch = (ScheduleRealInfo) task;
  46 + //和班次同步走向
  47 + gps.setUpDown(Integer.parseInt(sch.getXlDir()));
  48 +
  49 + //出场
  50 + if (sch.getBcType().equals("out")) {
  51 + outCarpark(gps, sch);
  52 + }
  53 + else if (sch.getBcType().equals("normal"))
  54 + normalInOut(gps, sch);
  55 + else if(sch.getBcType().equals("in")){
  56 + inCarpark(gps, sch);
  57 + }
  58 + }
  59 +
  60 + GeoCacheData.putGps(gps);
  61 + }
  62 +
  63 + /**
  64 + * 正常班次
  65 + *
  66 + * @param gps
  67 + * @param sch
  68 + */
  69 + private static void normalInOut(GpsEntity gps, ScheduleRealInfo sch) {
  70 + CircleQueue<GpsEntity> queue = GeoCacheData.getGps(gps.getNbbm());
  71 + GpsEntity prev = null;
  72 + if (queue != null)
  73 + prev = queue.getTail();
  74 +
  75 + List<StationRoute> srs = GeoCacheData.getStationRoute(sch.getXlBm(), gps.getUpDown());
  76 + StationRoute station = GeoUtils.gpsInStation(gps, srs);
  77 +
  78 + if (station != null) {
  79 + //站内
  80 + gps.setStopNo(station.getCode());
  81 + gps.setInstation(true);
  82 + stationInside(gps, prev, sch);
  83 + } else {
  84 + //站外
  85 + stationOutside(gps, prev, sch);
  86 + }
  87 + }
  88 +
  89 + /**
  90 + * GPS在站点内
  91 + *
  92 + * @param gps
  93 + * @param prev
  94 + * @param sch
  95 + */
  96 + private static void stationInside(GpsEntity gps, GpsEntity prev, ScheduleRealInfo sch) {
  97 + if(prev == null)
  98 + return;
  99 +
  100 + if (gps.getStopNo().equals(sch.getZdzCode()) && sch.getZdsjActual() == null) {
  101 + //到终点站
  102 + arriveEnd(sch, gps);
  103 + return;
  104 + }
  105 +
  106 + //上一个点在站外
  107 + if(!prev.isInstation())
  108 + return;
  109 + //超过 (待发时间 + 90%的单程运送时间),还在起点站。默认烂一圈
  110 + if (prev.getStopNo().equals(gps.getStopNo())){
  111 + if(gps.getStopNo().equals(sch.getQdzCode())
  112 + && gps.getTimestamp() > sch.getDfsjT() + (sch.getBcsj() * 60 * 1000 * 0.9)){
  113 +
  114 + ScheduleRealInfo next = dayOfSchedule.next(dayOfSchedule.next(sch));
  115 + dayOfSchedule.addExecPlan(next);
  116 + }
  117 + return;
  118 + }
  119 +
  120 + //发车
  121 + if (prev.getStopNo().equals(sch.getQdzCode())) {
  122 + busWillDepart(sch, gps);
  123 + return;
  124 + }
  125 +
  126 + //中途站
  127 + StationRoute prevStation = GeoCacheData.getStation(prev.getLineId(), prev.getUpDown(), prev.getStopNo());
  128 + StationRoute currStation = GeoCacheData.getStation(gps.getLineId(), gps.getUpDown(), gps.getStopNo());
  129 + if (currStation.getRouteSort() < prevStation.getRouteSort()) {
  130 + //开始下一个班次
  131 + finishPlan(sch);
  132 +
  133 + logger.info("路由反向。。。。。。:" + gps.getTimestamp());
  134 + //为班次补上实际时间
  135 +
  136 + }
  137 + }
  138 +
  139 + /**
  140 + * GPS在站点外
  141 + *
  142 + * @param gps
  143 + * @param prev
  144 + * @param sch
  145 + */
  146 + private static void stationOutside(GpsEntity gps, GpsEntity prev, ScheduleRealInfo sch) {
  147 + if(prev == null)
  148 + return;
  149 +
  150 + gps.setStopNo(prev.getStopNo());
  151 + if (prev.isInstation() && prev.getStopNo().equals(sch.getQdzCode())) {
  152 + //发车
  153 + busWillDepart(sch, gps);
  154 + return;
  155 + }
  156 + }
  157 +
  158 + /**
  159 + * 公交车起点发出
  160 + */
  161 + final static long DRIFT_VAL_TIME = 1000 * 60 * 10;
  162 + //班次最大差值1小时
  163 + final static long MAX_DIFF = 1000 * 60 * 60;
  164 + private static void busWillDepart(ScheduleRealInfo sch, GpsEntity gps) {
  165 + //实发时间不覆盖
  166 + if (sch.getFcsjActual() == null && Math.abs(gps.getTimestamp() - sch.getDfsjT()) < MAX_DIFF) {
  167 +
  168 + //提前10分钟以上发出,判断一下是否是漂移
  169 + if(sch.getDfsjT() - gps.getTimestamp() > DRIFT_VAL_TIME){
  170 + ScheduleRealInfo schPrev = dayOfSchedule.prev(sch);
  171 + if(schPrev != null && schPrev.getZdsjActual() != null){
  172 + //计划停站时间
  173 + long stopTimeJH = sch.getDfsjT() - schPrev.getZdsjT();
  174 + //实际停站时间
  175 + long actualStopTime = gps.getTimestamp() - schPrev.getZdsjActualTime();
  176 + /*
  177 + 没停够计划百分之60的,算漂移
  178 + (这里出现的误判,由程序在车辆到中途站的时候进行补偿)
  179 + */
  180 + if(stopTimeJH * 0.6 < actualStopTime){
  181 + logger.info("漂移.... 车辆:" + gps.getNbbm() + " ts: " + gps.getTimestamp());
  182 + return;
  183 + }
  184 + }
  185 + }
  186 +
  187 + LineConfig config = lineConfigData.get(sch.getXlBm());
  188 + if(config != null && config.getOutConfig() == 2){
  189 + //出站既出场
  190 + ScheduleRealInfo schPrev = dayOfSchedule.prev(sch);
  191 + if(schPrev.getBcType().equals("out")){
  192 + schPrev.setFcsjActualAll(schPrev.getDfsjT());
  193 + schPrev.setZdsjActualAll(schPrev.getZdsjT());
  194 + }
  195 + }
  196 +
  197 + sch.setFcsjActualAll(gps.getTimestamp());
  198 + logger.info("(站外)班次:" + sch.getDfsj() + "发车, 时间:" + sch.getFcsjActual());
  199 + }
  200 + }
  201 +
  202 + /**
  203 + * 公交车到达终点
  204 + *
  205 + * @param sch
  206 + * @param gps
  207 + */
  208 + private static void arriveEnd(ScheduleRealInfo sch, GpsEntity gps) {
  209 + sch.setZdsjActualAll(gps.getTimestamp());
  210 + ScheduleRealInfo next = finishPlan(sch);
  211 + logger.info("班次:" + sch.getDfsj() + "到达终点, 时间:" + sch.getZdsjActual());
  212 +
  213 + if (next == null)
  214 + return;
  215 +
  216 + //将gps转换为下一个班次走向的站内信号
  217 + int updown = Integer.parseInt(next.getXlDir());
  218 + List<StationRoute> srs = GeoCacheData.getStationRoute(next.getXlBm(), updown);
  219 + StationRoute station = GeoUtils.gpsInStation(gps, srs);
  220 + if (station != null) {
  221 + gps.setUpDown(updown);
  222 + gps.setStopNo(station.getCode());
  223 + }
  224 + }
  225 +
  226 + /**
  227 + * 出场班次
  228 + *
  229 + * @param gps
  230 + * @param sch
  231 + */
  232 + private static void outCarpark(GpsEntity gps, ScheduleRealInfo sch) {
  233 + String carpark = GeoUtils.gpsInCarpark(gps);
  234 + if (carpark != null) {
  235 + gps.setInstation(true);
  236 + gps.setStopNo(carpark);
  237 + return; // 还在场内
  238 + }
  239 +
  240 + CircleQueue<GpsEntity> queue = GeoCacheData.getGps(gps.getNbbm());
  241 + if (queue == null)
  242 + return;
  243 + //上一个gps
  244 + GpsEntity prev = queue.getTail();
  245 +
  246 + if (carpark == null && prev.isInstation() && prev.getStopNo().equals(sch.getQdzCode())) {
  247 + gps.setStopNo(prev.getStopNo());
  248 + //停车场发出
  249 + busWillDepart(sch, gps);
  250 + return;
  251 + }
  252 +
  253 + List<StationRoute> srs = GeoCacheData.getStationRoute(sch.getXlBm(), gps.getUpDown());
  254 + StationRoute station = GeoUtils.gpsInStation(gps, srs);
  255 +
  256 + if (station != null && station.getCode().equals(sch.getZdzCode())) {
  257 + gps.setStopNo(station.getCode());
  258 + //到达终点
  259 + arriveEnd(sch, gps);
  260 + }
  261 + }
  262 +
  263 +
  264 + /**
  265 + * 进场班次
  266 + * @param gps
  267 + * @param sch
  268 + */
  269 + private static void inCarpark(GpsEntity gps, ScheduleRealInfo sch) {
  270 + String carpark = GeoUtils.gpsInCarpark(gps);
  271 + if (carpark != null && carpark.equals(sch.getZdzCode())) {
  272 + //进场班次取第一个实际进场时间
  273 + if(sch.getZdsjActual() != null)
  274 + return;
  275 +
  276 + //进场
  277 + arriveEnd(sch, gps);
  278 + return;
  279 + }
  280 +
  281 + CircleQueue<GpsEntity> queue = GeoCacheData.getGps(gps.getNbbm());
  282 + if (queue == null)
  283 + return;
  284 + //上一个gps
  285 + GpsEntity prev = queue.getTail();
  286 +
  287 + if (carpark == null && prev.isInstation() && prev.getStopNo().equals(sch.getQdzCode())) {
  288 + gps.setStopNo(prev.getStopNo());
  289 + //进场班次发出
  290 + busWillDepart(sch, gps);
  291 + return;
  292 + }
  293 + }
  294 +
  295 + /**
  296 + * 完成班次 -返回下一个班次
  297 + *
  298 + * @param sch
  299 + */
  300 + private static ScheduleRealInfo finishPlan(ScheduleRealInfo sch) {
  301 + ScheduleRealInfo next = dayOfSchedule.next(sch);
  302 + if (next != null) {
  303 + next.setQdzArrDatesj(sch.getZdsjActual());
  304 + dayOfSchedule.addExecPlan(next);
  305 + }
  306 + return next;
  307 + }
  308 +
  309 + @Override
  310 + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
  311 + dayOfSchedule = applicationContext.getBean(DayOfSchedule.class);
  312 + lineConfigData = applicationContext.getBean(LineConfigData.class);
  313 + }
  314 +}
... ...
src/main/java/com/bsth/data/gpsdata/analyse/components/GpsStateCorrective.java 0 → 100644
  1 +package com.bsth.data.gpsdata.analyse.components;
  2 +
  3 +import com.bsth.data.gpsdata.GpsEntity;
  4 +import com.bsth.data.schedule.DayOfSchedule;
  5 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  6 +import com.vividsolutions.jts.geom.GeometryFactory;
  7 +import org.joda.time.format.DateTimeFormat;
  8 +import org.joda.time.format.DateTimeFormatter;
  9 +import org.slf4j.Logger;
  10 +import org.slf4j.LoggerFactory;
  11 +import org.springframework.beans.BeansException;
  12 +import org.springframework.context.ApplicationContext;
  13 +import org.springframework.context.ApplicationContextAware;
  14 +import org.springframework.stereotype.Component;
  15 +
  16 +/**
  17 + * GPS状态纠正
  18 + * Created by panzhao on 2016/12/23.
  19 + */
  20 +@Component
  21 +public class GpsStateCorrective implements ApplicationContextAware {
  22 +
  23 + static Logger logger = LoggerFactory.getLogger(GpsStateCorrective.class);
  24 +
  25 + static DayOfSchedule dayOfSchedule;
  26 +
  27 + private static GeometryFactory geometryFactory = new GeometryFactory();
  28 +
  29 + public static void correct(GpsEntity gps, ScheduleRealInfo sch){
  30 +/* int upDown = Integer.parseInt(sch.getXlDir());
  31 + gps.setUpDown(upDown);
  32 + List<StationRoute> srs = GeoCacheData.getStationRoute(sch.getXlBm(), upDown);
  33 +
  34 + Point point = geometryFactory.createPoint(new Coordinate(gps.getLat(), gps.getLon()));
  35 +
  36 + //之前的点位
  37 + CircleQueue<GpsEntity> queue = GeoCacheData.getGps(gps.getNbbm());
  38 + GpsEntity prev = null;
  39 + if(queue != null)
  40 + prev = queue.getTail();
  41 +
  42 + //线路上,站点间
  43 + StationRoute station = GeoUtils.pointInStation(point, srs);
  44 + //在站内
  45 + if(station != null){
  46 + gps.setStopNo(station.getCode());
  47 + gps.setInstation(true);
  48 + gps.setStation(station);
  49 +
  50 + if(prev != null && prev.getUpDown() == upDown){
  51 + StationRoute prevStation = GeoCacheData.getStation(prev.getLineId(), upDown, prev.getStopNo());
  52 +
  53 + //倒着开??
  54 + if(prevStation.getRouteSort() > station.getRouteSort()){
  55 + reversalHandle(gps, prev, sch);
  56 + }
  57 + }
  58 + }
  59 + else{
  60 + if(prev != null)
  61 + gps.setStopNo(prev.getStopNo());
  62 + }
  63 +
  64 + //是否在停车场内
  65 + Map<String, Polygon> carparkMap = GeoCacheData.tccMap;
  66 + Set<String> codes = carparkMap.keySet();
  67 + Polygon p;
  68 + for(String code : codes){
  69 + p = carparkMap.get(code);
  70 + //场内
  71 + if(p.contains(point)){
  72 + gps.setCarparkNo(code);
  73 + if(sch.getBcType().equals("out")){
  74 + gps.setInstation(true);
  75 + gps.setStopNo(code);
  76 + }
  77 + }
  78 + }*/
  79 + }
  80 +
  81 + private static DateTimeFormatter fmt = DateTimeFormat.forPattern("HH:mm");
  82 +
  83 + private static void reversalHandle(GpsEntity gps, GpsEntity prev, ScheduleRealInfo sch){
  84 + /*if(sch.getBcType().equals("out") && gps.getTimestamp() < sch.getZdsjT())
  85 + return;
  86 +
  87 + //先假设没到终点,直接开始了下一个班次
  88 + ScheduleRealInfo next = dayOfSchedule.next(sch);
  89 + String log = "倒着开??? nbbm: " + gps.getNbbm() + " 当前:" + gps.getStopNo() + " 上一站:" + prev.getStopNo() + " 当前班次:" + sch.getDfsj();
  90 + if(next != null){
  91 + dayOfSchedule.addExecPlan(next);
  92 +
  93 + log += (" 下一个班次:" + next.getDfsj());
  94 + }
  95 +
  96 + log += (" GPS时间:" + fmt.print(gps.getTimestamp()));
  97 +
  98 + logger.info(log);*/
  99 + }
  100 +
  101 + @Override
  102 + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
  103 + dayOfSchedule = applicationContext.getBean(DayOfSchedule.class);
  104 + }
  105 +}
... ...
src/main/java/com/bsth/data/gpsdata/analyse/util/GeoUtils.java 0 → 100644
  1 +package com.bsth.data.gpsdata.analyse.util;
  2 +
  3 +import com.bsth.data.gpsdata.GpsEntity;
  4 +import com.bsth.data.gpsdata.analyse.GeoCacheData;
  5 +import com.bsth.data.gpsdata.analyse.StationRoute;
  6 +import com.vividsolutions.jts.geom.Coordinate;
  7 +import com.vividsolutions.jts.geom.GeometryFactory;
  8 +import com.vividsolutions.jts.geom.Point;
  9 +import com.vividsolutions.jts.geom.Polygon;
  10 +
  11 +import java.util.List;
  12 +import java.util.Map;
  13 +import java.util.Set;
  14 +
  15 +/**
  16 + * Created by panzhao on 2016/12/23.
  17 + */
  18 +public class GeoUtils {
  19 +
  20 + private final static double EARTHRADIUS = 6378137;
  21 +
  22 + private static GeometryFactory geometryFactory = new GeometryFactory();
  23 + /**
  24 + * gps是否在路由上的某个站内
  25 + *
  26 + * @param gps
  27 + * @param srs
  28 + * @return
  29 + */
  30 + public static StationRoute gpsInStation(GpsEntity gps, List<StationRoute> srs) {
  31 + Point point = geometryFactory.createPoint(new Coordinate(gps.getLat(), gps.getLon()));
  32 + double min = -1, distance, distance2;
  33 + StationRoute stationRoute = null;
  34 +
  35 + for (StationRoute sr : srs) {
  36 + if (sr.getPolygon() == null) {
  37 + //圆形
  38 + distance = getDistance(sr.getPoint(), point);//sr.getPoint().distance(point);
  39 +
  40 + if (distance > sr.getRadius())
  41 + continue;
  42 +
  43 + if (min > distance || min == -1) {
  44 + min = distance;
  45 + stationRoute = sr;
  46 + }
  47 + } else {
  48 + //多边形
  49 + if (sr.getPolygon().contains(point)) {
  50 + stationRoute = sr;
  51 + break;
  52 + }
  53 + }
  54 + }
  55 + return stationRoute;
  56 + }
  57 +
  58 + public static double getDistance(Point p1, Point p2) {
  59 + double lng1 = getLoop(p1.getY(), -180, 180), lat1 = getRange(
  60 + p1.getX(), -74, 74);
  61 + double lng2 = getLoop(p2.getY(), -180, 180), lat2 = getRange(
  62 + p2.getX(), -74, 74);
  63 +
  64 + double x1, x2, y1, y2;
  65 + x1 = degreeToRad(lng1);
  66 + y1 = degreeToRad(lat1);
  67 + x2 = degreeToRad(lng2);
  68 + y2 = degreeToRad(lat2);
  69 + return EARTHRADIUS
  70 + * Math.acos((Math.sin(y1) * Math.sin(y2) + Math.cos(y1)
  71 + * Math.cos(y2) * Math.cos(x2 - x1)));
  72 + }
  73 +
  74 + private static double getLoop(double v, double a, double b) {
  75 + while (v > b) {
  76 + v -= b - a;
  77 + }
  78 + while (v < a) {
  79 + v += b - a;
  80 + }
  81 + return v;
  82 + }
  83 +
  84 + private static double getRange(double v, double a, double b) {
  85 + v = Math.min(Math.max(v, a), b);
  86 + return v;
  87 + }
  88 +
  89 + private static double degreeToRad(double degree) {
  90 + return Math.PI * degree / 180;
  91 + }
  92 +
  93 +
  94 + /**
  95 + * gps 是否在某个停车场内
  96 + * @param gps
  97 + * @return
  98 + */
  99 + public static String gpsInCarpark(GpsEntity gps){
  100 + Point point = geometryFactory.createPoint(new Coordinate(gps.getLat(), gps.getLon()));
  101 +
  102 + Map<String, Polygon> carparkMap = GeoCacheData.tccMap;
  103 + Set<String> codes = carparkMap.keySet();
  104 + Polygon polygon;
  105 + for(String code : codes){
  106 + polygon = carparkMap.get(code);
  107 + if(point.within(polygon)){
  108 + return code;
  109 + }
  110 + }
  111 + return null;
  112 + }
  113 +
  114 + /**
  115 + * 是否是有效的连续点
  116 + * @param prevGps
  117 + * @param gps
  118 + * @return
  119 + */
  120 + public static boolean overdue(GpsEntity prevGps, GpsEntity gps) {
  121 + return gps.getTimestamp() - prevGps.getTimestamp() < 120000;
  122 + }
  123 +}
... ...
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.analyse.components.GpsArrival;
  6 +import com.bsth.util.db.DBUtils_MS;
  7 +import com.google.common.collect.ArrayListMultimap;
  8 +import org.slf4j.Logger;
  9 +import org.slf4j.LoggerFactory;
  10 +import org.springframework.jdbc.core.JdbcTemplate;
  11 +import org.springframework.jdbc.core.RowMapper;
  12 +
  13 +import java.sql.ResultSet;
  14 +import java.sql.SQLException;
  15 +import java.util.*;
  16 +import java.util.concurrent.CountDownLatch;
  17 +import java.util.concurrent.ExecutorService;
  18 +import java.util.concurrent.Executors;
  19 +
  20 +/**
  21 + * 数据恢复
  22 + * Created by panzhao on 2016/12/24.
  23 + */
  24 +public class GpsDataRecovery {
  25 +
  26 + static Logger logger = LoggerFactory.getLogger(GpsDataRecovery.class);
  27 +
  28 + public static boolean run;
  29 +
  30 + static ExecutorService threadPool = Executors.newFixedThreadPool(50);
  31 +
  32 + private static CountDownLatch count;
  33 +
  34 + public static void recovery() {
  35 + List<GpsEntity> list = loadData();
  36 +
  37 + //按车辆分组数据
  38 + ArrayListMultimap<String, GpsEntity> listMap = ArrayListMultimap.create();
  39 + for (GpsEntity gps : list) {
  40 + if(gps.getNbbm() != null)
  41 + listMap.put(gps.getNbbm(), gps);
  42 + }
  43 +
  44 + count = new CountDownLatch(listMap.keySet().size());
  45 +
  46 + Set<String> keys = listMap.keySet();
  47 + for (String nbbm : keys) {
  48 + threadPool.execute(new RecoveryDataThread(listMap.get(nbbm), count));
  49 + /*if(nbbm.equals("W9A-250"))
  50 + new RecoveryDataThread(listMap.get(nbbm), count).run();*/
  51 + }
  52 + try {
  53 + //等待子线程结束
  54 + count.await();
  55 + logger.info("GPS 数据恢复完成....");
  56 + } catch (InterruptedException e) {
  57 + logger.error("", e);
  58 + }
  59 + }
  60 +
  61 + /**
  62 + * 加载当天的gps数据
  63 + *
  64 + * @return
  65 + */
  66 + public static List<GpsEntity> loadData() {
  67 + Calendar calendar = Calendar.getInstance();
  68 + int dayOfYear = calendar.get(Calendar.DAY_OF_YEAR);
  69 +
  70 + String sql = "select DEVICE_ID,LAT,LON,TS,SPEED_GPS,LINE_ID,SERVICE_STATE from BSTH_C_GPS_INFO where days_year=" + dayOfYear;
  71 + JdbcTemplate jdbcTemplate = new JdbcTemplate(DBUtils_MS.getDataSource());
  72 +
  73 + List<GpsEntity> list =
  74 + jdbcTemplate.query(sql, new RowMapper<GpsEntity>() {
  75 + @Override
  76 + public GpsEntity mapRow(ResultSet rs, int rowNum) throws SQLException {
  77 + GpsEntity gps = new GpsEntity();
  78 +
  79 + gps.setDeviceId(rs.getString("DEVICE_ID"));
  80 + gps.setNbbm(BasicData.deviceId2NbbmMap.get(gps.getDeviceId()));
  81 + gps.setSpeed(rs.getFloat("SPEED_GPS"));
  82 + gps.setLat(rs.getFloat("LAT"));
  83 + gps.setLon(rs.getFloat("LON"));
  84 + gps.setLineId(rs.getString("LINE_ID"));
  85 + gps.setTimestamp(rs.getLong("TS"));
  86 + gps.setUpDown(getUpOrDown(rs.getLong("SERVICE_STATE")));
  87 + return gps;
  88 + }
  89 + });
  90 + return list;
  91 + }
  92 +
  93 + /**
  94 + * 王通 2016/6/29 9:23:24 获取车辆线路上下行
  95 + *
  96 + * @return -1无效 0上行 1下行
  97 + */
  98 + public static int getUpOrDown(long serviceState) {
  99 + if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000
  100 + || (serviceState & 0x01000000) == 0x01000000 || (serviceState & 0x08000000) == 0x08000000)
  101 + return -1;
  102 + return (((serviceState & 0x10000000) == 0x10000000) ? 1 : 0);
  103 + }
  104 +
  105 + public static class RecoveryDataThread implements Runnable {
  106 +
  107 + List<GpsEntity> list;
  108 + CountDownLatch count;
  109 +
  110 + public RecoveryDataThread(List<GpsEntity> list, CountDownLatch count) {
  111 + this.list = list;
  112 + this.count = count;
  113 + }
  114 +
  115 + @Override
  116 + public void run() {
  117 + try {
  118 + //排序
  119 + Collections.sort(list, new GpsComp());
  120 + //依次跑完gps
  121 + //int i = 0;
  122 + for(GpsEntity gps : list){
  123 + /* i++;
  124 + if(i == 383){
  125 + System.out.println("aaa");
  126 + }*/
  127 + GpsArrival.arrival(gps);
  128 + }
  129 + } catch (Exception e) {
  130 + logger.error("", e);
  131 + } finally {
  132 + count.countDown();
  133 + }
  134 + }
  135 + }
  136 +
  137 + public static class GpsComp implements Comparator<GpsEntity>{
  138 +
  139 + @Override
  140 + public int compare(GpsEntity g1, GpsEntity g2) {
  141 + return (int) (g1.getTimestamp() - g2.getTimestamp());
  142 + }
  143 + }
  144 +}
... ...
src/main/java/com/bsth/data/schedule/DayOfSchedule.java
... ... @@ -3,9 +3,11 @@ package com.bsth.data.schedule;
3 3 import com.alibaba.fastjson.JSON;
4 4 import com.alibaba.fastjson.JSONArray;
5 5 import com.bsth.Application;
  6 +import com.bsth.data.BasicData;
6 7 import com.bsth.data.LineConfigData;
7 8 import com.bsth.data.directive.FirstScheduleCheckThread;
8 9 import com.bsth.data.gpsdata.GpsRealData;
  10 +import com.bsth.data.gpsdata.recovery.GpsDataRecovery;
9 11 import com.bsth.data.schedule.thread.ScheduleLateThread;
10 12 import com.bsth.data.schedule.thread.SchedulePstThread;
11 13 import com.bsth.data.schedule.thread.ScheduleRefreshThread;
... ... @@ -111,19 +113,30 @@ public class DayOfSchedule implements CommandLineRunner {
111 113 @Autowired
112 114 SubmitToTrafficManage submitToTrafficManage;
113 115  
  116 + @Autowired
  117 + LineConfigData lineConfigs;
  118 +
  119 + @Autowired
  120 + BasicData.BasicDataLoader dataLoader;
  121 +
114 122 private static DateTimeFormatter fmtyyyyMMdd = DateTimeFormat.forPattern("yyyy-MM-dd")
115 123 ,fmtHHmm = DateTimeFormat.forPattern("HH:mm");
116 124  
117 125 @Override
118 126 public void run(String... arg0) throws Exception {
  127 + //加载基础数据
  128 + dataLoader.loadAllData();
  129 + //从数据库恢复排班
  130 + //dataRecovery();
  131 +
119 132 //翻班线程
120 133 Application.mainServices.scheduleWithFixedDelay(scheduleRefreshThread, 15, 240, TimeUnit.SECONDS);
121 134 //入库
122   -// Application.mainServices.scheduleWithFixedDelay(schedulePstThread, 60, 60, TimeUnit.SECONDS);
  135 + Application.mainServices.scheduleWithFixedDelay(schedulePstThread, 60, 60, TimeUnit.SECONDS);
123 136 //首班出场指令补发器
124 137 // Application.mainServices.scheduleWithFixedDelay(firstScheduleCheckThread, 30, 240, TimeUnit.SECONDS);
125 138 //班次误点扫描
126   -// Application.mainServices.scheduleWithFixedDelay(scheduleLateThread, 60, 60, TimeUnit.SECONDS);
  139 + Application.mainServices.scheduleWithFixedDelay(scheduleLateThread, 60, 60, TimeUnit.SECONDS);
127 140  
128 141 //每天凌晨2点20提交数据到运管处
129 142 long diff = (DateUtils.getTimestamp() + 1000*60*140) - System.currentTimeMillis();
... ... @@ -134,6 +147,23 @@ public class DayOfSchedule implements CommandLineRunner {
134 147 //Application.mainServices.scheduleWithFixedDelay(submitToTrafficManage, diff / 1000, 60 * 60 * 24, TimeUnit.SECONDS);
135 148 }
136 149  
  150 + //数据恢复
  151 + private void dataRecovery() {
  152 + GpsDataRecovery.run = true;
  153 +
  154 + Collection<LineConfig> confs = lineConfigs.getAll();
  155 + String lineCode, currSchDate;
  156 + for(LineConfig conf : confs){
  157 + lineCode = conf.getLine().getLineCode();
  158 + currSchDate = calcSchDate(lineCode);
  159 + //加载班次数据
  160 + reloadSch(lineCode, currSchDate, false);
  161 + }
  162 +
  163 + //恢复gps数据
  164 + GpsDataRecovery.recovery();
  165 + }
  166 +
137 167 public Map<String, String> getCurrSchDate() {
138 168 return currSchDateMap;
139 169 }
... ... @@ -189,17 +219,20 @@ public class DayOfSchedule implements CommandLineRunner {
189 219 putAll(list);
190 220  
191 221 Set<String> cars = searchAllCars(list);
192   - //计算“起点站应到”时间
193   - for(String nbbm : cars)
  222 + for(String nbbm : cars){
  223 + //计算“起点站应到”时间
194 224 schAttrCalculator.calcQdzTimePlan(nbbmScheduleMap.get(nbbm));
195   -
  225 + //车辆 ——> 要执行的班次对照
  226 + carExecutePlanMap.put(nbbm, schAttrCalculator.calcCurrentExecSch(nbbmScheduleMap.get(nbbm)));
  227 + }
  228 +
196 229 //是否是出站即出场
197 230 LineConfig conf = lineConfigData.get(lineCode);
198 231 if(conf.getOutConfig() == 2){
199 232 for(String nbbm : cars)
200 233 schAttrCalculator.connectOutSchedule(nbbmScheduleMap.get(nbbm));
201 234 }
202   -
  235 +
203 236 // 页面 翻班通知
204 237 sendUtils.shiftSchedule(lineCode);
205 238 } catch (Exception e) {
... ... @@ -451,6 +484,10 @@ public class DayOfSchedule implements CommandLineRunner {
451 484 public ScheduleRealInfo next(ScheduleRealInfo sch) {
452 485  
453 486 List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());
  487 + int outConfig = -1;
  488 + LineConfig config = lineConfigData.get(sch.getXlBm());
  489 + if(config != null)
  490 + outConfig = config.getOutConfig();
454 491  
455 492 boolean flag = false;
456 493 ScheduleRealInfo next = null;
... ... @@ -462,6 +499,10 @@ public class DayOfSchedule implements CommandLineRunner {
462 499 //忽略烂班
463 500 if(temp.isDestroy())
464 501 continue;
  502 +
  503 + //出站既出场,忽略出场班次
  504 + if(outConfig == 2 && temp.getBcType().equals("out"))
  505 + continue;
465 506  
466 507 if(flag){
467 508 next = temp;
... ... @@ -471,6 +512,30 @@ public class DayOfSchedule implements CommandLineRunner {
471 512 return next;
472 513 }
473 514  
  515 + /**
  516 + * 上一个班次
  517 + * @param sch
  518 + * @return
  519 + */
  520 + public ScheduleRealInfo prev(ScheduleRealInfo sch){
  521 + List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());
  522 +
  523 + //boolean flag = false;
  524 + ScheduleRealInfo prev = null;
  525 + int size = list.size();
  526 +
  527 + for(int i = 0; i < size; i ++){
  528 + if(list.get(i).isDestroy())
  529 + continue;
  530 +
  531 + if(list.get(i).getId().equals(sch.getId())){
  532 + return prev;
  533 + }
  534 + prev = list.get(i);
  535 + }
  536 + return prev;
  537 + }
  538 +
474 539 public void put(ScheduleRealInfo sch) {
475 540 schAttrCalculator
476 541 .calcRealDate(sch)
... ... @@ -666,9 +731,18 @@ public class DayOfSchedule implements CommandLineRunner {
666 731 carExecutePlanMap.remove(clzbh);
667 732 }
668 733  
669   - public Map<String, ScheduleRealInfo> execPlamMap(){
  734 + public Map<String, ScheduleRealInfo> execPlanMap(){
670 735 return carExecutePlanMap;
671 736 }
  737 +
  738 + /**
  739 + * 车辆当前执行的班次
  740 + * @param nbbm
  741 + * @return
  742 + */
  743 + public static ScheduleRealInfo executeCurr(String nbbm){
  744 + return carExecutePlanMap.get(nbbm);
  745 + }
672 746  
673 747 /**
674 748 * @Title: changeCar
... ...
src/main/java/com/bsth/data/schedule/SchAttrCalculator.java
... ... @@ -215,4 +215,30 @@ public class SchAttrCalculator {
215 215 if(sch.getZdsjActualTime() == null && sch.getZdsjActual() != null)
216 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 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 3 import com.bsth.data.BasicData;
12 4 import com.bsth.data.LineConfigData;
13 5 import com.bsth.data.arrival.ArrivalData_GPS;
... ... @@ -15,6 +7,13 @@ import com.bsth.data.directive.DayOfDirectives;
15 7 import com.bsth.data.pilot80.PilotReport;
16 8 import com.bsth.data.schedule.DayOfSchedule;
17 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 56 currSchDate = dayOfSchedule.calcSchDate(lineCode);
58 57  
59 58 if(oldSchDate == null || !oldSchDate.equals(currSchDate)){
  59 +
60 60 logger.info(lineCode + "开始翻班, " + currSchDate);
61 61 //清除进出站数据
62 62 arrivalData.clearRAMData(lineCode);
... ...
src/main/java/com/bsth/entity/mcy_forms/Changetochange.java
1 1 package com.bsth.entity.mcy_forms;
2 2  
3   -import java.util.Date;
4   -
5 3 import javax.persistence.Entity;
6 4 import javax.persistence.GeneratedValue;
7 5 import javax.persistence.Id;
... ...
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/service/forms/FormsService.java
... ... @@ -30,7 +30,7 @@ public interface FormsService {
30 30  
31 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 35 public List<Operationservice> operationservice(Map<String, Object> map);
36 36  
... ...
src/main/java/com/bsth/service/forms/impl/FormsServiceImpl.java
... ... @@ -26,6 +26,7 @@ import com.bsth.entity.mcy_forms.Waybillday;
26 26 import com.bsth.entity.mcy_forms.Allline;
27 27 import com.bsth.entity.mcy_forms.Changetochange;
28 28 import com.bsth.entity.mcy_forms.Executionrate;
  29 +import com.bsth.service.forms.CommonService;
29 30 import com.bsth.service.forms.FormsService;
30 31 import com.bsth.service.realcontrol.ScheduleRealInfoService;
31 32  
... ... @@ -38,20 +39,32 @@ public class FormsServiceImpl implements FormsService {
38 39 @Autowired
39 40 ScheduleRealInfoService scheduleRealInfoService;
40 41  
  42 + @Autowired
  43 + CommonService commonService;
  44 +
41 45 // 行车路单日报表
42 46 @Override
43 47 public List<Waybillday> waybillday(Map<String, Object> map) {
  48 +
44 49 String sql ="select x.j_gh,x.cl_zbh,z.JZL,z.YH,z.personnel_name,x.schedule_date,x.gs_bm,x.gs_name,x.fgs_bm,x.fgs_name "
45 50 + " from bsth_c_s_sp_info_real x INNER join "
46 51 + " ( select y.RQ,y.XLBM,y.NBBM,y.JSY,y.JZL,y.YH,c.personnel_name from"
47 52 + " bsth_c_ylb y LEFT JOIN bsth_c_personnel c ON c.job_code=y.JSY "
48   - + " where to_days(y.RQ)=to_days('"+map.get("date").toString() + "') and y.XLBM= '"+ map.get("line").toString()+"' GROUP BY y.NBBM) "
49   - + " z on x.cl_zbh=z.nbbm where to_days( x.schedule_date)=to_days('"+map.get("date").toString()+"') "
50   - + " and x.xl_bm='"+map.get("line").toString()+"'"
51   - /*+ " and x.gs_bm='"+map.get("gsdmWaybillday").toString()+"'"
52   - + " and x.fgs_bm='"+map.get("fgsdmWaybillday").toString()+"'"*/
53   - + " GROUP BY x.j_gh,x.cl_zbh,z.JZL,z.YH,z.personnel_name,x.schedule_date,x.gs_bm,x.gs_name,x.fgs_bm,x.fgs_name";
54   - //x.cl_zbh,j_gh
  53 + + " where 1=1 ";
  54 + if(map.get("date").toString()!=""){
  55 + sql+=" and to_days(y.RQ)=to_days('"+map.get("date").toString() + "') ";
  56 + }
  57 + if( map.get("line").toString()!=""){
  58 + sql+=" and y.XLBM= '"+ map.get("line").toString()+"' GROUP BY y.NBBM) ";
  59 + }
  60 + sql+= " z on x.cl_zbh=z.nbbm where to_days( x.schedule_date)=to_days('"+map.get("date").toString()+"') ";
  61 + if(map.get("gsdmWaybillday").toString()!=""){
  62 + sql+=" and x.gs_bm='"+map.get("gsdmWaybillday").toString()+"'";
  63 + }
  64 + if(map.get("fgsdmWaybillday").toString()!=""){
  65 + sql+=" and x.fgs_bm='"+map.get("fgsdmWaybillday").toString()+"'";
  66 + }
  67 + sql += " GROUP BY x.j_gh,x.cl_zbh,z.JZL,z.YH,z.personnel_name,x.schedule_date,x.gs_bm,x.gs_name,x.fgs_bm,x.fgs_name ";
55 68 List<Waybillday> list = jdbcTemplate.query(sql, new RowMapper<Waybillday>() {
56 69 @Override
57 70 public Waybillday mapRow(ResultSet arg0, int arg1) throws SQLException {
... ... @@ -60,21 +73,16 @@ public class FormsServiceImpl implements FormsService {
60 73 wbd.setJzl(arg0.getString("JZL"));
61 74 wbd.setYh(arg0.getString("YH"));
62 75 wbd.setjName(arg0.getString("personnel_name"));
63   - // wbd.setZlc(arg0.getInt("zlc"));
64   - // System.out.println(arg0.getObject("yl"));
65   - // wbd.setYl(arg0.getString("yl"));
66   - // wbd.setNbbm(arg0.getString("nbbm"));
67 76 wbd.setRq(arg0.getString("schedule_date"));
68 77 wbd.setJgh(arg0.getString("j_gh"));
69 78 return wbd;
70   -
71 79 }
72 80 });
73 81  
74 82 for(int i=0;i<list.size();i++){
75 83 Waybillday w=list.get(i);
76 84 Map<String, Object> maps = new HashMap<>();
77   - maps = scheduleRealInfoService.findKMBC2(w.getJgh(), w.getCarPlate(),
  85 + maps = commonService.findKMBC2(w.getJgh(), w.getCarPlate(),
78 86 w.getRq());
79 87 w.setJzl1(maps.get("ksgl").toString());
80 88 w.setZlc(maps.get("realMileage").toString());
... ... @@ -86,18 +94,25 @@ public class FormsServiceImpl implements FormsService {
86 94 // 线路客流量报表
87 95 @Override
88 96 public List<Linepasswengerflow> linepasswengerflow(Map<String, Object> map) {
89   - String sql = " SELECT s.station_name,l.name,r.gs_bm,r.gs_name,r.fgs_bm,r.fgs_name"
  97 + String sql = " SELECT r.schedule_date,s.station_name,l.name,r.gs_bm,r.gs_name,r.fgs_bm,r.fgs_name"
90 98 + " from bsth_c_stationroute s "
91 99 + " LEFT JOIN bsth_c_line l on s.line_code=l.line_code "
92 100 + " LEFT JOIN bsth_c_s_sp_info_real r on r.xl_bm=l.line_code"
93   - + " where to_days(l.create_date)=to_days('"+map.get("date").toString() + "') "
94   - + " and l.line_code=" + map.get("line").toString()
95   - + " AND r.gs_bm is not null"
96   - /*+ " and r.gs_bm='"+map.get("gsdmLine").toString()+"'"
97   - + " and r.fgs_bm='"+map.get("fgsdmLine").toString()+"'"*/
98   - + " GROUP BY s.station_name,l.name,r.gs_bm,r.gs_name,r.fgs_bm,r.fgs_name ";
99   -
100   - //s.station_name
  101 + + " where 1=1 ";
  102 + if(map.get("date").toString()!=""){
  103 + sql+="and to_days(r.schedule_date)=to_days('"+map.get("date").toString() + "') ";
  104 + }
  105 + if( map.get("line").toString()!=""){
  106 + sql+=" and l.line_code=" + map.get("line").toString();
  107 + }
  108 + sql+= " AND r.gs_bm is not null";
  109 + if(map.get("gsdmLine").toString()!=""){
  110 + sql+=" and r.gs_bm='"+map.get("gsdmLine").toString()+"' ";
  111 + }
  112 + if(map.get("fgsdmLine").toString()!=""){
  113 + sql+=" and r.fgs_bm='"+map.get("fgsdmLine").toString()+"'";
  114 + }
  115 + sql += " GROUP BY s.station_name,l.name,r.gs_bm,r.gs_name,r.fgs_bm,r.fgs_name ";
101 116 List<Linepasswengerflow> list = jdbcTemplate.query(sql, new RowMapper<Linepasswengerflow>() {
102 117  
103 118 @Override
... ... @@ -109,8 +124,6 @@ public class FormsServiceImpl implements FormsService {
109 124 }
110 125 });
111 126  
112   -
113   -
114 127 return list;
115 128 }
116 129  
... ... @@ -122,16 +135,26 @@ public class FormsServiceImpl implements FormsService {
122 135 public List<Shiftuehiclemanth> shiftuehiclemanth(Map<String, Object> map) {
123 136 String sql = "select r.j_name,r.cl_zbh,r.j_gh,r.gs_bm,r.gs_name,r.fgs_bm,r.fgs_name,r.bc_type "
124 137 + " from bsth_c_s_sp_info_real r "
125   - + " where to_days(r.schedule_date_str) BETWEEN to_days('" + map.get("startDate").toString() + "') "
126   - + " and to_days('" + map.get("endDate").toString() + "') "
127   - + " and r.xl_bm='"+ map.get("line").toString() + "'"
128   - + " AND r.gs_bm is not null"
129   - + " and r.bc_type not in('in','out')"
130   - /* + " and r.gs_bm='"+map.get("gsdmManth").toString()+"'"
131   - + " and r.fgs_bm='"+map.get("fgsdmManth").toString()+"'"*/
132   - + " GROUP BY r.j_name,r.cl_zbh,r.j_gh,r.gs_bm,r.gs_name,r.fgs_bm,r.fgs_name"
133   - + " ORDER BY r.j_name";
134   - //r.j_name
  138 + + " where 1=1 ";
  139 + if(map.get("startDate").toString()!=""){
  140 + sql+=" and to_days(r.schedule_date_str) BETWEEN to_days('" + map.get("startDate").toString() + "') ";
  141 + }
  142 +
  143 + if(map.get("endDate").toString()!=""){
  144 + sql+=" and to_days('" + map.get("endDate").toString() + "') ";
  145 + }
  146 + if( map.get("line").toString()!=""){
  147 + sql+=" and r.xl_bm='"+ map.get("line").toString() + "' ";
  148 + }
  149 + sql+= " AND r.gs_bm is not null and r.bc_type not in('in','out')";
  150 + if(map.get("gsdmManth").toString()!=""){
  151 + sql+=" and r.gs_bm='"+map.get("gsdmManth").toString()+"' ";
  152 + }
  153 + if(map.get("fgsdmManth").toString()!=""){
  154 + sql+=" and r.fgs_bm='"+map.get("fgsdmManth").toString()+"' ";
  155 + }
  156 + sql += " GROUP BY r.j_name,r.cl_zbh,r.j_gh,r.gs_bm,r.gs_name,r.fgs_bm,r.fgs_name,r.bc_type ";
  157 +
135 158 startDate = map.get("startDate").toString();
136 159 endDate = map.get("endDate").toString();
137 160 List<Shiftuehiclemanth> list = jdbcTemplate.query(sql, new RowMapper<Shiftuehiclemanth>() {
... ... @@ -150,7 +173,7 @@ public class FormsServiceImpl implements FormsService {
150 173 Shiftuehiclemanth s=list.get(i);
151 174 Map<String, Object> maps = new HashMap<>();
152 175  
153   - maps = scheduleRealInfoService.findKMBC1(s.getjName(),s.getZbh(), startDate,
  176 + maps = commonService.findKMBC1(s.getjName(),s.getZbh(), startDate,
154 177 endDate);
155 178  
156 179 s.setJhlc(maps.get("jhlc").toString());
... ... @@ -172,13 +195,22 @@ public class FormsServiceImpl implements FormsService {
172 195 String sql = " select r.schedule_date,r.lp_name,r.xl_name,r.j_name,r.s_name, r.cl_zbh,r.xl_bm,"
173 196 + " r.cl_zbh,r.j_gh,r.j_gh,r.gs_bm,r.gs_name,r.fgs_bm,r.fgs_name,r.bc_type "
174 197 + " FROM bsth_c_s_sp_info_real r "
175   - + " where to_days(r.schedule_date)=to_days('"
176   - + map.get("date").toString() + "') and r.xl_bm=" + map.get("line").toString()
177   - + " and r.bc_type not in('in','out')"
178   - /*+ " and r.gs_bm='"+map.get("gsdmShif").toString()+"'"
179   - + " and r.fgs_bm='"+map.get("fgsdmShif").toString()+"'"*/
180   - + " GROUP BY r.schedule_date,r.lp_name,r.xl_name,r.j_name,r.s_name, r.cl_zbh,r.xl_bm,r.cl_zbh,r.j_gh,r.j_gh,r.gs_bm,r.gs_name,r.fgs_bm,r.fgs_name "
181   - + " ORDER BY r.lp_name asc";
  198 + + " where 1=1 ";
  199 + if(map.get("date").toString()!=""){
  200 + sql+=" and to_days(r.schedule_date)=to_days('"+ map.get("date").toString() + "') ";
  201 + }
  202 + if( map.get("line").toString()!=""){
  203 + sql+=" and r.xl_bm=" + map.get("line").toString();
  204 + }
  205 + sql+= " and r.bc_type not in('in','out')";
  206 + if(map.get("gsdmShif").toString()!=""){
  207 + sql+=" and r.gs_bm='"+map.get("gsdmShif").toString()+"'";
  208 + }
  209 + if(map.get("fgsdmShif").toString()!=""){
  210 + sql+=" and r.fgs_bm='"+map.get("fgsdmShif").toString()+"'";
  211 + }
  212 + sql += " GROUP BY r.schedule_date,r.lp_name,r.xl_name,r.j_name,r.s_name, r.cl_zbh,r.xl_bm,r.cl_zbh,r.j_gh,r.j_gh,r.gs_bm,r.gs_name,r.fgs_bm,r.fgs_name "
  213 + + " ORDER BY r.lp_name asc";
182 214  
183 215 List<Shifday> list = jdbcTemplate.query(sql, new RowMapper<Shifday>() {
184 216  
... ... @@ -200,7 +232,7 @@ public class FormsServiceImpl implements FormsService {
200 232 for(int i=0;i<list.size();i++){
201 233 Shifday shi=list.get(i);
202 234 Map<String, Object> maps = new HashMap<>();
203   - maps = scheduleRealInfoService.findKMBC2(shi.getJgh(), shi.getCarPlate(),
  235 + maps = commonService.findKMBC2(shi.getJgh(), shi.getCarPlate(),
204 236 shi.getRq());
205 237 shi.setJhlc(maps.get("jhlc").toString());// 计划里程
206 238 //shifday.setSjjhlc(map.get("remMileage").toString());//实际计划里程
... ... @@ -261,7 +293,6 @@ public class FormsServiceImpl implements FormsService {
261 293 @Override
262 294 public Changetochange mapRow(ResultSet arg0, int arg1) throws SQLException {
263 295 Changetochange chan = new Changetochange();
264   -
265 296 chan.setRq(rq);
266 297 chan.setGs(arg0.getString("gs"));
267 298 chan.setFgs(arg0.getString("fgs"));
... ... @@ -302,18 +333,22 @@ public class FormsServiceImpl implements FormsService {
302 333  
303 334 rq = rq2 + "-" + rq3;
304 335  
305   - String sql = " SELECT r.xl_bm,r.cl_zbh,r.j_gh,r.j_name,y.YH,y.JZL,r.gs_bm,r.gs_name,r.fgs_bm,r.fgs_name "
  336 + String sql = " SELECT r.xl_bm,r.xl_name,r.cl_zbh,r.j_gh,r.j_name,y.YH,y.JZL,r.gs_bm,r.gs_name,r.fgs_bm,r.fgs_name "
306 337 + " FROM bsth_c_s_sp_info_real r "
307   - + " INNER join ( select y.RQ,y.XLBM,y.NBBM,y.JSY,y.JZL,y.YH from bsth_c_ylb y "
308   - + " where y.RQ BETWEEN '" + map.get("startDate").toString() + "' and '"+ map.get("endDate").toString() + "'"
309   - + " and y.XLBM= '" + map.get("line").toString() + "' GROUP BY y.RQ,y.XLBM,y.NBBM,y.JSY,y.JZL,y.YH) y on r.cl_zbh=y.nbbm "
  338 + + " left join bsth_c_ylb y"
  339 + + " ON r.cl_zbh = y.nbbm "
310 340 + " where r.schedule_date_str BETWEEN '" + map.get("startDate").toString() + "'"
311 341 + " and '"+ map.get("endDate").toString() + "'"
312 342 + " and r.xl_bm='" + map.get("line").toString() + "'"
313   - + " AND r.gs_bm is not null"
314   - /* + " and r.gs_bm='"+map.get("gsdmSing").toString()+"'"
315   - + " and r.fgs_bm='"+map.get("fgsdmSing").toString()+"'"*/
316   - + " GROUP BY r.xl_bm,r.cl_zbh,r.j_gh,r.j_name,y.YH,y.JZL,r.gs_bm,r.gs_name,r.fgs_bm,r.fgs_name ";
  343 + + " AND r.gs_bm is not null";
  344 +
  345 + if(map.get("gsdmSing").toString()!=""){
  346 + sql+=" and r.gs_bm='"+map.get("gsdmSing").toString()+"'";
  347 + }
  348 + if(map.get("fgsdmSing").toString()!=""){
  349 + sql+=" and r.fgs_bm='"+map.get("fgsdmSing").toString()+"'";
  350 + }
  351 + sql += " GROUP BY r.xl_bm,r.cl_zbh,r.j_gh,r.j_name,y.YH,y.JZL,r.gs_bm,r.gs_name,r.fgs_bm,r.fgs_name ";
317 352  
318 353 startDate = map.get("startDate").toString();
319 354 endDate = map.get("endDate").toString();
... ... @@ -324,7 +359,7 @@ public class FormsServiceImpl implements FormsService {
324 359 Singledata sin = new Singledata();
325 360 sin.setrQ(rq);
326 361 sin.setgS(arg0.getString("gs_name"));
327   - sin.setxL(arg0.getString("xl_bm"));
  362 + sin.setxL(arg0.getString("xl_name"));
328 363 sin.setClzbh(arg0.getString("cl_zbh"));
329 364 sin.setJsy(arg0.getString("j_gh"));
330 365 sin.setjName(arg0.getString("j_name"));
... ... @@ -339,7 +374,7 @@ public class FormsServiceImpl implements FormsService {
339 374 for(int i=0;i<list.size();i++){
340 375 Singledata si=list.get(i);
341 376 Map<String, Object> maps = new HashMap<>();
342   - maps = scheduleRealInfoService.findKMBC1(si.getjName(),si.getClzbh(), startDate,
  377 + maps = commonService.findKMBC1(si.getjName(),si.getClzbh(), startDate,
343 378 endDate);
344 379 //sin.setjName(maps.get("j_name") == null ? "" : maps.get("j_name").toString());
345 380 si.setSgh(maps.get("s_gh") == null ? "" : maps.get("s_gh").toString());
... ... @@ -356,24 +391,30 @@ public class FormsServiceImpl implements FormsService {
356 391 @Override
357 392 public List<Operationservice> operationservice(Map<String, Object> map) {
358 393  
359   - String sql = " SELECT r.xl_bm,r.xl_name,r.cl_zbh,r.j_gh,r.j_name,y.YH,y.JZL,r.gs_bm,r.gs_name,r.fgs_bm,r.fgs_name,r.bc_type "
  394 + String sql = " SELECT r.schedule_date_str,r.xl_bm,r.xl_name,r.cl_zbh,r.j_gh,r.j_name,y.YH,y.JZL,r.gs_bm,r.gs_name,r.fgs_bm,r.fgs_name,r.bc_type "
360 395 + " FROM bsth_c_s_sp_info_real r "
361 396 // + "LEFT JOIN bsth_c_s_sp_info_real r on r.cl_zbh=y.NBBM"
362   - + " INNER join ( select y.RQ,y.XLBM,y.NBBM,y.JSY,y.JZL,y.YH from bsth_c_ylb y "
363   - + " where y.RQ BETWEEN '" + map.get("startDate").toString() + "' and '"+ map.get("endDate").toString() + "'"
364   - + " and y.XLBM= '" + map.get("line").toString() + "' GROUP BY y.RQ,y.XLBM,y.NBBM,y.JSY,y.JZL,y.YH) y on r.cl_zbh=y.nbbm "
365   - + " where r.schedule_date_str BETWEEN '"+ map.get("startDate").toString()
366   - + "'" + " and '" + map.get("endDate").toString() + "'"
367   - + " and r.xl_bm='" + map.get("line").toString() + "'"
368   - + " and r.bc_type not in('in','out')"
369   - /* + " and r.gs_bm='"+map.get("gsdmOperat").toString()+"'"
370   - + " and r.fgs_bm='"+map.get("fgsdmOperat").toString()+"'"*/
371   - + " AND r.gs_bm is not null"
372   - + " GROUP BY r.xl_bm,r.xl_name,r.cl_zbh,r.j_gh,r.j_name,y.YH,y.JZL,r.gs_bm,r.gs_name,r.fgs_bm,r.fgs_name";
  397 + + " left join bsth_c_ylb y ON r.cl_zbh = y.nbbm "
  398 + + " where 1=1 ";
  399 + if(map.get("startDate").toString()!=""){
  400 + sql+=" and to_days(r.schedule_date_str) BETWEEN to_days('" + map.get("startDate").toString() + "') ";
  401 + }
373 402  
374   - //r.j_name
375   - startDate = map.get("startDate").toString();
376   - endDate = map.get("endDate").toString();
  403 + if(map.get("endDate").toString()!=""){
  404 + sql+=" and to_days('" + map.get("endDate").toString() + "') ";
  405 + }
  406 + sql+=" and r.xl_bm='" + map.get("line").toString() + "'" ;
  407 + sql+=" and r.bc_type not in('in','out')";
  408 + if(map.get("gsdmOperat").toString()!=""){
  409 + sql+=" and r.gs_bm='"+map.get("gsdmOperat").toString()+"'";
  410 + }
  411 + if(map.get("fgsdmOperat").toString()!=""){
  412 + sql+=" and r.fgs_bm='"+map.get("fgsdmOperat").toString()+"'";
  413 + }
  414 + sql += " AND r.gs_bm is not null";
  415 + sql += " GROUP BY r.xl_bm,r.xl_name,r.cl_zbh,r.j_gh,r.j_name,y.YH,y.JZL,r.gs_bm,r.gs_name,r.fgs_bm,r.fgs_name";
  416 + startDate = map.get("startDate").toString();
  417 + endDate = map.get("endDate").toString();
377 418 List<Operationservice> list = jdbcTemplate.query(sql, new RowMapper<Operationservice>() {
378 419  
379 420 @Override
... ... @@ -392,9 +433,9 @@ public class FormsServiceImpl implements FormsService {
392 433 for(int i=0;i<list.size();i++){
393 434 Operationservice o=list.get(i);
394 435 Map<String, Object> maps = new HashMap<>();
395   - maps = scheduleRealInfoService.findKMBC1(o.getJname(), o.getClzbh(), startDate,
  436 + maps = commonService.findKMBC1(o.getJname(), o.getClzbh(), startDate,
396 437 endDate);
397   - o.setXsgl(maps.get("yygl").toString() == null ? "" : maps.get("yygl").toString());
  438 + o.setXsgl(maps.get("jhlc").toString() == null ? "" : maps.get("jhlc").toString());
398 439 o.setEmptMileage(maps.get("ksgl").toString() == null ? "" : maps.get("ksgl").toString());
399 440 o.setSjbc(maps.get("sjbc").toString() == null ? "" : maps.get("sjbc").toString());
400 441 }
... ... @@ -404,7 +445,7 @@ public class FormsServiceImpl implements FormsService {
404 445  
405 446 // 车辆加注
406 447 @Override
407   - public List<Vehicleloading> vehicleloading(/*String gsdmVehic,String fgsdmVehic,*/String line, String date) {
  448 + public List<Vehicleloading> vehicleloading(String gsdmVehic,String fgsdmVehic,String line, String date) {
408 449  
409 450 String sql = " SELECT r.schedule_date_str,r.xl_bm,r.xl_name,r.cl_zbh,r.j_name,y.YH,y.JZL,r.j_gh,r.gs_bm,r.gs_name,r.fgs_bm,r.fgs_name,r.bc_type "
410 451 + " FROM bsth_c_s_sp_info_real r "
... ... @@ -414,13 +455,14 @@ public class FormsServiceImpl implements FormsService {
414 455 + " where to_days(r.schedule_date_str)=to_days('" + date + "')"
415 456 + " and r.xl_bm='" + line + "' "
416 457 + " AND r.gs_bm is not null"
417   - + " and r.bc_type not in('in','out')"
418   - /* + " and r.gs_bm='"+gsdmVehic +"'"
419   - + " and r.fgs_bm='"+fgsdmVehic +"'"*/
420   - + " GROUP BY r.schedule_date_str,r.xl_bm,r.xl_name,r.cl_zbh,r.j_name,y.YH,y.JZL,r.j_gh,r.gs_bm,r.gs_name,r.fgs_bm,r.fgs_name ";
421   -
422   -
423   - //r.cl_zbh
  458 + + " and r.bc_type not in('in','out')";
  459 + if(gsdmVehic.toString()!=""){
  460 + sql+=" and r.gs_bm='"+gsdmVehic+"'";
  461 + }
  462 + if(fgsdmVehic.toString()!=""){
  463 + sql+=" and r.fgs_bm='"+fgsdmVehic +"'";
  464 + }
  465 + sql += " GROUP BY r.schedule_date_str,r.xl_bm,r.xl_name,r.cl_zbh,r.j_name,y.YH,y.JZL,r.j_gh,r.gs_bm,r.gs_name,r.fgs_bm,r.fgs_name ";
424 466 List<Vehicleloading> list = jdbcTemplate.query(sql, new RowMapper<Vehicleloading>() {
425 467 @Override
426 468 public Vehicleloading mapRow(ResultSet arg0, int arg1) throws SQLException {
... ... @@ -429,8 +471,8 @@ public class FormsServiceImpl implements FormsService {
429 471 ve.setgS(arg0.getString("gs_name"));
430 472 ve.setxL(arg0.getString("xl_name"));
431 473 ve.setClzbh(arg0.getString("cl_zbh"));
432   - ve.setHyl(arg0.getString("YH"));
433 474 ve.setJzl(arg0.getString("JZL"));
  475 + ve.setHyl(arg0.getString("YH"));
434 476 // ve.setLs(arg0.getString("").toString());//尿素
435 477 ve.setJgh(arg0.getString("j_gh").toString());
436 478 return ve;
... ... @@ -440,9 +482,9 @@ public class FormsServiceImpl implements FormsService {
440 482 for(int i=0;i<list.size();i++){
441 483 Vehicleloading v=list.get(i);
442 484 Map<String, Object> maps = new HashMap<>();
443   - maps = scheduleRealInfoService.findKMBC2(v.getJgh(), line,
444   - date);
445   - v.setJhlc(maps.get("yygl") == null ? "" : maps.get("yygl").toString());
  485 + maps = commonService.findKMBC2(v.getJgh(), v.getClzbh(),
  486 + v.getrQ());
  487 + v.setJhlc(maps.get("jhlc") == null ? "" : maps.get("jhlc").toString());
446 488 v.setJhbc(maps.get("jhbc").toString() == null ? "" : maps.get("jhbc").toString());// 计划班次
447 489 v.setSjbc(maps.get("sjbc").toString() == null ? "" : maps.get("sjbc").toString());// 实际班次
448 490 }
... ... @@ -476,8 +518,8 @@ public class FormsServiceImpl implements FormsService {
476 518 + " and '" + map.get("endDate").toString() + "' and xl_bm='"+ map.get("line").toString() + "' "
477 519 + " AND gs_bm is not null "
478 520 + " AND bc_type NOT IN ('in', 'out')"
479   - /*+ " and gs_bm='"+ map.get("gsdmTurn").toString() + "'"
480   - + " and fgs_bm='"+ map.get("fgsdmTurn").toString() + "'"*/
  521 + + " and gs_bm='"+ map.get("gsdmTurn").toString() + "'"
  522 + + " and fgs_bm='"+ map.get("fgsdmTurn").toString() + "'"
481 523 + " GROUP BY gs_bm,fgs_bm,xl_bm,gs_name,fgs_name,bc_type ) a left JOIN ("
482 524 + " SELECT COUNT(*) as xlgs,b.gs_bm,b.fgs_bm,b.xl_bm,b.gs_name,b.fgs_name, b.sbc,b.sxl ,b.scl,t.warrant_car "
483 525 + " from bsth_c_line t RIGHT JOIN (select gs_bm,fgs_bm,xl_bm,gs_name,fgs_name, count(*) as sbc,COUNT(DISTINCT xl_bm) as sxl ,COUNT(DISTINCT cl_zbh) as scl,bc_type from bsth_c_s_sp_info_real "
... ... @@ -510,7 +552,7 @@ public class FormsServiceImpl implements FormsService {
510 552 tu.setBcjh(arg0.getString("jbc").toString());
511 553 tu.setBcsj(arg0.getString("sbc").toString());
512 554 tu.setBbzxl(result2 + "%");// 班次执行率
513   - // tu.setSm(arg0.getString("gs_name").toString());
  555 + tu.setSm(arg0.getString("gs_name").toString());
514 556 tu.setGsgs(arg0.getString("gslsbm").toString());
515 557 tu.setFgsgs(arg0.getString("fgsbm").toString());
516 558 return tu;
... ... @@ -547,8 +589,8 @@ public class FormsServiceImpl implements FormsService {
547 589 + " from bsth_c_s_sp_info" + " where DATE_FORMAT(schedule_date,'%Y-%m-%d') BETWEEN '"
548 590 + map.get("startDate").toString() + "' and '" + map.get("endDate").toString() + "' and xl_bm='"
549 591 + map.get("line").toString() + "' AND gs_bm is not null AND bc_type NOT IN ('in', 'out')"
550   - /*+ " and gs_bm='"+ map.get("gsdmEcecut").toString() + "'"
551   - + " and fgs_bm='"+ map.get("fgsdmEcecut").toString() + "'"*/
  592 + + " and gs_bm='"+ map.get("gsdmEcecut").toString() + "'"
  593 + + " and fgs_bm='"+ map.get("fgsdmEcecut").toString() + "'"
552 594 + " GROUP BY gs_bm,fgs_bm,xl_bm,gs_name,fgs_name,bc_type ) a left JOIN ("
553 595 + "SELECT COUNT(*) as xlgs,b.gs_bm,b.fgs_bm,b.xl_bm,b.xl_name,b.gs_name,b.fgs_name, b.sbc,b.sxl ,b.scl "
554 596 + "from bsth_c_line t RIGHT JOIN (select gs_bm,fgs_bm,xl_bm,xl_name,gs_name,fgs_name, count(*) as sbc,COUNT(DISTINCT xl_bm) as sxl ,COUNT(DISTINCT cl_zbh) as scl,bc_type from bsth_c_s_sp_info_real "
... ... @@ -618,8 +660,8 @@ public class FormsServiceImpl implements FormsService {
618 660 + " from bsth_c_s_sp_info" + " where DATE_FORMAT(schedule_date,'%Y-%m-%d') BETWEEN '"
619 661 + map.get("startDate").toString() + "' and '" + map.get("endDate").toString() + "' and xl_bm='"
620 662 + map.get("line").toString() + "' AND gs_bm is not null AND bc_type NOT IN ('in', 'out') "
621   - /*+ " and gs_bm='"+ map.get("gsdmAllline").toString() + "'"
622   - + " and fgs_bm='"+ map.get("fgsdmAllline").toString() + "'"*/
  663 + + " and gs_bm='"+ map.get("gsdmAllline").toString() + "'"
  664 + + " and fgs_bm='"+ map.get("fgsdmAllline").toString() + "'"
623 665 + " GROUP BY gs_bm,fgs_bm,xl_bm,gs_name,fgs_name,bc_type ) a left JOIN ("
624 666 + "SELECT COUNT(*"
625 667 + ") as xlgs,b.gs_bm,b.fgs_bm,b.xl_bm,b."
... ... @@ -655,18 +697,13 @@ public class FormsServiceImpl implements FormsService {
655 697 tu.setBcsj(arg0.getString("sbc").toString());
656 698 tu.setBbzxl(result2 + "%");// 班次执行率
657 699  
658   - // tu.setSm(arg0.getString("xl_name").toString());
  700 + tu.setSm(arg0.getString("xl_name").toString());
659 701 tu.setGsgs(arg0.getString("gslsbm").toString());
660 702 tu.setFgsgs(arg0.getString("fgsbm").toString());
661 703 return tu;
662   - }
663   -
664   -
  704 + }
665 705 });
666 706  
667   -
668   -
669   -
670 707 return list;
671 708 }
672 709 }
... ...
src/main/java/com/bsth/service/gps/GpsService.java
... ... @@ -14,4 +14,6 @@ public interface GpsService {
14 14 Map<String, Object> search(Map<String, Object> map, int page, int size, String order, String direction);
15 15  
16 16 Map<String,Object> removeRealGps(String device);
  17 +
  18 + Map<String,Object> findRoadSpeed(String lineCode);
17 19 }
... ...
src/main/java/com/bsth/service/gps/GpsServiceImpl.java
1 1 package com.bsth.service.gps;
2 2  
3   -import java.lang.reflect.Field;
4   -import java.sql.Connection;
5   -import java.sql.PreparedStatement;
6   -import java.sql.ResultSet;
7   -import java.util.ArrayList;
8   -import java.util.Calendar;
9   -import java.util.Collection;
10   -import java.util.Collections;
11   -import java.util.Comparator;
12   -import java.util.Date;
13   -import java.util.HashMap;
14   -import java.util.List;
15   -import java.util.Map;
16   -
17   -import org.apache.commons.lang3.StringUtils;
18   -import org.slf4j.Logger;
19   -import org.slf4j.LoggerFactory;
20   -import org.springframework.beans.factory.annotation.Autowired;
21   -import org.springframework.stereotype.Service;
22   -
23 3 import com.bsth.common.ResponseCode;
24 4 import com.bsth.data.BasicData;
25 5 import com.bsth.data.arrival.ArrivalEntity;
... ... @@ -31,6 +11,19 @@ import com.bsth.util.DateUtils;
31 11 import com.bsth.util.TransGPS;
32 12 import com.bsth.util.TransGPS.Location;
33 13 import com.bsth.util.db.DBUtils_MS;
  14 +import org.apache.commons.lang3.StringUtils;
  15 +import org.slf4j.Logger;
  16 +import org.slf4j.LoggerFactory;
  17 +import org.springframework.beans.factory.annotation.Autowired;
  18 +import org.springframework.dao.DataAccessException;
  19 +import org.springframework.jdbc.core.JdbcTemplate;
  20 +import org.springframework.stereotype.Service;
  21 +
  22 +import java.lang.reflect.Field;
  23 +import java.sql.Connection;
  24 +import java.sql.PreparedStatement;
  25 +import java.sql.ResultSet;
  26 +import java.util.*;
34 27  
35 28 @Service
36 29 public class GpsServiceImpl implements GpsService {
... ... @@ -51,6 +44,9 @@ public class GpsServiceImpl implements GpsService {
51 44 @Autowired
52 45 GpsRealData gpsRealData;
53 46  
  47 + @Autowired
  48 + JdbcTemplate jdbcTemplate;
  49 +
54 50 // 历史gps查询
55 51 @Override
56 52 public List<Map<String, Object>> history(String device, Long startTime, Long endTime, int directions) {
... ... @@ -199,9 +195,9 @@ public class GpsServiceImpl implements GpsService {
199 195 inv = inv.substring(0, inv.length() - 1);
200 196  
201 197 // 查询到离站数据
202   - Map<String, ArrivalEntity> arrivalMap = findArrivalByTs(weekOfYear/* 30 */, st, et, inv);
  198 + //Map<String, ArrivalEntity> arrivalMap = findArrivalByTs(weekOfYear/* 30 */, st, et, inv);
203 199  
204   - String sql = "select DEVICE_ID,LON,LAT,TS,INOUT_STOP,SERVICE_STATE ,STOP_NO from bsth_c_gps_info where days_year=? and device_id in ("
  200 + String sql = "select DEVICE_ID,LON,LAT,TS,INOUT_STOP,SERVICE_STATE ,STOP_NO,DIRECTION,LINE_ID,SPEED_GPS from bsth_c_gps_info where days_year=? and device_id in ("
205 201 + inv + ") and ts > ? and ts < ?";
206 202 try {
207 203 conn = DBUtils_MS.getConnection();
... ... @@ -235,15 +231,19 @@ public class GpsServiceImpl implements GpsService {
235 231 map.put("ts", rs.getLong("TS"));
236 232 map.put("timestamp", rs.getLong("TS"));
237 233 map.put("stopNo", rs.getString("STOP_NO"));
  234 + map.put("direction", rs.getFloat("DIRECTION"));
  235 +
  236 + map.put("lineId", rs.getString("LINE_ID"));
  237 + map.put("speed", rs.getFloat("SPEED_GPS"));
238 238  
239 239 inOutStop = rs.getInt("INOUT_STOP");
240 240 map.put("inout_stop", inOutStop);
241 241  
242   - arrival = arrivalMap.get(rs.getString("DEVICE_ID") + "_" + rs.getLong("TS"));
243   - if (arrival != null) {
244   - map.put("inout_stop_info", arrival);
245   - map.put("inout_stop", arrival.getInOut());
246   - }
  242 + /*analyse = arrivalMap.get(rs.getString("DEVICE_ID") + "_" + rs.getLong("TS"));
  243 + if (analyse != null) {
  244 + map.put("inout_stop_info", analyse);
  245 + map.put("inout_stop", analyse.getInOut());
  246 + }*/
247 247 map.put("nbbm", BasicData.deviceId2NbbmMap.get(rs.getString("DEVICE_ID")));
248 248 map.put("state", 0);
249 249 // 上下行
... ... @@ -388,6 +388,22 @@ public class GpsServiceImpl implements GpsService {
388 388 return rs;
389 389 }
390 390  
  391 + @Override
  392 + public Map<String, Object> findRoadSpeed(String lineCode) {
  393 + Map<String, Object> rs = new HashMap<>();
  394 +
  395 + try {
  396 + String sql = "select ID, ST_AsText(GROAD_VECTOR) as GROAD_VECTOR,ROAD_CODE,ROAD_NAME,SPEED from bsth_c_road where road_code in(select section_code from bsth_c_sectionroute where line_code=? and destroy=0)";
  397 + List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, lineCode);
  398 + rs.put("status", ResponseCode.SUCCESS);
  399 + rs.put("roads", list);
  400 + } catch (DataAccessException e) {
  401 + logger.error("", e);
  402 + rs.put("status", ResponseCode.ERROR);
  403 + }
  404 + return rs;
  405 + }
  406 +
391 407 private void sortGpsList(final Field f, List<GpsEntity> rs) {
392 408 Collections.sort(rs, new Comparator<GpsEntity>() {
393 409  
... ...
src/main/java/com/bsth/service/impl/TrafficManageServiceImpl.java
... ... @@ -573,6 +573,7 @@ public class TrafficManageServiceImpl implements TrafficManageService{
573 573 String tomorrow = sdfnyr.format(DateUtils.addDays(new Date(), +1));
574 574 // 查询所有班次
575 575 List<SchedulePlanInfo> schedulePlanList = schedulePlanInfoRepository.findLineScheduleBc(tomorrow);
  576 + int j = 0; // 初始化标识
576 577 if(schedulePlanList != null ){
577 578 int size = schedulePlanList.size();
578 579 for (int i = 0; i < size; i++) {
... ... @@ -583,7 +584,7 @@ public class TrafficManageServiceImpl implements TrafficManageService{
583 584 if(line.getInUse() == null || line.getInUse() == 0){
584 585 continue;
585 586 }
586   - if(i == 0){// 第一次,则初始化值
  587 + if(++j == 1){// 第一次,则初始化值
587 588 zbh = schedulePlanInfo.getClZbh();
588 589 lp = schedulePlanInfo.getLp();
589 590 // 拼装XML
... ...
src/main/java/com/bsth/service/schedule/PeopleCarPlanServiceImpl.java
... ... @@ -912,7 +912,7 @@ public class PeopleCarPlanServiceImpl implements PeopleCarPlanService {
912 912 List<Map<String, Object>> resList = new ArrayList<Map<String, Object>>();
913 913 List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
914 914 Map<String, List<Map<String, Object>>> keyMap = new HashMap<String, List<Map<String, Object>>>();
915   - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
  915 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
916 916  
917 917 String company = map.get("company").toString();
918 918 String subCompany = map.get("subCompany").toString();
... ...
src/main/java/com/bsth/service/schedule/impl/TTInfoServiceImpl.java
1   -package com.bsth.service.schedule.impl;
2   -
3   -import com.bsth.entity.schedule.TTInfo;
4   -import com.bsth.service.schedule.ScheduleException;
5   -import com.bsth.service.schedule.TTInfoService;
6   -import org.apache.commons.lang3.StringUtils;
7   -import org.springframework.stereotype.Service;
8   -import org.springframework.transaction.annotation.Transactional;
9   -import org.springframework.util.CollectionUtils;
10   -
11   -import java.util.HashMap;
12   -import java.util.List;
13   -import java.util.Map;
14   -
15   -/**
16   - * Created by xu on 16/12/20.
17   - */
18   -@Service
19   -public class TTInfoServiceImpl extends BServiceImpl<TTInfo, Long> implements TTInfoService {
20   -
21   - @Override
22   - public void validate_name(TTInfo ttInfo) throws ScheduleException {
23   - // 名字重复验证
24   - Map<String, Object> param = new HashMap<>();
25   - if (ttInfo.getId() != null) {
26   - param.put("id_ne", ttInfo.getId());
27   - }
28   - param.put("xl.id_eq", ttInfo.getXl().getId());
29   - param.put("name_eq", ttInfo.getName());
30   -
31   - if (!CollectionUtils.isEmpty(list(param))) {
32   - throw new ScheduleException("名字重复");
33   - }
34   - }
35   -
36   - @Override
37   - public void validate_n_d(TTInfo ttInfo) throws ScheduleException {
38   - // 常规有效日重复验证
39   - // 找出所有未作废,已启用的时刻表,验证
40   - Map<String, Object> param = new HashMap<>();
41   - if (ttInfo.getId() != null) {
42   - param.put("id_ne", ttInfo.getId());
43   - }
44   - param.put("xl.id_eq", ttInfo.getXl().getId());
45   - param.put("isCancel_eq", false);
46   - param.put("isEnableDisTemplate_eq", true);
47   - List<TTInfo> ttInfos = list(param);
48   - if (StringUtils.isEmpty(ttInfo.getRule_days())) {
49   - throw new ScheduleException("常规有效日为空");
50   - } else {
51   - String[] nds = ttInfo.getRule_days().split(",");
52   - for (TTInfo t : ttInfos) {
53   - String[] nds_e = t.getRule_days().split(",");
54   - for (int i = 0; i < 7; i++) {
55   - if ("0".equals(nds[i])) {
56   - //
57   - } else {
58   - if (nds[i].equals(nds_e[i])) {
59   - throw new ScheduleException("当前常规有效日期已经使用");
60   - }
61   - }
62   - }
63   - }
64   - }
65   - }
66   -
67   - @Override
68   - public void validate_s_d(TTInfo ttInfo) throws ScheduleException {
69   - // 特殊有效日重复验证
70   - // 找出所有未作废,已启用的时刻表,验证
71   - Map<String, Object> param = new HashMap<>();
72   - if (ttInfo.getId() != null) {
73   - param.put("id_ne", ttInfo.getId());
74   - }
75   -
76   - param.put("xl.id_eq", ttInfo.getXl().getId());
77   - param.put("isCancel_eq", false);
78   - param.put("isEnableDisTemplate_eq", true);
79   - List<TTInfo> ttInfos = list(param);
80   - if (StringUtils.isEmpty(ttInfo.getSpecial_days())) {
81   - //
82   - } else {
83   - String[] sds = ttInfo.getSpecial_days().split(",");
84   - for (TTInfo t : ttInfos) {
85   - if (StringUtils.isEmpty(t.getSpecial_days())) {
86   - //
87   - } else {
88   - for (String sd : sds) {
89   - if (t.getSpecial_days().indexOf(sd) != -1) {
90   - throw new ScheduleException("当前特殊日期已经使用");
91   - }
92   - }
93   - }
94   - }
95   - }
96   - }
97   -
98   -
99   - @Transactional
100   - @Override
101   - public void delete(Long aLong) throws ScheduleException {
102   - toggleCancel(aLong);
103   - }
104   -
105   - @Transactional
106   - @Override
107   - public void toggleCancel(Long id) throws ScheduleException {
108   - TTInfo ttInfo = findById(id);
109   - if (ttInfo.getIsCancel()) {
110   - ttInfo.setIsCancel(false);
111   - } else {
112   - ttInfo.setIsCancel(true);
113   - }
114   - }
115   -}
  1 +package com.bsth.service.schedule.impl;
  2 +
  3 +import com.bsth.entity.schedule.TTInfo;
  4 +import com.bsth.service.schedule.ScheduleException;
  5 +import com.bsth.service.schedule.TTInfoService;
  6 +import org.apache.commons.lang3.StringUtils;
  7 +import org.springframework.stereotype.Service;
  8 +import org.springframework.transaction.annotation.Transactional;
  9 +import org.springframework.util.CollectionUtils;
  10 +
  11 +import java.util.HashMap;
  12 +import java.util.List;
  13 +import java.util.Map;
  14 +
  15 +/**
  16 + * Created by xu on 16/12/20.
  17 + */
  18 +@Service
  19 +public class TTInfoServiceImpl extends BServiceImpl<TTInfo, Long> implements TTInfoService {
  20 +
  21 + @Override
  22 + public void validate_name(TTInfo ttInfo) throws ScheduleException {
  23 + // 名字重复验证
  24 + Map<String, Object> param = new HashMap<>();
  25 + if (ttInfo.getId() != null) {
  26 + param.put("id_ne", ttInfo.getId());
  27 + }
  28 + param.put("xl.id_eq", ttInfo.getXl().getId());
  29 + param.put("name_eq", ttInfo.getName());
  30 +
  31 + if (!CollectionUtils.isEmpty(list(param))) {
  32 + throw new ScheduleException("名字重复");
  33 + }
  34 + }
  35 +
  36 + @Override
  37 + public void validate_n_d(TTInfo ttInfo) throws ScheduleException {
  38 + // 常规有效日重复验证
  39 + // 找出所有未作废,已启用的时刻表,验证
  40 + Map<String, Object> param = new HashMap<>();
  41 + if (ttInfo.getId() != null) {
  42 + param.put("id_ne", ttInfo.getId());
  43 + }
  44 + param.put("xl.id_eq", ttInfo.getXl().getId());
  45 + param.put("isCancel_eq", false);
  46 + param.put("isEnableDisTemplate_eq", true);
  47 + List<TTInfo> ttInfos = list(param);
  48 + if (StringUtils.isEmpty(ttInfo.getRule_days())) {
  49 + throw new ScheduleException("常规有效日为空");
  50 + } else {
  51 + String[] nds = ttInfo.getRule_days().split(",");
  52 + for (TTInfo t : ttInfos) {
  53 + String[] nds_e = t.getRule_days().split(",");
  54 + for (int i = 0; i < 7; i++) {
  55 + if ("0".equals(nds[i])) {
  56 + //
  57 + } else {
  58 + if (nds[i].equals(nds_e[i])) {
  59 + throw new ScheduleException("当前常规有效日期已经使用");
  60 + }
  61 + }
  62 + }
  63 + }
  64 + }
  65 + }
  66 +
  67 + @Override
  68 + public void validate_s_d(TTInfo ttInfo) throws ScheduleException {
  69 + // 特殊有效日重复验证
  70 + // 找出所有未作废,已启用的时刻表,验证
  71 + Map<String, Object> param = new HashMap<>();
  72 + if (ttInfo.getId() != null) {
  73 + param.put("id_ne", ttInfo.getId());
  74 + }
  75 +
  76 + param.put("xl.id_eq", ttInfo.getXl().getId());
  77 + param.put("isCancel_eq", false);
  78 + param.put("isEnableDisTemplate_eq", true);
  79 + List<TTInfo> ttInfos = list(param);
  80 + if (StringUtils.isEmpty(ttInfo.getSpecial_days())) {
  81 + //
  82 + } else {
  83 + String[] sds = ttInfo.getSpecial_days().split(",");
  84 + for (TTInfo t : ttInfos) {
  85 + if (StringUtils.isEmpty(t.getSpecial_days())) {
  86 + //
  87 + } else {
  88 + for (String sd : sds) {
  89 + if (t.getSpecial_days().indexOf(sd) != -1) {
  90 + throw new ScheduleException("当前特殊日期已经使用");
  91 + }
  92 + }
  93 + }
  94 + }
  95 + }
  96 + }
  97 +
  98 +
  99 + @Transactional
  100 + @Override
  101 + public void delete(Long aLong) throws ScheduleException {
  102 + toggleCancel(aLong);
  103 + }
  104 +
  105 + @Transactional
  106 + @Override
  107 + public void toggleCancel(Long id) throws ScheduleException {
  108 + TTInfo ttInfo = findById(id);
  109 + if (ttInfo.getIsCancel()) {
  110 + ttInfo.setIsCancel(false);
  111 + } else {
  112 + ttInfo.setIsCancel(true);
  113 + }
  114 + }
  115 +}
... ...