Commit a15528ca553c9fd0f6bed5b6bceb10d1f8013155
1 parent
5ca38896
update...
Showing
2 changed files
with
63 additions
and
1 deletions
src/main/java/com/bsth/XDApplication.java
| ... | ... | @@ -6,6 +6,7 @@ import com.bsth.data.car_out_info.UpdateDBThread; |
| 6 | 6 | import com.bsth.data.directive.DirectivesPstThread; |
| 7 | 7 | import com.bsth.data.forecast.SampleTimeDataLoader; |
| 8 | 8 | import com.bsth.data.gpsdata_v2.thread.GpsDataLoaderThread; |
| 9 | +import com.bsth.data.gpsdata_v2.thread.OfflineMonitorThread; | |
| 9 | 10 | import com.bsth.data.msg_queue.DirectivePushQueue; |
| 10 | 11 | import com.bsth.data.msg_queue.WebSocketPushQueue; |
| 11 | 12 | import com.bsth.data.schedule.DayOfSchedule; |
| ... | ... | @@ -67,6 +68,9 @@ public class XDApplication implements CommandLineRunner { |
| 67 | 68 | @Autowired |
| 68 | 69 | GpsDataLoaderThread gpsDataLoader; |
| 69 | 70 | |
| 71 | + @Autowired | |
| 72 | + OfflineMonitorThread offlineMonitorThread; | |
| 73 | + | |
| 70 | 74 | private static long timeDiff; |
| 71 | 75 | private static long timeDiffTraffic; |
| 72 | 76 | |
| ... | ... | @@ -134,7 +138,7 @@ public class XDApplication implements CommandLineRunner { |
| 134 | 138 | sexec.scheduleWithFixedDelay(scheduleLateThread, 70, 30, TimeUnit.SECONDS);//检查班次误点 |
| 135 | 139 | sexec.scheduleWithFixedDelay(gpsDataLoader, 100, 2, TimeUnit.SECONDS);//抓取GPS数据 |
| 136 | 140 | |
| 137 | - //sexec.scheduleWithFixedDelay(offlineMonitorThread, 120, 60, TimeUnit.SECONDS);//GPS设备掉离线 | |
| 141 | + sexec.scheduleWithFixedDelay(offlineMonitorThread, 120, 60, TimeUnit.SECONDS);//GPS设备掉离线 | |
| 138 | 142 | sexec.scheduleWithFixedDelay(schedulePstThread, 120, 10, TimeUnit.SECONDS);//班次延迟入库线程 |
| 139 | 143 | sexec.scheduleWithFixedDelay(seiPstThread, 160, 60, TimeUnit.SECONDS);//班次修正日志入库 |
| 140 | 144 | sexec.scheduleWithFixedDelay(directivesPstThread, 180, 120, TimeUnit.SECONDS);//调度指令延迟入库 | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/thread/OfflineMonitorThread.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata_v2.thread; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata_v2.GpsRealData; | |
| 4 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 5 | +import com.bsth.websocket.handler.SendUtils; | |
| 6 | +import org.slf4j.Logger; | |
| 7 | +import org.slf4j.LoggerFactory; | |
| 8 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 9 | +import org.springframework.stereotype.Component; | |
| 10 | + | |
| 11 | +import java.util.Collection; | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * GPS掉离线监控 | |
| 15 | + * Created by panzhao on 2017/1/11. | |
| 16 | + */ | |
| 17 | +@Component | |
| 18 | +public class OfflineMonitorThread extends Thread{ | |
| 19 | + | |
| 20 | + @Autowired | |
| 21 | + GpsRealData gpsRealData; | |
| 22 | + | |
| 23 | + //掉线阈值 | |
| 24 | + private final static int LOSE_TIME = 1000 * 60 * 10; | |
| 25 | + | |
| 26 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 27 | + | |
| 28 | + @Autowired | |
| 29 | + SendUtils sendUtils; | |
| 30 | + | |
| 31 | + //无任务时 离线阈值 | |
| 32 | + //private final static int OFFLINE_TIME = 1000 * 60 * 10; | |
| 33 | + | |
| 34 | + @Override | |
| 35 | + public void run() { | |
| 36 | + try{ | |
| 37 | + long t = System.currentTimeMillis(); | |
| 38 | + Collection<GpsEntity> list = gpsRealData.all(); | |
| 39 | + | |
| 40 | + String state; | |
| 41 | + for(GpsEntity gps : list){ | |
| 42 | + state = gps.getAbnormalStatus(); | |
| 43 | + | |
| 44 | + if(state != null && state.equals("offline")) | |
| 45 | + continue; | |
| 46 | + | |
| 47 | + if (t - gps.getTimestamp() > LOSE_TIME){ | |
| 48 | + gps.offline(); | |
| 49 | + | |
| 50 | + //通知页面有设备掉线 | |
| 51 | + sendUtils.deviceOffline(gps); | |
| 52 | + } | |
| 53 | + } | |
| 54 | + }catch (Exception e){ | |
| 55 | + logger.error("", e); | |
| 56 | + } | |
| 57 | + } | |
| 58 | +} | ... | ... |