Commit 0e3171c443f844e1960149c34329a82b9ed412c3

Authored by 王通
1 parent 167365ed

1.小码实时GPS数据接口

src/main/java/com/bsth/server_rs/gps/buffer/BasicDataBuffer.java 0 → 100644
  1 +package com.bsth.server_rs.gps.buffer;
  2 +
  3 +import java.util.HashMap;
  4 +import java.util.Map;
  5 +import java.util.Set;
  6 +
  7 +import org.springframework.stereotype.Component;
  8 +
  9 +import com.bsth.server_rs.gps.entity.LineInfo;
  10 +
  11 +/**
  12 + * Created by panzhao on 2017/3/30.
  13 + */
  14 +@Component
  15 +public class BasicDataBuffer {
  16 +
  17 + private static Map<Integer, LineInfo> LINEID_INFO = new HashMap<Integer, LineInfo>();
  18 +
  19 + private static Map<String, String> DEVICE_PLATE = new HashMap<String, String>();
  20 +
  21 + public static void putLine(Integer lineId, LineInfo info) {
  22 + LINEID_INFO.put(lineId, info);
  23 + }
  24 +
  25 + public static void putCar(String deviceId, String plateNo) {
  26 + DEVICE_PLATE.put(deviceId, plateNo);
  27 + }
  28 +
  29 + public static String getPlateByDevice(String deviceId) {
  30 + return DEVICE_PLATE.get(deviceId);
  31 + }
  32 +
  33 + public static Set<String> getAllDevice() {
  34 + return DEVICE_PLATE.keySet();
  35 + }
  36 +
  37 + public static LineInfo getLineById(Integer lineId) {
  38 + return LINEID_INFO.get(lineId);
  39 + }
  40 +}
src/main/java/com/bsth/server_rs/gps/buffer/BasicDataRefreshThread.java 0 → 100644
  1 +package com.bsth.server_rs.gps.buffer;
  2 +
  3 +import java.sql.ResultSet;
  4 +import java.sql.SQLException;
  5 +import java.util.ArrayList;
  6 +import java.util.List;
  7 +import java.util.Map;
  8 +
  9 +import org.slf4j.Logger;
  10 +import org.slf4j.LoggerFactory;
  11 +import org.springframework.beans.factory.annotation.Autowired;
  12 +import org.springframework.jdbc.core.JdbcTemplate;
  13 +import org.springframework.jdbc.core.RowMapper;
  14 +import org.springframework.stereotype.Component;
  15 +
  16 +import com.bsth.server_rs.gps.entity.LineInfo;
  17 +import com.bsth.server_rs.gps.entity.Point;
  18 +import com.bsth.server_rs.gps.entity.StopInfo;
  19 +
  20 +/**
  21 + * Created by panzhao on 2017/3/30.
  22 + */
  23 +@Component
  24 +public class BasicDataRefreshThread extends Thread{
  25 +
  26 + Logger logger = LoggerFactory.getLogger(this.getClass());
  27 +
  28 + @Autowired
  29 + private JdbcTemplate jdbcTemplate;
  30 +
  31 + @Override
  32 + public void run() {
  33 + try {
  34 + String qline = "select a.id,line_code,name,start_station_name,start_station_first_time,start_station_end_time,end_station_name,end_station_first_time,end_station_end_time,company,branche_company,length,telephone,speed_limit,shanghai_linecode,line_play_type,up_travel_time,down_travel_time from bsth_c_line a left join bsth_c_line_information b on a.id = b.line where a.destroy = 0";
  35 + String qstop = "select b.id,b.station_cod,b.station_name,b.road_coding,b.g_lonx,b.g_laty,b.shapes_type,b.radius,AsText(b.g_polygon_grid) as g_polygon_grid,a.line,a.line_code,a.directions,a.distances from bsth_c_stationroute a join bsth_c_station b on a.station = b.id where a.destroy = 0 order by a.line,a.directions,a.station_route_code";
  36 + String qcar = "select equipment_code device_id, car_plate plate_no from bsth_c_cars a where a.supplier_name = 3";
  37 +
  38 + List<LineInfo> lines = jdbcTemplate.query(qline, new RowMapperLineInfo());
  39 + List<StopInfo> stops = jdbcTemplate.query(qstop, new RowMapperStopInfo());
  40 + List<Map<String, Object>> cars = jdbcTemplate.queryForList(qcar);
  41 +
  42 + // 缓存线路基本信息
  43 + for (LineInfo line : lines) {
  44 + BasicDataBuffer.putLine(line.getLineId(), line);
  45 + }
  46 +
  47 + // 线路信息中添加上下行站点信息
  48 + int oldId = -1;
  49 + LineInfo line = null;
  50 + for (StopInfo stop : stops) {
  51 + if (stop.getLineCode() != oldId) {
  52 + oldId = stop.getLineCode();
  53 + line = BasicDataBuffer.getLineById(oldId);
  54 + }
  55 + if (line != null) {
  56 + if (stop.getDirections() == 0) line.getStopsUp().add(stop);
  57 + else line.getStopsDown().add(stop);
  58 + }
  59 + }
  60 +
  61 + for (Map<String, Object> car : cars) {
  62 + BasicDataBuffer.putCar((String)car.get("device_id"), (String)car.get("plate_no"));
  63 + }
  64 + }catch (Exception e){
  65 + logger.error("", e);
  66 + }
  67 + }
  68 +
  69 + final class RowMapperLineInfo implements RowMapper<LineInfo> {
  70 +
  71 + @Override
  72 + public LineInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
  73 + // TODO Auto-generated method stub
  74 + LineInfo line = new LineInfo();
  75 + line.setId(rs.getInt("id"));
  76 + line.setInUse(rs.getInt("in_use"));
  77 + line.setLineId(rs.getInt("line_code"));
  78 + line.setLineName(rs.getString("name"));
  79 + //line.setStartStation(rs.getInt("start_station"));
  80 + line.setStartStationName(rs.getString("start_station_name"));
  81 + line.setStartStationFirstTime(rs.getString("start_station_first_time"));
  82 + line.setStartStationEndTime(rs.getString("start_station_end_time"));
  83 + //line.setEndStation(rs.getInt("end_station"));
  84 + line.setEndStationName(rs.getString("end_station_name"));
  85 + line.setEndStationFirstTime(rs.getString("end_station_first_time"));
  86 + line.setEndStationEndTime(rs.getString("end_station_end_time"));
  87 + line.setCompany(rs.getString("company"));
  88 + line.setBrancheCompany(rs.getString("branche_company"));
  89 + line.setTelephone(rs.getString("telephone"));
  90 + line.setLinePlayType(rs.getInt("line_play_type"));
  91 + return line;
  92 + }
  93 +
  94 + }
  95 +
  96 + final class RowMapperStopInfo implements RowMapper<StopInfo> {
  97 +
  98 + @Override
  99 + public StopInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
  100 + // TODO Auto-generated method stub
  101 + StopInfo stop = new StopInfo();
  102 + stop.setId(rs.getInt("id"));
  103 + stop.setStationCod(rs.getString("station_cod"));
  104 + stop.setStationName(rs.getString("station_name"));
  105 + //stop.setStationType(rs.getString("station_type"));
  106 + stop.setRoadCoding(rs.getString("road_coding"));
  107 + float lon = rs.getFloat("g_lonx");
  108 + float lat = rs.getFloat("g_laty");
  109 + stop.setPoint(new Point(lon, lat));
  110 + stop.setLineId(rs.getInt("line"));
  111 + stop.setLineCode(rs.getInt("line_code"));
  112 + stop.setDirections(rs.getInt("directions"));
  113 + stop.setShapesType(rs.getString("shapes_type"));
  114 + stop.setRadius(rs.getInt("radius"));
  115 + stop.setPoints(new ArrayList<Point>());
  116 + stop.setDistances(rs.getDouble("distances")*1000);
  117 + return stop;
  118 + }
  119 +
  120 + }
  121 +}
src/main/java/com/bsth/server_rs/gps/entity/LineInfo.java 0 → 100644
  1 +package com.bsth.server_rs.gps.entity;
  2 +
  3 +import java.util.ArrayList;
  4 +import java.util.List;
  5 +
  6 +public class LineInfo {
  7 +
  8 + private int id;
  9 + private int lineId;
  10 + private String lineName;
  11 + private int startStation;
  12 + private String startStationName;
  13 + private String startStationFirstTime;
  14 + private String startStationEndTime;
  15 + private int endStation;
  16 + private String endStationName;
  17 + private String endStationFirstTime;
  18 + private String endStationEndTime;
  19 + private String company;
  20 + private String brancheCompany;
  21 + private double length;
  22 + private String telephone;
  23 + private int linePlayType;
  24 + private int inUse;
  25 + // 上行站点
  26 + private List<StopInfo> stopsUp = new ArrayList<StopInfo>();
  27 + // 下行站点
  28 + private List<StopInfo> stopsDown = new ArrayList<StopInfo>();
  29 +
  30 + public List<StopInfo> getStopsUp() {
  31 + return stopsUp;
  32 + }
  33 +
  34 + public void setStopsUp(List<StopInfo> stopsUp) {
  35 + this.stopsUp = stopsUp;
  36 + }
  37 +
  38 + public List<StopInfo> getStopsDown() {
  39 + return stopsDown;
  40 + }
  41 +
  42 + public void setStopsDown(List<StopInfo> stopsDown) {
  43 + this.stopsDown = stopsDown;
  44 + }
  45 +
  46 + public int getId() {
  47 + return id;
  48 + }
  49 +
  50 + public void setId(int id) {
  51 + this.id = id;
  52 + }
  53 +
  54 + public int getLineId() {
  55 + return lineId;
  56 + }
  57 +
  58 + public void setLineId(int lineId) {
  59 + this.lineId = lineId;
  60 + }
  61 +
  62 + public String getLineName() {
  63 + return lineName;
  64 + }
  65 +
  66 + public void setLineName(String lineName) {
  67 + this.lineName = lineName;
  68 + }
  69 +
  70 + public int getStartStation() {
  71 + return startStation;
  72 + }
  73 +
  74 + public void setStartStation(int startStation) {
  75 + this.startStation = startStation;
  76 + }
  77 +
  78 + public String getStartStationName() {
  79 + return startStationName;
  80 + }
  81 +
  82 + public void setStartStationName(String startStationName) {
  83 + this.startStationName = startStationName;
  84 + }
  85 +
  86 + public String getStartStationFirstTime() {
  87 + return startStationFirstTime;
  88 + }
  89 +
  90 + public void setStartStationFirstTime(String startStationFirstTime) {
  91 + this.startStationFirstTime = startStationFirstTime;
  92 + }
  93 +
  94 + public String getStartStationEndTime() {
  95 + return startStationEndTime;
  96 + }
  97 +
  98 + public void setStartStationEndTime(String startStationEndTime) {
  99 + this.startStationEndTime = startStationEndTime;
  100 + }
  101 +
  102 + public int getEndStation() {
  103 + return endStation;
  104 + }
  105 +
  106 + public void setEndStation(int endStation) {
  107 + this.endStation = endStation;
  108 + }
  109 +
  110 + public String getEndStationName() {
  111 + return endStationName;
  112 + }
  113 +
  114 + public void setEndStationName(String endStationName) {
  115 + this.endStationName = endStationName;
  116 + }
  117 +
  118 + public String getEndStationFirstTime() {
  119 + return endStationFirstTime;
  120 + }
  121 +
  122 + public void setEndStationFirstTime(String endStationFirstTime) {
  123 + this.endStationFirstTime = endStationFirstTime;
  124 + }
  125 +
  126 + public String getEndStationEndTime() {
  127 + return endStationEndTime;
  128 + }
  129 +
  130 + public void setEndStationEndTime(String endStationEndTime) {
  131 + this.endStationEndTime = endStationEndTime;
  132 + }
  133 +
  134 + public String getCompany() {
  135 + return company;
  136 + }
  137 +
  138 + public void setCompany(String company) {
  139 + this.company = company;
  140 + }
  141 +
  142 + public String getBrancheCompany() {
  143 + return brancheCompany;
  144 + }
  145 +
  146 + public void setBrancheCompany(String brancheCompany) {
  147 + this.brancheCompany = brancheCompany;
  148 + }
  149 +
  150 + public double getLength() {
  151 + return length;
  152 + }
  153 +
  154 + public void setLength(double length) {
  155 + this.length = length;
  156 + }
  157 +
  158 + public String getTelephone() {
  159 + return telephone;
  160 + }
  161 +
  162 + public void setTelephone(String telephone) {
  163 + this.telephone = telephone;
  164 + }
  165 +
  166 + public int getLinePlayType() {
  167 + return linePlayType;
  168 + }
  169 +
  170 + public void setLinePlayType(int linePlayType) {
  171 + this.linePlayType = linePlayType;
  172 + }
  173 +
  174 + public int getInUse() {
  175 + return inUse;
  176 + }
  177 +
  178 + public void setInUse(int inUse) {
  179 + this.inUse = inUse;
  180 + }
  181 +}
src/main/java/com/bsth/server_rs/gps/entity/Point.java 0 → 100644
  1 +package com.bsth.server_rs.gps.entity;
  2 +
  3 +public class Point {
  4 +
  5 + private double lon;
  6 + private double lat;
  7 +
  8 + public Point(double lon, double lat) {
  9 + this.lon = lon;
  10 + this.lat = lat;
  11 + }
  12 +
  13 + public double getLon() {
  14 + return lon;
  15 + }
  16 +
  17 + public double getLat() {
  18 + return lat;
  19 + }
  20 +}
src/main/java/com/bsth/server_rs/gps/entity/StopInfo.java 0 → 100644
  1 +package com.bsth.server_rs.gps.entity;
  2 +
  3 +import java.util.List;
  4 +
  5 +public class StopInfo {
  6 +
  7 + private int id;
  8 + private String stationCod;
  9 + private String stationName;
  10 + private String stationType;
  11 + private String roadCoding;
  12 + private Point point;
  13 + private String shapesType;
  14 + private int radius;
  15 + private List<Point> points;
  16 + private double distances;
  17 +
  18 + private int lineId;
  19 + private int lineCode;
  20 + private int directions;
  21 +
  22 + public double getDistances() {
  23 + return distances;
  24 + }
  25 +
  26 + public void setDistances(double distances) {
  27 + this.distances = distances;
  28 + }
  29 +
  30 + public int getRadius() {
  31 + return radius;
  32 + }
  33 +
  34 + public void setRadius(int radius) {
  35 + this.radius = radius;
  36 + }
  37 +
  38 + public List<Point> getPoints() {
  39 + return points;
  40 + }
  41 +
  42 + public void setPoints(List<Point> points) {
  43 + this.points = points;
  44 + }
  45 +
  46 + public String getShapesType() {
  47 + return shapesType;
  48 + }
  49 +
  50 + public void setShapesType(String shapesType) {
  51 + this.shapesType = shapesType;
  52 + }
  53 +
  54 + public int getDirections() {
  55 + return directions;
  56 + }
  57 +
  58 + public void setDirections(int directions) {
  59 + this.directions = directions;
  60 + }
  61 +
  62 + public int getLineId() {
  63 + return lineId;
  64 + }
  65 +
  66 + public void setLineId(int lineId) {
  67 + this.lineId = lineId;
  68 + }
  69 +
  70 + public Point getPoint() {
  71 + return point;
  72 + }
  73 +
  74 + public void setPoint(Point point) {
  75 + this.point = point;
  76 + }
  77 +
  78 + public int getId() {
  79 + return id;
  80 + }
  81 +
  82 + public void setId(int id) {
  83 + this.id = id;
  84 + }
  85 +
  86 + public String getStationCod() {
  87 + return stationCod;
  88 + }
  89 +
  90 + public void setStationCod(String stationCod) {
  91 + this.stationCod = stationCod;
  92 + }
  93 +
  94 + public String getStationName() {
  95 + return stationName;
  96 + }
  97 +
  98 + public void setStationName(String stationName) {
  99 + this.stationName = stationName;
  100 + }
  101 +
  102 + public String getStationType() {
  103 + return stationType;
  104 + }
  105 +
  106 + public void setStationType(String stationType) {
  107 + this.stationType = stationType;
  108 + }
  109 +
  110 + public String getRoadCoding() {
  111 + return roadCoding;
  112 + }
  113 +
  114 + public void setRoadCoding(String roadCoding) {
  115 + this.roadCoding = roadCoding;
  116 + }
  117 +
  118 + public int getLineCode() {
  119 + return lineCode;
  120 + }
  121 +
  122 + public void setLineCode(int lineCode) {
  123 + this.lineCode = lineCode;
  124 + }
  125 +}
src/main/java/com/bsth/util/ThreadLocalDateUtil.java 0 → 100644
  1 +package com.bsth.util;
  2 +
  3 +import java.text.DateFormat;
  4 +import java.text.ParseException;
  5 +import java.text.SimpleDateFormat;
  6 +import java.util.Date;
  7 +
  8 +public class ThreadLocalDateUtil {
  9 + private static final String date_format = "yyyyMMddHHmmss";
  10 + private static ThreadLocal<DateFormat> threadLocal = new ThreadLocal<DateFormat>();
  11 +
  12 + public static DateFormat getDateFormat()
  13 + {
  14 + DateFormat df = threadLocal.get();
  15 + if(df==null){
  16 + df = new SimpleDateFormat(date_format);
  17 + threadLocal.set(df);
  18 + }
  19 + return df;
  20 + }
  21 +
  22 + public static String formatDate(Date date) throws ParseException {
  23 + return getDateFormat().format(date);
  24 + }
  25 +
  26 + public static Date parse(String strDate) throws ParseException {
  27 + return getDateFormat().parse(strDate);
  28 + }
  29 +}