Commit fd6418514f9f266a18db41de37d9eae91c81d258
update...
Showing
28 changed files
with
2202 additions
and
2195 deletions
Too many changes to show.
To preserve performance only 28 of 55 files are displayed.
src/main/java/com/bsth/controller/oil/DlbController.java
| ... | ... | @@ -163,6 +163,7 @@ public class DlbController extends BaseController<Dlb, Integer>{ |
| 163 | 163 | m.put("hd", y.getHd()<=0?"0":y.getHd()); |
| 164 | 164 | String shyy ="无"; |
| 165 | 165 | if(y.getShyy()!=null){ |
| 166 | + shyy=y.getShyy(); | |
| 166 | 167 | if(shyy.equals("1")){shyy="票务用油";} |
| 167 | 168 | else if(shyy.equals("2")){shyy="保养用油";} |
| 168 | 169 | else if(shyy.equals("3")){shyy="报废车用油";} | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/DataHandleProcess.java
src/main/java/com/bsth/data/gpsdata_v2/GpsRealData.java
| 1 | -package com.bsth.data.gpsdata_v2; | |
| 2 | - | |
| 3 | -import com.bsth.data.BasicData; | |
| 4 | -import com.bsth.data.forecast.ForecastRealServer; | |
| 5 | -import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 6 | -import com.bsth.data.schedule.DayOfSchedule; | |
| 7 | -import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 8 | -import com.google.common.collect.TreeMultimap; | |
| 9 | -import org.apache.commons.lang3.StringUtils; | |
| 10 | -import org.slf4j.Logger; | |
| 11 | -import org.slf4j.LoggerFactory; | |
| 12 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 13 | -import org.springframework.stereotype.Component; | |
| 14 | - | |
| 15 | -import java.util.*; | |
| 16 | -import java.util.concurrent.ConcurrentHashMap; | |
| 17 | -import java.util.concurrent.ConcurrentMap; | |
| 18 | - | |
| 19 | -/** | |
| 20 | - * @author PanZhao | |
| 21 | - * @ClassName: GpsRealData | |
| 22 | - * @Description: TODO(实时GPS数据集合) | |
| 23 | - * @date 2016年8月12日 下午2:04:41 | |
| 24 | - */ | |
| 25 | -@Component | |
| 26 | -public class GpsRealData { | |
| 27 | - | |
| 28 | - static Logger logger = LoggerFactory.getLogger(GpsRealData.class); | |
| 29 | - | |
| 30 | - private static ConcurrentMap<String, GpsEntity> gpsMap; | |
| 31 | - | |
| 32 | - //按线路分组设备号 | |
| 33 | - private static TreeMultimap<String, String> lineCode2Devices; | |
| 34 | - | |
| 35 | - @Autowired | |
| 36 | - DayOfSchedule dayOfSchedule; | |
| 37 | - | |
| 38 | - @Autowired | |
| 39 | - ForecastRealServer forecastRealServer; | |
| 40 | - | |
| 41 | - /** | |
| 42 | - * 构造函数 | |
| 43 | - */ | |
| 44 | - public GpsRealData() { | |
| 45 | - gpsMap = new ConcurrentHashMap<>(); | |
| 46 | - lineCode2Devices = TreeMultimap.create(); | |
| 47 | - } | |
| 48 | - | |
| 49 | - | |
| 50 | - public void put(GpsEntity gps) { | |
| 51 | - String device = gps.getDeviceId(); | |
| 52 | - GpsEntity old = gpsMap.get(device); | |
| 53 | - | |
| 54 | - try { | |
| 55 | - if (!StringUtils.isEmpty(gps.getStopNo())) { | |
| 56 | - //站点编码改变 | |
| 57 | - if (null == old || !gps.getStopNo().equals(old.getStopNo())) { | |
| 58 | - gps.setArrTime(gps.getTimestamp()); | |
| 59 | - //预测到达终点时间 | |
| 60 | - forecastRealServer.forecast(gps.getNbbm(), gps); | |
| 61 | - } else { | |
| 62 | - gps.setArrTime(old.getArrTime()); | |
| 63 | - //不预测, 重新计算终点时间 | |
| 64 | - gps.setExpectStopTime(forecastRealServer.expectStopTime(gps.getNbbm())); | |
| 65 | - } | |
| 66 | - } | |
| 67 | - | |
| 68 | - //刷新对照 | |
| 69 | - gpsMap.put(device, gps); | |
| 70 | - if (StringUtils.isNotBlank(gps.getLineId())) { | |
| 71 | - //站点名称 | |
| 72 | - gps.setStationName(getStationName(gps)); | |
| 73 | - lineCode2Devices.put(gps.getLineId(), device); | |
| 74 | - | |
| 75 | - if(old != null && !gps.getLineId().equals(old.getLineId())) | |
| 76 | - lineCode2Devices.remove(old.getLineId(), device); | |
| 77 | - } | |
| 78 | - | |
| 79 | - //车辆换设备了 | |
| 80 | - String nbbm = gps.getNbbm(); | |
| 81 | - if(old != null && StringUtils.isNotEmpty(nbbm) && !nbbm.equals(old.getNbbm())){ | |
| 82 | - List<GpsEntity> list = findByNbbm(nbbm); | |
| 83 | - for(GpsEntity g : list){ | |
| 84 | - if(!g.getDeviceId().equals(device)) | |
| 85 | - gpsMap.remove(g.getDeviceId()); | |
| 86 | - } | |
| 87 | - } | |
| 88 | - } catch (Exception e) { | |
| 89 | - logger.error("", e); | |
| 90 | - } | |
| 91 | - } | |
| 92 | - | |
| 93 | - public String getStationName(GpsEntity gps) { | |
| 94 | - return BasicData.getStationNameByCode(gps.getStopNo(), gps.getLineId() + "_" + gps.getUpDown() + "_"); | |
| 95 | - } | |
| 96 | - | |
| 97 | - /** | |
| 98 | - * @Title: get @Description: TODO(设备号获取GPS) | |
| 99 | - */ | |
| 100 | - public GpsEntity get(String deviceId) { | |
| 101 | - return gpsMap.get(deviceId); | |
| 102 | - } | |
| 103 | - | |
| 104 | - public List<GpsEntity> findByNbbm(String nbbm){ | |
| 105 | - Collection<GpsEntity> arr = gpsMap.values(); | |
| 106 | - List<GpsEntity> rs = new ArrayList<>(); | |
| 107 | - for(GpsEntity g : arr){ | |
| 108 | - if(nbbm.equals(g.getNbbm())) | |
| 109 | - rs.add(g); | |
| 110 | - } | |
| 111 | - return rs; | |
| 112 | - } | |
| 113 | - | |
| 114 | - public GpsEntity getByNbbm(String nbbm){ | |
| 115 | - String device = BasicData.deviceId2NbbmMap.inverse().get(nbbm); | |
| 116 | - if(StringUtils.isNotBlank(device)) | |
| 117 | - return get(device); | |
| 118 | - else | |
| 119 | - return null; | |
| 120 | - } | |
| 121 | - | |
| 122 | - /** | |
| 123 | - * @Title: get @Description: TODO(线路编码获取GPS集合) @throws | |
| 124 | - */ | |
| 125 | - public List<GpsEntity> getByLine(String lineCode) { | |
| 126 | - NavigableSet<String> set = lineCode2Devices.get(lineCode); | |
| 127 | - | |
| 128 | - List<GpsEntity> rs = new ArrayList<>(); | |
| 129 | - GpsEntity gps; | |
| 130 | - ScheduleRealInfo sch; | |
| 131 | - for (String device : set) { | |
| 132 | - gps = gpsMap.get(device); | |
| 133 | - //过滤异常GPS数据 | |
| 134 | - if (gps == null || StringUtils.isBlank(gps.getNbbm())) | |
| 135 | - continue; | |
| 136 | - | |
| 137 | - sch = dayOfSchedule.execPlanMap().get(gps.getNbbm()); | |
| 138 | - if (null != sch) | |
| 139 | - gps.setSchId(sch.getId()); | |
| 140 | - rs.add(gps); | |
| 141 | - } | |
| 142 | - | |
| 143 | - return rs; | |
| 144 | - } | |
| 145 | - | |
| 146 | - public List<GpsEntity> get(List<String> pArray) { | |
| 147 | - List<GpsEntity> list = new ArrayList<>(); | |
| 148 | - | |
| 149 | - for (String code : pArray) | |
| 150 | - list.addAll(getByLine(code)); | |
| 151 | - return list; | |
| 152 | - } | |
| 153 | - | |
| 154 | - public Set<String> allDevices() { | |
| 155 | - return gpsMap.keySet(); | |
| 156 | - } | |
| 157 | - | |
| 158 | - public Collection<GpsEntity> all() { | |
| 159 | - return gpsMap.values(); | |
| 160 | - } | |
| 161 | - | |
| 162 | - public void remove(String device) { | |
| 163 | - gpsMap.remove(device); | |
| 164 | - } | |
| 1 | +package com.bsth.data.gpsdata_v2; | |
| 2 | + | |
| 3 | +import com.bsth.data.BasicData; | |
| 4 | +import com.bsth.data.forecast.ForecastRealServer; | |
| 5 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 6 | +import com.bsth.data.schedule.DayOfSchedule; | |
| 7 | +import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 8 | +import com.google.common.collect.TreeMultimap; | |
| 9 | +import org.apache.commons.lang3.StringUtils; | |
| 10 | +import org.slf4j.Logger; | |
| 11 | +import org.slf4j.LoggerFactory; | |
| 12 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 13 | +import org.springframework.stereotype.Component; | |
| 14 | + | |
| 15 | +import java.util.*; | |
| 16 | +import java.util.concurrent.ConcurrentHashMap; | |
| 17 | +import java.util.concurrent.ConcurrentMap; | |
| 18 | + | |
| 19 | +/** | |
| 20 | + * @author PanZhao | |
| 21 | + * @ClassName: GpsRealData | |
| 22 | + * @Description: TODO(实时GPS数据集合) | |
| 23 | + * @date 2016年8月12日 下午2:04:41 | |
| 24 | + */ | |
| 25 | +@Component | |
| 26 | +public class GpsRealData { | |
| 27 | + | |
| 28 | + static Logger logger = LoggerFactory.getLogger(GpsRealData.class); | |
| 29 | + | |
| 30 | + private static ConcurrentMap<String, GpsEntity> gpsMap; | |
| 31 | + | |
| 32 | + //按线路分组设备号 | |
| 33 | + private static TreeMultimap<String, String> lineCode2Devices; | |
| 34 | + | |
| 35 | + @Autowired | |
| 36 | + DayOfSchedule dayOfSchedule; | |
| 37 | + | |
| 38 | + @Autowired | |
| 39 | + ForecastRealServer forecastRealServer; | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * 构造函数 | |
| 43 | + */ | |
| 44 | + public GpsRealData() { | |
| 45 | + gpsMap = new ConcurrentHashMap<>(); | |
| 46 | + lineCode2Devices = TreeMultimap.create(); | |
| 47 | + } | |
| 48 | + | |
| 49 | + | |
| 50 | + public void put(GpsEntity gps) { | |
| 51 | + String device = gps.getDeviceId(); | |
| 52 | + GpsEntity old = gpsMap.get(device); | |
| 53 | + | |
| 54 | + try { | |
| 55 | + if (!StringUtils.isEmpty(gps.getStopNo())) { | |
| 56 | + //站点编码改变 | |
| 57 | + if (null == old || !gps.getStopNo().equals(old.getStopNo())) { | |
| 58 | + gps.setArrTime(gps.getTimestamp()); | |
| 59 | + //预测到达终点时间 | |
| 60 | + forecastRealServer.forecast(gps.getNbbm(), gps); | |
| 61 | + } else { | |
| 62 | + gps.setArrTime(old.getArrTime()); | |
| 63 | + //不预测, 重新计算终点时间 | |
| 64 | + gps.setExpectStopTime(forecastRealServer.expectStopTime(gps.getNbbm())); | |
| 65 | + } | |
| 66 | + } | |
| 67 | + | |
| 68 | + //刷新对照 | |
| 69 | + gpsMap.put(device, gps); | |
| 70 | + if (StringUtils.isNotBlank(gps.getLineId())) { | |
| 71 | + //站点名称 | |
| 72 | + gps.setStationName(getStationName(gps)); | |
| 73 | + lineCode2Devices.put(gps.getLineId(), device); | |
| 74 | + | |
| 75 | + if(old != null && !gps.getLineId().equals(old.getLineId())) | |
| 76 | + lineCode2Devices.remove(old.getLineId(), device); | |
| 77 | + } | |
| 78 | + | |
| 79 | + //车辆换设备了 | |
| 80 | + String nbbm = gps.getNbbm(); | |
| 81 | + if(old != null && StringUtils.isNotEmpty(nbbm) && !nbbm.equals(old.getNbbm())){ | |
| 82 | + List<GpsEntity> list = findByNbbm(nbbm); | |
| 83 | + for(GpsEntity g : list){ | |
| 84 | + if(!g.getDeviceId().equals(device)) | |
| 85 | + gpsMap.remove(g.getDeviceId()); | |
| 86 | + } | |
| 87 | + } | |
| 88 | + } catch (Exception e) { | |
| 89 | + logger.error("", e); | |
| 90 | + } | |
| 91 | + } | |
| 92 | + | |
| 93 | + public String getStationName(GpsEntity gps) { | |
| 94 | + return BasicData.getStationNameByCode(gps.getStopNo(), gps.getLineId() + "_" + gps.getUpDown() + "_"); | |
| 95 | + } | |
| 96 | + | |
| 97 | + /** | |
| 98 | + * @Title: get @Description: TODO(设备号获取GPS) | |
| 99 | + */ | |
| 100 | + public GpsEntity get(String deviceId) { | |
| 101 | + return gpsMap.get(deviceId); | |
| 102 | + } | |
| 103 | + | |
| 104 | + public List<GpsEntity> findByNbbm(String nbbm){ | |
| 105 | + Collection<GpsEntity> arr = gpsMap.values(); | |
| 106 | + List<GpsEntity> rs = new ArrayList<>(); | |
| 107 | + for(GpsEntity g : arr){ | |
| 108 | + if(nbbm.equals(g.getNbbm())) | |
| 109 | + rs.add(g); | |
| 110 | + } | |
| 111 | + return rs; | |
| 112 | + } | |
| 113 | + | |
| 114 | + public GpsEntity getByNbbm(String nbbm){ | |
| 115 | + String device = BasicData.deviceId2NbbmMap.inverse().get(nbbm); | |
| 116 | + if(StringUtils.isNotBlank(device)) | |
| 117 | + return get(device); | |
| 118 | + else | |
| 119 | + return null; | |
| 120 | + } | |
| 121 | + | |
| 122 | + /** | |
| 123 | + * @Title: get @Description: TODO(线路编码获取GPS集合) @throws | |
| 124 | + */ | |
| 125 | + public List<GpsEntity> getByLine(String lineCode) { | |
| 126 | + NavigableSet<String> set = lineCode2Devices.get(lineCode); | |
| 127 | + | |
| 128 | + List<GpsEntity> rs = new ArrayList<>(); | |
| 129 | + GpsEntity gps; | |
| 130 | + ScheduleRealInfo sch; | |
| 131 | + for (String device : set) { | |
| 132 | + gps = gpsMap.get(device); | |
| 133 | + //过滤异常GPS数据 | |
| 134 | + if (gps == null || StringUtils.isBlank(gps.getNbbm())) | |
| 135 | + continue; | |
| 136 | + | |
| 137 | + sch = dayOfSchedule.execPlanMap().get(gps.getNbbm()); | |
| 138 | + if (null != sch) | |
| 139 | + gps.setSchId(sch.getId()); | |
| 140 | + rs.add(gps); | |
| 141 | + } | |
| 142 | + | |
| 143 | + return rs; | |
| 144 | + } | |
| 145 | + | |
| 146 | + public List<GpsEntity> get(List<String> pArray) { | |
| 147 | + List<GpsEntity> list = new ArrayList<>(); | |
| 148 | + | |
| 149 | + for (String code : pArray) | |
| 150 | + list.addAll(getByLine(code)); | |
| 151 | + return list; | |
| 152 | + } | |
| 153 | + | |
| 154 | + public Set<String> allDevices() { | |
| 155 | + return gpsMap.keySet(); | |
| 156 | + } | |
| 157 | + | |
| 158 | + public Collection<GpsEntity> all() { | |
| 159 | + return gpsMap.values(); | |
| 160 | + } | |
| 161 | + | |
| 162 | + public void remove(String device) { | |
| 163 | + gpsMap.remove(device); | |
| 164 | + } | |
| 165 | 165 | } |
| 166 | 166 | \ No newline at end of file | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/cache/GeoCacheData.java
src/main/java/com/bsth/data/gpsdata_v2/cache/GpsCacheData.java
| 1 | -package com.bsth.data.gpsdata_v2.cache; | |
| 2 | - | |
| 3 | -import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 4 | -import com.bsth.data.gpsdata_v2.entity.StationRoute; | |
| 5 | -import com.bsth.data.gpsdata_v2.entity.trail.GpsExecTrail; | |
| 6 | -import com.bsth.data.gpsdata_v2.utils.CircleQueue; | |
| 7 | -import com.google.common.collect.ArrayListMultimap; | |
| 8 | -import org.slf4j.Logger; | |
| 9 | -import org.slf4j.LoggerFactory; | |
| 10 | - | |
| 11 | -import java.util.*; | |
| 12 | - | |
| 13 | -/** | |
| 14 | - * gps 数据缓存 | |
| 15 | - * Created by panzhao on 2017/11/15. | |
| 16 | - */ | |
| 17 | -public class GpsCacheData { | |
| 18 | - | |
| 19 | - /** | |
| 20 | - * 每辆车缓存最后300条gps | |
| 21 | - */ | |
| 22 | - private static final int CACHE_SIZE = 300; | |
| 23 | - private static Map<String, CircleQueue<GpsEntity>> gpsCacheMap = new HashMap<>(); | |
| 24 | - | |
| 25 | - /** | |
| 26 | - * 车辆执行班次的详细 进出站数据 | |
| 27 | - */ | |
| 28 | - private static ArrayListMultimap<String, GpsExecTrail> trailListMultimap = ArrayListMultimap.create(); | |
| 29 | - | |
| 30 | - static Logger logger = LoggerFactory.getLogger(GpsCacheData.class); | |
| 31 | - | |
| 32 | - public static CircleQueue<GpsEntity> getGps(String device) { | |
| 33 | - return gpsCacheMap.get(device); | |
| 34 | - } | |
| 35 | - | |
| 36 | - public static GpsExecTrail gpsExecTrail(String nbbm){ | |
| 37 | - List<GpsExecTrail> list = trailListMultimap.get(nbbm); | |
| 38 | - | |
| 39 | - GpsExecTrail trail; | |
| 40 | - if(null == list || list.size() == 0 | |
| 41 | - || list.get(list.size() - 1).isEnd()){ | |
| 42 | - trail = new GpsExecTrail(); | |
| 43 | - | |
| 44 | - trailListMultimap.put(nbbm, trail); | |
| 45 | - } | |
| 46 | - else{ | |
| 47 | - trail = list.get(list.size() - 1); | |
| 48 | - } | |
| 49 | - | |
| 50 | - return trail; | |
| 51 | - } | |
| 52 | - | |
| 53 | - public static void out(GpsEntity gps){ | |
| 54 | - GpsExecTrail trail = gpsExecTrail(gps.getNbbm()); | |
| 55 | - trail.getSrs().add(gps); | |
| 56 | - | |
| 57 | - } | |
| 58 | - | |
| 59 | - public static void in(GpsEntity gps, boolean end){ | |
| 60 | - GpsExecTrail trail = gpsExecTrail(gps.getNbbm()); | |
| 61 | - trail.getSrs().add(gps); | |
| 62 | - trail.setEnd(end); | |
| 63 | - } | |
| 64 | - | |
| 65 | - public static GpsEntity getPrev(GpsEntity gps){ | |
| 66 | - CircleQueue<GpsEntity> queue = gpsCacheMap.get(gps.getDeviceId()); | |
| 67 | - if(queue != null) | |
| 68 | - return queue.getTail(); | |
| 69 | - return null; | |
| 70 | - } | |
| 71 | - | |
| 72 | - public static void putGps(GpsEntity gps) { | |
| 73 | - CircleQueue<GpsEntity> queue = gpsCacheMap.get(gps.getDeviceId()); | |
| 74 | - if (queue == null) { | |
| 75 | - queue = new CircleQueue<>(CACHE_SIZE); | |
| 76 | - gpsCacheMap.put(gps.getDeviceId(), queue); | |
| 77 | - } | |
| 78 | - queue.add(gps); | |
| 79 | - } | |
| 80 | - | |
| 81 | - public static void clear(String deviceId) { | |
| 82 | - try { | |
| 83 | - CircleQueue<GpsEntity> queue = gpsCacheMap.get(deviceId); | |
| 84 | - if (queue != null) | |
| 85 | - queue.clear(); | |
| 86 | - } catch (Exception e) { | |
| 87 | - logger.error("", e); | |
| 88 | - } | |
| 89 | - } | |
| 90 | - | |
| 91 | - public static StationRoute prevStation(GpsEntity gps) { | |
| 92 | - List<GpsExecTrail> trails = trailListMultimap.get(gps.getNbbm()); | |
| 93 | - if(null == trails || trails.size() == 0) | |
| 94 | - return null; | |
| 95 | - | |
| 96 | - GpsEntity prev; | |
| 97 | - for(int i = trails.size() - 1; i > 0; i--){ | |
| 98 | - prev = trails.get(i).getSrs().peekLast(); | |
| 99 | - | |
| 100 | - if(prev != null){ | |
| 101 | - return GeoCacheData.getRouteCode(prev); | |
| 102 | - } | |
| 103 | - } | |
| 104 | - return null; | |
| 105 | - } | |
| 106 | - | |
| 107 | - public static List<StationRoute> prevMultiStation(GpsEntity gps) { | |
| 108 | - List<StationRoute> rs = new ArrayList<>(); | |
| 109 | - List<GpsExecTrail> trails = trailListMultimap.get(gps.getNbbm()); | |
| 110 | - if(null == trails || trails.size() == 0) | |
| 111 | - return null; | |
| 112 | - | |
| 113 | - for(int i = trails.size() - 1; i > 0; i--){ | |
| 114 | - rs.addAll(searchLinked(trails.get(i).getSrs(), gps.getUpDown())); | |
| 115 | - if(rs.size() > 3) | |
| 116 | - break; | |
| 117 | - } | |
| 118 | - return rs; | |
| 119 | - } | |
| 120 | - | |
| 121 | - private static List<StationRoute> searchLinked(LinkedList<GpsEntity> list, int upDown){ | |
| 122 | - List<StationRoute> rs = new ArrayList<>(); | |
| 123 | - Iterator<GpsEntity> iterator = list.iterator(); | |
| 124 | - GpsEntity gps; | |
| 125 | - int prevCode=0; | |
| 126 | - while (iterator.hasNext()){ | |
| 127 | - gps = iterator.next(); | |
| 128 | - if(gps.getInstation()!=1) | |
| 129 | - continue; | |
| 130 | - | |
| 131 | - if(gps.getUpDown() != upDown) | |
| 132 | - break; | |
| 133 | - | |
| 134 | - if(gps.getStation().getRouteSort() != prevCode) | |
| 135 | - rs.add(gps.getStation()); | |
| 136 | - | |
| 137 | - prevCode = gps.getStation().getRouteSort(); | |
| 138 | - | |
| 139 | - if(rs.size() >= 3) | |
| 140 | - break; | |
| 141 | - } | |
| 142 | - return rs; | |
| 143 | - } | |
| 144 | -} | |
| 1 | +package com.bsth.data.gpsdata_v2.cache; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 4 | +import com.bsth.data.gpsdata_v2.entity.StationRoute; | |
| 5 | +import com.bsth.data.gpsdata_v2.entity.trail.GpsExecTrail; | |
| 6 | +import com.bsth.data.gpsdata_v2.utils.CircleQueue; | |
| 7 | +import com.google.common.collect.ArrayListMultimap; | |
| 8 | +import org.slf4j.Logger; | |
| 9 | +import org.slf4j.LoggerFactory; | |
| 10 | + | |
| 11 | +import java.util.*; | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * gps 数据缓存 | |
| 15 | + * Created by panzhao on 2017/11/15. | |
| 16 | + */ | |
| 17 | +public class GpsCacheData { | |
| 18 | + | |
| 19 | + /** | |
| 20 | + * 每辆车缓存最后300条gps | |
| 21 | + */ | |
| 22 | + private static final int CACHE_SIZE = 300; | |
| 23 | + private static Map<String, CircleQueue<GpsEntity>> gpsCacheMap = new HashMap<>(); | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 车辆执行班次的详细 进出站数据 | |
| 27 | + */ | |
| 28 | + private static ArrayListMultimap<String, GpsExecTrail> trailListMultimap = ArrayListMultimap.create(); | |
| 29 | + | |
| 30 | + static Logger logger = LoggerFactory.getLogger(GpsCacheData.class); | |
| 31 | + | |
| 32 | + public static CircleQueue<GpsEntity> getGps(String device) { | |
| 33 | + return gpsCacheMap.get(device); | |
| 34 | + } | |
| 35 | + | |
| 36 | + public static GpsExecTrail gpsExecTrail(String nbbm){ | |
| 37 | + List<GpsExecTrail> list = trailListMultimap.get(nbbm); | |
| 38 | + | |
| 39 | + GpsExecTrail trail; | |
| 40 | + if(null == list || list.size() == 0 | |
| 41 | + || list.get(list.size() - 1).isEnd()){ | |
| 42 | + trail = new GpsExecTrail(); | |
| 43 | + | |
| 44 | + trailListMultimap.put(nbbm, trail); | |
| 45 | + } | |
| 46 | + else{ | |
| 47 | + trail = list.get(list.size() - 1); | |
| 48 | + } | |
| 49 | + | |
| 50 | + return trail; | |
| 51 | + } | |
| 52 | + | |
| 53 | + public static void out(GpsEntity gps){ | |
| 54 | + GpsExecTrail trail = gpsExecTrail(gps.getNbbm()); | |
| 55 | + trail.getSrs().add(gps); | |
| 56 | + | |
| 57 | + } | |
| 58 | + | |
| 59 | + public static void in(GpsEntity gps, boolean end){ | |
| 60 | + GpsExecTrail trail = gpsExecTrail(gps.getNbbm()); | |
| 61 | + trail.getSrs().add(gps); | |
| 62 | + trail.setEnd(end); | |
| 63 | + } | |
| 64 | + | |
| 65 | + public static GpsEntity getPrev(GpsEntity gps){ | |
| 66 | + CircleQueue<GpsEntity> queue = gpsCacheMap.get(gps.getDeviceId()); | |
| 67 | + if(queue != null) | |
| 68 | + return queue.getTail(); | |
| 69 | + return null; | |
| 70 | + } | |
| 71 | + | |
| 72 | + public static void putGps(GpsEntity gps) { | |
| 73 | + CircleQueue<GpsEntity> queue = gpsCacheMap.get(gps.getDeviceId()); | |
| 74 | + if (queue == null) { | |
| 75 | + queue = new CircleQueue<>(CACHE_SIZE); | |
| 76 | + gpsCacheMap.put(gps.getDeviceId(), queue); | |
| 77 | + } | |
| 78 | + queue.add(gps); | |
| 79 | + } | |
| 80 | + | |
| 81 | + public static void clear(String deviceId) { | |
| 82 | + try { | |
| 83 | + CircleQueue<GpsEntity> queue = gpsCacheMap.get(deviceId); | |
| 84 | + if (queue != null) | |
| 85 | + queue.clear(); | |
| 86 | + } catch (Exception e) { | |
| 87 | + logger.error("", e); | |
| 88 | + } | |
| 89 | + } | |
| 90 | + | |
| 91 | + public static StationRoute prevStation(GpsEntity gps) { | |
| 92 | + List<GpsExecTrail> trails = trailListMultimap.get(gps.getNbbm()); | |
| 93 | + if(null == trails || trails.size() == 0) | |
| 94 | + return null; | |
| 95 | + | |
| 96 | + GpsEntity prev; | |
| 97 | + for(int i = trails.size() - 1; i > 0; i--){ | |
| 98 | + prev = trails.get(i).getSrs().peekLast(); | |
| 99 | + | |
| 100 | + if(prev != null){ | |
| 101 | + return GeoCacheData.getRouteCode(prev); | |
| 102 | + } | |
| 103 | + } | |
| 104 | + return null; | |
| 105 | + } | |
| 106 | + | |
| 107 | + public static List<StationRoute> prevMultiStation(GpsEntity gps) { | |
| 108 | + List<StationRoute> rs = new ArrayList<>(); | |
| 109 | + List<GpsExecTrail> trails = trailListMultimap.get(gps.getNbbm()); | |
| 110 | + if(null == trails || trails.size() == 0) | |
| 111 | + return null; | |
| 112 | + | |
| 113 | + for(int i = trails.size() - 1; i > 0; i--){ | |
| 114 | + rs.addAll(searchLinked(trails.get(i).getSrs(), gps.getUpDown())); | |
| 115 | + if(rs.size() > 3) | |
| 116 | + break; | |
| 117 | + } | |
| 118 | + return rs; | |
| 119 | + } | |
| 120 | + | |
| 121 | + private static List<StationRoute> searchLinked(LinkedList<GpsEntity> list, int upDown){ | |
| 122 | + List<StationRoute> rs = new ArrayList<>(); | |
| 123 | + Iterator<GpsEntity> iterator = list.iterator(); | |
| 124 | + GpsEntity gps; | |
| 125 | + int prevCode=0; | |
| 126 | + while (iterator.hasNext()){ | |
| 127 | + gps = iterator.next(); | |
| 128 | + if(gps.getInstation()!=1) | |
| 129 | + continue; | |
| 130 | + | |
| 131 | + if(gps.getUpDown() != upDown) | |
| 132 | + break; | |
| 133 | + | |
| 134 | + if(gps.getStation().getRouteSort() != prevCode) | |
| 135 | + rs.add(gps.getStation()); | |
| 136 | + | |
| 137 | + prevCode = gps.getStation().getRouteSort(); | |
| 138 | + | |
| 139 | + if(rs.size() >= 3) | |
| 140 | + break; | |
| 141 | + } | |
| 142 | + return rs; | |
| 143 | + } | |
| 144 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/entity/CtLineString.java
| 1 | -package com.bsth.data.gpsdata_v2.entity; | |
| 2 | - | |
| 3 | -import com.bsth.util.Geo.Point; | |
| 4 | - | |
| 5 | -import java.util.List; | |
| 6 | - | |
| 7 | -/** | |
| 8 | - * Created by panzhao on 2017/11/15. | |
| 9 | - */ | |
| 10 | -public class CtLineString { | |
| 11 | - | |
| 12 | - public CtLineString(){} | |
| 13 | - public CtLineString(List<Point> ps){ | |
| 14 | - s = ps.get(0); | |
| 15 | - e = ps.get(1); | |
| 16 | - } | |
| 17 | - | |
| 18 | - Point s; | |
| 19 | - | |
| 20 | - Point e; | |
| 21 | - | |
| 22 | - public Point getS() { | |
| 23 | - return s; | |
| 24 | - } | |
| 25 | - | |
| 26 | - public void setS(Point s) { | |
| 27 | - this.s = s; | |
| 28 | - } | |
| 29 | - | |
| 30 | - public Point getE() { | |
| 31 | - return e; | |
| 32 | - } | |
| 33 | - | |
| 34 | - public void setE(Point e) { | |
| 35 | - this.e = e; | |
| 36 | - } | |
| 37 | -} | |
| 1 | +package com.bsth.data.gpsdata_v2.entity; | |
| 2 | + | |
| 3 | +import com.bsth.util.Geo.Point; | |
| 4 | + | |
| 5 | +import java.util.List; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * Created by panzhao on 2017/11/15. | |
| 9 | + */ | |
| 10 | +public class CtLineString { | |
| 11 | + | |
| 12 | + public CtLineString(){} | |
| 13 | + public CtLineString(List<Point> ps){ | |
| 14 | + s = ps.get(0); | |
| 15 | + e = ps.get(1); | |
| 16 | + } | |
| 17 | + | |
| 18 | + Point s; | |
| 19 | + | |
| 20 | + Point e; | |
| 21 | + | |
| 22 | + public Point getS() { | |
| 23 | + return s; | |
| 24 | + } | |
| 25 | + | |
| 26 | + public void setS(Point s) { | |
| 27 | + this.s = s; | |
| 28 | + } | |
| 29 | + | |
| 30 | + public Point getE() { | |
| 31 | + return e; | |
| 32 | + } | |
| 33 | + | |
| 34 | + public void setE(Point e) { | |
| 35 | + this.e = e; | |
| 36 | + } | |
| 37 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/entity/GpsEntity.java
| 1 | -package com.bsth.data.gpsdata_v2.entity; | |
| 2 | - | |
| 3 | -import com.fasterxml.jackson.annotation.JsonIgnore; | |
| 4 | - | |
| 5 | -/** | |
| 6 | - * | |
| 7 | - * @ClassName: GpsRealData | |
| 8 | - * @Description: TODO(HTTP接口的实时GPS数据) | |
| 9 | - * @author PanZhao | |
| 10 | - * @date 2016年5月11日 下午4:32:07 | |
| 11 | - * | |
| 12 | - */ | |
| 13 | -public class GpsEntity implements Cloneable{ | |
| 14 | - | |
| 15 | - /** 公司代码 */ | |
| 16 | - private Short companyCode; | |
| 17 | - | |
| 18 | - /** 线路编码 */ | |
| 19 | - private String lineId; | |
| 20 | - | |
| 21 | - /** 设备编码 */ | |
| 22 | - private String deviceId; | |
| 23 | - | |
| 24 | - /** 停车场编码 */ | |
| 25 | - private String carparkNo; | |
| 26 | - | |
| 27 | - /** 站点编码 */ | |
| 28 | - private String stopNo; | |
| 29 | - | |
| 30 | - /** 站点名称 */ | |
| 31 | - private String stationName; | |
| 32 | - | |
| 33 | - /** 到站时间 */ | |
| 34 | - private long arrTime; | |
| 35 | - | |
| 36 | - /** 经度 */ | |
| 37 | - private Float lon; | |
| 38 | - | |
| 39 | - /** 纬度 */ | |
| 40 | - private Float lat; | |
| 41 | - | |
| 42 | - /** GPS发送时间戳 */ | |
| 43 | - private Long timestamp; | |
| 44 | - | |
| 45 | - /** 网关收到时间 */ | |
| 46 | - private Long serverTimestamp; | |
| 47 | - | |
| 48 | - /** 速度 */ | |
| 49 | - private Float speed; | |
| 50 | - | |
| 51 | - /** 方向(角度) */ | |
| 52 | - private float direction; | |
| 53 | - | |
| 54 | - /** 营运状态( 0 营运 ,1 非营运, -1 无效) */ | |
| 55 | - private Integer state; | |
| 56 | - | |
| 57 | - /** 上下行(0 上行 , 1 下行 , -1 无效) */ | |
| 58 | - private Byte upDown; | |
| 59 | - | |
| 60 | - /** 车辆内部编码 */ | |
| 61 | - private String nbbm; | |
| 62 | - | |
| 63 | - /** 预计到达终点时间 */ | |
| 64 | - private Float expectStopTime; | |
| 65 | - | |
| 66 | - /** 当前执行班次ID */ | |
| 67 | - private Long schId; | |
| 68 | - | |
| 69 | - private int version; | |
| 70 | - | |
| 71 | - /** 0: 站外 1:站内 2:场内 */ | |
| 72 | - private int instation; | |
| 73 | - | |
| 74 | - /** 站点信息,站内时有值 */ | |
| 75 | - @JsonIgnore | |
| 76 | - private StationRoute station; | |
| 77 | - | |
| 78 | - /** | |
| 79 | - * 前置约束 -站点编码 | |
| 80 | - */ | |
| 81 | - @JsonIgnore | |
| 82 | - private String premiseCode; | |
| 83 | - | |
| 84 | - /** 状态 */ | |
| 85 | - private String signalState = "normal"; | |
| 86 | - | |
| 87 | - /** 异常状态 */ | |
| 88 | - private String abnormalStatus; | |
| 89 | - | |
| 90 | - /** 越界距离 */ | |
| 91 | - private double outOfBoundDistance; | |
| 92 | - | |
| 93 | - /** gps是否有效 设备端发送的状态 */ | |
| 94 | - private int valid; | |
| 95 | - | |
| 96 | - /** | |
| 97 | - * 数据来源 | |
| 98 | - * 1:网关 | |
| 99 | - * 0:转发 | |
| 100 | - */ | |
| 101 | - private int source = -1; | |
| 102 | - | |
| 103 | - public Object clone() { | |
| 104 | - try { | |
| 105 | - return super.clone(); | |
| 106 | - } catch (CloneNotSupportedException e) { | |
| 107 | - return null; | |
| 108 | - } | |
| 109 | - } | |
| 110 | - | |
| 111 | - public String getDeviceId() { | |
| 112 | - return deviceId; | |
| 113 | - } | |
| 114 | - | |
| 115 | - public void setDeviceId(String deviceId) { | |
| 116 | - this.deviceId = deviceId; | |
| 117 | - } | |
| 118 | - | |
| 119 | - public String getCarparkNo() { | |
| 120 | - return carparkNo; | |
| 121 | - } | |
| 122 | - | |
| 123 | - public void setCarparkNo(String carparkNo) { | |
| 124 | - this.carparkNo = carparkNo; | |
| 125 | - } | |
| 126 | - | |
| 127 | - public String getStopNo() { | |
| 128 | - return stopNo; | |
| 129 | - } | |
| 130 | - | |
| 131 | - public void setStopNo(String stopNo) { | |
| 132 | - this.stopNo = stopNo; | |
| 133 | - } | |
| 134 | - | |
| 135 | - public Float getLon() { | |
| 136 | - return lon; | |
| 137 | - } | |
| 138 | - | |
| 139 | - public void setLon(Float lon) { | |
| 140 | - this.lon = lon; | |
| 141 | - } | |
| 142 | - | |
| 143 | - public Float getLat() { | |
| 144 | - return lat; | |
| 145 | - } | |
| 146 | - | |
| 147 | - public void setLat(Float lat) { | |
| 148 | - this.lat = lat; | |
| 149 | - } | |
| 150 | - | |
| 151 | - public Long getTimestamp() { | |
| 152 | - return timestamp; | |
| 153 | - } | |
| 154 | - | |
| 155 | - public void setTimestamp(Long timestamp) { | |
| 156 | - this.timestamp = timestamp; | |
| 157 | - } | |
| 158 | - | |
| 159 | - | |
| 160 | - public Integer getState() { | |
| 161 | - return state; | |
| 162 | - } | |
| 163 | - | |
| 164 | - public void setState(Integer state) { | |
| 165 | - this.state = state; | |
| 166 | - } | |
| 167 | - | |
| 168 | - public String getNbbm() { | |
| 169 | - return nbbm; | |
| 170 | - } | |
| 171 | - | |
| 172 | - public void setNbbm(String nbbm) { | |
| 173 | - this.nbbm = nbbm; | |
| 174 | - } | |
| 175 | - | |
| 176 | - public String getStationName() { | |
| 177 | - return stationName; | |
| 178 | - } | |
| 179 | - | |
| 180 | - public void setStationName(String stationName) { | |
| 181 | - this.stationName = stationName; | |
| 182 | - } | |
| 183 | - | |
| 184 | - public long getArrTime() { | |
| 185 | - return arrTime; | |
| 186 | - } | |
| 187 | - | |
| 188 | - public void setArrTime(long arrTime) { | |
| 189 | - this.arrTime = arrTime; | |
| 190 | - } | |
| 191 | - | |
| 192 | - public Float getExpectStopTime() { | |
| 193 | - return expectStopTime; | |
| 194 | - } | |
| 195 | - | |
| 196 | - public void setExpectStopTime(Float expectStopTime) { | |
| 197 | - this.expectStopTime = expectStopTime; | |
| 198 | - } | |
| 199 | - | |
| 200 | - public String getLineId() { | |
| 201 | - return lineId; | |
| 202 | - } | |
| 203 | - | |
| 204 | - public void setLineId(String lineId) { | |
| 205 | - this.lineId = lineId; | |
| 206 | - } | |
| 207 | - | |
| 208 | - public Long getSchId() { | |
| 209 | - return schId; | |
| 210 | - } | |
| 211 | - | |
| 212 | - public void setSchId(Long schId) { | |
| 213 | - this.schId = schId; | |
| 214 | - } | |
| 215 | - | |
| 216 | - | |
| 217 | - public int getVersion() { | |
| 218 | - return version; | |
| 219 | - } | |
| 220 | - | |
| 221 | - public void setVersion(int version) { | |
| 222 | - this.version = version; | |
| 223 | - } | |
| 224 | - | |
| 225 | - public StationRoute getStation() { | |
| 226 | - return station; | |
| 227 | - } | |
| 228 | - | |
| 229 | - public void setStation(StationRoute station) { | |
| 230 | - this.station = station; | |
| 231 | - } | |
| 232 | - | |
| 233 | - public String getSignalState() { | |
| 234 | - return signalState; | |
| 235 | - } | |
| 236 | - | |
| 237 | - public void setSignalState(String signalState) { | |
| 238 | - this.signalState = signalState; | |
| 239 | - } | |
| 240 | - | |
| 241 | - public int getInstation() { | |
| 242 | - return instation; | |
| 243 | - } | |
| 244 | - | |
| 245 | - public void setInstation(int instation) { | |
| 246 | - this.instation = instation; | |
| 247 | - } | |
| 248 | - | |
| 249 | - public String getAbnormalStatus() { | |
| 250 | - return abnormalStatus; | |
| 251 | - } | |
| 252 | - | |
| 253 | - public void setAbnormalStatus(String abnormalStatus) { | |
| 254 | - this.abnormalStatus = abnormalStatus; | |
| 255 | - } | |
| 256 | - | |
| 257 | - public double getOutOfBoundDistance() { | |
| 258 | - return outOfBoundDistance; | |
| 259 | - } | |
| 260 | - | |
| 261 | - public void setOutOfBoundDistance(double outOfBoundDistance) { | |
| 262 | - this.outOfBoundDistance = outOfBoundDistance; | |
| 263 | - } | |
| 264 | - | |
| 265 | - public int getValid() { | |
| 266 | - return valid; | |
| 267 | - } | |
| 268 | - | |
| 269 | - public void setValid(int valid) { | |
| 270 | - this.valid = valid; | |
| 271 | - } | |
| 272 | - | |
| 273 | - | |
| 274 | - | |
| 275 | - public short getCompanyCode() { | |
| 276 | - return companyCode; | |
| 277 | - } | |
| 278 | - | |
| 279 | - public void setCompanyCode(short companyCode) { | |
| 280 | - this.companyCode = companyCode; | |
| 281 | - } | |
| 282 | - | |
| 283 | - public Byte getUpDown() { | |
| 284 | - return upDown; | |
| 285 | - } | |
| 286 | - | |
| 287 | - public void setUpDown(Byte upDown) { | |
| 288 | - this.upDown = upDown; | |
| 289 | - } | |
| 290 | - | |
| 291 | - | |
| 292 | - public float getDirection() { | |
| 293 | - return direction; | |
| 294 | - } | |
| 295 | - | |
| 296 | - public void setDirection(float direction) { | |
| 297 | - this.direction = direction; | |
| 298 | - } | |
| 299 | - | |
| 300 | - public Float getSpeed() { | |
| 301 | - return speed; | |
| 302 | - } | |
| 303 | - | |
| 304 | - public void setSpeed(Float speed) { | |
| 305 | - this.speed = speed; | |
| 306 | - } | |
| 307 | - | |
| 308 | - public int getSource() { | |
| 309 | - return source; | |
| 310 | - } | |
| 311 | - | |
| 312 | - public void setSource(int source) { | |
| 313 | - this.source = source; | |
| 314 | - } | |
| 315 | - | |
| 316 | - public void offline(){ | |
| 317 | - this.setAbnormalStatus("offline"); | |
| 318 | - } | |
| 319 | - | |
| 320 | -/* public boolean isOnline(){ | |
| 321 | - if(isOffline()) | |
| 322 | - return false; | |
| 323 | - | |
| 324 | - long t = System.currentTimeMillis(); | |
| 325 | - | |
| 326 | - if((t - this.getServerTimestamp()) > 1000 * 60 * 2){ | |
| 327 | - return false; | |
| 328 | - } | |
| 329 | - | |
| 330 | - if((this.getServerTimestamp() - t) > 1000 * 60 * 3){ | |
| 331 | - return false; | |
| 332 | - } | |
| 333 | - return true; | |
| 334 | - }*/ | |
| 335 | - | |
| 336 | - /** | |
| 337 | - * 是否营运 | |
| 338 | - * @return | |
| 339 | - */ | |
| 340 | - public boolean isService(){ | |
| 341 | - return state!=null && state==0; | |
| 342 | - } | |
| 343 | - | |
| 344 | - public boolean isOffline(){ | |
| 345 | - return this.getAbnormalStatus() != null && this.getAbnormalStatus().equals("offline"); | |
| 346 | - } | |
| 347 | - | |
| 348 | - public Long getServerTimestamp() { | |
| 349 | - return serverTimestamp; | |
| 350 | - } | |
| 351 | - | |
| 352 | - public void setServerTimestamp(Long serverTimestamp) { | |
| 353 | - this.serverTimestamp = serverTimestamp; | |
| 354 | - } | |
| 355 | - | |
| 356 | - public String getPremiseCode() { | |
| 357 | - return premiseCode; | |
| 358 | - } | |
| 359 | - | |
| 360 | - public void setPremiseCode(String premiseCode) { | |
| 361 | - this.premiseCode = premiseCode; | |
| 362 | - } | |
| 363 | -} | |
| 1 | +package com.bsth.data.gpsdata_v2.entity; | |
| 2 | + | |
| 3 | +import com.fasterxml.jackson.annotation.JsonIgnore; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * | |
| 7 | + * @ClassName: GpsRealData | |
| 8 | + * @Description: TODO(HTTP接口的实时GPS数据) | |
| 9 | + * @author PanZhao | |
| 10 | + * @date 2016年5月11日 下午4:32:07 | |
| 11 | + * | |
| 12 | + */ | |
| 13 | +public class GpsEntity implements Cloneable{ | |
| 14 | + | |
| 15 | + /** 公司代码 */ | |
| 16 | + private Short companyCode; | |
| 17 | + | |
| 18 | + /** 线路编码 */ | |
| 19 | + private String lineId; | |
| 20 | + | |
| 21 | + /** 设备编码 */ | |
| 22 | + private String deviceId; | |
| 23 | + | |
| 24 | + /** 停车场编码 */ | |
| 25 | + private String carparkNo; | |
| 26 | + | |
| 27 | + /** 站点编码 */ | |
| 28 | + private String stopNo; | |
| 29 | + | |
| 30 | + /** 站点名称 */ | |
| 31 | + private String stationName; | |
| 32 | + | |
| 33 | + /** 到站时间 */ | |
| 34 | + private long arrTime; | |
| 35 | + | |
| 36 | + /** 经度 */ | |
| 37 | + private Float lon; | |
| 38 | + | |
| 39 | + /** 纬度 */ | |
| 40 | + private Float lat; | |
| 41 | + | |
| 42 | + /** GPS发送时间戳 */ | |
| 43 | + private Long timestamp; | |
| 44 | + | |
| 45 | + /** 网关收到时间 */ | |
| 46 | + private Long serverTimestamp; | |
| 47 | + | |
| 48 | + /** 速度 */ | |
| 49 | + private Float speed; | |
| 50 | + | |
| 51 | + /** 方向(角度) */ | |
| 52 | + private float direction; | |
| 53 | + | |
| 54 | + /** 营运状态( 0 营运 ,1 非营运, -1 无效) */ | |
| 55 | + private Integer state; | |
| 56 | + | |
| 57 | + /** 上下行(0 上行 , 1 下行 , -1 无效) */ | |
| 58 | + private Byte upDown; | |
| 59 | + | |
| 60 | + /** 车辆内部编码 */ | |
| 61 | + private String nbbm; | |
| 62 | + | |
| 63 | + /** 预计到达终点时间 */ | |
| 64 | + private Float expectStopTime; | |
| 65 | + | |
| 66 | + /** 当前执行班次ID */ | |
| 67 | + private Long schId; | |
| 68 | + | |
| 69 | + private int version; | |
| 70 | + | |
| 71 | + /** 0: 站外 1:站内 2:场内 */ | |
| 72 | + private int instation; | |
| 73 | + | |
| 74 | + /** 站点信息,站内时有值 */ | |
| 75 | + @JsonIgnore | |
| 76 | + private StationRoute station; | |
| 77 | + | |
| 78 | + /** | |
| 79 | + * 前置约束 -站点编码 | |
| 80 | + */ | |
| 81 | + @JsonIgnore | |
| 82 | + private String premiseCode; | |
| 83 | + | |
| 84 | + /** 状态 */ | |
| 85 | + private String signalState = "normal"; | |
| 86 | + | |
| 87 | + /** 异常状态 */ | |
| 88 | + private String abnormalStatus; | |
| 89 | + | |
| 90 | + /** 越界距离 */ | |
| 91 | + private double outOfBoundDistance; | |
| 92 | + | |
| 93 | + /** gps是否有效 设备端发送的状态 */ | |
| 94 | + private int valid; | |
| 95 | + | |
| 96 | + /** | |
| 97 | + * 数据来源 | |
| 98 | + * 1:网关 | |
| 99 | + * 0:转发 | |
| 100 | + */ | |
| 101 | + private int source = -1; | |
| 102 | + | |
| 103 | + public Object clone() { | |
| 104 | + try { | |
| 105 | + return super.clone(); | |
| 106 | + } catch (CloneNotSupportedException e) { | |
| 107 | + return null; | |
| 108 | + } | |
| 109 | + } | |
| 110 | + | |
| 111 | + public String getDeviceId() { | |
| 112 | + return deviceId; | |
| 113 | + } | |
| 114 | + | |
| 115 | + public void setDeviceId(String deviceId) { | |
| 116 | + this.deviceId = deviceId; | |
| 117 | + } | |
| 118 | + | |
| 119 | + public String getCarparkNo() { | |
| 120 | + return carparkNo; | |
| 121 | + } | |
| 122 | + | |
| 123 | + public void setCarparkNo(String carparkNo) { | |
| 124 | + this.carparkNo = carparkNo; | |
| 125 | + } | |
| 126 | + | |
| 127 | + public String getStopNo() { | |
| 128 | + return stopNo; | |
| 129 | + } | |
| 130 | + | |
| 131 | + public void setStopNo(String stopNo) { | |
| 132 | + this.stopNo = stopNo; | |
| 133 | + } | |
| 134 | + | |
| 135 | + public Float getLon() { | |
| 136 | + return lon; | |
| 137 | + } | |
| 138 | + | |
| 139 | + public void setLon(Float lon) { | |
| 140 | + this.lon = lon; | |
| 141 | + } | |
| 142 | + | |
| 143 | + public Float getLat() { | |
| 144 | + return lat; | |
| 145 | + } | |
| 146 | + | |
| 147 | + public void setLat(Float lat) { | |
| 148 | + this.lat = lat; | |
| 149 | + } | |
| 150 | + | |
| 151 | + public Long getTimestamp() { | |
| 152 | + return timestamp; | |
| 153 | + } | |
| 154 | + | |
| 155 | + public void setTimestamp(Long timestamp) { | |
| 156 | + this.timestamp = timestamp; | |
| 157 | + } | |
| 158 | + | |
| 159 | + | |
| 160 | + public Integer getState() { | |
| 161 | + return state; | |
| 162 | + } | |
| 163 | + | |
| 164 | + public void setState(Integer state) { | |
| 165 | + this.state = state; | |
| 166 | + } | |
| 167 | + | |
| 168 | + public String getNbbm() { | |
| 169 | + return nbbm; | |
| 170 | + } | |
| 171 | + | |
| 172 | + public void setNbbm(String nbbm) { | |
| 173 | + this.nbbm = nbbm; | |
| 174 | + } | |
| 175 | + | |
| 176 | + public String getStationName() { | |
| 177 | + return stationName; | |
| 178 | + } | |
| 179 | + | |
| 180 | + public void setStationName(String stationName) { | |
| 181 | + this.stationName = stationName; | |
| 182 | + } | |
| 183 | + | |
| 184 | + public long getArrTime() { | |
| 185 | + return arrTime; | |
| 186 | + } | |
| 187 | + | |
| 188 | + public void setArrTime(long arrTime) { | |
| 189 | + this.arrTime = arrTime; | |
| 190 | + } | |
| 191 | + | |
| 192 | + public Float getExpectStopTime() { | |
| 193 | + return expectStopTime; | |
| 194 | + } | |
| 195 | + | |
| 196 | + public void setExpectStopTime(Float expectStopTime) { | |
| 197 | + this.expectStopTime = expectStopTime; | |
| 198 | + } | |
| 199 | + | |
| 200 | + public String getLineId() { | |
| 201 | + return lineId; | |
| 202 | + } | |
| 203 | + | |
| 204 | + public void setLineId(String lineId) { | |
| 205 | + this.lineId = lineId; | |
| 206 | + } | |
| 207 | + | |
| 208 | + public Long getSchId() { | |
| 209 | + return schId; | |
| 210 | + } | |
| 211 | + | |
| 212 | + public void setSchId(Long schId) { | |
| 213 | + this.schId = schId; | |
| 214 | + } | |
| 215 | + | |
| 216 | + | |
| 217 | + public int getVersion() { | |
| 218 | + return version; | |
| 219 | + } | |
| 220 | + | |
| 221 | + public void setVersion(int version) { | |
| 222 | + this.version = version; | |
| 223 | + } | |
| 224 | + | |
| 225 | + public StationRoute getStation() { | |
| 226 | + return station; | |
| 227 | + } | |
| 228 | + | |
| 229 | + public void setStation(StationRoute station) { | |
| 230 | + this.station = station; | |
| 231 | + } | |
| 232 | + | |
| 233 | + public String getSignalState() { | |
| 234 | + return signalState; | |
| 235 | + } | |
| 236 | + | |
| 237 | + public void setSignalState(String signalState) { | |
| 238 | + this.signalState = signalState; | |
| 239 | + } | |
| 240 | + | |
| 241 | + public int getInstation() { | |
| 242 | + return instation; | |
| 243 | + } | |
| 244 | + | |
| 245 | + public void setInstation(int instation) { | |
| 246 | + this.instation = instation; | |
| 247 | + } | |
| 248 | + | |
| 249 | + public String getAbnormalStatus() { | |
| 250 | + return abnormalStatus; | |
| 251 | + } | |
| 252 | + | |
| 253 | + public void setAbnormalStatus(String abnormalStatus) { | |
| 254 | + this.abnormalStatus = abnormalStatus; | |
| 255 | + } | |
| 256 | + | |
| 257 | + public double getOutOfBoundDistance() { | |
| 258 | + return outOfBoundDistance; | |
| 259 | + } | |
| 260 | + | |
| 261 | + public void setOutOfBoundDistance(double outOfBoundDistance) { | |
| 262 | + this.outOfBoundDistance = outOfBoundDistance; | |
| 263 | + } | |
| 264 | + | |
| 265 | + public int getValid() { | |
| 266 | + return valid; | |
| 267 | + } | |
| 268 | + | |
| 269 | + public void setValid(int valid) { | |
| 270 | + this.valid = valid; | |
| 271 | + } | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + public short getCompanyCode() { | |
| 276 | + return companyCode; | |
| 277 | + } | |
| 278 | + | |
| 279 | + public void setCompanyCode(short companyCode) { | |
| 280 | + this.companyCode = companyCode; | |
| 281 | + } | |
| 282 | + | |
| 283 | + public Byte getUpDown() { | |
| 284 | + return upDown; | |
| 285 | + } | |
| 286 | + | |
| 287 | + public void setUpDown(Byte upDown) { | |
| 288 | + this.upDown = upDown; | |
| 289 | + } | |
| 290 | + | |
| 291 | + | |
| 292 | + public float getDirection() { | |
| 293 | + return direction; | |
| 294 | + } | |
| 295 | + | |
| 296 | + public void setDirection(float direction) { | |
| 297 | + this.direction = direction; | |
| 298 | + } | |
| 299 | + | |
| 300 | + public Float getSpeed() { | |
| 301 | + return speed; | |
| 302 | + } | |
| 303 | + | |
| 304 | + public void setSpeed(Float speed) { | |
| 305 | + this.speed = speed; | |
| 306 | + } | |
| 307 | + | |
| 308 | + public int getSource() { | |
| 309 | + return source; | |
| 310 | + } | |
| 311 | + | |
| 312 | + public void setSource(int source) { | |
| 313 | + this.source = source; | |
| 314 | + } | |
| 315 | + | |
| 316 | + public void offline(){ | |
| 317 | + this.setAbnormalStatus("offline"); | |
| 318 | + } | |
| 319 | + | |
| 320 | +/* public boolean isOnline(){ | |
| 321 | + if(isOffline()) | |
| 322 | + return false; | |
| 323 | + | |
| 324 | + long t = System.currentTimeMillis(); | |
| 325 | + | |
| 326 | + if((t - this.getServerTimestamp()) > 1000 * 60 * 2){ | |
| 327 | + return false; | |
| 328 | + } | |
| 329 | + | |
| 330 | + if((this.getServerTimestamp() - t) > 1000 * 60 * 3){ | |
| 331 | + return false; | |
| 332 | + } | |
| 333 | + return true; | |
| 334 | + }*/ | |
| 335 | + | |
| 336 | + /** | |
| 337 | + * 是否营运 | |
| 338 | + * @return | |
| 339 | + */ | |
| 340 | + public boolean isService(){ | |
| 341 | + return state!=null && state==0; | |
| 342 | + } | |
| 343 | + | |
| 344 | + public boolean isOffline(){ | |
| 345 | + return this.getAbnormalStatus() != null && this.getAbnormalStatus().equals("offline"); | |
| 346 | + } | |
| 347 | + | |
| 348 | + public Long getServerTimestamp() { | |
| 349 | + return serverTimestamp; | |
| 350 | + } | |
| 351 | + | |
| 352 | + public void setServerTimestamp(Long serverTimestamp) { | |
| 353 | + this.serverTimestamp = serverTimestamp; | |
| 354 | + } | |
| 355 | + | |
| 356 | + public String getPremiseCode() { | |
| 357 | + return premiseCode; | |
| 358 | + } | |
| 359 | + | |
| 360 | + public void setPremiseCode(String premiseCode) { | |
| 361 | + this.premiseCode = premiseCode; | |
| 362 | + } | |
| 363 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/entity/PreconditionGeo.java
| 1 | -package com.bsth.data.gpsdata_v2.entity; | |
| 2 | - | |
| 3 | -import com.bsth.util.Geo.Polygon; | |
| 4 | - | |
| 5 | -/** | |
| 6 | - * 前置围栏 -地理坐标 | |
| 7 | - * Created by panzhao on 2017/9/23. | |
| 8 | - */ | |
| 9 | -public class PreconditionGeo { | |
| 10 | - | |
| 11 | - private String name; | |
| 12 | - | |
| 13 | - /** | |
| 14 | - * 前置约束的站点编码 | |
| 15 | - */ | |
| 16 | - private String stationCode; | |
| 17 | - | |
| 18 | - /** | |
| 19 | - * 线路编码 | |
| 20 | - */ | |
| 21 | - private String lineCode; | |
| 22 | - | |
| 23 | - /** | |
| 24 | - * 上下行 | |
| 25 | - */ | |
| 26 | - private int upDown; | |
| 27 | - | |
| 28 | - /** | |
| 29 | - * 多边形坐标 | |
| 30 | - */ | |
| 31 | - private String coords; | |
| 32 | - | |
| 33 | - private com.bsth.util.Geo.Polygon polygon; | |
| 34 | - | |
| 35 | - private Integer order; | |
| 36 | - | |
| 37 | - public String getName() { | |
| 38 | - return name; | |
| 39 | - } | |
| 40 | - | |
| 41 | - public void setName(String name) { | |
| 42 | - this.name = name; | |
| 43 | - } | |
| 44 | - | |
| 45 | - public String getStationCode() { | |
| 46 | - return stationCode; | |
| 47 | - } | |
| 48 | - | |
| 49 | - public void setStationCode(String stationCode) { | |
| 50 | - this.stationCode = stationCode; | |
| 51 | - } | |
| 52 | - | |
| 53 | - public String getLineCode() { | |
| 54 | - return lineCode; | |
| 55 | - } | |
| 56 | - | |
| 57 | - public void setLineCode(String lineCode) { | |
| 58 | - this.lineCode = lineCode; | |
| 59 | - } | |
| 60 | - | |
| 61 | - public int getUpDown() { | |
| 62 | - return upDown; | |
| 63 | - } | |
| 64 | - | |
| 65 | - public void setUpDown(int upDown) { | |
| 66 | - this.upDown = upDown; | |
| 67 | - } | |
| 68 | - | |
| 69 | - public String getCoords() { | |
| 70 | - return coords; | |
| 71 | - } | |
| 72 | - | |
| 73 | - public void setCoords(String coords) { | |
| 74 | - this.coords = coords; | |
| 75 | - } | |
| 76 | - | |
| 77 | - public Integer getOrder() { | |
| 78 | - return order; | |
| 79 | - } | |
| 80 | - | |
| 81 | - public void setOrder(Integer order) { | |
| 82 | - this.order = order; | |
| 83 | - } | |
| 84 | - | |
| 85 | - public Polygon getPolygon() { | |
| 86 | - return polygon; | |
| 87 | - } | |
| 88 | - | |
| 89 | - public void setPolygon(Polygon polygon) { | |
| 90 | - this.polygon = polygon; | |
| 91 | - } | |
| 92 | -} | |
| 1 | +package com.bsth.data.gpsdata_v2.entity; | |
| 2 | + | |
| 3 | +import com.bsth.util.Geo.Polygon; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * 前置围栏 -地理坐标 | |
| 7 | + * Created by panzhao on 2017/9/23. | |
| 8 | + */ | |
| 9 | +public class PreconditionGeo { | |
| 10 | + | |
| 11 | + private String name; | |
| 12 | + | |
| 13 | + /** | |
| 14 | + * 前置约束的站点编码 | |
| 15 | + */ | |
| 16 | + private String stationCode; | |
| 17 | + | |
| 18 | + /** | |
| 19 | + * 线路编码 | |
| 20 | + */ | |
| 21 | + private String lineCode; | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * 上下行 | |
| 25 | + */ | |
| 26 | + private int upDown; | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * 多边形坐标 | |
| 30 | + */ | |
| 31 | + private String coords; | |
| 32 | + | |
| 33 | + private com.bsth.util.Geo.Polygon polygon; | |
| 34 | + | |
| 35 | + private Integer order; | |
| 36 | + | |
| 37 | + public String getName() { | |
| 38 | + return name; | |
| 39 | + } | |
| 40 | + | |
| 41 | + public void setName(String name) { | |
| 42 | + this.name = name; | |
| 43 | + } | |
| 44 | + | |
| 45 | + public String getStationCode() { | |
| 46 | + return stationCode; | |
| 47 | + } | |
| 48 | + | |
| 49 | + public void setStationCode(String stationCode) { | |
| 50 | + this.stationCode = stationCode; | |
| 51 | + } | |
| 52 | + | |
| 53 | + public String getLineCode() { | |
| 54 | + return lineCode; | |
| 55 | + } | |
| 56 | + | |
| 57 | + public void setLineCode(String lineCode) { | |
| 58 | + this.lineCode = lineCode; | |
| 59 | + } | |
| 60 | + | |
| 61 | + public int getUpDown() { | |
| 62 | + return upDown; | |
| 63 | + } | |
| 64 | + | |
| 65 | + public void setUpDown(int upDown) { | |
| 66 | + this.upDown = upDown; | |
| 67 | + } | |
| 68 | + | |
| 69 | + public String getCoords() { | |
| 70 | + return coords; | |
| 71 | + } | |
| 72 | + | |
| 73 | + public void setCoords(String coords) { | |
| 74 | + this.coords = coords; | |
| 75 | + } | |
| 76 | + | |
| 77 | + public Integer getOrder() { | |
| 78 | + return order; | |
| 79 | + } | |
| 80 | + | |
| 81 | + public void setOrder(Integer order) { | |
| 82 | + this.order = order; | |
| 83 | + } | |
| 84 | + | |
| 85 | + public Polygon getPolygon() { | |
| 86 | + return polygon; | |
| 87 | + } | |
| 88 | + | |
| 89 | + public void setPolygon(Polygon polygon) { | |
| 90 | + this.polygon = polygon; | |
| 91 | + } | |
| 92 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/entity/StationRoute.java
| 1 | -package com.bsth.data.gpsdata_v2.entity; | |
| 2 | - | |
| 3 | -import com.bsth.util.Geo.Point; | |
| 4 | -import com.bsth.util.Geo.Polygon; | |
| 5 | - | |
| 6 | -/** | |
| 7 | - * Created by panzhao on 2016/12/23. | |
| 8 | - */ | |
| 9 | -public class StationRoute { | |
| 10 | - | |
| 11 | - /** | |
| 12 | - * 线路编码 | |
| 13 | - */ | |
| 14 | - private String lineCode; | |
| 15 | - | |
| 16 | - /** | |
| 17 | - * 上下行 | |
| 18 | - */ | |
| 19 | - private int directions; | |
| 20 | - | |
| 21 | - /** | |
| 22 | - * 站点编码 | |
| 23 | - */ | |
| 24 | - private String code; | |
| 25 | - | |
| 26 | - /** | |
| 27 | - * 路由顺序 | |
| 28 | - */ | |
| 29 | - private int routeSort; | |
| 30 | - | |
| 31 | - /** | |
| 32 | - * 站点位置 | |
| 33 | - */ | |
| 34 | - private Point point; | |
| 35 | - | |
| 36 | - /** | |
| 37 | - * 圆形半径 | |
| 38 | - */ | |
| 39 | - private Float radius; | |
| 40 | - | |
| 41 | - /** | |
| 42 | - * 多边形电子围栏 | |
| 43 | - */ | |
| 44 | - private Polygon polygon; | |
| 45 | - | |
| 46 | - /** | |
| 47 | - * 站点标记 | |
| 48 | - */ | |
| 49 | - private String mark; | |
| 50 | - | |
| 51 | - /** | |
| 52 | - * 下一站 | |
| 53 | - */ | |
| 54 | - private StationRoute next; | |
| 55 | - | |
| 56 | - /** | |
| 57 | - * 上一站 | |
| 58 | - */ | |
| 59 | - private StationRoute prve; | |
| 60 | - | |
| 61 | - private String name; | |
| 62 | - | |
| 63 | - /** | |
| 64 | - * 是否有前置进站约束 | |
| 65 | - */ | |
| 66 | - private boolean premise; | |
| 67 | - | |
| 68 | - public String getCode() { | |
| 69 | - return code; | |
| 70 | - } | |
| 71 | - | |
| 72 | - public void setCode(String code) { | |
| 73 | - this.code = code; | |
| 74 | - } | |
| 75 | - | |
| 76 | - public int getRouteSort() { | |
| 77 | - return routeSort; | |
| 78 | - } | |
| 79 | - | |
| 80 | - public void setRouteSort(int routeSort) { | |
| 81 | - this.routeSort = routeSort; | |
| 82 | - } | |
| 83 | - | |
| 84 | - public Point getPoint() { | |
| 85 | - return point; | |
| 86 | - } | |
| 87 | - | |
| 88 | - public void setPoint(Point point) { | |
| 89 | - this.point = point; | |
| 90 | - } | |
| 91 | - | |
| 92 | - public Float getRadius() { | |
| 93 | - return radius; | |
| 94 | - } | |
| 95 | - | |
| 96 | - public void setRadius(Float radius) { | |
| 97 | - this.radius = radius; | |
| 98 | - } | |
| 99 | - | |
| 100 | - public Polygon getPolygon() { | |
| 101 | - return polygon; | |
| 102 | - } | |
| 103 | - | |
| 104 | - public void setPolygon(Polygon polygon) { | |
| 105 | - this.polygon = polygon; | |
| 106 | - } | |
| 107 | - | |
| 108 | - public String getLineCode() { | |
| 109 | - return lineCode; | |
| 110 | - } | |
| 111 | - | |
| 112 | - public void setLineCode(String lineCode) { | |
| 113 | - this.lineCode = lineCode; | |
| 114 | - } | |
| 115 | - | |
| 116 | - public int getDirections() { | |
| 117 | - return directions; | |
| 118 | - } | |
| 119 | - | |
| 120 | - public void setDirections(int directions) { | |
| 121 | - this.directions = directions; | |
| 122 | - } | |
| 123 | - | |
| 124 | - public StationRoute getNext() { | |
| 125 | - return next; | |
| 126 | - } | |
| 127 | - | |
| 128 | - public void setNext(StationRoute next) { | |
| 129 | - this.next = next; | |
| 130 | - } | |
| 131 | - | |
| 132 | - public StationRoute getPrve() { | |
| 133 | - return prve; | |
| 134 | - } | |
| 135 | - | |
| 136 | - public void setPrve(StationRoute prve) { | |
| 137 | - this.prve = prve; | |
| 138 | - } | |
| 139 | - | |
| 140 | - public String getMark() { | |
| 141 | - return mark; | |
| 142 | - } | |
| 143 | - | |
| 144 | - public void setMark(String mark) { | |
| 145 | - this.mark = mark; | |
| 146 | - } | |
| 147 | - | |
| 148 | - public String getName() { | |
| 149 | - return name; | |
| 150 | - } | |
| 151 | - | |
| 152 | - public void setName(String name) { | |
| 153 | - this.name = name; | |
| 154 | - } | |
| 155 | - | |
| 156 | - public boolean isPremise() { | |
| 157 | - return premise; | |
| 158 | - } | |
| 159 | - | |
| 160 | - public void setPremise(boolean premise) { | |
| 161 | - this.premise = premise; | |
| 162 | - } | |
| 163 | -} | |
| 164 | - | |
| 1 | +package com.bsth.data.gpsdata_v2.entity; | |
| 2 | + | |
| 3 | +import com.bsth.util.Geo.Point; | |
| 4 | +import com.bsth.util.Geo.Polygon; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * Created by panzhao on 2016/12/23. | |
| 8 | + */ | |
| 9 | +public class StationRoute { | |
| 10 | + | |
| 11 | + /** | |
| 12 | + * 线路编码 | |
| 13 | + */ | |
| 14 | + private String lineCode; | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * 上下行 | |
| 18 | + */ | |
| 19 | + private int directions; | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * 站点编码 | |
| 23 | + */ | |
| 24 | + private String code; | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * 路由顺序 | |
| 28 | + */ | |
| 29 | + private int routeSort; | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * 站点位置 | |
| 33 | + */ | |
| 34 | + private Point point; | |
| 35 | + | |
| 36 | + /** | |
| 37 | + * 圆形半径 | |
| 38 | + */ | |
| 39 | + private Float radius; | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * 多边形电子围栏 | |
| 43 | + */ | |
| 44 | + private Polygon polygon; | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * 站点标记 | |
| 48 | + */ | |
| 49 | + private String mark; | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * 下一站 | |
| 53 | + */ | |
| 54 | + private StationRoute next; | |
| 55 | + | |
| 56 | + /** | |
| 57 | + * 上一站 | |
| 58 | + */ | |
| 59 | + private StationRoute prve; | |
| 60 | + | |
| 61 | + private String name; | |
| 62 | + | |
| 63 | + /** | |
| 64 | + * 是否有前置进站约束 | |
| 65 | + */ | |
| 66 | + private boolean premise; | |
| 67 | + | |
| 68 | + public String getCode() { | |
| 69 | + return code; | |
| 70 | + } | |
| 71 | + | |
| 72 | + public void setCode(String code) { | |
| 73 | + this.code = code; | |
| 74 | + } | |
| 75 | + | |
| 76 | + public int getRouteSort() { | |
| 77 | + return routeSort; | |
| 78 | + } | |
| 79 | + | |
| 80 | + public void setRouteSort(int routeSort) { | |
| 81 | + this.routeSort = routeSort; | |
| 82 | + } | |
| 83 | + | |
| 84 | + public Point getPoint() { | |
| 85 | + return point; | |
| 86 | + } | |
| 87 | + | |
| 88 | + public void setPoint(Point point) { | |
| 89 | + this.point = point; | |
| 90 | + } | |
| 91 | + | |
| 92 | + public Float getRadius() { | |
| 93 | + return radius; | |
| 94 | + } | |
| 95 | + | |
| 96 | + public void setRadius(Float radius) { | |
| 97 | + this.radius = radius; | |
| 98 | + } | |
| 99 | + | |
| 100 | + public Polygon getPolygon() { | |
| 101 | + return polygon; | |
| 102 | + } | |
| 103 | + | |
| 104 | + public void setPolygon(Polygon polygon) { | |
| 105 | + this.polygon = polygon; | |
| 106 | + } | |
| 107 | + | |
| 108 | + public String getLineCode() { | |
| 109 | + return lineCode; | |
| 110 | + } | |
| 111 | + | |
| 112 | + public void setLineCode(String lineCode) { | |
| 113 | + this.lineCode = lineCode; | |
| 114 | + } | |
| 115 | + | |
| 116 | + public int getDirections() { | |
| 117 | + return directions; | |
| 118 | + } | |
| 119 | + | |
| 120 | + public void setDirections(int directions) { | |
| 121 | + this.directions = directions; | |
| 122 | + } | |
| 123 | + | |
| 124 | + public StationRoute getNext() { | |
| 125 | + return next; | |
| 126 | + } | |
| 127 | + | |
| 128 | + public void setNext(StationRoute next) { | |
| 129 | + this.next = next; | |
| 130 | + } | |
| 131 | + | |
| 132 | + public StationRoute getPrve() { | |
| 133 | + return prve; | |
| 134 | + } | |
| 135 | + | |
| 136 | + public void setPrve(StationRoute prve) { | |
| 137 | + this.prve = prve; | |
| 138 | + } | |
| 139 | + | |
| 140 | + public String getMark() { | |
| 141 | + return mark; | |
| 142 | + } | |
| 143 | + | |
| 144 | + public void setMark(String mark) { | |
| 145 | + this.mark = mark; | |
| 146 | + } | |
| 147 | + | |
| 148 | + public String getName() { | |
| 149 | + return name; | |
| 150 | + } | |
| 151 | + | |
| 152 | + public void setName(String name) { | |
| 153 | + this.name = name; | |
| 154 | + } | |
| 155 | + | |
| 156 | + public boolean isPremise() { | |
| 157 | + return premise; | |
| 158 | + } | |
| 159 | + | |
| 160 | + public void setPremise(boolean premise) { | |
| 161 | + this.premise = premise; | |
| 162 | + } | |
| 163 | +} | |
| 164 | + | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/entity/trail/GpsExecTrail.java
| 1 | -package com.bsth.data.gpsdata_v2.entity.trail; | |
| 2 | - | |
| 3 | -import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 4 | - | |
| 5 | -import java.util.LinkedList; | |
| 6 | - | |
| 7 | -/** | |
| 8 | - * GPS 班次执行轨迹,过程数据 | |
| 9 | - * Created by panzhao on 2017/11/16. | |
| 10 | - */ | |
| 11 | -public class GpsExecTrail { | |
| 12 | - | |
| 13 | - /** | |
| 14 | - * 执行的班次ID | |
| 15 | - */ | |
| 16 | - private Long schId; | |
| 17 | - | |
| 18 | - /** | |
| 19 | - * 实际经过的站点路由 | |
| 20 | - */ | |
| 21 | - private LinkedList<GpsEntity> srs = new LinkedList<>(); | |
| 22 | - | |
| 23 | - /** | |
| 24 | - * 车辆编码 | |
| 25 | - */ | |
| 26 | - private String nbbm; | |
| 27 | - | |
| 28 | - /** | |
| 29 | - * 是否结束 | |
| 30 | - */ | |
| 31 | - private boolean end; | |
| 32 | - | |
| 33 | - public Long getSchId() { | |
| 34 | - return schId; | |
| 35 | - } | |
| 36 | - | |
| 37 | - public void setSchId(Long schId) { | |
| 38 | - this.schId = schId; | |
| 39 | - } | |
| 40 | - | |
| 41 | - public LinkedList<GpsEntity> getSrs() { | |
| 42 | - return srs; | |
| 43 | - } | |
| 44 | - | |
| 45 | - public void setSrs(LinkedList<GpsEntity> srs) { | |
| 46 | - this.srs = srs; | |
| 47 | - } | |
| 48 | - | |
| 49 | - public String getNbbm() { | |
| 50 | - return nbbm; | |
| 51 | - } | |
| 52 | - | |
| 53 | - public void setNbbm(String nbbm) { | |
| 54 | - this.nbbm = nbbm; | |
| 55 | - } | |
| 56 | - | |
| 57 | - public boolean isEnd() { | |
| 58 | - return end; | |
| 59 | - } | |
| 60 | - | |
| 61 | - public void setEnd(boolean end) { | |
| 62 | - this.end = end; | |
| 63 | - } | |
| 64 | -} | |
| 1 | +package com.bsth.data.gpsdata_v2.entity.trail; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 4 | + | |
| 5 | +import java.util.LinkedList; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * GPS 班次执行轨迹,过程数据 | |
| 9 | + * Created by panzhao on 2017/11/16. | |
| 10 | + */ | |
| 11 | +public class GpsExecTrail { | |
| 12 | + | |
| 13 | + /** | |
| 14 | + * 执行的班次ID | |
| 15 | + */ | |
| 16 | + private Long schId; | |
| 17 | + | |
| 18 | + /** | |
| 19 | + * 实际经过的站点路由 | |
| 20 | + */ | |
| 21 | + private LinkedList<GpsEntity> srs = new LinkedList<>(); | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * 车辆编码 | |
| 25 | + */ | |
| 26 | + private String nbbm; | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * 是否结束 | |
| 30 | + */ | |
| 31 | + private boolean end; | |
| 32 | + | |
| 33 | + public Long getSchId() { | |
| 34 | + return schId; | |
| 35 | + } | |
| 36 | + | |
| 37 | + public void setSchId(Long schId) { | |
| 38 | + this.schId = schId; | |
| 39 | + } | |
| 40 | + | |
| 41 | + public LinkedList<GpsEntity> getSrs() { | |
| 42 | + return srs; | |
| 43 | + } | |
| 44 | + | |
| 45 | + public void setSrs(LinkedList<GpsEntity> srs) { | |
| 46 | + this.srs = srs; | |
| 47 | + } | |
| 48 | + | |
| 49 | + public String getNbbm() { | |
| 50 | + return nbbm; | |
| 51 | + } | |
| 52 | + | |
| 53 | + public void setNbbm(String nbbm) { | |
| 54 | + this.nbbm = nbbm; | |
| 55 | + } | |
| 56 | + | |
| 57 | + public boolean isEnd() { | |
| 58 | + return end; | |
| 59 | + } | |
| 60 | + | |
| 61 | + public void setEnd(boolean end) { | |
| 62 | + this.end = end; | |
| 63 | + } | |
| 64 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/handlers/AbnormalStateProcess.java
| 1 | -package com.bsth.data.gpsdata_v2.handlers; | |
| 2 | - | |
| 3 | -import com.bsth.data.gpsdata_v2.cache.GeoCacheData; | |
| 4 | -import com.bsth.data.gpsdata_v2.entity.CtLineString; | |
| 5 | -import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 6 | -import com.bsth.data.gpsdata_v2.utils.GeoUtils; | |
| 7 | -import com.bsth.util.Geo.Point; | |
| 8 | -import org.springframework.stereotype.Component; | |
| 9 | - | |
| 10 | -import java.util.List; | |
| 11 | - | |
| 12 | -/** | |
| 13 | - * 越界/超速 判断 | |
| 14 | - * Created by panzhao on 2017/11/16. | |
| 15 | - */ | |
| 16 | -@Component | |
| 17 | -public class AbnormalStateProcess { | |
| 18 | - | |
| 19 | - /** | |
| 20 | - * 默认限速 | |
| 21 | - */ | |
| 22 | - private static final double DEFAULT_SPEED_LIMIT = 60; | |
| 23 | - /** | |
| 24 | - * 越界阈值 | |
| 25 | - */ | |
| 26 | - private static final double OUT_BOUNDS_THRESHOLD = 100; | |
| 27 | - | |
| 28 | - | |
| 29 | - public void process(GpsEntity gps) { | |
| 30 | - if(isOffline(gps)) | |
| 31 | - return; | |
| 32 | - | |
| 33 | - if(overspeed(gps)) | |
| 34 | - return; | |
| 35 | - | |
| 36 | - if(outOfBounds((gps))) | |
| 37 | - return; | |
| 38 | - } | |
| 39 | - | |
| 40 | - private boolean isOffline(GpsEntity gps){ | |
| 41 | - return gps.getAbnormalStatus() != null && gps.getAbnormalStatus().equals("offline"); | |
| 42 | - } | |
| 43 | - | |
| 44 | - | |
| 45 | - /** | |
| 46 | - * 是否超速 | |
| 47 | - * @param gps | |
| 48 | - * @return | |
| 49 | - */ | |
| 50 | - private boolean overspeed(GpsEntity gps){ | |
| 51 | - double maxSpeed = DEFAULT_SPEED_LIMIT; | |
| 52 | - if(GeoCacheData.speedLimit(gps.getLineId()) != null) | |
| 53 | - maxSpeed = GeoCacheData.speedLimit(gps.getLineId()); | |
| 54 | - | |
| 55 | - if(gps.getSpeed() > maxSpeed){ | |
| 56 | - gps.setAbnormalStatus("overspeed"); | |
| 57 | - return true; | |
| 58 | - } | |
| 59 | - return false; | |
| 60 | - } | |
| 61 | - | |
| 62 | - | |
| 63 | - /** | |
| 64 | - * 是否越界 | |
| 65 | - * @param gps | |
| 66 | - * @return | |
| 67 | - */ | |
| 68 | - public boolean outOfBounds(GpsEntity gps){ | |
| 69 | - //只处理场站外的车 | |
| 70 | - if(gps.getInstation() != 0){ | |
| 71 | - return false; | |
| 72 | - } | |
| 73 | - | |
| 74 | - List<CtLineString> list = GeoCacheData.getLineStringList(gps); | |
| 75 | - Point point = new Point(gps.getLon(), gps.getLat()); | |
| 76 | - | |
| 77 | - double min = -1, distance; | |
| 78 | - | |
| 79 | - for(CtLineString lineString : list){ | |
| 80 | - distance = GeoUtils.getDistanceFromLine(lineString.getS(),lineString.getE(), point); | |
| 81 | - | |
| 82 | - if(min == -1 || min > distance) | |
| 83 | - min = distance; | |
| 84 | - } | |
| 85 | - | |
| 86 | - gps.setOutOfBoundDistance(min); | |
| 87 | - if(min > OUT_BOUNDS_THRESHOLD){ | |
| 88 | - gps.setAbnormalStatus("outBounds"); | |
| 89 | - return true; | |
| 90 | - } | |
| 91 | - return false; | |
| 92 | - } | |
| 93 | -} | |
| 1 | +package com.bsth.data.gpsdata_v2.handlers; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata_v2.cache.GeoCacheData; | |
| 4 | +import com.bsth.data.gpsdata_v2.entity.CtLineString; | |
| 5 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 6 | +import com.bsth.data.gpsdata_v2.utils.GeoUtils; | |
| 7 | +import com.bsth.util.Geo.Point; | |
| 8 | +import org.springframework.stereotype.Component; | |
| 9 | + | |
| 10 | +import java.util.List; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 越界/超速 判断 | |
| 14 | + * Created by panzhao on 2017/11/16. | |
| 15 | + */ | |
| 16 | +@Component | |
| 17 | +public class AbnormalStateProcess { | |
| 18 | + | |
| 19 | + /** | |
| 20 | + * 默认限速 | |
| 21 | + */ | |
| 22 | + private static final double DEFAULT_SPEED_LIMIT = 60; | |
| 23 | + /** | |
| 24 | + * 越界阈值 | |
| 25 | + */ | |
| 26 | + private static final double OUT_BOUNDS_THRESHOLD = 100; | |
| 27 | + | |
| 28 | + | |
| 29 | + public void process(GpsEntity gps) { | |
| 30 | + if(isOffline(gps)) | |
| 31 | + return; | |
| 32 | + | |
| 33 | + if(overspeed(gps)) | |
| 34 | + return; | |
| 35 | + | |
| 36 | + if(outOfBounds((gps))) | |
| 37 | + return; | |
| 38 | + } | |
| 39 | + | |
| 40 | + private boolean isOffline(GpsEntity gps){ | |
| 41 | + return gps.getAbnormalStatus() != null && gps.getAbnormalStatus().equals("offline"); | |
| 42 | + } | |
| 43 | + | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * 是否超速 | |
| 47 | + * @param gps | |
| 48 | + * @return | |
| 49 | + */ | |
| 50 | + private boolean overspeed(GpsEntity gps){ | |
| 51 | + double maxSpeed = DEFAULT_SPEED_LIMIT; | |
| 52 | + if(GeoCacheData.speedLimit(gps.getLineId()) != null) | |
| 53 | + maxSpeed = GeoCacheData.speedLimit(gps.getLineId()); | |
| 54 | + | |
| 55 | + if(gps.getSpeed() > maxSpeed){ | |
| 56 | + gps.setAbnormalStatus("overspeed"); | |
| 57 | + return true; | |
| 58 | + } | |
| 59 | + return false; | |
| 60 | + } | |
| 61 | + | |
| 62 | + | |
| 63 | + /** | |
| 64 | + * 是否越界 | |
| 65 | + * @param gps | |
| 66 | + * @return | |
| 67 | + */ | |
| 68 | + public boolean outOfBounds(GpsEntity gps){ | |
| 69 | + //只处理场站外的车 | |
| 70 | + if(gps.getInstation() != 0){ | |
| 71 | + return false; | |
| 72 | + } | |
| 73 | + | |
| 74 | + List<CtLineString> list = GeoCacheData.getLineStringList(gps); | |
| 75 | + Point point = new Point(gps.getLon(), gps.getLat()); | |
| 76 | + | |
| 77 | + double min = -1, distance; | |
| 78 | + | |
| 79 | + for(CtLineString lineString : list){ | |
| 80 | + distance = GeoUtils.getDistanceFromLine(lineString.getS(),lineString.getE(), point); | |
| 81 | + | |
| 82 | + if(min == -1 || min > distance) | |
| 83 | + min = distance; | |
| 84 | + } | |
| 85 | + | |
| 86 | + gps.setOutOfBoundDistance(min); | |
| 87 | + if(min > OUT_BOUNDS_THRESHOLD){ | |
| 88 | + gps.setAbnormalStatus("outBounds"); | |
| 89 | + return true; | |
| 90 | + } | |
| 91 | + return false; | |
| 92 | + } | |
| 93 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/handlers/GpsStateProcess.java
| 1 | -package com.bsth.data.gpsdata_v2.handlers; | |
| 2 | - | |
| 3 | -import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 4 | -import com.bsth.data.gpsdata_v2.status_manager.GpsStatusManager; | |
| 5 | -import com.bsth.data.schedule.DayOfSchedule; | |
| 6 | -import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 7 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 8 | -import org.springframework.stereotype.Component; | |
| 9 | - | |
| 10 | -/** | |
| 11 | - * GPS 状态处理 | |
| 12 | - * Created by panzhao on 2017/11/15. | |
| 13 | - */ | |
| 14 | -@Component | |
| 15 | -public class GpsStateProcess { | |
| 16 | - | |
| 17 | - @Autowired | |
| 18 | - DayOfSchedule dayOfSchedule; | |
| 19 | - | |
| 20 | - @Autowired | |
| 21 | - GpsStatusManager gpsStatusManager; | |
| 22 | - | |
| 23 | - public void process(GpsEntity gps){ | |
| 24 | - //在执行的任务 | |
| 25 | - ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm()); | |
| 26 | - | |
| 27 | - if(null == sch) | |
| 28 | - return; | |
| 29 | - | |
| 30 | - byte upDown = Byte.parseByte(sch.getXlDir()); | |
| 31 | - | |
| 32 | - if(gps.getUpDown() != upDown){ | |
| 33 | - gps.setUpDown(upDown);//修正走向 | |
| 34 | - } | |
| 35 | - | |
| 36 | - if((!gps.isService() || gps.getUpDown() != upDown) && | |
| 37 | - !dayOfSchedule.emptyService(sch)){ | |
| 38 | - //下发指令纠正车载的 营运状态 和 走向 | |
| 39 | - gpsStatusManager.changeServiceState(gps.getNbbm(), upDown, 0, "同步@系统"); | |
| 40 | - } | |
| 41 | - | |
| 42 | - if(!sch.getXlBm().equals(gps.getLineId())){ | |
| 43 | - //切换车载的 线路编码 | |
| 44 | - gpsStatusManager.changeLine(gps.getNbbm(), sch.getXlBm(), "同步@系统"); | |
| 45 | - } | |
| 46 | - } | |
| 47 | -} | |
| 1 | +package com.bsth.data.gpsdata_v2.handlers; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 4 | +import com.bsth.data.gpsdata_v2.status_manager.GpsStatusManager; | |
| 5 | +import com.bsth.data.schedule.DayOfSchedule; | |
| 6 | +import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 7 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 8 | +import org.springframework.stereotype.Component; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * GPS 状态处理 | |
| 12 | + * Created by panzhao on 2017/11/15. | |
| 13 | + */ | |
| 14 | +@Component | |
| 15 | +public class GpsStateProcess { | |
| 16 | + | |
| 17 | + @Autowired | |
| 18 | + DayOfSchedule dayOfSchedule; | |
| 19 | + | |
| 20 | + @Autowired | |
| 21 | + GpsStatusManager gpsStatusManager; | |
| 22 | + | |
| 23 | + public void process(GpsEntity gps){ | |
| 24 | + //在执行的任务 | |
| 25 | + ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm()); | |
| 26 | + | |
| 27 | + if(null == sch) | |
| 28 | + return; | |
| 29 | + | |
| 30 | + byte upDown = Byte.parseByte(sch.getXlDir()); | |
| 31 | + | |
| 32 | + if(gps.getUpDown() != upDown){ | |
| 33 | + gps.setUpDown(upDown);//修正走向 | |
| 34 | + } | |
| 35 | + | |
| 36 | + if((!gps.isService() || gps.getUpDown() != upDown) && | |
| 37 | + !dayOfSchedule.emptyService(sch)){ | |
| 38 | + //下发指令纠正车载的 营运状态 和 走向 | |
| 39 | + gpsStatusManager.changeServiceState(gps.getNbbm(), upDown, 0, "同步@系统"); | |
| 40 | + } | |
| 41 | + | |
| 42 | + if(!sch.getXlBm().equals(gps.getLineId())){ | |
| 43 | + //切换车载的 线路编码 | |
| 44 | + gpsStatusManager.changeLine(gps.getNbbm(), sch.getXlBm(), "同步@系统"); | |
| 45 | + } | |
| 46 | + } | |
| 47 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/handlers/InStationProcess.java
src/main/java/com/bsth/data/gpsdata_v2/handlers/OutStationProcess.java
| ... | ... | @@ -77,10 +77,10 @@ public class OutStationProcess { |
| 77 | 77 | return; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - /*int diff = (int) (sch.getDfsjT() - gps.getTimestamp()); | |
| 80 | + int diff = (int) (sch.getDfsjT() - gps.getTimestamp()); | |
| 81 | 81 | //首班出场最多提前2小时 |
| 82 | 82 | if((dayOfSchedule.isFirstOut(sch) && diff > MAX_BEFORE_TIME) || diff > MAX_BEFORE_TIME / 2) |
| 83 | - return;*/ | |
| 83 | + return; | |
| 84 | 84 | |
| 85 | 85 | gps.setPremiseCode(null);//清除前置围栏标记 |
| 86 | 86 | |
| ... | ... | @@ -191,4 +191,4 @@ public class OutStationProcess { |
| 191 | 191 | return true; |
| 192 | 192 | return false; |
| 193 | 193 | } |
| 194 | 194 | -} |
| 195 | +} | |
| 195 | 196 | \ No newline at end of file | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/handlers/ReverseRouteProcess.java
| 1 | -package com.bsth.data.gpsdata_v2.handlers; | |
| 2 | - | |
| 3 | -import com.bsth.data.gpsdata_v2.cache.GpsCacheData; | |
| 4 | -import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 5 | -import com.bsth.data.gpsdata_v2.entity.StationRoute; | |
| 6 | -import com.bsth.data.schedule.DayOfSchedule; | |
| 7 | -import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 8 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 9 | -import org.springframework.stereotype.Component; | |
| 10 | - | |
| 11 | -import java.util.List; | |
| 12 | - | |
| 13 | -/** | |
| 14 | - * 反向路由处理(进站的时候处理) | |
| 15 | - * Created by panzhao on 2017/11/20. | |
| 16 | - */ | |
| 17 | -@Component | |
| 18 | -public class ReverseRouteProcess { | |
| 19 | - | |
| 20 | - private static final int REVER_THRESHOLD = 3; | |
| 21 | - | |
| 22 | - private static final long TIME_THRESHOLD = 1000 * 60 * 120; | |
| 23 | - | |
| 24 | - @Autowired | |
| 25 | - DayOfSchedule dayOfSchedule; | |
| 26 | - | |
| 27 | - public void process(GpsEntity gps){ | |
| 28 | - if(reversRoute(gps)){ | |
| 29 | - ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm()); | |
| 30 | - if(isInOut(sch) || !sch.getXlBm().equals(gps.getLineId())) | |
| 31 | - return; | |
| 32 | - | |
| 33 | - //next | |
| 34 | - ScheduleRealInfo next = dayOfSchedule.next(sch); | |
| 35 | - if(isInOut(next)) | |
| 36 | - return; | |
| 37 | - | |
| 38 | - //跳下一个班次 | |
| 39 | - if(Math.abs(next.getDfsjT() - gps.getTimestamp()) < TIME_THRESHOLD) | |
| 40 | - dayOfSchedule.addExecPlan(next); | |
| 41 | - } | |
| 42 | - } | |
| 43 | - | |
| 44 | - private boolean reversRoute(GpsEntity gps) { | |
| 45 | - if(gps.getInstation() != 1) | |
| 46 | - return false; | |
| 47 | - | |
| 48 | - int sortNo = gps.getStation().getRouteSort(); | |
| 49 | - StationRoute prev = GpsCacheData.prevStation(gps); | |
| 50 | - //和上一个站点是反向 | |
| 51 | - if(null != prev && sortNo < prev.getRouteSort()){ | |
| 52 | - | |
| 53 | - //满足3个进站反向信号 | |
| 54 | - List<StationRoute> prevs = GpsCacheData.prevMultiStation(gps); | |
| 55 | - | |
| 56 | - int count = 0; | |
| 57 | - for(StationRoute s : prevs){ | |
| 58 | - if(sortNo < s.getRouteSort()) | |
| 59 | - count ++; | |
| 60 | - sortNo = s.getRouteSort(); | |
| 61 | - } | |
| 62 | - | |
| 63 | - if(count >= REVER_THRESHOLD) | |
| 64 | - return true; | |
| 65 | - } | |
| 66 | - | |
| 67 | - return false; | |
| 68 | - } | |
| 69 | - | |
| 70 | - private boolean isInOut(ScheduleRealInfo sch){ | |
| 71 | - return sch.getBcType().equals("in") || sch.getBcType().equals("out"); | |
| 72 | - } | |
| 73 | -} | |
| 1 | +package com.bsth.data.gpsdata_v2.handlers; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata_v2.cache.GpsCacheData; | |
| 4 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 5 | +import com.bsth.data.gpsdata_v2.entity.StationRoute; | |
| 6 | +import com.bsth.data.schedule.DayOfSchedule; | |
| 7 | +import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 8 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 9 | +import org.springframework.stereotype.Component; | |
| 10 | + | |
| 11 | +import java.util.List; | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * 反向路由处理(进站的时候处理) | |
| 15 | + * Created by panzhao on 2017/11/20. | |
| 16 | + */ | |
| 17 | +@Component | |
| 18 | +public class ReverseRouteProcess { | |
| 19 | + | |
| 20 | + private static final int REVER_THRESHOLD = 3; | |
| 21 | + | |
| 22 | + private static final long TIME_THRESHOLD = 1000 * 60 * 120; | |
| 23 | + | |
| 24 | + @Autowired | |
| 25 | + DayOfSchedule dayOfSchedule; | |
| 26 | + | |
| 27 | + public void process(GpsEntity gps){ | |
| 28 | + if(reversRoute(gps)){ | |
| 29 | + ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm()); | |
| 30 | + if(isInOut(sch) || !sch.getXlBm().equals(gps.getLineId())) | |
| 31 | + return; | |
| 32 | + | |
| 33 | + //next | |
| 34 | + ScheduleRealInfo next = dayOfSchedule.next(sch); | |
| 35 | + if(isInOut(next)) | |
| 36 | + return; | |
| 37 | + | |
| 38 | + //跳下一个班次 | |
| 39 | + if(Math.abs(next.getDfsjT() - gps.getTimestamp()) < TIME_THRESHOLD) | |
| 40 | + dayOfSchedule.addExecPlan(next); | |
| 41 | + } | |
| 42 | + } | |
| 43 | + | |
| 44 | + private boolean reversRoute(GpsEntity gps) { | |
| 45 | + if(gps.getInstation() != 1) | |
| 46 | + return false; | |
| 47 | + | |
| 48 | + int sortNo = gps.getStation().getRouteSort(); | |
| 49 | + StationRoute prev = GpsCacheData.prevStation(gps); | |
| 50 | + //和上一个站点是反向 | |
| 51 | + if(null != prev && sortNo < prev.getRouteSort()){ | |
| 52 | + | |
| 53 | + //满足3个进站反向信号 | |
| 54 | + List<StationRoute> prevs = GpsCacheData.prevMultiStation(gps); | |
| 55 | + | |
| 56 | + int count = 0; | |
| 57 | + for(StationRoute s : prevs){ | |
| 58 | + if(sortNo < s.getRouteSort()) | |
| 59 | + count ++; | |
| 60 | + sortNo = s.getRouteSort(); | |
| 61 | + } | |
| 62 | + | |
| 63 | + if(count >= REVER_THRESHOLD) | |
| 64 | + return true; | |
| 65 | + } | |
| 66 | + | |
| 67 | + return false; | |
| 68 | + } | |
| 69 | + | |
| 70 | + private boolean isInOut(ScheduleRealInfo sch){ | |
| 71 | + return sch.getBcType().equals("in") || sch.getBcType().equals("out"); | |
| 72 | + } | |
| 73 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/handlers/StationInsideProcess.java
| 1 | -package com.bsth.data.gpsdata_v2.handlers; | |
| 2 | - | |
| 3 | -import com.bsth.data.gpsdata_v2.cache.GeoCacheData; | |
| 4 | -import com.bsth.data.gpsdata_v2.cache.GpsCacheData; | |
| 5 | -import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 6 | -import com.bsth.data.gpsdata_v2.entity.StationRoute; | |
| 7 | -import com.bsth.data.gpsdata_v2.utils.GeoUtils; | |
| 8 | -import org.springframework.stereotype.Component; | |
| 9 | - | |
| 10 | -import java.util.List; | |
| 11 | - | |
| 12 | -/** | |
| 13 | - * 站内 场内判定 | |
| 14 | - * Created by panzhao on 2017/11/16. | |
| 15 | - */ | |
| 16 | -@Component | |
| 17 | -public class StationInsideProcess { | |
| 18 | - | |
| 19 | - public void process(GpsEntity gps){ | |
| 20 | - //是否在场内 | |
| 21 | - String parkCode = GeoUtils.gpsInCarpark(gps); | |
| 22 | - | |
| 23 | - if (parkCode != null) { | |
| 24 | - gps.setInstation(2); | |
| 25 | - gps.setStopNo(parkCode); | |
| 26 | - gps.setCarparkNo(parkCode); | |
| 27 | - } | |
| 28 | - | |
| 29 | - //是否在站内 | |
| 30 | - List<StationRoute> srs = GeoCacheData.getStationRoute(gps.getLineId(), gps.getUpDown()); | |
| 31 | - StationRoute station = GeoUtils.gpsInStation(gps, srs); | |
| 32 | - if (station != null) { | |
| 33 | - gps.setInstation(1); | |
| 34 | - gps.setStopNo(station.getCode()); | |
| 35 | - gps.setStation(station); | |
| 36 | - } | |
| 37 | - | |
| 38 | - //是否在进站前置围栏内 | |
| 39 | - String premiseCode = GeoUtils.gpsInPremiseGeo(gps); | |
| 40 | - gps.setPremiseCode(premiseCode); | |
| 41 | - | |
| 42 | - //上一个点位 | |
| 43 | - GpsEntity prev = GpsCacheData.getPrev(gps); | |
| 44 | - | |
| 45 | - if(null != prev){ | |
| 46 | - //继承前置围栏状态 | |
| 47 | - if(null == premiseCode && null != prev.getPremiseCode()) | |
| 48 | - gps.setPremiseCode(prev.getPremiseCode()); | |
| 49 | - | |
| 50 | - //在场,站外 | |
| 51 | - if(gps.getInstation() == 0){ | |
| 52 | - gps.setStopNo(prev.getStopNo());//继承上一个点的站点编码 | |
| 53 | - } | |
| 54 | - } | |
| 55 | - } | |
| 56 | -} | |
| 1 | +package com.bsth.data.gpsdata_v2.handlers; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata_v2.cache.GeoCacheData; | |
| 4 | +import com.bsth.data.gpsdata_v2.cache.GpsCacheData; | |
| 5 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 6 | +import com.bsth.data.gpsdata_v2.entity.StationRoute; | |
| 7 | +import com.bsth.data.gpsdata_v2.utils.GeoUtils; | |
| 8 | +import org.springframework.stereotype.Component; | |
| 9 | + | |
| 10 | +import java.util.List; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 站内 场内判定 | |
| 14 | + * Created by panzhao on 2017/11/16. | |
| 15 | + */ | |
| 16 | +@Component | |
| 17 | +public class StationInsideProcess { | |
| 18 | + | |
| 19 | + public void process(GpsEntity gps){ | |
| 20 | + //是否在场内 | |
| 21 | + String parkCode = GeoUtils.gpsInCarpark(gps); | |
| 22 | + | |
| 23 | + if (parkCode != null) { | |
| 24 | + gps.setInstation(2); | |
| 25 | + gps.setStopNo(parkCode); | |
| 26 | + gps.setCarparkNo(parkCode); | |
| 27 | + } | |
| 28 | + | |
| 29 | + //是否在站内 | |
| 30 | + List<StationRoute> srs = GeoCacheData.getStationRoute(gps.getLineId(), gps.getUpDown()); | |
| 31 | + StationRoute station = GeoUtils.gpsInStation(gps, srs); | |
| 32 | + if (station != null) { | |
| 33 | + gps.setInstation(1); | |
| 34 | + gps.setStopNo(station.getCode()); | |
| 35 | + gps.setStation(station); | |
| 36 | + } | |
| 37 | + | |
| 38 | + //是否在进站前置围栏内 | |
| 39 | + String premiseCode = GeoUtils.gpsInPremiseGeo(gps); | |
| 40 | + gps.setPremiseCode(premiseCode); | |
| 41 | + | |
| 42 | + //上一个点位 | |
| 43 | + GpsEntity prev = GpsCacheData.getPrev(gps); | |
| 44 | + | |
| 45 | + if(null != prev){ | |
| 46 | + //继承前置围栏状态 | |
| 47 | + if(null == premiseCode && null != prev.getPremiseCode()) | |
| 48 | + gps.setPremiseCode(prev.getPremiseCode()); | |
| 49 | + | |
| 50 | + //在场,站外 | |
| 51 | + if(gps.getInstation() == 0){ | |
| 52 | + gps.setStopNo(prev.getStopNo());//继承上一个点的站点编码 | |
| 53 | + } | |
| 54 | + } | |
| 55 | + } | |
| 56 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/load/GatewayHttpLoader.java
| 1 | -package com.bsth.data.gpsdata_v2.load; | |
| 2 | - | |
| 3 | -import com.alibaba.fastjson.JSON; | |
| 4 | -import com.bsth.data.BasicData; | |
| 5 | -import com.bsth.data.gpsdata_v2.GpsRealData; | |
| 6 | -import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 7 | -import com.bsth.data.gpsdata_v2.utils.GpsDataUtils; | |
| 8 | -import com.bsth.util.ConfigUtil; | |
| 9 | -import org.apache.commons.lang3.StringUtils; | |
| 10 | -import org.apache.http.HttpEntity; | |
| 11 | -import org.apache.http.client.config.RequestConfig; | |
| 12 | -import org.apache.http.client.methods.CloseableHttpResponse; | |
| 13 | -import org.apache.http.client.methods.HttpGet; | |
| 14 | -import org.apache.http.impl.client.CloseableHttpClient; | |
| 15 | -import org.apache.http.impl.client.HttpClients; | |
| 16 | -import org.slf4j.Logger; | |
| 17 | -import org.slf4j.LoggerFactory; | |
| 18 | -import org.springframework.beans.BeansException; | |
| 19 | -import org.springframework.context.ApplicationContext; | |
| 20 | -import org.springframework.context.ApplicationContextAware; | |
| 21 | -import org.springframework.stereotype.Component; | |
| 22 | - | |
| 23 | -import java.io.BufferedReader; | |
| 24 | -import java.io.InputStreamReader; | |
| 25 | -import java.util.ArrayList; | |
| 26 | -import java.util.List; | |
| 27 | - | |
| 28 | -/** | |
| 29 | - * 从网关http 接口加载数据 | |
| 30 | - * Created by panzhao on 2017/11/15. | |
| 31 | - */ | |
| 32 | -@Component | |
| 33 | -public class GatewayHttpLoader implements ApplicationContextAware{ | |
| 34 | - | |
| 35 | - static Logger logger = LoggerFactory.getLogger(GatewayHttpLoader.class); | |
| 36 | - | |
| 37 | - static String url; | |
| 38 | - static List<GpsEntity> list; | |
| 39 | - static CloseableHttpClient httpClient = null; | |
| 40 | - static HttpGet get; | |
| 41 | - static RequestConfig requestConfig; | |
| 42 | - static CloseableHttpResponse response; | |
| 43 | - static HttpEntity entity; | |
| 44 | - static BufferedReader br; | |
| 45 | - | |
| 46 | - static GpsRealData gpsRealData; | |
| 47 | - | |
| 48 | - static{ | |
| 49 | - url = ConfigUtil.get("http.gps.real.url"); | |
| 50 | - list = new ArrayList<>(); | |
| 51 | - httpClient = HttpClients.createDefault(); | |
| 52 | - get = new HttpGet(url); | |
| 53 | - requestConfig = RequestConfig.custom() | |
| 54 | - .setConnectTimeout(1500).setConnectionRequestTimeout(1000) | |
| 55 | - .setSocketTimeout(1500).build(); | |
| 56 | - get.setConfig(requestConfig); | |
| 57 | - } | |
| 58 | - | |
| 59 | - public static List<GpsEntity> load(){ | |
| 60 | - try{ | |
| 61 | - if(list.size() > 0) | |
| 62 | - list.clear(); | |
| 63 | - | |
| 64 | - response = httpClient.execute(get); | |
| 65 | - entity = response.getEntity(); | |
| 66 | - | |
| 67 | - if(null == entity) | |
| 68 | - return list; | |
| 69 | - | |
| 70 | - br = new BufferedReader(new InputStreamReader(entity.getContent())); | |
| 71 | - | |
| 72 | - StringBuilder sb = new StringBuilder(); | |
| 73 | - String str; | |
| 74 | - while ((str = br.readLine()) != null) | |
| 75 | - sb.append(str); | |
| 76 | - | |
| 77 | - list = JSON.parseArray(JSON.parseObject(sb.toString()).getString("data"), GpsEntity.class); | |
| 78 | - //过滤掉无效的点位 | |
| 79 | - list = GpsDataUtils.clearInvalid(list); | |
| 80 | - | |
| 81 | - List<GpsEntity> ups = new ArrayList<>(); | |
| 82 | - String nbbm; | |
| 83 | - for (GpsEntity gps : list) { | |
| 84 | - if (StringUtils.isBlank(gps.getDeviceId())) | |
| 85 | - continue; | |
| 86 | - | |
| 87 | - if (gps_equals(gpsRealData.get(gps.getDeviceId()), gps)) | |
| 88 | - continue; | |
| 89 | - | |
| 90 | - nbbm = BasicData.deviceId2NbbmMap.get(gps.getDeviceId()); | |
| 91 | - gps.setNbbm(nbbm); | |
| 92 | - ups.add(gps); | |
| 93 | - } | |
| 94 | - list = ups; | |
| 95 | - | |
| 96 | - if (null != response) | |
| 97 | - response.close(); | |
| 98 | - }catch (Exception e){ | |
| 99 | - logger.error("", e); | |
| 100 | - } | |
| 101 | - return list; | |
| 102 | - } | |
| 103 | - | |
| 104 | - | |
| 105 | - private static boolean gps_equals(GpsEntity old, GpsEntity gps){ | |
| 106 | - if(old != null && | |
| 107 | - old.getTimestamp().equals(gps.getTimestamp()) && | |
| 108 | - old.getLat().equals(gps.getLat()) && | |
| 109 | - old.getLon().equals(gps.getLon())) | |
| 110 | - return true; | |
| 111 | - return false; | |
| 112 | - } | |
| 113 | - | |
| 114 | - @Override | |
| 115 | - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | |
| 116 | - gpsRealData = applicationContext.getBean(GpsRealData.class); | |
| 117 | - } | |
| 118 | -} | |
| 1 | +package com.bsth.data.gpsdata_v2.load; | |
| 2 | + | |
| 3 | +import com.alibaba.fastjson.JSON; | |
| 4 | +import com.bsth.data.BasicData; | |
| 5 | +import com.bsth.data.gpsdata_v2.GpsRealData; | |
| 6 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 7 | +import com.bsth.data.gpsdata_v2.utils.GpsDataUtils; | |
| 8 | +import com.bsth.util.ConfigUtil; | |
| 9 | +import org.apache.commons.lang3.StringUtils; | |
| 10 | +import org.apache.http.HttpEntity; | |
| 11 | +import org.apache.http.client.config.RequestConfig; | |
| 12 | +import org.apache.http.client.methods.CloseableHttpResponse; | |
| 13 | +import org.apache.http.client.methods.HttpGet; | |
| 14 | +import org.apache.http.impl.client.CloseableHttpClient; | |
| 15 | +import org.apache.http.impl.client.HttpClients; | |
| 16 | +import org.slf4j.Logger; | |
| 17 | +import org.slf4j.LoggerFactory; | |
| 18 | +import org.springframework.beans.BeansException; | |
| 19 | +import org.springframework.context.ApplicationContext; | |
| 20 | +import org.springframework.context.ApplicationContextAware; | |
| 21 | +import org.springframework.stereotype.Component; | |
| 22 | + | |
| 23 | +import java.io.BufferedReader; | |
| 24 | +import java.io.InputStreamReader; | |
| 25 | +import java.util.ArrayList; | |
| 26 | +import java.util.List; | |
| 27 | + | |
| 28 | +/** | |
| 29 | + * 从网关http 接口加载数据 | |
| 30 | + * Created by panzhao on 2017/11/15. | |
| 31 | + */ | |
| 32 | +@Component | |
| 33 | +public class GatewayHttpLoader implements ApplicationContextAware{ | |
| 34 | + | |
| 35 | + static Logger logger = LoggerFactory.getLogger(GatewayHttpLoader.class); | |
| 36 | + | |
| 37 | + static String url; | |
| 38 | + static List<GpsEntity> list; | |
| 39 | + static CloseableHttpClient httpClient = null; | |
| 40 | + static HttpGet get; | |
| 41 | + static RequestConfig requestConfig; | |
| 42 | + static CloseableHttpResponse response; | |
| 43 | + static HttpEntity entity; | |
| 44 | + static BufferedReader br; | |
| 45 | + | |
| 46 | + static GpsRealData gpsRealData; | |
| 47 | + | |
| 48 | + static{ | |
| 49 | + url = ConfigUtil.get("http.gps.real.url"); | |
| 50 | + list = new ArrayList<>(); | |
| 51 | + httpClient = HttpClients.createDefault(); | |
| 52 | + get = new HttpGet(url); | |
| 53 | + requestConfig = RequestConfig.custom() | |
| 54 | + .setConnectTimeout(1500).setConnectionRequestTimeout(1000) | |
| 55 | + .setSocketTimeout(1500).build(); | |
| 56 | + get.setConfig(requestConfig); | |
| 57 | + } | |
| 58 | + | |
| 59 | + public static List<GpsEntity> load(){ | |
| 60 | + try{ | |
| 61 | + if(list.size() > 0) | |
| 62 | + list.clear(); | |
| 63 | + | |
| 64 | + response = httpClient.execute(get); | |
| 65 | + entity = response.getEntity(); | |
| 66 | + | |
| 67 | + if(null == entity) | |
| 68 | + return list; | |
| 69 | + | |
| 70 | + br = new BufferedReader(new InputStreamReader(entity.getContent())); | |
| 71 | + | |
| 72 | + StringBuilder sb = new StringBuilder(); | |
| 73 | + String str; | |
| 74 | + while ((str = br.readLine()) != null) | |
| 75 | + sb.append(str); | |
| 76 | + | |
| 77 | + list = JSON.parseArray(JSON.parseObject(sb.toString()).getString("data"), GpsEntity.class); | |
| 78 | + //过滤掉无效的点位 | |
| 79 | + list = GpsDataUtils.clearInvalid(list); | |
| 80 | + | |
| 81 | + List<GpsEntity> ups = new ArrayList<>(); | |
| 82 | + String nbbm; | |
| 83 | + for (GpsEntity gps : list) { | |
| 84 | + if (StringUtils.isBlank(gps.getDeviceId())) | |
| 85 | + continue; | |
| 86 | + | |
| 87 | + if (gps_equals(gpsRealData.get(gps.getDeviceId()), gps)) | |
| 88 | + continue; | |
| 89 | + | |
| 90 | + nbbm = BasicData.deviceId2NbbmMap.get(gps.getDeviceId()); | |
| 91 | + gps.setNbbm(nbbm); | |
| 92 | + ups.add(gps); | |
| 93 | + } | |
| 94 | + list = ups; | |
| 95 | + | |
| 96 | + if (null != response) | |
| 97 | + response.close(); | |
| 98 | + }catch (Exception e){ | |
| 99 | + logger.error("", e); | |
| 100 | + } | |
| 101 | + return list; | |
| 102 | + } | |
| 103 | + | |
| 104 | + | |
| 105 | + private static boolean gps_equals(GpsEntity old, GpsEntity gps){ | |
| 106 | + if(old != null && | |
| 107 | + old.getTimestamp().equals(gps.getTimestamp()) && | |
| 108 | + old.getLat().equals(gps.getLat()) && | |
| 109 | + old.getLon().equals(gps.getLon())) | |
| 110 | + return true; | |
| 111 | + return false; | |
| 112 | + } | |
| 113 | + | |
| 114 | + @Override | |
| 115 | + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | |
| 116 | + gpsRealData = applicationContext.getBean(GpsRealData.class); | |
| 117 | + } | |
| 118 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/load/SocketClientLoader.java
| 1 | -package com.bsth.data.gpsdata_v2.load; | |
| 2 | - | |
| 3 | -import com.alibaba.fastjson.JSON; | |
| 4 | -import com.bsth.data.BasicData; | |
| 5 | -import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 6 | -import com.bsth.data.gpsdata_v2.utils.GpsDataUtils; | |
| 7 | -import com.bsth.util.ConfigUtil; | |
| 8 | -import org.apache.http.HttpEntity; | |
| 9 | -import org.apache.http.client.config.RequestConfig; | |
| 10 | -import org.apache.http.client.methods.CloseableHttpResponse; | |
| 11 | -import org.apache.http.client.methods.HttpGet; | |
| 12 | -import org.apache.http.impl.client.CloseableHttpClient; | |
| 13 | -import org.apache.http.impl.client.HttpClients; | |
| 14 | -import org.slf4j.Logger; | |
| 15 | -import org.slf4j.LoggerFactory; | |
| 16 | -import org.springframework.stereotype.Component; | |
| 17 | - | |
| 18 | -import java.io.BufferedReader; | |
| 19 | -import java.io.InputStreamReader; | |
| 20 | -import java.util.ArrayList; | |
| 21 | -import java.util.List; | |
| 22 | - | |
| 23 | -/** | |
| 24 | - * 从专用的socket client 加载数据 | |
| 25 | - * Created by panzhao on 2017/11/15. | |
| 26 | - */ | |
| 27 | -@Component | |
| 28 | -public class SocketClientLoader { | |
| 29 | - | |
| 30 | - static Logger logger = LoggerFactory.getLogger(SocketClientLoader.class); | |
| 31 | - | |
| 32 | - static String url; | |
| 33 | - static List<GpsEntity> list; | |
| 34 | - static CloseableHttpClient httpClient = null; | |
| 35 | - static HttpGet get; | |
| 36 | - static RequestConfig requestConfig; | |
| 37 | - static CloseableHttpResponse response; | |
| 38 | - static HttpEntity entity; | |
| 39 | - static BufferedReader br; | |
| 40 | - | |
| 41 | - static { | |
| 42 | - url = ConfigUtil.get("http.gps.real.cache.url"); | |
| 43 | - list = new ArrayList<>(); | |
| 44 | - httpClient = HttpClients.createDefault(); | |
| 45 | - get = new HttpGet(url); | |
| 46 | - requestConfig = RequestConfig.custom() | |
| 47 | - .setConnectTimeout(1500).setConnectionRequestTimeout(1000) | |
| 48 | - .setSocketTimeout(1500).build(); | |
| 49 | - get.setConfig(requestConfig); | |
| 50 | - } | |
| 51 | - | |
| 52 | - public static List<GpsEntity> load(){ | |
| 53 | - try { | |
| 54 | - if(list.size() > 0) | |
| 55 | - list.clear(); | |
| 56 | - logger.info("load start..."); | |
| 57 | - response = httpClient.execute(get); | |
| 58 | - entity = response.getEntity(); | |
| 59 | - if(null == entity) | |
| 60 | - return list; | |
| 61 | - | |
| 62 | - br = new BufferedReader(new InputStreamReader(entity.getContent())); | |
| 63 | - StringBuilder sb = new StringBuilder(); | |
| 64 | - String str; | |
| 65 | - while ((str = br.readLine()) != null) | |
| 66 | - sb.append(str); | |
| 67 | - | |
| 68 | - list = JSON.parseArray(sb.toString(), GpsEntity.class); | |
| 69 | - | |
| 70 | - //过滤掉无效的点位 | |
| 71 | - list = GpsDataUtils.clearInvalid(list); | |
| 72 | - | |
| 73 | - logger.info("load end!"); | |
| 74 | - for (GpsEntity gps : list) { | |
| 75 | - gps.setNbbm(BasicData.deviceId2NbbmMap.get(gps.getDeviceId())); | |
| 76 | - } | |
| 77 | - | |
| 78 | - if (null != response) | |
| 79 | - response.close(); | |
| 80 | - } catch (Exception e) { | |
| 81 | - logger.error("", e); | |
| 82 | - } | |
| 83 | - | |
| 84 | - return list; | |
| 85 | - } | |
| 86 | -} | |
| 1 | +package com.bsth.data.gpsdata_v2.load; | |
| 2 | + | |
| 3 | +import com.alibaba.fastjson.JSON; | |
| 4 | +import com.bsth.data.BasicData; | |
| 5 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 6 | +import com.bsth.data.gpsdata_v2.utils.GpsDataUtils; | |
| 7 | +import com.bsth.util.ConfigUtil; | |
| 8 | +import org.apache.http.HttpEntity; | |
| 9 | +import org.apache.http.client.config.RequestConfig; | |
| 10 | +import org.apache.http.client.methods.CloseableHttpResponse; | |
| 11 | +import org.apache.http.client.methods.HttpGet; | |
| 12 | +import org.apache.http.impl.client.CloseableHttpClient; | |
| 13 | +import org.apache.http.impl.client.HttpClients; | |
| 14 | +import org.slf4j.Logger; | |
| 15 | +import org.slf4j.LoggerFactory; | |
| 16 | +import org.springframework.stereotype.Component; | |
| 17 | + | |
| 18 | +import java.io.BufferedReader; | |
| 19 | +import java.io.InputStreamReader; | |
| 20 | +import java.util.ArrayList; | |
| 21 | +import java.util.List; | |
| 22 | + | |
| 23 | +/** | |
| 24 | + * 从专用的socket client 加载数据 | |
| 25 | + * Created by panzhao on 2017/11/15. | |
| 26 | + */ | |
| 27 | +@Component | |
| 28 | +public class SocketClientLoader { | |
| 29 | + | |
| 30 | + static Logger logger = LoggerFactory.getLogger(SocketClientLoader.class); | |
| 31 | + | |
| 32 | + static String url; | |
| 33 | + static List<GpsEntity> list; | |
| 34 | + static CloseableHttpClient httpClient = null; | |
| 35 | + static HttpGet get; | |
| 36 | + static RequestConfig requestConfig; | |
| 37 | + static CloseableHttpResponse response; | |
| 38 | + static HttpEntity entity; | |
| 39 | + static BufferedReader br; | |
| 40 | + | |
| 41 | + static { | |
| 42 | + url = ConfigUtil.get("http.gps.real.cache.url"); | |
| 43 | + list = new ArrayList<>(); | |
| 44 | + httpClient = HttpClients.createDefault(); | |
| 45 | + get = new HttpGet(url); | |
| 46 | + requestConfig = RequestConfig.custom() | |
| 47 | + .setConnectTimeout(1500).setConnectionRequestTimeout(1000) | |
| 48 | + .setSocketTimeout(1500).build(); | |
| 49 | + get.setConfig(requestConfig); | |
| 50 | + } | |
| 51 | + | |
| 52 | + public static List<GpsEntity> load(){ | |
| 53 | + try { | |
| 54 | + if(list.size() > 0) | |
| 55 | + list.clear(); | |
| 56 | + logger.info("load start..."); | |
| 57 | + response = httpClient.execute(get); | |
| 58 | + entity = response.getEntity(); | |
| 59 | + if(null == entity) | |
| 60 | + return list; | |
| 61 | + | |
| 62 | + br = new BufferedReader(new InputStreamReader(entity.getContent())); | |
| 63 | + StringBuilder sb = new StringBuilder(); | |
| 64 | + String str; | |
| 65 | + while ((str = br.readLine()) != null) | |
| 66 | + sb.append(str); | |
| 67 | + | |
| 68 | + list = JSON.parseArray(sb.toString(), GpsEntity.class); | |
| 69 | + | |
| 70 | + //过滤掉无效的点位 | |
| 71 | + list = GpsDataUtils.clearInvalid(list); | |
| 72 | + | |
| 73 | + logger.info("load end!"); | |
| 74 | + for (GpsEntity gps : list) { | |
| 75 | + gps.setNbbm(BasicData.deviceId2NbbmMap.get(gps.getDeviceId())); | |
| 76 | + } | |
| 77 | + | |
| 78 | + if (null != response) | |
| 79 | + response.close(); | |
| 80 | + } catch (Exception e) { | |
| 81 | + logger.error("", e); | |
| 82 | + } | |
| 83 | + | |
| 84 | + return list; | |
| 85 | + } | |
| 86 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/rfid/UploadRfidDataService.java
src/main/java/com/bsth/data/gpsdata_v2/rfid/entity/RfidInoutStation.java
| 1 | -package com.bsth.data.gpsdata_v2.rfid.entity; | |
| 2 | - | |
| 3 | -/** | |
| 4 | - * RFID 进出数据 | |
| 5 | - * Created by panzhao on 2017/11/22. | |
| 6 | - */ | |
| 7 | -public class RfidInoutStation { | |
| 8 | - | |
| 9 | - private String nbbm; | |
| 10 | - | |
| 11 | - private String station; | |
| 12 | - | |
| 13 | - /** | |
| 14 | - * 0 进 | |
| 15 | - * 1 出 | |
| 16 | - */ | |
| 17 | - private int type; | |
| 18 | - | |
| 19 | - /** | |
| 20 | - * 信号时间 | |
| 21 | - */ | |
| 22 | - private long t; | |
| 23 | - | |
| 24 | - public String getNbbm() { | |
| 25 | - return nbbm; | |
| 26 | - } | |
| 27 | - | |
| 28 | - public void setNbbm(String nbbm) { | |
| 29 | - this.nbbm = nbbm; | |
| 30 | - } | |
| 31 | - | |
| 32 | - public String getStation() { | |
| 33 | - return station; | |
| 34 | - } | |
| 35 | - | |
| 36 | - public void setStation(String station) { | |
| 37 | - this.station = station; | |
| 38 | - } | |
| 39 | - | |
| 40 | - public int getType() { | |
| 41 | - return type; | |
| 42 | - } | |
| 43 | - | |
| 44 | - public void setType(int type) { | |
| 45 | - this.type = type; | |
| 46 | - } | |
| 47 | - | |
| 48 | - public long getT() { | |
| 49 | - return t; | |
| 50 | - } | |
| 51 | - | |
| 52 | - public void setT(long t) { | |
| 53 | - this.t = t; | |
| 54 | - } | |
| 55 | -} | |
| 1 | +package com.bsth.data.gpsdata_v2.rfid.entity; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * RFID 进出数据 | |
| 5 | + * Created by panzhao on 2017/11/22. | |
| 6 | + */ | |
| 7 | +public class RfidInoutStation { | |
| 8 | + | |
| 9 | + private String nbbm; | |
| 10 | + | |
| 11 | + private String station; | |
| 12 | + | |
| 13 | + /** | |
| 14 | + * 0 进 | |
| 15 | + * 1 出 | |
| 16 | + */ | |
| 17 | + private int type; | |
| 18 | + | |
| 19 | + /** | |
| 20 | + * 信号时间 | |
| 21 | + */ | |
| 22 | + private long t; | |
| 23 | + | |
| 24 | + public String getNbbm() { | |
| 25 | + return nbbm; | |
| 26 | + } | |
| 27 | + | |
| 28 | + public void setNbbm(String nbbm) { | |
| 29 | + this.nbbm = nbbm; | |
| 30 | + } | |
| 31 | + | |
| 32 | + public String getStation() { | |
| 33 | + return station; | |
| 34 | + } | |
| 35 | + | |
| 36 | + public void setStation(String station) { | |
| 37 | + this.station = station; | |
| 38 | + } | |
| 39 | + | |
| 40 | + public int getType() { | |
| 41 | + return type; | |
| 42 | + } | |
| 43 | + | |
| 44 | + public void setType(int type) { | |
| 45 | + this.type = type; | |
| 46 | + } | |
| 47 | + | |
| 48 | + public long getT() { | |
| 49 | + return t; | |
| 50 | + } | |
| 51 | + | |
| 52 | + public void setT(long t) { | |
| 53 | + this.t = t; | |
| 54 | + } | |
| 55 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/rfid/handle/RfidSignalHandle.java
src/main/java/com/bsth/data/gpsdata_v2/status_manager/GpsStatusManager.java
| 1 | -package com.bsth.data.gpsdata_v2.status_manager; | |
| 2 | - | |
| 3 | -import com.bsth.Application; | |
| 4 | -import com.bsth.data.gpsdata_v2.status_manager.gps_line_state.LineStateHandle; | |
| 5 | -import com.bsth.data.gpsdata_v2.status_manager.gps_service_state.ServiceStateHandle; | |
| 6 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 7 | -import org.springframework.boot.CommandLineRunner; | |
| 8 | -import org.springframework.stereotype.Component; | |
| 9 | - | |
| 10 | -import java.util.concurrent.TimeUnit; | |
| 11 | - | |
| 12 | -/** | |
| 13 | - * GPS 状态管理 | |
| 14 | - * Created by panzhao on 2017/7/13. | |
| 15 | - */ | |
| 16 | -@Component | |
| 17 | -public class GpsStatusManager implements CommandLineRunner { | |
| 18 | - | |
| 19 | - @Autowired | |
| 20 | - StatusCheckThread checkThread; | |
| 21 | - | |
| 22 | - @Autowired | |
| 23 | - LineStateHandle lineStateHandle; | |
| 24 | - | |
| 25 | - @Autowired | |
| 26 | - ServiceStateHandle serviceStateHandle; | |
| 27 | - | |
| 28 | - /** | |
| 29 | - * 切换线路 | |
| 30 | - * @param nbbm | |
| 31 | - * @param lineCode | |
| 32 | - * @param sender | |
| 33 | - */ | |
| 34 | - public void changeLine(String nbbm, String lineCode, String sender){ | |
| 35 | - lineStateHandle.changeLine(nbbm, lineCode, sender); | |
| 36 | - } | |
| 37 | - | |
| 38 | - /** | |
| 39 | - * 切换营运状态 | |
| 40 | - * @param nbbm | |
| 41 | - * @param state 0 营运, 1:非营运 | |
| 42 | - * @param sender | |
| 43 | - */ | |
| 44 | - public void changeServiceState(String nbbm, String upDown,int state, String sender){ | |
| 45 | - changeServiceState(nbbm, Integer.parseInt(upDown), state, sender); | |
| 46 | - } | |
| 47 | - | |
| 48 | - /** | |
| 49 | - * 切换营运状态 | |
| 50 | - * @param nbbm | |
| 51 | - * @param state 0 营运, 1:非营运 | |
| 52 | - * @param sender | |
| 53 | - */ | |
| 54 | - public void changeServiceState(String nbbm, int upDown,int state, String sender){ | |
| 55 | - serviceStateHandle.changeState(nbbm, upDown, state, sender); | |
| 56 | - } | |
| 57 | - | |
| 58 | - @Override | |
| 59 | - public void run(String... strings) throws Exception { | |
| 60 | - Application.mainServices.scheduleWithFixedDelay(checkThread, 120, 120, TimeUnit.SECONDS); | |
| 61 | - } | |
| 62 | - | |
| 63 | - @Component | |
| 64 | - public static class StatusCheckThread extends Thread{ | |
| 65 | - | |
| 66 | - @Autowired | |
| 67 | - LineStateHandle lineStateHandle; | |
| 68 | - | |
| 69 | - @Autowired | |
| 70 | - ServiceStateHandle serviceStateHandle; | |
| 71 | - | |
| 72 | - @Override | |
| 73 | - public void run() { | |
| 74 | - /** 检查线路切换结果 */ | |
| 75 | - lineStateHandle.checkResultAll(); | |
| 76 | - /** 检查营运状态切换结果 */ | |
| 77 | - serviceStateHandle.checkResultAll(); | |
| 78 | - } | |
| 79 | - } | |
| 80 | -} | |
| 1 | +package com.bsth.data.gpsdata_v2.status_manager; | |
| 2 | + | |
| 3 | +import com.bsth.Application; | |
| 4 | +import com.bsth.data.gpsdata_v2.status_manager.gps_line_state.LineStateHandle; | |
| 5 | +import com.bsth.data.gpsdata_v2.status_manager.gps_service_state.ServiceStateHandle; | |
| 6 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 7 | +import org.springframework.boot.CommandLineRunner; | |
| 8 | +import org.springframework.stereotype.Component; | |
| 9 | + | |
| 10 | +import java.util.concurrent.TimeUnit; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * GPS 状态管理 | |
| 14 | + * Created by panzhao on 2017/7/13. | |
| 15 | + */ | |
| 16 | +@Component | |
| 17 | +public class GpsStatusManager implements CommandLineRunner { | |
| 18 | + | |
| 19 | + @Autowired | |
| 20 | + StatusCheckThread checkThread; | |
| 21 | + | |
| 22 | + @Autowired | |
| 23 | + LineStateHandle lineStateHandle; | |
| 24 | + | |
| 25 | + @Autowired | |
| 26 | + ServiceStateHandle serviceStateHandle; | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * 切换线路 | |
| 30 | + * @param nbbm | |
| 31 | + * @param lineCode | |
| 32 | + * @param sender | |
| 33 | + */ | |
| 34 | + public void changeLine(String nbbm, String lineCode, String sender){ | |
| 35 | + lineStateHandle.changeLine(nbbm, lineCode, sender); | |
| 36 | + } | |
| 37 | + | |
| 38 | + /** | |
| 39 | + * 切换营运状态 | |
| 40 | + * @param nbbm | |
| 41 | + * @param state 0 营运, 1:非营运 | |
| 42 | + * @param sender | |
| 43 | + */ | |
| 44 | + public void changeServiceState(String nbbm, String upDown,int state, String sender){ | |
| 45 | + changeServiceState(nbbm, Integer.parseInt(upDown), state, sender); | |
| 46 | + } | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * 切换营运状态 | |
| 50 | + * @param nbbm | |
| 51 | + * @param state 0 营运, 1:非营运 | |
| 52 | + * @param sender | |
| 53 | + */ | |
| 54 | + public void changeServiceState(String nbbm, int upDown,int state, String sender){ | |
| 55 | + serviceStateHandle.changeState(nbbm, upDown, state, sender); | |
| 56 | + } | |
| 57 | + | |
| 58 | + @Override | |
| 59 | + public void run(String... strings) throws Exception { | |
| 60 | + Application.mainServices.scheduleWithFixedDelay(checkThread, 120, 120, TimeUnit.SECONDS); | |
| 61 | + } | |
| 62 | + | |
| 63 | + @Component | |
| 64 | + public static class StatusCheckThread extends Thread{ | |
| 65 | + | |
| 66 | + @Autowired | |
| 67 | + LineStateHandle lineStateHandle; | |
| 68 | + | |
| 69 | + @Autowired | |
| 70 | + ServiceStateHandle serviceStateHandle; | |
| 71 | + | |
| 72 | + @Override | |
| 73 | + public void run() { | |
| 74 | + /** 检查线路切换结果 */ | |
| 75 | + lineStateHandle.checkResultAll(); | |
| 76 | + /** 检查营运状态切换结果 */ | |
| 77 | + serviceStateHandle.checkResultAll(); | |
| 78 | + } | |
| 79 | + } | |
| 80 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/status_manager/gps_line_state/ChangeBean.java
| 1 | -package com.bsth.data.gpsdata_v2.status_manager.gps_line_state; | |
| 2 | - | |
| 3 | -/** | |
| 4 | - * Created by panzhao on 2017/7/13. | |
| 5 | - */ | |
| 6 | -public class ChangeBean { | |
| 7 | - | |
| 8 | - /** | |
| 9 | - * 车辆自编号 | |
| 10 | - */ | |
| 11 | - private String nbbm; | |
| 12 | - | |
| 13 | - /** | |
| 14 | - * 要切换到的线路 | |
| 15 | - */ | |
| 16 | - private String lineCode; | |
| 17 | - | |
| 18 | - /** | |
| 19 | - * 指令发送次数 | |
| 20 | - */ | |
| 21 | - private int sendCount; | |
| 22 | - | |
| 23 | - /** | |
| 24 | - * 上次指令时间 | |
| 25 | - */ | |
| 26 | - private long st; | |
| 27 | - | |
| 28 | - /**发送人 */ | |
| 29 | - private String sender; | |
| 30 | - | |
| 31 | - public static ChangeBean getInstance(String nbbm, String lineCode, String sender){ | |
| 32 | - ChangeBean cb = new ChangeBean(); | |
| 33 | - cb.setNbbm(nbbm); | |
| 34 | - cb.setLineCode(lineCode); | |
| 35 | - cb.setSendCount(0); | |
| 36 | - cb.setSender(sender); | |
| 37 | - return cb; | |
| 38 | - } | |
| 39 | - | |
| 40 | - public void countPlus(){ | |
| 41 | - sendCount ++; | |
| 42 | - } | |
| 43 | - | |
| 44 | - public String getLineCode() { | |
| 45 | - return lineCode; | |
| 46 | - } | |
| 47 | - | |
| 48 | - public void setLineCode(String lineCode) { | |
| 49 | - this.lineCode = lineCode; | |
| 50 | - } | |
| 51 | - | |
| 52 | - public int getSendCount() { | |
| 53 | - return sendCount; | |
| 54 | - } | |
| 55 | - | |
| 56 | - public void setSendCount(int sendCount) { | |
| 57 | - this.sendCount = sendCount; | |
| 58 | - } | |
| 59 | - | |
| 60 | - public long getSt() { | |
| 61 | - return st; | |
| 62 | - } | |
| 63 | - | |
| 64 | - public void setSt(long st) { | |
| 65 | - this.st = st; | |
| 66 | - } | |
| 67 | - | |
| 68 | - public String getSender() { | |
| 69 | - return sender; | |
| 70 | - } | |
| 71 | - | |
| 72 | - public void setSender(String sender) { | |
| 73 | - this.sender = sender; | |
| 74 | - } | |
| 75 | - | |
| 76 | - public String getNbbm() { | |
| 77 | - return nbbm; | |
| 78 | - } | |
| 79 | - | |
| 80 | - public void setNbbm(String nbbm) { | |
| 81 | - this.nbbm = nbbm; | |
| 82 | - } | |
| 83 | -} | |
| 1 | +package com.bsth.data.gpsdata_v2.status_manager.gps_line_state; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * Created by panzhao on 2017/7/13. | |
| 5 | + */ | |
| 6 | +public class ChangeBean { | |
| 7 | + | |
| 8 | + /** | |
| 9 | + * 车辆自编号 | |
| 10 | + */ | |
| 11 | + private String nbbm; | |
| 12 | + | |
| 13 | + /** | |
| 14 | + * 要切换到的线路 | |
| 15 | + */ | |
| 16 | + private String lineCode; | |
| 17 | + | |
| 18 | + /** | |
| 19 | + * 指令发送次数 | |
| 20 | + */ | |
| 21 | + private int sendCount; | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * 上次指令时间 | |
| 25 | + */ | |
| 26 | + private long st; | |
| 27 | + | |
| 28 | + /**发送人 */ | |
| 29 | + private String sender; | |
| 30 | + | |
| 31 | + public static ChangeBean getInstance(String nbbm, String lineCode, String sender){ | |
| 32 | + ChangeBean cb = new ChangeBean(); | |
| 33 | + cb.setNbbm(nbbm); | |
| 34 | + cb.setLineCode(lineCode); | |
| 35 | + cb.setSendCount(0); | |
| 36 | + cb.setSender(sender); | |
| 37 | + return cb; | |
| 38 | + } | |
| 39 | + | |
| 40 | + public void countPlus(){ | |
| 41 | + sendCount ++; | |
| 42 | + } | |
| 43 | + | |
| 44 | + public String getLineCode() { | |
| 45 | + return lineCode; | |
| 46 | + } | |
| 47 | + | |
| 48 | + public void setLineCode(String lineCode) { | |
| 49 | + this.lineCode = lineCode; | |
| 50 | + } | |
| 51 | + | |
| 52 | + public int getSendCount() { | |
| 53 | + return sendCount; | |
| 54 | + } | |
| 55 | + | |
| 56 | + public void setSendCount(int sendCount) { | |
| 57 | + this.sendCount = sendCount; | |
| 58 | + } | |
| 59 | + | |
| 60 | + public long getSt() { | |
| 61 | + return st; | |
| 62 | + } | |
| 63 | + | |
| 64 | + public void setSt(long st) { | |
| 65 | + this.st = st; | |
| 66 | + } | |
| 67 | + | |
| 68 | + public String getSender() { | |
| 69 | + return sender; | |
| 70 | + } | |
| 71 | + | |
| 72 | + public void setSender(String sender) { | |
| 73 | + this.sender = sender; | |
| 74 | + } | |
| 75 | + | |
| 76 | + public String getNbbm() { | |
| 77 | + return nbbm; | |
| 78 | + } | |
| 79 | + | |
| 80 | + public void setNbbm(String nbbm) { | |
| 81 | + this.nbbm = nbbm; | |
| 82 | + } | |
| 83 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/status_manager/gps_line_state/LineStateHandle.java
| 1 | -package com.bsth.data.gpsdata_v2.status_manager.gps_line_state; | |
| 2 | - | |
| 3 | -import com.bsth.data.gpsdata_v2.GpsRealData; | |
| 4 | -import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 5 | -import com.bsth.data.msg_queue.DirectivePushQueue; | |
| 6 | -import com.bsth.service.directive.DirectiveService; | |
| 7 | -import org.slf4j.Logger; | |
| 8 | -import org.slf4j.LoggerFactory; | |
| 9 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 10 | -import org.springframework.stereotype.Component; | |
| 11 | - | |
| 12 | -import java.util.Collection; | |
| 13 | -import java.util.concurrent.ConcurrentHashMap; | |
| 14 | - | |
| 15 | -/** | |
| 16 | - * 设备线路状态处理 | |
| 17 | - * Created by panzhao on 2017/7/13. | |
| 18 | - */ | |
| 19 | -@Component | |
| 20 | -public class LineStateHandle { | |
| 21 | - | |
| 22 | - private static ConcurrentHashMap<String, ChangeBean> map; | |
| 23 | - | |
| 24 | - @Autowired | |
| 25 | - DirectiveService directiveService; | |
| 26 | - @Autowired | |
| 27 | - GpsRealData gpsRealData; | |
| 28 | - | |
| 29 | - Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 30 | - | |
| 31 | - /** 重发次数 */ | |
| 32 | - private final static int MAX_SEND_COUNT=3; | |
| 33 | - /** 重发间隔 */ | |
| 34 | - private final static int SEND_SPACE=1000 * 60 * 6; | |
| 35 | - /** 最大有效时间 */ | |
| 36 | - private final static int MAX_AVAIL_TIME=1000 * 60 * 60 * 2; | |
| 37 | - | |
| 38 | - static{ | |
| 39 | - map = new ConcurrentHashMap(); | |
| 40 | - } | |
| 41 | - | |
| 42 | - public void changeLine(String nbbm, String lineCode, String sender){ | |
| 43 | - ChangeBean cb = map.get(nbbm); | |
| 44 | - if(cb != null && cb.getLineCode().equals(lineCode)){ | |
| 45 | - return; | |
| 46 | - } | |
| 47 | - | |
| 48 | - cb = ChangeBean.getInstance(nbbm, lineCode, sender); | |
| 49 | - map.put(nbbm, cb); | |
| 50 | - | |
| 51 | - changeLine(cb); | |
| 52 | - } | |
| 53 | - | |
| 54 | - private void changeLine(ChangeBean cb){ | |
| 55 | - cb.setSt(System.currentTimeMillis()); | |
| 56 | - cb.countPlus(); | |
| 57 | - DirectivePushQueue.put64(cb.getNbbm(), cb.getLineCode(), cb.getSender()); | |
| 58 | - } | |
| 59 | - | |
| 60 | - | |
| 61 | - public void checkResultAll(){ | |
| 62 | - Collection<ChangeBean> cbs = map.values(); | |
| 63 | - for(ChangeBean cb : cbs){ | |
| 64 | - checkResult(cb); | |
| 65 | - } | |
| 66 | - } | |
| 67 | - | |
| 68 | - private void checkResult(ChangeBean cb){ | |
| 69 | - try{ | |
| 70 | - GpsEntity gps = gpsRealData.getByNbbm(cb.getNbbm()); | |
| 71 | - if(gps == null) | |
| 72 | - return; | |
| 73 | - | |
| 74 | - if(cb.getLineCode().equals(gps.getLineId())){ | |
| 75 | - map.remove(cb.getNbbm()); | |
| 76 | - logger.info("线路切换成功," + cb.getNbbm() + "、" + cb.getLineCode()); | |
| 77 | - } | |
| 78 | - else{ | |
| 79 | - reSend(cb); | |
| 80 | - } | |
| 81 | - }catch (Exception e){ | |
| 82 | - logger.error("", e); | |
| 83 | - } | |
| 84 | - } | |
| 85 | - | |
| 86 | - private void reSend(ChangeBean cb){ | |
| 87 | - if(cb.getSendCount() >= MAX_SEND_COUNT){ | |
| 88 | - map.remove(cb.getNbbm()); | |
| 89 | - logger.info("超过重发次数," + cb.getNbbm() + "、" + cb.getLineCode()); | |
| 90 | - return; | |
| 91 | - } | |
| 92 | - | |
| 93 | - long diff = System.currentTimeMillis() - cb.getSt(); | |
| 94 | - if(diff >= MAX_AVAIL_TIME){ | |
| 95 | - map.remove(cb.getNbbm()); | |
| 96 | - logger.info("超过有效时间," + cb.getNbbm() + "、" + cb.getLineCode() + "、" + cb.getSt()); | |
| 97 | - return; | |
| 98 | - } | |
| 99 | - | |
| 100 | - if(diff >= SEND_SPACE){ | |
| 101 | - cb.setSender("补发@系统"); | |
| 102 | - changeLine(cb); | |
| 103 | - logger.info("重发线路切换指令," + cb.getNbbm() + "、" + cb.getLineCode()); | |
| 104 | - return; | |
| 105 | - } | |
| 106 | - } | |
| 107 | -} | |
| 1 | +package com.bsth.data.gpsdata_v2.status_manager.gps_line_state; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata_v2.GpsRealData; | |
| 4 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 5 | +import com.bsth.data.msg_queue.DirectivePushQueue; | |
| 6 | +import com.bsth.service.directive.DirectiveService; | |
| 7 | +import org.slf4j.Logger; | |
| 8 | +import org.slf4j.LoggerFactory; | |
| 9 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 10 | +import org.springframework.stereotype.Component; | |
| 11 | + | |
| 12 | +import java.util.Collection; | |
| 13 | +import java.util.concurrent.ConcurrentHashMap; | |
| 14 | + | |
| 15 | +/** | |
| 16 | + * 设备线路状态处理 | |
| 17 | + * Created by panzhao on 2017/7/13. | |
| 18 | + */ | |
| 19 | +@Component | |
| 20 | +public class LineStateHandle { | |
| 21 | + | |
| 22 | + private static ConcurrentHashMap<String, ChangeBean> map; | |
| 23 | + | |
| 24 | + @Autowired | |
| 25 | + DirectiveService directiveService; | |
| 26 | + @Autowired | |
| 27 | + GpsRealData gpsRealData; | |
| 28 | + | |
| 29 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 30 | + | |
| 31 | + /** 重发次数 */ | |
| 32 | + private final static int MAX_SEND_COUNT=3; | |
| 33 | + /** 重发间隔 */ | |
| 34 | + private final static int SEND_SPACE=1000 * 60 * 6; | |
| 35 | + /** 最大有效时间 */ | |
| 36 | + private final static int MAX_AVAIL_TIME=1000 * 60 * 60 * 2; | |
| 37 | + | |
| 38 | + static{ | |
| 39 | + map = new ConcurrentHashMap(); | |
| 40 | + } | |
| 41 | + | |
| 42 | + public void changeLine(String nbbm, String lineCode, String sender){ | |
| 43 | + ChangeBean cb = map.get(nbbm); | |
| 44 | + if(cb != null && cb.getLineCode().equals(lineCode)){ | |
| 45 | + return; | |
| 46 | + } | |
| 47 | + | |
| 48 | + cb = ChangeBean.getInstance(nbbm, lineCode, sender); | |
| 49 | + map.put(nbbm, cb); | |
| 50 | + | |
| 51 | + changeLine(cb); | |
| 52 | + } | |
| 53 | + | |
| 54 | + private void changeLine(ChangeBean cb){ | |
| 55 | + cb.setSt(System.currentTimeMillis()); | |
| 56 | + cb.countPlus(); | |
| 57 | + DirectivePushQueue.put64(cb.getNbbm(), cb.getLineCode(), cb.getSender()); | |
| 58 | + } | |
| 59 | + | |
| 60 | + | |
| 61 | + public void checkResultAll(){ | |
| 62 | + Collection<ChangeBean> cbs = map.values(); | |
| 63 | + for(ChangeBean cb : cbs){ | |
| 64 | + checkResult(cb); | |
| 65 | + } | |
| 66 | + } | |
| 67 | + | |
| 68 | + private void checkResult(ChangeBean cb){ | |
| 69 | + try{ | |
| 70 | + GpsEntity gps = gpsRealData.getByNbbm(cb.getNbbm()); | |
| 71 | + if(gps == null) | |
| 72 | + return; | |
| 73 | + | |
| 74 | + if(cb.getLineCode().equals(gps.getLineId())){ | |
| 75 | + map.remove(cb.getNbbm()); | |
| 76 | + logger.info("线路切换成功," + cb.getNbbm() + "、" + cb.getLineCode()); | |
| 77 | + } | |
| 78 | + else{ | |
| 79 | + reSend(cb); | |
| 80 | + } | |
| 81 | + }catch (Exception e){ | |
| 82 | + logger.error("", e); | |
| 83 | + } | |
| 84 | + } | |
| 85 | + | |
| 86 | + private void reSend(ChangeBean cb){ | |
| 87 | + if(cb.getSendCount() >= MAX_SEND_COUNT){ | |
| 88 | + map.remove(cb.getNbbm()); | |
| 89 | + logger.info("超过重发次数," + cb.getNbbm() + "、" + cb.getLineCode()); | |
| 90 | + return; | |
| 91 | + } | |
| 92 | + | |
| 93 | + long diff = System.currentTimeMillis() - cb.getSt(); | |
| 94 | + if(diff >= MAX_AVAIL_TIME){ | |
| 95 | + map.remove(cb.getNbbm()); | |
| 96 | + logger.info("超过有效时间," + cb.getNbbm() + "、" + cb.getLineCode() + "、" + cb.getSt()); | |
| 97 | + return; | |
| 98 | + } | |
| 99 | + | |
| 100 | + if(diff >= SEND_SPACE){ | |
| 101 | + cb.setSender("补发@系统"); | |
| 102 | + changeLine(cb); | |
| 103 | + logger.info("重发线路切换指令," + cb.getNbbm() + "、" + cb.getLineCode()); | |
| 104 | + return; | |
| 105 | + } | |
| 106 | + } | |
| 107 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/status_manager/gps_service_state/ServiceStateHandle.java
| 1 | -package com.bsth.data.gpsdata_v2.status_manager.gps_service_state; | |
| 2 | - | |
| 3 | -import com.bsth.data.gpsdata_v2.GpsRealData; | |
| 4 | -import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 5 | -import com.bsth.data.msg_queue.DirectivePushQueue; | |
| 6 | -import com.bsth.service.directive.DirectiveService; | |
| 7 | -import org.slf4j.Logger; | |
| 8 | -import org.slf4j.LoggerFactory; | |
| 9 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 10 | -import org.springframework.stereotype.Component; | |
| 11 | - | |
| 12 | -import java.util.Collection; | |
| 13 | -import java.util.concurrent.ConcurrentHashMap; | |
| 14 | - | |
| 15 | -/** | |
| 16 | - * 设备营运状态/上下行 处理 | |
| 17 | - * Created by panzhao on 2017/7/13. | |
| 18 | - */ | |
| 19 | -@Component | |
| 20 | -public class ServiceStateHandle { | |
| 21 | - | |
| 22 | - private static ConcurrentHashMap<String, StateBean> map; | |
| 23 | - | |
| 24 | - @Autowired | |
| 25 | - DirectiveService directiveService; | |
| 26 | - @Autowired | |
| 27 | - GpsRealData gpsRealData; | |
| 28 | - | |
| 29 | - Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 30 | - | |
| 31 | - /** 重发次数 */ | |
| 32 | - private final static int MAX_SEND_COUNT=3; | |
| 33 | - /** 重发间隔 */ | |
| 34 | - private final static int SEND_SPACE=1000 * 60 * 3; | |
| 35 | - /** 最大有效时间 */ | |
| 36 | - private final static int MAX_AVAIL_TIME=1000 * 60 * 50; | |
| 37 | - | |
| 38 | - static{ | |
| 39 | - map = new ConcurrentHashMap(); | |
| 40 | - } | |
| 41 | - | |
| 42 | - public void changeState(String nbbm, int upDown ,int state, String sender){ | |
| 43 | - if(map.containsKey(nbbm)){ | |
| 44 | - return; | |
| 45 | - } | |
| 46 | - StateBean sb = StateBean.getInstance(nbbm, upDown, state, sender); | |
| 47 | - map.put(nbbm, sb); | |
| 48 | - changeState(sb); | |
| 49 | - } | |
| 50 | - | |
| 51 | - private void changeState(StateBean sb){ | |
| 52 | - sb.setSt(System.currentTimeMillis()); | |
| 53 | - sb.countPlus(); | |
| 54 | - DirectivePushQueue.put6003(sb.getNbbm(), sb.getState(), sb.getUpDown(), sb.getSender()); | |
| 55 | - } | |
| 56 | - | |
| 57 | - public void checkResultAll(){ | |
| 58 | - Collection<StateBean> sbs = map.values(); | |
| 59 | - for(StateBean sb : sbs){ | |
| 60 | - checkResult(sb); | |
| 61 | - } | |
| 62 | - } | |
| 63 | - | |
| 64 | - private void checkResult(StateBean sb){ | |
| 65 | - try{ | |
| 66 | - GpsEntity gps = gpsRealData.getByNbbm(sb.getNbbm()); | |
| 67 | - if(gps == null) | |
| 68 | - return; | |
| 69 | - | |
| 70 | - if(gps.getState().equals(sb.getState()) && gps.getUpDown() == sb.getUpDown()){ | |
| 71 | - map.remove(sb.getNbbm()); | |
| 72 | - logger.info("状态切换成功," + sb.getNbbm() + "、" + sb.getState() + "、" + sb.getUpDown()); | |
| 73 | - } | |
| 74 | - else | |
| 75 | - reSend(sb); | |
| 76 | - }catch (Exception e){ | |
| 77 | - logger.error("", e); | |
| 78 | - } | |
| 79 | - } | |
| 80 | - | |
| 81 | - private void reSend(StateBean sb){ | |
| 82 | - if(sb.getSendCount() >= MAX_SEND_COUNT){ | |
| 83 | - map.remove(sb.getNbbm()); | |
| 84 | - logger.info("超过重发次数," + sb.getNbbm() + "、" + sb.getState()); | |
| 85 | - return; | |
| 86 | - } | |
| 87 | - | |
| 88 | - long diff = System.currentTimeMillis() - sb.getSt(); | |
| 89 | - if(diff >= MAX_AVAIL_TIME){ | |
| 90 | - map.remove(sb.getNbbm()); | |
| 91 | - logger.info("状态切换超过有效时间," + sb.getNbbm() + "、" + sb.getState() + "、" + sb.getSt()); | |
| 92 | - return; | |
| 93 | - } | |
| 94 | - | |
| 95 | - if(diff >= SEND_SPACE){ | |
| 96 | - sb.setSender("补发@系统"); | |
| 97 | - changeState(sb); | |
| 98 | - logger.info("重发状态切换指令," + sb.getNbbm() + "、" + sb.getState() + "、" + sb.getUpDown()); | |
| 99 | - return; | |
| 100 | - } | |
| 101 | - } | |
| 102 | -} | |
| 1 | +package com.bsth.data.gpsdata_v2.status_manager.gps_service_state; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata_v2.GpsRealData; | |
| 4 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 5 | +import com.bsth.data.msg_queue.DirectivePushQueue; | |
| 6 | +import com.bsth.service.directive.DirectiveService; | |
| 7 | +import org.slf4j.Logger; | |
| 8 | +import org.slf4j.LoggerFactory; | |
| 9 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 10 | +import org.springframework.stereotype.Component; | |
| 11 | + | |
| 12 | +import java.util.Collection; | |
| 13 | +import java.util.concurrent.ConcurrentHashMap; | |
| 14 | + | |
| 15 | +/** | |
| 16 | + * 设备营运状态/上下行 处理 | |
| 17 | + * Created by panzhao on 2017/7/13. | |
| 18 | + */ | |
| 19 | +@Component | |
| 20 | +public class ServiceStateHandle { | |
| 21 | + | |
| 22 | + private static ConcurrentHashMap<String, StateBean> map; | |
| 23 | + | |
| 24 | + @Autowired | |
| 25 | + DirectiveService directiveService; | |
| 26 | + @Autowired | |
| 27 | + GpsRealData gpsRealData; | |
| 28 | + | |
| 29 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 30 | + | |
| 31 | + /** 重发次数 */ | |
| 32 | + private final static int MAX_SEND_COUNT=3; | |
| 33 | + /** 重发间隔 */ | |
| 34 | + private final static int SEND_SPACE=1000 * 60 * 3; | |
| 35 | + /** 最大有效时间 */ | |
| 36 | + private final static int MAX_AVAIL_TIME=1000 * 60 * 50; | |
| 37 | + | |
| 38 | + static{ | |
| 39 | + map = new ConcurrentHashMap(); | |
| 40 | + } | |
| 41 | + | |
| 42 | + public void changeState(String nbbm, int upDown ,int state, String sender){ | |
| 43 | + if(map.containsKey(nbbm)){ | |
| 44 | + return; | |
| 45 | + } | |
| 46 | + StateBean sb = StateBean.getInstance(nbbm, upDown, state, sender); | |
| 47 | + map.put(nbbm, sb); | |
| 48 | + changeState(sb); | |
| 49 | + } | |
| 50 | + | |
| 51 | + private void changeState(StateBean sb){ | |
| 52 | + sb.setSt(System.currentTimeMillis()); | |
| 53 | + sb.countPlus(); | |
| 54 | + DirectivePushQueue.put6003(sb.getNbbm(), sb.getState(), sb.getUpDown(), sb.getSender()); | |
| 55 | + } | |
| 56 | + | |
| 57 | + public void checkResultAll(){ | |
| 58 | + Collection<StateBean> sbs = map.values(); | |
| 59 | + for(StateBean sb : sbs){ | |
| 60 | + checkResult(sb); | |
| 61 | + } | |
| 62 | + } | |
| 63 | + | |
| 64 | + private void checkResult(StateBean sb){ | |
| 65 | + try{ | |
| 66 | + GpsEntity gps = gpsRealData.getByNbbm(sb.getNbbm()); | |
| 67 | + if(gps == null) | |
| 68 | + return; | |
| 69 | + | |
| 70 | + if(gps.getState().equals(sb.getState()) && gps.getUpDown() == sb.getUpDown()){ | |
| 71 | + map.remove(sb.getNbbm()); | |
| 72 | + logger.info("状态切换成功," + sb.getNbbm() + "、" + sb.getState() + "、" + sb.getUpDown()); | |
| 73 | + } | |
| 74 | + else | |
| 75 | + reSend(sb); | |
| 76 | + }catch (Exception e){ | |
| 77 | + logger.error("", e); | |
| 78 | + } | |
| 79 | + } | |
| 80 | + | |
| 81 | + private void reSend(StateBean sb){ | |
| 82 | + if(sb.getSendCount() >= MAX_SEND_COUNT){ | |
| 83 | + map.remove(sb.getNbbm()); | |
| 84 | + logger.info("超过重发次数," + sb.getNbbm() + "、" + sb.getState()); | |
| 85 | + return; | |
| 86 | + } | |
| 87 | + | |
| 88 | + long diff = System.currentTimeMillis() - sb.getSt(); | |
| 89 | + if(diff >= MAX_AVAIL_TIME){ | |
| 90 | + map.remove(sb.getNbbm()); | |
| 91 | + logger.info("状态切换超过有效时间," + sb.getNbbm() + "、" + sb.getState() + "、" + sb.getSt()); | |
| 92 | + return; | |
| 93 | + } | |
| 94 | + | |
| 95 | + if(diff >= SEND_SPACE){ | |
| 96 | + sb.setSender("补发@系统"); | |
| 97 | + changeState(sb); | |
| 98 | + logger.info("重发状态切换指令," + sb.getNbbm() + "、" + sb.getState() + "、" + sb.getUpDown()); | |
| 99 | + return; | |
| 100 | + } | |
| 101 | + } | |
| 102 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/status_manager/gps_service_state/StateBean.java
| 1 | -package com.bsth.data.gpsdata_v2.status_manager.gps_service_state; | |
| 2 | - | |
| 3 | -/** | |
| 4 | - * Created by panzhao on 2017/7/13. | |
| 5 | - */ | |
| 6 | -public class StateBean { | |
| 7 | - | |
| 8 | - /** | |
| 9 | - * 车辆自编号 | |
| 10 | - */ | |
| 11 | - private String nbbm; | |
| 12 | - | |
| 13 | - /** | |
| 14 | - * 要切换到营运状态 | |
| 15 | - */ | |
| 16 | - private int state; | |
| 17 | - | |
| 18 | - /** | |
| 19 | - * 要切换到的上下行 | |
| 20 | - */ | |
| 21 | - private int upDown; | |
| 22 | - | |
| 23 | - /** | |
| 24 | - * 指令发送次数 | |
| 25 | - */ | |
| 26 | - private int sendCount; | |
| 27 | - | |
| 28 | - /** | |
| 29 | - * 上次指令时间 | |
| 30 | - */ | |
| 31 | - private long st; | |
| 32 | - | |
| 33 | - /**发送人 */ | |
| 34 | - private String sender; | |
| 35 | - | |
| 36 | - public static StateBean getInstance(String nbbm, int upDown, int state, String sender){ | |
| 37 | - StateBean sb = new StateBean(); | |
| 38 | - sb.setNbbm(nbbm); | |
| 39 | - sb.setState(state); | |
| 40 | - sb.setSendCount(0); | |
| 41 | - sb.setSender(sender); | |
| 42 | - sb.setUpDown(upDown); | |
| 43 | - return sb; | |
| 44 | - } | |
| 45 | - | |
| 46 | - public int getState() { | |
| 47 | - return state; | |
| 48 | - } | |
| 49 | - | |
| 50 | - public void setState(int state) { | |
| 51 | - this.state = state; | |
| 52 | - } | |
| 53 | - | |
| 54 | - public int getSendCount() { | |
| 55 | - return sendCount; | |
| 56 | - } | |
| 57 | - | |
| 58 | - public void setSendCount(int sendCount) { | |
| 59 | - this.sendCount = sendCount; | |
| 60 | - } | |
| 61 | - | |
| 62 | - public long getSt() { | |
| 63 | - return st; | |
| 64 | - } | |
| 65 | - | |
| 66 | - public void setSt(long st) { | |
| 67 | - this.st = st; | |
| 68 | - } | |
| 69 | - | |
| 70 | - public String getSender() { | |
| 71 | - return sender; | |
| 72 | - } | |
| 73 | - | |
| 74 | - public void setSender(String sender) { | |
| 75 | - this.sender = sender; | |
| 76 | - } | |
| 77 | - | |
| 78 | - public void countPlus(){ | |
| 79 | - sendCount ++; | |
| 80 | - } | |
| 81 | - | |
| 82 | - public int getUpDown() { | |
| 83 | - return upDown; | |
| 84 | - } | |
| 85 | - | |
| 86 | - public void setUpDown(int upDown) { | |
| 87 | - this.upDown = upDown; | |
| 88 | - } | |
| 89 | - | |
| 90 | - public String getNbbm() { | |
| 91 | - return nbbm; | |
| 92 | - } | |
| 93 | - | |
| 94 | - public void setNbbm(String nbbm) { | |
| 95 | - this.nbbm = nbbm; | |
| 96 | - } | |
| 97 | -} | |
| 1 | +package com.bsth.data.gpsdata_v2.status_manager.gps_service_state; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * Created by panzhao on 2017/7/13. | |
| 5 | + */ | |
| 6 | +public class StateBean { | |
| 7 | + | |
| 8 | + /** | |
| 9 | + * 车辆自编号 | |
| 10 | + */ | |
| 11 | + private String nbbm; | |
| 12 | + | |
| 13 | + /** | |
| 14 | + * 要切换到营运状态 | |
| 15 | + */ | |
| 16 | + private int state; | |
| 17 | + | |
| 18 | + /** | |
| 19 | + * 要切换到的上下行 | |
| 20 | + */ | |
| 21 | + private int upDown; | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * 指令发送次数 | |
| 25 | + */ | |
| 26 | + private int sendCount; | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * 上次指令时间 | |
| 30 | + */ | |
| 31 | + private long st; | |
| 32 | + | |
| 33 | + /**发送人 */ | |
| 34 | + private String sender; | |
| 35 | + | |
| 36 | + public static StateBean getInstance(String nbbm, int upDown, int state, String sender){ | |
| 37 | + StateBean sb = new StateBean(); | |
| 38 | + sb.setNbbm(nbbm); | |
| 39 | + sb.setState(state); | |
| 40 | + sb.setSendCount(0); | |
| 41 | + sb.setSender(sender); | |
| 42 | + sb.setUpDown(upDown); | |
| 43 | + return sb; | |
| 44 | + } | |
| 45 | + | |
| 46 | + public int getState() { | |
| 47 | + return state; | |
| 48 | + } | |
| 49 | + | |
| 50 | + public void setState(int state) { | |
| 51 | + this.state = state; | |
| 52 | + } | |
| 53 | + | |
| 54 | + public int getSendCount() { | |
| 55 | + return sendCount; | |
| 56 | + } | |
| 57 | + | |
| 58 | + public void setSendCount(int sendCount) { | |
| 59 | + this.sendCount = sendCount; | |
| 60 | + } | |
| 61 | + | |
| 62 | + public long getSt() { | |
| 63 | + return st; | |
| 64 | + } | |
| 65 | + | |
| 66 | + public void setSt(long st) { | |
| 67 | + this.st = st; | |
| 68 | + } | |
| 69 | + | |
| 70 | + public String getSender() { | |
| 71 | + return sender; | |
| 72 | + } | |
| 73 | + | |
| 74 | + public void setSender(String sender) { | |
| 75 | + this.sender = sender; | |
| 76 | + } | |
| 77 | + | |
| 78 | + public void countPlus(){ | |
| 79 | + sendCount ++; | |
| 80 | + } | |
| 81 | + | |
| 82 | + public int getUpDown() { | |
| 83 | + return upDown; | |
| 84 | + } | |
| 85 | + | |
| 86 | + public void setUpDown(int upDown) { | |
| 87 | + this.upDown = upDown; | |
| 88 | + } | |
| 89 | + | |
| 90 | + public String getNbbm() { | |
| 91 | + return nbbm; | |
| 92 | + } | |
| 93 | + | |
| 94 | + public void setNbbm(String nbbm) { | |
| 95 | + this.nbbm = nbbm; | |
| 96 | + } | |
| 97 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/thread/GpsDataLoaderThread.java
| 1 | -package com.bsth.data.gpsdata_v2.thread; | |
| 2 | - | |
| 3 | -import com.bsth.data.gpsdata_v2.DataHandleProcess; | |
| 4 | -import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 5 | -import com.bsth.data.gpsdata_v2.load.GatewayHttpLoader; | |
| 6 | -import com.bsth.data.gpsdata_v2.load.SocketClientLoader; | |
| 7 | -import org.slf4j.Logger; | |
| 8 | -import org.slf4j.LoggerFactory; | |
| 9 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 10 | -import org.springframework.stereotype.Component; | |
| 11 | - | |
| 12 | -import java.util.List; | |
| 13 | - | |
| 14 | -/** | |
| 15 | - * Created by panzhao on 2017/1/11. | |
| 16 | - */ | |
| 17 | -@Component | |
| 18 | -public class GpsDataLoaderThread extends Thread { | |
| 19 | - | |
| 20 | - Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 21 | - | |
| 22 | - //0:从GPS客户端内存获取 -1:从网关获取 | |
| 23 | - private static int flag = 0; | |
| 24 | - | |
| 25 | - public static void setFlag(int v) { | |
| 26 | - flag = v; | |
| 27 | - } | |
| 28 | - | |
| 29 | - @Autowired | |
| 30 | - DataHandleProcess handleProcess; | |
| 31 | - | |
| 32 | - @Override | |
| 33 | - public void run() { | |
| 34 | - try { | |
| 35 | - List<GpsEntity> list; | |
| 36 | - if (flag == 0) | |
| 37 | - list = SocketClientLoader.load(); | |
| 38 | - else | |
| 39 | - list = GatewayHttpLoader.load(); | |
| 40 | - | |
| 41 | - if(null != list && list.size() > 0) | |
| 42 | - handleProcess.handle(list); | |
| 43 | - } catch (Exception e) { | |
| 44 | - logger.error("", e); | |
| 45 | - } | |
| 46 | - } | |
| 1 | +package com.bsth.data.gpsdata_v2.thread; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata_v2.DataHandleProcess; | |
| 4 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 5 | +import com.bsth.data.gpsdata_v2.load.GatewayHttpLoader; | |
| 6 | +import com.bsth.data.gpsdata_v2.load.SocketClientLoader; | |
| 7 | +import org.slf4j.Logger; | |
| 8 | +import org.slf4j.LoggerFactory; | |
| 9 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 10 | +import org.springframework.stereotype.Component; | |
| 11 | + | |
| 12 | +import java.util.List; | |
| 13 | + | |
| 14 | +/** | |
| 15 | + * Created by panzhao on 2017/1/11. | |
| 16 | + */ | |
| 17 | +@Component | |
| 18 | +public class GpsDataLoaderThread extends Thread { | |
| 19 | + | |
| 20 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 21 | + | |
| 22 | + //0:从GPS客户端内存获取 -1:从网关获取 | |
| 23 | + private static int flag = 0; | |
| 24 | + | |
| 25 | + public static void setFlag(int v) { | |
| 26 | + flag = v; | |
| 27 | + } | |
| 28 | + | |
| 29 | + @Autowired | |
| 30 | + DataHandleProcess handleProcess; | |
| 31 | + | |
| 32 | + @Override | |
| 33 | + public void run() { | |
| 34 | + try { | |
| 35 | + List<GpsEntity> list; | |
| 36 | + if (flag == 0) | |
| 37 | + list = SocketClientLoader.load(); | |
| 38 | + else | |
| 39 | + list = GatewayHttpLoader.load(); | |
| 40 | + | |
| 41 | + if(null != list && list.size() > 0) | |
| 42 | + handleProcess.handle(list); | |
| 43 | + } catch (Exception e) { | |
| 44 | + logger.error("", e); | |
| 45 | + } | |
| 46 | + } | |
| 47 | 47 | } |
| 48 | 48 | \ No newline at end of file | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/utils/CircleQueue.java
| 1 | -package com.bsth.data.gpsdata_v2.utils; | |
| 2 | - | |
| 3 | -import java.util.Arrays; | |
| 4 | - | |
| 5 | -/** | |
| 6 | - * 循环队列 | |
| 7 | - * Created by panzhao on 2016/12/23. | |
| 8 | - */ | |
| 9 | -public class CircleQueue<T> { | |
| 10 | - | |
| 11 | - /** | |
| 12 | - * (循环队列)数组的容量 | |
| 13 | - */ | |
| 14 | - public int capacity; | |
| 15 | - | |
| 16 | - /** | |
| 17 | - * 数组:保存循环队列的元素 | |
| 18 | - */ | |
| 19 | - public Object[] elementData; | |
| 20 | - | |
| 21 | - /** | |
| 22 | - * 头 | |
| 23 | - */ | |
| 24 | - public int head = 0; | |
| 25 | - | |
| 26 | - /** | |
| 27 | - * 尾 | |
| 28 | - */ | |
| 29 | - public int tail = 0; | |
| 30 | - | |
| 31 | - /** | |
| 32 | - * 以指定长度的数组来创建循环队列 | |
| 33 | - * | |
| 34 | - * @param initSize | |
| 35 | - */ | |
| 36 | - public CircleQueue(final int initSize) { | |
| 37 | - capacity = initSize; | |
| 38 | - elementData = new Object[capacity]; | |
| 39 | - } | |
| 40 | - | |
| 41 | - /** | |
| 42 | - * 获取循环队列的大小 | |
| 43 | - */ | |
| 44 | - public int size() { | |
| 45 | - if (isEmpty()) { | |
| 46 | - return 0; | |
| 47 | - } else if (isFull()) { | |
| 48 | - return capacity; | |
| 49 | - } else { | |
| 50 | - return tail + 1; | |
| 51 | - } | |
| 52 | - } | |
| 53 | - | |
| 54 | - /** | |
| 55 | - * 插入队尾一个元素 | |
| 56 | - */ | |
| 57 | - public void add(final T element) { | |
| 58 | - if (isEmpty()) { | |
| 59 | - elementData[0] = element; | |
| 60 | - } else if (isFull()) { | |
| 61 | - elementData[head] = element; | |
| 62 | - head++; | |
| 63 | - tail++; | |
| 64 | - head = head == capacity ? 0 : head; | |
| 65 | - tail = tail == capacity ? 0 : tail; | |
| 66 | - } else { | |
| 67 | - elementData[tail + 1] = element; | |
| 68 | - tail++; | |
| 69 | - } | |
| 70 | - } | |
| 71 | - | |
| 72 | - public boolean isEmpty() { | |
| 73 | - return tail == head && tail == 0 && elementData[tail] == null; | |
| 74 | - } | |
| 75 | - | |
| 76 | - public boolean isFull() { | |
| 77 | - return head != 0 && head - tail == 1 || head == 0 && tail == capacity - 1; | |
| 78 | - } | |
| 79 | - | |
| 80 | - public void clear() { | |
| 81 | - Arrays.fill(elementData, null); | |
| 82 | - head = 0; | |
| 83 | - tail = 0; | |
| 84 | - } | |
| 85 | - | |
| 86 | - /** | |
| 87 | - * @return 取 循环队列里的值(先进的index=0) | |
| 88 | - */ | |
| 89 | - public Object[] getQueue() { | |
| 90 | - final Object[] elementDataSort; | |
| 91 | - final Object[] elementDataCopy = elementData.clone(); | |
| 92 | - if (isEmpty()) { | |
| 93 | - elementDataSort = new Object[0]; | |
| 94 | - } else if (isFull()) { | |
| 95 | - elementDataSort = new Object[capacity]; | |
| 96 | - int indexMax = capacity; | |
| 97 | - int indexSort = 0; | |
| 98 | - for (int i = head; i < indexMax;) { | |
| 99 | - elementDataSort[indexSort] = elementDataCopy[i]; | |
| 100 | - indexSort++; | |
| 101 | - i++; | |
| 102 | - if (i == capacity) { | |
| 103 | - i = 0; | |
| 104 | - indexMax = head; | |
| 105 | - } | |
| 106 | - } | |
| 107 | - } else { | |
| 108 | - elementDataSort = new Object[tail + 1]; | |
| 109 | - for (int i = 0; i <= tail; i++) { | |
| 110 | - elementDataSort[i] = elementDataCopy[i]; | |
| 111 | - } | |
| 112 | - } | |
| 113 | - return elementDataSort; | |
| 114 | - } | |
| 115 | - | |
| 116 | - /** | |
| 117 | - * 取最后一个值 | |
| 118 | - * @return | |
| 119 | - */ | |
| 120 | - public T getTail(){ | |
| 121 | - return elementData[tail] == null?null:(T)elementData[tail]; | |
| 122 | - } | |
| 1 | +package com.bsth.data.gpsdata_v2.utils; | |
| 2 | + | |
| 3 | +import java.util.Arrays; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * 循环队列 | |
| 7 | + * Created by panzhao on 2016/12/23. | |
| 8 | + */ | |
| 9 | +public class CircleQueue<T> { | |
| 10 | + | |
| 11 | + /** | |
| 12 | + * (循环队列)数组的容量 | |
| 13 | + */ | |
| 14 | + public int capacity; | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * 数组:保存循环队列的元素 | |
| 18 | + */ | |
| 19 | + public Object[] elementData; | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * 头 | |
| 23 | + */ | |
| 24 | + public int head = 0; | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * 尾 | |
| 28 | + */ | |
| 29 | + public int tail = 0; | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * 以指定长度的数组来创建循环队列 | |
| 33 | + * | |
| 34 | + * @param initSize | |
| 35 | + */ | |
| 36 | + public CircleQueue(final int initSize) { | |
| 37 | + capacity = initSize; | |
| 38 | + elementData = new Object[capacity]; | |
| 39 | + } | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * 获取循环队列的大小 | |
| 43 | + */ | |
| 44 | + public int size() { | |
| 45 | + if (isEmpty()) { | |
| 46 | + return 0; | |
| 47 | + } else if (isFull()) { | |
| 48 | + return capacity; | |
| 49 | + } else { | |
| 50 | + return tail + 1; | |
| 51 | + } | |
| 52 | + } | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * 插入队尾一个元素 | |
| 56 | + */ | |
| 57 | + public void add(final T element) { | |
| 58 | + if (isEmpty()) { | |
| 59 | + elementData[0] = element; | |
| 60 | + } else if (isFull()) { | |
| 61 | + elementData[head] = element; | |
| 62 | + head++; | |
| 63 | + tail++; | |
| 64 | + head = head == capacity ? 0 : head; | |
| 65 | + tail = tail == capacity ? 0 : tail; | |
| 66 | + } else { | |
| 67 | + elementData[tail + 1] = element; | |
| 68 | + tail++; | |
| 69 | + } | |
| 70 | + } | |
| 71 | + | |
| 72 | + public boolean isEmpty() { | |
| 73 | + return tail == head && tail == 0 && elementData[tail] == null; | |
| 74 | + } | |
| 75 | + | |
| 76 | + public boolean isFull() { | |
| 77 | + return head != 0 && head - tail == 1 || head == 0 && tail == capacity - 1; | |
| 78 | + } | |
| 79 | + | |
| 80 | + public void clear() { | |
| 81 | + Arrays.fill(elementData, null); | |
| 82 | + head = 0; | |
| 83 | + tail = 0; | |
| 84 | + } | |
| 85 | + | |
| 86 | + /** | |
| 87 | + * @return 取 循环队列里的值(先进的index=0) | |
| 88 | + */ | |
| 89 | + public Object[] getQueue() { | |
| 90 | + final Object[] elementDataSort; | |
| 91 | + final Object[] elementDataCopy = elementData.clone(); | |
| 92 | + if (isEmpty()) { | |
| 93 | + elementDataSort = new Object[0]; | |
| 94 | + } else if (isFull()) { | |
| 95 | + elementDataSort = new Object[capacity]; | |
| 96 | + int indexMax = capacity; | |
| 97 | + int indexSort = 0; | |
| 98 | + for (int i = head; i < indexMax;) { | |
| 99 | + elementDataSort[indexSort] = elementDataCopy[i]; | |
| 100 | + indexSort++; | |
| 101 | + i++; | |
| 102 | + if (i == capacity) { | |
| 103 | + i = 0; | |
| 104 | + indexMax = head; | |
| 105 | + } | |
| 106 | + } | |
| 107 | + } else { | |
| 108 | + elementDataSort = new Object[tail + 1]; | |
| 109 | + for (int i = 0; i <= tail; i++) { | |
| 110 | + elementDataSort[i] = elementDataCopy[i]; | |
| 111 | + } | |
| 112 | + } | |
| 113 | + return elementDataSort; | |
| 114 | + } | |
| 115 | + | |
| 116 | + /** | |
| 117 | + * 取最后一个值 | |
| 118 | + * @return | |
| 119 | + */ | |
| 120 | + public T getTail(){ | |
| 121 | + return elementData[tail] == null?null:(T)elementData[tail]; | |
| 122 | + } | |
| 123 | 123 | } |
| 124 | 124 | \ No newline at end of file | ... | ... |