Commit cd23dc4509d5c0c3344e80e2f3d828881a1589d8

Authored by 潘钊
1 parent d54b68ef

update...

src/main/java/com/bsth/data/directive/DirectiveCreator.java
@@ -81,7 +81,7 @@ public class DirectiveCreator { @@ -81,7 +81,7 @@ public class DirectiveCreator {
81 } 81 }
82 82
83 83
84 - public D60 createD60_01(String nbbm, String text, int upDown, int state, Date alarmTime){ 84 + public D60 createD60_02(String nbbm, String text, int upDown, int state, Date alarmTime){
85 SimpleDateFormat sdfMMddHHmm = new SimpleDateFormat("MMddHHmm"); 85 SimpleDateFormat sdfMMddHHmm = new SimpleDateFormat("MMddHHmm");
86 86
87 Long timestamp = System.currentTimeMillis(); 87 Long timestamp = System.currentTimeMillis();
@@ -102,7 +102,7 @@ public class DirectiveCreator { @@ -102,7 +102,7 @@ public class DirectiveCreator {
102 directive.setMsgId(msgId); 102 directive.setMsgId(msgId);
103 // 构造数据 103 // 构造数据
104 data.setDeviceId(deviceId); 104 data.setDeviceId(deviceId);
105 - data.setDispatchInstruct((short) 0x01); 105 + data.setDispatchInstruct((short) 0x02);
106 data.setTimestamp(timestamp); 106 data.setTimestamp(timestamp);
107 data.setCompanyCode(company); 107 data.setCompanyCode(company);
108 data.setMsgId(msgId); 108 data.setMsgId(msgId);
src/main/java/com/bsth/data/gpsdata_v2/handlers/GpsStateProcess.java
@@ -7,6 +7,9 @@ import com.bsth.entity.realcontrol.ScheduleRealInfo; @@ -7,6 +7,9 @@ import com.bsth.entity.realcontrol.ScheduleRealInfo;
7 import org.springframework.beans.factory.annotation.Autowired; 7 import org.springframework.beans.factory.annotation.Autowired;
8 import org.springframework.stereotype.Component; 8 import org.springframework.stereotype.Component;
9 9
  10 +import java.util.concurrent.ConcurrentHashMap;
  11 +import java.util.concurrent.ConcurrentMap;
  12 +
10 /** 13 /**
11 * GPS 状态处理 14 * GPS 状态处理
12 * Created by panzhao on 2017/11/15. 15 * Created by panzhao on 2017/11/15.
@@ -20,6 +23,13 @@ public class GpsStateProcess { @@ -20,6 +23,13 @@ public class GpsStateProcess {
20 @Autowired 23 @Autowired
21 GpsStatusManager gpsStatusManager; 24 GpsStatusManager gpsStatusManager;
22 25
  26 + /**
  27 + * 设置状态差异连续次数
  28 + */
  29 + private static ConcurrentMap<String, Integer> stateDiffMap = new ConcurrentHashMap<>();
  30 +
  31 + private final static int CHANGE_THRESHOLD = 2;
  32 +
23 public void process(GpsEntity gps) { 33 public void process(GpsEntity gps) {
24 //在执行的任务 34 //在执行的任务
25 ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm()); 35 ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm());
@@ -29,16 +39,40 @@ public class GpsStateProcess { @@ -29,16 +39,40 @@ public class GpsStateProcess {
29 39
30 int upDown = Integer.parseInt(sch.getXlDir()); 40 int upDown = Integer.parseInt(sch.getXlDir());
31 int schState = dayOfSchedule.emptyService(sch)?1:0; 41 int schState = dayOfSchedule.emptyService(sch)?1:0;
  42 + String device = gps.getDeviceId();
  43 + /**
  44 + * 网关在进终点的时候,会直接将当前点位状态改变
  45 + * 为避免出现单个点的状态跳动,设置一下切换阈值
  46 + */
  47 + if(gps.getState() != schState || gps.getUpDown() != upDown){
  48 + Integer count = 0;
  49 + if(stateDiffMap.containsKey(device))
  50 + count = stateDiffMap.get(device);
  51 +
  52 + count ++;
32 53
33 - if(gps.getState().intValue() != schState || gps.getUpDown().intValue() != upDown){  
34 - //下发指令纠正车载的 营运状态 和 走向  
35 - gpsStatusManager.changeServiceState(gps.getNbbm(), upDown, schState, "同步@系统"); 54 + if(count >= CHANGE_THRESHOLD){
  55 + //下发指令纠正车载的 营运状态 和 走向
  56 + gpsStatusManager.changeServiceState(gps.getNbbm(), upDown, schState, "同步@系统");
  57 + count = 0;
  58 + }
  59 +
  60 + stateDiffMap.put(device, count);
  61 +
  62 + //记录原始设备状态
  63 + gps.setOrigStateStr(gps.getUpDown() + "_" + gps.getState());
36 } 64 }
  65 + else
  66 + stateDiffMap.put(device, 0);
37 67
38 if (gps.getUpDown() != upDown) { 68 if (gps.getUpDown() != upDown) {
39 gps.setUpDown((byte) upDown);//修正走向 69 gps.setUpDown((byte) upDown);//修正走向
40 } 70 }
41 71
  72 + if(gps.getState() != schState){
  73 + gps.setState(schState);//修正营运状态
  74 + }
  75 +
42 if (!sch.getXlBm().equals(gps.getLineId())) { 76 if (!sch.getXlBm().equals(gps.getLineId())) {
43 //切换车载的 线路编码 77 //切换车载的 线路编码
44 gpsStatusManager.changeLine(gps.getNbbm(), sch.getXlBm(), "同步@系统"); 78 gpsStatusManager.changeLine(gps.getNbbm(), sch.getXlBm(), "同步@系统");
src/main/java/com/bsth/data/gpsdata_v2/handlers/InStationProcess.java
@@ -144,6 +144,8 @@ public class InStationProcess { @@ -144,6 +144,8 @@ public class InStationProcess {
144 dayOfSchedule.addExecPlan(next); 144 dayOfSchedule.addExecPlan(next);
145 inStationAndInPark(sch, next);//进站既进场 145 inStationAndInPark(sch, next);//进站既进场
146 } 146 }
  147 + else
  148 + dayOfSchedule.removeExecPlan(nbbm);
147 149
148 //路牌的下一个班次,页面显示起点实际到达时间 150 //路牌的下一个班次,页面显示起点实际到达时间
149 ScheduleRealInfo lpNext = dayOfSchedule.nextByLp(sch); 151 ScheduleRealInfo lpNext = dayOfSchedule.nextByLp(sch);
@@ -180,10 +182,10 @@ public class InStationProcess { @@ -180,10 +182,10 @@ public class InStationProcess {
180 /** 182 /**
181 * 下一班不是全程班次的时候,下发运营指令 183 * 下一班不是全程班次的时候,下发运营指令
182 * 全程班次时,由网关根据进出起终点,自动切换走向 184 * 全程班次时,由网关根据进出起终点,自动切换走向
183 - */ 185 +
184 if(null != next && !next.getBcType().equals("normal")) 186 if(null != next && !next.getBcType().equals("normal"))
185 DirectivePushQueue.put6003(next, "到站@系统"); 187 DirectivePushQueue.put6003(next, "到站@系统");
186 - 188 + */
187 //下发调度指令 189 //下发调度指令
188 DirectivePushQueue.put6002(next, doneSum, "到站@系统", ""); 190 DirectivePushQueue.put6002(next, doneSum, "到站@系统", "");
189 } 191 }
src/main/java/com/bsth/data/gpsdata_v2/utils/GpsDataUtils.java
@@ -15,6 +15,8 @@ public class GpsDataUtils { @@ -15,6 +15,8 @@ public class GpsDataUtils {
15 15
16 static Logger logger = LoggerFactory.getLogger(GpsDataUtils.class); 16 static Logger logger = LoggerFactory.getLogger(GpsDataUtils.class);
17 17
  18 + private final static long MAX_DIFF = 1000 * 60 * 60 * 24;
  19 +
18 /** 20 /**
19 * 过滤无效的gps点位 21 * 过滤无效的gps点位
20 * 22 *
@@ -24,9 +26,16 @@ public class GpsDataUtils { @@ -24,9 +26,16 @@ public class GpsDataUtils {
24 public static List<GpsEntity> clearInvalid(List<GpsEntity> list) { 26 public static List<GpsEntity> clearInvalid(List<GpsEntity> list) {
25 List<GpsEntity> rs = new ArrayList<>(); 27 List<GpsEntity> rs = new ArrayList<>();
26 28
  29 + long t = System.currentTimeMillis();
27 try { 30 try {
28 GpsEntity prev; 31 GpsEntity prev;
29 for (GpsEntity gps : list) { 32 for (GpsEntity gps : list) {
  33 + if(Math.abs(gps.getTimestamp() - t) > MAX_DIFF){
  34 + //尝试校准GPS时间
  35 + gps.setTimestamp(t + 1);
  36 + gps.setAbnormalStatus("timeError");
  37 + }
  38 +
30 prev = GpsRealData.get(gps.getDeviceId()); 39 prev = GpsRealData.get(gps.getDeviceId());
31 40
32 //不接收过期数据 41 //不接收过期数据
@@ -48,7 +57,7 @@ public class GpsDataUtils { @@ -48,7 +57,7 @@ public class GpsDataUtils {
48 if (rs.size() < list.size()) 57 if (rs.size() < list.size())
49 logger.info("过滤无效的点位 : " + (list.size() - rs.size())); 58 logger.info("过滤无效的点位 : " + (list.size() - rs.size()));
50 } catch (Exception e) { 59 } catch (Exception e) {
51 - logger.error("", e); 60 + logger.error("过滤GPS出现异常", e);
52 rs = list; 61 rs = list;
53 } 62 }
54 return rs; 63 return rs;
src/main/java/com/bsth/data/msg_queue/DirectivePushQueue.java
@@ -24,7 +24,7 @@ public class DirectivePushQueue implements ApplicationContextAware { @@ -24,7 +24,7 @@ public class DirectivePushQueue implements ApplicationContextAware {
24 static ConcurrentLinkedQueue<QueueData_Directive> linkedList; 24 static ConcurrentLinkedQueue<QueueData_Directive> linkedList;
25 static DataPushThread thread; 25 static DataPushThread thread;
26 static DirectiveService directiveService; 26 static DirectiveService directiveService;
27 - static long t; 27 + static long threadT;
28 28
29 /** 29 /**
30 * 下发运营指令6003的最小间隔时间 30 * 下发运营指令6003的最小间隔时间
@@ -34,11 +34,11 @@ public class DirectivePushQueue implements ApplicationContextAware { @@ -34,11 +34,11 @@ public class DirectivePushQueue implements ApplicationContextAware {
34 /** 34 /**
35 * 车辆 ——> 上次下发6003的时间 35 * 车辆 ——> 上次下发6003的时间
36 */ 36 */
37 - static ConcurrentMap<String, Long> lastSend6003Map; 37 + static ConcurrentMap<String, Long> lastSend60TimeMap;
38 38
39 static { 39 static {
40 linkedList = new ConcurrentLinkedQueue<>(); 40 linkedList = new ConcurrentLinkedQueue<>();
41 - lastSend6003Map = new ConcurrentHashMap<>(); 41 + lastSend60TimeMap = new ConcurrentHashMap<>();
42 } 42 }
43 43
44 public static void put6002(ScheduleRealInfo sch, int finish, String sender, String txtPrefix){ 44 public static void put6002(ScheduleRealInfo sch, int finish, String sender, String txtPrefix){
@@ -52,12 +52,13 @@ public class DirectivePushQueue implements ApplicationContextAware { @@ -52,12 +52,13 @@ public class DirectivePushQueue implements ApplicationContextAware {
52 qd6002.setTxtPrefix(txtPrefix); 52 qd6002.setTxtPrefix(txtPrefix);
53 53
54 linkedList.add(qd6002); 54 linkedList.add(qd6002);
  55 + lastSend60TimeMap.put(sch.getClZbh(), System.currentTimeMillis());
55 } 56 }
56 57
57 public static void put6003(String nbbm, int state, int upDown, String sender){ 58 public static void put6003(String nbbm, int state, int upDown, String sender){
58 long t = System.currentTimeMillis(); 59 long t = System.currentTimeMillis();
59 - if(lastSend6003Map.containsKey(nbbm)  
60 - && t - lastSend6003Map.get(nbbm) < MIN_SEND6003_SPACE) 60 + if(lastSend60TimeMap.containsKey(nbbm)
  61 + && t - lastSend60TimeMap.get(nbbm) < MIN_SEND6003_SPACE)
61 return; //最短下发间隔 62 return; //最短下发间隔
62 63
63 QueueData_Directive qd6003 = new QueueData_Directive(); 64 QueueData_Directive qd6003 = new QueueData_Directive();
@@ -68,7 +69,7 @@ public class DirectivePushQueue implements ApplicationContextAware { @@ -68,7 +69,7 @@ public class DirectivePushQueue implements ApplicationContextAware {
68 qd6003.setCode("60_03"); 69 qd6003.setCode("60_03");
69 70
70 linkedList.add(qd6003); 71 linkedList.add(qd6003);
71 - lastSend6003Map.put(nbbm, t); 72 + lastSend60TimeMap.put(nbbm, t);
72 } 73 }
73 74
74 public static void put6003(ScheduleRealInfo sch, String sender){ 75 public static void put6003(ScheduleRealInfo sch, String sender){
@@ -146,7 +147,7 @@ public class DirectivePushQueue implements ApplicationContextAware { @@ -146,7 +147,7 @@ public class DirectivePushQueue implements ApplicationContextAware {
146 sleepFlag = true; 147 sleepFlag = true;
147 } 148 }
148 } 149 }
149 - t = System.currentTimeMillis(); 150 + threadT = System.currentTimeMillis();
150 } 151 }
151 catch(InterruptedException e){ 152 catch(InterruptedException e){
152 log.error("", e); 153 log.error("", e);
src/main/java/com/bsth/service/directive/DirectiveServiceImpl.java
@@ -128,7 +128,7 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;D60, Integer&gt; implemen @@ -128,7 +128,7 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;D60, Integer&gt; implemen
128 text += " (放站到"+sch.getMajorStationName()+"带客)"; 128 text += " (放站到"+sch.getMajorStationName()+"带客)";
129 } 129 }
130 130
131 - //下发0x01指令 调度指令(闹钟有效) 131 + //下发0x02指令 调度指令(闹钟有效)
132 long t = System.currentTimeMillis() + 1000 * 30, 132 long t = System.currentTimeMillis() + 1000 * 30,
133 alarmTime = sch.getDfsjT() < t?t:sch.getDfsjT(); 133 alarmTime = sch.getDfsjT() < t?t:sch.getDfsjT();
134 134
@@ -139,7 +139,7 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;D60, Integer&gt; implemen @@ -139,7 +139,7 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;D60, Integer&gt; implemen
139 int state = 0;//营运状态 139 int state = 0;//营运状态
140 if(dayOfSchedule.emptyService(sch)) 140 if(dayOfSchedule.emptyService(sch))
141 state = 1; 141 state = 1;
142 - d60 = new DirectiveCreator().createD60_01(sch.getClZbh(), text, Integer.parseInt(sch.getXlDir()) 142 + d60 = new DirectiveCreator().createD60_02(sch.getClZbh(), text, Integer.parseInt(sch.getXlDir())
143 , state, new Date(alarmTime)); 143 , state, new Date(alarmTime));
144 144
145 d60.setLineCode(sch.getXlBm()); 145 d60.setLineCode(sch.getXlBm());
src/main/java/com/bsth/service/gps/GpsServiceImpl.java
@@ -5,6 +5,7 @@ import com.bsth.data.BasicData; @@ -5,6 +5,7 @@ import com.bsth.data.BasicData;
5 import com.bsth.data.forecast.entity.ArrivalEntity; 5 import com.bsth.data.forecast.entity.ArrivalEntity;
6 import com.bsth.data.gpsdata_v2.GpsRealData; 6 import com.bsth.data.gpsdata_v2.GpsRealData;
7 import com.bsth.data.gpsdata_v2.cache.GeoCacheData; 7 import com.bsth.data.gpsdata_v2.cache.GeoCacheData;
  8 +import com.bsth.data.gpsdata_v2.cache.GpsCacheData;
8 import com.bsth.data.gpsdata_v2.entity.GpsEntity; 9 import com.bsth.data.gpsdata_v2.entity.GpsEntity;
9 import com.bsth.data.gpsdata_v2.utils.GeoUtils; 10 import com.bsth.data.gpsdata_v2.utils.GeoUtils;
10 import com.bsth.data.pilot80.PilotReport; 11 import com.bsth.data.pilot80.PilotReport;
@@ -492,6 +493,7 @@ public class GpsServiceImpl implements GpsService { @@ -492,6 +493,7 @@ public class GpsServiceImpl implements GpsService {
492 try { 493 try {
493 494
494 gpsRealData.remove(device); 495 gpsRealData.remove(device);
  496 + GpsCacheData.remove(BasicData.deviceId2NbbmMap.get(device));
495 rs.put("status", ResponseCode.SUCCESS); 497 rs.put("status", ResponseCode.SUCCESS);
496 } catch (Exception e) { 498 } catch (Exception e) {
497 rs.put("status", ResponseCode.ERROR); 499 rs.put("status", ResponseCode.ERROR);
src/main/resources/static/real_control_v2/fragments/north/nav/all_devices.html
@@ -36,6 +36,7 @@ @@ -36,6 +36,7 @@
36 <div class="uk-autocomplete uk-form " > 36 <div class="uk-autocomplete uk-form " >
37 <select name="abnormalStatus"> 37 <select name="abnormalStatus">
38 <option value="">全部</option> 38 <option value="">全部</option>
  39 + <option value="timeError">时间戳异常</option>
39 <option value="outBounds">越界</option> 40 <option value="outBounds">越界</option>
40 <option value="overspeed">超速</option> 41 <option value="overspeed">超速</option>
41 <option value="offline">离线</option> 42 <option value="offline">离线</option>
@@ -58,11 +59,11 @@ @@ -58,11 +59,11 @@
58 <th style="width: 14%;">站点</th> 59 <th style="width: 14%;">站点</th>
59 <th style="width: 11%;">车辆</th> 60 <th style="width: 11%;">车辆</th>
60 <th style="width: 11%;">设备号</th> 61 <th style="width: 11%;">设备号</th>
61 - <th style="width: 9%;">走向/营运</th> 62 + <th style="width: 12%;">走向/营运</th>
62 <th style="width: 9%;">程序版本</th> 63 <th style="width: 9%;">程序版本</th>
63 <th>最后GPS时间</th> 64 <th>最后GPS时间</th>
64 - <th style="width: 9%;">状态</th>  
65 - <th style="width: 8%;">来源</th> 65 + <th style="width: 8%;">状态</th>
  66 + <th style="width: 6%;">源</th>
66 </tr> 67 </tr>
67 </thead> 68 </thead>
68 <tbody> 69 <tbody>
@@ -81,7 +82,11 @@ @@ -81,7 +82,11 @@
81 <td>{{gps.stationName}}</td> 82 <td>{{gps.stationName}}</td>
82 <td>{{gps.nbbm}}</td> 83 <td>{{gps.nbbm}}</td>
83 <td>{{gps.deviceId}}</td> 84 <td>{{gps.deviceId}}</td>
84 - <td>{{gps.upDown}}/{{gps.state}}</td> 85 + <td>{{gps.upDown}}/{{gps.state}}
  86 + {{if gps.origStateStr!=null}}
  87 + (<span style="color: #fe6262;">{{gps.origStateStr}}</span>)
  88 + {{/if}}
  89 + </td>
85 <td>{{gps.version}}</td> 90 <td>{{gps.version}}</td>
86 <td>{{gps.timeStr}}</td> 91 <td>{{gps.timeStr}}</td>
87 <td> 92 <td>
@@ -95,18 +100,14 @@ @@ -95,18 +100,14 @@
95 <span class="sm-red">GPS (0,0)</span> 100 <span class="sm-red">GPS (0,0)</span>
96 {{else if gps.abnormalStatus=='offline'}} 101 {{else if gps.abnormalStatus=='offline'}}
97 <span>离线</span> 102 <span>离线</span>
  103 + {{else if gps.abnormalStatus=='timeError'}}
  104 + <span class="sm-red" title="设备时间戳异常,尝试以服务器时间修正">time_ex</span>
98 {{else}} 105 {{else}}
99 ... 106 ...
100 {{/if}} 107 {{/if}}
101 </td> 108 </td>
102 <td> 109 <td>
103 - {{if gps.source==1}}  
104 - <span style="color: #1e1ef5;" title="已切换至新网关">网关</span>  
105 - {{else if gps.source==0}}  
106 - <span style="color: #8e8e8e;" title="转接的数据,无法下发指令">转发</span>  
107 - {{else}}  
108 - <span class="sm-grey">未知</span>  
109 - {{/if}} 110 + <span class="sm-grey">{{gps.source}}</span>
110 </td> 111 </td>
111 </tr> 112 </tr>
112 {{/each}} 113 {{/each}}