抽奖 活动列表去重
This commit is contained in:
parent
5b43823751
commit
a7dc52bb90
@ -16,7 +16,7 @@ import com.red.circle.other.infra.database.rds.service.activity.LotteryUserCount
|
||||
import com.red.circle.other.inner.asserts.lottery.LotteryErrorCode;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -52,6 +52,22 @@ public class LotteryActivityDetailQryExe {
|
||||
.orderByAsc(LotteryPrize::getSortOrder)
|
||||
.list();
|
||||
|
||||
// 去重:按照 prize_name 去重,优先保留 EARLY 池的奖品(用户首次看到的)
|
||||
Map<String, LotteryPrize> uniquePrizes = new LinkedHashMap<>();
|
||||
for (LotteryPrize prize : prizes) {
|
||||
String prizeName = prize.getPrizeName();
|
||||
if (!uniquePrizes.containsKey(prizeName)) {
|
||||
// 如果这个奖品名称还没有,就添加
|
||||
uniquePrizes.put(prizeName, prize);
|
||||
} else {
|
||||
// 如果已存在,优先保留 EARLY 池的
|
||||
LotteryPrize existingPrize = uniquePrizes.get(prizeName);
|
||||
if ("EARLY".equals(prize.getPrizePool()) && !"EARLY".equals(existingPrize.getPrizePool())) {
|
||||
uniquePrizes.put(prizeName, prize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 查询用户抽奖券数量
|
||||
int ticketCount = 0;
|
||||
if (activity.getNeedTicket() == 1) {
|
||||
@ -81,7 +97,7 @@ public class LotteryActivityDetailQryExe {
|
||||
// 组装返回数据
|
||||
LotteryActivityDetailCO detail = new LotteryActivityDetailCO();
|
||||
detail.setActivity(convertActivityToCO(activity, usedCount));
|
||||
detail.setPrizeList(prizes.stream()
|
||||
detail.setPrizeList(uniquePrizes.values().stream()
|
||||
.map(this::convertPrizeToCO)
|
||||
.collect(Collectors.toList()));
|
||||
detail.setUserTicketCount(ticketCount);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user