You've already forked FrameTour-BE
feat(notify): 添加批量查询用户授权余额功能
- 新增批量查询用户授权余额接口 /api/mobile/notify/auth/batch-remaining - 实现批量检查用户对多个模板的授权记录功能 - 添加景区所有场景及模板列表查询接口并支持缓存 - 优化授权记录查询性能,使用批量查询替代逐个查询 - 新增批量查询请求对象 BatchRemainingCountReq 和响应对象 WechatSubscribeAllScenesResp - 在数据层添加批量查询用户授权记录的 SQL 映射 - 实现缓存管理机制,支持所有场景模板配置的缓存读写与清理
This commit is contained in:
@@ -228,31 +228,30 @@ public class UserNotificationAuthorizationServiceImpl implements UserNotificatio
|
||||
public Map<String, UserNotificationAuthorizationEntity> batchCheckAuthorization(
|
||||
Long memberId, List<String> templateIds, Long scenicId) {
|
||||
log.debug("批量检查用户授权: memberId={}, templateIds={}, scenicId={}", memberId, templateIds, scenicId);
|
||||
|
||||
|
||||
Map<String, UserNotificationAuthorizationEntity> result = new HashMap<>();
|
||||
|
||||
|
||||
if (templateIds == null || templateIds.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// 查询用户在该景区的所有授权记录
|
||||
List<UserNotificationAuthorizationEntity> userRecords = getUserAuthorizations(memberId);
|
||||
|
||||
// 过滤出指定景区和模板的记录
|
||||
Map<String, UserNotificationAuthorizationEntity> recordMap = userRecords.stream()
|
||||
.filter(record -> scenicId.equals(record.getScenicId()))
|
||||
.filter(record -> templateIds.contains(record.getTemplateId()))
|
||||
|
||||
// 使用批量查询方法
|
||||
List<UserNotificationAuthorizationEntity> records =
|
||||
userNotificationAuthorizationMapper.selectBatchByTemplateIds(memberId, templateIds, scenicId);
|
||||
|
||||
// 转换为Map
|
||||
Map<String, UserNotificationAuthorizationEntity> recordMap = records.stream()
|
||||
.collect(Collectors.toMap(
|
||||
UserNotificationAuthorizationEntity::getTemplateId,
|
||||
record -> record,
|
||||
(existing, replacement) -> existing
|
||||
));
|
||||
|
||||
|
||||
// 为每个模板ID填充结果
|
||||
for (String templateId : templateIds) {
|
||||
result.put(templateId, recordMap.get(templateId));
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.ycwl.basic.service.notify;
|
||||
|
||||
import com.ycwl.basic.model.mobile.notify.resp.WechatSubscribeAllScenesResp;
|
||||
import com.ycwl.basic.model.pc.notify.entity.WechatSubscribeTemplateConfigEntity;
|
||||
import com.ycwl.basic.repository.WechatSubscribeNotifyConfigRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -33,6 +34,26 @@ public class WechatSubscribeNotifyConfigService {
|
||||
return configRepository.getSceneTemplateConfigsCached(scenicId, sceneKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取景区下所有场景Key列表
|
||||
*
|
||||
* @param scenicId 景区ID
|
||||
* @return 场景Key列表
|
||||
*/
|
||||
public List<String> listAllSceneKeys(Long scenicId) {
|
||||
return configRepository.listAllSceneKeys(scenicId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取景区下所有场景及其模板列表(带缓存,不含用户授权信息)
|
||||
*
|
||||
* @param scenicId 景区ID
|
||||
* @return 所有场景及模板配置
|
||||
*/
|
||||
public WechatSubscribeAllScenesResp getAllScenesWithTemplatesCached(Long scenicId) {
|
||||
return configRepository.getAllScenesWithTemplatesCached(scenicId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取事件下的模板配置列表(带缓存)
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user