Commit 96584bb134295c4fb83bf118bae4b8c9e0fdcfb1
1 parent
28f637a0
1.加入电科所用的4个接口,以及接口对应的数据生成
Showing
6 changed files
with
795 additions
and
701 deletions
src/main/java/com/bsth/CXFConfig.java
| ... | ... | @@ -14,6 +14,7 @@ import com.bsth.server_rs.bigdata.BigscreenService; |
| 14 | 14 | import com.bsth.server_rs.departure.DepartureRestService; |
| 15 | 15 | import com.bsth.server_rs.destroy.DestroyDetailRestService; |
| 16 | 16 | import com.bsth.server_rs.directive.DirectiveRestService; |
| 17 | +import com.bsth.server_rs.dks.DksRestService; | |
| 17 | 18 | import com.bsth.server_rs.electric.ElectricService; |
| 18 | 19 | import com.bsth.server_rs.exception.AesExceptionMapper; |
| 19 | 20 | import com.bsth.server_rs.gps.GpsRestService; |
| ... | ... | @@ -129,6 +130,8 @@ public class CXFConfig { |
| 129 | 130 | private CarparkRestService carparkRestService; |
| 130 | 131 | @Autowired |
| 131 | 132 | private DepartureRestService departureRestService; |
| 133 | + @Autowired | |
| 134 | + private DksRestService dksRestService; | |
| 132 | 135 | |
| 133 | 136 | @Bean |
| 134 | 137 | public Server rsServer() { |
| ... | ... | @@ -155,7 +158,8 @@ public class CXFConfig { |
| 155 | 158 | rateService, |
| 156 | 159 | destroyDetailRestService, |
| 157 | 160 | carparkRestService, |
| 158 | - departureRestService)); | |
| 161 | + departureRestService, | |
| 162 | + dksRestService)); | |
| 159 | 163 | endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(), new AesExceptionMapper())); |
| 160 | 164 | //endpoint.setFeatures(Arrays.asList(new Swagger2Feature())); |
| 161 | 165 | endpoint.getInInterceptors().add(new AuthorizeInterceptor_IN()); | ... | ... |
src/main/java/com/bsth/redis/ElecRedisService.java
| 1 | -package com.bsth.redis; | |
| 2 | - | |
| 3 | -import com.bsth.Application; | |
| 4 | -import com.bsth.entity.ElecInfo; | |
| 5 | -import com.bsth.redis.util.RedisUtils; | |
| 6 | -import com.bsth.repository.ElecInfoRepository; | |
| 7 | -import com.bsth.util.ConfigUtil; | |
| 8 | -import com.bsth.util.ConvertUtil; | |
| 9 | -import com.google.common.collect.ArrayListMultimap; | |
| 10 | -import org.joda.time.DateTime; | |
| 11 | -import org.slf4j.Logger; | |
| 12 | -import org.slf4j.LoggerFactory; | |
| 13 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 14 | -import org.springframework.boot.CommandLineRunner; | |
| 15 | -import org.springframework.core.annotation.Order; | |
| 16 | -import org.springframework.data.redis.core.RedisTemplate; | |
| 17 | -import org.springframework.data.redis.serializer.StringRedisSerializer; | |
| 18 | -import org.springframework.stereotype.Component; | |
| 19 | -import org.springframework.stereotype.Service; | |
| 20 | - | |
| 21 | -import java.util.*; | |
| 22 | -import java.util.concurrent.TimeUnit; | |
| 23 | - | |
| 24 | -/** | |
| 25 | - * 油量数据Redis缓存 | |
| 26 | - * Created by panzhao on 2017/3/19. | |
| 27 | - */ | |
| 28 | -@Service | |
| 29 | -@Order(3) | |
| 30 | -public class ElecRedisService implements CommandLineRunner { | |
| 31 | - | |
| 32 | - @Autowired | |
| 33 | - private RedisTemplate redisTemplate; | |
| 34 | - | |
| 35 | - @Autowired | |
| 36 | - ElecInfoRepository elecInfoRepository; | |
| 37 | - | |
| 38 | - @Autowired | |
| 39 | - RedisUtils redisUtils; | |
| 40 | - | |
| 41 | - static Logger logger = LoggerFactory.getLogger(ElecRedisService.class); | |
| 42 | - | |
| 43 | - private final static String REDIS_KEY_PREFIX = "elec:"; | |
| 44 | - | |
| 45 | - /** | |
| 46 | - * 将油量数据写入redis | |
| 47 | - * | |
| 48 | - * @param list | |
| 49 | - */ | |
| 50 | - public void wirte(List<ElecInfo> list) { | |
| 51 | - ArrayListMultimap<String, ElecInfo> multimap; | |
| 52 | - try { | |
| 53 | - if (list.size() == 0) | |
| 54 | - return; | |
| 55 | - //按日期和线路分组数据 | |
| 56 | - Class clazz = ElecInfo.class; | |
| 57 | - multimap = new ConvertUtil().groupMultiList(list, ":", clazz.getDeclaredField("nbbm"), clazz.getDeclaredField("rq")); | |
| 58 | - | |
| 59 | - //写入redis | |
| 60 | - Iterator<String> iterator = multimap.keySet().iterator(); | |
| 61 | - String key; | |
| 62 | - while (iterator.hasNext()) { | |
| 63 | - key = iterator.next(); | |
| 64 | - mergeData(key, multimap.get(key)); | |
| 65 | - } | |
| 66 | - } catch (Exception e) { | |
| 67 | - logger.error("", e); | |
| 68 | - } | |
| 69 | - } | |
| 70 | - | |
| 71 | - /** | |
| 72 | - * 根据车辆和日期获取油耗数据,以 车辆_驾驶员 为key | |
| 73 | - * | |
| 74 | - * @param nbbmArray | |
| 75 | - * @param rq | |
| 76 | - * @return | |
| 77 | - */ | |
| 78 | - public ArrayListMultimap findByNbbmGroup(Iterable<String> nbbmArray, String rq) { | |
| 79 | - ArrayListMultimap rs = ArrayListMultimap.create(); | |
| 80 | - | |
| 81 | - rq = rq.replaceAll("-", ""); | |
| 82 | - try { | |
| 83 | - List<ElecInfo> list = new ArrayList<>(); | |
| 84 | - for (String nbbm : nbbmArray) { | |
| 85 | - nbbm = nbbm.split("_")[1]; | |
| 86 | - list.addAll(read(nbbm, rq)); | |
| 87 | - } | |
| 88 | - Class clazz = ElecInfo.class; | |
| 89 | - rs = new ConvertUtil().groupMultiList(list, "_", clazz.getDeclaredField("nbbm"), clazz.getDeclaredField("jsy")); | |
| 90 | - } catch (Exception e) { | |
| 91 | - logger.error("", e); | |
| 92 | - } | |
| 93 | - return rs; | |
| 94 | - } | |
| 95 | - | |
| 96 | - public List<ElecInfo> read(String nbbm, String rq) { | |
| 97 | - return redisTemplate.opsForList().range(REDIS_KEY_PREFIX + nbbm + ":" + rq, 0, -1); | |
| 98 | - } | |
| 99 | - | |
| 100 | - /** | |
| 101 | - * 将 list 与redis里的数据合并 | |
| 102 | - * | |
| 103 | - * @param key | |
| 104 | - * @param list | |
| 105 | - */ | |
| 106 | - public void mergeData(String key, List<ElecInfo> list) { | |
| 107 | - key = REDIS_KEY_PREFIX + key; | |
| 108 | - | |
| 109 | - //更新 直接覆盖更新 | |
| 110 | - redisTemplate.execute(redisUtils.getUpdateCallback(key, list)); | |
| 111 | - } | |
| 112 | - | |
| 113 | - @Autowired | |
| 114 | - ElecRefreshThread elecRefreshThread; | |
| 115 | - | |
| 116 | - @Override | |
| 117 | - public void run(String... strings) throws Exception { | |
| 118 | - Application.mainServices.schedule(new Runnable() { | |
| 119 | - @Override | |
| 120 | - public void run() { | |
| 121 | - //启动加载油耗缓存 | |
| 122 | - synchData(null); | |
| 123 | - } | |
| 124 | - }, 30, TimeUnit.SECONDS); | |
| 125 | - | |
| 126 | - | |
| 127 | - //定时刷新油耗信息 | |
| 128 | - Application.mainServices.scheduleWithFixedDelay(elecRefreshThread, 60 * 40, 60 * 40, TimeUnit.SECONDS); | |
| 129 | - } | |
| 130 | - | |
| 131 | - /** | |
| 132 | - * 和数据库同步数据 | |
| 133 | - */ | |
| 134 | - public void synchData(Integer days) { | |
| 135 | - int cacheDays = Integer.parseInt(ConfigUtil.get("cache.days")); | |
| 136 | - if (null != days && days < cacheDays) | |
| 137 | - cacheDays = days; | |
| 138 | - //设置key 序列化器 | |
| 139 | - redisTemplate.setKeySerializer(new StringRedisSerializer()); | |
| 140 | - | |
| 141 | - DateTime dt = new DateTime(); | |
| 142 | - dt = dt.withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0).minusDays(cacheDays); | |
| 143 | - List<ElecInfo> list = elecInfoRepository.findByDateLT(dt.toDate()); | |
| 144 | - //写入redis | |
| 145 | - wirte(list); | |
| 146 | - logger.info("刷新电耗数据, days: " + cacheDays + " -size: " + list.size() + " -LT: " + dt.toString("yyyy-MM-dd")); | |
| 147 | - } | |
| 148 | - | |
| 149 | - @Component | |
| 150 | - public static class ElecRefreshThread extends Thread { | |
| 151 | - | |
| 152 | - @Autowired | |
| 153 | - ElecRedisService elecRedisService; | |
| 154 | - | |
| 155 | - @Override | |
| 156 | - public void run() { | |
| 157 | - try { | |
| 158 | - elecRedisService.synchData(5); | |
| 159 | - } catch (Exception e) { | |
| 160 | - logger.error("", e); | |
| 161 | - } | |
| 162 | - } | |
| 163 | - } | |
| 164 | -} | |
| 1 | +package com.bsth.redis; | |
| 2 | + | |
| 3 | +import com.bsth.Application; | |
| 4 | +import com.bsth.entity.ElecInfo; | |
| 5 | +import com.bsth.redis.util.RedisUtils; | |
| 6 | +import com.bsth.repository.ElecInfoRepository; | |
| 7 | +import com.bsth.util.ConfigUtil; | |
| 8 | +import com.bsth.util.ConvertUtil; | |
| 9 | +import com.google.common.collect.ArrayListMultimap; | |
| 10 | +import org.joda.time.DateTime; | |
| 11 | +import org.slf4j.Logger; | |
| 12 | +import org.slf4j.LoggerFactory; | |
| 13 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 14 | +import org.springframework.boot.CommandLineRunner; | |
| 15 | +import org.springframework.core.annotation.Order; | |
| 16 | +import org.springframework.data.redis.core.RedisTemplate; | |
| 17 | +import org.springframework.data.redis.serializer.StringRedisSerializer; | |
| 18 | +import org.springframework.stereotype.Component; | |
| 19 | +import org.springframework.stereotype.Service; | |
| 20 | + | |
| 21 | +import java.util.*; | |
| 22 | +import java.util.concurrent.TimeUnit; | |
| 23 | + | |
| 24 | +/** | |
| 25 | + * 油量数据Redis缓存 | |
| 26 | + * Created by panzhao on 2017/3/19. | |
| 27 | + */ | |
| 28 | +@Service | |
| 29 | +@Order(3) | |
| 30 | +public class ElecRedisService implements CommandLineRunner { | |
| 31 | + | |
| 32 | + @Autowired | |
| 33 | + private RedisTemplate redisTemplate; | |
| 34 | + | |
| 35 | + @Autowired | |
| 36 | + ElecInfoRepository elecInfoRepository; | |
| 37 | + | |
| 38 | + @Autowired | |
| 39 | + RedisUtils redisUtils; | |
| 40 | + | |
| 41 | + static Logger logger = LoggerFactory.getLogger(ElecRedisService.class); | |
| 42 | + | |
| 43 | + private final static String REDIS_KEY_PREFIX = "elec:"; | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * 将油量数据写入redis | |
| 47 | + * | |
| 48 | + * @param list | |
| 49 | + */ | |
| 50 | + public void wirte(List<ElecInfo> list) { | |
| 51 | + ArrayListMultimap<String, ElecInfo> multimap; | |
| 52 | + try { | |
| 53 | + if (list.size() == 0) | |
| 54 | + return; | |
| 55 | + //按日期和线路分组数据 | |
| 56 | + Class clazz = ElecInfo.class; | |
| 57 | + multimap = new ConvertUtil().groupMultiList(list, ":", clazz.getDeclaredField("nbbm"), clazz.getDeclaredField("rq")); | |
| 58 | + | |
| 59 | + //写入redis | |
| 60 | + Iterator<String> iterator = multimap.keySet().iterator(); | |
| 61 | + String key; | |
| 62 | + while (iterator.hasNext()) { | |
| 63 | + key = iterator.next(); | |
| 64 | + mergeData(key, multimap.get(key)); | |
| 65 | + } | |
| 66 | + } catch (Exception e) { | |
| 67 | + logger.error("", e); | |
| 68 | + } | |
| 69 | + } | |
| 70 | + | |
| 71 | + /** | |
| 72 | + * 根据车辆和日期获取油耗数据,以 车辆_驾驶员 为key | |
| 73 | + * | |
| 74 | + * @param nbbmArray | |
| 75 | + * @param rq | |
| 76 | + * @return | |
| 77 | + */ | |
| 78 | + public ArrayListMultimap findByNbbmGroup(Iterable<String> nbbmArray, String rq) { | |
| 79 | + ArrayListMultimap rs = ArrayListMultimap.create(); | |
| 80 | + | |
| 81 | + rq = rq.replaceAll("-", ""); | |
| 82 | + try { | |
| 83 | + List<ElecInfo> list = new ArrayList<>(); | |
| 84 | + for (String nbbm : nbbmArray) { | |
| 85 | + nbbm = nbbm.split("_")[1]; | |
| 86 | + list.addAll(read(nbbm, rq)); | |
| 87 | + } | |
| 88 | + Class clazz = ElecInfo.class; | |
| 89 | + rs = new ConvertUtil().groupMultiList(list, "_", clazz.getDeclaredField("nbbm"), clazz.getDeclaredField("jsy")); | |
| 90 | + } catch (Exception e) { | |
| 91 | + logger.error("", e); | |
| 92 | + } | |
| 93 | + return rs; | |
| 94 | + } | |
| 95 | + | |
| 96 | + /** | |
| 97 | + * 根据车辆和日期获取油耗数据,以 车辆 为key | |
| 98 | + * | |
| 99 | + * @param nbbmArray | |
| 100 | + * @param rq | |
| 101 | + * @return | |
| 102 | + */ | |
| 103 | + public ArrayListMultimap findByNbbmGroup1(Iterable<String> nbbmArray, String rq) { | |
| 104 | + ArrayListMultimap rs = ArrayListMultimap.create(); | |
| 105 | + | |
| 106 | + rq = rq.replaceAll("-", ""); | |
| 107 | + try { | |
| 108 | + List<ElecInfo> list = new ArrayList<>(); | |
| 109 | + for (String nbbm : nbbmArray) { | |
| 110 | + list.addAll(read(nbbm, rq)); | |
| 111 | + } | |
| 112 | + Class clazz = ElecInfo.class; | |
| 113 | + rs = new ConvertUtil().groupMultiList(list, "_", clazz.getDeclaredField("nbbm")); | |
| 114 | + } catch (Exception e) { | |
| 115 | + logger.error("", e); | |
| 116 | + } | |
| 117 | + return rs; | |
| 118 | + } | |
| 119 | + | |
| 120 | + public List<ElecInfo> read(String nbbm, String rq) { | |
| 121 | + return redisTemplate.opsForList().range(REDIS_KEY_PREFIX + nbbm + ":" + rq, 0, -1); | |
| 122 | + } | |
| 123 | + | |
| 124 | + /** | |
| 125 | + * 将 list 与redis里的数据合并 | |
| 126 | + * | |
| 127 | + * @param key | |
| 128 | + * @param list | |
| 129 | + */ | |
| 130 | + public void mergeData(String key, List<ElecInfo> list) { | |
| 131 | + key = REDIS_KEY_PREFIX + key; | |
| 132 | + | |
| 133 | + //更新 直接覆盖更新 | |
| 134 | + redisTemplate.execute(redisUtils.getUpdateCallback(key, list)); | |
| 135 | + } | |
| 136 | + | |
| 137 | + @Autowired | |
| 138 | + ElecRefreshThread elecRefreshThread; | |
| 139 | + | |
| 140 | + @Override | |
| 141 | + public void run(String... strings) throws Exception { | |
| 142 | + Application.mainServices.schedule(new Runnable() { | |
| 143 | + @Override | |
| 144 | + public void run() { | |
| 145 | + //启动加载油耗缓存 | |
| 146 | + synchData(null); | |
| 147 | + } | |
| 148 | + }, 30, TimeUnit.SECONDS); | |
| 149 | + | |
| 150 | + | |
| 151 | + //定时刷新油耗信息 | |
| 152 | + Application.mainServices.scheduleWithFixedDelay(elecRefreshThread, 60 * 40, 60 * 40, TimeUnit.SECONDS); | |
| 153 | + } | |
| 154 | + | |
| 155 | + /** | |
| 156 | + * 和数据库同步数据 | |
| 157 | + */ | |
| 158 | + public void synchData(Integer days) { | |
| 159 | + int cacheDays = Integer.parseInt(ConfigUtil.get("cache.days")); | |
| 160 | + if (null != days && days < cacheDays) | |
| 161 | + cacheDays = days; | |
| 162 | + //设置key 序列化器 | |
| 163 | + redisTemplate.setKeySerializer(new StringRedisSerializer()); | |
| 164 | + | |
| 165 | + DateTime dt = new DateTime(); | |
| 166 | + dt = dt.withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0).minusDays(cacheDays); | |
| 167 | + List<ElecInfo> list = elecInfoRepository.findByDateLT(dt.toDate()); | |
| 168 | + //写入redis | |
| 169 | + wirte(list); | |
| 170 | + logger.info("刷新电耗数据, days: " + cacheDays + " -size: " + list.size() + " -LT: " + dt.toString("yyyy-MM-dd")); | |
| 171 | + } | |
| 172 | + | |
| 173 | + @Component | |
| 174 | + public static class ElecRefreshThread extends Thread { | |
| 175 | + | |
| 176 | + @Autowired | |
| 177 | + ElecRedisService elecRedisService; | |
| 178 | + | |
| 179 | + @Override | |
| 180 | + public void run() { | |
| 181 | + try { | |
| 182 | + elecRedisService.synchData(5); | |
| 183 | + } catch (Exception e) { | |
| 184 | + logger.error("", e); | |
| 185 | + } | |
| 186 | + } | |
| 187 | + } | |
| 188 | +} | ... | ... |
src/main/java/com/bsth/redis/OilRedisService.java
| 1 | -package com.bsth.redis; | |
| 2 | - | |
| 3 | -import com.bsth.Application; | |
| 4 | -import com.bsth.entity.OilInfo; | |
| 5 | -import com.bsth.redis.util.RedisUtils; | |
| 6 | -import com.bsth.repository.OilInfoRepository; | |
| 7 | -import com.bsth.util.ConfigUtil; | |
| 8 | -import com.bsth.util.ConvertUtil; | |
| 9 | -import com.google.common.collect.ArrayListMultimap; | |
| 10 | -import org.joda.time.DateTime; | |
| 11 | -import org.slf4j.Logger; | |
| 12 | -import org.slf4j.LoggerFactory; | |
| 13 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 14 | -import org.springframework.boot.CommandLineRunner; | |
| 15 | -import org.springframework.core.annotation.Order; | |
| 16 | -import org.springframework.data.redis.core.RedisTemplate; | |
| 17 | -import org.springframework.data.redis.serializer.StringRedisSerializer; | |
| 18 | -import org.springframework.stereotype.Component; | |
| 19 | -import org.springframework.stereotype.Service; | |
| 20 | - | |
| 21 | -import java.util.*; | |
| 22 | -import java.util.concurrent.TimeUnit; | |
| 23 | - | |
| 24 | -/** | |
| 25 | - * 油量数据Redis缓存 | |
| 26 | - * Created by panzhao on 2017/3/19. | |
| 27 | - */ | |
| 28 | -@Service | |
| 29 | -@Order(3) | |
| 30 | -public class OilRedisService implements CommandLineRunner { | |
| 31 | - | |
| 32 | - @Autowired | |
| 33 | - private RedisTemplate redisTemplate; | |
| 34 | - | |
| 35 | - @Autowired | |
| 36 | - OilInfoRepository oilInfoRepository; | |
| 37 | - | |
| 38 | - @Autowired | |
| 39 | - RedisUtils redisUtils; | |
| 40 | - | |
| 41 | - static Logger logger = LoggerFactory.getLogger(OilRedisService.class); | |
| 42 | - | |
| 43 | - private final static String REDIS_KEY_PREFIX = "oil:"; | |
| 44 | - | |
| 45 | - /** | |
| 46 | - * 将油量数据写入redis | |
| 47 | - * | |
| 48 | - * @param list | |
| 49 | - */ | |
| 50 | - public void wirte(List<OilInfo> list) { | |
| 51 | - ArrayListMultimap<String, OilInfo> multimap; | |
| 52 | - try { | |
| 53 | - if (list.size() == 0) | |
| 54 | - return; | |
| 55 | - //按日期和线路分组数据 | |
| 56 | - Class clazz = OilInfo.class; | |
| 57 | - multimap = new ConvertUtil().groupMultiList(list, ":", clazz.getDeclaredField("nbbm"), clazz.getDeclaredField("rq")); | |
| 58 | - | |
| 59 | - //写入redis | |
| 60 | - Iterator<String> iterator = multimap.keySet().iterator(); | |
| 61 | - String key; | |
| 62 | - while (iterator.hasNext()) { | |
| 63 | - key = iterator.next(); | |
| 64 | - mergeData(key, multimap.get(key)); | |
| 65 | - } | |
| 66 | - } catch (Exception e) { | |
| 67 | - logger.error("", e); | |
| 68 | - } | |
| 69 | - } | |
| 70 | - | |
| 71 | - /** | |
| 72 | - * 根据车辆和日期获取油耗数据,以 车辆_驾驶员 为key | |
| 73 | - * | |
| 74 | - * @param nbbmArray | |
| 75 | - * @param rq | |
| 76 | - * @return | |
| 77 | - */ | |
| 78 | - public ArrayListMultimap<String, OilInfo> findByNbbmGroup(Iterable<String> nbbmArray, String rq) { | |
| 79 | - ArrayListMultimap<String, OilInfo> rs = ArrayListMultimap.create(); | |
| 80 | - | |
| 81 | - rq = rq.replaceAll("-", ""); | |
| 82 | - try { | |
| 83 | - List<OilInfo> list = new ArrayList<>(); | |
| 84 | - Set<String> nbbms = new HashSet<>(); | |
| 85 | - for (String nbbm : nbbmArray) { | |
| 86 | - nbbm = nbbm.split("_")[1]; | |
| 87 | - if (!nbbms.contains(nbbm)) { | |
| 88 | - nbbms.add(nbbm); | |
| 89 | - list.addAll(read(nbbm, rq)); | |
| 90 | - } | |
| 91 | - } | |
| 92 | - Class clazz = OilInfo.class; | |
| 93 | - rs = new ConvertUtil().groupMultiList(list, "_", clazz.getDeclaredField("nbbm"), clazz.getDeclaredField("jsy")); | |
| 94 | - } catch (Exception e) { | |
| 95 | - logger.error("", e); | |
| 96 | - } | |
| 97 | - return rs; | |
| 98 | - } | |
| 99 | - | |
| 100 | - /** | |
| 101 | - * 根据车辆和日期获取油耗数据,以 车辆_驾驶员 为key | |
| 102 | - * | |
| 103 | - * @param nbbmArray | |
| 104 | - * @param rq | |
| 105 | - * @return | |
| 106 | - */ | |
| 107 | - public Map<String, OilInfo> findByNbbmGroupRaw(Iterable<String> nbbmArray, String rq) { | |
| 108 | - Map<String, OilInfo> rs = new HashMap<>(); | |
| 109 | - | |
| 110 | - rq = rq.replaceAll("-", ""); | |
| 111 | - try { | |
| 112 | - List<OilInfo> list = new ArrayList<>(); | |
| 113 | - for (String nbbm : nbbmArray) { | |
| 114 | - nbbm = nbbm.split("_")[1]; | |
| 115 | - list.addAll(read(nbbm, rq)); | |
| 116 | - } | |
| 117 | - Class clazz = OilInfo.class; | |
| 118 | - rs = new ConvertUtil().groupList(list, "_", clazz.getDeclaredField("nbbm"), clazz.getDeclaredField("jsy")); | |
| 119 | - } catch (Exception e) { | |
| 120 | - logger.error("", e); | |
| 121 | - } | |
| 122 | - return rs; | |
| 123 | - } | |
| 124 | - | |
| 125 | - public List<OilInfo> read(String nbbm, String rq) { | |
| 126 | - return redisTemplate.opsForList().range(REDIS_KEY_PREFIX + nbbm + ":" + rq, 0, -1); | |
| 127 | - } | |
| 128 | - | |
| 129 | - /** | |
| 130 | - * 将 list 与redis里的数据合并 | |
| 131 | - * | |
| 132 | - * @param key | |
| 133 | - * @param list | |
| 134 | - */ | |
| 135 | - public void mergeData(String key, List<OilInfo> list) { | |
| 136 | - key = REDIS_KEY_PREFIX + key; | |
| 137 | - | |
| 138 | - //更新 直接覆盖更新 | |
| 139 | - redisTemplate.execute(redisUtils.getUpdateCallback(key, list)); | |
| 140 | - } | |
| 141 | - | |
| 142 | - @Autowired | |
| 143 | - OilRefreshThread oilRefreshThread; | |
| 144 | - | |
| 145 | - @Override | |
| 146 | - public void run(String... strings) throws Exception { | |
| 147 | - Application.mainServices.schedule(new Runnable() { | |
| 148 | - @Override | |
| 149 | - public void run() { | |
| 150 | - //启动加载油耗缓存 | |
| 151 | - synchData(null); | |
| 152 | - } | |
| 153 | - }, 30, TimeUnit.SECONDS); | |
| 154 | - | |
| 155 | - | |
| 156 | - //定时刷新油耗信息 | |
| 157 | - Application.mainServices.scheduleWithFixedDelay(oilRefreshThread, 60 * 40, 60 * 40, TimeUnit.SECONDS); | |
| 158 | - } | |
| 159 | - | |
| 160 | - /** | |
| 161 | - * 和数据库同步数据 | |
| 162 | - */ | |
| 163 | - public void synchData(Integer days) { | |
| 164 | - int cacheDays = Integer.parseInt(ConfigUtil.get("cache.days")); | |
| 165 | - if (null != days && days < cacheDays) | |
| 166 | - cacheDays = days; | |
| 167 | - //设置key 序列化器 | |
| 168 | - redisTemplate.setKeySerializer(new StringRedisSerializer()); | |
| 169 | - | |
| 170 | - DateTime dt = new DateTime(); | |
| 171 | - dt = dt.withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0).minusDays(cacheDays); | |
| 172 | - List<OilInfo> list = oilInfoRepository.findByDateLT(dt.toDate()); | |
| 173 | - //写入redis | |
| 174 | - wirte(list); | |
| 175 | - logger.info("刷新油耗数据, days: " + cacheDays + " -size: " + list.size() + " -LT: " + dt.toString("yyyy-MM-dd")); | |
| 176 | - } | |
| 177 | - | |
| 178 | - @Component | |
| 179 | - public static class OilRefreshThread extends Thread { | |
| 180 | - | |
| 181 | - @Autowired | |
| 182 | - OilRedisService oilRedisService; | |
| 183 | - | |
| 184 | - @Override | |
| 185 | - public void run() { | |
| 186 | - try { | |
| 187 | - oilRedisService.synchData(5); | |
| 188 | - } catch (Exception e) { | |
| 189 | - logger.error("", e); | |
| 190 | - } | |
| 191 | - } | |
| 192 | - } | |
| 193 | -} | |
| 1 | +package com.bsth.redis; | |
| 2 | + | |
| 3 | +import com.bsth.Application; | |
| 4 | +import com.bsth.entity.OilInfo; | |
| 5 | +import com.bsth.redis.util.RedisUtils; | |
| 6 | +import com.bsth.repository.OilInfoRepository; | |
| 7 | +import com.bsth.util.ConfigUtil; | |
| 8 | +import com.bsth.util.ConvertUtil; | |
| 9 | +import com.google.common.collect.ArrayListMultimap; | |
| 10 | +import org.joda.time.DateTime; | |
| 11 | +import org.slf4j.Logger; | |
| 12 | +import org.slf4j.LoggerFactory; | |
| 13 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 14 | +import org.springframework.boot.CommandLineRunner; | |
| 15 | +import org.springframework.core.annotation.Order; | |
| 16 | +import org.springframework.data.redis.core.RedisTemplate; | |
| 17 | +import org.springframework.data.redis.serializer.StringRedisSerializer; | |
| 18 | +import org.springframework.stereotype.Component; | |
| 19 | +import org.springframework.stereotype.Service; | |
| 20 | + | |
| 21 | +import java.util.*; | |
| 22 | +import java.util.concurrent.TimeUnit; | |
| 23 | + | |
| 24 | +/** | |
| 25 | + * 油量数据Redis缓存 | |
| 26 | + * Created by panzhao on 2017/3/19. | |
| 27 | + */ | |
| 28 | +@Service | |
| 29 | +@Order(3) | |
| 30 | +public class OilRedisService implements CommandLineRunner { | |
| 31 | + | |
| 32 | + @Autowired | |
| 33 | + private RedisTemplate redisTemplate; | |
| 34 | + | |
| 35 | + @Autowired | |
| 36 | + OilInfoRepository oilInfoRepository; | |
| 37 | + | |
| 38 | + @Autowired | |
| 39 | + RedisUtils redisUtils; | |
| 40 | + | |
| 41 | + static Logger logger = LoggerFactory.getLogger(OilRedisService.class); | |
| 42 | + | |
| 43 | + private final static String REDIS_KEY_PREFIX = "oil:"; | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * 将油量数据写入redis | |
| 47 | + * | |
| 48 | + * @param list | |
| 49 | + */ | |
| 50 | + public void wirte(List<OilInfo> list) { | |
| 51 | + ArrayListMultimap<String, OilInfo> multimap; | |
| 52 | + try { | |
| 53 | + if (list.size() == 0) | |
| 54 | + return; | |
| 55 | + //按日期和线路分组数据 | |
| 56 | + Class clazz = OilInfo.class; | |
| 57 | + multimap = new ConvertUtil().groupMultiList(list, ":", clazz.getDeclaredField("nbbm"), clazz.getDeclaredField("rq")); | |
| 58 | + | |
| 59 | + //写入redis | |
| 60 | + Iterator<String> iterator = multimap.keySet().iterator(); | |
| 61 | + String key; | |
| 62 | + while (iterator.hasNext()) { | |
| 63 | + key = iterator.next(); | |
| 64 | + mergeData(key, multimap.get(key)); | |
| 65 | + } | |
| 66 | + } catch (Exception e) { | |
| 67 | + logger.error("", e); | |
| 68 | + } | |
| 69 | + } | |
| 70 | + | |
| 71 | + /** | |
| 72 | + * 根据车辆和日期获取油耗数据,以 车辆_驾驶员 为key | |
| 73 | + * | |
| 74 | + * @param nbbmArray | |
| 75 | + * @param rq | |
| 76 | + * @return | |
| 77 | + */ | |
| 78 | + public ArrayListMultimap<String, OilInfo> findByNbbmGroup(Iterable<String> nbbmArray, String rq) { | |
| 79 | + ArrayListMultimap<String, OilInfo> rs = ArrayListMultimap.create(); | |
| 80 | + | |
| 81 | + rq = rq.replaceAll("-", ""); | |
| 82 | + try { | |
| 83 | + List<OilInfo> list = new ArrayList<>(); | |
| 84 | + Set<String> nbbms = new HashSet<>(); | |
| 85 | + for (String nbbm : nbbmArray) { | |
| 86 | + nbbm = nbbm.split("_")[1]; | |
| 87 | + if (!nbbms.contains(nbbm)) { | |
| 88 | + nbbms.add(nbbm); | |
| 89 | + list.addAll(read(nbbm, rq)); | |
| 90 | + } | |
| 91 | + } | |
| 92 | + Class clazz = OilInfo.class; | |
| 93 | + rs = new ConvertUtil().groupMultiList(list, "_", clazz.getDeclaredField("nbbm"), clazz.getDeclaredField("jsy")); | |
| 94 | + } catch (Exception e) { | |
| 95 | + logger.error("", e); | |
| 96 | + } | |
| 97 | + return rs; | |
| 98 | + } | |
| 99 | + | |
| 100 | + /** | |
| 101 | + * 根据车辆和日期获取油耗数据,以 车辆_驾驶员 为key | |
| 102 | + * | |
| 103 | + * @param nbbmArray | |
| 104 | + * @param rq | |
| 105 | + * @return | |
| 106 | + */ | |
| 107 | + public Map<String, OilInfo> findByNbbmGroupRaw(Iterable<String> nbbmArray, String rq) { | |
| 108 | + Map<String, OilInfo> rs = new HashMap<>(); | |
| 109 | + | |
| 110 | + rq = rq.replaceAll("-", ""); | |
| 111 | + try { | |
| 112 | + List<OilInfo> list = new ArrayList<>(); | |
| 113 | + for (String nbbm : nbbmArray) { | |
| 114 | + nbbm = nbbm.split("_")[1]; | |
| 115 | + list.addAll(read(nbbm, rq)); | |
| 116 | + } | |
| 117 | + Class clazz = OilInfo.class; | |
| 118 | + rs = new ConvertUtil().groupList(list, "_", clazz.getDeclaredField("nbbm"), clazz.getDeclaredField("jsy")); | |
| 119 | + } catch (Exception e) { | |
| 120 | + logger.error("", e); | |
| 121 | + } | |
| 122 | + return rs; | |
| 123 | + } | |
| 124 | + | |
| 125 | + /** | |
| 126 | + * 根据车辆和日期获取油耗数据,以 车辆 为key | |
| 127 | + * | |
| 128 | + * @param nbbmArray | |
| 129 | + * @param rq | |
| 130 | + * @return | |
| 131 | + */ | |
| 132 | + public ArrayListMultimap<String, OilInfo> findByNbbmGroup1(Iterable<String> nbbmArray, String rq) { | |
| 133 | + ArrayListMultimap<String, OilInfo> rs = ArrayListMultimap.create(); | |
| 134 | + | |
| 135 | + rq = rq.replaceAll("-", ""); | |
| 136 | + try { | |
| 137 | + List<OilInfo> list = new ArrayList<>(); | |
| 138 | + Set<String> nbbms = new HashSet<>(); | |
| 139 | + for (String nbbm : nbbmArray) { | |
| 140 | + if (!nbbms.contains(nbbm)) { | |
| 141 | + nbbms.add(nbbm); | |
| 142 | + list.addAll(read(nbbm, rq)); | |
| 143 | + } | |
| 144 | + } | |
| 145 | + Class clazz = OilInfo.class; | |
| 146 | + rs = new ConvertUtil().groupMultiList(list, "_", clazz.getDeclaredField("nbbm")); | |
| 147 | + } catch (Exception e) { | |
| 148 | + logger.error("", e); | |
| 149 | + } | |
| 150 | + return rs; | |
| 151 | + } | |
| 152 | + | |
| 153 | + public List<OilInfo> read(String nbbm, String rq) { | |
| 154 | + return redisTemplate.opsForList().range(REDIS_KEY_PREFIX + nbbm + ":" + rq, 0, -1); | |
| 155 | + } | |
| 156 | + | |
| 157 | + /** | |
| 158 | + * 将 list 与redis里的数据合并 | |
| 159 | + * | |
| 160 | + * @param key | |
| 161 | + * @param list | |
| 162 | + */ | |
| 163 | + public void mergeData(String key, List<OilInfo> list) { | |
| 164 | + key = REDIS_KEY_PREFIX + key; | |
| 165 | + | |
| 166 | + //更新 直接覆盖更新 | |
| 167 | + redisTemplate.execute(redisUtils.getUpdateCallback(key, list)); | |
| 168 | + } | |
| 169 | + | |
| 170 | + @Autowired | |
| 171 | + OilRefreshThread oilRefreshThread; | |
| 172 | + | |
| 173 | + @Override | |
| 174 | + public void run(String... strings) throws Exception { | |
| 175 | + Application.mainServices.schedule(new Runnable() { | |
| 176 | + @Override | |
| 177 | + public void run() { | |
| 178 | + //启动加载油耗缓存 | |
| 179 | + synchData(null); | |
| 180 | + } | |
| 181 | + }, 30, TimeUnit.SECONDS); | |
| 182 | + | |
| 183 | + | |
| 184 | + //定时刷新油耗信息 | |
| 185 | + Application.mainServices.scheduleWithFixedDelay(oilRefreshThread, 60 * 40, 60 * 40, TimeUnit.SECONDS); | |
| 186 | + } | |
| 187 | + | |
| 188 | + /** | |
| 189 | + * 和数据库同步数据 | |
| 190 | + */ | |
| 191 | + public void synchData(Integer days) { | |
| 192 | + int cacheDays = Integer.parseInt(ConfigUtil.get("cache.days")); | |
| 193 | + if (null != days && days < cacheDays) | |
| 194 | + cacheDays = days; | |
| 195 | + //设置key 序列化器 | |
| 196 | + redisTemplate.setKeySerializer(new StringRedisSerializer()); | |
| 197 | + | |
| 198 | + DateTime dt = new DateTime(); | |
| 199 | + dt = dt.withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0).minusDays(cacheDays); | |
| 200 | + List<OilInfo> list = oilInfoRepository.findByDateLT(dt.toDate()); | |
| 201 | + //写入redis | |
| 202 | + wirte(list); | |
| 203 | + logger.info("刷新油耗数据, days: " + cacheDays + " -size: " + list.size() + " -LT: " + dt.toString("yyyy-MM-dd")); | |
| 204 | + } | |
| 205 | + | |
| 206 | + @Component | |
| 207 | + public static class OilRefreshThread extends Thread { | |
| 208 | + | |
| 209 | + @Autowired | |
| 210 | + OilRedisService oilRedisService; | |
| 211 | + | |
| 212 | + @Override | |
| 213 | + public void run() { | |
| 214 | + try { | |
| 215 | + oilRedisService.synchData(5); | |
| 216 | + } catch (Exception e) { | |
| 217 | + logger.error("", e); | |
| 218 | + } | |
| 219 | + } | |
| 220 | + } | |
| 221 | +} | ... | ... |
src/main/java/com/bsth/redis/ScheduleRedisService.java
| 1 | -package com.bsth.redis; | |
| 2 | - | |
| 3 | -import com.bsth.Application; | |
| 4 | -import com.bsth.common.BasicData; | |
| 5 | -import com.bsth.entity.ScheduleRealInfo; | |
| 6 | -import com.bsth.redis.util.RedisUtils; | |
| 7 | -import com.bsth.repository.ScheduleRealInfoRepository; | |
| 8 | -import com.bsth.server_rs.base_info.line.Line; | |
| 9 | -import com.bsth.server_rs.base_info.line.buffer.LineBufferData; | |
| 10 | -import com.bsth.util.ConfigUtil; | |
| 11 | -import com.bsth.util.ConvertUtil; | |
| 12 | -import com.google.common.collect.ArrayListMultimap; | |
| 13 | -import org.apache.commons.lang3.StringUtils; | |
| 14 | -import org.joda.time.DateTime; | |
| 15 | -import org.joda.time.format.DateTimeFormat; | |
| 16 | -import org.joda.time.format.DateTimeFormatter; | |
| 17 | -import org.slf4j.Logger; | |
| 18 | -import org.slf4j.LoggerFactory; | |
| 19 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 20 | -import org.springframework.boot.CommandLineRunner; | |
| 21 | -import org.springframework.core.annotation.Order; | |
| 22 | -import org.springframework.data.redis.core.ListOperations; | |
| 23 | -import org.springframework.data.redis.core.RedisTemplate; | |
| 24 | -import org.springframework.data.redis.serializer.StringRedisSerializer; | |
| 25 | -import org.springframework.stereotype.Component; | |
| 26 | -import org.springframework.stereotype.Service; | |
| 27 | - | |
| 28 | -import java.util.ArrayList; | |
| 29 | -import java.util.Iterator; | |
| 30 | -import java.util.List; | |
| 31 | -import java.util.concurrent.TimeUnit; | |
| 32 | - | |
| 33 | -/** | |
| 34 | - * 班次 redis 缓存管理 | |
| 35 | - * Created by panzhao on 2017/3/13. | |
| 36 | - */ | |
| 37 | -@Service | |
| 38 | -@Order(2) | |
| 39 | -public class ScheduleRedisService implements CommandLineRunner { | |
| 40 | - | |
| 41 | - @Autowired | |
| 42 | - ScheduleRealInfoRepository scheduleRealInfoRepository; | |
| 43 | - | |
| 44 | - private final static String REDIS_KEY_PREFIX = "schedule:"; | |
| 45 | - | |
| 46 | - @Autowired | |
| 47 | - private RedisTemplate redisTemplate; | |
| 48 | - | |
| 49 | - @Autowired | |
| 50 | - RedisUtils redisUtils; | |
| 51 | - | |
| 52 | - static Logger logger = LoggerFactory.getLogger(ScheduleRedisService.class); | |
| 53 | - | |
| 54 | - private final static long DAY_TIME = 1000 * 60 * 60 * 24L; | |
| 55 | - | |
| 56 | - /** | |
| 57 | - * 将一批班次写入redis | |
| 58 | - * | |
| 59 | - * @param list | |
| 60 | - */ | |
| 61 | - public void wirte(List<ScheduleRealInfo> list) { | |
| 62 | - ArrayListMultimap<String, ScheduleRealInfo> multimap; | |
| 63 | - try { | |
| 64 | - if (list.size() == 0) | |
| 65 | - return; | |
| 66 | - //按日期和线路分组数据 | |
| 67 | - Class clazz = ScheduleRealInfo.class; | |
| 68 | - multimap = new ConvertUtil().groupMultiList(list, ":", clazz.getDeclaredField("xlBm"), clazz.getDeclaredField("scheduleDateStr")); | |
| 69 | - | |
| 70 | - //写入redis | |
| 71 | - Iterator<String> iterator = multimap.keySet().iterator(); | |
| 72 | - String key; | |
| 73 | - while (iterator.hasNext()) { | |
| 74 | - key = iterator.next(); | |
| 75 | - replace(key, multimap.get(key)); | |
| 76 | - } | |
| 77 | - } catch (Exception e) { | |
| 78 | - logger.error("", e); | |
| 79 | - } | |
| 80 | - } | |
| 81 | - | |
| 82 | - /** | |
| 83 | - * 将 list 与redis里的数据合并 | |
| 84 | - * | |
| 85 | - * @param key | |
| 86 | - * @param list | |
| 87 | - */ | |
| 88 | - public void mergeData(String key, List<ScheduleRealInfo> list) { | |
| 89 | - key = REDIS_KEY_PREFIX + key.replaceAll("-", ""); | |
| 90 | - | |
| 91 | - ListOperations<String, ScheduleRealInfo> ops = redisTemplate.opsForList(); | |
| 92 | - List<ScheduleRealInfo> cacheList = ops.range(key, 0, -1); | |
| 93 | - | |
| 94 | - for (ScheduleRealInfo sch : cacheList) { | |
| 95 | - if (!list.contains(sch)) | |
| 96 | - list.add(sch); | |
| 97 | - } | |
| 98 | - | |
| 99 | - //更新 | |
| 100 | - redisTemplate.execute(redisUtils.getUpdateCallback(key, list)); | |
| 101 | - } | |
| 102 | - | |
| 103 | - /** | |
| 104 | - * 覆盖数据 | |
| 105 | - * | |
| 106 | - * @param key | |
| 107 | - * @param list | |
| 108 | - */ | |
| 109 | - public void replace(String key, List<ScheduleRealInfo> list) { | |
| 110 | - key = REDIS_KEY_PREFIX + key.replaceAll("-", ""); | |
| 111 | - redisTemplate.execute(redisUtils.getUpdateCallback(key, list)); | |
| 112 | - } | |
| 113 | - | |
| 114 | - /** | |
| 115 | - * 删除数据 | |
| 116 | - * | |
| 117 | - * @param key | |
| 118 | - */ | |
| 119 | - public void delete(String lineCode, String rq) { | |
| 120 | - String key = REDIS_KEY_PREFIX + (lineCode + ":" + rq).replaceAll("-", ""); | |
| 121 | - redisTemplate.delete(key); | |
| 122 | - } | |
| 123 | - | |
| 124 | - /** | |
| 125 | - * 根据日期和线路编码从redis获取班次 | |
| 126 | - * | |
| 127 | - * @param dateStr | |
| 128 | - * @param lineCode | |
| 129 | - * @return | |
| 130 | - */ | |
| 131 | - public List<ScheduleRealInfo> read(String dateStr, String lineCode) { | |
| 132 | - return redisTemplate.opsForList().range(REDIS_KEY_PREFIX + lineCode + ":" + dateStr, 0, -1); | |
| 133 | - } | |
| 134 | - | |
| 135 | - /** | |
| 136 | - * 返回指定日期,公司的实际排班,并按线路_车辆分组 | |
| 137 | - * | |
| 138 | - * @param rq | |
| 139 | - * @param companyId | |
| 140 | - * @return | |
| 141 | - */ | |
| 142 | - public ArrayListMultimap<String, ScheduleRealInfo> findByDateAndGroupByNbbm(String rq, String companyId) { | |
| 143 | - List<String> lineArray = LineBufferData.findCodesByCompany(companyId); | |
| 144 | - ArrayListMultimap<String, ScheduleRealInfo> rs = ArrayListMultimap.create(); | |
| 145 | - | |
| 146 | - rq = rq.replaceAll("-", ""); | |
| 147 | - List<ScheduleRealInfo> list; | |
| 148 | - for (String lineCode : lineArray) { | |
| 149 | - | |
| 150 | - list = read(rq, lineCode); | |
| 151 | - | |
| 152 | - for (ScheduleRealInfo sch : list) { | |
| 153 | - rs.put(sch.getXlBm() + "_" + sch.getClZbh(), sch); | |
| 154 | - } | |
| 155 | - } | |
| 156 | - return rs; | |
| 157 | - } | |
| 158 | - | |
| 159 | - /** | |
| 160 | - * 返回指定日期,公司的实际排班,并按线路分组 | |
| 161 | - * | |
| 162 | - * @param rq | |
| 163 | - * @param companyId | |
| 164 | - * @return | |
| 165 | - */ | |
| 166 | - public ArrayListMultimap<String, ScheduleRealInfo> findByDateAndGroupByLine(String rq, String companyId) { | |
| 167 | - | |
| 168 | - List<String> lineArray = LineBufferData.findCodesByCompany(companyId); | |
| 169 | - ArrayListMultimap<String, ScheduleRealInfo> rs = ArrayListMultimap.create(); | |
| 170 | - | |
| 171 | - rq = rq.replaceAll("-", ""); | |
| 172 | - List<ScheduleRealInfo> list; | |
| 173 | - for (String lineCode : lineArray) { | |
| 174 | - | |
| 175 | - list = read(rq, lineCode); | |
| 176 | - | |
| 177 | - for (ScheduleRealInfo sch : list) { | |
| 178 | - rs.put(sch.getXlBm(), sch); | |
| 179 | - } | |
| 180 | - } | |
| 181 | - return rs; | |
| 182 | - } | |
| 183 | - | |
| 184 | - @Autowired | |
| 185 | - ScheduleRefreshThread scheduleRefreshThread; | |
| 186 | - @Autowired | |
| 187 | - ScheduleClearThread scheduleClearThread; | |
| 188 | - | |
| 189 | - @Override | |
| 190 | - public void run(String... strings) throws Exception { | |
| 191 | - //用子线程去加载,,不要阻塞 | |
| 192 | - Application.mainServices.schedule(new Runnable() { | |
| 193 | - @Override | |
| 194 | - public void run() { | |
| 195 | - try { | |
| 196 | - logger.info("redis 实际排班 start..."); | |
| 197 | - int cacheDays = Integer.parseInt(ConfigUtil.get("cache.days")); | |
| 198 | - //设置key 序列化器 | |
| 199 | - redisTemplate.setKeySerializer(new StringRedisSerializer()); | |
| 200 | - | |
| 201 | - DateTime dt = new DateTime(); | |
| 202 | - dt = dt.minusDays(cacheDays); | |
| 203 | - List<ScheduleRealInfo> list = scheduleRealInfoRepository.findByDateLT(dt.toString("yyyy-MM-dd")); | |
| 204 | - calcTime(list); | |
| 205 | - //写入redis | |
| 206 | - wirte(list); | |
| 207 | - logger.info("redis 实际排班 over..."); | |
| 208 | - } catch (Exception e) { | |
| 209 | - logger.info("redis 实际排班 异常", e); | |
| 210 | - } | |
| 211 | - } | |
| 212 | - }, 5, TimeUnit.SECONDS); | |
| 213 | - | |
| 214 | - //定时刷新一次当日实际排班 | |
| 215 | - int minute = 5; | |
| 216 | - Application.mainServices.scheduleWithFixedDelay(scheduleRefreshThread, minute, minute, TimeUnit.MINUTES); | |
| 217 | - //24小时清理一次实际排班数据 | |
| 218 | - Application.mainServices.scheduleWithFixedDelay(scheduleClearThread, 24, 24, TimeUnit.HOURS); | |
| 219 | - } | |
| 220 | - | |
| 221 | - public List<ScheduleRealInfo> findByMultiLine(List<String> lineArray, String rq) { | |
| 222 | - rq = rq.replaceAll("-", ""); | |
| 223 | - List<ScheduleRealInfo> rs = new ArrayList<>(); | |
| 224 | - for (String lineCode : lineArray) { | |
| 225 | - rs.addAll(read(rq, lineCode)); | |
| 226 | - } | |
| 227 | - return rs; | |
| 228 | - } | |
| 229 | - | |
| 230 | - @Component | |
| 231 | - public static class ScheduleRefreshThread extends Thread { | |
| 232 | - | |
| 233 | - @Autowired | |
| 234 | - ScheduleRealInfoRepository realInfoRepository; | |
| 235 | - | |
| 236 | - @Autowired | |
| 237 | - ScheduleRedisService scheduleRedisService; | |
| 238 | - | |
| 239 | - @Override | |
| 240 | - public void run() { | |
| 241 | - try { | |
| 242 | - DateTime dt = new DateTime(); | |
| 243 | - DateTime yesterday = dt.minusDays(2); | |
| 244 | - | |
| 245 | - String rq = yesterday.toString("yyyy-MM-dd"); | |
| 246 | - logger.info("refresh lt yesterday ..." + rq + " -start"); | |
| 247 | - List<ScheduleRealInfo> list = realInfoRepository.findByDateLT(rq); | |
| 248 | - | |
| 249 | - //计算时间戳 | |
| 250 | - scheduleRedisService.calcTime(list); | |
| 251 | - scheduleRedisService.wirte(list); | |
| 252 | - | |
| 253 | - logger.info("refresh lt yesterday ..." + rq + " -end### size: " + list.size()); | |
| 254 | - } catch (Exception e) { | |
| 255 | - logger.error("", e); | |
| 256 | - } | |
| 257 | - } | |
| 258 | - } | |
| 259 | - | |
| 260 | - @Component | |
| 261 | - public static class ScheduleClearThread extends Thread { | |
| 262 | - | |
| 263 | - @Autowired | |
| 264 | - ScheduleRedisService scheduleRedisService; | |
| 265 | - | |
| 266 | - @Override | |
| 267 | - public void run() { | |
| 268 | - try { | |
| 269 | - int cacheDays = Integer.parseInt(ConfigUtil.get("cache.days")); | |
| 270 | - DateTime dt = new DateTime(); | |
| 271 | - dt = dt.minusDays(cacheDays); | |
| 272 | - String rq = dt.toString("yyyy-MM-dd"); | |
| 273 | - | |
| 274 | - List<Line> lines = LineBufferData.findAll(); | |
| 275 | - for (Line line : lines) { | |
| 276 | - scheduleRedisService.delete(line.getLineCode(), rq); | |
| 277 | - } | |
| 278 | - } catch (Exception e) { | |
| 279 | - logger.error("", e); | |
| 280 | - } | |
| 281 | - } | |
| 282 | - } | |
| 283 | - | |
| 284 | - /** | |
| 285 | - * ############ 时间戳计算 ########## | |
| 286 | - */ | |
| 287 | - private static DateTimeFormatter fmtyyyyMMddHHmm = DateTimeFormat.forPattern("yyyy-MM-ddHH:mm"), | |
| 288 | - fmtHHmm = DateTimeFormat.forPattern("HH:mm"); | |
| 289 | - | |
| 290 | - public void calcTime(List<ScheduleRealInfo> list) { | |
| 291 | - if (list.size() == 0) | |
| 292 | - return; | |
| 293 | - | |
| 294 | - //计算真实执行日期 和 时间戳 | |
| 295 | - for (ScheduleRealInfo sch : list) { | |
| 296 | - calcRealDate(BasicData.lineStartTimeMap.get(sch.getXlBm()), sch); | |
| 297 | - } | |
| 298 | - } | |
| 299 | - | |
| 300 | - /** | |
| 301 | - * @Title: calcRealDate | |
| 302 | - * @Description: TODO(计算班次的真实执行日期) | |
| 303 | - */ | |
| 304 | - public void calcRealDate(String startTime, ScheduleRealInfo sch) { | |
| 305 | - try { | |
| 306 | - if (null == startTime) | |
| 307 | - return; | |
| 308 | - | |
| 309 | - if (null == sch.getBcsj()) | |
| 310 | - sch.setBcsj(0); | |
| 311 | - | |
| 312 | - String rq = sch.getScheduleDateStr(); | |
| 313 | - //计发时间 | |
| 314 | - sch.setFcsjT(parseTime(rq, sch.getFcsj(), startTime)); | |
| 315 | - //待发时间 | |
| 316 | - sch.setDfsjT(parseTime(rq, sch.getDfsj(), startTime)); | |
| 317 | - //计划终点时间 | |
| 318 | - if (StringUtils.isEmpty(sch.getZdsj())) { | |
| 319 | - sch.setZdsjT(sch.getFcsjT() + (sch.getBcsj() * 60 * 1000)); | |
| 320 | - sch.setZdsj(fmtHHmm.print(sch.getZdsjT())); | |
| 321 | - } else | |
| 322 | - sch.setZdsjT(sch.getFcsjT() + (sch.getBcsj() * 60 * 1000)); | |
| 323 | - //实发时间 | |
| 324 | - if (StringUtils.isNotEmpty(sch.getFcsjActual())) | |
| 325 | - sch.setFcsjActualAll(parseTime(rq, sch.getFcsjActual(), startTime)); | |
| 326 | - | |
| 327 | - //实达时间 | |
| 328 | - if (StringUtils.isNotEmpty(sch.getZdsjActual())) | |
| 329 | - sch.setZdsjActualAll(parseTime(rq, sch.getZdsjActual(), startTime)); | |
| 330 | - } catch (Exception e) { | |
| 331 | - logger.error("", e); | |
| 332 | - } | |
| 333 | - } | |
| 334 | - | |
| 335 | - private long parseTime(String rq, String sj, String startTime) { | |
| 336 | - long t = fmtyyyyMMddHHmm.parseMillis(rq + sj); | |
| 337 | - if (sj.compareTo(startTime) < 0) { | |
| 338 | - t += DAY_TIME; | |
| 339 | - } | |
| 340 | - return t; | |
| 341 | - } | |
| 342 | -} | |
| 1 | +package com.bsth.redis; | |
| 2 | + | |
| 3 | +import com.bsth.Application; | |
| 4 | +import com.bsth.common.BasicData; | |
| 5 | +import com.bsth.entity.ScheduleRealInfo; | |
| 6 | +import com.bsth.redis.util.RedisUtils; | |
| 7 | +import com.bsth.repository.ScheduleRealInfoRepository; | |
| 8 | +import com.bsth.server_rs.base_info.line.Line; | |
| 9 | +import com.bsth.server_rs.base_info.line.buffer.LineBufferData; | |
| 10 | +import com.bsth.util.ConfigUtil; | |
| 11 | +import com.bsth.util.ConvertUtil; | |
| 12 | +import com.google.common.collect.ArrayListMultimap; | |
| 13 | +import org.apache.commons.lang3.StringUtils; | |
| 14 | +import org.joda.time.DateTime; | |
| 15 | +import org.joda.time.format.DateTimeFormat; | |
| 16 | +import org.joda.time.format.DateTimeFormatter; | |
| 17 | +import org.slf4j.Logger; | |
| 18 | +import org.slf4j.LoggerFactory; | |
| 19 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 20 | +import org.springframework.boot.CommandLineRunner; | |
| 21 | +import org.springframework.core.annotation.Order; | |
| 22 | +import org.springframework.data.redis.core.ListOperations; | |
| 23 | +import org.springframework.data.redis.core.RedisTemplate; | |
| 24 | +import org.springframework.data.redis.serializer.StringRedisSerializer; | |
| 25 | +import org.springframework.stereotype.Component; | |
| 26 | +import org.springframework.stereotype.Service; | |
| 27 | + | |
| 28 | +import java.util.ArrayList; | |
| 29 | +import java.util.Iterator; | |
| 30 | +import java.util.List; | |
| 31 | +import java.util.concurrent.TimeUnit; | |
| 32 | + | |
| 33 | +/** | |
| 34 | + * 班次 redis 缓存管理 | |
| 35 | + * Created by panzhao on 2017/3/13. | |
| 36 | + */ | |
| 37 | +@Service | |
| 38 | +@Order(2) | |
| 39 | +public class ScheduleRedisService implements CommandLineRunner { | |
| 40 | + | |
| 41 | + @Autowired | |
| 42 | + ScheduleRealInfoRepository scheduleRealInfoRepository; | |
| 43 | + | |
| 44 | + private final static String REDIS_KEY_PREFIX = "schedule:"; | |
| 45 | + | |
| 46 | + @Autowired | |
| 47 | + private RedisTemplate redisTemplate; | |
| 48 | + | |
| 49 | + @Autowired | |
| 50 | + RedisUtils redisUtils; | |
| 51 | + | |
| 52 | + static Logger logger = LoggerFactory.getLogger(ScheduleRedisService.class); | |
| 53 | + | |
| 54 | + private final static long DAY_TIME = 1000 * 60 * 60 * 24L; | |
| 55 | + | |
| 56 | + /** | |
| 57 | + * 将一批班次写入redis | |
| 58 | + * | |
| 59 | + * @param list | |
| 60 | + */ | |
| 61 | + public void wirte(List<ScheduleRealInfo> list) { | |
| 62 | + ArrayListMultimap<String, ScheduleRealInfo> multimap; | |
| 63 | + try { | |
| 64 | + if (list.size() == 0) | |
| 65 | + return; | |
| 66 | + //按日期和线路分组数据 | |
| 67 | + Class clazz = ScheduleRealInfo.class; | |
| 68 | + multimap = new ConvertUtil().groupMultiList(list, ":", clazz.getDeclaredField("xlBm"), clazz.getDeclaredField("scheduleDateStr")); | |
| 69 | + | |
| 70 | + //写入redis | |
| 71 | + Iterator<String> iterator = multimap.keySet().iterator(); | |
| 72 | + String key; | |
| 73 | + while (iterator.hasNext()) { | |
| 74 | + key = iterator.next(); | |
| 75 | + replace(key, multimap.get(key)); | |
| 76 | + } | |
| 77 | + } catch (Exception e) { | |
| 78 | + logger.error("", e); | |
| 79 | + } | |
| 80 | + } | |
| 81 | + | |
| 82 | + /** | |
| 83 | + * 将 list 与redis里的数据合并 | |
| 84 | + * | |
| 85 | + * @param key | |
| 86 | + * @param list | |
| 87 | + */ | |
| 88 | + public void mergeData(String key, List<ScheduleRealInfo> list) { | |
| 89 | + key = REDIS_KEY_PREFIX + key.replaceAll("-", ""); | |
| 90 | + | |
| 91 | + ListOperations<String, ScheduleRealInfo> ops = redisTemplate.opsForList(); | |
| 92 | + List<ScheduleRealInfo> cacheList = ops.range(key, 0, -1); | |
| 93 | + | |
| 94 | + for (ScheduleRealInfo sch : cacheList) { | |
| 95 | + if (!list.contains(sch)) | |
| 96 | + list.add(sch); | |
| 97 | + } | |
| 98 | + | |
| 99 | + //更新 | |
| 100 | + redisTemplate.execute(redisUtils.getUpdateCallback(key, list)); | |
| 101 | + } | |
| 102 | + | |
| 103 | + /** | |
| 104 | + * 覆盖数据 | |
| 105 | + * | |
| 106 | + * @param key | |
| 107 | + * @param list | |
| 108 | + */ | |
| 109 | + public void replace(String key, List<ScheduleRealInfo> list) { | |
| 110 | + key = REDIS_KEY_PREFIX + key.replaceAll("-", ""); | |
| 111 | + redisTemplate.execute(redisUtils.getUpdateCallback(key, list)); | |
| 112 | + } | |
| 113 | + | |
| 114 | + /** | |
| 115 | + * 删除数据 | |
| 116 | + * | |
| 117 | + * @param key | |
| 118 | + */ | |
| 119 | + public void delete(String lineCode, String rq) { | |
| 120 | + String key = REDIS_KEY_PREFIX + (lineCode + ":" + rq).replaceAll("-", ""); | |
| 121 | + redisTemplate.delete(key); | |
| 122 | + } | |
| 123 | + | |
| 124 | + /** | |
| 125 | + * 根据日期和线路编码从redis获取班次 | |
| 126 | + * | |
| 127 | + * @param dateStr | |
| 128 | + * @param lineCode | |
| 129 | + * @return | |
| 130 | + */ | |
| 131 | + public List<ScheduleRealInfo> read(String dateStr, String lineCode) { | |
| 132 | + return redisTemplate.opsForList().range(REDIS_KEY_PREFIX + lineCode + ":" + dateStr, 0, -1); | |
| 133 | + } | |
| 134 | + | |
| 135 | + /** | |
| 136 | + * 返回指定日期,公司的实际排班,并按线路_车辆分组 | |
| 137 | + * | |
| 138 | + * @param rq | |
| 139 | + * @param companyId | |
| 140 | + * @return | |
| 141 | + */ | |
| 142 | + public ArrayListMultimap<String, ScheduleRealInfo> findByDateAndGroupByNbbm(String rq, String companyId) { | |
| 143 | + List<String> lineArray = LineBufferData.findCodesByCompany(companyId); | |
| 144 | + ArrayListMultimap<String, ScheduleRealInfo> rs = ArrayListMultimap.create(); | |
| 145 | + | |
| 146 | + rq = rq.replaceAll("-", ""); | |
| 147 | + List<ScheduleRealInfo> list; | |
| 148 | + for (String lineCode : lineArray) { | |
| 149 | + | |
| 150 | + list = read(rq, lineCode); | |
| 151 | + | |
| 152 | + for (ScheduleRealInfo sch : list) { | |
| 153 | + rs.put(sch.getXlBm() + "_" + sch.getClZbh(), sch); | |
| 154 | + } | |
| 155 | + } | |
| 156 | + return rs; | |
| 157 | + } | |
| 158 | + | |
| 159 | + /** | |
| 160 | + * 返回指定日期,公司的实际排班,并按线路分组 | |
| 161 | + * | |
| 162 | + * @param rq | |
| 163 | + * @param companyId | |
| 164 | + * @return | |
| 165 | + */ | |
| 166 | + public ArrayListMultimap<String, ScheduleRealInfo> findByDateAndGroupByLine(String rq, String companyId) { | |
| 167 | + | |
| 168 | + List<String> lineArray = LineBufferData.findCodesByCompany(companyId); | |
| 169 | + ArrayListMultimap<String, ScheduleRealInfo> rs = ArrayListMultimap.create(); | |
| 170 | + | |
| 171 | + rq = rq.replaceAll("-", ""); | |
| 172 | + List<ScheduleRealInfo> list; | |
| 173 | + for (String lineCode : lineArray) { | |
| 174 | + | |
| 175 | + list = read(rq, lineCode); | |
| 176 | + | |
| 177 | + for (ScheduleRealInfo sch : list) { | |
| 178 | + rs.put(sch.getXlBm(), sch); | |
| 179 | + } | |
| 180 | + } | |
| 181 | + return rs; | |
| 182 | + } | |
| 183 | + | |
| 184 | + /** | |
| 185 | + * 返回指定日期,所有实际排班,并按自编号分组 | |
| 186 | + * | |
| 187 | + * @param rq | |
| 188 | + * @return | |
| 189 | + */ | |
| 190 | + public ArrayListMultimap<String, ScheduleRealInfo> findByDate(String rq) { | |
| 191 | + | |
| 192 | + List<Line> lines = LineBufferData.findAll(); | |
| 193 | + ArrayListMultimap<String, ScheduleRealInfo> rs = ArrayListMultimap.create(); | |
| 194 | + | |
| 195 | + rq = rq.replaceAll("-", ""); | |
| 196 | + List<ScheduleRealInfo> list; | |
| 197 | + for (Line line : lines) { | |
| 198 | + | |
| 199 | + list = read(rq, line.getLineCode()); | |
| 200 | + | |
| 201 | + for (ScheduleRealInfo sch : list) { | |
| 202 | + rs.put(sch.getClZbh(), sch); | |
| 203 | + } | |
| 204 | + } | |
| 205 | + return rs; | |
| 206 | + } | |
| 207 | + | |
| 208 | + @Autowired | |
| 209 | + ScheduleRefreshThread scheduleRefreshThread; | |
| 210 | + @Autowired | |
| 211 | + ScheduleClearThread scheduleClearThread; | |
| 212 | + | |
| 213 | + @Override | |
| 214 | + public void run(String... strings) throws Exception { | |
| 215 | + //用子线程去加载,,不要阻塞 | |
| 216 | + Application.mainServices.schedule(new Runnable() { | |
| 217 | + @Override | |
| 218 | + public void run() { | |
| 219 | + try { | |
| 220 | + logger.info("redis 实际排班 start..."); | |
| 221 | + int cacheDays = Integer.parseInt(ConfigUtil.get("cache.days")); | |
| 222 | + //设置key 序列化器 | |
| 223 | + redisTemplate.setKeySerializer(new StringRedisSerializer()); | |
| 224 | + | |
| 225 | + DateTime dt = new DateTime(); | |
| 226 | + dt = dt.minusDays(cacheDays); | |
| 227 | + List<ScheduleRealInfo> list = scheduleRealInfoRepository.findByDateLT(dt.toString("yyyy-MM-dd")); | |
| 228 | + calcTime(list); | |
| 229 | + //写入redis | |
| 230 | + wirte(list); | |
| 231 | + logger.info("redis 实际排班 over..."); | |
| 232 | + } catch (Exception e) { | |
| 233 | + logger.info("redis 实际排班 异常", e); | |
| 234 | + } | |
| 235 | + } | |
| 236 | + }, 5, TimeUnit.SECONDS); | |
| 237 | + | |
| 238 | + //定时刷新一次当日实际排班 | |
| 239 | + int minute = 5; | |
| 240 | + Application.mainServices.scheduleWithFixedDelay(scheduleRefreshThread, minute, minute, TimeUnit.MINUTES); | |
| 241 | + //24小时清理一次实际排班数据 | |
| 242 | + Application.mainServices.scheduleWithFixedDelay(scheduleClearThread, 24, 24, TimeUnit.HOURS); | |
| 243 | + } | |
| 244 | + | |
| 245 | + public List<ScheduleRealInfo> findByMultiLine(List<String> lineArray, String rq) { | |
| 246 | + rq = rq.replaceAll("-", ""); | |
| 247 | + List<ScheduleRealInfo> rs = new ArrayList<>(); | |
| 248 | + for (String lineCode : lineArray) { | |
| 249 | + rs.addAll(read(rq, lineCode)); | |
| 250 | + } | |
| 251 | + return rs; | |
| 252 | + } | |
| 253 | + | |
| 254 | + @Component | |
| 255 | + public static class ScheduleRefreshThread extends Thread { | |
| 256 | + | |
| 257 | + @Autowired | |
| 258 | + ScheduleRealInfoRepository realInfoRepository; | |
| 259 | + | |
| 260 | + @Autowired | |
| 261 | + ScheduleRedisService scheduleRedisService; | |
| 262 | + | |
| 263 | + @Override | |
| 264 | + public void run() { | |
| 265 | + try { | |
| 266 | + DateTime dt = new DateTime(); | |
| 267 | + DateTime yesterday = dt.minusDays(2); | |
| 268 | + | |
| 269 | + String rq = yesterday.toString("yyyy-MM-dd"); | |
| 270 | + logger.info("refresh lt yesterday ..." + rq + " -start"); | |
| 271 | + List<ScheduleRealInfo> list = realInfoRepository.findByDateLT(rq); | |
| 272 | + | |
| 273 | + //计算时间戳 | |
| 274 | + scheduleRedisService.calcTime(list); | |
| 275 | + scheduleRedisService.wirte(list); | |
| 276 | + | |
| 277 | + logger.info("refresh lt yesterday ..." + rq + " -end### size: " + list.size()); | |
| 278 | + } catch (Exception e) { | |
| 279 | + logger.error("", e); | |
| 280 | + } | |
| 281 | + } | |
| 282 | + } | |
| 283 | + | |
| 284 | + @Component | |
| 285 | + public static class ScheduleClearThread extends Thread { | |
| 286 | + | |
| 287 | + @Autowired | |
| 288 | + ScheduleRedisService scheduleRedisService; | |
| 289 | + | |
| 290 | + @Override | |
| 291 | + public void run() { | |
| 292 | + try { | |
| 293 | + int cacheDays = Integer.parseInt(ConfigUtil.get("cache.days")); | |
| 294 | + DateTime dt = new DateTime(); | |
| 295 | + dt = dt.minusDays(cacheDays); | |
| 296 | + String rq = dt.toString("yyyy-MM-dd"); | |
| 297 | + | |
| 298 | + List<Line> lines = LineBufferData.findAll(); | |
| 299 | + for (Line line : lines) { | |
| 300 | + scheduleRedisService.delete(line.getLineCode(), rq); | |
| 301 | + } | |
| 302 | + } catch (Exception e) { | |
| 303 | + logger.error("", e); | |
| 304 | + } | |
| 305 | + } | |
| 306 | + } | |
| 307 | + | |
| 308 | + /** | |
| 309 | + * ############ 时间戳计算 ########## | |
| 310 | + */ | |
| 311 | + private static DateTimeFormatter fmtyyyyMMddHHmm = DateTimeFormat.forPattern("yyyy-MM-ddHH:mm"), | |
| 312 | + fmtHHmm = DateTimeFormat.forPattern("HH:mm"); | |
| 313 | + | |
| 314 | + public void calcTime(List<ScheduleRealInfo> list) { | |
| 315 | + if (list.size() == 0) | |
| 316 | + return; | |
| 317 | + | |
| 318 | + //计算真实执行日期 和 时间戳 | |
| 319 | + for (ScheduleRealInfo sch : list) { | |
| 320 | + calcRealDate(BasicData.lineStartTimeMap.get(sch.getXlBm()), sch); | |
| 321 | + } | |
| 322 | + } | |
| 323 | + | |
| 324 | + /** | |
| 325 | + * @Title: calcRealDate | |
| 326 | + * @Description: TODO(计算班次的真实执行日期) | |
| 327 | + */ | |
| 328 | + public void calcRealDate(String startTime, ScheduleRealInfo sch) { | |
| 329 | + try { | |
| 330 | + if (null == startTime) | |
| 331 | + return; | |
| 332 | + | |
| 333 | + if (null == sch.getBcsj()) | |
| 334 | + sch.setBcsj(0); | |
| 335 | + | |
| 336 | + String rq = sch.getScheduleDateStr(); | |
| 337 | + //计发时间 | |
| 338 | + sch.setFcsjT(parseTime(rq, sch.getFcsj(), startTime)); | |
| 339 | + //待发时间 | |
| 340 | + sch.setDfsjT(parseTime(rq, sch.getDfsj(), startTime)); | |
| 341 | + //计划终点时间 | |
| 342 | + if (StringUtils.isEmpty(sch.getZdsj())) { | |
| 343 | + sch.setZdsjT(sch.getFcsjT() + (sch.getBcsj() * 60 * 1000)); | |
| 344 | + sch.setZdsj(fmtHHmm.print(sch.getZdsjT())); | |
| 345 | + } else | |
| 346 | + sch.setZdsjT(sch.getFcsjT() + (sch.getBcsj() * 60 * 1000)); | |
| 347 | + //实发时间 | |
| 348 | + if (StringUtils.isNotEmpty(sch.getFcsjActual())) | |
| 349 | + sch.setFcsjActualAll(parseTime(rq, sch.getFcsjActual(), startTime)); | |
| 350 | + | |
| 351 | + //实达时间 | |
| 352 | + if (StringUtils.isNotEmpty(sch.getZdsjActual())) | |
| 353 | + sch.setZdsjActualAll(parseTime(rq, sch.getZdsjActual(), startTime)); | |
| 354 | + } catch (Exception e) { | |
| 355 | + logger.error("", e); | |
| 356 | + } | |
| 357 | + } | |
| 358 | + | |
| 359 | + private long parseTime(String rq, String sj, String startTime) { | |
| 360 | + long t = fmtyyyyMMddHHmm.parseMillis(rq + sj); | |
| 361 | + if (sj.compareTo(startTime) < 0) { | |
| 362 | + t += DAY_TIME; | |
| 363 | + } | |
| 364 | + return t; | |
| 365 | + } | |
| 366 | +} | ... | ... |
src/main/java/com/bsth/repository/SchedulePlanInfoRepository.java
| ... | ... | @@ -17,9 +17,18 @@ public interface SchedulePlanInfoRepository extends PagingAndSortingRepository<S |
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * 获取大于指定日期的班次信息 |
| 20 | - * @param schDate | |
| 20 | + * @param s | |
| 21 | + * @param e | |
| 21 | 22 | * @return |
| 22 | 23 | */ |
| 23 | 24 | @Query("select s from SchedulePlanInfo s where s.scheduleDate>?1 and s.scheduleDate<=?2") |
| 24 | 25 | List<SchedulePlanInfo> findByDateRange(Date s, Date e); |
| 26 | + | |
| 27 | + /** | |
| 28 | + * 获取大于指定日期的班次信息 | |
| 29 | + * @param s | |
| 30 | + * @return | |
| 31 | + */ | |
| 32 | + @Query("select s from SchedulePlanInfo s where s.scheduleDate=?1") | |
| 33 | + List<SchedulePlanInfo> findByDate(Date s); | |
| 25 | 34 | } | ... | ... |
src/main/resources/logback.xml
| ... | ... | @@ -44,4 +44,9 @@ |
| 44 | 44 | <appender-ref ref="STDOUT" /> |
| 45 | 45 | <appender-ref ref="FILE" /> |
| 46 | 46 | </root> |
| 47 | + <!--<include resource="org/springframework/boot/logging/logback/base.xml"/> | |
| 48 | + <logger name="org.springframework.jdbc.core" additivity="false" level="DEBUG" > | |
| 49 | + <appender-ref ref="CONSOLE" /> | |
| 50 | + <appender-ref ref="FILE" /> | |
| 51 | + </logger>--> | |
| 47 | 52 | </configuration> |
| 48 | 53 | \ No newline at end of file | ... | ... |