Merge remote-tracking branch 'origin/test' into test
This commit is contained in:
commit
d8b4e2c731
|
|
@ -207,9 +207,9 @@ public class DiscSpinningController {
|
|||
} else {
|
||||
String redisKey = "";
|
||||
if (source.equals(2)) {
|
||||
redisKey = RedisKeys.getDateKey("spinning:amount:taskW") + userId;
|
||||
redisKey = RedisKeys.getDateKey("spinning:draw:taskW") + userId;
|
||||
} else if (source.equals(3)) {
|
||||
redisKey = RedisKeys.getDateKey("spinning:amount:taskM") + userId;
|
||||
redisKey = RedisKeys.getDateKey("spinning:draw:taskM") + userId;
|
||||
}
|
||||
Map<String, Object> week = redisUtils.get(redisKey, Map.class);
|
||||
for (Map.Entry<String, Object> entry : week.entrySet()) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -97,20 +98,19 @@ public class DiscSpinningServiceImpl extends ServiceImpl<DiscSpinningDao, DiscSp
|
|||
@Transactional
|
||||
public DiscSpinningRecord draws(int drawCount, double orderAmount, Long sourceId, Long userId, Integer source) {
|
||||
DiscSpinning result = new DiscSpinning("谢谢惠顾", 1, BigDecimal.ZERO);
|
||||
List<DiscSpinning> prizes = baseMapper.selectList(new QueryWrapper<DiscSpinning>().eq("disc_type", source).orderByAsc("odds"));
|
||||
List<DiscSpinning> prizes = baseMapper.selectList(new QueryWrapper<DiscSpinning>().eq("disc_type", source).orderByAsc("number"));
|
||||
if (CollectionUtil.isEmpty(prizes)) {
|
||||
DiscSpinningRecord record = new DiscSpinningRecord(result.getName(), sourceId, userId, result.getUrl(), result.getType(),
|
||||
result.getNumber(), DateUtils.formatYMD(new Date()), DateUtils.format(new Date()), source);
|
||||
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()
|
||||
|
|
|
|||
|
|
@ -363,7 +363,7 @@ public class TaskCenterServiceImpl extends ServiceImpl<TaskCenterDao, TaskCenter
|
|||
}
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(taskWRedisMap)) {
|
||||
redisUtils.set(RedisKeys.getDateKey("spinning:amount:taskW") + userId, taskWRedisMap, DateUtils.todayAfterSecond());
|
||||
redisUtils.set(RedisKeys.getDateKey("spinning:draw:taskW") + userId, taskWRedisMap, DateUtils.todayAfterSecond());
|
||||
}
|
||||
} else if ("3".equals(type)) {
|
||||
if (signCount == null) {
|
||||
|
|
@ -379,7 +379,7 @@ public class TaskCenterServiceImpl extends ServiceImpl<TaskCenterDao, TaskCenter
|
|||
}
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(taskWRedisMap)) {
|
||||
redisUtils.set(RedisKeys.getDateKey("spinning:amount:taskM") + userId, taskWRedisMap, DateUtils.todayAfterSecond());
|
||||
redisUtils.set(RedisKeys.getDateKey("spinning:draw:taskM") + userId, taskWRedisMap, DateUtils.todayAfterSecond());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue