This commit is contained in:
parent
90ba7eff9c
commit
19db286c01
|
|
@ -2,6 +2,7 @@ package com.sqx.modules.discSpinning.service.impl;
|
|||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.sqx.common.utils.DateUtils;
|
||||
|
|
@ -104,13 +105,12 @@ public class DiscSpinningServiceImpl extends ServiceImpl<DiscSpinningDao, DiscSp
|
|||
recordService.save(record);
|
||||
return record;
|
||||
}
|
||||
Random random = new Random();
|
||||
|
||||
BigDecimal maxNumber = prizes.stream()
|
||||
.map(DiscSpinning::getNumber)
|
||||
.max(BigDecimal::compareTo)
|
||||
.orElse(null);
|
||||
BigDecimal randomNum = new BigDecimal(ThreadLocalRandom.current().nextDouble(0.01, maxNumber.doubleValue()));
|
||||
|
||||
BigDecimal randomNum = new BigDecimal(RandomUtil.randomDouble(0.01, maxNumber.doubleValue()));
|
||||
List<DiscSpinningAmount> amounts = new ArrayList<>();
|
||||
Map<String, List<DiscSpinningAmount>> amountMaps = redisUtils.getMapData(RedisKeys.getDateKey("spinning:amount:") + source, "setDiscSpinningAmounts", DiscSpinningAmount.class);
|
||||
for (int i = drawCount; i >= 0; i--) {
|
||||
|
|
@ -125,11 +125,11 @@ public class DiscSpinningServiceImpl extends ServiceImpl<DiscSpinningDao, DiscSp
|
|||
int maxAmount = Integer.parseInt(commonRepository.findOne(900).getValue());
|
||||
double resultAmount = 0;
|
||||
if (prize.getType() == 2) {
|
||||
double baseRandom = random.nextDouble();
|
||||
double baseRandom = RandomUtil.randomDouble(0.01, 1);
|
||||
double baseAmount = 0;
|
||||
for (DiscSpinningAmount amount : amounts) {
|
||||
if (baseRandom < amount.getRandom()) {
|
||||
resultAmount = baseAmount + random.nextDouble() * (amount.getMaxAmount() - baseAmount);
|
||||
resultAmount = baseAmount + RandomUtil.randomDouble(0.01, 1) * (amount.getMaxAmount() - baseAmount);
|
||||
break;
|
||||
}
|
||||
baseAmount = amount.getMaxAmount();
|
||||
|
|
|
|||
|
|
@ -43,9 +43,13 @@ public class RedisServiceImpl implements RedisService {
|
|||
this.redisTemplate = redisTemplate;
|
||||
}
|
||||
|
||||
//spinning:amount:3
|
||||
@Override
|
||||
public void setDiscSpinningAmounts(String key) {
|
||||
List<DiscSpinningAmount> amounts = amountService.list(new QueryWrapper<DiscSpinningAmount>().eq("status", 1).orderByAsc("max_amount"));
|
||||
List<DiscSpinningAmount> amounts = amountService.list(new QueryWrapper<DiscSpinningAmount>()
|
||||
.eq("status", 1)
|
||||
.eq("type",key.split(":")[2])
|
||||
.orderByAsc("max_amount"));
|
||||
Map<Integer, List<DiscSpinningAmount>> map =
|
||||
amounts.stream().collect(Collectors.groupingBy(
|
||||
disc -> disc.getNum() == null ? 0 : disc.getNum()
|
||||
|
|
|
|||
Loading…
Reference in New Issue