|
|
@@ -2801,13 +2801,16 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
|
|
|
GoodsDonSku giftSku = goodsDonSkuMapper.selectById(Constant.GPT_ACTIVITY_GIFT_SKU_ID);
|
|
|
GroupsRelation giftRelation = null;
|
|
|
try {
|
|
|
- Long giftRelationId = getTicket(userId, giftSku.getId(), Boolean.FALSE);
|
|
|
- if (giftRelationId == null) {
|
|
|
- throw BusinessRuntimeException.getInstance("系统繁忙,请重新领取");
|
|
|
- }
|
|
|
- giftRelation = groupsRelationMapper.selectById(giftRelationId);
|
|
|
+ giftRelation = getReusableGptActivityGiftRelation(userIds, giftSku.getId());
|
|
|
if (giftRelation == null) {
|
|
|
- throw BusinessRuntimeException.getInstance("系统繁忙,请重新领取");
|
|
|
+ Long giftRelationId = getTicket(userId, giftSku.getId(), Boolean.FALSE);
|
|
|
+ if (giftRelationId == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("系统繁忙,请重新领取");
|
|
|
+ }
|
|
|
+ giftRelation = groupsRelationMapper.selectById(giftRelationId);
|
|
|
+ if (giftRelation == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("系统繁忙,请重新领取");
|
|
|
+ }
|
|
|
}
|
|
|
GptActivityRedeemResult redeemResult = requestGptActivityRedeemCode(Constant.AI_API_SVC_DOMAIN, giftRelation, giftSku);
|
|
|
record.setRelationId(giftRelation.getId());
|
|
|
@@ -2841,6 +2844,21 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private GroupsRelation getReusableGptActivityGiftRelation(List<Long> userIds, Long giftSkuId) {
|
|
|
+ TicketRedemptionCodeRecord retryRecord = ticketRedemptionCodeRecordMapper.selectOne(Wrappers.lambdaQuery(TicketRedemptionCodeRecord.class)
|
|
|
+ .in(TicketRedemptionCodeRecord::getUserId, userIds)
|
|
|
+ .eq(TicketRedemptionCodeRecord::getSkuId, giftSkuId)
|
|
|
+ .eq(TicketRedemptionCodeRecord::getSourceType, RedisKey.GPT_API_QUOTA_KEY)
|
|
|
+ .eq(TicketRedemptionCodeRecord::getStatus, "error")
|
|
|
+ .isNotNull(TicketRedemptionCodeRecord::getRelationId)
|
|
|
+ .orderByDesc(TicketRedemptionCodeRecord::getId)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (retryRecord != null) {
|
|
|
+ return groupsRelationMapper.selectById(retryRecord.getRelationId());
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
private GptActivityRedeemResult requestGptActivityRedeemCode(String apiDomain, GroupsRelation giftRelation, GoodsDonSku giftSku) throws Exception {
|
|
|
//默认5刀额度
|
|
|
Integer quota = 2500000;
|