From 37c866f665fc1d2255f0442f92516c686c6c9edf Mon Sep 17 00:00:00 2001
From: kong <sunuping1@sina.com>
Date: 星期日, 12 四月 2026 16:55:52 +0800
Subject: [PATCH] add 优惠券切换
---
xp-robotaxi-itinerary-boot/src/main/java/com/xiaopeng/itinerary/service/impl/XpPricingServiceImpl.java | 43 ++++++++++++++++++++++---------------------
1 files changed, 22 insertions(+), 21 deletions(-)
diff --git a/xp-robotaxi-itinerary-boot/src/main/java/com/xiaopeng/itinerary/service/impl/XpPricingServiceImpl.java b/xp-robotaxi-itinerary-boot/src/main/java/com/xiaopeng/itinerary/service/impl/XpPricingServiceImpl.java
index 79c8241..35c1dbe 100644
--- a/xp-robotaxi-itinerary-boot/src/main/java/com/xiaopeng/itinerary/service/impl/XpPricingServiceImpl.java
+++ b/xp-robotaxi-itinerary-boot/src/main/java/com/xiaopeng/itinerary/service/impl/XpPricingServiceImpl.java
@@ -269,26 +269,23 @@
);
}
- // 优惠券
+ // 优惠券:null=自动最佳;0=不使用;>0=指定券
XpPricingCardVo finalXpPricingCardVo = xpPricingCardVo;
R<UserCouponVo> coupon = null;
CompletableFuture<R<UserCouponVo>> couponFuture=null;
- // 判断是否指定优惠券
- if(routeAndFareDto.getUserCouponId()!=null){
- coupon = xpAppUserCouponClient.getUserCoupon(new GetUserCouponDto(Long.valueOf(userId), finalXpPricingCardVo.getTotalPrice(), routeAndFareDto.getOpenCityId(),routeAndFareDto.getUserCouponId()));
+ Long ucId = routeAndFareDto.getUserCouponId();
+ if (Long.valueOf(0L).equals(ucId)) {
+ coupon = R.ok(new UserCouponVo());
+ } else if (ucId != null && ucId > 0L) {
+ coupon = xpAppUserCouponClient.getUserCoupon(new GetUserCouponDto(Long.valueOf(userId), finalXpPricingCardVo.getTotalPrice(), routeAndFareDto.getOpenCityId(), ucId));
if(coupon.getCode()==200 && coupon.getData().getStatus()==2){
throw new ServiceException("优惠券不满足条件", I18nKeyConstant.COUPON_NOT_SATISFY);
}
- }else {
-
+ } else {
couponFuture= CompletableFuture.supplyAsync(
- () -> {
- // 优惠券
- return xpAppUserCouponClient.getUserCoupon(
- new GetUserCouponDto(Long.valueOf(userId), finalXpPricingCardVo.getTotalPrice(), routeAndFareDto.getOpenCityId(),null)
-// new GetUserCouponDto(Long.valueOf(userId), 1d, routeAndFareDto.getOpenCityId())
- );
- },
+ () -> xpAppUserCouponClient.getUserCoupon(
+ new GetUserCouponDto(Long.valueOf(userId), finalXpPricingCardVo.getTotalPrice(), routeAndFareDto.getOpenCityId(),null)
+ ),
executorService
);
}
@@ -304,10 +301,10 @@
// 4. 等待所有并行任务完成并获取结果
R<Boolean> diagnosisResult = diagnosisAreaFuture.join();
R<UserCouponVo> couponResult =null;
- if(routeAndFareDto.getUserCouponId()!=null){
- couponResult =coupon;
- }else {
- couponResult =couponFuture.join();
+ if (Long.valueOf(0L).equals(ucId) || (ucId != null && ucId > 0L)) {
+ couponResult = coupon;
+ } else {
+ couponResult = couponFuture.join();
}
// 5. 处理诊断结果
@@ -617,7 +614,8 @@
}
final Integer planRuleForQueue = dto.getSelectedRoutePlanRule() != null ? dto.getSelectedRoutePlanRule()
: (xpRoutePlan != null ? xpRoutePlan.getRoutePlanRule() : null);
- xpOrder.setCouponId(dto.getUserCouponId());
+ Long couponRef = dto.getUserCouponId();
+ xpOrder.setCouponId(couponRef != null && couponRef > 0L ? couponRef : null);
// 产生订单
R<Long> addOrderR = xpOrderClient.addOrder(xpOrder);
if (addOrderR.getCode() != R.SUCCESS) {
@@ -765,9 +763,12 @@
}
R<UserCouponVo> coupon = null;
CompletableFuture<R<UserCouponVo>> couponFuture = null;
- if (routeAndFareDto.getUserCouponId() != null) {
+ Long ucId = routeAndFareDto.getUserCouponId();
+ if (Long.valueOf(0L).equals(ucId)) {
+ coupon = R.ok(new UserCouponVo());
+ } else if (ucId != null && ucId > 0L) {
coupon = xpAppUserCouponClient.getUserCoupon(
- new GetUserCouponDto(Long.valueOf(userId), xpPricingCardVo.getTotalPrice(), routeAndFareDto.getOpenCityId(), routeAndFareDto.getUserCouponId()));
+ new GetUserCouponDto(Long.valueOf(userId), xpPricingCardVo.getTotalPrice(), routeAndFareDto.getOpenCityId(), ucId));
if (coupon.getCode() == 200 && coupon.getData().getStatus() == 2) {
throw new ServiceException("优惠券不满足条件", I18nKeyConstant.COUPON_NOT_SATISFY);
}
@@ -778,7 +779,7 @@
executorService);
}
R<UserCouponVo> couponResult;
- if (routeAndFareDto.getUserCouponId() != null) {
+ if (Long.valueOf(0L).equals(ucId) || (ucId != null && ucId > 0L)) {
couponResult = coupon;
} else {
couponResult = couponFuture.join();
--
Gitblit v1.7.1