Просмотр исходного кода

【优化】SYSTEM: 小程序订阅模版获取增加缓存

puhui999 10 месяцев назад
Родитель
Сommit
5307852fb2

+ 9 - 0
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/redis/RedisKeyConstants.java

@@ -98,4 +98,13 @@ public interface RedisKeyConstants {
      * VALUE 数据格式:String 模版信息
      */
     String SMS_TEMPLATE = "sms_template";
+
+    /**
+     * 小程序订阅模版的缓存
+     *
+     * KEY 格式:wxa_subscribe_template:{userType}
+     * VALUE 数据格式 String, 模版信息
+     */
+    String WXA_SUBSCRIBE_TEMPLATE = "wxa_subscribe_template";
+
 }

+ 3 - 0
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientService.java

@@ -76,6 +76,9 @@ public interface SocialClientService {
     /**
      * 获得微信小程订阅模板
      *
+     * 缓存的目的:考虑到微信小程序订阅消息选择好模版后几乎不会变动,缓存增加查询效率
+     *
+     * @param userType 用户类型
      * @return 微信小程订阅模板
      */
     List<TemplateInfo> getSubscribeTemplateList(Integer userType);

+ 3 - 0
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImpl.java

@@ -24,6 +24,7 @@ import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialCl
 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO;
 import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO;
 import cn.iocoder.yudao.module.system.dal.mysql.social.SocialClientMapper;
+import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants;
 import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
 import com.binarywang.spring.starter.wxjava.miniapp.properties.WxMaProperties;
 import com.binarywang.spring.starter.wxjava.mp.properties.WxMpProperties;
@@ -48,6 +49,7 @@ import me.chanjar.weixin.mp.api.WxMpService;
 import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
 import me.chanjar.weixin.mp.config.impl.WxMpRedisConfigImpl;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.stereotype.Service;
 
@@ -265,6 +267,7 @@ public class SocialClientServiceImpl implements SocialClientService {
     }
 
     @Override
+    @Cacheable(cacheNames = RedisKeyConstants.WXA_SUBSCRIBE_TEMPLATE, key = "#userType", condition = "#result != null")
     public List<TemplateInfo> getSubscribeTemplateList(Integer userType) {
         WxMaService service = getWxMaService(userType);
         try {