Commit 5308e80a7a546560378d0a60e862a345bcc395c3
1 parent
ac4452a2
update...
Showing
10 changed files
with
228 additions
and
183 deletions
src/main/java/com/bsth/ServiceStateTest.java deleted
100644 → 0
| 1 | -package com.bsth; | |
| 2 | - | |
| 3 | -public class ServiceStateTest { | |
| 4 | - | |
| 5 | - public static void main(String[] args) { | |
| 6 | - System.out.println("运营状态:" + getService(603979776)); | |
| 7 | - System.out.println("上下行:" + getUpOrDown(603979776)); | |
| 8 | - } | |
| 9 | - | |
| 10 | - /** | |
| 11 | - * 获取运营状态 | |
| 12 | - * | |
| 13 | - * @return -1无效 0运营 1未运营 | |
| 14 | - */ | |
| 15 | - public static byte getService(long serviceState) { | |
| 16 | - if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000) | |
| 17 | - return -1; | |
| 18 | - return (byte) (((serviceState & 0x02000000) == 0x02000000) ? 1 : 0); | |
| 19 | - } | |
| 20 | - | |
| 21 | - /** | |
| 22 | - * 王通 2016/6/29 9:23:24 获取车辆线路上下行 | |
| 23 | - * | |
| 24 | - * @return -1无效 0上行 1下行 | |
| 25 | - */ | |
| 26 | - public static byte getUpOrDown(long serviceState) { | |
| 27 | - if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000 | |
| 28 | - || (serviceState & 0x01000000) == 0x01000000 || (serviceState & 0x08000000) == 0x08000000) | |
| 29 | - return -1; | |
| 30 | - return (byte) (((serviceState & 0x10000000) == 0x10000000) ? 1 : 0); | |
| 31 | - } | |
| 32 | -} |
src/main/java/com/bsth/XDApplication.java
0 → 100644
| 1 | +package com.bsth; | |
| 2 | + | |
| 3 | +import com.bsth.data.BasicData; | |
| 4 | +import com.bsth.data.ThreadMonotor; | |
| 5 | +import com.bsth.data.car_out_info.UpdateDBThread; | |
| 6 | +import com.bsth.data.directive.DirectivesPstThread; | |
| 7 | +import com.bsth.data.gpsdata.thread.GpsDataLoaderThread; | |
| 8 | +import com.bsth.data.gpsdata.thread.OfflineMonitorThread; | |
| 9 | +import com.bsth.data.schedule.late_adjust.ScheduleLateThread; | |
| 10 | +import com.bsth.data.schedule.thread.CalcOilThread; | |
| 11 | +import com.bsth.data.schedule.thread.SchedulePstThread; | |
| 12 | +import com.bsth.data.schedule.thread.ScheduleRefreshThread; | |
| 13 | +import com.bsth.data.schedule.thread.SubmitToTrafficManage; | |
| 14 | +import com.bsth.util.DateUtils; | |
| 15 | +import com.bsth.util.Tools; | |
| 16 | +import org.slf4j.Logger; | |
| 17 | +import org.slf4j.LoggerFactory; | |
| 18 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 19 | +import org.springframework.boot.CommandLineRunner; | |
| 20 | +import org.springframework.stereotype.Component; | |
| 21 | + | |
| 22 | +import java.util.concurrent.ScheduledExecutorService; | |
| 23 | +import java.util.concurrent.TimeUnit; | |
| 24 | + | |
| 25 | +/** | |
| 26 | + * 线调大部分服务都在这里启动 | |
| 27 | + * Created by panzhao on 2017/5/14. | |
| 28 | + */ | |
| 29 | +@Component | |
| 30 | +public class XDApplication implements CommandLineRunner { | |
| 31 | + | |
| 32 | + Logger log = LoggerFactory.getLogger(this.getClass()); | |
| 33 | + | |
| 34 | + @Autowired | |
| 35 | + BasicData.BasicDataLoader basicDataLoader; | |
| 36 | + @Autowired | |
| 37 | + UpdateDBThread fcxxUpdateThread; | |
| 38 | + @Autowired | |
| 39 | + GpsDataLoaderThread gpsDataLoader; | |
| 40 | + @Autowired | |
| 41 | + OfflineMonitorThread offlineMonitorThread; | |
| 42 | + @Autowired | |
| 43 | + ScheduleRefreshThread scheduleRefreshThread; | |
| 44 | + @Autowired | |
| 45 | + SchedulePstThread schedulePstThread; | |
| 46 | + @Autowired | |
| 47 | + ScheduleLateThread scheduleLateThread; | |
| 48 | + @Autowired | |
| 49 | + SubmitToTrafficManage submitToTrafficManage; | |
| 50 | + @Autowired | |
| 51 | + CalcOilThread calcOilThread; | |
| 52 | + @Autowired | |
| 53 | + DirectivesPstThread directivesPstThread; | |
| 54 | + @Autowired | |
| 55 | + ThreadMonotor threadMonotor; | |
| 56 | + | |
| 57 | + private static long timeDiff; | |
| 58 | + | |
| 59 | + static { | |
| 60 | + timeDiff = (DateUtils.getTimestamp() + 1000 * 60 * 140) - System.currentTimeMillis(); | |
| 61 | + if (timeDiff < 0) | |
| 62 | + timeDiff += (1000 * 60 * 60 * 24); | |
| 63 | + } | |
| 64 | + | |
| 65 | + @Override | |
| 66 | + public void run(String... strings) throws Exception { | |
| 67 | + try { | |
| 68 | + Tools tools = new Tools("application.properties"); | |
| 69 | + String environment = tools.getValue("spring.profiles.active"); | |
| 70 | + //预先加载基础的对照数据 | |
| 71 | + basicDataLoader.loadAllData(); | |
| 72 | + switch (environment){ | |
| 73 | + case "dev": | |
| 74 | + devInit(); | |
| 75 | + break; | |
| 76 | + case "prod": | |
| 77 | + prodInit(); | |
| 78 | + break; | |
| 79 | + } | |
| 80 | + }catch (Exception e){ | |
| 81 | + log.error("线调后台启动出现异常!!", e); | |
| 82 | + System.exit(1); | |
| 83 | + } | |
| 84 | + } | |
| 85 | + | |
| 86 | + public void devInit(){ | |
| 87 | + ScheduledExecutorService sexec = Application.mainServices; | |
| 88 | + //抓取GPS数据 | |
| 89 | + //sexec.scheduleWithFixedDelay(gpsDataLoader, 30, 2, TimeUnit.SECONDS); | |
| 90 | + //实际排班更新线程 | |
| 91 | + //sexec.scheduleWithFixedDelay(scheduleRefreshThread, 15, 240, TimeUnit.SECONDS); | |
| 92 | + } | |
| 93 | + | |
| 94 | + public void prodInit(){ | |
| 95 | + ScheduledExecutorService sexec = Application.mainServices; | |
| 96 | + //发车信息 | |
| 97 | + sexec.scheduleWithFixedDelay(fcxxUpdateThread, 60, 40, TimeUnit.SECONDS); | |
| 98 | + //抓取GPS数据 | |
| 99 | + sexec.scheduleWithFixedDelay(gpsDataLoader, 30, 2, TimeUnit.SECONDS); | |
| 100 | + //检查设备掉离线 | |
| 101 | + sexec.scheduleWithFixedDelay(offlineMonitorThread, 120, 60, TimeUnit.SECONDS); | |
| 102 | + //实际排班更新线程 | |
| 103 | + sexec.scheduleWithFixedDelay(scheduleRefreshThread, 15, 240, TimeUnit.SECONDS); | |
| 104 | + //实际排班延迟入库线程 | |
| 105 | + sexec.scheduleWithFixedDelay(schedulePstThread, 60, 30, TimeUnit.SECONDS); | |
| 106 | + //检查班次误点 | |
| 107 | + sexec.scheduleWithFixedDelay(scheduleLateThread, 60, 30, TimeUnit.SECONDS); | |
| 108 | + //调度指令延迟入库 | |
| 109 | + sexec.scheduleWithFixedDelay(directivesPstThread, 180, 180, TimeUnit.SECONDS); | |
| 110 | + | |
| 111 | + //运管处静态数据提交 | |
| 112 | + log.info(timeDiff / 1000 / 60 + "分钟之后提交到运管处"); | |
| 113 | + sexec.scheduleAtFixedRate(submitToTrafficManage, timeDiff / 1000, 60 * 60 * 24, TimeUnit.SECONDS); | |
| 114 | + //计算油、公里加注 | |
| 115 | + sexec.scheduleAtFixedRate(calcOilThread, timeDiff / 1000, 60 * 60 * 24, TimeUnit.SECONDS); | |
| 116 | + | |
| 117 | + | |
| 118 | + //线程监听(防止重要的线程阻塞、异常结束。以及部分主备切换工作) | |
| 119 | + sexec.scheduleWithFixedDelay(threadMonotor, 120, 60, TimeUnit.SECONDS); | |
| 120 | + } | |
| 121 | +} | ... | ... |
src/main/java/com/bsth/data/BasicData.java
src/main/java/com/bsth/data/car_out_info/CarOutInfo.java deleted
100644 → 0
| 1 | -package com.bsth.data.car_out_info; | |
| 2 | - | |
| 3 | -import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 4 | - | |
| 5 | -import java.util.List; | |
| 6 | - | |
| 7 | -/** | |
| 8 | - * Created by panzhao on 2017/5/7. | |
| 9 | - */ | |
| 10 | -public interface CarOutInfo { | |
| 11 | - | |
| 12 | - void updateAll(); | |
| 13 | - | |
| 14 | - void update(String lineCode); | |
| 15 | - | |
| 16 | - void update(List<ScheduleRealInfo> list) ; | |
| 17 | -} |
src/main/java/com/bsth/data/car_out_info/CarOutInfoHandler.java
| ... | ... | @@ -9,15 +9,12 @@ import org.apache.commons.lang3.StringUtils; |
| 9 | 9 | import org.slf4j.Logger; |
| 10 | 10 | import org.slf4j.LoggerFactory; |
| 11 | 11 | import org.springframework.beans.factory.annotation.Autowired; |
| 12 | -import org.springframework.boot.CommandLineRunner; | |
| 13 | 12 | import org.springframework.jdbc.core.BatchPreparedStatementSetter; |
| 14 | 13 | import org.springframework.jdbc.core.JdbcTemplate; |
| 15 | 14 | import org.springframework.jdbc.datasource.DataSourceTransactionManager; |
| 16 | 15 | import org.springframework.stereotype.Component; |
| 17 | -import org.springframework.stereotype.Service; | |
| 18 | 16 | import org.springframework.transaction.TransactionDefinition; |
| 19 | 17 | import org.springframework.transaction.TransactionStatus; |
| 20 | -import org.springframework.transaction.annotation.Transactional; | |
| 21 | 18 | import org.springframework.transaction.support.DefaultTransactionDefinition; |
| 22 | 19 | |
| 23 | 20 | import java.sql.PreparedStatement; |
| ... | ... | @@ -28,14 +25,23 @@ import java.util.*; |
| 28 | 25 | * 发车信息表处理程序 |
| 29 | 26 | * Created by panzhao on 2017/5/5. |
| 30 | 27 | */ |
| 31 | -@Service | |
| 32 | -public class CarOutInfoHandler implements CommandLineRunner, CarOutInfo { | |
| 28 | +@Component | |
| 29 | +public class CarOutInfoHandler { | |
| 33 | 30 | |
| 34 | 31 | @Autowired |
| 35 | 32 | DayOfSchedule dayOfSchedule; |
| 36 | 33 | |
| 37 | 34 | //班次类型对照表 |
| 38 | - Map<String, String> bcTypeMap; | |
| 35 | + static Map<String, String> bcTypeMap; | |
| 36 | + | |
| 37 | + static{ | |
| 38 | + bcTypeMap = new HashMap<>(); | |
| 39 | + bcTypeMap.put("normal", "正常班次"); | |
| 40 | + bcTypeMap.put("region", "区间"); | |
| 41 | + bcTypeMap.put("venting", "直放"); | |
| 42 | + bcTypeMap.put("major", "放站"); | |
| 43 | + bcTypeMap.put("ldks", "两点间空驶"); | |
| 44 | + } | |
| 39 | 45 | |
| 40 | 46 | private static ScheduleComparator.FCSJ schFCSJComparator = new ScheduleComparator.FCSJ(); |
| 41 | 47 | |
| ... | ... | @@ -47,7 +53,6 @@ public class CarOutInfoHandler implements CommandLineRunner, CarOutInfo { |
| 47 | 53 | /** |
| 48 | 54 | * 全量更新发车信息表 |
| 49 | 55 | */ |
| 50 | - @Override | |
| 51 | 56 | public void updateAll() { |
| 52 | 57 | Set<String> ks = BasicData.lineCode2NameMap.keySet(); |
| 53 | 58 | for (String lineCode : ks) { |
| ... | ... | @@ -55,7 +60,6 @@ public class CarOutInfoHandler implements CommandLineRunner, CarOutInfo { |
| 55 | 60 | } |
| 56 | 61 | } |
| 57 | 62 | |
| 58 | - @Override | |
| 59 | 63 | public void update(String lineCode) { |
| 60 | 64 | try { |
| 61 | 65 | ArrayListMultimap<String, ScheduleRealInfo> lpScheduleMap = dayOfSchedule.getLpScheduleMap(); |
| ... | ... | @@ -75,8 +79,6 @@ public class CarOutInfoHandler implements CommandLineRunner, CarOutInfo { |
| 75 | 79 | } |
| 76 | 80 | } |
| 77 | 81 | |
| 78 | - @Transactional | |
| 79 | - @Override | |
| 80 | 82 | public void update(List<ScheduleRealInfo> list) { |
| 81 | 83 | if (list.size() == 0) |
| 82 | 84 | return; |
| ... | ... | @@ -194,30 +196,4 @@ public class CarOutInfoHandler implements CommandLineRunner, CarOutInfo { |
| 194 | 196 | } |
| 195 | 197 | return array; |
| 196 | 198 | } |
| 197 | - | |
| 198 | - @Autowired | |
| 199 | - UpdateInfoThread updateInfoThread; | |
| 200 | - | |
| 201 | - @Override | |
| 202 | - public void run(String... strings) throws Exception { | |
| 203 | - bcTypeMap = new HashMap<>(); | |
| 204 | - bcTypeMap.put("normal", "正常班次"); | |
| 205 | - bcTypeMap.put("region", "区间"); | |
| 206 | - bcTypeMap.put("venting", "直放"); | |
| 207 | - bcTypeMap.put("major", "放站"); | |
| 208 | - bcTypeMap.put("ldks", "两点间空驶"); | |
| 209 | - //Application.mainServices.scheduleWithFixedDelay(updateInfoThread, 60, 40, TimeUnit.SECONDS); | |
| 210 | - } | |
| 211 | - | |
| 212 | - @Component | |
| 213 | - private static class UpdateInfoThread extends Thread { | |
| 214 | - | |
| 215 | - @Autowired | |
| 216 | - CarOutInfo carOutInfoHandler; | |
| 217 | - | |
| 218 | - @Override | |
| 219 | - public void run() { | |
| 220 | - carOutInfoHandler.updateAll(); | |
| 221 | - } | |
| 222 | - } | |
| 223 | 199 | } | ... | ... |
src/main/java/com/bsth/data/car_out_info/UpdateDBThread.java
0 → 100644
| 1 | +package com.bsth.data.car_out_info; | |
| 2 | + | |
| 3 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 4 | +import org.springframework.stereotype.Component; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * 数据库发车信息表更新线程 | |
| 8 | + * Created by panzhao on 2017/5/14. | |
| 9 | + */ | |
| 10 | +@Component | |
| 11 | +public class UpdateDBThread extends Thread{ | |
| 12 | + | |
| 13 | + @Autowired | |
| 14 | + CarOutInfoHandler carOutInfoHandler; | |
| 15 | + | |
| 16 | + @Override | |
| 17 | + public void run() { | |
| 18 | + carOutInfoHandler.updateAll(); | |
| 19 | + } | |
| 20 | +} | ... | ... |
src/main/java/com/bsth/data/forecast/ForecastRealServer.java
| ... | ... | @@ -47,7 +47,7 @@ public class ForecastRealServer implements CommandLineRunner { |
| 47 | 47 | |
| 48 | 48 | //车辆 ——> 预测终点时间 |
| 49 | 49 | //static Map<String, Float> forecastMap = new HashMap<>(); |
| 50 | - //线路_上下行 ——> 封装耗时数据的路由链 | |
| 50 | + //线路_上下行 ——> 耗时数据的路由链 | |
| 51 | 51 | public static ArrayListMultimap<String, SimpleRoute> lineSampleMap; |
| 52 | 52 | //车辆 ——> 预测结果 |
| 53 | 53 | public static Map<String, ForecastResult> forecastMap; | ... | ... |
src/main/java/com/bsth/data/gpsdata/GpsRealData.java
| ... | ... | @@ -2,8 +2,6 @@ package com.bsth.data.gpsdata; |
| 2 | 2 | |
| 3 | 3 | import com.bsth.data.BasicData; |
| 4 | 4 | import com.bsth.data.forecast.ForecastRealServer; |
| 5 | -import com.bsth.data.gpsdata.thread.GpsDataLoaderThread; | |
| 6 | -import com.bsth.data.gpsdata.thread.OfflineMonitorThread; | |
| 7 | 5 | import com.bsth.data.schedule.DayOfSchedule; |
| 8 | 6 | import com.bsth.entity.realcontrol.ScheduleRealInfo; |
| 9 | 7 | import com.google.common.collect.TreeMultimap; |
| ... | ... | @@ -11,7 +9,6 @@ import org.apache.commons.lang3.StringUtils; |
| 11 | 9 | import org.slf4j.Logger; |
| 12 | 10 | import org.slf4j.LoggerFactory; |
| 13 | 11 | import org.springframework.beans.factory.annotation.Autowired; |
| 14 | -import org.springframework.boot.CommandLineRunner; | |
| 15 | 12 | import org.springframework.stereotype.Component; |
| 16 | 13 | |
| 17 | 14 | import java.util.*; |
| ... | ... | @@ -25,7 +22,7 @@ import java.util.concurrent.ConcurrentMap; |
| 25 | 22 | * @date 2016年8月12日 下午2:04:41 |
| 26 | 23 | */ |
| 27 | 24 | @Component |
| 28 | -public class GpsRealData implements CommandLineRunner { | |
| 25 | +public class GpsRealData { | |
| 29 | 26 | |
| 30 | 27 | static Logger logger = LoggerFactory.getLogger(GpsRealData.class); |
| 31 | 28 | |
| ... | ... | @@ -35,12 +32,6 @@ public class GpsRealData implements CommandLineRunner { |
| 35 | 32 | private static TreeMultimap<String, String> lineCode2Devices; |
| 36 | 33 | |
| 37 | 34 | @Autowired |
| 38 | - GpsDataLoaderThread gpsDataLoader; | |
| 39 | - | |
| 40 | - @Autowired | |
| 41 | - OfflineMonitorThread offlineMonitorThread; | |
| 42 | - | |
| 43 | - @Autowired | |
| 44 | 35 | DayOfSchedule dayOfSchedule; |
| 45 | 36 | |
| 46 | 37 | @Autowired |
| ... | ... | @@ -54,15 +45,6 @@ public class GpsRealData implements CommandLineRunner { |
| 54 | 45 | lineCode2Devices = TreeMultimap.create(); |
| 55 | 46 | } |
| 56 | 47 | |
| 57 | - @Override | |
| 58 | - public void run(String... arg0) throws Exception { | |
| 59 | - logger.info("gpsDataLoader,30,2"); | |
| 60 | - //http形式获取GPS数据 | |
| 61 | - //Application.mainServices.scheduleWithFixedDelay(gpsDataLoader, 30, 2, TimeUnit.SECONDS); | |
| 62 | - //定时扫描掉离线 | |
| 63 | - //Application.mainServices.scheduleWithFixedDelay(offlineMonitorThread, 120, 60, TimeUnit.SECONDS); | |
| 64 | - } | |
| 65 | - | |
| 66 | 48 | |
| 67 | 49 | public void put(GpsEntity gps) { |
| 68 | 50 | String device = gps.getDeviceId(); | ... | ... |
src/main/java/com/bsth/data/gpsdata/thread/GpsDataLoaderThread.java
| ... | ... | @@ -6,7 +6,6 @@ import com.bsth.data.BasicData; |
| 6 | 6 | import com.bsth.data.gpsdata.GpsEntity; |
| 7 | 7 | import com.bsth.data.gpsdata.GpsRealData; |
| 8 | 8 | import com.bsth.data.gpsdata.arrival.GpsRealAnalyse; |
| 9 | -import com.bsth.data.gpsdata.recovery.GpsDataRecovery; | |
| 10 | 9 | import com.bsth.util.ConfigUtil; |
| 11 | 10 | import org.apache.commons.lang3.StringUtils; |
| 12 | 11 | import org.apache.http.HttpEntity; |
| ... | ... | @@ -38,10 +37,16 @@ public class GpsDataLoaderThread extends Thread { |
| 38 | 37 | */ |
| 39 | 38 | public GpsDataLoaderThread() { |
| 40 | 39 | url = ConfigUtil.get("http.gps.real.url"); |
| 40 | + clientUrl = ConfigUtil.get("http.gps.real.cache.url"); | |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | // 网关数据接口地址 |
| 44 | 44 | private static String url; |
| 45 | + // GPS客户端内存数据接口 | |
| 46 | + private static String clientUrl; | |
| 47 | + | |
| 48 | + //0:从客户端内存获取 -1:从网关获取 | |
| 49 | + private static int flag = 0; | |
| 45 | 50 | |
| 46 | 51 | @Autowired |
| 47 | 52 | GpsRealData gpsRealData; |
| ... | ... | @@ -52,17 +57,20 @@ public class GpsDataLoaderThread extends Thread { |
| 52 | 57 | @Override |
| 53 | 58 | public void run() { |
| 54 | 59 | try { |
| 55 | - //如果正在恢复数据 | |
| 56 | - if (GpsDataRecovery.run) | |
| 57 | - return; | |
| 58 | - | |
| 59 | - load(); | |
| 60 | + if(flag == 0) | |
| 61 | + load(); | |
| 62 | + else if(flag == -1) | |
| 63 | + loadByGateway(); | |
| 60 | 64 | } catch (Exception e) { |
| 61 | 65 | logger.error("", e); |
| 62 | 66 | } |
| 63 | 67 | } |
| 64 | 68 | |
| 65 | - public void load() throws Exception { | |
| 69 | + /** | |
| 70 | + * 从网关获取实时GPS数据 | |
| 71 | + * @throws Exception | |
| 72 | + */ | |
| 73 | + public void loadByGateway() throws Exception { | |
| 66 | 74 | List<GpsEntity> list = null; |
| 67 | 75 | List<GpsEntity> updateList = new ArrayList<>(); |
| 68 | 76 | CloseableHttpClient httpClient = null; |
| ... | ... | @@ -72,8 +80,8 @@ public class GpsDataLoaderThread extends Thread { |
| 72 | 80 | HttpGet get = new HttpGet(url); |
| 73 | 81 | //超时时间 |
| 74 | 82 | RequestConfig requestConfig = RequestConfig.custom() |
| 75 | - .setConnectTimeout(2000).setConnectionRequestTimeout(1000) | |
| 76 | - .setSocketTimeout(2000).build(); | |
| 83 | + .setConnectTimeout(1500).setConnectionRequestTimeout(1000) | |
| 84 | + .setSocketTimeout(1500).build(); | |
| 77 | 85 | get.setConfig(requestConfig); |
| 78 | 86 | |
| 79 | 87 | response = httpClient.execute(get); |
| ... | ... | @@ -128,4 +136,59 @@ public class GpsDataLoaderThread extends Thread { |
| 128 | 136 | response.close(); |
| 129 | 137 | } |
| 130 | 138 | } |
| 139 | + | |
| 140 | + /** | |
| 141 | + * 从客户端内存获取GPS数据 | |
| 142 | + */ | |
| 143 | + public void load() throws Exception{ | |
| 144 | + List<GpsEntity> list = null; | |
| 145 | + CloseableHttpClient httpClient = null; | |
| 146 | + CloseableHttpResponse response = null; | |
| 147 | + | |
| 148 | + try { | |
| 149 | + httpClient = HttpClients.createDefault(); | |
| 150 | + HttpGet get = new HttpGet(url); | |
| 151 | + //超时时间 | |
| 152 | + RequestConfig requestConfig = RequestConfig.custom() | |
| 153 | + .setConnectTimeout(2000).setConnectionRequestTimeout(1000) | |
| 154 | + .setSocketTimeout(2000).build(); | |
| 155 | + get.setConfig(requestConfig); | |
| 156 | + | |
| 157 | + response = httpClient.execute(get); | |
| 158 | + | |
| 159 | + HttpEntity entity = response.getEntity(); | |
| 160 | + if (null != entity) { | |
| 161 | + BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent())); | |
| 162 | + StringBuffer stringBuffer = new StringBuffer(); | |
| 163 | + String str = ""; | |
| 164 | + while ((str = br.readLine()) != null) | |
| 165 | + stringBuffer.append(str); | |
| 166 | + | |
| 167 | + JSONObject jsonObj = JSON.parseObject(stringBuffer.toString()); | |
| 168 | + | |
| 169 | + if (jsonObj != null) | |
| 170 | + list = JSON.parseArray(jsonObj.getString("data"), GpsEntity.class); | |
| 171 | + | |
| 172 | + String nbbm; | |
| 173 | + for (GpsEntity gps : list) { | |
| 174 | + | |
| 175 | + nbbm = BasicData.deviceId2NbbmMap.get(gps.getDeviceId()); | |
| 176 | + if (StringUtils.isBlank(nbbm)) | |
| 177 | + gps.setIncomplete(true);//标记为异常数据 | |
| 178 | + else | |
| 179 | + gps.setNbbm(nbbm); | |
| 180 | + } | |
| 181 | + //分析数据 | |
| 182 | + gpsRealAnalyse.analyse(list); | |
| 183 | + } else | |
| 184 | + logger.error("client gps result is null"); | |
| 185 | + } catch (Exception e) { | |
| 186 | + logger.error("", e); | |
| 187 | + } finally { | |
| 188 | + if (null != httpClient) | |
| 189 | + httpClient.close(); | |
| 190 | + if (null != response) | |
| 191 | + response.close(); | |
| 192 | + } | |
| 193 | + } | |
| 131 | 194 | } |
| 132 | 195 | \ No newline at end of file | ... | ... |
src/main/java/com/bsth/data/schedule/DayOfSchedule.java
| ... | ... | @@ -2,20 +2,11 @@ package com.bsth.data.schedule; |
| 2 | 2 | |
| 3 | 3 | import com.alibaba.fastjson.JSON; |
| 4 | 4 | import com.alibaba.fastjson.JSONArray; |
| 5 | -import com.bsth.Application; | |
| 6 | 5 | import com.bsth.common.Constants; |
| 7 | 6 | import com.bsth.common.ResponseCode; |
| 8 | -import com.bsth.data.BasicData; | |
| 9 | 7 | import com.bsth.data.LineConfigData; |
| 10 | -import com.bsth.data.ThreadMonotor; | |
| 11 | -import com.bsth.data.directive.DirectivesPstThread; | |
| 12 | 8 | import com.bsth.data.gpsdata.GpsRealData; |
| 13 | 9 | import com.bsth.data.gpsdata.recovery.GpsDataRecovery; |
| 14 | -import com.bsth.data.schedule.late_adjust.ScheduleLateThread; | |
| 15 | -import com.bsth.data.schedule.thread.CalcOilThread; | |
| 16 | -import com.bsth.data.schedule.thread.SchedulePstThread; | |
| 17 | -import com.bsth.data.schedule.thread.ScheduleRefreshThread; | |
| 18 | -import com.bsth.data.schedule.thread.SubmitToTrafficManage; | |
| 19 | 10 | import com.bsth.entity.realcontrol.LineConfig; |
| 20 | 11 | import com.bsth.entity.realcontrol.ScheduleRealInfo; |
| 21 | 12 | import com.bsth.entity.schedule.SchedulePlanInfo; |
| ... | ... | @@ -33,8 +24,6 @@ import org.joda.time.format.DateTimeFormatter; |
| 33 | 24 | import org.slf4j.Logger; |
| 34 | 25 | import org.slf4j.LoggerFactory; |
| 35 | 26 | import org.springframework.beans.factory.annotation.Autowired; |
| 36 | -import org.springframework.boot.CommandLineRunner; | |
| 37 | -import org.springframework.core.annotation.Order; | |
| 38 | 27 | import org.springframework.dao.DataIntegrityViolationException; |
| 39 | 28 | import org.springframework.jdbc.core.JdbcTemplate; |
| 40 | 29 | import org.springframework.stereotype.Component; |
| ... | ... | @@ -42,7 +31,6 @@ import org.springframework.stereotype.Component; |
| 42 | 31 | import java.text.ParseException; |
| 43 | 32 | import java.text.SimpleDateFormat; |
| 44 | 33 | import java.util.*; |
| 45 | -import java.util.concurrent.TimeUnit; | |
| 46 | 34 | |
| 47 | 35 | /** |
| 48 | 36 | * @author PanZhao |
| ... | ... | @@ -51,8 +39,7 @@ import java.util.concurrent.TimeUnit; |
| 51 | 39 | * @date 2016年8月15日 上午10:16:12 |
| 52 | 40 | */ |
| 53 | 41 | @Component |
| 54 | -@Order(value = 3) | |
| 55 | -public class DayOfSchedule implements CommandLineRunner { | |
| 42 | +public class DayOfSchedule { | |
| 56 | 43 | |
| 57 | 44 | Logger logger = LoggerFactory.getLogger(this.getClass()); |
| 58 | 45 | |
| ... | ... | @@ -95,9 +82,6 @@ public class DayOfSchedule implements CommandLineRunner { |
| 95 | 82 | @Autowired |
| 96 | 83 | GpsRealData gpsRealData; |
| 97 | 84 | |
| 98 | - @Autowired | |
| 99 | - BasicData.BasicDataLoader basicDataLoader; | |
| 100 | - | |
| 101 | 85 | /** |
| 102 | 86 | * 线路当前使用的排班的日期 |
| 103 | 87 | */ |
| ... | ... | @@ -117,63 +101,13 @@ public class DayOfSchedule implements CommandLineRunner { |
| 117 | 101 | } |
| 118 | 102 | |
| 119 | 103 | @Autowired |
| 120 | - ScheduleRefreshThread scheduleRefreshThread; | |
| 121 | - | |
| 122 | - @Autowired | |
| 123 | - SchedulePstThread schedulePstThread; | |
| 124 | - | |
| 125 | - @Autowired | |
| 126 | - ScheduleLateThread scheduleLateThread; | |
| 127 | - | |
| 128 | - @Autowired | |
| 129 | - SubmitToTrafficManage submitToTrafficManage; | |
| 130 | - | |
| 131 | - @Autowired | |
| 132 | 104 | LineConfigData lineConfigs; |
| 133 | 105 | |
| 134 | 106 | @Autowired |
| 135 | 107 | GpsDataRecovery gpsDataRecovery; |
| 136 | 108 | |
| 137 | - @Autowired | |
| 138 | - DirectivesPstThread directivesPstThread; | |
| 139 | - | |
| 140 | - @Autowired | |
| 141 | - CalcOilThread calcOilThread; | |
| 142 | - | |
| 143 | - @Autowired | |
| 144 | - ThreadMonotor threadMonotor; | |
| 145 | - | |
| 146 | 109 | private static DateTimeFormatter fmtyyyyMMdd = DateTimeFormat.forPattern("yyyy-MM-dd"), fmtHHmm = DateTimeFormat.forPattern("HH:mm"); |
| 147 | 110 | |
| 148 | - @Override | |
| 149 | - public void run(String... arg0) throws Exception { | |
| 150 | - basicDataLoader.loadAllData(); | |
| 151 | - | |
| 152 | - //翻班线程 | |
| 153 | -// Application.mainServices.scheduleWithFixedDelay(scheduleRefreshThread, 15, 240, TimeUnit.SECONDS); | |
| 154 | - //入库 | |
| 155 | -// Application.mainServices.scheduleWithFixedDelay(schedulePstThread, 60, 30, TimeUnit.SECONDS); | |
| 156 | - //班次误点扫描 | |
| 157 | -// Application.mainServices.scheduleWithFixedDelay(scheduleLateThread, 60, 30, TimeUnit.SECONDS); | |
| 158 | - | |
| 159 | - //每天凌晨2点20提交数据到运管处 | |
| 160 | - long diff = (DateUtils.getTimestamp() + 1000 * 60 * 140) - System.currentTimeMillis(); | |
| 161 | - if (diff < 0) | |
| 162 | - diff += (1000 * 60 * 60 * 24); | |
| 163 | - | |
| 164 | - logger.info(diff / 1000 / 60 + "分钟之后提交到运管处"); | |
| 165 | - //Application.mainServices.scheduleAtFixedRate(submitToTrafficManage, diff / 1000, 60 * 60 * 24, TimeUnit.SECONDS); | |
| 166 | - | |
| 167 | - //计算油、公里加注 | |
| 168 | - Application.mainServices.scheduleAtFixedRate(calcOilThread, diff / 1000, 60 * 60 * 24, TimeUnit.SECONDS); | |
| 169 | - | |
| 170 | - //指令持久化线程 | |
| 171 | - Application.mainServices.scheduleWithFixedDelay(directivesPstThread, 180, 180, TimeUnit.SECONDS); | |
| 172 | - | |
| 173 | - //监听 | |
| 174 | - Application.mainServices.scheduleWithFixedDelay(threadMonotor, 120, 60, TimeUnit.SECONDS); | |
| 175 | - } | |
| 176 | - | |
| 177 | 111 | //数据恢复 |
| 178 | 112 | private void dataRecovery() { |
| 179 | 113 | GpsDataRecovery.run = true; | ... | ... |