Commit 37848c9aa880a71961f6553743d97b9da8b65818

Authored by 潘钊
1 parent 4fa4687e

update

src/main/java/com/bsth/controller/realcontrol/ScheduleRealInfoController.java
1 1 package com.bsth.controller.realcontrol;
2 2  
3 3 import java.util.Collection;
  4 +import java.util.List;
4 5 import java.util.Map;
5 6  
6 7 import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -66,4 +67,40 @@ public class ScheduleRealInfoController extends BaseController<ScheduleRealInfo,
66 67 public Map<String, String> carDeviceMapp(){
67 68 return CommonMapped.vehicDeviceBiMap.inverse();
68 69 }
  70 +
  71 + /**
  72 + *
  73 + * @Title: findPersionByLine
  74 + * @Description: TODO(根据线路主键获取驾驶员)
  75 + * @param @param lineId
  76 + * @throws
  77 + */
  78 + @RequestMapping(value = "/driver", method = RequestMethod.GET)
  79 + public List<Map<String, String>> findDriverByLine(@RequestParam String lineCode){
  80 + return scheduleRealInfoService.findDriverByLine(lineCode);
  81 + }
  82 +
  83 + /**
  84 + *
  85 + * @Title: findPersionByLine
  86 + * @Description: TODO(根据线路主键获取售票员)
  87 + * @param @param lineId
  88 + * @throws
  89 + */
  90 + @RequestMapping(value = "/conductor", method = RequestMethod.GET)
  91 + public List<Map<String, String>> findConductorByLine(@RequestParam String lineCode){
  92 + return scheduleRealInfoService.findConductorByLine(lineCode);
  93 + }
  94 +
  95 + /**
  96 + *
  97 + * @Title: findPersionByLine
  98 + * @Description: TODO(根据线路主键获取车辆)
  99 + * @param @param lineId
  100 + * @throws
  101 + */
  102 + @RequestMapping(value = "/cars", method = RequestMethod.GET)
  103 + public List<Map<String, String>> findCarByLine(@RequestParam String lineCode){
  104 + return scheduleRealInfoService.findCarByLine(lineCode);
  105 + }
69 106 }
... ...
src/main/java/com/bsth/repository/schedule/CarConfigInfoRepository.java
... ... @@ -2,9 +2,13 @@ package com.bsth.repository.schedule;
2 2  
3 3 import com.bsth.entity.schedule.CarConfigInfo;
4 4 import com.bsth.repository.BaseRepository;
  5 +
  6 +import java.util.List;
  7 +
5 8 import org.springframework.data.domain.Page;
6 9 import org.springframework.data.domain.Pageable;
7 10 import org.springframework.data.jpa.repository.EntityGraph;
  11 +import org.springframework.data.jpa.repository.Query;
8 12 import org.springframework.stereotype.Repository;
9 13  
10 14 /**
... ... @@ -16,4 +20,9 @@ public interface CarConfigInfoRepository extends BaseRepository&lt;CarConfigInfo, L
16 20 @EntityGraph(value = "carConfigInfo_xl_cl", type = EntityGraph.EntityGraphType.FETCH)
17 21 @Override
18 22 Page<CarConfigInfo> findAll(Pageable pageable);
  23 +
  24 +
  25 + @EntityGraph(value = "carConfigInfo_xl_cl", type = EntityGraph.EntityGraphType.FETCH)
  26 + @Query("select cc from CarConfigInfo cc where cc.xl.lineCode=?1")
  27 + List<CarConfigInfo> findBylineCode(String lineCode);
19 28 }
... ...
src/main/java/com/bsth/repository/schedule/EmployeeConfigInfoRepository.java
... ... @@ -16,6 +16,6 @@ import org.springframework.stereotype.Repository;
16 16 public interface EmployeeConfigInfoRepository extends BaseRepository<EmployeeConfigInfo, Long> {
17 17  
18 18 @EntityGraph(value = "employeeConfigInfo_xl_cl", type = EntityGraph.EntityGraphType.FETCH)
19   - @Query("select ec from EmployeeConfigInfo ec where ec.xl.id=?1")
20   - List<EmployeeConfigInfo> findByLine(Integer lineId);
  19 + @Query("select ec from EmployeeConfigInfo ec where ec.xl.lineCode=?1")
  20 + List<EmployeeConfigInfo> findBylineCode(String lineCode);
21 21 }
... ...
src/main/java/com/bsth/service/realcontrol/ScheduleRealInfoService.java
1 1 package com.bsth.service.realcontrol;
2 2  
3 3 import java.util.Collection;
  4 +import java.util.List;
4 5 import java.util.Map;
5 6  
6 7 import org.springframework.stereotype.Service;
... ... @@ -17,4 +18,10 @@ public interface ScheduleRealInfoService extends BaseService&lt;ScheduleRealInfo, L
17 18  
18 19 Map<String, Object> destroy(String idsStr, int spaceAdjust, String remarks, String reason, int spaceNum);
19 20  
  21 + List<Map<String, String>> findDriverByLine(String lineCode);
  22 +
  23 + List<Map<String, String>> findConductorByLine(String lineCode);
  24 +
  25 + List<Map<String, String>> findCarByLine(String lineCode);
  26 +
20 27 }
... ...
src/main/java/com/bsth/service/realcontrol/impl/ScheduleRealInfoServiceImpl.java
... ... @@ -14,8 +14,14 @@ import org.springframework.beans.factory.annotation.Autowired;
14 14 import org.springframework.stereotype.Service;
15 15  
16 16 import com.bsth.common.ResponseCode;
  17 +import com.bsth.entity.Cars;
  18 +import com.bsth.entity.Personnel;
17 19 import com.bsth.entity.realcontrol.ScheduleRealInfo;
  20 +import com.bsth.entity.schedule.CarConfigInfo;
  21 +import com.bsth.entity.schedule.EmployeeConfigInfo;
18 22 import com.bsth.repository.realcontrol.ScheduleRealInfoRepository;
  23 +import com.bsth.repository.schedule.CarConfigInfoRepository;
  24 +import com.bsth.repository.schedule.EmployeeConfigInfoRepository;
19 25 import com.bsth.service.impl.BaseServiceImpl;
20 26 import com.bsth.service.realcontrol.ScheduleRealInfoService;
21 27 import com.bsth.service.realcontrol.buffer.ScheduleBuffer;
... ... @@ -30,6 +36,12 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
30 36 @Autowired
31 37 ScheduleRealInfoRepository scheduleRealInfoRepository;
32 38  
  39 + @Autowired
  40 + EmployeeConfigInfoRepository employeeConfigInfoRepository;
  41 +
  42 + @Autowired
  43 + CarConfigInfoRepository carConfigInfoRepository;
  44 +
33 45 Logger logger = LoggerFactory.getLogger(this.getClass());
34 46  
35 47 SimpleDateFormat sdfMonth = new SimpleDateFormat("yyyy-MM-dd")
... ... @@ -139,4 +151,73 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
139 151 }
140 152 return map;
141 153 }
  154 +
  155 + //线路id获取驾驶员
  156 + @Override
  157 + public List<Map<String, String>> findDriverByLine(String lineCode) {
  158 + List<EmployeeConfigInfo> list = employeeConfigInfoRepository.findBylineCode(lineCode);
  159 +
  160 + List<Map<String, String>> rsList = new ArrayList<>();
  161 + Map<String, String> map = null;
  162 + Personnel driver = null;
  163 + String code = null;
  164 +
  165 + for(EmployeeConfigInfo employee : list){
  166 + driver = employee.getJsy();
  167 + if(driver != null){
  168 + map = new HashMap<>();
  169 + code = driver.getJobCode();
  170 + map.put("id", code);
  171 + map.put("text", code + "/" + driver.getPersonnelName());
  172 + rsList.add(map);
  173 + }
  174 + }
  175 + return rsList;
  176 + }
  177 +
  178 + //线路id获取售票员
  179 + @Override
  180 + public List<Map<String, String>> findConductorByLine(String lineCode) {
  181 + List<EmployeeConfigInfo> list = employeeConfigInfoRepository.findBylineCode(lineCode);
  182 +
  183 + List<Map<String, String>> rsList = new ArrayList<>();
  184 + Map<String, String> map = null;
  185 + Personnel conductor = null;
  186 + String code = null;
  187 +
  188 + for(EmployeeConfigInfo employee : list){
  189 + conductor = employee.getSpy();
  190 + if(conductor != null){
  191 + code = conductor.getJobCode();
  192 + map = new HashMap<>();
  193 + map.put("id", code);
  194 + map.put("text", code + "/" + conductor.getPersonnelName());
  195 + rsList.add(map);
  196 + }
  197 + }
  198 + return rsList;
  199 + }
  200 +
  201 + @Override
  202 + public List<Map<String, String>> findCarByLine(String lineCode) {
  203 +
  204 + List<CarConfigInfo> list = carConfigInfoRepository.findBylineCode(lineCode);
  205 +
  206 + List<Map<String, String>> rsList = new ArrayList<>();
  207 + Map<String, String> map = null;
  208 + Cars car = null;
  209 + String code = null;
  210 +
  211 + for(CarConfigInfo cci : list){
  212 + car = cci.getCl();
  213 + if(car != null){
  214 + code = car.getInsideCode();
  215 + map = new HashMap<>();
  216 + map.put("id", code);
  217 + map.put("text", code);
  218 + rsList.add(map);
  219 + }
  220 + }
  221 + return rsList;
  222 + }
142 223 }
... ...
src/main/java/com/bsth/vehicle/gpsdata/GpsArrivalStationThread.java
... ... @@ -8,7 +8,6 @@ import java.text.SimpleDateFormat;
8 8 import java.util.ArrayList;
9 9 import java.util.Calendar;
10 10 import java.util.Iterator;
11   -import java.util.LinkedList;
12 11 import java.util.List;
13 12 import java.util.Set;
14 13  
... ... @@ -37,7 +36,7 @@ public class GpsArrivalStationThread extends Thread{
37 36 Logger logger = LoggerFactory.getLogger(this.getClass());
38 37 SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
39 38  
40   - private static int diff = 1000 * 60 * 60;
  39 + private static int diff = 1000 * 60 * 20;
41 40  
42 41 @Override
43 42 public void run() {
... ... @@ -47,7 +46,6 @@ public class GpsArrivalStationThread extends Thread{
47 46 } catch (ParseException e) {
48 47 e.printStackTrace();
49 48 }
50   - System.out.println("size: " + list.size());
51 49 GpsArrivalDataBuffer.putAll(list);
52 50 //实际到离站和计划排班相匹配
53 51  
... ... @@ -85,26 +83,62 @@ public class GpsArrivalStationThread extends Thread{
85 83 }
86 84 }
87 85  
88   - //单个匹配
89 86 public void match(ScheduleRealInfo scInfo, ArrivalInfo arr){
  87 + try{
  88 + //匹配起点
  89 + matchStart(scInfo, arr);
  90 +
  91 + //计划终点
  92 + matchEnd(scInfo, arr);
  93 + }catch(Exception e){
  94 + e.printStackTrace();
  95 + }
  96 + }
  97 +
  98 + /**
  99 + *
  100 + * @Title: matchStart
  101 + * @Description: TODO(匹配起点 出站时间)
  102 + * @param @param scInfo
  103 + * @throws
  104 + */
  105 + public void matchStart(ScheduleRealInfo scInfo, ArrivalInfo arr){
  106 + if(scInfo.getFcsjT() == null
  107 + || arr.getInOut() != 1)
  108 + return;
  109 +
90 110 Long ts = arr.getTs();
91   - //起点
92   - if(scInfo.getFcsjActualTime() == null
93   - && scInfo.getQdzCode().equals(arr.getStopNo())
  111 + //起点站和发车时间比比较
  112 + if(scInfo.getQdzCode().equals(arr.getStopNo())
94 113 && Math.abs(scInfo.getFcsjT() - ts) < diff){
95   -
96 114 scInfo.setFcsjActualTime(ts);
97 115 scInfo.setFcsjActual(sdf.format(ts));
  116 +
98 117 System.out.println("成功匹配一个起点...");
  118 + ScheduleBuffer.persistentList.add(scInfo);
99 119 }
100   - //终点
101   - if(scInfo.getZdsjActualTime() == null
102   - && scInfo.getZdzCode().equals(arr.getStopNo())
  120 + }
  121 +
  122 + /**
  123 + *
  124 + * @Title: matchEnd
  125 + * @Description: TODO(匹配终点 进站时间)
  126 + * @throws
  127 + */
  128 + public void matchEnd(ScheduleRealInfo scInfo, ArrivalInfo arr){
  129 + if(scInfo.getZdsjT() == null
  130 + || arr.getInOut() != 0)
  131 + return;
  132 +
  133 + Long ts = arr.getTs();
  134 + //终点站和发车时间比较
  135 + if(scInfo.getZdzCode().equals(arr.getStopNo())
103 136 && Math.abs(scInfo.getZdsjT() - ts) < diff){
104   -
105 137 scInfo.setZdsjActualTime(ts);
106 138 scInfo.setZdsjActual(sdf.format(ts));
  139 +
107 140 System.out.println("成功匹配一个终点...");
  141 + ScheduleBuffer.persistentList.add(scInfo);
108 142 }
109 143 }
110 144  
... ... @@ -136,7 +170,7 @@ public class GpsArrivalStationThread extends Thread{
136 170 conn = DBUtils_MS.getConnection();
137 171 ps = conn.prepareStatement(sql);
138 172 ps.setInt(1, weeks_year);
139   - ps.setLong(2, GpsArrivalDataBuffer.markTime);
  173 + ps.setLong(2, /*GpsArrivalDataBuffer.markTime*/1467099600000L);
140 174  
141 175 Long t = System.currentTimeMillis();
142 176 rs = ps.executeQuery();
... ...
src/main/java/com/bsth/vehicle/gpsdata/controller/GpsDataController.java
1 1 package com.bsth.vehicle.gpsdata.controller;
2 2  
3 3 import java.util.List;
  4 +import java.util.Map;
4 5  
5 6 import org.springframework.beans.factory.annotation.Autowired;
6 7 import org.springframework.web.bind.annotation.PathVariable;
... ... @@ -10,6 +11,7 @@ import org.springframework.web.bind.annotation.RestController;
10 11  
11 12 import com.bsth.vehicle.gpsdata.buffer.GpsRealDataBuffer;
12 13 import com.bsth.vehicle.gpsdata.entity.GpsRealData;
  14 +import com.bsth.vehicle.gpsdata.service.GpsDataService;
13 15 import com.google.common.base.Splitter;
14 16  
15 17 @RestController
... ... @@ -19,6 +21,9 @@ public class GpsDataController {
19 21 @Autowired
20 22 GpsRealDataBuffer gpsBuffer;
21 23  
  24 + @Autowired
  25 + GpsDataService gpsDataService;
  26 +
22 27 @RequestMapping(value = "/real/line/{lineCode}")
23 28 public List<GpsRealData> findByLineCode(@PathVariable("lineCode") Integer lineCode){
24 29 return gpsBuffer.getListByLineCode(lineCode);
... ... @@ -28,4 +33,13 @@ public class GpsDataController {
28 33 public List<GpsRealData> findByLineCode(@RequestParam String lineCodes){
29 34 return gpsBuffer.getListByLines(Splitter.on(",").split(lineCodes).iterator());
30 35 }
  36 +
  37 + @RequestMapping(value = "/history/{device}")
  38 + public List<Map<String, Object>> history(@PathVariable("device") String device
  39 + ,@RequestParam Long startTime
  40 + ,@RequestParam Long endTime,
  41 + @RequestParam int directions){
  42 +
  43 + return gpsDataService.history(device, startTime, endTime, directions);
  44 + }
31 45 }
... ...
src/main/java/com/bsth/vehicle/gpsdata/entity/ArrivalInfo.java
... ... @@ -17,18 +17,17 @@ import javax.persistence.Transient;
17 17 public class ArrivalInfo {
18 18  
19 19 @Transient
20   - static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd")
21   - ,sdf2 = new SimpleDateFormat("HH:mm")
22   - ,sdf3 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
  20 + static SimpleDateFormat sdf = new SimpleDateFormat("HH:mm")
  21 + ,sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
23 22  
24 23  
25 24 public ArrivalInfo(String deviceId, Long ts, String lineCode, Integer upDown, String stopNo, Integer inOut,
26 25 Date createDate, Integer weeksYear) {
27 26 this.deviceId = deviceId;
28 27  
29   - //gps是2014年的数据,临时将ts拉到当天
  28 + //gps是2014年的数据,临时将ts拉到6月1号
30 29 try {
31   - this.ts = sdf3.parse(sdf.format(new Date()) +" " + sdf2.format(new Date(ts))).getTime();
  30 + this.ts = sdf2.parse("2016-06-01 " + sdf.format(new Date(ts))).getTime();
32 31 } catch (ParseException e) {
33 32 e.printStackTrace();
34 33 }
... ...
src/main/java/com/bsth/vehicle/gpsdata/service/GpsDataServiceImpl.java
... ... @@ -59,7 +59,7 @@ public class GpsDataServiceImpl implements GpsDataService{
59 59  
60 60 //to 百度坐标
61 61 lon = rs.getFloat("LON");
62   - lat = rs.getFloat("lat");
  62 + lat = rs.getFloat("LAT");
63 63 location = TransGPS.LocationMake(lon, lat);
64 64 location = TransGPS.bd_encrypt(TransGPS.transformFromWGSToGCJ(location));
65 65  
... ... @@ -67,7 +67,7 @@ public class GpsDataServiceImpl implements GpsDataService{
67 67 map.put("device", rs.getString("DEVICE_ID"));
68 68 map.put("lon", location.getLng());
69 69 map.put("lat", location.getLat());
70   - map.put("ts", rs.getLong("ts"));
  70 + map.put("ts", rs.getLong("TS"));
71 71 map.put("inout_stop", rs.getInt("INOUT_STOP"));
72 72 //上下行
73 73 map.put("upDown", upDown);
... ...