Commit 8a2cefa9584a0034e4517ed8847a37487129b30c

Authored by 王通
1 parent 9be2dd8f

1.加入按线路名查询最新版本的路段信息

src/main/java/com/bsth/server_rs/base_info/section/LD_SectionRestService.java
@@ -11,6 +11,7 @@ import javax.ws.rs.PathParam; @@ -11,6 +11,7 @@ import javax.ws.rs.PathParam;
11 import javax.ws.rs.Produces; 11 import javax.ws.rs.Produces;
12 import javax.ws.rs.core.MediaType; 12 import javax.ws.rs.core.MediaType;
13 import java.util.Collection; 13 import java.util.Collection;
  14 +import java.util.List;
14 import java.util.Map; 15 import java.util.Map;
15 16
16 /** 17 /**
@@ -37,4 +38,10 @@ public class LD_SectionRestService { @@ -37,4 +38,10 @@ public class LD_SectionRestService {
37 public Map<String, Collection<LD_SectionRoute>> findByLineCode(@PathParam("lineCode") String lineCode){ 38 public Map<String, Collection<LD_SectionRoute>> findByLineCode(@PathParam("lineCode") String lineCode){
38 return sectionBufferData.findByLineCode(lineCode); 39 return sectionBufferData.findByLineCode(lineCode);
39 } 40 }
  41 +
  42 + @GET
  43 + @Path("/lineName/{lineName}")
  44 + public List<LD_SectionRoute> findByLineName(@PathParam("lineName") String lineName){
  45 + return sectionBufferData.findByLineName(lineName);
  46 + }
40 } 47 }
src/main/java/com/bsth/server_rs/base_info/section/buffer/LD_SectionBufferData.java
@@ -16,6 +16,7 @@ import org.springframework.jdbc.core.JdbcTemplate; @@ -16,6 +16,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
16 import org.springframework.stereotype.Component; 16 import org.springframework.stereotype.Component;
17 17
18 import java.util.*; 18 import java.util.*;
  19 +import java.util.concurrent.ConcurrentHashMap;
19 import java.util.concurrent.TimeUnit; 20 import java.util.concurrent.TimeUnit;
20 21
21 /** 22 /**
@@ -30,6 +31,11 @@ public class LD_SectionBufferData implements CommandLineRunner { @@ -30,6 +31,11 @@ public class LD_SectionBufferData implements CommandLineRunner {
30 private static List<LD_Section> data; 31 private static List<LD_Section> data;
31 private static Map<String, LD_Section> codeMap; 32 private static Map<String, LD_Section> codeMap;
32 33
  34 + /**
  35 + * 线路名称和路段集合映射
  36 + */
  37 + private static Map<String, List<LD_SectionRoute>> name2sections = new ConcurrentHashMap<>();
  38 +
33 //路段限速缓存信息 39 //路段限速缓存信息
34 private static List<RoadSpeed> roadSpeedList; 40 private static List<RoadSpeed> roadSpeedList;
35 41
@@ -135,4 +141,12 @@ public class LD_SectionBufferData implements CommandLineRunner { @@ -135,4 +141,12 @@ public class LD_SectionBufferData implements CommandLineRunner {
135 listMap.putAll(k2, routeListMap.get(k2)); 141 listMap.putAll(k2, routeListMap.get(k2));
136 return listMap.asMap(); 142 return listMap.asMap();
137 } 143 }
  144 +
  145 + public static void putLastedRoute(Map<String, List<LD_SectionRoute>> map) {
  146 + name2sections = map;
  147 + }
  148 +
  149 + public List<LD_SectionRoute> findByLineName(String lineName) {
  150 + return name2sections.get(lineName);
  151 + }
138 } 152 }
src/main/java/com/bsth/server_rs/base_info/section/buffer/LD_SectionRefreshThread.java
@@ -10,7 +10,10 @@ import org.springframework.jdbc.core.BeanPropertyRowMapper; @@ -10,7 +10,10 @@ import org.springframework.jdbc.core.BeanPropertyRowMapper;
10 import org.springframework.jdbc.core.JdbcTemplate; 10 import org.springframework.jdbc.core.JdbcTemplate;
11 import org.springframework.stereotype.Component; 11 import org.springframework.stereotype.Component;
12 12
  13 +import java.util.ArrayList;
  14 +import java.util.HashMap;
13 import java.util.List; 15 import java.util.List;
  16 +import java.util.Map;
14 17
15 /** 18 /**
16 * Created by panzhao on 2017/3/27. 19 * Created by panzhao on 2017/3/27.
@@ -51,6 +54,22 @@ public class LD_SectionRefreshThread extends Thread{ @@ -51,6 +54,22 @@ public class LD_SectionRefreshThread extends Thread{
51 List<RoadSpeed> roadSpeedList = jdbcTemplate.query("select id,name,ST_AsText(g_road_vector) as g_road_vector,speed,speed_start_date,speed_end_date,line,is_start,create_date,update_date from bsth_c_road_speed where is_start=0", BeanPropertyRowMapper.newInstance(RoadSpeed.class)); 54 List<RoadSpeed> roadSpeedList = jdbcTemplate.query("select id,name,ST_AsText(g_road_vector) as g_road_vector,speed,speed_start_date,speed_end_date,line,is_start,create_date,update_date from bsth_c_road_speed where is_start=0", BeanPropertyRowMapper.newInstance(RoadSpeed.class));
52 if(roadSpeedList.size() > 0) 55 if(roadSpeedList.size() > 0)
53 LD_SectionBufferData.putRoadSpeeds(roadSpeedList); 56 LD_SectionBufferData.putRoadSpeeds(roadSpeedList);
  57 +
  58 + //查询最新版本路段信息
  59 + List<LD_SectionRoute> sectionRoutes = jdbcTemplate.query("select b.line_name,a.line_code,a.section_code,a.directions,a.sectionroute_code,a.versions from (select l.name line_name,l.line_code line_code,max(versions) versions from bsth_c_line l left join bsth_c_line_versions v on l.line_code = v.line_code where l.destroy = 0 group by l.line_code) b left join bsth_c_ls_sectionroute a on a.line_code = b.line_code and a.versions = b.versions where a.destroy = 0 order by a.line_code,a.directions,a.sectionroute_code", BeanPropertyRowMapper.newInstance(LD_SectionRoute.class));
  60 + Map<String, List<LD_SectionRoute>> name2sections = new HashMap<>();
  61 + List<LD_SectionRoute> routes = null;
  62 + String lastedLineName = "";
  63 + for (LD_SectionRoute sr : sectionRoutes) {
  64 + if ("".equals(lastedLineName) || !lastedLineName.equals(sr.getLineName())) {
  65 + name2sections.put(lastedLineName, routes);
  66 + lastedLineName = sr.getLineName();
  67 + routes = new ArrayList<>();
  68 + }
  69 + sr.setSection(LD_SectionBufferData.findOne(sr.getSectionCode()));
  70 + routes.add(sr);
  71 + }
  72 + LD_SectionBufferData.putLastedRoute(name2sections);
54 }catch (Exception e){ 73 }catch (Exception e){
55 logger.error("", e); 74 logger.error("", e);
56 } 75 }
src/main/java/com/bsth/server_rs/base_info/section/entity/LD_SectionRoute.java
@@ -6,6 +6,9 @@ package com.bsth.server_rs.base_info.section.entity; @@ -6,6 +6,9 @@ package com.bsth.server_rs.base_info.section.entity;
6 */ 6 */
7 public class LD_SectionRoute { 7 public class LD_SectionRoute {
8 8
  9 + /** 线路名称 */
  10 + private String lineName;
  11 +
9 /** 线路编号 */ 12 /** 线路编号 */
10 private String lineCode; 13 private String lineCode;
11 14
@@ -24,6 +27,14 @@ public class LD_SectionRoute { @@ -24,6 +27,14 @@ public class LD_SectionRoute {
24 /** 路段详细 */ 27 /** 路段详细 */
25 private LD_Section section; 28 private LD_Section section;
26 29
  30 + public String getLineName() {
  31 + return lineName;
  32 + }
  33 +
  34 + public void setLineName(String lineName) {
  35 + this.lineName = lineName;
  36 + }
  37 +
27 public String getLineCode() { 38 public String getLineCode() {
28 return lineCode; 39 return lineCode;
29 } 40 }