bravo-pool-batchGen
This commit is contained in:
@@ -68,9 +68,6 @@ public class BravoGiftSendService {
|
||||
BigDecimal everyoneGoldNum = everyGiftNumB.multiply(BigDecimal.valueOf(gift.getGoldPrice()));
|
||||
int multiple = everyoneGoldNum.divide(divisor, 0, RoundingMode.DOWN).intValue();
|
||||
|
||||
BigDecimal userNum = BigDecimal.valueOf(receiverList.size());
|
||||
long totalInput = userNum.multiply(everyoneGoldNum).longValue();
|
||||
|
||||
BravoGiftConfig config = getConfig();
|
||||
BravoGiftConfig partitionConfig = config.getRatioByPartitionId(partitionId);
|
||||
SuperLuckyGiftIncomeAllot incomeAllot = incomeAllotService.calculate(partitionConfig, gift, everyGiftNum, receiverList);
|
||||
@@ -80,10 +77,8 @@ public class BravoGiftSendService {
|
||||
log.info("[brave] uid {}, partitionId {}, addStockGoldNum {}, afterStock {}",
|
||||
senderUid, partitionId, incomeAllot.getRemainValue(), afterStock);
|
||||
|
||||
int userTicketNum = userMetaService.updateUserMetaBefore(senderUid, totalInput);
|
||||
|
||||
Map<Long, BravoRecord> recordMap = draw(config, senderUid, partitionId, gift, everyGiftNum, everyoneGoldNum,
|
||||
divisor, multiple, userTicketNum, receiverList, room, sendGiftTime);
|
||||
divisor, multiple, receiverList, room, sendGiftTime);
|
||||
log.info("[brave] uid {}, totalWinGoldNum {}", senderUid, JSON.toJSONString(recordMap));
|
||||
|
||||
sendMq(recordMap, incomeAllot);
|
||||
@@ -102,8 +97,8 @@ public class BravoGiftSendService {
|
||||
|
||||
public Map<Long, BravoRecord> draw(BravoGiftConfig config, Long senderUid, int partitionId,
|
||||
Gift gift, int everyGiftNum, BigDecimal everyInput, BigDecimal divisor, int multiple,
|
||||
int userTicketNum, List<Long> receiverList, Room room, Date sendGiftTime) {
|
||||
|
||||
List<Long> receiverList, Room room, Date sendGiftTime) {
|
||||
int userTicketNum = userMetaService.getUserTicketNum(senderUid);
|
||||
if (multiple > 1 && userTicketNum > 1){
|
||||
int needTicketNum = multiple == 2? 1 : multiple == 4 ? 2 : 8;
|
||||
int superNum = Math.min(userTicketNum / needTicketNum, receiverList.size());
|
||||
@@ -235,7 +230,7 @@ public class BravoGiftSendService {
|
||||
}
|
||||
|
||||
BigDecimal winGoldNum = afterMultiple.multiply(totalInput);
|
||||
userMetaService.updateUserMetaAfter(senderUid, totalInput, multiple, winGoldNum);
|
||||
userMetaService.updateUserMeta(senderUid, totalInput, multiple, winGoldNum);
|
||||
|
||||
return recordService.buildRecord(senderUid, partitionId, gift, giftNum, null != room? room.getUid(): null,
|
||||
receiverUid,isSupplement, afterMultiple, winGoldNum, sendGiftTime);
|
||||
@@ -259,7 +254,7 @@ public class BravoGiftSendService {
|
||||
BigDecimal multiple = drawResultList.stream().map(BravoResult::getAfterOutput).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
BigDecimal winGoldNum = multiple.multiply(divisor);
|
||||
BigDecimal totalAfterMultiple = winGoldNum.compareTo(BigDecimal.ZERO) > 0? winGoldNum.divide(totalInput, 2, RoundingMode.DOWN): BigDecimal.ZERO;
|
||||
userMetaService.updateUserMetaAfter(senderUid, totalInput, multipleGiftNum, winGoldNum);
|
||||
userMetaService.updateUserMeta(senderUid, totalInput, multipleGiftNum, winGoldNum);
|
||||
|
||||
return recordService.buildRecord(senderUid, partitionId, gift, giftNum, null != room? room.getUid(): null,
|
||||
receiverUid, drawResultList, false, totalAfterMultiple, winGoldNum, sendGiftTime);
|
||||
|
@@ -6,7 +6,6 @@ import com.accompany.business.service.SendSysMsgService;
|
||||
import com.accompany.business.service.user.UsersService;
|
||||
import com.accompany.business.vo.message.MessageTemplate;
|
||||
import com.accompany.business.vo.message.TextSpan;
|
||||
import com.accompany.common.constant.Attach;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.netease.neteaseacc.dto.BaseChatRoomMsg;
|
||||
import com.accompany.core.enumeration.I18nAlertEnum;
|
||||
|
@@ -51,7 +51,8 @@ public class BravoPoolService {
|
||||
return resultList;
|
||||
}
|
||||
}
|
||||
genPool(config, uid, partitionId, userPool);
|
||||
int poolNum = thisNum / config.getPoolSize() + 1;
|
||||
genPool(config, uid, partitionId, userPool, poolNum);
|
||||
}
|
||||
//还回去
|
||||
if (!CollectionUtils.isEmpty(resultList)){
|
||||
@@ -60,11 +61,11 @@ public class BravoPoolService {
|
||||
throw new ServiceException(BusiStatus.SERVERBUSY);
|
||||
}
|
||||
|
||||
private void genPool(BravoGiftConfig config, Long uid, int partitionId, RQueue<BravoResult> userPool) {
|
||||
private void genPool(BravoGiftConfig config, Long uid, int partitionId, RQueue<BravoResult> userPool, int poolNum) {
|
||||
boolean locked = false;
|
||||
RLock lock = redissonClient.getLock(RedisKey.bravo_user_lock.getKey(uid.toString()));
|
||||
try {
|
||||
locked = lock.tryLock(5,3, TimeUnit.SECONDS);
|
||||
locked = lock.tryLock(8,5, TimeUnit.SECONDS);
|
||||
|
||||
if (!userPool.isEmpty()){
|
||||
log.info("[bravo] genPool uid {} 已生成pool,无需再生成", uid);
|
||||
@@ -86,7 +87,7 @@ public class BravoPoolService {
|
||||
BravoGiftConfig partitionConfig = config.getRatioByPartitionId(partitionId);
|
||||
BravoPool pool = selectPool(config, partitionConfig, uid, poolType, poolList);
|
||||
|
||||
buildPool(config, uid, userPool, pool);
|
||||
buildPool(config, uid, userPool, pool, poolNum);
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -97,7 +98,7 @@ public class BravoPoolService {
|
||||
}
|
||||
}
|
||||
|
||||
private void buildPool(BravoGiftConfig config, Long uid, RQueue<BravoResult> userPool, BravoPool pool) {
|
||||
private void buildPool(BravoGiftConfig config, Long uid, RQueue<BravoResult> userPool, BravoPool pool, int poolNum) {
|
||||
List<BravoPool.BravoPoolItem> poolItemList = pool.getItemList().stream().filter(item->item.getNum()>0).collect(Collectors.toList());
|
||||
List<BigDecimal> winList = buildWinList(poolItemList);
|
||||
BigDecimal[] poolArray = new BigDecimal[config.getPoolSize()];
|
||||
@@ -125,7 +126,14 @@ public class BravoPoolService {
|
||||
result.setOutput(output);
|
||||
return result;
|
||||
}).collect(Collectors.toList());
|
||||
userPool.addAll(poolList);
|
||||
|
||||
List<BravoResult> batchPoolList = new ArrayList<>();
|
||||
for (int i = 0; i < poolNum; i++) {
|
||||
Collections.shuffle(poolList);
|
||||
batchPoolList.addAll(poolList);
|
||||
log.info("[bravo] genPool buildPool uid {}, batch {} poolList {}", uid, i, JSON.toJSONString(poolList));
|
||||
}
|
||||
userPool.addAll(batchPoolList);
|
||||
}
|
||||
|
||||
private List<BigDecimal> buildWinList(List<BravoPool.BravoPoolItem> poolItemList) {
|
||||
|
@@ -60,10 +60,16 @@ public class BravoUserMetaService {
|
||||
return productionRatio;
|
||||
}
|
||||
|
||||
public int updateUserMetaBefore(long senderUid, long input) {
|
||||
public void updateUserMeta(long senderUid, BigDecimal input, int times, BigDecimal output) {
|
||||
RList<BravoResult> historyQueue = getUserHistoryQueue(senderUid);
|
||||
historyQueue.add(0, new BravoResult(null, input, output, null, null));
|
||||
historyQueue.expireAsync(Duration.of(14, ChronoUnit.DAYS));
|
||||
|
||||
RMap<String, Number> userMetaMap = getUserMeta(senderUid);
|
||||
long totalOutput = userMetaMap.addAndGet(OUTPUT_KEY, output).longValue();
|
||||
long afterTimes = userMetaMap.addAndGet(TIMES_KEY, times).longValue();
|
||||
long totalInputAfter = userMetaMap.addAndGet(INPUT_KEY, input).longValue();
|
||||
long totalInputBefore = totalInputAfter - input;
|
||||
long totalInputBefore = totalInputAfter - input.longValue();
|
||||
|
||||
long addTicketNum = 0L;
|
||||
int remainTicketNum = 0;
|
||||
@@ -74,23 +80,8 @@ public class BravoUserMetaService {
|
||||
remainTicketNum = userMetaMap.addAndGet(TICKET_NUM_KEY, addTicketNum).intValue();
|
||||
}
|
||||
|
||||
log.info("[bravo] updateUserMetaBefore uid {} times {} totalInput {} addTicketNum {} remainTicketNum {}",
|
||||
senderUid, totalInputAfter, addTicketNum, remainTicketNum);
|
||||
|
||||
return remainTicketNum;
|
||||
}
|
||||
|
||||
public void updateUserMetaAfter(long senderUid, BigDecimal input, int times, BigDecimal output) {
|
||||
RList<BravoResult> historyQueue = getUserHistoryQueue(senderUid);
|
||||
historyQueue.add(0, new BravoResult(null, input, output, null, null));
|
||||
historyQueue.expireAsync(Duration.of(14, ChronoUnit.DAYS));
|
||||
|
||||
RMap<String, Number> userMetaMap = getUserMeta(senderUid);
|
||||
long totalOutput = userMetaMap.addAndGet(OUTPUT_KEY, output).longValue();
|
||||
long afterTimes = userMetaMap.addAndGet(TIMES_KEY, times).longValue();
|
||||
|
||||
log.info("[bravo] updateUserMetaAfter uid {} totalOutput {} afterTimes {}",
|
||||
senderUid, totalOutput, afterTimes);
|
||||
log.info("[bravo] updateUserMeta uid {} totalOutput {} times {} afterTimes {} totalInput {} addTicketNum {} remainTicketNum {}",
|
||||
senderUid, totalOutput, times, afterTimes, totalInputAfter, addTicketNum, remainTicketNum);
|
||||
}
|
||||
|
||||
public RMap<String, Number> getUserMeta(Long uid) {
|
||||
@@ -101,6 +92,11 @@ public class BravoUserMetaService {
|
||||
return redissonClient.getList(RedisKey.bravo_user_history.getKey(uid.toString()));
|
||||
}
|
||||
|
||||
public int getUserTicketNum(Long uid) {
|
||||
RMap<String, Number> userMetaMap = redissonClient.getMap(RedisKey.bravo_user_meta.getKey(uid.toString()));
|
||||
return userMetaMap.getOrDefault(TICKET_NUM_KEY, 0).intValue();
|
||||
}
|
||||
|
||||
public int subSuperNum(long uid, int needTicketNum, int superNum, int superTicketNum) {
|
||||
RMap<String, Number> userMetaMap = getUserMeta(uid);
|
||||
int afterNum = userMetaMap.addAndGet(TICKET_NUM_KEY, -superTicketNum).intValue();
|
||||
|
Reference in New Issue
Block a user