diff --git a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/asserts/lottery/LotteryErrorCode.java b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/asserts/lottery/LotteryErrorCode.java index 8caf905e..34ff00da 100644 --- a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/asserts/lottery/LotteryErrorCode.java +++ b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/asserts/lottery/LotteryErrorCode.java @@ -172,6 +172,11 @@ public enum LotteryErrorCode implements IResponseErrorCode { */ 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; diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryWinnerHistoryQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryWinnerHistoryQryExe.java index c4ef241b..26d194d5 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryWinnerHistoryQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryWinnerHistoryQryExe.java @@ -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.LotteryPrize; 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.LotteryPrizeService; 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.model.dto.user.UserProfileDTO; import com.red.circle.tool.core.text.StringUtils; import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -35,25 +34,29 @@ public class LotteryWinnerHistoryQryExe { private final LotteryRecordService lotteryRecordService; private final LotteryPrizeService lotteryPrizeService; private final LotteryActivityService lotteryActivityService; + private final LotteryWithdrawService lotteryWithdrawService; private final UserProfileClient userProfileClient; public List execute(LotteryWinnerHistoryQryCmd cmd) { // 1. 查询中奖记录 List records = queryWinRecords(cmd); - if (records.isEmpty()) { + // 2. 查询提现记录(已完成的) + List withdrawRecords = queryWithdrawRecords(cmd); + + // 3. 收集所有用户ID + List 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<>(); } - - // 2. 获取用户信息 - List userIds = records.stream() - .map(LotteryRecord::getUserId) - .distinct() - .collect(Collectors.toList()); Map userMap = getUserProfiles(userIds); - // 3. 获取奖品信息 + // 4. 获取奖品信息 List prizeIds = records.stream() .map(LotteryRecord::getPrizeId) .distinct() @@ -61,15 +64,18 @@ public class LotteryWinnerHistoryQryExe { Map prizeMap = getPrizes(prizeIds); - // 4. 获取活动信息 - List activityIds = records.stream() - .map(LotteryRecord::getActivityId) - .distinct() - .collect(Collectors.toList()); + // 5. 获取活动信息 + List activityIds = new ArrayList<>(); + activityIds.addAll(records.stream().map(LotteryRecord::getActivityId).toList()); + activityIds.addAll(withdrawRecords.stream() + .map(LotteryWithdraw::getActivityId) + .filter(Objects::nonNull) + .toList()); + activityIds = activityIds.stream().distinct().collect(Collectors.toList()); Map activityMap = getActivities(activityIds); - // 5. 组装结果 + // 6. 组装中奖记录结果 List result = new ArrayList<>(); for (LotteryRecord record : records) { @@ -83,7 +89,7 @@ public class LotteryWinnerHistoryQryExe { LotteryWinnerHistoryCO historyCO = new LotteryWinnerHistoryCO(); historyCO.setUserId(record.getUserId()); - historyCO.setNickname(maskNickname(user.getUserNickname())); + historyCO.setNickname(user.getUserNickname()); historyCO.setAvatar(user.getUserAvatar()); historyCO.setPrizeName(prize.getPrizeName()); historyCO.setPrizeType(prize.getPrizeType()); @@ -95,6 +101,53 @@ public class LotteryWinnerHistoryQryExe { 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; } @@ -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); return query.list(); } + /** + * 查询提现记录(已完成的). + */ + private List 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(); + } + /** * 获取用户信息. */ diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryWithdrawApplyExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryWithdrawApplyExe.java index 2c7e2728..6dddb8ae 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryWithdrawApplyExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/LotteryWithdrawApplyExe.java @@ -37,6 +37,8 @@ public class LotteryWithdrawApplyExe { Long userId = cmd.requiredReqUserId(); BigDecimal amount = cmd.getAmount(); Long activityId = Long.valueOf(cmd.getActivityId()); + ResponseAssert.isTrue(LotteryErrorCode.INSUFFICIENT_WITHDRAWAL_REQ_AMOUNT, + amount.compareTo(BigDecimal.valueOf(10)) == 0); // 1. 获取用户本周累计金额 String weekKey = getCurrentWeekKey(); diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/activity/LotteryWinnerHistoryQryCmd.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/activity/LotteryWinnerHistoryQryCmd.java index ce2183d2..fdce43e8 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/activity/LotteryWinnerHistoryQryCmd.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/activity/LotteryWinnerHistoryQryCmd.java @@ -24,7 +24,7 @@ public class LotteryWinnerHistoryQryCmd extends AppExtCommand { /** * 查询数量(默认50,用于滚动展示). */ - private Integer limit = 50; + private Integer limit = 100; /** * 最小奖品价值(可选,只展示大奖).