diff --git a/luoo_user/src/main/java/com/luoo/user/pojo/LotteryUser.java b/luoo_user/src/main/java/com/luoo/user/pojo/LotteryUser.java index 4b22f2d..ccb8868 100644 --- a/luoo_user/src/main/java/com/luoo/user/pojo/LotteryUser.java +++ b/luoo_user/src/main/java/com/luoo/user/pojo/LotteryUser.java @@ -52,7 +52,6 @@ public class LotteryUser { @ApiModelProperty(value = "用户id") private String userId; - @NotNull @Column(name = "region_id", nullable = false) @ApiModelProperty(value = "区域id") private Integer regionId; diff --git a/luoo_user/src/main/java/com/luoo/user/service/DrawLotteryService.java b/luoo_user/src/main/java/com/luoo/user/service/DrawLotteryService.java index 9bb6ff9..23f4596 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/DrawLotteryService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/DrawLotteryService.java @@ -148,9 +148,14 @@ public class DrawLotteryService { * @return 中奖者列表 */ private List drawWinners(List list, int winnersCount) { - List winners = new ArrayList<>(); - Collections.shuffle(winners, new Random()); - return winners.subList(0, Math.min(winnersCount, winners.size())); + // 创建一个新列表,以便对它进行洗牌操作而不影响原始列表 + List shuffledList = new ArrayList<>(list); + + // 对新列表进行洗牌操作 + Collections.shuffle(shuffledList, new Random()); + + // 返回前 winnersCount 个元素 + return shuffledList.subList(0, Math.min(winnersCount, shuffledList.size())); } }