Commit 283ad9e5aa021f38885cff4075f00231af5a907c

Authored by 潘钊
1 parent bd8321da

update...

src/main/java/com/bsth/data/gpsdata_v2/cache/GeoCacheData.java
... ... @@ -278,7 +278,7 @@ public class GeoCacheData {
278 278 int len = coords.length;
279 279 for (int i = 0; i < len; i++) {
280 280 temps = coords[i].split(" ");
281   - cds.add(new Point(Float.parseFloat(temps[1]), Float.parseFloat(temps[0])));
  281 + cds.add(new Point(Float.parseFloat(temps[0]), Float.parseFloat(temps[1])));
282 282 }
283 283 return new Polygon(cds);
284 284 }
... ...
src/main/java/com/bsth/data/gpsdata_v2/handlers/InStationProcess.java
... ... @@ -42,40 +42,56 @@ public class InStationProcess {
42 42  
43 43 Logger logger = LoggerFactory.getLogger(this.getClass());
44 44  
45   - public void process(GpsEntity gps){
  45 + public void process(GpsEntity gps) {
46 46 GpsEntity prev = GpsCacheData.getPrev(gps);
47 47  
48   - if(isInsideStation(gps) &&
49   - (prev == null || !isInsideStation(prev) || !prev.getStopNo().equals(gps.getStopNo()))){
50   - inStation(gps, prev); //进站
  48 + if(null == prev)
  49 + return;
  50 +
  51 + //从站外到站内
  52 + if(prev.getInstation() == 0 && gps.getInstation() > 0){
  53 + inStation(gps, prev);
  54 + }
  55 +
  56 + //从站内到另一个站内
  57 + if(prev.getInstation() == 1 && gps.getInstation() == 1
  58 + && !prev.getStopNo().equals(gps.getStopNo())
  59 + && !prev.getStation().getName().equals(gps.getStation().getName()))
  60 + inStation(gps, prev);
  61 +
  62 + //从场内到站内
  63 + if(prev.getInstation() == 2 && gps.getInstation() == 1){
  64 + inStation(gps, prev);
51 65 }
52   - }
53 66  
54   - private boolean isInsideStation(GpsEntity gps){
55   - return gps.getInstation() >= 1;
  67 + //被起点站覆盖的情况下进场
  68 + if(isInPark(gps, prev))
  69 + inStation(gps, prev);
56 70 }
57 71  
58 72 /**
59 73 * 进站
  74 + *
60 75 * @param gps
61 76 * @param prev
62 77 */
63   - private void inStation(GpsEntity gps, GpsEntity prev){
64   - boolean flow=true;
  78 + private void inStation(GpsEntity gps, GpsEntity prev) {
  79 + boolean flow = true;
65 80 //要经过一个中途站才能进
66 81 StationRoute s = GpsCacheData.prevStation(gps);
67 82 List<StationRoute> routes = GeoCacheData.getStationRoute(gps.getLineId(), gps.getUpDown());
68   - if(routes.size() > 3 && null != s && s.getName().equals(gps.getStation().getName())){
  83 + if (gps.getInstation() == 1 && routes.size() > 3
  84 + && null != s && s.getName().equals(gps.getStation().getName())) {
69 85 logger.info("没有进中途站,拒绝进站... -" + gps.getNbbm() + " -time:" + gps.getTimestamp());
70 86 flow = false;
71 87 }
72 88  
73 89  
74 90 ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm());
75   - boolean isEnd=false;
  91 + boolean isEnd = false;
76 92  
77 93 //进终点
78   - if(flow && null != sch && sch.getZdzCode().equals(gps.getStopNo())){
  94 + if (flow && null != sch && sch.getZdzCode().equals(gps.getStopNo())) {
79 95 inEndStation(sch, gps);
80 96 isEnd = true;
81 97 }
... ... @@ -85,16 +101,17 @@ public class InStationProcess {
85 101  
86 102 /**
87 103 * 进班次终点
  104 + *
88 105 * @param gps
89 106 */
90 107 private void inEndStation(ScheduleRealInfo sch, GpsEntity gps) {
91 108 String nbbm = sch.getClZbh();
92 109 //校验进站前置约束
93   - if(!validInPremise(gps))
  110 + if (!validInPremise(gps))
94 111 return;
95 112  
96 113 //实达时间不覆盖
97   - if(StringUtils.isNotEmpty(sch.getZdsjActual()))
  114 + if (StringUtils.isNotEmpty(sch.getZdsjActual()))
98 115 return;
99 116  
100 117 //应用到离站缓冲区设置参数
... ... @@ -110,14 +127,14 @@ public class InStationProcess {
110 127  
111 128 //车辆的下一个班次
112 129 ScheduleRealInfo next = dayOfSchedule.next(sch);
113   - if(next != null){
  130 + if (next != null) {
114 131 dayOfSchedule.addExecPlan(next);
115 132 inStationAndInPark(sch, next);//进站既进场
116 133 }
117 134  
118 135 //路牌的下一个班次,页面显示起点实际到达时间
119 136 ScheduleRealInfo lpNext = dayOfSchedule.nextByLp(sch);
120   - if(lpNext != null){
  137 + if (lpNext != null) {
121 138 lpNext.setQdzArrDatesj(sch.getZdsjActual());
122 139 }
123 140  
... ... @@ -138,33 +155,33 @@ public class InStationProcess {
138 155 DirectivePushQueue.put6002(next, doneSum, "到站@系统");
139 156  
140 157 //套跑 -下发线路切换指令
141   - if(null != next && !next.getXlBm().equals(sch.getXlBm())){
  158 + if (null != next && !next.getXlBm().equals(sch.getXlBm())) {
142 159 gpsStatusManager.changeLine(next.getClZbh(), next.getXlBm(), "套跑@系统");
143 160 }
144 161  
145   - if(null == next && gps.isService())
  162 + if (null == next && gps.isService())
146 163 nonService(sch, "结束@系统");//班次结束
147   - else if(dayOfSchedule.emptyService(next))
  164 + else if (dayOfSchedule.emptyService(next))
148 165 nonService(sch, "空驶@系统");//下一班非营运
149 166 }
150 167  
151 168 /**
152 169 * 校验进站前置约束
  170 + *
153 171 * @param gps
154 172 * @return
155 173 */
156 174 private boolean validInPremise(GpsEntity gps) {
157 175 StationRoute sr = gps.getStation();
158   - if(null == sr || !sr.isPremise())
  176 + if (null == sr || !sr.isPremise())
159 177 return true;
160 178  
161 179 String premiseCode = gps.getPremiseCode();
162 180  
163   - if(StringUtils.isNotEmpty(premiseCode) && premiseCode.equals(gps.getStopNo())){
  181 + if (StringUtils.isNotEmpty(premiseCode) && premiseCode.equals(gps.getStopNo())) {
164 182 logger.info("满足前置进站约束 " + premiseCode);
165 183 return true;
166   - }
167   - else{
  184 + } else {
168 185 logger.info(gps.getNbbm() + " not premiseCode 不满足前置进站约束 " + premiseCode);
169 186 }
170 187 return false;
... ... @@ -172,9 +189,10 @@ public class InStationProcess {
172 189  
173 190 /**
174 191 * 进站既进场
  192 + *
175 193 * @param sch
176 194 */
177   - private void inStationAndInPark(ScheduleRealInfo sch, ScheduleRealInfo next){
  195 + private void inStationAndInPark(ScheduleRealInfo sch, ScheduleRealInfo next) {
178 196 LineConfig config = lineConfigData.get(sch.getXlBm());
179 197 //限定出站既出场的停车场
180 198 String park = config.getTwinsPark();
... ... @@ -191,7 +209,7 @@ public class InStationProcess {
191 209  
192 210 //分班的时候,需要再跳过1个班次
193 211 next = dayOfSchedule.next(next);
194   - if(next != null)
  212 + if (next != null)
195 213 dayOfSchedule.addExecPlan(next);
196 214  
197 215 //进场,切换成非营运状态
... ... @@ -200,27 +218,28 @@ public class InStationProcess {
200 218 }
201 219  
202 220  
203   - private boolean isEmptyMileage(ScheduleRealInfo sch){
204   - return sch.getBcsj()==0 || sch.getJhlcOrig().intValue()==0;
  221 + private boolean isEmptyMileage(ScheduleRealInfo sch) {
  222 + return sch.getBcsj() == 0 || sch.getJhlcOrig().intValue() == 0;
205 223 }
206 224  
207 225  
208 226 /**
209 227 * 切换为非营运状态
  228 + *
210 229 * @param sch
211 230 * @param sender
212 231 */
213   - private void nonService(ScheduleRealInfo sch, String sender){
  232 + private void nonService(ScheduleRealInfo sch, String sender) {
214 233 gpsStatusManager.changeServiceState(sch.getClZbh(), sch.getXlDir(), 1, sender);
215 234 }
216 235  
217   - private void endSch(ScheduleRealInfo sch, Long t){
  236 + private void endSch(ScheduleRealInfo sch, Long t) {
218 237 sch.setFcsjActualAll(t);
219 238 sch.setZdsjActualAll(t);
220 239 }
221 240  
222 241 private void transformUpDown(GpsEntity gps, ScheduleRealInfo sch) {
223   - if(null == sch)
  242 + if (null == sch)
224 243 return;
225 244 byte upDown = Byte.parseByte(sch.getXlDir());
226 245 //gps 切换走向
... ... @@ -233,4 +252,10 @@ public class InStationProcess {
233 252 gps.setStopNo(station.getCode());
234 253 }
235 254 }
  255 +
  256 + private boolean isInPark(GpsEntity gps, GpsEntity prve){
  257 + if(StringUtils.isNotEmpty(gps.getCarparkNo()) && StringUtils.isEmpty(prve.getCarparkNo()))
  258 + return true;
  259 + return false;
  260 + }
236 261 }
... ...
src/main/java/com/bsth/data/gpsdata_v2/handlers/OutStationProcess.java
... ... @@ -39,33 +39,49 @@ public class OutStationProcess {
39 39  
40 40 @Autowired
41 41 GpsStatusManager gpsStatusManager;
  42 + private final static int MAX_BEFORE_TIME = 1000 * 60 * 120;
42 43  
43 44 public void process(GpsEntity gps){
44 45 GpsEntity prev = GpsCacheData.getPrev(gps);
45   - if(gps.getInstation()==0 && prev!=null && isInsideStation(prev)){
46   - outStation(gps); //出站
47   - }
48   - }
49 46  
50   - private boolean isInsideStation(GpsEntity gps){
51   - return gps.getInstation() >= 1;
  47 + if(null == prev)
  48 + return;
  49 +
  50 + //从站内到站外
  51 + if(prev.getInstation() > 0 && gps.getInstation() == 0)
  52 + outStation(gps, prev);
  53 +
  54 + //从站内到另一个站内
  55 + if(prev.getInstation() > 0 && gps.getInstation() > 0
  56 + && !prev.getStopNo().equals(gps.getStopNo()))
  57 + outStation(gps, prev);
  58 +
  59 + //在被起点站覆盖的情况下出场
  60 + if(isOutPark(gps, prev))
  61 + outStation(gps, prev);
52 62 }
53 63  
54 64 /**
55 65 * 出站
56 66 * @param gps
57 67 */
58   - private void outStation(GpsEntity gps) {
  68 + private void outStation(GpsEntity gps, GpsEntity prev) {
59 69 ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm());
60 70  
61 71 //起点发车
62   - if (null != sch && sch.getQdzCode().equals(gps.getStopNo())){
  72 + if (null != sch &&
  73 + (sch.getQdzCode().equals(prev.getStopNo()) || sch.getQdzCode().equals(prev.getCarparkNo()))){
63 74 //发车班次匹配
64 75 if(!signalSchPlanMatcher.outMatch(gps, sch)){
65   - outStation(gps);
  76 + //outStation(gps);
66 77 return;
67 78 }
68 79  
  80 + /*int diff = (int) (sch.getDfsjT() - gps.getTimestamp());
  81 + //首班出场最多提前2小时
  82 + if((dayOfSchedule.isFirstOut(sch) && diff > MAX_BEFORE_TIME) || diff > MAX_BEFORE_TIME / 2)
  83 + return;*/
  84 +
69 85 gps.setPremiseCode(null);//清除前置围栏标记
70 86  
71 87 if(StringUtils.isNotEmpty(sch.getFcsjActual())
... ... @@ -123,6 +139,10 @@ public class OutStationProcess {
123 139 if(Math.abs(t2 - c) < threshold && c - t1 > threshold){
124 140 return true;
125 141 }
  142 +
  143 + if(c - t1 > 1000 * 60 * 60 * 2 && Math.abs(t2 - c) < c - t1){
  144 + return true;
  145 + }
126 146 return false;
127 147 }
128 148  
... ... @@ -165,4 +185,10 @@ public class OutStationProcess {
165 185 sch.setFcsjActualAll(t);
166 186 sch.setZdsjActualAll(t);
167 187 }
  188 +
  189 + private boolean isOutPark(GpsEntity gps, GpsEntity prve){
  190 + if(StringUtils.isNotEmpty(prve.getCarparkNo()) && StringUtils.isEmpty(gps.getCarparkNo()))
  191 + return true;
  192 + return false;
  193 + }
168 194 }
... ...
src/main/java/com/bsth/data/gpsdata_v2/rfid/UploadRfidDataService.java
1 1 package com.bsth.data.gpsdata_v2.rfid;
2 2  
  3 +import com.alibaba.fastjson.JSON;
3 4 import com.bsth.data.gpsdata_v2.rfid.entity.RfidInoutStation;
4 5 import com.bsth.data.gpsdata_v2.rfid.handle.RfidSignalHandle;
  6 +import org.slf4j.Logger;
  7 +import org.slf4j.LoggerFactory;
5 8 import org.springframework.beans.factory.annotation.Autowired;
6 9 import org.springframework.web.bind.annotation.RequestBody;
7 10 import org.springframework.web.bind.annotation.RequestMapping;
... ... @@ -20,8 +23,11 @@ public class UploadRfidDataService {
20 23 @Autowired
21 24 RfidSignalHandle rfidSignalHandle;
22 25  
  26 + Logger logger = LoggerFactory.getLogger(this.getClass());
  27 +
23 28 @RequestMapping("inside")
24 29 public void inside(@RequestBody List<RfidInoutStation> list) {
  30 + logger.info("up rfid: " + JSON.toJSONString(list));
25 31 rfidSignalHandle.handle(list);
26 32 }
27 33 }
... ...
src/main/java/com/bsth/data/gpsdata_v2/utils/GpsDataRecovery.java
... ... @@ -59,7 +59,7 @@ public class GpsDataRecovery implements ApplicationContextAware {
59 59 for (String nbbm : keys) {
60 60 Collections.sort(listMap.get(nbbm), comp);
61 61 threadPool.submit(new RecoveryThread(listMap.get(nbbm), count));
62   - /*if(nbbm.equals("W2H-015"))
  62 + /*if(nbbm.equals("S0L-065"))
63 63 new RecoveryThread(listMap.get(nbbm), count).run();*/
64 64 /*if(lineId.equals("60028"))
65 65 new RecoveryThread(listMap.get(lineId), count).run();*/
... ... @@ -151,6 +151,9 @@ public class GpsDataRecovery implements ApplicationContextAware {
151 151 for (GpsEntity gps : list) {
152 152 try {
153 153  
  154 + /*if(gps.getTimestamp() >= 1511386080000L)
  155 + System.out.println("aaa");*/
  156 +
154 157 gpsStateProcess.process(gps);//状态处理
155 158 stationInsideProcess.process(gps);//场站内外判定
156 159  
... ...
src/main/java/com/bsth/data/gpsdata_v2/utils/SignalSchPlanMatcher.java
... ... @@ -2,12 +2,17 @@ package com.bsth.data.gpsdata_v2.utils;
2 2  
3 3 import com.bsth.data.gpsdata_v2.entity.GpsEntity;
4 4 import com.bsth.data.schedule.DayOfSchedule;
  5 +import com.bsth.data.schedule.ScheduleComparator;
5 6 import com.bsth.entity.realcontrol.ScheduleRealInfo;
  7 +import org.apache.commons.lang3.StringUtils;
6 8 import org.slf4j.Logger;
7 9 import org.slf4j.LoggerFactory;
8 10 import org.springframework.beans.factory.annotation.Autowired;
9 11 import org.springframework.stereotype.Component;
10 12  
  13 +import java.util.Collections;
  14 +import java.util.List;
  15 +
11 16 /**
12 17 * 班次匹配器
13 18 * Created by panzhao on 2016/12/31.
... ... @@ -18,6 +23,8 @@ public class SignalSchPlanMatcher {
18 23 @Autowired
19 24 DayOfSchedule dayOfSchedule;
20 25  
  26 + static ScheduleComparator.DFSJ schComp = new ScheduleComparator.DFSJ();
  27 +
21 28 Logger log = LoggerFactory.getLogger(this.getClass());
22 29  
23 30 /**
... ... @@ -26,12 +33,27 @@ public class SignalSchPlanMatcher {
26 33 * @param sch
27 34 * @return
28 35 */
29   - public void outMatch(GpsEntity gps, ScheduleRealInfo sch){
  36 + public boolean outMatch(GpsEntity gps, ScheduleRealInfo sch){
30 37 long t = gps.getTimestamp();
31 38 if(t < sch.getDfsjT())
32   - return;
  39 + return true;
33 40  
34 41 try{
  42 + //晚于待发时间 半小时 ,匹配一下最佳的班次
  43 + if(t - sch.getDfsjT() > 1000 * 60 * 30){
  44 + ScheduleRealInfo near = searchNearOut(gps);
  45 +
  46 + if(null != near && !near.getId().equals(sch.getId())){
  47 + dayOfSchedule.addExecPlan(near);
  48 + return false;
  49 + }
  50 + }
  51 +
  52 + }catch (Exception e){
  53 + log.error("", e);
  54 + }
  55 + return true;
  56 + /*try{
35 57 //会不会是分班没有完成
36 58 if(sch.getBcType().equals("in") && t - sch.getDfsjT() > 1000 * 60 * 20){
37 59 ScheduleRealInfo fbFirst = dayOfSchedule.nextByBcType(sch, "normal");
... ... @@ -71,10 +93,35 @@ public class SignalSchPlanMatcher {
71 93 if(r / s > 0.7){
72 94 if(dayOfSchedule.addExecPlan(next))
73 95 outMatch(gps, next);
74   - }
  96 + }*/
75 97 }
76 98  
77   - public static int fcSpace(ScheduleRealInfo sch, GpsEntity gps){
78   - return (int) Math.abs((sch.getDfsjT() - gps.getTimestamp()));
  99 + /**
  100 + * 搜索一个离发车信号最近的班次
  101 + * @param gps
  102 + * @return
  103 + */
  104 + private ScheduleRealInfo searchNearOut(GpsEntity gps) {
  105 + List<ScheduleRealInfo> list = dayOfSchedule.findByNbbm(gps.getNbbm());
  106 + //排序
  107 + Collections.sort(list, schComp);
  108 +
  109 + ScheduleRealInfo near = null;
  110 + int diff, minDiff=-1;
  111 + for(ScheduleRealInfo sch : list){
  112 +
  113 + if(StringUtils.isNotEmpty(sch.getFcsjActual()))
  114 + continue;
  115 +
  116 + if(StringUtils.isNotEmpty(sch.getZdsjActual()))
  117 + continue;
  118 +
  119 + diff = (int) Math.abs(gps.getTimestamp() - sch.getDfsjT());
  120 + if(null == near || diff < minDiff){
  121 + near = sch;
  122 + minDiff = diff;
  123 + }
  124 + }
  125 + return near;
79 126 }
80 127 }
... ...
src/main/java/com/bsth/data/msg_queue/DirectivePushQueue.java
... ... @@ -108,15 +108,15 @@ public class DirectivePushQueue implements ApplicationContextAware {
108 108 code = qd.getCode();
109 109  
110 110 if(code.equals("60_02")){
111   - directiveService.send60Dispatch(qd.getSch(), qd.getFinish(), qd.getSender());
  111 + //directiveService.send60Dispatch(qd.getSch(), qd.getFinish(), qd.getSender());
112 112 log.info("directive 60_02 sch id: " + qd.getSch().getId());
113 113 }
114 114 else if(code.equals("60_03")){
115   - directiveService.send60Operation(qd.getNbbm(), qd.getState(), qd.getUpDown(), qd.getSender());
  115 + //directiveService.send60Operation(qd.getNbbm(), qd.getState(), qd.getUpDown(), qd.getSender());
116 116 log.info("directive 60_03 nbbm: " + qd.getNbbm());
117 117 }
118 118 else if(code.equals("64")){
119   - directiveService.lineChange(qd.getNbbm(), qd.getLineCode(), qd.getSender());
  119 + //directiveService.lineChange(qd.getNbbm(), qd.getLineCode(), qd.getSender());
120 120 log.info("directive 64 nbbm: " + qd.getNbbm() + " lineCode: " + qd.getLineCode());
121 121 }
122 122  
... ...
src/main/java/com/bsth/data/schedule/SchAttrCalculator.java
... ... @@ -219,7 +219,7 @@ public class SchAttrCalculator {
219 219 boolean limitPark = StringUtils.isNotEmpty(park);
220 220  
221 221 ScheduleRealInfo sch, prev = null;
222   - for(int i = list.size() - 1; i > 0; i --){
  222 + for(int i = list.size() - 1; i >= 0; i --){
223 223 sch = list.get(i);
224 224  
225 225 //如果是出站既出场,忽略出场班次
... ...