Commit 88a1c131d056a4ad08b309e6fb1412f1a79074bd

Authored by 潘钊
2 parents 31bd9352 af02e4e1

Merge branch 'minhang' into pudong

# Conflicts:
#	src/main/resources/ms-jdbc.properties
Showing 29 changed files with 2380 additions and 1666 deletions

Too many changes to show.

To preserve performance only 29 of 60 files are displayed.

src/main/java/com/bsth/controller/BusIntervalController.java
... ... @@ -22,6 +22,11 @@ public class BusIntervalController {
22 22 public List<Map<String,Object>> getDir(@RequestParam Map<String, Object> map){
23 23 return busIntervalService.getDir(map);
24 24 }
  25 +
  26 + @RequestMapping(value = "/getLp", method = RequestMethod.GET)
  27 + public List<Map<String,Object>> getLp(@RequestParam Map<String, Object> map){
  28 + return busIntervalService.getLp(map);
  29 + }
25 30  
26 31 @RequestMapping(value = "/interval", method = RequestMethod.GET)
27 32 public List<Map<String,Object>> interval(@RequestParam Map<String, Object> map){
... ...
src/main/java/com/bsth/controller/oil/YlbController.java
... ... @@ -3,7 +3,9 @@ package com.bsth.controller.oil;
3 3 import java.text.ParseException;
4 4 import java.text.SimpleDateFormat;
5 5 import java.util.ArrayList;
  6 +import java.util.Calendar;
6 7 import java.util.Date;
  8 +import java.util.GregorianCalendar;
7 9 import java.util.HashMap;
8 10 import java.util.Iterator;
9 11 import java.util.List;
... ... @@ -107,8 +109,16 @@ public class YlbController extends BaseController&lt;Ylb, Integer&gt;{
107 109 try {
108 110 String rq=map.get("rq").toString();
109 111 if(!(rq=="")){
  112 +
110 113 SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
111   - map.put("rq_eq", sdf.parse(rq));
  114 + Calendar calendar = new GregorianCalendar();
  115 + calendar.setTime(sdf.parse(rq));
  116 + calendar.add(calendar.DATE,1);
  117 + Date date=calendar.getTime();
  118 + map.put("rq_ge", rq);
  119 + map.put("rq_le", sdf.format(date));
  120 + System.out.println(rq);
  121 + System.out.println(sdf.format(date));
112 122 }
113 123 } catch (ParseException e) {
114 124 // TODO Auto-generated catch block
... ...
src/main/java/com/bsth/controller/realcontrol/ScheduleRealInfoController.java
... ... @@ -131,13 +131,13 @@ public class ScheduleRealInfoController extends BaseController&lt;ScheduleRealInfo,
131 131 * @Title: adjust @Description: TODO(调整人车) @param @param id
132 132 * 班次ID @param @param nbbm 内部编码 @param @param jsy 驾驶员 @param @param spy
133 133 * 售票员 @throws
134   - */
  134 +
135 135 @RequestMapping(value = "/adjust", method = RequestMethod.POST)
136 136 public Map<String, Object> adjust(@RequestParam Long id, String nbbm, String jsy,
137 137 String spy, Integer revertLine, Integer borrowLine, String borrowTimeStr, String revertTimeStr) {
138 138 return scheduleRealInfoService.adjust(id, nbbm, jsy, spy, revertLine, borrowLine, borrowTimeStr, revertTimeStr);
139 139 }
140   -
  140 + */
141 141 /**
142 142 *
143 143 * @Title: realOutAdjust
... ... @@ -292,8 +292,9 @@ public class ScheduleRealInfoController extends BaseController&lt;ScheduleRealInfo,
292 292 }
293 293  
294 294 @RequestMapping(value = "/queryUserInfo")
295   - public List<ScheduleRealInfo> queryUserInfo(@RequestParam String line, @RequestParam String date) {
296   - return scheduleRealInfoService.queryUserInfo(line, date);
  295 + public List<ScheduleRealInfo> queryUserInfo(@RequestParam String line,
  296 + @RequestParam String date,@RequestParam String state) {
  297 + return scheduleRealInfoService.queryUserInfo(line, date,state);
297 298 }
298 299  
299 300 @RequestMapping(value = "/exportWaybill")
... ...
src/main/java/com/bsth/controller/report/ReportController.java
... ... @@ -50,23 +50,28 @@ public class ReportController {
50 50 }
51 51  
52 52 @RequestMapping(value = "/tbodyTime1", method = RequestMethod.GET)
53   - public Map<String, Object> tbodyTime1(@RequestParam String line,@RequestParam String date) {
54   - return service.tbodyTime1(line, date);
  53 + public Map<String, Object> tbodyTime1(@RequestParam String line,@RequestParam String ttinfo) {
  54 + return service.tbodyTime1(line, ttinfo);
55 55 }
56 56  
57 57 @RequestMapping(value = "/tbodyTime2", method = RequestMethod.GET)
58   - public Map<String, Object> tbodyTime2(@RequestParam String line,@RequestParam String date) {
59   - return service.tbodyTime2(line, date);
  58 + public Map<String, Object> tbodyTime2(@RequestParam String line,@RequestParam String ttinfo) {
  59 + return service.tbodyTime2(line, ttinfo);
60 60 }
61 61  
62 62 @RequestMapping(value = "/tbodyTime3", method = RequestMethod.GET)
63   - public List<Map<String, Object>> tbodyTime3(@RequestParam String line,@RequestParam String date) {
64   - return service.tbodyTime3(line, date);
  63 + public List<Map<String, Object>> tbodyTime3(@RequestParam String line,@RequestParam String ttinfo) {
  64 + return service.tbodyTime3(line, ttinfo);
65 65 }
66 66  
67 67 @RequestMapping(value = "/tbodyTime5", method = RequestMethod.GET)
68   - public List<Map<String, Object>> tbodyTime5(@RequestParam String line,@RequestParam String date) {
69   - return service.tbodyTime5(line, date);
  68 + public List<Map<String, Object>> tbodyTime5(@RequestParam String line,@RequestParam String ttinfo) {
  69 + return service.tbodyTime5(line, ttinfo);
  70 + }
  71 +
  72 + @RequestMapping(value="/getTtinfo", method = RequestMethod.GET)
  73 + public List<Map<String,Object>> getTtinfo(@RequestParam Map<String, Object> map){
  74 + return service.getTtinfo(map);
70 75 }
71 76  
72 77 }
... ...
src/main/java/com/bsth/data/LineConfigData.java
1 1 package com.bsth.data;
2 2  
3   -import java.util.Collection;
4   -import java.util.HashMap;
5   -import java.util.Iterator;
6   -import java.util.Map;
7   -import java.util.Set;
8   -
9   -import org.slf4j.Logger;
10   -import org.slf4j.LoggerFactory;
11   -import org.springframework.beans.factory.annotation.Autowired;
12   -import org.springframework.boot.CommandLineRunner;
13   -import org.springframework.stereotype.Component;
14   -
15 3 import com.bsth.entity.Line;
16 4 import com.bsth.entity.realcontrol.D80ReplyTemp;
17 5 import com.bsth.entity.realcontrol.LineConfig;
18 6 import com.bsth.oplog.normal.OpLogger;
19 7 import com.bsth.service.LineService;
20 8 import com.bsth.service.realcontrol.LineConfigService;
  9 +import org.slf4j.Logger;
  10 +import org.slf4j.LoggerFactory;
  11 +import org.springframework.beans.factory.annotation.Autowired;
  12 +import org.springframework.boot.CommandLineRunner;
  13 +import org.springframework.stereotype.Component;
  14 +
  15 +import java.util.*;
21 16  
22 17 /**
23 18 *
... ... @@ -92,7 +87,7 @@ public class LineConfigData implements CommandLineRunner {
92 87 //出场时间类型
93 88 conf.setOutConfig(1);
94 89 //进场时间类型
95   - conf.setInConfig(1);
  90 + //conf.setInConfig(1);
96 91 //短语模板
97 92 conf.setPhraseTemps("");
98 93 //调度指令模板
... ...
src/main/java/com/bsth/data/gpsdata/GpsRealData.java
... ... @@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
5 5 import com.bsth.Application;
6 6 import com.bsth.data.BasicData;
7 7 import com.bsth.data.forecast.ForecastRealServer;
  8 +import com.bsth.data.gpsdata.analyse.GeoCacheData;
8 9 import com.bsth.data.gpsdata.analyse.GpsAnalyse;
9 10 import com.bsth.data.gpsdata.recovery.GpsDataRecovery;
10 11 import com.bsth.data.schedule.DayOfSchedule;
... ... @@ -58,8 +59,6 @@ public class GpsRealData implements CommandLineRunner{
58 59 @Autowired
59 60 ForecastRealServer forecastRealServer;
60 61  
61   -
62   -
63 62 /**
64 63 * 构造函数
65 64 */
... ... @@ -72,13 +71,18 @@ public class GpsRealData implements CommandLineRunner{
72 71 @Override
73 72 public void run(String... arg0) throws Exception {
74 73 logger.info("gpsDataLoader,20,6");
75   - Application.mainServices.scheduleWithFixedDelay(gpsDataLoader, 40, 20, TimeUnit.SECONDS);
  74 + Application.mainServices.scheduleWithFixedDelay(gpsDataLoader, 40, 6, TimeUnit.SECONDS);
76 75 }
77 76  
  77 + static final long CLEAR_DIFF = 1000 * 60 * 60 * 2;
78 78 public GpsEntity add(GpsEntity gps) {
79 79 String device = gps.getDeviceId();
80 80 GpsEntity old = gpsMap.get(device);
81 81  
  82 + //断线2个小时,清除缓存数据
  83 + if(gps.getTimestamp() - old.getTimestamp() > CLEAR_DIFF && gps.getNbbm() != null)
  84 + GeoCacheData.clear(gps.getNbbm());
  85 +
82 86 //分析gps
83 87 if(isAvailable(gps) && (old == null || old.getTimestamp() != gps.getTimestamp()))
84 88 GpsAnalyse.start(gps);
... ... @@ -281,4 +285,4 @@ public class GpsRealData implements CommandLineRunner{
281 285 return;
282 286 }*/
283 287 }
284   -}
  288 +}
285 289 \ No newline at end of file
... ...
src/main/java/com/bsth/data/gpsdata/analyse/CircleQueue.java
1   -package com.bsth.data.gpsdata.analyse;
2   -
3   -import java.util.Arrays;
4   -
5   -/**
6   - * 循环队列
7   - * Created by panzhao on 2016/12/23.
8   - */
9   -public class CircleQueue<T> {
10   -
11   - /**
12   - * (循环队列)数组的容量
13   - */
14   - public int capacity;
15   -
16   - /**
17   - * 数组:保存循环队列的元素
18   - */
19   - public Object[] elementData;
20   -
21   - /**
22   - * 队头(先进先出)
23   - */
24   - public int head = 0;
25   -
26   - /**
27   - * 队尾
28   - */
29   - public int tail = 0;
30   -
31   - /**
32   - * 以指定长度的数组来创建循环队列
33   - *
34   - * @param initSize
35   - */
36   - public CircleQueue(final int initSize) {
37   - capacity = initSize;
38   - elementData = new Object[capacity];
39   - }
40   -
41   - /**
42   - * 获取循环队列的大小(包含元素的个数)
43   - */
44   - public int size() {
45   - if (isEmpty()) {
46   - return 0;
47   - } else if (isFull()) {
48   - return capacity;
49   - } else {
50   - return tail + 1;
51   - }
52   - }
53   -
54   - /**
55   - * 插入队尾一个元素
56   - */
57   - public void add(final T element) {
58   - if (isEmpty()) {
59   - elementData[0] = element;
60   - } else if (isFull()) {
61   - elementData[head] = element;
62   - head++;
63   - tail++;
64   - head = head == capacity ? 0 : head;
65   - tail = tail == capacity ? 0 : tail;
66   - } else {
67   - elementData[tail + 1] = element;
68   - tail++;
69   - }
70   - }
71   -
72   - public boolean isEmpty() {
73   - return tail == head && tail == 0 && elementData[tail] == null;
74   - }
75   -
76   - public boolean isFull() {
77   - return head != 0 && head - tail == 1 || head == 0 && tail == capacity - 1;
78   - }
79   -
80   - public void clear() {
81   - Arrays.fill(elementData, null);
82   - head = 0;
83   - tail = 0;
84   - }
85   -
86   - /**
87   - * @return 取 循环队列里的值(先进的index=0)
88   - */
89   - public Object[] getQueue() {
90   - final Object[] elementDataSort = new Object[capacity];
91   - final Object[] elementDataCopy = elementData.clone();
92   - if (isEmpty()) {
93   - } else if (isFull()) {
94   - int indexMax = capacity;
95   - int indexSort = 0;
96   - for (int i = head; i < indexMax;) {
97   - elementDataSort[indexSort] = elementDataCopy[i];
98   - indexSort++;
99   - i++;
100   - if (i == capacity) {
101   - i = 0;
102   - indexMax = head;
103   - }
104   - }
105   - } else {
106   - for (int i = 0; i < tail; i++) {
107   - elementDataSort[i] = elementDataCopy[i];
108   - }
109   - }
110   - return elementDataSort;
111   - }
112   -
113   - public T getTail(){
114   - return elementData[tail] == null?null:(T)elementData[tail];
115   - }
  1 +package com.bsth.data.gpsdata.analyse;
  2 +
  3 +import java.util.Arrays;
  4 +
  5 +/**
  6 + * 循环队列
  7 + * Created by panzhao on 2016/12/23.
  8 + */
  9 +public class CircleQueue<T> {
  10 +
  11 + /**
  12 + * (循环队列)数组的容量
  13 + */
  14 + public int capacity;
  15 +
  16 + /**
  17 + * 数组:保存循环队列的元素
  18 + */
  19 + public Object[] elementData;
  20 +
  21 + /**
  22 + * 队头(先进先出)
  23 + */
  24 + public int head = 0;
  25 +
  26 + /**
  27 + * 队尾
  28 + */
  29 + public int tail = 0;
  30 +
  31 + /**
  32 + * 以指定长度的数组来创建循环队列
  33 + *
  34 + * @param initSize
  35 + */
  36 + public CircleQueue(final int initSize) {
  37 + capacity = initSize;
  38 + elementData = new Object[capacity];
  39 + }
  40 +
  41 + /**
  42 + * 获取循环队列的大小(包含元素的个数)
  43 + */
  44 + public int size() {
  45 + if (isEmpty()) {
  46 + return 0;
  47 + } else if (isFull()) {
  48 + return capacity;
  49 + } else {
  50 + return tail + 1;
  51 + }
  52 + }
  53 +
  54 + /**
  55 + * 插入队尾一个元素
  56 + */
  57 + public void add(final T element) {
  58 + if (isEmpty()) {
  59 + elementData[0] = element;
  60 + } else if (isFull()) {
  61 + elementData[head] = element;
  62 + head++;
  63 + tail++;
  64 + head = head == capacity ? 0 : head;
  65 + tail = tail == capacity ? 0 : tail;
  66 + } else {
  67 + elementData[tail + 1] = element;
  68 + tail++;
  69 + }
  70 + }
  71 +
  72 + public boolean isEmpty() {
  73 + return tail == head && tail == 0 && elementData[tail] == null;
  74 + }
  75 +
  76 + public boolean isFull() {
  77 + return head != 0 && head - tail == 1 || head == 0 && tail == capacity - 1;
  78 + }
  79 +
  80 + public void clear() {
  81 + Arrays.fill(elementData, null);
  82 + head = 0;
  83 + tail = 0;
  84 + }
  85 +
  86 + /**
  87 + * @return 取 循环队列里的值(先进的index=0)
  88 + */
  89 + public Object[] getQueue() {
  90 + final Object[] elementDataSort = new Object[capacity];
  91 + final Object[] elementDataCopy = elementData.clone();
  92 + if (isEmpty()) {
  93 + } else if (isFull()) {
  94 + int indexMax = capacity;
  95 + int indexSort = 0;
  96 + for (int i = head; i < indexMax;) {
  97 + elementDataSort[indexSort] = elementDataCopy[i];
  98 + indexSort++;
  99 + i++;
  100 + if (i == capacity) {
  101 + i = 0;
  102 + indexMax = head;
  103 + }
  104 + }
  105 + } else {
  106 + for (int i = 0; i < tail; i++) {
  107 + elementDataSort[i] = elementDataCopy[i];
  108 + }
  109 + }
  110 + return elementDataSort;
  111 + }
  112 +
  113 + public T getTail(){
  114 + return elementData[tail] == null?null:(T)elementData[tail];
  115 + }
116 116 }
117 117 \ No newline at end of file
... ...
src/main/java/com/bsth/data/gpsdata/analyse/GeoCacheData.java
... ... @@ -50,7 +50,7 @@ public class GeoCacheData {
50 50 CircleQueue<GpsEntity> queue = gpsCacheMap.get(gps.getNbbm());
51 51 if (queue == null) {
52 52 //第一个点从站内开始
53   - if(!gps.isInstation())
  53 + if (!gps.isInstation())
54 54 return;
55 55  
56 56 queue = new CircleQueue<>(CACHE_SIZE);
... ... @@ -59,6 +59,16 @@ public class GeoCacheData {
59 59 queue.add(gps);
60 60 }
61 61  
  62 + public static void clear(String nbbm) {
  63 + try {
  64 + CircleQueue<GpsEntity> queue = gpsCacheMap.get(nbbm);
  65 + if (queue != null)
  66 + queue.clear();
  67 + } catch (Exception e) {
  68 + logger.error("", e);
  69 + }
  70 + }
  71 +
62 72 public static List<StationRoute> getStationRoute(String lineCode, int directions) {
63 73 return stationCacheMap.get(lineCode + "_" + directions);
64 74 }
... ... @@ -74,7 +84,7 @@ public class GeoCacheData {
74 84 return null;
75 85 }
76 86  
77   - public static Polygon getTccPolygon(String code){
  87 + public static Polygon getTccPolygon(String code) {
78 88 return tccMap.get(code);
79 89 }
80 90  
... ... @@ -97,7 +107,7 @@ public class GeoCacheData {
97 107 String shapesType = rs.getString("SHAPES_TYPE");
98 108 //多边形电子围栏
99 109 if (StringUtils.isNotEmpty(shapesType) && shapesType.equals("d")) {
100   - geometryFactory.createPolygon(parsePolygon(rs.getString("G_POLYGON_GRID")));
  110 + sRoute.setPolygon(geometryFactory.createPolygon(parsePolygon(rs.getString("G_POLYGON_GRID"))));
101 111 }
102 112 return sRoute;
103 113 }
... ... @@ -133,11 +143,11 @@ public class GeoCacheData {
133 143 tccTempMap.put(tMap.get("PARK_CODE").toString()
134 144 , polygon);
135 145 } catch (Exception e) {
136   - logger.error("停车场:" + tMap.get("PARK_CODE") , e);
  146 + logger.error("停车场:" + tMap.get("PARK_CODE"), e);
137 147 }
138 148 }
139 149  
140   - if(tccTempMap.size() > 0)
  150 + if (tccTempMap.size() > 0)
141 151 tccMap = tccTempMap;
142 152 }
143 153  
... ... @@ -166,5 +176,4 @@ public class GeoCacheData {
166 176 }
167 177 return cds;
168 178 }
169   -
170 179 }
171 180 \ No newline at end of file
... ...
src/main/java/com/bsth/data/gpsdata/analyse/GpsAnalyse.java
1   -package com.bsth.data.gpsdata.analyse;
2   -
3   -import com.bsth.data.gpsdata.GpsEntity;
4   -import com.bsth.data.gpsdata.analyse.components.GpsArrival;
5   -import org.slf4j.Logger;
6   -import org.slf4j.LoggerFactory;
7   -
8   -import java.util.concurrent.ExecutorService;
9   -import java.util.concurrent.Executors;
10   -
11   -/**
12   - * 分析gps状态信息
13   - * Created by panzhao on 2016/12/23.
14   - */
15   -public class GpsAnalyse {
16   -
17   - static Logger logger = LoggerFactory.getLogger(GpsAnalyse.class);
18   -
19   - //线程池
20   - static ExecutorService threadPool = Executors.newFixedThreadPool(50);
21   -
22   - public static void start(GpsEntity gps) {
23   - threadPool.execute(new ArrivalMatchThread(gps));
24   - }
25   -
26   - public static class ArrivalMatchThread implements Runnable {
27   -
28   - private GpsEntity gps;
29   -
30   - public ArrivalMatchThread(GpsEntity gps) {
31   - this.gps = gps;
32   - }
33   -
34   - @Override
35   - public void run() {
36   - GpsArrival.arrival(gps);
37   - }
38   - }
  1 +package com.bsth.data.gpsdata.analyse;
  2 +
  3 +import com.bsth.data.gpsdata.GpsEntity;
  4 +import com.bsth.data.gpsdata.analyse.components.GpsArrival;
  5 +import org.slf4j.Logger;
  6 +import org.slf4j.LoggerFactory;
  7 +
  8 +import java.util.concurrent.ExecutorService;
  9 +import java.util.concurrent.Executors;
  10 +
  11 +/**
  12 + * 分析gps状态信息
  13 + * Created by panzhao on 2016/12/23.
  14 + */
  15 +public class GpsAnalyse {
  16 +
  17 + static Logger logger = LoggerFactory.getLogger(GpsAnalyse.class);
  18 +
  19 + //线程池
  20 + static ExecutorService threadPool = Executors.newFixedThreadPool(50);
  21 +
  22 + public static void start(GpsEntity gps) {
  23 + threadPool.execute(new ArrivalMatchThread(gps));
  24 + }
  25 +
  26 + public static class ArrivalMatchThread implements Runnable {
  27 +
  28 + private GpsEntity gps;
  29 +
  30 + public ArrivalMatchThread(GpsEntity gps) {
  31 + this.gps = gps;
  32 + }
  33 +
  34 + @Override
  35 + public void run() {
  36 + GpsArrival.arrival(gps);
  37 + }
  38 + }
39 39 }
40 40 \ No newline at end of file
... ...
src/main/java/com/bsth/data/gpsdata/analyse/StationRoute.java
1   -package com.bsth.data.gpsdata.analyse;
2   -
3   -import com.vividsolutions.jts.geom.Point;
4   -import com.vividsolutions.jts.geom.Polygon;
5   -
6   -/**
7   - * Created by panzhao on 2016/12/23.
8   - */
9   -public class StationRoute {
10   -
11   - /**
12   - * 线路编码
13   - */
14   - private String lineCode;
15   -
16   - /**
17   - * 上下行
18   - */
19   - private int directions;
20   -
21   - /**
22   - * 站点编码
23   - */
24   - private String code;
25   -
26   - /**
27   - * 路由顺序
28   - */
29   - private int routeSort;
30   -
31   - /**
32   - * 站点位置
33   - */
34   - private Point point;
35   -
36   - /**
37   - * 圆形半径
38   - */
39   - private Float radius;
40   -
41   - /**
42   - * 多边形电子围栏
43   - */
44   - private Polygon polygon;
45   -
46   - /**
47   - * 站点标记
48   - */
49   - private String mark;
50   -
51   - /**
52   - * 下一站
53   - */
54   - private StationRoute next;
55   -
56   - /**
57   - * 上一站
58   - */
59   - private StationRoute prve;
60   -
61   - public String getCode() {
62   - return code;
63   - }
64   -
65   - public void setCode(String code) {
66   - this.code = code;
67   - }
68   -
69   - public int getRouteSort() {
70   - return routeSort;
71   - }
72   -
73   - public void setRouteSort(int routeSort) {
74   - this.routeSort = routeSort;
75   - }
76   -
77   - public Point getPoint() {
78   - return point;
79   - }
80   -
81   - public void setPoint(Point point) {
82   - this.point = point;
83   - }
84   -
85   - public Float getRadius() {
86   - return radius;
87   - }
88   -
89   - public void setRadius(Float radius) {
90   - this.radius = radius;
91   - }
92   -
93   - public Polygon getPolygon() {
94   - return polygon;
95   - }
96   -
97   - public void setPolygon(Polygon polygon) {
98   - this.polygon = polygon;
99   - }
100   -
101   - public String getLineCode() {
102   - return lineCode;
103   - }
104   -
105   - public void setLineCode(String lineCode) {
106   - this.lineCode = lineCode;
107   - }
108   -
109   - public int getDirections() {
110   - return directions;
111   - }
112   -
113   - public void setDirections(int directions) {
114   - this.directions = directions;
115   - }
116   -
117   - public StationRoute getNext() {
118   - return next;
119   - }
120   -
121   - public void setNext(StationRoute next) {
122   - this.next = next;
123   - }
124   -
125   - public StationRoute getPrve() {
126   - return prve;
127   - }
128   -
129   - public void setPrve(StationRoute prve) {
130   - this.prve = prve;
131   - }
132   -
133   - public String getMark() {
134   - return mark;
135   - }
136   -
137   - public void setMark(String mark) {
138   - this.mark = mark;
139   - }
140   -}
141   -
  1 +package com.bsth.data.gpsdata.analyse;
  2 +
  3 +import com.vividsolutions.jts.geom.Point;
  4 +import com.vividsolutions.jts.geom.Polygon;
  5 +
  6 +/**
  7 + * Created by panzhao on 2016/12/23.
  8 + */
  9 +public class StationRoute {
  10 +
  11 + /**
  12 + * 线路编码
  13 + */
  14 + private String lineCode;
  15 +
  16 + /**
  17 + * 上下行
  18 + */
  19 + private int directions;
  20 +
  21 + /**
  22 + * 站点编码
  23 + */
  24 + private String code;
  25 +
  26 + /**
  27 + * 路由顺序
  28 + */
  29 + private int routeSort;
  30 +
  31 + /**
  32 + * 站点位置
  33 + */
  34 + private Point point;
  35 +
  36 + /**
  37 + * 圆形半径
  38 + */
  39 + private Float radius;
  40 +
  41 + /**
  42 + * 多边形电子围栏
  43 + */
  44 + private Polygon polygon;
  45 +
  46 + /**
  47 + * 站点标记
  48 + */
  49 + private String mark;
  50 +
  51 + /**
  52 + * 下一站
  53 + */
  54 + private StationRoute next;
  55 +
  56 + /**
  57 + * 上一站
  58 + */
  59 + private StationRoute prve;
  60 +
  61 + public String getCode() {
  62 + return code;
  63 + }
  64 +
  65 + public void setCode(String code) {
  66 + this.code = code;
  67 + }
  68 +
  69 + public int getRouteSort() {
  70 + return routeSort;
  71 + }
  72 +
  73 + public void setRouteSort(int routeSort) {
  74 + this.routeSort = routeSort;
  75 + }
  76 +
  77 + public Point getPoint() {
  78 + return point;
  79 + }
  80 +
  81 + public void setPoint(Point point) {
  82 + this.point = point;
  83 + }
  84 +
  85 + public Float getRadius() {
  86 + return radius;
  87 + }
  88 +
  89 + public void setRadius(Float radius) {
  90 + this.radius = radius;
  91 + }
  92 +
  93 + public Polygon getPolygon() {
  94 + return polygon;
  95 + }
  96 +
  97 + public void setPolygon(Polygon polygon) {
  98 + this.polygon = polygon;
  99 + }
  100 +
  101 + public String getLineCode() {
  102 + return lineCode;
  103 + }
  104 +
  105 + public void setLineCode(String lineCode) {
  106 + this.lineCode = lineCode;
  107 + }
  108 +
  109 + public int getDirections() {
  110 + return directions;
  111 + }
  112 +
  113 + public void setDirections(int directions) {
  114 + this.directions = directions;
  115 + }
  116 +
  117 + public StationRoute getNext() {
  118 + return next;
  119 + }
  120 +
  121 + public void setNext(StationRoute next) {
  122 + this.next = next;
  123 + }
  124 +
  125 + public StationRoute getPrve() {
  126 + return prve;
  127 + }
  128 +
  129 + public void setPrve(StationRoute prve) {
  130 + this.prve = prve;
  131 + }
  132 +
  133 + public String getMark() {
  134 + return mark;
  135 + }
  136 +
  137 + public void setMark(String mark) {
  138 + this.mark = mark;
  139 + }
  140 +}
  141 +
... ...
src/main/java/com/bsth/data/gpsdata/analyse/StationRouteComp.java
1   -package com.bsth.data.gpsdata.analyse;
2   -
3   -import java.util.Comparator;
4   -
5   -/**
6   - * Created by panzhao on 2016/12/24.
7   - */
8   -public class StationRouteComp implements Comparator<StationRoute>{
9   - @Override
10   - public int compare(StationRoute s1, StationRoute s2) {
11   - return s1.getRouteSort() - s2.getRouteSort();
12   - }
13   -}
  1 +package com.bsth.data.gpsdata.analyse;
  2 +
  3 +import java.util.Comparator;
  4 +
  5 +/**
  6 + * Created by panzhao on 2016/12/24.
  7 + */
  8 +public class StationRouteComp implements Comparator<StationRoute>{
  9 + @Override
  10 + public int compare(StationRoute s1, StationRoute s2) {
  11 + return s1.getRouteSort() - s2.getRouteSort();
  12 + }
  13 +}
... ...
src/main/java/com/bsth/data/gpsdata/analyse/components/GpsArrival.java
... ... @@ -9,6 +9,8 @@ import com.bsth.data.gpsdata.analyse.util.GeoUtils;
9 9 import com.bsth.data.schedule.DayOfSchedule;
10 10 import com.bsth.entity.realcontrol.LineConfig;
11 11 import com.bsth.entity.realcontrol.ScheduleRealInfo;
  12 +import com.bsth.service.directive.DirectiveService;
  13 +import com.bsth.websocket.handler.SendUtils;
12 14 import org.slf4j.Logger;
13 15 import org.slf4j.LoggerFactory;
14 16 import org.springframework.beans.BeansException;
... ... @@ -28,8 +30,9 @@ public class GpsArrival implements ApplicationContextAware {
28 30 static Logger logger = LoggerFactory.getLogger(GpsArrival.class);
29 31  
30 32 static DayOfSchedule dayOfSchedule;
31   -
32 33 static LineConfigData lineConfigData;
  34 + static SendUtils sendUtils;
  35 + static DirectiveService directiveService;
33 36  
34 37 public static void arrival(GpsEntity gps) {
35 38  
... ... @@ -49,10 +52,9 @@ public class GpsArrival implements ApplicationContextAware {
49 52 //出场
50 53 if (sch.getBcType().equals("out")) {
51 54 outCarpark(gps, sch);
52   - }
53   - else if (sch.getBcType().equals("normal"))
  55 + } else if (sch.getBcType().equals("normal"))
54 56 normalInOut(gps, sch);
55   - else if(sch.getBcType().equals("in")){
  57 + else if (sch.getBcType().equals("in")) {
56 58 inCarpark(gps, sch);
57 59 }
58 60 }
... ... @@ -94,7 +96,7 @@ public class GpsArrival implements ApplicationContextAware {
94 96 * @param sch
95 97 */
96 98 private static void stationInside(GpsEntity gps, GpsEntity prev, ScheduleRealInfo sch) {
97   - if(prev == null)
  99 + if (prev == null)
98 100 return;
99 101  
100 102 if (gps.getStopNo().equals(sch.getZdzCode()) && sch.getZdsjActual() == null) {
... ... @@ -104,15 +106,16 @@ public class GpsArrival implements ApplicationContextAware {
104 106 }
105 107  
106 108 //上一个点在站外
107   - if(!prev.isInstation())
  109 + if (!prev.isInstation())
108 110 return;
109   - //超过 (待发时间 + 90%的单程运送时间),还在起点站。默认烂一圈
110   - if (prev.getStopNo().equals(gps.getStopNo())){
111   - if(gps.getStopNo().equals(sch.getQdzCode())
112   - && gps.getTimestamp() > sch.getDfsjT() + (sch.getBcsj() * 60 * 1000 * 0.9)){
113   -
114   - ScheduleRealInfo next = dayOfSchedule.next(dayOfSchedule.next(sch));
115   - dayOfSchedule.addExecPlan(next);
  111 + //超过 (待发时间 + 90%的单程运送时间) 并且超过下一个班次的待发时间,还在起点站。默认烂一圈
  112 + if (prev.getStopNo().equals(gps.getStopNo())) {
  113 + if (gps.getStopNo().equals(sch.getQdzCode())
  114 + && gps.getTimestamp() > sch.getDfsjT() + (sch.getBcsj() * 60 * 1000 * 0.9)) {
  115 +
  116 + ScheduleRealInfo next = dayOfSchedule.next(sch);
  117 + if(gps.getTimestamp() > next.getDfsjT())
  118 + dayOfSchedule.addExecPlan(dayOfSchedule.next(next));
116 119 }
117 120 return;
118 121 }
... ... @@ -123,6 +126,9 @@ public class GpsArrival implements ApplicationContextAware {
123 126 return;
124 127 }
125 128  
  129 + if (gps.getUpDown() != prev.getUpDown())
  130 + return;
  131 +
126 132 //中途站
127 133 StationRoute prevStation = GeoCacheData.getStation(prev.getLineId(), prev.getUpDown(), prev.getStopNo());
128 134 StationRoute currStation = GeoCacheData.getStation(gps.getLineId(), gps.getUpDown(), gps.getStopNo());
... ... @@ -132,7 +138,6 @@ public class GpsArrival implements ApplicationContextAware {
132 138  
133 139 logger.info("路由反向。。。。。。:" + gps.getTimestamp());
134 140 //为班次补上实际时间
135   -
136 141 }
137 142 }
138 143  
... ... @@ -144,7 +149,7 @@ public class GpsArrival implements ApplicationContextAware {
144 149 * @param sch
145 150 */
146 151 private static void stationOutside(GpsEntity gps, GpsEntity prev, ScheduleRealInfo sch) {
147   - if(prev == null)
  152 + if (prev == null)
148 153 return;
149 154  
150 155 gps.setStopNo(prev.getStopNo());
... ... @@ -159,42 +164,47 @@ public class GpsArrival implements ApplicationContextAware {
159 164 * 公交车起点发出
160 165 */
161 166 final static long DRIFT_VAL_TIME = 1000 * 60 * 10;
162   - //班次最大差值1小时
163   - final static long MAX_DIFF = 1000 * 60 * 60;
  167 + //班次最大差值2小时
  168 + final static long MAX_DIFF = 1000 * 60 * 60 * 2;
  169 +
164 170 private static void busWillDepart(ScheduleRealInfo sch, GpsEntity gps) {
165 171 //实发时间不覆盖
166 172 if (sch.getFcsjActual() == null && Math.abs(gps.getTimestamp() - sch.getDfsjT()) < MAX_DIFF) {
167 173  
168 174 //提前10分钟以上发出,判断一下是否是漂移
169   - if(sch.getDfsjT() - gps.getTimestamp() > DRIFT_VAL_TIME){
  175 + /*if (sch.getDfsjT() - gps.getTimestamp() > DRIFT_VAL_TIME) {
170 176 ScheduleRealInfo schPrev = dayOfSchedule.prev(sch);
171   - if(schPrev != null && schPrev.getZdsjActual() != null){
  177 + if (schPrev != null && schPrev.getZdsjActual() != null) {
172 178 //计划停站时间
173 179 long stopTimeJH = sch.getDfsjT() - schPrev.getZdsjT();
174 180 //实际停站时间
175 181 long actualStopTime = gps.getTimestamp() - schPrev.getZdsjActualTime();
176   - /*
177   - 没停够计划百分之60的,算漂移
  182 + *//*
  183 + 没停够计划百分之30的,算漂移
178 184 (这里出现的误判,由程序在车辆到中途站的时候进行补偿)
179   - */
180   - if(stopTimeJH * 0.6 < actualStopTime){
  185 + *//*
  186 + if (stopTimeJH * 0.3 > actualStopTime) {
181 187 logger.info("漂移.... 车辆:" + gps.getNbbm() + " ts: " + gps.getTimestamp());
182 188 return;
183 189 }
184 190 }
185   - }
  191 + }*/
186 192  
187 193 LineConfig config = lineConfigData.get(sch.getXlBm());
188   - if(config != null && config.getOutConfig() == 2){
  194 + if (config != null && config.getOutConfig() == 2) {
189 195 //出站既出场
190 196 ScheduleRealInfo schPrev = dayOfSchedule.prev(sch);
191   - if(schPrev.getBcType().equals("out")){
192   - schPrev.setFcsjActualAll(schPrev.getDfsjT());
193   - schPrev.setZdsjActualAll(schPrev.getZdsjT());
  197 + if (schPrev.getBcType().equals("out")) {
  198 + schPrev.setFcsjActualAll(gps.getTimestamp());
  199 + schPrev.setZdsjActualAll(gps.getTimestamp());
194 200 }
195 201 }
196 202  
197 203 sch.setFcsjActualAll(gps.getTimestamp());
  204 + //通知客户端
  205 + sendUtils.sendFcsj(sch);
  206 + //持久化
  207 + dayOfSchedule.save(sch);
198 208 logger.info("(站外)班次:" + sch.getDfsj() + "发车, 时间:" + sch.getFcsjActual());
199 209 }
200 210 }
... ... @@ -206,13 +216,39 @@ public class GpsArrival implements ApplicationContextAware {
206 216 * @param gps
207 217 */
208 218 private static void arriveEnd(ScheduleRealInfo sch, GpsEntity gps) {
  219 + if(Math.abs(gps.getTimestamp() - sch.getZdsjT()) >= MAX_DIFF)
  220 + return;
  221 +
209 222 sch.setZdsjActualAll(gps.getTimestamp());
210 223 ScheduleRealInfo next = finishPlan(sch);
  224 + //已完成班次数
  225 + int doneSum = dayOfSchedule.doneSum(sch.getClZbh());
  226 + //通知客户端
  227 + sendUtils.sendZdsj(sch, next, doneSum);
  228 + //持久化
  229 + dayOfSchedule.save(sch);
211 230 logger.info("班次:" + sch.getDfsj() + "到达终点, 时间:" + sch.getZdsjActual());
212 231  
213 232 if (next == null)
214 233 return;
215 234  
  235 + LineConfig config = lineConfigData.get(sch.getXlBm());
  236 + //进站既进场
  237 + if (next.getBcType().equals("in") &&
  238 + config != null && config.getOutConfig() == 2) {
  239 + next.setFcsjActualAll(gps.getTimestamp());
  240 + next.setZdsjActualAll(gps.getTimestamp());
  241 +
  242 + finishPlan(next);
  243 + } else {
  244 + //下发调度指令
  245 + directiveService.send60Dispatch(next, doneSum, "到站@系统");
  246 +
  247 + //套跑 -下发线路切换指令
  248 + /* if (!next.getXlBm().equals(sch.getXlBm()))
  249 + directiveService.lineChange(sch.getClZbh(), next.getXlBm(), "套跑@系统");*/
  250 + }
  251 +
216 252 //将gps转换为下一个班次走向的站内信号
217 253 int updown = Integer.parseInt(next.getXlDir());
218 254 List<StationRoute> srs = GeoCacheData.getStationRoute(next.getXlBm(), updown);
... ... @@ -230,39 +266,52 @@ public class GpsArrival implements ApplicationContextAware {
230 266 * @param sch
231 267 */
232 268 private static void outCarpark(GpsEntity gps, ScheduleRealInfo sch) {
  269 + CircleQueue<GpsEntity> queue = GeoCacheData.getGps(gps.getNbbm());
  270 + GpsEntity prev = null;
  271 + if (queue != null)
  272 + prev = queue.getTail();
  273 +
  274 + //是否在停车场内
233 275 String carpark = GeoUtils.gpsInCarpark(gps);
234   - if (carpark != null) {
  276 + if (carpark != null && carpark.equals(sch.getQdzCode())) {
235 277 gps.setInstation(true);
236 278 gps.setStopNo(carpark);
237 279 return; // 还在场内
238 280 }
239 281  
240   - CircleQueue<GpsEntity> queue = GeoCacheData.getGps(gps.getNbbm());
241   - if (queue == null)
242   - return;
243   - //上一个gps
244   - GpsEntity prev = queue.getTail();
245   -
246   - if (carpark == null && prev.isInstation() && prev.getStopNo().equals(sch.getQdzCode())) {
247   - gps.setStopNo(prev.getStopNo());
248   - //停车场发出
249   - busWillDepart(sch, gps);
250   - return;
251   - }
252   -
253 282 List<StationRoute> srs = GeoCacheData.getStationRoute(sch.getXlBm(), gps.getUpDown());
254 283 StationRoute station = GeoUtils.gpsInStation(gps, srs);
255   -
256   - if (station != null && station.getCode().equals(sch.getZdzCode())) {
  284 + //线路上 站点内
  285 + if (station != null) {
  286 + gps.setInstation(true);
257 287 gps.setStopNo(station.getCode());
  288 +
  289 + //上一个点附带的站点站标记
  290 + if (prev != null && prev.getStopNo() != null
  291 + && prev.getStopNo().equals(sch.getZdzCode()))
  292 + return;
  293 +
258 294 //到达终点
259   - arriveEnd(sch, gps);
  295 + if (station.getCode().equals(sch.getZdzCode()))
  296 + arriveEnd(sch, gps);
  297 + }
  298 +
  299 + //上一个点在场内
  300 + if (prev != null && prev.isInstation() && prev.getStopNo().equals(sch.getQdzCode())) {
  301 + //当前点在场外
  302 + if (carpark == null) {
  303 + gps.setStopNo(prev.getStopNo());
  304 + //停车场发出
  305 + busWillDepart(sch, gps);
  306 + return;
  307 + }
260 308 }
261 309 }
262 310  
263 311  
264 312 /**
265 313 * 进场班次
  314 + *
266 315 * @param gps
267 316 * @param sch
268 317 */
... ... @@ -270,7 +319,7 @@ public class GpsArrival implements ApplicationContextAware {
270 319 String carpark = GeoUtils.gpsInCarpark(gps);
271 320 if (carpark != null && carpark.equals(sch.getZdzCode())) {
272 321 //进场班次取第一个实际进场时间
273   - if(sch.getZdsjActual() != null)
  322 + if (sch.getZdsjActual() != null)
274 323 return;
275 324  
276 325 //进场
... ... @@ -310,5 +359,7 @@ public class GpsArrival implements ApplicationContextAware {
310 359 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
311 360 dayOfSchedule = applicationContext.getBean(DayOfSchedule.class);
312 361 lineConfigData = applicationContext.getBean(LineConfigData.class);
  362 + sendUtils = applicationContext.getBean(SendUtils.class);
  363 + directiveService = applicationContext.getBean(DirectiveService.class);
313 364 }
314 365 }
... ...
src/main/java/com/bsth/data/gpsdata/analyse/components/GpsStateCorrective.java
1   -package com.bsth.data.gpsdata.analyse.components;
2   -
3   -import com.bsth.data.gpsdata.GpsEntity;
4   -import com.bsth.data.schedule.DayOfSchedule;
5   -import com.bsth.entity.realcontrol.ScheduleRealInfo;
6   -import com.vividsolutions.jts.geom.GeometryFactory;
7   -import org.joda.time.format.DateTimeFormat;
8   -import org.joda.time.format.DateTimeFormatter;
9   -import org.slf4j.Logger;
10   -import org.slf4j.LoggerFactory;
11   -import org.springframework.beans.BeansException;
12   -import org.springframework.context.ApplicationContext;
13   -import org.springframework.context.ApplicationContextAware;
14   -import org.springframework.stereotype.Component;
15   -
16   -/**
17   - * GPS状态纠正
18   - * Created by panzhao on 2016/12/23.
19   - */
20   -@Component
21   -public class GpsStateCorrective implements ApplicationContextAware {
22   -
23   - static Logger logger = LoggerFactory.getLogger(GpsStateCorrective.class);
24   -
25   - static DayOfSchedule dayOfSchedule;
26   -
27   - private static GeometryFactory geometryFactory = new GeometryFactory();
28   -
29   - public static void correct(GpsEntity gps, ScheduleRealInfo sch){
30   -/* int upDown = Integer.parseInt(sch.getXlDir());
31   - gps.setUpDown(upDown);
32   - List<StationRoute> srs = GeoCacheData.getStationRoute(sch.getXlBm(), upDown);
33   -
34   - Point point = geometryFactory.createPoint(new Coordinate(gps.getLat(), gps.getLon()));
35   -
36   - //之前的点位
37   - CircleQueue<GpsEntity> queue = GeoCacheData.getGps(gps.getNbbm());
38   - GpsEntity prev = null;
39   - if(queue != null)
40   - prev = queue.getTail();
41   -
42   - //线路上,站点间
43   - StationRoute station = GeoUtils.pointInStation(point, srs);
44   - //在站内
45   - if(station != null){
46   - gps.setStopNo(station.getCode());
47   - gps.setInstation(true);
48   - gps.setStation(station);
49   -
50   - if(prev != null && prev.getUpDown() == upDown){
51   - StationRoute prevStation = GeoCacheData.getStation(prev.getLineId(), upDown, prev.getStopNo());
52   -
53   - //倒着开??
54   - if(prevStation.getRouteSort() > station.getRouteSort()){
55   - reversalHandle(gps, prev, sch);
56   - }
57   - }
58   - }
59   - else{
60   - if(prev != null)
61   - gps.setStopNo(prev.getStopNo());
62   - }
63   -
64   - //是否在停车场内
65   - Map<String, Polygon> carparkMap = GeoCacheData.tccMap;
66   - Set<String> codes = carparkMap.keySet();
67   - Polygon p;
68   - for(String code : codes){
69   - p = carparkMap.get(code);
70   - //场内
71   - if(p.contains(point)){
72   - gps.setCarparkNo(code);
73   - if(sch.getBcType().equals("out")){
74   - gps.setInstation(true);
75   - gps.setStopNo(code);
76   - }
77   - }
78   - }*/
79   - }
80   -
81   - private static DateTimeFormatter fmt = DateTimeFormat.forPattern("HH:mm");
82   -
83   - private static void reversalHandle(GpsEntity gps, GpsEntity prev, ScheduleRealInfo sch){
84   - /*if(sch.getBcType().equals("out") && gps.getTimestamp() < sch.getZdsjT())
85   - return;
86   -
87   - //先假设没到终点,直接开始了下一个班次
88   - ScheduleRealInfo next = dayOfSchedule.next(sch);
89   - String log = "倒着开??? nbbm: " + gps.getNbbm() + " 当前:" + gps.getStopNo() + " 上一站:" + prev.getStopNo() + " 当前班次:" + sch.getDfsj();
90   - if(next != null){
91   - dayOfSchedule.addExecPlan(next);
92   -
93   - log += (" 下一个班次:" + next.getDfsj());
94   - }
95   -
96   - log += (" GPS时间:" + fmt.print(gps.getTimestamp()));
97   -
98   - logger.info(log);*/
99   - }
100   -
101   - @Override
102   - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
103   - dayOfSchedule = applicationContext.getBean(DayOfSchedule.class);
104   - }
105   -}
  1 +package com.bsth.data.gpsdata.analyse.components;
  2 +
  3 +import com.bsth.data.gpsdata.GpsEntity;
  4 +import com.bsth.data.schedule.DayOfSchedule;
  5 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  6 +import com.vividsolutions.jts.geom.GeometryFactory;
  7 +import org.joda.time.format.DateTimeFormat;
  8 +import org.joda.time.format.DateTimeFormatter;
  9 +import org.slf4j.Logger;
  10 +import org.slf4j.LoggerFactory;
  11 +import org.springframework.beans.BeansException;
  12 +import org.springframework.context.ApplicationContext;
  13 +import org.springframework.context.ApplicationContextAware;
  14 +import org.springframework.stereotype.Component;
  15 +
  16 +/**
  17 + * GPS状态纠正
  18 + * Created by panzhao on 2016/12/23.
  19 + */
  20 +@Component
  21 +public class GpsStateCorrective implements ApplicationContextAware {
  22 +
  23 + static Logger logger = LoggerFactory.getLogger(GpsStateCorrective.class);
  24 +
  25 + static DayOfSchedule dayOfSchedule;
  26 +
  27 + private static GeometryFactory geometryFactory = new GeometryFactory();
  28 +
  29 + public static void correct(GpsEntity gps, ScheduleRealInfo sch){
  30 +/* int upDown = Integer.parseInt(sch.getXlDir());
  31 + gps.setUpDown(upDown);
  32 + List<StationRoute> srs = GeoCacheData.getStationRoute(sch.getXlBm(), upDown);
  33 +
  34 + Point point = geometryFactory.createPoint(new Coordinate(gps.getLat(), gps.getLon()));
  35 +
  36 + //之前的点位
  37 + CircleQueue<GpsEntity> queue = GeoCacheData.getGps(gps.getNbbm());
  38 + GpsEntity prev = null;
  39 + if(queue != null)
  40 + prev = queue.getTail();
  41 +
  42 + //线路上,站点间
  43 + StationRoute station = GeoUtils.pointInStation(point, srs);
  44 + //在站内
  45 + if(station != null){
  46 + gps.setStopNo(station.getCode());
  47 + gps.setInstation(true);
  48 + gps.setStation(station);
  49 +
  50 + if(prev != null && prev.getUpDown() == upDown){
  51 + StationRoute prevStation = GeoCacheData.getStation(prev.getLineId(), upDown, prev.getStopNo());
  52 +
  53 + //倒着开??
  54 + if(prevStation.getRouteSort() > station.getRouteSort()){
  55 + reversalHandle(gps, prev, sch);
  56 + }
  57 + }
  58 + }
  59 + else{
  60 + if(prev != null)
  61 + gps.setStopNo(prev.getStopNo());
  62 + }
  63 +
  64 + //是否在停车场内
  65 + Map<String, Polygon> carparkMap = GeoCacheData.tccMap;
  66 + Set<String> codes = carparkMap.keySet();
  67 + Polygon p;
  68 + for(String code : codes){
  69 + p = carparkMap.get(code);
  70 + //场内
  71 + if(p.contains(point)){
  72 + gps.setCarparkNo(code);
  73 + if(sch.getBcType().equals("out")){
  74 + gps.setInstation(true);
  75 + gps.setStopNo(code);
  76 + }
  77 + }
  78 + }*/
  79 + }
  80 +
  81 + private static DateTimeFormatter fmt = DateTimeFormat.forPattern("HH:mm");
  82 +
  83 + private static void reversalHandle(GpsEntity gps, GpsEntity prev, ScheduleRealInfo sch){
  84 + /*if(sch.getBcType().equals("out") && gps.getTimestamp() < sch.getZdsjT())
  85 + return;
  86 +
  87 + //先假设没到终点,直接开始了下一个班次
  88 + ScheduleRealInfo next = dayOfSchedule.next(sch);
  89 + String log = "倒着开??? nbbm: " + gps.getNbbm() + " 当前:" + gps.getStopNo() + " 上一站:" + prev.getStopNo() + " 当前班次:" + sch.getDfsj();
  90 + if(next != null){
  91 + dayOfSchedule.addExecPlan(next);
  92 +
  93 + log += (" 下一个班次:" + next.getDfsj());
  94 + }
  95 +
  96 + log += (" GPS时间:" + fmt.print(gps.getTimestamp()));
  97 +
  98 + logger.info(log);*/
  99 + }
  100 +
  101 + @Override
  102 + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
  103 + dayOfSchedule = applicationContext.getBean(DayOfSchedule.class);
  104 + }
  105 +}
... ...
src/main/java/com/bsth/data/gpsdata/analyse/util/GeoUtils.java
1   -package com.bsth.data.gpsdata.analyse.util;
2   -
3   -import com.bsth.data.gpsdata.GpsEntity;
4   -import com.bsth.data.gpsdata.analyse.GeoCacheData;
5   -import com.bsth.data.gpsdata.analyse.StationRoute;
6   -import com.vividsolutions.jts.geom.Coordinate;
7   -import com.vividsolutions.jts.geom.GeometryFactory;
8   -import com.vividsolutions.jts.geom.Point;
9   -import com.vividsolutions.jts.geom.Polygon;
10   -
11   -import java.util.List;
12   -import java.util.Map;
13   -import java.util.Set;
14   -
15   -/**
16   - * Created by panzhao on 2016/12/23.
17   - */
18   -public class GeoUtils {
19   -
20   - private final static double EARTHRADIUS = 6378137;
21   -
22   - private static GeometryFactory geometryFactory = new GeometryFactory();
23   - /**
24   - * gps是否在路由上的某个站内
25   - *
26   - * @param gps
27   - * @param srs
28   - * @return
29   - */
30   - public static StationRoute gpsInStation(GpsEntity gps, List<StationRoute> srs) {
31   - Point point = geometryFactory.createPoint(new Coordinate(gps.getLat(), gps.getLon()));
32   - double min = -1, distance, distance2;
33   - StationRoute stationRoute = null;
34   -
35   - for (StationRoute sr : srs) {
36   - if (sr.getPolygon() == null) {
37   - //圆形
38   - distance = getDistance(sr.getPoint(), point);//sr.getPoint().distance(point);
39   -
40   - if (distance > sr.getRadius())
41   - continue;
42   -
43   - if (min > distance || min == -1) {
44   - min = distance;
45   - stationRoute = sr;
46   - }
47   - } else {
48   - //多边形
49   - if (sr.getPolygon().contains(point)) {
50   - stationRoute = sr;
51   - break;
52   - }
53   - }
54   - }
55   - return stationRoute;
56   - }
57   -
58   - public static double getDistance(Point p1, Point p2) {
59   - double lng1 = getLoop(p1.getY(), -180, 180), lat1 = getRange(
60   - p1.getX(), -74, 74);
61   - double lng2 = getLoop(p2.getY(), -180, 180), lat2 = getRange(
62   - p2.getX(), -74, 74);
63   -
64   - double x1, x2, y1, y2;
65   - x1 = degreeToRad(lng1);
66   - y1 = degreeToRad(lat1);
67   - x2 = degreeToRad(lng2);
68   - y2 = degreeToRad(lat2);
69   - return EARTHRADIUS
70   - * Math.acos((Math.sin(y1) * Math.sin(y2) + Math.cos(y1)
71   - * Math.cos(y2) * Math.cos(x2 - x1)));
72   - }
73   -
74   - private static double getLoop(double v, double a, double b) {
75   - while (v > b) {
76   - v -= b - a;
77   - }
78   - while (v < a) {
79   - v += b - a;
80   - }
81   - return v;
82   - }
83   -
84   - private static double getRange(double v, double a, double b) {
85   - v = Math.min(Math.max(v, a), b);
86   - return v;
87   - }
88   -
89   - private static double degreeToRad(double degree) {
90   - return Math.PI * degree / 180;
91   - }
92   -
93   -
94   - /**
95   - * gps 是否在某个停车场内
96   - * @param gps
97   - * @return
98   - */
99   - public static String gpsInCarpark(GpsEntity gps){
100   - Point point = geometryFactory.createPoint(new Coordinate(gps.getLat(), gps.getLon()));
101   -
102   - Map<String, Polygon> carparkMap = GeoCacheData.tccMap;
103   - Set<String> codes = carparkMap.keySet();
104   - Polygon polygon;
105   - for(String code : codes){
106   - polygon = carparkMap.get(code);
107   - if(point.within(polygon)){
108   - return code;
109   - }
110   - }
111   - return null;
112   - }
113   -
114   - /**
115   - * 是否是有效的连续点
116   - * @param prevGps
117   - * @param gps
118   - * @return
119   - */
120   - public static boolean overdue(GpsEntity prevGps, GpsEntity gps) {
121   - return gps.getTimestamp() - prevGps.getTimestamp() < 120000;
122   - }
123   -}
  1 +package com.bsth.data.gpsdata.analyse.util;
  2 +
  3 +import com.bsth.data.gpsdata.GpsEntity;
  4 +import com.bsth.data.gpsdata.analyse.GeoCacheData;
  5 +import com.bsth.data.gpsdata.analyse.StationRoute;
  6 +import com.vividsolutions.jts.geom.Coordinate;
  7 +import com.vividsolutions.jts.geom.GeometryFactory;
  8 +import com.vividsolutions.jts.geom.Point;
  9 +import com.vividsolutions.jts.geom.Polygon;
  10 +
  11 +import java.util.List;
  12 +import java.util.Map;
  13 +import java.util.Set;
  14 +
  15 +/**
  16 + * Created by panzhao on 2016/12/23.
  17 + */
  18 +public class GeoUtils {
  19 +
  20 + private final static double EARTHRADIUS = 6378137;
  21 +
  22 + private static GeometryFactory geometryFactory = new GeometryFactory();
  23 + /**
  24 + * gps是否在路由上的某个站内
  25 + *
  26 + * @param gps
  27 + * @param srs
  28 + * @return
  29 + */
  30 + public static StationRoute gpsInStation(GpsEntity gps, List<StationRoute> srs) {
  31 + Point point = geometryFactory.createPoint(new Coordinate(gps.getLat(), gps.getLon()));
  32 + double min = -1, distance, distance2;
  33 + StationRoute stationRoute = null;
  34 +
  35 + for (StationRoute sr : srs) {
  36 + if (sr.getPolygon() == null) {
  37 + //圆形
  38 + distance = getDistance(sr.getPoint(), point);//sr.getPoint().distance(point);
  39 +
  40 + if (distance > sr.getRadius())
  41 + continue;
  42 +
  43 + if (min > distance || min == -1) {
  44 + min = distance;
  45 + stationRoute = sr;
  46 + }
  47 + } else {
  48 + //多边形
  49 + if (sr.getPolygon().contains(point)) {
  50 + stationRoute = sr;
  51 + break;
  52 + }
  53 + }
  54 + }
  55 + return stationRoute;
  56 + }
  57 +
  58 + public static double getDistance(Point p1, Point p2) {
  59 + double lng1 = getLoop(p1.getY(), -180, 180), lat1 = getRange(
  60 + p1.getX(), -74, 74);
  61 + double lng2 = getLoop(p2.getY(), -180, 180), lat2 = getRange(
  62 + p2.getX(), -74, 74);
  63 +
  64 + double x1, x2, y1, y2;
  65 + x1 = degreeToRad(lng1);
  66 + y1 = degreeToRad(lat1);
  67 + x2 = degreeToRad(lng2);
  68 + y2 = degreeToRad(lat2);
  69 + return EARTHRADIUS
  70 + * Math.acos((Math.sin(y1) * Math.sin(y2) + Math.cos(y1)
  71 + * Math.cos(y2) * Math.cos(x2 - x1)));
  72 + }
  73 +
  74 + private static double getLoop(double v, double a, double b) {
  75 + while (v > b) {
  76 + v -= b - a;
  77 + }
  78 + while (v < a) {
  79 + v += b - a;
  80 + }
  81 + return v;
  82 + }
  83 +
  84 + private static double getRange(double v, double a, double b) {
  85 + v = Math.min(Math.max(v, a), b);
  86 + return v;
  87 + }
  88 +
  89 + private static double degreeToRad(double degree) {
  90 + return Math.PI * degree / 180;
  91 + }
  92 +
  93 +
  94 + /**
  95 + * gps 是否在某个停车场内
  96 + * @param gps
  97 + * @return
  98 + */
  99 + public static String gpsInCarpark(GpsEntity gps){
  100 + Point point = geometryFactory.createPoint(new Coordinate(gps.getLat(), gps.getLon()));
  101 +
  102 + Map<String, Polygon> carparkMap = GeoCacheData.tccMap;
  103 + Set<String> codes = carparkMap.keySet();
  104 + Polygon polygon;
  105 + for(String code : codes){
  106 + polygon = carparkMap.get(code);
  107 + if(point.within(polygon)){
  108 + return code;
  109 + }
  110 + }
  111 + return null;
  112 + }
  113 +
  114 + /**
  115 + * 是否是有效的连续点
  116 + * @param prevGps
  117 + * @param gps
  118 + * @return
  119 + */
  120 + public static boolean overdue(GpsEntity prevGps, GpsEntity gps) {
  121 + return gps.getTimestamp() - prevGps.getTimestamp() < 120000;
  122 + }
  123 +}
... ...
src/main/java/com/bsth/data/gpsdata/recovery/GpsDataRecovery.java
... ... @@ -46,13 +46,14 @@ public class GpsDataRecovery {
46 46 Set<String> keys = listMap.keySet();
47 47 for (String nbbm : keys) {
48 48 threadPool.execute(new RecoveryDataThread(listMap.get(nbbm), count));
49   - /*if(nbbm.equals("W9A-250"))
  49 + /*if(nbbm.equals("W9H-003"))
50 50 new RecoveryDataThread(listMap.get(nbbm), count).run();*/
51 51 }
52 52 try {
53 53 //等待子线程结束
54 54 count.await();
55 55 logger.info("GPS 数据恢复完成....");
  56 + run = false;
56 57 } catch (InterruptedException e) {
57 58 logger.error("", e);
58 59 }
... ... @@ -67,7 +68,7 @@ public class GpsDataRecovery {
67 68 Calendar calendar = Calendar.getInstance();
68 69 int dayOfYear = calendar.get(Calendar.DAY_OF_YEAR);
69 70  
70   - String sql = "select DEVICE_ID,LAT,LON,TS,SPEED_GPS,LINE_ID,SERVICE_STATE from BSTH_C_GPS_INFO where days_year=" + dayOfYear;
  71 + String sql = "select DEVICE_ID,LAT,LON,TS,SPEED_GPS,LINE_ID,SERVICE_STATE from bsth_c_gps_info where days_year=" + dayOfYear;
71 72 JdbcTemplate jdbcTemplate = new JdbcTemplate(DBUtils_MS.getDataSource());
72 73  
73 74 List<GpsEntity> list =
... ... @@ -120,10 +121,13 @@ public class GpsDataRecovery {
120 121 //依次跑完gps
121 122 //int i = 0;
122 123 for(GpsEntity gps : list){
123   - /* i++;
124   - if(i == 383){
  124 + /* i++;
  125 + if(i == 4527){
125 126 System.out.println("aaa");
126   - }*/
  127 + }
  128 +
  129 + if(gps.getTimestamp() == 1482726071000L)
  130 + System.out.println("bbb");*/
127 131 GpsArrival.arrival(gps);
128 132 }
129 133 } catch (Exception e) {
... ... @@ -141,4 +145,4 @@ public class GpsDataRecovery {
141 145 return (int) (g1.getTimestamp() - g2.getTimestamp());
142 146 }
143 147 }
144 148 -}
  149 +}
145 150 \ No newline at end of file
... ...
src/main/java/com/bsth/data/pilot80/PilotReport.java
1 1 package com.bsth.data.pilot80;
2 2  
3   -import java.util.ArrayList;
4   -import java.util.Collection;
5   -import java.util.List;
6   -
7   -import org.slf4j.Logger;
8   -import org.slf4j.LoggerFactory;
9   -import org.springframework.beans.factory.annotation.Autowired;
10   -import org.springframework.stereotype.Component;
11   -
12 3 import com.bsth.data.BasicData;
13 4 import com.bsth.data.LineConfigData;
14 5 import com.bsth.data.gpsdata.GpsEntity;
... ... @@ -23,6 +14,14 @@ import com.bsth.repository.directive.D80Repository;
23 14 import com.bsth.service.directive.DirectiveService;
24 15 import com.bsth.websocket.handler.SendUtils;
25 16 import com.google.common.collect.ArrayListMultimap;
  17 +import org.slf4j.Logger;
  18 +import org.slf4j.LoggerFactory;
  19 +import org.springframework.beans.factory.annotation.Autowired;
  20 +import org.springframework.stereotype.Component;
  21 +
  22 +import java.util.ArrayList;
  23 +import java.util.Collection;
  24 +import java.util.List;
26 25  
27 26 /**
28 27 *
... ... @@ -180,7 +179,7 @@ public class PilotReport {
180 179 return;
181 180  
182 181 LineConfig conf = lineConfigData.get(sch.getXlBm());
183   - if(conf.getInConfig() == 1){
  182 + if(conf.getOutConfig() == 1){
184 183 //为相关班次写入进场时间
185 184 sch.setZdsjActualAll(d80.getTimestamp());
186 185  
... ...
src/main/java/com/bsth/data/schedule/DayOfSchedule.java
... ... @@ -37,547 +37,535 @@ import java.util.*;
37 37 import java.util.concurrent.TimeUnit;
38 38  
39 39 /**
40   - *
  40 + * @author PanZhao
41 41 * @ClassName: DayOfSchedule
42 42 * @Description: TODO(当日实际排班)
43   - * @author PanZhao
44 43 * @date 2016年8月15日 上午10:16:12
45   - *
46 44 */
47 45 @Component
48 46 public class DayOfSchedule implements CommandLineRunner {
49 47  
50   - Logger logger = LoggerFactory.getLogger(this.getClass());
51   -
52   - // 按车辆分组的班次数据
53   - private static ArrayListMultimap<String, ScheduleRealInfo> nbbmScheduleMap;
54   -
55   - // 班次主键映射
56   - private static Map<Long, ScheduleRealInfo> id2SchedulMap;
57   -
58   - // 车辆和排班起终点站对照(包括进出的停车场,区间起终点)
59   - private static TreeMultimap<String, String> nbbm2SEStationMap;
60   -
61   - //车辆 ——> 当前执行班次
62   - private static Map<String, ScheduleRealInfo> carExecutePlanMap;
63   -
64   - // 持久化缓冲区
65   - public static LinkedList<ScheduleRealInfo> pstBuffer;
66   -
67   - // 排序器
68   - private static ScheduleComparator.FCSJ schFCSJComparator;
69   -
70   - @Autowired
71   - LineConfigData lineConfigData;
72   -
73   - @Autowired
74   - ScheduleRealInfoRepository schRepository;
75   -
76   - @Autowired
77   - SchedulePlanInfoService schPlanService;
78   -
79   - @Autowired
80   - SchAttrCalculator schAttrCalculator;
81   -
82   - @Autowired
83   - SendUtils sendUtils;
84   -
85   - @Autowired
86   - GpsRealData gpsRealData;
87   -
88   - /** 线路当前使用的排班的日期 */
89   - public static Map<String, String> currSchDateMap;
90   -
91   - static {
92   - nbbmScheduleMap = ArrayListMultimap.create();
93   - id2SchedulMap = new HashMap<>();
94   - pstBuffer = new LinkedList<>();
95   - schFCSJComparator = new ScheduleComparator.FCSJ();
96   - currSchDateMap = new HashMap<>();
97   - nbbm2SEStationMap = TreeMultimap.create();
98   - carExecutePlanMap = new HashMap<>();
99   - }
100   -
101   - @Autowired
102   - ScheduleRefreshThread scheduleRefreshThread;
103   -
104   - @Autowired
105   - SchedulePstThread schedulePstThread;
106   -
107   - @Autowired
108   - FirstScheduleCheckThread firstScheduleCheckThread;
109   -
110   - @Autowired
111   - ScheduleLateThread scheduleLateThread;
112   -
113   - @Autowired
114   - SubmitToTrafficManage submitToTrafficManage;
115   -
116   - @Autowired
117   - LineConfigData lineConfigs;
118   -
119   - @Autowired
120   - BasicData.BasicDataLoader dataLoader;
121   -
122   - private static DateTimeFormatter fmtyyyyMMdd = DateTimeFormat.forPattern("yyyy-MM-dd")
123   - ,fmtHHmm = DateTimeFormat.forPattern("HH:mm");
124   -
125   - @Override
126   - public void run(String... arg0) throws Exception {
127   - //加载基础数据
128   - dataLoader.loadAllData();
129   - //从数据库恢复排班
130   - //dataRecovery();
131   -
132   - //翻班线程
133   - Application.mainServices.scheduleWithFixedDelay(scheduleRefreshThread, 15, 240, TimeUnit.SECONDS);
134   - //入库
135   - Application.mainServices.scheduleWithFixedDelay(schedulePstThread, 60, 60, TimeUnit.SECONDS);
136   - //首班出场指令补发器
137   -// Application.mainServices.scheduleWithFixedDelay(firstScheduleCheckThread, 30, 240, TimeUnit.SECONDS);
138   - //班次误点扫描
139   - Application.mainServices.scheduleWithFixedDelay(scheduleLateThread, 60, 60, TimeUnit.SECONDS);
140   -
141   - //每天凌晨2点20提交数据到运管处
142   - long diff = (DateUtils.getTimestamp() + 1000*60*140) - System.currentTimeMillis();
143   - if(diff < 0)
144   - diff+=(1000*60*60*24);
145   -
146   - logger.info(diff/1000/60 + "分钟之后提交到运管处");
147   - //Application.mainServices.scheduleWithFixedDelay(submitToTrafficManage, diff / 1000, 60 * 60 * 24, TimeUnit.SECONDS);
148   - }
149   -
150   - //数据恢复
151   - private void dataRecovery() {
152   - GpsDataRecovery.run = true;
153   -
154   - Collection<LineConfig> confs = lineConfigs.getAll();
155   - String lineCode, currSchDate;
156   - for(LineConfig conf : confs){
157   - lineCode = conf.getLine().getLineCode();
158   - currSchDate = calcSchDate(lineCode);
159   - //加载班次数据
160   - reloadSch(lineCode, currSchDate, false);
161   - }
  48 + Logger logger = LoggerFactory.getLogger(this.getClass());
162 49  
163   - //恢复gps数据
164   - GpsDataRecovery.recovery();
165   - }
166   -
167   - public Map<String, String> getCurrSchDate() {
168   - return currSchDateMap;
169   - }
170   -
171   - /**
172   - *
173   - * @Title: calcSchDateB
174   - * @Description: TODO(计算线路当前应该使用的排班日期)
175   - */
176   - public String calcSchDate(String lineCode) {
177   - LineConfig conf = lineConfigData.get(lineCode);
178   - long ct = System.currentTimeMillis();
179   -
180   - String schDate = fmtyyyyMMdd.print(ct);
181   - // 小于当天起始运营时间,则取前一天的排班
182   - if (ct < conf.getCurrStartTime())
183   - schDate = DateUtils.subtractDay(schDate, 1);
184   -
185   - return schDate;
186   - }
187   -
188   - /**
189   - * @Title: reloadSch
190   - * @Title: reloadSch
191   - * @Description: TODO(重新载入排班)
192   - * @param @param
193   - * lineCode 线路编码
194   - * @param @param
195   - * schDate 班次日期 yyyy-MM-dd
196   - * @param @param
197   - * forcePlan 强制从计划调度重新抓取
198   - */
199   - public int reloadSch(String lineCode, String schDate, boolean forcePlan) {
200   - try {
201   - List<ScheduleRealInfo> list;
202   -
203   - if (forcePlan)
204   - removeRealSch(lineCode, schDate);
205   - else
206   - clearRAMData(lineCode);
207   -
208   - if (existRealSch(lineCode, schDate))
209   - list = loadRealSch(lineCode, schDate);// 从实际排班表加载
210   - else {
211   - list = loadPlanSch(lineCode, schDate);// 从计划排班表加载
212   - // 写入数据库
213   - batchSave(list);
214   - }
215   -
216   - //更新线路和班次日期对照
217   - currSchDateMap.put(lineCode, schDate);
218   - //添加到缓存
219   - putAll(list);
220   -
221   - Set<String> cars = searchAllCars(list);
222   - for(String nbbm : cars){
223   - //计算“起点站应到”时间
224   - schAttrCalculator.calcQdzTimePlan(nbbmScheduleMap.get(nbbm));
225   - //车辆 ——> 要执行的班次对照
226   - carExecutePlanMap.put(nbbm, schAttrCalculator.calcCurrentExecSch(nbbmScheduleMap.get(nbbm)));
227   - }
228   -
229   - //是否是出站即出场
230   - LineConfig conf = lineConfigData.get(lineCode);
231   - if(conf.getOutConfig() == 2){
232   - for(String nbbm : cars)
233   - schAttrCalculator.connectOutSchedule(nbbmScheduleMap.get(nbbm));
234   - }
235   -
236   - // 页面 翻班通知
237   - sendUtils.shiftSchedule(lineCode);
238   - } catch (Exception e) {
239   - logger.error("", e);
240   - return -1;
241   - }
  50 + // 按车辆分组的班次数据
  51 + private static ArrayListMultimap<String, ScheduleRealInfo> nbbmScheduleMap;
242 52  
243   - return 0;
244   - }
245   -
246   - /**
247   - *
248   - * @Title: searchAllCars
249   - * @Description: TODO(搜索班次集合中的车辆)
250   - */
251   - private Set<String> searchAllCars(List<ScheduleRealInfo> list) {
252   - Set<String> cars = new HashSet<>();
253   - for(ScheduleRealInfo sch : list)
254   - cars.add(sch.getClZbh());
255   -
256   - return cars;
257   - }
258   -
259   - private void putAll(List<ScheduleRealInfo> list) {
260   - for (ScheduleRealInfo sch : list)
261   - put(sch);
262   - }
263   -
264   - /**
265   - * @Title: removeRealSch
266   - * @Description: TODO(清除实际排班,包括数据库和内存数据)
267   - * @param @param
268   - * lineCode 线路编码
269   - * @param @param
270   - * schDate 班次日期 yyyy-MM-dd
271   - */
272   - public void removeRealSch(String lineCode, String schDate) throws Exception {
273   - try {
274   - // 清理数据库数据
275   - schRepository.deleteByLineCodeAndDate(lineCode + "", schDate);
276   -
277   - // 清理内存数据
278   - clearRAMData(lineCode + "");
279   - } catch (Exception e) {
280   - logger.error("removeRealSch error, " + lineCode + " -" + schDate, e);
281   - throw e;
282   - }
283   - }
284   -
285   - /**
286   - *
287   - * @Title: clearRAMData
288   - * @Description: TODO(清理内存数据)
289   - */
290   - public void clearRAMData(String lineCode) {
291   - int count = 0;
292   - List<ScheduleRealInfo> remList = new ArrayList<>();
293   - Collection<ScheduleRealInfo> schs = nbbmScheduleMap.values();
294   - for (ScheduleRealInfo sch : schs) {
295   - if (sch.getXlBm().equals(lineCode))
296   - remList.add(sch);
297   - }
298   -
299   - for(ScheduleRealInfo sch : remList){
300   - if(null != sch){
301   - nbbmScheduleMap.remove(sch.getClZbh(), sch);
302   - id2SchedulMap.remove(sch.getId());
303   - count ++;
304   - }
305   - }
306   -
307   - logger.info(lineCode + "排班清理 " + count);
308   - }
309   -
310   - /**
311   - * @Title: existRealSch
312   - * @Description: TODO(实际排班是否已存在)
313   - */
314   - public boolean existRealSch(String lineCode, String schDate) {
315   - int count = schRepository.countByLineCodeAndDate(lineCode, schDate);
316   - return count > 0;
317   - }
318   -
319   - /**
320   - * @Title: loadRealSch
321   - * @Description: TODO(从实际排班表加载数据)
322   - */
323   - public List<ScheduleRealInfo> loadRealSch(String lineCode, String schDate) {
324   - return schRepository.findByLineCodeAndDate(lineCode, schDate);
325   - }
326   -
327   - /**
328   - * @Title: loadPlanSch
329   - * @Description: TODO(从计划排班表加载数据)
330   - */
331   - public List<ScheduleRealInfo> loadPlanSch(String lineCode, String schDate) {
332   - logger.info("从计划排班表恢复排班,lineCode: " + lineCode + ", schDate: " + schDate);
333   - List<ScheduleRealInfo> realList = new ArrayList<>();
334   -
335   - try {
336   - Map<String, Object> data = new HashMap<>();
337   -
338   - data.put("scheduleDate_eq", fmtyyyyMMdd.parseDateTime(schDate).toDate());
339   - data.put("xlBm_eq", lineCode);
340   -
341   - // 查询计划排班
342   - List<SchedulePlanInfo> planItr = cleanSchPlanItr(schPlanService.list(data).iterator());
343   -
344   - // 转换为实际排班
345   - realList = JSONArray.parseArray(JSON.toJSONString(planItr), ScheduleRealInfo.class);
346   -
347   - SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
348   - String fcsj;
349   - for (ScheduleRealInfo sch : realList) {
350   - sch.setScheduleDateStr(fmtyyyyMMdd.print(sch.getScheduleDate().getTime()));
351   - sch.setRealExecDate(sch.getScheduleDateStr());
352   -
353   - if(StringUtils.isEmpty(sch.getFcsj()))
354   - sch.setFcsj("00:00");
355   -
356   - fcsj=sch.getFcsj().trim();
357   - //处理一下发车时间格式没有:号的问题
358   - if(fcsj.indexOf(":") == -1 && fcsj.length() >= 4){
359   - sch.setFcsj(fcsj.substring(0, 2) + ":" + fcsj.substring(2, 4));
360   - }
361   -
362   - try {
363   - sdf.parse(sch.getFcsj());
364   - } catch (ParseException e) {
365   - //发车时间仍然校验不过的,直接写成00:00
366   - sch.setFcsj("00:00");
367   - }
368   - sch.setDfsj(sch.getFcsj());
369   -
370   - // 计划终点时间
371   - if (sch.getBcsj() != null) {
372   - sch.setZdsj(fmtHHmm.print(fmtHHmm.parseMillis(sch.getFcsj()) + (sch.getBcsj() * 60 * 1000)));
373   - sch.setLate(false);
374   - }
375   - //计划里程为0,设置NULL
376   - if(sch.getJhlc() != null && sch.getJhlc() == 0)
377   - sch.setJhlc(null);
378   - }
379   - } catch (Exception e) {
380   - logger.error("", e);
381   - }
382   - return realList;
383   - }
384   -
385   - /**
386   - * @Title: batchSave
387   - * @Description: TODO(批量入库)
388   - */
389   - private void batchSave(List<ScheduleRealInfo> list) {
390   - // 查询数据库最大ID
391   - Long id = schRepository.getMaxId();
392   - if (null == id)
393   - id = 0L;
394   - id++;
395   -
396   - SimpleDateFormat sdfyyyyMMdd = new SimpleDateFormat("yyyy-MM-dd");
397   - for (ScheduleRealInfo item : list) {
398   - item.setSpId(item.getId());// 保留原始的计划ID
399   - item.setId(id++);// 设置ID
400   - item.setScheduleDateStr(sdfyyyyMMdd.format(item.getScheduleDate()));
401   - }
  53 + // 班次主键映射
  54 + private static Map<Long, ScheduleRealInfo> id2SchedulMap;
402 55  
403   - // 入库
404   - new BatchSaveUtils<ScheduleRealInfo>().saveList(list, ScheduleRealInfo.class);
405   - }
  56 + // 车辆和排班起终点站对照(包括进出的停车场,区间起终点)
  57 + private static TreeMultimap<String, String> nbbm2SEStationMap;
406 58  
407   - private List<SchedulePlanInfo> cleanSchPlanItr(Iterator<SchedulePlanInfo> itrab) {
408   - List<SchedulePlanInfo> list = new ArrayList<>();
  59 + //车辆 ——> 当前执行班次
  60 + private static Map<String, ScheduleRealInfo> carExecutePlanMap;
409 61  
410   - SchedulePlanInfo sp;
411   - while (itrab.hasNext()) {
412   - sp = itrab.next();
413   - sp.setSchedulePlan(null);
414   - list.add(sp);
415   - }
416   - return list;
417   - }
418   -
419   - /**
420   - *
421   - * @Title: findByLineCode
422   - * @Description: TODO(lineCode 获取班次)
423   - */
424   - public List<ScheduleRealInfo> findByLineCode(String lineCode) {
425   - List<ScheduleRealInfo> rs = new ArrayList<>();
  62 + // 持久化缓冲区
  63 + public static LinkedList<ScheduleRealInfo> pstBuffer;
426 64  
427   - Collection<ScheduleRealInfo> schs = nbbmScheduleMap.values();
428   - for (ScheduleRealInfo sch : schs) {
429   - if (sch.getXlBm().equals(lineCode))
430   - rs.add(sch);
431   - }
432   - return rs;
433   - }
434   -
435   - /**
436   - *
437   - * @Title: findCarByLineCode
438   - * @Description: TODO(线路下运营的车辆)
439   - */
440   - public Set<String> findCarByLineCode(String lineCode){
441   - Set<String> rs = new HashSet<>();
442   -
443   - Collection<ScheduleRealInfo> schs = nbbmScheduleMap.values();
444   - for (ScheduleRealInfo sch : schs) {
445   - if (sch.getXlBm().equals(lineCode))
446   - rs.add(sch.getClZbh());
447   - }
448   -
449   - return rs;
450   - }
451   -
452   - public List<ScheduleRealInfo> findByNbbm(String nbbm) {
453   - return nbbmScheduleMap.get(nbbm);
454   - }
455   -
456   - /**
457   - *
458   - * @Title: findByLineAndUpDown
459   - * @Description: TODO(lineCode 和走向获取班次)
460   - */
461   - public List<ScheduleRealInfo> findByLineAndUpDown(String lineCode, Integer upDown) {
462   - List<ScheduleRealInfo> list = findByLineCode(lineCode), rs = new ArrayList<>();
463   -
464   - for (ScheduleRealInfo sch : list) {
465   - if (sch.getXlDir().equals(upDown + ""))
466   - rs.add(sch);
467   - }
468   - return rs;
469   - }
470   -
471   - public ScheduleRealInfo get(long id) {
472   - return id2SchedulMap.get(id);
473   - }
474   -
475   - public Set<String> getSEStationList(String nbbm) {
476   - return nbbm2SEStationMap.get(nbbm);
477   - }
478   -
479   - /**
480   - *
481   - * @Title: next
482   - * @Description: TODO(下一个班次)
483   - */
484   - public ScheduleRealInfo next(ScheduleRealInfo sch) {
485   -
486   - List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());
487   - int outConfig = -1;
488   - LineConfig config = lineConfigData.get(sch.getXlBm());
489   - if(config != null)
490   - outConfig = config.getOutConfig();
491   -
492   - boolean flag = false;
493   - ScheduleRealInfo next = null;
494   - for(ScheduleRealInfo temp : list){
495   - if(temp.getId() == sch.getId()){
496   - flag = true;
497   - continue;
498   - }
499   - //忽略烂班
500   - if(temp.isDestroy())
501   - continue;
  65 + // 排序器
  66 + private static ScheduleComparator.FCSJ schFCSJComparator;
502 67  
503   - //出站既出场,忽略出场班次
504   - if(outConfig == 2 && temp.getBcType().equals("out"))
505   - continue;
506   -
507   - if(flag){
508   - next = temp;
509   - break;
510   - }
511   - }
512   - return next;
513   - }
514   -
515   - /**
516   - * 上一个班次
517   - * @param sch
518   - * @return
519   - */
520   - public ScheduleRealInfo prev(ScheduleRealInfo sch){
521   - List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());
522   -
523   - //boolean flag = false;
524   - ScheduleRealInfo prev = null;
525   - int size = list.size();
526   -
527   - for(int i = 0; i < size; i ++){
528   - if(list.get(i).isDestroy())
529   - continue;
  68 + @Autowired
  69 + LineConfigData lineConfigData;
  70 +
  71 + @Autowired
  72 + ScheduleRealInfoRepository schRepository;
  73 +
  74 + @Autowired
  75 + SchedulePlanInfoService schPlanService;
  76 +
  77 + @Autowired
  78 + SchAttrCalculator schAttrCalculator;
  79 +
  80 + @Autowired
  81 + SendUtils sendUtils;
  82 +
  83 + @Autowired
  84 + GpsRealData gpsRealData;
  85 +
  86 + /**
  87 + * 线路当前使用的排班的日期
  88 + */
  89 + public static Map<String, String> currSchDateMap;
  90 +
  91 + static {
  92 + nbbmScheduleMap = ArrayListMultimap.create();
  93 + id2SchedulMap = new HashMap<>();
  94 + pstBuffer = new LinkedList<>();
  95 + schFCSJComparator = new ScheduleComparator.FCSJ();
  96 + currSchDateMap = new HashMap<>();
  97 + nbbm2SEStationMap = TreeMultimap.create();
  98 + carExecutePlanMap = new HashMap<>();
  99 + }
  100 +
  101 + @Autowired
  102 + ScheduleRefreshThread scheduleRefreshThread;
  103 +
  104 + @Autowired
  105 + SchedulePstThread schedulePstThread;
  106 +
  107 + @Autowired
  108 + FirstScheduleCheckThread firstScheduleCheckThread;
  109 +
  110 + @Autowired
  111 + ScheduleLateThread scheduleLateThread;
  112 +
  113 + @Autowired
  114 + SubmitToTrafficManage submitToTrafficManage;
  115 +
  116 + @Autowired
  117 + LineConfigData lineConfigs;
  118 +
  119 + @Autowired
  120 + BasicData.BasicDataLoader dataLoader;
  121 +
  122 + private static DateTimeFormatter fmtyyyyMMdd = DateTimeFormat.forPattern("yyyy-MM-dd"), fmtHHmm = DateTimeFormat.forPattern("HH:mm");
  123 +
  124 + @Override
  125 + public void run(String... arg0) throws Exception {
  126 + //加载基础数据
  127 + dataLoader.loadAllData();
  128 + //从数据库恢复排班
  129 + //dataRecovery();
  130 +
  131 + //翻班线程
  132 + Application.mainServices.scheduleWithFixedDelay(scheduleRefreshThread, 15, 240, TimeUnit.SECONDS);
  133 + //入库
  134 + Application.mainServices.scheduleWithFixedDelay(schedulePstThread, 60, 60, TimeUnit.SECONDS);
  135 + //首班出场指令补发器
  136 +// Application.mainServices.scheduleWithFixedDelay(firstScheduleCheckThread, 30, 240, TimeUnit.SECONDS);
  137 + //班次误点扫描
  138 + Application.mainServices.scheduleWithFixedDelay(scheduleLateThread, 60, 60, TimeUnit.SECONDS);
  139 +
  140 + //每天凌晨2点20提交数据到运管处
  141 + long diff = (DateUtils.getTimestamp() + 1000 * 60 * 140) - System.currentTimeMillis();
  142 + if (diff < 0)
  143 + diff += (1000 * 60 * 60 * 24);
  144 +
  145 + logger.info(diff / 1000 / 60 + "分钟之后提交到运管处");
  146 + //Application.mainServices.scheduleWithFixedDelay(submitToTrafficManage, diff / 1000, 60 * 60 * 24, TimeUnit.SECONDS);
  147 + }
  148 +
  149 + //数据恢复
  150 + private void dataRecovery() {
  151 + GpsDataRecovery.run = true;
  152 +
  153 + Collection<LineConfig> confs = lineConfigs.getAll();
  154 + String lineCode, currSchDate;
  155 + for (LineConfig conf : confs) {
  156 + lineCode = conf.getLine().getLineCode();
  157 + currSchDate = calcSchDate(lineCode);
  158 + //加载班次数据
  159 + reloadSch(lineCode, currSchDate, false);
  160 + }
  161 +
  162 + //恢复gps数据
  163 + GpsDataRecovery.recovery();
  164 + }
  165 +
  166 + public Map<String, String> getCurrSchDate() {
  167 + return currSchDateMap;
  168 + }
  169 +
  170 + /**
  171 + * @Title: calcSchDateB
  172 + * @Description: TODO(计算线路当前应该使用的排班日期)
  173 + */
  174 + public String calcSchDate(String lineCode) {
  175 + LineConfig conf = lineConfigData.get(lineCode);
  176 + long ct = System.currentTimeMillis();
  177 +
  178 + String schDate = fmtyyyyMMdd.print(ct);
  179 + // 小于当天起始运营时间,则取前一天的排班
  180 + if (ct < conf.getCurrStartTime())
  181 + schDate = DateUtils.subtractDay(schDate, 1);
  182 +
  183 + return schDate;
  184 + }
  185 +
  186 + /**
  187 + * @param @param lineCode 线路编码
  188 + * @param @param schDate 班次日期 yyyy-MM-dd
  189 + * @param @param forcePlan 强制从计划调度重新抓取
  190 + * @Title: reloadSch
  191 + * @Title: reloadSch
  192 + * @Description: TODO(重新载入排班)
  193 + */
  194 + public int reloadSch(String lineCode, String schDate, boolean forcePlan) {
  195 + try {
  196 + List<ScheduleRealInfo> list;
  197 +
  198 + if (forcePlan)
  199 + removeRealSch(lineCode, schDate);
  200 + else
  201 + clearRAMData(lineCode);
  202 +
  203 + if (existRealSch(lineCode, schDate))
  204 + list = loadRealSch(lineCode, schDate);// 从实际排班表加载
  205 + else {
  206 + list = loadPlanSch(lineCode, schDate);// 从计划排班表加载
  207 + // 写入数据库
  208 + batchSave(list);
  209 + }
  210 +
  211 + //更新线路和班次日期对照
  212 + currSchDateMap.put(lineCode, schDate);
  213 + //添加到缓存
  214 + putAll(list);
  215 +
  216 + Set<String> cars = searchAllCars(list);
  217 + for (String nbbm : cars) {
  218 + //计算“起点站应到”时间
  219 + schAttrCalculator.calcQdzTimePlan(nbbmScheduleMap.get(nbbm));
  220 + //车辆 ——> 要执行的班次对照
  221 + reCalcExecPlan(nbbm);
  222 + }
  223 +
  224 + //是否是出站即出场
  225 + LineConfig conf = lineConfigData.get(lineCode);
  226 + if (conf.getOutConfig() == 2) {
  227 + for (String nbbm : cars)
  228 + schAttrCalculator.connectOutSchedule(nbbmScheduleMap.get(nbbm));
  229 + }
  230 +
  231 + // 页面 翻班通知
  232 + sendUtils.shiftSchedule(lineCode);
  233 + } catch (Exception e) {
  234 + logger.error("", e);
  235 + return -1;
  236 + }
  237 +
  238 + return 0;
  239 + }
  240 +
  241 + /**
  242 + * @Title: searchAllCars
  243 + * @Description: TODO(搜索班次集合中的车辆)
  244 + */
  245 + private Set<String> searchAllCars(List<ScheduleRealInfo> list) {
  246 + Set<String> cars = new HashSet<>();
  247 + for (ScheduleRealInfo sch : list)
  248 + cars.add(sch.getClZbh());
  249 +
  250 + return cars;
  251 + }
  252 +
  253 + private void putAll(List<ScheduleRealInfo> list) {
  254 + for (ScheduleRealInfo sch : list)
  255 + put(sch);
  256 + }
  257 +
  258 + /**
  259 + * @param @param lineCode 线路编码
  260 + * @param @param schDate 班次日期 yyyy-MM-dd
  261 + * @Title: removeRealSch
  262 + * @Description: TODO(清除实际排班,包括数据库和内存数据)
  263 + */
  264 + public void removeRealSch(String lineCode, String schDate) throws Exception {
  265 + try {
  266 + // 清理数据库数据
  267 + schRepository.deleteByLineCodeAndDate(lineCode + "", schDate);
  268 +
  269 + // 清理内存数据
  270 + clearRAMData(lineCode + "");
  271 + } catch (Exception e) {
  272 + logger.error("removeRealSch error, " + lineCode + " -" + schDate, e);
  273 + throw e;
  274 + }
  275 + }
  276 +
  277 + /**
  278 + * @Title: clearRAMData
  279 + * @Description: TODO(清理内存数据)
  280 + */
  281 + public void clearRAMData(String lineCode) {
  282 + int count = 0;
  283 + List<ScheduleRealInfo> remList = new ArrayList<>();
  284 + Collection<ScheduleRealInfo> schs = nbbmScheduleMap.values();
  285 + for (ScheduleRealInfo sch : schs) {
  286 + if (sch.getXlBm().equals(lineCode))
  287 + remList.add(sch);
  288 + }
  289 +
  290 + for (ScheduleRealInfo sch : remList) {
  291 + if (null != sch) {
  292 + nbbmScheduleMap.remove(sch.getClZbh(), sch);
  293 + id2SchedulMap.remove(sch.getId());
  294 + count++;
  295 + }
  296 + }
  297 +
  298 + logger.info(lineCode + "排班清理 " + count);
  299 + }
  300 +
  301 + /**
  302 + * @Title: existRealSch
  303 + * @Description: TODO(实际排班是否已存在)
  304 + */
  305 + public boolean existRealSch(String lineCode, String schDate) {
  306 + int count = schRepository.countByLineCodeAndDate(lineCode, schDate);
  307 + return count > 0;
  308 + }
  309 +
  310 + /**
  311 + * @Title: loadRealSch
  312 + * @Description: TODO(从实际排班表加载数据)
  313 + */
  314 + public List<ScheduleRealInfo> loadRealSch(String lineCode, String schDate) {
  315 + return schRepository.findByLineCodeAndDate(lineCode, schDate);
  316 + }
  317 +
  318 + /**
  319 + * @Title: loadPlanSch
  320 + * @Description: TODO(从计划排班表加载数据)
  321 + */
  322 + public List<ScheduleRealInfo> loadPlanSch(String lineCode, String schDate) {
  323 + logger.info("从计划排班表恢复排班,lineCode: " + lineCode + ", schDate: " + schDate);
  324 + List<ScheduleRealInfo> realList = new ArrayList<>();
  325 +
  326 + try {
  327 + Map<String, Object> data = new HashMap<>();
  328 +
  329 + data.put("scheduleDate_eq", fmtyyyyMMdd.parseDateTime(schDate).toDate());
  330 + data.put("xlBm_eq", lineCode);
  331 +
  332 + // 查询计划排班
  333 + List<SchedulePlanInfo> planItr = cleanSchPlanItr(schPlanService.list(data).iterator());
  334 +
  335 + // 转换为实际排班
  336 + realList = JSONArray.parseArray(JSON.toJSONString(planItr), ScheduleRealInfo.class);
  337 +
  338 + SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
  339 + String fcsj;
  340 + for (ScheduleRealInfo sch : realList) {
  341 + sch.setScheduleDateStr(fmtyyyyMMdd.print(sch.getScheduleDate().getTime()));
  342 + sch.setRealExecDate(sch.getScheduleDateStr());
  343 +
  344 + if (StringUtils.isEmpty(sch.getFcsj()))
  345 + sch.setFcsj("00:00");
  346 +
  347 + fcsj = sch.getFcsj().trim();
  348 + //处理一下发车时间格式没有:号的问题
  349 + if (fcsj.indexOf(":") == -1 && fcsj.length() >= 4) {
  350 + sch.setFcsj(fcsj.substring(0, 2) + ":" + fcsj.substring(2, 4));
  351 + }
  352 +
  353 + try {
  354 + sdf.parse(sch.getFcsj());
  355 + } catch (ParseException e) {
  356 + //发车时间仍然校验不过的,直接写成00:00
  357 + sch.setFcsj("00:00");
  358 + }
  359 + sch.setDfsj(sch.getFcsj());
  360 +
  361 + // 计划终点时间
  362 + if (sch.getBcsj() != null) {
  363 + sch.setZdsj(fmtHHmm.print(fmtHHmm.parseMillis(sch.getFcsj()) + (sch.getBcsj() * 60 * 1000)));
  364 + sch.setLate(false);
  365 + }
  366 + //计划里程为0,设置NULL
  367 + if (sch.getJhlc() != null && sch.getJhlc() == 0)
  368 + sch.setJhlc(null);
  369 + }
  370 + } catch (Exception e) {
  371 + logger.error("", e);
  372 + }
  373 + return realList;
  374 + }
  375 +
  376 + /**
  377 + * @Title: batchSave
  378 + * @Description: TODO(批量入库)
  379 + */
  380 + private void batchSave(List<ScheduleRealInfo> list) {
  381 + // 查询数据库最大ID
  382 + Long id = schRepository.getMaxId();
  383 + if (null == id)
  384 + id = 0L;
  385 + id++;
  386 +
  387 + SimpleDateFormat sdfyyyyMMdd = new SimpleDateFormat("yyyy-MM-dd");
  388 + for (ScheduleRealInfo item : list) {
  389 + item.setSpId(item.getId());// 保留原始的计划ID
  390 + item.setId(id++);// 设置ID
  391 + item.setScheduleDateStr(sdfyyyyMMdd.format(item.getScheduleDate()));
  392 + }
  393 +
  394 + // 入库
  395 + new BatchSaveUtils<ScheduleRealInfo>().saveList(list, ScheduleRealInfo.class);
  396 + }
  397 +
  398 + private List<SchedulePlanInfo> cleanSchPlanItr(Iterator<SchedulePlanInfo> itrab) {
  399 + List<SchedulePlanInfo> list = new ArrayList<>();
  400 +
  401 + SchedulePlanInfo sp;
  402 + while (itrab.hasNext()) {
  403 + sp = itrab.next();
  404 + sp.setSchedulePlan(null);
  405 + list.add(sp);
  406 + }
  407 + return list;
  408 + }
  409 +
  410 + /**
  411 + * @Title: findByLineCode
  412 + * @Description: TODO(lineCode 获取班次)
  413 + */
  414 + public List<ScheduleRealInfo> findByLineCode(String lineCode) {
  415 + List<ScheduleRealInfo> rs = new ArrayList<>();
  416 +
  417 + Collection<ScheduleRealInfo> schs = nbbmScheduleMap.values();
  418 + for (ScheduleRealInfo sch : schs) {
  419 + if (sch.getXlBm().equals(lineCode))
  420 + rs.add(sch);
  421 + }
  422 + return rs;
  423 + }
  424 +
  425 + /**
  426 + * @Title: findCarByLineCode
  427 + * @Description: TODO(线路下运营的车辆)
  428 + */
  429 + public Set<String> findCarByLineCode(String lineCode) {
  430 + Set<String> rs = new HashSet<>();
  431 +
  432 + Collection<ScheduleRealInfo> schs = nbbmScheduleMap.values();
  433 + for (ScheduleRealInfo sch : schs) {
  434 + if (sch.getXlBm().equals(lineCode))
  435 + rs.add(sch.getClZbh());
  436 + }
  437 +
  438 + return rs;
  439 + }
  440 +
  441 + public List<ScheduleRealInfo> findByNbbm(String nbbm) {
  442 + return nbbmScheduleMap.get(nbbm);
  443 + }
  444 +
  445 + /**
  446 + * @Title: findByLineAndUpDown
  447 + * @Description: TODO(lineCode 和走向获取班次)
  448 + */
  449 + public List<ScheduleRealInfo> findByLineAndUpDown(String lineCode, Integer upDown) {
  450 + List<ScheduleRealInfo> list = findByLineCode(lineCode), rs = new ArrayList<>();
  451 +
  452 + for (ScheduleRealInfo sch : list) {
  453 + if (sch.getXlDir().equals(upDown + ""))
  454 + rs.add(sch);
  455 + }
  456 + return rs;
  457 + }
  458 +
  459 + public ScheduleRealInfo get(long id) {
  460 + return id2SchedulMap.get(id);
  461 + }
  462 +
  463 + public Set<String> getSEStationList(String nbbm) {
  464 + return nbbm2SEStationMap.get(nbbm);
  465 + }
  466 +
  467 + /**
  468 + * @Title: next
  469 + * @Description: TODO(下一个班次)
  470 + */
  471 + public ScheduleRealInfo next(ScheduleRealInfo sch) {
  472 +
  473 + List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());
  474 + int outConfig = -1;
  475 + LineConfig config = lineConfigData.get(sch.getXlBm());
  476 + if (config != null)
  477 + outConfig = config.getOutConfig();
  478 +
  479 + boolean flag = false;
  480 + ScheduleRealInfo next = null;
  481 + for (ScheduleRealInfo temp : list) {
  482 + if (temp.getId() == sch.getId()) {
  483 + flag = true;
  484 + continue;
  485 + }
  486 + //忽略烂班
  487 + if (temp.isDestroy())
  488 + continue;
  489 +
  490 + //出站既出场,忽略出场班次
  491 + if (outConfig == 2 && temp.getBcType().equals("out"))
  492 + continue;
  493 +
  494 + if (flag) {
  495 + next = temp;
  496 + break;
  497 + }
  498 + }
  499 + return next;
  500 + }
  501 +
  502 + /**
  503 + * 上一个班次
  504 + *
  505 + * @param sch
  506 + * @return
  507 + */
  508 + public ScheduleRealInfo prev(ScheduleRealInfo sch) {
  509 + List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());
  510 +
  511 + //boolean flag = false;
  512 + ScheduleRealInfo prev = null;
  513 + int size = list.size();
  514 +
  515 + for (int i = 0; i < size; i++) {
  516 + if (list.get(i).isDestroy())
  517 + continue;
  518 +
  519 + if (list.get(i).getId().equals(sch.getId())) {
  520 + return prev;
  521 + }
  522 + prev = list.get(i);
  523 + }
  524 + return prev;
  525 + }
  526 +
  527 + public void put(ScheduleRealInfo sch) {
  528 + schAttrCalculator
  529 + .calcRealDate(sch)
  530 + .calcAllTimeByFcsj(sch);
  531 +
  532 + String nbbm = sch.getClZbh();
  533 + nbbmScheduleMap.put(nbbm, sch);
  534 + nbbm2SEStationMap.put(nbbm, sch.getQdzCode());
  535 + nbbm2SEStationMap.put(nbbm, sch.getZdzCode());
  536 +
  537 + //主键索引
  538 + id2SchedulMap.put(sch.getId(), sch);
  539 + //跨24点的,再save一次
  540 + if (!sch.getRealExecDate().equals(sch.getScheduleDateStr()))
  541 + save(sch);
  542 + }
  543 +
  544 + public void delete(ScheduleRealInfo sch) {
  545 + //ScheduleRealInfo sch = id2SchedulMap.get(id);
  546 + if (!sch.isSflj())
  547 + return;
  548 +
  549 + nbbmScheduleMap.remove(sch.getClZbh(), sch);
  550 + id2SchedulMap.remove(sch.getId());
  551 + //return sch;
  552 + }
530 553  
531   - if(list.get(i).getId().equals(sch.getId())){
532   - return prev;
533   - }
534   - prev = list.get(i);
535   - }
536   - return prev;
537   - }
538   -
539   - public void put(ScheduleRealInfo sch) {
540   - schAttrCalculator
541   - .calcRealDate(sch)
542   - .calcAllTimeByFcsj(sch);
543   -
544   - String nbbm = sch.getClZbh();
545   - nbbmScheduleMap.put(nbbm, sch);
546   - nbbm2SEStationMap.put(nbbm, sch.getQdzCode());
547   - nbbm2SEStationMap.put(nbbm, sch.getZdzCode());
548   -
549   - //主键索引
550   - id2SchedulMap.put(sch.getId(), sch);
551   - //跨24点的,再save一次
552   - if(!sch.getRealExecDate().equals(sch.getScheduleDateStr()))
553   - save(sch);
554   - }
555   -
556   - public void delete(ScheduleRealInfo sch) {
557   - //ScheduleRealInfo sch = id2SchedulMap.get(id);
558   - if(!sch.isSflj())
559   - return;
560   -
561   - nbbmScheduleMap.remove(sch.getClZbh(), sch);
562   - id2SchedulMap.remove(sch.getId());
563   - //return sch;
564   - }
565   -
566 554 // public void calcQdzTimePlan(String nbbm){
567 555 // schAttrCalculator.calcQdzTimePlan(nbbmScheduleMap.get(nbbm));
568 556 // }
569   -
570   - public List<ScheduleRealInfo> updateQdzTimePlan(String nbbm){
571   - return schAttrCalculator.updateQdzTimePlan(nbbmScheduleMap.get(nbbm));
572   - }
573   -
574   - /**
575   - *
576   - * @Title: nextAll
577   - * @Description: TODO(之后的所有班次)
578   - */
  557 +
  558 + public List<ScheduleRealInfo> updateQdzTimePlan(String nbbm) {
  559 + return schAttrCalculator.updateQdzTimePlan(nbbmScheduleMap.get(nbbm));
  560 + }
  561 +
  562 + /**
  563 + *
  564 + * @Title: nextAll
  565 + * @Description: TODO(之后的所有班次)
  566 + */
579 567 /* public List<ScheduleRealInfo> nextAll(ScheduleRealInfo sch) {
580   - List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());
  568 + List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());
581 569 // 排序
582 570 Collections.sort(list, schFCSJComparator);
583 571  
... ... @@ -592,190 +580,193 @@ public class DayOfSchedule implements CommandLineRunner {
592 580 return rs;
593 581 }*/
594 582  
595   - /**
596   - *
597   - * @Title: doneSum
598   - * @Description: TODO(已完成班次总数)
599   - */
600   - public int doneSum(String clZbh) {
601   - List<ScheduleRealInfo> list = nbbmScheduleMap.get(clZbh);
602   - int rs = 0;
603   -
604   - for(ScheduleRealInfo sch : list){
605   - if(sch.getStatus() == 2 && !sch.isDestroy())
606   - rs ++;
607   - }
608   - return rs;
609   - }
610   -
611   - /**
612   - *
613   - * @Title: prveNotExecNum
614   - * @Description: TODO(班次之前未执行班次数量)
615   - */
616   - public int prveNotExecNum(ScheduleRealInfo sch){
617   - int n = 0;
618   - List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());
619   - for(ScheduleRealInfo s : list){
620   - if(s.getFcsjActual() == null && !s.isDestroy())
621   - n ++;
622   -
623   - if(s.getId().equals(sch.getId()))
624   - break;
625   - }
626   - return n;
627   - }
628   -
629   - /**
630   - *
631   - * @Title: validEndTime
632   - * @Description: TODO(是否是有效的到达时间)
633   - */
634   - public boolean validEndTime(ScheduleRealInfo sch, Long ts) {
635   - if(sch.getFcsjActualTime() != null && sch.getFcsjActualTime() > ts)
636   - return false;
637   -
638   - return validTime(sch, ts);
639   - }
640   -
641   - /**
642   - *
643   - * @Title: validStartTime
644   - * @Description: TODO(是否是合适的发车时间)
645   - */
646   - public boolean validStartTime(ScheduleRealInfo sch, Long ts) {
647   - if(sch.getZdsjActualTime() != null && sch.getZdsjActualTime() < ts)
648   - return false;
649   -
650   - return validTime(sch, ts);
651   - }
652   -
653   - public boolean validTime(ScheduleRealInfo sch, Long ts){
654   - List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());
655   - int ci = list.indexOf(sch);
656   - ScheduleRealInfo prve, next;
657   - if(ci > 0){
658   - //之前班次实际时间不能大于该时间
659   - for(int i = ci - 1; i >= 0; i --){
660   - prve = list.get(i);
661   - if(prve.getZdsjActualTime() != null && prve.getZdsjActualTime() > ts )
662   - return false;
663   -
664   - if(prve.getFcsjActualTime() != null && prve.getFcsjActualTime() > ts)
665   - return false;
666   - }
667   - }
668   -
669   - if(ci < list.size() - 1){
670   - //之后班次实际时间不能小于该时间
671   - for(int i = ci + 1; i < list.size(); i ++){
672   - next = list.get(i);
673   - if(next.getFcsjActualTime() != null && next.getFcsjActualTime() < ts)
674   - return false;
675   -
676   - if(next.getZdsjActualTime() != null && next.getZdsjActualTime() < ts)
677   - return false;
678   - }
679   - }
680   - return true;
681   - }
682   -
683   - public void save(ScheduleRealInfo sch){
684   - //schRepository.save(sch);
685   - pstBuffer.add(sch);
686   - }
687   -
688   -
689   - /**
690   - *
691   - * @Title: nextByBcType
692   - * @Description: TODO(获取下一个指定班次类型的班次)
693   - */
694   - public ScheduleRealInfo nextByBcType(String nbbm, String bcType){
695   - List<ScheduleRealInfo> list = findByBcType(nbbm, bcType);
696   -
697   - Collections.sort(list, schFCSJComparator);
698   - ScheduleRealInfo sch = null;
699   - for(ScheduleRealInfo temp : list){
700   - if(temp.getFcsjActual() == null)
701   - sch = temp;
702   - }
703   -
704   - return sch;
705   - }
706   -
707   - public List<ScheduleRealInfo> findByBcType(String nbbm, String bcType){
708   - List<ScheduleRealInfo> all = nbbmScheduleMap.get(nbbm)
709   - ,outList = new ArrayList<>();
710   -
711   - for(ScheduleRealInfo sch : all){
712   - if(sch.getBcType().equals(bcType))
713   - outList.add(sch);
714   - }
715   - return outList;
716   - }
717   -
718   - public Set<String> allCar(){
719   - return nbbmScheduleMap.keySet();
720   - }
721   -
722   - public Collection<ScheduleRealInfo> findAll(){
723   - return nbbmScheduleMap.values();
724   - }
725   -
726   - public void addExecPlan(ScheduleRealInfo sch){
727   - carExecutePlanMap.put(sch.getClZbh(), sch);
728   - }
729   -
730   - public void removeExecPlan(String clzbh){
731   - carExecutePlanMap.remove(clzbh);
732   - }
733   -
734   - public Map<String, ScheduleRealInfo> execPlanMap(){
735   - return carExecutePlanMap;
736   - }
737   -
738   - /**
739   - * 车辆当前执行的班次
740   - * @param nbbm
741   - * @return
742   - */
743   - public static ScheduleRealInfo executeCurr(String nbbm){
744   - return carExecutePlanMap.get(nbbm);
745   - }
746   -
747   - /**
748   - * @Title: changeCar
749   - * @Description: TODO(班次换车) 返回有更新的班次
750   - * @param @param sch
751   - * @param @param newClZbh 新的车辆自编号
752   - */
753   - public List<ScheduleRealInfo> changeCar(ScheduleRealInfo sch , String newClZbh){
754   - List<ScheduleRealInfo> ups = new ArrayList<>();
755   - String oldClzbh = sch.getClZbh();
756   - if(oldClzbh.equals(newClZbh))
757   - return ups;
758   -
759   -
760   - //变更相关映射信息
761   - nbbmScheduleMap.remove(sch.getClZbh(), sch);
762   -
763   - sch.setClZbh(newClZbh);
764   - nbbmScheduleMap.put(newClZbh, sch);
765   - nbbm2SEStationMap.put(newClZbh, sch.getQdzCode());
766   - nbbm2SEStationMap.put(newClZbh, sch.getZdzCode());
767   -
768   - //重新计算班次应到时间
769   - ups.addAll(updateQdzTimePlan(oldClzbh));
770   - ups.addAll(updateQdzTimePlan(newClZbh));
771   - return ups;
772   - }
773   -
774   - /**
775   - *
776   - * @Title: linkToSchPlan
777   - * @Description: TODO(车辆关联到班次)
778   - */
  583 + /**
  584 + * @Title: doneSum
  585 + * @Description: TODO(已完成班次总数)
  586 + */
  587 + public int doneSum(String clZbh) {
  588 + List<ScheduleRealInfo> list = nbbmScheduleMap.get(clZbh);
  589 + int rs = 0;
  590 +
  591 + for (ScheduleRealInfo sch : list) {
  592 + if (sch.getStatus() == 2 && !sch.isDestroy())
  593 + rs++;
  594 + }
  595 + return rs;
  596 + }
  597 +
  598 + /**
  599 + * @Title: prveNotExecNum
  600 + * @Description: TODO(班次之前未执行班次数量)
  601 + */
  602 + public int prveNotExecNum(ScheduleRealInfo sch) {
  603 + int n = 0;
  604 + List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());
  605 + for (ScheduleRealInfo s : list) {
  606 + if (s.getFcsjActual() == null && !s.isDestroy())
  607 + n++;
  608 +
  609 + if (s.getId().equals(sch.getId()))
  610 + break;
  611 + }
  612 + return n;
  613 + }
  614 +
  615 + /**
  616 + * @Title: validEndTime
  617 + * @Description: TODO(是否是有效的到达时间)
  618 + */
  619 + public boolean validEndTime(ScheduleRealInfo sch, Long ts) {
  620 + if (sch.getFcsjActualTime() != null && sch.getFcsjActualTime() > ts)
  621 + return false;
  622 +
  623 + return validTime(sch, ts);
  624 + }
  625 +
  626 + /**
  627 + * @Title: validStartTime
  628 + * @Description: TODO(是否是合适的发车时间)
  629 + */
  630 + public boolean validStartTime(ScheduleRealInfo sch, Long ts) {
  631 + if (sch.getZdsjActualTime() != null && sch.getZdsjActualTime() < ts)
  632 + return false;
  633 +
  634 + return validTime(sch, ts);
  635 + }
  636 +
  637 + public boolean validTime(ScheduleRealInfo sch, Long ts) {
  638 + List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());
  639 + int ci = list.indexOf(sch);
  640 + ScheduleRealInfo prve, next;
  641 + if (ci > 0) {
  642 + //之前班次实际时间不能大于该时间
  643 + for (int i = ci - 1; i >= 0; i--) {
  644 + prve = list.get(i);
  645 + if (prve.getZdsjActualTime() != null && prve.getZdsjActualTime() > ts)
  646 + return false;
  647 +
  648 + if (prve.getFcsjActualTime() != null && prve.getFcsjActualTime() > ts)
  649 + return false;
  650 + }
  651 + }
  652 +
  653 + if (ci < list.size() - 1) {
  654 + //之后班次实际时间不能小于该时间
  655 + for (int i = ci + 1; i < list.size(); i++) {
  656 + next = list.get(i);
  657 + if (next.getFcsjActualTime() != null && next.getFcsjActualTime() < ts)
  658 + return false;
  659 +
  660 + if (next.getZdsjActualTime() != null && next.getZdsjActualTime() < ts)
  661 + return false;
  662 + }
  663 + }
  664 + return true;
  665 + }
  666 +
  667 + public void save(ScheduleRealInfo sch) {
  668 + //schRepository.save(sch);
  669 + pstBuffer.add(sch);
  670 + }
  671 +
  672 +
  673 + /**
  674 + * @Title: nextByBcType
  675 + * @Description: TODO(获取下一个指定班次类型的班次)
  676 + */
  677 + public ScheduleRealInfo nextByBcType(String nbbm, String bcType) {
  678 + List<ScheduleRealInfo> list = findByBcType(nbbm, bcType);
  679 +
  680 + Collections.sort(list, schFCSJComparator);
  681 + ScheduleRealInfo sch = null;
  682 + for (ScheduleRealInfo temp : list) {
  683 + if (temp.getFcsjActual() == null)
  684 + sch = temp;
  685 + }
  686 +
  687 + return sch;
  688 + }
  689 +
  690 + public List<ScheduleRealInfo> findByBcType(String nbbm, String bcType) {
  691 + List<ScheduleRealInfo> all = nbbmScheduleMap.get(nbbm), outList = new ArrayList<>();
  692 +
  693 + for (ScheduleRealInfo sch : all) {
  694 + if (sch.getBcType().equals(bcType))
  695 + outList.add(sch);
  696 + }
  697 + return outList;
  698 + }
  699 +
  700 + public Set<String> allCar() {
  701 + return nbbmScheduleMap.keySet();
  702 + }
  703 +
  704 + public Collection<ScheduleRealInfo> findAll() {
  705 + return nbbmScheduleMap.values();
  706 + }
  707 +
  708 + public void addExecPlan(ScheduleRealInfo sch) {
  709 + carExecutePlanMap.put(sch.getClZbh(), sch);
  710 + }
  711 +
  712 + public void removeExecPlan(String clzbh) {
  713 + carExecutePlanMap.remove(clzbh);
  714 + }
  715 +
  716 + public Map<String, ScheduleRealInfo> execPlanMap() {
  717 + return carExecutePlanMap;
  718 + }
  719 +
  720 + /**
  721 + * 车辆当前执行的班次
  722 + *
  723 + * @param nbbm
  724 + * @return
  725 + */
  726 + public static ScheduleRealInfo executeCurr(String nbbm) {
  727 + return carExecutePlanMap.get(nbbm);
  728 + }
  729 +
  730 + /**
  731 + * @param @param sch
  732 + * @param @param newClZbh 新的车辆自编号
  733 + * @Title: changeCar
  734 + * @Description: TODO(班次换车) 返回有更新的班次
  735 + */
  736 + public List<ScheduleRealInfo> changeCar(ScheduleRealInfo sch, String newClZbh) {
  737 + List<ScheduleRealInfo> ups = new ArrayList<>();
  738 + String oldClzbh = sch.getClZbh();
  739 + if (oldClzbh.equals(newClZbh))
  740 + return ups;
  741 +
  742 +
  743 + //变更相关映射信息
  744 + nbbmScheduleMap.remove(sch.getClZbh(), sch);
  745 +
  746 + sch.setClZbh(newClZbh);
  747 + nbbmScheduleMap.put(newClZbh, sch);
  748 + nbbm2SEStationMap.put(newClZbh, sch.getQdzCode());
  749 + nbbm2SEStationMap.put(newClZbh, sch.getZdzCode());
  750 +
  751 + //重新计算班次应到时间
  752 + ups.addAll(updateQdzTimePlan(oldClzbh));
  753 + ups.addAll(updateQdzTimePlan(newClZbh));
  754 +
  755 + //重新计算车辆当前执行班次
  756 + reCalcExecPlan(newClZbh);
  757 + reCalcExecPlan(sch.getClZbh());
  758 + return ups;
  759 + }
  760 +
  761 + public void reCalcExecPlan(String nbbm){
  762 + carExecutePlanMap.put(nbbm, schAttrCalculator.calcCurrentExecSch(nbbmScheduleMap.get(nbbm)));
  763 + }
  764 +
  765 + /**
  766 + *
  767 + * @Title: linkToSchPlan
  768 + * @Description: TODO(车辆关联到班次)
  769 + */
779 770 /* public void linkToSchPlan(String nbbm) {
780 771 //当前GPS状态
781 772 GpsEntity gps = gpsRealData.get(BasicData.deviceId2NbbmMap.inverse().get(nbbm));
... ...
src/main/java/com/bsth/entity/realcontrol/LineConfig.java
1 1 package com.bsth.entity.realcontrol;
2 2  
  3 +import com.bsth.entity.Line;
  4 +
  5 +import javax.persistence.*;
3 6 import java.text.ParseException;
4 7 import java.text.SimpleDateFormat;
5 8 import java.util.Date;
6 9 import java.util.HashSet;
7 10 import java.util.Set;
8 11  
9   -import javax.persistence.CascadeType;
10   -import javax.persistence.Entity;
11   -import javax.persistence.GeneratedValue;
12   -import javax.persistence.Id;
13   -import javax.persistence.NamedAttributeNode;
14   -import javax.persistence.NamedEntityGraph;
15   -import javax.persistence.NamedEntityGraphs;
16   -import javax.persistence.OneToMany;
17   -import javax.persistence.OneToOne;
18   -import javax.persistence.Table;
19   -import javax.persistence.Transient;
20   -
21   -import com.bsth.entity.Line;
22   -import com.bsth.util.DateUtils;
23   -
24 12 /**
25 13 *
26 14 * @ClassName: LineConfig
... ... @@ -59,9 +47,6 @@ public class LineConfig {
59 47 /** 出场时间设置 0:真实出场(设备离开缓冲区时间) 1:请求出场时间 2:出站即出场 */
60 48 private int outConfig;
61 49  
62   - /** 进场时间设置 0:真实进场(设备进入缓冲区时间) 1:请求进场时间 2:出站即出场*/
63   - private int inConfig;
64   -
65 50 /** 短语模板 , 号分隔多个 */
66 51 private String phraseTemps;
67 52  
... ... @@ -111,14 +96,6 @@ public class LineConfig {
111 96 this.outConfig = outConfig;
112 97 }
113 98  
114   - public int getInConfig() {
115   - return inConfig;
116   - }
117   -
118   - public void setInConfig(int inConfig) {
119   - this.inConfig = inConfig;
120   - }
121   -
122 99 public String getPhraseTemps() {
123 100 return phraseTemps;
124 101 }
... ...
src/main/java/com/bsth/entity/realcontrol/ScheduleType.java
1   -package com.bsth.entity.realcontrol;
2   -
3   -/**
4   - * 班次类型
5   - * Created by panzhao on 2016/12/23.
6   - */
7   -public enum ScheduleType {
8   -
9   - normal, //正常班次
10   - out, //出场
11   - in, //进场
12   - region, //区间
13   - venting,//直放
14   - major //放站
15   -}
  1 +package com.bsth.entity.realcontrol;
  2 +
  3 +/**
  4 + * 班次类型
  5 + * Created by panzhao on 2016/12/23.
  6 + */
  7 +public enum ScheduleType {
  8 +
  9 + normal, //正常班次
  10 + out, //出场
  11 + in, //进场
  12 + region, //区间
  13 + venting,//直放
  14 + major //放站
  15 +}
... ...
src/main/java/com/bsth/repository/realcontrol/ScheduleRealInfoRepository.java
... ... @@ -24,6 +24,9 @@ public interface ScheduleRealInfoRepository extends BaseRepository&lt;ScheduleRealI
24 24 @Query(value="select min(s.id), s.jGh,s.clZbh,s.lpName,s.jName from ScheduleRealInfo s where s.xlBm = ?1 and DATE_FORMAT(s.scheduleDate,'%Y-%m-%d') = ?2 GROUP BY s.jGh,s.clZbh,s.lpName ,s.jName order by (lpName+1)")
25 25 List<ScheduleRealInfo> queryUserInfo2(String line,String date);
26 26  
  27 + @Query(value="select min(s.id), s.jGh,s.clZbh,s.lpName,s.jName from ScheduleRealInfo s where s.xlBm = ?1 and DATE_FORMAT(s.scheduleDate,'%Y-%m-%d') = ?2 GROUP BY s.jGh,s.clZbh,s.lpName ,s.jName order by (lpName+1)")
  28 + List<ScheduleRealInfo> queryUserInfo3(String line,String date);
  29 +
27 30 @Query(value="select s from ScheduleRealInfo s where s.jName = ?1 and s.clZbh = ?2 and s.lpName = ?3 order by bcs")
28 31 List<ScheduleRealInfo> exportWaybill(String jName,String clZbh,String lpName);
29 32  
... ...
src/main/java/com/bsth/service/BusIntervalService.java
... ... @@ -8,6 +8,8 @@ public interface BusIntervalService {
8 8  
9 9 List<Map<String, Object>> getDir(Map<String, Object> map);
10 10  
  11 + List<Map<String, Object>> getLp(Map<String, Object> map);
  12 +
11 13 List<Map<String, Object>> interval(Map<String, Object> map);
12 14  
13 15 Map<String, Object> timeAndSpeed(Map<String, Object> map);
... ...
src/main/java/com/bsth/service/impl/BusIntervalServiceImpl.java
1 1 package com.bsth.service.impl;
2 2  
  3 +import java.math.BigDecimal;
  4 +import java.math.RoundingMode;
3 5 import java.sql.ResultSet;
4 6 import java.sql.SQLException;
5 7 import java.text.DecimalFormat;
... ... @@ -11,12 +13,14 @@ import java.util.Date;
11 13 import java.util.HashMap;
12 14 import java.util.List;
13 15 import java.util.Map;
  16 +import java.util.Set;
14 17  
15 18 import org.springframework.beans.factory.annotation.Autowired;
16 19 import org.springframework.jdbc.core.JdbcTemplate;
17 20 import org.springframework.jdbc.core.RowMapper;
18 21 import org.springframework.stereotype.Service;
19 22  
  23 +import com.bsth.entity.realcontrol.ChildTaskPlan;
20 24 import com.bsth.entity.realcontrol.ScheduleRealInfo;
21 25 import com.bsth.repository.realcontrol.ScheduleRealInfoRepository;
22 26 import com.bsth.service.BusIntervalService;
... ... @@ -36,9 +40,9 @@ public class BusIntervalServiceImpl implements BusIntervalService {
36 40 private JdbcTemplate jdbcTemplate;
37 41  
38 42 private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
39   - private DecimalFormat df = new DecimalFormat("##0.00");
  43 + private DecimalFormat df = new DecimalFormat("0.##");
40 44  
41   - public List<ScheduleRealInfo> getSchedule(String company, String subCompany, String line, String startDate, String endDate, String model, String times){
  45 + public List<ScheduleRealInfo> getSchedule(String company, String subCompany, String line, String startDate, String endDate, String model, String times, boolean normal){
42 46 List<Long> ttList = new ArrayList<Long>();
43 47 List<ScheduleRealInfo> list = new ArrayList<ScheduleRealInfo>();
44 48 List<ScheduleRealInfo> resList = new ArrayList<ScheduleRealInfo>();
... ... @@ -56,14 +60,18 @@ public class BusIntervalServiceImpl implements BusIntervalService {
56 60 if(company.length() != 0){
57 61 sql += " and gs_bm = '"+company+"' and fgs_bm = '"+subCompany+"'";
58 62 }
59   - sql += " and bc_type = 'normal'";
  63 + if(normal){
  64 + sql += " and bc_type != 'in' and bc_type != 'out'";
  65 + }
60 66  
61   - list =jdbcTemplate.query(sql,
  67 + list = jdbcTemplate.query(sql,
62 68 new RowMapper<ScheduleRealInfo>(){
63 69 @Override
64 70 public ScheduleRealInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
65 71 ScheduleRealInfo schedule = new ScheduleRealInfo();
66 72 schedule.setScheduleDateStr(rs.getString("schedule_date_Str"));
  73 + schedule.setRealExecDate(rs.getString("real_exec_date"));
  74 + schedule.setXlBm(rs.getString("xl_bm"));
67 75 schedule.setXlName(rs.getString("xl_name"));
68 76 schedule.setLpName(rs.getString("lp_name"));
69 77 schedule.setBcType(rs.getString("bc_type"));
... ... @@ -75,6 +83,7 @@ public class BusIntervalServiceImpl implements BusIntervalService {
75 83 schedule.setFcsjActual(rs.getString("fcsj_actual"));
76 84 schedule.setZdsj(rs.getString("zdsj"));
77 85 schedule.setZdsjActual(rs.getString("zdsj_actual"));
  86 + schedule.setQdzCode(rs.getString("qdz_code"));
78 87 schedule.setQdzName(rs.getString("qdz_name"));
79 88 schedule.setZdzName(rs.getString("zdz_name"));
80 89 schedule.setXlDir(rs.getString("xl_dir"));
... ... @@ -88,15 +97,57 @@ public class BusIntervalServiceImpl implements BusIntervalService {
88 97 schedule.setjGh(rs.getString("j_gh"));
89 98 schedule.setjName(rs.getString("j_name"));
90 99 schedule.setSpId(rs.getLong("sp_id"));
  100 + schedule.setSflj(rs.getBoolean("sflj"));
  101 +
  102 + String[] split1 = schedule.getFcsj().split(":");
  103 + String[] split3 = schedule.getZdsj().split(":");
  104 + long fcsj = Long.valueOf(split1[0]) * 60 + Long.valueOf(split1[1]);
  105 + long zdsj = Long.valueOf(split3[0]) * 60 + Long.valueOf(split3[1]);
  106 + if(!schedule.getScheduleDateStr().equals(schedule.getRealExecDate())){
  107 + fcsj += 1440l;
  108 + zdsj += 1440l;
  109 + }
  110 + if(zdsj < fcsj)
  111 + zdsj += 1440l;
  112 + if(schedule.getDfsj() != null){
  113 + String[] split0 = schedule.getDfsj().split(":");
  114 + long dfsj = Long.valueOf(split0[0]) * 60 + Long.valueOf(split0[1]);
  115 + if(!schedule.getScheduleDateStr().equals(schedule.getRealExecDate()))
  116 + dfsj += 1440l;
  117 + schedule.setDfsj(dfsj/60 + ":" + dfsj%60);
  118 + schedule.setDfsjT(dfsj);
  119 + }
  120 + if(schedule.getFcsjActual() != null){
  121 + String[] split2 = schedule.getFcsjActual().split(":");
  122 + long fcsjA = Long.valueOf(split2[0]) * 60 + Long.valueOf(split2[1]);
  123 + if(!schedule.getScheduleDateStr().equals(schedule.getRealExecDate()))
  124 + fcsjA += 1440l;
  125 + schedule.setFcsjActual(fcsjA/60 + ":" + fcsjA%60);
  126 + schedule.setFcsjActualTime(fcsjA);
  127 + }
  128 + if(schedule.getZdsjActual() != null){
  129 + String[] split4 = schedule.getZdsjActual().split(":");
  130 + long zdsjA = Long.valueOf(split4[0]) * 60 + Long.valueOf(split4[1]);
  131 + if(!schedule.getScheduleDateStr().equals(schedule.getRealExecDate()))
  132 + zdsjA += 1440l;
  133 + if(schedule.getFcsjActualTime() != null && zdsjA < schedule.getFcsjActualTime())
  134 + zdsjA += 1440l;
  135 + schedule.setZdsjActual(zdsjA/60 + ":" + zdsjA%60);
  136 + schedule.setZdsjActualTime(zdsjA);
  137 + }
  138 + schedule.setFcsj(fcsj/60 + ":" + fcsj%60);
  139 + schedule.setZdsj(zdsj/60 + ":" + zdsj%60);
  140 + schedule.setFcsjT(fcsj);
  141 + schedule.setZdsjT(zdsj);
91 142 return schedule;
92 143 }
93 144 });
94 145  
95 146 if(model.length() != 0){
96   -// sql = "select * from bsth_c_s_ttinfo_detail where ttinfo = '"+model+"' and bc_type = 'normal'";
97   - sql = "select id from bsth_c_s_sp_info where tt_info = '" + model + "' and bc_type = 'normal'";
  147 +// sql = "select * from bsth_c_s_ttinfo_detail where ttinfo = '"+model+"' and bc_type != 'in' and bc_type != 'out'";
  148 + sql = "select id from bsth_c_s_sp_info where tt_info = '" + model + "' and bc_type != 'in' and bc_type != 'out'";
98 149  
99   - ttList =jdbcTemplate.query(sql,
  150 + ttList = jdbcTemplate.query(sql,
100 151 new RowMapper<Long>(){
101 152 @Override
102 153 public Long mapRow(ResultSet rs, int rowNum) throws SQLException {
... ... @@ -143,7 +194,7 @@ public class BusIntervalServiceImpl implements BusIntervalService {
143 194 }
144 195 }
145 196 }
146   -
  197 +
147 198 list = new ArrayList<ScheduleRealInfo>();
148 199 List<Long> keyList = new ArrayList<Long>();
149 200 Map<Long, List<ScheduleRealInfo>> keyMap = new HashMap<Long, List<ScheduleRealInfo>>();
... ... @@ -161,7 +212,7 @@ public class BusIntervalServiceImpl implements BusIntervalService {
161 212 list.add(schedule);
162 213 }
163 214 }
164   -
  215 +
165 216 return list;
166 217 }
167 218  
... ... @@ -176,7 +227,7 @@ public class BusIntervalServiceImpl implements BusIntervalService {
176 227  
177 228 String sql = "select start_station_name, end_station_name from bsth_c_line where line_code = '"+line+"'";
178 229  
179   - list =jdbcTemplate.query(sql,
  230 + list = jdbcTemplate.query(sql,
180 231 new RowMapper<Map<String, Object>>(){
181 232 @Override
182 233 public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
... ... @@ -205,8 +256,45 @@ public class BusIntervalServiceImpl implements BusIntervalService {
205 256 }
206 257  
207 258 @Override
  259 + public List<Map<String, Object>> getLp(Map<String, Object> map){
  260 + List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
  261 +
  262 + String line = map.get("line").toString();
  263 + String ttId = map.get("ttId").toString();
  264 +
  265 + try {
  266 + String sql = "select td.lp, lp.lp_name from bsth_c_s_ttinfo_detail td" +
  267 + " left join bsth_c_s_gbi lp on td.lp = lp.id" +
  268 + " left join bsth_c_line cl on cl.id = td.xl where 1=1";
  269 + if(line.length() != 0)
  270 + sql += " and cl.line_code = '"+line+"'";
  271 + if(ttId.length() != 0)
  272 + sql += " and td.ttinfo = '"+ttId+"'";
  273 + sql += " group by td.lp";
  274 +
  275 + list = jdbcTemplate.query(sql,
  276 + new RowMapper<Map<String, Object>>(){
  277 + @Override
  278 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  279 + Map<String, Object> map = new HashMap<String, Object>();
  280 + map.put("id", rs.getString("lp"));
  281 + map.put("name", rs.getString("lp_name"));
  282 + return map;
  283 + }
  284 +
  285 + });
  286 + } catch (Exception e) {
  287 + // TODO: handle exception
  288 + e.printStackTrace();
  289 + }
  290 +
  291 + return list;
  292 + }
  293 +
  294 + @Override
208 295 public List<Map<String, Object>> interval(Map<String, Object> map) {
209 296 List<Map<String, Object>> resList = new ArrayList<Map<String, Object>>();
  297 + List<Map<String, Object>> tempList = new ArrayList<Map<String, Object>>();
210 298 Map<String, List<ScheduleRealInfo>> keyMap = new HashMap<String, List<ScheduleRealInfo>>();
211 299  
212 300 String company = map.get("company").toString();
... ... @@ -215,7 +303,8 @@ public class BusIntervalServiceImpl implements BusIntervalService {
215 303 String startDate = map.get("startDate").toString();
216 304 String endDate = map.get("endDate").toString();
217 305 String model = map.get("model").toString();
218   - String times = map.get("times").toString();
  306 + String statu = map.get("statu").toString();
  307 +// String times = map.get("times").toString();
219 308 String type = map.get("type").toString();
220 309  
221 310 if(startDate.length() == 0){
... ... @@ -224,273 +313,737 @@ public class BusIntervalServiceImpl implements BusIntervalService {
224 313 if(endDate.length() == 0){
225 314 endDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
226 315 }
227   - if(times.length() == 0){
228   - times = "06:00-07:00";
  316 + if(statu.equals("0")){
  317 + line = "";
229 318 }
  319 +// if(times.length() == 0){
  320 +// times = "06:00-07:00";
  321 +// }
230 322  
231   - List<ScheduleRealInfo> list = this.getSchedule(company, subCompany, line, startDate, endDate, model, times);
  323 + List<ScheduleRealInfo> list = this.getSchedule(company, subCompany, line, startDate, endDate, model, "", true);
232 324  
233 325 String[] date1 = startDate.split("-");
234 326 String[] date2 = endDate.split("-");
235 327 startDate = date1[0] + "年" + date1[1] + "月" + date1[2] + "日";
236 328 endDate = date2[0] + "年" + date2[1] + "月" + date2[2] + "日";
  329 + String Date = "";
  330 + if(startDate.equals(endDate))
  331 + Date = startDate;
  332 + else
  333 + Date = startDate + "--" + endDate;
237 334  
238   - String[] split = times.split("-");
239   - int startTime = Integer.valueOf(split[0].split(":")[0])*60 + Integer.valueOf(split[0].split(":")[1]);
240   - int endTime = Integer.valueOf(split[1].split(":")[0])*60 + Integer.valueOf(split[1].split(":")[1]);
  335 +// String[] split = times.split("-");
  336 +// int startTime = Integer.valueOf(split[0].split(":")[0])*60 + Integer.valueOf(split[0].split(":")[1]);
  337 +// int endTime = Integer.valueOf(split[1].split(":")[0])*60 + Integer.valueOf(split[1].split(":")[1]);
241 338  
242   - //分组统计班次间隔
243 339 for(ScheduleRealInfo schedule : list){
244   - long fcsj = schedule.getFcsjT();
245   - if(endTime != 0?(fcsj >= startTime && fcsj <= endTime):(fcsj >= startTime)){
246   - String key = schedule.getXlName() + "/" + schedule.getQdzName();
247   - if(!keyMap.containsKey(key))
248   - keyMap.put(key, new ArrayList<ScheduleRealInfo>());
249   - keyMap.get(key).add(schedule);
250   - }
  340 + String key = schedule.getXlBm() + "/" + schedule.getXlName() + "/" + schedule.getQdzName();
  341 + if(!keyMap.containsKey(key))
  342 + keyMap.put(key, new ArrayList<ScheduleRealInfo>());
  343 + keyMap.get(key).add(schedule);
251 344 }
  345 +
  346 + List<String> keyList = new ArrayList<String>();
  347 + Map<String, List<Long>> temp0 = new HashMap<String, List<Long>>();
  348 + Map<String, List<Long>> temp1 = new HashMap<String, List<Long>>();
  349 + String companyName = "", subCompanyName = "";
252 350 for(String key : keyMap.keySet()){
253   - long jhInterval = 0;
254   - long sjInterval = 0;
255   - int jhNum = 0;
256   - int sjNum = 0;
257   - String companyName = "", subCompanyName = "";
258   - Map<String, Object> tempMap = new HashMap<String, Object>();
259   - Map<String, List<ScheduleRealInfo>> temp = new HashMap<String, List<ScheduleRealInfo>>();
  351 + if(keyMap.get(key).size() < 2)
  352 + continue;
  353 + Map<String, List<ScheduleRealInfo>> keyMap2 = new HashMap<String, List<ScheduleRealInfo>>();
260 354 for(ScheduleRealInfo schedule : keyMap.get(key)){
  355 + if(companyName.length() == 0 && schedule.getGsName() != null)
  356 + companyName = schedule.getGsName();
  357 + if(subCompanyName.length() == 0 && schedule.getFgsName() != null)
  358 + subCompanyName = schedule.getFgsName();
261 359 String date = schedule.getScheduleDateStr();
262   - if(!temp.containsKey(date))
263   - temp.put(date, new ArrayList<ScheduleRealInfo>());
264   - temp.get(date).add(schedule);
  360 + if(!keyMap2.containsKey(date))
  361 + keyMap2.put(date, new ArrayList<ScheduleRealInfo>());
  362 + keyMap2.get(date).add(schedule);
265 363 }
266   - for(String date : temp.keySet()){
267   - List<ScheduleRealInfo> tempList = temp.get(date);
268   - for(int i = 1; i < tempList.size(); i++){
269   - jhNum++;
270   - ScheduleRealInfo schedule1 = tempList.get(i - 1);
271   - ScheduleRealInfo schedule2 = tempList.get(i);
272   -
273   - if(schedule1.getGsName() != null && companyName.length() == 0)
274   - companyName = schedule1.getGsName();
275   - if(schedule1.getFgsName() != null && subCompanyName.length() == 0)
276   - subCompanyName = schedule1.getFgsName();
277   -
278   - jhInterval += schedule2.getFcsjT();
279   - jhInterval -= schedule1.getFcsjT();
280   - if(schedule1.getFcsjActual()!=null && schedule2.getFcsjActual()!=null){
281   - sjNum++;
282   - sjInterval += schedule2.getFcsjActualTime();
283   - sjInterval -= schedule1.getFcsjActualTime();
  364 + Map<Long, List<Long>> timeMap0 = new HashMap<Long, List<Long>>();
  365 + Map<Long, List<Long>> timeMap1 = new HashMap<Long, List<Long>>();
  366 + List<Long> timeList = new ArrayList<Long>();
  367 + for(String date : keyMap2.keySet()){
  368 + if(keyMap2.get(date).size() < 2)
  369 + continue;
  370 + List<Long> fcsjs = new ArrayList<Long>();
  371 + List<Long> fcsjAs = new ArrayList<Long>();
  372 + for(ScheduleRealInfo schedule : keyMap2.get(date)){
  373 + if(schedule.getFcsjT() != null && !schedule.isSflj())
  374 + fcsjs.add(schedule.getFcsjT());
  375 + if(schedule.getFcsjActualTime() != null && schedule.getStatus() != -1)
  376 + fcsjAs.add(schedule.getFcsjActualTime());
  377 + }
  378 + Collections.sort(fcsjs);
  379 + Collections.sort(fcsjAs);
  380 +
  381 + if(statu.equals("1")){
  382 + for(int i = 1; i < fcsjs.size(); i++){
  383 + long fcsj1 = fcsjs.get(i - 1);
  384 + long fcsj2 = fcsjs.get(i);
  385 + Long time = fcsj1/60;
  386 + if(!timeMap0.containsKey(time) && !timeMap1.containsKey(time)){
  387 + timeMap0.put(time, new ArrayList<Long>());
  388 + timeMap1.put(time, new ArrayList<Long>());
  389 + timeList.add(time);
  390 + }
  391 + timeMap0.get(time).add(fcsj2 - fcsj1);
  392 + }
  393 + for(int i = 1; i < fcsjAs.size(); i++){
  394 + long fcsj1 = fcsjAs.get(i - 1);
  395 + long fcsj2 = fcsjAs.get(i);
  396 + Long time = fcsj1/60;
  397 + if(timeMap1.containsKey(time)){
  398 + timeMap1.get(time).add(fcsj2 - fcsj1);
  399 + }
  400 + }
  401 + }else if(statu.equals("0")){
  402 + for(int i = 1; i < fcsjs.size(); i++){
  403 + long fcsj1 = fcsjs.get(i - 1);
  404 + long fcsj2 = fcsjs.get(i);
  405 + if(!temp0.containsKey(key) && !temp1.containsKey(key)){
  406 + temp0.put(key, new ArrayList<Long>());
  407 + temp1.put(key, new ArrayList<Long>());
  408 + if(!keyList.contains(key))
  409 + keyList.add(key);
  410 + }
  411 + temp0.get(key).add(fcsj2 - fcsj1);
  412 + }
  413 + for(int i = 1; i < fcsjAs.size(); i++){
  414 + long fcsj1 = fcsjAs.get(i - 1);
  415 + long fcsj2 = fcsjAs.get(i);
  416 + temp1.get(key).add(fcsj2 - fcsj1);
284 417 }
285 418 }
286 419 }
287   - if(startDate.equals(endDate))
288   - tempMap.put("date", startDate);
289   - else
290   - tempMap.put("date", startDate + "--" + endDate);
291   - String[] keys = key.split("/");
292   - tempMap.put("line", keys[0]);
293   - tempMap.put("qdz", keys[1]);
294   - tempMap.put("times", times);
295   - tempMap.put("company", companyName);
296   - tempMap.put("subCompany", subCompanyName);
297   - if(jhNum != 0)
298   - tempMap.put("jhInterval", jhInterval/jhNum);
299   - else
300   - tempMap.put("jhInterval", "/");
301   - if(sjNum != 0){
302   - tempMap.put("sjInterval", sjInterval/sjNum);
303   - tempMap.put("deviation", sjInterval/sjNum - jhInterval/jhNum);
304   - }
305   - else{
306   - tempMap.put("sjInterval", "/");
307   - tempMap.put("deviation", "/");
  420 +
  421 + if(statu.equals("1")){
  422 + for(Long time : timeList){
  423 + Map<String, Object> tempMap = new HashMap<String, Object>();
  424 + List<Long> fcsjs = timeMap0.get(time);
  425 + List<Long> fcsjAs = timeMap1.get(time);
  426 + Collections.sort(fcsjs);
  427 + Collections.sort(fcsjAs);
  428 + String[] split = key.split("/");
  429 + tempMap.put("date", Date);
  430 + tempMap.put("line", split[1]);
  431 + tempMap.put("qdz", split[2]);
  432 + tempMap.put("company", companyName);
  433 + tempMap.put("subCompany", subCompanyName);
  434 + long jhInterval = 0l;
  435 + long sjInterval = 0l;
  436 + for(Long i : fcsjs)
  437 + jhInterval += i;
  438 + for(Long i : fcsjAs)
  439 + sjInterval += i;
  440 + tempMap.put("jhInterval", fcsjs.size()>0?df.format((double)jhInterval/fcsjs.size()):"/");
  441 + tempMap.put("sjInterval", fcsjAs.size()>0?df.format((double)sjInterval/fcsjAs.size()):"/");
  442 + tempMap.put("MaxInterval", fcsjAs.size()>0?fcsjAs.get(fcsjAs.size() - 1):"/");
  443 + tempMap.put("MinInterval", fcsjAs.size()>0?fcsjAs.get(0):"/");
  444 + tempMap.put("times", (time>9?time:"0"+time) + ":00-" + (time+1>9?(time+1):"0"+(time+1)) + ":00");
  445 + if(tempMap.get("jhInterval").toString().equals("/")
  446 + ||tempMap.get("sjInterval").toString().equals("/")){
  447 + tempMap.put("deviation", "/");
  448 + } else {
  449 + tempMap.put("deviation", df.format(Double.valueOf(tempMap.get("sjInterval").toString())
  450 + - Double.valueOf(tempMap.get("jhInterval").toString())));
  451 + }
  452 + tempList.add(tempMap);
  453 + }
308 454 }
309   - if(tempMap.get("jhInterval") != null && !tempMap.get("jhInterval").toString().equals("0") && !tempMap.get("jhInterval").toString().equals("/"))
310   - resList.add(tempMap);
311 455 }
312 456  
313   - //排序
314   - Map<String, List<Map<String, Object>>> temp = new HashMap<String, List<Map<String, Object>>>();
315   - List<Map<String, Object>> tempList = new ArrayList<Map<String, Object>>();
316   - for(Map<String, Object> m : resList){
317   - String key = m.get("line").toString();
318   - if(!temp.containsKey(key))
319   - temp.put(key, new ArrayList<Map<String, Object>>());
320   - temp.get(key).add(m);
321   - }
322   - for(String key : temp.keySet()){
323   - for(Map<String, Object> m : temp.get(key)){
324   - tempList.add(m);
  457 + if(statu.equals("1")){
  458 + List<Long> sortList = new ArrayList<Long>();
  459 + Map<Long, List<Map<String, Object>>> sortMap = new HashMap<Long, List<Map<String, Object>>>();
  460 + for(Map<String, Object> m : tempList){
  461 + Long sort = Long.valueOf(m.get("times").toString().substring(0, 2));
  462 + if(!sortMap.containsKey(sort)){
  463 + sortMap.put(sort, new ArrayList<Map<String, Object>>());
  464 + sortList.add(sort);
  465 + }
  466 + sortMap.get(sort).add(m);
  467 + }
  468 + Collections.sort(sortList);
  469 + for(Long sort : sortList){
  470 + for(Map<String, Object> m : sortMap.get(sort))
  471 + resList.add(m);
  472 + }
  473 + }else if(statu.equals("0")){
  474 + List<Long> longList = new ArrayList<Long>();
  475 + for(String key : keyList){
  476 + long xlBm = Long.valueOf(key.split("/")[0]);
  477 + if(!longList.contains(xlBm))
  478 + longList.add(xlBm);
  479 + Collections.sort(longList);
  480 + }
  481 + for(long xlBm : longList){
  482 + for(String key : keyList){
  483 + String[] split = key.split("/");
  484 + if((long)Long.valueOf(split[0]) == xlBm){
  485 + Map<String, Object> tempMap = new HashMap<String, Object>();
  486 + List<Long> fcsjs = temp0.get(key);
  487 + List<Long> fcsjAs = temp1.get(key);
  488 + Collections.sort(fcsjs);
  489 + Collections.sort(fcsjAs);
  490 + long fcsj = 0l;
  491 + long fcsjA = 0l;
  492 + for(long l : fcsjs)
  493 + fcsj += l;
  494 + for(long l : fcsjAs)
  495 + fcsjA += l;
  496 + tempMap.put("date", Date);
  497 + tempMap.put("line", split[1]);
  498 + tempMap.put("qdz", split[2]);
  499 + tempMap.put("company", companyName);
  500 + tempMap.put("subCompany", subCompanyName);
  501 + tempMap.put("jhInterval", fcsjs.size()>0?df.format((double)fcsj/fcsjs.size()):"/");
  502 + tempMap.put("sjInterval", fcsjAs.size()>0?df.format((double)fcsjA/fcsjAs.size()):"/");
  503 + tempMap.put("MaxInterval", fcsjAs.size()>0?fcsjAs.get(fcsjAs.size() - 1):"/");
  504 + tempMap.put("MinInterval", fcsjAs.size()>0?fcsjAs.get(0):"/");
  505 + if(tempMap.get("jhInterval").toString().equals("/")
  506 + ||tempMap.get("sjInterval").toString().equals("/")){
  507 + tempMap.put("deviation", "/");
  508 + } else {
  509 + tempMap.put("deviation", df.format(Double.valueOf(tempMap.get("sjInterval").toString())
  510 + - Double.valueOf(tempMap.get("jhInterval").toString())));
  511 + }
  512 + resList.add(tempMap);
  513 + }
  514 + }
325 515 }
326 516 }
327 517  
328   - return tempList;
  518 + return resList;
329 519 }
330 520  
331 521 @Override
332 522 public Map<String, Object> timeAndSpeed(Map<String, Object> map) {
  523 + List<Long> ttList = new ArrayList<Long>();
  524 + List<ChildTaskPlan> cList = new ArrayList<ChildTaskPlan>();
  525 + List<ScheduleRealInfo> list = new ArrayList<ScheduleRealInfo>();
333 526 List<Map<String, Object>> resList = new ArrayList<Map<String, Object>>();
334   - List<Map<String, Object>> dateList = new ArrayList<Map<String, Object>>();
  527 + List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>();
335 528 Map<String, List<ScheduleRealInfo>> keyMap = new HashMap<String, List<ScheduleRealInfo>>();
  529 + Map<String, List<ChildTaskPlan>> cMap = new HashMap<String, List<ChildTaskPlan>>();
336 530 Map<String, Object> modelMap = new HashMap<String, Object>();
337   -
  531 +
338 532 String company = map.get("company").toString();
339 533 String subCompany = map.get("subCompany").toString();
  534 + String lp = map.get("lp").toString();
340 535 String line = map.get("line").toString();
  536 + String statu = map.get("statu").toString();
341 537 String startDate = map.get("startDate").toString();
342 538 String endDate = map.get("endDate").toString();
343 539 String model = map.get("model").toString();
344   - String times = map.get("times").toString();
345 540 String type = map.get("type").toString();
346   - String zdzName = map.get("upDown").toString();
347   -
  541 +
348 542 if(startDate.length() == 0){
349 543 startDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
350 544 }
351 545 if(endDate.length() == 0){
352 546 endDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
353 547 }
354   - if(times.length() == 0){
355   - times = "06:00-07:00";
  548 +
  549 + try {
  550 +
  551 + String sql = "select * from bsth_c_s_sp_info_real where DATE_FORMAT(schedule_date,'%Y-%m-%d') >= '"+startDate+"' and DATE_FORMAT(schedule_date,'%Y-%m-%d') <= '"+endDate+"'";
  552 + if(line.length() != 0 && statu.equals("1")){
  553 + sql += " and xl_bm = '"+line+"'";
  554 + }
  555 + if(lp.length() != 0 && statu.equals("1")){
  556 + sql += " and lp_name = '"+lp+"'";
  557 + }
  558 + if(company.length() != 0){
  559 + sql += " and gs_bm = '"+company+"' and fgs_bm = '"+subCompany+"'";
  560 + }
  561 + sql += " and bc_type != 'in' and bc_type != 'out' order by fcsj";
  562 +
  563 + list = jdbcTemplate.query(sql,
  564 + new RowMapper<ScheduleRealInfo>(){
  565 + @Override
  566 + public ScheduleRealInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
  567 + ScheduleRealInfo schedule = new ScheduleRealInfo();
  568 + schedule.setId(rs.getLong("id"));
  569 + schedule.setScheduleDateStr(rs.getString("schedule_date_Str"));
  570 + schedule.setRealExecDate(rs.getString("real_exec_date"));
  571 + schedule.setXlName(rs.getString("xl_name"));
  572 + schedule.setLpName(rs.getString("lp_name"));
  573 + schedule.setBcType(rs.getString("bc_type"));
  574 + schedule.setBcs(rs.getInt("bcs"));
  575 + schedule.setBcsj(rs.getInt("bcsj"));
  576 + schedule.setJhlc(rs.getDouble("jhlc"));
  577 + schedule.setDfsj(rs.getString("dfsj"));
  578 + schedule.setFcsj(rs.getString("fcsj"));
  579 + schedule.setFcsjActual(rs.getString("fcsj_actual"));
  580 + schedule.setZdsj(rs.getString("zdsj"));
  581 + schedule.setZdsjActual(rs.getString("zdsj_actual"));
  582 + schedule.setQdzName(rs.getString("qdz_name"));
  583 + schedule.setZdzName(rs.getString("zdz_name"));
  584 + schedule.setXlDir(rs.getString("xl_dir"));
  585 + schedule.setStatus(rs.getInt("status"));
  586 + schedule.setRemarks(rs.getString("remarks"));
  587 + schedule.setGsName(rs.getString("gs_name"));
  588 + schedule.setFgsName(rs.getString("fgs_name"));
  589 + schedule.setDfAuto(rs.getBoolean("df_auto"));
  590 + schedule.setOnline(rs.getBoolean("online"));
  591 + schedule.setClZbh(rs.getString("cl_zbh"));
  592 + schedule.setjGh(rs.getString("j_gh"));
  593 + schedule.setjName(rs.getString("j_name"));
  594 + schedule.setStatus(rs.getInt("status"));
  595 + schedule.setSpId(rs.getLong("sp_id"));
  596 + if(schedule.getDfsj() != null){
  597 + String[] split0 = schedule.getDfsj().split(":");
  598 + long dfsj = Long.valueOf(split0[0]) * 60 + Long.valueOf(split0[1]);
  599 + if(!schedule.getScheduleDateStr().equals(schedule.getRealExecDate()))
  600 + dfsj += 1440l;
  601 + schedule.setDfsj(dfsj/60 + ":" + dfsj%60);
  602 + schedule.setDfsjT(dfsj);
  603 + }
  604 + if(schedule.getFcsjActual() != null){
  605 + String[] split2 = schedule.getFcsjActual().split(":");
  606 + long fcsjA = Long.valueOf(split2[0]) * 60 + Long.valueOf(split2[1]);
  607 + if(!schedule.getScheduleDateStr().equals(schedule.getRealExecDate()))
  608 + fcsjA += 1440l;
  609 + schedule.setFcsjActual(fcsjA/60 + ":" + fcsjA%60);
  610 + schedule.setFcsjActualTime(fcsjA);
  611 + }
  612 + if(schedule.getZdsjActual() != null){
  613 + String[] split4 = schedule.getZdsjActual().split(":");
  614 + long zdsjA = Long.valueOf(split4[0]) * 60 + Long.valueOf(split4[1]);
  615 + if(!schedule.getScheduleDateStr().equals(schedule.getRealExecDate()))
  616 + zdsjA += 1440l;
  617 + schedule.setZdsjActual(zdsjA/60 + ":" + zdsjA%60);
  618 + schedule.setZdsjActualTime(zdsjA);
  619 + }
  620 + String[] split1 = schedule.getFcsj().split(":");
  621 + String[] split3 = schedule.getZdsj().split(":");
  622 + long fcsj = Long.valueOf(split1[0]) * 60 + Long.valueOf(split1[1]);
  623 + long zdsj = Long.valueOf(split3[0]) * 60 + Long.valueOf(split3[1]);
  624 +
  625 + if(!schedule.getScheduleDateStr().equals(schedule.getRealExecDate())){
  626 + fcsj += 1440l;
  627 + zdsj += 1440l;
  628 + }
  629 + schedule.setFcsj(fcsj/60 + ":" + fcsj%60);
  630 + schedule.setZdsj(zdsj/60 + ":" + zdsj%60);
  631 + schedule.setFcsjT(fcsj);
  632 + schedule.setZdsjT(zdsj);
  633 + return schedule;
  634 + }
  635 + });
  636 +
  637 + sql = "select * from bsth_c_s_child_task order by start_date";
  638 +
  639 + cList = jdbcTemplate.query(sql,
  640 + new RowMapper<ChildTaskPlan>(){
  641 + @Override
  642 + public ChildTaskPlan mapRow(ResultSet rs, int rowNum) throws SQLException {
  643 + ChildTaskPlan cTask = new ChildTaskPlan();
  644 + cTask.setDestroy(rs.getBoolean("destroy"));
  645 + cTask.setStartDate(rs.getString("start_date"));
  646 + cTask.setEndDate(rs.getString("end_date"));
  647 + cTask.setMileage(rs.getFloat("mileage"));
  648 + cTask.setMileageType(rs.getString("mileage_type"));
  649 + cTask.setRemarks(rs.getString("schedule"));
  650 + return cTask;
  651 + }
  652 + });
  653 +
  654 + if(model.length() != 0){
  655 + sql = "select id from bsth_c_s_sp_info where tt_info = '" + model + "' and bc_type != 'in' and bc_type != 'out'";
  656 +
  657 + ttList = jdbcTemplate.query(sql,
  658 + new RowMapper<Long>(){
  659 + @Override
  660 + public Long mapRow(ResultSet rs, int rowNum) throws SQLException {
  661 + return rs.getLong("id");
  662 + }
  663 + });
  664 + }
  665 +
  666 + } catch (Exception e) {
  667 + // TODO: handle exception
  668 + e.printStackTrace();
356 669 }
357   -
358   - List<ScheduleRealInfo> list = this.getSchedule(company, subCompany, line, startDate, endDate, model, times);
359 670  
  671 +
360 672 String[] date1 = startDate.split("-");
361 673 String[] date2 = endDate.split("-");
  674 + String date = "";
362 675 startDate = date1[0] + "年" + date1[1] + "月" + date1[2] + "日";
363 676 endDate = date2[0] + "年" + date2[1] + "月" + date2[2] + "日";
364   -
365   - String[] split = times.split("-");
366   - int startTime = Integer.valueOf(split[0].split(":")[0])*60 + Integer.valueOf(split[0].split(":")[1]);
367   - int endTime = Integer.valueOf(split[1].split(":")[0])*60 + Integer.valueOf(split[1].split(":")[1]);
  677 + if(startDate.equals(endDate)){
  678 + date = date1[0] + "年" + date1[1] + "月" + date1[2] + "日";
  679 + } else {
  680 + date = date1[0] + "年" + date1[1] + "月" + date1[2] + "日--" +
  681 + date2[0] + "年" + date2[1] + "月" + date2[2] + "日";
  682 + }
  683 +
  684 + for(ChildTaskPlan cTask : cList){
  685 + String key = cTask.getRemarks();
  686 + if(!cMap.containsKey(key))
  687 + cMap.put(key, new ArrayList<ChildTaskPlan>());
  688 + cMap.get(key).add(cTask);
  689 + }
368 690  
369 691 for(ScheduleRealInfo schedule : list){
370   - if(zdzName.length() != 0 && !zdzName.equals(schedule.getZdzName())){
371   - continue;
372   - }
373   - int fcsj = Integer.valueOf(schedule.getFcsjT() + "");
374   - if(!(endTime != 0?(fcsj >= startTime && fcsj < endTime):(fcsj >= startTime))){
375   - continue;
376   - }
377   - String key = schedule.getXlName() + "/" + schedule.getLpName() + "/" + schedule.getZdzName();
378   - if(!keyMap.containsKey(key)){
379   - keyMap.put(key, new ArrayList<ScheduleRealInfo>());
  692 + if(model.length() != 0){
  693 + for(Long tt : ttList)
  694 + if((long) tt == (long)schedule.getSpId()){
  695 + String key = schedule.getScheduleDateStr() + "/" + schedule.getXlName() + "/" + schedule.getLpName();
  696 + if(!keyMap.containsKey(key))
  697 + keyMap.put(key, new ArrayList<ScheduleRealInfo>());
  698 + keyMap.get(key).add(schedule);
  699 + }
  700 + }else{
  701 + String key = schedule.getScheduleDateStr() + "/" + schedule.getXlName() + "/" + schedule.getLpName();
  702 + if(!keyMap.containsKey(key))
  703 + keyMap.put(key, new ArrayList<ScheduleRealInfo>());
  704 + keyMap.get(key).add(schedule);
380 705 }
381   - keyMap.get(key).add(schedule);
382 706 }
383   -
384   - long yysjSum = 0;
385   - double yysdSum = 0;
386   - long yssjSum = 0;
387   - double yssdSum = 0;
  707 +
  708 + String companyName = "", subCompanyName = "";
388 709 for(String key : keyMap.keySet()){
389 710 Map<String, Object> tempMap = new HashMap<String, Object>();
390   - long yysj = 0;
391   - double yysd = 0;
392   - long yssj = 0;
393   - double yssd = 0;
394   - int yyNum = 0;
395   - int ysNum = 0;
396   - String companyName = "", subCompanyName = "";
397   - for(ScheduleRealInfo schedule : keyMap.get(key)){
398   - if(schedule.getGsName() != null && companyName.length() == 0)
  711 + Map<Long, ScheduleRealInfo> sortMap = new HashMap<Long, ScheduleRealInfo>();
  712 + List<Map<String, Object>> mapList = new ArrayList<Map<String, Object>>();
  713 + List<Long> keyList = new ArrayList<Long>();
  714 + List<ScheduleRealInfo> list2 = keyMap.get(key);
  715 + long jhyysj = 0, sjyysj = 0;
  716 + long jhyssj = 0, sjyssj = 0;
  717 + double jhlc = 0, sjlc = 0;
  718 + for(ScheduleRealInfo schedule : list2){
  719 + if(companyName.length() == 0 && schedule.getGsName() != null){
399 720 companyName = schedule.getGsName();
400   - if(schedule.getFgsName() != null && subCompanyName.length() == 0)
  721 + }
  722 + if(subCompanyName.length() == 0 && schedule.getFgsName() != null){
401 723 subCompanyName = schedule.getFgsName();
402   - if(!tempMap.containsKey("xlDir"))
403   - tempMap.put("xlDir", schedule.getXlDir());
404   - if(!tempMap.containsKey("qdz_zdz") && schedule.getXlDir().equals("0"))
405   - tempMap.put("qdz_zdz", schedule.getQdzName() + "--" + schedule.getZdzName());
406   - else if(!tempMap.containsKey("qdz_zdz"))
407   - tempMap.put("qdz_zdz", schedule.getZdzName() + "--" + schedule.getQdzName());
408   - if(schedule.getBcsj() != null && schedule.getJhlc() != null){
409   - int bcsj = schedule.getBcsj();
410   - double jhlc = schedule.getJhlc();
411   - yysd += jhlc/bcsj;
412   - yysj += bcsj;
413   - yyNum++;
414   - if(schedule.getFcsjActual() != null && schedule.getZdsjActual() != null){
415   - long time = schedule.getZdsjActualTime() - schedule.getFcsjActualTime();
416   - yssd += jhlc/time;
417   - yssj += time;
418   - ysNum++;
  724 + }
  725 + long fcsj = schedule.getFcsjT();
  726 + if(sortMap.containsKey(fcsj)){
  727 + if(sortMap.get(fcsj).getFcsjActual() != null)
  728 + continue;
  729 + } else {
  730 + keyList.add(fcsj);
  731 + }
  732 + sortMap.put(fcsj, schedule);
  733 + }
  734 + Collections.sort(keyList);
  735 +
  736 + for(int i = 1; i < keyList.size(); i++){
  737 + ScheduleRealInfo schedule1 = sortMap.get(keyList.get(i - 1));
  738 + ScheduleRealInfo schedule2 = sortMap.get(keyList.get(i));
  739 + jhyysj += schedule2.getFcsjT() - schedule1.getFcsjT();
  740 +
  741 + long zdsj2 = schedule2.getZdsjT();
  742 + long fcsj2 = schedule2.getFcsjT();
  743 + if(fcsj2 > zdsj2)
  744 + zdsj2 += 1440l;
  745 + jhyssj += zdsj2 - fcsj2;
  746 + jhlc += schedule2.getJhlc()==null?0:schedule2.getJhlc();
  747 + if(i == 1){
  748 + long zdsj1 = schedule1.getZdsjT();
  749 + long fcsj1 = schedule1.getFcsjT();
  750 + if(fcsj1 > zdsj1)
  751 + zdsj1 += 1440l;
  752 + jhyssj += zdsj1 - fcsj1;
  753 + jhlc += schedule1.getJhlc()==null?0:schedule1.getJhlc();
  754 + }
  755 + }
  756 +
  757 + for(int i = 0; i < keyList.size(); i++){
  758 + Map<String, Object> m = new HashMap<String, Object>();
  759 + ScheduleRealInfo schedule = sortMap.get(keyList.get(i));
  760 +
  761 + if(cMap.containsKey(schedule.getId())){
  762 + List<ChildTaskPlan> cTasks = cMap.get(schedule.getId());
  763 + for(ChildTaskPlan childTaskPlan : cTasks){
  764 + Map<String, Object> temp = new HashMap<String, Object>();
  765 + if(childTaskPlan.getMileageType().equals("empty") || childTaskPlan.isDestroy()){
  766 + temp.put("lc", null);
  767 + temp.put("fcsj", null);
  768 + temp.put("zdsj", null);
  769 + }else{
  770 + temp.put("lc", childTaskPlan.getMileage()==null?0:childTaskPlan.getMileage());
  771 + if(childTaskPlan.getStartDate() != null && childTaskPlan.getEndDate() != null){
  772 + String[] split1 = childTaskPlan.getStartDate().split(":");
  773 + Long fcsj = Long.valueOf(split1[0])*60 + Long.valueOf(split1[1]);
  774 + temp.put("fcsj", fcsj);
  775 + String[] split2 = childTaskPlan.getEndDate().split(":");
  776 + Long zdsj = Long.valueOf(split2[0])*60 + Long.valueOf(split2[1]);
  777 + temp.put("zdsj", zdsj);
  778 + }else{
  779 + temp.put("zdsj", null);
  780 + temp.put("fcsj", null);
  781 + }
  782 + }
  783 + mapList.add(temp);
419 784 }
  785 + }else{
  786 + m.put("lc", schedule.getJhlc()==null?0:schedule.getJhlc());
  787 + if(schedule.getFcsjActual() != null && schedule.getZdsjActual() != null && schedule.getStatus() != -1){
  788 + String[] split1 = schedule.getFcsjActual().split(":");
  789 + Long fcsj = Long.valueOf(split1[0])*60 + Long.valueOf(split1[1]);
  790 + schedule.setFcsjActualTime(fcsj);
  791 + m.put("fcsj", fcsj);
  792 + String[] split2 = schedule.getZdsjActual().split(":");
  793 + Long zdsj = Long.valueOf(split2[0])*60 + Long.valueOf(split2[1]);
  794 + schedule.setZdsjActualTime(zdsj);
  795 + m.put("zdsj", zdsj);
  796 + }else{
  797 + m.put("zdsj", null);
  798 + m.put("fcsj", null);
  799 + }
  800 + mapList.add(m);
  801 + }
  802 + }
  803 + for(int i = 1; i < mapList.size(); i++){
  804 + Map<String, Object> m1 = mapList.get(i - 1);
  805 + Map<String, Object> m2 = mapList.get(i);
  806 + if(m1.get("fcsj") != null && m2.get("fcsj") != null){
  807 + sjyysj += Long.valueOf(m2.get("fcsj").toString()) - Long.valueOf(m1.get("fcsj").toString());
  808 + }
  809 + if(m2.get("fcsj") != null){
  810 + long zdsj = Long.valueOf(m2.get("zdsj").toString());
  811 + long fcsj = Long.valueOf(m2.get("fcsj").toString());
  812 + if(fcsj > zdsj)
  813 + zdsj += 1440l;
  814 + sjyssj += zdsj - fcsj;
  815 + sjlc += Double.valueOf(m2.get("lc").toString());
  816 + }
  817 + if(i == 1 && m1.get("fcsj") != null){
  818 + long zdsj = Long.valueOf(m1.get("zdsj").toString());
  819 + long fcsj = Long.valueOf(m1.get("fcsj").toString());
  820 + if(fcsj > zdsj)
  821 + zdsj += 1440l;
  822 + sjyssj += zdsj - fcsj;
  823 + sjlc += Double.valueOf(m1.get("lc").toString());
420 824 }
421 825 }
422   - if(startTime != endTime)
423   - tempMap.put("date", startDate + "--" + endDate);
424   - else
425   - tempMap.put("date", startDate);
426   - tempMap.put("times", times);
427   - String[] keys = key.split("/");
428   - tempMap.put("line", keys[0]);
429   - tempMap.put("lp", keys[1]);
430   - tempMap.put("zdz", keys[2]);
431 826 tempMap.put("company", companyName);
432 827 tempMap.put("subCompany", subCompanyName);
  828 + String[] split = key.split("/");
  829 + tempMap.put("date", split[0]);
  830 + tempMap.put("line", split[1]);
  831 + tempMap.put("lp", split[2]);
  832 + tempMap.put("jhlc", jhlc);
  833 + tempMap.put("sjlc", sjlc);
  834 +
  835 + if(jhyysj == 0){
  836 + tempMap.put("jhyysj", "0");
  837 + tempMap.put("jhyycs", "0");
  838 + } else {
  839 + tempMap.put("jhyysj", df.format((float)jhyysj / 60));
  840 + tempMap.put("jhyycs", df.format(jhlc == 0 ? 0 : jhlc / jhyysj * 60));
  841 + }
433 842  
434   - tempMap.put("yysj", (yysj/60) + "小时" + (yysj%60) + "分钟");
435   - yysjSum += yysj;
436   - if(yyNum != 0){
437   - tempMap.put("yysd", df.format((yysd/yyNum)*60) + "公里/小时");
438   - yysdSum += Double.valueOf(df.format((yysd/yyNum)*60));
  843 + if(jhyssj == 0){
  844 + tempMap.put("jhyssj", "0");
  845 + tempMap.put("jhyscs", "0");
439 846 } else {
440   - tempMap.put("yysd", "/");
  847 + tempMap.put("jhyssj", df.format((float)jhyssj / 60));
  848 + tempMap.put("jhyscs", df.format(jhlc == 0 ? 0 : jhlc / jhyssj * 60));
441 849 }
442 850  
443   - tempMap.put("yssj", (yssj/60) + "小时" + (yssj%60) + "分钟");
444   - yssjSum += yssj;
445   - if(ysNum != 0){
446   - tempMap.put("yssd", df.format((yssd/ysNum)*60) + "公里/小时");
447   - yssdSum += Double.valueOf(df.format((yssd/ysNum)*60));
  851 + if(sjyysj == 0){
  852 + tempMap.put("sjyysj", "0");
  853 + tempMap.put("sjyycs", "0");
448 854 } else {
449   - tempMap.put("yssd", "/");
  855 + tempMap.put("sjyysj", df.format((float)sjyysj / 60));
  856 + tempMap.put("sjyycs", df.format(sjlc == 0 ? 0 : sjlc / sjyysj * 60));
450 857 }
451 858  
452   - dateList.add(tempMap);
  859 + if(sjyssj == 0){
  860 + tempMap.put("sjyssj", "0");
  861 + tempMap.put("sjyscs", "0");
  862 + } else {
  863 + tempMap.put("sjyssj", df.format((float)sjyssj / 60));
  864 + tempMap.put("sjyscs", df.format(sjlc == 0 ? 0 : sjlc / sjyssj * 60));
  865 + }
  866 + resList.add(tempMap);
453 867 }
454   - int size = keyMap.keySet().size();
455   - size = size == 0 ? 1 : size;
456   - modelMap.put("yysj", (yysjSum/size)/60 + "小时" + (yysjSum/size)%60 + "分钟");
457   - modelMap.put("yysd", df.format(yysdSum/size) + "公里/小时");
458   - modelMap.put("yssj", (yssjSum/size)/60 + "小时" + (yssjSum/size)%60 + "分钟");
459   - modelMap.put("yssd", df.format(yssdSum/size) + "公里/小时");
460   -
461 868 Map<String, List<Map<String, Object>>> keyMap2 = new HashMap<String, List<Map<String, Object>>>();
462   - for(Map<String, Object> m : dateList){
463   - String key = m.get("line").toString();
  869 + for(Map<String, Object> m : resList){
  870 + String key = m.get("line").toString() + "/" + m.get("lp").toString();
464 871 if(!keyMap2.containsKey(key))
465 872 keyMap2.put(key, new ArrayList<Map<String, Object>>());
466 873 keyMap2.get(key).add(m);
467 874 }
468   - for(String key : keyMap2.keySet()){
469   - List<Integer> keyList = new ArrayList<Integer>();
470   - Map<Integer, List<Map<String, Object>>> temp = new HashMap<Integer, List<Map<String,Object>>>();
471   - for(Map<String, Object> m : keyMap2.get(key)){
472   - String lp = m.get("lp").toString();
473   - String str = "";
474   - for(int i = 0; i < lp.length(); i++){
475   - str += (int)lp.charAt(i);
  875 + Set<String> keySet = keyMap2.keySet();
  876 + List<String> list3 = new ArrayList<String>();
  877 + List<Map<String, Object>> list4 = new ArrayList<Map<String, Object>>();
  878 + list3.addAll(keySet);
  879 + Collections.sort(list3, new Comparator<String>() {
  880 +
  881 + public int compare(String o1, String o2) {
  882 +
  883 + Long a = 0l;
  884 + Long b = 0l;
  885 + String[] split1 = o1.split("/");
  886 + String[] split2 = o2.split("/");
  887 + char[] charArray1 = split1[1].toCharArray();
  888 + char[] charArray2 = split2[1].toCharArray();
  889 + for(int i = 0; i < charArray1.length; i++){
  890 + long temp = 1l;
  891 + for(int j = 0; j < i; j++)
  892 + temp *= 10;
  893 + a += (long)charArray1[charArray1.length - 1 - i] * temp;
476 894 }
477   - Integer num = Integer.valueOf(str)*10+Integer.valueOf(m.get("xlDir").toString());
478   - if(!temp.containsKey(num)){
479   - temp.put(num, new ArrayList<Map<String, Object>>());
480   - keyList.add(num);
  895 + for(int i = 0; i < charArray2.length; i++){
  896 + long temp = 1l;
  897 + for(int j = 0; j < i; j++)
  898 + temp *= 10;
  899 + b += (long)charArray2[charArray2.length - 1 - i] * temp;
481 900 }
482   - temp.get(num).add(m);
  901 +
  902 + return a.compareTo(b);
483 903 }
484   - Collections.sort(keyList);
485   - for(Integer lp : keyList){
486   - List<Map<String, Object>> tempList = temp.get(lp);
487   - for(Map<String, Object> m : tempList){
488   - resList.add(m);
  904 + });
  905 + Collections.sort(list3, new Comparator<String>() {
  906 +
  907 + public int compare(String o1, String o2) {
  908 +
  909 + Long a = 0l;
  910 + Long b = 0l;
  911 + String[] split1 = o1.split("/");
  912 + String[] split2 = o2.split("/");
  913 + char[] charArray1 = split1[0].toCharArray();
  914 + char[] charArray2 = split2[0].toCharArray();
  915 + for(int i = 0; i < charArray1.length; i++){
  916 + long temp = 1l;
  917 + for(int j = 0; j < i; j++)
  918 + temp *= 10;
  919 + a += (long)charArray1[charArray1.length - 1 - i] * temp;
  920 + }
  921 + for(int i = 0; i < charArray2.length; i++){
  922 + long temp = 1l;
  923 + for(int j = 0; j < i; j++)
  924 + temp *= 10;
  925 + b += (long)charArray2[charArray2.length - 1 - i] * temp;
  926 + }
  927 +
  928 + return a.compareTo(b);
  929 + }
  930 + });
  931 + for(String key : list3){
  932 + Map<String, Object> tempMap = new HashMap<String, Object>();
  933 + BigDecimal jhyysj = new BigDecimal(0), jhyssj = new BigDecimal(0);
  934 + BigDecimal jhyycs = new BigDecimal(0), jhyscs = new BigDecimal(0);
  935 + BigDecimal sjyysj = new BigDecimal(0), sjyssj = new BigDecimal(0);
  936 + BigDecimal sjyycs = new BigDecimal(0), sjyscs = new BigDecimal(0);
  937 + for(Map<String, Object> m : keyMap2.get(key)){
  938 + jhyysj = jhyysj.add(new BigDecimal(m.get("jhyysj").toString()));
  939 + jhyssj = jhyssj.add(new BigDecimal(m.get("jhyssj").toString()));
  940 + jhyycs = jhyycs.add(new BigDecimal(m.get("jhyycs").toString()));
  941 + jhyscs = jhyscs.add(new BigDecimal(m.get("jhyscs").toString()));
  942 + sjyysj = sjyysj.add(new BigDecimal(m.get("sjyysj").toString()));
  943 + sjyssj = sjyssj.add(new BigDecimal(m.get("sjyssj").toString()));
  944 + sjyycs = sjyycs.add(new BigDecimal(m.get("sjyycs").toString()));
  945 + sjyscs = sjyscs.add(new BigDecimal(m.get("sjyscs").toString()));
  946 + }
  947 + BigDecimal size = new BigDecimal(keyMap2.get(key).size());
  948 + tempMap.put("jhyysj", jhyysj.equals(0)?0:jhyysj.divide(size, 2, RoundingMode.HALF_UP));
  949 + tempMap.put("jhyssj", jhyssj.equals(0)?0:jhyssj.divide(size, 2, RoundingMode.HALF_UP));
  950 + tempMap.put("jhyycs", jhyycs.equals(0)?0:jhyycs.divide(size, 2, RoundingMode.HALF_UP));
  951 + tempMap.put("jhyscs", jhyscs.equals(0)?0:jhyscs.divide(size, 2, RoundingMode.HALF_UP));
  952 + tempMap.put("sjyysj", sjyysj.equals(0)?0:sjyysj.divide(size, 2, RoundingMode.HALF_UP));
  953 + tempMap.put("sjyssj", sjyssj.equals(0)?0:sjyssj.divide(size, 2, RoundingMode.HALF_UP));
  954 + tempMap.put("sjyycs", sjyycs.equals(0)?0:sjyycs.divide(size, 2, RoundingMode.HALF_UP));
  955 + tempMap.put("sjyscs", sjyscs.equals(0)?0:sjyscs.divide(size, 2, RoundingMode.HALF_UP));
  956 + String[] split = key.split("/");
  957 + tempMap.put("line", split[0]);
  958 + tempMap.put("lp", split[1]);
  959 + tempMap.put("company", companyName);
  960 + tempMap.put("subCompany", subCompanyName);
  961 + tempMap.put("date", date);
  962 + list4.add(tempMap);
  963 + }
  964 + modelMap.put("dataList", list4);
  965 +
  966 + if(statu.equals("0")){
  967 + Map<String, List<Map<String, Object>>> keyMap4 = new HashMap<String, List<Map<String, Object>>>();
  968 + List<Map<String, Object>> list5 = new ArrayList<Map<String, Object>>();
  969 + List<String> keyList = new ArrayList<String>();
  970 + for(Map<String, Object> m : list4){
  971 + String key = m.get("line").toString();
  972 + if(!keyMap4.containsKey(key)){
  973 + keyList.add(key);
  974 + keyMap4.put(key, new ArrayList<Map<String, Object>>());
489 975 }
  976 + keyMap4.get(key).add(m);
  977 + }
  978 + for(String key : keyList){
  979 + Map<String, Object> tempMap = new HashMap<String, Object>();
  980 + BigDecimal jhyysj = new BigDecimal(0), jhyssj = new BigDecimal(0);
  981 + BigDecimal jhyycs = new BigDecimal(0), jhyscs = new BigDecimal(0);
  982 + BigDecimal sjyysj = new BigDecimal(0), sjyssj = new BigDecimal(0);
  983 + BigDecimal sjyycs = new BigDecimal(0), sjyscs = new BigDecimal(0);
  984 + for(Map<String, Object> m : keyMap4.get(key)){
  985 + jhyysj = jhyysj.add(new BigDecimal(m.get("jhyysj").toString()));
  986 + jhyssj = jhyssj.add(new BigDecimal(m.get("jhyssj").toString()));
  987 + jhyycs = jhyycs.add(new BigDecimal(m.get("jhyycs").toString()));
  988 + jhyscs = jhyscs.add(new BigDecimal(m.get("jhyscs").toString()));
  989 + sjyysj = sjyysj.add(new BigDecimal(m.get("sjyysj").toString()));
  990 + sjyssj = sjyssj.add(new BigDecimal(m.get("sjyssj").toString()));
  991 + sjyycs = sjyycs.add(new BigDecimal(m.get("sjyycs").toString()));
  992 + sjyscs = sjyscs.add(new BigDecimal(m.get("sjyscs").toString()));
  993 + }
  994 + BigDecimal size = new BigDecimal(keyMap4.get(key).size());
  995 + tempMap.put("jhyysj", jhyysj.equals(0)?0:jhyysj.divide(size, 2, RoundingMode.HALF_UP));
  996 + tempMap.put("jhyssj", jhyssj.equals(0)?0:jhyssj.divide(size, 2, RoundingMode.HALF_UP));
  997 + tempMap.put("jhyycs", jhyycs.equals(0)?0:jhyycs.divide(size, 2, RoundingMode.HALF_UP));
  998 + tempMap.put("jhyscs", jhyscs.equals(0)?0:jhyscs.divide(size, 2, RoundingMode.HALF_UP));
  999 + tempMap.put("sjyysj", sjyysj.equals(0)?0:sjyysj.divide(size, 2, RoundingMode.HALF_UP));
  1000 + tempMap.put("sjyssj", sjyssj.equals(0)?0:sjyssj.divide(size, 2, RoundingMode.HALF_UP));
  1001 + tempMap.put("sjyycs", sjyycs.equals(0)?0:sjyycs.divide(size, 2, RoundingMode.HALF_UP));
  1002 + tempMap.put("sjyscs", sjyscs.equals(0)?0:sjyscs.divide(size, 2, RoundingMode.HALF_UP));
  1003 + tempMap.put("line", key);
  1004 + tempMap.put("lp", keyMap4.get(key).size());
  1005 + tempMap.put("company", companyName);
  1006 + tempMap.put("subCompany", subCompanyName);
  1007 + tempMap.put("date", date);
  1008 + tempMap.put("work", keyMap4.get(key));
  1009 + list5.add(tempMap);
  1010 + }
  1011 +
  1012 +
  1013 + modelMap.put("dataList", list5);
  1014 + }
  1015 + modelMap.put("statu", statu);
  1016 +
  1017 + dataList = (List<Map<String, Object>>)modelMap.get("dataList");
  1018 + if(dataList.size() != 0){
  1019 + BigDecimal jhyysj = new BigDecimal(0), jhyssj = new BigDecimal(0);
  1020 + BigDecimal jhyycs = new BigDecimal(0), jhyscs = new BigDecimal(0);
  1021 + BigDecimal sjyysj = new BigDecimal(0), sjyssj = new BigDecimal(0);
  1022 + BigDecimal sjyycs = new BigDecimal(0), sjyscs = new BigDecimal(0);
  1023 + for(Map<String, Object> m : dataList){
  1024 + jhyysj = jhyysj.add(new BigDecimal(m.get("jhyysj").toString()));
  1025 + jhyssj = jhyssj.add(new BigDecimal(m.get("jhyssj").toString()));
  1026 + jhyycs = jhyycs.add(new BigDecimal(m.get("jhyycs").toString()));
  1027 + jhyscs = jhyscs.add(new BigDecimal(m.get("jhyscs").toString()));
  1028 + sjyysj = sjyysj.add(new BigDecimal(m.get("sjyysj").toString()));
  1029 + sjyssj = sjyssj.add(new BigDecimal(m.get("sjyssj").toString()));
  1030 + sjyycs = sjyycs.add(new BigDecimal(m.get("sjyycs").toString()));
  1031 + sjyscs = sjyscs.add(new BigDecimal(m.get("sjyscs").toString()));
490 1032 }
  1033 + BigDecimal size = new BigDecimal(dataList.size());
  1034 + modelMap.put("jhyysj", jhyysj.equals(0)?0:jhyysj.divide(size, 2, RoundingMode.HALF_UP));
  1035 + modelMap.put("jhyssj", jhyssj.equals(0)?0:jhyssj.divide(size, 2, RoundingMode.HALF_UP));
  1036 + modelMap.put("jhyycs", jhyycs.equals(0)?0:jhyycs.divide(size, 2, RoundingMode.HALF_UP));
  1037 + modelMap.put("jhyscs", jhyscs.equals(0)?0:jhyscs.divide(size, 2, RoundingMode.HALF_UP));
  1038 + modelMap.put("sjyysj", sjyysj.equals(0)?0:sjyysj.divide(size, 2, RoundingMode.HALF_UP));
  1039 + modelMap.put("sjyssj", sjyssj.equals(0)?0:sjyssj.divide(size, 2, RoundingMode.HALF_UP));
  1040 + modelMap.put("sjyycs", sjyycs.equals(0)?0:sjyycs.divide(size, 2, RoundingMode.HALF_UP));
  1041 + modelMap.put("sjyscs", sjyscs.equals(0)?0:sjyscs.divide(size, 2, RoundingMode.HALF_UP));
  1042 + modelMap.put("company", companyName);
  1043 + modelMap.put("subCompany", subCompanyName);
  1044 + modelMap.put("dataList", dataList);
491 1045 }
492 1046  
493   - modelMap.put("dateList", resList);
494 1047 return modelMap;
495 1048 }
496 1049  
... ... @@ -523,7 +1076,7 @@ public class BusIntervalServiceImpl implements BusIntervalService {
523 1076 times = "06:00-07:00";
524 1077 }
525 1078  
526   - list = getSchedule(company, subCompany, line, startDate, endDate, model, times);
  1079 + list = getSchedule(company, subCompany, line, startDate, endDate, model, times, true);
527 1080  
528 1081 String[] date1 = startDate.split("-");
529 1082 String[] date2 = endDate.split("-");
... ... @@ -534,7 +1087,6 @@ public class BusIntervalServiceImpl implements BusIntervalService {
534 1087 int startTime = Integer.valueOf(split[0].split(":")[0])*60 + Integer.valueOf(split[0].split(":")[1]);
535 1088 int endTime = Integer.valueOf(split[1].split(":")[0])*60 + Integer.valueOf(split[1].split(":")[1]);
536 1089  
537   -
538 1090 for(ScheduleRealInfo schedule : list){
539 1091 if(qdzName.length() != 0 && !qdzName.equals(schedule.getQdzName())){
540 1092 continue;
... ... @@ -550,26 +1102,11 @@ public class BusIntervalServiceImpl implements BusIntervalService {
550 1102 }
551 1103 for(String key : keyMap.keySet()){
552 1104 Map<String, Object> tempMap = new HashMap<String, Object>();
553   - int jhbc = 0;
554   - int sjbc = 0;
555   - int kbc = 0;
556   - int mbc = 0;
557   - long jhdf = 0l;
558   - long sjdf = 0l;
559   - long wddf1 = 0l;
560   - long wddf2 = 0l;
561   - long jhfc = 0l;
562   - long sjfc = 0l;
563   - long wdfc1 = 0l;
564   - long wdfc2 = 0l;
565   - long jhys = 0l;
566   - long sjys = 0l;
567   - long yssjMax = 0l;
568   - long yssjMin = 0l;
569   - long jhtz = 0l;
570   - long sjtz = 0l;
571   - long tzsjMax = 0l;
572   - long tzsjMin = 0l;
  1105 + int jhbc = 0, sjbc = 0, kbc = 0, mbc = 0;
  1106 + long jhdf = 0l, sjdf = 0l, wddf1 = 0l, wddf2 = 0l;
  1107 + long jhfc = 0l, sjfc = 0l, wdfc1 = 0l, wdfc2 = 0l;
  1108 + long jhys = 0l, sjys = 0l, yssjMax = 0l, yssjMin = 0l;
  1109 + long jhtz = 0l, sjtz = 0l, tzsjMax = 0l, tzsjMin = 0l;
573 1110 String companyName = "", subCompanyName = "";
574 1111 for(ScheduleRealInfo schedule : keyMap.get(key)){
575 1112 if(schedule.getGsName() != null && companyName.length() == 0)
... ... @@ -776,7 +1313,7 @@ public class BusIntervalServiceImpl implements BusIntervalService {
776 1313  
777 1314 return resList;
778 1315 }
779   -
  1316 +
780 1317 @Override
781 1318 public List<Map<String, Object>> lbStatuAnaly(Map<String, Object> map) {
782 1319 List<Map<String, Object>> resList = new ArrayList<Map<String, Object>>();
... ... @@ -802,7 +1339,7 @@ public class BusIntervalServiceImpl implements BusIntervalService {
802 1339 times = "06:00-07:00";
803 1340 }
804 1341  
805   - list = getSchedule(company, subCompany, line, startDate, endDate, model, times);
  1342 + list = getSchedule(company, subCompany, line, startDate, endDate, model, times, true);
806 1343  
807 1344 String[] date1 = startDate.split("-");
808 1345 String[] date2 = endDate.split("-");
... ... @@ -974,9 +1511,9 @@ public class BusIntervalServiceImpl implements BusIntervalService {
974 1511 if(company.length() != 0){
975 1512 sql += " and gs_bm = '"+company+"' and fgs_bm = '"+subCompany+"'";
976 1513 }
977   - sql += " and bc_type = 'normal'";
  1514 + sql += " and bc_type != 'in' and bc_type != 'out'";
978 1515  
979   - list =jdbcTemplate.query(sql,
  1516 + list = jdbcTemplate.query(sql,
980 1517 new RowMapper<ScheduleRealInfo>(){
981 1518 @Override
982 1519 public ScheduleRealInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
... ...
src/main/java/com/bsth/service/oil/impl/YlbServiceImpl.java
... ... @@ -131,6 +131,7 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
131 131 t.setXlbm(map.get("xlBm")==null?"":map.get("xlBm").toString());
132 132 t.setJcsx(Integer.parseInt(map.get("seqNumber").toString()));
133 133 t.setSsgsdm(map.get("company")==null?"":map.get("company").toString());
  134 + t.setFgsdm(map.get("bCompany")==null?"":map.get("bCompany").toString());
134 135 t.setRq(dBefore);
135 136 repository.save(t);
136 137 result = "success";
... ... @@ -216,6 +217,7 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
216 217 t.setXlbm(map.get("xlBm")==null?"":map.get("xlBm").toString());
217 218 t.setJcsx(Integer.parseInt(map.get("seqNumber").toString()));
218 219 t.setSsgsdm(map.get("company")==null?"":map.get("company").toString());
  220 + t.setFgsdm(map.get("bCompany")==null?"":map.get("bCompany").toString());
219 221 t.setRq(sdf.parse(rq));
220 222 repository.save(t);
221 223 newMap.put("status", ResponseCode.SUCCESS);
... ...
src/main/java/com/bsth/service/realcontrol/ScheduleRealInfoService.java
... ... @@ -27,8 +27,8 @@ public interface ScheduleRealInfoService extends BaseService&lt;ScheduleRealInfo, L
27 27  
28 28 List<Map<String, String>> sreachVehic(String nbbm);
29 29  
30   - Map<String, Object> adjust(Long id, String nbbm, String jsy, String spy, Integer revertLine, Integer borrowLine, String borrowTimeStr, String revertTimeStr);
31   -
  30 +/* Map<String, Object> adjust(Long id, String nbbm, String jsy, String spy, Integer revertLine, Integer borrowLine, String borrowTimeStr, String revertTimeStr);
  31 + */
32 32 /**
33 33 *
34 34 * @Title: adjustCar
... ... @@ -59,7 +59,7 @@ public interface ScheduleRealInfoService extends BaseService&lt;ScheduleRealInfo, L
59 59 */
60 60 void adjustConductor(ScheduleRealInfo schedule, String conductor, String conductorName);
61 61  
62   - List<ScheduleRealInfo> queryUserInfo(String line,String date);
  62 + List<ScheduleRealInfo> queryUserInfo(String line,String date,String state);
63 63  
64 64 List<ScheduleRealInfo> exportWaybill(String jName,String clZbh,String lpName,String date);
65 65  
... ...
src/main/java/com/bsth/service/realcontrol/impl/LineConfigServiceImpl.java
... ... @@ -70,7 +70,7 @@ public class LineConfigServiceImpl extends BaseServiceImpl&lt;LineConfig, Integer&gt;
70 70 LineConfig conf = lineConfigData.get(lineCode);
71 71  
72 72 conf.setOutConfig(type);
73   - conf.setInConfig(type);
  73 + //conf.setInConfig(type);
74 74 lineConfigData.set(conf);
75 75  
76 76 rs.put("status", ResponseCode.SUCCESS);
... ...
src/main/java/com/bsth/service/realcontrol/impl/ScheduleRealInfoServiceImpl.java
... ... @@ -382,7 +382,7 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
382 382 return list;
383 383 }
384 384  
385   - @Override
  385 +/* @Override
386 386 public Map<String, Object> adjust(Long id, String nbbm, String jsy, String spy, Integer revertLine, Integer borrowLine, String borrowTimeStr, String revertTimeStr) {
387 387 // 班次
388 388 ScheduleRealInfo schedule = dayOfSchedule.get(id);
... ... @@ -435,7 +435,7 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
435 435 map.put("status", 200);
436 436 map.put("t", schedule);
437 437 return map;
438   - }
  438 + }*/
439 439  
440 440 @Override
441 441 public void adjustCar(ScheduleRealInfo schedule, String car) {
... ... @@ -459,8 +459,13 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
459 459 }
460 460  
461 461 @Override
462   - public List<ScheduleRealInfo> queryUserInfo(String line, String date) {
463   - return scheduleRealInfoRepository.queryUserInfo2(line, date);
  462 + public List<ScheduleRealInfo> queryUserInfo(String line, String date,String state) {
  463 + if(state.equals("2")){
  464 + return scheduleRealInfoRepository.queryUserInfo2(line, date);
  465 + }else{
  466 + return scheduleRealInfoRepository.queryUserInfo3(line, date);
  467 + }
  468 +
464 469 }
465 470 /**
466 471 *
... ... @@ -613,13 +618,6 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
613 618  
614 619 @Override
615 620 public List<Object[]> historyMessage(String line, String date, String code) {
616   -
617   - String sql="select t.car_code,d.sender,d.txt_content,d.timestamp from ("
618   - + " select equipment_code,car_code from bsth_c_cars where id in("
619   - + " select cl from bsth_c_s_ccinfo where xl in ( "
620   - + " select id from bsth_c_line where line_code=?1 ))) t"
621   - + " left join bsth_v_directive_60 d on t.equipment_code=d.device_id "
622   - + " where d.timestamp >=?2 and d.timestamp <=?3 and t.car_code like '%?4%'";
623 621 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
624 622 long d= 0;
625 623 long t=0;
... ... @@ -680,7 +678,8 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
680 678 sch.addRemarks(remarks);
681 679 sch.calcStatus();
682 680  
683   - scheduleRealInfoRepository.save(sch);
  681 + dayOfSchedule.save(sch);
  682 + //scheduleRealInfoRepository.save(sch);
684 683  
685 684 ts.add(sch);
686 685  
... ... @@ -883,10 +882,13 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
883 882 next.setQdzArrDateSJ(zdsjActual);
884 883 ts.add(next);
885 884 }
  885 +
  886 + //重新计算车辆执行班次
  887 + dayOfSchedule.reCalcExecPlan(sch.getClZbh());
886 888 }
887 889 }
888 890 else {
889   - if(sch.getZdsjActual() != null){
  891 + /*if(sch.getZdsjActual() != null){
890 892 //将对应的到离站数据标记为不可信
891 893 List<ArrivalEntity> list = ArrivalData_GPS.findByNbbm(sch.getClZbh());
892 894 for(ArrivalEntity arr : list){
... ... @@ -898,7 +900,7 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
898 900 break;
899 901 }
900 902 }
901   - }
  903 + }*/
902 904  
903 905 //清除实达时间
904 906 sch.clearZdsjActual();
... ... @@ -1182,7 +1184,11 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
1182 1184 while(it.hasNext()){
1183 1185 ChildTaskPlan childTaskPlan = it.next();
1184 1186 if(childTaskPlan.getMileageType().equals("empty")){
1185   - ksgl += childTaskPlan.getMileage()==null?0:childTaskPlan.getMileage();
  1187 + if(childTaskPlan.isDestroy()){
  1188 + remMileage += childTaskPlan.getMileage()==null?0:childTaskPlan.getMileage();
  1189 + }else{
  1190 + ksgl += childTaskPlan.getMileage()==null?0:childTaskPlan.getMileage();
  1191 + }
1186 1192 }else{
1187 1193 if(childTaskPlan.isDestroy()){
1188 1194 remMileage += childTaskPlan.getMileage()==null?0:childTaskPlan.getMileage();
... ... @@ -1240,11 +1246,33 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
1240 1246 @Override
1241 1247 public List<ScheduleRealInfo> queryListWaybill(String jName, String clZbh,
1242 1248 String lpName,String date,String type) {
  1249 + List <ScheduleRealInfo> list=null;
1243 1250 if(type.equals("qp")){
1244   - return scheduleRealInfoRepository.queryListWaybill2(jName,clZbh,lpName,date);
  1251 + list= scheduleRealInfoRepository.queryListWaybill2(jName,clZbh,lpName,date);
1245 1252 }else{
1246   - return scheduleRealInfoRepository.queryListWaybill(jName,clZbh,lpName,date);
  1253 + list= scheduleRealInfoRepository.queryListWaybill(jName,clZbh,lpName,date);
1247 1254 }
  1255 + for (int i = 0; i < list.size(); i++) {
  1256 + ScheduleRealInfo s=list.get(i);
  1257 + String remarks="";
  1258 + if(s.getRemarks()!=null){
  1259 + remarks +=s.getRemarks();
  1260 + }
  1261 + Set<ChildTaskPlan> childTaskPlans = s.getcTasks();
  1262 + if(!childTaskPlans.isEmpty()){
  1263 + Iterator<ChildTaskPlan> it = childTaskPlans.iterator();
  1264 + while(it.hasNext()){
  1265 + ChildTaskPlan c = it.next();
  1266 + if(c.getRemarks()!=null && c.getRemarks().length()>0){
  1267 + remarks += c.getRemarks();
  1268 + }
  1269 +
  1270 + }
  1271 + }
  1272 + s.setRemarks(remarks);
  1273 + }
  1274 +
  1275 + return list;
1248 1276 }
1249 1277  
1250 1278 @Override
... ... @@ -1325,11 +1353,6 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
1325 1353 }else{
1326 1354 ssgl_other += tempJhlc;
1327 1355 }
1328   -
1329   -
1330   - }else{
1331   - ssgl += tempJhlc;
1332   - ssgl_other += tempJhlc;
1333 1356 }
1334 1357 }else{
1335 1358 Iterator<ChildTaskPlan> it = childTaskPlans.iterator();
... ... @@ -1570,6 +1593,7 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
1570 1593 //根据线路代码获取公司
1571 1594 Line li = lineRepository.findByLineCode(scheduleRealInfo.getXlBm());
1572 1595 yesterdayDataList.get(i).put("company", li.getCompany());
  1596 + yesterdayDataList.get(i).put("bCompany", li.getBrancheCompany());
1573 1597 //计算总公里
1574 1598 Set<ChildTaskPlan> childTaskPlans = scheduleRealInfo.getcTasks();
1575 1599 //如果没有子任务,里程就是已执行(Status=2);有子任务的,忽略主任务,子任务的烂班
... ...
src/main/java/com/bsth/service/report/ReportService.java
... ... @@ -19,11 +19,13 @@ public interface ReportService {
19 19  
20 20 List<Object[]> historyMessageCount(String line, String date, String code);
21 21  
22   - Map<String, Object> tbodyTime1(String line ,String date);
  22 + Map<String, Object> tbodyTime1(String line ,String ttinfo);
23 23  
24   - Map<String, Object> tbodyTime2(String line ,String date);
  24 + Map<String, Object> tbodyTime2(String line ,String ttinfo);
25 25  
26   - List<Map<String, Object>> tbodyTime3(String line ,String date);
27   - List<Map<String, Object>> tbodyTime5(String line ,String date);
  26 + List<Map<String, Object>> tbodyTime3(String line ,String ttinfo);
  27 + List<Map<String, Object>> tbodyTime5(String line ,String ttinfo);
  28 +
  29 + List<Map<String, Object>> getTtinfo(Map<String, Object> map);
28 30  
29 31 }
... ...
src/main/java/com/bsth/service/report/impl/ReportServiceImpl.java
... ... @@ -257,16 +257,18 @@ public class ReportServiceImpl implements ReportService{
257 257 return list;
258 258 }
259 259 @Override
260   - public Map<String, Object> tbodyTime1(String line, String date) {
  260 + public Map<String, Object> tbodyTime1(String line, String ttinfo) {
261 261 DecimalFormat df = new DecimalFormat("#0.00");
262 262 // TODO Auto-generated method stub
263 263 //查询配车
264   - String sqlPc=" SELECT cl_zbh FROM bsth_c_s_sp_info "
265   - +" where DATE_FORMAT(schedule_date,'%Y-%m-%d') ='"+date+"' "
266   - + " and xl_bm='"+line+"' and bc_type='normal' "
267   - + " group by cl_zbh ";
  264 + String sqlPc=" select count(*) from bsth_c_cars where id in("
  265 + + " select cl from bsth_c_s_ccinfo where xl in ( "
  266 + + " select id from bsth_c_line where line_code='"+line+"' )"
  267 + + " group by equipment_code ) ";
  268 +
268 269 Map<String, Object> map=new HashMap<String,Object>();
269   - List<Map<String, Object>> listPc= jdbcTemplate.query(sqlPc,
  270 +
  271 + /*List<Map<String, Object>> listPc= jdbcTemplate.query(sqlPc,
270 272 new RowMapper<Map<String, Object>>(){
271 273 @Override
272 274 public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
... ... @@ -274,13 +276,12 @@ public class ReportServiceImpl implements ReportService{
274 276 m.put("zbh", rs.getString("cl_zbh"));
275 277 return m;
276 278 }
277   - });
  279 + });*/
278 280 //配车
279   - int pcs=listPc.size();
280   -
281   -
282   - String sqlPlan="select jhlc, bc_type ,fcsj from bsth_c_s_sp_info "
283   - + "where DATE_FORMAT(schedule_date,'%Y-%m-%d') ='"+date+"' and xl_bm='"+line+"'";
  281 + int pcs=jdbcTemplate.queryForObject(sqlPc, Integer.class);
  282 +
  283 + String sqlPlan=" SELECT jhlc,bc_type,fcsj FROM bsth_c_s_ttinfo_detail "
  284 + +" where ttinfo ='"+ttinfo+"' ";
284 285  
285 286 //班次
286 287 int zgf_0 = 6*60+31,zgf_1 = 8*60+30,wgf_0 = 16*60+1,wgf_1 = 18*60;
... ... @@ -306,17 +307,10 @@ public class ReportServiceImpl implements ReportService{
306 307 String fcsjs[]=m.get("fcsj").toString().split(":");
307 308  
308 309 zlc +=jhlc;
309   - if(bcType.equals("normal")){
310   - qcBc ++;
311   - if((Integer.parseInt(fcsjs[0])*60+Integer.parseInt(fcsjs[1])) > zgf_0
312   - && (Integer.parseInt(fcsjs[0])*60+Integer.parseInt(fcsjs[1])) < zgf_1){
313   - zqcBc++;
314   - }else if((Integer.parseInt(fcsjs[0])*60+Integer.parseInt(fcsjs[1])) > wgf_0
315   - && (Integer.parseInt(fcsjs[0])*60+Integer.parseInt(fcsjs[1])) < wgf_1){
316   - wqcBc++;
317   - }
318   - yylc +=jhlc;
319   - }else if(bcType.equals("region")){
  310 + if(bcType.equals("in") || bcType.equals("out")){
  311 + kslc+=jhlc;
  312 + }
  313 + else if(bcType.equals("region")){
320 314 qjBc++;
321 315 if((Integer.parseInt(fcsjs[0])*60+Integer.parseInt(fcsjs[1])) > zgf_0
322 316 && (Integer.parseInt(fcsjs[0])*60+Integer.parseInt(fcsjs[1])) < zgf_1){
... ... @@ -328,7 +322,15 @@ public class ReportServiceImpl implements ReportService{
328 322  
329 323 yylc+=jhlc;
330 324 }else{
331   - kslc+=jhlc;
  325 + qcBc ++;
  326 + if((Integer.parseInt(fcsjs[0])*60+Integer.parseInt(fcsjs[1])) > zgf_0
  327 + && (Integer.parseInt(fcsjs[0])*60+Integer.parseInt(fcsjs[1])) < zgf_1){
  328 + zqcBc++;
  329 + }else if((Integer.parseInt(fcsjs[0])*60+Integer.parseInt(fcsjs[1])) > wgf_0
  330 + && (Integer.parseInt(fcsjs[0])*60+Integer.parseInt(fcsjs[1])) < wgf_1){
  331 + wqcBc++;
  332 + }
  333 + yylc +=jhlc;
332 334 }
333 335 }
334 336  
... ... @@ -346,30 +348,91 @@ public class ReportServiceImpl implements ReportService{
346 348 return map;
347 349 }
348 350 @Override
349   - public Map<String, Object> tbodyTime2(String line, String date) {
  351 + public Map<String, Object> tbodyTime2(String line, String ttinfo) {
350 352 DecimalFormat df = new DecimalFormat("#0.00");
351 353 // TODO Auto-generated method stub
352   - //查询配车
353   - String sqlPc=" SELECT sum(bcsj) as yysj ,sum(jhlc) as yygl FROM bsth_c_s_sp_info "
354   - +" where DATE_FORMAT(schedule_date,'%Y-%m-%d') ='"+date+"' "
355   - + " and xl_bm='"+line+"' and bc_type in ('normal' ,'region' )";
  354 + //最早营运时间 区分夜宵线
  355 + String sqlMinYysj="select start_opt from bsth_c_line_config where line = '"+BasicData.lineId2CodeMap.inverse().get(line) +"'";
  356 + String minfcsj=jdbcTemplate.queryForObject(sqlMinYysj, String.class);
  357 + String[] minSjs = minfcsj.split(":");
  358 + int minSj=Integer.parseInt(minSjs[0])*60+Integer.parseInt(minSjs[1]);
  359 + //查询时间里程
  360 + String sqlPc=" (SELECT jhlc,fcsj,bc_type,lp,2 as xh FROM bsth_c_s_ttinfo_detail "
  361 + + " where ttinfo ='"+ttinfo+"' and fcsj <='"+minfcsj+"' ) "
  362 + + " union "
  363 + + " (SELECT jhlc,fcsj,bc_type,lp,1 as xh FROM bsth_c_s_ttinfo_detail "
  364 + + " where ttinfo ='"+ttinfo+"' and fcsj > '"+minfcsj+"') order by lp,xh,fcsj";
  365 +
356 366 Map<String, Object> map=new HashMap<String,Object>();
357 367 List<Map<String, Object>> list= jdbcTemplate.query(sqlPc,
358 368 new RowMapper<Map<String, Object>>(){
359 369 @Override
360 370 public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
361 371 Map<String, Object> m=new HashMap<String,Object>();
362   - m.put("yysj", rs.getInt("yysj"));
363   - m.put("yygl", rs.getString("yygl")==null?"0":rs.getString("yygl"));
  372 + m.put("fcsj", rs.getString("fcsj"));
  373 + m.put("yygl", rs.getString("jhlc")==null?"0":rs.getString("jhlc"));
  374 + m.put("bcType", rs.getString("bc_type"));
  375 + m.put("lp", rs.getString("lp"));
364 376 return m;
365 377 }
366 378 });
367 379 int yysj=0 ;
368 380 double yycs=0 ,yygl=0;
369   - if(list.size()>0){
370   - Map<String, Object> m=list.get(0);
371   - yysj=Integer.parseInt((m.get("yysj").toString()));
372   - yygl=Double.parseDouble(m.get("yygl").toString());
  381 + String lp ="0";
  382 + int sj=0;
  383 +
  384 + for(int i=0;i<list.size();i++){
  385 + Map<String, Object> m=list.get(i);
  386 + String time=m.get("fcsj").toString();
  387 + String[] times = time.split(":");
  388 + if(lp.equals(m.get("lp").toString())){
  389 + if(Integer.parseInt(times[0])*60+Integer.parseInt(times[1]) <=minSj){
  390 + if(m.get("bcType").equals("in") || m.get("bcType").equals("out")){
  391 + if(m.get("bcType").equals("in")){
  392 + if(sj!=0){
  393 + yysj +=(Integer.parseInt(times[0])+24)*60+Integer.parseInt(times[1])-sj;
  394 + }
  395 + sj=0;
  396 + }
  397 + }else{
  398 + yygl += Double.parseDouble(m.get("yygl").toString());
  399 +
  400 + if(sj==0){
  401 + sj=(Integer.parseInt(times[0])+24)*60+Integer.parseInt(times[1]);
  402 + }else{
  403 + yysj +=(Integer.parseInt(times[0])+24)*60+Integer.parseInt(times[1])-sj;
  404 + sj=(Integer.parseInt(times[0])+24)*60+Integer.parseInt(times[1]);
  405 + }
  406 + }
  407 + }else{
  408 + if(m.get("bcType").equals("in") || m.get("bcType").equals("out")){
  409 + if(m.get("bcType").equals("in")){
  410 + if(sj!=0){
  411 + yysj +=Integer.parseInt(times[0])*60+Integer.parseInt(times[1])-sj;
  412 + }
  413 + sj=0;
  414 + }
  415 + }else{
  416 + yygl += Double.parseDouble(m.get("yygl").toString());
  417 +
  418 + if(sj==0){
  419 + sj=Integer.parseInt(times[0])*60+Integer.parseInt(times[1]);
  420 + }else{
  421 + yysj +=Integer.parseInt(times[0])*60+Integer.parseInt(times[1])-sj;
  422 + sj=Integer.parseInt(times[0])*60+Integer.parseInt(times[1]);
  423 + }
  424 + }
  425 + }
  426 + }else{
  427 + if( !(m.get("bcType").equals("in") || m.get("bcType").equals("out"))){
  428 + yygl += Double.parseDouble(m.get("yygl").toString());
  429 + sj =Integer.parseInt(times[0])*60+Integer.parseInt(times[1]);
  430 + }else{
  431 + sj=0;
  432 + }
  433 + lp=m.get("lp").toString();
  434 +
  435 + }
373 436 }
374 437 if(yysj>0){
375 438 yycs =yygl/(yysj*1.0/60);
... ... @@ -767,4 +830,34 @@ public class ReportServiceImpl implements ReportService{
767 830 newList.add(newmap5);
768 831 return newList;
769 832 }
  833 + @Override
  834 + public List<Map<String, Object>> getTtinfo(Map<String, Object> map) {
  835 + // TODO Auto-generated method stub
  836 + List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
  837 + String line = map.get("line").toString();
  838 + try {
  839 + String sql = "select tt.id, tt.name from bsth_c_s_ttinfo tt "
  840 + + "left join bsth_c_line cl on cl.id = tt.xl "
  841 + + " where tt.is_cancel = 0 and tt.is_enable_dis_template = 1";
  842 + if(line.length() != 0){
  843 + sql += " and cl.line_code = '"+line+"'";
  844 + }
  845 + sql += " order by tt.create_date desc";
  846 +
  847 + list = jdbcTemplate.query(sql,
  848 + new RowMapper<Map<String, Object>>(){
  849 + @Override
  850 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  851 + Map<String, Object> map = new HashMap<String, Object>();
  852 + map.put("id", rs.getString("id"));
  853 + map.put("name", rs.getString("name"));
  854 + return map;
  855 + }
  856 + });
  857 + }catch (Exception e) {
  858 + // TODO Auto-generated catch block
  859 + e.printStackTrace();
  860 + }
  861 + return list;
  862 + }
770 863 }
... ...
src/main/resources/ms-jdbc.properties
... ... @@ -8,4 +8,3 @@ ms.mysql.url= jdbc:mysql://192.168.80.21:3306/ms?useUnicode=true&amp;characterEncodi
8 8 ms.mysql.username= root
9 9 ms.mysql.password= root2jsp@JSP
10 10  
11   -
... ...