Commit 98689200ceef2ff9aabf630ecf468a70fac553f7

Authored by 王通
1 parent aefc68fd

1./external相关接口

src/main/java/com/bsth/CXFConfig.java
@@ -102,6 +102,8 @@ public class CXFConfig { @@ -102,6 +102,8 @@ public class CXFConfig {
102 } 102 }
103 103
104 @Autowired 104 @Autowired
  105 + private AuthorizeInterceptor_IN authorizeInterceptorIn;
  106 + @Autowired
105 ScheduleRealService scheduleRealService; 107 ScheduleRealService scheduleRealService;
106 @Autowired 108 @Autowired
107 StationRestService stationRestService; 109 StationRestService stationRestService;
@@ -184,7 +186,7 @@ public class CXFConfig { @@ -184,7 +186,7 @@ public class CXFConfig {
184 stationPassengerService)); 186 stationPassengerService));
185 endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(), new AesExceptionMapper())); 187 endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(), new AesExceptionMapper()));
186 //endpoint.setFeatures(Arrays.asList(new Swagger2Feature())); 188 //endpoint.setFeatures(Arrays.asList(new Swagger2Feature()));
187 - endpoint.getInInterceptors().add(new AuthorizeInterceptor_IN()); 189 + endpoint.getInInterceptors().add(authorizeInterceptorIn);
188 return endpoint.create(); 190 return endpoint.create();
189 } 191 }
190 192
src/main/java/com/bsth/server_rs/AuthorizeInterceptor_IN.java
1 package com.bsth.server_rs; 1 package com.bsth.server_rs;
2 2
3 -import com.bsth.common.SystemParamKeys;  
4 import com.bsth.entity.PasswordUser; 3 import com.bsth.entity.PasswordUser;
5 import com.bsth.entity.Resource; 4 import com.bsth.entity.Resource;
6 import com.bsth.server_rs.exception.AesException; 5 import com.bsth.server_rs.exception.AesException;
7 import com.bsth.service.SystemParamService; 6 import com.bsth.service.SystemParamService;
8 import com.bsth.service.UserService; 7 import com.bsth.service.UserService;
  8 +import com.bsth.util.ThreadLocalUtils;
9 import org.apache.commons.lang3.StringEscapeUtils; 9 import org.apache.commons.lang3.StringEscapeUtils;
10 import org.apache.cxf.interceptor.Fault; 10 import org.apache.cxf.interceptor.Fault;
11 import org.apache.cxf.message.Message; 11 import org.apache.cxf.message.Message;
@@ -16,18 +16,19 @@ import org.eclipse.jetty.util.UrlEncoded; @@ -16,18 +16,19 @@ import org.eclipse.jetty.util.UrlEncoded;
16 import org.slf4j.Logger; 16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory; 17 import org.slf4j.LoggerFactory;
18 import org.springframework.beans.BeansException; 18 import org.springframework.beans.BeansException;
19 -import org.springframework.beans.factory.InitializingBean; 19 +import org.springframework.beans.factory.annotation.Value;
20 import org.springframework.context.ApplicationContext; 20 import org.springframework.context.ApplicationContext;
21 import org.springframework.context.ApplicationContextAware; 21 import org.springframework.context.ApplicationContextAware;
22 import org.springframework.stereotype.Component; 22 import org.springframework.stereotype.Component;
23 import org.springframework.util.AntPathMatcher; 23 import org.springframework.util.AntPathMatcher;
24 import org.springframework.util.PathMatcher; 24 import org.springframework.util.PathMatcher;
25 25
  26 +import java.io.BufferedReader;
  27 +import java.io.FileReader;
  28 +import java.io.IOException;
26 import java.security.MessageDigest; 29 import java.security.MessageDigest;
27 -import java.util.Arrays;  
28 -import java.util.HashMap;  
29 -import java.util.Map;  
30 -import java.util.Set; 30 +import java.util.*;
  31 +import java.util.concurrent.ConcurrentHashMap;
31 32
32 /** 33 /**
33 * rest 接口授权校验(IN 输入拦截) 34 * rest 接口授权校验(IN 输入拦截)
@@ -51,6 +52,15 @@ public class AuthorizeInterceptor_IN extends AbstractPhaseInterceptor<Message> i @@ -51,6 +52,15 @@ public class AuthorizeInterceptor_IN extends AbstractPhaseInterceptor<Message> i
51 52
52 private static PathMatcher matcher = new AntPathMatcher(); 53 private static PathMatcher matcher = new AntPathMatcher();
53 54
  55 + @Value("${path.limits}")
  56 + private String pathLimits;
  57 +
  58 + private Map<String, Set<String>> pwd2lines = new ConcurrentHashMap<>();
  59 +
  60 + private Map<String, Set<String>> pwd2device = new ConcurrentHashMap<>();
  61 +
  62 + private ThreadLocal<String> passwords = new ThreadLocal<>();
  63 +
54 public AuthorizeInterceptor_IN() { 64 public AuthorizeInterceptor_IN() {
55 super(Phase.RECEIVE); 65 super(Phase.RECEIVE);
56 } 66 }
@@ -123,12 +133,15 @@ public class AuthorizeInterceptor_IN extends AbstractPhaseInterceptor&lt;Message&gt; i @@ -123,12 +133,15 @@ public class AuthorizeInterceptor_IN extends AbstractPhaseInterceptor&lt;Message&gt; i
123 throw new AesException(AesException.SIGN_CHECK_FAIL); 133 throw new AesException(AesException.SIGN_CHECK_FAIL);
124 } 134 }
125 135
  136 + ThreadLocalUtils.setPassword(map.get(PASSWORD));
126 validate(map, message); 137 validate(map, message);
127 } 138 }
128 139
129 - private static void validate(Map<String, String> map, Message message) {  
130 - PasswordUser user = userService.get(map.get(PASSWORD)); 140 + private void validate(Map<String, String> map, Message message) {
  141 + String password = map.get(PASSWORD);
  142 + PasswordUser user = userService.get(password);
131 if (user.getResources().size() > 0) { 143 if (user.getResources().size() > 0) {
  144 + loadLimit(password);
132 boolean isMatch = false; 145 boolean isMatch = false;
133 String uri = (String) message.get(Message.REQUEST_URI); 146 String uri = (String) message.get(Message.REQUEST_URI);
134 for (Resource resource : user.getResources()) { 147 for (Resource resource : user.getResources()) {
@@ -143,6 +156,49 @@ public class AuthorizeInterceptor_IN extends AbstractPhaseInterceptor&lt;Message&gt; i @@ -143,6 +156,49 @@ public class AuthorizeInterceptor_IN extends AbstractPhaseInterceptor&lt;Message&gt; i
143 } 156 }
144 } 157 }
145 158
  159 + public void loadLimit(String password) {
  160 + if (!pwd2lines.containsKey(password)) {
  161 + Set<String> set = new HashSet<>();
  162 + try {
  163 + BufferedReader reader = new BufferedReader(new FileReader(pathLimits + String.format("lines-%s.txt", password)));
  164 + String line = null;
  165 + while ((line = reader.readLine()) != null) {
  166 + set.add(line);
  167 + }
  168 + } catch (IOException e) {
  169 + logger.error("加载受限线路信息异常", e);
  170 + } finally {
  171 + pwd2lines.put(password, set);
  172 + }
  173 + }
  174 + if (!pwd2device.containsKey(password)) {
  175 + Set<String> set = new HashSet<>();
  176 + try {
  177 + BufferedReader reader = new BufferedReader(new FileReader(pathLimits + String.format("devices-%s.txt", password)));
  178 + String line = null;
  179 + while ((line = reader.readLine()) != null) {
  180 + set.add(line);
  181 + }
  182 + } catch (IOException e) {
  183 + logger.error("加载受限设备信息异常", e);
  184 + } finally {
  185 + pwd2device.put(password, set);
  186 + }
  187 + }
  188 + }
  189 +
  190 + public Set<String> getLimitLines(String password) {
  191 + return pwd2lines.get(password);
  192 + }
  193 +
  194 + public Set<String> getLimitDevices(String password) {
  195 + return pwd2device.get(password);
  196 + }
  197 +
  198 + public ThreadLocal<String> getPasswords() {
  199 + return passwords;
  200 + }
  201 +
146 public static Map<String, String> multi2One(MultiMap<String> params) { 202 public static Map<String, String> multi2One(MultiMap<String> params) {
147 Map<String, String> map = new HashMap<>(); 203 Map<String, String> map = new HashMap<>();
148 Set<String> ks = params.keySet(); 204 Set<String> ks = params.keySet();
@@ -189,6 +245,7 @@ public class AuthorizeInterceptor_IN extends AbstractPhaseInterceptor&lt;Message&gt; i @@ -189,6 +245,7 @@ public class AuthorizeInterceptor_IN extends AbstractPhaseInterceptor&lt;Message&gt; i
189 245
190 @Override 246 @Override
191 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { 247 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
  248 + logger.error("------------------------------path: {}", pathLimits);
192 userService = applicationContext.getBean(UserService.class); 249 userService = applicationContext.getBean(UserService.class);
193 systemParamService = applicationContext.getBean(SystemParamService.class); 250 systemParamService = applicationContext.getBean(SystemParamService.class);
194 } 251 }
src/main/java/com/bsth/server_rs/base_info/car/Car.java
@@ -69,6 +69,8 @@ public class Car implements Serializable { @@ -69,6 +69,8 @@ public class Car implements Serializable {
69 69
70 private Date updateDate; 70 private Date updateDate;
71 71
  72 + private String vehicleType;
  73 +
72 public String getNbbm() { 74 public String getNbbm() {
73 return nbbm; 75 return nbbm;
74 } 76 }
@@ -180,4 +182,20 @@ public class Car implements Serializable { @@ -180,4 +182,20 @@ public class Car implements Serializable {
180 public void setRemark(String remark) { 182 public void setRemark(String remark) {
181 this.remark = remark; 183 this.remark = remark;
182 } 184 }
  185 +
  186 + public Date getUpdateDate() {
  187 + return updateDate;
  188 + }
  189 +
  190 + public void setUpdateDate(Date updateDate) {
  191 + this.updateDate = updateDate;
  192 + }
  193 +
  194 + public String getVehicleType() {
  195 + return vehicleType;
  196 + }
  197 +
  198 + public void setVehicleType(String vehicleType) {
  199 + this.vehicleType = vehicleType;
  200 + }
183 } 201 }
src/main/java/com/bsth/server_rs/base_info/car/buffer/CarBufferData.java
@@ -22,8 +22,8 @@ public class CarBufferData implements CommandLineRunner { @@ -22,8 +22,8 @@ public class CarBufferData implements CommandLineRunner {
22 22
23 private static List<Car> data; 23 private static List<Car> data;
24 private static Map<String, Car> idMap; 24 private static Map<String, Car> idMap;
25 - private static Map<String, Car> device2car;  
26 private static ArrayListMultimap<String, Car> companyListMap; 25 private static ArrayListMultimap<String, Car> companyListMap;
  26 + private static Map<String, Car> device2car = new HashMap<>();
27 27
28 /** 28 /**
29 * 待入库的bus car 29 * 待入库的bus car
@@ -49,20 +49,25 @@ public class CarBufferData implements CommandLineRunner { @@ -49,20 +49,25 @@ public class CarBufferData implements CommandLineRunner {
49 return companyListMap.get(company); 49 return companyListMap.get(company);
50 } 50 }
51 51
  52 + public static Car findByDevice(String device){
  53 + return device2car.get(device);
  54 + }
  55 +
52 public static void replaceAll(List<Car> newData){ 56 public static void replaceAll(List<Car> newData){
53 data = newData; 57 data = newData;
54 Map<String, Car> idMapCopy = new HashMap<>(); 58 Map<String, Car> idMapCopy = new HashMap<>();
55 - Map<String, Car> device2carCopy = new HashMap<>();  
56 ArrayListMultimap<String, Car> listMap = ArrayListMultimap.create(); 59 ArrayListMultimap<String, Car> listMap = ArrayListMultimap.create();
  60 + Map<String, Car> device2carCopy = new HashMap<>();
57 61
58 for(Car car : data){ 62 for(Car car : data){
59 idMapCopy.put(car.getNbbm(), car); 63 idMapCopy.put(car.getNbbm(), car);
60 - device2carCopy.put(car.getEquipmentCode(), car);  
61 listMap.put(car.getCompanyCode(), car); 64 listMap.put(car.getCompanyCode(), car);
  65 + device2carCopy.put(car.getEquipmentCode(), car);
62 } 66 }
63 idMap = idMapCopy; 67 idMap = idMapCopy;
64 - device2car = device2carCopy; 68 +
65 companyListMap = listMap; 69 companyListMap = listMap;
  70 + device2car = device2carCopy;
66 } 71 }
67 72
68 @Override 73 @Override
src/main/java/com/bsth/server_rs/base_info/car/buffer/CarRefreshThread.java
@@ -29,7 +29,7 @@ public class CarRefreshThread extends Thread{ @@ -29,7 +29,7 @@ public class CarRefreshThread extends Thread{
29 29
30 try { 30 try {
31 31
32 - List<Car> list = jdbcTemplate.query("SELECT DISTINCT t1.*,t2.line_code,t2.name as line_name FROM(SELECT c.inside_code as nbbm,c.business_code as company_code,c.branche_company_code,c.car_plate,c.equipment_code,c.car_type,c.vehicle_stats,c.sfdc,c.scrap_state,c.id_rfid,c.tag_rfid,c.update_date,c2.xl,c2.qyrq FROM bsth_c_cars c LEFT JOIN bsth_c_s_ccinfo c2 ON c.id = c2.cl and c2.is_cancel=0) t1 LEFT JOIN bsth_c_line t2 on t1.xl=t2.id ORDER BY nbbm,qyrq" 32 + List<Car> list = jdbcTemplate.query("SELECT DISTINCT t1.*,t2.line_code,t2.name as line_name FROM(SELECT c.inside_code as nbbm,c.business_code as company_code,c.branche_company_code,c.car_plate,c.equipment_code,c.car_type,c.vehicle_stats,c.sfdc,c.scrap_state,c.id_rfid,c.tag_rfid,c.update_date,c2.xl,c2.qyrq,c.vehicle_type FROM bsth_c_cars c LEFT JOIN bsth_c_s_ccinfo c2 ON c.id = c2.cl and c2.is_cancel=0) t1 LEFT JOIN bsth_c_line t2 on t1.xl=t2.id ORDER BY nbbm,qyrq"
33 , BeanPropertyRowMapper.newInstance(Car.class)); 33 , BeanPropertyRowMapper.newInstance(Car.class));
34 34
35 Map<String, Car> map = new HashMap<>(); 35 Map<String, Car> map = new HashMap<>();
src/main/java/com/bsth/server_rs/base_info/line/Line.java
@@ -123,6 +123,21 @@ public class Line implements Serializable { @@ -123,6 +123,21 @@ public class Line implements Serializable {
123 */ 123 */
124 private Integer inUse; 124 private Integer inUse;
125 125
  126 + /**
  127 + *
  128 + */
  129 + private Date revokeDate;
  130 +
  131 + /**
  132 + * 停车场编码
  133 + */
  134 + private String carPark;
  135 +
  136 + /**
  137 + * 坐标点
  138 + */
  139 + private String coordinates;
  140 +
126 public String getName() { 141 public String getName() {
127 return name; 142 return name;
128 } 143 }
@@ -387,4 +402,28 @@ public class Line implements Serializable { @@ -387,4 +402,28 @@ public class Line implements Serializable {
387 public void setInUse(Integer inUse) { 402 public void setInUse(Integer inUse) {
388 this.inUse = inUse; 403 this.inUse = inUse;
389 } 404 }
  405 +
  406 + public Date getRevokeDate() {
  407 + return revokeDate;
  408 + }
  409 +
  410 + public void setRevokeDate(Date revokeDate) {
  411 + this.revokeDate = revokeDate;
  412 + }
  413 +
  414 + public String getCarPark() {
  415 + return carPark;
  416 + }
  417 +
  418 + public void setCarPark(String carPark) {
  419 + this.carPark = carPark;
  420 + }
  421 +
  422 + public String getCoordinates() {
  423 + return coordinates;
  424 + }
  425 +
  426 + public void setCoordinates(String coordinates) {
  427 + this.coordinates = coordinates;
  428 + }
390 } 429 }
src/main/java/com/bsth/server_rs/dks/ExternalRestService.java
1 package com.bsth.server_rs.dks; 1 package com.bsth.server_rs.dks;
2 2
3 import com.bsth.common.SystemParamKeys; 3 import com.bsth.common.SystemParamKeys;
4 -import com.bsth.redis.ElecRedisService;  
5 -import com.bsth.redis.OilRedisService; 4 +import com.bsth.entity.ScheduleRealInfo;
6 import com.bsth.redis.ScheduleRedisService; 5 import com.bsth.redis.ScheduleRedisService;
7 -import com.bsth.repository.SchedulePlanInfoRepository;  
8 import com.bsth.repository.ScheduleRealInfoRepository; 6 import com.bsth.repository.ScheduleRealInfoRepository;
9 import com.bsth.server_rs.AuthorizeInterceptor_IN; 7 import com.bsth.server_rs.AuthorizeInterceptor_IN;
10 import com.bsth.server_rs.base_info.car.Car; 8 import com.bsth.server_rs.base_info.car.Car;
11 import com.bsth.server_rs.base_info.car.buffer.CarBufferData; 9 import com.bsth.server_rs.base_info.car.buffer.CarBufferData;
  10 +import com.bsth.server_rs.base_info.carpark.Carpark;
  11 +import com.bsth.server_rs.base_info.carpark.buffer.CarparkBufferData;
12 import com.bsth.server_rs.base_info.line.Line; 12 import com.bsth.server_rs.base_info.line.Line;
13 import com.bsth.server_rs.base_info.line.buffer.LineBufferData; 13 import com.bsth.server_rs.base_info.line.buffer.LineBufferData;
  14 +import com.bsth.server_rs.base_info.section.buffer.LD_SectionBufferData;
  15 +import com.bsth.server_rs.base_info.section.entity.LD_SectionRoute;
14 import com.bsth.server_rs.base_info.station.buffer.StationBufferData; 16 import com.bsth.server_rs.base_info.station.buffer.StationBufferData;
15 import com.bsth.server_rs.base_info.station.entity.StationRotue; 17 import com.bsth.server_rs.base_info.station.entity.StationRotue;
  18 +import com.bsth.server_rs.gps.buffer.BasicDataBuffer;
16 import com.bsth.server_rs.gps.buffer.GpsRealDataBuffer; 19 import com.bsth.server_rs.gps.buffer.GpsRealDataBuffer;
  20 +import com.bsth.server_rs.gps.dao.HistoryGpsDao;
17 import com.bsth.server_rs.gps.entity.GpsEntity; 21 import com.bsth.server_rs.gps.entity.GpsEntity;
  22 +import com.bsth.server_rs.gps.entity.HistoryArrivalEntity;
  23 +import com.bsth.server_rs.schedule.dto.ScheduleRealInfoDTO_JK;
18 import com.bsth.service.SystemParamService; 24 import com.bsth.service.SystemParamService;
  25 +import com.bsth.util.ThreadLocalUtils;
  26 +import org.apache.commons.lang3.StringUtils;
  27 +import org.joda.time.DateTime;
  28 +import org.joda.time.format.DateTimeFormat;
  29 +import org.joda.time.format.DateTimeFormatter;
19 import org.slf4j.Logger; 30 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory; 31 import org.slf4j.LoggerFactory;
21 import org.springframework.beans.factory.annotation.Autowired; 32 import org.springframework.beans.factory.annotation.Autowired;
22 -import org.springframework.jdbc.core.JdbcTemplate;  
23 import org.springframework.stereotype.Component; 33 import org.springframework.stereotype.Component;
24 -import org.springframework.web.bind.annotation.PathVariable;  
25 34
26 import javax.ws.rs.GET; 35 import javax.ws.rs.GET;
27 import javax.ws.rs.Path; 36 import javax.ws.rs.Path;
@@ -44,6 +53,21 @@ public class ExternalRestService { @@ -44,6 +53,21 @@ public class ExternalRestService {
44 @Autowired 53 @Autowired
45 private SystemParamService systemParamService; 54 private SystemParamService systemParamService;
46 55
  56 + @Autowired
  57 + private LD_SectionBufferData ldSectionBufferData;
  58 +
  59 + @Autowired
  60 + private HistoryGpsDao historyGpsDao;
  61 +
  62 + @Autowired
  63 + private AuthorizeInterceptor_IN authorizeInterceptorIn;
  64 +
  65 + @Autowired
  66 + private ScheduleRealInfoRepository scheduleRealInfoRepository;
  67 +
  68 + @Autowired
  69 + private ScheduleRedisService scheduleRedisService;
  70 +
47 @GET 71 @GET
48 @Path("/{company}/gps/all") 72 @Path("/{company}/gps/all")
49 public List<GpsEntity> findAllGps(@PathParam("company") String company) { 73 public List<GpsEntity> findAllGps(@PathParam("company") String company) {
@@ -60,4 +84,265 @@ public class ExternalRestService { @@ -60,4 +84,265 @@ public class ExternalRestService {
60 84
61 return result; 85 return result;
62 } 86 }
  87 +
  88 + @GET
  89 + @Path("/line")
  90 + public List<Map<String, Object>> findAllLine() {
  91 + List<Map<String, Object>> result = new ArrayList<>();
  92 + String password = ThreadLocalUtils.getPassword();
  93 + Set<String> limitLines = authorizeInterceptorIn.getLimitLines(password);
  94 + if (limitLines == null || limitLines.isEmpty()) {
  95 + return result;
  96 + }
  97 + for (Line line : LineBufferData.findAll()) {
  98 + String lineCode = line.getLineCode();
  99 + if (limitLines.contains(lineCode) || limitLines.contains("ALL")) {
  100 + Map<String, Object> lineMap = new HashMap<>();
  101 + Collection<LD_SectionRoute> sectionRoutes = ldSectionBufferData.findByLineCode(lineCode).get(String.format("%s_0", lineCode));
  102 + StringBuilder sb = new StringBuilder("");
  103 + if (sectionRoutes != null) {
  104 + for (LD_SectionRoute sectionRoute : sectionRoutes) {
  105 + sb.append(sectionRoute.getSection().getGsectionVector().replace("LINESTRING(", "").replace(")", "")).append(",");
  106 + }
  107 + sb.deleteCharAt(sb.length() - 1);
  108 + }
  109 + lineMap.put("company", BasicDataBuffer.getBusinessByCode(line.getCompany()));
  110 + lineMap.put("branch", BasicDataBuffer.getBusinessByCode(String.format("%s_%s", line.getCompany(), line.getBrancheCompany())));
  111 + lineMap.put("lineName", line.getName());
  112 + lineMap.put("lineCode", line.getShanghaiLinecode());
  113 + lineMap.put("lineCodeExternal", lineCode);
  114 + lineMap.put("startStation", line.getStartStationName());
  115 + lineMap.put("endStation", line.getEndStationName());
  116 + lineMap.put("lineLength", line.getTotalMileage());
  117 + lineMap.put("upSEtime", String.format("%s-%s", line.getStartStationFirstTime(), line.getStartStationEndTime()));
  118 + lineMap.put("upLinelonlat", sb.toString());
  119 + lineMap.put("downSEtime", String.format("%s-%s", line.getEndStationFirstTime(), line.getEndStationEndTime()));
  120 + lineMap.put("downLinelonlat", null);
  121 +
  122 + result.add(lineMap);
  123 + }
  124 + }
  125 +
  126 + return result;
  127 + }
  128 +
  129 + @GET
  130 + @Path("/station")
  131 + public List<Map<String, Object>> findAllStation() {
  132 + List<Map<String, Object>> result = new ArrayList<>();
  133 + String password = ThreadLocalUtils.getPassword();
  134 + Set<String> limitLines = new HashSet<>(authorizeInterceptorIn.getLimitLines(password));
  135 + if (limitLines == null || limitLines.isEmpty()) {
  136 + return result;
  137 + }
  138 + if (limitLines.contains("ALL")) {
  139 + limitLines.clear();
  140 + for (Line line : LineBufferData.findAll()) {
  141 + limitLines.add(line.getLineCode());
  142 + }
  143 + }
  144 + for (String lineCode : limitLines) {
  145 + if (StringUtils.isNotEmpty(lineCode)) {
  146 + Map<String, Object> lineMap = new HashMap<>();
  147 + Line line = LineBufferData.findOne(lineCode);
  148 + lineMap.put("lineName", line.getName());
  149 + lineMap.put("lineCode", line.getShanghaiLinecode());
  150 + lineMap.put("lineCodeExternal", lineCode);
  151 +
  152 + int count = 1;
  153 + List<Map<String, Object>> upStations = new ArrayList<>(), downStations = new ArrayList<>();
  154 + Collection<StationRotue> upStationRoutes = StationBufferData.findRouteByLineCode(lineCode).get(String.format("%s_0", lineCode));
  155 + if (upStationRoutes != null) {
  156 + for (StationRotue route : upStationRoutes) {
  157 + Map<String, Object> stopMap = new HashMap<>();
  158 + stopMap.put("levelNo", count);
  159 + stopMap.put("levelName", route.getStationName());
  160 + stopMap.put("levelLonlat", String.format("%f %f", route.getStation().getLon(), route.getStation().getLat()));
  161 + stopMap.put("stationCode", route.getStationCode());
  162 + upStations.add(stopMap);
  163 + count++;
  164 + }
  165 + }
  166 + count = 1;
  167 + Collection<StationRotue> downStationRoutes = StationBufferData.findRouteByLineCode(lineCode).get(String.format("%s_1", lineCode));
  168 + if (downStationRoutes != null) {
  169 + for (StationRotue route : downStationRoutes) {
  170 + Map<String, Object> stopMap = new HashMap<>();
  171 + stopMap.put("levelNo", count);
  172 + stopMap.put("levelName", route.getStationName());
  173 + stopMap.put("levelLonlat", String.format("%f %f", route.getStation().getLon(), route.getStation().getLat()));
  174 + stopMap.put("stationCode", route.getStationCode());
  175 + downStations.add(stopMap);
  176 + count++;
  177 + }
  178 + }
  179 +
  180 + lineMap.put("upStations", upStations);
  181 + lineMap.put("downStations", downStations);
  182 + result.add(lineMap);
  183 + }
  184 + }
  185 +
  186 + return result;
  187 + }
  188 +
  189 + @GET
  190 + @Path("/vehicle")
  191 + public List<Map<String, Object>> findAllVehicle() {
  192 + List<Map<String, Object>> result = new ArrayList<>();
  193 + Map<String, String> device2line = GpsRealDataBuffer.getDevice2Line();
  194 + String password = ThreadLocalUtils.getPassword();
  195 + Set<String> limitLines = authorizeInterceptorIn.getLimitLines(password);
  196 + Set<String> limitDevices = authorizeInterceptorIn.getLimitDevices(password);
  197 + if (limitLines == null || limitLines.isEmpty()) {
  198 + return result;
  199 + }
  200 + if (limitDevices == null || limitDevices.isEmpty()) {
  201 + return result;
  202 + }
  203 + for (Car car : CarBufferData.findAll()) {
  204 + if (limitDevices.contains(car.getEquipmentCode()) || limitDevices.contains("ALL")) {
  205 + Map<String, Object> carMap = new HashMap<>();
  206 + Line line = LineBufferData.findOne(device2line.get(car.getEquipmentCode()));
  207 + if (line == null || !limitLines.contains(line.getLineCode()) || !limitLines.contains("ALL")) {
  208 + continue;
  209 + }
  210 + carMap.put("lineName", line.getName());
  211 + carMap.put("lineCode", line.getShanghaiLinecode());
  212 + carMap.put("lineCodeExternal", line.getLineCode());
  213 + carMap.put("vehicleId", car.getCarPlate());
  214 + carMap.put("vehicleNo", car.getNbbm());
  215 + carMap.put("vehicleType", car.getVehicleType());
  216 + carMap.put("energyType", car.getSfdc() ? 3 : 0);
  217 +
  218 + result.add(carMap);
  219 + }
  220 + }
  221 +
  222 + return result;
  223 + }
  224 +
  225 + @GET
  226 + @Path("/parking")
  227 + public List<Map<String, Object>> findAllParking() {
  228 + List<Map<String, Object>> result = new ArrayList<>();
  229 + String password = ThreadLocalUtils.getPassword();
  230 + Set<String> limitLines = authorizeInterceptorIn.getLimitLines(password);
  231 + if (limitLines == null || limitLines.isEmpty()) {
  232 + return result;
  233 + }
  234 + StringBuilder sb = new StringBuilder();
  235 + for (Line line : LineBufferData.findAll()) {
  236 + String lineCode = line.getLineCode();
  237 + if (limitLines.contains(lineCode) || limitLines.contains("ALL")) {
  238 + sb.append(line.getCarPark()).append(",");
  239 + }
  240 + }
  241 + String limitParkings = sb.toString();
  242 +
  243 + if (limitParkings.equals("")) {
  244 + return result;
  245 + }
  246 + for (Carpark carpark : CarparkBufferData.findAll()) {
  247 + if (limitParkings.indexOf(String.format("%s,", carpark.getParkCode())) > -1) {
  248 + Map<String, Object> parkMap = new HashMap<>();
  249 + parkMap.put("company", BasicDataBuffer.getBusinessByCode(carpark.getCompany()));
  250 + parkMap.put("parkName", carpark.getParkName());
  251 + parkMap.put("parkAddress", null);
  252 + parkMap.put("parkLonlat", carpark.getgParkPoint());
  253 + result.add(parkMap);
  254 + }
  255 + }
  256 +
  257 + return result;
  258 + }
  259 +
  260 + @GET
  261 + @Path("/gps/all")
  262 + public List<Map<String, Object>> findAllGps() {
  263 + List<Map<String, Object>> result = new ArrayList<>();
  264 + String password = ThreadLocalUtils.getPassword();
  265 + Set<String> limitLines = authorizeInterceptorIn.getLimitLines(password);
  266 + Set<String> limitDevices = authorizeInterceptorIn.getLimitDevices(password);
  267 + if (limitLines == null || limitLines.isEmpty()) {
  268 + return result;
  269 + }
  270 + for (GpsEntity gps : GpsRealDataBuffer.all()) {
  271 + String lineCode = gps.getLineId(), deviceId = gps.getDeviceId();
  272 + if ((limitLines.contains(lineCode) || limitLines.contains("ALL")) && (limitDevices.contains(deviceId) || limitDevices.contains("ALL"))) {
  273 + Line line = LineBufferData.findOne(lineCode);
  274 + Car car = CarBufferData.findByDevice(deviceId);
  275 + if (car == null) {
  276 + continue;
  277 + }
  278 + Map<String, Object> gpsMap = new HashMap<>();
  279 + gpsMap.put("lineName", line.getName());
  280 + gpsMap.put("lineCode", line.getShanghaiLinecode());
  281 + gpsMap.put("lineCodeExternal", line.getLineCode());
  282 + gpsMap.put("vehicleId", car.getCarPlate());
  283 + gpsMap.put("gpsTime", gps.getTimestamp());
  284 + gpsMap.put("gpsLonlat", String.format("%f %f", gps.getLon(), gps.getLat()));
  285 + gpsMap.put("angle", gps.getDirection());
  286 +
  287 + result.add(gpsMap);
  288 + }
  289 + }
  290 +
  291 + return result;
  292 + }
  293 + @GET
  294 + @Path("/history-arrival/{line}/{st}/{et}")
  295 + public List<HistoryArrivalEntity> historyArrival(@PathParam("line") String line, @PathParam("st") String st, @PathParam("et") String et) {
  296 + List<HistoryArrivalEntity> result = new ArrayList<>();
  297 + String password = ThreadLocalUtils.getPassword();
  298 + Set<String> limitLines = authorizeInterceptorIn.getLimitLines(password);
  299 + Set<String> limitDevices = authorizeInterceptorIn.getLimitDevices(password);
  300 + if (limitLines == null || limitLines.isEmpty()) {
  301 + return result;
  302 + }
  303 + if (limitDevices == null || limitDevices.isEmpty()) {
  304 + return result;
  305 + }
  306 + List<HistoryArrivalEntity> arrivals = historyGpsDao.queryArrival(line, Long.parseLong(st), Long.parseLong(et));
  307 + for (HistoryArrivalEntity arrival : arrivals) {
  308 + String lineCode = String.valueOf(arrival.getLineId()), deviceId = arrival.getDeviceId();
  309 + Line line1 = LineBufferData.findOne(lineCode);
  310 + if (line1 == null) {
  311 + continue;
  312 + }
  313 + arrival.setLineName(line1.getName());
  314 + if ((limitLines.contains(lineCode) || limitLines.contains("ALL")) && (limitDevices.contains(deviceId) || limitDevices.contains("ALL"))) {
  315 + result.add(arrival);
  316 + }
  317 + }
  318 +
  319 + return result;
  320 + }
  321 +
  322 + @GET
  323 + @Path("/waybill/{company}/{rq}")
  324 + public List<ScheduleRealInfoDTO_JK> sch_jk(@PathParam("company") String company, @PathParam("rq") String rq) {
  325 + DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyyMMdd");
  326 + DateTime dateTime = fmt.parseDateTime(rq);
  327 + if (!dateTime.isBefore(DateTime.now().withTimeAtStartOfDay())) {
  328 + return new ArrayList<>();
  329 + }
  330 + List<ScheduleRealInfo> scheduleRealInfos = scheduleRealInfoRepository.findByDateAndCompany(dateTime.toString("yyyy-MM-dd"), company);
  331 + scheduleRedisService.calcTime(scheduleRealInfos);
  332 + List<ScheduleRealInfoDTO_JK> result = ScheduleRealInfoDTO_JK.getMultiInstance(scheduleRealInfos);
  333 + for (ScheduleRealInfoDTO_JK jk : result) {
  334 + if (jk.getZdsjActualTime() == null) {
  335 + jk.setZdsjActualTime(jk.getZdsjT());
  336 + }
  337 + }
  338 +
  339 + return result;
  340 + }
  341 +
  342 + @GET
  343 + @Path("/limits/reload")
  344 + public void reload() {
  345 + String password = ThreadLocalUtils.getPassword();
  346 + authorizeInterceptorIn.loadLimit(password);
  347 + }
63 } 348 }
src/main/java/com/bsth/server_rs/gps/buffer/BasicDataBuffer.java
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<Integer> getAllLine() {  
34 - return LINEID_INFO.keySet();  
35 - }  
36 -  
37 - public static LineInfo getLineById(Integer lineId) {  
38 - return LINEID_INFO.get(lineId);  
39 - }  
40 -} 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 + private static Map<String, String> BCODE_NAME = new HashMap<>();
  22 +
  23 + public static void putLine(Integer lineId, LineInfo info) {
  24 + LINEID_INFO.put(lineId, info);
  25 + }
  26 +
  27 + public static void putCar(String deviceId, String plateNo) {
  28 + DEVICE_PLATE.put(deviceId, plateNo);
  29 + }
  30 +
  31 + public static String getPlateByDevice(String deviceId) {
  32 + return DEVICE_PLATE.get(deviceId);
  33 + }
  34 +
  35 + public static Set<Integer> getAllLine() {
  36 + return LINEID_INFO.keySet();
  37 + }
  38 +
  39 + public static LineInfo getLineById(Integer lineId) {
  40 + return LINEID_INFO.get(lineId);
  41 + }
  42 +
  43 + public static void putBusiness(String code, String name) {
  44 + BCODE_NAME.put(code, name);
  45 + }
  46 +
  47 + public static String getBusinessByCode(String code) {
  48 + return BCODE_NAME.get(code);
  49 + }
  50 +}
src/main/java/com/bsth/server_rs/gps/buffer/BasicDataRefreshThread.java
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.InitializingBean;  
12 -import org.springframework.beans.factory.annotation.Autowired;  
13 -import org.springframework.jdbc.core.JdbcTemplate;  
14 -import org.springframework.jdbc.core.RowMapper;  
15 -import org.springframework.stereotype.Component;  
16 -  
17 -import com.bsth.server_rs.gps.entity.LineInfo;  
18 -import com.bsth.server_rs.gps.entity.Point;  
19 -import com.bsth.server_rs.gps.entity.StopInfo;  
20 -  
21 -/**  
22 - * Created by panzhao on 2017/3/30.  
23 - */  
24 -@Component  
25 -public class BasicDataRefreshThread extends Thread implements InitializingBean {  
26 -  
27 - Logger logger = LoggerFactory.getLogger(this.getClass());  
28 -  
29 - @Autowired  
30 - private JdbcTemplate jdbcTemplate;  
31 -  
32 - @Override  
33 - public void run() {  
34 - loadBasicData();  
35 - }  
36 -  
37 - private void loadBasicData() {  
38 - try {  
39 - String qline = "select a.id,in_use,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 and a.nature = 'hlwgj'";  
40 - 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";  
41 - String qcar = "select equipment_code device_id, car_plate plate_no from bsth_c_cars";  
42 -  
43 - List<LineInfo> lines = jdbcTemplate.query(qline, new RowMapperLineInfo());  
44 - List<StopInfo> stops = jdbcTemplate.query(qstop, new RowMapperStopInfo());  
45 - List<Map<String, Object>> cars = jdbcTemplate.queryForList(qcar);  
46 -  
47 - // 缓存线路基本信息  
48 - for (LineInfo line : lines) {  
49 - BasicDataBuffer.putLine(line.getLineId(), line);  
50 - }  
51 -  
52 - // 线路信息中添加上下行站点信息  
53 - int oldId = -1;  
54 - LineInfo line = null;  
55 - for (StopInfo stop : stops) {  
56 - if (stop.getLineCode() != oldId) {  
57 - oldId = stop.getLineCode();  
58 - line = BasicDataBuffer.getLineById(oldId);  
59 - }  
60 - if (line != null) {  
61 - if (stop.getDirections() == 0) line.getStopsUp().add(stop);  
62 - else line.getStopsDown().add(stop);  
63 - }  
64 - }  
65 -  
66 - for (Map<String, Object> car : cars) {  
67 - BasicDataBuffer.putCar((String)car.get("device_id"), (String)car.get("plate_no"));  
68 - }  
69 -  
70 - logger.info("基础数据加载成功");  
71 - }catch (Exception e){  
72 - logger.error("基础数据加载失败", e);  
73 - }  
74 - }  
75 -  
76 - final class RowMapperLineInfo implements RowMapper<LineInfo> {  
77 -  
78 - @Override  
79 - public LineInfo mapRow(ResultSet rs, int rowNum) throws SQLException {  
80 - // TODO Auto-generated method stub  
81 - LineInfo line = new LineInfo();  
82 - line.setId(rs.getInt("id"));  
83 - line.setInUse(rs.getInt("in_use"));  
84 - line.setLineId(rs.getInt("line_code"));  
85 - line.setLineName(rs.getString("name"));  
86 - //line.setStartStation(rs.getInt("start_station"));  
87 - line.setStartStationName(rs.getString("start_station_name"));  
88 - line.setStartStationFirstTime(rs.getString("start_station_first_time"));  
89 - line.setStartStationEndTime(rs.getString("start_station_end_time"));  
90 - //line.setEndStation(rs.getInt("end_station"));  
91 - line.setEndStationName(rs.getString("end_station_name"));  
92 - line.setEndStationFirstTime(rs.getString("end_station_first_time"));  
93 - line.setEndStationEndTime(rs.getString("end_station_end_time"));  
94 - line.setCompany(rs.getString("company"));  
95 - line.setBrancheCompany(rs.getString("branche_company"));  
96 - line.setTelephone(rs.getString("telephone"));  
97 - line.setLinePlayType(rs.getInt("line_play_type"));  
98 - return line;  
99 - }  
100 -  
101 - }  
102 -  
103 - final class RowMapperStopInfo implements RowMapper<StopInfo> {  
104 -  
105 - @Override  
106 - public StopInfo mapRow(ResultSet rs, int rowNum) throws SQLException {  
107 - // TODO Auto-generated method stub  
108 - StopInfo stop = new StopInfo();  
109 - stop.setId(rs.getInt("id"));  
110 - stop.setStationCod(rs.getString("station_cod"));  
111 - stop.setStationName(rs.getString("station_name"));  
112 - //stop.setStationType(rs.getString("station_type"));  
113 - stop.setRoadCoding(rs.getString("road_coding"));  
114 - float lon = rs.getFloat("g_lonx");  
115 - float lat = rs.getFloat("g_laty");  
116 - stop.setPoint(new Point(lon, lat));  
117 - stop.setLineId(rs.getInt("line"));  
118 - stop.setLineCode(rs.getInt("line_code"));  
119 - stop.setDirections(rs.getInt("directions"));  
120 - stop.setShapesType(rs.getString("shapes_type"));  
121 - stop.setRadius(rs.getInt("radius"));  
122 - stop.setPoints(new ArrayList<Point>());  
123 - stop.setDistances(rs.getDouble("distances")*1000);  
124 - return stop;  
125 - }  
126 -  
127 - }  
128 -  
129 - @Override  
130 - public void afterPropertiesSet() throws Exception {  
131 - // TODO Auto-generated method stub  
132 - loadBasicData();  
133 - }  
134 -} 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.InitializingBean;
  12 +import org.springframework.beans.factory.annotation.Autowired;
  13 +import org.springframework.jdbc.core.JdbcTemplate;
  14 +import org.springframework.jdbc.core.RowMapper;
  15 +import org.springframework.stereotype.Component;
  16 +
  17 +import com.bsth.server_rs.gps.entity.LineInfo;
  18 +import com.bsth.server_rs.gps.entity.Point;
  19 +import com.bsth.server_rs.gps.entity.StopInfo;
  20 +
  21 +/**
  22 + * Created by panzhao on 2017/3/30.
  23 + */
  24 +@Component
  25 +public class BasicDataRefreshThread extends Thread implements InitializingBean {
  26 +
  27 + Logger logger = LoggerFactory.getLogger(this.getClass());
  28 +
  29 + @Autowired
  30 + private JdbcTemplate jdbcTemplate;
  31 +
  32 + @Override
  33 + public void run() {
  34 + loadBasicData();
  35 + }
  36 +
  37 + private void loadBasicData() {
  38 + try {
  39 + String qline = "select a.id,in_use,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 and a.nature = 'hlwgj'";
  40 + 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";
  41 + String qcar = "select equipment_code device_id, car_plate plate_no from bsth_c_cars";
  42 + String qbusiness = "select business_code, up_code, business_name from bsth_c_business where up_code <> 0";
  43 +
  44 + List<LineInfo> lines = jdbcTemplate.query(qline, new RowMapperLineInfo());
  45 + List<StopInfo> stops = jdbcTemplate.query(qstop, new RowMapperStopInfo());
  46 + List<Map<String, Object>> cars = jdbcTemplate.queryForList(qcar);
  47 + List<Map<String, Object>> businesses = jdbcTemplate.queryForList(qbusiness);
  48 +
  49 + // 缓存线路基本信息
  50 + for (LineInfo line : lines) {
  51 + BasicDataBuffer.putLine(line.getLineId(), line);
  52 + }
  53 +
  54 + // 线路信息中添加上下行站点信息
  55 + int oldId = -1;
  56 + LineInfo line = null;
  57 + for (StopInfo stop : stops) {
  58 + if (stop.getLineCode() != oldId) {
  59 + oldId = stop.getLineCode();
  60 + line = BasicDataBuffer.getLineById(oldId);
  61 + }
  62 + if (line != null) {
  63 + if (stop.getDirections() == 0) line.getStopsUp().add(stop);
  64 + else line.getStopsDown().add(stop);
  65 + }
  66 + }
  67 +
  68 + for (Map<String, Object> car : cars) {
  69 + BasicDataBuffer.putCar((String)car.get("device_id"), (String)car.get("plate_no"));
  70 + }
  71 +
  72 + for (Map<String, Object> business : businesses) {
  73 + String businessCode = (String)business.get("business_code"), upCode = (String)business.get("up_code"), businessName = (String)business.get("business_name");
  74 + if ("88".equals(upCode)) {
  75 + BasicDataBuffer.putBusiness(businessCode, businessName);
  76 + } else {
  77 + BasicDataBuffer.putBusiness(String.format("%s_%s", upCode, businessCode), businessName);
  78 + }
  79 + }
  80 +
  81 + logger.info("基础数据加载成功");
  82 + }catch (Exception e){
  83 + logger.error("基础数据加载失败", e);
  84 + }
  85 + }
  86 +
  87 + final class RowMapperLineInfo implements RowMapper<LineInfo> {
  88 +
  89 + @Override
  90 + public LineInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
  91 + // TODO Auto-generated method stub
  92 + LineInfo line = new LineInfo();
  93 + line.setId(rs.getInt("id"));
  94 + line.setInUse(rs.getInt("in_use"));
  95 + line.setLineId(rs.getInt("line_code"));
  96 + line.setLineName(rs.getString("name"));
  97 + //line.setStartStation(rs.getInt("start_station"));
  98 + line.setStartStationName(rs.getString("start_station_name"));
  99 + line.setStartStationFirstTime(rs.getString("start_station_first_time"));
  100 + line.setStartStationEndTime(rs.getString("start_station_end_time"));
  101 + //line.setEndStation(rs.getInt("end_station"));
  102 + line.setEndStationName(rs.getString("end_station_name"));
  103 + line.setEndStationFirstTime(rs.getString("end_station_first_time"));
  104 + line.setEndStationEndTime(rs.getString("end_station_end_time"));
  105 + line.setCompany(rs.getString("company"));
  106 + line.setBrancheCompany(rs.getString("branche_company"));
  107 + line.setTelephone(rs.getString("telephone"));
  108 + line.setLinePlayType(rs.getInt("line_play_type"));
  109 + return line;
  110 + }
  111 +
  112 + }
  113 +
  114 + final class RowMapperStopInfo implements RowMapper<StopInfo> {
  115 +
  116 + @Override
  117 + public StopInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
  118 + // TODO Auto-generated method stub
  119 + StopInfo stop = new StopInfo();
  120 + stop.setId(rs.getInt("id"));
  121 + stop.setStationCod(rs.getString("station_cod"));
  122 + stop.setStationName(rs.getString("station_name"));
  123 + //stop.setStationType(rs.getString("station_type"));
  124 + stop.setRoadCoding(rs.getString("road_coding"));
  125 + float lon = rs.getFloat("g_lonx");
  126 + float lat = rs.getFloat("g_laty");
  127 + stop.setPoint(new Point(lon, lat));
  128 + stop.setLineId(rs.getInt("line"));
  129 + stop.setLineCode(rs.getInt("line_code"));
  130 + stop.setDirections(rs.getInt("directions"));
  131 + stop.setShapesType(rs.getString("shapes_type"));
  132 + stop.setRadius(rs.getInt("radius"));
  133 + stop.setPoints(new ArrayList<Point>());
  134 + stop.setDistances(rs.getDouble("distances")*1000);
  135 + return stop;
  136 + }
  137 +
  138 + }
  139 +
  140 + @Override
  141 + public void afterPropertiesSet() throws Exception {
  142 + // TODO Auto-generated method stub
  143 + loadBasicData();
  144 + }
  145 +}
src/main/java/com/bsth/server_rs/gps/buffer/GpsRealDataBuffer.java
1 -package com.bsth.server_rs.gps.buffer;  
2 -  
3 -import com.bsth.server_rs.gps.entity.GpsEntity;  
4 -import org.springframework.beans.factory.annotation.Autowired;  
5 -import org.springframework.stereotype.Component;  
6 -  
7 -import java.util.Collection;  
8 -import java.util.HashMap;  
9 -import java.util.Map;  
10 -  
11 -/**  
12 - * Created by panzhao on 2017/3/30.  
13 - */  
14 -@Component  
15 -public class GpsRealDataBuffer {  
16 -  
17 - private static Map<String, GpsEntity> realMap;  
18 -  
19 - @Autowired  
20 - GpsRefreshThread gpsRefreshThread;  
21 -  
22 - static{  
23 - realMap = new HashMap<>();  
24 - }  
25 -  
26 - public static void put(GpsEntity gps){  
27 - realMap.put(gps.getDeviceId(), gps);  
28 - }  
29 -  
30 - public static GpsEntity get(String device){  
31 - return realMap.get(device);  
32 - }  
33 -  
34 - public static Collection<GpsEntity> all(){  
35 - return realMap.values();  
36 - }  
37 -} 1 +package com.bsth.server_rs.gps.buffer;
  2 +
  3 +import com.bsth.server_rs.gps.entity.GpsEntity;
  4 +import org.springframework.beans.factory.annotation.Autowired;
  5 +import org.springframework.stereotype.Component;
  6 +
  7 +import java.util.Collection;
  8 +import java.util.HashMap;
  9 +import java.util.Map;
  10 +
  11 +/**
  12 + * Created by panzhao on 2017/3/30.
  13 + */
  14 +@Component
  15 +public class GpsRealDataBuffer {
  16 +
  17 + private static Map<String, GpsEntity> realMap = new HashMap<>();
  18 +
  19 + private static Map<String, String> device2line = new HashMap<>();
  20 +
  21 + @Autowired
  22 + GpsRefreshThread gpsRefreshThread;
  23 +
  24 + public static void put(GpsEntity gps){
  25 + realMap.put(gps.getDeviceId(), gps);
  26 + }
  27 +
  28 + public static GpsEntity get(String device){
  29 + return realMap.get(device);
  30 + }
  31 +
  32 + public static Collection<GpsEntity> all(){
  33 + return realMap.values();
  34 + }
  35 +
  36 + public static void putLineCode(String device, String lineCode){
  37 + device2line.put(device, lineCode);
  38 + }
  39 +
  40 + public static String getLineCodeByDevice(String device){
  41 + return device2line.get(device);
  42 + }
  43 +
  44 + public static Map<String, String> getDevice2Line(){
  45 + return device2line;
  46 + }
  47 +}
src/main/java/com/bsth/server_rs/gps/buffer/GpsRefreshThread.java
@@ -68,6 +68,7 @@ public class GpsRefreshThread extends Thread{ @@ -68,6 +68,7 @@ public class GpsRefreshThread extends Thread{
68 gps.setNbbm(car.getNbbm()); 68 gps.setNbbm(car.getNbbm());
69 } 69 }
70 GpsRealDataBuffer.put(gps); 70 GpsRealDataBuffer.put(gps);
  71 + GpsRealDataBuffer.putLineCode(gps.getDeviceId(), gps.getLineId());
71 } 72 }
72 }catch (Exception e){ 73 }catch (Exception e){
73 logger.error("", e); 74 logger.error("", e);
src/main/java/com/bsth/server_rs/gps/dao/HistoryGpsDao.java
1 -package com.bsth.server_rs.gps.dao;  
2 -  
3 -import com.bsth.redis.util.DateUtils;  
4 -import com.bsth.server_rs.base_info.car.Car;  
5 -import com.bsth.server_rs.base_info.car.buffer.CarBufferData;  
6 -import com.bsth.server_rs.gps.entity.DeviceChange;  
7 -import com.bsth.server_rs.gps.entity.HistoryGpsEntity;  
8 -import com.bsth.util.DBUtils_MS;  
9 -import org.apache.commons.lang3.StringUtils;  
10 -import org.joda.time.format.DateTimeFormat;  
11 -import org.joda.time.format.DateTimeFormatter;  
12 -import org.slf4j.Logger;  
13 -import org.slf4j.LoggerFactory;  
14 -import org.springframework.beans.factory.annotation.Autowired;  
15 -import org.springframework.jdbc.core.BeanPropertyRowMapper;  
16 -import org.springframework.jdbc.core.JdbcTemplate;  
17 -import org.springframework.stereotype.Component;  
18 -  
19 -import java.util.*;  
20 -  
21 -/**  
22 - * Created by panzhao on 2017/8/31.  
23 - */  
24 -@Component  
25 -public class HistoryGpsDao {  
26 -  
27 - Logger logger = LoggerFactory.getLogger(this.getClass());  
28 -  
29 - @Autowired  
30 - JdbcTemplate jdbcTemplate;  
31 -  
32 - /**  
33 - * 最大查询间隔  
34 - */  
35 - private static final long GPS_RANGE = 1000 * 60 * 60 * 24;  
36 -  
37 - private static DateTimeFormatter fmtyyyy = DateTimeFormat.forPattern("yyyy");  
38 -  
39 - public Collection<Map<String, Object>> query(String nbbm, Long st, Long et) {  
40 - List<Map<String, Object>> list = new ArrayList<>();  
41 - if (et - st > GPS_RANGE)  
42 - return list;  
43 -  
44 - // day_of_year 分区字段  
45 - Calendar sCal = Calendar.getInstance();  
46 - sCal.setTime(new Date(st));  
47 - int sDayOfYear = sCal.get(Calendar.DAY_OF_YEAR);  
48 - Calendar eCal = Calendar.getInstance();  
49 - eCal.setTime(new Date(et));  
50 - int eDayOfYear = eCal.get(Calendar.DAY_OF_YEAR);  
51 -  
52 - List<DeviceChange> dcs = findDeviceChangeLogs(nbbm, et, st);  
53 -  
54 - //按年分表  
55 - String tableName = "bsth_c_gps_info_" + fmtyyyy.print(st);  
56 -  
57 - StringBuilder sql = new StringBuilder("");  
58 - long t1,t2;  
59 - DeviceChange dc;  
60 - for(int i = 0,len=dcs.size(); i < len; i++){  
61 - t1 = st;  
62 - t2 = et;  
63 - dc = dcs.get(i);  
64 - if(dc.getSt() > st)  
65 - t1 = dc.getSt();  
66 - if(dc.getEt() < et && dc.getEt()!=0)  
67 - t2 = dc.getEt();  
68 -  
69 - sql.append("select DEVICE_ID,LON,LAT,TS,INOUT_STOP,SERVICE_STATE ,STOP_NO,DIRECTION,LINE_ID,SPEED_GPS,SECTION_CODE from "+tableName+" where days_year in ("+sDayOfYear+","+eDayOfYear+") " +  
70 - " and device_id='"+dc.getDevice()+"' and ts >= "+t1+" and ts <= "+t2+" ");  
71 -  
72 - if(i == len - 1)  
73 - sql.append(" ORDER BY device_id,ts,stop_no");  
74 - else  
75 - sql.append(" UNION ");  
76 - }  
77 -  
78 - logger.info("轨迹回放 nbbm: " + nbbm + " -st: " + st + " -et: " + et + " -sql: " + sql.toString());  
79 -  
80 - //查询GPS数据  
81 - JdbcTemplate jdbcTemplate_ms = new JdbcTemplate(DBUtils_MS.getDataSource());  
82 - List<Map<String, Object>> dataList = jdbcTemplate_ms.queryForList(sql.toString());  
83 -  
84 - Float lon, lat;  
85 - int inOutStop;  
86 - long serviceState;  
87 -  
88 - Map<String, Object> map;  
89 - for(Map<String, Object> rs : dataList){  
90 - serviceState = map_get_long(rs, "SERVICE_STATE");  
91 - if(getGpsValid(serviceState) == 1)  
92 - continue;  
93 -  
94 - map = new HashMap<>();  
95 -  
96 - lon = map_get_float(rs, "LON");  
97 - lat = map_get_float(rs, "LAT");  
98 - //原始坐标  
99 - map.put("lon", lon);  
100 - map.put("lat", lat);  
101 -  
102 - map.put("deviceId", map_get_str(rs, "DEVICE_ID"));  
103 - map.put("ts", map_get_long(rs, "TS"));  
104 - map.put("timestamp", map_get_long(rs, "TS"));  
105 - map.put("stopNo", map_get_str(rs, "STOP_NO"));  
106 - map.put("direction", map_get_float(rs,"DIRECTION"));  
107 -  
108 - map.put("lineId", map_get_str(rs, "LINE_ID"));  
109 - map.put("speed", map_get_float(rs,"SPEED_GPS"));  
110 -  
111 - inOutStop = Integer.parseInt(rs.get("INOUT_STOP").toString());  
112 - map.put("inout_stop", inOutStop);  
113 -  
114 -  
115 - map.put("nbbm", nbbm);  
116 - map.put("state", getService(serviceState));  
117 - // 上下行  
118 - map.put("upDown", getUpOrDown(serviceState));  
119 - //路段编码  
120 - map.put("section_code", map_get_str(rs,"SECTION_CODE"));  
121 - list.add(map);  
122 - }  
123 - // 按时间排序  
124 - Collections.sort(list, new Comparator<Map<String, Object>>() {  
125 -  
126 - @Override  
127 - public int compare(Map<String, Object> o1, Map<String, Object> o2) {  
128 - return (int) (Long.parseLong(o1.get("ts").toString()) - Long.parseLong(o2.get("ts").toString()));  
129 - }  
130 - });  
131 -  
132 - return list;  
133 - }  
134 -  
135 -  
136 - private List<DeviceChange> findDeviceChangeLogs(String nbbm, long et, long st){  
137 - List<DeviceChange> dcs = null;  
138 - List<DeviceChange> rs = new ArrayList<>();  
139 - try{  
140 -  
141 - dcs = jdbcTemplate.query("select cl_zbh as nbbm,new_device_no as device,old_device_no as old_device,UNIX_TIMESTAMP(qyrq) * 1000 as st from bsth_c_car_device where is_cancel=0 and cl_zbh='"+nbbm+"' order by qyrq"  
142 - , BeanPropertyRowMapper.newInstance(DeviceChange.class));  
143 -  
144 -  
145 - //生成一条初始记录  
146 - if(dcs.size() > 0){  
147 - DeviceChange first = dcs.get(0);  
148 -  
149 - DeviceChange initDv = new DeviceChange();  
150 - initDv.setDevice(first.getOldDevice());  
151 - if(StringUtils.isNotEmpty(initDv.getDevice())){  
152 - initDv.setNbbm(first.getNbbm());  
153 - initDv.setSt(0);  
154 - initDv.setEt(first.getSt());  
155 - dcs.add(0, initDv);  
156 - }  
157 - }  
158 - for(int i = 0,len=dcs.size(); i < len - 1; i++){  
159 - dcs.get(i).setEt(dcs.get(i + 1).getSt());  
160 - }  
161 -  
162 - for(DeviceChange dc : dcs){  
163 - if(dc.getEt() < st && dc.getEt() != 0)  
164 - continue;  
165 - if(dc.getSt() > et)  
166 - continue;  
167 -  
168 - rs.add(dc);  
169 - }  
170 -  
171 - //没有设备变更记录,则参考车辆信息上的设备号  
172 - if(null == rs || rs.size() == 0){  
173 - Car car = CarBufferData.findOne(nbbm);  
174 -  
175 - if(null != car){  
176 - DeviceChange dc = new DeviceChange();  
177 - dc.setNbbm(nbbm);  
178 - dc.setDevice(car.getEquipmentCode());  
179 - dc.setSt(st);  
180 - dc.setEt(et);  
181 - dc.setType(1);  
182 -  
183 - rs.add(dc);  
184 - }  
185 - }  
186 - }catch (Exception e){  
187 - logger.error("", e);  
188 - }  
189 - return rs;  
190 - }  
191 -  
192 - private static DateTimeFormatter fmtyyyyMMdd = DateTimeFormat.forPattern("yyyy-MM-dd");  
193 - private List<HistoryGpsEntity> query(String deviceId, Calendar sCal, Calendar eCal) {  
194 - int sDayOfYear = sCal.get(Calendar.DAY_OF_YEAR);  
195 - int eDayOfYear = eCal.get(Calendar.DAY_OF_YEAR);  
196 - long st = sCal.getTimeInMillis();  
197 - long et = eCal.getTimeInMillis();  
198 -  
199 - List<HistoryGpsEntity> list = new ArrayList<>();  
200 - // 如果是同一天  
201 - if (sDayOfYear == eDayOfYear) {  
202 - list = query(sDayOfYear, st, et, deviceId);  
203 - } else {  
204 - // 跨天  
205 - Long tempSt, tempEt;  
206 - for (int i = sDayOfYear; i <= eDayOfYear; i++) {  
207 -  
208 - if (i == sDayOfYear) {  
209 - tempSt = st;  
210 - tempEt = fmtyyyyMMdd.parseMillis(fmtyyyyMMdd.print(tempSt)) + 1000 * 60 * 60 * 24;  
211 - } else if (i == eDayOfYear) {  
212 - tempSt = fmtyyyyMMdd.parseMillis(fmtyyyyMMdd.print(et));  
213 - tempEt = et;  
214 - } else {  
215 - tempSt = DateUtils.getTimesmorning(sCal) * 1000;  
216 - tempEt = DateUtils.getTimesnight(sCal);  
217 - }  
218 -  
219 - list.addAll(query(sDayOfYear, tempSt, tempEt, deviceId));  
220 - // 加一天  
221 - sCal.add(Calendar.DATE, 1);  
222 - }  
223 - }  
224 - return list;  
225 - }  
226 -  
227 - private List<HistoryGpsEntity> query(int dayOfYear, Long st, Long et, String deviceId) {  
228 - String sql = "select device_id,line_id,service_state,direction,lon,lat,ts,stop_no,speed_gps as speed,inout_stop,section_code from bsth_c_gps_info where days_year=" + dayOfYear + " and device_id='"+deviceId+"' and ts > " + st + " and ts < " + et;  
229 -  
230 - JdbcTemplate jdbcTemplate = new JdbcTemplate(DBUtils_MS.getDataSource());  
231 - List<HistoryGpsEntity> list = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(HistoryGpsEntity.class));  
232 - return list;  
233 - }  
234 -  
235 - /**  
236 - * 王通 2016/6/29 9:23:24 获取车辆线路上下行  
237 - *  
238 - * @return -1无效 0上行 1下行  
239 - */  
240 - private static byte getUpOrDown(long serviceState) {  
241 - if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000  
242 - || (serviceState & 0x01000000) == 0x01000000 || (serviceState & 0x08000000) == 0x08000000)  
243 - return -1;  
244 - return (byte) (((serviceState & 0x10000000) == 0x10000000) ? 1 : 0);  
245 - }  
246 -  
247 - /**  
248 - * 获取运营状态  
249 - *  
250 - * @return -1无效 0运营 1未运营  
251 - */  
252 - private static byte getService(long serviceState) {  
253 - if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000)  
254 - return -1;  
255 - return (byte) (((serviceState & 0x02000000) == 0x02000000) ? 1 : 0);  
256 - }  
257 -  
258 - private String map_get_str(Map<String, Object> map, String key){  
259 - return map.containsKey(key)?map.get(key).toString():"";  
260 - }  
261 -  
262 - private Long map_get_long(Map<String, Object> map, String key){  
263 - return map.containsKey(key)?Long.parseLong(map.get(key).toString()):-1;  
264 - }  
265 -  
266 - private Float map_get_float(Map<String, Object> map, String key){  
267 - return map.containsKey(key)?Float.parseFloat(map.get(key).toString()):-1;  
268 - }  
269 -  
270 - public static byte getGpsValid(long serviceState) {  
271 - return (byte)(((serviceState & 0x80000000) == 0x80000000) ? 1 : 0);  
272 - }  
273 -} 1 +package com.bsth.server_rs.gps.dao;
  2 +
  3 +import com.bsth.redis.util.DateUtils;
  4 +import com.bsth.server_rs.base_info.car.Car;
  5 +import com.bsth.server_rs.base_info.car.buffer.CarBufferData;
  6 +import com.bsth.server_rs.gps.entity.DeviceChange;
  7 +import com.bsth.server_rs.gps.entity.HistoryArrivalEntity;
  8 +import com.bsth.server_rs.gps.entity.HistoryGpsEntity;
  9 +import com.bsth.util.DBUtils_MS;
  10 +import org.apache.commons.lang3.StringUtils;
  11 +import org.joda.time.format.DateTimeFormat;
  12 +import org.joda.time.format.DateTimeFormatter;
  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.stereotype.Component;
  19 +
  20 +import java.util.*;
  21 +
  22 +/**
  23 + * Created by panzhao on 2017/8/31.
  24 + */
  25 +@Component
  26 +public class HistoryGpsDao {
  27 +
  28 + Logger logger = LoggerFactory.getLogger(this.getClass());
  29 +
  30 + @Autowired
  31 + JdbcTemplate jdbcTemplate;
  32 +
  33 + /**
  34 + * 最大查询间隔
  35 + */
  36 + private static final long GPS_RANGE = 1000 * 60 * 60 * 24;
  37 +
  38 + private static DateTimeFormatter fmtyyyy = DateTimeFormat.forPattern("yyyy");
  39 +
  40 + public Collection<Map<String, Object>> query(String nbbm, Long st, Long et) {
  41 + List<Map<String, Object>> list = new ArrayList<>();
  42 + if (et - st > GPS_RANGE)
  43 + return list;
  44 +
  45 + // day_of_year 分区字段
  46 + Calendar sCal = Calendar.getInstance();
  47 + sCal.setTime(new Date(st));
  48 + int sDayOfYear = sCal.get(Calendar.DAY_OF_YEAR);
  49 + Calendar eCal = Calendar.getInstance();
  50 + eCal.setTime(new Date(et));
  51 + int eDayOfYear = eCal.get(Calendar.DAY_OF_YEAR);
  52 +
  53 + List<DeviceChange> dcs = findDeviceChangeLogs(nbbm, et, st);
  54 +
  55 + //按年分表
  56 + String tableName = "bsth_c_gps_info_" + fmtyyyy.print(st);
  57 +
  58 + StringBuilder sql = new StringBuilder("");
  59 + long t1,t2;
  60 + DeviceChange dc;
  61 + for(int i = 0,len=dcs.size(); i < len; i++){
  62 + t1 = st;
  63 + t2 = et;
  64 + dc = dcs.get(i);
  65 + if(dc.getSt() > st)
  66 + t1 = dc.getSt();
  67 + if(dc.getEt() < et && dc.getEt()!=0)
  68 + t2 = dc.getEt();
  69 +
  70 + sql.append("select DEVICE_ID,LON,LAT,TS,INOUT_STOP,SERVICE_STATE ,STOP_NO,DIRECTION,LINE_ID,SPEED_GPS,SECTION_CODE from "+tableName+" where days_year in ("+sDayOfYear+","+eDayOfYear+") " +
  71 + " and device_id='"+dc.getDevice()+"' and ts >= "+t1+" and ts <= "+t2+" ");
  72 +
  73 + if(i == len - 1)
  74 + sql.append(" ORDER BY device_id,ts,stop_no");
  75 + else
  76 + sql.append(" UNION ");
  77 + }
  78 +
  79 + logger.info("轨迹回放 nbbm: " + nbbm + " -st: " + st + " -et: " + et + " -sql: " + sql.toString());
  80 +
  81 + //查询GPS数据
  82 + JdbcTemplate jdbcTemplate_ms = new JdbcTemplate(DBUtils_MS.getDataSource());
  83 + List<Map<String, Object>> dataList = jdbcTemplate_ms.queryForList(sql.toString());
  84 +
  85 + Float lon, lat;
  86 + int inOutStop;
  87 + long serviceState;
  88 +
  89 + Map<String, Object> map;
  90 + for(Map<String, Object> rs : dataList){
  91 + serviceState = map_get_long(rs, "SERVICE_STATE");
  92 + if(getGpsValid(serviceState) == 1)
  93 + continue;
  94 +
  95 + map = new HashMap<>();
  96 +
  97 + lon = map_get_float(rs, "LON");
  98 + lat = map_get_float(rs, "LAT");
  99 + //原始坐标
  100 + map.put("lon", lon);
  101 + map.put("lat", lat);
  102 +
  103 + map.put("deviceId", map_get_str(rs, "DEVICE_ID"));
  104 + map.put("ts", map_get_long(rs, "TS"));
  105 + map.put("timestamp", map_get_long(rs, "TS"));
  106 + map.put("stopNo", map_get_str(rs, "STOP_NO"));
  107 + map.put("direction", map_get_float(rs,"DIRECTION"));
  108 +
  109 + map.put("lineId", map_get_str(rs, "LINE_ID"));
  110 + map.put("speed", map_get_float(rs,"SPEED_GPS"));
  111 +
  112 + inOutStop = Integer.parseInt(rs.get("INOUT_STOP").toString());
  113 + map.put("inout_stop", inOutStop);
  114 +
  115 +
  116 + map.put("nbbm", nbbm);
  117 + map.put("state", getService(serviceState));
  118 + // 上下行
  119 + map.put("upDown", getUpOrDown(serviceState));
  120 + //路段编码
  121 + map.put("section_code", map_get_str(rs,"SECTION_CODE"));
  122 + list.add(map);
  123 + }
  124 + // 按时间排序
  125 + Collections.sort(list, new Comparator<Map<String, Object>>() {
  126 +
  127 + @Override
  128 + public int compare(Map<String, Object> o1, Map<String, Object> o2) {
  129 + return (int) (Long.parseLong(o1.get("ts").toString()) - Long.parseLong(o2.get("ts").toString()));
  130 + }
  131 + });
  132 +
  133 + return list;
  134 + }
  135 +
  136 + public List<HistoryArrivalEntity> queryArrival(String line, Long st, Long et) {
  137 + if (et - st > GPS_RANGE)
  138 + return new ArrayList<>();
  139 +
  140 + // day_of_year 分区字段
  141 + Calendar sCal = Calendar.getInstance();
  142 + sCal.setTime(new Date(st));
  143 + int startWeek = sCal.get(Calendar.WEEK_OF_YEAR), startYear = sCal.get(Calendar.YEAR);
  144 + Calendar eCal = Calendar.getInstance();
  145 + eCal.setTime(new Date(et));
  146 + int endWeek = eCal.get(Calendar.WEEK_OF_YEAR), endYear = eCal.get(Calendar.YEAR);
  147 +
  148 + //按年分表
  149 + String tableName1 = "bsth_c_arrival_info_" + startYear, tableName2 = "bsth_c_arrival_info_" + endYear;
  150 +
  151 + String sql = "SELECT device_id, line_id, stop_no, ts, up_down, in_out FROM %s WHERE weeks_year = %d AND line_id = %s AND ts BETWEEN %d AND %d";
  152 + StringBuilder builder = new StringBuilder(String.format(sql, tableName1, startWeek, line, st, et));
  153 + if (startYear == endYear) {
  154 + if (startWeek != endWeek) {
  155 + builder.append(" UNION ").append(String.format(sql, tableName1, endWeek, line, st, et));
  156 + }
  157 + } else {
  158 + builder.append(" UNION ").append(String.format(sql, tableName2, endWeek, line, st, et));
  159 + }
  160 +
  161 + logger.info("到离站查询 line: {} -st: {} -et: {} -sql: {}", line, st, et, builder);
  162 +
  163 + //查询GPS数据
  164 + JdbcTemplate jdbcTemplate_ms = new JdbcTemplate(DBUtils_MS.getDataSource());
  165 + return jdbcTemplate_ms.query(builder.toString(), BeanPropertyRowMapper.newInstance(HistoryArrivalEntity.class));
  166 + }
  167 +
  168 +
  169 + private List<DeviceChange> findDeviceChangeLogs(String nbbm, long et, long st){
  170 + List<DeviceChange> dcs = null;
  171 + List<DeviceChange> rs = new ArrayList<>();
  172 + try{
  173 +
  174 + dcs = jdbcTemplate.query("select cl_zbh as nbbm,new_device_no as device,old_device_no as old_device,UNIX_TIMESTAMP(qyrq) * 1000 as st from bsth_c_car_device where is_cancel=0 and cl_zbh='"+nbbm+"' order by qyrq"
  175 + , BeanPropertyRowMapper.newInstance(DeviceChange.class));
  176 +
  177 +
  178 + //生成一条初始记录
  179 + if(dcs.size() > 0){
  180 + DeviceChange first = dcs.get(0);
  181 +
  182 + DeviceChange initDv = new DeviceChange();
  183 + initDv.setDevice(first.getOldDevice());
  184 + if(StringUtils.isNotEmpty(initDv.getDevice())){
  185 + initDv.setNbbm(first.getNbbm());
  186 + initDv.setSt(0);
  187 + initDv.setEt(first.getSt());
  188 + dcs.add(0, initDv);
  189 + }
  190 + }
  191 + for(int i = 0,len=dcs.size(); i < len - 1; i++){
  192 + dcs.get(i).setEt(dcs.get(i + 1).getSt());
  193 + }
  194 +
  195 + for(DeviceChange dc : dcs){
  196 + if(dc.getEt() < st && dc.getEt() != 0)
  197 + continue;
  198 + if(dc.getSt() > et)
  199 + continue;
  200 +
  201 + rs.add(dc);
  202 + }
  203 +
  204 + //没有设备变更记录,则参考车辆信息上的设备号
  205 + if(null == rs || rs.size() == 0){
  206 + Car car = CarBufferData.findOne(nbbm);
  207 +
  208 + if(null != car){
  209 + DeviceChange dc = new DeviceChange();
  210 + dc.setNbbm(nbbm);
  211 + dc.setDevice(car.getEquipmentCode());
  212 + dc.setSt(st);
  213 + dc.setEt(et);
  214 + dc.setType(1);
  215 +
  216 + rs.add(dc);
  217 + }
  218 + }
  219 + }catch (Exception e){
  220 + logger.error("", e);
  221 + }
  222 + return rs;
  223 + }
  224 +
  225 + private static DateTimeFormatter fmtyyyyMMdd = DateTimeFormat.forPattern("yyyy-MM-dd");
  226 + private List<HistoryGpsEntity> query(String deviceId, Calendar sCal, Calendar eCal) {
  227 + int sDayOfYear = sCal.get(Calendar.DAY_OF_YEAR);
  228 + int eDayOfYear = eCal.get(Calendar.DAY_OF_YEAR);
  229 + long st = sCal.getTimeInMillis();
  230 + long et = eCal.getTimeInMillis();
  231 +
  232 + List<HistoryGpsEntity> list = new ArrayList<>();
  233 + // 如果是同一天
  234 + if (sDayOfYear == eDayOfYear) {
  235 + list = query(sDayOfYear, st, et, deviceId);
  236 + } else {
  237 + // 跨天
  238 + Long tempSt, tempEt;
  239 + for (int i = sDayOfYear; i <= eDayOfYear; i++) {
  240 +
  241 + if (i == sDayOfYear) {
  242 + tempSt = st;
  243 + tempEt = fmtyyyyMMdd.parseMillis(fmtyyyyMMdd.print(tempSt)) + 1000 * 60 * 60 * 24;
  244 + } else if (i == eDayOfYear) {
  245 + tempSt = fmtyyyyMMdd.parseMillis(fmtyyyyMMdd.print(et));
  246 + tempEt = et;
  247 + } else {
  248 + tempSt = DateUtils.getTimesmorning(sCal) * 1000;
  249 + tempEt = DateUtils.getTimesnight(sCal);
  250 + }
  251 +
  252 + list.addAll(query(sDayOfYear, tempSt, tempEt, deviceId));
  253 + // 加一天
  254 + sCal.add(Calendar.DATE, 1);
  255 + }
  256 + }
  257 + return list;
  258 + }
  259 +
  260 + private List<HistoryGpsEntity> query(int dayOfYear, Long st, Long et, String deviceId) {
  261 + String sql = "select device_id,line_id,service_state,direction,lon,lat,ts,stop_no,speed_gps as speed,inout_stop,section_code from bsth_c_gps_info where days_year=" + dayOfYear + " and device_id='"+deviceId+"' and ts > " + st + " and ts < " + et;
  262 +
  263 + JdbcTemplate jdbcTemplate = new JdbcTemplate(DBUtils_MS.getDataSource());
  264 + List<HistoryGpsEntity> list = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(HistoryGpsEntity.class));
  265 + return list;
  266 + }
  267 +
  268 + /**
  269 + * 王通 2016/6/29 9:23:24 获取车辆线路上下行
  270 + *
  271 + * @return -1无效 0上行 1下行
  272 + */
  273 + private static byte getUpOrDown(long serviceState) {
  274 + if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000
  275 + || (serviceState & 0x01000000) == 0x01000000 || (serviceState & 0x08000000) == 0x08000000)
  276 + return -1;
  277 + return (byte) (((serviceState & 0x10000000) == 0x10000000) ? 1 : 0);
  278 + }
  279 +
  280 + /**
  281 + * 获取运营状态
  282 + *
  283 + * @return -1无效 0运营 1未运营
  284 + */
  285 + private static byte getService(long serviceState) {
  286 + if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000)
  287 + return -1;
  288 + return (byte) (((serviceState & 0x02000000) == 0x02000000) ? 1 : 0);
  289 + }
  290 +
  291 + private String map_get_str(Map<String, Object> map, String key){
  292 + return map.containsKey(key)?map.get(key).toString():"";
  293 + }
  294 +
  295 + private Long map_get_long(Map<String, Object> map, String key){
  296 + return map.containsKey(key)?Long.parseLong(map.get(key).toString()):-1;
  297 + }
  298 +
  299 + private Float map_get_float(Map<String, Object> map, String key){
  300 + return map.containsKey(key)?Float.parseFloat(map.get(key).toString()):-1;
  301 + }
  302 +
  303 + public static byte getGpsValid(long serviceState) {
  304 + return (byte)(((serviceState & 0x80000000) == 0x80000000) ? 1 : 0);
  305 + }
  306 +}
src/main/java/com/bsth/server_rs/gps/entity/HistoryArrivalEntity.java 0 → 100644
  1 +package com.bsth.server_rs.gps.entity;
  2 +
  3 +public class HistoryArrivalEntity {
  4 +
  5 + private String deviceId;
  6 +
  7 + private int lineId;
  8 +
  9 + private String lineName;
  10 +
  11 + private String stopNo;
  12 +
  13 + private int upDown;
  14 +
  15 + private int inOut;
  16 +
  17 + private long ts;
  18 +
  19 + public String getDeviceId() {
  20 + return deviceId;
  21 + }
  22 +
  23 + public void setDeviceId(String deviceId) {
  24 + this.deviceId = deviceId;
  25 + }
  26 +
  27 + public int getLineId() {
  28 + return lineId;
  29 + }
  30 +
  31 + public void setLineId(int lineId) {
  32 + this.lineId = lineId;
  33 + }
  34 +
  35 + public String getLineName() {
  36 + return lineName;
  37 + }
  38 +
  39 + public void setLineName(String lineName) {
  40 + this.lineName = lineName;
  41 + }
  42 +
  43 + public String getStopNo() {
  44 + return stopNo;
  45 + }
  46 +
  47 + public void setStopNo(String stopNo) {
  48 + this.stopNo = stopNo;
  49 + }
  50 +
  51 + public int getUpDown() {
  52 + return upDown;
  53 + }
  54 +
  55 + public void setUpDown(int upDown) {
  56 + this.upDown = upDown;
  57 + }
  58 +
  59 + public int getInOut() {
  60 + return inOut;
  61 + }
  62 +
  63 + public void setInOut(int inOut) {
  64 + this.inOut = inOut;
  65 + }
  66 +
  67 + public long getTs() {
  68 + return ts;
  69 + }
  70 +
  71 + public void setTs(long ts) {
  72 + this.ts = ts;
  73 + }
  74 +}
src/main/java/com/bsth/util/ThreadLocalUtils.java 0 → 100644
  1 +package com.bsth.util;
  2 +
  3 +public class ThreadLocalUtils {
  4 +
  5 + private static ThreadLocal<String> passwords = new ThreadLocal<>();
  6 +
  7 + public static void setPassword(String password) {
  8 + passwords.set(password);
  9 + }
  10 +
  11 + public static String getPassword() {
  12 + return passwords.get();
  13 + }
  14 +}
src/main/resources/application.properties
@@ -15,3 +15,6 @@ server.compression.mime-types=application/json,application/xml,text/html,text/xm @@ -15,3 +15,6 @@ server.compression.mime-types=application/json,application/xml,text/html,text/xm
15 15
16 #redis 16 #redis
17 cache.days=15 17 cache.days=15
  18 +
  19 +#limits
  20 +path.limits=limits/