Commit 479b1ed2e9b9108db697ff6bc99c16013141459d
1 parent
d7e1c51c
update...
Showing
4 changed files
with
21 additions
and
52 deletions
src/main/java/com/bsth/StartCommand.java
| 1 | package com.bsth; | 1 | package com.bsth; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | +import com.bsth.server_rs.gps.buffer.GpsRefreshThread; | ||
| 4 | import com.bsth.server_rs.schedule.real.thread.ExecSchDataRefreshThread; | 5 | import com.bsth.server_rs.schedule.real.thread.ExecSchDataRefreshThread; |
| 5 | import com.bsth.server_rs.schedule.real.thread.SchInOutDataRefreshThread; | 6 | import com.bsth.server_rs.schedule.real.thread.SchInOutDataRefreshThread; |
| 6 | import com.bsth.server_rs.thread.RfidCardInfoPersistenceThread; | 7 | import com.bsth.server_rs.thread.RfidCardInfoPersistenceThread; |
| @@ -23,12 +24,12 @@ public class StartCommand implements CommandLineRunner{ | @@ -23,12 +24,12 @@ public class StartCommand implements CommandLineRunner{ | ||
| 23 | 24 | ||
| 24 | @Autowired | 25 | @Autowired |
| 25 | RfidCardInfoPersistenceThread rfidCardInfoPersistenceThread; | 26 | RfidCardInfoPersistenceThread rfidCardInfoPersistenceThread; |
| 26 | - | ||
| 27 | @Autowired | 27 | @Autowired |
| 28 | SchInOutDataRefreshThread schInOutDataRefreshThread; | 28 | SchInOutDataRefreshThread schInOutDataRefreshThread; |
| 29 | - | ||
| 30 | @Autowired | 29 | @Autowired |
| 31 | ExecSchDataRefreshThread execSchDataRefreshThread; | 30 | ExecSchDataRefreshThread execSchDataRefreshThread; |
| 31 | + @Autowired | ||
| 32 | + GpsRefreshThread gpsRefreshThread; | ||
| 32 | 33 | ||
| 33 | @Override | 34 | @Override |
| 34 | public void run(String... arg0){ | 35 | public void run(String... arg0){ |
| @@ -37,11 +38,14 @@ public class StartCommand implements CommandLineRunner{ | @@ -37,11 +38,14 @@ public class StartCommand implements CommandLineRunner{ | ||
| 37 | ScheduledExecutorService sexec = Application.mainServices; | 38 | ScheduledExecutorService sexec = Application.mainServices; |
| 38 | //定时将人车卡数据入库 | 39 | //定时将人车卡数据入库 |
| 39 | sexec.scheduleWithFixedDelay(rfidCardInfoPersistenceThread, 120, 60 * 10, TimeUnit.SECONDS); | 40 | sexec.scheduleWithFixedDelay(rfidCardInfoPersistenceThread, 120, 60 * 10, TimeUnit.SECONDS); |
| 40 | - | ||
| 41 | //定时从调度系统刷新进出场数据 | 41 | //定时从调度系统刷新进出场数据 |
| 42 | sexec.scheduleWithFixedDelay(schInOutDataRefreshThread, 40, 20, TimeUnit.SECONDS); | 42 | sexec.scheduleWithFixedDelay(schInOutDataRefreshThread, 40, 20, TimeUnit.SECONDS); |
| 43 | //定时从调度系统刷新车辆正在的执行班次 | 43 | //定时从调度系统刷新车辆正在的执行班次 |
| 44 | sexec.scheduleWithFixedDelay(execSchDataRefreshThread, 20, 60 * 2, TimeUnit.SECONDS); | 44 | sexec.scheduleWithFixedDelay(execSchDataRefreshThread, 20, 60 * 2, TimeUnit.SECONDS); |
| 45 | + //定时刷新实时gps缓存 | ||
| 46 | + Application.mainServices.scheduleWithFixedDelay(gpsRefreshThread, 10, 7, TimeUnit.SECONDS); | ||
| 47 | + | ||
| 48 | + | ||
| 45 | } catch (Exception e) { | 49 | } catch (Exception e) { |
| 46 | e.printStackTrace(); | 50 | e.printStackTrace(); |
| 47 | } | 51 | } |
src/main/java/com/bsth/redis/OilRedisService.java
| @@ -106,14 +106,6 @@ public class OilRedisService implements CommandLineRunner { | @@ -106,14 +106,6 @@ public class OilRedisService implements CommandLineRunner { | ||
| 106 | public void mergeData(String key, List<OilInfo> list) { | 106 | public void mergeData(String key, List<OilInfo> list) { |
| 107 | key = REDIS_KEY_PREFIX + key; | 107 | key = REDIS_KEY_PREFIX + key; |
| 108 | 108 | ||
| 109 | -/* ListOperations<String, OilInfo> ops = redisTemplate.opsForList(); | ||
| 110 | - List<OilInfo> cacheList = ops.range(key, 0, -1); | ||
| 111 | - | ||
| 112 | - for (OilInfo oil : cacheList) { | ||
| 113 | - if (!list.contains(oil)) | ||
| 114 | - list.add(oil); | ||
| 115 | - }*/ | ||
| 116 | - | ||
| 117 | //更新 直接覆盖更新 | 109 | //更新 直接覆盖更新 |
| 118 | redisTemplate.execute(redisUtils.getUpdateCallback(key, list)); | 110 | redisTemplate.execute(redisUtils.getUpdateCallback(key, list)); |
| 119 | } | 111 | } |
| @@ -123,15 +115,19 @@ public class OilRedisService implements CommandLineRunner { | @@ -123,15 +115,19 @@ public class OilRedisService implements CommandLineRunner { | ||
| 123 | 115 | ||
| 124 | @Override | 116 | @Override |
| 125 | public void run(String... strings) throws Exception { | 117 | public void run(String... strings) throws Exception { |
| 118 | + //启动加载油耗缓存 | ||
| 119 | + synchData(null); | ||
| 126 | //定时刷新油耗信息 | 120 | //定时刷新油耗信息 |
| 127 | - Application.mainServices.scheduleWithFixedDelay(oilRefreshThread, 40, 60 * 40, TimeUnit.SECONDS); | 121 | + Application.mainServices.scheduleWithFixedDelay(oilRefreshThread, 60 * 40, 60 * 40, TimeUnit.SECONDS); |
| 128 | } | 122 | } |
| 129 | 123 | ||
| 130 | /** | 124 | /** |
| 131 | * 和数据库同步数据 | 125 | * 和数据库同步数据 |
| 132 | */ | 126 | */ |
| 133 | - public void synchData(){ | 127 | + public void synchData(Integer days){ |
| 134 | int cacheDays = Integer.parseInt(ConfigUtil.get("cache.days")); | 128 | int cacheDays = Integer.parseInt(ConfigUtil.get("cache.days")); |
| 129 | + if(null != days && days < cacheDays) | ||
| 130 | + cacheDays = days; | ||
| 135 | //设置key 序列化器 | 131 | //设置key 序列化器 |
| 136 | redisTemplate.setKeySerializer(new StringRedisSerializer()); | 132 | redisTemplate.setKeySerializer(new StringRedisSerializer()); |
| 137 | 133 | ||
| @@ -140,6 +136,7 @@ public class OilRedisService implements CommandLineRunner { | @@ -140,6 +136,7 @@ public class OilRedisService implements CommandLineRunner { | ||
| 140 | List<OilInfo> list = oilInfoRepository.findByDateLT(dt.toDate()); | 136 | List<OilInfo> list = oilInfoRepository.findByDateLT(dt.toDate()); |
| 141 | //写入redis | 137 | //写入redis |
| 142 | wirte(list); | 138 | wirte(list); |
| 139 | + logger.info("刷新油耗数据, days: " + cacheDays + " -size: " + list.size()); | ||
| 143 | } | 140 | } |
| 144 | 141 | ||
| 145 | @Component | 142 | @Component |
| @@ -150,7 +147,7 @@ public class OilRedisService implements CommandLineRunner { | @@ -150,7 +147,7 @@ public class OilRedisService implements CommandLineRunner { | ||
| 150 | @Override | 147 | @Override |
| 151 | public void run() { | 148 | public void run() { |
| 152 | try { | 149 | try { |
| 153 | - oilRedisService.synchData(); | 150 | + oilRedisService.synchData(2); |
| 154 | } catch (Exception e) { | 151 | } catch (Exception e) { |
| 155 | logger.error("", e); | 152 | logger.error("", e); |
| 156 | } | 153 | } |
src/main/java/com/bsth/redis/ScheduleRedisService.java
| @@ -134,31 +134,6 @@ public class ScheduleRedisService implements CommandLineRunner { | @@ -134,31 +134,6 @@ public class ScheduleRedisService implements CommandLineRunner { | ||
| 134 | 134 | ||
| 135 | /** | 135 | /** |
| 136 | * 返回指定日期,公司的实际排班,并按线路_车辆分组 | 136 | * 返回指定日期,公司的实际排班,并按线路_车辆分组 |
| 137 | - * (新老系统并行时调用这个函数) | ||
| 138 | - * | ||
| 139 | - * @param rq | ||
| 140 | - * @param companyId | ||
| 141 | - * @return | ||
| 142 | - | ||
| 143 | - public ArrayListMultimap<String, ScheduleRealInfo> findByDateAndGroupByNbbm_bingxing(String rq, String companyId) { | ||
| 144 | - List<String> lineArray = webServiceProxy.findLinesByCompany_new(companyId); | ||
| 145 | - ArrayListMultimap<String, ScheduleRealInfo> rs = ArrayListMultimap.create(); | ||
| 146 | - | ||
| 147 | - rq = rq.replaceAll("-", ""); | ||
| 148 | - List<ScheduleRealInfo> list; | ||
| 149 | - for (String lineCode : lineArray) { | ||
| 150 | - | ||
| 151 | - list = read(rq, lineCode); | ||
| 152 | - | ||
| 153 | - for (ScheduleRealInfo sch : list) { | ||
| 154 | - rs.put(sch.getXlBm() + "_" + sch.getClZbh(), sch); | ||
| 155 | - } | ||
| 156 | - } | ||
| 157 | - return rs; | ||
| 158 | - }*/ | ||
| 159 | - | ||
| 160 | - /** | ||
| 161 | - * 返回指定日期,公司的实际排班,并按线路_车辆分组 | ||
| 162 | * | 137 | * |
| 163 | * @param rq | 138 | * @param rq |
| 164 | * @param companyId | 139 | * @param companyId |
| @@ -253,12 +228,15 @@ public class ScheduleRedisService implements CommandLineRunner { | @@ -253,12 +228,15 @@ public class ScheduleRedisService implements CommandLineRunner { | ||
| 253 | public void run() { | 228 | public void run() { |
| 254 | try { | 229 | try { |
| 255 | DateTime dt = new DateTime(); | 230 | DateTime dt = new DateTime(); |
| 256 | - logger.info("ScheduleRefreshThread..." + dt.toString("yyyy-MM-dd")); | ||
| 257 | - List<ScheduleRealInfo> list = realInfoRepository.findAll(dt.toString("yyyy-MM-dd")); | 231 | + String rq = dt.toString("yyyy-MM-dd"); |
| 232 | + logger.info("ScheduleRefreshThread..." + rq + " -start"); | ||
| 233 | + List<ScheduleRealInfo> list = realInfoRepository.findAll(rq); | ||
| 258 | 234 | ||
| 259 | //计算时间戳 | 235 | //计算时间戳 |
| 260 | scheduleRedisService.calcTime(list); | 236 | scheduleRedisService.calcTime(list); |
| 261 | scheduleRedisService.wirte(list); | 237 | scheduleRedisService.wirte(list); |
| 238 | + | ||
| 239 | + logger.info("ScheduleRefreshThread..." + rq + " -end"); | ||
| 262 | } catch (Exception e) { | 240 | } catch (Exception e) { |
| 263 | logger.error("", e); | 241 | logger.error("", e); |
| 264 | } | 242 | } |
src/main/java/com/bsth/server_rs/gps/buffer/GpsRealDataBuffer.java
| 1 | package com.bsth.server_rs.gps.buffer; | 1 | package com.bsth.server_rs.gps.buffer; |
| 2 | 2 | ||
| 3 | -import com.bsth.Application; | ||
| 4 | import com.bsth.server_rs.gps.entity.GpsEntity; | 3 | import com.bsth.server_rs.gps.entity.GpsEntity; |
| 5 | import org.springframework.beans.factory.annotation.Autowired; | 4 | import org.springframework.beans.factory.annotation.Autowired; |
| 6 | -import org.springframework.boot.CommandLineRunner; | ||
| 7 | -import org.springframework.core.annotation.Order; | ||
| 8 | import org.springframework.stereotype.Component; | 5 | import org.springframework.stereotype.Component; |
| 9 | 6 | ||
| 10 | import java.util.Collection; | 7 | import java.util.Collection; |
| 11 | import java.util.HashMap; | 8 | import java.util.HashMap; |
| 12 | import java.util.Map; | 9 | import java.util.Map; |
| 13 | -import java.util.concurrent.TimeUnit; | ||
| 14 | 10 | ||
| 15 | /** | 11 | /** |
| 16 | * Created by panzhao on 2017/3/30. | 12 | * Created by panzhao on 2017/3/30. |
| 17 | */ | 13 | */ |
| 18 | @Component | 14 | @Component |
| 19 | -@Order(8) | ||
| 20 | -public class GpsRealDataBuffer implements CommandLineRunner { | 15 | +public class GpsRealDataBuffer { |
| 21 | 16 | ||
| 22 | private static Map<String, GpsEntity> realMap; | 17 | private static Map<String, GpsEntity> realMap; |
| 23 | 18 | ||
| @@ -39,9 +34,4 @@ public class GpsRealDataBuffer implements CommandLineRunner { | @@ -39,9 +34,4 @@ public class GpsRealDataBuffer implements CommandLineRunner { | ||
| 39 | public static Collection<GpsEntity> all(){ | 34 | public static Collection<GpsEntity> all(){ |
| 40 | return realMap.values(); | 35 | return realMap.values(); |
| 41 | } | 36 | } |
| 42 | - | ||
| 43 | - @Override | ||
| 44 | - public void run(String... strings) throws Exception { | ||
| 45 | - Application.mainServices.scheduleWithFixedDelay(gpsRefreshThread, 10, 8, TimeUnit.SECONDS); | ||
| 46 | - } | ||
| 47 | } | 37 | } |