Commit a5a512715af323fbf2fd8772dc91430d2079aee8

Authored by 廖磊
2 parents 94029b6c 2987450f

Merge branch 'minhang' of 192.168.168.201:panzhaov5/bsth_control into minhang

Showing 73 changed files with 2797 additions and 776 deletions

Too many changes to show.

To preserve performance only 73 of 225 files are displayed.

README.md
1 -公交调度系统BS版 0.1 1 +公交调度系统BS版 0.1
2 ====== 2 ======
3 ---------- 3 ----------
4 ## 目录 4 ## 目录
@@ -336,4 +336,4 @@ @@ -336,4 +336,4 @@
336 { 336 {
337 "errCode":0 337 "errCode":0
338 } 338 }
339 -```  
340 \ No newline at end of file 339 \ No newline at end of file
  340 +```
@@ -197,6 +197,28 @@ @@ -197,6 +197,28 @@
197 <artifactId>kaptcha</artifactId> 197 <artifactId>kaptcha</artifactId>
198 <version>0.0.9</version> 198 <version>0.0.9</version>
199 </dependency> 199 </dependency>
  200 +
  201 + <dependency>
  202 + <groupId>commons-codec</groupId>
  203 + <artifactId>commons-codec</artifactId>
  204 + <version>1.4</version>
  205 + <scope>compile</scope>
  206 + </dependency>
  207 + <dependency>
  208 + <groupId>org.bouncycastle</groupId>
  209 + <artifactId>bcprov-jdk15on</artifactId>
  210 + <version>1.52</version>
  211 + </dependency>
  212 + <dependency>
  213 + <groupId>axis</groupId>
  214 + <artifactId>axis</artifactId>
  215 + <version>1.4</version>
  216 + </dependency>
  217 + <dependency>
  218 + <groupId>javax.xml</groupId>
  219 + <artifactId>jaxrpc-api</artifactId>
  220 + <version>1.1</version>
  221 + </dependency>
200 </dependencies> 222 </dependencies>
201 223
202 <dependencyManagement> 224 <dependencyManagement>
src/main/java/com/bsth/Application.java
@@ -16,7 +16,7 @@ import org.springframework.context.annotation.Primary; @@ -16,7 +16,7 @@ import org.springframework.context.annotation.Primary;
16 @SpringBootApplication 16 @SpringBootApplication
17 public class Application extends SpringBootServletInitializer { 17 public class Application extends SpringBootServletInitializer {
18 18
19 - public static ScheduledExecutorService mainServices = Executors.newScheduledThreadPool(8); 19 + public static ScheduledExecutorService mainServices = Executors.newScheduledThreadPool(11);
20 20
21 @Override 21 @Override
22 protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 22 protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
src/main/java/com/bsth/Test.java deleted 100644 → 0
1 -//package com.bsth;  
2 -//  
3 -//import java.io.ByteArrayOutputStream;  
4 -//import java.io.IOException;  
5 -//import java.io.InputStream;  
6 -//import java.io.OutputStream;  
7 -//import java.net.HttpURLConnection;  
8 -//import java.net.URL;  
9 -//import java.util.HashMap;  
10 -//import java.util.Map;  
11 -//  
12 -//import org.apache.commons.io.IOUtils;  
13 -//  
14 -//import com.fasterxml.jackson.databind.ObjectMapper;  
15 -//  
16 -//public class Test {  
17 -//  
18 -// public static void main(String[] args) {  
19 -// Map<String, Object> map = new HashMap<>();  
20 -// map.put("timestamp", 1469764939000L);  
21 -// map.put("operCode", 128);  
22 -// map.put("deviceId", "66ML0007");  
23 -//  
24 -// Map<String , Object> dataMap = new HashMap<>();  
25 -// dataMap.put("requestCode", 161);  
26 -// dataMap.put("lineId", 1025);  
27 -// dataMap.put("operCode2", 38);  
28 -//  
29 -// map.put("data", dataMap);  
30 -// request(map, "http://192.168.168.171:9088/control/upstream");  
31 -//  
32 -// }  
33 -//  
34 -// private static Map<String, Object> request(Map<String, Object> map, String url) {  
35 -// InputStream in = null;  
36 -// OutputStream out = null;  
37 -// HttpURLConnection con = null;  
38 -// try {  
39 -// con = (HttpURLConnection)new URL(url).openConnection();  
40 -// con.setRequestMethod("POST");  
41 -// con.setRequestProperty("keep-alive", "true");  
42 -// con.setRequestProperty("accept", "*/*");  
43 -// con.setDoInput(true);  
44 -// con.setDoOutput(true);  
45 -// con.setReadTimeout(2500);  
46 -// con.setConnectTimeout(2500);  
47 -// out = con.getOutputStream();  
48 -// out.write("json=".getBytes());  
49 -// out.write(new ObjectMapper().writeValueAsBytes(map));  
50 -// out.flush();  
51 -// System.out.println("con.getResponseCode(): " + con.getResponseCode());  
52 -// if (con.getResponseCode() == 200) {  
53 -// in = con.getInputStream();  
54 -// ByteArrayOutputStream bout = new ByteArrayOutputStream();  
55 -// IOUtils.copy(in, bout); bout.close();  
56 -// System.out.println("Message:" + new String(bout.toByteArray()));  
57 -// return new ObjectMapper().readValue(bout.toByteArray(), Map.class);  
58 -// }  
59 -// } catch (IOException e) {  
60 -// e.printStackTrace();  
61 -// } finally {  
62 -// con.disconnect();  
63 -// try {  
64 -// if (in != null) in.close();  
65 -// if (out != null) out.close();  
66 -// } catch (IOException e) {  
67 -// e.printStackTrace();  
68 -// }  
69 -// }  
70 -// return null;  
71 -// }  
72 -//}  
src/main/java/com/bsth/Test2.java deleted 100644 → 0
1 -package com.bsth;  
2 -  
3 -public class Test2 {  
4 -  
5 - public static void main(String[] args) {  
6 -  
7 - for(int i = 0; i < 20; i ++){  
8 - new MyThread(i + "").start();  
9 - }  
10 - }  
11 -  
12 - public static class MyThread extends Thread {  
13 -  
14 - private String name ;  
15 -  
16 - public MyThread(String name) {  
17 - this.name = name;  
18 - }  
19 -  
20 - @Override  
21 - public void run() {  
22 - method(name);  
23 - }  
24 - }  
25 -  
26 - public static void method(String name){  
27 - System.out.println("线程" + name + "开始...");  
28 - int a = 0;  
29 - for(int i = 0; i < 1000; i ++){  
30 - a ++;  
31 - }  
32 - a--;  
33 - System.out.println("线程" + name + "结束... a = " + a);  
34 - }  
35 -}  
src/main/java/com/bsth/controller/StationRouteController.java
@@ -120,6 +120,15 @@ public class StationRouteController extends BaseController&lt;StationRoute, Integer @@ -120,6 +120,15 @@ public class StationRouteController extends BaseController&lt;StationRoute, Integer
120 return stationRouteRepository.findStations(xlid, xldir); 120 return stationRouteRepository.findStations(xlid, xldir);
121 } 121 }
122 122
123 - 123 + /**
  124 + *
  125 + * @Title: findByMultiLine
  126 + * @Description: TODO(多线路路由查询)
  127 + */
  128 + @RequestMapping(value = "/multiLine", method = RequestMethod.GET)
  129 + public Map<String, Object> findByMultiLine(@RequestParam String lineIds){
  130 +
  131 + return service.findByMultiLine(lineIds);
  132 + }
124 133
125 } 134 }
src/main/java/com/bsth/controller/directive/DirectiveController.java
@@ -63,7 +63,7 @@ public class DirectiveController { @@ -63,7 +63,7 @@ public class DirectiveController {
63 * @throws 63 * @throws
64 */ 64 */
65 @RequestMapping(value = "/lineChnage", method = RequestMethod.POST) 65 @RequestMapping(value = "/lineChnage", method = RequestMethod.POST)
66 - public int lineChange(@RequestParam String nbbm, @RequestParam Integer lineId){ 66 + public int lineChange(@RequestParam String nbbm, @RequestParam String lineId){
67 SysUser user = SecurityUtils.getCurrentUser(); 67 SysUser user = SecurityUtils.getCurrentUser();
68 return directiveService.lineChange(nbbm, lineId, user.getUserName()); 68 return directiveService.lineChange(nbbm, lineId, user.getUserName());
69 } 69 }
src/main/java/com/bsth/controller/directive/UpstreamEntrance.java
@@ -3,7 +3,6 @@ package com.bsth.controller.directive; @@ -3,7 +3,6 @@ package com.bsth.controller.directive;
3 import org.slf4j.Logger; 3 import org.slf4j.Logger;
4 import org.slf4j.LoggerFactory; 4 import org.slf4j.LoggerFactory;
5 import org.springframework.beans.factory.annotation.Autowired; 5 import org.springframework.beans.factory.annotation.Autowired;
6 -import org.springframework.context.annotation.Scope;  
7 import org.springframework.web.bind.annotation.RequestMapping; 6 import org.springframework.web.bind.annotation.RequestMapping;
8 import org.springframework.web.bind.annotation.RequestMethod; 7 import org.springframework.web.bind.annotation.RequestMethod;
9 import org.springframework.web.bind.annotation.RequestParam; 8 import org.springframework.web.bind.annotation.RequestParam;
@@ -26,7 +25,6 @@ import com.bsth.entity.directive.DirectiveReponse; @@ -26,7 +25,6 @@ import com.bsth.entity.directive.DirectiveReponse;
26 */ 25 */
27 @RestController 26 @RestController
28 @RequestMapping("/control") 27 @RequestMapping("/control")
29 -@Scope("prototype")  
30 public class UpstreamEntrance { 28 public class UpstreamEntrance {
31 29
32 Logger logger = LoggerFactory.getLogger(this.getClass()); 30 Logger logger = LoggerFactory.getLogger(this.getClass());
src/main/java/com/bsth/controller/forecast/SampleController.java
1 package com.bsth.controller.forecast; 1 package com.bsth.controller.forecast;
2 2
  3 +import java.io.UnsupportedEncodingException;
  4 +import java.net.URLDecoder;
  5 +import java.util.HashMap;
  6 +import java.util.Map;
  7 +
  8 +import org.slf4j.Logger;
  9 +import org.slf4j.LoggerFactory;
3 import org.springframework.beans.factory.annotation.Autowired; 10 import org.springframework.beans.factory.annotation.Autowired;
4 import org.springframework.web.bind.annotation.RequestMapping; 11 import org.springframework.web.bind.annotation.RequestMapping;
  12 +import org.springframework.web.bind.annotation.RequestParam;
5 import org.springframework.web.bind.annotation.RestController; 13 import org.springframework.web.bind.annotation.RestController;
6 14
  15 +import com.alibaba.fastjson.JSON;
  16 +import com.alibaba.fastjson.JSONObject;
  17 +import com.bsth.common.ResponseCode;
7 import com.bsth.controller.BaseController; 18 import com.bsth.controller.BaseController;
  19 +import com.bsth.controller.forecast.dto.CreateSampleParam;
8 import com.bsth.entity.forecast.Sample; 20 import com.bsth.entity.forecast.Sample;
9 import com.bsth.service.forecast.SampleService; 21 import com.bsth.service.forecast.SampleService;
10 22
@@ -15,8 +27,20 @@ public class SampleController extends BaseController&lt;Sample, Long&gt;{ @@ -15,8 +27,20 @@ public class SampleController extends BaseController&lt;Sample, Long&gt;{
15 @Autowired 27 @Autowired
16 SampleService sampleService; 28 SampleService sampleService;
17 29
  30 + Logger loger = LoggerFactory.getLogger(this.getClass());
  31 +
18 @RequestMapping("/create/gps") 32 @RequestMapping("/create/gps")
19 - public int createDataByGps(String lineCode, Integer updown){  
20 - return sampleService.createDataByGps(lineCode, updown); 33 + public Map<String, Object> createDataByGps(@RequestParam String data){
  34 + Map<String, Object> rs = new HashMap<>();
  35 + try {
  36 + data = URLDecoder.decode(data, "utf-8");
  37 + CreateSampleParam param = JSONObject.toJavaObject(JSON.parseObject(data), CreateSampleParam.class);
  38 +
  39 + rs = sampleService.createDataByGps(param);
  40 + } catch (UnsupportedEncodingException e) {
  41 + loger.info("", e);
  42 + rs.put("status", ResponseCode.ERROR);
  43 + }
  44 + return rs;
21 } 45 }
22 } 46 }
src/main/java/com/bsth/controller/forecast/dto/CreateSampleParam.java 0 → 100644
  1 +package com.bsth.controller.forecast.dto;
  2 +
  3 +import java.util.Set;
  4 +
  5 +public class CreateSampleParam {
  6 +
  7 + private String lineCode;
  8 +
  9 + private String startDate;
  10 +
  11 + private String endDate;
  12 +
  13 + private Integer updown;
  14 +
  15 + private Set<TimeRange> timeRange;
  16 +
  17 + public static class TimeRange{
  18 + private String s;
  19 + private String e;
  20 + private String tag;
  21 + public String getS() {
  22 + return s;
  23 + }
  24 + public void setS(String s) {
  25 + this.s = s;
  26 + }
  27 + public String getE() {
  28 + return e;
  29 + }
  30 + public void setE(String e) {
  31 + this.e = e;
  32 + }
  33 + public String getTag() {
  34 + return tag;
  35 + }
  36 + public void setTag(String tag) {
  37 + this.tag = tag;
  38 + }
  39 + }
  40 +
  41 + public String getLineCode() {
  42 + return lineCode;
  43 + }
  44 +
  45 + public void setLineCode(String lineCode) {
  46 + this.lineCode = lineCode;
  47 + }
  48 +
  49 + public String getStartDate() {
  50 + return startDate;
  51 + }
  52 +
  53 + public void setStartDate(String startDate) {
  54 + this.startDate = startDate;
  55 + }
  56 +
  57 + public String getEndDate() {
  58 + return endDate;
  59 + }
  60 +
  61 + public void setEndDate(String endDate) {
  62 + this.endDate = endDate;
  63 + }
  64 +
  65 + public Integer getUpdown() {
  66 + return updown;
  67 + }
  68 +
  69 + public void setUpdown(Integer updown) {
  70 + this.updown = updown;
  71 + }
  72 +
  73 + public Set<TimeRange> getTimeRange() {
  74 + return timeRange;
  75 + }
  76 +
  77 + public void setTimeRange(Set<TimeRange> timeRange) {
  78 + this.timeRange = timeRange;
  79 + }
  80 +}
src/main/java/com/bsth/controller/gps/GpsController.java
@@ -24,14 +24,25 @@ public class GpsController { @@ -24,14 +24,25 @@ public class GpsController {
24 24
25 @Autowired 25 @Autowired
26 GpsService gpsService; 26 GpsService gpsService;
  27 +
  28 + @RequestMapping(value = "/real/all")
  29 + public Map<String, Object> search(@RequestParam Map<String, Object> map,
  30 + @RequestParam(defaultValue = "0") int page,
  31 + @RequestParam(defaultValue = "15") int size,
  32 + @RequestParam(defaultValue = "timestamp") String order,
  33 + @RequestParam(defaultValue = "DESC") String direction){
  34 +
  35 +
  36 + return gpsService.search(map, page, size, order, direction);
  37 + }
27 38
28 @RequestMapping(value = "/real/line/{lineCode}") 39 @RequestMapping(value = "/real/line/{lineCode}")
29 - public List<GpsEntity> findByLineCode(@PathVariable("lineCode") Integer lineCode) {  
30 - return gpsRealData.get(lineCode); 40 + public List<GpsEntity> findByLineCode(@PathVariable("lineCode") String lineCode) {
  41 + return gpsRealData.getByLine(lineCode);
31 } 42 }
32 43
33 @RequestMapping(value = "/real/line") 44 @RequestMapping(value = "/real/line")
34 - public List<GpsEntity> findByLineCode(@RequestParam String lineCodes) { 45 + public List<GpsEntity> findByLineCodes(@RequestParam String lineCodes) {
35 return gpsRealData.get(Splitter.on(",").splitToList(lineCodes)); 46 return gpsRealData.get(Splitter.on(",").splitToList(lineCodes));
36 } 47 }
37 48
src/main/java/com/bsth/controller/realcontrol/BasicDataController.java 0 → 100644
  1 +package com.bsth.controller.realcontrol;
  2 +
  3 +import java.util.Map;
  4 +
  5 +import org.springframework.web.bind.annotation.RequestMapping;
  6 +import org.springframework.web.bind.annotation.RestController;
  7 +
  8 +import com.bsth.data.BasicData;
  9 +
  10 +@RestController
  11 +@RequestMapping("/basic")
  12 +public class BasicDataController {
  13 +
  14 +
  15 + @RequestMapping("/cars")
  16 + public Iterable<String> findAllNbbm(Map<String, Object> map){
  17 + return BasicData.deviceId2NbbmMap.values();
  18 + }
  19 +
  20 + @RequestMapping("/lineCode2Name")
  21 + public Map<String, String> findLineCodeMap(){
  22 + return BasicData.lineCode2NameMap;
  23 + }
  24 +}
src/main/java/com/bsth/controller/realcontrol/ScheduleRealInfoController.java
1 package com.bsth.controller.realcontrol; 1 package com.bsth.controller.realcontrol;
2 2
  3 +import java.io.UnsupportedEncodingException;
  4 +import java.net.URLDecoder;
3 import java.util.Collection; 5 import java.util.Collection;
4 import java.util.List; 6 import java.util.List;
5 import java.util.Map; 7 import java.util.Map;
6 8
  9 +import org.apache.commons.lang3.StringEscapeUtils;
7 import org.springframework.beans.factory.annotation.Autowired; 10 import org.springframework.beans.factory.annotation.Autowired;
8 import org.springframework.web.bind.annotation.PathVariable; 11 import org.springframework.web.bind.annotation.PathVariable;
9 import org.springframework.web.bind.annotation.RequestMapping; 12 import org.springframework.web.bind.annotation.RequestMapping;
@@ -223,6 +226,8 @@ public class ScheduleRealInfoController extends BaseController&lt;ScheduleRealInfo, @@ -223,6 +226,8 @@ public class ScheduleRealInfoController extends BaseController&lt;ScheduleRealInfo,
223 */ 226 */
224 @RequestMapping(value = "/outgoAdjustAll", method = RequestMethod.POST) 227 @RequestMapping(value = "/outgoAdjustAll", method = RequestMethod.POST)
225 public Map<String, Object> outgoAdjustAll(@RequestParam String params){ 228 public Map<String, Object> outgoAdjustAll(@RequestParam String params){
  229 + //反转义
  230 + params = StringEscapeUtils.unescapeHtml4(params);
226 return scheduleRealInfoService.outgoAdjustAll(params); 231 return scheduleRealInfoService.outgoAdjustAll(params);
227 } 232 }
228 233
@@ -257,7 +262,7 @@ public class ScheduleRealInfoController extends BaseController&lt;ScheduleRealInfo, @@ -257,7 +262,7 @@ public class ScheduleRealInfoController extends BaseController&lt;ScheduleRealInfo,
257 * @throws 262 * @throws
258 */ 263 */
259 @RequestMapping(value = "/findRouteByLine") 264 @RequestMapping(value = "/findRouteByLine")
260 - public Map<String, Object> findRouteByLine(@RequestParam Integer lineCode){ 265 + public Map<String, Object> findRouteByLine(@RequestParam String lineCode){
261 return scheduleRealInfoService.findRouteByLine(lineCode); 266 return scheduleRealInfoService.findRouteByLine(lineCode);
262 } 267 }
263 268
src/main/java/com/bsth/controller/schedule/CarConfigInfoController.java
@@ -51,4 +51,9 @@ public class CarConfigInfoController extends BaseController&lt;CarConfigInfo, Long&gt; @@ -51,4 +51,9 @@ public class CarConfigInfoController extends BaseController&lt;CarConfigInfo, Long&gt;
51 public List<Map<String, Object>> findCarConfigCars() { 51 public List<Map<String, Object>> findCarConfigCars() {
52 return carConfigInfoRepository.findCarConfigCars(); 52 return carConfigInfoRepository.findCarConfigCars();
53 } 53 }
  54 +
  55 + @RequestMapping(value = "/cars2", method = RequestMethod.GET)
  56 + public List<Map<String, Object>> findCarsFromConfig() {
  57 + return carConfigInfoRepository.findCarsFromConfig();
  58 + }
54 } 59 }
src/main/java/com/bsth/controller/schedule/EmployeeConfigInfoController.java
@@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired; @@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
8 import org.springframework.boot.context.properties.EnableConfigurationProperties; 8 import org.springframework.boot.context.properties.EnableConfigurationProperties;
9 import org.springframework.web.bind.annotation.*; 9 import org.springframework.web.bind.annotation.*;
10 10
  11 +import java.util.List;
11 import java.util.Map; 12 import java.util.Map;
12 13
13 /** 14 /**
@@ -45,4 +46,14 @@ public class EmployeeConfigInfoController extends BaseController&lt;EmployeeConfigI @@ -45,4 +46,14 @@ public class EmployeeConfigInfoController extends BaseController&lt;EmployeeConfigI
45 public Map<String, Object> save(@RequestBody EmployeeConfigInfo t){ 46 public Map<String, Object> save(@RequestBody EmployeeConfigInfo t){
46 return baseService.save(t); 47 return baseService.save(t);
47 } 48 }
  49 +
  50 + @RequestMapping(value = "/jsy", method = RequestMethod.GET)
  51 + public List<Map<String, Object>> findJsyFromConfig() {
  52 + return employeeConfigInfoRepository.findJsyFromConfig();
  53 + }
  54 +
  55 + @RequestMapping(value = "/spy", method = RequestMethod.GET)
  56 + public List<Map<String, Object>> findSpyFromConfig() {
  57 + return employeeConfigInfoRepository.findSpyFromConfig();
  58 + }
48 } 59 }
src/main/java/com/bsth/controller/schedule/SchedulePlanController.java
@@ -4,10 +4,11 @@ import com.bsth.controller.BaseController; @@ -4,10 +4,11 @@ import com.bsth.controller.BaseController;
4 import com.bsth.entity.schedule.SchedulePlan; 4 import com.bsth.entity.schedule.SchedulePlan;
5 import com.bsth.service.schedule.SchedulePlanService; 5 import com.bsth.service.schedule.SchedulePlanService;
6 import org.springframework.beans.factory.annotation.Autowired; 6 import org.springframework.beans.factory.annotation.Autowired;
7 -import org.springframework.web.bind.annotation.*; 7 +import org.springframework.web.bind.annotation.RequestBody;
  8 +import org.springframework.web.bind.annotation.RequestMapping;
  9 +import org.springframework.web.bind.annotation.RequestMethod;
  10 +import org.springframework.web.bind.annotation.RestController;
8 11
9 -import java.util.Date;  
10 -import java.util.List;  
11 import java.util.Map; 12 import java.util.Map;
12 13
13 /** 14 /**
@@ -34,21 +35,18 @@ public class SchedulePlanController extends BaseController&lt;SchedulePlan, Long&gt; { @@ -34,21 +35,18 @@ public class SchedulePlanController extends BaseController&lt;SchedulePlan, Long&gt; {
34 return baseService.save(t); 35 return baseService.save(t);
35 } 36 }
36 37
37 - // TODO:  
38 -// @RequestMapping(value = "/groupinfos/{xlid}/{date}", method = RequestMethod.GET)  
39 -// public List<Map<String, Object>> findGroupInfo(  
40 -// Integer xlid, Date scheduleDate) {  
41 -//  
42 -// }  
43 -  
44 - @RequestMapping(value = "/groupinfos/{xlid}/{date}", method = RequestMethod.GET)  
45 - public List<Map<String, Object>> findGroupInfo(  
46 - @PathVariable(value = "xlid") Integer xlid,  
47 - @PathVariable(value = "date") Date scheduleDate) {  
48 - return schedulePlanService.findGroupInfo(xlid, scheduleDate); 38 + /**
  39 + * 获取明天的一歌排班计划。
  40 + * @return
  41 + * @throws Exception
  42 + */
  43 + @RequestMapping(value = "/tommorw", method = RequestMethod.GET)
  44 + public SchedulePlan getTommorwPlan() throws Exception {
  45 + try {
  46 + return schedulePlanService.findSchedulePlanTommorw();
  47 + } catch (Exception exp) {
  48 + throw new Exception(exp.getCause());
  49 + }
49 } 50 }
50 51
51 -// public int updateGroupInfo  
52 -  
53 -  
54 } 52 }
src/main/java/com/bsth/controller/schedule/SchedulePlanInfoController.java
1 package com.bsth.controller.schedule; 1 package com.bsth.controller.schedule;
2 2
  3 +import com.bsth.common.ResponseCode;
3 import com.bsth.controller.BaseController; 4 import com.bsth.controller.BaseController;
4 import com.bsth.entity.schedule.SchedulePlanInfo; 5 import com.bsth.entity.schedule.SchedulePlanInfo;
5 -import org.springframework.web.bind.annotation.RequestMapping;  
6 -import org.springframework.web.bind.annotation.RestController; 6 +import com.bsth.service.schedule.SchedulePlanInfoService;
  7 +import org.springframework.beans.factory.annotation.Autowired;
  8 +import org.springframework.web.bind.annotation.*;
  9 +
  10 +import java.util.Date;
  11 +import java.util.HashMap;
  12 +import java.util.List;
  13 +import java.util.Map;
7 14
8 /** 15 /**
9 * Created by xu on 16/6/16. 16 * Created by xu on 16/6/16.
@@ -11,5 +18,30 @@ import org.springframework.web.bind.annotation.RestController; @@ -11,5 +18,30 @@ import org.springframework.web.bind.annotation.RestController;
11 @RestController 18 @RestController
12 @RequestMapping("spic") 19 @RequestMapping("spic")
13 public class SchedulePlanInfoController extends BaseController<SchedulePlanInfo, Long> { 20 public class SchedulePlanInfoController extends BaseController<SchedulePlanInfo, Long> {
  21 + @Autowired
  22 + private SchedulePlanInfoService schedulePlanInfoService;
  23 +
  24 + @RequestMapping(value = "/groupinfos/{xlid}/{date}", method = RequestMethod.GET)
  25 + public List<SchedulePlanInfoService.GroupInfo> findGroupInfo(
  26 + @PathVariable(value = "xlid") Integer xlid,
  27 + @PathVariable(value = "date") Date scheduleDate) {
  28 + return schedulePlanInfoService.findGroupInfo(xlid, scheduleDate);
  29 + }
  30 +
  31 + @RequestMapping(value = "/groupinfos/update", method = RequestMethod.POST)
  32 + public Map<String, Object> updateGroupInfo(@RequestBody SchedulePlanInfoService.GroupInfoUpdate groupInfoUpdate) {
  33 + Map<String, Object> resultMap = new HashMap<>();
  34 + try {
  35 + schedulePlanInfoService.updateGroupInfo(groupInfoUpdate);
  36 +
  37 + resultMap.put("status", ResponseCode.SUCCESS);
  38 + resultMap.put("msg", "更新成功");
  39 + } catch (Exception exp) {
  40 + exp.printStackTrace();
  41 + resultMap.put("status", ResponseCode.ERROR);
  42 + resultMap.put("msg", exp.getLocalizedMessage());
  43 + }
14 44
  45 + return resultMap;
  46 + }
15 } 47 }
src/main/java/com/bsth/controller/schedule/TrafficManageController.java 0 → 100644
  1 +package com.bsth.controller.schedule;
  2 +
  3 +import com.bsth.service.TrafficManageService;
  4 +
  5 +import org.springframework.beans.factory.annotation.Autowired;
  6 +import org.springframework.web.bind.annotation.RequestMapping;
  7 +import org.springframework.web.bind.annotation.RequestMethod;
  8 +import org.springframework.web.bind.annotation.RestController;
  9 +
  10 +/**
  11 + *
  12 + * @author BSTH
  13 + *
  14 + */
  15 +@RestController
  16 +@RequestMapping("trmg")
  17 +public class TrafficManageController {
  18 +
  19 + @Autowired
  20 + private TrafficManageService trManageService;
  21 +
  22 +
  23 + @RequestMapping(value = "/setXL", method = RequestMethod.GET)
  24 + public String setXL() throws Exception {
  25 + try {
  26 + return trManageService.setXL();
  27 + } catch (Exception exp) {
  28 + throw new Exception(exp.getCause());
  29 + }
  30 + }
  31 +}
src/main/java/com/bsth/controller/sys/UserController.java
@@ -7,7 +7,6 @@ import javax.servlet.http.HttpServletRequest; @@ -7,7 +7,6 @@ import javax.servlet.http.HttpServletRequest;
7 import javax.servlet.http.HttpSession; 7 import javax.servlet.http.HttpSession;
8 8
9 import org.apache.commons.lang3.StringUtils; 9 import org.apache.commons.lang3.StringUtils;
10 -import org.apache.commons.net.util.Base64;  
11 import org.slf4j.Logger; 10 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory; 11 import org.slf4j.LoggerFactory;
13 import org.springframework.beans.factory.annotation.Autowired; 12 import org.springframework.beans.factory.annotation.Autowired;
@@ -22,6 +21,7 @@ import org.springframework.web.bind.annotation.RestController; @@ -22,6 +21,7 @@ import org.springframework.web.bind.annotation.RestController;
22 import com.bsth.common.Constants; 21 import com.bsth.common.Constants;
23 import com.bsth.common.ResponseCode; 22 import com.bsth.common.ResponseCode;
24 import com.bsth.controller.BaseController; 23 import com.bsth.controller.BaseController;
  24 +import com.bsth.controller.sys.util.RSAUtils;
25 import com.bsth.entity.sys.SysUser; 25 import com.bsth.entity.sys.SysUser;
26 import com.bsth.security.util.SecurityUtils; 26 import com.bsth.security.util.SecurityUtils;
27 import com.bsth.service.sys.SysUserService; 27 import com.bsth.service.sys.SysUserService;
@@ -35,12 +35,21 @@ public class UserController extends BaseController&lt;SysUser, Integer&gt; { @@ -35,12 +35,21 @@ public class UserController extends BaseController&lt;SysUser, Integer&gt; {
35 @Autowired 35 @Autowired
36 SysUserService sysUserService; 36 SysUserService sysUserService;
37 37
  38 + @RequestMapping(value = "/login/jCryptionKey")
  39 + public Map<String, Object> jCryptionKey(HttpServletRequest request){
  40 + //公匙返回页面
  41 + Map<String, Object> rs = new HashMap<>();
  42 + rs.put("publickey", RSAUtils.generateBase64PublicKey());
  43 + return rs;
  44 + }
  45 +
38 //需要验证码的账号 46 //需要验证码的账号
39 public static Map<String, Integer> captchaMap = new HashMap<>(); 47 public static Map<String, Integer> captchaMap = new HashMap<>();
40 48
41 @RequestMapping(value = "/login", method = RequestMethod.POST) 49 @RequestMapping(value = "/login", method = RequestMethod.POST)
42 public Map<String, Object> login(HttpServletRequest request, @RequestParam String userName, 50 public Map<String, Object> login(HttpServletRequest request, @RequestParam String userName,
43 - @RequestParam String password) { 51 + @RequestParam String password, String captcha) {
  52 +
44 Map<String, Object> rs = new HashMap<>(); 53 Map<String, Object> rs = new HashMap<>();
45 rs.put("status", ResponseCode.ERROR); 54 rs.put("status", ResponseCode.ERROR);
46 try { 55 try {
@@ -51,32 +60,26 @@ public class UserController extends BaseController&lt;SysUser, Integer&gt; { @@ -51,32 +60,26 @@ public class UserController extends BaseController&lt;SysUser, Integer&gt; {
51 //校验验证码 60 //校验验证码
52 String verCode = (String) session 61 String verCode = (String) session
53 .getAttribute(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY); 62 .getAttribute(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY);
54 - String captcha = request.getParameter("captcha");  
55 63
56 - if(StringUtils.isBlank(captcha)){  
57 - rs.put("msg", "请输入验证码");  
58 - return rs;  
59 - } 64 + if(StringUtils.isBlank(captcha))
  65 + return put(rs, "msg", "请输入验证码");
60 66
61 - if(!verCode.equals(captcha)){  
62 - rs.put("msg", "验证码有误,请刷新后重新输入");  
63 - return rs;  
64 - } 67 + if(!verCode.equals(captcha))
  68 + return put(rs, "msg", "验证码有误,请刷新后重新输入");
65 } 69 }
66 70
  71 + //解密RSA
  72 + userName = RSAUtils.decryptBase64(userName);
  73 + password = RSAUtils.decryptBase64(password);
  74 +
67 SysUser user = sysUserService.findByUserName(userName); 75 SysUser user = sysUserService.findByUserName(userName);
68 - if (null == user) {  
69 - rs.put("msg", "不存在的用户");  
70 - return rs;  
71 - } 76 + if (null == user)
  77 + return put(rs, "msg", "不存在的用户");
72 78
73 - if (!user.isEnabled()) {  
74 - rs.put("msg", "该用户已被锁定,请联系管理员");  
75 - return rs;  
76 - } 79 + if (!user.isEnabled())
  80 + return put(rs, "msg", "该用户已被锁定,请联系管理员");
77 81
78 // 校验密码 82 // 校验密码
79 - password = fourDecodeBase64(password);  
80 boolean matchStatus = new BCryptPasswordEncoder(4).matches(password, user.getPassword()); 83 boolean matchStatus = new BCryptPasswordEncoder(4).matches(password, user.getPassword());
81 if (!matchStatus) { 84 if (!matchStatus) {
82 rs.put("msg", "密码有误"); 85 rs.put("msg", "密码有误");
@@ -109,9 +112,10 @@ public class UserController extends BaseController&lt;SysUser, Integer&gt; { @@ -109,9 +112,10 @@ public class UserController extends BaseController&lt;SysUser, Integer&gt; {
109 Integer size = captchaMap.get(userName); 112 Integer size = captchaMap.get(userName);
110 return size == null?0:size; 113 return size == null?0:size;
111 } 114 }
112 -  
113 - private String fourDecodeBase64(String t) {  
114 - return new String(Base64.decodeBase64(Base64.decodeBase64(Base64.decodeBase64(Base64.decodeBase64(t))))); 115 +
  116 + public Map<String, Object> put(Map<String, Object> rs, String key, Object val){
  117 + rs.put(key, val);
  118 + return rs;
115 } 119 }
116 120
117 /** 121 /**
src/main/java/com/bsth/controller/sys/util/RSAUtils.java 0 → 100644
  1 +package com.bsth.controller.sys.util;
  2 +
  3 +import java.security.KeyPair;
  4 +import java.security.KeyPairGenerator;
  5 +import java.security.SecureRandom;
  6 +import java.security.Security;
  7 +import java.security.interfaces.RSAPrivateKey;
  8 +import java.security.interfaces.RSAPublicKey;
  9 +
  10 +import javax.crypto.Cipher;
  11 +
  12 +import org.apache.commons.net.util.Base64;
  13 +
  14 +public class RSAUtils {
  15 + private static final KeyPair keyPair = initKey();
  16 +
  17 + private static KeyPair initKey(){
  18 + try {
  19 + Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
  20 + SecureRandom random = new SecureRandom();
  21 + KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA", "BC");
  22 + generator.initialize(1024, random);
  23 + return generator.generateKeyPair();
  24 + }catch (Exception e) {
  25 + throw new RuntimeException(e);
  26 + }
  27 + }
  28 +
  29 + /**
  30 + * 生成public key
  31 + * @return
  32 + */
  33 + public static String generateBase64PublicKey(){
  34 + RSAPublicKey key = (RSAPublicKey)keyPair.getPublic();
  35 + return new String(Base64.encodeBase64(key.getEncoded()));
  36 + }
  37 +
  38 + /**
  39 + * 解密
  40 + * @param string
  41 + * @return
  42 + */
  43 + public static String decryptBase64(String string) {
  44 + return new String(decrypt(Base64.decodeBase64(string)));
  45 + }
  46 +
  47 + private static byte[] decrypt(byte[] string) {
  48 + try {
  49 + Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
  50 + Cipher cipher = Cipher.getInstance("RSA/None/PKCS1Padding", "BC");
  51 + RSAPrivateKey pbk = (RSAPrivateKey)keyPair.getPrivate();
  52 + cipher.init(Cipher.DECRYPT_MODE, pbk);
  53 + byte[] plainText = cipher.doFinal(string);
  54 + return plainText;
  55 + }catch (Exception e) {
  56 + throw new RuntimeException(e);
  57 + }
  58 + }
  59 +}
src/main/java/com/bsth/data/BasicData.java
@@ -57,7 +57,7 @@ public class BasicData implements CommandLineRunner{ @@ -57,7 +57,7 @@ public class BasicData implements CommandLineRunner{
57 public static TreeMultimap<String, String> lineCode2SocketUserMap = TreeMultimap.create(); 57 public static TreeMultimap<String, String> lineCode2SocketUserMap = TreeMultimap.create();
58 58
59 //线路ID和code 对照 59 //线路ID和code 对照
60 - public static BiMap<Integer, Integer> lineId2CodeMap; 60 + public static BiMap<Integer, String> lineId2CodeMap;
61 61
62 //线路编码和名称对照 62 //线路编码和名称对照
63 public static Map<String, String> lineCode2NameMap; 63 public static Map<String, String> lineCode2NameMap;
@@ -127,7 +127,7 @@ public class BasicData implements CommandLineRunner{ @@ -127,7 +127,7 @@ public class BasicData implements CommandLineRunner{
127 127
128 128
129 private void loadStationRouteInfo() { 129 private void loadStationRouteInfo() {
130 - Iterator<StationRoute> iterator = stationRouteRepository.findAll().iterator(); 130 + Iterator<StationRoute> iterator = stationRouteRepository.findAllEffective().iterator();
131 Map<String, Integer> map = new HashMap<>(); 131 Map<String, Integer> map = new HashMap<>();
132 StationRoute route; 132 StationRoute route;
133 133
@@ -211,12 +211,12 @@ public class BasicData implements CommandLineRunner{ @@ -211,12 +211,12 @@ public class BasicData implements CommandLineRunner{
211 Iterator<Line> iterator = lineRepository.findAll().iterator(); 211 Iterator<Line> iterator = lineRepository.findAll().iterator();
212 212
213 Line line; 213 Line line;
214 - BiMap<Integer, Integer> biMap = HashBiMap.create(); 214 + BiMap<Integer, String> biMap = HashBiMap.create();
215 Map<String, String> code2name = new HashMap<>(); 215 Map<String, String> code2name = new HashMap<>();
216 216
217 while(iterator.hasNext()){ 217 while(iterator.hasNext()){
218 line = iterator.next(); 218 line = iterator.next();
219 - biMap.put(line.getId(), Integer.parseInt(line.getLineCode())); 219 + biMap.put(line.getId(), line.getLineCode());
220 code2name.put(line.getLineCode(), line.getName()); 220 code2name.put(line.getLineCode(), line.getName());
221 } 221 }
222 222
src/main/java/com/bsth/data/arrival/ArrivalData_GPS.java
@@ -50,7 +50,8 @@ public class ArrivalData_GPS implements CommandLineRunner{ @@ -50,7 +50,8 @@ public class ArrivalData_GPS implements CommandLineRunner{
50 50
51 @Override 51 @Override
52 public void run(String... arg0) throws Exception { 52 public void run(String... arg0) throws Exception {
53 - Application.mainServices.scheduleWithFixedDelay(dataLoaderThread, 30, 15, TimeUnit.SECONDS); 53 + logger.info("ArrivalData_GPS,30,10");
  54 + Application.mainServices.scheduleWithFixedDelay(dataLoaderThread, 30, 10, TimeUnit.SECONDS);
54 } 55 }
55 56
56 @Component 57 @Component
@@ -88,6 +89,7 @@ public class ArrivalData_GPS implements CommandLineRunner{ @@ -88,6 +89,7 @@ public class ArrivalData_GPS implements CommandLineRunner{
88 } 89 }
89 //从专业的角度分析一下数据 90 //从专业的角度分析一下数据
90 analyseData.analyse(carSet); 91 analyseData.analyse(carSet);
  92 +
91 //开始匹配 93 //开始匹配
92 Arrival2Schedule.start(carSet); 94 Arrival2Schedule.start(carSet);
93 }catch(Exception e){ 95 }catch(Exception e){
src/main/java/com/bsth/data/arrival/ArrivalEntity.java
1 package com.bsth.data.arrival; 1 package com.bsth.data.arrival;
2 2
  3 +import java.text.SimpleDateFormat;
3 import java.util.Date; 4 import java.util.Date;
4 5
5 import com.bsth.data.BasicData; 6 import com.bsth.data.BasicData;
6 -import com.bsth.util.DateUtils;  
7 7
8 /** 8 /**
9 * 9 *
@@ -88,7 +88,8 @@ public class ArrivalEntity { @@ -88,7 +88,8 @@ public class ArrivalEntity {
88 @Override 88 @Override
89 public String toString() { 89 public String toString() {
90 try { 90 try {
91 - return "["+BasicData.deviceId2NbbmMap.get(this.deviceId)+", "+DateUtils.sdfHHmm.format(new Date(this.ts)) 91 + SimpleDateFormat sdfHHmm = new SimpleDateFormat("HH:mm");
  92 + return "["+BasicData.deviceId2NbbmMap.get(this.deviceId)+", "+sdfHHmm.format(new Date(this.ts))
92 +","+(this.getUpDown()==0?"上行":"下行")+","+(this.inOut==0?"进":"出")+","+this.stopNo+" ("+this.stopName+")]"; 93 +","+(this.getUpDown()==0?"上行":"下行")+","+(this.inOut==0?"进":"出")+","+this.stopNo+" ("+this.stopName+")]";
93 } catch (Exception e) { 94 } catch (Exception e) {
94 return ""; 95 return "";
src/main/java/com/bsth/data/arrival/DataLoader.java
@@ -141,6 +141,41 @@ public class DataLoader { @@ -141,6 +141,41 @@ public class DataLoader {
141 return list; 141 return list;
142 } 142 }
143 143
  144 + /**
  145 + *
  146 + * @Title: loadByLineAndStartTime
  147 + * @Description: TODO(根据线路,走向和时间戳加载数据)
  148 + */
  149 + public List<ArrivalEntity> loadByLineAndTime(String lineCode, int updown, long st, long et){
  150 + Calendar cal = Calendar.getInstance();
  151 + cal.setTimeInMillis(st);
  152 + int weeks_year = cal.get(Calendar.WEEK_OF_YEAR);
  153 +
  154 + Connection conn = null;
  155 + PreparedStatement ps = null;
  156 + ResultSet rs = null;
  157 +
  158 + List<ArrivalEntity> list = new ArrayList<>();
  159 + String sql = "select * from bsth_c_arrival_info where weeks_year=? and line_id=? and up_down=? and in_out=0 AND create_timestamp > ? AND create_timestamp <=? AND ABS(create_timestamp - ts) < 3600000 order by ts";
  160 + try{
  161 + conn = DBUtils_MS.getConnection();
  162 + ps = conn.prepareStatement(sql);
  163 + ps.setInt(1, weeks_year);
  164 + ps.setString(2, lineCode);
  165 + ps.setInt(3, updown);
  166 + ps.setLong(4, st);
  167 + ps.setLong(5, et);
  168 + rs = ps.executeQuery();
  169 +
  170 + list = resultSet2Set(rs);
  171 + }catch(Exception e){
  172 + logger.error("", e);
  173 + }finally {
  174 + DBUtils_MS.close(rs, ps, conn);
  175 + }
  176 + return list;
  177 + }
  178 +
144 public List<ArrivalEntity> resultSet2Set(ResultSet rs) throws SQLException{ 179 public List<ArrivalEntity> resultSet2Set(ResultSet rs) throws SQLException{
145 List<ArrivalEntity> list = new ArrayList<>(); 180 List<ArrivalEntity> list = new ArrayList<>();
146 181
src/main/java/com/bsth/data/directive/DayOfDirectives.java
@@ -38,6 +38,9 @@ public class DayOfDirectives { @@ -38,6 +38,9 @@ public class DayOfDirectives {
38 38
39 // 线路切换指令 64 39 // 线路切换指令 64
40 public static Map<String, D64> d64Map; 40 public static Map<String, D64> d64Map;
  41 +
  42 + //等待C0_A4回复的用户
  43 + //public static Map<K, V>
41 44
42 @Autowired 45 @Autowired
43 DirectiveService directiveService; 46 DirectiveService directiveService;
src/main/java/com/bsth/data/directive/DirectiveCreator.java
@@ -43,7 +43,7 @@ public class DirectiveCreator { @@ -43,7 +43,7 @@ public class DirectiveCreator {
43 * @return Directive60 返回类型 43 * @return Directive60 返回类型
44 * @throws 44 * @throws
45 */ 45 */
46 - public static D60 createD60(String nbbm, String text, Short dispatchInstruct, int upDown, int state) { 46 + public D60 createD60(String nbbm, String text, Short dispatchInstruct, int upDown, int state) {
47 Long timestamp = System.currentTimeMillis(); 47 Long timestamp = System.currentTimeMillis();
48 48
49 Short company = Short.parseShort(BasicData.nbbm2CompanyCodeMap.get(nbbm)); 49 Short company = Short.parseShort(BasicData.nbbm2CompanyCodeMap.get(nbbm));
@@ -81,7 +81,7 @@ public class DirectiveCreator { @@ -81,7 +81,7 @@ public class DirectiveCreator {
81 } 81 }
82 82
83 83
84 - public static D60 createD60_02(String nbbm, String text, int upDown, int state, Date alarmTime){ 84 + public D60 createD60_02(String nbbm, String text, int upDown, int state, Date alarmTime){
85 SimpleDateFormat sdfMMddHHmm = new SimpleDateFormat("MMddHHmm"); 85 SimpleDateFormat sdfMMddHHmm = new SimpleDateFormat("MMddHHmm");
86 86
87 Long timestamp = System.currentTimeMillis(); 87 Long timestamp = System.currentTimeMillis();
@@ -129,19 +129,16 @@ public class DirectiveCreator { @@ -129,19 +129,16 @@ public class DirectiveCreator {
129 * @param @param t 时间戳 129 * @param @param t 时间戳
130 * @throws 130 * @throws
131 */ 131 */
132 - public static D64 createD64(String nbbm, Integer lineCode, long t){ 132 + public D64 createD64(String nbbm, String lineCode, long t){
133 String deviceId = BasicData.deviceId2NbbmMap.inverse().get(nbbm); 133 String deviceId = BasicData.deviceId2NbbmMap.inverse().get(nbbm);
134 134
135 D64 change = new D64(); 135 D64 change = new D64();
136 D64Data data = new D64Data(); 136 D64Data data = new D64Data();
137 data.setCityCode(cityCode); 137 data.setCityCode(cityCode);
138 data.setDeviceId(deviceId); 138 data.setDeviceId(deviceId);
  139 +
139 //线路编码补满6位数 140 //线路编码补满6位数
140 - if(lineCode > 999999){  
141 - logger.error("线路编码不能超过6位,code:" + lineCode);  
142 - return null;  
143 - }  
144 - String lineCodeStr = String.format("%06d", lineCode); 141 + String lineCodeStr = padLeft(lineCode, 6, '0');
145 data.setLineId(lineCodeStr); 142 data.setLineId(lineCodeStr);
146 143
147 change.setDeviceId(deviceId); 144 change.setDeviceId(deviceId);
@@ -160,7 +157,7 @@ public class DirectiveCreator { @@ -160,7 +157,7 @@ public class DirectiveCreator {
160 * @param @param lineId 线路ID 157 * @param @param lineId 线路ID
161 * @throws 158 * @throws
162 */ 159 */
163 - public static String createDeviceRefreshData(String deviceId, Integer lineCode) { 160 + public String createDeviceRefreshData(String deviceId, String lineCode) {
164 Long t = System.currentTimeMillis(); 161 Long t = System.currentTimeMillis();
165 Map<String, Object> param = new HashMap<>(); 162 Map<String, Object> param = new HashMap<>();
166 param.put("deviceId", deviceId); 163 param.put("deviceId", deviceId);
@@ -175,11 +172,7 @@ public class DirectiveCreator { @@ -175,11 +172,7 @@ public class DirectiveCreator {
175 data.put("centerId", 1); 172 data.put("centerId", 1);
176 173
177 //线路编码补满6位数 174 //线路编码补满6位数
178 - if(lineCode > 999999){  
179 - logger.error("线路编码不能超过6位,code:" + lineCode);  
180 - return null;  
181 - }  
182 - String lineCodeStr = String.format("%06d", lineCode); 175 + String lineCodeStr = padLeft(lineCode, 6, '0');
183 176
184 data.put("lineId", lineCodeStr); 177 data.put("lineId", lineCodeStr);
185 data.put("lineVersion", 0); 178 data.put("lineVersion", 0);
@@ -189,7 +182,15 @@ public class DirectiveCreator { @@ -189,7 +182,15 @@ public class DirectiveCreator {
189 return JSON.toJSONString(param); 182 return JSON.toJSONString(param);
190 } 183 }
191 184
192 - public static void main(String[] args) {  
193 - System.out.println(String.format("%06d", "1025"));  
194 - } 185 + public String padLeft(String oriStr,int len,char alexin){
  186 + String str = "";
  187 + int strlen = oriStr.length();
  188 + if(strlen < len){
  189 + for(int i=0;i<len-strlen;i++){
  190 + str = str+alexin;
  191 + }
  192 + }
  193 + str = str + oriStr;
  194 + return str;
  195 + }
195 } 196 }
src/main/java/com/bsth/data/forecast/ForecastRealServer.java 0 → 100644
  1 +package com.bsth.data.forecast;
  2 +
  3 +import java.text.DecimalFormat;
  4 +import java.util.ArrayList;
  5 +import java.util.HashMap;
  6 +import java.util.List;
  7 +import java.util.Map;
  8 +import java.util.concurrent.TimeUnit;
  9 +
  10 +import org.slf4j.Logger;
  11 +import org.slf4j.LoggerFactory;
  12 +import org.springframework.beans.factory.annotation.Autowired;
  13 +import org.springframework.boot.CommandLineRunner;
  14 +import org.springframework.stereotype.Component;
  15 +
  16 +import com.bsth.Application;
  17 +import com.bsth.data.forecast.entity.ForecastResult;
  18 +import com.bsth.data.forecast.entity.ForecastResult.ForecastResultItem;
  19 +import com.bsth.data.forecast.entity.SimpleRoute;
  20 +import com.bsth.data.forecast.entity.SimpleRoute.TimeRange;
  21 +import com.bsth.data.gpsdata.GpsEntity;
  22 +import com.bsth.data.gpsdata.GpsRealData;
  23 +import com.bsth.data.schedule.DayOfSchedule;
  24 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  25 +import com.google.common.collect.ArrayListMultimap;
  26 +
  27 +/**
  28 + *
  29 + * @ClassName: SampleTimeData
  30 + * @Description: TODO(实时到离站预测)
  31 + * @author PanZhao
  32 + * @date 2016年9月18日 上午10:15:17
  33 + *
  34 + */
  35 +@Component
  36 +public class ForecastRealServer implements CommandLineRunner {
  37 +
  38 + @Autowired
  39 + SampleTimeDataLoader dataLoader;
  40 +
  41 + @Autowired
  42 + DayOfSchedule dayOfSchedule;
  43 +
  44 + @Autowired
  45 + GpsRealData gpsRealData;
  46 +
  47 + Logger logger = LoggerFactory.getLogger(this.getClass());
  48 +
  49 + //车辆 ——> 预测终点时间
  50 + //static Map<String, Float> forecastMap = new HashMap<>();
  51 + //线路_上下行 ——> 封装耗时数据的路由链
  52 + public static ArrayListMultimap<String, SimpleRoute> lineSampleMap;
  53 + //车辆 ——> 预测结果
  54 + public static Map<String, ForecastResult> forecastMap;
  55 +
  56 + static{
  57 + lineSampleMap = ArrayListMultimap.create();
  58 + forecastMap = new HashMap<>();
  59 + }
  60 +
  61 + @Override
  62 + public void run(String... arg0) throws Exception {
  63 + //2小时更新一次站点间耗时数据
  64 + Application.mainServices.scheduleWithFixedDelay(dataLoader, 12, 120 * 60, TimeUnit.SECONDS);
  65 + }
  66 +
  67 + /**
  68 + *
  69 + * @Title: forecast
  70 + * @Description: TODO(预测后续时间)
  71 + * @param @param nbbm 车辆自编号
  72 + */
  73 +/* public void forecast(String nbbm){
  74 + logger.info("预测," + nbbm);
  75 + //当前执行班次
  76 + ScheduleRealInfo sch = dayOfSchedule.execPlamMap().get(nbbm);
  77 + if(null == sch)
  78 + return;
  79 +
  80 + //车辆当前位置
  81 + //GpsEntity gps = gpsRealData.findByDeviceId(BasicData.deviceId2NbbmMap.inverse().get(sch.getClZbh()));
  82 + GpsEntity gps = gpsRealData.findByDeviceId(BasicData.deviceId2NbbmMap.inverse().get(nbbm));
  83 + forecast(nbbm, gps);
  84 + }*/
  85 +
  86 + public void forecast(String nbbm, GpsEntity gps){
  87 + try{
  88 + long t = System.currentTimeMillis();
  89 + //终点站
  90 + String eStation = null;
  91 + //当前执行班次
  92 + ScheduleRealInfo sch = dayOfSchedule.execPlamMap().get(nbbm);
  93 + if(null != sch)
  94 + eStation = sch.getZdzCode();
  95 +
  96 + //预测结果
  97 + ForecastResult forecastRes = new ForecastResult();
  98 + forecastRes.setStation(gps.getStopNo());
  99 + forecastRes.setArrTime(gps.getArrTime());
  100 + forecastRes.setFollows(
  101 + calc(gps.getLineId()
  102 + ,gps.getUpDown()
  103 + , gps.getStopNo(), eStation
  104 + , t - gps.getArrTime()));
  105 +
  106 + forecastMap.put(nbbm, forecastRes);
  107 + //GPS附加预计终点时间
  108 + gps.setExpectStopTime(expectStopTime(nbbm));
  109 + }catch(Exception e){
  110 + logger.error("", e);
  111 + }
  112 + }
  113 +
  114 + /**
  115 + *
  116 + * @Title: expectStopTime
  117 + * @Description: TODO(预计到达终点时间)
  118 + */
  119 + public Float expectStopTime(String nbbm){
  120 + long t = System.currentTimeMillis()
  121 + ,diff = 0L
  122 + ,firstExpTime;
  123 +
  124 + Float rs = null;
  125 + ForecastResult forecastRes = forecastMap.get(nbbm);
  126 + if(null == forecastRes)
  127 + return rs;
  128 +
  129 + List<ForecastResultItem> trs = forecastRes.getFollows();
  130 + if(null != trs && trs.size() > 0){
  131 +
  132 + //当前时间已超过第一个预计到站时间,后续预测时间补上差值
  133 + firstExpTime = trs.get(0).getTime();
  134 + if(firstExpTime < t)
  135 + diff = t - firstExpTime;
  136 +
  137 + rs = ((float)((trs.get(trs.size() - 1).getTime()) - t + diff)) / 1000 / 60;
  138 + }
  139 +
  140 + //保留2位小数
  141 + if(null != rs)
  142 + rs = Float.parseFloat(new DecimalFormat(".00").format(rs));
  143 +
  144 + return rs;
  145 + }
  146 +
  147 + /**
  148 + *
  149 + * @Title: expectDetail
  150 + * @Description: TODO(预测明细)
  151 + */
  152 + public List<TimeRange> expectDetail(String nbbm){
  153 +
  154 + return null;
  155 + }
  156 +
  157 +
  158 + public List<ForecastResultItem> calc(String lineCode, int updown , String sStation, String eStation, long diff){
  159 + long t = System.currentTimeMillis()
  160 + , ct = t - diff;
  161 +
  162 + List<SimpleRoute> srs = lineSampleMap.get(lineCode + "_" + updown);
  163 + SimpleRoute curr;
  164 + int len = srs.size();
  165 +
  166 + List<ForecastResultItem> rs = null;
  167 + ForecastResultItem frItem;
  168 +
  169 + for(int i = 0; i < len; i ++){
  170 + curr = srs.get(i);
  171 +
  172 + if(curr.stationCode.equals(sStation)){
  173 + rs = new ArrayList<>();
  174 + continue;
  175 + }
  176 +
  177 + if(null == rs)
  178 + continue;
  179 +
  180 + frItem = new ForecastResultItem();
  181 + frItem.setStationId(curr.stationCode);
  182 + frItem.setStationName(curr.stationName);
  183 + if(null == curr.ranges || curr.ranges.size() == 0)
  184 + break;
  185 +
  186 + //从多个时区耗时中选择一个
  187 + for(TimeRange tr : curr.ranges){
  188 + if(tr.startTime < t){
  189 + ct += ((long)(tr.runTime * 60 * 1000));
  190 + frItem.setTime(ct);
  191 + break;
  192 + }
  193 + }
  194 +
  195 + if(null != eStation && eStation.equals(curr.stationCode))
  196 + break;
  197 +
  198 + rs.add(frItem);
  199 + }
  200 +
  201 + return rs;
  202 + }
  203 +}
src/main/java/com/bsth/data/forecast/SampleTimeDataLoader.java 0 → 100644
  1 +package com.bsth.data.forecast;
  2 +
  3 +import java.text.SimpleDateFormat;
  4 +import java.util.ArrayList;
  5 +import java.util.Collections;
  6 +import java.util.Comparator;
  7 +import java.util.Date;
  8 +import java.util.Iterator;
  9 +import java.util.List;
  10 +import java.util.Set;
  11 +
  12 +import org.slf4j.Logger;
  13 +import org.slf4j.LoggerFactory;
  14 +import org.springframework.beans.factory.annotation.Autowired;
  15 +import org.springframework.stereotype.Component;
  16 +
  17 +import com.bsth.data.forecast.entity.SimpleRoute;
  18 +import com.bsth.data.forecast.entity.SimpleRoute.TimeRange;
  19 +import com.bsth.entity.StationRoute;
  20 +import com.bsth.entity.forecast.Sample;
  21 +import com.bsth.repository.StationRouteRepository;
  22 +import com.bsth.repository.forecast.SampleRepository;
  23 +import com.google.common.collect.ArrayListMultimap;
  24 +
  25 +/**
  26 + *
  27 + * @Title: loadData
  28 + * @Description: TODO(从数据库加载数据)
  29 + */
  30 +@Component
  31 +public class SampleTimeDataLoader extends Thread {
  32 +
  33 + @Autowired
  34 + SampleRepository sampleRepository;
  35 +
  36 + @Autowired
  37 + StationRouteRepository stationRouteRepository;
  38 +
  39 + // 当天日期
  40 + String rq;
  41 +
  42 + SimpleDateFormat sdfyyyyMMddHHmm = new SimpleDateFormat("yyyy-MM-ddHH:mm");
  43 +
  44 + Logger logger = LoggerFactory.getLogger(this.getClass());
  45 +
  46 + @Override
  47 + public void run() {
  48 + SimpleDateFormat sdfyyyyMMdd = new SimpleDateFormat("yyyy-MM-dd");
  49 + rq = sdfyyyyMMdd.format(new Date());
  50 +
  51 + Iterator<Sample> iterator = sampleRepository.findAll().iterator();
  52 + ArrayListMultimap<String, Sample> sampleMap = ArrayListMultimap.create();
  53 +
  54 + Sample sample;
  55 + String key;
  56 + while (iterator.hasNext()) {
  57 + sample = iterator.next();
  58 + key = sample.getLineCode() + "_" + sample.getUpdown() + "_" + sample.getsStation() + "_"
  59 + + sample.geteStation();
  60 + sampleMap.put(key, sample);
  61 + }
  62 +
  63 + // 加载全部路由信息
  64 + List<StationRoute> allRoutes = stationRouteRepository.findAllEffective();
  65 + // 线路和走向分组
  66 + ArrayListMultimap<String, StationRoute> groupMap = ArrayListMultimap.create();
  67 + for (StationRoute sr : allRoutes)
  68 + groupMap.put(sr.getLineCode() + "_" + sr.getDirections(), sr);
  69 +
  70 + ArrayListMultimap<String, SimpleRoute> lineSampleMapCopy = ArrayListMultimap.create();
  71 + // 排序路由链并附加各个时区耗时信息
  72 + StationRouteComp comp = new StationRouteComp();
  73 + Set<String> kys = groupMap.keySet();
  74 + List<StationRoute> routeList;
  75 + StationRoute sRoute;
  76 +
  77 + List<Sample> sapList;
  78 + for (String k : kys) {
  79 + routeList = groupMap.get(k);
  80 + // 排序
  81 + Collections.sort(routeList, comp);
  82 +
  83 + for (int i = 1; i < routeList.size(); i++) {
  84 + sRoute = routeList.get(i);
  85 +
  86 + sapList = sampleMap.get(k + "_" +routeList.get(i - 1).getStationCode() + "_" + sRoute.getStationCode());
  87 +
  88 + lineSampleMapCopy.put(k, createSimpleRoute(sRoute, sapList));
  89 + }
  90 + }
  91 +
  92 + ForecastRealServer.lineSampleMap = lineSampleMapCopy;
  93 + logger.info("SampleTimeDataLoader.... over...");
  94 + }
  95 +
  96 + private SimpleRoute createSimpleRoute(StationRoute sRoute, List<Sample> list) {
  97 + SimpleRoute simple = new SimpleRoute();
  98 +
  99 + simple.stationCode = sRoute.getStationCode();
  100 + simple.ranges = new ArrayList<>();
  101 +
  102 + try{
  103 + TimeRange tg;
  104 + for (Sample s : list) {
  105 + tg = new TimeRange();
  106 + tg.startTime = sdfyyyyMMddHHmm.parse(rq + s.getsDate()).getTime();
  107 + tg.endTime = sdfyyyyMMddHHmm.parse(rq + s.geteDate()).getTime();
  108 + tg.runTime = s.getRunTime();
  109 + simple.ranges.add(tg);
  110 + }
  111 +
  112 + //排序
  113 + Collections.sort(simple.ranges);
  114 + }catch(Exception e){
  115 + logger.error("", e);
  116 + }
  117 + return simple;
  118 + }
  119 +
  120 + public static class StationRouteComp implements Comparator<StationRoute> {
  121 +
  122 + @Override
  123 + public int compare(StationRoute o1, StationRoute o2) {
  124 + return o1.getStationRouteCode() - o2.getStationRouteCode();
  125 + }
  126 + }
  127 +}
src/main/java/com/bsth/data/forecast/entity/ForecastResult.java 0 → 100644
  1 +package com.bsth.data.forecast.entity;
  2 +
  3 +import java.util.List;
  4 +
  5 +/**
  6 + *
  7 + * @ClassName: ForecastResult
  8 + * @Description: TODO(预测结果)
  9 + * @author PanZhao
  10 + * @date 2016年9月19日 上午11:09:28
  11 + *
  12 + */
  13 +public class ForecastResult {
  14 +
  15 + /** 当前站 */
  16 + private String station;
  17 +
  18 + /** 到站时间 */
  19 + private long arrTime;
  20 +
  21 + /** 后续站点预测明细 */
  22 + private List<ForecastResultItem> follows;
  23 +
  24 + /** 预计到达终点时间(分钟) */
  25 + private Float stopTime;
  26 +
  27 + public static class ForecastResultItem {
  28 +
  29 + /** 站点ID */
  30 + private String stationId;
  31 +
  32 + /** 站点名称 */
  33 + private String stationName;
  34 +
  35 + /** 时间戳 */
  36 + private long time;
  37 +
  38 + public String getStationId() {
  39 + return stationId;
  40 + }
  41 +
  42 + public void setStationId(String stationId) {
  43 + this.stationId = stationId;
  44 + }
  45 +
  46 + public String getStationName() {
  47 + return stationName;
  48 + }
  49 +
  50 + public void setStationName(String stationName) {
  51 + this.stationName = stationName;
  52 + }
  53 +
  54 + public long getTime() {
  55 + return time;
  56 + }
  57 +
  58 + public void setTime(long time) {
  59 + this.time = time;
  60 + }
  61 + }
  62 +
  63 + public String getStation() {
  64 + return station;
  65 + }
  66 +
  67 + public void setStation(String station) {
  68 + this.station = station;
  69 + }
  70 +
  71 + public long getArrTime() {
  72 + return arrTime;
  73 + }
  74 +
  75 + public void setArrTime(long arrTime) {
  76 + this.arrTime = arrTime;
  77 + }
  78 +
  79 + public Float getStopTime() {
  80 + return stopTime;
  81 + }
  82 +
  83 + public void setStopTime(Float stopTime) {
  84 + this.stopTime = stopTime;
  85 + }
  86 +
  87 + public List<ForecastResultItem> getFollows() {
  88 + return follows;
  89 + }
  90 +
  91 + public void setFollows(List<ForecastResultItem> follows) {
  92 + this.follows = follows;
  93 + }
  94 +}
src/main/java/com/bsth/data/forecast/entity/SimpleRoute.java 0 → 100644
  1 +package com.bsth.data.forecast.entity;
  2 +
  3 +import java.util.List;
  4 +
  5 +/**
  6 + *
  7 + * @ClassName: SimpleStationRoute
  8 + * @Description: TODO(简单的路由耗时封装)
  9 + * @author PanZhao
  10 + * @date 2016年9月18日 上午10:51:56
  11 + *
  12 + */
  13 +public class SimpleRoute {
  14 +
  15 + /** 站点编码 */
  16 + public String stationCode;
  17 +
  18 + /** 站点名称 */
  19 + public String stationName;
  20 +
  21 + public List<TimeRange> ranges;
  22 +
  23 + public static class TimeRange implements Comparable<TimeRange>{
  24 +
  25 + /** 开始时间 */
  26 + public long startTime;
  27 +
  28 + /** 截止时间 */
  29 + public long endTime;
  30 +
  31 + /** 运行时间 */
  32 + public float runTime;
  33 +
  34 + @Override
  35 + public int compareTo(TimeRange o) {
  36 + return (int) (o.startTime - this.startTime);
  37 + }
  38 + }
  39 +}
src/main/java/com/bsth/data/gpsdata/GpsEntity.java
@@ -14,7 +14,7 @@ public class GpsEntity { @@ -14,7 +14,7 @@ public class GpsEntity {
14 private Integer companyCode; 14 private Integer companyCode;
15 15
16 /** 线路编码 */ 16 /** 线路编码 */
17 - private Integer lineId; 17 + private String lineId;
18 18
19 /** 设备编码 */ 19 /** 设备编码 */
20 private String deviceId; 20 private String deviceId;
@@ -24,6 +24,12 @@ public class GpsEntity { @@ -24,6 +24,12 @@ public class GpsEntity {
24 24
25 /** 站点编码 */ 25 /** 站点编码 */
26 private String stopNo; 26 private String stopNo;
  27 +
  28 + /** 站点名称 */
  29 + private String stationName;
  30 +
  31 + /** 到站时间 */
  32 + private long arrTime;
27 33
28 /** 经度 */ 34 /** 经度 */
29 private Float lon; 35 private Float lon;
@@ -49,17 +55,17 @@ public class GpsEntity { @@ -49,17 +55,17 @@ public class GpsEntity {
49 /** 车辆内部编码 */ 55 /** 车辆内部编码 */
50 private String nbbm; 56 private String nbbm;
51 57
52 - /** 站点名称 */  
53 - private String stationName;  
54 -  
55 - /** 当前班次ID */  
56 - private Long currSchId;  
57 -  
58 - /** 下一个班次ID */  
59 - private Long nextSchId; 58 + /** 预计到达终点时间 */
  59 + private Float expectStopTime;
60 60
61 /** 设备是否在线 */ 61 /** 设备是否在线 */
62 private boolean online; 62 private boolean online;
  63 +
  64 + /** 当前执行班次ID */
  65 + private Long schId;
  66 +
  67 + /** 是否异常数据 */
  68 + private boolean abnormal;
63 69
64 public Integer getCompanyCode() { 70 public Integer getCompanyCode() {
65 return companyCode; 71 return companyCode;
@@ -69,14 +75,6 @@ public class GpsEntity { @@ -69,14 +75,6 @@ public class GpsEntity {
69 this.companyCode = companyCode; 75 this.companyCode = companyCode;
70 } 76 }
71 77
72 - public Integer getLineId() {  
73 - return lineId;  
74 - }  
75 -  
76 - public void setLineId(Integer lineId) {  
77 - this.lineId = lineId;  
78 - }  
79 -  
80 public String getDeviceId() { 78 public String getDeviceId() {
81 return deviceId; 79 return deviceId;
82 } 80 }
@@ -156,22 +154,6 @@ public class GpsEntity { @@ -156,22 +154,6 @@ public class GpsEntity {
156 public void setUpDown(Integer upDown) { 154 public void setUpDown(Integer upDown) {
157 this.upDown = upDown; 155 this.upDown = upDown;
158 } 156 }
159 -  
160 - public Long getCurrSchId() {  
161 - return currSchId;  
162 - }  
163 -  
164 - public void setCurrSchId(Long currSchId) {  
165 - this.currSchId = currSchId;  
166 - }  
167 -  
168 - public Long getNextSchId() {  
169 - return nextSchId;  
170 - }  
171 -  
172 - public void setNextSchId(Long nextSchId) {  
173 - this.nextSchId = nextSchId;  
174 - }  
175 157
176 public String getNbbm() { 158 public String getNbbm() {
177 return nbbm; 159 return nbbm;
@@ -196,4 +178,44 @@ public class GpsEntity { @@ -196,4 +178,44 @@ public class GpsEntity {
196 public void setOnline(boolean online) { 178 public void setOnline(boolean online) {
197 this.online = online; 179 this.online = online;
198 } 180 }
  181 +
  182 + public long getArrTime() {
  183 + return arrTime;
  184 + }
  185 +
  186 + public void setArrTime(long arrTime) {
  187 + this.arrTime = arrTime;
  188 + }
  189 +
  190 + public Float getExpectStopTime() {
  191 + return expectStopTime;
  192 + }
  193 +
  194 + public void setExpectStopTime(Float expectStopTime) {
  195 + this.expectStopTime = expectStopTime;
  196 + }
  197 +
  198 + public String getLineId() {
  199 + return lineId;
  200 + }
  201 +
  202 + public void setLineId(String lineId) {
  203 + this.lineId = lineId;
  204 + }
  205 +
  206 + public Long getSchId() {
  207 + return schId;
  208 + }
  209 +
  210 + public void setSchId(Long schId) {
  211 + this.schId = schId;
  212 + }
  213 +
  214 + public boolean isAbnormal() {
  215 + return abnormal;
  216 + }
  217 +
  218 + public void setAbnormal(boolean abnormal) {
  219 + this.abnormal = abnormal;
  220 + }
199 } 221 }
src/main/java/com/bsth/data/gpsdata/GpsRealData.java
@@ -3,12 +3,14 @@ package com.bsth.data.gpsdata; @@ -3,12 +3,14 @@ package com.bsth.data.gpsdata;
3 import java.io.BufferedReader; 3 import java.io.BufferedReader;
4 import java.io.InputStreamReader; 4 import java.io.InputStreamReader;
5 import java.util.ArrayList; 5 import java.util.ArrayList;
  6 +import java.util.Collection;
6 import java.util.HashMap; 7 import java.util.HashMap;
7 import java.util.List; 8 import java.util.List;
8 import java.util.Map; 9 import java.util.Map;
9 import java.util.NavigableSet; 10 import java.util.NavigableSet;
10 import java.util.concurrent.TimeUnit; 11 import java.util.concurrent.TimeUnit;
11 12
  13 +import org.apache.commons.lang3.StringUtils;
12 import org.apache.http.HttpEntity; 14 import org.apache.http.HttpEntity;
13 import org.apache.http.client.methods.CloseableHttpResponse; 15 import org.apache.http.client.methods.CloseableHttpResponse;
14 import org.apache.http.client.methods.HttpGet; 16 import org.apache.http.client.methods.HttpGet;
@@ -24,6 +26,9 @@ import com.alibaba.fastjson.JSON; @@ -24,6 +26,9 @@ import com.alibaba.fastjson.JSON;
24 import com.alibaba.fastjson.JSONObject; 26 import com.alibaba.fastjson.JSONObject;
25 import com.bsth.Application; 27 import com.bsth.Application;
26 import com.bsth.data.BasicData; 28 import com.bsth.data.BasicData;
  29 +import com.bsth.data.forecast.ForecastRealServer;
  30 +import com.bsth.data.schedule.DayOfSchedule;
  31 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
27 import com.bsth.util.ConfigUtil; 32 import com.bsth.util.ConfigUtil;
28 import com.google.common.collect.TreeMultimap; 33 import com.google.common.collect.TreeMultimap;
29 34
@@ -43,7 +48,7 @@ public class GpsRealData implements CommandLineRunner{ @@ -43,7 +48,7 @@ public class GpsRealData implements CommandLineRunner{
43 private static Map<String, GpsEntity> gpsMap; 48 private static Map<String, GpsEntity> gpsMap;
44 49
45 //按线路分组设备号 50 //按线路分组设备号
46 - private static TreeMultimap<Integer, String> lineCode2Devices; 51 + private static TreeMultimap<String, String> lineCode2Devices;
47 52
48 // 网关数据接口地址 53 // 网关数据接口地址
49 private static String url; 54 private static String url;
@@ -51,6 +56,11 @@ public class GpsRealData implements CommandLineRunner{ @@ -51,6 +56,11 @@ public class GpsRealData implements CommandLineRunner{
51 @Autowired 56 @Autowired
52 GpsDataLoader gpsDataLoader; 57 GpsDataLoader gpsDataLoader;
53 58
  59 + @Autowired
  60 + DayOfSchedule dayOfSchedule;
  61 +
  62 + @Autowired
  63 + ForecastRealServer forecastRealServer;
54 /** 64 /**
55 * 构造函数 65 * 构造函数
56 */ 66 */
@@ -62,12 +72,25 @@ public class GpsRealData implements CommandLineRunner{ @@ -62,12 +72,25 @@ public class GpsRealData implements CommandLineRunner{
62 72
63 @Override 73 @Override
64 public void run(String... arg0) throws Exception { 74 public void run(String... arg0) throws Exception {
65 - logger.info("gpsDataLoader,20,8");  
66 - Application.mainServices.scheduleWithFixedDelay(gpsDataLoader, 20, 8, TimeUnit.SECONDS); 75 + Application.mainServices.scheduleWithFixedDelay(gpsDataLoader, 20, 7, TimeUnit.SECONDS);
67 } 76 }
68 77
69 - public static GpsEntity add(GpsEntity gps) { 78 + public GpsEntity add(GpsEntity gps) {
70 String device = gps.getDeviceId(); 79 String device = gps.getDeviceId();
  80 + GpsEntity old = gpsMap.get(device);
  81 +
  82 + //定时定距数据附带站点编码改变
  83 + if(null == old || !old.getStopNo().equals(gps.getStopNo())){
  84 + gps.setArrTime(gps.getTimestamp());
  85 + //预测到达终点时间
  86 + forecastRealServer.forecast(gps.getNbbm(), gps);
  87 + }
  88 + else{
  89 + gps.setArrTime(old.getArrTime());
  90 + //不预测, 重新计算终点时间
  91 + gps.setExpectStopTime(forecastRealServer.expectStopTime(gps.getNbbm()));
  92 + }
  93 +
71 gpsMap.put(device, gps); 94 gpsMap.put(device, gps);
72 lineCode2Devices.put(gps.getLineId(), device); 95 lineCode2Devices.put(gps.getLineId(), device);
73 return gps; 96 return gps;
@@ -85,12 +108,22 @@ public class GpsRealData implements CommandLineRunner{ @@ -85,12 +108,22 @@ public class GpsRealData implements CommandLineRunner{
85 * 108 *
86 * @Title: get @Description: TODO(线路编码获取GPS集合) @throws 109 * @Title: get @Description: TODO(线路编码获取GPS集合) @throws
87 */ 110 */
88 - public List<GpsEntity> get(Integer lineCode) { 111 + public List<GpsEntity> getByLine(String lineCode) {
89 NavigableSet<String> set = lineCode2Devices.get(lineCode); 112 NavigableSet<String> set = lineCode2Devices.get(lineCode);
90 113
91 List<GpsEntity> rs = new ArrayList<>(); 114 List<GpsEntity> rs = new ArrayList<>();
  115 + GpsEntity gps;
  116 + ScheduleRealInfo sch;
92 for(String device : set){ 117 for(String device : set){
93 - rs.add(gpsMap.get(device)); 118 + gps = gpsMap.get(device);
  119 + //过滤异常GPS数据
  120 + if(gps.isAbnormal())
  121 + continue;
  122 +
  123 + sch = dayOfSchedule.execPlamMap().get(gps.getNbbm());
  124 + if(null != sch)
  125 + gps.setSchId(sch.getId());
  126 + rs.add(gps);
94 } 127 }
95 128
96 return rs; 129 return rs;
@@ -100,7 +133,7 @@ public class GpsRealData implements CommandLineRunner{ @@ -100,7 +133,7 @@ public class GpsRealData implements CommandLineRunner{
100 List<GpsEntity> list = new ArrayList<>(); 133 List<GpsEntity> list = new ArrayList<>();
101 134
102 for(String code : pArray) 135 for(String code : pArray)
103 - list.addAll(get(Integer.parseInt(code))); 136 + list.addAll(getByLine(code));
104 return list; 137 return list;
105 } 138 }
106 139
@@ -108,10 +141,17 @@ public class GpsRealData implements CommandLineRunner{ @@ -108,10 +141,17 @@ public class GpsRealData implements CommandLineRunner{
108 return gpsMap.get(deviceId); 141 return gpsMap.get(deviceId);
109 } 142 }
110 143
  144 + public Collection<GpsEntity> all(){
  145 + return gpsMap.values();
  146 + }
  147 +
111 @Component 148 @Component
112 public static class GpsDataLoader extends Thread{ 149 public static class GpsDataLoader extends Thread{
113 150
114 Logger logger = LoggerFactory.getLogger(GpsDataLoader.class); 151 Logger logger = LoggerFactory.getLogger(GpsDataLoader.class);
  152 +
  153 + @Autowired
  154 + GpsRealData gpsRealData;
115 155
116 @Override 156 @Override
117 public void run() { 157 public void run() {
@@ -129,7 +169,7 @@ public class GpsRealData implements CommandLineRunner{ @@ -129,7 +169,7 @@ public class GpsRealData implements CommandLineRunner{
129 try { 169 try {
130 httpClient = HttpClients.createDefault(); 170 httpClient = HttpClients.createDefault();
131 HttpGet get = new HttpGet(url); 171 HttpGet get = new HttpGet(url);
132 - 172 +
133 response = httpClient.execute(get); 173 response = httpClient.execute(get);
134 174
135 HttpEntity entity = response.getEntity(); 175 HttpEntity entity = response.getEntity();
@@ -146,11 +186,17 @@ public class GpsRealData implements CommandLineRunner{ @@ -146,11 +186,17 @@ public class GpsRealData implements CommandLineRunner{
146 if (jsonObj != null) 186 if (jsonObj != null)
147 list = JSON.parseArray(jsonObj.getString("data"), GpsEntity.class); 187 list = JSON.parseArray(jsonObj.getString("data"), GpsEntity.class);
148 188
  189 + String nbbm;
149 //附加车辆内部编码 190 //附加车辆内部编码
150 for(GpsEntity gps : list){ 191 for(GpsEntity gps : list){
151 - gps.setNbbm(BasicData.deviceId2NbbmMap.get(gps.getDeviceId())); 192 + nbbm = BasicData.deviceId2NbbmMap.get(gps.getDeviceId());
  193 + if(StringUtils.isBlank(nbbm))
  194 + gps.setAbnormal(true);//标记为异常数据
  195 + else
  196 + gps.setNbbm(nbbm);
  197 +
152 gps.setStationName(BasicData.stationCode2NameMap.get(gps.getStopNo())); 198 gps.setStationName(BasicData.stationCode2NameMap.get(gps.getStopNo()));
153 - add(gps); 199 + gpsRealData.add(gps);
154 } 200 }
155 } else 201 } else
156 logger.error("result is null"); 202 logger.error("result is null");
src/main/java/com/bsth/data/match/Arrival2Schedule.java
@@ -158,11 +158,7 @@ public class Arrival2Schedule implements ApplicationContextAware { @@ -158,11 +158,7 @@ public class Arrival2Schedule implements ApplicationContextAware {
158 158
159 //漂移判定 159 //漂移判定
160 if(driftCheck(mr, arr)){ 160 if(driftCheck(mr, arr)){
161 - mr.sch.setFcsjActualAll(mr.ts);  
162 - //通知客户端  
163 - sendUtils.sendFcsj(mr.sch);  
164 - //持久化  
165 - dayOfSchedule.save(mr.sch); 161 + carOut(mr);
166 } 162 }
167 } 163 }
168 } 164 }
@@ -203,26 +199,58 @@ public class Arrival2Schedule implements ApplicationContextAware { @@ -203,26 +199,58 @@ public class Arrival2Schedule implements ApplicationContextAware {
203 //排序后的第一个 就是最合适的匹配 199 //排序后的第一个 就是最合适的匹配
204 Collections.sort(mrs, mrComparator); 200 Collections.sort(mrs, mrComparator);
205 mr = mrs.get(0); 201 mr = mrs.get(0);
206 - mr.sch.setZdsjActualAll(mr.ts); 202 + carInStop(mr);
  203 + }
  204 + }
  205 +
  206 + /**
  207 + *
  208 + * @Title: carOut
  209 + * @Description: TODO(车辆发出)
  210 + */
  211 + public void carOut(MatchResult mr){
  212 + //设置发车时间
  213 + mr.sch.setFcsjActualAll(mr.ts);
  214 + //通知客户端
  215 + sendUtils.sendFcsj(mr.sch);
  216 + //持久化
  217 + dayOfSchedule.save(mr.sch);
  218 + //车辆当前执行班次
  219 + dayOfSchedule.addExecPlan(mr.sch);
  220 + }
  221 +
  222 + /**
  223 + *
  224 + * @Title: carInStop
  225 + * @Description: TODO(车辆进入终点站)
  226 + */
  227 + public void carInStop(MatchResult mr){
  228 + mr.sch.setZdsjActualAll(mr.ts);
  229 +
  230 + int doneSum = dayOfSchedule.doneSum(mr.sch.getClZbh());
  231 + ScheduleRealInfo next = dayOfSchedule.next(mr.sch);
  232 + if(null != next){
  233 + next.setQdzArrDateSJ(mr.sch.getZdsjActual());
  234 + //下发调度指令
  235 + directiveService.send60Dispatch(next, doneSum, "到站@系统");
207 236
208 - int doneSum = dayOfSchedule.doneSum(mr.sch.getClZbh());  
209 - ScheduleRealInfo next = dayOfSchedule.next(mr.sch);  
210 - if(null != next){  
211 - next.setQdzArrDateSJ(mr.sch.getZdsjActual());  
212 - //下发调度指令  
213 - directiveService.send60Dispatch(next, doneSum, "到站@系统");  
214 -  
215 - //起点既停车场的进场班次  
216 - if(next.getBcType().equals("in") && next.getJhlc() == null)  
217 - next.setFcsjActualAll(mr.ts);  
218 - }  
219 - else//下发文本指令(已结束运营)  
220 - directiveService.send60Phrase(nbbm, "到达终点 " + mr.sch.getZdzName() + ",已完成当日所有排班。", "系统");  
221 - //通知客户端  
222 - sendUtils.sendZdsj(mr.sch, next, doneSum);  
223 - //持久化  
224 - dayOfSchedule.save(mr.sch); 237 + //完成“起点既停车场”的进场班次
  238 + if(next.getBcType().equals("in") && next.getJhlc() == null)
  239 + next.setFcsjActualAll(mr.ts);
  240 +
  241 + //套跑 -下发线路切换指令
  242 + if(!next.getXlBm().equals(mr.sch.getXlBm()))
  243 + directiveService.lineChange(next.getClZbh(), next.getXlBm(), "套跑@系统");
225 } 244 }
  245 + else//下发文本指令(已结束运营)
  246 + directiveService.send60Phrase(nbbm, "到达终点 " + mr.sch.getZdzName() + ",已完成当日所有排班。", "系统");
  247 + //通知客户端
  248 + sendUtils.sendZdsj(mr.sch, next, doneSum);
  249 + //持久化
  250 + dayOfSchedule.save(mr.sch);
  251 + logger.info(mr.sch.getClZbh() + "移除正在执行班次," + mr.sch.getFcsj());
  252 + //移除车辆正在执行班次索引
  253 + dayOfSchedule.removeExecPlan(mr.sch.getClZbh());
226 } 254 }
227 255
228 /** 256 /**
src/main/java/com/bsth/data/match/Arrival2Schedule_old.java deleted 100644 → 0
1 -package com.bsth.data.match;  
2 -//package com.bsth.data.match;  
3 -//  
4 -//import java.util.ArrayList;  
5 -//import java.util.Collections;  
6 -//import java.util.List;  
7 -//import java.util.Set;  
8 -//  
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 -//import com.bsth.data.arrival.ArrivalComparator;  
17 -//import com.bsth.data.arrival.ArrivalData_GPS;  
18 -//import com.bsth.data.arrival.ArrivalEntity;  
19 -//import com.bsth.data.schedule.DayOfSchedule;  
20 -//import com.bsth.data.schedule.ScheduleComparator;  
21 -//import com.bsth.entity.realcontrol.ScheduleRealInfo;  
22 -//import com.bsth.service.directive.DirectiveService;  
23 -//import com.bsth.websocket.handler.SendUtils;  
24 -//  
25 -///**  
26 -// *  
27 -// * @ClassName: Arrival2Schedule  
28 -// * @Description: TODO(进出数据匹配班次)  
29 -// * @author PanZhao  
30 -// * @date 2016年8月10日 下午2:26:22  
31 -// *  
32 -// */  
33 -//@Component  
34 -//public class Arrival2Schedule implements ApplicationContextAware{  
35 -//  
36 -// private static ScheduleComparator.FCSJ schComparator;  
37 -// private static ArrivalComparator arrComparator;  
38 -// private static SendUtils sendUtils;  
39 -// private static DayOfSchedule dayOfSchedule;  
40 -// private static DirectiveService directiveService;  
41 -//  
42 -// private final static long MAX_RANGE = 1000 * 60 * 60 * 1L;  
43 -//  
44 -// static{  
45 -// schComparator = new ScheduleComparator.FCSJ();  
46 -// arrComparator = new ArrivalComparator();  
47 -// }  
48 -//  
49 -// static Logger logger = LoggerFactory.getLogger(Arrival2Schedule.class);  
50 -//  
51 -// /**  
52 -// *  
53 -// * @Title: start  
54 -// * @Description: TODO(开始)  
55 -// * @param @param cars 需要匹配的车辆集合  
56 -// */  
57 -// public static void start(Set<String> cars){  
58 -//  
59 -// for(String car : cars){  
60 -// new GpsMatchThread(car).start();  
61 -// }  
62 -// }  
63 -//  
64 -// public static class GpsMatchThread extends Thread{  
65 -//  
66 -// String nbbm;  
67 -// public GpsMatchThread(String nbbm){  
68 -// this.nbbm = nbbm;  
69 -// }  
70 -//  
71 -// @Override  
72 -// public void run() {  
73 -// //班次列表  
74 -// List<ScheduleRealInfo> schList = dayOfSchedule.findByNbbm(nbbm);  
75 -// //进出起终点数据  
76 -// List<ArrivalEntity> arrList = ArrivalData_GPS.getIncrement(nbbm);  
77 -// logger.info("####匹配进出站增量数据 " + arrList.size());  
78 -// //排序  
79 -// Collections.sort(schList, schComparator);  
80 -// Collections.sort(arrList, arrComparator);  
81 -//  
82 -// int si = lastMatchPoint(schList);  
83 -// int ai = afterByTime(arrList, lastMatchTime(schList.get(si)));  
84 -//  
85 -// //按起始索引开始匹配  
86 -// match(arrList, ai, schList, si);  
87 -// }  
88 -//  
89 -// public void match(List<ArrivalEntity> arrList, int ai, List<ScheduleRealInfo> schList, int si){  
90 -//  
91 -// int sLen = schList.size();  
92 -// for(; si < sLen; si ++)  
93 -// match(arrList, ai, schList.get(si));  
94 -// }  
95 -//  
96 -// public void match(List<ArrivalEntity> arrList, int ai, ScheduleRealInfo sch){  
97 -// //烂班不参与  
98 -// if(sch.isDestroy())  
99 -// return;  
100 -//  
101 -// int aLen = arrList.size();  
102 -//  
103 -// List<MatchResult> inRsList = new ArrayList<>()  
104 -// ,outRsList = new ArrayList<>();  
105 -//  
106 -// MatchResult mrs;  
107 -// for(;ai < aLen; ai ++){  
108 -// mrs = match(arrList.get(ai), sch);  
109 -// if(!mrs.success)  
110 -// continue;  
111 -//  
112 -// if(mrs.inOut == 0)  
113 -// inRsList.add(mrs);  
114 -// else if(mrs.inOut == 1)  
115 -// outRsList.add(mrs);  
116 -// }  
117 -//  
118 -// if(outRsList.size() > 0){  
119 -// //排序后的第一个 就是最合适的匹配  
120 -// Collections.sort(outRsList, new MatchResultComparator());  
121 -// mrs = outRsList.get(0);  
122 -//  
123 -// mrs.sch.setFcsjActualAll(mrs.ts);  
124 -// //通知客户端  
125 -// sendUtils.sendFcsj(mrs.sch);  
126 -// //持久化  
127 -// dayOfSchedule.save(mrs.sch);  
128 -// }  
129 -//  
130 -// if(inRsList.size() > 0){  
131 -// //排序后的第一个 就是最合适的匹配  
132 -// Collections.sort(inRsList, new MatchResultComparator());  
133 -// mrs = inRsList.get(0);  
134 -//  
135 -// /*if(!dayOfSchedule.validEndTime(mrs.sch, mrs.ts)){  
136 -// return;  
137 -// }*/  
138 -//  
139 -// mrs.sch.setZdsjActualAll(mrs.ts);  
140 -// int doneSum = dayOfSchedule.doneSum(mrs.sch.getClZbh());  
141 -// ScheduleRealInfo next = dayOfSchedule.next(mrs.sch);  
142 -// if(null != next){  
143 -// next.setQdzArrDateSJ(mrs.sch.getZdsjActual());  
144 -// //下发调度指令  
145 -// directiveService.send60Dispatch(next, doneSum, "系统");  
146 -// }  
147 -// else{  
148 -// //下发文本指令(已结束运营)  
149 -// directiveService.send60Phrase(nbbm, "到达终点 " + mrs.sch.getZdzName() + ",已完成当日所有排班。", "系统");  
150 -// }  
151 -// //通知客户端  
152 -// sendUtils.sendZdsj(mrs.sch, next, doneSum);  
153 -// //持久化  
154 -// dayOfSchedule.save(mrs.sch);  
155 -// }  
156 -// }  
157 -//  
158 -// public MatchResult match(ArrivalEntity arr, ScheduleRealInfo sch){  
159 -// MatchResult mrs = new MatchResult();  
160 -// mrs.inOut = arr.getInOut();  
161 -// mrs.sch = sch;  
162 -// mrs.ts = arr.getTs();  
163 -//  
164 -// if(Integer.parseInt(sch.getXlDir()) != arr.getUpDown()){  
165 -// return mrs;  
166 -// }  
167 -//  
168 -// if(arr.getInOut() == 1){  
169 -// if(sch.getFcsjActual() == null  
170 -// && sch.getQdzCode().equals(arr.getStopNo())  
171 -// && dayOfSchedule.validStartTime(sch, arr.getTs())){  
172 -//  
173 -// mrs.diff = arr.getTs() - sch.getDfsjT();  
174 -// if(Math.abs(mrs.diff) < MAX_RANGE)  
175 -// mrs.success = true;  
176 -// }  
177 -// }  
178 -// else if(arr.getInOut() == 0 && sch.getZdsj() != null){  
179 -// if(sch.getZdsjActual() == null  
180 -// && sch.getZdzCode().equals(arr.getStopNo())  
181 -// && dayOfSchedule.validEndTime(sch, arr.getTs())){  
182 -//  
183 -// mrs.diff = arr.getTs() - sch.getZdsjT();  
184 -// if(Math.abs(mrs.diff) < MAX_RANGE)  
185 -// mrs.success = true;  
186 -// }  
187 -// }  
188 -//  
189 -// return mrs;  
190 -// }  
191 -//  
192 -// /**  
193 -// *  
194 -// * @Title: lastMatchPoint  
195 -// * @Description: TODO(最后一个已实发的班次索引)  
196 -// */  
197 -// public int lastMatchPoint(List<ScheduleRealInfo> schList){  
198 -// int len = schList.size()  
199 -// ,rs = 0;  
200 -//  
201 -// ScheduleRealInfo sch;  
202 -// for(int i = len - 2; i >= 0; i --){  
203 -// sch = schList.get(i);  
204 -// if(sch.getFcsjActual() != null){  
205 -// rs = i;  
206 -// if(sch.getStatus() == 2)  
207 -// rs ++;  
208 -// break;  
209 -// }  
210 -// }  
211 -// return rs;  
212 -// }  
213 -//  
214 -// public long lastMatchTime(ScheduleRealInfo sch){  
215 -// Long t = 0L;  
216 -// if(null != sch.getFcsjActualTime())  
217 -// t = sch.getFcsjActualTime();  
218 -// if(null != sch.getZdsjActualTime())  
219 -// t = sch.getZdsjActualTime();  
220 -// return t;  
221 -// }  
222 -//  
223 -// /**  
224 -// *  
225 -// * @Title: afterByTime  
226 -// * @Description: TODO(参数时间戳之后的起始索引)  
227 -// */  
228 -// public int afterByTime(List<ArrivalEntity> arrList, long t){  
229 -// int len = arrList.size()  
230 -// ,rs = len - 1;  
231 -//  
232 -// for(int i = 0; i < len; i ++){  
233 -// if(arrList.get(i).getTs() > t){  
234 -// rs = i;  
235 -// break;  
236 -// }  
237 -// }  
238 -// return rs;  
239 -// }  
240 -// }  
241 -//  
242 -// @Override  
243 -// public void setApplicationContext(ApplicationContext arg0) throws BeansException {  
244 -// sendUtils = arg0.getBean(SendUtils.class);  
245 -// dayOfSchedule = arg0.getBean(DayOfSchedule.class);  
246 -// directiveService = arg0.getBean(DirectiveService.class);  
247 -// }  
248 -//}  
src/main/java/com/bsth/data/schedule/DayOfSchedule.java
1 package com.bsth.data.schedule; 1 package com.bsth.data.schedule;
2 2
3 import java.text.ParseException; 3 import java.text.ParseException;
  4 +import java.text.SimpleDateFormat;
4 import java.util.ArrayList; 5 import java.util.ArrayList;
5 import java.util.Collection; 6 import java.util.Collection;
6 import java.util.Collections; 7 import java.util.Collections;
@@ -23,8 +24,11 @@ import org.springframework.stereotype.Component; @@ -23,8 +24,11 @@ import org.springframework.stereotype.Component;
23 import com.alibaba.fastjson.JSON; 24 import com.alibaba.fastjson.JSON;
24 import com.alibaba.fastjson.JSONArray; 25 import com.alibaba.fastjson.JSONArray;
25 import com.bsth.Application; 26 import com.bsth.Application;
  27 +import com.bsth.data.BasicData;
26 import com.bsth.data.LineConfigData; 28 import com.bsth.data.LineConfigData;
27 import com.bsth.data.directive.FirstScheduleCheckThread; 29 import com.bsth.data.directive.FirstScheduleCheckThread;
  30 +import com.bsth.data.gpsdata.GpsEntity;
  31 +import com.bsth.data.gpsdata.GpsRealData;
28 import com.bsth.data.schedule.thread.ScheduleLateThread; 32 import com.bsth.data.schedule.thread.ScheduleLateThread;
29 import com.bsth.data.schedule.thread.SchedulePstThread; 33 import com.bsth.data.schedule.thread.SchedulePstThread;
30 import com.bsth.data.schedule.thread.ScheduleRefreshThread; 34 import com.bsth.data.schedule.thread.ScheduleRefreshThread;
@@ -60,6 +64,9 @@ public class DayOfSchedule implements CommandLineRunner { @@ -60,6 +64,9 @@ public class DayOfSchedule implements CommandLineRunner {
60 64
61 // 车辆和排班起终点站对照(包括进出的停车场,区间起终点) 65 // 车辆和排班起终点站对照(包括进出的停车场,区间起终点)
62 private static TreeMultimap<String, String> nbbm2SEStationMap; 66 private static TreeMultimap<String, String> nbbm2SEStationMap;
  67 +
  68 + //车辆 ——> 当前执行班次
  69 + private static Map<String, ScheduleRealInfo> carExecutePlanMap;
63 70
64 // 持久化缓冲区 71 // 持久化缓冲区
65 public static LinkedList<ScheduleRealInfo> pstBuffer; 72 public static LinkedList<ScheduleRealInfo> pstBuffer;
@@ -81,6 +88,9 @@ public class DayOfSchedule implements CommandLineRunner { @@ -81,6 +88,9 @@ public class DayOfSchedule implements CommandLineRunner {
81 88
82 @Autowired 89 @Autowired
83 SendUtils sendUtils; 90 SendUtils sendUtils;
  91 +
  92 + @Autowired
  93 + GpsRealData gpsRealData;
84 94
85 /** 线路当前使用的排班的日期 */ 95 /** 线路当前使用的排班的日期 */
86 public static Map<String, String> currSchDateMap; 96 public static Map<String, String> currSchDateMap;
@@ -92,6 +102,7 @@ public class DayOfSchedule implements CommandLineRunner { @@ -92,6 +102,7 @@ public class DayOfSchedule implements CommandLineRunner {
92 schFCSJComparator = new ScheduleComparator.FCSJ(); 102 schFCSJComparator = new ScheduleComparator.FCSJ();
93 currSchDateMap = new HashMap<>(); 103 currSchDateMap = new HashMap<>();
94 nbbm2SEStationMap = TreeMultimap.create(); 104 nbbm2SEStationMap = TreeMultimap.create();
  105 + carExecutePlanMap = new HashMap<>();
95 } 106 }
96 107
97 @Autowired 108 @Autowired
@@ -130,7 +141,9 @@ public class DayOfSchedule implements CommandLineRunner { @@ -130,7 +141,9 @@ public class DayOfSchedule implements CommandLineRunner {
130 public String calcSchDate(String lineCode) { 141 public String calcSchDate(String lineCode) {
131 LineConfig conf = lineConfigData.get(lineCode); 142 LineConfig conf = lineConfigData.get(lineCode);
132 long ct = System.currentTimeMillis(); 143 long ct = System.currentTimeMillis();
133 - String schDate = DateUtils.sdfyyyyMMdd.format(new Date(ct)); 144 +
  145 + SimpleDateFormat sdfyyyyMMdd = new SimpleDateFormat("yyyy-MM-dd");
  146 + String schDate = sdfyyyyMMdd.format(new Date(ct));
134 // 小于当天起始运营时间,则取前一天的排班 147 // 小于当天起始运营时间,则取前一天的排班
135 if (ct < conf.getCurrStartTime()) 148 if (ct < conf.getCurrStartTime())
136 schDate = DateUtils.subtractDay(schDate, 1); 149 schDate = DateUtils.subtractDay(schDate, 1);
@@ -283,7 +296,10 @@ public class DayOfSchedule implements CommandLineRunner { @@ -283,7 +296,10 @@ public class DayOfSchedule implements CommandLineRunner {
283 296
284 try { 297 try {
285 Map<String, Object> data = new HashMap<>(); 298 Map<String, Object> data = new HashMap<>();
286 - data.put("scheduleDate_eq", DateUtils.sdfyyyyMMdd.parse(schDate)); 299 + SimpleDateFormat sdfyyyyMMdd = new SimpleDateFormat("yyyy-MM-dd")
  300 + ,sdfHHmm = new SimpleDateFormat("HH:mm");
  301 +
  302 + data.put("scheduleDate_eq", sdfyyyyMMdd.parse(schDate));
287 data.put("xlBm_eq", lineCode); 303 data.put("xlBm_eq", lineCode);
288 304
289 // 查询计划排班 305 // 查询计划排班
@@ -293,13 +309,13 @@ public class DayOfSchedule implements CommandLineRunner { @@ -293,13 +309,13 @@ public class DayOfSchedule implements CommandLineRunner {
293 realList = JSONArray.parseArray(JSON.toJSONString(planItr), ScheduleRealInfo.class); 309 realList = JSONArray.parseArray(JSON.toJSONString(planItr), ScheduleRealInfo.class);
294 310
295 for (ScheduleRealInfo sch : realList) { 311 for (ScheduleRealInfo sch : realList) {
296 - sch.setScheduleDateStr(DateUtils.sdfyyyyMMdd.format(sch.getScheduleDate())); 312 + sch.setScheduleDateStr(sdfyyyyMMdd.format(sch.getScheduleDate()));
297 sch.setRealExecDate(sch.getScheduleDateStr()); 313 sch.setRealExecDate(sch.getScheduleDateStr());
298 // 计划终点时间 314 // 计划终点时间
299 if (sch.getBcsj() != null) { 315 if (sch.getBcsj() != null) {
300 try{ 316 try{
301 - sch.setZdsjT(DateUtils.sdfHHmm.parse(sch.getFcsj()).getTime() + (sch.getBcsj() * 60 * 1000));  
302 - sch.setZdsj(DateUtils.sdfHHmm.format(sch.getZdsjT())); 317 + sch.setZdsjT(sdfHHmm.parse(sch.getFcsj()).getTime() + (sch.getBcsj() * 60 * 1000));
  318 + sch.setZdsj(sdfHHmm.format(sch.getZdsjT()));
303 sch.setLate(false); 319 sch.setLate(false);
304 }catch(ParseException pe){ 320 }catch(ParseException pe){
305 logger.error("loadPlanSch... 计算终点时间失败..."); 321 logger.error("loadPlanSch... 计算终点时间失败...");
@@ -326,10 +342,11 @@ public class DayOfSchedule implements CommandLineRunner { @@ -326,10 +342,11 @@ public class DayOfSchedule implements CommandLineRunner {
326 id = 0L; 342 id = 0L;
327 id++; 343 id++;
328 344
  345 + SimpleDateFormat sdfyyyyMMdd = new SimpleDateFormat("yyyy-MM-dd");
329 for (ScheduleRealInfo item : list) { 346 for (ScheduleRealInfo item : list) {
330 item.setSpId(item.getId());// 保留原始的计划ID 347 item.setSpId(item.getId());// 保留原始的计划ID
331 item.setId(id++);// 设置ID 348 item.setId(id++);// 设置ID
332 - item.setScheduleDateStr(DateUtils.sdfyyyyMMdd.format(item.getScheduleDate())); 349 + item.setScheduleDateStr(sdfyyyyMMdd.format(item.getScheduleDate()));
333 } 350 }
334 351
335 // 入库 352 // 入库
@@ -596,4 +613,44 @@ public class DayOfSchedule implements CommandLineRunner { @@ -596,4 +613,44 @@ public class DayOfSchedule implements CommandLineRunner {
596 public Collection<ScheduleRealInfo> findAll(){ 613 public Collection<ScheduleRealInfo> findAll(){
597 return nbbmScheduleMap.values(); 614 return nbbmScheduleMap.values();
598 } 615 }
  616 +
  617 + public void addExecPlan(ScheduleRealInfo sch){
  618 + carExecutePlanMap.put(sch.getClZbh(), sch);
  619 + }
  620 +
  621 + public void removeExecPlan(String clzbh){
  622 + carExecutePlanMap.remove(clzbh);
  623 + }
  624 +
  625 + public Map<String, ScheduleRealInfo> execPlamMap(){
  626 + return carExecutePlanMap;
  627 + }
  628 +
  629 + /**
  630 + *
  631 + * @Title: linkToSchPlan
  632 + * @Description: TODO(车辆关联到班次)
  633 + */
  634 +/* public void linkToSchPlan(String nbbm) {
  635 + //当前GPS状态
  636 + GpsEntity gps = gpsRealData.get(BasicData.deviceId2NbbmMap.inverse().get(nbbm));
  637 + if(null == gps)
  638 + return;
  639 +
  640 + //班次集合
  641 + List<ScheduleRealInfo> schArr = nbbmScheduleMap.get(nbbm);
  642 +
  643 + for(ScheduleRealInfo sch : schArr){
  644 + if(sch.getStatus() == 2)
  645 + continue;
  646 + if(sch.isDestroy())
  647 + continue;
  648 + if(!sch.getXlBm().equals(gps.getLineId())
  649 + || Integer.parseInt(sch.getXlDir()) != gps.getUpDown().intValue())
  650 + continue;
  651 +
  652 + addExecPlan(sch);
  653 + break;
  654 + }
  655 + }*/
599 } 656 }
src/main/java/com/bsth/data/schedule/SchAttrCalculator.java
1 package com.bsth.data.schedule; 1 package com.bsth.data.schedule;
2 2
3 import java.text.ParseException; 3 import java.text.ParseException;
  4 +import java.text.SimpleDateFormat;
4 import java.util.Collections; 5 import java.util.Collections;
5 import java.util.Date; 6 import java.util.Date;
6 import java.util.List; 7 import java.util.List;
@@ -13,7 +14,6 @@ import org.springframework.stereotype.Component; @@ -13,7 +14,6 @@ import org.springframework.stereotype.Component;
13 import com.bsth.data.LineConfigData; 14 import com.bsth.data.LineConfigData;
14 import com.bsth.entity.realcontrol.LineConfig; 15 import com.bsth.entity.realcontrol.LineConfig;
15 import com.bsth.entity.realcontrol.ScheduleRealInfo; 16 import com.bsth.entity.realcontrol.ScheduleRealInfo;
16 -import com.bsth.util.DateUtils;  
17 17
18 /** 18 /**
19 * 19 *
@@ -48,11 +48,13 @@ public class SchAttrCalculator { @@ -48,11 +48,13 @@ public class SchAttrCalculator {
48 * 早于线路开始运营时间的,加一天 48 * 早于线路开始运营时间的,加一天
49 * 如该线路 2点开始运营,2016-08-23的班次,则 2016-08-23 0:25 的班次应该调整成 2016-08-24 0:25 49 * 如该线路 2点开始运营,2016-08-23的班次,则 2016-08-23 0:25 的班次应该调整成 2016-08-24 0:25
50 */ 50 */
51 - long st = DateUtils.sdfyyyyMMddHHmm.parse(sch.getScheduleDateStr() + conf.getStartOpt()).getTime(); 51 + SimpleDateFormat sdfyyyyMMddHHmm = new SimpleDateFormat("yyyy-MM-ddHH:mm")
  52 + ,sdfyyyyMMdd = new SimpleDateFormat("yyyy-MM-dd");
  53 + long st = sdfyyyyMMddHHmm.parse(sch.getScheduleDateStr() + conf.getStartOpt()).getTime();
52 if (st > sch.getFcsjT()) 54 if (st > sch.getFcsjT())
53 sch.setFcsjAll(sch.getFcsjT() + DAY_TIME); 55 sch.setFcsjAll(sch.getFcsjT() + DAY_TIME);
54 56
55 - sch.setRealExecDate(DateUtils.sdfyyyyMMdd.format(new Date(sch.getFcsjT()))); 57 + sch.setRealExecDate(sdfyyyyMMdd.format(new Date(sch.getFcsjT())));
56 } catch (Exception e) { 58 } catch (Exception e) {
57 logger.error("", e); 59 logger.error("", e);
58 } 60 }
@@ -69,11 +71,12 @@ public class SchAttrCalculator { @@ -69,11 +71,12 @@ public class SchAttrCalculator {
69 // 生成时间戳 71 // 生成时间戳
70 calcTimestamp(sch); 72 calcTimestamp(sch);
71 73
  74 + SimpleDateFormat sdfHHmm = new SimpleDateFormat("HH:mm");
72 // 计划终点时间 75 // 计划终点时间
73 if (sch.getBcsj() != null) { 76 if (sch.getBcsj() != null) {
74 Date zdDate = new Date(sch.getDfsjT() + (sch.getBcsj() * 60 * 1000)); 77 Date zdDate = new Date(sch.getDfsjT() + (sch.getBcsj() * 60 * 1000));
75 sch.setZdsjT(zdDate.getTime()); 78 sch.setZdsjT(zdDate.getTime());
76 - sch.setZdsj(DateUtils.sdfHHmm.format(zdDate)); 79 + sch.setZdsj(sdfHHmm.format(zdDate));
77 } 80 }
78 } catch (ParseException e) { 81 } catch (ParseException e) {
79 logger.error("", e); 82 logger.error("", e);
@@ -132,7 +135,8 @@ public class SchAttrCalculator { @@ -132,7 +135,8 @@ public class SchAttrCalculator {
132 } 135 }
133 136
134 public SchAttrCalculator calcFcsjTime(ScheduleRealInfo sch) throws ParseException { 137 public SchAttrCalculator calcFcsjTime(ScheduleRealInfo sch) throws ParseException {
135 - sch.setFcsjT(DateUtils.sdfyyyyMMddHHmm.parse(sch.getRealExecDate() + sch.getFcsj()).getTime()); 138 + SimpleDateFormat sdfyyyyMMddHHmm = new SimpleDateFormat("yyyy-MM-ddHH:mm");
  139 + sch.setFcsjT(sdfyyyyMMddHHmm.parse(sch.getRealExecDate() + sch.getFcsj()).getTime());
136 return this; 140 return this;
137 } 141 }
138 142
src/main/java/com/bsth/data/schedule/thread/ScheduleLateThread.java
@@ -47,7 +47,9 @@ public class ScheduleLateThread extends Thread{ @@ -47,7 +47,9 @@ public class ScheduleLateThread extends Thread{
47 if(sch.getDfsjT() > t) 47 if(sch.getDfsjT() > t)
48 break; 48 break;
49 49
50 - if(sch.getStatus() == 0 && sch.getFcsjActual() == null){ 50 + if(sch.isLate() == false
  51 + && sch.getStatus() == 0
  52 + && sch.getFcsjActual() == null){
51 //应发未发 53 //应发未发
52 sch.setLate(true); 54 sch.setLate(true);
53 //通知客户端 55 //通知客户端
src/main/java/com/bsth/entity/Cars.java
@@ -57,7 +57,7 @@ public class Cars implements Serializable { @@ -57,7 +57,7 @@ public class Cars implements Serializable {
57 /** 设备终端号 */ 57 /** 设备终端号 */
58 @Column(nullable = false) 58 @Column(nullable = false)
59 private String equipmentCode; 59 private String equipmentCode;
60 - 60 +
61 // 以下信息来自总公司的业务系统,可能需要调用相关接口 61 // 以下信息来自总公司的业务系统,可能需要调用相关接口
62 /** 车型类别 */ 62 /** 车型类别 */
63 private String carClass ; 63 private String carClass ;
@@ -115,6 +115,8 @@ public class Cars implements Serializable { @@ -115,6 +115,8 @@ public class Cars implements Serializable {
115 private String vehicleStats; 115 private String vehicleStats;
116 /** 营运状态 */ 116 /** 营运状态 */
117 private String operatorsState; 117 private String operatorsState;
  118 + /** 营运证编码 */
  119 + private String serviceNo;
118 /** 是否电车(TODO:在原系统里没有,这里暂时留着) */ 120 /** 是否电车(TODO:在原系统里没有,这里暂时留着) */
119 private Boolean sfdc; 121 private Boolean sfdc;
120 /** 备注/描述 */ 122 /** 备注/描述 */
@@ -148,8 +150,16 @@ public class Cars implements Serializable { @@ -148,8 +150,16 @@ public class Cars implements Serializable {
148 /** 修改日期 */ 150 /** 修改日期 */
149 @Column(name = "update_date", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP") 151 @Column(name = "update_date", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")
150 private Date updateDate; 152 private Date updateDate;
  153 +
  154 + public String getServiceNo() {
  155 + return serviceNo;
  156 + }
  157 +
  158 + public void setServiceNo(String serviceNo) {
  159 + this.serviceNo = serviceNo;
  160 + }
151 161
152 - public Integer getId() { 162 + public Integer getId() {
153 return id; 163 return id;
154 } 164 }
155 165
src/main/java/com/bsth/entity/Line.java
@@ -42,18 +42,6 @@ public class Line implements Serializable { @@ -42,18 +42,6 @@ public class Line implements Serializable {
42 // 简称 42 // 简称
43 private String shortName; 43 private String shortName;
44 44
45 - /** 配置车辆总数 老版本系统字段, 新版本系统业务需求暂时没用到该字段 ,这里暂时留着 */  
46 - private Integer carSumNumber;  
47 -  
48 - /** 空调车辆数量 老版本系统字段, 新版本系统业务需求暂时没用到该字段 ,这里暂时留着 */  
49 - private Integer hvacCarNumber;  
50 -  
51 - /** 普通车辆数量 老版本系统字段, 新版本系统业务需求暂时没用到该字段 ,这里暂时留着 */  
52 - private Integer ordCarNumber;  
53 -  
54 - /** 停车场编码 老版本系统字段, 新版本系统业务需求暂时没用到该字段 ,这里暂时留着 */  
55 - private String carParkCode;  
56 -  
57 // 起始站名称 45 // 起始站名称
58 private String startStationName; 46 private String startStationName;
59 47
@@ -118,6 +106,21 @@ public class Line implements Serializable { @@ -118,6 +106,21 @@ public class Line implements Serializable {
118 // 设备线路编码 106 // 设备线路编码
119 private String eqLinecode; 107 private String eqLinecode;
120 108
  109 + /** 配置车辆总数 老版本系统字段, 新版本系统业务需求暂时没用到该字段 ,这里暂时留着 */
  110 + private Integer carSumNumber;
  111 +
  112 + /** 空调车辆数量 老版本系统字段, 新版本系统业务需求暂时没用到该字段 ,这里暂时留着 */
  113 + private Integer hvacCarNumber;
  114 +
  115 + /** 普通车辆数量 老版本系统字段, 新版本系统业务需求暂时没用到该字段 ,这里暂时留着 */
  116 + private Integer ordCarNumber;
  117 +
  118 + /** 停车场编码 老版本系统字段, 新版本系统业务需求暂时没用到该字段 ,这里暂时留着 */
  119 + private String carParkCode;
  120 +
  121 + /** 线路规划类型 <0:双向;1:环线> */
  122 + private Integer linePlayType;
  123 +
121 // 描述 124 // 描述
122 private String descriptions; 125 private String descriptions;
123 126
@@ -134,6 +137,14 @@ public class Line implements Serializable { @@ -134,6 +137,14 @@ public class Line implements Serializable {
134 // 修改日期 137 // 修改日期
135 @Column(name = "update_date", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP") 138 @Column(name = "update_date", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")
136 private Date updateDate; 139 private Date updateDate;
  140 +
  141 + public Integer getLinePlayType() {
  142 + return linePlayType;
  143 + }
  144 +
  145 + public void setLinePlayType(Integer linePlayType) {
  146 + this.linePlayType = linePlayType;
  147 + }
137 148
138 public Integer getId() { 149 public Integer getId() {
139 return id; 150 return id;
src/main/java/com/bsth/entity/Personnel.java
@@ -53,7 +53,17 @@ public class Personnel { @@ -53,7 +53,17 @@ public class Personnel {
53 private String personnelType; 53 private String personnelType;
54 /** 所属岗位/工种(字典类型gzType) */ 54 /** 所属岗位/工种(字典类型gzType) */
55 private String posts; 55 private String posts;
  56 +
  57 + /** 身份证 */
  58 + private String card;
56 59
  60 + public String getCard() {
  61 + return card;
  62 + }
  63 +
  64 + public void setCard(String card) {
  65 + this.card = card;
  66 + }
57 67
58 /** 人员编码(TODO:在原系统里没有,这里暂时留着) */ 68 /** 人员编码(TODO:在原系统里没有,这里暂时留着) */
59 private String personnelCode; 69 private String personnelCode;
src/main/java/com/bsth/entity/Station.java
@@ -41,6 +41,9 @@ public class Station { @@ -41,6 +41,9 @@ public class Station {
41 // 所在道路编码 41 // 所在道路编码
42 private String roadCoding; 42 private String roadCoding;
43 43
  44 + // 站点的具体地址
  45 + private String addr;
  46 +
44 /** 47 /**
45 * 经纬坐标类型 48 * 经纬坐标类型
46 * 49 *
@@ -111,6 +114,14 @@ public class Station { @@ -111,6 +114,14 @@ public class Station {
111 // 修改日期 114 // 修改日期
112 @Column(name = "update_date", columnDefinition = "timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP") 115 @Column(name = "update_date", columnDefinition = "timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")
113 private Date updateDate; 116 private Date updateDate;
  117 +
  118 + public String getAddr() {
  119 + return addr;
  120 + }
  121 +
  122 + public void setAddr(String addr) {
  123 + this.addr = addr;
  124 + }
114 125
115 public Integer getId() { 126 public Integer getId() {
116 return id; 127 return id;
src/main/java/com/bsth/entity/StationRoute.java
@@ -21,7 +21,8 @@ import java.util.Date; @@ -21,7 +21,8 @@ import java.util.Date;
21 @Table(name = "bsth_c_stationroute") 21 @Table(name = "bsth_c_stationroute")
22 @NamedEntityGraphs({ 22 @NamedEntityGraphs({
23 @NamedEntityGraph(name = "stationRoute_station", attributeNodes = { 23 @NamedEntityGraph(name = "stationRoute_station", attributeNodes = {
24 - @NamedAttributeNode("station") 24 + @NamedAttributeNode("station"),
  25 + @NamedAttributeNode("line")
25 }) 26 })
26 }) 27 })
27 public class StationRoute { 28 public class StationRoute {
src/main/java/com/bsth/entity/directive/D64.java
@@ -40,6 +40,8 @@ public class D64 extends Directive{ @@ -40,6 +40,8 @@ public class D64 extends Directive{
40 private String deviceId; 40 private String deviceId;
41 41
42 private String lineId; 42 private String lineId;
  43 +
  44 + private String txtContent;
43 45
44 public Short getCityCode() { 46 public Short getCityCode() {
45 return cityCode; 47 return cityCode;
@@ -64,6 +66,14 @@ public class D64 extends Directive{ @@ -64,6 +66,14 @@ public class D64 extends Directive{
64 public void setLineId(String lineId) { 66 public void setLineId(String lineId) {
65 this.lineId = lineId; 67 this.lineId = lineId;
66 } 68 }
  69 +
  70 + public String getTxtContent() {
  71 + return txtContent;
  72 + }
  73 +
  74 + public void setTxtContent(String txtContent) {
  75 + this.txtContent = txtContent;
  76 + }
67 } 77 }
68 78
69 public Integer getId() { 79 public Integer getId() {
src/main/java/com/bsth/entity/directive/DC0_A4.java 0 → 100644
  1 +package com.bsth.entity.directive;
  2 +
  3 +import javax.persistence.Embeddable;
  4 +import javax.persistence.GeneratedValue;
  5 +import javax.persistence.Id;
  6 +
  7 +/**
  8 + *
  9 + * @ClassName: DC0_A4
  10 + * @Description: TODO(参数查询)
  11 + * @author PanZhao
  12 + * @date 2016年10月18日 下午5:22:36
  13 + *
  14 + */
  15 +public class DC0_A4 extends Directive{
  16 +
  17 + @Id
  18 + @GeneratedValue
  19 + private Integer id;
  20 +
  21 +
  22 + @Embeddable
  23 + public static class DC0A4Data {
  24 + /**
  25 + * 二级协议
  26 + */
  27 + private Short operCode2;
  28 + /** 设备编号 */
  29 + private String deviceId;
  30 + /** 网关IP地址 */
  31 + private String ipAddress;
  32 + /** 网关端口 */
  33 + private int port;
  34 + /** 定时定距上报模式 */
  35 + private short reportMode;
  36 + /** 定时上报时间间隔 */
  37 + private int interval;
  38 + /** 定距上报距离间隔 */
  39 + private String distance;
  40 + /** 非线路状态超速阀门 */
  41 + private short speedingThreshold;
  42 + /** 预警阀门 */
  43 + private short alarmThreshold;
  44 + /** pos机IP地址 */
  45 + private String posIpAddress;
  46 + }
  47 +}
src/main/java/com/bsth/entity/forecast/Sample.java
1 package com.bsth.entity.forecast; 1 package com.bsth.entity.forecast;
2 2
3 3
  4 +import java.text.SimpleDateFormat;
  5 +import java.util.Date;
  6 +
4 import javax.persistence.Entity; 7 import javax.persistence.Entity;
5 import javax.persistence.GeneratedValue; 8 import javax.persistence.GeneratedValue;
6 import javax.persistence.Id; 9 import javax.persistence.Id;
7 import javax.persistence.Table; 10 import javax.persistence.Table;
8 import javax.persistence.Transient; 11 import javax.persistence.Transient;
9 12
  13 +import org.slf4j.Logger;
  14 +import org.slf4j.LoggerFactory;
  15 +
  16 +import com.bsth.data.arrival.ArrivalEntity;
  17 +
10 /** 18 /**
11 * 19 *
12 * @ClassName: Sample 20 * @ClassName: Sample
@@ -19,11 +27,36 @@ import javax.persistence.Transient; @@ -19,11 +27,36 @@ import javax.persistence.Transient;
19 @Table(name = "bsth_forecast_sample") 27 @Table(name = "bsth_forecast_sample")
20 public class Sample { 28 public class Sample {
21 29
  30 + @Transient
  31 + static Logger logger = LoggerFactory.getLogger(Sample.class);
  32 +
  33 + public Sample(ArrivalEntity prve, ArrivalEntity curr) {
  34 + //SimpleDateFormat sdfHHmm = new SimpleDateFormat("HH:mm");
  35 +
  36 + this.setsStation(prve.getStopNo());
  37 + this.seteStation(curr.getStopNo());
  38 + this.setsTime(prve.getTs());
  39 + this.seteTime(curr.getTs());
  40 + //this.setsDate(sdfHHmm.format(new Date(prve.getTs())));
  41 + //this.seteDate(sdfHHmm.format(new Date(curr.getTs())));
  42 +
  43 + /*try{
  44 + this.setsTime(sdfHHmm.parse(this.sDate).getTime());
  45 + this.seteTime(sdfHHmm.parse(this.eDate).getTime());
  46 + }catch(Exception e){
  47 + logger.error("", e);
  48 + }*/
  49 + Long diff = (curr.getTs() - prve.getTs());
  50 + this.setRunTime(Float.parseFloat(diff.toString()) / 1000 / 60);
  51 + }
  52 +
  53 + public Sample(){}
  54 +
22 @Id 55 @Id
23 @GeneratedValue 56 @GeneratedValue
24 private Long id; 57 private Long id;
25 58
26 - private Integer lineCode; 59 + private String lineCode;
27 60
28 // 开始时间 61 // 开始时间
29 private String sDate; 62 private String sDate;
@@ -135,11 +168,11 @@ public class Sample { @@ -135,11 +168,11 @@ public class Sample {
135 this.runTime = runTime; 168 this.runTime = runTime;
136 } 169 }
137 170
138 - public Integer getLineCode() { 171 + public String getLineCode() {
139 return lineCode; 172 return lineCode;
140 } 173 }
141 174
142 - public void setLineCode(Integer lineCode) { 175 + public void setLineCode(String lineCode) {
143 this.lineCode = lineCode; 176 this.lineCode = lineCode;
144 } 177 }
145 178
src/main/java/com/bsth/entity/realcontrol/LineConfig.java
1 package com.bsth.entity.realcontrol; 1 package com.bsth.entity.realcontrol;
2 2
3 import java.text.ParseException; 3 import java.text.ParseException;
  4 +import java.text.SimpleDateFormat;
4 import java.util.Date; 5 import java.util.Date;
5 import java.util.HashSet; 6 import java.util.HashSet;
6 import java.util.Set; 7 import java.util.Set;
@@ -137,7 +138,9 @@ public class LineConfig { @@ -137,7 +138,9 @@ public class LineConfig {
137 public long getCurrStartTime() { 138 public long getCurrStartTime() {
138 Date d = null; 139 Date d = null;
139 try { 140 try {
140 - d = DateUtils.sdfyyyyMMddHHmm.parse(DateUtils.sdfyyyyMMdd.format(new Date()) + this.startOpt); 141 + SimpleDateFormat sdfyyyyMMddHHmm = new SimpleDateFormat("yyyy-MM-ddHH:mm")
  142 + ,sdfyyyyMMdd = new SimpleDateFormat("yyyy-MM-dd");
  143 + d = sdfyyyyMMddHHmm.parse(sdfyyyyMMdd.format(new Date()) + this.startOpt);
141 } catch (ParseException e) { 144 } catch (ParseException e) {
142 e.printStackTrace(); 145 e.printStackTrace();
143 } 146 }
src/main/java/com/bsth/entity/realcontrol/ScheduleRealInfo.java
1 package com.bsth.entity.realcontrol; 1 package com.bsth.entity.realcontrol;
2 2
3 import com.bsth.entity.sys.SysUser; 3 import com.bsth.entity.sys.SysUser;
4 -import com.bsth.util.DateUtils;  
5 import com.fasterxml.jackson.annotation.JsonIgnore; 4 import com.fasterxml.jackson.annotation.JsonIgnore;
6 5
7 import javax.persistence.*; 6 import javax.persistence.*;
@@ -9,6 +8,7 @@ import javax.persistence.*; @@ -9,6 +8,7 @@ import javax.persistence.*;
9 import org.apache.commons.lang3.StringUtils; 8 import org.apache.commons.lang3.StringUtils;
10 9
11 import java.text.ParseException; 10 import java.text.ParseException;
  11 +import java.text.SimpleDateFormat;
12 import java.util.Date; 12 import java.util.Date;
13 import java.util.HashSet; 13 import java.util.HashSet;
14 import java.util.Set; 14 import java.util.Set;
@@ -510,13 +510,15 @@ public class ScheduleRealInfo { @@ -510,13 +510,15 @@ public class ScheduleRealInfo {
510 510
511 public void setDfsjAll(Long dfsjT) { 511 public void setDfsjAll(Long dfsjT) {
512 this.dfsjT = dfsjT; 512 this.dfsjT = dfsjT;
513 - this.dfsj = DateUtils.sdfHHmm.format(new Date(this.dfsjT)); 513 + SimpleDateFormat sdfHHmm = new SimpleDateFormat("HH:mm");
  514 + this.dfsj = sdfHHmm.format(new Date(this.dfsjT));
514 } 515 }
515 516
516 public void setDfsjAll(String dfsj) { 517 public void setDfsjAll(String dfsj) {
517 518
518 try { 519 try {
519 - this.dfsjT = DateUtils.sdfyyyyMMddHHmm.parse(this.realExecDate + dfsj).getTime(); 520 + SimpleDateFormat sdfyyyyMMddHHmm = new SimpleDateFormat("yyyy-MM-ddHH:mm");
  521 + this.dfsjT = sdfyyyyMMddHHmm.parse(this.realExecDate + dfsj).getTime();
520 this.dfsj = dfsj; 522 this.dfsj = dfsj;
521 } catch (ParseException e) { 523 } catch (ParseException e) {
522 e.printStackTrace(); 524 e.printStackTrace();
@@ -525,10 +527,11 @@ public class ScheduleRealInfo { @@ -525,10 +527,11 @@ public class ScheduleRealInfo {
525 527
526 public void calcEndTime(){ 528 public void calcEndTime(){
527 //计划终点时间 529 //计划终点时间
  530 + SimpleDateFormat sdfHHmm = new SimpleDateFormat("HH:mm");
528 if(this.getBcsj() != null){ 531 if(this.getBcsj() != null){
529 Date zdDate = new Date(this.getDfsjT() + (this.getBcsj() * 60 * 1000)); 532 Date zdDate = new Date(this.getDfsjT() + (this.getBcsj() * 60 * 1000));
530 this.setZdsjT(zdDate.getTime()); 533 this.setZdsjT(zdDate.getTime());
531 - this.setZdsj(DateUtils.sdfHHmm.format(zdDate)); 534 + this.setZdsj(sdfHHmm.format(zdDate));
532 } 535 }
533 } 536 }
534 537
@@ -581,7 +584,8 @@ public class ScheduleRealInfo { @@ -581,7 +584,8 @@ public class ScheduleRealInfo {
581 */ 584 */
582 public void setFcsjAll(String fcsj){ 585 public void setFcsjAll(String fcsj){
583 try { 586 try {
584 - this.fcsjT = DateUtils.sdfyyyyMMddHHmm.parse(this.realExecDate + fcsj).getTime(); 587 + SimpleDateFormat sdfyyyyMMddHHmm = new SimpleDateFormat("yyyy-MM-ddHH:mm");
  588 + this.fcsjT = sdfyyyyMMddHHmm.parse(this.realExecDate + fcsj).getTime();
585 this.fcsj = fcsj; 589 this.fcsj = fcsj;
586 } catch (ParseException e) { 590 } catch (ParseException e) {
587 e.printStackTrace(); 591 e.printStackTrace();
@@ -596,7 +600,8 @@ public class ScheduleRealInfo { @@ -596,7 +600,8 @@ public class ScheduleRealInfo {
596 */ 600 */
597 public void setFcsjAll(Long fcsjT){ 601 public void setFcsjAll(Long fcsjT){
598 this.fcsjT = fcsjT; 602 this.fcsjT = fcsjT;
599 - this.fcsj = DateUtils.sdfHHmm.format(new Date(fcsjT)); 603 + SimpleDateFormat sdfHHmm = new SimpleDateFormat("HH:mm");
  604 + this.fcsj = sdfHHmm.format(new Date(fcsjT));
600 } 605 }
601 606
602 /** 607 /**
@@ -607,7 +612,8 @@ public class ScheduleRealInfo { @@ -607,7 +612,8 @@ public class ScheduleRealInfo {
607 */ 612 */
608 public void setFcsjActualAll(String fcsjActual){ 613 public void setFcsjActualAll(String fcsjActual){
609 try { 614 try {
610 - this.fcsjActualTime = DateUtils.sdfyyyyMMddHHmm.parse(this.realExecDate + fcsjActual).getTime(); 615 + SimpleDateFormat sdfyyyyMMddHHmm = new SimpleDateFormat("yyyy-MM-ddHH:mm");
  616 + this.fcsjActualTime = sdfyyyyMMddHHmm.parse(this.realExecDate + fcsjActual).getTime();
611 this.fcsjActual = fcsjActual; 617 this.fcsjActual = fcsjActual;
612 618
613 calcStatus(); 619 calcStatus();
@@ -624,7 +630,8 @@ public class ScheduleRealInfo { @@ -624,7 +630,8 @@ public class ScheduleRealInfo {
624 */ 630 */
625 public void setFcsjActualAll(Long t){ 631 public void setFcsjActualAll(Long t){
626 this.fcsjActualTime = t; 632 this.fcsjActualTime = t;
627 - this.fcsjActual = DateUtils.sdfHHmm.format(new Date(t)); 633 + SimpleDateFormat sdfHHmm = new SimpleDateFormat("HH:mm");
  634 + this.fcsjActual = sdfHHmm.format(new Date(t));
628 635
629 //更新班次状态 636 //更新班次状态
630 calcStatus(); 637 calcStatus();
@@ -638,7 +645,8 @@ public class ScheduleRealInfo { @@ -638,7 +645,8 @@ public class ScheduleRealInfo {
638 */ 645 */
639 public void setZdsjActualAll(Long t){ 646 public void setZdsjActualAll(Long t){
640 this.zdsjActualTime = t; 647 this.zdsjActualTime = t;
641 - this.zdsjActual = DateUtils.sdfHHmm.format(new Date(t)); 648 + SimpleDateFormat sdfHHmm = new SimpleDateFormat("HH:mm");
  649 + this.zdsjActual = sdfHHmm.format(new Date(t));
642 650
643 //更新班次状态 651 //更新班次状态
644 calcStatus(); 652 calcStatus();
@@ -653,7 +661,8 @@ public class ScheduleRealInfo { @@ -653,7 +661,8 @@ public class ScheduleRealInfo {
653 */ 661 */
654 public void setZdsjActualAll(String zdsjActual){ 662 public void setZdsjActualAll(String zdsjActual){
655 try { 663 try {
656 - this.zdsjActualTime = DateUtils.sdfyyyyMMddHHmm.parse(this.realExecDate + zdsjActual).getTime(); 664 + SimpleDateFormat sdfyyyyMMddHHmm = new SimpleDateFormat("yyyy-MM-ddHH:mm");
  665 + this.zdsjActualTime = sdfyyyyMMddHHmm.parse(this.realExecDate + zdsjActual).getTime();
657 this.zdsjActual = zdsjActual; 666 this.zdsjActual = zdsjActual;
658 667
659 calcStatus(); 668 calcStatus();
src/main/java/com/bsth/repository/StationRouteRepository.java
@@ -6,6 +6,7 @@ import java.util.Map; @@ -6,6 +6,7 @@ import java.util.Map;
6 import com.bsth.entity.schedule.CarConfigInfo; 6 import com.bsth.entity.schedule.CarConfigInfo;
7 import org.springframework.data.domain.Page; 7 import org.springframework.data.domain.Page;
8 import org.springframework.data.domain.Pageable; 8 import org.springframework.data.domain.Pageable;
  9 +import org.springframework.data.domain.Sort;
9 import org.springframework.data.jpa.domain.Specification; 10 import org.springframework.data.jpa.domain.Specification;
10 import org.springframework.data.jpa.repository.EntityGraph; 11 import org.springframework.data.jpa.repository.EntityGraph;
11 import org.springframework.data.jpa.repository.Modifying; 12 import org.springframework.data.jpa.repository.Modifying;
@@ -229,8 +230,28 @@ public interface StationRouteRepository extends BaseRepository&lt;StationRoute, Int @@ -229,8 +230,28 @@ public interface StationRouteRepository extends BaseRepository&lt;StationRoute, Int
229 230
230 @EntityGraph(value = "stationRoute_station", type = EntityGraph.EntityGraphType.FETCH) 231 @EntityGraph(value = "stationRoute_station", type = EntityGraph.EntityGraphType.FETCH)
231 @Query("select s from StationRoute s where s.destroy=0") 232 @Query("select s from StationRoute s where s.destroy=0")
232 - List<StationRoute> findAll2(); 233 + List<StationRoute> findAllEffective();
233 234
234 - @Query("select new map(sr.station.id as stationid, sr.stationName as stationname) from StationRoute sr where sr.line.id=?1 and sr.directions=?2") 235 + @EntityGraph(value = "stationRoute_station", type = EntityGraph.EntityGraphType.FETCH)
  236 + @Override
  237 + Page<StationRoute> findAll(Specification<StationRoute> spec, Pageable pageable);
  238 +
  239 + @EntityGraph(value = "stationRoute_station", type = EntityGraph.EntityGraphType.FETCH)
  240 + @Override
  241 + List<StationRoute> findAll(Specification<StationRoute> spec);
  242 +
  243 + @EntityGraph(value = "stationRoute_station", type = EntityGraph.EntityGraphType.FETCH)
  244 + @Override
  245 + List<StationRoute> findAll(Specification<StationRoute> spec, Sort sort);
  246 +
  247 +
  248 + @Query("select new map(sr.station.id as stationid, sr.stationName as stationname) from StationRoute sr where sr.line.id=?1 and sr.directions=?2")
235 List<Map<String, Object>> findStations(Integer xlid, Integer xldir); 249 List<Map<String, Object>> findStations(Integer xlid, Integer xldir);
  250 +
  251 + @Query("select r from StationRoute r where r.lineCode=?1 and r.directions=?2 and r.destroy=0 order by r.stationRouteCode")
  252 + List<StationRoute> findByLine(String lineCode, int updown);
  253 +
  254 + @EntityGraph(value = "stationRoute_station", type = EntityGraph.EntityGraphType.FETCH)
  255 + @Query("select s from StationRoute s where s.destroy=0 and s.lineCode=?1")
  256 + List<StationRoute> findByLineCode(String lineCode);
236 } 257 }
src/main/java/com/bsth/repository/forecast/SampleRepository.java
@@ -15,5 +15,5 @@ public interface SampleRepository extends BaseRepository&lt;Sample, Long&gt;{ @@ -15,5 +15,5 @@ public interface SampleRepository extends BaseRepository&lt;Sample, Long&gt;{
15 @Transactional 15 @Transactional
16 @Modifying 16 @Modifying
17 @Query("delete Sample where lineCode=?1 and updown=?2") 17 @Query("delete Sample where lineCode=?1 and updown=?2")
18 - void deleteByLineAndUpdown(Integer lineCode, int updown); 18 + void deleteByLineAndUpdown(String lineCode, int updown);
19 } 19 }
src/main/java/com/bsth/repository/realcontrol/ScheduleRealInfoRepository.java
@@ -20,7 +20,7 @@ public interface ScheduleRealInfoRepository extends BaseRepository&lt;ScheduleRealI @@ -20,7 +20,7 @@ public interface ScheduleRealInfoRepository extends BaseRepository&lt;ScheduleRealI
20 List<ScheduleRealInfo> findByLines(List<String> lines); 20 List<ScheduleRealInfo> findByLines(List<String> lines);
21 21
22 22
23 - @Query(value="select s from ScheduleRealInfo s where s.xlBm = ?1 and DATE_FORMAT(s.scheduleDate,'%Y-%m-%d') = ?2 and s.bcType = 'out' order by (lpName+1)") 23 + @Query(value="select s from ScheduleRealInfo s where s.xlBm = ?1 and DATE_FORMAT(s.scheduleDate,'%Y-%m-%d') = ?2 GROUP BY s.jGh,s.clZbh,s.lpName order by (lpName+1)")
24 List<ScheduleRealInfo> queryUserInfo(String line,String date); 24 List<ScheduleRealInfo> queryUserInfo(String line,String date);
25 25
26 @Query(value="select s from ScheduleRealInfo s where s.jName = ?1 and s.clZbh = ?2 and s.lpName = ?3 order by bcs") 26 @Query(value="select s from ScheduleRealInfo s where s.jName = ?1 and s.clZbh = ?2 and s.lpName = ?3 order by bcs")
@@ -29,7 +29,7 @@ public interface ScheduleRealInfoRepository extends BaseRepository&lt;ScheduleRealI @@ -29,7 +29,7 @@ public interface ScheduleRealInfoRepository extends BaseRepository&lt;ScheduleRealI
29 @Query(value="select new map(clZbh as clZbh,jGh as jGh,jName as jName,sum(jhlc) as zgl,sum(addMileage) as ksgl,count(jName) as bcs) from ScheduleRealInfo s where s.xlBm = ?1 and DATE_FORMAT(s.scheduleDate,'%Y-%m-%d') = ?2 group by clZbh,jGh") 29 @Query(value="select new map(clZbh as clZbh,jGh as jGh,jName as jName,sum(jhlc) as zgl,sum(addMileage) as ksgl,count(jName) as bcs) from ScheduleRealInfo s where s.xlBm = ?1 and DATE_FORMAT(s.scheduleDate,'%Y-%m-%d') = ?2 group by clZbh,jGh")
30 List<Map<String, Object>> dailyInfo(String line,String date); 30 List<Map<String, Object>> dailyInfo(String line,String date);
31 31
32 - @Query(value="SELECT r.xl_name,r.lp_name,r.cl_zbh,d.sender,d.timestamp,d.txt_content FROM bsth_c_s_sp_info_real r RIGHT JOIN bsth_v_directive_60 d ON r.id = d.sch WHERE d.is_dispatch = 1 AND r.xl_bm = ?1 AND r.schedule_date = ?2 and r.cl_zbh = ?3",nativeQuery=true) 32 + @Query(value="SELECT r.xl_name,r.lp_name,r.cl_zbh,d.sender,d.timestamp,d.txt_content FROM bsth_c_s_sp_info_real r RIGHT JOIN bsth_v_directive_60 d ON r.id = d.sch WHERE d.is_dispatch = 1 AND r.xl_bm = ?1 AND r.schedule_date = ?2 and r.cl_zbh = ?3 order by d.timestamp",nativeQuery=true)
33 List<Object[]> historyMessage(String line,String date,String code); 33 List<Object[]> historyMessage(String line,String date,String code);
34 34
35 @Query(value = "select max(id) from ScheduleRealInfo") 35 @Query(value = "select max(id) from ScheduleRealInfo")
@@ -54,7 +54,7 @@ public interface ScheduleRealInfoRepository extends BaseRepository&lt;ScheduleRealI @@ -54,7 +54,7 @@ public interface ScheduleRealInfoRepository extends BaseRepository&lt;ScheduleRealI
54 @Query(value="select s from ScheduleRealInfo s where s.xlBm = ?1 and s.scheduleDate >= str_to_date(?2,'%Y-%m-%d') and s.scheduleDate <= str_to_date(?3,'%Y-%m-%d') and s.lpName = ?4 order by s.fcsj") 54 @Query(value="select s from ScheduleRealInfo s where s.xlBm = ?1 and s.scheduleDate >= str_to_date(?2,'%Y-%m-%d') and s.scheduleDate <= str_to_date(?3,'%Y-%m-%d') and s.lpName = ?4 order by s.fcsj")
55 List<ScheduleRealInfo> correctForm(String line,String startDate,String endDate,String lpName); 55 List<ScheduleRealInfo> correctForm(String line,String startDate,String endDate,String lpName);
56 56
57 - @Query(value="select s from ScheduleRealInfo s where s.jName = ?1 and s.clZbh = ?2 and s.lpName = ?3 and s.scheduleDate <= str_to_date(?4,'%Y-%m-%d') order by bcs") 57 + @Query(value="select s from ScheduleRealInfo s where s.jName = ?1 and s.clZbh = ?2 and s.lpName = ?3 and s.scheduleDate = str_to_date(?4,'%Y-%m-%d') order by bcs")
58 List<ScheduleRealInfo> queryListWaybill(String jName,String clZbh,String lpName,String date); 58 List<ScheduleRealInfo> queryListWaybill(String jName,String clZbh,String lpName,String date);
59 59
60 @Query(value="select s from ScheduleRealInfo s where s.xlBm = ?1 and DATE_FORMAT(s.scheduleDate,'%Y-%m-%d') = ?2") 60 @Query(value="select s from ScheduleRealInfo s where s.xlBm = ?1 and DATE_FORMAT(s.scheduleDate,'%Y-%m-%d') = ?2")
@@ -74,4 +74,7 @@ public interface ScheduleRealInfoRepository extends BaseRepository&lt;ScheduleRealI @@ -74,4 +74,7 @@ public interface ScheduleRealInfoRepository extends BaseRepository&lt;ScheduleRealI
74 74
75 @Query(value="select s from ScheduleRealInfo s where s.xlBm = ?1 and DATE_FORMAT(s.scheduleDate,'%Y-%m-%d') = ?2") 75 @Query(value="select s from ScheduleRealInfo s where s.xlBm = ?1 and DATE_FORMAT(s.scheduleDate,'%Y-%m-%d') = ?2")
76 List<ScheduleRealInfo> scheduleByDateAndLine(String line,String date); 76 List<ScheduleRealInfo> scheduleByDateAndLine(String line,String date);
  77 +
  78 + @Query(value="select new map(s.scheduleDate as scheduleDate,s.xlBm as xlBm,s.clZbh as clZbh,s.jGh as jGh) from ScheduleRealInfo s where (s.xlBm = ?1 or s.xlBm is not null) and DATE_FORMAT(s.scheduleDate,'%Y-%m-%d') = ?2 GROUP BY xlBm,clZbh,jGh ORDER BY xlBm,clZbh,realExecDate,fcsjActual")
  79 + List<Map<String,Object>> yesterdayDataList(String line,String date);
77 } 80 }
src/main/java/com/bsth/repository/schedule/CarConfigInfoRepository.java
@@ -42,4 +42,7 @@ public interface CarConfigInfoRepository extends BaseRepository&lt;CarConfigInfo, L @@ -42,4 +42,7 @@ public interface CarConfigInfoRepository extends BaseRepository&lt;CarConfigInfo, L
42 42
43 @Query("select new map(cc.cl.insideCode as nbbm, cc.id as id) from CarConfigInfo cc") 43 @Query("select new map(cc.cl.insideCode as nbbm, cc.id as id) from CarConfigInfo cc")
44 List<Map<String, Object>> findCarConfigCars(); 44 List<Map<String, Object>> findCarConfigCars();
  45 +
  46 + @Query("select new map(cc.cl.id as id, cc.cl.insideCode as insideCode) from CarConfigInfo cc")
  47 + List<Map<String, Object>> findCarsFromConfig();
45 } 48 }
46 \ No newline at end of file 49 \ No newline at end of file
src/main/java/com/bsth/repository/schedule/EmployeeConfigInfoRepository.java
@@ -5,6 +5,7 @@ import com.bsth.entity.schedule.EmployeeConfigInfo; @@ -5,6 +5,7 @@ import com.bsth.entity.schedule.EmployeeConfigInfo;
5 import com.bsth.repository.BaseRepository; 5 import com.bsth.repository.BaseRepository;
6 6
7 import java.util.List; 7 import java.util.List;
  8 +import java.util.Map;
8 9
9 import org.springframework.data.domain.Page; 10 import org.springframework.data.domain.Page;
10 import org.springframework.data.domain.Pageable; 11 import org.springframework.data.domain.Pageable;
@@ -34,4 +35,18 @@ public interface EmployeeConfigInfoRepository extends BaseRepository&lt;EmployeeCon @@ -34,4 +35,18 @@ public interface EmployeeConfigInfoRepository extends BaseRepository&lt;EmployeeCon
34 @EntityGraph(value = "employeeConfigInfo_jsy_spy_xl", type = EntityGraph.EntityGraphType.FETCH) 35 @EntityGraph(value = "employeeConfigInfo_jsy_spy_xl", type = EntityGraph.EntityGraphType.FETCH)
35 @Query("select cc from EmployeeConfigInfo cc where cc.id=?1") 36 @Query("select cc from EmployeeConfigInfo cc where cc.id=?1")
36 EmployeeConfigInfo findOneExtend(Long aLong); 37 EmployeeConfigInfo findOneExtend(Long aLong);
  38 +
  39 + @Query("select new map(" +
  40 + "ec.jsy.id as jsyId, " +
  41 + "ec.jsy.jobCode as jsyGh, " +
  42 + "ec.jsy.personnelName as jsyName) " +
  43 + "from EmployeeConfigInfo ec ")
  44 + List<Map<String, Object>> findJsyFromConfig();
  45 +
  46 + @Query("select new map(" +
  47 + "ec.spy.id as spyId, " +
  48 + "ec.spy.jobCode as spyGh, " +
  49 + "ec.spy.personnelName as spyName) " +
  50 + "from EmployeeConfigInfo ec ")
  51 + List<Map<String, Object>> findSpyFromConfig();
37 } 52 }
src/main/java/com/bsth/repository/schedule/SchedulePlanInfoRepository.java
@@ -9,7 +9,9 @@ import java.util.List; @@ -9,7 +9,9 @@ import java.util.List;
9 import org.springframework.data.domain.Page; 9 import org.springframework.data.domain.Page;
10 import org.springframework.data.domain.Pageable; 10 import org.springframework.data.domain.Pageable;
11 import org.springframework.data.jpa.domain.Specification; 11 import org.springframework.data.jpa.domain.Specification;
  12 +import org.springframework.data.jpa.repository.Modifying;
12 import org.springframework.data.jpa.repository.Query; 13 import org.springframework.data.jpa.repository.Query;
  14 +import org.springframework.data.repository.query.Param;
13 import org.springframework.stereotype.Repository; 15 import org.springframework.stereotype.Repository;
14 16
15 /** 17 /**
@@ -23,4 +25,97 @@ public interface SchedulePlanInfoRepository extends BaseRepository&lt;SchedulePlanI @@ -23,4 +25,97 @@ public interface SchedulePlanInfoRepository extends BaseRepository&lt;SchedulePlanI
23 25
24 Long deleteByXlAndScheduleDateGreaterThanEqualAndScheduleDateLessThanEqual(Integer xlid, Date startDate, Date endDate); 26 Long deleteByXlAndScheduleDateGreaterThanEqualAndScheduleDateLessThanEqual(Integer xlid, Date startDate, Date endDate);
25 27
  28 +
  29 + @Query(value = " select " +
  30 + "xl as xlId, " +
  31 + "xl_name as xlName, " +
  32 + "schedule_date as scheduleDate, " +
  33 + "lp_name as lpName, " +
  34 + "cl as clId, " +
  35 + "cl_zbh as clZbh, " +
  36 + "group_concat(distinct fcsj) ccsj, " +
  37 + "group_concat(distinct j) jsyId, " +
  38 + "group_concat(distinct j_gh) jsyGh, " +
  39 + "group_concat(distinct j_name) jsyName, " +
  40 + "group_concat(distinct s) spyId, " +
  41 + "group_concat(distinct s_gh) spyGh, " +
  42 + "group_concat(distinct s_name) spyName, " +
  43 + "max(create_date) as createDate " +
  44 + "from bsth_c_s_sp_info " +
  45 + "where bc_type = 'out' and " +
  46 + "xl = ?1 and " +
  47 + "schedule_date = ?2 " +
  48 + "group by xl_name, schedule_date, lp_name " +
  49 + "order by xl_name, schedule_date, lp ", nativeQuery = true)
  50 + List<Object[]> findGroupInfo(Integer xlid, Date scheduleDate);
  51 +
  52 + @Modifying
  53 + @Query(value = "update " +
  54 + "SchedulePlanInfo scpinfo " +
  55 + "set scpinfo.cl = :p1, scpinfo.clZbh = :p2 " +
  56 + "where scpinfo.xl = :p3 and " +
  57 + "scpinfo.scheduleDate = :p4 and " +
  58 + "scpinfo.lpName = :p5 ")
  59 + int updateGroupInfo_type_1(
  60 + @Param("p1") Integer clid,
  61 + @Param("p2") String clZbh,
  62 + @Param("p3") Integer xlid,
  63 + @Param("p4") Date scheduleDate,
  64 + @Param("p5") String lpName);
  65 +
  66 + @Modifying
  67 + @Query(value = "update " +
  68 + "SchedulePlanInfo scpinfo " +
  69 + "set scpinfo.fcsj = :p1 " +
  70 + "where scpinfo.xl = :p2 and " +
  71 + "scpinfo.scheduleDate = :p3 and " +
  72 + "scpinfo.lpName = :p4 and " +
  73 + "scpinfo.fcsj = :p5 and " +
  74 + "scpinfo.bcType = :p6 ")
  75 + int updateGroupInfo_type_2_4(
  76 + @Param("p1") String fcsj,
  77 + @Param("p2") Integer xlid,
  78 + @Param("p3") Date scheduleDate,
  79 + @Param("p4") String lpName,
  80 + @Param("p5") String fcsj_src,
  81 + @Param("p6") String bcType);
  82 +
  83 + @Modifying
  84 + @Query(value = "update " +
  85 + "SchedulePlanInfo scpinfo " +
  86 + "set scpinfo.j = :p1, " +
  87 + "scpinfo.jGh = :p2, " +
  88 + "scpinfo.jName = :p3 " +
  89 + "where scpinfo.xl = :p4 and " +
  90 + "scpinfo.scheduleDate = :p5 and " +
  91 + "scpinfo.lpName = :p6 and " +
  92 + "scpinfo.j = :p7 ")
  93 + int updateGroupInfo_type_3_5_jsy(
  94 + @Param("p1") Integer jsyId,
  95 + @Param("p2") String jsyGh,
  96 + @Param("p3") String jsyName,
  97 + @Param("p4") Integer xlId,
  98 + @Param("p5") Date scheduleDate,
  99 + @Param("p6") String lpName,
  100 + @Param("p7") Integer jsyId_src);
  101 +
  102 + @Modifying
  103 + @Query(value = "update " +
  104 + "SchedulePlanInfo scpinfo " +
  105 + "set scpinfo.s = :p1, " +
  106 + "scpinfo.sGh = :p2, " +
  107 + "scpinfo.sName = :p3 " +
  108 + "where scpinfo.xl = :p4 and " +
  109 + "scpinfo.scheduleDate = :p5 and " +
  110 + "scpinfo.lpName = :p6 and " +
  111 + "scpinfo.s = :p7 ")
  112 + int updateGroupInfo_type_3_5_spy(
  113 + @Param("p1") Integer spyId,
  114 + @Param("p2") String spyGh,
  115 + @Param("p3") String spyName,
  116 + @Param("p4") Integer xlId,
  117 + @Param("p5") Date scheduleDate,
  118 + @Param("p6") String lpName,
  119 + @Param("p7") Integer spyId_src);
  120 +
26 } 121 }
src/main/java/com/bsth/repository/schedule/SchedulePlanRepository.java
@@ -6,15 +6,8 @@ import org.springframework.data.domain.Page; @@ -6,15 +6,8 @@ import org.springframework.data.domain.Page;
6 import org.springframework.data.domain.Pageable; 6 import org.springframework.data.domain.Pageable;
7 import org.springframework.data.jpa.domain.Specification; 7 import org.springframework.data.jpa.domain.Specification;
8 import org.springframework.data.jpa.repository.EntityGraph; 8 import org.springframework.data.jpa.repository.EntityGraph;
9 -import org.springframework.data.jpa.repository.Query;  
10 -import org.springframework.data.repository.query.Param;  
11 import org.springframework.stereotype.Repository; 9 import org.springframework.stereotype.Repository;
12 10
13 -import javax.persistence.SqlResultSetMapping;  
14 -import java.util.Date;  
15 -import java.util.List;  
16 -import java.util.Map;  
17 -  
18 /** 11 /**
19 * Created by xu on 16/6/16. 12 * Created by xu on 16/6/16.
20 */ 13 */
@@ -24,37 +17,4 @@ public interface SchedulePlanRepository extends BaseRepository&lt;SchedulePlan, Lon @@ -24,37 +17,4 @@ public interface SchedulePlanRepository extends BaseRepository&lt;SchedulePlan, Lon
24 @Override 17 @Override
25 Page<SchedulePlan> findAll(Specification<SchedulePlan> spec, Pageable pageable); 18 Page<SchedulePlan> findAll(Specification<SchedulePlan> spec, Pageable pageable);
26 19
27 - @Query(value = " select " +  
28 - "xl_name as xlName, " +  
29 - "schedule_date as scheduleDate, " +  
30 - "lp_name as lpName, " +  
31 - "cl_zbh as clZbh, " +  
32 - "group_concat(distinct fcsj) ccsj, " +  
33 - "group_concat(distinct j_gh) jsyGh, " +  
34 - "group_concat(distinct j_name) jsyName, " +  
35 - "group_concat(distinct s_gh) spyGh, " +  
36 - "group_concat(distinct s_name) spyName, " +  
37 - "max(create_date) as createDate " +  
38 - "from bsth_c_s_sp_info " +  
39 - "where bc_type = 'out' and " +  
40 - "xl = ?1 and " +  
41 - "schedule_date = ?2 " +  
42 - "group by xl_name, schedule_date, lp_name " +  
43 - "order by xl_name, schedule_date, lp ", nativeQuery = true)  
44 - List<Object[]> findGroupInfo(Integer xlid, Date scheduleDate);  
45 -  
46 - @Query(value = "update " +  
47 - "bsth_c_s_sp_info " +  
48 - "set cl = :p1, cl_zbh = :p2 " +  
49 - "where xl = :p3 and " +  
50 - "schedule_date = :p4 and " +  
51 - "lp_name = :p5 ",  
52 - nativeQuery = true)  
53 - int updateGroupInfo_clinfo(  
54 - @Param("p1") Integer clid,  
55 - @Param("p2") String clZbh,  
56 - @Param("p3") Integer xlid,  
57 - @Param("p4") Date scheduleDate,  
58 - @Param("p5") String lpName);  
59 -  
60 } 20 }
src/main/java/com/bsth/security/WebSecurityConfig.java
@@ -13,12 +13,10 @@ import org.springframework.security.core.session.SessionRegistry; @@ -13,12 +13,10 @@ import org.springframework.security.core.session.SessionRegistry;
13 import org.springframework.security.core.session.SessionRegistryImpl; 13 import org.springframework.security.core.session.SessionRegistryImpl;
14 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 14 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
15 import org.springframework.security.web.access.intercept.FilterSecurityInterceptor; 15 import org.springframework.security.web.access.intercept.FilterSecurityInterceptor;
16 -import org.springframework.security.web.authentication.logout.LogoutHandler;  
17 import org.springframework.security.web.session.HttpSessionEventPublisher; 16 import org.springframework.security.web.session.HttpSessionEventPublisher;
18 17
19 import com.bsth.common.Constants; 18 import com.bsth.common.Constants;
20 import com.bsth.security.filter.LoginInterceptor; 19 import com.bsth.security.filter.LoginInterceptor;
21 -import com.bsth.security.handler.CustomLogoutHandler;  
22 20
23 @Configuration 21 @Configuration
24 @EnableWebSecurity 22 @EnableWebSecurity
@@ -59,7 +57,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @@ -59,7 +57,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
59 //.failureUrl(Constants.LOGIN_PAGE + "?error=true")登录失败跳转的链接 57 //.failureUrl(Constants.LOGIN_PAGE + "?error=true")登录失败跳转的链接
60 //.successHandler(loginSuccessHandler())登录成功后处理 58 //.successHandler(loginSuccessHandler())登录成功后处理
61 .and().logout() 59 .and().logout()
62 - .addLogoutHandler(logoutHandler()) 60 + //.addLogoutHandler(logoutHandler())
63 //禁用CXRF 61 //禁用CXRF
64 .and().csrf().disable() 62 .and().csrf().disable()
65 //禁用匿名用户功能 63 //禁用匿名用户功能
@@ -92,10 +90,10 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @@ -92,10 +90,10 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
92 return new LoginSuccessHandler(); 90 return new LoginSuccessHandler();
93 }*/ 91 }*/
94 92
95 - @Bean 93 +/* @Bean
96 public LogoutHandler logoutHandler(){ 94 public LogoutHandler logoutHandler(){
97 return new CustomLogoutHandler(); 95 return new CustomLogoutHandler();
98 - } 96 + }*/
99 97
100 @Bean 98 @Bean
101 public SessionRegistry sessionRegistry() { 99 public SessionRegistry sessionRegistry() {
src/main/java/com/bsth/security/handler/CustomLogoutHandler.java
1 -package com.bsth.security.handler;  
2 -  
3 -import javax.servlet.http.HttpServletRequest;  
4 -import javax.servlet.http.HttpServletResponse;  
5 -  
6 -import org.springframework.security.core.Authentication;  
7 -import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;  
8 -  
9 -import com.bsth.entity.sys.SysUser;  
10 -  
11 -public class CustomLogoutHandler extends SecurityContextLogoutHandler{  
12 -  
13 - @Override  
14 - public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {  
15 - SysUser user = (SysUser) authentication.getPrincipal();  
16 - System.out.println(user.getName() + "注销...");  
17 - //日志记录  
18 -  
19 - super.logout(request, response, authentication);  
20 - }  
21 -} 1 +//package com.bsth.security.handler;
  2 +//
  3 +//import javax.servlet.http.HttpServletRequest;
  4 +//import javax.servlet.http.HttpServletResponse;
  5 +//
  6 +//import org.springframework.security.core.Authentication;
  7 +//import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
  8 +//
  9 +//import com.bsth.entity.sys.SysUser;
  10 +//
  11 +//public class CustomLogoutHandler extends SecurityContextLogoutHandler{
  12 +//
  13 +// @Override
  14 +// public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
  15 +// SysUser user = (SysUser) authentication.getPrincipal();
  16 +// System.out.println(user.getName() + "注销...");
  17 +// //日志记录
  18 +//
  19 +// super.logout(request, response, authentication);
  20 +// }
  21 +//}
src/main/java/com/bsth/service/StationRouteService.java
@@ -78,4 +78,6 @@ public interface StationRouteService extends BaseService&lt;StationRoute, Integer&gt; @@ -78,4 +78,6 @@ public interface StationRouteService extends BaseService&lt;StationRoute, Integer&gt;
78 * @return List<Map<String, Object>> 78 * @return List<Map<String, Object>>
79 */ 79 */
80 List<Map<String, Object>> findStationRouteInfo(Map<String, Object> map); 80 List<Map<String, Object>> findStationRouteInfo(Map<String, Object> map);
  81 +
  82 + Map<String, Object> findByMultiLine(String lineIds);
81 } 83 }
src/main/java/com/bsth/service/TrafficManageService.java 0 → 100644
  1 +package com.bsth.service;
  2 +
  3 +import com.bsth.entity.Line;
  4 +
  5 +/**
  6 + *
  7 + * @Interface: LineService(线路service业务层实现接口)
  8 + *
  9 + * @extends : BaseService
  10 + *
  11 + * @Description: TODO(线路service业务层实现接口)
  12 + *
  13 + * @Author bsth@lq
  14 + *
  15 + * @Date 2016年4月28日 上午9:21:17
  16 + *
  17 + * @Version 公交调度系统BS版 0.1
  18 + *
  19 + */
  20 +public interface TrafficManageService {
  21 +
  22 + /**
  23 + * 获取线路编码
  24 + *
  25 + * @return long <lineCode:线路编码>
  26 + */
  27 + String setXL();
  28 +
  29 +}
src/main/java/com/bsth/service/directive/DirectiveService.java
@@ -53,7 +53,7 @@ public interface DirectiveService extends BaseService&lt;D60, Integer&gt;{ @@ -53,7 +53,7 @@ public interface DirectiveService extends BaseService&lt;D60, Integer&gt;{
53 * @param @param lineId 新线路编码 53 * @param @param lineId 新线路编码
54 * @throws 54 * @throws
55 */ 55 */
56 - int lineChange(String nbbm, Integer lineId, String sender); 56 + int lineChange(String nbbm, String lineId, String sender);
57 57
58 /** 58 /**
59 * 59 *
src/main/java/com/bsth/service/directive/DirectiveServiceImpl.java
@@ -38,7 +38,6 @@ import com.bsth.repository.directive.D64Repository; @@ -38,7 +38,6 @@ import com.bsth.repository.directive.D64Repository;
38 import com.bsth.repository.directive.D80Repository; 38 import com.bsth.repository.directive.D80Repository;
39 import com.bsth.security.util.SecurityUtils; 39 import com.bsth.security.util.SecurityUtils;
40 import com.bsth.service.impl.BaseServiceImpl; 40 import com.bsth.service.impl.BaseServiceImpl;
41 -import com.bsth.util.DateUtils;  
42 import com.bsth.websocket.handler.RealControlSocketHandler; 41 import com.bsth.websocket.handler.RealControlSocketHandler;
43 import com.fasterxml.jackson.core.JsonProcessingException; 42 import com.fasterxml.jackson.core.JsonProcessingException;
44 import com.fasterxml.jackson.databind.ObjectMapper; 43 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -119,7 +118,7 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;D60, Integer&gt; implemen @@ -119,7 +118,7 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;D60, Integer&gt; implemen
119 118
120 //下发0x02指令 调度指令(闹钟有效) 119 //下发0x02指令 调度指令(闹钟有效)
121 Long alarmTime = System.currentTimeMillis() + 1000 * 30; 120 Long alarmTime = System.currentTimeMillis() + 1000 * 30;
122 - d60 = DirectiveCreator.createD60_02(sch.getClZbh(), text, Integer.parseInt(sch.getXlDir()) 121 + d60 = new DirectiveCreator().createD60_02(sch.getClZbh(), text, Integer.parseInt(sch.getXlDir())
123 , 0, new Date(alarmTime)); 122 , 0, new Date(alarmTime));
124 } catch (Exception e) { 123 } catch (Exception e) {
125 logger.error("生成调度指令时出现异常", e); 124 logger.error("生成调度指令时出现异常", e);
@@ -193,7 +192,7 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;D60, Integer&gt; implemen @@ -193,7 +192,7 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;D60, Integer&gt; implemen
193 logger.info("切换运营状态, nbbm: " + nbbm + " ,state: " + state + " ,upDown:" + upDown); 192 logger.info("切换运营状态, nbbm: " + nbbm + " ,state: " + state + " ,upDown:" + upDown);
194 193
195 String text = "切换为 " + (upDown == 0 ? "上行" : "下行") + (state == 0 ? "营运" : "未营运"); 194 String text = "切换为 " + (upDown == 0 ? "上行" : "下行") + (state == 0 ? "营运" : "未营运");
196 - D60 d60 = DirectiveCreator.createD60(nbbm, text, (short) 0x03, upDown, state); 195 + D60 d60 = new DirectiveCreator().createD60(nbbm, text, (short) 0x03, upDown, state);
197 196
198 if (null == d60) 197 if (null == d60)
199 return -1; 198 return -1;
@@ -220,10 +219,12 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;D60, Integer&gt; implemen @@ -220,10 +219,12 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;D60, Integer&gt; implemen
220 * 线路切换 219 * 线路切换
221 */ 220 */
222 @Override 221 @Override
223 - public int lineChange(String nbbm, Integer lineCode, String sender) { 222 + public int lineChange(String nbbm, String lineCode, String sender) {
  223 + DirectiveCreator crt = new DirectiveCreator();
  224 +
224 Long t = System.currentTimeMillis(); 225 Long t = System.currentTimeMillis();
225 //生成64数据包 226 //生成64数据包
226 - D64 d64 = DirectiveCreator.createD64(nbbm, lineCode, t); 227 + D64 d64 = crt.createD64(nbbm, lineCode, t);
227 228
228 if(null != sender) 229 if(null != sender)
229 d64.setSender(sender); 230 d64.setSender(sender);
@@ -234,13 +235,14 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;D60, Integer&gt; implemen @@ -234,13 +235,14 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;D60, Integer&gt; implemen
234 int code = GatewayHttpUtils.postJson(JSON.toJSONString(d64)); 235 int code = GatewayHttpUtils.postJson(JSON.toJSONString(d64));
235 // 入库 236 // 入库
236 d64.setHttpCode(code); 237 d64.setHttpCode(code);
  238 + d64.getData().setTxtContent("切换线路[" + lineCode + "]");
237 dayOfDirectives.put64(d64); 239 dayOfDirectives.put64(d64);
238 240
239 // 通知设备刷新线路文件,忽略结果 241 // 通知设备刷新线路文件,忽略结果
240 if (code == 0) 242 if (code == 0)
241 - GatewayHttpUtils.postJson(DirectiveCreator.createDeviceRefreshData(deviceId, lineCode)); 243 + GatewayHttpUtils.postJson(crt.createDeviceRefreshData(deviceId, lineCode));
242 else 244 else
243 - d64.setErrorText("[刷新线路文件] 网关通讯失败, code: " + code); 245 + d64.setErrorText(" 网关通讯失败, code: " + code);
244 246
245 d64Repository.save(d64); 247 d64Repository.save(d64);
246 return code; 248 return code;
@@ -278,7 +280,7 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;D60, Integer&gt; implemen @@ -278,7 +280,7 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;D60, Integer&gt; implemen
278 state = 0; 280 state = 0;
279 } 281 }
280 282
281 - return DirectiveCreator.createD60(nbbm, text, dispatchInstruct, upDown, state); 283 + return new DirectiveCreator().createD60(nbbm, text, dispatchInstruct, upDown, state);
282 } 284 }
283 285
284 @Override 286 @Override
@@ -397,16 +399,17 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;D60, Integer&gt; implemen @@ -397,16 +399,17 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;D60, Integer&gt; implemen
397 399
398 List<Directive> rs = list.subList(s, e); 400 List<Directive> rs = list.subList(s, e);
399 401
  402 + SimpleDateFormat sdfHHmm = new SimpleDateFormat("HH:mm");
400 // 时间格式化,车辆自编号转换 403 // 时间格式化,车辆自编号转换
401 for (Directive d : rs) { 404 for (Directive d : rs) {
402 if (d.getTimeHHmm() == null) 405 if (d.getTimeHHmm() == null)
403 - d.setTimeHHmm(DateUtils.sdfHHmm.format(new Date(d.getTimestamp()))); 406 + d.setTimeHHmm(sdfHHmm.format(new Date(d.getTimestamp())));
404 if (d.getNbbm() == null) 407 if (d.getNbbm() == null)
405 d.setNbbm(BasicData.deviceId2NbbmMap.get(d.getDeviceId())); 408 d.setNbbm(BasicData.deviceId2NbbmMap.get(d.getDeviceId()));
406 } 409 }
407 410
408 rsMap.put("list", rs); 411 rsMap.put("list", rs);
409 - rsMap.put("totalPages", count % size == 0 ? count / size : count / size + 1); 412 + rsMap.put("totalPages", count % size == 0 ? (count / size - 1) : count / size);
410 rsMap.put("page", page); 413 rsMap.put("page", page);
411 return rsMap; 414 return rsMap;
412 } 415 }
@@ -449,9 +452,10 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;D60, Integer&gt; implemen @@ -449,9 +452,10 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;D60, Integer&gt; implemen
449 if (e > count) 452 if (e > count)
450 e = count; 453 e = count;
451 454
  455 + SimpleDateFormat sdfHHmm = new SimpleDateFormat("HH:mm");
452 List<D80> rs = d80s.subList(s, e); 456 List<D80> rs = d80s.subList(s, e);
453 for(D80 d80 : rs){ 457 for(D80 d80 : rs){
454 - d80.setTimeStr(DateUtils.sdfHHmm.format(new Date(d80.getTimestamp()))); 458 + d80.setTimeStr(sdfHHmm.format(new Date(d80.getTimestamp())));
455 } 459 }
456 460
457 Map<String, Object> rsMap = new HashMap<>(); 461 Map<String, Object> rsMap = new HashMap<>();
src/main/java/com/bsth/service/forecast/SampleService.java
1 package com.bsth.service.forecast; 1 package com.bsth.service.forecast;
2 2
  3 +import java.util.Map;
  4 +
  5 +import com.bsth.controller.forecast.dto.CreateSampleParam;
3 import com.bsth.entity.forecast.Sample; 6 import com.bsth.entity.forecast.Sample;
4 import com.bsth.service.BaseService; 7 import com.bsth.service.BaseService;
5 8
6 public interface SampleService extends BaseService<Sample, Long>{ 9 public interface SampleService extends BaseService<Sample, Long>{
7 10
8 - int createDataByGps(String lineCode, Integer updown); 11 + Map<String, Object> createDataByGps(CreateSampleParam param);
9 12
10 } 13 }
src/main/java/com/bsth/service/forecast/SampleServiceImpl.java
1 package com.bsth.service.forecast; 1 package com.bsth.service.forecast;
2 2
  3 +import java.text.SimpleDateFormat;
  4 +import java.util.ArrayList;
  5 +import java.util.Collections;
  6 +import java.util.Comparator;
  7 +import java.util.HashMap;
3 import java.util.Iterator; 8 import java.util.Iterator;
  9 +import java.util.List;
4 import java.util.Map; 10 import java.util.Map;
5 11
6 import javax.transaction.Transactional; 12 import javax.transaction.Transactional;
7 13
  14 +import org.slf4j.Logger;
  15 +import org.slf4j.LoggerFactory;
8 import org.springframework.beans.factory.annotation.Autowired; 16 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.stereotype.Service; 17 import org.springframework.stereotype.Service;
10 18
  19 +import com.bsth.common.ResponseCode;
  20 +import com.bsth.controller.forecast.dto.CreateSampleParam;
11 import com.bsth.data.BasicData; 21 import com.bsth.data.BasicData;
  22 +import com.bsth.data.arrival.ArrivalEntity;
  23 +import com.bsth.data.arrival.DataLoader;
12 import com.bsth.entity.forecast.Sample; 24 import com.bsth.entity.forecast.Sample;
13 import com.bsth.repository.forecast.SampleRepository; 25 import com.bsth.repository.forecast.SampleRepository;
  26 +import com.bsth.service.forecast.util.CreateByArrivalData;
14 import com.bsth.service.impl.BaseServiceImpl; 27 import com.bsth.service.impl.BaseServiceImpl;
15 28
16 @Service 29 @Service
@@ -19,10 +32,16 @@ public class SampleServiceImpl extends BaseServiceImpl&lt;Sample, Long&gt; implements @@ -19,10 +32,16 @@ public class SampleServiceImpl extends BaseServiceImpl&lt;Sample, Long&gt; implements
19 @Autowired 32 @Autowired
20 SampleRepository sampleRepository; 33 SampleRepository sampleRepository;
21 34
  35 + @Autowired
  36 + CreateByArrivalData createByArrivalData;
  37 +
  38 + Logger logger = LoggerFactory.getLogger(this.getClass());
  39 +
22 @Override 40 @Override
23 public Iterable<Sample> list(Map<String, Object> map) { 41 public Iterable<Sample> list(Map<String, Object> map) {
24 Iterable<Sample> rs = super.list(map); 42 Iterable<Sample> rs = super.list(map);
25 43
  44 + List<Sample> rsList = new ArrayList<>();
26 //转换站点名称 45 //转换站点名称
27 Iterator<Sample> iterator = rs.iterator(); 46 Iterator<Sample> iterator = rs.iterator();
28 Sample s; 47 Sample s;
@@ -30,16 +49,63 @@ public class SampleServiceImpl extends BaseServiceImpl&lt;Sample, Long&gt; implements @@ -30,16 +49,63 @@ public class SampleServiceImpl extends BaseServiceImpl&lt;Sample, Long&gt; implements
30 s = iterator.next(); 49 s = iterator.next();
31 s.setsName(BasicData.stationCode2NameMap.get(s.getsStation())); 50 s.setsName(BasicData.stationCode2NameMap.get(s.getsStation()));
32 s.seteName(BasicData.stationCode2NameMap.get(s.geteStation())); 51 s.seteName(BasicData.stationCode2NameMap.get(s.geteStation()));
  52 +
  53 + rsList.add(s);
33 } 54 }
34 - return rs; 55 +
  56 + //排序
  57 + Collections.sort(rsList, new Comparator<Sample>() {
  58 + @Override
  59 + public int compare(Sample arg0, Sample arg1) {
  60 + return arg0.geteDate().compareTo(arg1.geteDate());
  61 + }
  62 + });
  63 +
  64 + return rsList;
  65 + }
  66 +
  67 + @Override
  68 + public Map<String, Object> save(Sample t) {
  69 + if(null == t.getId())
  70 + t.setTag(t.getTag() + t.getsDate() + " - " + t.geteDate());
  71 + return super.save(t);
35 } 72 }
36 73
37 @Transactional 74 @Transactional
38 @Override 75 @Override
39 - public int createDataByGps(String lineCode, Integer updown) {  
40 - //删除原有数据  
41 - sampleRepository.deleteByLineAndUpdown(Integer.parseInt(lineCode), updown); 76 + public Map<String, Object> createDataByGps(CreateSampleParam param) {
  77 + Map<String, Object> rs = new HashMap<>();
  78 + try{
  79 + //删除原有数据
  80 + sampleRepository.deleteByLineAndUpdown(param.getLineCode(), param.getUpdown());
  81 +
  82 + //查询到离站数据
  83 + DataLoader loader = new DataLoader();
  84 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  85 +
  86 + long st = sdf.parse(param.getStartDate()).getTime()
  87 + ,et = sdf.parse(param.getEndDate()).getTime()
  88 + ,i = st
  89 + ,range = 1000 * 60 * 60 * 24;
  90 +
  91 + logger.info("初始值:" + 1500 * (int)((et - st) / range));
  92 + List<ArrivalEntity> all = new ArrayList<>(1500 * (int)((et - st) / range));
  93 + for(; i < et; i += range)
  94 + all.addAll(loader.loadByLineAndTime(param.getLineCode(), param.getUpdown() , i, i + range));
  95 +
  96 + logger.info("实际数据量:" + all.size());
  97 +
  98 + List<Sample> resList = createByArrivalData.create(all, param);
  99 +
  100 + //入库
  101 + sampleRepository.save(resList);
  102 +
  103 + rs.put("status", ResponseCode.SUCCESS);
  104 + }catch(Exception e){
  105 + logger.error("" , e);
  106 + rs.put("status", ResponseCode.ERROR);
  107 + }
42 108
43 - return 0; 109 + return rs;
44 } 110 }
45 } 111 }
src/main/java/com/bsth/service/forecast/util/CreateByArrivalData.java 0 → 100644
  1 +package com.bsth.service.forecast.util;
  2 +
  3 +import java.text.DecimalFormat;
  4 +import java.text.ParseException;
  5 +import java.text.SimpleDateFormat;
  6 +import java.util.ArrayList;
  7 +import java.util.Collections;
  8 +import java.util.Comparator;
  9 +import java.util.Date;
  10 +import java.util.HashMap;
  11 +import java.util.List;
  12 +import java.util.Map;
  13 +import java.util.Set;
  14 +
  15 +import org.slf4j.Logger;
  16 +import org.slf4j.LoggerFactory;
  17 +import org.springframework.beans.factory.annotation.Autowired;
  18 +import org.springframework.context.annotation.Scope;
  19 +import org.springframework.stereotype.Component;
  20 +
  21 +import com.bsth.controller.forecast.dto.CreateSampleParam;
  22 +import com.bsth.controller.forecast.dto.CreateSampleParam.TimeRange;
  23 +import com.bsth.data.arrival.ArrivalComparator;
  24 +import com.bsth.data.arrival.ArrivalEntity;
  25 +import com.bsth.entity.StationRoute;
  26 +import com.bsth.entity.forecast.Sample;
  27 +import com.bsth.repository.StationRouteRepository;
  28 +import com.google.common.collect.ArrayListMultimap;
  29 +
  30 +/**
  31 + *
  32 + * @ClassName: CreateByArrivalData
  33 + * @Description: TODO(根据到离站数据生成线路站点间耗时)
  34 + * @author PanZhao
  35 + * @date 2016年9月17日 下午2:33:20
  36 + *
  37 + */
  38 +@Component
  39 +@Scope("prototype")
  40 +public class CreateByArrivalData {
  41 +
  42 + @Autowired
  43 + StationRouteRepository routeRepository;
  44 +
  45 + SimpleDateFormat sdfyyyyMMdd = new SimpleDateFormat("yyyy-MM-dd")
  46 + ,sdfHHmm = new SimpleDateFormat("HH:mm")
  47 + ,sdfyyyyMMddHHmm = new SimpleDateFormat("yyyy-MM-ddHH:mm");
  48 +
  49 + String rq = sdfyyyyMMdd.format(new Date());
  50 +
  51 + Logger logger = LoggerFactory.getLogger(this.getClass());
  52 +
  53 + /**
  54 + *
  55 + * @Title: create
  56 + * @Description: TODO(到离站数据 生成站点耗时)
  57 + * @throws
  58 + */
  59 + public List<Sample> create(List<ArrivalEntity> all, CreateSampleParam param) {
  60 + List<Sample> rs = new ArrayList<>();
  61 + try{
  62 + //路由
  63 + List<StationRoute> routes = routeRepository.findByLine(param.getLineCode(), param.getUpdown());
  64 + //按顺序索引路由
  65 + Map<String, Integer> rMap = new HashMap<>();
  66 + for(int i = 0; i < routes.size(); i ++){
  67 + //起点站不要
  68 + if(routes.get(i).getStationMark().equals("B"))
  69 + continue;
  70 + rMap.put(routes.get(i).getStationCode(), i);
  71 + }
  72 +
  73 + Collections.sort(all, new ArrivalComparator());
  74 +
  75 + //所有的站点耗时数据
  76 + List<Sample> sampleList = calcTimeArray(rMap, all);
  77 + //时区分组,取值
  78 + Set<TimeRange> rgs = param.getTimeRange();
  79 +
  80 + //生成数据
  81 + for(TimeRange rg : rgs)
  82 + rs.addAll(calcCenterVal(sampleList, rg, param.getUpdown()));
  83 + }catch(Exception e){
  84 + logger.error("", e);
  85 + }
  86 +
  87 + return rs;
  88 + }
  89 +
  90 + private List<Sample> calcTimeArray(Map<String, Integer> rMap, List<ArrivalEntity> arrs) throws ParseException {
  91 +
  92 + //车辆和所在站点对照
  93 + Map<String, ArrivalEntity> carMap = new HashMap<>();
  94 +
  95 + int size = arrs.size();
  96 + ArrivalEntity curr, old;
  97 + String device;
  98 +
  99 + List<Sample> sampleList = new ArrayList<>();
  100 + Sample sample;
  101 + for(int i = 0; i < size; i ++){
  102 + curr = arrs.get(i);
  103 + device = curr.getDeviceId();
  104 + old = carMap.get(device);
  105 +
  106 + carMap.put(device, curr);
  107 +
  108 + if(null == old || null == rMap.get(curr.getStopNo())
  109 + || null == rMap.get(old.getStopNo())
  110 + //跨天的数据不要
  111 + || !sdfyyyyMMdd.format(new Date(old.getTs())).equals(sdfyyyyMMdd.format(new Date(curr.getTs()))))
  112 + continue;
  113 +
  114 + //连续站点
  115 + if(rMap.get(curr.getStopNo())
  116 + - rMap.get(old.getStopNo()) == 1){
  117 +
  118 + sample = new Sample(old, curr);
  119 + //将日期全部拉到同一天
  120 + sample.setLineCode(old.getLineCode());
  121 + sample.setsTime(sdfyyyyMMddHHmm.parse(rq + sdfHHmm.format(sample.getsTime())).getTime());
  122 + sample.seteTime(sdfyyyyMMddHHmm.parse(rq + sdfHHmm.format(sample.geteTime())).getTime());
  123 + //sample.setsDate(sdfHHmm.format(new Date(sample.getsTime())));
  124 + //sample.seteDate(sdfHHmm.format(new Date(sample.geteTime())));
  125 + sampleList.add(sample);
  126 +
  127 + }
  128 + carMap.put(device, curr);
  129 + }
  130 + return sampleList;
  131 + }
  132 +
  133 +
  134 + private List<Sample> calcCenterVal(List<Sample> all, TimeRange rg, Integer updown){
  135 + List<Sample> subList = new ArrayList<>()
  136 + ,rsList = new ArrayList<>();
  137 +
  138 + try{
  139 + Collections.sort(all, new SampleComp2());
  140 + //按时区分组数据
  141 + long st = sdfyyyyMMddHHmm.parse(rq + rg.getS()).getTime()
  142 + ,et = sdfyyyyMMddHHmm.parse(rq + rg.getE()).getTime();
  143 + for(Sample s : all){
  144 + if(s.geteTime() > st && s.geteTime() < et)
  145 + subList.add(s);
  146 + else if(s.geteTime() > et)
  147 + break;
  148 + }
  149 +
  150 + //按站点分组数据
  151 + ArrayListMultimap<String, Sample> arrMap = ArrayListMultimap.create();
  152 + for(Sample s : subList)
  153 + arrMap.put(s.getsStation() + "_" + s.geteStation(), s);
  154 +
  155 + //每个站点间取出一个占比最大的数值
  156 + Set<String> keys = arrMap.keySet();
  157 + Sample sample;
  158 + for(String k : keys){
  159 + sample = maxRatioVal(arrMap.get(k));
  160 +
  161 + sample.setTag(rg.getTag() + rg.getS() + " - " + rg.getE());
  162 + sample.setsDate(rg.getS());
  163 + sample.seteDate(rg.getE());
  164 + sample.setUpdown(updown);
  165 + rsList.add(sample);
  166 + }
  167 +
  168 + }catch(Exception e){
  169 + logger.error("", e);
  170 + }
  171 + return rsList;
  172 + }
  173 +
  174 + /**
  175 + *
  176 + * @Title: maxRatioVal
  177 + * @Description: TODO(从一组数值中取出占比最大的值)
  178 + */
  179 + public Sample maxRatioVal(List<Sample> list){
  180 + //StringBuilder valStr = new StringBuilder();
  181 + if(list.size() == 0)
  182 + return null;
  183 + //排序
  184 + Collections.sort(list, new SampleComp());
  185 +
  186 + ArrayListMultimap<String, Sample> arrMap = ArrayListMultimap.create();
  187 + //1.5分钟范围分组
  188 + int range = 15
  189 + ,curr = (int)(list.get(0).getRunTime() * 10);
  190 +
  191 + for(Sample s : list){
  192 + if(s.getRunTime() * 10 > curr + range){
  193 + curr += range;
  194 + }
  195 + arrMap.put(curr + "_" + curr + range, s);
  196 + //valStr.append(s.getRunTime() + ",");
  197 + }
  198 +
  199 + //数值最多的分组,求个平均值
  200 + String maxKey = maxKey(arrMap);
  201 + float absVal = abs(arrMap.get(maxKey));
  202 +
  203 + Sample rs = list.get(0);
  204 +
  205 + DecimalFormat dformat=new DecimalFormat(".00");
  206 + rs.setRunTime(Float.parseFloat(dformat.format(absVal)));
  207 +
  208 + //logger.info("全部:[ " + valStr + "] ,计算的中间值:" + absVal);
  209 + return rs;
  210 + }
  211 +
  212 + private String maxKey(ArrayListMultimap<String, Sample> arrMap){
  213 + String maxKey = null;
  214 + int size = 0;
  215 + Set<String> kys = arrMap.keySet();
  216 + for(String k : kys){
  217 + if(null != maxKey && arrMap.get(k).size() < size)
  218 + continue;
  219 +
  220 + size = arrMap.get(k).size();
  221 + maxKey = k;
  222 + }
  223 + return maxKey;
  224 + }
  225 +
  226 + private float abs(List<Sample> list){
  227 + float sum = 0;
  228 +
  229 + for(Sample s : list)
  230 + sum += s.getRunTime();
  231 +
  232 + return sum / list.size();
  233 + }
  234 +
  235 + public static class SampleComp implements Comparator<Sample>{
  236 +
  237 + @Override
  238 + public int compare(Sample arg0, Sample arg1) {
  239 + return (int)(arg0.getRunTime() * 10 - arg1.getRunTime() * 10);
  240 + }
  241 + }
  242 +
  243 + public static class SampleComp2 implements Comparator<Sample>{
  244 +
  245 + @Override
  246 + public int compare(Sample arg0, Sample arg1) {
  247 + if(arg0.geteTime() == arg1.geteTime())
  248 + return 0;
  249 +
  250 + return (int)(arg0.geteTime() - arg1.geteTime());
  251 + }
  252 + }
  253 +}
src/main/java/com/bsth/service/gps/GpsService.java
@@ -10,4 +10,6 @@ public interface GpsService { @@ -10,4 +10,6 @@ public interface GpsService {
10 List<Map<String, Object>> history(String[] nbbmArray, Long st, Long et); 10 List<Map<String, Object>> history(String[] nbbmArray, Long st, Long et);
11 11
12 Map<String, Object> findBuffAeraByCode(String code, String type); 12 Map<String, Object> findBuffAeraByCode(String code, String type);
  13 +
  14 + Map<String, Object> search(Map<String, Object> map, int page, int size, String order, String direction);
13 } 15 }
src/main/java/com/bsth/service/gps/GpsServiceImpl.java
1 package com.bsth.service.gps; 1 package com.bsth.service.gps;
2 2
  3 +import java.lang.reflect.Field;
3 import java.sql.Connection; 4 import java.sql.Connection;
4 import java.sql.PreparedStatement; 5 import java.sql.PreparedStatement;
5 import java.sql.ResultSet; 6 import java.sql.ResultSet;
6 import java.util.ArrayList; 7 import java.util.ArrayList;
7 import java.util.Calendar; 8 import java.util.Calendar;
  9 +import java.util.Collection;
8 import java.util.Collections; 10 import java.util.Collections;
9 import java.util.Comparator; 11 import java.util.Comparator;
10 import java.util.Date; 12 import java.util.Date;
@@ -17,8 +19,11 @@ import org.slf4j.LoggerFactory; @@ -17,8 +19,11 @@ import org.slf4j.LoggerFactory;
17 import org.springframework.beans.factory.annotation.Autowired; 19 import org.springframework.beans.factory.annotation.Autowired;
18 import org.springframework.stereotype.Service; 20 import org.springframework.stereotype.Service;
19 21
  22 +import com.bsth.common.ResponseCode;
20 import com.bsth.data.BasicData; 23 import com.bsth.data.BasicData;
21 import com.bsth.data.arrival.ArrivalEntity; 24 import com.bsth.data.arrival.ArrivalEntity;
  25 +import com.bsth.data.gpsdata.GpsEntity;
  26 +import com.bsth.data.gpsdata.GpsRealData;
22 import com.bsth.repository.CarParkRepository; 27 import com.bsth.repository.CarParkRepository;
23 import com.bsth.repository.StationRepository; 28 import com.bsth.repository.StationRepository;
24 import com.bsth.util.DateUtils; 29 import com.bsth.util.DateUtils;
@@ -37,6 +42,9 @@ public class GpsServiceImpl implements GpsService{ @@ -37,6 +42,9 @@ public class GpsServiceImpl implements GpsService{
37 ResultSet rs = null; 42 ResultSet rs = null;
38 43
39 Logger logger = LoggerFactory.getLogger(this.getClass()); 44 Logger logger = LoggerFactory.getLogger(this.getClass());
  45 +
  46 + @Autowired
  47 + GpsRealData gpsRealData;
40 48
41 // 历史gps查询 49 // 历史gps查询
42 @Override 50 @Override
@@ -307,4 +315,89 @@ public class GpsServiceImpl implements GpsService{ @@ -307,4 +315,89 @@ public class GpsServiceImpl implements GpsService{
307 315
308 return rs; 316 return rs;
309 } 317 }
  318 +
  319 + @Override
  320 + public Map<String, Object> search(Map<String, Object> map, int page, int size, String order, String direction) {
  321 + Map<String, Object> rsMap = new HashMap<>();
  322 + try{
  323 + //全量
  324 + Collection<GpsEntity> list = gpsRealData.all();
  325 + //过滤后的
  326 + List<GpsEntity> rs = new ArrayList<>();
  327 + Field[] fields = GpsEntity.class.getDeclaredFields();
  328 + //排序字段
  329 + Field orderField = null;
  330 + //参与过滤的字段
  331 + List<Field> fs = new ArrayList<>();
  332 + for(Field f : fields){
  333 + f.setAccessible(true);
  334 + if(map.containsKey(f.getName()))
  335 + fs.add(f);
  336 +
  337 + if(f.getName().equals(order))
  338 + orderField = f;
  339 + }
  340 + //过滤数据
  341 + for(GpsEntity gps : list){
  342 + if(fieldEquals(fs, gps, map))
  343 + rs.add(gps);
  344 + }
  345 +
  346 + //排序
  347 + if(null != orderField)
  348 + sortGpsList(orderField, rs);
  349 +
  350 + //分页
  351 + int count = rs.size()
  352 + ,s = page * size, e = s + size;
  353 + if (e > count)
  354 + e = count;
  355 +
  356 + rsMap.put("list", rs.subList(s, e));
  357 + rsMap.put("totalPages", count % size == 0 ? count / size : count / size + 1);
  358 + rsMap.put("page", page);
  359 + rsMap.put("status", ResponseCode.SUCCESS);
  360 + }catch(Exception e){
  361 + logger.error("", e);
  362 + rsMap.put("status", ResponseCode.ERROR);
  363 + }
  364 + return rsMap;
  365 + }
  366 +
  367 + private void sortGpsList(final Field f, List<GpsEntity> rs) {
  368 + Collections.sort(rs, new Comparator<GpsEntity>() {
  369 +
  370 + @Override
  371 + public int compare(GpsEntity o1, GpsEntity o2) {
  372 + try {
  373 + if(f.get(o1) == f.get(o2))
  374 + return 0;
  375 +
  376 + if(null == f.get(o1))
  377 + return 1;
  378 +
  379 + if(null == f.get(o2))
  380 + return -1;
  381 +
  382 + return f.get(o1).toString().compareTo(f.get(o2).toString());
  383 + } catch (Exception e) {
  384 + logger.error("", e);
  385 + return -1;
  386 + }
  387 + }
  388 + });
  389 + }
  390 +
  391 + public boolean fieldEquals(List<Field> fs, Object obj, Map<String, Object> map){
  392 + try{
  393 + for(Field f : fs){
  394 + if(f.get(obj).toString().indexOf(map.get(f.getName()).toString()) == -1)
  395 + return false;
  396 + }
  397 + }catch(Exception e){
  398 + logger.error("", e);
  399 + return false;
  400 + }
  401 + return true;
  402 + }
310 } 403 }
src/main/java/com/bsth/service/impl/StationRouteServiceImpl.java
@@ -11,8 +11,12 @@ import java.util.Map; @@ -11,8 +11,12 @@ import java.util.Map;
11 import java.util.Properties; 11 import java.util.Properties;
12 12
13 import org.springframework.beans.factory.annotation.Autowired; 13 import org.springframework.beans.factory.annotation.Autowired;
  14 +import org.springframework.data.jpa.repository.EntityGraph;
14 import org.springframework.stereotype.Service; 15 import org.springframework.stereotype.Service;
15 16
  17 +import com.alibaba.fastjson.JSON;
  18 +import com.alibaba.fastjson.JSONArray;
  19 +import com.alibaba.fastjson.serializer.PropertyFilter;
16 import com.bsth.common.ResponseCode; 20 import com.bsth.common.ResponseCode;
17 import com.bsth.entity.Line; 21 import com.bsth.entity.Line;
18 import com.bsth.entity.Station; 22 import com.bsth.entity.Station;
@@ -25,6 +29,8 @@ import com.bsth.service.StationRouteService; @@ -25,6 +29,8 @@ import com.bsth.service.StationRouteService;
25 import com.bsth.util.FTPClientUtils; 29 import com.bsth.util.FTPClientUtils;
26 import com.bsth.util.PackTarGZUtils; 30 import com.bsth.util.PackTarGZUtils;
27 import com.bsth.util.db.DBUtils_MS; 31 import com.bsth.util.db.DBUtils_MS;
  32 +import com.google.common.base.Splitter;
  33 +import com.google.common.collect.Lists;
28 34
29 /** 35 /**
30 * 36 *
@@ -579,12 +585,12 @@ public class StationRouteServiceImpl extends BaseServiceImpl&lt;StationRoute, Integ @@ -579,12 +585,12 @@ public class StationRouteServiceImpl extends BaseServiceImpl&lt;StationRoute, Integ
579 File textFile = clientUtils.GetFtpFile(url, port, username, password, remotePath, textFileName); 585 File textFile = clientUtils.GetFtpFile(url, port, username, password, remotePath, textFileName);
580 586
581 /*File[] sources = new File[] {textFile};*/ 587 /*File[] sources = new File[] {textFile};*/
582 - File[] sources = new File[] {textFile}; 588 + //File[] sources = new File[] {textFile};
583 589
584 File target = new File(odlGzFileName); 590 File target = new File(odlGzFileName);
585 591
586 // 将txt文件打包 592 // 将txt文件打包
587 - File targetFile = packTarGZUtils.pack(sources, target); 593 + File targetFile = PackTarGZUtils.compress(textFile, target);
588 594
589 /*clientUtils.testUpLoadFromDisk(targetFile,targetFile.getName());*/ 595 /*clientUtils.testUpLoadFromDisk(targetFile,targetFile.getName());*/
590 596
@@ -971,4 +977,41 @@ public class StationRouteServiceImpl extends BaseServiceImpl&lt;StationRoute, Integ @@ -971,4 +977,41 @@ public class StationRouteServiceImpl extends BaseServiceImpl&lt;StationRoute, Integ
971 977
972 return resultList; 978 return resultList;
973 } 979 }
  980 +
  981 + @Override
  982 + public Map<String, Object> findByMultiLine(String lineIds) {
  983 + Map<String, Object> rs = new HashMap<>();
  984 + try{
  985 + List<String> idx = Splitter.on(',').splitToList(lineIds);
  986 + //路由
  987 + List<StationRoute> list = new ArrayList<>();
  988 + /**
  989 + * in 查询符 无法和 @EntityGraph 同时配合使用,这可能是一个bug
  990 + * 暂时只能循环单线路查询
  991 + */
  992 + //repository.multiLine(idx)
  993 + for(String id : idx){
  994 + list.addAll(repository.findByLineCode(id));
  995 + }
  996 +
  997 + //过滤部分字段
  998 + String jsonStr = JSON.toJSONString(list, new PropertyFilter() {
  999 +
  1000 + @Override
  1001 + public boolean apply(Object object, String name, Object value) {
  1002 + if(name.equals("line"))
  1003 + return false;
  1004 + return true;
  1005 + }
  1006 + });
  1007 +
  1008 + rs.put("status", ResponseCode.SUCCESS);
  1009 + rs.put("list", jsonStr);
  1010 + }catch(Exception e){
  1011 + logger.error("", e);
  1012 + rs.put("status", ResponseCode.ERROR);
  1013 + }
  1014 +
  1015 + return rs;
  1016 + }
974 } 1017 }
src/main/java/com/bsth/service/impl/TrafficManageServiceImpl.java 0 → 100644
  1 +package com.bsth.service.impl;
  2 +
  3 +import java.util.Iterator;
  4 +
  5 +import org.springframework.beans.factory.annotation.Autowired;
  6 +import org.springframework.stereotype.Service;
  7 +
  8 +import com.bsth.entity.Line;
  9 +import com.bsth.repository.LineRepository;
  10 +import com.bsth.service.TrafficManageService;
  11 +import com.bsth.webService.trafficManage.geotool.services.Internal;
  12 +import com.bsth.webService.trafficManage.geotool.services.InternalPortType;
  13 +
  14 +/**
  15 + *
  16 + * @ClassName: LineServiceImpl(线路service业务层实现类)
  17 + *
  18 + * @Extends : BaseService
  19 + *
  20 + * @Description: TODO(线路service业务层)
  21 + *
  22 + * @Author bsth@lq
  23 + *
  24 + * @Date 2016年4月28日 上午9:21:17
  25 + *
  26 + * @Version 公交调度系统BS版 0.1
  27 + *
  28 + */
  29 +
  30 +@Service
  31 +public class TrafficManageServiceImpl implements TrafficManageService{
  32 +
  33 + @Autowired
  34 + private LineRepository repository;
  35 +
  36 + // 运管处接口
  37 + private InternalPortType portType = new Internal().getInternalHttpSoap11Endpoint();
  38 + // 用户名
  39 + private final String userName = "pudong";
  40 + // 密码
  41 + private final String password = "pudong123";
  42 +
  43 + /**
  44 + * 获取线路编码
  45 + *
  46 + * @return int <lineCode:线路编码>
  47 + */
  48 + public String setXL() {
  49 + String result = "";
  50 + StringBuffer sbBuffer = new StringBuffer();
  51 + Iterator<Line> lines = repository.findAll().iterator();
  52 + if(lines.hasNext()){
  53 + Line line = lines.next();
  54 + }
  55 + System.out.println(portType.setXL(sbBuffer.toString(), userName, password));;
  56 + System.out.println("abdfedddddddddddddddddddddddddddd");
  57 + return result;
  58 + }
  59 +
  60 +}
src/main/java/com/bsth/service/realcontrol/ScheduleRealInfoService.java
@@ -80,7 +80,7 @@ public interface ScheduleRealInfoService extends BaseService&lt;ScheduleRealInfo, L @@ -80,7 +80,7 @@ public interface ScheduleRealInfoService extends BaseService&lt;ScheduleRealInfo, L
80 80
81 Map<String, Object> outgoAdjustAll(String params); 81 Map<String, Object> outgoAdjustAll(String params);
82 82
83 - Map<String, Object> findRouteByLine(Integer lineCode); 83 + Map<String, Object> findRouteByLine(String lineCode);
84 84
85 List<Map<String,String>> findLine(String line); 85 List<Map<String,String>> findLine(String line);
86 86
@@ -110,4 +110,6 @@ public interface ScheduleRealInfoService extends BaseService&lt;ScheduleRealInfo, L @@ -110,4 +110,6 @@ public interface ScheduleRealInfoService extends BaseService&lt;ScheduleRealInfo, L
110 Map<String,Object> scheduleDaily(String line,String date); 110 Map<String,Object> scheduleDaily(String line,String date);
111 111
112 List<ScheduleRealInfo> realScheduleList(String line,String date); 112 List<ScheduleRealInfo> realScheduleList(String line,String date);
  113 +
  114 + List<Map<String,Object>> yesterdayDataList(String line);
113 } 115 }
src/main/java/com/bsth/service/realcontrol/impl/ScheduleRealInfoServiceImpl.java
@@ -310,8 +310,9 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf @@ -310,8 +310,9 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
310 SysUser user = SecurityUtils.getCurrentUser(); 310 SysUser user = SecurityUtils.getCurrentUser();
311 String schDate = DayOfSchedule.currSchDateMap.get(t.getXlBm()); 311 String schDate = DayOfSchedule.currSchDateMap.get(t.getXlBm());
312 312
  313 + SimpleDateFormat sdfyyyyMMdd = new SimpleDateFormat("yyyy-MM-dd");
313 t.setScheduleDateStr(schDate); 314 t.setScheduleDateStr(schDate);
314 - t.setScheduleDate(DateUtils.sdfyyyyMMdd.parse(schDate)); 315 + t.setScheduleDate(sdfyyyyMMdd.parse(schDate));
315 t.setRealExecDate(schDate); 316 t.setRealExecDate(schDate);
316 t.setCreateBy(user); 317 t.setCreateBy(user);
317 t.setSflj(true); 318 t.setSflj(true);
@@ -467,37 +468,48 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf @@ -467,37 +468,48 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
467 // int cjbc = scheduleRealInfoRepository.findCjbc(jName, clZbh, lpName); 468 // int cjbc = scheduleRealInfoRepository.findCjbc(jName, clZbh, lpName);
468 // int ljbc = scheduleRealInfoRepository.findLjbc(jName, clZbh, lpName); 469 // int ljbc = scheduleRealInfoRepository.findLjbc(jName, clZbh, lpName);
469 int jhbc = 0,cjbc = 0,ljbc = 0; 470 int jhbc = 0,cjbc = 0,ljbc = 0;
470 - double jhlc = 0, yygl = 0, ksgl = 0; 471 + double jhlc = 0, yygl = 0, ksgl = 0,tempJhlc = 0;
471 float addMileage = 0l,remMileage = 0l; 472 float addMileage = 0l,remMileage = 0l;
472 473
473 Map<String,Object> map; 474 Map<String,Object> map;
474 for(ScheduleRealInfo scheduleRealInfo : scheduleRealInfos){ 475 for(ScheduleRealInfo scheduleRealInfo : scheduleRealInfos){
475 if(scheduleRealInfo != null){ 476 if(scheduleRealInfo != null){
476 //计算计划里程(主任务过滤掉临加班次),烂班里程,临加里程,计划班次,烂班班次,增加班次 477 //计算计划里程(主任务过滤掉临加班次),烂班里程,临加里程,计划班次,烂班班次,增加班次
477 - if(scheduleRealInfo.isSflj()){  
478 - addMileage += addMileage += scheduleRealInfo.getAddMileage()==null?0:scheduleRealInfo.getAddMileage();  
479 - ljbc++;  
480 - }else{  
481 - jhlc += scheduleRealInfo.getJhlc()==null?0:scheduleRealInfo.getJhlc();  
482 - if(scheduleRealInfo.getStatus() != -1){  
483 - remMileage += scheduleRealInfo.getRemMileage()==null?0:scheduleRealInfo.getRemMileage(); 478 + if(scheduleRealInfo != null){
  479 + //计划里程(主任务过滤掉临加班次),
  480 + //烂班里程(主任务烂班),
  481 + //临加里程(主任务临加),
  482 + //计划班次,烂班班次,增加班次
  483 + tempJhlc = scheduleRealInfo.getJhlc()==null?0:scheduleRealInfo.getJhlc();
  484 + if(scheduleRealInfo.isSflj()){
  485 + addMileage += tempJhlc;
  486 + ljbc++;
484 }else{ 487 }else{
485 - cjbc++; 488 + jhlc += tempJhlc;
  489 + jhbc++;
  490 + if(scheduleRealInfo.getStatus() == -1){
  491 + remMileage += tempJhlc;
  492 + cjbc++;
  493 + }
486 } 494 }
487 - jhbc++;  
488 - }  
489 - Set<ChildTaskPlan> childTaskPlans = scheduleRealInfo.getcTasks();  
490 - //计算营运里程,空驶里程  
491 - if(childTaskPlans.isEmpty()){  
492 - yygl += scheduleRealInfo.getJhlc()==null?0:scheduleRealInfo.getJhlc();  
493 - }else{  
494 - Iterator<ChildTaskPlan> it = childTaskPlans.iterator();  
495 - while(it.hasNext()){  
496 - ChildTaskPlan childTaskPlan = it.next();  
497 - if(childTaskPlan.getMileageType().equals("empty")){  
498 - ksgl += childTaskPlan.getMileage()==null?0:childTaskPlan.getMileage(); 495 + Set<ChildTaskPlan> childTaskPlans = scheduleRealInfo.getcTasks();
  496 + //计算营运里程,空驶里程
  497 + if(childTaskPlans.isEmpty()){
  498 + if(scheduleRealInfo.getBcType().equals("in") || scheduleRealInfo.getBcType().equals("out")
  499 + || scheduleRealInfo.getBcType().equals("venting")){
  500 + ksgl += tempJhlc;
499 }else{ 501 }else{
500 - yygl += childTaskPlan.getMileage()==null?0:childTaskPlan.getMileage(); 502 + yygl += tempJhlc;
  503 + }
  504 + }else{
  505 + Iterator<ChildTaskPlan> it = childTaskPlans.iterator();
  506 + while(it.hasNext()){
  507 + ChildTaskPlan childTaskPlan = it.next();
  508 + if(childTaskPlan.getMileageType().equals("empty")){
  509 + ksgl += childTaskPlan.getMileage()==null?0:childTaskPlan.getMileage();
  510 + }else{
  511 + yygl += childTaskPlan.getMileage()==null?0:childTaskPlan.getMileage();
  512 + }
501 } 513 }
502 } 514 }
503 } 515 }
@@ -899,7 +911,7 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf @@ -899,7 +911,7 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
899 } 911 }
900 912
901 @Override 913 @Override
902 - public Map<String, Object> findRouteByLine(Integer lineCode) { 914 + public Map<String, Object> findRouteByLine(String lineCode) {
903 Map<String, Object> map = new HashMap<>(); 915 Map<String, Object> map = new HashMap<>();
904 //上行 916 //上行
905 Integer lineId = BasicData.lineId2CodeMap.inverse().get(lineCode); 917 Integer lineId = BasicData.lineId2CodeMap.inverse().get(lineCode);
@@ -1122,39 +1134,164 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf @@ -1122,39 +1134,164 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
1122 List<ScheduleRealInfo> list = scheduleRealInfoRepository.scheduleByDateAndLine(line, date); 1134 List<ScheduleRealInfo> list = scheduleRealInfoRepository.scheduleByDateAndLine(line, date);
1123 List<Map<String,Object>> lMap = new ArrayList<Map<String,Object>>(); 1135 List<Map<String,Object>> lMap = new ArrayList<Map<String,Object>>();
1124 DecimalFormat format = new DecimalFormat("0.00"); 1136 DecimalFormat format = new DecimalFormat("0.00");
1125 - double jhlc = 0.00;  
1126 - float sjgl = 0l,ssgl = 0l; 1137 + double jhlc = 0, tempJhlc = 0,childMileage = 0;
  1138 + float sjgl = 0f,ssgl = 0f,ssgl_lz = 0f,ssgl_dm = 0f,ssgl_gz = 0f,ssgl_jf = 0f,ssgl_zs = 0f,ssgl_qr = 0f
  1139 + ,ssgl_qc = 0f,ssgl_kx = 0f,ssgl_qh = 0f,ssgl_yw = 0f,ssgl_other = 0f,ljgl = 0f;
  1140 + //班次
  1141 + int sj_0 = 6*60+31,sj_1 = 8*60+30,sj_2 = 16*60+1,sj_3 = 18*60;
  1142 + int jhbc = 0,jhbc_m = 0,jhbc_a = 0;
  1143 + int sjbc = 0,sjbc_m = 0,sjbc_a = 0;
  1144 + int ljbc = 0,ljbc_m = 0,ljbc_a = 0;
  1145 + int fzbc = 0,fzbc_m = 0,fzbc_a = 0;
  1146 + int dtbc = 0,dtbc_m = 0,dtbc_a = 0;
  1147 + int djg = 0,djg_m = 0,djg_a = 0,djg_time = 0;
1127 Map<String,Object> map = new HashMap<String, Object>(); 1148 Map<String,Object> map = new HashMap<String, Object>();
1128 for(ScheduleRealInfo scheduleRealInfo: list){ 1149 for(ScheduleRealInfo scheduleRealInfo: list){
1129 if(scheduleRealInfo != null){ 1150 if(scheduleRealInfo != null){
1130 - if(!scheduleRealInfo.isSflj()){  
1131 - jhlc += scheduleRealInfo.getJhlc()==null?0:scheduleRealInfo.getJhlc();  
1132 - }  
1133 - if(scheduleRealInfo.isDestroy()){  
1134 - ssgl += scheduleRealInfo.getJhlc()==null?0:scheduleRealInfo.getJhlc();  
1135 - }  
1136 -  
1137 Set<ChildTaskPlan> childTaskPlans = scheduleRealInfo.getcTasks(); 1151 Set<ChildTaskPlan> childTaskPlans = scheduleRealInfo.getcTasks();
1138 - //计算实际里程,驶里程 1152 + //计算实际里程,少驶里程,计划里程=实际里程+少驶里程
1139 if(childTaskPlans.isEmpty()){ 1153 if(childTaskPlans.isEmpty()){
1140 - sjgl += scheduleRealInfo.getJhlc()==null?0:scheduleRealInfo.getJhlc(); 1154 + tempJhlc = scheduleRealInfo.getJhlc()==null?0:scheduleRealInfo.getJhlc();
  1155 + jhlc += tempJhlc;
  1156 + if(scheduleRealInfo.getStatus() == 2){
  1157 + sjgl += tempJhlc;
  1158 + }else if(scheduleRealInfo.getStatus() == -1){
  1159 + ssgl += tempJhlc;
  1160 + if(scheduleRealInfo.getRemarks().indexOf("路阻") != -1){
  1161 + ssgl_lz += tempJhlc;
  1162 + }else if(scheduleRealInfo.getRemarks().indexOf("吊慢") != -1){
  1163 + ssgl_dm += tempJhlc;
  1164 + }else if(scheduleRealInfo.getRemarks().indexOf("故障") != -1){
  1165 + ssgl_gz += tempJhlc;
  1166 + }else if(scheduleRealInfo.getRemarks().indexOf("纠纷") != -1){
  1167 + ssgl_jf += tempJhlc;
  1168 + }else if(scheduleRealInfo.getRemarks().indexOf("肇事") != -1){
  1169 + ssgl_zs += tempJhlc;
  1170 + }else if(scheduleRealInfo.getRemarks().indexOf("缺人") != -1){
  1171 + ssgl_qr += tempJhlc;
  1172 + }else if(scheduleRealInfo.getRemarks().indexOf("缺车") != -1){
  1173 + ssgl_qc += tempJhlc;
  1174 + }else if(scheduleRealInfo.getRemarks().indexOf("客稀") != -1){
  1175 + ssgl_kx += tempJhlc;
  1176 + }else if(scheduleRealInfo.getRemarks().indexOf("气候") != -1){
  1177 + ssgl_qh += tempJhlc;
  1178 + }else if(scheduleRealInfo.getRemarks().indexOf("援外") != -1){
  1179 + ssgl_yw += tempJhlc;
  1180 + }else{
  1181 + ssgl_other += tempJhlc;
  1182 + }
  1183 +
  1184 + //临加公里
  1185 + if(scheduleRealInfo.isSflj()){
  1186 + ljgl += tempJhlc;
  1187 + }
  1188 + }
1141 }else{ 1189 }else{
1142 Iterator<ChildTaskPlan> it = childTaskPlans.iterator(); 1190 Iterator<ChildTaskPlan> it = childTaskPlans.iterator();
1143 while(it.hasNext()){ 1191 while(it.hasNext()){
1144 ChildTaskPlan childTaskPlan = it.next(); 1192 ChildTaskPlan childTaskPlan = it.next();
  1193 + childMileage = childTaskPlan.getMileage()==null?0:childTaskPlan.getMileage();
  1194 + jhlc += childMileage;
1145 if(childTaskPlan.isDestroy()){ 1195 if(childTaskPlan.isDestroy()){
1146 - ssgl += childTaskPlan.getMileage()==null?0:childTaskPlan.getMileage(); 1196 + ssgl += childMileage;
  1197 + if(childTaskPlan.getDestroyReason().equals("路阻")){
  1198 + ssgl_lz += childTaskPlan.getMileage();
  1199 + }else if(childTaskPlan.getDestroyReason().equals("吊慢")){
  1200 + ssgl_dm += childTaskPlan.getMileage();
  1201 + }else if(childTaskPlan.getDestroyReason().equals("故障")){
  1202 + ssgl_gz += childTaskPlan.getMileage();
  1203 + }else if(childTaskPlan.getDestroyReason().equals("纠纷")){
  1204 + ssgl_jf += childTaskPlan.getMileage();
  1205 + }else if(childTaskPlan.getDestroyReason().equals("肇事")){
  1206 + ssgl_zs += childTaskPlan.getMileage();
  1207 + }else if(childTaskPlan.getDestroyReason().equals("缺人")){
  1208 + ssgl_qr += childTaskPlan.getMileage();
  1209 + }else if(childTaskPlan.getDestroyReason().equals("缺车")){
  1210 + ssgl_qc += childTaskPlan.getMileage();
  1211 + }else if(childTaskPlan.getDestroyReason().equals("客稀")){
  1212 + ssgl_kx += childTaskPlan.getMileage();
  1213 + }else if(childTaskPlan.getDestroyReason().equals("气候")){
  1214 + ssgl_qh += childTaskPlan.getMileage();
  1215 + }else if(childTaskPlan.getDestroyReason().equals("援外")){
  1216 + ssgl_yw += childTaskPlan.getMileage();
  1217 + }else{
  1218 + ssgl_other += childTaskPlan.getMileage();
  1219 + }
1147 }else{ 1220 }else{
1148 - sjgl += childTaskPlan.getMileage()==null?0:childTaskPlan.getMileage(); 1221 + sjgl += childMileage;
1149 } 1222 }
1150 } 1223 }
1151 } 1224 }
  1225 +
  1226 + //班次
  1227 + jhbc++;
  1228 + String[] fcsj = scheduleRealInfo.getFcsj().split(":");
  1229 + String[] fcsjActual = (scheduleRealInfo.getFcsjActual()==null?"0:00":scheduleRealInfo.getFcsjActual()).split(":");
  1230 + if((Integer.parseInt(fcsj[0])*60+Integer.parseInt(fcsj[1])) > sj_0 && (Integer.parseInt(fcsj[0])*60+Integer.parseInt(fcsj[1])) < sj_1){
  1231 + jhbc_m++;
  1232 + }else if((Integer.parseInt(fcsj[0])*60+Integer.parseInt(fcsj[1])) > sj_2 && (Integer.parseInt(fcsj[0])*60+Integer.parseInt(fcsj[1])) < sj_3){
  1233 + jhbc_a++;
  1234 + }
  1235 + if(scheduleRealInfo.getStatus() == 2){
  1236 + sjbc++;
  1237 + if((Integer.parseInt(fcsjActual[0])*60+Integer.parseInt(fcsjActual[1])) > sj_0 && (Integer.parseInt(fcsjActual[0])*60+Integer.parseInt(fcsjActual[1])) < sj_1){
  1238 + sjbc_m++;
  1239 + }else if((Integer.parseInt(fcsjActual[0])*60+Integer.parseInt(fcsjActual[1])) > sj_2 && (Integer.parseInt(fcsjActual[0])*60+Integer.parseInt(fcsjActual[1])) < sj_3){
  1240 + sjbc_a++;
  1241 + }
  1242 + }
  1243 + if(scheduleRealInfo.isSflj()){
  1244 + ljbc++;
  1245 + if((Integer.parseInt(fcsjActual[0])*60+Integer.parseInt(fcsjActual[1])) > sj_0 && (Integer.parseInt(fcsjActual[0])*60+Integer.parseInt(fcsjActual[1])) < sj_1){
  1246 + ljbc_m++;
  1247 + }else if((Integer.parseInt(fcsjActual[0])*60+Integer.parseInt(fcsjActual[1])) > sj_2 && (Integer.parseInt(fcsjActual[0])*60+Integer.parseInt(fcsjActual[1])) < sj_3){
  1248 + ljbc_a++;
  1249 + }
  1250 + }
  1251 + if(scheduleRealInfo.getBcType().equals("venting")){
  1252 + fzbc++;
  1253 + if((Integer.parseInt(fcsjActual[0])*60+Integer.parseInt(fcsjActual[1])) > sj_0 && (Integer.parseInt(fcsjActual[0])*60+Integer.parseInt(fcsjActual[1])) < sj_1){
  1254 + fzbc_m++;
  1255 + }else if((Integer.parseInt(fcsjActual[0])*60+Integer.parseInt(fcsjActual[1])) > sj_2 && (Integer.parseInt(fcsjActual[0])*60+Integer.parseInt(fcsjActual[1])) < sj_3){
  1256 + fzbc_a++;
  1257 + }
  1258 + }
1152 } 1259 }
1153 } 1260 }
1154 map.put("xlName", xlName); 1261 map.put("xlName", xlName);
1155 map.put("jhlc", format.format(jhlc)); 1262 map.put("jhlc", format.format(jhlc));
1156 map.put("sjgl", format.format(sjgl)); 1263 map.put("sjgl", format.format(sjgl));
1157 map.put("ssgl", format.format(ssgl)); 1264 map.put("ssgl", format.format(ssgl));
  1265 + map.put("ssgl_lz", ssgl_lz==0?0:format.format(ssgl_lz));
  1266 + map.put("ssgl_dm", ssgl_dm==0?0:format.format(ssgl_dm));
  1267 + map.put("ssgl_gz", ssgl_gz==0?0:format.format(ssgl_gz));
  1268 + map.put("ssgl_jf", ssgl_jf==0?0:format.format(ssgl_jf));
  1269 + map.put("ssgl_zs", ssgl_zs==0?0:format.format(ssgl_zs));
  1270 + map.put("ssgl_qr", ssgl_qr==0?0:format.format(ssgl_qr));
  1271 + map.put("ssgl_qc", ssgl_qc==0?0:format.format(ssgl_qc));
  1272 + map.put("ssgl_kx", ssgl_kx==0?0:format.format(ssgl_kx));
  1273 + map.put("ssgl_qh", ssgl_qh==0?0:format.format(ssgl_qh));
  1274 + map.put("ssgl_yw", ssgl_yw==0?0:format.format(ssgl_yw));
  1275 + map.put("ssgl_other", ssgl_other==0?0:format.format(ssgl_other));
  1276 + map.put("ljgl", ljgl==0?0:format.format(ljgl));
  1277 + map.put("jhbc_m", jhbc_m);
  1278 + map.put("jhbc_a", jhbc_a);
  1279 + map.put("sjbc", sjbc);
  1280 + map.put("sjbc_m", sjbc_m);
  1281 + map.put("sjbc_a", sjbc_a);
  1282 + map.put("ljbc", ljbc);
  1283 + map.put("ljbc_m", ljbc_m);
  1284 + map.put("ljbc_a", ljbc_a);
  1285 + map.put("fzbc", fzbc);
  1286 + map.put("fzbc_m", fzbc_m);
  1287 + map.put("fzbc_a", fzbc_a);
  1288 + map.put("dtbc", dtbc);
  1289 + map.put("dtbc_m", dtbc_m);
  1290 + map.put("dtbc_a", dtbc_a);
  1291 + map.put("djg", djg);
  1292 + map.put("djg_m", djg_m);
  1293 + map.put("djg_a", djg_a);
  1294 + map.put("djg_time", djg_time);
1158 lMap.add(map); 1295 lMap.add(map);
1159 return lMap; 1296 return lMap;
1160 } 1297 }
@@ -1259,6 +1396,15 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf @@ -1259,6 +1396,15 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
1259 1396
1260 @Override 1397 @Override
1261 public List<ScheduleRealInfo> realScheduleList(String line, String date) { 1398 public List<ScheduleRealInfo> realScheduleList(String line, String date) {
  1399 + List<ScheduleRealInfo> listInfo = scheduleRealInfoRepository.queryUserInfo(line, date);
  1400 + List<ScheduleRealInfo> listTotal = scheduleRealInfoRepository.scheduleByDateAndLine(line, date);
  1401 + for(ScheduleRealInfo info:listInfo){
  1402 + for(ScheduleRealInfo total:listTotal){
  1403 + if(info.getjGh().equals(total.getjGh()) && info.getLpName().equals(total.getLpName()) && info.getClZbh().equals(total.getClZbh())){
  1404 +
  1405 + }
  1406 + }
  1407 + }
1262 return scheduleRealInfoRepository.scheduleByDateAndLine(line, date); 1408 return scheduleRealInfoRepository.scheduleByDateAndLine(line, date);
1263 } 1409 }
1264 1410
@@ -1275,4 +1421,52 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf @@ -1275,4 +1421,52 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
1275 1421
1276 return rs; 1422 return rs;
1277 } 1423 }
  1424 +
  1425 + public List<Map<String,Object>> yesterdayDataList(String line) {
  1426 + //前一天日期
  1427 + String date = sdfMonth.format(org.apache.commons.lang.time.DateUtils.addDays(new Date(), -1));
  1428 + List<Map<String,Object>> yesterdayDataList = scheduleRealInfoRepository.yesterdayDataList(line, date);
  1429 + List<ScheduleRealInfo> list = scheduleRealInfoRepository.scheduleByDateAndLine(line, date);
  1430 + for(ScheduleRealInfo scheduleRealInfo:list){
  1431 + if(scheduleRealInfo != null){
  1432 + for(int i=0;i<yesterdayDataList.size();i++){
  1433 + if(scheduleRealInfo.getXlBm().equals(yesterdayDataList.get(i).get("xlBm")) && scheduleRealInfo.getClZbh().equals(yesterdayDataList.get(i).get("clZbh"))
  1434 + && scheduleRealInfo.getjGh().equals(yesterdayDataList.get(i).get("jGh"))){
  1435 + //根据线路代码获取公司
  1436 + Line li = lineRepository.findByLineCode(line);
  1437 + yesterdayDataList.get(i).put("company", li.getCompany());
  1438 + //计算总公里
  1439 + Set<ChildTaskPlan> childTaskPlans = scheduleRealInfo.getcTasks();
  1440 + //如果没有子任务,里程就是已执行(Status=2);有子任务的,忽略主任务,子任务的烂班
  1441 + if(childTaskPlans.isEmpty()){
  1442 + if(scheduleRealInfo.getStatus() == 2){
  1443 + yesterdayDataList.get(i).put("totalKilometers", scheduleRealInfo.getJhlc()==null?0.0:scheduleRealInfo.getJhlc()+(double)(yesterdayDataList.get(i).get("totalKilometers")==null?0.0:yesterdayDataList.get(i).get("totalKilometers")));
  1444 + }
  1445 + }else{
  1446 + Iterator<ChildTaskPlan> it = childTaskPlans.iterator();
  1447 + while(it.hasNext()){
  1448 + ChildTaskPlan childTaskPlan = it.next();
  1449 + if(!childTaskPlan.isDestroy()){
  1450 + yesterdayDataList.get(i).put("totalKilometers", childTaskPlan.getMileage()==null?0.0:childTaskPlan.getMileage()+(double)(yesterdayDataList.get(i).get("totalKilometers")==null?0.0:yesterdayDataList.get(i).get("totalKilometers")));
  1451 + }
  1452 + }
  1453 + }
  1454 + }
  1455 + }
  1456 + }
  1457 + }
  1458 + //增加顺序号
  1459 + for(int i=0;i<yesterdayDataList.size();i++){
  1460 + if(i == 0){
  1461 + yesterdayDataList.get(i).put("seqNumber", 1);
  1462 + }else{
  1463 + if(yesterdayDataList.get(i-1).get("clZbh").equals(yesterdayDataList.get(i).get("clZbh"))){
  1464 + yesterdayDataList.get(i).put("seqNumber", 1+(int)yesterdayDataList.get(i-1).get("seqNumber"));
  1465 + }else{
  1466 + yesterdayDataList.get(i).put("seqNumber", 1);
  1467 + }
  1468 + }
  1469 + }
  1470 + return yesterdayDataList;
  1471 + }
1278 } 1472 }
src/main/java/com/bsth/service/schedule/SchedulePlanInfoService.java
@@ -2,9 +2,387 @@ package com.bsth.service.schedule; @@ -2,9 +2,387 @@ package com.bsth.service.schedule;
2 2
3 import com.bsth.entity.schedule.SchedulePlanInfo; 3 import com.bsth.entity.schedule.SchedulePlanInfo;
4 import com.bsth.service.BaseService; 4 import com.bsth.service.BaseService;
  5 +import org.joda.time.DateTime;
  6 +
  7 +import java.util.Date;
  8 +import java.util.List;
5 9
6 /** 10 /**
7 * Created by xu on 16/6/16. 11 * Created by xu on 16/6/16.
8 */ 12 */
9 public interface SchedulePlanInfoService extends BaseService<SchedulePlanInfo, Long> { 13 public interface SchedulePlanInfoService extends BaseService<SchedulePlanInfo, Long> {
  14 + /**
  15 + * 查找分组排班信息。
  16 + * @param xlid 线路Id
  17 + * @param scheduleDate 排班日期
  18 + * @return
  19 + */
  20 + List<GroupInfo> findGroupInfo(Integer xlid, Date scheduleDate);
  21 +
  22 + /**
  23 + * 更新分组信息。
  24 + * type=1,替换车辆
  25 + * type=2,修改出场班次1时间(首班车时间)
  26 + * type=3,替换分组人员(驾驶员1和售票员1)
  27 + * type=4,如果分班,修改出场班次2时间(分班后的第一个出场班次时间)
  28 + * type=5,如果分班,修改分组人员(驾驶员2和售票员2)
  29 + * @param groupInfoUpdate 分组更新信息,包含类型,更新前的信息,更新后的信息
  30 + * @return
  31 + */
  32 + int updateGroupInfo(GroupInfoUpdate groupInfoUpdate);
  33 +
  34 + /**
  35 + * 分组更新信息。
  36 + */
  37 + static class GroupInfoUpdate {
  38 + /** 类型 */
  39 + private int type;
  40 + /** 原始分组值 */
  41 + private GroupInfo src;
  42 + /** 更新分组值 */
  43 + private GroupInfo update;
  44 +
  45 + public int getType() {
  46 + return type;
  47 + }
  48 +
  49 + public void setType(int type) {
  50 + this.type = type;
  51 + }
  52 +
  53 + public GroupInfo getSrc() {
  54 + return src;
  55 + }
  56 +
  57 + public void setSrc(GroupInfo src) {
  58 + this.src = src;
  59 + }
  60 +
  61 + public GroupInfo getUpdate() {
  62 + return update;
  63 + }
  64 +
  65 + public void setUpdate(GroupInfo update) {
  66 + this.update = update;
  67 + }
  68 + }
  69 +
  70 + /**
  71 + * 分组信息。
  72 + */
  73 + static class GroupInfo {
  74 + /** 线路Id */
  75 + private Integer xlId;
  76 + /** 线路名称 */
  77 + private String xlName;
  78 + /** 排班时间 */
  79 + private Date scheduleDate;
  80 + /** 路牌名字 */
  81 + private String lpName;
  82 + /** 车辆Id */
  83 + private Integer clId;
  84 + /** 车辆自编号 */
  85 + private String clZbh;
  86 + /** 出场班次1时间 */
  87 + private String ccsj1;
  88 + /** 出场班次2时间 */
  89 + private String ccsj2;
  90 +
  91 + /** 驾驶员1id */
  92 + private Integer jsy1Id;
  93 + /** 驾驶员1工号 */
  94 + private String jsy1Gh;
  95 + /** 驾驶员1姓名 */
  96 + private String jsy1Name;
  97 + /** 驾驶员1id */
  98 + private Integer jsy2Id;
  99 + /** 驾驶员1工号 */
  100 + private String jsy2Gh;
  101 + /** 驾驶员1姓名 */
  102 + private String jsy2Name;
  103 +
  104 + /** 售票员1id */
  105 + private Integer spy1Id;
  106 + /** 售票员1工号 */
  107 + private String spy1Gh;
  108 + /** 售票员1姓名 */
  109 + private String spy1Name;
  110 + /** 售票员1id */
  111 + private Integer spy2Id;
  112 + /** 售票员1工号 */
  113 + private String spy2Gh;
  114 + /** 售票员1姓名 */
  115 + private String spy2Name;
  116 +
  117 + /** 创建时间 */
  118 + private Date createDate;
  119 +
  120 + public GroupInfo() {}
  121 +
  122 + public GroupInfo(Object[] datas) {
  123 + // 线路Id
  124 + this.xlId = Integer.valueOf(String.valueOf(datas[0]));
  125 + // 线路名称
  126 + this.xlName = String.valueOf(datas[1]);
  127 + // 排班时间
  128 + this.scheduleDate = new DateTime(datas[2]).toDate();
  129 + // 路牌名字
  130 + this.lpName = String.valueOf(datas[3]);
  131 + // 车辆id
  132 + this.clId = Integer.valueOf(String.valueOf(datas[4]));
  133 + // 车辆自编号
  134 + this.clZbh = String.valueOf(datas[5]);
  135 + // 出场时间,如果有多个,需要分开
  136 + Object ccsj = datas[6];
  137 + if (ccsj != null) {
  138 + String[] ccsj_array = ((String) ccsj).split(",");
  139 + if (ccsj_array.length > 1) {
  140 + this.ccsj1 = String.valueOf(ccsj_array[0]);
  141 + this.ccsj2 = String.valueOf(ccsj_array[1]);
  142 + } else {
  143 + this.ccsj1 = String.valueOf(ccsj_array[0]);
  144 + }
  145 + }
  146 + // 驾驶员id,如果有多个,需要分开
  147 + Object jsyId = datas[7];
  148 + if (jsyId != null) {
  149 + String[] jsyId_array = ((String) jsyId).split(",");
  150 + if (jsyId_array.length > 1) {
  151 + this.jsy1Id = Integer.valueOf(String.valueOf(jsyId_array[0]));
  152 + this.jsy2Id = Integer.valueOf(String.valueOf(jsyId_array[1]));
  153 + } else {
  154 + this.jsy1Id = Integer.valueOf(String.valueOf(jsyId_array[0]));
  155 + }
  156 + }
  157 + // 驾驶员工号,如果有多个,需要分开
  158 + Object jsyGh = datas[8];
  159 + if (jsyGh != null) {
  160 + String[] jsyGh_array = ((String) jsyGh).split(",");
  161 + if (jsyGh_array.length > 1) {
  162 + this.jsy1Gh = String.valueOf(jsyGh_array[0]);
  163 + this.jsy2Gh = String.valueOf(jsyGh_array[1]);
  164 + } else {
  165 + this.jsy1Gh = String.valueOf(jsyGh_array[0]);
  166 + }
  167 + }
  168 + // 驾驶员名字,如果有多个,需要分开
  169 + Object jsyName = datas[9];
  170 + if (jsyName != null) {
  171 + String[] jsyName_array = ((String) jsyName).split(",");
  172 + if (jsyName_array.length > 1) {
  173 + this.jsy1Name = String.valueOf(jsyName_array[0]);
  174 + this.jsy2Name = String.valueOf(jsyName_array[1]);
  175 + } else {
  176 + this.jsy1Name = String.valueOf(jsyName_array[0]);
  177 + }
  178 + }
  179 +
  180 + // 售票员id,如果有多个,需要分开
  181 + Object spyId = datas[10];
  182 + if (spyId != null) {
  183 + String[] spyId_array = ((String) spyId).split(",");
  184 + if (spyId_array.length > 1) {
  185 + this.spy1Id = Integer.valueOf(String.valueOf(spyId_array[0]));
  186 + this.spy2Id = Integer.valueOf(String.valueOf(spyId_array[1]));
  187 + } else {
  188 + this.spy1Id = Integer.valueOf(String.valueOf(spyId_array[0]));
  189 + }
  190 + }
  191 +
  192 + // 售票员工号,如果有多个,需要分开
  193 + Object spyGh = datas[11];
  194 + if (spyGh != null) {
  195 + String[] spyGh_array = ((String) spyGh).split(",");
  196 + if (spyGh_array.length > 1) {
  197 + this.spy1Gh = String.valueOf(spyGh_array[0]);
  198 + this.spy2Gh = String.valueOf(spyGh_array[1]);
  199 + } else {
  200 + this.spy1Gh = String.valueOf(spyGh_array[0]);
  201 + }
  202 + }
  203 + // 售票员名字,如果有多个,需要分开
  204 + Object spyName = datas[12];
  205 + if (spyName != null) {
  206 + String[] spyName_array = ((String) spyName).split(",");
  207 + if (spyName_array.length > 1) {
  208 + this.spy1Name = String.valueOf(spyName_array[0]);
  209 + this.spy2Name = String.valueOf(spyName_array[1]);
  210 + } else {
  211 + this.spy1Name = String.valueOf(spyName_array[0]);
  212 + }
  213 + }
  214 + // 创建时间
  215 + this.createDate = new DateTime(datas[13]).toDate();
  216 +
  217 + // TODO:可能还有其他字段
  218 + }
  219 +
  220 + public String getXlName() {
  221 + return xlName;
  222 + }
  223 +
  224 + public void setXlName(String xlName) {
  225 + this.xlName = xlName;
  226 + }
  227 +
  228 + public Date getScheduleDate() {
  229 + return scheduleDate;
  230 + }
  231 +
  232 + public void setScheduleDate(Date scheduleDate) {
  233 + this.scheduleDate = scheduleDate;
  234 + }
  235 +
  236 + public String getLpName() {
  237 + return lpName;
  238 + }
  239 +
  240 + public void setLpName(String lpName) {
  241 + this.lpName = lpName;
  242 + }
  243 +
  244 + public Integer getClId() {
  245 + return clId;
  246 + }
  247 +
  248 + public void setClId(Integer clId) {
  249 + this.clId = clId;
  250 + }
  251 +
  252 + public String getClZbh() {
  253 + return clZbh;
  254 + }
  255 +
  256 + public void setClZbh(String clZbh) {
  257 + this.clZbh = clZbh;
  258 + }
  259 +
  260 + public String getCcsj1() {
  261 + return ccsj1;
  262 + }
  263 +
  264 + public void setCcsj1(String ccsj1) {
  265 + this.ccsj1 = ccsj1;
  266 + }
  267 +
  268 + public String getCcsj2() {
  269 + return ccsj2;
  270 + }
  271 +
  272 + public void setCcsj2(String ccsj2) {
  273 + this.ccsj2 = ccsj2;
  274 + }
  275 +
  276 + public Integer getJsy1Id() {
  277 + return jsy1Id;
  278 + }
  279 +
  280 + public void setJsy1Id(Integer jsy1Id) {
  281 + this.jsy1Id = jsy1Id;
  282 + }
  283 +
  284 + public String getJsy1Gh() {
  285 + return jsy1Gh;
  286 + }
  287 +
  288 + public void setJsy1Gh(String jsy1Gh) {
  289 + this.jsy1Gh = jsy1Gh;
  290 + }
  291 +
  292 + public String getJsy1Name() {
  293 + return jsy1Name;
  294 + }
  295 +
  296 + public void setJsy1Name(String jsy1Name) {
  297 + this.jsy1Name = jsy1Name;
  298 + }
  299 +
  300 + public Integer getJsy2Id() {
  301 + return jsy2Id;
  302 + }
  303 +
  304 + public void setJsy2Id(Integer jsy2Id) {
  305 + this.jsy2Id = jsy2Id;
  306 + }
  307 +
  308 + public String getJsy2Gh() {
  309 + return jsy2Gh;
  310 + }
  311 +
  312 + public void setJsy2Gh(String jsy2Gh) {
  313 + this.jsy2Gh = jsy2Gh;
  314 + }
  315 +
  316 + public String getJsy2Name() {
  317 + return jsy2Name;
  318 + }
  319 +
  320 + public void setJsy2Name(String jsy2Name) {
  321 + this.jsy2Name = jsy2Name;
  322 + }
  323 +
  324 + public Integer getSpy1Id() {
  325 + return spy1Id;
  326 + }
  327 +
  328 + public void setSpy1Id(Integer spy1Id) {
  329 + this.spy1Id = spy1Id;
  330 + }
  331 +
  332 + public String getSpy1Gh() {
  333 + return spy1Gh;
  334 + }
  335 +
  336 + public void setSpy1Gh(String spy1Gh) {
  337 + this.spy1Gh = spy1Gh;
  338 + }
  339 +
  340 + public String getSpy1Name() {
  341 + return spy1Name;
  342 + }
  343 +
  344 + public void setSpy1Name(String spy1Name) {
  345 + this.spy1Name = spy1Name;
  346 + }
  347 +
  348 + public Integer getSpy2Id() {
  349 + return spy2Id;
  350 + }
  351 +
  352 + public void setSpy2Id(Integer spy2Id) {
  353 + this.spy2Id = spy2Id;
  354 + }
  355 +
  356 + public String getSpy2Gh() {
  357 + return spy2Gh;
  358 + }
  359 +
  360 + public void setSpy2Gh(String spy2Gh) {
  361 + this.spy2Gh = spy2Gh;
  362 + }
  363 +
  364 + public String getSpy2Name() {
  365 + return spy2Name;
  366 + }
  367 +
  368 + public void setSpy2Name(String spy2Name) {
  369 + this.spy2Name = spy2Name;
  370 + }
  371 +
  372 + public Date getCreateDate() {
  373 + return createDate;
  374 + }
  375 +
  376 + public void setCreateDate(Date createDate) {
  377 + this.createDate = createDate;
  378 + }
  379 +
  380 + public Integer getXlId() {
  381 + return xlId;
  382 + }
  383 +
  384 + public void setXlId(Integer xlId) {
  385 + this.xlId = xlId;
  386 + }
  387 + }
10 } 388 }
src/main/java/com/bsth/service/schedule/SchedulePlanInfoServiceImpl.java
1 package com.bsth.service.schedule; 1 package com.bsth.service.schedule;
2 2
3 import com.bsth.entity.schedule.SchedulePlanInfo; 3 import com.bsth.entity.schedule.SchedulePlanInfo;
  4 +import com.bsth.repository.schedule.SchedulePlanInfoRepository;
4 import com.bsth.service.impl.BaseServiceImpl; 5 import com.bsth.service.impl.BaseServiceImpl;
  6 +import org.springframework.beans.factory.annotation.Autowired;
5 import org.springframework.stereotype.Service; 7 import org.springframework.stereotype.Service;
  8 +import org.springframework.transaction.annotation.Transactional;
  9 +
  10 +import java.util.ArrayList;
  11 +import java.util.Date;
  12 +import java.util.List;
6 13
7 /** 14 /**
8 * Created by xu on 16/6/16. 15 * Created by xu on 16/6/16.
9 */ 16 */
10 @Service 17 @Service
11 public class SchedulePlanInfoServiceImpl extends BaseServiceImpl<SchedulePlanInfo, Long> implements SchedulePlanInfoService { 18 public class SchedulePlanInfoServiceImpl extends BaseServiceImpl<SchedulePlanInfo, Long> implements SchedulePlanInfoService {
  19 + @Autowired
  20 + private SchedulePlanInfoRepository schedulePlanInfoRepository;
  21 +
  22 + @Override
  23 + public List<GroupInfo> findGroupInfo(Integer xlid, Date scheduleDate) {
  24 + List<Object[]> groupInfos = schedulePlanInfoRepository.findGroupInfo(xlid, scheduleDate);
  25 + List<GroupInfo> groupInfoList = new ArrayList<>();
  26 + for (Object[] groupInfo : groupInfos) {
  27 + groupInfoList.add(new GroupInfo(groupInfo));
  28 + }
  29 + return groupInfoList;
  30 + }
  31 +
  32 + @Override
  33 + @Transactional
  34 + public int updateGroupInfo(GroupInfoUpdate groupInfoUpdate) {
  35 + int type = groupInfoUpdate.getType();
  36 + int result;
  37 + if (type == 1) {
  38 + // 换车
  39 + if (groupInfoUpdate.getUpdate().getClId() != groupInfoUpdate.getSrc().getClId()) {
  40 + result = this.schedulePlanInfoRepository.updateGroupInfo_type_1(
  41 + groupInfoUpdate.getUpdate().getClId(),
  42 + groupInfoUpdate.getUpdate().getClZbh(),
  43 + groupInfoUpdate.getSrc().getXlId(),
  44 + groupInfoUpdate.getSrc().getScheduleDate(),
  45 + groupInfoUpdate.getSrc().getLpName()
  46 + );
  47 + }
  48 +
  49 + } else if (type == 2) {
  50 + // 更改出场班次1的时间
  51 + if (!groupInfoUpdate.getUpdate().getCcsj1().equals(groupInfoUpdate.getSrc().getCcsj1())) {
  52 + result = this.schedulePlanInfoRepository.updateGroupInfo_type_2_4(
  53 + groupInfoUpdate.getUpdate().getCcsj1(),
  54 + groupInfoUpdate.getSrc().getXlId(),
  55 + groupInfoUpdate.getUpdate().getScheduleDate(),
  56 + groupInfoUpdate.getSrc().getLpName(),
  57 + groupInfoUpdate.getSrc().getCcsj1(),
  58 + "out"
  59 + );
  60 + }
  61 +
  62 + } else if (type == 3) {
  63 + // 更改驾驶员1
  64 + if (groupInfoUpdate.getUpdate().getJsy1Id() != groupInfoUpdate.getSrc().getJsy1Id()) {
  65 + result = this.schedulePlanInfoRepository.updateGroupInfo_type_3_5_jsy(
  66 + groupInfoUpdate.getUpdate().getJsy1Id(),
  67 + groupInfoUpdate.getUpdate().getJsy1Gh(),
  68 + groupInfoUpdate.getUpdate().getJsy1Name(),
  69 + groupInfoUpdate.getSrc().getXlId(),
  70 + groupInfoUpdate.getSrc().getScheduleDate(),
  71 + groupInfoUpdate.getSrc().getLpName(),
  72 + groupInfoUpdate.getSrc().getJsy1Id()
  73 + );
  74 + }
  75 + // 更改售票员1
  76 + if (groupInfoUpdate.getUpdate().getSpy1Id() != groupInfoUpdate.getSrc().getSpy1Id()) {
  77 + result = this.schedulePlanInfoRepository.updateGroupInfo_type_3_5_spy(
  78 + groupInfoUpdate.getUpdate().getSpy1Id(),
  79 + groupInfoUpdate.getUpdate().getSpy1Gh(),
  80 + groupInfoUpdate.getUpdate().getSpy1Name(),
  81 + groupInfoUpdate.getSrc().getXlId(),
  82 + groupInfoUpdate.getSrc().getScheduleDate(),
  83 + groupInfoUpdate.getSrc().getLpName(),
  84 + groupInfoUpdate.getSrc().getSpy1Id()
  85 + );
  86 + }
  87 +
  88 + } else if (type == 4) {
  89 + // 更改出场班次2的时间
  90 + if (!groupInfoUpdate.getUpdate().getCcsj2().equals(groupInfoUpdate.getSrc().getCcsj2())) {
  91 + result = this.schedulePlanInfoRepository.updateGroupInfo_type_2_4(
  92 + groupInfoUpdate.getUpdate().getCcsj2(),
  93 + groupInfoUpdate.getSrc().getXlId(),
  94 + groupInfoUpdate.getUpdate().getScheduleDate(),
  95 + groupInfoUpdate.getSrc().getLpName(),
  96 + groupInfoUpdate.getSrc().getCcsj2(),
  97 + "out"
  98 + );
  99 + }
  100 +
  101 + } else if (type == 5) {
  102 + // 更改驾驶员2
  103 + if (groupInfoUpdate.getUpdate().getJsy2Id() != groupInfoUpdate.getSrc().getJsy2Id()) {
  104 + result = this.schedulePlanInfoRepository.updateGroupInfo_type_3_5_jsy(
  105 + groupInfoUpdate.getUpdate().getJsy2Id(),
  106 + groupInfoUpdate.getUpdate().getJsy2Gh(),
  107 + groupInfoUpdate.getUpdate().getJsy2Name(),
  108 + groupInfoUpdate.getSrc().getXlId(),
  109 + groupInfoUpdate.getSrc().getScheduleDate(),
  110 + groupInfoUpdate.getSrc().getLpName(),
  111 + groupInfoUpdate.getSrc().getJsy2Id()
  112 + );
  113 + }
  114 + // 更改售票员2
  115 + if (groupInfoUpdate.getUpdate().getSpy2Id() != groupInfoUpdate.getSrc().getSpy2Id()) {
  116 + result = this.schedulePlanInfoRepository.updateGroupInfo_type_3_5_spy(
  117 + groupInfoUpdate.getUpdate().getSpy2Id(),
  118 + groupInfoUpdate.getUpdate().getSpy2Gh(),
  119 + groupInfoUpdate.getUpdate().getSpy2Name(),
  120 + groupInfoUpdate.getSrc().getXlId(),
  121 + groupInfoUpdate.getSrc().getScheduleDate(),
  122 + groupInfoUpdate.getSrc().getLpName(),
  123 + groupInfoUpdate.getSrc().getSpy2Id()
  124 + );
  125 + }
  126 +
  127 + } else {
  128 + throw new RuntimeException("未知的更新类型,type=" + type);
  129 + }
  130 +
  131 + return 0;
  132 + }
12 } 133 }
src/main/java/com/bsth/service/schedule/SchedulePlanService.java
@@ -3,31 +3,13 @@ package com.bsth.service.schedule; @@ -3,31 +3,13 @@ package com.bsth.service.schedule;
3 import com.bsth.entity.schedule.SchedulePlan; 3 import com.bsth.entity.schedule.SchedulePlan;
4 import com.bsth.service.BaseService; 4 import com.bsth.service.BaseService;
5 5
6 -import java.util.Date;  
7 -import java.util.List;  
8 -import java.util.Map;  
9 -  
10 /** 6 /**
11 * Created by xu on 16/6/16. 7 * Created by xu on 16/6/16.
12 */ 8 */
13 public interface SchedulePlanService extends BaseService<SchedulePlan, Long> { 9 public interface SchedulePlanService extends BaseService<SchedulePlan, Long> {
14 -  
15 - /**  
16 - * 查找分组排班信息。  
17 - * @param xlid 线路Id  
18 - * @param scheduleDate 排班日期  
19 - * @return  
20 - */  
21 - List<Map<String, Object>> findGroupInfo(Integer xlid, Date scheduleDate);  
22 -  
23 /** 10 /**
24 - * 更新分组排班信息。  
25 - * @param clid 车辆id  
26 - * @param clZbh 车辆自编号  
27 - * @param xlid 线路id  
28 - * @param scheduleDate 排班日期  
29 - * @param lpName 路牌名字 11 + * 获取有明日排班的计划。
30 * @return 12 * @return
31 */ 13 */
32 - int updateGroupInfo_clinfo(Integer clid, String clZbh, Integer xlid, Date scheduleDate, String lpName); 14 + SchedulePlan findSchedulePlanTommorw();
33 } 15 }
src/main/java/com/bsth/service/schedule/SchedulePlanServiceImpl.java
@@ -12,6 +12,7 @@ import com.bsth.service.schedule.rules.shiftloop.ScheduleResults_output; @@ -12,6 +12,7 @@ import com.bsth.service.schedule.rules.shiftloop.ScheduleResults_output;
12 import com.bsth.service.schedule.rules.shiftloop.ScheduleRule_input; 12 import com.bsth.service.schedule.rules.shiftloop.ScheduleRule_input;
13 import com.bsth.service.schedule.rules.strategy.IStrategy; 13 import com.bsth.service.schedule.rules.strategy.IStrategy;
14 import com.google.common.collect.Multimap; 14 import com.google.common.collect.Multimap;
  15 +import org.joda.time.DateTime;
15 import org.kie.api.KieBase; 16 import org.kie.api.KieBase;
16 import org.kie.api.runtime.KieSession; 17 import org.kie.api.runtime.KieSession;
17 import org.springframework.beans.factory.annotation.Autowired; 18 import org.springframework.beans.factory.annotation.Autowired;
@@ -122,90 +123,16 @@ public class SchedulePlanServiceImpl extends BaseServiceImpl&lt;SchedulePlan, Long&gt; @@ -122,90 +123,16 @@ public class SchedulePlanServiceImpl extends BaseServiceImpl&lt;SchedulePlan, Long&gt;
122 } 123 }
123 124
124 @Override 125 @Override
125 - public List<Map<String, Object>> findGroupInfo(Integer xlid, Date scheduleDate) {  
126 - List<Object[]> groupInfos = schedulePlanRepository.findGroupInfo(xlid, scheduleDate);  
127 - List<Map<String, Object>> ret = new ArrayList<>();  
128 - for (Object[] datas : groupInfos) {  
129 - // TODO:貌似springdata没有优雅的方式把List<Object[]>转换成List<Map<String, Object>>方法,  
130 - // TODO:可能jpa有相关标注,以后找到,此方法就作废  
131 -  
132 - Map<String, Object> map = new HashMap<>();  
133 -  
134 - // 线路名称  
135 - map.put("xlName", datas[0]);  
136 - // 排班时间  
137 - map.put("scheduleDate", datas[1]);  
138 - // 路牌名字  
139 - map.put("lpName", datas[2]);  
140 - // 车辆自编号  
141 - map.put("clZbh", datas[3]);  
142 - // 出场时间,如果有多个,需要分开  
143 - Object ccsj = datas[4];  
144 - if (ccsj != null) {  
145 - String[] ccsj_array = ((String) ccsj).split(",");  
146 - if (ccsj_array.length > 1) {  
147 - map.put("ccsj1", ccsj_array[0]);  
148 - map.put("ccsj2", ccsj_array[1]);  
149 - } else {  
150 - map.put("ccsj1", ccsj_array[0]);  
151 - }  
152 - }  
153 - // 驾驶员工号,如果有多个,需要分开  
154 - Object jsyGh = datas[5];  
155 - if (jsyGh != null) {  
156 - String[] jsyGh_array = ((String) jsyGh).split(",");  
157 - if (jsyGh_array.length > 1) {  
158 - map.put("jsy1Gh", jsyGh_array[0]);  
159 - map.put("jsy2Gh", jsyGh_array[1]);  
160 - } else {  
161 - map.put("jsy1Gh", jsyGh_array[0]);  
162 - }  
163 - }  
164 - // 驾驶员名字,如果有多个,需要分开  
165 - Object jsyName = datas[6];  
166 - if (jsyName != null) {  
167 - String[] jsyName_array = ((String) jsyName).split(",");  
168 - if (jsyName_array.length > 1) {  
169 - map.put("jsy1Name", jsyName_array[0]);  
170 - map.put("jsy2Name", jsyName_array[1]);  
171 - } else {  
172 - map.put("jsy1Name", jsyName_array[0]);  
173 - }  
174 - }  
175 - // 售票员工号,如果有多个,需要分开  
176 - Object spyGh = datas[7];  
177 - if (spyGh != null) {  
178 - String[] spyGh_array = ((String) spyGh).split(",");  
179 - if (spyGh_array.length > 1) {  
180 - map.put("spy1Gh", spyGh_array[0]);  
181 - map.put("spy2Gh", spyGh_array[1]);  
182 - } else {  
183 - map.put("spy1Gh", spyGh_array[0]);  
184 - }  
185 - }  
186 - // 售票员名字,如果有多个,需要分开  
187 - Object spyName = datas[8];  
188 - if (spyName != null) {  
189 - String[] spyName_array = ((String) spyName).split(",");  
190 - if (spyName_array.length > 1) {  
191 - map.put("spy1Name", spyName_array[0]);  
192 - map.put("spy2Name", spyName_array[1]);  
193 - } else {  
194 - map.put("spy1Name", spyName_array[0]);  
195 - }  
196 - }  
197 - // 创建时间  
198 - map.put("createDate", datas[9]);  
199 -  
200 - // TODO:可能还有其他字段  
201 -  
202 - ret.add(map); 126 + public SchedulePlan findSchedulePlanTommorw() {
  127 + DateTime today = new DateTime(new Date());
  128 + DateTime tommorw = new DateTime(today.getYear(), today.getMonthOfYear(), today.getDayOfMonth(), 0, 0).plusDays(1);
  129 + Map<String, Object> param = new HashMap<>();
  130 + param.put("scheduleFromTime_le", tommorw);
  131 + param.put("scheduleToTime_ge", tommorw);
  132 + Iterator<SchedulePlan> schedulePlanIterator = this.list(param).iterator();
  133 + if (schedulePlanIterator.hasNext()) {
  134 + return schedulePlanIterator.next();
203 } 135 }
204 - return ret;  
205 - }  
206 -  
207 - @Override  
208 - public int updateGroupInfo_clinfo(Integer clid, String clZbh, Integer xlid, Date scheduleDate, String lpName) {  
209 - return schedulePlanRepository.updateGroupInfo_clinfo(clid, clZbh, xlid, scheduleDate, lpName); 136 + return null;
210 } 137 }
211 } 138 }