幸运24-雪花主键-mq-合并topic
This commit is contained in:
@@ -32,7 +32,7 @@ import java.util.Optional;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class Lucky24MessageService extends BaseService implements InitializingBean {
|
||||
public class Lucky24MessageService implements InitializingBean {
|
||||
|
||||
@Autowired
|
||||
private RedissonClient redissonClient;
|
||||
@@ -66,37 +66,6 @@ public class Lucky24MessageService extends BaseService implements InitializingBe
|
||||
Gift gift = giftService.getGiftById(giftMessage.getGiftId());
|
||||
Date createTime = new Date(giftMessage.getCreateTime());
|
||||
|
||||
Lucky24Record record = insertRecord(giftMessage);
|
||||
|
||||
log.info("【处理lucky24 mq】 record 插入成功 messId:{} recordId:{} record:{}",
|
||||
giftMessage.getMessId(), record.getId(), JSON.toJSONString(record));
|
||||
|
||||
// 收礼者收益
|
||||
Lucky24GiftConfig config = sendService.getConfig();
|
||||
Lucky24GiftConfig partitionConfig = config.getRatioByPartitionId(giftMessage.getPartitionId());
|
||||
SuperLuckyGiftIncomeAllot receiverIncomeAllot = incomeAllotService.calculate(partitionConfig, gift, giftMessage.getGiftNum(), Collections.singletonList(record.getReceiverUid()));
|
||||
superLuckyGiftSendService.syncSettlement(giftMessage.getUid(), gift, giftMessage.getGiftNum(), giftMessage.getGiftNum(), room, receiverIncomeAllot, createTime);
|
||||
|
||||
logger.info("【处理lucky24 mq】 收礼收益已发放 messId: {} incomeAllot: {}", giftMessage.getMessId(), JSON.toJSONString(receiverIncomeAllot));
|
||||
|
||||
// 异步,报错不会触发mq重试
|
||||
if (!CollectionUtils.isEmpty(config.getFollowUidList()) && config.getFollowUidList().contains(record.getUid())){
|
||||
robotMsgService.pushFollowUser(record.getUid(), record.getReceiverUid(), record.getRoomUid());
|
||||
}
|
||||
|
||||
// 异步,报错不会触发mq重试
|
||||
lucky24SendWeekRankService.updateRank(record);
|
||||
|
||||
// 删除该标识,表示消息已经消费过
|
||||
jedisService.hdel(RedisKey.lucky_24_status.getKey(), giftMessage.getMessId());
|
||||
}
|
||||
|
||||
public void handleMessageV2(Lucky24Message giftMessage) {
|
||||
|
||||
Room room = null != giftMessage.getRoomUid()? roomService.getRoomByUid(giftMessage.getRoomUid()): null;
|
||||
Gift gift = giftService.getGiftById(giftMessage.getGiftId());
|
||||
Date createTime = new Date(giftMessage.getCreateTime());
|
||||
|
||||
Optional<Lucky24Record> recordOptional = insertRecordIgnore(giftMessage);
|
||||
if (recordOptional.isEmpty()){
|
||||
return;
|
||||
@@ -113,7 +82,7 @@ public class Lucky24MessageService extends BaseService implements InitializingBe
|
||||
SuperLuckyGiftIncomeAllot receiverIncomeAllot = incomeAllotService.calculate(partitionConfig, gift, giftMessage.getGiftNum(), Collections.singletonList(record.getReceiverUid()));
|
||||
superLuckyGiftSendService.syncSettlement(giftMessage.getUid(), gift, giftMessage.getGiftNum(), giftMessage.getGiftNum(), room, receiverIncomeAllot, createTime);
|
||||
|
||||
logger.info("【处理lucky24 mq】 收礼收益已发放 messId: {} incomeAllot: {}", giftMessage.getMessId(), JSON.toJSONString(receiverIncomeAllot));
|
||||
log.info("【处理lucky24 mq】 收礼收益已发放 messId: {} incomeAllot: {}", giftMessage.getMessId(), JSON.toJSONString(receiverIncomeAllot));
|
||||
|
||||
// 异步,报错不会触发mq重试
|
||||
if (!CollectionUtils.isEmpty(config.getFollowUidList()) && config.getFollowUidList().contains(record.getUid())){
|
||||
@@ -127,44 +96,6 @@ public class Lucky24MessageService extends BaseService implements InitializingBe
|
||||
recordMessMap.fastRemove(giftMessage.getMessId());
|
||||
}
|
||||
|
||||
private Lucky24Record insertRecord(Lucky24Message giftMessage) {
|
||||
Lucky24Record record = new Lucky24Record();
|
||||
|
||||
if (null == giftMessage.getId()){
|
||||
giftMessage.setId(identifierGenerator.nextId( null).longValue());
|
||||
}
|
||||
|
||||
record.setId(giftMessage.getId());
|
||||
record.setMessId(giftMessage.getMessId());
|
||||
record.setPartitionId(giftMessage.getPartitionId());
|
||||
record.setUid(giftMessage.getUid());
|
||||
record.setReceiverUid(giftMessage.getReceiverUid());
|
||||
record.setRoomUid(giftMessage.getRoomUid());
|
||||
record.setGiftId(giftMessage.getGiftId());
|
||||
record.setGiftGoldPrice(giftMessage.getGiftGoldPrice());
|
||||
record.setGiftNum(giftMessage.getGiftNum());
|
||||
record.setPoolType(giftMessage.getPoolType());
|
||||
record.setPoolId(giftMessage.getPoolId());
|
||||
|
||||
if (null == giftMessage.getPoolType() && null != giftMessage.getPoolId()){
|
||||
Lucky24Pool pool = poolMapper.selectById(giftMessage.getPoolId());
|
||||
if (null != pool){
|
||||
record.setPoolType(pool.getType());
|
||||
}
|
||||
}
|
||||
|
||||
record.setIsSupplement(giftMessage.getIsSupplement());
|
||||
record.setDrawMultiple(giftMessage.getDrawMultiple());
|
||||
record.setAfterMultiple(giftMessage.getAfterMultiple());
|
||||
record.setWinGoldNum(giftMessage.getWinGoldNum());
|
||||
record.setCreateTime(new Date(giftMessage.getCreateTime()));
|
||||
record.setStockResult(giftMessage.getStockResult());
|
||||
|
||||
recordService.insertRecord(record);
|
||||
|
||||
return record;
|
||||
}
|
||||
|
||||
private Optional<Lucky24Record> insertRecordIgnore(Lucky24Message giftMessage) {
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
@@ -57,7 +57,7 @@ public class RocketMQService {
|
||||
List<Message<String>> messageList = lucky24Messages.stream()
|
||||
.map(giftMessage -> MessageBuilder.withPayload(JSON.toJSONString(giftMessage)).build())
|
||||
.collect(Collectors.toList());
|
||||
mqMessageProducer.send(MqConstant.LUCKY_24_V2_TOPIC, messageList,
|
||||
mqMessageProducer.send(MqConstant.LUCKY_24_TOPIC, messageList,
|
||||
sendResult -> log.info("sendLucky24Message success result: {} message: {}", JSON.toJSONString(sendResult), messageList),
|
||||
throwable -> log.error("sendLucky24Message fail message: {}", messageList, throwable));
|
||||
}
|
||||
|
Reference in New Issue
Block a user