|
|
@@ -3,11 +3,7 @@ package com.kym.service.cache;
|
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
|
import com.kym.common.exception.BusinessException;
|
|
|
import com.kym.common.utils.CommUtil;
|
|
|
-import com.kym.entity.WashStation;
|
|
|
import com.kym.entity.common.RedisKeys;
|
|
|
-import com.kym.service.WashStationService;
|
|
|
-import org.springframework.boot.context.event.ApplicationStartedEvent;
|
|
|
-import org.springframework.context.ApplicationListener;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
@@ -15,7 +11,6 @@ import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author skyline
|
|
|
@@ -35,7 +30,7 @@ public enum KymCache {
|
|
|
*
|
|
|
* @param map
|
|
|
*/
|
|
|
- public static void putStationId2MerchantId(Map<String, String> map) {
|
|
|
+ public void putStationId2MerchantId(Map<String, String> map) {
|
|
|
map.forEach((k, v) -> KymCacheInjector.redisTemplate.opsForValue().set(RedisKeys.STATION_ID_TO_MERCHANT_ID + k, v));
|
|
|
}
|
|
|
|
|
|
@@ -44,7 +39,7 @@ public enum KymCache {
|
|
|
*
|
|
|
* @param map
|
|
|
*/
|
|
|
- public static void putStationId2Name(Map<String, String> map) {
|
|
|
+ public void putStationId2Name(Map<String, String> map) {
|
|
|
map.forEach((k, v) -> KymCacheInjector.redisTemplate.opsForValue().set(RedisKeys.STATION_ID_TO_NAME + k, v));
|
|
|
}
|
|
|
|
|
|
@@ -120,22 +115,8 @@ public enum KymCache {
|
|
|
|
|
|
|
|
|
@Component
|
|
|
- public static class KymCacheInjector implements ApplicationListener<ApplicationStartedEvent> {
|
|
|
-
|
|
|
+ public static class KymCacheInjector {
|
|
|
private static final StringRedisTemplate redisTemplate = SpringUtil.getBean(StringRedisTemplate.class);
|
|
|
|
|
|
- private final WashStationService washStationService;
|
|
|
-
|
|
|
-
|
|
|
- private KymCacheInjector(WashStationService washStationService) {
|
|
|
- this.washStationService = washStationService;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onApplicationEvent(ApplicationStartedEvent event) {
|
|
|
- // 将数据库数据缓存到redis
|
|
|
-
|
|
|
- putStationId2Name(washStationService.list().stream().collect(Collectors.toMap(WashStation::getStationId, WashStation::getStationName)));
|
|
|
- }
|
|
|
}
|
|
|
}
|