Commit 45edec6e894a8841bddfa5cbd143abeb7e60b6cc

Authored by 潘钊
1 parent caaf2960

update...

src/main/java/com/bsth/controller/realcontrol/RealMapController.java
... ... @@ -45,8 +45,8 @@ public class RealMapController {
45 45 * @Description: TODO(获取线路的站点,路段路由)
46 46 */
47 47 @RequestMapping(value = "/findRouteByLine")
48   - public Map<String, Object> findRouteByLine(@RequestParam String lineCode) {
49   - return realMapService.findRouteByLine(lineCode);
  48 + public Map<String, Object> findRouteByLine(@RequestParam String idx) {
  49 + return realMapService.findRouteByLine(idx);
50 50 }
51 51  
52 52 @RequestMapping(value = "/multiRouteByLine")
... ...
src/main/java/com/bsth/security/WebSecurityConfig.java
... ... @@ -36,7 +36,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
36 36 public void configure(WebSecurity web) throws Exception {
37 37 // 白名单
38 38 web.ignoring().antMatchers(Constants.LOGIN_PAGE, Constants.LOGIN, Constants.ASSETS_URL, Constants.FAVICON_URL, Constants.CAPTCHA,
39   - Constants.SERVICE_INTERFACE, Constants.METRONIC_URL, Constants.LOGIN_FAILURE, Constants.UPSTREAM_URL, Constants.XD_CHILD_PAGES, Constants.XD_REAL_GPS);
  39 + Constants.SERVICE_INTERFACE, Constants.METRONIC_URL, Constants.LOGIN_FAILURE, Constants.UPSTREAM_URL, Constants.XD_CHILD_PAGES);
40 40 }
41 41  
42 42 @Override
... ...
src/main/java/com/bsth/security/filter/LoginInterceptor.java
... ... @@ -3,10 +3,11 @@ package com.bsth.security.filter;
3 3 import com.alibaba.fastjson.JSON;
4 4 import com.bsth.common.Constants;
5 5 import com.bsth.common.ResponseCode;
6   -import com.bsth.filter.BaseFilter;
7 6 import com.bsth.util.RequestUtils;
8 7 import org.springframework.security.core.Authentication;
9 8 import org.springframework.security.core.context.SecurityContextHolder;
  9 +import org.springframework.util.AntPathMatcher;
  10 +import org.springframework.util.PathMatcher;
10 11  
11 12 import javax.servlet.*;
12 13 import javax.servlet.http.HttpServletRequest;
... ... @@ -23,40 +24,67 @@ import java.util.Map;
23 24 * @date 2016年3月24日 上午11:49:20
24 25 *
25 26 */
26   -public class LoginInterceptor extends BaseFilter {
  27 +public class LoginInterceptor implements Filter {
  28 +
  29 + private final PathMatcher pathMatcher = new AntPathMatcher();
  30 +
  31 + /**
  32 + * 白名单
  33 + * 相比于 BaseFilter,此处对线调GPS请求进行了拦截验证
  34 + */
  35 + private String[] whiteListURLs = { Constants.LOGIN_PAGE,Constants.CAPTCHA, Constants.SERVICE_INTERFACE,
  36 + Constants.ASSETS_URL, Constants.FAVICON_URL, Constants.METRONIC_URL, Constants.LOGIN, Constants.LOGIN_FAILURE, Constants.UPSTREAM_URL, Constants.XD_CHILD_PAGES };
  37 +
27 38  
28 39 @Override
29 40 public void destroy() {
30 41  
31 42 }
32 43  
  44 +
33 45 @Override
34 46 public void init(FilterConfig filterConfig) throws ServletException {
35 47  
36 48 }
37 49  
38 50 @Override
39   - public void doFilter(HttpServletRequest request,
40   - HttpServletResponse response, FilterChain chain)
41   - throws IOException, ServletException {
42   - Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
43   -
44   - if(null == authentication){
45   - //没有登录
46   -
47   - if(RequestUtils.isAjaxRequest(request)){
48   - Map<String, Object> map = new HashMap<>();
49   - map.put("status",
50   - ResponseCode.NO_AUTHENTICATION);
51   - response.getWriter().print(JSON.toJSONString(map));
52   - }
53   - else
54   - response.sendRedirect(Constants.LOGIN_PAGE);
  51 + public void doFilter(ServletRequest request, ServletResponse response,
  52 + FilterChain chain) throws IOException, ServletException {
  53 +
  54 + HttpServletRequest httpRequest = (HttpServletRequest) request;
  55 + HttpServletResponse httpResponse = (HttpServletResponse) response;
  56 +
  57 + String currentURL = httpRequest.getServletPath();
  58 +
  59 + if (!isWhiteURL(currentURL)) {
  60 + Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
55 61  
56   - return;
  62 + if(null == authentication){
  63 + //没有登录
  64 +
  65 + if(RequestUtils.isAjaxRequest(httpRequest)){
  66 + Map<String, Object> map = new HashMap<>();
  67 + map.put("status",
  68 + ResponseCode.NO_AUTHENTICATION);
  69 + response.getWriter().print(JSON.toJSONString(map));
  70 + }
  71 + else
  72 + httpResponse.sendRedirect(Constants.LOGIN_PAGE);
  73 +
  74 + return;
  75 + }
57 76 }
58 77  
59 78 chain.doFilter(request, response);
60 79 }
61 80  
  81 + private boolean isWhiteURL(String currentURL) {
  82 + for (String whiteURL : whiteListURLs) {
  83 + if (pathMatcher.match(whiteURL, currentURL)) {
  84 + return true;
  85 + }
  86 + }
  87 + return false;
  88 + }
  89 +
62 90 }
... ...
src/main/java/com/bsth/service/realcontrol/RealMapService.java
... ... @@ -10,7 +10,7 @@ public interface RealMapService {
10 10  
11 11 Map<String,Object> carParkSpatialData();
12 12  
13   - Map<String,Object> findRouteByLine(String lineCode);
  13 + Map<String, Object> findRouteByLine(String idx);
14 14  
15 15 Map<String,Object> findRouteAndStationByLine(String lineCode);
16 16  
... ...
src/main/java/com/bsth/service/realcontrol/impl/RealMapServiceImpl.java
... ... @@ -2,11 +2,14 @@ package com.bsth.service.realcontrol.impl;
2 2  
3 3 import com.bsth.common.ResponseCode;
4 4 import com.bsth.controller.realcontrol.dto.StationSpatialData;
  5 +import com.bsth.data.gpsdata.arrival.utils.GeoUtils;
5 6 import com.bsth.entity.CarPark;
6 7 import com.bsth.service.realcontrol.RealMapService;
7 8 import com.bsth.service.realcontrol.dto.SectionRouteCoords;
8 9 import com.bsth.util.TransGPS;
9 10 import com.google.common.base.Splitter;
  11 +import com.google.common.collect.ArrayListMultimap;
  12 +import com.vividsolutions.jts.geom.*;
10 13 import org.slf4j.Logger;
11 14 import org.slf4j.LoggerFactory;
12 15 import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -74,10 +77,17 @@ public class RealMapServiceImpl implements RealMapService {
74 77 }
75 78  
76 79 @Override
77   - public Map<String, Object> findRouteByLine(String lineCode) {
  80 + public Map<String, Object> findRouteByLine(String idx) {
78 81 Map<String, Object> rs = new HashMap<>();
79   - String sql = "SELECT r.ID,r.LINE_CODE,r.SECTION_CODE,r.SECTIONROUTE_CODE,r.DIRECTIONS,s.SECTION_NAME,ST_AsText(s.GSECTION_VECTOR) GSECTION_VECTOR,s.SECTION_DISTANCE,s.SECTION_TIME FROM bsth_c_sectionroute r INNER JOIN bsth_c_section s on r.section_code=s.section_code WHERE r.line_code=? and r.destroy=0 order by sectionroute_code";
80   - List<SectionRouteCoords> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper(SectionRouteCoords.class), lineCode);
  82 + StringBuilder inCond = new StringBuilder("(");
  83 + List<String> codeList = Splitter.on(",").splitToList(idx);
  84 + for(String lineCode : codeList){
  85 + inCond.append("'" + lineCode + "',");
  86 + }
  87 + inCond.deleteCharAt(inCond.length() - 1).append(")");
  88 +
  89 + String sql = "SELECT r.ID,r.LINE_CODE,r.SECTION_CODE,r.SECTIONROUTE_CODE,r.DIRECTIONS,s.SECTION_NAME,ST_AsText(s.GSECTION_VECTOR) GSECTION_VECTOR,s.SECTION_DISTANCE,s.SECTION_TIME FROM bsth_c_sectionroute r INNER JOIN bsth_c_section s on r.section_code=s.section_code WHERE r.line_code in "+inCond.toString()+" and r.destroy=0 order by sectionroute_code";
  90 + List<SectionRouteCoords> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper(SectionRouteCoords.class));
81 91  
82 92 //排序
83 93 Collections.sort(list, new Comparator<SectionRouteCoords>() {
... ... @@ -87,28 +97,40 @@ public class RealMapServiceImpl implements RealMapService {
87 97 }
88 98 });
89 99  
90   - List<String> upList = new ArrayList<>(),
91   - downList = new ArrayList<>();
92   -
93   - String vectorStr = "";
  100 + ArrayListMultimap<String, SectionRouteCoords> listMultimap = ArrayListMultimap.create();
94 101 for (SectionRouteCoords sr : list) {
95   - vectorStr = sr.getGsectionVector();
96   - vectorStr = vectorStr.substring(11, vectorStr.length() - 2);
97   -
98   - if (sr.getDirections() == 0)
99   - upList.add(vectorStr);
100   - else
101   - downList.add(vectorStr);
  102 + //按lineCode 分组
  103 + listMultimap.put(sr.getLineCode(), sr);
  104 + }
  105 + //坐标转换
  106 + Map<String, Object> subMap;
  107 + Set<String> ks = listMultimap.keySet();
  108 + List<SectionRouteCoords> sublist;
  109 + List<String> upList,downList;
  110 + String vectorStr = "";
  111 + for(String k : ks){
  112 + subMap = new HashMap<>();
  113 + sublist = listMultimap.get(k);
  114 + upList = new ArrayList<>();
  115 + downList = new ArrayList<>();
  116 + for(SectionRouteCoords sr : sublist){
  117 + vectorStr = sr.getGsectionVector();
  118 + vectorStr = vectorStr.substring(11, vectorStr.length() - 2);
  119 + if (sr.getDirections() == 0)
  120 + upList.add(vectorStr);
  121 + else
  122 + downList.add(vectorStr);
  123 + }
  124 + subMap.put("up", upList);
  125 + //subMap.put("upJoins", jointCoords(upList));
  126 + subMap.put("down", downList);
  127 + subMap.put("up_bd", multiWgsToBd(upList));
  128 + subMap.put("down_bd", multiWgsToBd(downList));
  129 + subMap.put("up_gcj", multiWgsToGcj(upList));
  130 + subMap.put("down_gcj", multiWgsToGcj(downList));
  131 +
  132 + rs.put(k, subMap);
102 133 }
103   -
104   - rs.put("up", upList);
105   - rs.put("down", downList);
106   - rs.put("up_bd", multiWgsToBd(upList));
107   - rs.put("down_bd", multiWgsToBd(downList));
108   - rs.put("up_gcj", multiWgsToGcj(upList));
109   - rs.put("down_gcj", multiWgsToGcj(downList));
110   -
111   - rs.put("lineId", lineCode);
112 134 return rs;
113 135 }
114 136  
... ... @@ -227,4 +249,115 @@ public class RealMapServiceImpl implements RealMapService {
227 249 }
228 250 return gcjList;
229 251 }
  252 +
  253 + /**
  254 + * 将相连的路段拼接起来,去掉接口覆盖区域。
  255 + * 主要因为前端地图绘制时,过多的路段会带来性能消耗。在这里提前拼接好以减少路段数量
  256 + * @param list
  257 + * @return
  258 + */
  259 + private List<String> jointCoords(List<String> list){
  260 + List<String> rs = new ArrayList<>();
  261 + int len = list.size();
  262 + if(len == 0)
  263 + return rs;
  264 +
  265 + StringBuilder joinstr = new StringBuilder(list.get(0));
  266 + String str;
  267 + for(int i = 1; i < len; i ++){
  268 + str = jointCoords(joinstr.toString(), list.get(i));
  269 + if(str != null)
  270 + joinstr.append("," + str);
  271 + else{
  272 + rs.add(joinstr.toString());
  273 + joinstr = new StringBuilder(list.get(i));
  274 + }
  275 + }
  276 + rs.add(joinstr.toString());
  277 + return rs;
  278 + }
  279 +
  280 + static GeometryFactory geometryFactory = new GeometryFactory();
  281 + private String jointCoords(String c1, String c2){
  282 + String rs=null;
  283 + LineString s1 = createLineString(c1);
  284 + LineString s2 = createLineString(c2);
  285 +
  286 + if(s1.intersects(s2)){
  287 + Geometry g = s1.intersection(s2);
  288 + Point inPoint = geometryFactory.createPoint(g.getCoordinates()[0]);//第一个交点
  289 +
  290 + //第一条线截断至交点
  291 + rs = truncationEnd(s1, inPoint);
  292 + //第二条线从交点开始
  293 + rs += ("," + truncationStart(s2, inPoint));
  294 + }
  295 + return rs;
  296 + }
  297 +
  298 + private LineString createLineString(String c){
  299 + List<String> list = Splitter.on(",").splitToList(c);
  300 +
  301 + Coordinate[] cds = new Coordinate[list.size()];
  302 + String[] strs;
  303 + for(int i = 0; i < list.size(); i ++){
  304 + strs = list.get(i).split(" ");
  305 + cds[i] = new Coordinate(Float.parseFloat(strs[1]), Float.parseFloat(strs[0]));
  306 + }
  307 + return geometryFactory.createLineString(cds);
  308 + }
  309 +
  310 + private String truncationEnd(LineString lineString, Point p){
  311 + Coordinate[] all = lineString.getCoordinates();
  312 + LineString sl;
  313 +
  314 + Coordinate[] cs;
  315 + StringBuilder sb = new StringBuilder("");
  316 + double threshold = 0.1,distance;
  317 + for(int i = 0; i < all.length - 1; i ++){
  318 + cs = new Coordinate[2];
  319 + cs[0] = all[i];
  320 + cs[1] = all[i + 1];
  321 + sl = geometryFactory.createLineString(cs);
  322 +
  323 + sb.append("," + cs[0].y + " " + cs[0].x);
  324 + distance = GeoUtils.getDistanceFromLine(sl, p);
  325 + if(distance < threshold){
  326 + sb.append("," + p.getY() + " " + p.getX());
  327 + break;
  328 + }
  329 + else
  330 + sb.append("," + cs[1].y + " " + cs[1].x);
  331 + }
  332 + sb.deleteCharAt(0);
  333 + return sb.toString();
  334 + }
  335 +
  336 + private String truncationStart(LineString lineString, Point p){
  337 + Coordinate[] all = lineString.getCoordinates();
  338 + LineString sl;
  339 +
  340 + Coordinate[] cs;
  341 + StringBuilder sb = new StringBuilder("");
  342 + double threshold = 0.1,distance;
  343 + for(int i = 0; i < all.length - 1; i ++){
  344 + cs = new Coordinate[2];
  345 + cs[0] = all[i];
  346 + cs[1] = all[i + 1];
  347 + sl = geometryFactory.createLineString(cs);
  348 +
  349 + distance = GeoUtils.getDistanceFromLine(sl, p);
  350 + if(distance < threshold){
  351 + sb.append("," + p.getY() + " " + p.getX());
  352 + sb.append("," + cs[1].y + " " + cs[1].x);
  353 + break;
  354 + }
  355 + else{
  356 + sb.append("," + cs[0].y + " " + cs[0].x);
  357 + sb.append("," + cs[1].y + " " + cs[1].x);
  358 + }
  359 + }
  360 + sb.deleteCharAt(0);
  361 + return sb.toString();
  362 + }
230 363 }
... ...
src/main/resources/static/pages/control/lineallot/allot.html
... ... @@ -421,7 +421,22 @@
421 421  
422 422 function cacheRoute(lsData, cb) {
423 423 //showLoad('缓存线路路由信息...');
424   - var i = 0, cacheData = {};
  424 + //拼接线路编码
  425 + var idx='';
  426 + $.each(lsData, function () {
  427 + idx+=(this.lineCode + ',');
  428 + });
  429 + idx=idx.substr(0, idx.length - 1);
  430 + $.get('/realMap/findRouteByLine', {idx: idx}, function (rs) {
  431 + if (rs) {
  432 + //cacheData[item.lineCode] = rs;
  433 + for(var lineCode in rs){
  434 + storage.setItem(lineCode + '_route', JSON.stringify(rs[lineCode]));
  435 + }
  436 + cb && cb();
  437 + }
  438 + });
  439 +/* var i = 0, cacheData = {};
425 440 (function () {
426 441 if (i >= lsData.length) {
427 442 //写入localStorage
... ... @@ -442,7 +457,7 @@
442 457 f();
443 458 }
444 459 });
445   - })();
  460 + })();*/
446 461 }
447 462  
448 463 //历史纪录
... ...
src/main/resources/static/real_control_v2/js/data/data_gps.js
... ... @@ -18,7 +18,13 @@ var gb_data_gps = (function () {
18 18 $.ajax({
19 19 url: '/gps/real/line',
20 20 data: {lineCodes: gb_data_basic.line_idx},
  21 + dataType: 'json',
21 22 success: function (rs) {
  23 + //用定时的gps来检测session断开
  24 + if(rs.status && rs.status==407){
  25 + location.href = '/login.html';
  26 + return;
  27 + }
22 28 refreshData(rs);
23 29 cb();
24 30 },
... ...