Commit a552e70157fec0c4c883bcf7c2cbe86c613a3f77

Authored by 潘钊
1 parent 172ae0d4

移出配置文件

src/main/java/com/bsth/gpsdata/buffer/GpsRealDataBuffer.java
1 1 package com.bsth.gpsdata.buffer;
2 2  
  3 +import java.util.ArrayList;
3 4 import java.util.HashMap;
4 5 import java.util.Iterator;
5 6 import java.util.List;
... ... @@ -63,6 +64,11 @@ public class GpsRealDataBuffer {
63 64 */
64 65 private static Map<String, String> stationCodeMap;
65 66  
  67 + /**
  68 + * 最后同步时间
  69 + */
  70 + private static Long lastUpdateTime;
  71 +
66 72  
67 73 public boolean isNullEmpty(){
68 74 return deviceGpsMap == null;
... ... @@ -170,13 +176,49 @@ public class GpsRealDataBuffer {
170 176 * @throws
171 177 */
172 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 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 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 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 5 import org.springframework.beans.factory.annotation.Autowired;
6 6 import org.springframework.web.bind.annotation.PathVariable;
7 7 import org.springframework.web.bind.annotation.RequestMapping;
  8 +import org.springframework.web.bind.annotation.RequestParam;
8 9 import org.springframework.web.bind.annotation.RestController;
9 10  
10 11 import com.bsth.gpsdata.buffer.GpsRealDataBuffer;
11 12 import com.bsth.gpsdata.entity.GpsRealData;
  13 +import com.google.common.base.Splitter;
12 14  
13 15 @RestController
14 16 @RequestMapping("gps")
... ... @@ -21,4 +23,9 @@ public class GpsDataController {
21 23 public List<GpsRealData> findByLineCode(@PathVariable("lineCode") Integer lineCode){
22 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 21 import com.alibaba.fastjson.JSONObject;
22 22 import com.bsth.gpsdata.buffer.GpsRealDataBuffer;
23 23 import com.bsth.gpsdata.entity.GpsRealData;
24   -import com.bsth.gpsdata.util.ConfigUtil;
  24 +import com.bsth.util.Tools;
25 25 import com.google.common.collect.ImmutableMap;
26 26  
27 27 /**
... ... @@ -42,7 +42,8 @@ public class GpsBufferRefreshThread extends Thread{
42 42  
43 43  
44 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 49 @Autowired
... ... @@ -81,6 +82,7 @@ public class GpsBufferRefreshThread extends Thread{
81 82  
82 83 //更新缓存
83 84 gpsBuffer.updateBuffer(upLines, upGpsList);
  85 + gpsBuffer.setLastUpdateTime(System.currentTimeMillis());
84 86 }
85 87  
86 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   -}