You've already forked FrameTour-BE
refactor(notify):重构通知授权模块,移除外部接口
- 移除用户通知授权检查、消费和记录查询的外部接口 - 废弃相关请求和响应 DTO 类文件 - 将授权检查和统计功能迁移至内部服务调用 - 新增批量检查授权方法 batchCheckAuthorization- 新增获取用户授权统计信息方法 getAuthorizationStats - 更新 UserNotificationAuthorizationService 接口定义- 优化 ServiceImpl 中的数据处理逻辑和引入 Collectors 工具类
This commit is contained in:
@@ -2,7 +2,9 @@ package com.ycwl.basic.service;
|
||||
|
||||
import com.ycwl.basic.model.pc.notify.entity.UserNotificationAuthorizationEntity;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 用户通知授权记录Service接口
|
||||
@@ -84,4 +86,46 @@ public interface UserNotificationAuthorizationService {
|
||||
* @return 授权记录
|
||||
*/
|
||||
UserNotificationAuthorizationEntity getById(Long id);
|
||||
|
||||
/**
|
||||
* 批量检查多个模板的授权状态
|
||||
*
|
||||
* @param memberId 用户ID
|
||||
* @param templateIds 模板ID列表
|
||||
* @param scenicId 景区ID
|
||||
* @return 授权记录映射
|
||||
*/
|
||||
Map<String, UserNotificationAuthorizationEntity> batchCheckAuthorization(
|
||||
Long memberId, List<String> templateIds, Long scenicId);
|
||||
|
||||
/**
|
||||
* 获取用户授权统计信息
|
||||
*
|
||||
* @param memberId 用户ID
|
||||
* @return 统计信息
|
||||
*/
|
||||
AuthorizationStats getAuthorizationStats(Long memberId);
|
||||
|
||||
/**
|
||||
* 授权统计信息DTO
|
||||
*/
|
||||
class AuthorizationStats {
|
||||
private int totalTemplates; // 总模板数
|
||||
private int totalAuthorizations; // 总授权次数
|
||||
private int totalConsumed; // 总消费次数
|
||||
private int totalRemaining; // 剩余授权次数
|
||||
private Date queryTime; // 查询时间
|
||||
|
||||
// getters and setters
|
||||
public int getTotalTemplates() { return totalTemplates; }
|
||||
public void setTotalTemplates(int totalTemplates) { this.totalTemplates = totalTemplates; }
|
||||
public int getTotalAuthorizations() { return totalAuthorizations; }
|
||||
public void setTotalAuthorizations(int totalAuthorizations) { this.totalAuthorizations = totalAuthorizations; }
|
||||
public int getTotalConsumed() { return totalConsumed; }
|
||||
public void setTotalConsumed(int totalConsumed) { this.totalConsumed = totalConsumed; }
|
||||
public int getTotalRemaining() { return totalRemaining; }
|
||||
public void setTotalRemaining(int totalRemaining) { this.totalRemaining = totalRemaining; }
|
||||
public Date getQueryTime() { return queryTime; }
|
||||
public void setQueryTime(Date queryTime) { this.queryTime = queryTime; }
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.ycwl.basic.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.ycwl.basic.mapper.UserNotificationAuthorizationMapper;
|
||||
import com.ycwl.basic.model.pc.notify.entity.UserNotificationAuthorizationEntity;
|
||||
import com.ycwl.basic.service.UserNotificationAuthorizationService;
|
||||
@@ -9,8 +8,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 用户通知授权记录Service实现类
|
||||
@@ -135,4 +134,56 @@ public class UserNotificationAuthorizationServiceImpl implements UserNotificatio
|
||||
log.debug("根据ID查询授权记录: id={}", id);
|
||||
return userNotificationAuthorizationMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
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()))
|
||||
.collect(Collectors.toMap(
|
||||
UserNotificationAuthorizationEntity::getTemplateId,
|
||||
record -> record,
|
||||
(existing, replacement) -> existing
|
||||
));
|
||||
|
||||
// 为每个模板ID填充结果
|
||||
for (String templateId : templateIds) {
|
||||
result.put(templateId, recordMap.get(templateId));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthorizationStats getAuthorizationStats(Long memberId) {
|
||||
log.debug("获取用户授权统计信息: memberId={}", memberId);
|
||||
|
||||
List<UserNotificationAuthorizationEntity> records = getUserAuthorizations(memberId);
|
||||
|
||||
AuthorizationStats stats = new AuthorizationStats();
|
||||
stats.setTotalTemplates(records.size());
|
||||
stats.setTotalAuthorizations(records.stream()
|
||||
.mapToInt(UserNotificationAuthorizationEntity::getAuthorizationCount)
|
||||
.sum());
|
||||
stats.setTotalConsumed(records.stream()
|
||||
.mapToInt(UserNotificationAuthorizationEntity::getConsumedCount)
|
||||
.sum());
|
||||
stats.setTotalRemaining(stats.getTotalAuthorizations() - stats.getTotalConsumed());
|
||||
stats.setQueryTime(new Date());
|
||||
|
||||
return stats;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user