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

@@ -44,6 +44,16 @@ public interface UserNotificationAuthorizationService {
*/
UserNotificationAuthorizationEntity recordAuthorization(Long memberId, String templateId, Long scenicId);
/**
* 批量记录用户授权
*
* @param memberId 用户ID
* @param templateIds 模板ID列表
* @param scenicId 景区ID
* @return 批量授权记录结果
*/
List<AuthorizationRecord> batchRecordAuthorization(Long memberId, List<String> templateIds, Long scenicId);
/**
* 消费一次授权
*
@@ -106,6 +116,50 @@ public interface UserNotificationAuthorizationService {
*/
AuthorizationStats getAuthorizationStats(Long memberId);
/**
* 授权记录结果
*/
class AuthorizationRecord {
private boolean success; // 是否成功
private String templateId; // 模板ID
private Long id; // 记录ID
private Long scenicId; // 景区ID
private Integer authorizationCount; // 授权次数
private Integer consumedCount; // 已消费次数
private Integer remainingCount; // 剩余次数
private Date lastAuthorizedTime; // 最后授权时间
private Date lastConsumedTime; // 最后消费时间
private Integer status; // 状态
private Date createTime; // 创建时间
private String failureReason; // 失败原因
// getters and setters
public boolean isSuccess() { return success; }
public void setSuccess(boolean success) { this.success = success; }
public String getTemplateId() { return templateId; }
public void setTemplateId(String templateId) { this.templateId = templateId; }
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
public Long getScenicId() { return scenicId; }
public void setScenicId(Long scenicId) { this.scenicId = scenicId; }
public Integer getAuthorizationCount() { return authorizationCount; }
public void setAuthorizationCount(Integer authorizationCount) { this.authorizationCount = authorizationCount; }
public Integer getConsumedCount() { return consumedCount; }
public void setConsumedCount(Integer consumedCount) { this.consumedCount = consumedCount; }
public Integer getRemainingCount() { return remainingCount; }
public void setRemainingCount(Integer remainingCount) { this.remainingCount = remainingCount; }
public Date getLastAuthorizedTime() { return lastAuthorizedTime; }
public void setLastAuthorizedTime(Date lastAuthorizedTime) { this.lastAuthorizedTime = lastAuthorizedTime; }
public Date getLastConsumedTime() { return lastConsumedTime; }
public void setLastConsumedTime(Date lastConsumedTime) { this.lastConsumedTime = lastConsumedTime; }
public Integer getStatus() { return status; }
public void setStatus(Integer status) { this.status = status; }
public Date getCreateTime() { return createTime; }
public void setCreateTime(Date createTime) { this.createTime = createTime; }
public String getFailureReason() { return failureReason; }
public void setFailureReason(String failureReason) { this.failureReason = failureReason; }
}
/**
* 授权统计信息DTO
*/

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