123
This commit is contained in:
@@ -83,6 +83,9 @@ public class PrizeInfoController extends BaseController {
|
||||
@RepeatSubmit()
|
||||
@PutMapping()
|
||||
public R<Void> edit(@Validated(EditGroup.class) @RequestBody PrizeInfo bo) {
|
||||
if(bo.getId() == 1){
|
||||
return R.fail("无法编辑系统内置谢谢惠顾");
|
||||
}
|
||||
return toAjax(prizeInfoService.updateById(bo));
|
||||
}
|
||||
|
||||
@@ -96,6 +99,10 @@ public class PrizeInfoController extends BaseController {
|
||||
@DeleteMapping("/{ids}")
|
||||
public R<Void> remove(@NotEmpty(message = "主键不能为空")
|
||||
@PathVariable Long[] ids) {
|
||||
return toAjax(prizeInfoService.removeBatchByIds(Arrays.asList(ids), true));
|
||||
List<Long> idArray = Arrays.asList(ids);
|
||||
if(idArray.contains(1L)){
|
||||
return R.fail("无法删除系统内置谢谢惠顾");
|
||||
}
|
||||
return toAjax(prizeInfoService.removeBatchByIds(idArray, true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,8 +34,6 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
@Slf4j
|
||||
public class LotteryService {
|
||||
|
||||
// 固定配置
|
||||
private static final Long THANKS_PRIZE_ID = 0L;
|
||||
private static final String USER_DRAW_COUNT_KEY = "user:draw:count:%s";
|
||||
private static final long USER_DRAW_COUNT_EXPIRE = 7 * 24 * 60 * 60; // 用户累计抽数缓存过期时间:7天
|
||||
private static final double RANDOM_MAX = 10000; // 概率放大倍数,提升随机数精度
|
||||
@@ -69,14 +67,14 @@ public class LotteryService {
|
||||
if(user == null){
|
||||
throw new ServiceException("用户不存在");
|
||||
}
|
||||
boolean openDraw = drawService.getOpenDraw(user.getGender());
|
||||
if(!openDraw){
|
||||
throw new ServiceException("暂未开启积分抽奖,请等待活动通知");
|
||||
}
|
||||
boolean select = GenderEnum.isSelect(user.getGender());
|
||||
if(select){
|
||||
throw new ServiceException("请选择性别后在抽奖");
|
||||
}
|
||||
boolean openDraw = drawService.getOpenDraw(user.getGender());
|
||||
if(!openDraw){
|
||||
throw new ServiceException("暂未开启积分抽奖,请等待活动通知");
|
||||
}
|
||||
Account account = accountService.getByUserId(user.getId());
|
||||
Integer drawPoint = drawService.getDrawPoint(user.getGender());
|
||||
if(account.getPoints() < drawPoint){
|
||||
@@ -120,10 +118,23 @@ public class LotteryService {
|
||||
int currentContinuousDraws = getContinuousDraws(userId);
|
||||
int newContinuousDraws = currentContinuousDraws + 1;
|
||||
log.info("用户{}当前累计抽数:{},本次抽数:{}", userId, currentContinuousDraws, newContinuousDraws);
|
||||
// 步骤2:获取有效奖品列表(启用状态,排除谢谢惠顾)
|
||||
// 步骤2:获取所有奖品列表
|
||||
List<PrizeOnline> validPrizes = prizeOnlineService.selectPrizeOnlineList(user.getGender());
|
||||
if (validPrizes.isEmpty()) {
|
||||
throw new ServiceException("无有效奖品,请刷新页面后再次抽奖");
|
||||
throw new ServiceException("无有效奖品,请刷新后再次抽奖");
|
||||
}
|
||||
// 找出系统内置谢谢惠顾
|
||||
PrizeOnline thankPrize = null;
|
||||
for (int i = 0; i < validPrizes.size(); i++) {
|
||||
PrizeOnline validPrize = validPrizes.get(i);
|
||||
if(validPrize.getPrizeId() == 1){
|
||||
thankPrize = validPrize;
|
||||
validPrizes.remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(thankPrize == null){
|
||||
throw new ServiceException("奖品库异常,请刷新后再次抽奖");
|
||||
}
|
||||
// 步骤3:执行抽奖规则(保底→最低抽数过滤→概率抽奖)
|
||||
PrizeOnline winPrize = null;
|
||||
@@ -236,13 +247,10 @@ public class LotteryService {
|
||||
if (cacheCount != null) {
|
||||
return cacheCount;
|
||||
}
|
||||
// 2. 缓存未命中,从数据库查询最后一次累计抽数
|
||||
// Integer dbCount = userDrawRecordMapper.selectLastContinuousDraws(userId);
|
||||
Integer dbCount = 0;
|
||||
int finalCount = dbCount == null ? 0 : dbCount;
|
||||
// 3. 存入缓存(设置过期时间)
|
||||
bucket.set(finalCount, USER_DRAW_COUNT_EXPIRE, java.util.concurrent.TimeUnit.SECONDS);
|
||||
return finalCount;
|
||||
// 3. 存入缓存
|
||||
// bucket.set(0, USER_DRAW_COUNT_EXPIRE, java.util.concurrent.TimeUnit.SECONDS);
|
||||
bucket.set(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -45,18 +45,25 @@ public class PrizeOnlineServiceImpl extends ServiceImpl<PrizeOnlineMapper,PrizeO
|
||||
throw new ServiceException("奖品必须为9个");
|
||||
}
|
||||
boolean hasNone = false;
|
||||
int bigNum = 0;
|
||||
List<Long> prizeIds = new ArrayList<>();
|
||||
for (PrizeOnline prizeOnline : bo) {
|
||||
prizeOnline.setGender(gender);
|
||||
if(PrizeTypeEnum.NONE.getCode().equals(prizeOnline.getPrizeType())){
|
||||
if(prizeOnline.getPrizeId() != null && prizeOnline.getPrizeId() == 1){
|
||||
hasNone = true;
|
||||
}
|
||||
if(PrizeTypeEnum.GOOD.getCode().equals(prizeOnline.getPrizeType())){
|
||||
bigNum++;
|
||||
}
|
||||
if(prizeOnline.getId() != null){
|
||||
prizeIds.add(prizeOnline.getId());
|
||||
}
|
||||
}
|
||||
if(!hasNone){
|
||||
throw new ServiceException("奖品必须包含谢谢惠顾");
|
||||
throw new ServiceException("奖品必须包含内置的谢谢惠顾");
|
||||
}
|
||||
if(bigNum > 1){
|
||||
throw new ServiceException("奖品只能有1个大奖");
|
||||
}
|
||||
List<PrizeOnline> dbList = this.selectPrizeOnlineList(gender);
|
||||
List<Long> dbIds = dbList.stream().map(PrizeOnline::getId).collect(Collectors.toList());
|
||||
|
||||
Reference in New Issue
Block a user