Commit a552e70157fec0c4c883bcf7c2cbe86c613a3f77

Authored by 潘钊
1 parent 172ae0d4

移出配置文件

src/main/java/com/bsth/gpsdata/buffer/GpsRealDataBuffer.java
1 package com.bsth.gpsdata.buffer; 1 package com.bsth.gpsdata.buffer;
2 2
  3 +import java.util.ArrayList;
3 import java.util.HashMap; 4 import java.util.HashMap;
4 import java.util.Iterator; 5 import java.util.Iterator;
5 import java.util.List; 6 import java.util.List;
@@ -63,6 +64,11 @@ public class GpsRealDataBuffer { @@ -63,6 +64,11 @@ public class GpsRealDataBuffer {
63 */ 64 */
64 private static Map<String, String> stationCodeMap; 65 private static Map<String, String> stationCodeMap;
65 66
  67 + /**
  68 + * 最后同步时间
  69 + */
  70 + private static Long lastUpdateTime;
  71 +
66 72
67 public boolean isNullEmpty(){ 73 public boolean isNullEmpty(){
68 return deviceGpsMap == null; 74 return deviceGpsMap == null;
@@ -170,13 +176,49 @@ public class GpsRealDataBuffer { @@ -170,13 +176,49 @@ public class GpsRealDataBuffer {
170 * @throws 176 * @throws
171 */ 177 */
172 public List<GpsRealData> getListByLineCode(Integer lineCode){ 178 public List<GpsRealData> getListByLineCode(Integer lineCode){
173 - List<GpsRealData> list = lineGpsMultimap.get(lineCode); 179 + List<GpsRealData> list = lineGpsMultimap.get(lineCode)
  180 + ,resList = new ArrayList<>();
174 181
175 //写入车辆自编号 182 //写入车辆自编号
  183 + String nbbm;
  184 + logger.info("list size..." + list.size());
176 for(GpsRealData gpsData : list){ 185 for(GpsRealData gpsData : list){
177 - gpsData.setNbbm(vehicDeviceMap.get(gpsData.getDeviceId()));  
178 - gpsData.setStationName(stationCodeMap.get(gpsData.getStopNo())); 186 + nbbm = vehicDeviceMap.get(gpsData.getDeviceId());
  187 + if(null != nbbm){
  188 + gpsData.setNbbm(nbbm);
  189 + gpsData.setStationName(stationCodeMap.get(gpsData.getStopNo()));
  190 + resList.add(gpsData);
  191 + }
179 } 192 }
  193 + return resList;
  194 + }
  195 +
  196 + /**
  197 + *
  198 + * @Title: getListByLineCode
  199 + * @Description: TODO(根据多个线路编码获取该线路所有的GPS点)
  200 + * @return List<GpsRealData> 返回类型
  201 + * @throws
  202 + */
  203 + public List<GpsRealData> getListByLines(Iterator<String> iterator){
  204 +
  205 + List<GpsRealData> list = new ArrayList<>();
  206 +
  207 + Integer code;
  208 + while(iterator.hasNext()){
  209 + code = Integer.parseInt(iterator.next());
  210 + list.addAll(getListByLineCode(code));
  211 + }
  212 +
180 return list; 213 return list;
181 } 214 }
  215 +
  216 +
  217 + public void setLastUpdateTime(Long time){
  218 + lastUpdateTime = time;
  219 + }
  220 +
  221 + public Long getLastUpdateTime(){
  222 + return lastUpdateTime;
  223 + }
182 } 224 }
src/main/java/com/bsth/gpsdata/config.properties deleted 100644 → 0
1 -#http.gps.real.url= http://222.66.0.204:5555/transport_server/rtgps/  
2 -http.gps.real.url= http://192.168.168.192:8080/transport_server/rtgps/  
3 \ No newline at end of file 0 \ No newline at end of file
src/main/java/com/bsth/gpsdata/controller/GpsDataController.java
@@ -5,10 +5,12 @@ import java.util.List; @@ -5,10 +5,12 @@ import java.util.List;
5 import org.springframework.beans.factory.annotation.Autowired; 5 import org.springframework.beans.factory.annotation.Autowired;
6 import org.springframework.web.bind.annotation.PathVariable; 6 import org.springframework.web.bind.annotation.PathVariable;
7 import org.springframework.web.bind.annotation.RequestMapping; 7 import org.springframework.web.bind.annotation.RequestMapping;
  8 +import org.springframework.web.bind.annotation.RequestParam;
8 import org.springframework.web.bind.annotation.RestController; 9 import org.springframework.web.bind.annotation.RestController;
9 10
10 import com.bsth.gpsdata.buffer.GpsRealDataBuffer; 11 import com.bsth.gpsdata.buffer.GpsRealDataBuffer;
11 import com.bsth.gpsdata.entity.GpsRealData; 12 import com.bsth.gpsdata.entity.GpsRealData;
  13 +import com.google.common.base.Splitter;
12 14
13 @RestController 15 @RestController
14 @RequestMapping("gps") 16 @RequestMapping("gps")
@@ -21,4 +23,9 @@ public class GpsDataController { @@ -21,4 +23,9 @@ public class GpsDataController {
21 public List<GpsRealData> findByLineCode(@PathVariable("lineCode") Integer lineCode){ 23 public List<GpsRealData> findByLineCode(@PathVariable("lineCode") Integer lineCode){
22 return gpsBuffer.getListByLineCode(lineCode); 24 return gpsBuffer.getListByLineCode(lineCode);
23 } 25 }
  26 +
  27 + @RequestMapping(value = "/real/line")
  28 + public List<GpsRealData> findByLineCode(@RequestParam String lineCodes){
  29 + return gpsBuffer.getListByLines(Splitter.on(",").split(lineCodes).iterator());
  30 + }
24 } 31 }
src/main/java/com/bsth/gpsdata/thread/GpsBufferRefreshThread.java
@@ -21,7 +21,7 @@ import com.alibaba.fastjson.JSON; @@ -21,7 +21,7 @@ import com.alibaba.fastjson.JSON;
21 import com.alibaba.fastjson.JSONObject; 21 import com.alibaba.fastjson.JSONObject;
22 import com.bsth.gpsdata.buffer.GpsRealDataBuffer; 22 import com.bsth.gpsdata.buffer.GpsRealDataBuffer;
23 import com.bsth.gpsdata.entity.GpsRealData; 23 import com.bsth.gpsdata.entity.GpsRealData;
24 -import com.bsth.gpsdata.util.ConfigUtil; 24 +import com.bsth.util.Tools;
25 import com.google.common.collect.ImmutableMap; 25 import com.google.common.collect.ImmutableMap;
26 26
27 /** 27 /**
@@ -42,7 +42,8 @@ public class GpsBufferRefreshThread extends Thread{ @@ -42,7 +42,8 @@ public class GpsBufferRefreshThread extends Thread{
42 42
43 43
44 public GpsBufferRefreshThread() { 44 public GpsBufferRefreshThread() {
45 - url = ConfigUtil.getProp("http.gps.real.url"); 45 + Tools t = new Tools("application.properties");
  46 + url = t.getValue("http.gps.real.url");
46 } 47 }
47 48
48 @Autowired 49 @Autowired
@@ -81,6 +82,7 @@ public class GpsBufferRefreshThread extends Thread{ @@ -81,6 +82,7 @@ public class GpsBufferRefreshThread extends Thread{
81 82
82 //更新缓存 83 //更新缓存
83 gpsBuffer.updateBuffer(upLines, upGpsList); 84 gpsBuffer.updateBuffer(upLines, upGpsList);
  85 + gpsBuffer.setLastUpdateTime(System.currentTimeMillis());
84 } 86 }
85 87
86 logger.info("本次刷新GPS实时数据耗时:" + (System.currentTimeMillis() - t) + "毫秒"); 88 logger.info("本次刷新GPS实时数据耗时:" + (System.currentTimeMillis() - t) + "毫秒");
src/main/java/com/bsth/gpsdata/util/ConfigUtil.java deleted 100644 → 0
1 -package com.bsth.gpsdata.util;  
2 -  
3 -import java.io.IOException;  
4 -import java.io.InputStream;  
5 -import java.util.Properties;  
6 -  
7 -public class ConfigUtil {  
8 -  
9 - private static Properties properties = new Properties();  
10 -  
11 - static {  
12 - InputStream in = Object.class.getResourceAsStream("/com/bsth/gpsdata/config.properties");  
13 - try {  
14 - properties.load(in);  
15 - } catch (IOException e) {  
16 - e.printStackTrace();  
17 - }  
18 - }  
19 -  
20 - public static String getProp(String key){  
21 -  
22 - return properties.getProperty(key);  
23 - }  
24 -}