You've already forked FrameTour-BE
- 为微信订阅消息配置接口添加 Redis 缓存支持 - 在 WechatSubscribeNotifyConfigRepository 中实现缓存读写和清除机制 - 修改 Controller 层接口添加 @IgnoreToken 注解支持匿名访问 - 优化查询逻辑,添加 memberId 为空时的提前返回处理 - 在管理服务中添加缓存清除逻辑,确保配置变更时缓存同步更新 - 实现批量缓存清除功能,支持按景区和全局范围清除缓存
75 lines
2.3 KiB
Java
75 lines
2.3 KiB
Java
package com.ycwl.basic.service.notify;
|
|
|
|
import com.ycwl.basic.model.pc.notify.entity.WechatSubscribeTemplateConfigEntity;
|
|
import com.ycwl.basic.repository.WechatSubscribeNotifyConfigRepository;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 微信订阅消息配置查询服务(仅负责"配置解析",不包含授权/发送逻辑)
|
|
* 底层通过 Repository 实现 Redis 缓存
|
|
*
|
|
* @Author: System
|
|
* @Date: 2025/12/31
|
|
*/
|
|
@Service
|
|
public class WechatSubscribeNotifyConfigService {
|
|
|
|
private final WechatSubscribeNotifyConfigRepository configRepository;
|
|
|
|
public WechatSubscribeNotifyConfigService(WechatSubscribeNotifyConfigRepository configRepository) {
|
|
this.configRepository = configRepository;
|
|
}
|
|
|
|
/**
|
|
* 获取场景下的模板配置列表(带缓存)
|
|
*
|
|
* @param scenicId 景区ID
|
|
* @param sceneKey 场景标识
|
|
* @return 启用的模板配置列表
|
|
*/
|
|
public List<WechatSubscribeTemplateConfigEntity> listSceneTemplateConfigs(Long scenicId, String sceneKey) {
|
|
return configRepository.getSceneTemplateConfigsCached(scenicId, sceneKey);
|
|
}
|
|
|
|
/**
|
|
* 获取事件下的模板配置列表(带缓存)
|
|
*
|
|
* @param scenicId 景区ID
|
|
* @param eventKey 事件标识
|
|
* @return 启用的模板配置列表
|
|
*/
|
|
public List<WechatSubscribeTemplateConfigEntity> listEventTemplateConfigs(Long scenicId, String eventKey) {
|
|
return configRepository.getEventTemplateConfigsCached(scenicId, eventKey);
|
|
}
|
|
|
|
/**
|
|
* 清除指定场景的配置缓存
|
|
*/
|
|
public void clearSceneConfigsCache(Long scenicId, String sceneKey) {
|
|
configRepository.clearSceneTemplateConfigsCache(scenicId, sceneKey);
|
|
}
|
|
|
|
/**
|
|
* 清除指定事件的配置缓存
|
|
*/
|
|
public void clearEventConfigsCache(Long scenicId, String eventKey) {
|
|
configRepository.clearEventTemplateConfigsCache(scenicId, eventKey);
|
|
}
|
|
|
|
/**
|
|
* 清除景区下所有订阅消息配置缓存
|
|
*/
|
|
public void clearAllConfigsCacheByScenic(Long scenicId) {
|
|
configRepository.clearAllConfigsCacheByScenic(scenicId);
|
|
}
|
|
|
|
/**
|
|
* 清除所有订阅消息配置缓存(全局配置变更时调用)
|
|
*/
|
|
public void clearAllConfigsCache() {
|
|
configRepository.clearAllConfigsCache();
|
|
}
|
|
}
|