zoujiajian 1 год назад
Родитель
Сommit
d2267f91f3

+ 7 - 1
netflix-service/src/main/java/com/cyksj/service/order/impl/VipOrderDonServiceImpl.java

@@ -27,6 +27,7 @@ import com.cyksj.model.request.OrderAttach;
 import com.cyksj.model.request.VipOrderDonPayReq;
 import com.cyksj.service.order.VipOrderDonService;
 import com.cyksj.service.pay.AliPayCommonService;
+import com.cyksj.service.relation.GroupRelationFrontService;
 import com.cyksj.service.user.UserBenefitsService;
 import com.cyksj.service.user.UserBindRelationService;
 import lombok.RequiredArgsConstructor;
@@ -69,6 +70,8 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
 
 	private final ShopConfigMapper shopConfigMapper;
 
+	private final GroupRelationFrontService groupRelationFrontService;
+
 	@Override
 	public VipOrderDon submit(VipOrderDonPayReq payRequest) {
 		Long userId = payRequest.getUserId();
@@ -195,7 +198,10 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
 	}
 
 	private void sendVipTicketToUser(Long userId) {
-
+		List<VipGoodsSku> skus = vipGoodsSkuMapper.selectList(null);
+		skus.forEach(sku -> {
+			groupRelationFrontService.getTicket(userId, sku.getSkuId(), Boolean.TRUE);
+		});
 	}
 
 	private void deductOrderMoney(VipOrderDon orderDon, User user, VipOrderDonPayReq payRequest) {

+ 5 - 0
netflix-service/src/main/java/com/cyksj/service/relation/GroupRelationFrontService.java

@@ -91,4 +91,9 @@ public interface GroupRelationFrontService {
 	Long getTrialTicketByUserIdAndGoodsId(Long userId, Long trialSkuId, Integer ticketType);
 
 	Boolean getMirrorPopups(long userId);
+
+	/**
+	 * 用户获取车票
+	 */
+	Long getTicket(Long userId, Long skuId, Boolean isVip);
 }

+ 48 - 0
netflix-service/src/main/java/com/cyksj/service/relation/impl/GroupRelationFrontServiceImpl.java

@@ -1309,6 +1309,54 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 		return flag;
 	}
 
+	@Override
+	public Long getTicket(Long userId, Long skuId, Boolean isVip) {
+		Retryer<Long> build = RetryerBuilder.<Long>newBuilder()
+				.retryIfException()
+				//运行时异常重试
+				.retryIfRuntimeException()
+				//false重试
+				.retryIfResult(res -> res == null)
+				//1s 间隔
+				.withWaitStrategy(WaitStrategies.fixedWait(1, TimeUnit.SECONDS))
+				//停止策略 : 尝试请求1次
+				.withStopStrategy(StopStrategies.stopAfterAttempt(1)).build();
+		try {
+			return build.call(() -> {
+				//体验规格
+				GroupsTrips groups = groupsMapper.selectCollegeStudentUserGptTicket(skuId);
+				GroupsRelation relation = null;
+				if (groups != null) {
+					relation = groupsRelationMapper.selectRandomOneRelationByGroupsId(groups.getId());
+				}
+				if (relation == null) {
+					//生成空车队
+					GoodsDonSku sku = goodsDonSkuMapper.selectById(skuId);
+					relation = groupsFuncService.createNewGroupsTrips(sku);
+				}
+				DateTime startTime = DateTime.now();
+				DateTime expiryTime = DateUtil.offsetDay(startTime, 1);
+				int update = groupsRelationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
+						.set(GroupsRelation::getUserId, userId)
+						.set(GroupsRelation::getStartTime, startTime)
+						.set(GroupsRelation::getExpiryTime, expiryTime)
+						.set(GroupsRelation::getStatus, GroupsRelation.Status.validity)
+						.set(GroupsRelation::getIsVip, isVip)
+						.eq(GroupsRelation::getId, relation.getId())
+						.eq(GroupsRelation::getUserId, 0));
+				if (update > 0) {
+					groupsMapper.decrAvailableNum(groups.getId());
+					return relation.getId();
+				}
+				log.error("发送用户:{} GPT镜像车票失败,进行重试", userId);
+				return null;
+			});
+		} catch (ExecutionException | RetryException e) {
+			log.error("发送用户GPT镜像失败:{}", StringUtil.getErrorText(e));
+			return null;
+		}
+	}
+
 	private DistributePosterGoodsDetailView setGoodsPoster(RenewalView ticket, User user, List<Long> userIds) {
 		DistributePosterGoodsDetailView distributePosterGoodsDetailView = beanSearcher.searchFirst(DistributePosterGoodsDetailView.class, MapUtils.flatBuilder(request.getParameterMap())
 				.field(DistributePosterGoodsFrontView::getGoodsId, ticket.getGoodsId()).build());