幸运24-额外-判断和库存不足退回削峰

This commit is contained in:
2025-10-16 17:24:24 +08:00
parent fe91bdb278
commit e6adfb387e
2 changed files with 85 additions and 10 deletions

View File

@@ -104,7 +104,7 @@ public class Lucky24GiftSendService {
List<Long> receiverList, Room room, Date sendGiftTime, boolean extraSwitch) {
if (!extraSwitch
|| config.getBlackUidList().contains(senderUid)
|| userMetaService.getTimes(senderUid) <= (long) config.getNewUserPoolCount() * config.getPoolSize()){
|| userMetaService.getTimes(senderUid) <= (long) config.getPoolSize() * config.getNewUserPoolCount()){
return draw(config, partitionConfig, senderUid, partitionId, gift, everyGiftNum, everyoneGoldNum, receiverList, room, sendGiftTime);
}
@@ -114,9 +114,15 @@ public class Lucky24GiftSendService {
return draw(config, partitionConfig, senderUid, partitionId, gift, everyGiftNum, everyoneGoldNum, receiverList, room, sendGiftTime);
}
int extraDrawMultiple = extraService.drawMultiple(extraPoolConfig, senderUid, partitionId);
Lucky24Result extraResult = new Lucky24Result(Lucky24PoolTypeEnum.EXTRA_POOL.getType(), null, everyoneGoldNum, extraDrawMultiple, false);
Lucky24Record extraRecord = updateMeta(config, partitionConfig, senderUid, partitionId, gift, everyGiftNum, extraLuckerUid, everyoneGoldNum, room, sendGiftTime, null, extraResult);
Integer extraDrawMultiple = extraService.drawMultiple(extraPoolConfig, senderUid, partitionId);
if (null == extraDrawMultiple){
return draw(config, partitionConfig, senderUid, partitionId, gift, everyGiftNum, everyoneGoldNum, receiverList, room, sendGiftTime);
}
Lucky24Record extraRecord = extraService.buildRecord(config, partitionConfig, senderUid, partitionId, extraLuckerUid, gift, everyGiftNum, everyoneGoldNum, room, sendGiftTime, extraDrawMultiple);
if (null == extraRecord){
return draw(config, partitionConfig, senderUid, partitionId, gift, everyGiftNum, everyoneGoldNum, receiverList, room, sendGiftTime);
}
List<Long> receiverUidList = new ArrayList<>(receiverList);
receiverUidList.remove(extraLuckerUid);

View File

@@ -1,8 +1,15 @@
package com.accompany.business.service.lucky;
import com.accompany.business.constant.Lucky24PoolTypeEnum;
import com.accompany.business.dto.lucky.Lucky24GiftConfig;
import com.accompany.business.dto.lucky.Lucky24Result;
import com.accompany.business.model.Gift;
import com.accompany.common.utils.DateTimeUtil;
import com.accompany.core.enumeration.PartitionEnum;
import com.accompany.core.model.Room;
import com.accompany.payment.service.UserRechargeLevelService;
import com.accompany.sharding.model.Lucky24Record;
import com.accompany.sharding.vo.Lucky24StockResultVo;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RMap;
import org.springframework.beans.factory.annotation.Autowired;
@@ -24,6 +31,15 @@ public class Lucky24ExtraService {
private Lucky24ExtraStockService stockService;
@Autowired
private Lucky24UserMetaService userMetaService;
@Autowired
private Lucky24RobotMsgService robotMsgService;
@Autowired
private Lucky24SettlementService settlementService;
@Autowired
private Lucky24RecordService recordService;
@Autowired
private UserRechargeLevelService userRechargeLevelService;
public BigDecimal addStock(Integer partitionId, BigDecimal addScore) {
return stockService.addStock(partitionId, addScore);
}
@@ -105,7 +121,7 @@ public class Lucky24ExtraService {
return luckyer;
}
public int drawMultiple(Lucky24GiftConfig.Lucky24ExtraPoolConfig extraPoolConfig, long senderUid, Integer partitionId) {
public Integer drawMultiple(Lucky24GiftConfig.Lucky24ExtraPoolConfig extraPoolConfig, long senderUid, Integer partitionId) {
Map<String, Number> userMetaMapSnapshot = userMetaService.getUserMeta(senderUid).readAllMap();
@@ -128,11 +144,11 @@ public class Lucky24ExtraService {
// floor返回小于或等于 key 的最大键值对
Map.Entry<BigDecimal, TreeMap<Long, TreeMap<BigDecimal, Integer>>> inputJudgeEntry = extraPoolConfig.getJudgeConfig().floorEntry(todayAvgInput);
if (null == inputJudgeEntry){
return 0;
return null;
}
TreeMap<Long, TreeMap<BigDecimal, Integer>> inputJudgeMap = inputJudgeEntry.getValue();
if (CollectionUtils.isEmpty(inputJudgeMap)){
return 0;
return null;
}
log.info("[lucky24] extra randomExtra first uid {} partitionId {} todayInput {} todayTimes {} todayAvgInput {} ceilingKey {}",
@@ -148,11 +164,11 @@ public class Lucky24ExtraService {
// ceiling返回大于或等于 key 的最小键值对
Map.Entry<Long, TreeMap<BigDecimal, Integer>> threeDayAgoInputEntry = inputJudgeMap.ceilingEntry(threeDayAgoInput);
if (null == threeDayAgoInputEntry){
return 0;
return null;
}
TreeMap<BigDecimal, Integer> threeDayAgoInputMap = threeDayAgoInputEntry.getValue();
if (CollectionUtils.isEmpty(threeDayAgoInputMap)){
return 0;
return null;
}
log.info("[lucky24] extra randomExtra second uid {} partitionId {} todayInput {} twoDayAgoInput {} threeDayAgoInput {} floorKey {}",
@@ -170,7 +186,8 @@ public class Lucky24ExtraService {
// floor返回小于或等于 key 的最大键值对
Map.Entry<BigDecimal, Integer> threeDayProductionRatioEntry = threeDayAgoInputMap.ceilingEntry(threeDayProductionRatio);
int drawMultiple = null == threeDayProductionRatioEntry || null == threeDayProductionRatioEntry.getValue()? 0: threeDayProductionRatioEntry.getValue();
Integer drawMultiple = null == threeDayProductionRatioEntry || null == threeDayProductionRatioEntry.getValue()?
null: threeDayProductionRatioEntry.getValue();
log.info("[lucky24] extra randomExtra uid {} partitionId {} todayOutput {} twoDayAgoOutput {} threeDayAgoOutput {} threeDayAgoInput {} productionRation {} floorKey {} result {}",
senderUid, partitionId, todayOutput, twoDayAgoOutput, threeDayAgoOutput, threeDayAgoInput, threeDayProductionRatio.toPlainString(), threeDayAgoInputEntry.getKey(), drawMultiple);
@@ -178,4 +195,56 @@ public class Lucky24ExtraService {
return drawMultiple;
}
public Lucky24Record buildRecord(Lucky24GiftConfig config, Lucky24GiftConfig partitionConfig, long senderUid, Integer partitionId, Long receiverUid,
Gift gift, int giftNum, long everyoneGoldNum, Room room, Date sendGiftTime, Integer drawMultiple){
long afterMultiple = drawMultiple;
// 额外平台库存
long preWinGoldNum = afterMultiple * everyoneGoldNum;
BigDecimal preWinGoldNumDecimal = BigDecimal.valueOf(preWinGoldNum);
Lucky24StockResultVo stockResultVo = judgeStock(partitionId, preWinGoldNumDecimal, senderUid, receiverUid, gift, giftNum, everyoneGoldNum, room, sendGiftTime);
if (!stockResultVo.isSuccess()){
return null;
}
// 个人库存
String userRechargeLevel = userRechargeLevelService.getLevelByUid(senderUid);
stockResultVo = userMetaService.judgePersonalStock(partitionConfig, senderUid, receiverUid, everyoneGoldNum, userRechargeLevel, afterMultiple, preWinGoldNum);
afterMultiple = stockResultVo.getMultiple();
long winGoldNum = afterMultiple * everyoneGoldNum;
if (winGoldNum > 0L){
settlementService.sendReward(config, senderUid, room, gift, winGoldNum, afterMultiple);
}
userMetaService.updateUserMeta(senderUid, partitionId, everyoneGoldNum, winGoldNum);
log.info("[lucky24] extra uid {} partitionId {} receiverUid {} drawMultiple {} preWinGoldNum {} afterMultiple {} winGoldNum {}",
senderUid, partitionId, receiverUid, drawMultiple, preWinGoldNum, afterMultiple, winGoldNum);
return recordService.buildRecord(senderUid, partitionId, gift, giftNum, null != room ? room.getUid() : null,
receiverUid, Lucky24PoolTypeEnum.EXTRA_POOL.getType(), null,
Boolean.FALSE, drawMultiple, afterMultiple, !stockResultVo.isSuccess()? stockResultVo: null, sendGiftTime);
}
private Lucky24StockResultVo judgeStock(Integer partitionId, BigDecimal winGoldNum, Long senderUid, Long receiverUid,
Gift gift, int giftNum, long everyoneGoldNum,
Room room, Date sendGiftTime){
BigDecimal afterStock = stockService.subStock(partitionId, winGoldNum);
BigDecimal beforeStock = afterStock.add(winGoldNum);
boolean enough = afterStock.compareTo(BigDecimal.ZERO) >= 0;
if (!enough){
log.info("[lucky24] extraStock sender {} receiver {} 产出大于库存 winGoldNum {} afterStock {}",
senderUid, receiverUid, winGoldNum, afterStock);
afterStock = stockService.addStock(partitionId, winGoldNum);
robotMsgService.pushExtraStockNotEnough(partitionId, afterStock, senderUid, receiverUid, gift, giftNum, everyoneGoldNum, winGoldNum, room, sendGiftTime);
}
Lucky24StockResultVo resultVo = new Lucky24StockResultVo();
resultVo.setSuccess(enough);
resultVo.setExtraStock(beforeStock);
resultVo.setPreWinGoldNum(winGoldNum);
return resultVo;
}
}