release: 修复抽奖bug

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

@ -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;

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

Loading…
Cancel
Save