Commit 479b1ed2e9b9108db697ff6bc99c16013141459d
1 parent
d7e1c51c
update...
Showing
4 changed files
with
21 additions
and
52 deletions
src/main/java/com/bsth/StartCommand.java
| 1 | 1 | package com.bsth; |
| 2 | 2 | |
| 3 | 3 | |
| 4 | +import com.bsth.server_rs.gps.buffer.GpsRefreshThread; | |
| 4 | 5 | import com.bsth.server_rs.schedule.real.thread.ExecSchDataRefreshThread; |
| 5 | 6 | import com.bsth.server_rs.schedule.real.thread.SchInOutDataRefreshThread; |
| 6 | 7 | import com.bsth.server_rs.thread.RfidCardInfoPersistenceThread; |
| ... | ... | @@ -23,12 +24,12 @@ public class StartCommand implements CommandLineRunner{ |
| 23 | 24 | |
| 24 | 25 | @Autowired |
| 25 | 26 | RfidCardInfoPersistenceThread rfidCardInfoPersistenceThread; |
| 26 | - | |
| 27 | 27 | @Autowired |
| 28 | 28 | SchInOutDataRefreshThread schInOutDataRefreshThread; |
| 29 | - | |
| 30 | 29 | @Autowired |
| 31 | 30 | ExecSchDataRefreshThread execSchDataRefreshThread; |
| 31 | + @Autowired | |
| 32 | + GpsRefreshThread gpsRefreshThread; | |
| 32 | 33 | |
| 33 | 34 | @Override |
| 34 | 35 | public void run(String... arg0){ |
| ... | ... | @@ -37,11 +38,14 @@ public class StartCommand implements CommandLineRunner{ |
| 37 | 38 | ScheduledExecutorService sexec = Application.mainServices; |
| 38 | 39 | //定时将人车卡数据入库 |
| 39 | 40 | sexec.scheduleWithFixedDelay(rfidCardInfoPersistenceThread, 120, 60 * 10, TimeUnit.SECONDS); |
| 40 | - | |
| 41 | 41 | //定时从调度系统刷新进出场数据 |
| 42 | 42 | sexec.scheduleWithFixedDelay(schInOutDataRefreshThread, 40, 20, TimeUnit.SECONDS); |
| 43 | 43 | //定时从调度系统刷新车辆正在的执行班次 |
| 44 | 44 | sexec.scheduleWithFixedDelay(execSchDataRefreshThread, 20, 60 * 2, TimeUnit.SECONDS); |
| 45 | + //定时刷新实时gps缓存 | |
| 46 | + Application.mainServices.scheduleWithFixedDelay(gpsRefreshThread, 10, 7, TimeUnit.SECONDS); | |
| 47 | + | |
| 48 | + | |
| 45 | 49 | } catch (Exception e) { |
| 46 | 50 | e.printStackTrace(); |
| 47 | 51 | } | ... | ... |
src/main/java/com/bsth/redis/OilRedisService.java
| ... | ... | @@ -106,14 +106,6 @@ public class OilRedisService implements CommandLineRunner { |
| 106 | 106 | public void mergeData(String key, List<OilInfo> list) { |
| 107 | 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 | 110 | redisTemplate.execute(redisUtils.getUpdateCallback(key, list)); |
| 119 | 111 | } |
| ... | ... | @@ -123,15 +115,19 @@ public class OilRedisService implements CommandLineRunner { |
| 123 | 115 | |
| 124 | 116 | @Override |
| 125 | 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 | 128 | int cacheDays = Integer.parseInt(ConfigUtil.get("cache.days")); |
| 129 | + if(null != days && days < cacheDays) | |
| 130 | + cacheDays = days; | |
| 135 | 131 | //设置key 序列化器 |
| 136 | 132 | redisTemplate.setKeySerializer(new StringRedisSerializer()); |
| 137 | 133 | |
| ... | ... | @@ -140,6 +136,7 @@ public class OilRedisService implements CommandLineRunner { |
| 140 | 136 | List<OilInfo> list = oilInfoRepository.findByDateLT(dt.toDate()); |
| 141 | 137 | //写入redis |
| 142 | 138 | wirte(list); |
| 139 | + logger.info("刷新油耗数据, days: " + cacheDays + " -size: " + list.size()); | |
| 143 | 140 | } |
| 144 | 141 | |
| 145 | 142 | @Component |
| ... | ... | @@ -150,7 +147,7 @@ public class OilRedisService implements CommandLineRunner { |
| 150 | 147 | @Override |
| 151 | 148 | public void run() { |
| 152 | 149 | try { |
| 153 | - oilRedisService.synchData(); | |
| 150 | + oilRedisService.synchData(2); | |
| 154 | 151 | } catch (Exception e) { |
| 155 | 152 | logger.error("", e); |
| 156 | 153 | } | ... | ... |
src/main/java/com/bsth/redis/ScheduleRedisService.java
| ... | ... | @@ -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 | 138 | * @param rq |
| 164 | 139 | * @param companyId |
| ... | ... | @@ -253,12 +228,15 @@ public class ScheduleRedisService implements CommandLineRunner { |
| 253 | 228 | public void run() { |
| 254 | 229 | try { |
| 255 | 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 | 236 | scheduleRedisService.calcTime(list); |
| 261 | 237 | scheduleRedisService.wirte(list); |
| 238 | + | |
| 239 | + logger.info("ScheduleRefreshThread..." + rq + " -end"); | |
| 262 | 240 | } catch (Exception e) { |
| 263 | 241 | logger.error("", e); |
| 264 | 242 | } | ... | ... |
src/main/java/com/bsth/server_rs/gps/buffer/GpsRealDataBuffer.java
| 1 | 1 | package com.bsth.server_rs.gps.buffer; |
| 2 | 2 | |
| 3 | -import com.bsth.Application; | |
| 4 | 3 | import com.bsth.server_rs.gps.entity.GpsEntity; |
| 5 | 4 | import org.springframework.beans.factory.annotation.Autowired; |
| 6 | -import org.springframework.boot.CommandLineRunner; | |
| 7 | -import org.springframework.core.annotation.Order; | |
| 8 | 5 | import org.springframework.stereotype.Component; |
| 9 | 6 | |
| 10 | 7 | import java.util.Collection; |
| 11 | 8 | import java.util.HashMap; |
| 12 | 9 | import java.util.Map; |
| 13 | -import java.util.concurrent.TimeUnit; | |
| 14 | 10 | |
| 15 | 11 | /** |
| 16 | 12 | * Created by panzhao on 2017/3/30. |
| 17 | 13 | */ |
| 18 | 14 | @Component |
| 19 | -@Order(8) | |
| 20 | -public class GpsRealDataBuffer implements CommandLineRunner { | |
| 15 | +public class GpsRealDataBuffer { | |
| 21 | 16 | |
| 22 | 17 | private static Map<String, GpsEntity> realMap; |
| 23 | 18 | |
| ... | ... | @@ -39,9 +34,4 @@ public class GpsRealDataBuffer implements CommandLineRunner { |
| 39 | 34 | public static Collection<GpsEntity> all(){ |
| 40 | 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 | } | ... | ... |