From c44c213f923032bf526c3727ac6bdb1276d391e4 Mon Sep 17 00:00:00 2001 From: huangyw <1207046171@qq.com> Date: Mon, 5 Aug 2024 16:02:54 +0800 Subject: [PATCH] =?UTF-8?q?release:=20=E4=BF=AE=E5=A4=8D=E6=8A=BD=E5=A5=96?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/luoo/user/pojo/LotteryUser.java | 1 - .../com/luoo/user/service/DrawLotteryService.java | 11 ++++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) 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())); } }