release: 修复抽奖bug

release-2024-08-08
huangyw 4 months ago
parent 9df1366b00
commit c44c213f92

@ -52,7 +52,6 @@ public class LotteryUser {
@ApiModelProperty(value = "用户id") @ApiModelProperty(value = "用户id")
private String userId; private String userId;
@NotNull
@Column(name = "region_id", nullable = false) @Column(name = "region_id", nullable = false)
@ApiModelProperty(value = "区域id") @ApiModelProperty(value = "区域id")
private Integer regionId; private Integer regionId;

@ -148,9 +148,14 @@ public class DrawLotteryService {
* @return * @return
*/ */
private List<LotteryUser> drawWinners(List<LotteryUser> list, int winnersCount) { private List<LotteryUser> drawWinners(List<LotteryUser> list, int winnersCount) {
List<LotteryUser> winners = new ArrayList<>(); // 创建一个新列表,以便对它进行洗牌操作而不影响原始列表
Collections.shuffle(winners, new Random()); List<LotteryUser> shuffledList = new ArrayList<>(list);
return winners.subList(0, Math.min(winnersCount, winners.size()));
// 对新列表进行洗牌操作
Collections.shuffle(shuffledList, new Random());
// 返回前 winnersCount 个元素
return shuffledList.subList(0, Math.min(winnersCount, shuffledList.size()));
} }
} }

Loading…
Cancel
Save