feat(notify): 支持批量授权记录及景区模板查询

- 新增批量授权记录接口,支持一次请求处理多个模板ID
- 新增查询景区通知模板及用户授权余额接口
- 修改授权记录请求体,将单个templateId改为templateIds列表
- 增加授权记录响应结构,区分成功与失败记录
- 新增通知授权工具类,封装常用授权检查与消费方法
- 使用JwtTokenUtil获取当前用户ID替代BaseContextHandler
- 移除过时的BaseContextHandler导入及相关代码依赖
This commit is contained in:
2025-10-15 09:41:18 +08:00
parent 86d5f8ceb1
commit c80086ba69
7 changed files with 520 additions and 59 deletions

View File

@@ -82,6 +82,48 @@ public class UserNotificationAuthorizationServiceImpl implements UserNotificatio
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public List<AuthorizationRecord> batchRecordAuthorization(Long memberId, List<String> templateIds, Long scenicId) {
log.info("批量记录用户授权: memberId={}, templateIds={}, scenicId={}", memberId, templateIds, scenicId);
List<AuthorizationRecord> results = new ArrayList<>();
if (templateIds == null || templateIds.isEmpty()) {
return results;
}
for (String templateId : templateIds) {
AuthorizationRecord record = new AuthorizationRecord();
record.setTemplateId(templateId);
try {
UserNotificationAuthorizationEntity entity = recordAuthorization(memberId, templateId, scenicId);
// 转换为响应对象
record.setSuccess(true);
record.setId(entity.getId());
record.setScenicId(entity.getScenicId());
record.setAuthorizationCount(entity.getAuthorizationCount());
record.setConsumedCount(entity.getConsumedCount());
record.setRemainingCount(entity.getRemainingCount());
record.setLastAuthorizedTime(entity.getLastAuthorizedTime());
record.setLastConsumedTime(entity.getLastConsumedTime());
record.setStatus(entity.getStatus());
record.setCreateTime(entity.getCreateTime());
} catch (Exception e) {
log.error("批量授权记录失败: memberId={}, templateId={}, scenicId={}", memberId, templateId, scenicId, e);
record.setSuccess(false);
record.setFailureReason(e.getMessage());
}
results.add(record);
}
return results;
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean consumeAuthorization(Long memberId, String templateId, Long scenicId) {