Commit 979dd092546749345beef7797458d2baee3405b7
1 parent
8ee2ece2
1.发布进出停车场轨迹接口
Showing
3 changed files
with
274 additions
and
0 deletions
src/main/java/com/bsth/server_rs/base_info/iocarpark/IoCarparkRestService.java
0 → 100644
| 1 | +package com.bsth.server_rs.base_info.iocarpark; | ||
| 2 | + | ||
| 3 | +import com.bsth.server_rs.base_info.iocarpark.buffer.IoCarparkBufferData; | ||
| 4 | +import com.bsth.server_rs.base_info.iocarpark.entity.IoCarparkSectionRoute; | ||
| 5 | +import com.bsth.server_rs.base_info.section.entity.LD_SectionRoute; | ||
| 6 | +import org.slf4j.Logger; | ||
| 7 | +import org.slf4j.LoggerFactory; | ||
| 8 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 9 | +import org.springframework.stereotype.Component; | ||
| 10 | + | ||
| 11 | +import javax.ws.rs.*; | ||
| 12 | +import javax.ws.rs.core.MediaType; | ||
| 13 | +import java.util.Collection; | ||
| 14 | +import java.util.List; | ||
| 15 | +import java.util.Map; | ||
| 16 | + | ||
| 17 | +/** | ||
| 18 | + * @author Hill | ||
| 19 | + */ | ||
| 20 | + | ||
| 21 | +@Component | ||
| 22 | +@Path("/iocarpark") | ||
| 23 | +@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) | ||
| 24 | +public class IoCarparkRestService { | ||
| 25 | + | ||
| 26 | + private final static Logger log = LoggerFactory.getLogger(IoCarparkRestService.class); | ||
| 27 | + | ||
| 28 | + @Autowired | ||
| 29 | + IoCarparkBufferData ioCarparkBufferData; | ||
| 30 | + | ||
| 31 | + @GET | ||
| 32 | + @Path("/all") | ||
| 33 | + public Map<String, Collection<IoCarparkSectionRoute>> findAll(){ | ||
| 34 | + return IoCarparkBufferData.findAllRoute(); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + @GET | ||
| 38 | + @Path("/{company}") | ||
| 39 | + public Map<String, Collection<IoCarparkSectionRoute>> findByCompany(@PathParam("company") String company){ | ||
| 40 | + return ioCarparkBufferData.findRouteByCompany(company); | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + @GET | ||
| 44 | + @Path("/line/{lineCode}") | ||
| 45 | + public Map<String, Collection<IoCarparkSectionRoute>> findByLineCode(@PathParam("lineCode") String lineCode){ | ||
| 46 | + return ioCarparkBufferData.findByLineCode(lineCode); | ||
| 47 | + } | ||
| 48 | +} |
src/main/java/com/bsth/server_rs/base_info/iocarpark/buffer/IoCarparkBufferData.java
0 → 100644
| 1 | +package com.bsth.server_rs.base_info.iocarpark.buffer; | ||
| 2 | + | ||
| 3 | +import com.bsth.Application; | ||
| 4 | +import com.bsth.server_rs.base_info.iocarpark.entity.IoCarparkSectionRoute; | ||
| 5 | +import com.bsth.server_rs.base_info.line.Line; | ||
| 6 | +import com.bsth.server_rs.base_info.line.buffer.LineBufferData; | ||
| 7 | +import com.bsth.server_rs.base_info.section.entity.LD_Section; | ||
| 8 | +import com.google.common.collect.ArrayListMultimap; | ||
| 9 | +import org.slf4j.Logger; | ||
| 10 | +import org.slf4j.LoggerFactory; | ||
| 11 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 12 | +import org.springframework.boot.CommandLineRunner; | ||
| 13 | +import org.springframework.core.annotation.Order; | ||
| 14 | +import org.springframework.jdbc.core.JdbcTemplate; | ||
| 15 | +import org.springframework.stereotype.Component; | ||
| 16 | + | ||
| 17 | +import java.util.*; | ||
| 18 | +import java.util.concurrent.ConcurrentHashMap; | ||
| 19 | + | ||
| 20 | +/** | ||
| 21 | + * @author Hill | ||
| 22 | + */ | ||
| 23 | +@Component | ||
| 24 | +@Order(6) | ||
| 25 | +public class IoCarparkBufferData { | ||
| 26 | + | ||
| 27 | + | ||
| 28 | + private static List<LD_Section> data; | ||
| 29 | + private static Map<String, LD_Section> codeMap; | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * 线路名称和路段集合映射 | ||
| 33 | + */ | ||
| 34 | + private static Map<String, List<IoCarparkSectionRoute>> name2sections = new ConcurrentHashMap<>(); | ||
| 35 | + | ||
| 36 | + @Autowired | ||
| 37 | + JdbcTemplate jdbcTemplate; | ||
| 38 | + | ||
| 39 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
| 40 | + | ||
| 41 | + /** | ||
| 42 | + 路由缓存 | ||
| 43 | + 线路编码_上下行 ——> 路由集合 | ||
| 44 | + */ | ||
| 45 | + private static ArrayListMultimap<String, IoCarparkSectionRoute> routeListMap; | ||
| 46 | + | ||
| 47 | + | ||
| 48 | + public static List<LD_Section> findAll(){ | ||
| 49 | + return data; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + public static Map<String, Collection<IoCarparkSectionRoute>> findAllRoute(){ | ||
| 53 | + return routeListMap.asMap(); | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + public static LD_Section findOne(String code){ | ||
| 57 | + return codeMap.get(code); | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + public static void replaceAll(List<LD_Section> newData){ | ||
| 61 | + data = newData; | ||
| 62 | + Map<String, LD_Section> codeMapCopy = new HashMap<>(); | ||
| 63 | + for(LD_Section section : data){ | ||
| 64 | + codeMapCopy.put(section.getSectionCode(), section); | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + codeMap = codeMapCopy; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + public static void replaceRoutes(List<IoCarparkSectionRoute> list){ | ||
| 71 | + Collections.sort(list, new Comparator<IoCarparkSectionRoute>() { | ||
| 72 | + @Override | ||
| 73 | + public int compare(IoCarparkSectionRoute o1, IoCarparkSectionRoute o2) { | ||
| 74 | + return o1.getSectionrouteCode().compareTo(o2.getSectionrouteCode()); | ||
| 75 | + } | ||
| 76 | + }); | ||
| 77 | + | ||
| 78 | + ArrayListMultimap<String, IoCarparkSectionRoute> routeListMapCopy = ArrayListMultimap.create(); | ||
| 79 | + for(IoCarparkSectionRoute sr : list){ | ||
| 80 | + routeListMapCopy.put(sr.getLineCode()+"_" + sr.getStart() + "_" + sr.getEnd(), sr); | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + routeListMap = routeListMapCopy; | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + public Map<String, Collection<IoCarparkSectionRoute>> findRouteByCompany(String company) { | ||
| 87 | + List<Line> lines = LineBufferData.findByCompany(company); | ||
| 88 | + | ||
| 89 | + ArrayListMultimap<String, IoCarparkSectionRoute> listMap = ArrayListMultimap.create(); | ||
| 90 | + | ||
| 91 | + | ||
| 92 | + Set<String> ks = routeListMap.keySet(); | ||
| 93 | + | ||
| 94 | + for(String k : ks){ | ||
| 95 | + if(include(lines, k)){ | ||
| 96 | + listMap.putAll(k, routeListMap.get(k)); | ||
| 97 | + } | ||
| 98 | + } | ||
| 99 | + return listMap.asMap(); | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + private static boolean include(List<Line> lines, String k){ | ||
| 103 | + | ||
| 104 | + for(Line line : lines){ | ||
| 105 | + if(k.startsWith(line.getLineCode() + "_")) | ||
| 106 | + return true; | ||
| 107 | + } | ||
| 108 | + return false; | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + public Map<String, Collection<IoCarparkSectionRoute>> findByLineCode(String lineCode) { | ||
| 112 | + | ||
| 113 | + ArrayListMultimap<String, IoCarparkSectionRoute> listMap = ArrayListMultimap.create(); | ||
| 114 | + | ||
| 115 | + Set<String> ks = routeListMap.keySet(); | ||
| 116 | + | ||
| 117 | + for(String k : ks){ | ||
| 118 | + if(k.startsWith(lineCode + "_")){ | ||
| 119 | + listMap.putAll(k, routeListMap.get(k)); | ||
| 120 | + } | ||
| 121 | + } | ||
| 122 | + return listMap.asMap(); | ||
| 123 | + } | ||
| 124 | +} |
src/main/java/com/bsth/server_rs/base_info/iocarpark/entity/IoCarparkSectionRoute.java
0 → 100644
| 1 | +package com.bsth.server_rs.base_info.iocarpark.entity; | ||
| 2 | + | ||
| 3 | +import com.bsth.server_rs.base_info.section.entity.LD_Section; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * @author Hill | ||
| 7 | + * 进出场路段路由 | ||
| 8 | + */ | ||
| 9 | +public class IoCarparkSectionRoute { | ||
| 10 | + | ||
| 11 | + /** 线路编号 */ | ||
| 12 | + private String lineCode; | ||
| 13 | + | ||
| 14 | + /** | ||
| 15 | + * 起点场站编号 | ||
| 16 | + */ | ||
| 17 | + private String start; | ||
| 18 | + | ||
| 19 | + /** | ||
| 20 | + * 终点场站编号 | ||
| 21 | + */ | ||
| 22 | + private String end; | ||
| 23 | + | ||
| 24 | + /** 路段编号 */ | ||
| 25 | + private String sectionCode; | ||
| 26 | + | ||
| 27 | + /** 路段路由方向 */ | ||
| 28 | + private Integer directions; | ||
| 29 | + | ||
| 30 | + /** 路段路由序号 */ | ||
| 31 | + private Integer sectionrouteCode; | ||
| 32 | + | ||
| 33 | + /** 版本号 */ | ||
| 34 | + private Integer versions; | ||
| 35 | + | ||
| 36 | + /** 路段详细 */ | ||
| 37 | + private LD_Section section; | ||
| 38 | + | ||
| 39 | + public String getLineCode() { | ||
| 40 | + return lineCode; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public void setLineCode(String lineCode) { | ||
| 44 | + this.lineCode = lineCode; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public String getStart() { | ||
| 48 | + return start; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public void setStart(String start) { | ||
| 52 | + this.start = start; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public String getEnd() { | ||
| 56 | + return end; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + public void setEnd(String end) { | ||
| 60 | + this.end = end; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public String getSectionCode() { | ||
| 64 | + return sectionCode; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + public void setSectionCode(String sectionCode) { | ||
| 68 | + this.sectionCode = sectionCode; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + public Integer getDirections() { | ||
| 72 | + return directions; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + public void setDirections(Integer directions) { | ||
| 76 | + this.directions = directions; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + public Integer getSectionrouteCode() { | ||
| 80 | + return sectionrouteCode; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + public void setSectionrouteCode(Integer sectionrouteCode) { | ||
| 84 | + this.sectionrouteCode = sectionrouteCode; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + public Integer getVersions() { | ||
| 88 | + return versions; | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + public void setVersions(Integer versions) { | ||
| 92 | + this.versions = versions; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + public LD_Section getSection() { | ||
| 96 | + return section; | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + public void setSection(LD_Section section) { | ||
| 100 | + this.section = section; | ||
| 101 | + } | ||
| 102 | +} |