This commit is contained in:
tianfeng 2025-10-24 14:51:36 +08:00
parent ba7a024e03
commit ac0c8fe4de
4 changed files with 107 additions and 21 deletions

View File

@ -172,6 +172,11 @@ public enum LotteryErrorCode implements IResponseErrorCode {
*/ */
INSUFFICIENT_WITHDRAWAL_AMOUNT(9732, "Insufficient withdrawal amount"), INSUFFICIENT_WITHDRAWAL_AMOUNT(9732, "Insufficient withdrawal amount"),
/**
* 提现金额不足10.
*/
INSUFFICIENT_WITHDRAWAL_REQ_AMOUNT(9733, "The withdrawal amount must be greater than 10"),
; ;
private final Integer code; private final Integer code;

View File

@ -5,17 +5,16 @@ import com.red.circle.other.app.dto.cmd.activity.LotteryWinnerHistoryQryCmd;
import com.red.circle.other.infra.database.rds.entity.activity.LotteryActivity; import com.red.circle.other.infra.database.rds.entity.activity.LotteryActivity;
import com.red.circle.other.infra.database.rds.entity.activity.LotteryPrize; import com.red.circle.other.infra.database.rds.entity.activity.LotteryPrize;
import com.red.circle.other.infra.database.rds.entity.activity.LotteryRecord; import com.red.circle.other.infra.database.rds.entity.activity.LotteryRecord;
import com.red.circle.other.infra.database.rds.entity.activity.LotteryWithdraw;
import com.red.circle.other.infra.database.rds.service.activity.LotteryActivityService; import com.red.circle.other.infra.database.rds.service.activity.LotteryActivityService;
import com.red.circle.other.infra.database.rds.service.activity.LotteryPrizeService; import com.red.circle.other.infra.database.rds.service.activity.LotteryPrizeService;
import com.red.circle.other.infra.database.rds.service.activity.LotteryRecordService; import com.red.circle.other.infra.database.rds.service.activity.LotteryRecordService;
import com.red.circle.other.infra.database.rds.service.activity.LotteryWithdrawService;
import com.red.circle.other.inner.endpoint.user.user.UserProfileClient; import com.red.circle.other.inner.endpoint.user.user.UserProfileClient;
import com.red.circle.other.inner.model.dto.user.UserProfileDTO; import com.red.circle.other.inner.model.dto.user.UserProfileDTO;
import com.red.circle.tool.core.text.StringUtils; import com.red.circle.tool.core.text.StringUtils;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList; import java.util.*;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -35,25 +34,29 @@ public class LotteryWinnerHistoryQryExe {
private final LotteryRecordService lotteryRecordService; private final LotteryRecordService lotteryRecordService;
private final LotteryPrizeService lotteryPrizeService; private final LotteryPrizeService lotteryPrizeService;
private final LotteryActivityService lotteryActivityService; private final LotteryActivityService lotteryActivityService;
private final LotteryWithdrawService lotteryWithdrawService;
private final UserProfileClient userProfileClient; private final UserProfileClient userProfileClient;
public List<LotteryWinnerHistoryCO> execute(LotteryWinnerHistoryQryCmd cmd) { public List<LotteryWinnerHistoryCO> execute(LotteryWinnerHistoryQryCmd cmd) {
// 1. 查询中奖记录 // 1. 查询中奖记录
List<LotteryRecord> records = queryWinRecords(cmd); List<LotteryRecord> records = queryWinRecords(cmd);
if (records.isEmpty()) { // 2. 查询提现记录已完成的
List<LotteryWithdraw> withdrawRecords = queryWithdrawRecords(cmd);
// 3. 收集所有用户ID
List<Long> userIds = new ArrayList<>();
userIds.addAll(records.stream().map(LotteryRecord::getUserId).collect(Collectors.toList()));
userIds.addAll(withdrawRecords.stream().map(LotteryWithdraw::getUserId).collect(Collectors.toList()));
userIds = userIds.stream().distinct().collect(Collectors.toList());
if (userIds.isEmpty()) {
return new ArrayList<>(); return new ArrayList<>();
} }
// 2. 获取用户信息
List<Long> userIds = records.stream()
.map(LotteryRecord::getUserId)
.distinct()
.collect(Collectors.toList());
Map<Long, UserProfileDTO> userMap = getUserProfiles(userIds); Map<Long, UserProfileDTO> userMap = getUserProfiles(userIds);
// 3. 获取奖品信息 // 4. 获取奖品信息
List<Long> prizeIds = records.stream() List<Long> prizeIds = records.stream()
.map(LotteryRecord::getPrizeId) .map(LotteryRecord::getPrizeId)
.distinct() .distinct()
@ -61,15 +64,18 @@ public class LotteryWinnerHistoryQryExe {
Map<Long, LotteryPrize> prizeMap = getPrizes(prizeIds); Map<Long, LotteryPrize> prizeMap = getPrizes(prizeIds);
// 4. 获取活动信息 // 5. 获取活动信息
List<Long> activityIds = records.stream() List<Long> activityIds = new ArrayList<>();
.map(LotteryRecord::getActivityId) activityIds.addAll(records.stream().map(LotteryRecord::getActivityId).toList());
.distinct() activityIds.addAll(withdrawRecords.stream()
.collect(Collectors.toList()); .map(LotteryWithdraw::getActivityId)
.filter(Objects::nonNull)
.toList());
activityIds = activityIds.stream().distinct().collect(Collectors.toList());
Map<Long, LotteryActivity> activityMap = getActivities(activityIds); Map<Long, LotteryActivity> activityMap = getActivities(activityIds);
// 5. 组装结果 // 6. 组装中奖记录结果
List<LotteryWinnerHistoryCO> result = new ArrayList<>(); List<LotteryWinnerHistoryCO> result = new ArrayList<>();
for (LotteryRecord record : records) { for (LotteryRecord record : records) {
@ -83,7 +89,7 @@ public class LotteryWinnerHistoryQryExe {
LotteryWinnerHistoryCO historyCO = new LotteryWinnerHistoryCO(); LotteryWinnerHistoryCO historyCO = new LotteryWinnerHistoryCO();
historyCO.setUserId(record.getUserId()); historyCO.setUserId(record.getUserId());
historyCO.setNickname(maskNickname(user.getUserNickname())); historyCO.setNickname(user.getUserNickname());
historyCO.setAvatar(user.getUserAvatar()); historyCO.setAvatar(user.getUserAvatar());
historyCO.setPrizeName(prize.getPrizeName()); historyCO.setPrizeName(prize.getPrizeName());
historyCO.setPrizeType(prize.getPrizeType()); historyCO.setPrizeType(prize.getPrizeType());
@ -95,6 +101,53 @@ public class LotteryWinnerHistoryQryExe {
result.add(historyCO); result.add(historyCO);
} }
// 7. 组装提现记录结果
for (LotteryWithdraw withdraw : withdrawRecords) {
UserProfileDTO user = userMap.get(withdraw.getUserId());
if (user == null) {
continue;
}
LotteryActivity activity = withdraw.getActivityId() != null
? activityMap.get(withdraw.getActivityId())
: null;
LotteryWinnerHistoryCO historyCO = new LotteryWinnerHistoryCO();
historyCO.setUserId(withdraw.getUserId());
historyCO.setNickname(user.getUserNickname());
historyCO.setAvatar(user.getUserAvatar());
// 根据description判断类型
String description = withdraw.getDescription();
if (description != null && description.contains("兑换金币")) {
historyCO.setPrizeName("兑换金币");
historyCO.setPrizeType("EXCHANGE");
} else if (description != null && description.contains("转账给用户")) {
historyCO.setPrizeName("用户转账");
historyCO.setPrizeType("TRANSFER");
} else {
historyCO.setPrizeName("提现");
historyCO.setPrizeType("WITHDRAW");
}
historyCO.setPrizeValue(withdraw.getAmount());
historyCO.setPrizeIcon(""); // 提现记录没有图标
historyCO.setDrawTime(withdraw.getCreateTime());
historyCO.setActivityName(activity != null ? activity.getActivityName() : "");
result.add(historyCO);
}
// 8. 按时间倒序排序
result.sort((a, b) -> b.getDrawTime().compareTo(a.getDrawTime()));
// 9. 限制数量
Integer limit = cmd.getLimit() != null ? cmd.getLimit() : 100;
if (result.size() > limit) {
result = result.subList(0, limit);
}
return result; return result;
} }
@ -130,12 +183,38 @@ public class LotteryWinnerHistoryQryExe {
} }
// 限制数量 // 限制数量
Integer limit = cmd.getLimit() != null ? cmd.getLimit() : 50; Integer limit = cmd.getLimit() != null ? cmd.getLimit() : 100;
query.last("LIMIT " + limit); query.last("LIMIT " + limit);
return query.list(); return query.list();
} }
/**
* 查询提现记录已完成的.
*/
private List<LotteryWithdraw> queryWithdrawRecords(LotteryWinnerHistoryQryCmd cmd) {
var query = lotteryWithdrawService.query()
.in(LotteryWithdraw::getStatus, 1, 3) // 已通过已完成
.orderByDesc(LotteryWithdraw::getCreateTime);
// 如果指定了活动ID
if (cmd.getActivityId() != null) {
query.eq(LotteryWithdraw::getActivityId, cmd.getActivityId());
}
// 如果指定了最小奖品价值提现金额
if (StringUtils.isNotBlank(cmd.getMinPrizeValue())) {
BigDecimal minValue = new BigDecimal(cmd.getMinPrizeValue());
query.ge(LotteryWithdraw::getAmount, minValue);
}
// 限制数量提现记录和中奖记录合并后再限制这里先查一半
Integer limit = cmd.getLimit() != null ? cmd.getLimit() : 100;
query.last("LIMIT " + (limit / 2));
return query.list();
}
/** /**
* 获取用户信息. * 获取用户信息.
*/ */

View File

@ -37,6 +37,8 @@ public class LotteryWithdrawApplyExe {
Long userId = cmd.requiredReqUserId(); Long userId = cmd.requiredReqUserId();
BigDecimal amount = cmd.getAmount(); BigDecimal amount = cmd.getAmount();
Long activityId = Long.valueOf(cmd.getActivityId()); Long activityId = Long.valueOf(cmd.getActivityId());
ResponseAssert.isTrue(LotteryErrorCode.INSUFFICIENT_WITHDRAWAL_REQ_AMOUNT,
amount.compareTo(BigDecimal.valueOf(10)) == 0);
// 1. 获取用户本周累计金额 // 1. 获取用户本周累计金额
String weekKey = getCurrentWeekKey(); String weekKey = getCurrentWeekKey();

View File

@ -24,7 +24,7 @@ public class LotteryWinnerHistoryQryCmd extends AppExtCommand {
/** /**
* 查询数量默认50用于滚动展示. * 查询数量默认50用于滚动展示.
*/ */
private Integer limit = 50; private Integer limit = 100;
/** /**
* 最小奖品价值可选只展示大奖. * 最小奖品价值可选只展示大奖.