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