Commit 068aa54f725e985348c6a954c3444f435ab1acc3

Authored by panzh
1 parent 7612f361

update...

src/main/java/com/bsth/controller/GeoDataController.java
@@ -34,4 +34,13 @@ public class GeoDataController { @@ -34,4 +34,13 @@ public class GeoDataController {
34 rs.put("stations", stationLists); 34 rs.put("stations", stationLists);
35 return rs; 35 return rs;
36 } 36 }
  37 +
  38 + @RequestMapping("/stations/{lineCode}/{upDown}")
  39 + public Map<String, Object> findStationsByUpDown(@PathVariable("lineCode") String lineCode,@PathVariable("upDown") int upDown) {
  40 + List<StationRoute> list = GeoCacheData.find(lineCode, upDown);
  41 +
  42 + Map<String, Object> rs = new HashMap<>();
  43 + rs.put("stations", list);
  44 + return rs;
  45 + }
37 } 46 }
src/main/java/com/bsth/controller/XmlInfoPublishController.java 0 → 100644
  1 +package com.bsth.controller;
  2 +
  3 +import com.bsth.controller.dto.DispatchScreen;
  4 +import com.bsth.data.BasicCacheData;
  5 +import com.bsth.data.geo.GeoCacheData;
  6 +import com.bsth.data.gps.GpsCacheData;
  7 +import com.bsth.data.history.HistoryConsumeTimeDataHandler;
  8 +import com.bsth.data.schedule.entity.ScheduleRealInfo;
  9 +import com.bsth.entity.GpsEntity;
  10 +import com.bsth.entity.Line;
  11 +import com.bsth.entity.StationRoute;
  12 +import org.apache.commons.lang3.StringUtils;
  13 +import org.slf4j.Logger;
  14 +import org.slf4j.LoggerFactory;
  15 +import org.springframework.beans.factory.annotation.Autowired;
  16 +import org.springframework.jdbc.core.BeanPropertyRowMapper;
  17 +import org.springframework.jdbc.core.JdbcTemplate;
  18 +import org.springframework.web.bind.annotation.RequestMapping;
  19 +import org.springframework.web.bind.annotation.RequestParam;
  20 +import org.springframework.web.bind.annotation.RestController;
  21 +
  22 +import java.text.DecimalFormat;
  23 +import java.util.*;
  24 +
  25 +/**
  26 + * 信息发布,xml 格式
  27 + */
  28 +@RestController
  29 +@RequestMapping("xxfb")
  30 +public class XmlInfoPublishController {
  31 +
  32 +
  33 + @Autowired
  34 + JdbcTemplate jdbcTemplate;
  35 +
  36 + Logger logger = LoggerFactory.getLogger(this.getClass());
  37 +
  38 + static DecimalFormat df = new DecimalFormat("#.00");
  39 +
  40 + @RequestMapping("getLineInfoByName")
  41 + public String getLineInfoByName(@RequestParam String linename, @RequestParam String t) {
  42 + StringBuilder sb = new StringBuilder();
  43 + try {
  44 + if (StringUtils.isBlank(linename))
  45 + return "";
  46 +
  47 + Collection<Line> vs = BasicCacheData.code2LineMap.values();
  48 +
  49 + Line line = null;
  50 + for (Line v : vs) {
  51 + if (linename.equals(v.getName())) {
  52 + line = v;
  53 + break;
  54 + }
  55 + }
  56 +
  57 + if (null == line)
  58 + return "";
  59 +
  60 + //to xml
  61 + sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  62 + sb.append("<linedetail>");
  63 +
  64 + sb.append("<end_earlytime>" + line.getEndStationFirstTime() + "</end_earlytime>");
  65 + sb.append("<end_latetime>" + line.getEndStationEndTime() + "</end_latetime>");
  66 + sb.append("<end_stop>" + line.getEndStationName() + "</end_stop>");
  67 + sb.append("<line_id>" + line.getLineCode() + "</line_id>");
  68 + sb.append("<line_name>" + line.getName() + "</line_name>");
  69 + sb.append("<start_earlytime>" + line.getStartStationFirstTime() + "</start_earlytime>");
  70 + sb.append("<start_latetime>" + line.getStartStationEndTime() + "</start_latetime>");
  71 + sb.append("<start_stop>" + line.getStartStationName() + "</start_stop>");
  72 +
  73 + sb.append("</linedetail>");
  74 + } catch (Exception e) {
  75 + logger.error("", e);
  76 + }
  77 + return sb.toString();
  78 + }
  79 +
  80 + @RequestMapping("getLine")
  81 + public String getLine(@RequestParam String lineid, @RequestParam String t) {
  82 + StringBuilder sb = new StringBuilder();
  83 + try {
  84 +
  85 + List<StationRoute>[] listArray = GeoCacheData.find(lineid);
  86 +
  87 + List<StationRoute> srs0 = listArray[0];
  88 + List<StationRoute> srs1 = listArray[1];
  89 +
  90 + //to xml
  91 +
  92 + sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  93 + sb.append("<lineInfoDetails>");
  94 +
  95 + if (null != srs0) {
  96 + //上行
  97 + sb.append("<lineResults0>");
  98 + sb.append("<direction>true</direction>");
  99 + sb.append("<stops>");
  100 + for (StationRoute s : srs0) {
  101 + sb.append("<stop>");
  102 + sb.append("<zdmc>" + s.getName() + "</zdmc>");
  103 + sb.append("<id>" + s.getStationCode() + "</id>");
  104 + sb.append("</stop>");
  105 + }
  106 + sb.append("</stops>");
  107 + sb.append("</lineResults0>");
  108 + }
  109 +
  110 +
  111 + if (null != srs1) {
  112 + //下行
  113 + sb.append("<lineResults1>");
  114 + sb.append("<direction>false</direction>");
  115 + sb.append("<stops>");
  116 + for (StationRoute s : srs1) {
  117 + sb.append("<stop>");
  118 + sb.append("<zdmc>" + s.getName() + "</zdmc>");
  119 + sb.append("<id>" + s.getStationCode() + "</id>");
  120 + sb.append("</stop>");
  121 + }
  122 + sb.append("</stops>");
  123 + sb.append("</lineResults1>");
  124 + }
  125 +
  126 + sb.append("</lineInfoDetails>");
  127 + } catch (Exception e) {
  128 + logger.error("", e);
  129 + }
  130 + return sb.toString();
  131 + }
  132 +
  133 + @RequestMapping("carMonitor")
  134 + public String carMonitor(@RequestParam String lineid, @RequestParam String stopid, @RequestParam String direction, String t) {
  135 + StringBuilder sb = new StringBuilder();
  136 +
  137 + try {
  138 +
  139 + int upDown = Integer.parseInt(direction);
  140 + List<GpsEntity> list = GpsCacheData.findList(lineid, upDown);
  141 +
  142 + Map<String, Double> disMap = new HashMap<>();
  143 + List<StationRoute> srs = GeoCacheData.find(lineid, upDown);
  144 +
  145 + StationRoute es = GeoCacheData.findByCode(lineid, upDown, stopid), s = null;
  146 +
  147 + List<GpsEntity> vs = new ArrayList<>();
  148 + ScheduleRealInfo sch = null;
  149 + double sum;
  150 +
  151 + int serialNo = es.getSerialNo();
  152 + for (GpsEntity gps : list) {
  153 +
  154 + s = GeoCacheData.findByCode(gps);
  155 + if (null == s || s.getSerialNo() > serialNo)
  156 + continue;
  157 +
  158 + sch = gps.getSch();
  159 + if (null != sch) {//有班次
  160 + if (serialNo > sch.getQdzNo() && serialNo < sch.getZdzNo())
  161 + vs.add(gps);
  162 + } else {
  163 + vs.add(gps);
  164 + }
  165 +
  166 + sum = 0;
  167 +
  168 + for (StationRoute sr : srs) {
  169 + if (sr.getSerialNo() < serialNo
  170 + && sr.getSerialNo() > gps.getStationNo()) {
  171 + sum += sr.getLength();
  172 + }
  173 + }
  174 +
  175 + disMap.put(gps.getDeviceId(), sum);
  176 + }
  177 +
  178 +
  179 + Map<String, Integer> forecast = HistoryConsumeTimeDataHandler.forecastEnd(vs, stopid);
  180 +
  181 + //to xml
  182 +
  183 + sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  184 + sb.append("<result>");
  185 + sb.append("<cars lineid=\"" + lineid + "\">");
  186 +
  187 + for (GpsEntity v : vs) {
  188 + sb.append("<car>");
  189 + sb.append("<terminal>" + BasicCacheData.device2plateMap.get(v.getDeviceId()) + "</terminal>");
  190 + sb.append("<stopdis>" + df.format(v.getStopDis()) + "</stopdis>");
  191 + sb.append("<distance>" + df.format((disMap.get(v.getDeviceId()) + v.getDistance())) + "</distance>");
  192 + sb.append("<time>" + forecast.get(v.getDeviceId()) + "</time>");
  193 + sb.append("</car>");
  194 + }
  195 +
  196 + sb.append("</cars>");
  197 + sb.append("</result>");
  198 + } catch (Exception e) {
  199 + logger.error("", e);
  200 + }
  201 + return sb.toString();
  202 + }
  203 +
  204 + @RequestMapping("getdispatchScreen")
  205 + public String getdispatchScreen(@RequestParam String lineid, @RequestParam String direction, String t) {
  206 + StringBuilder sb = new StringBuilder();
  207 +
  208 + try {
  209 + String sql = "select cph as plate,dfsj as time,line_code from bsth_t_clfcxxb where line_code='" + lineid + "' and updown=" + direction;
  210 +
  211 + List<DispatchScreen> list = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(DispatchScreen.class));
  212 +
  213 + //to xml
  214 +
  215 + sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  216 + sb.append("<result>");
  217 + sb.append("<cars lineid=\"" + lineid + "\">");
  218 +
  219 + char[] cs;
  220 + for (DispatchScreen d : list) {
  221 + cs = d.getTime().toCharArray();
  222 + sb.append("<car>");
  223 + sb.append("<vehicle>" + d.getPlate() + "</vehicle>");
  224 + sb.append("<time>" + (cs[0] + cs[1] + ":" + cs[2] + cs[3] + ":00") + "</time>");
  225 + sb.append("</car>");
  226 + }
  227 +
  228 + sb.append("</cars>");
  229 + sb.append("</result>");
  230 + } catch (Exception e) {
  231 + logger.error("", e);
  232 + }
  233 + return sb.toString();
  234 + }
  235 +}
src/main/java/com/bsth/controller/dto/DispatchScreen.java 0 → 100644
  1 +package com.bsth.controller.dto;
  2 +
  3 +public class DispatchScreen {
  4 +
  5 + private String lineCode;
  6 + private String plate;
  7 + private String time;
  8 +
  9 + public String getLineCode() {
  10 + return lineCode;
  11 + }
  12 +
  13 + public void setLineCode(String lineCode) {
  14 + this.lineCode = lineCode;
  15 + }
  16 +
  17 + public String getPlate() {
  18 + return plate;
  19 + }
  20 +
  21 + public void setPlate(String plate) {
  22 + this.plate = plate;
  23 + }
  24 +
  25 + public String getTime() {
  26 + return time;
  27 + }
  28 +
  29 + public void setTime(String time) {
  30 + this.time = time;
  31 + }
  32 +}
src/main/java/com/bsth/data/BasicCacheData.java
@@ -30,6 +30,8 @@ public class BasicCacheData { @@ -30,6 +30,8 @@ public class BasicCacheData {
30 30
31 public static BiMap<String, String> device2nbbmMap; 31 public static BiMap<String, String> device2nbbmMap;
32 32
  33 + public static Map<String, String> device2plateMap;
  34 +
33 Logger logger = LoggerFactory.getLogger(this.getClass()); 35 Logger logger = LoggerFactory.getLogger(this.getClass());
34 36
35 @Autowired 37 @Autowired
@@ -41,19 +43,26 @@ public class BasicCacheData { @@ -41,19 +43,26 @@ public class BasicCacheData {
41 } 43 }
42 44
43 private void loadDevice2nbbmMap() { 45 private void loadDevice2nbbmMap() {
44 - List<Map<String, Object>> list = jdbcTemplate.queryForList("select INSIDE_CODE,EQUIPMENT_CODE from bsth_c_cars where inside_code is not null and equipment_code is not null"); 46 + List<Map<String, Object>> list = jdbcTemplate.queryForList("select INSIDE_CODE,EQUIPMENT_CODE,CAR_PLATE from bsth_c_cars where equipment_code is not null");
45 47
46 BiMap<String, String> biMap = HashBiMap.create(); 48 BiMap<String, String> biMap = HashBiMap.create();
  49 + Map<String, String> pateMap = new HashMap<>();
47 50
48 for (Map<String, Object> map : list) { 51 for (Map<String, Object> map : list) {
49 - biMap.put(map.get("EQUIPMENT_CODE").toString(), map.get("INSIDE_CODE").toString()); 52 + try {
  53 + biMap.put(map.get("EQUIPMENT_CODE").toString(), map.get("INSIDE_CODE").toString());
  54 + pateMap.put(map.get("EQUIPMENT_CODE").toString(), map.get("CAR_PLATE").toString());
  55 + } catch (Exception e) {
  56 + logger.error("", e);
  57 + }
50 } 58 }
51 59
52 device2nbbmMap = biMap; 60 device2nbbmMap = biMap;
  61 + device2plateMap = pateMap;
53 } 62 }
54 63
55 private void loadCode2LineMap() { 64 private void loadCode2LineMap() {
56 - String sql = "select line_code,`name`,start_station_name,end_station_name from bsth_c_line WHERE destroy=0 and `remove`!=1"; 65 + String sql = "select line_code,`name`,start_station_name,end_station_name,start_station_first_time,start_station_end_time,end_station_first_time,end_station_end_time from bsth_c_line WHERE destroy=0 and `remove`!=1";
57 List<Line> list = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(Line.class)); 66 List<Line> list = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(Line.class));
58 67
59 Map<String, Line> map = new HashMap<>(); 68 Map<String, Line> map = new HashMap<>();
src/main/java/com/bsth/data/geo/loader/util/GeoCalculator.java
@@ -75,9 +75,10 @@ public class GeoCalculator { @@ -75,9 +75,10 @@ public class GeoCalculator {
75 if (pi > ci) 75 if (pi > ci)
76 continue; 76 continue;
77 77
78 - /*if(s.getStationCode().equals("32270"))  
79 - System.out.println("bbb");*/  
80 - s.setPaths(new CopyOnWriteArrayList(subList(seCds, pi, ci + 1))); 78 + if (ci - pi < 2)
  79 + s.setPaths(null);
  80 + else
  81 + s.setPaths(new CopyOnWriteArrayList(subList(seCds, pi, ci + 1)));
81 pi = ci; 82 pi = ci;
82 } 83 }
83 84
src/main/java/com/bsth/data/gps/GpsCacheData.java
@@ -48,13 +48,12 @@ public class GpsCacheData { @@ -48,13 +48,12 @@ public class GpsCacheData {
48 GpsEntity prev = realMap.get(device); 48 GpsEntity prev = realMap.get(device);
49 49
50 if (null != prev) { 50 if (null != prev) {
51 - if (!prev.getCode().equals(gps.getCode())){ 51 + if (!prev.getCode().equals(gps.getCode())) {
52 lineRealMap.remove(prev.getCode(), prev.getDeviceId()); 52 lineRealMap.remove(prev.getCode(), prev.getDeviceId());
53 lineRealMap.put(gps.getCode(), gps.getDeviceId()); 53 lineRealMap.put(gps.getCode(), gps.getDeviceId());
54 } 54 }
55 putPrev(prev); 55 putPrev(prev);
56 - }  
57 - else 56 + } else
58 lineRealMap.put(gps.getCode(), gps.getDeviceId()); 57 lineRealMap.put(gps.getCode(), gps.getDeviceId());
59 58
60 59
@@ -113,13 +112,13 @@ public class GpsCacheData { @@ -113,13 +112,13 @@ public class GpsCacheData {
113 List<String> ds = lineRealMap.get(lineCode + "_" + upDown); 112 List<String> ds = lineRealMap.get(lineCode + "_" + upDown);
114 113
115 List<GpsEntity> list = new ArrayList<>(ds.size()); 114 List<GpsEntity> list = new ArrayList<>(ds.size());
116 - for(String d : ds){ 115 + for (String d : ds) {
117 list.add(findOne(d)); 116 list.add(findOne(d));
118 } 117 }
119 118
120 Map<String, Object> rs = new HashMap<>(); 119 Map<String, Object> rs = new HashMap<>();
121 rs.put("list", list); 120 rs.put("list", list);
122 - rs.put("forecast", HistoryConsumeTimeDataHandler.forecastEnd(list)); 121 + rs.put("forecast", HistoryConsumeTimeDataHandler.forecastEnd(list, null));//终点时间预测
123 return rs; 122 return rs;
124 } 123 }
125 124
@@ -156,4 +155,15 @@ public class GpsCacheData { @@ -156,4 +155,15 @@ public class GpsCacheData {
156 prevMap.remove(deviceId); 155 prevMap.remove(deviceId);
157 } 156 }
158 } 157 }
  158 +
  159 + public static List<GpsEntity> findList(String lineCode, int upDown) {
  160 + List<String> ds = lineRealMap.get(lineCode + "_" + upDown);
  161 +
  162 + List<GpsEntity> list = new ArrayList<>(ds.size());
  163 + for (String d : ds) {
  164 + list.add(findOne(d));
  165 + }
  166 +
  167 + return list;
  168 + }
159 } 169 }
src/main/java/com/bsth/data/gps/process/chains/InOutStationProcess.java
@@ -9,6 +9,7 @@ import com.bsth.entity.CarPark; @@ -9,6 +9,7 @@ import com.bsth.entity.CarPark;
9 import com.bsth.entity.GpsEntity; 9 import com.bsth.entity.GpsEntity;
10 import com.bsth.entity.StationRoute; 10 import com.bsth.entity.StationRoute;
11 import com.bsth.util.geo.GeoUtils; 11 import com.bsth.util.geo.GeoUtils;
  12 +import com.bsth.util.geo.Point;
12 import org.slf4j.Logger; 13 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory; 14 import org.slf4j.LoggerFactory;
14 import org.springframework.beans.factory.annotation.Autowired; 15 import org.springframework.beans.factory.annotation.Autowired;
@@ -53,19 +54,22 @@ public class InOutStationProcess { @@ -53,19 +54,22 @@ public class InOutStationProcess {
53 if (null != sDetail) { 54 if (null != sDetail) {
54 s = sDetail.getSr(); 55 s = sDetail.getSr();
55 gps.setInOut(1); 56 gps.setInOut(1);
56 - gps.setStationCode(s.getStationCode());  
57 gps.setInStationDistance(sDetail.getDistance()); 57 gps.setInStationDistance(sDetail.getDistance());
58 - gps.setStationName(s.getName());  
59 - gps.setStationNo(s.getSerialNo()); 58 + gps.setStationInfo(s);
60 59
61 //起点站站内的信号,不发布 60 //起点站站内的信号,不发布
62 if ("B".equals(s.getMark())) 61 if ("B".equals(s.getMark()))
63 gps.setRelease(false); 62 gps.setRelease(false);
64 63
65 - } else if (null != prev && gps.getInOut() == 0) {  
66 - gps.setStationCode(prev.getStationCode());  
67 - gps.setStationName(prev.getStationName());  
68 - gps.setStationNo(prev.getStationNo()); 64 + } else if (gps.getInOut() == 0) {
  65 + if (null != prev)
  66 + gps.setStationInfo(prev);
  67 + else {
  68 + //第一个站外点,按路段匹配一下所在站点
  69 + s = searchStationByRoad(gps);
  70 + if (null != s)
  71 + gps.setStationInfo(s);
  72 + }
69 } 73 }
70 74
71 if (null == prev || null == prev.getStationCode()) 75 if (null == prev || null == prev.getStationCode())
@@ -95,6 +99,40 @@ public class InOutStationProcess { @@ -95,6 +99,40 @@ public class InOutStationProcess {
95 outStation(gps); 99 outStation(gps);
96 } 100 }
97 101
  102 + private StationRoute searchStationByRoad(GpsEntity gps) {
  103 + List<StationRoute> srs = GeoCacheData.find(gps.getLineId(), gps.getUpDown());
  104 +
  105 + StationRoute rs = null;
  106 + Point p = gps.getPoint();
  107 + List<Point> ps;
  108 + double distance, min = -1, m2 = -1;
  109 + for (StationRoute s : srs) {
  110 + ps = s.getPaths();
  111 + if (null == ps)
  112 + continue;
  113 +
  114 + for (int i = 1, size = ps.size(); i < size; i++) {
  115 + distance = GeoUtils.getDistanceFromLine(p, ps.get(i - 1), ps.get(i));
  116 +
  117 + if (Double.isNaN(distance))
  118 + continue;
  119 +
  120 + if (min == -1 || distance < min)
  121 + min = distance;
  122 + }
  123 +
  124 + if (m2 == -1 || min < m2) {
  125 + m2 = min;
  126 + rs = s;
  127 + }
  128 +
  129 + if (m2 < 2)
  130 + break;
  131 + }
  132 +
  133 + return m2 > 0 && m2 < 30 ? rs : null;
  134 + }
  135 +
98 private void inStation(GpsEntity gps, GpsEntity prev) { 136 private void inStation(GpsEntity gps, GpsEntity prev) {
99 StationRoute s; 137 StationRoute s;
100 /** 138 /**
src/main/java/com/bsth/data/gps/process/chains/SectionProcess.java
@@ -25,7 +25,7 @@ public class SectionProcess { @@ -25,7 +25,7 @@ public class SectionProcess {
25 static DecimalFormat df = new DecimalFormat("#.00"); 25 static DecimalFormat df = new DecimalFormat("#.00");
26 26
27 public void process(GpsEntity gps) { 27 public void process(GpsEntity gps) {
28 - /*if (gps.getDeviceId().equals("226L4179")) 28 + /*if (gps.getDeviceId().equals("22S0N007"))
29 System.out.println("aaa");*/ 29 System.out.println("aaa");*/
30 30
31 ScheduleRealInfo sch = gps.getSch(); 31 ScheduleRealInfo sch = gps.getSch();
@@ -36,7 +36,7 @@ public class SectionProcess { @@ -36,7 +36,7 @@ public class SectionProcess {
36 if (gps.getInOut() == 0) 36 if (gps.getInOut() == 0)
37 calcOverstep(gps); 37 calcOverstep(gps);
38 38
39 - List<Point> ps; 39 + List<Point> ps, paths2;
40 //计算到下一站的距离 40 //计算到下一站的距离
41 StationRoute s = GeoCacheData.findByCode(gps); 41 StationRoute s = GeoCacheData.findByCode(gps);
42 if (null != s && !"E".equals(s.getMark())) { 42 if (null != s && !"E".equals(s.getMark())) {
@@ -44,12 +44,15 @@ public class SectionProcess { @@ -44,12 +44,15 @@ public class SectionProcess {
44 if (null == paths) 44 if (null == paths)
45 return; 45 return;
46 46
47 - IntersePoint intersePoint = GeoUtils.pointToLineNearPoint(gps.getPoint(), paths); 47 + IntersePoint intersect = GeoUtils.pointToLineNearPoint(gps.getPoint(), paths);
  48 +
  49 + if (null != intersect
  50 + && intersect.getIndex() < paths.size()) {
48 51
49 - if (null != intersePoint  
50 - && intersePoint.getIndex() < paths.size()) { 52 + paths2 = new ArrayList<>(paths);
  53 + paths2.add(intersect.getIndex(), intersect.getPoint());
51 54
52 - ps = subList(paths, intersePoint.getIndex() + 1, paths.size()); 55 + ps = subList(paths2, intersect.getIndex(), paths2.size());
53 gps.setDistance(GeoUtils.getDistance(ps)); 56 gps.setDistance(GeoUtils.getDistance(ps));
54 } 57 }
55 } 58 }
@@ -109,8 +112,13 @@ public class SectionProcess { @@ -109,8 +112,13 @@ public class SectionProcess {
109 if (min == -1 || distance < min) { 112 if (min == -1 || distance < min) {
110 min = distance; 113 min = distance;
111 near = sr; 114 near = sr;
  115 +
  116 + if(min == 0)
  117 + break;
112 } 118 }
113 } 119 }
  120 + if(min == 0)
  121 + break;
114 } 122 }
115 gps.setOverstepDistance(Double.parseDouble(df.format(min))); 123 gps.setOverstepDistance(Double.parseDouble(df.format(min)));
116 124
src/main/java/com/bsth/data/history/HistoryConsumeTimeDataHandler.java
@@ -76,7 +76,7 @@ public class HistoryConsumeTimeDataHandler { @@ -76,7 +76,7 @@ public class HistoryConsumeTimeDataHandler {
76 76
77 private static DateTimeFormatter fmtHHmmss = DateTimeFormat.forPattern("HHmmss"); 77 private static DateTimeFormatter fmtHHmmss = DateTimeFormat.forPattern("HHmmss");
78 78
79 - public static Map<String, Integer> forecastEnd(List<GpsEntity> list) { 79 + public static Map<String, Integer> forecastEnd(List<GpsEntity> list, String eCode) {
80 80
81 int v = Integer.parseInt(fmtHHmmss.print(System.currentTimeMillis())); 81 int v = Integer.parseInt(fmtHHmmss.print(System.currentTimeMillis()));
82 int peakVal = 1; 82 int peakVal = 1;
@@ -88,15 +88,15 @@ public class HistoryConsumeTimeDataHandler { @@ -88,15 +88,15 @@ public class HistoryConsumeTimeDataHandler {
88 Map<String, Integer> rs = new HashMap<>(); 88 Map<String, Integer> rs = new HashMap<>();
89 89
90 for (GpsEntity gps : list) { 90 for (GpsEntity gps : list) {
91 - rs.put(gps.getDeviceId(), forecastEnd(gps, peakVal)); 91 + rs.put(gps.getDeviceId(), forecastEnd(gps, peakVal, eCode));
92 } 92 }
93 93
94 return rs; 94 return rs;
95 } 95 }
96 96
97 - private static Integer forecastEnd(GpsEntity gps, int peakVal) { 97 + private static Integer forecastEnd(GpsEntity gps, int peakVal, String eCode) {
98 int sum = 0; 98 int sum = 0;
99 - Integer[] ns = findConsumeArray(gps, peakVal); 99 + Integer[] ns = findConsumeArray(gps, peakVal, eCode);
100 100
101 if (null == ns) 101 if (null == ns)
102 return 0; 102 return 0;
@@ -129,14 +129,15 @@ public class HistoryConsumeTimeDataHandler { @@ -129,14 +129,15 @@ public class HistoryConsumeTimeDataHandler {
129 return lctMaps.get(lineCode + "_" + upDown); 129 return lctMaps.get(lineCode + "_" + upDown);
130 } 130 }
131 131
132 - public static Integer[] findConsumeArray(GpsEntity gps, int peakVal) {  
133 - String sCode = gps.getStationCode()  
134 - , eCode = null;  
135 - if (null != gps.getSch())  
136 - eCode = gps.getSch().getZdzCode();  
137 - else {  
138 - List<StationRoute> srs = GeoCacheData.find(gps.getLineId(), gps.getUpDown());  
139 - eCode = srs.get(srs.size() - 1).getStationCode(); 132 + public static Integer[] findConsumeArray(GpsEntity gps, int peakVal, String eCode) {
  133 + String sCode = gps.getStationCode();
  134 + if (null == eCode) {
  135 + if (null != gps.getSch())
  136 + eCode = gps.getSch().getZdzCode();
  137 + else {
  138 + List<StationRoute> srs = GeoCacheData.find(gps.getLineId(), gps.getUpDown());
  139 + eCode = srs.get(srs.size() - 1).getStationCode();
  140 + }
140 } 141 }
141 return findConsumeArray(gps.getLineId(), gps.getUpDown(), sCode, eCode, peakVal); 142 return findConsumeArray(gps.getLineId(), gps.getUpDown(), sCode, eCode, peakVal);
142 } 143 }
src/main/java/com/bsth/entity/GpsEntity.java
@@ -50,6 +50,10 @@ public class GpsEntity implements Serializable { @@ -50,6 +50,10 @@ public class GpsEntity implements Serializable {
50 private String stationCode; 50 private String stationCode;
51 private String stationName; 51 private String stationName;
52 private int stationNo; 52 private int stationNo;
  53 + /**
  54 + * 当前站点站距信息
  55 + */
  56 + private double stopDis;
53 57
54 /** 58 /**
55 * 0: 站外 1: 站内 2:场内 59 * 0: 站外 1: 站内 2:场内
@@ -139,6 +143,20 @@ public class GpsEntity implements Serializable { @@ -139,6 +143,20 @@ public class GpsEntity implements Serializable {
139 return gps; 143 return gps;
140 } 144 }
141 145
  146 + public void setStationInfo(StationRoute s){
  147 + this.stationCode = s.getStationCode();
  148 + this.stationName = s.getName();
  149 + this.stationNo = s.getSerialNo();
  150 + this.stopDis = s.getLength();
  151 + }
  152 +
  153 + public void setStationInfo(GpsEntity prev){
  154 + this.stationCode = prev.stationCode;
  155 + this.stationName = prev.stationName;
  156 + this.stationNo = prev.stationNo;
  157 + this.stopDis = prev.stopDis;
  158 + }
  159 +
142 public Point getPoint(){ 160 public Point getPoint(){
143 return new Point(lon, lat); 161 return new Point(lon, lat);
144 } 162 }
@@ -350,4 +368,12 @@ public class GpsEntity implements Serializable { @@ -350,4 +368,12 @@ public class GpsEntity implements Serializable {
350 public void setRelease(boolean release) { 368 public void setRelease(boolean release) {
351 this.release = release; 369 this.release = release;
352 } 370 }
  371 +
  372 + public double getStopDis() {
  373 + return stopDis;
  374 + }
  375 +
  376 + public void setStopDis(double stopDis) {
  377 + this.stopDis = stopDis;
  378 + }
353 } 379 }
src/main/java/com/bsth/entity/Line.java
@@ -27,6 +27,19 @@ public class Line { @@ -27,6 +27,19 @@ public class Line {
27 /** 终点站名称 */ 27 /** 终点站名称 */
28 private String endStationName; 28 private String endStationName;
29 29
  30 + /** 起始站首班车时间 */
  31 + private String startStationFirstTime;
  32 +
  33 + /** 起始站末班车时间 */
  34 + private String startStationEndTime;
  35 +
  36 + /** 终点站首班时间 */
  37 + private String endStationFirstTime;
  38 +
  39 + /** 终点站末班时间 */
  40 + private String endStationEndTime;
  41 +
  42 +
30 public String getLineCode() { 43 public String getLineCode() {
31 return lineCode; 44 return lineCode;
32 } 45 }
@@ -74,4 +87,36 @@ public class Line { @@ -74,4 +87,36 @@ public class Line {
74 public void setCamelChars(String camelChars) { 87 public void setCamelChars(String camelChars) {
75 this.camelChars = camelChars; 88 this.camelChars = camelChars;
76 } 89 }
  90 +
  91 + public String getStartStationFirstTime() {
  92 + return startStationFirstTime;
  93 + }
  94 +
  95 + public void setStartStationFirstTime(String startStationFirstTime) {
  96 + this.startStationFirstTime = startStationFirstTime;
  97 + }
  98 +
  99 + public String getStartStationEndTime() {
  100 + return startStationEndTime;
  101 + }
  102 +
  103 + public void setStartStationEndTime(String startStationEndTime) {
  104 + this.startStationEndTime = startStationEndTime;
  105 + }
  106 +
  107 + public String getEndStationFirstTime() {
  108 + return endStationFirstTime;
  109 + }
  110 +
  111 + public void setEndStationFirstTime(String endStationFirstTime) {
  112 + this.endStationFirstTime = endStationFirstTime;
  113 + }
  114 +
  115 + public String getEndStationEndTime() {
  116 + return endStationEndTime;
  117 + }
  118 +
  119 + public void setEndStationEndTime(String endStationEndTime) {
  120 + this.endStationEndTime = endStationEndTime;
  121 + }
77 } 122 }
src/main/java/com/bsth/entity/StationRoute.java
@@ -176,6 +176,8 @@ public class StationRoute { @@ -176,6 +176,8 @@ public class StationRoute {
176 } 176 }
177 177
178 public void setPaths(CopyOnWriteArrayList<Point> paths) { 178 public void setPaths(CopyOnWriteArrayList<Point> paths) {
  179 + if (null == paths)
  180 + return;
179 this.paths = paths; 181 this.paths = paths;
180 182
181 if (paths.size() > 1) { 183 if (paths.size() > 1) {
src/main/resources/logback.xml
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 <configuration> 3 <configuration>
4 4
5 <!-- <property resource="application.properties" /> --> 5 <!-- <property resource="application.properties" /> -->
6 - <property name="LOG_BASE" value="G:/bus_info_publish" /> 6 + <property name="LOG_BASE" value="E:/bus_info_publish" />
7 <!-- 控制台输出 --> 7 <!-- 控制台输出 -->
8 <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> 8 <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
9 9
src/main/resources/static/index.html
@@ -60,9 +60,9 @@ @@ -60,9 +60,9 @@
60 </a> 60 </a>
61 </li> 61 </li>
62 <li class="nav-item "> 62 <li class="nav-item ">
63 - <a class="nav-link" href="../examples/icons.html"> 63 + <a class="nav-link" href="/pages/interface_test/iTest.html">
64 <i class="material-icons">info</i> 64 <i class="material-icons">info</i>
65 - <p>负载情况</p> 65 + <p>信息发布接口测试</p>
66 </a> 66 </a>
67 </li> 67 </li>
68 <li class="nav-item "> 68 <li class="nav-item ">
@@ -152,7 +152,7 @@ @@ -152,7 +152,7 @@
152 $('.left_menus ul>li.nav-item.active').removeClass('active'); 152 $('.left_menus ul>li.nav-item.active').removeClass('active');
153 $(this).parents('li.nav-item').addClass('active'); 153 $(this).parents('li.nav-item').addClass('active');
154 return false; 154 return false;
155 - }).eq(3).trigger('click'); 155 + }).eq(5).trigger('click');
156 156
157 157
158 $('body').bootstrapMaterialDesign(); 158 $('body').bootstrapMaterialDesign();
src/main/resources/static/pages/interface_test/iTest.html 0 → 100644
  1 +<style>
  2 +
  3 + #interface_test_page .result_wrap {
  4 + height: calc(100% - 70px);
  5 + margin-top: 25px;
  6 + }
  7 +
  8 + #interface_test_page .col-md-2 {
  9 + padding: 0;
  10 + }
  11 +
  12 + #interface_test_page .col-md-2:first-child {
  13 + padding-left: 15px;
  14 + }
  15 +</style>
  16 +<div class="container-fluid page" id="interface_test_page">
  17 + <div class="card">
  18 +
  19 + <div class="card-body" style="height: 100%">
  20 + <div class="top_form_card" style="width: 100%;">
  21 + <form>
  22 + <div class="row">
  23 + <div class="col-md-2">
  24 + <div class="form-group">
  25 + <label class="bmd-label-floating">接口名称</label>
  26 + <select class="form-control" name="interfaceName">
  27 + <option>getLineInfoByName</option>
  28 + <option>getLine</option>
  29 + <option selected>carMonitor</option>
  30 + <option>getdispatchScreen</option>
  31 + </select>
  32 + </div>
  33 + </div>
  34 + <div class="col-md-2 field" style="margin-top: 5px;">
  35 + <div class="form-group">
  36 + <label class="bmd-label-floating">线路</label>
  37 + <div class="ct_auto_wrap line_autocompleter">
  38 + <input type="text" name="lineName" required class="form-control" autocomplete="off">
  39 + </div>
  40 + </div>
  41 + </div>
  42 +
  43 + <div class="col-md-2 field">
  44 + <div class="form-group">
  45 + <label class="bmd-label-floating">走向</label>
  46 + <select class="form-control" name="direction">
  47 + <option value=0>上行</option>
  48 + <option value=1>下行</option>
  49 + </select>
  50 + </div>
  51 + </div>
  52 +
  53 + <div class="col-md-2 field">
  54 + <div class="form-group">
  55 + <label class="bmd-label-floating">站点</label>
  56 + <select class="form-control" name="stopid"></select>
  57 + </div>
  58 + </div>
  59 +
  60 + <div class="col-md-2 field" style="margin-top: 5px;">
  61 + <div class="form-group">
  62 + <label class="bmd-label-floating">时间(t)</label>
  63 + <input type="text" name="t" class="form-control" value="2018-06-25 12:10">
  64 + </div>
  65 + </div>
  66 + <div class="col-md-1">
  67 + <div class="form-group">
  68 + <button type="submit" class="btn btn-primary btn-raised" style="margin-top: 22px;">
  69 + <i class="material-icons">search</i> 请求接口
  70 + </button>
  71 + </div>
  72 + </div>
  73 + </div>
  74 + </form>
  75 + </div>
  76 +
  77 + <div class="result_wrap">
  78 + <div class="form-group">
  79 + <label for="get_url_text" class="bmd-label-floating">GET</label>
  80 + <textarea class="form-control" id="get_url_text" rows="1" spellcheck="false"></textarea>
  81 + </div>
  82 + <br>
  83 + <div class="form-group" style="height: calc(100% - 120px)">
  84 + <label for="result_text" class="bmd-label-floating">RESULT</label>
  85 + <textarea class="form-control" id="result_text" style="height: 100% !important;" spellcheck="false"></textarea>
  86 + </div>
  87 + </div>
  88 + </div>
  89 + </div>
  90 +</div>
  91 +
  92 +
  93 +<script>
  94 + (function () {
  95 + var wrap = '#interface_test_page';
  96 +
  97 + //切换接口
  98 + $('[name=interfaceName]', wrap).on('change', show_fields);
  99 +
  100 + //线路自动补全
  101 + $.get('/basic/lines', function (rs) {
  102 + var data = [], item;
  103 + for (var i = 0, len = rs.length; i < len; i++) {
  104 + item = rs[i];
  105 + data.push({
  106 + code: item.lineCode,
  107 + text: item.name,
  108 + others: [item.fullChars, item.camelChars]
  109 + });
  110 + }
  111 + gb_ct_autocompleter.build($('.line_autocompleter', wrap), data);
  112 + });
  113 +
  114 + //线路选择事件
  115 + $('.line_autocompleter input', wrap).on('auto_change', fullStations);
  116 + $('select[name=direction]', wrap).on('change', fullStations);
  117 +
  118 + function fullStations() {
  119 + var $stopSelect = $('select[name=stopid]', wrap);
  120 + /*if(!$stopSelect.is(':visible'))
  121 + return;*/
  122 +
  123 + //填充站点下拉框
  124 + var lineCode = $('input[name=lineName]', wrap).data('val')
  125 + , upDown = $('select[name=direction]', wrap).val();
  126 +
  127 + $.get('/geo_data/stations/' + lineCode + '/' + upDown, function (rs) {
  128 + console.log('stations', rs);
  129 + var array = rs.stations;
  130 +
  131 + var opts = '<option value="">请选择...</option>';
  132 + for (var i = 0, len = array.length; i < len; i++) {
  133 + opts += '<option value="' + array[i].stationCode + '">' + array[i].name + '</option>';
  134 + }
  135 +
  136 + $stopSelect.html(opts);
  137 + });
  138 + }
  139 +
  140 + function show_fields() {
  141 + var v = $(this).val()
  142 + , ns;
  143 +
  144 + if (v == 'getLineInfoByName' || v == 'getLine')
  145 + ns = ['lineName', 't'];
  146 + else if (v == 'carMonitor')
  147 + ns = ['lineName', 'stopid', 'direction', 't'];
  148 + else if (v == 'getdispatchScreen')
  149 + ns = ['lineName', 'direction', 't'];
  150 +
  151 + $('form .row>div.field', wrap).hide();
  152 +
  153 + $('form .form-group [name]', wrap).each(function () {
  154 + if (ns.indexOf($(this).attr('name')) != -1)
  155 + $(this).parents('.field').show();
  156 + });
  157 + }
  158 +
  159 + $('form', wrap).on('submit', function () {
  160 + try {
  161 + var params = '';
  162 + var data = $(this).serializeJSON();
  163 + var lineCode = $('input[name=lineName]', wrap).data('val');
  164 + var v = data.interfaceName;
  165 +
  166 + if (v == 'getLineInfoByName')
  167 + params = '?linename=' + data.lineName;
  168 + else if (v == 'getLine')
  169 + params = '?lineid=' + lineCode;
  170 +
  171 + else if (v == 'carMonitor')
  172 + params = '?lineid=' + lineCode + '&stopid=' + data.stopid + '&direction=' + data.direction;
  173 + else if (v == 'getdispatchScreen')
  174 + params = '?lineid=' + lineCode + '&direction=' + data.direction;
  175 +
  176 + params += '&t=' + data.t;
  177 +
  178 + var url = '/xxfb/' + v + params
  179 + , fullUrl = window.location.href + 'xxfb/' + v + params;
  180 +
  181 + $('#get_url_text').text(fullUrl);
  182 +
  183 + $.ajax({
  184 + url: url,
  185 + dataType: 'text',
  186 + success: function (data) {
  187 + $('#result_text').text(formatXml(data));
  188 + }
  189 + });
  190 + } catch (e) {
  191 + console.log(e);
  192 + }
  193 +
  194 + return false;
  195 + });
  196 +
  197 + function formatXml(xml) {
  198 + var formatted = '';
  199 + var reg = /(>)(<)(\/*)/g;
  200 + xml = xml.replace(reg, '$1\r\n$2$3');
  201 + var pad = 0;
  202 + jQuery.each(xml.split('\r\n'), function(index, node) {
  203 + var indent = 0;
  204 + if (node.match( /.+<\/\w[^>]*>$/ )) {
  205 + indent = 0;
  206 + } else if (node.match( /^<\/\w/ )) {
  207 + if (pad != 0) {
  208 + pad -= 1;
  209 + }
  210 + } else if (node.match( /^<\w[^>]*[^\/]>.*$/ )) {
  211 + indent = 1;
  212 + } else {
  213 + indent = 0;
  214 + }
  215 +
  216 + var padding = '';
  217 + for (var i = 0; i < pad; i++) {
  218 + padding += ' ';
  219 + }
  220 +
  221 + formatted += padding + node + '\r\n';
  222 + pad += indent;
  223 + });
  224 +
  225 + return formatted;
  226 + }
  227 + })();
  228 +</script>
0 \ No newline at end of file 229 \ No newline at end of file
src/main/resources/static/pages/real/js/map.js
@@ -79,7 +79,7 @@ var gb_real_gps_map = (function () { @@ -79,7 +79,7 @@ var gb_real_gps_map = (function () {
79 obj.bd_lon = coord.lng; 79 obj.bd_lon = coord.lng;
80 } 80 }
81 81
82 - var gps_marker_arr = [], topMarker; 82 + var gps_marker_arr = {}, topMarker;
83 var renderGps = function (arr) { 83 var renderGps = function (arr) {
84 var gps, m, w; 84 var gps, m, w;
85 for (var i = 0, len = arr.length; i < len; i++) { 85 for (var i = 0, len = arr.length; i < len; i++) {
@@ -219,9 +219,23 @@ var gb_real_gps_map = (function () { @@ -219,9 +219,23 @@ var gb_real_gps_map = (function () {
219 this.closePath(); 219 this.closePath();
220 return this; 220 return this;
221 }; 221 };
  222 +
  223 +
  224 + /**
  225 + * 定位到gps
  226 + * @param device
  227 + */
  228 + var focus = function (device) {
  229 + var m = gps_marker_arr[device];
  230 + if(m){
  231 + map.setCenter(m.getPosition());
  232 + bdOpenWindow(m);
  233 + }
  234 + }
222 return { 235 return {
223 init: init, 236 init: init,
224 drawLine: drawLine, 237 drawLine: drawLine,
225 - renderGps: renderGps 238 + renderGps: renderGps,
  239 + focus: focus
226 } 240 }
227 })(); 241 })();
228 \ No newline at end of file 242 \ No newline at end of file
src/main/resources/static/pages/real/main.html
@@ -133,8 +133,6 @@ @@ -133,8 +133,6 @@
133 未知站点 133 未知站点
134 {{/if}} 134 {{/if}}
135 </h5> 135 </h5>
136 - <p>设备状态:...  
137 - </p>  
138 <p>设备号:{{deviceId}}</p> 136 <p>设备号:{{deviceId}}</p>
139 <p>速度:{{speed}}</p> 137 <p>速度:{{speed}}</p>
140 <p>经度:{{lon}}</p> 138 <p>经度:{{lon}}</p>
@@ -245,11 +243,15 @@ @@ -245,11 +243,15 @@
245 rect.addClass('twinkle').one(animationEnd, function () { 243 rect.addClass('twinkle').one(animationEnd, function () {
246 $(this).removeClass('twinkle'); 244 $(this).removeClass('twinkle');
247 }); 245 });
248 - /*console.log('d3.select(rect[0])', d3.select(rect[0]));  
249 - d3.select(rect[0])  
250 - .transition()  
251 - .duration(1000)  
252 - .style('fill', 'green');*/ 246 + });
  247 +
  248 + /**
  249 + * 点击rect
  250 + */
  251 + $('.svg_charts svg').on('click', 'g.gps-wrap>rect', function () {
  252 + var device = $(this).attr('_id').split('_')[1];
  253 +
  254 + gb_real_gps_map.focus(device);
253 }); 255 });
254 })(); 256 })();
255 </script> 257 </script>
256 \ No newline at end of file 258 \ No newline at end of file