Commit c319a4c41b0f73068e8798362b548f88bf58eec4

Authored by 潘钊
1 parent 54e31c08

加入到离站预测模块

Showing 48 changed files with 1427 additions and 308 deletions
src/main/java/com/bsth/Application.java
... ... @@ -16,7 +16,7 @@ import org.springframework.context.annotation.Primary;
16 16 @SpringBootApplication
17 17 public class Application extends SpringBootServletInitializer {
18 18  
19   - public static ScheduledExecutorService mainServices = Executors.newScheduledThreadPool(8);
  19 + public static ScheduledExecutorService mainServices = Executors.newScheduledThreadPool(11);
20 20  
21 21 @Override
22 22 protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
... ...
src/main/java/com/bsth/controller/directive/DirectiveController.java
... ... @@ -62,7 +62,7 @@ public class DirectiveController {
62 62 * @param @param lineId 新线路编码
63 63 * @throws
64 64 */
65   - @RequestMapping(value = "/lineChnage", method = RequestMethod.GET)
  65 + @RequestMapping(value = "/lineChnage", method = RequestMethod.POST)
66 66 public int lineChange(@RequestParam String nbbm, @RequestParam Integer lineId){
67 67 SysUser user = SecurityUtils.getCurrentUser();
68 68 return directiveService.lineChange(nbbm, lineId, user.getUserName());
... ...
src/main/java/com/bsth/controller/directive/UpstreamEntrance.java
... ... @@ -3,7 +3,6 @@ package com.bsth.controller.directive;
3 3 import org.slf4j.Logger;
4 4 import org.slf4j.LoggerFactory;
5 5 import org.springframework.beans.factory.annotation.Autowired;
6   -import org.springframework.context.annotation.Scope;
7 6 import org.springframework.web.bind.annotation.RequestMapping;
8 7 import org.springframework.web.bind.annotation.RequestMethod;
9 8 import org.springframework.web.bind.annotation.RequestParam;
... ... @@ -26,7 +25,6 @@ import com.bsth.entity.directive.DirectiveReponse;
26 25 */
27 26 @RestController
28 27 @RequestMapping("/control")
29   -@Scope("prototype")
30 28 public class UpstreamEntrance {
31 29  
32 30 Logger logger = LoggerFactory.getLogger(this.getClass());
... ...
src/main/java/com/bsth/controller/forecast/SampleController.java
... ... @@ -2,7 +2,11 @@ package com.bsth.controller.forecast;
2 2  
3 3 import java.io.UnsupportedEncodingException;
4 4 import java.net.URLDecoder;
  5 +import java.util.HashMap;
  6 +import java.util.Map;
5 7  
  8 +import org.slf4j.Logger;
  9 +import org.slf4j.LoggerFactory;
6 10 import org.springframework.beans.factory.annotation.Autowired;
7 11 import org.springframework.web.bind.annotation.RequestMapping;
8 12 import org.springframework.web.bind.annotation.RequestParam;
... ... @@ -10,6 +14,7 @@ import org.springframework.web.bind.annotation.RestController;
10 14  
11 15 import com.alibaba.fastjson.JSON;
12 16 import com.alibaba.fastjson.JSONObject;
  17 +import com.bsth.common.ResponseCode;
13 18 import com.bsth.controller.BaseController;
14 19 import com.bsth.controller.forecast.dto.CreateSampleParam;
15 20 import com.bsth.entity.forecast.Sample;
... ... @@ -22,16 +27,20 @@ public class SampleController extends BaseController<Sample, Long>{
22 27 @Autowired
23 28 SampleService sampleService;
24 29  
  30 + Logger loger = LoggerFactory.getLogger(this.getClass());
  31 +
25 32 @RequestMapping("/create/gps")
26   - public int createDataByGps(@RequestParam String data){
27   -
  33 + public Map<String, Object> createDataByGps(@RequestParam String data){
  34 + Map<String, Object> rs = new HashMap<>();
28 35 try {
29 36 data = URLDecoder.decode(data, "utf-8");
30 37 CreateSampleParam param = JSONObject.toJavaObject(JSON.parseObject(data), CreateSampleParam.class);
31   - System.out.println(param);
  38 +
  39 + rs = sampleService.createDataByGps(param);
32 40 } catch (UnsupportedEncodingException e) {
33   - e.printStackTrace();
  41 + loger.info("", e);
  42 + rs.put("status", ResponseCode.ERROR);
34 43 }
35   - return 0;
  44 + return rs;
36 45 }
37 46 }
... ...
src/main/java/com/bsth/controller/gps/GpsController.java
... ... @@ -26,12 +26,12 @@ public class GpsController {
26 26 GpsService gpsService;
27 27  
28 28 @RequestMapping(value = "/real/line/{lineCode}")
29   - public List<GpsEntity> findByLineCode(@PathVariable("lineCode") Integer lineCode) {
30   - return gpsRealData.get(lineCode);
  29 + public List<GpsEntity> findByLineCode(@PathVariable("lineCode") String lineCode) {
  30 + return gpsRealData.getByLine(lineCode);
31 31 }
32 32  
33 33 @RequestMapping(value = "/real/line")
34   - public List<GpsEntity> findByLineCode(@RequestParam String lineCodes) {
  34 + public List<GpsEntity> findByLineCodes(@RequestParam String lineCodes) {
35 35 return gpsRealData.get(Splitter.on(",").splitToList(lineCodes));
36 36 }
37 37  
... ...
src/main/java/com/bsth/controller/realcontrol/ScheduleRealInfoController.java
... ... @@ -262,7 +262,7 @@ public class ScheduleRealInfoController extends BaseController&lt;ScheduleRealInfo,
262 262 * @throws
263 263 */
264 264 @RequestMapping(value = "/findRouteByLine")
265   - public Map<String, Object> findRouteByLine(@RequestParam Integer lineCode){
  265 + public Map<String, Object> findRouteByLine(@RequestParam String lineCode){
266 266 return scheduleRealInfoService.findRouteByLine(lineCode);
267 267 }
268 268  
... ...
src/main/java/com/bsth/data/BasicData.java
... ... @@ -57,7 +57,7 @@ public class BasicData implements CommandLineRunner{
57 57 public static TreeMultimap<String, String> lineCode2SocketUserMap = TreeMultimap.create();
58 58  
59 59 //线路ID和code 对照
60   - public static BiMap<Integer, Integer> lineId2CodeMap;
  60 + public static BiMap<Integer, String> lineId2CodeMap;
61 61  
62 62 //线路编码和名称对照
63 63 public static Map<String, String> lineCode2NameMap;
... ... @@ -211,12 +211,12 @@ public class BasicData implements CommandLineRunner{
211 211 Iterator<Line> iterator = lineRepository.findAll().iterator();
212 212  
213 213 Line line;
214   - BiMap<Integer, Integer> biMap = HashBiMap.create();
  214 + BiMap<Integer, String> biMap = HashBiMap.create();
215 215 Map<String, String> code2name = new HashMap<>();
216 216  
217 217 while(iterator.hasNext()){
218 218 line = iterator.next();
219   - biMap.put(line.getId(), Integer.parseInt(line.getLineCode()));
  219 + biMap.put(line.getId(), line.getLineCode());
220 220 code2name.put(line.getLineCode(), line.getName());
221 221 }
222 222  
... ...
src/main/java/com/bsth/data/arrival/ArrivalData_GPS.java
... ... @@ -88,6 +88,7 @@ public class ArrivalData_GPS implements CommandLineRunner{
88 88 }
89 89 //从专业的角度分析一下数据
90 90 analyseData.analyse(carSet);
  91 +
91 92 //开始匹配
92 93 Arrival2Schedule.start(carSet);
93 94 }catch(Exception e){
... ...
src/main/java/com/bsth/data/arrival/ArrivalEntity.java
1 1 package com.bsth.data.arrival;
2 2  
  3 +import java.text.SimpleDateFormat;
3 4 import java.util.Date;
4 5  
5 6 import com.bsth.data.BasicData;
6   -import com.bsth.util.DateUtils;
7 7  
8 8 /**
9 9 *
... ... @@ -88,7 +88,8 @@ public class ArrivalEntity {
88 88 @Override
89 89 public String toString() {
90 90 try {
91   - return "["+BasicData.deviceId2NbbmMap.get(this.deviceId)+", "+DateUtils.sdfHHmm.format(new Date(this.ts))
  91 + SimpleDateFormat sdfHHmm = new SimpleDateFormat("HH:mm");
  92 + return "["+BasicData.deviceId2NbbmMap.get(this.deviceId)+", "+sdfHHmm.format(new Date(this.ts))
92 93 +","+(this.getUpDown()==0?"上行":"下行")+","+(this.inOut==0?"进":"出")+","+this.stopNo+" ("+this.stopName+")]";
93 94 } catch (Exception e) {
94 95 return "";
... ...
src/main/java/com/bsth/data/arrival/DataLoader.java
... ... @@ -141,6 +141,41 @@ public class DataLoader {
141 141 return list;
142 142 }
143 143  
  144 + /**
  145 + *
  146 + * @Title: loadByLineAndStartTime
  147 + * @Description: TODO(根据线路,走向和时间戳加载数据)
  148 + */
  149 + public List<ArrivalEntity> loadByLineAndTime(String lineCode, int updown, long st, long et){
  150 + Calendar cal = Calendar.getInstance();
  151 + cal.setTimeInMillis(st);
  152 + int weeks_year = cal.get(Calendar.WEEK_OF_YEAR);
  153 +
  154 + Connection conn = null;
  155 + PreparedStatement ps = null;
  156 + ResultSet rs = null;
  157 +
  158 + List<ArrivalEntity> list = new ArrayList<>();
  159 + String sql = "select * from bsth_c_arrival_info where weeks_year=? and line_id=? and up_down=? and in_out=0 AND create_timestamp > ? AND create_timestamp <=? AND ABS(create_timestamp - ts) < 3600000 order by ts";
  160 + try{
  161 + conn = DBUtils_MS.getConnection();
  162 + ps = conn.prepareStatement(sql);
  163 + ps.setInt(1, weeks_year);
  164 + ps.setString(2, lineCode);
  165 + ps.setInt(3, updown);
  166 + ps.setLong(4, st);
  167 + ps.setLong(5, et);
  168 + rs = ps.executeQuery();
  169 +
  170 + list = resultSet2Set(rs);
  171 + }catch(Exception e){
  172 + logger.error("", e);
  173 + }finally {
  174 + DBUtils_MS.close(rs, ps, conn);
  175 + }
  176 + return list;
  177 + }
  178 +
144 179 public List<ArrivalEntity> resultSet2Set(ResultSet rs) throws SQLException{
145 180 List<ArrivalEntity> list = new ArrayList<>();
146 181  
... ...
src/main/java/com/bsth/data/forecast/ForecastRealServer.java 0 → 100644
  1 +package com.bsth.data.forecast;
  2 +
  3 +import java.text.DecimalFormat;
  4 +import java.util.ArrayList;
  5 +import java.util.HashMap;
  6 +import java.util.List;
  7 +import java.util.Map;
  8 +import java.util.concurrent.TimeUnit;
  9 +
  10 +import org.slf4j.Logger;
  11 +import org.slf4j.LoggerFactory;
  12 +import org.springframework.beans.factory.annotation.Autowired;
  13 +import org.springframework.boot.CommandLineRunner;
  14 +import org.springframework.stereotype.Component;
  15 +
  16 +import com.bsth.Application;
  17 +import com.bsth.data.forecast.entity.ForecastResult;
  18 +import com.bsth.data.forecast.entity.ForecastResult.ForecastResultItem;
  19 +import com.bsth.data.forecast.entity.SimpleRoute;
  20 +import com.bsth.data.forecast.entity.SimpleRoute.TimeRange;
  21 +import com.bsth.data.gpsdata.GpsEntity;
  22 +import com.bsth.data.gpsdata.GpsRealData;
  23 +import com.bsth.data.schedule.DayOfSchedule;
  24 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  25 +import com.google.common.collect.ArrayListMultimap;
  26 +
  27 +/**
  28 + *
  29 + * @ClassName: SampleTimeData
  30 + * @Description: TODO(实时到离站预测)
  31 + * @author PanZhao
  32 + * @date 2016年9月18日 上午10:15:17
  33 + *
  34 + */
  35 +@Component
  36 +public class ForecastRealServer implements CommandLineRunner {
  37 +
  38 + @Autowired
  39 + SampleTimeDataLoader dataLoader;
  40 +
  41 + @Autowired
  42 + DayOfSchedule dayOfSchedule;
  43 +
  44 + @Autowired
  45 + GpsRealData gpsRealData;
  46 +
  47 + Logger logger = LoggerFactory.getLogger(this.getClass());
  48 +
  49 + //车辆 ——> 预测终点时间
  50 + //static Map<String, Float> forecastMap = new HashMap<>();
  51 + //线路_上下行 ——> 封装耗时数据的路由链
  52 + public static ArrayListMultimap<String, SimpleRoute> lineSampleMap;
  53 + //车辆 ——> 预测结果
  54 + public static Map<String, ForecastResult> forecastMap;
  55 +
  56 + static{
  57 + lineSampleMap = ArrayListMultimap.create();
  58 + forecastMap = new HashMap<>();
  59 + }
  60 +
  61 + @Override
  62 + public void run(String... arg0) throws Exception {
  63 + //2小时更新一次站点间耗时数据
  64 + Application.mainServices.scheduleWithFixedDelay(dataLoader, 12, 120 * 60, TimeUnit.SECONDS);
  65 + }
  66 +
  67 + /**
  68 + *
  69 + * @Title: forecast
  70 + * @Description: TODO(预测后续时间)
  71 + * @param @param nbbm 车辆自编号
  72 + */
  73 +/* public void forecast(String nbbm){
  74 + logger.info("预测," + nbbm);
  75 + //当前执行班次
  76 + ScheduleRealInfo sch = dayOfSchedule.execPlamMap().get(nbbm);
  77 + if(null == sch)
  78 + return;
  79 +
  80 + //车辆当前位置
  81 + //GpsEntity gps = gpsRealData.findByDeviceId(BasicData.deviceId2NbbmMap.inverse().get(sch.getClZbh()));
  82 + GpsEntity gps = gpsRealData.findByDeviceId(BasicData.deviceId2NbbmMap.inverse().get(nbbm));
  83 + forecast(nbbm, gps);
  84 + }*/
  85 +
  86 + public void forecast(String nbbm, GpsEntity gps){
  87 + try{
  88 + long t = System.currentTimeMillis();
  89 + //终点站
  90 + String eStation = null;
  91 + //当前执行班次
  92 + ScheduleRealInfo sch = dayOfSchedule.execPlamMap().get(nbbm);
  93 + if(null != sch)
  94 + eStation = sch.getZdzCode();
  95 +
  96 + //预测结果
  97 + ForecastResult forecastRes = new ForecastResult();
  98 + forecastRes.setStation(gps.getStopNo());
  99 + forecastRes.setArrTime(gps.getArrTime());
  100 + forecastRes.setFollows(
  101 + calc(gps.getLineId()
  102 + ,gps.getUpDown()
  103 + , gps.getStopNo(), eStation
  104 + , t - gps.getArrTime()));
  105 +
  106 +
  107 + forecastMap.put(nbbm, forecastRes);
  108 + //GPS附加预计终点时间
  109 + gps.setExpectStopTime(expectStopTime(nbbm));
  110 + }catch(Exception e){
  111 + logger.error("", e);
  112 + }
  113 + }
  114 +
  115 + /**
  116 + *
  117 + * @Title: expectStopTime
  118 + * @Description: TODO(预计到达终点时间)
  119 + */
  120 + public Float expectStopTime(String nbbm){
  121 + long t = System.currentTimeMillis();
  122 +
  123 + Float rs = null;
  124 + ForecastResult forecastRes = forecastMap.get(nbbm);
  125 + if(null != forecastRes){
  126 + List<ForecastResultItem> trs = forecastRes.getFollows();
  127 + if(null != trs && trs.size() > 0)
  128 + rs = ((float)((trs.get(trs.size() - 1).getTime()) - t)) / 1000 / 60;
  129 + }
  130 +
  131 + //保留2位小数
  132 + if(null != rs)
  133 + rs = Float.parseFloat(new DecimalFormat(".00").format(rs));
  134 +
  135 + return rs;
  136 + }
  137 +
  138 + /**
  139 + *
  140 + * @Title: expectDetail
  141 + * @Description: TODO(预测明细)
  142 + */
  143 + public List<TimeRange> expectDetail(String nbbm){
  144 +
  145 + return null;
  146 + }
  147 +
  148 +
  149 + public List<ForecastResultItem> calc(String lineCode, int updown , String sStation, String eStation, long diff){
  150 + long t = System.currentTimeMillis()
  151 + , ct = t - diff;
  152 +
  153 + List<SimpleRoute> srs = lineSampleMap.get(lineCode + "_" + updown);
  154 + SimpleRoute curr;
  155 + int len = srs.size();
  156 +
  157 + List<ForecastResultItem> rs = null;
  158 + ForecastResultItem frItem;
  159 +
  160 + for(int i = 0; i < len; i ++){
  161 + curr = srs.get(i);
  162 +
  163 + if(curr.stationCode.equals(sStation)){
  164 + rs = new ArrayList<>();
  165 + continue;
  166 + }
  167 +
  168 + if(null == rs)
  169 + continue;
  170 +
  171 + frItem = new ForecastResultItem();
  172 + frItem.setStationId(curr.stationCode);
  173 + frItem.setStationName(curr.stationName);
  174 + if(null == curr.ranges || curr.ranges.size() == 0)
  175 + break;
  176 +
  177 + //从多个时区耗时中选择一个
  178 + for(TimeRange tr : curr.ranges){
  179 + if(tr.startTime < t){
  180 + ct += ((long)(tr.runTime * 60 * 1000));
  181 + frItem.setTime(ct);
  182 + break;
  183 + }
  184 + }
  185 +
  186 + if(null != eStation && eStation.equals(curr.stationCode))
  187 + break;
  188 +
  189 + rs.add(frItem);
  190 + }
  191 +
  192 + return rs;
  193 + }
  194 +}
... ...
src/main/java/com/bsth/data/forecast/SampleTimeDataLoader.java 0 → 100644
  1 +package com.bsth.data.forecast;
  2 +
  3 +import java.text.SimpleDateFormat;
  4 +import java.util.ArrayList;
  5 +import java.util.Collections;
  6 +import java.util.Comparator;
  7 +import java.util.Date;
  8 +import java.util.Iterator;
  9 +import java.util.List;
  10 +import java.util.Set;
  11 +
  12 +import org.slf4j.Logger;
  13 +import org.slf4j.LoggerFactory;
  14 +import org.springframework.beans.factory.annotation.Autowired;
  15 +import org.springframework.stereotype.Component;
  16 +
  17 +import com.bsth.data.forecast.entity.SimpleRoute;
  18 +import com.bsth.data.forecast.entity.SimpleRoute.TimeRange;
  19 +import com.bsth.entity.StationRoute;
  20 +import com.bsth.entity.forecast.Sample;
  21 +import com.bsth.repository.StationRouteRepository;
  22 +import com.bsth.repository.forecast.SampleRepository;
  23 +import com.google.common.collect.ArrayListMultimap;
  24 +
  25 +/**
  26 + *
  27 + * @Title: loadData
  28 + * @Description: TODO(从数据库加载数据)
  29 + */
  30 +@Component
  31 +public class SampleTimeDataLoader extends Thread {
  32 +
  33 + @Autowired
  34 + SampleRepository sampleRepository;
  35 +
  36 + @Autowired
  37 + StationRouteRepository stationRouteRepository;
  38 +
  39 + // 当天日期
  40 + String rq;
  41 +
  42 + SimpleDateFormat sdfyyyyMMddHHmm = new SimpleDateFormat("yyyy-MM-ddHH:mm");
  43 +
  44 + Logger logger = LoggerFactory.getLogger(this.getClass());
  45 +
  46 + @Override
  47 + public void run() {
  48 + SimpleDateFormat sdfyyyyMMdd = new SimpleDateFormat("yyyy-MM-dd");
  49 + rq = sdfyyyyMMdd.format(new Date());
  50 +
  51 + Iterator<Sample> iterator = sampleRepository.findAll().iterator();
  52 + ArrayListMultimap<String, Sample> sampleMap = ArrayListMultimap.create();
  53 +
  54 + Sample sample;
  55 + String key;
  56 + while (iterator.hasNext()) {
  57 + sample = iterator.next();
  58 + key = sample.getLineCode() + "_" + sample.getUpdown() + "_" + sample.getsStation() + "_"
  59 + + sample.geteStation();
  60 + sampleMap.put(key, sample);
  61 + }
  62 +
  63 + // 加载全部路由信息
  64 + List<StationRoute> allRoutes = stationRouteRepository.findAll2();
  65 + // 线路和走向分组
  66 + ArrayListMultimap<String, StationRoute> groupMap = ArrayListMultimap.create();
  67 + for (StationRoute sr : allRoutes)
  68 + groupMap.put(sr.getLineCode() + "_" + sr.getDirections(), sr);
  69 +
  70 + ArrayListMultimap<String, SimpleRoute> lineSampleMapCopy = ArrayListMultimap.create();
  71 + // 排序路由链并附加各个时区耗时信息
  72 + StationRouteComp comp = new StationRouteComp();
  73 + Set<String> kys = groupMap.keySet();
  74 + List<StationRoute> routeList;
  75 + StationRoute sRoute;
  76 +
  77 + List<Sample> sapList;
  78 + for (String k : kys) {
  79 + routeList = groupMap.get(k);
  80 + // 排序
  81 + Collections.sort(routeList, comp);
  82 +
  83 + for (int i = 1; i < routeList.size(); i++) {
  84 + sRoute = routeList.get(i);
  85 +
  86 + sapList = sampleMap.get(k + "_" +routeList.get(i - 1).getStationCode() + "_" + sRoute.getStationCode());
  87 +
  88 + lineSampleMapCopy.put(k, createSimpleRoute(sRoute, sapList));
  89 + }
  90 + }
  91 +
  92 + ForecastRealServer.lineSampleMap = lineSampleMapCopy;
  93 + logger.info("SampleTimeDataLoader.... over...");
  94 + }
  95 +
  96 + private SimpleRoute createSimpleRoute(StationRoute sRoute, List<Sample> list) {
  97 + SimpleRoute simple = new SimpleRoute();
  98 +
  99 + simple.stationCode = sRoute.getStationCode();
  100 + simple.ranges = new ArrayList<>();
  101 +
  102 + try{
  103 + TimeRange tg;
  104 + for (Sample s : list) {
  105 + tg = new TimeRange();
  106 + tg.startTime = sdfyyyyMMddHHmm.parse(rq + s.getsDate()).getTime();
  107 + tg.endTime = sdfyyyyMMddHHmm.parse(rq + s.geteDate()).getTime();
  108 + tg.runTime = s.getRunTime();
  109 + simple.ranges.add(tg);
  110 + }
  111 +
  112 + //排序
  113 + Collections.sort(simple.ranges);
  114 + }catch(Exception e){
  115 + logger.error("", e);
  116 + }
  117 + return simple;
  118 + }
  119 +
  120 + public static class StationRouteComp implements Comparator<StationRoute> {
  121 +
  122 + @Override
  123 + public int compare(StationRoute o1, StationRoute o2) {
  124 + return o1.getStationRouteCode() - o2.getStationRouteCode();
  125 + }
  126 + }
  127 +}
... ...
src/main/java/com/bsth/data/forecast/entity/ForecastResult.java 0 → 100644
  1 +package com.bsth.data.forecast.entity;
  2 +
  3 +import java.util.List;
  4 +
  5 +/**
  6 + *
  7 + * @ClassName: ForecastResult
  8 + * @Description: TODO(预测结果)
  9 + * @author PanZhao
  10 + * @date 2016年9月19日 上午11:09:28
  11 + *
  12 + */
  13 +public class ForecastResult {
  14 +
  15 + /** 当前站 */
  16 + private String station;
  17 +
  18 + /** 到站时间 */
  19 + private long arrTime;
  20 +
  21 + /** 后续站点预测明细 */
  22 + private List<ForecastResultItem> follows;
  23 +
  24 + /** 预计到达终点时间(分钟) */
  25 + private Float stopTime;
  26 +
  27 + public static class ForecastResultItem {
  28 +
  29 + /** 站点ID */
  30 + private String stationId;
  31 +
  32 + /** 站点名称 */
  33 + private String stationName;
  34 +
  35 + /** 时间戳 */
  36 + private long time;
  37 +
  38 + public String getStationId() {
  39 + return stationId;
  40 + }
  41 +
  42 + public void setStationId(String stationId) {
  43 + this.stationId = stationId;
  44 + }
  45 +
  46 + public String getStationName() {
  47 + return stationName;
  48 + }
  49 +
  50 + public void setStationName(String stationName) {
  51 + this.stationName = stationName;
  52 + }
  53 +
  54 + public long getTime() {
  55 + return time;
  56 + }
  57 +
  58 + public void setTime(long time) {
  59 + this.time = time;
  60 + }
  61 + }
  62 +
  63 + public String getStation() {
  64 + return station;
  65 + }
  66 +
  67 + public void setStation(String station) {
  68 + this.station = station;
  69 + }
  70 +
  71 + public long getArrTime() {
  72 + return arrTime;
  73 + }
  74 +
  75 + public void setArrTime(long arrTime) {
  76 + this.arrTime = arrTime;
  77 + }
  78 +
  79 + public Float getStopTime() {
  80 + return stopTime;
  81 + }
  82 +
  83 + public void setStopTime(Float stopTime) {
  84 + this.stopTime = stopTime;
  85 + }
  86 +
  87 + public List<ForecastResultItem> getFollows() {
  88 + return follows;
  89 + }
  90 +
  91 + public void setFollows(List<ForecastResultItem> follows) {
  92 + this.follows = follows;
  93 + }
  94 +}
... ...
src/main/java/com/bsth/data/forecast/entity/SimpleRoute.java 0 → 100644
  1 +package com.bsth.data.forecast.entity;
  2 +
  3 +import java.util.List;
  4 +
  5 +/**
  6 + *
  7 + * @ClassName: SimpleStationRoute
  8 + * @Description: TODO(简单的路由耗时封装)
  9 + * @author PanZhao
  10 + * @date 2016年9月18日 上午10:51:56
  11 + *
  12 + */
  13 +public class SimpleRoute {
  14 +
  15 + /** 站点编码 */
  16 + public String stationCode;
  17 +
  18 + /** 站点名称 */
  19 + public String stationName;
  20 +
  21 + public List<TimeRange> ranges;
  22 +
  23 + public static class TimeRange implements Comparable<TimeRange>{
  24 +
  25 + /** 开始时间 */
  26 + public long startTime;
  27 +
  28 + /** 截止时间 */
  29 + public long endTime;
  30 +
  31 + /** 运行时间 */
  32 + public float runTime;
  33 +
  34 + @Override
  35 + public int compareTo(TimeRange o) {
  36 + return (int) (o.startTime - this.startTime);
  37 + }
  38 + }
  39 +}
... ...
src/main/java/com/bsth/data/gpsdata/GpsEntity.java
... ... @@ -14,7 +14,7 @@ public class GpsEntity {
14 14 private Integer companyCode;
15 15  
16 16 /** 线路编码 */
17   - private Integer lineId;
  17 + private String lineId;
18 18  
19 19 /** 设备编码 */
20 20 private String deviceId;
... ... @@ -24,6 +24,12 @@ public class GpsEntity {
24 24  
25 25 /** 站点编码 */
26 26 private String stopNo;
  27 +
  28 + /** 站点名称 */
  29 + private String stationName;
  30 +
  31 + /** 到站时间 */
  32 + private long arrTime;
27 33  
28 34 /** 经度 */
29 35 private Float lon;
... ... @@ -49,17 +55,14 @@ public class GpsEntity {
49 55 /** 车辆内部编码 */
50 56 private String nbbm;
51 57  
52   - /** 站点名称 */
53   - private String stationName;
54   -
55   - /** 当前班次ID */
56   - private Long currSchId;
57   -
58   - /** 下一个班次ID */
59   - private Long nextSchId;
  58 + /** 预计到达终点时间 */
  59 + private Float expectStopTime;
60 60  
61 61 /** 设备是否在线 */
62 62 private boolean online;
  63 +
  64 + /** 当前执行班次ID */
  65 + private Long schId;
63 66  
64 67 public Integer getCompanyCode() {
65 68 return companyCode;
... ... @@ -69,14 +72,6 @@ public class GpsEntity {
69 72 this.companyCode = companyCode;
70 73 }
71 74  
72   - public Integer getLineId() {
73   - return lineId;
74   - }
75   -
76   - public void setLineId(Integer lineId) {
77   - this.lineId = lineId;
78   - }
79   -
80 75 public String getDeviceId() {
81 76 return deviceId;
82 77 }
... ... @@ -156,22 +151,6 @@ public class GpsEntity {
156 151 public void setUpDown(Integer upDown) {
157 152 this.upDown = upDown;
158 153 }
159   -
160   - public Long getCurrSchId() {
161   - return currSchId;
162   - }
163   -
164   - public void setCurrSchId(Long currSchId) {
165   - this.currSchId = currSchId;
166   - }
167   -
168   - public Long getNextSchId() {
169   - return nextSchId;
170   - }
171   -
172   - public void setNextSchId(Long nextSchId) {
173   - this.nextSchId = nextSchId;
174   - }
175 154  
176 155 public String getNbbm() {
177 156 return nbbm;
... ... @@ -196,4 +175,36 @@ public class GpsEntity {
196 175 public void setOnline(boolean online) {
197 176 this.online = online;
198 177 }
  178 +
  179 + public long getArrTime() {
  180 + return arrTime;
  181 + }
  182 +
  183 + public void setArrTime(long arrTime) {
  184 + this.arrTime = arrTime;
  185 + }
  186 +
  187 + public Float getExpectStopTime() {
  188 + return expectStopTime;
  189 + }
  190 +
  191 + public void setExpectStopTime(Float expectStopTime) {
  192 + this.expectStopTime = expectStopTime;
  193 + }
  194 +
  195 + public String getLineId() {
  196 + return lineId;
  197 + }
  198 +
  199 + public void setLineId(String lineId) {
  200 + this.lineId = lineId;
  201 + }
  202 +
  203 + public Long getSchId() {
  204 + return schId;
  205 + }
  206 +
  207 + public void setSchId(Long schId) {
  208 + this.schId = schId;
  209 + }
199 210 }
... ...
src/main/java/com/bsth/data/gpsdata/GpsRealData.java
... ... @@ -25,6 +25,9 @@ import com.alibaba.fastjson.JSON;
25 25 import com.alibaba.fastjson.JSONObject;
26 26 import com.bsth.Application;
27 27 import com.bsth.data.BasicData;
  28 +import com.bsth.data.forecast.ForecastRealServer;
  29 +import com.bsth.data.schedule.DayOfSchedule;
  30 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
28 31 import com.bsth.util.ConfigUtil;
29 32 import com.google.common.collect.TreeMultimap;
30 33  
... ... @@ -44,7 +47,7 @@ public class GpsRealData implements CommandLineRunner{
44 47 private static Map<String, GpsEntity> gpsMap;
45 48  
46 49 //按线路分组设备号
47   - private static TreeMultimap<Integer, String> lineCode2Devices;
  50 + private static TreeMultimap<String, String> lineCode2Devices;
48 51  
49 52 // 网关数据接口地址
50 53 private static String url;
... ... @@ -52,6 +55,11 @@ public class GpsRealData implements CommandLineRunner{
52 55 @Autowired
53 56 GpsDataLoader gpsDataLoader;
54 57  
  58 + @Autowired
  59 + DayOfSchedule dayOfSchedule;
  60 +
  61 + @Autowired
  62 + ForecastRealServer forecastRealServer;
55 63 /**
56 64 * 构造函数
57 65 */
... ... @@ -63,12 +71,25 @@ public class GpsRealData implements CommandLineRunner{
63 71  
64 72 @Override
65 73 public void run(String... arg0) throws Exception {
66   - logger.info("gpsDataLoader,20,8");
67 74 Application.mainServices.scheduleWithFixedDelay(gpsDataLoader, 20, 8, TimeUnit.SECONDS);
68 75 }
69 76  
70   - public static GpsEntity add(GpsEntity gps) {
  77 + public GpsEntity add(GpsEntity gps) {
71 78 String device = gps.getDeviceId();
  79 + GpsEntity old = gpsMap.get(device);
  80 +
  81 + //定时定距数据附带站点编码改变
  82 + if(null == old || !old.getStopNo().equals(gps.getStopNo())){
  83 + gps.setArrTime(gps.getTimestamp());
  84 + //预测到达终点时间
  85 + forecastRealServer.forecast(gps.getNbbm(), gps);
  86 + }
  87 + else{
  88 + gps.setArrTime(old.getArrTime());
  89 + //不预测, 重新计算终点时间
  90 + gps.setExpectStopTime(forecastRealServer.expectStopTime(gps.getNbbm()));
  91 + }
  92 +
72 93 gpsMap.put(device, gps);
73 94 lineCode2Devices.put(gps.getLineId(), device);
74 95 return gps;
... ... @@ -86,12 +107,18 @@ public class GpsRealData implements CommandLineRunner{
86 107 *
87 108 * @Title: get @Description: TODO(线路编码获取GPS集合) @throws
88 109 */
89   - public List<GpsEntity> get(Integer lineCode) {
  110 + public List<GpsEntity> getByLine(String lineCode) {
90 111 NavigableSet<String> set = lineCode2Devices.get(lineCode);
91 112  
92 113 List<GpsEntity> rs = new ArrayList<>();
  114 + GpsEntity gps;
  115 + ScheduleRealInfo sch;
93 116 for(String device : set){
94   - rs.add(gpsMap.get(device));
  117 + gps = gpsMap.get(device);
  118 + sch = dayOfSchedule.execPlamMap().get(gps.getNbbm());
  119 + if(null != sch)
  120 + gps.setSchId(sch.getId());
  121 + rs.add(gps);
95 122 }
96 123  
97 124 return rs;
... ... @@ -101,7 +128,7 @@ public class GpsRealData implements CommandLineRunner{
101 128 List<GpsEntity> list = new ArrayList<>();
102 129  
103 130 for(String code : pArray)
104   - list.addAll(get(Integer.parseInt(code)));
  131 + list.addAll(getByLine(code));
105 132 return list;
106 133 }
107 134  
... ... @@ -113,6 +140,9 @@ public class GpsRealData implements CommandLineRunner{
113 140 public static class GpsDataLoader extends Thread{
114 141  
115 142 Logger logger = LoggerFactory.getLogger(GpsDataLoader.class);
  143 +
  144 + @Autowired
  145 + GpsRealData gpsRealData;
116 146  
117 147 @Override
118 148 public void run() {
... ... @@ -130,7 +160,7 @@ public class GpsRealData implements CommandLineRunner{
130 160 try {
131 161 httpClient = HttpClients.createDefault();
132 162 HttpGet get = new HttpGet(url);
133   -
  163 +
134 164 response = httpClient.execute(get);
135 165  
136 166 HttpEntity entity = response.getEntity();
... ... @@ -156,7 +186,7 @@ public class GpsRealData implements CommandLineRunner{
156 186  
157 187 gps.setNbbm(nbbm);
158 188 gps.setStationName(BasicData.stationCode2NameMap.get(gps.getStopNo()));
159   - add(gps);
  189 + gpsRealData.add(gps);
160 190 }
161 191 } else
162 192 logger.error("result is null");
... ...
src/main/java/com/bsth/data/match/Arrival2Schedule.java
... ... @@ -91,6 +91,14 @@ public class Arrival2Schedule implements ApplicationContextAware {
91 91 for(ArrivalEntity arr : arrList){
92 92 match(arr, schList);
93 93 }
  94 +
  95 + //车辆关联到班次
  96 + //ScheduleRealInfo sch = dayOfSchedule.execPlamMap().get(this.nbbm);
  97 + //if(null == sch){
  98 + //dayOfSchedule.findByNbbm(this.nbbm);
  99 + //dayOfSchedule.addExecPlan(sch);
  100 + //dayOfSchedule.linkToSchPlan(this.nbbm);
  101 + //}
94 102 }
95 103  
96 104 private void match(ArrivalEntity arr, List<ScheduleRealInfo> schList) {
... ... @@ -163,6 +171,8 @@ public class Arrival2Schedule implements ApplicationContextAware {
163 171 sendUtils.sendFcsj(mr.sch);
164 172 //持久化
165 173 dayOfSchedule.save(mr.sch);
  174 + //车辆当前执行班次
  175 + dayOfSchedule.addExecPlan(mr.sch);
166 176 }
167 177 }
168 178 }
... ... @@ -222,6 +232,9 @@ public class Arrival2Schedule implements ApplicationContextAware {
222 232 sendUtils.sendZdsj(mr.sch, next, doneSum);
223 233 //持久化
224 234 dayOfSchedule.save(mr.sch);
  235 + logger.info(mr.sch.getClZbh() + "移除正在执行班次," + mr.sch.getFcsj());
  236 + //移除车辆正在执行班次引用
  237 + dayOfSchedule.removeExecPlan(mr.sch.getClZbh());
225 238 }
226 239 }
227 240  
... ...
src/main/java/com/bsth/data/schedule/DayOfSchedule.java
1 1 package com.bsth.data.schedule;
2 2  
3 3 import java.text.ParseException;
  4 +import java.text.SimpleDateFormat;
4 5 import java.util.ArrayList;
5 6 import java.util.Collection;
6 7 import java.util.Collections;
... ... @@ -23,8 +24,11 @@ import org.springframework.stereotype.Component;
23 24 import com.alibaba.fastjson.JSON;
24 25 import com.alibaba.fastjson.JSONArray;
25 26 import com.bsth.Application;
  27 +import com.bsth.data.BasicData;
26 28 import com.bsth.data.LineConfigData;
27 29 import com.bsth.data.directive.FirstScheduleCheckThread;
  30 +import com.bsth.data.gpsdata.GpsEntity;
  31 +import com.bsth.data.gpsdata.GpsRealData;
28 32 import com.bsth.data.schedule.thread.ScheduleLateThread;
29 33 import com.bsth.data.schedule.thread.SchedulePstThread;
30 34 import com.bsth.data.schedule.thread.ScheduleRefreshThread;
... ... @@ -60,6 +64,9 @@ public class DayOfSchedule implements CommandLineRunner {
60 64  
61 65 // 车辆和排班起终点站对照(包括进出的停车场,区间起终点)
62 66 private static TreeMultimap<String, String> nbbm2SEStationMap;
  67 +
  68 + //车辆 ——> 当前执行班次
  69 + private static Map<String, ScheduleRealInfo> carExecutePlanMap;
63 70  
64 71 // 持久化缓冲区
65 72 public static LinkedList<ScheduleRealInfo> pstBuffer;
... ... @@ -81,6 +88,9 @@ public class DayOfSchedule implements CommandLineRunner {
81 88  
82 89 @Autowired
83 90 SendUtils sendUtils;
  91 +
  92 + @Autowired
  93 + GpsRealData gpsRealData;
84 94  
85 95 /** 线路当前使用的排班的日期 */
86 96 public static Map<String, String> currSchDateMap;
... ... @@ -92,6 +102,7 @@ public class DayOfSchedule implements CommandLineRunner {
92 102 schFCSJComparator = new ScheduleComparator.FCSJ();
93 103 currSchDateMap = new HashMap<>();
94 104 nbbm2SEStationMap = TreeMultimap.create();
  105 + carExecutePlanMap = new HashMap<>();
95 106 }
96 107  
97 108 @Autowired
... ... @@ -130,7 +141,9 @@ public class DayOfSchedule implements CommandLineRunner {
130 141 public String calcSchDate(String lineCode) {
131 142 LineConfig conf = lineConfigData.get(lineCode);
132 143 long ct = System.currentTimeMillis();
133   - String schDate = DateUtils.sdfyyyyMMdd.format(new Date(ct));
  144 +
  145 + SimpleDateFormat sdfyyyyMMdd = new SimpleDateFormat("yyyy-MM-dd");
  146 + String schDate = sdfyyyyMMdd.format(new Date(ct));
134 147 // 小于当天起始运营时间,则取前一天的排班
135 148 if (ct < conf.getCurrStartTime())
136 149 schDate = DateUtils.subtractDay(schDate, 1);
... ... @@ -283,7 +296,10 @@ public class DayOfSchedule implements CommandLineRunner {
283 296  
284 297 try {
285 298 Map<String, Object> data = new HashMap<>();
286   - data.put("scheduleDate_eq", DateUtils.sdfyyyyMMdd.parse(schDate));
  299 + SimpleDateFormat sdfyyyyMMdd = new SimpleDateFormat("yyyy-MM-dd")
  300 + ,sdfHHmm = new SimpleDateFormat("HH:mm");
  301 +
  302 + data.put("scheduleDate_eq", sdfyyyyMMdd.parse(schDate));
287 303 data.put("xlBm_eq", lineCode);
288 304  
289 305 // 查询计划排班
... ... @@ -293,13 +309,13 @@ public class DayOfSchedule implements CommandLineRunner {
293 309 realList = JSONArray.parseArray(JSON.toJSONString(planItr), ScheduleRealInfo.class);
294 310  
295 311 for (ScheduleRealInfo sch : realList) {
296   - sch.setScheduleDateStr(DateUtils.sdfyyyyMMdd.format(sch.getScheduleDate()));
  312 + sch.setScheduleDateStr(sdfyyyyMMdd.format(sch.getScheduleDate()));
297 313 sch.setRealExecDate(sch.getScheduleDateStr());
298 314 // 计划终点时间
299 315 if (sch.getBcsj() != null) {
300 316 try{
301   - sch.setZdsjT(DateUtils.sdfHHmm.parse(sch.getFcsj()).getTime() + (sch.getBcsj() * 60 * 1000));
302   - sch.setZdsj(DateUtils.sdfHHmm.format(sch.getZdsjT()));
  317 + sch.setZdsjT(sdfHHmm.parse(sch.getFcsj()).getTime() + (sch.getBcsj() * 60 * 1000));
  318 + sch.setZdsj(sdfHHmm.format(sch.getZdsjT()));
303 319 sch.setLate(false);
304 320 }catch(ParseException pe){
305 321 logger.error("loadPlanSch... 计算终点时间失败...");
... ... @@ -326,10 +342,11 @@ public class DayOfSchedule implements CommandLineRunner {
326 342 id = 0L;
327 343 id++;
328 344  
  345 + SimpleDateFormat sdfyyyyMMdd = new SimpleDateFormat("yyyy-MM-dd");
329 346 for (ScheduleRealInfo item : list) {
330 347 item.setSpId(item.getId());// 保留原始的计划ID
331 348 item.setId(id++);// 设置ID
332   - item.setScheduleDateStr(DateUtils.sdfyyyyMMdd.format(item.getScheduleDate()));
  349 + item.setScheduleDateStr(sdfyyyyMMdd.format(item.getScheduleDate()));
333 350 }
334 351  
335 352 // 入库
... ... @@ -596,4 +613,44 @@ public class DayOfSchedule implements CommandLineRunner {
596 613 public Collection<ScheduleRealInfo> findAll(){
597 614 return nbbmScheduleMap.values();
598 615 }
  616 +
  617 + public void addExecPlan(ScheduleRealInfo sch){
  618 + carExecutePlanMap.put(sch.getClZbh(), sch);
  619 + }
  620 +
  621 + public void removeExecPlan(String clzbh){
  622 + carExecutePlanMap.remove(clzbh);
  623 + }
  624 +
  625 + public Map<String, ScheduleRealInfo> execPlamMap(){
  626 + return carExecutePlanMap;
  627 + }
  628 +
  629 + /**
  630 + *
  631 + * @Title: linkToSchPlan
  632 + * @Description: TODO(车辆关联到班次)
  633 + */
  634 +/* public void linkToSchPlan(String nbbm) {
  635 + //当前GPS状态
  636 + GpsEntity gps = gpsRealData.get(BasicData.deviceId2NbbmMap.inverse().get(nbbm));
  637 + if(null == gps)
  638 + return;
  639 +
  640 + //班次集合
  641 + List<ScheduleRealInfo> schArr = nbbmScheduleMap.get(nbbm);
  642 +
  643 + for(ScheduleRealInfo sch : schArr){
  644 + if(sch.getStatus() == 2)
  645 + continue;
  646 + if(sch.isDestroy())
  647 + continue;
  648 + if(!sch.getXlBm().equals(gps.getLineId())
  649 + || Integer.parseInt(sch.getXlDir()) != gps.getUpDown().intValue())
  650 + continue;
  651 +
  652 + addExecPlan(sch);
  653 + break;
  654 + }
  655 + }*/
599 656 }
... ...
src/main/java/com/bsth/data/schedule/SchAttrCalculator.java
1 1 package com.bsth.data.schedule;
2 2  
3 3 import java.text.ParseException;
  4 +import java.text.SimpleDateFormat;
4 5 import java.util.Collections;
5 6 import java.util.Date;
6 7 import java.util.List;
... ... @@ -13,7 +14,6 @@ import org.springframework.stereotype.Component;
13 14 import com.bsth.data.LineConfigData;
14 15 import com.bsth.entity.realcontrol.LineConfig;
15 16 import com.bsth.entity.realcontrol.ScheduleRealInfo;
16   -import com.bsth.util.DateUtils;
17 17  
18 18 /**
19 19 *
... ... @@ -48,11 +48,13 @@ public class SchAttrCalculator {
48 48 * 早于线路开始运营时间的,加一天
49 49 * 如该线路 2点开始运营,2016-08-23的班次,则 2016-08-23 0:25 的班次应该调整成 2016-08-24 0:25
50 50 */
51   - long st = DateUtils.sdfyyyyMMddHHmm.parse(sch.getScheduleDateStr() + conf.getStartOpt()).getTime();
  51 + SimpleDateFormat sdfyyyyMMddHHmm = new SimpleDateFormat("yyyy-MM-ddHH:mm")
  52 + ,sdfyyyyMMdd = new SimpleDateFormat("yyyy-MM-dd");
  53 + long st = sdfyyyyMMddHHmm.parse(sch.getScheduleDateStr() + conf.getStartOpt()).getTime();
52 54 if (st > sch.getFcsjT())
53 55 sch.setFcsjAll(sch.getFcsjT() + DAY_TIME);
54 56  
55   - sch.setRealExecDate(DateUtils.sdfyyyyMMdd.format(new Date(sch.getFcsjT())));
  57 + sch.setRealExecDate(sdfyyyyMMdd.format(new Date(sch.getFcsjT())));
56 58 } catch (Exception e) {
57 59 logger.error("", e);
58 60 }
... ... @@ -69,11 +71,12 @@ public class SchAttrCalculator {
69 71 // 生成时间戳
70 72 calcTimestamp(sch);
71 73  
  74 + SimpleDateFormat sdfHHmm = new SimpleDateFormat("HH:mm");
72 75 // 计划终点时间
73 76 if (sch.getBcsj() != null) {
74 77 Date zdDate = new Date(sch.getDfsjT() + (sch.getBcsj() * 60 * 1000));
75 78 sch.setZdsjT(zdDate.getTime());
76   - sch.setZdsj(DateUtils.sdfHHmm.format(zdDate));
  79 + sch.setZdsj(sdfHHmm.format(zdDate));
77 80 }
78 81 } catch (ParseException e) {
79 82 logger.error("", e);
... ... @@ -132,7 +135,8 @@ public class SchAttrCalculator {
132 135 }
133 136  
134 137 public SchAttrCalculator calcFcsjTime(ScheduleRealInfo sch) throws ParseException {
135   - sch.setFcsjT(DateUtils.sdfyyyyMMddHHmm.parse(sch.getRealExecDate() + sch.getFcsj()).getTime());
  138 + SimpleDateFormat sdfyyyyMMddHHmm = new SimpleDateFormat("yyyy-MM-ddHH:mm");
  139 + sch.setFcsjT(sdfyyyyMMddHHmm.parse(sch.getRealExecDate() + sch.getFcsj()).getTime());
136 140 return this;
137 141 }
138 142  
... ...
src/main/java/com/bsth/entity/forecast/Sample.java
1 1 package com.bsth.entity.forecast;
2 2  
3 3  
  4 +import java.text.SimpleDateFormat;
  5 +import java.util.Date;
  6 +
4 7 import javax.persistence.Entity;
5 8 import javax.persistence.GeneratedValue;
6 9 import javax.persistence.Id;
7 10 import javax.persistence.Table;
8 11 import javax.persistence.Transient;
9 12  
  13 +import org.slf4j.Logger;
  14 +import org.slf4j.LoggerFactory;
  15 +
  16 +import com.bsth.data.arrival.ArrivalEntity;
  17 +
10 18 /**
11 19 *
12 20 * @ClassName: Sample
... ... @@ -19,11 +27,36 @@ import javax.persistence.Transient;
19 27 @Table(name = "bsth_forecast_sample")
20 28 public class Sample {
21 29  
  30 + @Transient
  31 + static Logger logger = LoggerFactory.getLogger(Sample.class);
  32 +
  33 + public Sample(ArrivalEntity prve, ArrivalEntity curr) {
  34 + //SimpleDateFormat sdfHHmm = new SimpleDateFormat("HH:mm");
  35 +
  36 + this.setsStation(prve.getStopNo());
  37 + this.seteStation(curr.getStopNo());
  38 + this.setsTime(prve.getTs());
  39 + this.seteTime(curr.getTs());
  40 + //this.setsDate(sdfHHmm.format(new Date(prve.getTs())));
  41 + //this.seteDate(sdfHHmm.format(new Date(curr.getTs())));
  42 +
  43 + /*try{
  44 + this.setsTime(sdfHHmm.parse(this.sDate).getTime());
  45 + this.seteTime(sdfHHmm.parse(this.eDate).getTime());
  46 + }catch(Exception e){
  47 + logger.error("", e);
  48 + }*/
  49 + Long diff = (curr.getTs() - prve.getTs());
  50 + this.setRunTime(Float.parseFloat(diff.toString()) / 1000 / 60);
  51 + }
  52 +
  53 + public Sample(){}
  54 +
22 55 @Id
23 56 @GeneratedValue
24 57 private Long id;
25 58  
26   - private Integer lineCode;
  59 + private String lineCode;
27 60  
28 61 // 开始时间
29 62 private String sDate;
... ... @@ -135,11 +168,11 @@ public class Sample {
135 168 this.runTime = runTime;
136 169 }
137 170  
138   - public Integer getLineCode() {
  171 + public String getLineCode() {
139 172 return lineCode;
140 173 }
141 174  
142   - public void setLineCode(Integer lineCode) {
  175 + public void setLineCode(String lineCode) {
143 176 this.lineCode = lineCode;
144 177 }
145 178  
... ...
src/main/java/com/bsth/entity/realcontrol/LineConfig.java
1 1 package com.bsth.entity.realcontrol;
2 2  
3 3 import java.text.ParseException;
  4 +import java.text.SimpleDateFormat;
4 5 import java.util.Date;
5 6 import java.util.HashSet;
6 7 import java.util.Set;
... ... @@ -137,7 +138,9 @@ public class LineConfig {
137 138 public long getCurrStartTime() {
138 139 Date d = null;
139 140 try {
140   - d = DateUtils.sdfyyyyMMddHHmm.parse(DateUtils.sdfyyyyMMdd.format(new Date()) + this.startOpt);
  141 + SimpleDateFormat sdfyyyyMMddHHmm = new SimpleDateFormat("yyyy-MM-ddHH:mm")
  142 + ,sdfyyyyMMdd = new SimpleDateFormat("yyyy-MM-dd");
  143 + d = sdfyyyyMMddHHmm.parse(sdfyyyyMMdd.format(new Date()) + this.startOpt);
141 144 } catch (ParseException e) {
142 145 e.printStackTrace();
143 146 }
... ...
src/main/java/com/bsth/entity/realcontrol/ScheduleRealInfo.java
1 1 package com.bsth.entity.realcontrol;
2 2  
3 3 import com.bsth.entity.sys.SysUser;
4   -import com.bsth.util.DateUtils;
5 4 import com.fasterxml.jackson.annotation.JsonIgnore;
6 5  
7 6 import javax.persistence.*;
... ... @@ -9,6 +8,7 @@ import javax.persistence.*;
9 8 import org.apache.commons.lang3.StringUtils;
10 9  
11 10 import java.text.ParseException;
  11 +import java.text.SimpleDateFormat;
12 12 import java.util.Date;
13 13 import java.util.HashSet;
14 14 import java.util.Set;
... ... @@ -510,13 +510,15 @@ public class ScheduleRealInfo {
510 510  
511 511 public void setDfsjAll(Long dfsjT) {
512 512 this.dfsjT = dfsjT;
513   - this.dfsj = DateUtils.sdfHHmm.format(new Date(this.dfsjT));
  513 + SimpleDateFormat sdfHHmm = new SimpleDateFormat("HH:mm");
  514 + this.dfsj = sdfHHmm.format(new Date(this.dfsjT));
514 515 }
515 516  
516 517 public void setDfsjAll(String dfsj) {
517 518  
518 519 try {
519   - this.dfsjT = DateUtils.sdfyyyyMMddHHmm.parse(this.realExecDate + dfsj).getTime();
  520 + SimpleDateFormat sdfyyyyMMddHHmm = new SimpleDateFormat("yyyy-MM-ddHH:mm");
  521 + this.dfsjT = sdfyyyyMMddHHmm.parse(this.realExecDate + dfsj).getTime();
520 522 this.dfsj = dfsj;
521 523 } catch (ParseException e) {
522 524 e.printStackTrace();
... ... @@ -525,10 +527,11 @@ public class ScheduleRealInfo {
525 527  
526 528 public void calcEndTime(){
527 529 //计划终点时间
  530 + SimpleDateFormat sdfHHmm = new SimpleDateFormat("HH:mm");
528 531 if(this.getBcsj() != null){
529 532 Date zdDate = new Date(this.getDfsjT() + (this.getBcsj() * 60 * 1000));
530 533 this.setZdsjT(zdDate.getTime());
531   - this.setZdsj(DateUtils.sdfHHmm.format(zdDate));
  534 + this.setZdsj(sdfHHmm.format(zdDate));
532 535 }
533 536 }
534 537  
... ... @@ -581,7 +584,8 @@ public class ScheduleRealInfo {
581 584 */
582 585 public void setFcsjAll(String fcsj){
583 586 try {
584   - this.fcsjT = DateUtils.sdfyyyyMMddHHmm.parse(this.realExecDate + fcsj).getTime();
  587 + SimpleDateFormat sdfyyyyMMddHHmm = new SimpleDateFormat("yyyy-MM-ddHH:mm");
  588 + this.fcsjT = sdfyyyyMMddHHmm.parse(this.realExecDate + fcsj).getTime();
585 589 this.fcsj = fcsj;
586 590 } catch (ParseException e) {
587 591 e.printStackTrace();
... ... @@ -596,7 +600,8 @@ public class ScheduleRealInfo {
596 600 */
597 601 public void setFcsjAll(Long fcsjT){
598 602 this.fcsjT = fcsjT;
599   - this.fcsj = DateUtils.sdfHHmm.format(new Date(fcsjT));
  603 + SimpleDateFormat sdfHHmm = new SimpleDateFormat("HH:mm");
  604 + this.fcsj = sdfHHmm.format(new Date(fcsjT));
600 605 }
601 606  
602 607 /**
... ... @@ -607,7 +612,8 @@ public class ScheduleRealInfo {
607 612 */
608 613 public void setFcsjActualAll(String fcsjActual){
609 614 try {
610   - this.fcsjActualTime = DateUtils.sdfyyyyMMddHHmm.parse(this.realExecDate + fcsjActual).getTime();
  615 + SimpleDateFormat sdfyyyyMMddHHmm = new SimpleDateFormat("yyyy-MM-ddHH:mm");
  616 + this.fcsjActualTime = sdfyyyyMMddHHmm.parse(this.realExecDate + fcsjActual).getTime();
611 617 this.fcsjActual = fcsjActual;
612 618  
613 619 calcStatus();
... ... @@ -624,7 +630,8 @@ public class ScheduleRealInfo {
624 630 */
625 631 public void setFcsjActualAll(Long t){
626 632 this.fcsjActualTime = t;
627   - this.fcsjActual = DateUtils.sdfHHmm.format(new Date(t));
  633 + SimpleDateFormat sdfHHmm = new SimpleDateFormat("HH:mm");
  634 + this.fcsjActual = sdfHHmm.format(new Date(t));
628 635  
629 636 //更新班次状态
630 637 calcStatus();
... ... @@ -638,7 +645,8 @@ public class ScheduleRealInfo {
638 645 */
639 646 public void setZdsjActualAll(Long t){
640 647 this.zdsjActualTime = t;
641   - this.zdsjActual = DateUtils.sdfHHmm.format(new Date(t));
  648 + SimpleDateFormat sdfHHmm = new SimpleDateFormat("HH:mm");
  649 + this.zdsjActual = sdfHHmm.format(new Date(t));
642 650  
643 651 //更新班次状态
644 652 calcStatus();
... ... @@ -653,7 +661,8 @@ public class ScheduleRealInfo {
653 661 */
654 662 public void setZdsjActualAll(String zdsjActual){
655 663 try {
656   - this.zdsjActualTime = DateUtils.sdfyyyyMMddHHmm.parse(this.realExecDate + zdsjActual).getTime();
  664 + SimpleDateFormat sdfyyyyMMddHHmm = new SimpleDateFormat("yyyy-MM-ddHH:mm");
  665 + this.zdsjActualTime = sdfyyyyMMddHHmm.parse(this.realExecDate + zdsjActual).getTime();
657 666 this.zdsjActual = zdsjActual;
658 667  
659 668 calcStatus();
... ...
src/main/java/com/bsth/repository/StationRouteRepository.java
... ... @@ -233,4 +233,7 @@ public interface StationRouteRepository extends BaseRepository&lt;StationRoute, Int
233 233  
234 234 @Query("select new map(sr.station.id as stationid, sr.stationName as stationname) from StationRoute sr where sr.line.id=?1 and sr.directions=?2")
235 235 List<Map<String, Object>> findStations(Integer xlid, Integer xldir);
  236 +
  237 + @Query("select r from StationRoute r where r.lineCode=?1 and r.directions=?2 and r.destroy=0 order by r.stationRouteCode")
  238 + List<StationRoute> findByLine(String lineCode, int updown);
236 239 }
... ...
src/main/java/com/bsth/repository/forecast/SampleRepository.java
... ... @@ -15,5 +15,5 @@ public interface SampleRepository extends BaseRepository&lt;Sample, Long&gt;{
15 15 @Transactional
16 16 @Modifying
17 17 @Query("delete Sample where lineCode=?1 and updown=?2")
18   - void deleteByLineAndUpdown(Integer lineCode, int updown);
  18 + void deleteByLineAndUpdown(String lineCode, int updown);
19 19 }
... ...
src/main/java/com/bsth/service/directive/DirectiveServiceImpl.java
... ... @@ -397,10 +397,11 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;D60, Integer&gt; implemen
397 397  
398 398 List<Directive> rs = list.subList(s, e);
399 399  
  400 + SimpleDateFormat sdfHHmm = new SimpleDateFormat("HH:mm");
400 401 // 时间格式化,车辆自编号转换
401 402 for (Directive d : rs) {
402 403 if (d.getTimeHHmm() == null)
403   - d.setTimeHHmm(DateUtils.sdfHHmm.format(new Date(d.getTimestamp())));
  404 + d.setTimeHHmm(sdfHHmm.format(new Date(d.getTimestamp())));
404 405 if (d.getNbbm() == null)
405 406 d.setNbbm(BasicData.deviceId2NbbmMap.get(d.getDeviceId()));
406 407 }
... ... @@ -449,9 +450,10 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;D60, Integer&gt; implemen
449 450 if (e > count)
450 451 e = count;
451 452  
  453 + SimpleDateFormat sdfHHmm = new SimpleDateFormat("HH:mm");
452 454 List<D80> rs = d80s.subList(s, e);
453 455 for(D80 d80 : rs){
454   - d80.setTimeStr(DateUtils.sdfHHmm.format(new Date(d80.getTimestamp())));
  456 + d80.setTimeStr(sdfHHmm.format(new Date(d80.getTimestamp())));
455 457 }
456 458  
457 459 Map<String, Object> rsMap = new HashMap<>();
... ...
src/main/java/com/bsth/service/forecast/SampleService.java
1 1 package com.bsth.service.forecast;
2 2  
  3 +import java.util.Map;
  4 +
  5 +import com.bsth.controller.forecast.dto.CreateSampleParam;
3 6 import com.bsth.entity.forecast.Sample;
4 7 import com.bsth.service.BaseService;
5 8  
6 9 public interface SampleService extends BaseService<Sample, Long>{
7 10  
8   - int createDataByGps(String lineCode, Integer updown);
  11 + Map<String, Object> createDataByGps(CreateSampleParam param);
9 12  
10 13 }
... ...
src/main/java/com/bsth/service/forecast/SampleServiceImpl.java
1 1 package com.bsth.service.forecast;
2 2  
  3 +import java.text.SimpleDateFormat;
  4 +import java.util.ArrayList;
  5 +import java.util.Collections;
  6 +import java.util.Comparator;
  7 +import java.util.HashMap;
3 8 import java.util.Iterator;
  9 +import java.util.List;
4 10 import java.util.Map;
5 11  
6 12 import javax.transaction.Transactional;
7 13  
  14 +import org.slf4j.Logger;
  15 +import org.slf4j.LoggerFactory;
8 16 import org.springframework.beans.factory.annotation.Autowired;
9 17 import org.springframework.stereotype.Service;
10 18  
  19 +import com.bsth.common.ResponseCode;
  20 +import com.bsth.controller.forecast.dto.CreateSampleParam;
11 21 import com.bsth.data.BasicData;
  22 +import com.bsth.data.arrival.ArrivalEntity;
  23 +import com.bsth.data.arrival.DataLoader;
12 24 import com.bsth.entity.forecast.Sample;
13 25 import com.bsth.repository.forecast.SampleRepository;
  26 +import com.bsth.service.forecast.util.CreateByArrivalData;
14 27 import com.bsth.service.impl.BaseServiceImpl;
15 28  
16 29 @Service
... ... @@ -19,10 +32,16 @@ public class SampleServiceImpl extends BaseServiceImpl&lt;Sample, Long&gt; implements
19 32 @Autowired
20 33 SampleRepository sampleRepository;
21 34  
  35 + @Autowired
  36 + CreateByArrivalData createByArrivalData;
  37 +
  38 + Logger logger = LoggerFactory.getLogger(this.getClass());
  39 +
22 40 @Override
23 41 public Iterable<Sample> list(Map<String, Object> map) {
24 42 Iterable<Sample> rs = super.list(map);
25 43  
  44 + List<Sample> rsList = new ArrayList<>();
26 45 //转换站点名称
27 46 Iterator<Sample> iterator = rs.iterator();
28 47 Sample s;
... ... @@ -30,16 +49,62 @@ public class SampleServiceImpl extends BaseServiceImpl&lt;Sample, Long&gt; implements
30 49 s = iterator.next();
31 50 s.setsName(BasicData.stationCode2NameMap.get(s.getsStation()));
32 51 s.seteName(BasicData.stationCode2NameMap.get(s.geteStation()));
  52 +
  53 + rsList.add(s);
33 54 }
34   - return rs;
  55 +
  56 + //排序
  57 + Collections.sort(rsList, new Comparator<Sample>() {
  58 + @Override
  59 + public int compare(Sample arg0, Sample arg1) {
  60 + return arg0.geteDate().compareTo(arg1.geteDate());
  61 + }
  62 + });
  63 +
  64 + return rsList;
  65 + }
  66 +
  67 + @Override
  68 + public Map<String, Object> save(Sample t) {
  69 + t.setTag(t.getTag() + t.getsDate() + " - " + t.geteDate());
  70 + return super.save(t);
35 71 }
36 72  
37 73 @Transactional
38 74 @Override
39   - public int createDataByGps(String lineCode, Integer updown) {
40   - //删除原有数据
41   - sampleRepository.deleteByLineAndUpdown(Integer.parseInt(lineCode), updown);
  75 + public Map<String, Object> createDataByGps(CreateSampleParam param) {
  76 + Map<String, Object> rs = new HashMap<>();
  77 + try{
  78 + //删除原有数据
  79 + sampleRepository.deleteByLineAndUpdown(param.getLineCode(), param.getUpdown());
  80 +
  81 + //查询到离站数据
  82 + DataLoader loader = new DataLoader();
  83 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  84 +
  85 + long st = sdf.parse(param.getStartDate()).getTime()
  86 + ,et = sdf.parse(param.getEndDate()).getTime()
  87 + ,i = st
  88 + ,range = 1000 * 60 * 60 * 24;
  89 +
  90 + logger.info("初始值:" + 1500 * (int)((et - st) / range));
  91 + List<ArrivalEntity> all = new ArrayList<>(1500 * (int)((et - st) / range));
  92 + for(; i < et; i += range)
  93 + all.addAll(loader.loadByLineAndTime(param.getLineCode(), param.getUpdown() , i, i + range));
  94 +
  95 + logger.info("实际数据量:" + all.size());
  96 +
  97 + List<Sample> resList = createByArrivalData.create(all, param);
  98 +
  99 + //入库
  100 + sampleRepository.save(resList);
  101 +
  102 + rs.put("status", ResponseCode.SUCCESS);
  103 + }catch(Exception e){
  104 + logger.error("" , e);
  105 + rs.put("status", ResponseCode.ERROR);
  106 + }
42 107  
43   - return 0;
  108 + return rs;
44 109 }
45 110 }
... ...
src/main/java/com/bsth/service/forecast/util/CreateByArrivalData.java 0 → 100644
  1 +package com.bsth.service.forecast.util;
  2 +
  3 +import java.text.DecimalFormat;
  4 +import java.text.ParseException;
  5 +import java.text.SimpleDateFormat;
  6 +import java.util.ArrayList;
  7 +import java.util.Collections;
  8 +import java.util.Comparator;
  9 +import java.util.Date;
  10 +import java.util.HashMap;
  11 +import java.util.List;
  12 +import java.util.Map;
  13 +import java.util.Set;
  14 +
  15 +import org.slf4j.Logger;
  16 +import org.slf4j.LoggerFactory;
  17 +import org.springframework.beans.factory.annotation.Autowired;
  18 +import org.springframework.context.annotation.Scope;
  19 +import org.springframework.stereotype.Component;
  20 +
  21 +import com.bsth.controller.forecast.dto.CreateSampleParam;
  22 +import com.bsth.controller.forecast.dto.CreateSampleParam.TimeRange;
  23 +import com.bsth.data.arrival.ArrivalComparator;
  24 +import com.bsth.data.arrival.ArrivalEntity;
  25 +import com.bsth.entity.StationRoute;
  26 +import com.bsth.entity.forecast.Sample;
  27 +import com.bsth.repository.StationRouteRepository;
  28 +import com.google.common.collect.ArrayListMultimap;
  29 +
  30 +/**
  31 + *
  32 + * @ClassName: CreateByArrivalData
  33 + * @Description: TODO(根据到离站数据生成线路站点间耗时)
  34 + * @author PanZhao
  35 + * @date 2016年9月17日 下午2:33:20
  36 + *
  37 + */
  38 +@Component
  39 +@Scope("prototype")
  40 +public class CreateByArrivalData {
  41 +
  42 + @Autowired
  43 + StationRouteRepository routeRepository;
  44 +
  45 + SimpleDateFormat sdfyyyyMMdd = new SimpleDateFormat("yyyy-MM-dd")
  46 + ,sdfHHmm = new SimpleDateFormat("HH:mm")
  47 + ,sdfyyyyMMddHHmm = new SimpleDateFormat("yyyy-MM-ddHH:mm");
  48 +
  49 + String rq = sdfyyyyMMdd.format(new Date());
  50 +
  51 + Logger logger = LoggerFactory.getLogger(this.getClass());
  52 +
  53 + /**
  54 + *
  55 + * @Title: create
  56 + * @Description: TODO(到离站数据 生成站点耗时)
  57 + * @throws
  58 + */
  59 + public List<Sample> create(List<ArrivalEntity> all, CreateSampleParam param) {
  60 + List<Sample> rs = new ArrayList<>();
  61 + try{
  62 + //路由
  63 + List<StationRoute> routes = routeRepository.findByLine(param.getLineCode(), param.getUpdown());
  64 + //按顺序索引路由
  65 + Map<String, Integer> rMap = new HashMap<>();
  66 + for(int i = 0; i < routes.size(); i ++){
  67 + //起点站不要
  68 + if(routes.get(i).getStationMark().equals("B"))
  69 + continue;
  70 + rMap.put(routes.get(i).getStationCode(), i);
  71 + }
  72 +
  73 + Collections.sort(all, new ArrivalComparator());
  74 +
  75 + //所有的站点耗时数据
  76 + List<Sample> sampleList = calcTimeArray(rMap, all);
  77 + //时区分组,取值
  78 + Set<TimeRange> rgs = param.getTimeRange();
  79 +
  80 + //生成数据
  81 + for(TimeRange rg : rgs)
  82 + rs.addAll(calcCenterVal(sampleList, rg, param.getUpdown()));
  83 + }catch(Exception e){
  84 + logger.error("", e);
  85 + }
  86 +
  87 + return rs;
  88 + }
  89 +
  90 + private List<Sample> calcTimeArray(Map<String, Integer> rMap, List<ArrivalEntity> arrs) throws ParseException {
  91 +
  92 + //车辆和所在站点对照
  93 + Map<String, ArrivalEntity> carMap = new HashMap<>();
  94 +
  95 + int size = arrs.size();
  96 + ArrivalEntity curr, old;
  97 + String device;
  98 +
  99 + List<Sample> sampleList = new ArrayList<>();
  100 + Sample sample;
  101 + for(int i = 0; i < size; i ++){
  102 + curr = arrs.get(i);
  103 + device = curr.getDeviceId();
  104 + old = carMap.get(device);
  105 +
  106 + carMap.put(device, curr);
  107 +
  108 + if(null == old || null == rMap.get(curr.getStopNo())
  109 + || null == rMap.get(old.getStopNo())
  110 + //跨天的数据不要
  111 + || !sdfyyyyMMdd.format(new Date(old.getTs())).equals(sdfyyyyMMdd.format(new Date(curr.getTs()))))
  112 + continue;
  113 +
  114 + //连续站点
  115 + if(rMap.get(curr.getStopNo())
  116 + - rMap.get(old.getStopNo()) == 1){
  117 +
  118 + sample = new Sample(old, curr);
  119 + //将日期全部拉到同一天
  120 + sample.setLineCode(old.getLineCode());
  121 + sample.setsTime(sdfyyyyMMddHHmm.parse(rq + sdfHHmm.format(sample.getsTime())).getTime());
  122 + sample.seteTime(sdfyyyyMMddHHmm.parse(rq + sdfHHmm.format(sample.geteTime())).getTime());
  123 + //sample.setsDate(sdfHHmm.format(new Date(sample.getsTime())));
  124 + //sample.seteDate(sdfHHmm.format(new Date(sample.geteTime())));
  125 + sampleList.add(sample);
  126 +
  127 + }
  128 + carMap.put(device, curr);
  129 + }
  130 + return sampleList;
  131 + }
  132 +
  133 +
  134 + private List<Sample> calcCenterVal(List<Sample> all, TimeRange rg, Integer updown){
  135 + List<Sample> subList = new ArrayList<>()
  136 + ,rsList = new ArrayList<>();
  137 +
  138 + try{
  139 + Collections.sort(all, new SampleComp2());
  140 + //按时区分组数据
  141 + long st = sdfyyyyMMddHHmm.parse(rq + rg.getS()).getTime()
  142 + ,et = sdfyyyyMMddHHmm.parse(rq + rg.getE()).getTime();
  143 + for(Sample s : all){
  144 + if(s.geteTime() > st && s.geteTime() < et)
  145 + subList.add(s);
  146 + else if(s.geteTime() > et)
  147 + break;
  148 + }
  149 +
  150 + //按站点分组数据
  151 + ArrayListMultimap<String, Sample> arrMap = ArrayListMultimap.create();
  152 + for(Sample s : subList)
  153 + arrMap.put(s.getsStation() + "_" + s.geteStation(), s);
  154 +
  155 + //每个站点间取出一个占比最大的数值
  156 + Set<String> keys = arrMap.keySet();
  157 + Sample sample;
  158 + for(String k : keys){
  159 + sample = maxRatioVal(arrMap.get(k));
  160 +
  161 + sample.setTag(rg.getTag() + rg.getS() + " - " + rg.getE());
  162 + sample.setsDate(rg.getS());
  163 + sample.seteDate(rg.getE());
  164 + sample.setUpdown(updown);
  165 + rsList.add(sample);
  166 + }
  167 +
  168 + }catch(Exception e){
  169 + logger.error("", e);
  170 + }
  171 + return rsList;
  172 + }
  173 +
  174 + /**
  175 + *
  176 + * @Title: maxRatioVal
  177 + * @Description: TODO(从一组数值中取出占比最大的值)
  178 + */
  179 + public Sample maxRatioVal(List<Sample> list){
  180 + //StringBuilder valStr = new StringBuilder();
  181 + if(list.size() == 0)
  182 + return null;
  183 + //排序
  184 + Collections.sort(list, new SampleComp());
  185 +
  186 + ArrayListMultimap<String, Sample> arrMap = ArrayListMultimap.create();
  187 + //1.5分钟范围分组
  188 + int range = 15
  189 + ,curr = (int)(list.get(0).getRunTime() * 10);
  190 +
  191 + for(Sample s : list){
  192 + if(s.getRunTime() * 10 > curr + range){
  193 + curr += range;
  194 + }
  195 + arrMap.put(curr + "_" + curr + range, s);
  196 + //valStr.append(s.getRunTime() + ",");
  197 + }
  198 +
  199 + //数值最多的分组,求个平均值
  200 + String maxKey = maxKey(arrMap);
  201 + float absVal = abs(arrMap.get(maxKey));
  202 +
  203 + Sample rs = list.get(0);
  204 +
  205 + DecimalFormat dformat=new DecimalFormat(".00");
  206 + rs.setRunTime(Float.parseFloat(dformat.format(absVal)));
  207 +
  208 + //logger.info("全部:[ " + valStr + "] ,计算的中间值:" + absVal);
  209 + return rs;
  210 + }
  211 +
  212 + private String maxKey(ArrayListMultimap<String, Sample> arrMap){
  213 + String maxKey = null;
  214 + int size = 0;
  215 + Set<String> kys = arrMap.keySet();
  216 + for(String k : kys){
  217 + if(null != maxKey && arrMap.get(k).size() < size)
  218 + continue;
  219 +
  220 + size = arrMap.get(k).size();
  221 + maxKey = k;
  222 + }
  223 + return maxKey;
  224 + }
  225 +
  226 + private float abs(List<Sample> list){
  227 + float sum = 0;
  228 +
  229 + for(Sample s : list)
  230 + sum += s.getRunTime();
  231 +
  232 + return sum / list.size();
  233 + }
  234 +
  235 + public static class SampleComp implements Comparator<Sample>{
  236 +
  237 + @Override
  238 + public int compare(Sample arg0, Sample arg1) {
  239 + return (int)(arg0.getRunTime() * 10 - arg1.getRunTime() * 10);
  240 + }
  241 + }
  242 +
  243 + public static class SampleComp2 implements Comparator<Sample>{
  244 +
  245 + @Override
  246 + public int compare(Sample arg0, Sample arg1) {
  247 + return (int)(arg0.geteTime() - arg1.geteTime());
  248 + }
  249 + }
  250 +}
... ...
src/main/java/com/bsth/service/realcontrol/ScheduleRealInfoService.java
... ... @@ -80,7 +80,7 @@ public interface ScheduleRealInfoService extends BaseService&lt;ScheduleRealInfo, L
80 80  
81 81 Map<String, Object> outgoAdjustAll(String params);
82 82  
83   - Map<String, Object> findRouteByLine(Integer lineCode);
  83 + Map<String, Object> findRouteByLine(String lineCode);
84 84  
85 85 List<Map<String,String>> findLine(String line);
86 86  
... ...
src/main/java/com/bsth/service/realcontrol/impl/ScheduleRealInfoServiceImpl.java
... ... @@ -310,8 +310,9 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
310 310 SysUser user = SecurityUtils.getCurrentUser();
311 311 String schDate = DayOfSchedule.currSchDateMap.get(t.getXlBm());
312 312  
  313 + SimpleDateFormat sdfyyyyMMdd = new SimpleDateFormat("yyyy-MM-dd");
313 314 t.setScheduleDateStr(schDate);
314   - t.setScheduleDate(DateUtils.sdfyyyyMMdd.parse(schDate));
  315 + t.setScheduleDate(sdfyyyyMMdd.parse(schDate));
315 316 t.setRealExecDate(schDate);
316 317 t.setCreateBy(user);
317 318 t.setSflj(true);
... ... @@ -899,7 +900,7 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
899 900 }
900 901  
901 902 @Override
902   - public Map<String, Object> findRouteByLine(Integer lineCode) {
  903 + public Map<String, Object> findRouteByLine(String lineCode) {
903 904 Map<String, Object> map = new HashMap<>();
904 905 //上行
905 906 Integer lineId = BasicData.lineId2CodeMap.inverse().get(lineCode);
... ...
src/main/java/com/bsth/util/DateUtils.java
... ... @@ -96,7 +96,7 @@ public class DateUtils {
96 96 return (int) (cal.getTimeInMillis() / 1000);
97 97 }
98 98  
99   - public static SimpleDateFormat sdfyyyyMMddHHmm = new SimpleDateFormat("yyyy-MM-ddHH:mm")
  99 + private static SimpleDateFormat sdfyyyyMMddHHmm = new SimpleDateFormat("yyyy-MM-ddHH:mm")
100 100 ,sdfyyyyMMdd = new SimpleDateFormat("yyyy-MM-dd")
101 101 ,sdfHHmm = new SimpleDateFormat("HH:mm");
102 102 public static long getTimesByHHmm(String str) throws ParseException{
... ...
src/main/resources/static/index.html
1 1 <!DOCTYPE html>
2   -<html>
  2 +<html lang="zh">
3 3 <head>
  4 +<meta name="renderer" content="webkit" />
  5 +<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
4 6 <meta charset="UTF-8">
5 7 <title>调度系统</title>
6   -<meta name=”renderer” content=”webkit”>
7   -<meta http-equiv=”X-UA-Compatible” content=”IE=Edge,chrome=1″ >
8 8  
9 9 <meta http-equiv="Pragma" content="no-cache">
10 10 <meta http-equiv="Cache-control" content="no-cache">
... ...
src/main/resources/static/login.html
1 1 <!DOCTYPE html>
2   -<html lang="en">
  2 +<html lang="zh">
3 3 <head>
  4 +<meta name="renderer" content="webkit" />
  5 +<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
4 6 <meta charset="utf-8" />
5 7 <title>登录</title>
6 8 <link
... ...
src/main/resources/static/pages/control/line/child_pages/child_task.html
... ... @@ -176,7 +176,7 @@ $(function(){
176 176 var scheduleIdMap;
177 177  
178 178 //滚动时固定表头
179   - $('.custom-table-panel').on('scroll', function(){
  179 + $('#childTaskDiv .custom-table-panel').on('scroll', function(){
180 180 var top = $(this).scrollTop()
181 181 ,$header = $(this).find('.custom-table-header');
182 182 $header.css('top', top);
... ...
src/main/resources/static/pages/control/line/css/lineControl.css
... ... @@ -267,8 +267,8 @@ body{
267 267 }
268 268  
269 269 .portlet-fullscreen .nav-tabs > li > a:hover
270   -,.portlet-fullscreen .nav-tabs > li > a:active{
271   - border: none;
  270 +/* ,.portlet-fullscreen .nav-tabs > li > a:active */{
  271 + border: none;
272 272 background: #0E5384;
273 273 }
274 274  
... ... @@ -279,10 +279,11 @@ body{
279 279 .portlet-fullscreen .nav-tabs>li.active>a{
280 280 background: #FFFFFF;
281 281 color: #0A3F64;
282   - border: 1px solid #FFFFFF;
  282 + border: none;
283 283 border-radius: 5px 5px 0 0 !important;
284 284 }
285 285  
  286 +
286 287 .portlet-fullscreen .nav-tabs {
287 288 /* border-bottom: 1px solid #337AB7; */
288 289 }
... ... @@ -397,7 +398,7 @@ body{
397 398 .card_wrap .line_chart .top .center{
398 399 height: 100%;
399 400 font-size: 15px;
400   - color: #5E96D2;
  401 + color: #babdbd;
401 402 padding: 10px 0px;
402 403 width: auto;
403 404 float: left;
... ... @@ -644,16 +645,24 @@ body{
644 645 height: 25px;
645 646 fill: rgba(253, 253, 253, 0.17);
646 647 rx: 5px;
647   - stroke: #26c281;
648 648 }
649 649  
650 650 .vehci-g.up text,
651 651 .vehci-g.down text{
652   - stroke: #26c281;
653 652 font-size: 12px;
654 653 cursor: default;
655 654 }
656 655  
  656 +.vehci-g.up text,
  657 +.vehci-g.up rect{
  658 + stroke: #337ac4;
  659 +}
  660 +
  661 +.vehci-g.down text,
  662 +.vehci-g.down rect{
  663 + stroke: #e43a45;
  664 +}
  665 +
657 666 .vehci-g.updown-error rect,
658 667 .vehci-g.updown-error text{
659 668 stroke: #CACA17;
... ... @@ -1035,7 +1044,8 @@ height: 400px;
1035 1044 }
1036 1045  
1037 1046 .station_text {
1038   - letter-spacing: -2.6px;
  1047 + /* letter-spacing: -2.6px; */
  1048 + font-family: 华文细黑,华文黑体,宋体;
1039 1049 }
1040 1050 }
1041 1051  
... ... @@ -1577,7 +1587,11 @@ height: 400px;
1577 1587 ::-webkit-scrollbar {
1578 1588 width: 15px;
1579 1589 height: 16px;
1580   -}
  1590 +}
  1591 +
  1592 +#tab_home .custom-table-panel::-webkit-scrollbar{
  1593 + border-top: 1px solid #e7ecf1;
  1594 +}
1581 1595  
1582 1596 ::-webkit-scrollbar-track,
1583 1597 ::-webkit-scrollbar-thumb {
... ... @@ -2588,4 +2602,65 @@ tr.child_task td:nth-child(1):AFTER{
2588 2602 font-size: 10px;
2589 2603 color: #bdbdbd;
2590 2604 margin-left: 3px;
  2605 +}
  2606 +
  2607 +.card_wrap .custom-table-panel{
  2608 + height: calc(100% - 40px);
  2609 +}
  2610 +
  2611 +#tab_home .card_wrap table tr td{
  2612 + white-space: nowrap;
  2613 + overflow: hidden;
  2614 + text-overflow: ellipsis;
  2615 + cursor: pointer;
  2616 +}
  2617 +.sm-text{
  2618 + font-size: 12px;
  2619 + color: #9a9a9a;
  2620 +}
  2621 +
  2622 +td.lt-no-data{
  2623 + text-align: left;
  2624 + font-size: 12px !important;
  2625 + color: #ff7676;
  2626 + text-indent: 8px;
  2627 +}
  2628 +
  2629 +tr._home_tr_active td.lt-no-data{
  2630 + color: #ffffff;
  2631 +}
  2632 +
  2633 +tr._home_tr_active {
  2634 + background: #6a96c5;
  2635 + color: #ffffff;
  2636 +}
  2637 +
  2638 +tr._home_tr_active .sm-text{
  2639 + color: #ded8d8;
  2640 +}
  2641 +
  2642 +abbr.abnormal{
  2643 + color: red;
  2644 +}
  2645 +
  2646 +tr._home_tr_active abbr.abnormal{
  2647 + color: #ffffff;
  2648 +}
  2649 +
  2650 +.line_chart:BEFORE {
  2651 + content: "\f178";
  2652 + font: normal normal normal 14px/1 FontAwesome;
  2653 + position: absolute;
  2654 + top: 20px;
  2655 + left: 20px;
  2656 + color: #d0d0d0;
  2657 +}
  2658 +
  2659 +.line_chart:AFTER {
  2660 + content: "\f177";
  2661 + font: normal normal normal 14px/1 FontAwesome;
  2662 + position: absolute;
  2663 + bottom: 20px;
  2664 + right: 20px;
  2665 + color: #d0d0d0;
2591 2666 }
2592 2667 \ No newline at end of file
... ...
src/main/resources/static/pages/control/line/index.html
... ... @@ -174,7 +174,7 @@
174 174 </li>
175 175 <li class="menu-item submenu">
176 176 <button type="button" class="menu-btn">
177   - <span class="menu-text">车辆状态发送</span>
  177 + <span class="menu-text">车辆状态切换</span>
178 178 </button>
179 179 <menu class="menu">
180 180 <li class="menu-item">
... ...
src/main/resources/static/pages/control/line/js/data.js
... ... @@ -9,7 +9,7 @@ var _data = (function(){
9 9 //实时GPS数据
10 10 var allGps = {};
11 11 //10秒刷新一次实时GPS
12   - var realGpsT = 1000 * 10;
  12 + var realGpsT = 1000 * 8;
13 13  
14 14 var dateStr = moment().format('YYYY-MM-DD');
15 15 //实际排班
... ... @@ -33,26 +33,6 @@ var _data = (function(){
33 33 }
34 34  
35 35 var dataObject = {
36   - /*//班次发车
37   - setFcsj: function(schId, fcsj, fcsjT){
38   - schedules[schId].fcsjActual = fcsj;
39   - schedules[schId].fcsjActualTime = fcsjT;
40   - },*/
41   - //根据线路编码获取上行和下行班次
42   - /*findByLineAll: function(xlbm){
43   - var array = [],sch;
44   - for(var id in schedules){
45   - sch = schedules[id];
46   - if(sch.xlBm == xlbm)
47   - array.push(e);
48   - }
49   - //排序
50   - array.sort(function(a, b){
51   - return a.fcsjT - b.fcsjT;
52   - });
53   -
54   - return array;
55   - },*/
56 36 //根据线路和上下行获取计划排班
57 37 findSchByLine: function(xlbm, upDown){
58 38 var array = [];
... ... @@ -160,14 +140,10 @@ var _data = (function(){
160 140 attachSchedulInfo: function(gpsArray){
161 141 $.each(gpsArray, function(){
162 142 gps = this;
163   - if(gps.currSchId)
164   - gps.currSch = schedules[gps.currSchId];
165   - if(gps.nextSchId)
166   - gps.nextSch = schedules[gps.nextSchId];
  143 + if(gps.schId)
  144 + gps.sch = schedules[gps.schId];
167 145  
168 146 });
169   -
170   - return gpsArray;
171 147 }
172 148 //查询站点路由
173 149 ,queryStationRoute : function(lineId,container, cb, width){
... ... @@ -180,7 +156,7 @@ var _data = (function(){
180 156 startRefreshGpsTimer: function(){
181 157 var f = arguments.callee;
182 158 refreshGpsProxy();
183   - gpsTimer = setTimeout(f, realGpsT);
  159 + //gpsTimer = setTimeout(f, realGpsT);
184 160 },
185 161 //查询实际排班计划
186 162 queryRealSchedule: function(lineArrayStr, cb){
... ... @@ -274,6 +250,7 @@ var _data = (function(){
274 250  
275 251 function refreshGpsProxy(){
276 252 refreshGps(function(add, up){
  253 + //触发元素刷新事件
277 254 $('#tab_home,#tab_map #mapContainer').trigger('gps_refresh', [add, up]);
278 255 });
279 256 }
... ... @@ -316,22 +293,49 @@ var _data = (function(){
316 293 if(!gpsList || gpsList.length == 0)
317 294 return;
318 295  
319   - var prve = allGps
320   - ,addArray = []
321   - ,upArray = []
322   - ,oldGps;
  296 + //var prve = allGps
  297 + //,addArray = []
  298 + //,upArray = []
  299 + // ,oldGps;
323 300 for(var i = 0, gps; gps=gpsList[i++];){
324   - oldGps = prve[gps.deviceId];
  301 + /*oldGps = prve[gps.deviceId];
325 302 if(!oldGps){
326 303 addArray.push(gps);
327 304 }
328 305 else if(gps.timestamp > oldGps.timestamp){
329 306 //更新
330 307 upArray.push(gps);
331   - }
  308 + }*/
  309 + //addArray.push(gps);
  310 +/* if(prve[gps.deviceId] &&
  311 + gps.timestamp == prve[gps.deviceId].timestamp)
  312 + continue;*/
  313 + //异常状态检查
  314 + abnormalCheck(gps);
  315 + //关联班次信息
  316 + if(gps.schId)
  317 + gps.sch = schedules[gps.schId];
  318 +
332 319 allGps[gps.deviceId] = gps;
333 320 }
334   - cb && cb(addArray, upArray);
  321 + //cb && cb(addArray, upArray);
  322 + cb && cb(allGps);
  323 + }
  324 +
  325 + function abnormalCheck(gps){
  326 + var routes = stationRoute[gps.lineId][gps.upDown]
  327 + ,rs;
  328 + $.each(routes , function(){
  329 + if(this.stationCode == gps.stopNo){
  330 + rs = 1;
  331 + return false;
  332 + }
  333 + });
  334 +
  335 + if(!rs){
  336 + gps.abnormal = true;
  337 + gps.abnormalText = '走向异常?';
  338 + }
335 339 }
336 340  
337 341 function getGpsError(jqXHR, textStatus){
... ...
src/main/resources/static/pages/control/line/js/drawSvg.js
... ... @@ -5,7 +5,7 @@
5 5 var drawSvg = (function(){
6 6  
7 7 var mt = 44//顶部距离
8   - ,p = 112//上下行之间的间隔 132
  8 + ,p = 116//上下行之间的间隔
9 9 ,x = d3.scale.linear()
10 10 ,w
11 11 ,homeSvgMapp = {}
... ... @@ -69,12 +69,14 @@ var drawSvg = (function(){
69 69 init: function(lineId, data, container, w, mtop){
70 70 if(!data || data.length == 0)
71 71 return;
72   -
  72 +
73 73 mt = mtop;
74   - //起终点站
  74 + //索引起终点站
75 75 $.each(data, function(){
76   - if(this.stationMark == 'B' || this.stationMark == 'E' )
  76 + if(this.stationMark == 'B' || this.stationMark == 'E' ){
77 77 seGps[lineId + '_' + this.id[0]] = [];
  78 + seGps[lineId + '_' + this.id[1]] = [];
  79 + }
78 80 });
79 81  
80 82 var svg = d3.select('#' + container).append('svg')
... ... @@ -94,22 +96,6 @@ var drawSvg = (function(){
94 96 //下行线条
95 97 drawPath(svg, data, 'down', 10);
96 98  
97   -/* //左弧线 path
98   - svg.append('path')
99   - .attr('d', function(){
100   - var cx = x(0) - 8;
101   - return arcPath(cx , mt + 5,cx - 20);
102   - })
103   - .attr('class', 'up_path arc');
104   -
105   - //右弧线 path
106   - svg.append('path')
107   - .attr('d', function(){
108   - var cx = x(dLen - 1) + 8;
109   - return arcPath(cx , mt + 5,cx + 20);
110   - })
111   - .attr('class', 'down_path arc');*/
112   -
113 99 var g = svg.append('g').selectAll('g')
114 100 .data(data)
115 101 .enter()
... ... @@ -183,12 +169,11 @@ var drawSvg = (function(){
183 169 if(!gpsArray || gpsArray.length == 0)
184 170 return;
185 171  
186   - //console.log('len', gpsArray.length);
187 172 //暂时先清空重新画
188 173 var fGps = gpsArray[0];
189 174 var hSvg = homeSvgMapp[fGps.lineId]
190 175 ,aSvg = aloneSvgMapp[fGps.lineId];
191   - //svg.selectAll('.vehci-g').remove();
  176 +
192 177 if(fGps.upDown == 0){
193 178 hSvg.selectAll('.vehci-g.up').remove();
194 179 hSvg.selectAll('.start.park').remove();
... ... @@ -205,8 +190,9 @@ var drawSvg = (function(){
205 190 }
206 191  
207 192 for(var i = 0, gps; gps = gpsArray[i ++];){
  193 + //首页svg
208 194 drawGpsToSvg(gps, hSvg);
209   -
  195 + //单线路svg
210 196 drawGpsToSvg(gps, aSvg, true);
211 197 }
212 198  
... ... @@ -215,25 +201,28 @@ var drawSvg = (function(){
215 201 for(var eid in seGps){
216 202 len = seGps[eid].length;
217 203 if(len > 0){
218   - var a_e = $('#' + eid, aSvg[0])
219   - ,a_x = parseInt(a_e.attr('cx'))
220   - ,a_y = parseInt(a_e.attr('cy'));
221   - tempStartAndStop(aSvg, eid, a_e, a_x, a_y);
222   -
  204 + //首页svg
223 205 var h_e = $('#' + eid, hSvg[0])
224 206 ,h_x = parseInt(h_e.attr('cx'))
225 207 ,h_y = parseInt(h_e.attr('cy'));
226 208 tempStartAndStop(hSvg, eid ,h_e , h_x, h_y);
  209 + //单线路svg
  210 + var a_e = $('#' + eid, aSvg[0])
  211 + ,a_x = parseInt(a_e.attr('cx'))
  212 + ,a_y = parseInt(a_e.attr('cy'));
  213 + tempStartAndStop(aSvg, eid, a_e, a_x, a_y);
227 214 }
228 215 }
229 216  
230 217 function tempStartAndStop(svg, eid, e, x, y){
  218 + var se = e.attr('class').indexOf('start') != -1?'start':'end';
231 219  
232   - var gs = svg.append('g').classed({'start': e.attr('class').indexOf('start') != -1, 'park': true})
  220 + var gs = svg.append('g').attr('class', se + ' park')
233 221 .selectAll('g').data(seGps[eid]).enter().append('g');
234 222  
  223 +
235 224 //Y轴居中
236   - y = (y + 66) - len * 13;
  225 + //y = (y + 66) - len * 13;
237 226 gs.append('rect')
238 227 .attr('x', x + 15)
239 228 .attr('y', function(d, i){
... ... @@ -297,6 +286,7 @@ var drawSvg = (function(){
297 286 }
298 287 };
299 288  
  289 + //flag 2张svg , 起终点只画一次
300 290 function drawGpsToSvg(gps, svg, flag){
301 291 var stionId = gps.lineId + '_' + gps.stopNo
302 292 ,station = $('#' + stionId, svg[0])/*
... ...
src/main/resources/static/pages/control/line/js/home.js
... ... @@ -35,10 +35,17 @@ var _home = (function() {
35 35 $('.card_wrap').css('height', ah / 3);
36 36  
37 37 // 滚动条
38   - $('.card_wrap .table_wrap').slimscroll({
  38 + /*$('.card_wrap .table_wrap').slimscroll({
39 39 height : '187px',
40 40 alwaysVisible : true,
41 41 opacity : .8
  42 + });*/
  43 +
  44 + //table 滚动时固定表头
  45 + $('#tab_home .custom-table-panel').on('scroll', function(){
  46 + var top = $(this).scrollTop()
  47 + ,$header = $(this).find('.custom-table-header');
  48 + $header.css('top', top);
42 49 });
43 50  
44 51 // SVG线路图
... ... @@ -54,19 +61,20 @@ var _home = (function() {
54 61 // 模拟图GPS刷新事件
55 62 $('#tab_home').on(
56 63 'gps_refresh',
57   - function(e, add, up) {
  64 + function(e, allGps) {
58 65 // 现在先每次全量画
59   - var list = _data.findAllGps();
60   - _data.attachSchedulInfo(list);
  66 + //var list = _data.findAllGps();
  67 + //allGps = _data.attachSchedulInfo(allGps);
61 68  
62 69 // drawSvg.drawVehicle(list);
63 70 // 按线路分组
64   - var listMap = groupByLine(list);
65   -
  71 + var listMap = groupByLine(allGps);
  72 +
66 73 for ( var key in listMap) {
67 74 var htmlStr = template('home_table_temp', {
68 75 list : listMap[key]
69 76 });
  77 + //表格
70 78 $('#tab_' + key).find('tbody').html(htmlStr);
71 79 // 更新badge
72 80 $('#' + key + '_badge').text(
... ... @@ -84,7 +92,7 @@ var _home = (function() {
84 92 $('.load-anim').fadeOut(800);
85 93 $('menu.menu').show();
86 94 }, 400);
87   -
  95 +/*
88 96 setTimeout(function() {
89 97 // 提示文本
90 98 var promptFlag = storage.getItem('promptFlag_0913');
... ... @@ -97,7 +105,7 @@ var _home = (function() {
97 105 storage.setItem('promptFlag_0913', 1);
98 106 }
99 107 }, 1500);
100   - }
  108 +*/ }
101 109 }
102 110  
103 111 function gpslistToMap(gpslist){
... ... @@ -117,10 +125,23 @@ var _home = (function() {
117 125  
118 126 rs[key].push(this);
119 127 });
  128 +
  129 + //排序
  130 + for(var k in rs){
  131 + rs[k].sort(gpsSort);
  132 + }
120 133 return rs;
121 134 }
122 135  
123   -
  136 + function gpsSort(a, b){
  137 + if(!a.expectStopTime)
  138 + return 1;
  139 + if(!b.expectStopTime)
  140 + return 0;
  141 +
  142 + return a.expectStopTime - b.expectStopTime;
  143 + }
  144 +
124 145 countDown('home.js');
125 146 return homeObject;
126 147 })();
127 148 \ No newline at end of file
... ...
src/main/resources/static/pages/control/line/js/homeMenu.js
... ... @@ -34,7 +34,12 @@ var _home_menu = (function(){
34 34 $('#homeMenu').removeClass('show-menu');
35 35 });
36 36 });
37   -
  37 + //点击选中
  38 + $('.portlet-fullscreen').on('click', '.vehicDataTable tr td', function(e){
  39 + e.preventDefault();
  40 + $('.vehicDataTable tr._home_tr_active').removeClass('_home_tr_active');
  41 + $(this).parent().addClass('_home_tr_active');
  42 + });
38 43  
39 44 function showMenu(x, y) {
40 45 var menu = $('#homeMenu'),
... ...
src/main/resources/static/pages/control/line/js/main.js
1 1 var _main = (function(){
2   -
3   -/*setTimeout(function(){
4   - //生成头部选项卡
5   - var topTabs = '', tabPanels = '';
6   - $.each(_data.getLines(), function(i, line){
7   - topTabs += '<li ><a data-id="'+line.lineCode+'" href="#tab_line_'+line.lineCode+'" data-toggle="tab" '+
8   - 'aria-expanded="false"> '+line.name+'<span>(<zz>0</zz>,<zz>0</zz> <zz>托管</zz>)</span> </a></li>';
9   -
10   - tabPanels += '<div class="tab-pane fade tab_line" data-id="'+line.lineCode+'" id="tab_line_'+line.lineCode+'"></div>';
11   -
12   - });
13   - $('#top-tabs-wrap .nav-tabs').append(topTabs);
14   - $('#top-tabs-wrap .tab-content').append(tabPanels);
15   -
16   - //加载地图页数据
17   - $('#tab_map').load('/pages/mapmonitor/real/real.html');
18   -
19   - //初始化单线路调度页面
20   - _alone.init(function(){
21   - //初始化信使
22   - _messenger.init();
23   - //初始化主页
24   - homeObject.init();
25   -
26   - $.each(_data.getLines(), function(){
27   - //计算应发未发数量
28   - _messenger.setYFWFNum(this.lineCode);
29   - });
30   - });
31   -
32   - //监控模式下,拦截post请求
33   - if(operationMode == 0){
34   - $(document).on('ajaxSend', interceptPOST);
35   - }
36   -
37   -}, 200)*/
38 2  
39   -
40   - /*var startEp = EventProxy.create("template", function (template, data, l10n) {
41   - _.template(template, data, l10n);
42   - });*/
43 3 var initEp;
44 4 var mainInstance = {
45 5 start: function(){
... ...
src/main/resources/static/pages/control/line/temps/home_tp.html
... ... @@ -27,26 +27,42 @@
27 27  
28 28 </div>
29 29 </div>
30   - <table class="table table-striped table-bordered table-advance"
31   - style="table-layout: fixed;">
32   - <thead>
33   - <tr>
34   - <th style="width: 22%;">车辆编码</th>
35   - <th style="width: 17%;">路牌</th>
36   - <th style="width: 17%;">速度</th>
37   - <th style="width: 22%;">终点时间</th>
38   - <th style="width: 22%;" class="col_hide_1680">下一班</th>
39   - </tr>
40   - </thead>
41   - </table>
42   - <div class="table_wrap">
43   - <table
44   - class="table table-striped table-bordered table-advance table-hover vehicDataTable"
45   - style="table-layout: fixed;" id="tab_{{lineObj.lineCode}}_0">
46   - <tbody>
47   - </tbody>
48   - </table>
  30 + <div class="custom-table-panel">
  31 + <div style="height: 33px;position: relative;">
  32 + <div class="custom-table-header" style="min-width: 700px;">
  33 + <table class="table table-bordered table-advance" >
  34 + <thead>
  35 + <tr>
  36 + <th width="14%">车辆编码</th>
  37 + <th width="8%">速度</th>
  38 + <th width="14%">终点时间</th>
  39 + <th width="16%">当前站点</th>
  40 + <th width="16%">终点站</th>
  41 + <th width="11%">计划终点</th>
  42 + <th width="10%">驾驶员</th>
  43 + <th width="10%">售票员</th>
  44 + </tr>
  45 + </thead>
  46 + </table>
  47 + </div>
  48 + </div>
  49 + <div class="custom-table-body" style="min-width: 700px;">
  50 + <table class="table table-bordered vehicDataTable" id="tab_{{lineObj.lineCode}}_0">
  51 + <colgroup>
  52 + <col width="14%"></col>
  53 + <col width="8%"></col>
  54 + <col width="14%"></col>
  55 + <col width="16%"></col>
  56 + <col width="16%"></col>
  57 + <col width="11%"></col>
  58 + <col width="10%"></col>
  59 + <col width="10%"></col>
  60 + </colgroup>
  61 + <tbody></tbody>
  62 + </table>
  63 + </div>
49 64 </div>
  65 +
50 66 </div>
51 67 <div class="col-lg-8 line_chart" id="line_chart_{{lineObj.lineCode}}">
52 68 <div class="top">
... ... @@ -74,25 +90,40 @@
74 90 </ul>-->
75 91 </div>
76 92 </div>
77   - <table class="table table-striped table-bordered table-advance"
78   - style="table-layout: fixed;">
79   - <thead>
80   - <tr>
81   - <th style="width: 22%;">车辆编码</th>
82   - <th style="width: 17%;">路牌</th>
83   - <th style="width: 17%;">速度</th>
84   - <th style="width: 22%;">终点时间</th>
85   - <th style="width: 22%;" class="col_hide_1680">下一班</th>
86   - </tr>
87   - </thead>
88   - </table>
89   - <div class="table_wrap">
90   - <table
91   - class="table table-striped table-bordered table-advance table-hover vehicDataTable"
92   - style="table-layout: fixed;" id="tab_{{lineObj.lineCode}}_1">
93   - <tbody>
94   - </tbody>
95   - </table>
  93 + <div class="custom-table-panel">
  94 + <div style="height: 33px;position: relative;">
  95 + <div class="custom-table-header" style="min-width: 700px;">
  96 + <table class="table table-bordered table-advance" >
  97 + <thead>
  98 + <tr>
  99 + <th width="14%">车辆编码</th>
  100 + <th width="8%">速度</th>
  101 + <th width="14%">终点时间</th>
  102 + <th width="16%">当前站点</th>
  103 + <th width="16%">终点站</th>
  104 + <th width="11%">计划终点</th>
  105 + <th width="10%">驾驶员</th>
  106 + <th width="10%">售票员</th>
  107 + </tr>
  108 + </thead>
  109 + </table>
  110 + </div>
  111 + </div>
  112 + <div class="custom-table-body" style="min-width: 700px;">
  113 + <table class="table table-bordered vehicDataTable" id="tab_{{lineObj.lineCode}}_1">
  114 + <colgroup>
  115 + <col width="14%"></col>
  116 + <col width="8%"></col>
  117 + <col width="14%"></col>
  118 + <col width="16%"></col>
  119 + <col width="16%"></col>
  120 + <col width="11%"></col>
  121 + <col width="10%"></col>
  122 + <col width="10%"></col>
  123 + </colgroup>
  124 + <tbody></tbody>
  125 + </table>
  126 + </div>
96 127 </div>
97 128 </div>
98 129 </div>
... ... @@ -122,23 +153,30 @@
122 153 <script id="home_table_temp" type="text/html">
123 154 {{each list as obj i}}
124 155 <tr data-nbbm="{{obj.nbbm}}" data-device="{{obj.deviceId}}">
125   - <td style="width: 22%;"> {{obj.nbbm}} </td>
126   - <td style="width: 17%;">
127   - {{if obj.currSch != null}}
128   - {{obj.currSch.lpName}}
  156 + <td title="{{obj.nbbm}}">
  157 + {{if !obj.abnormal}}
  158 + {{obj.nbbm}}
  159 + {{else}}
  160 + <abbr class="abnormal" title="{{obj.abnormalText}}">{{obj.nbbm}}</abbr>
  161 + {{/if}}
  162 + </td>
  163 + <td> {{obj.speed}} </td>
  164 + <td>
  165 + {{if obj.expectStopTime != null}}
  166 + {{obj.expectStopTime}} <span class="sm-text">分钟</span>
129 167 {{else}}
130   -
  168 + <span class="sm-text">无</span>
131 169 {{/if}}
132 170 </td>
133   - <td style="width: 17%;"> {{obj.speed}} </td>
134   - <td style="width: 22%;" > 暂无 </td>
135   - <td style="width: 22%;" class="col_hide_1680">
136   -{{if obj.nextSch != null}}
137   - {{obj.nextSch.dfsj}}
138   -{{else}}
139   - 无
140   -{{/if}}
141   - </td>
  171 + <td title="{{obj.stationName}}"> {{obj.stationName}} </td>
  172 + {{if obj.sch != null}}
  173 + <td title="{{obj.sch.zdzName}}"> {{obj.sch.zdzName}} </td>
  174 + <td>{{obj.sch.zdsj}}</td>
  175 + <td> {{obj.sch.jName}} </td>
  176 + <td> {{obj.sch.sName}} </td>
  177 + {{else}}
  178 + <td colspan=4 class="lt-no-data">无班次信息</td>
  179 + {{/if}}
142 180 </tr>
143 181 {{/each}}
144 182 </script>
... ...
src/main/resources/static/pages/control/line/temps/tooltip_tp.html
... ... @@ -9,14 +9,7 @@
9 9 <div><a href="javascript:;" data-for="station" class="tip_modal">{{stationName}}</a></div>
10 10 <div>速度:{{speed}}</div>
11 11 <hr >
12   - <div>预计 ? 分钟后到达<a href="javascript:;" data-for="station" class="tip_modal">下一站</a></div>
13   - <div>终点站:
14   - <a href="javascript:;" data-for="station" >
15   - {{if currSch != null}}
16   - {{currSch.zdzName}}
17   - {{/if}}
18   -
19   - </a></div>
  12 + <div>预计 {{expectStopTime}} 分钟到达终点</div>
20 13 <hr >
21 14 <div class="subtitle">{{fromNow}}更新(在线)</div>
22 15 <div class="subtitle" style="margin-top: 8px;">
... ...
src/main/resources/static/pages/forecast/sample/css/main.css
... ... @@ -311,4 +311,16 @@ rect.f_rect{
311 311 overflow-x: hidden;
312 312 padding-right: 15px;
313 313 margin: 15px 0px;
314   -}
315 314 \ No newline at end of file
  315 +}
  316 +
  317 +#forecast_sample_modal ul.tabs-left li{
  318 +}
  319 +
  320 +#forecast_sample_modal span.desc {
  321 + color: #5580a5;
  322 + text-align: left;
  323 + font-size: 12px;
  324 +}
  325 +#forecast_sample_modal ul.tabs-left li.active span.desc{
  326 + color: #989292;
  327 +}
... ...
src/main/resources/static/pages/forecast/sample/js/svg.js
... ... @@ -70,7 +70,7 @@ var sampleSvg = (function(){
70 70 });
71 71  
72 72 var h = rts[rts.length - 1].cy + 50;
73   - svg.style('height', h).style('opacity', 0);
  73 + svg.style('height', h)/*.style('opacity', 0)*/;
74 74 $('#svgWrap').css('height', h + 6);
75 75  
76 76 //画线
... ... @@ -97,7 +97,7 @@ var sampleSvg = (function(){
97 97 showTags();
98 98  
99 99 //d3 anim
100   - svg.transition().delay(100).style('opacity', 1);
  100 + //svg.transition().delay(100).style('opacity', 1);
101 101 }
102 102  
103 103 //tag 点击事件
... ... @@ -141,7 +141,7 @@ var sampleSvg = (function(){
141 141 .attr('x', function(d){return d.cp[0]})
142 142 .attr('y', function(d){return d.cp[1]})
143 143 .attr('class', 'f_text')
144   - .text(function(d){return d.runTime + 'm'});
  144 + .text(function(d){return d.runTime + ''});
145 145 }
146 146  
147 147  
... ... @@ -151,17 +151,19 @@ var sampleSvg = (function(){
151 151 }
152 152  
153 153 function showTags(){
  154 + var index = layer.msg('加载中', {icon: 16, time: 0,shade:0.3});
154 155 //查询 耗时信息
155 156 $.get('/sample/all', {'lineCode_eq': _opt.lineCode, 'updown_eq': _opt.updown}, function(rs){
156 157 //按tag分组数据
157 158 _data = {};
158   - var tags = '';//
  159 + var tags = '', ct;//
159 160 $.each(rs, function(i, d){
160   - if(!_data[d.tag]){
161   - _data[d.tag] = [];
162   - tags += '<a class="tag" title="'+d.tag+'">'+(d.tag + ' ' + d.sDate + ' - ' + d.eDate)+'</a>';
  161 + ct = cutTag(d.tag);
  162 + if(!_data[ct]){
  163 + _data[ct] = [];
  164 + tags += '<a class="tag" title="'+ct+'">'+ d.tag +'</a>';
163 165 }
164   - _data[d.tag].push(d);
  166 + _data[ct].push(d);
165 167 });
166 168  
167 169 var wrap = $('#trafficChart .sample_tags');
... ... @@ -169,6 +171,8 @@ var sampleSvg = (function(){
169 171 wrap.append(tags);
170 172 //选中第一个tag
171 173 $('#trafficChart .sample_tags a.tag:eq(0)').click();
  174 +
  175 + layer.close(index);
172 176 });
173 177 }
174 178  
... ... @@ -185,7 +189,7 @@ var sampleSvg = (function(){
185 189 $.get('/pages/forecast/sample/modal.html', function(rs){
186 190 var index = layer.open({
187 191 type: 1,
188   - area: '550px',
  192 + area: '560px',
189 193 content: rs,
190 194 shift: 5,
191 195 title: '人工编辑',
... ... @@ -230,5 +234,9 @@ var sampleSvg = (function(){
230 234 return cp;
231 235 }
232 236  
  237 + function cutTag(tag){
  238 + return tag.replace(new RegExp(/:/g),'').replace(new RegExp(/ /g),'').replace(new RegExp(/-/g) ,'');
  239 + }
  240 +
233 241 return drawObject;
234 242 })();
235 243 \ No newline at end of file
... ...
src/main/resources/static/pages/forecast/sample/main.html
... ... @@ -264,8 +264,10 @@
264 264 delete param.dr_etime;
265 265 param.timeRange = timeRange;
266 266  
267   - $.post('/sample/create/gps', {data: encodeURI(JSON.stringify(param))}, function(rs){
268   - console.log(rs);
  267 + layer.msg('服务器正在处理数据,请稍等...', {icon: 16, shade: 0.3});
  268 + $post('/sample/create/gps', {data: encodeURI(JSON.stringify(param))}, function(rs){
  269 + layer.closeAll();
  270 + drawSvg();
269 271 });
270 272 }
271 273 }catch (e){
... ...
src/main/resources/static/pages/forecast/sample/modal.html
... ... @@ -8,7 +8,7 @@
8 8 <ul class="nav nav-tabs tabs-left">
9 9 {{each data as obj i}}
10 10 <li >
11   - <a href="#tab_sample_{{i}}" data-toggle="tab" title="{{obj.t}}"> {{obj.t}} </a>
  11 + <a href="#tab_sample_{{i}}" data-toggle="tab" title="{{obj.t}}"> {{#obj.escapeTag}} </a>
12 12 </li>
13 13 {{/each}}
14 14 <li ><a href="#tab_sample_add" data-toggle="tab" style="font-size: 12px;color: red;"> <i class="fa fa-plus"></i> 新增 </a></li>
... ... @@ -89,9 +89,9 @@
89 89 <label class="col-md-3 control-label">时区:</label>
90 90 <div class="col-md-9">
91 91 <select class="form-control" name="tag" style="width:100%;" multiple required>
92   - <option value="早高峰">早高峰</option>
93   - <option value="平峰">平峰</option>
94   - <option value="晚高峰">晚高峰</option>
  92 + {{each tsArray as t i}}
  93 + <option value="{{t}}">{{t}}</option>
  94 + {{/each}}
95 95 </select>
96 96 </div>
97 97 </div>
... ... @@ -129,9 +129,12 @@
129 129 <script>
130 130 !function(){
131 131 var _data,_opt,id, currentData, layero, drawObject;
132   - var tagRange = {'早高峰': {s: '06:31', e: '08:30'}, '平峰': {s: '08:31', e: '16:00'}, '晚高峰': {s: '16:01', e: '18:00'}};
  132 + var tagRange = {};
133 133  
134 134 $('#forecast_sample_modal').on('init', function(e, rs){
  135 + //提取出tag Range
  136 + var tsArray = extractTag(rs._data);
  137 +
135 138 _data = rs._data;
136 139 _opt = rs._opt;
137 140 drawObject = rs.drawObject;
... ... @@ -147,8 +150,14 @@
147 150 var eid = id, sid = _prve.stationCode;
148 151 var sampData = searchData(sid, eid);
149 152 var baseData = {sid: sid, eid: eid, sName: toName(sid), eName: toName(eid)};
150   - console.log('baseData', baseData);
151   - var html = template('forecast_sample_tab_detail_temp', {data: sampData, base: baseData});
  153 +
  154 + //tag加换行符
  155 + $.each(sampData, function(){
  156 + var t = this.d.tag.replace(new RegExp(/ /g),'');
  157 + this.escapeTag = t.substr(0, t.length - 11) + '<br>' + '<span class="desc">' + t.substr(t.length - 11, 11) + '</span>';
  158 + });
  159 +
  160 + var html = template('forecast_sample_tab_detail_temp', {data: sampData, base: baseData, tsArray: tsArray});
152 161 $('#forecast_sample_modal .row').html(html);
153 162 //默认选中tab
154 163 defaultSelect(rs.tag);
... ... @@ -294,5 +303,23 @@
294 303 }
295 304 return rs;
296 305 }
  306 +
  307 + function extractTag(_data){
  308 + var rs = [];
  309 + var len, t, s, e;
  310 + for(var key in _data){
  311 + len = key.length;
  312 + t = key.substring(0, len - 8);
  313 + s = key.substring(len - 8, len - 4);
  314 + e = key.substring(len - 4, len);
  315 +
  316 + s = s.substr(0, 2) + ':' + s.substr(2);
  317 + e = e.substr(0, 2) + ':' + e.substr(2);
  318 + tagRange[t] = {s: s, e: e};
  319 + rs.push(t);
  320 + }
  321 +
  322 + return rs;
  323 + }
297 324 }();
298 325 </script>
299 326 \ No newline at end of file
... ...
src/main/resources/static/pages/mapmonitor/real/real.html
... ... @@ -124,12 +124,12 @@ CanvasRenderingContext2D.prototype.roundRect = function (x, y, w, h, r) {
124 124 }
125 125  
126 126 //GPS刷新事件
127   -$('#mapContainer').on('gps_refresh', function(e, add, up){
  127 +$('#mapContainer').on('gps_refresh', function(e, all){
128 128 if($(this).is(":hidden"))
129 129 return;
130   - var all = add ,gps;
  130 +/* var all = add ,gps;
131 131 if(up)
132   - all = all.concat(up);
  132 + all = all.concat(up); */
133 133  
134 134 $.each(all, function(){
135 135 consts.allGps[this.deviceId] = this;
... ...