ソースを参照

1、积分规则配置增加缓存
2、更改redis的数据库

rayson 1 年間 前
コミット
5ffd49a0d7

+ 8 - 0
menduner/menduner-reward-biz/src/main/java/com/citu/module/menduner/reward/dal/redis/RedisKeyConstants.java

@@ -16,6 +16,14 @@ public interface RedisKeyConstants {
      */
     String POINT_RULE_CONFIG = "point_rule_config";
 
+    /**
+     * 积分规则配置
+     * <p>
+     * KEY 格式:point_rule_config_list:{url}
+     * VALUE 数据类型:String 积分规则配置
+     */
+    String POINT_RULE_CONFIG_LIST = "point_rule_config_list";
+
     /**
      * 点击指标数量
      * <p>

+ 24 - 6
menduner/menduner-reward-biz/src/main/java/com/citu/module/menduner/reward/service/config/PointRuleConfigServiceImpl.java

@@ -12,6 +12,7 @@ import com.citu.module.menduner.reward.enums.config.PointRuleConfigStatusEnum;
 import com.citu.module.menduner.system.enums.MendunerStatusEnum;
 import org.springframework.cache.annotation.CacheEvict;
 import org.springframework.cache.annotation.Cacheable;
+import org.springframework.cache.annotation.Caching;
 import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
 
@@ -20,7 +21,6 @@ import java.util.List;
 
 import static com.citu.framework.common.exception.util.ServiceExceptionUtil.exception;
 import static com.citu.module.menduner.reward.enums.ErrorCodeConstants.POINT_RULE_CONFIG_NOT_EXISTS;
-import static com.citu.module.menduner.reward.enums.ErrorCodeConstants.POINT_RULE_CONFIG_URL_EXISTS;
 
 /**
  * 积分规则配置 Service 实现类
@@ -36,6 +36,10 @@ public class PointRuleConfigServiceImpl implements PointRuleConfigService {
 
     @Override
     @DSTransactional
+    @Caching(evict = {
+            @CacheEvict(value = RedisKeyConstants.POINT_RULE_CONFIG, key = "#updateReqVO.url"),
+            @CacheEvict(value = RedisKeyConstants.POINT_RULE_CONFIG_LIST)
+    })
     public Long createPointRuleConfig(PointRuleConfigSaveReqVO createReqVO) {
         // 插入
         PointRuleConfigDO pointRuleConfig = BeanUtils.toBean(createReqVO, PointRuleConfigDO.class);
@@ -51,7 +55,10 @@ public class PointRuleConfigServiceImpl implements PointRuleConfigService {
 
     @Override
     @DSTransactional
-    @CacheEvict(value = RedisKeyConstants.POINT_RULE_CONFIG, key = "#updateReqVO.url")
+    @Caching(evict = {
+            @CacheEvict(value = RedisKeyConstants.POINT_RULE_CONFIG, key = "#updateReqVO.url"),
+            @CacheEvict(value = RedisKeyConstants.POINT_RULE_CONFIG_LIST)
+    })
     public void updatePointRuleConfig(PointRuleConfigSaveReqVO updateReqVO) {
         // 校验存在
         validatePointRuleConfigExists(updateReqVO.getId());
@@ -67,7 +74,10 @@ public class PointRuleConfigServiceImpl implements PointRuleConfigService {
 
     @Override
     @DSTransactional
-    @CacheEvict(value = RedisKeyConstants.POINT_RULE_CONFIG, key = "#id")
+    @Caching(evict = {
+            @CacheEvict(value = RedisKeyConstants.POINT_RULE_CONFIG, key = "#id"),
+            @CacheEvict(value = RedisKeyConstants.POINT_RULE_CONFIG_LIST)
+    })
     public void deletePointRuleConfig(Long id) {
         // 校验存在
         validatePointRuleConfigExists(id);
@@ -92,13 +102,15 @@ public class PointRuleConfigServiceImpl implements PointRuleConfigService {
     }
 
     @Override
-    @Cacheable(value = RedisKeyConstants.POINT_RULE_CONFIG, key = "#url",
+    @Cacheable(value = RedisKeyConstants.POINT_RULE_CONFIG + "#1h", key = "#url",
             unless = "#result == null")
     public List<PointRuleConfigDO> getByUrlList(String url) {
         return mapper.selectByUrlAndStatus(url, PointRuleConfigStatusEnum.ENABLE);
     }
 
     @Override
+    @Cacheable(value = RedisKeyConstants.POINT_RULE_CONFIG_LIST + "#1h",
+            unless = "#result == null")
     public List<PointRuleConfigDO> selectDistinctUrlList() {
         return mapper.selectDistinctUrlList();
     }
@@ -115,7 +127,10 @@ public class PointRuleConfigServiceImpl implements PointRuleConfigService {
 
     @Override
     @DSTransactional
-    @CacheEvict(value = RedisKeyConstants.POINT_RULE_CONFIG, allEntries = true)
+    @Caching(evict = {
+            @CacheEvict(value = RedisKeyConstants.POINT_RULE_CONFIG, allEntries = true),
+            @CacheEvict(value = RedisKeyConstants.POINT_RULE_CONFIG_LIST)
+    })
     public boolean enable(List<Long> ids) {
         for (Long id : ids) {
             PointRuleConfigDO configDO = valid(id);
@@ -130,7 +145,10 @@ public class PointRuleConfigServiceImpl implements PointRuleConfigService {
 
     @Override
     @DSTransactional
-    @CacheEvict(value = RedisKeyConstants.POINT_RULE_CONFIG, allEntries = true)
+    @Caching(evict = {
+            @CacheEvict(value = RedisKeyConstants.POINT_RULE_CONFIG, allEntries = true),
+            @CacheEvict(value = RedisKeyConstants.POINT_RULE_CONFIG_LIST)
+    })
     public boolean disable(List<Long> ids) {
         for (Long id : ids) {
             PointRuleConfigDO configDO = valid(id);

+ 1 - 1
menduner/menduner-reward-biz/src/main/resources/application-dev.yaml

@@ -55,7 +55,7 @@ spring:
   redis:
     host: 400-infra.server.iocoder.cn # 地址
     port: 6379 # 端口
-    database: 1 # 数据库索引
+    database: 2 # 数据库索引
 #    password: 123456 # 密码,建议生产环境开启
 
 --- #################### MQ 消息队列相关配置 ####################

+ 1 - 1
menduner/menduner-reward-biz/src/main/resources/application-local.yaml

@@ -66,7 +66,7 @@ spring:
   redis:
     host: 192.168.3.80 # 地址
     port: 6379 # 端口
-    database: 0 # 数据库索引
+    database: 2 # 数据库索引
 #    password: 123456 # 密码,建议生产环境开启
 
 --- #################### MQ 消息队列相关配置 ####################

+ 1 - 1
menduner/menduner-system-biz/src/main/resources/application-local.yaml

@@ -66,7 +66,7 @@ spring:
   redis:
     host: 192.168.3.80 # 地址
     port: 6379 # 端口
-    database: 0 # 数据库索引
+    database: 1 # 数据库索引
 #    password: 123456 # 密码,建议生产环境开启
 
 --- #################### MQ 消息队列相关配置 ####################