Commit 5307852fb2c826c07ca06d207d9ce665d18fca2e

Authored by puhui999
1 parent 4c846ef4

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

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 {
98 98 * VALUE 数据格式:String 模版信息
99 99 */
100 100 String SMS_TEMPLATE = "sms_template";
  101 +
  102 + /**
  103 + * 小程序订阅模版的缓存
  104 + *
  105 + * KEY 格式:wxa_subscribe_template:{userType}
  106 + * VALUE 数据格式 String, 模版信息
  107 + */
  108 + String WXA_SUBSCRIBE_TEMPLATE = "wxa_subscribe_template";
  109 +
101 110 }
... ...
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 {
76 76 /**
77 77 * 获得微信小程订阅模板
78 78 *
  79 + * 缓存的目的:考虑到微信小程序订阅消息选择好模版后几乎不会变动,缓存增加查询效率
  80 + *
  81 + * @param userType 用户类型
79 82 * @return 微信小程订阅模板
80 83 */
81 84 List<TemplateInfo> getSubscribeTemplateList(Integer userType);
... ...
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
24 24 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO;
25 25 import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO;
26 26 import cn.iocoder.yudao.module.system.dal.mysql.social.SocialClientMapper;
  27 +import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants;
27 28 import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
28 29 import com.binarywang.spring.starter.wxjava.miniapp.properties.WxMaProperties;
29 30 import com.binarywang.spring.starter.wxjava.mp.properties.WxMpProperties;
... ... @@ -48,6 +49,7 @@ import me.chanjar.weixin.mp.api.WxMpService;
48 49 import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
49 50 import me.chanjar.weixin.mp.config.impl.WxMpRedisConfigImpl;
50 51 import org.springframework.beans.factory.annotation.Value;
  52 +import org.springframework.cache.annotation.Cacheable;
51 53 import org.springframework.data.redis.core.StringRedisTemplate;
52 54 import org.springframework.stereotype.Service;
53 55  
... ... @@ -265,6 +267,7 @@ public class SocialClientServiceImpl implements SocialClientService {
265 267 }
266 268  
267 269 @Override
  270 + @Cacheable(cacheNames = RedisKeyConstants.WXA_SUBSCRIBE_TEMPLATE, key = "#userType", condition = "#result != null")
268 271 public List<TemplateInfo> getSubscribeTemplateList(Integer userType) {
269 272 WxMaService service = getWxMaService(userType);
270 273 try {
... ...