抽奖金额问题
This commit is contained in:
parent
d85348c2b1
commit
6e8f527643
|
|
@ -48,6 +48,8 @@ public class DiscSpinningServiceImpl extends ServiceImpl<DiscSpinningDao, DiscSp
|
|||
private final WuyouPay wuyouPay;
|
||||
private final PlatformTransactionManager transactionManager;
|
||||
|
||||
private Random random = new Random();
|
||||
|
||||
|
||||
@Autowired
|
||||
public DiscSpinningServiceImpl(CommonInfoService commonRepository,
|
||||
|
|
@ -116,8 +118,8 @@ public class DiscSpinningServiceImpl extends ServiceImpl<DiscSpinningDao, DiscSp
|
|||
recordService.save(record);
|
||||
return record;
|
||||
}
|
||||
Random random = new Random();
|
||||
BigDecimal randomNum = new BigDecimal(random.nextInt(maxNumber.intValue()));
|
||||
|
||||
BigDecimal randomNum = new BigDecimal(getRandomInt(maxNumber.intValue()));
|
||||
List<DiscSpinningAmount> amounts = new ArrayList<>();
|
||||
Map<String, List<DiscSpinningAmount>> amountMaps = redisUtils.getMapData(RedisKeys.getDateKey("spinning:amount:") + source, "setDiscSpinningAmounts", DiscSpinningAmount.class);
|
||||
if (CollectionUtil.isNotEmpty(amountMaps)) {
|
||||
|
|
@ -134,14 +136,12 @@ public class DiscSpinningServiceImpl extends ServiceImpl<DiscSpinningDao, DiscSp
|
|||
int maxAmount = Integer.parseInt(commonRepository.findOne(900).getValue());
|
||||
double resultAmount = 0;
|
||||
if (prize.getType() == 2) {
|
||||
double baseRandom = RandomUtil.randomDouble(0.01, 1);
|
||||
double baseAmount = 0;
|
||||
double baseRandom = getRandomDouble();
|
||||
for (DiscSpinningAmount amount : amounts) {
|
||||
if (baseRandom < amount.getRandom()) {
|
||||
resultAmount = baseAmount + RandomUtil.randomDouble(0.01, 1) * (amount.getMaxAmount() - baseAmount);
|
||||
resultAmount = getRandomDouble() * amount.getMaxAmount();
|
||||
break;
|
||||
}
|
||||
baseAmount = amount.getMaxAmount();
|
||||
}
|
||||
|
||||
if (resultAmount < 0.01) {
|
||||
|
|
@ -193,5 +193,23 @@ public class DiscSpinningServiceImpl extends ServiceImpl<DiscSpinningDao, DiscSp
|
|||
int value = random.nextInt(maxValue) * random.nextInt(maxValue);
|
||||
return new BigDecimal(value / 100);
|
||||
}
|
||||
|
||||
public double getRandomDouble() {
|
||||
random.setSeed(UUID.randomUUID().hashCode());
|
||||
return random.nextDouble();
|
||||
}
|
||||
|
||||
public int getRandomInt(int maxValue) {
|
||||
random.setSeed(UUID.randomUUID().hashCode());
|
||||
return random.nextInt(maxValue);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < 500; i++) {
|
||||
random.setSeed(UUID.randomUUID().hashCode());
|
||||
System.out.println(random.nextInt(100)*random.nextInt(100));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue