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

This commit is contained in:
puhui999 2024-07-30 16:05:25 +08:00
parent 4c846ef4ce
commit 5307852fb2
3 changed files with 15 additions and 0 deletions

View File

@ -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";
}

View File

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

View File

@ -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 {