Authored by chenchao

use optimize coupon

@@ -338,7 +338,8 @@ public class ChargeService { @@ -338,7 +338,8 @@ public class ChargeService {
338 List<String> couponCodes = chargeParam.getCouponCodes(); 338 List<String> couponCodes = chargeParam.getCouponCodes();
339 339
340 switch (chargeParam.getChargeStage()) { 340 switch (chargeParam.getChargeStage()) {
341 - case PAYMENT: { 341 + case PAYMENT:
  342 + case COMPUTE:{
342 if (CollectionUtils.isEmpty(couponCodes)) { 343 if (CollectionUtils.isEmpty(couponCodes)) {
343 //场景:砍价活动不需要推荐 344 //场景:砍价活动不需要推荐
344 return; 345 return;
@@ -352,7 +353,6 @@ public class ChargeService { @@ -352,7 +353,6 @@ public class ChargeService {
352 case SELECT_COUPON: 353 case SELECT_COUPON:
353 calculateSelectCoupons(chargeContext); 354 calculateSelectCoupons(chargeContext);
354 break; 355 break;
355 - case COMPUTE:  
356 case SUBMIT: { 356 case SUBMIT: {
357 if (CollectionUtils.isEmpty(couponCodes)) { 357 if (CollectionUtils.isEmpty(couponCodes)) {
358 return; 358 return;
@@ -112,7 +112,7 @@ public class ShoppingController { @@ -112,7 +112,7 @@ public class ShoppingController {
112 112
113 ShoppingRequest req = ShoppingRequest.builder().uid(uid) 113 ShoppingRequest req = ShoppingRequest.builder().uid(uid)
114 .skup(skup) 114 .skup(skup)
115 - .couponCodes(activityTypeEnum.isCouponFlag() ? CouponCodeUtils.asList(couponCode) : null) 115 + .couponCodes(activityTypeEnum.isCouponFlag() ? CouponCodeUtils.asListDefaultUseAutoRecommended(couponCode) : null)
116 .addressId(addressId) 116 .addressId(addressId)
117 .userActivityId(userActivityId).activityType(activityTypeEnum) 117 .userActivityId(userActivityId).activityType(activityTypeEnum)
118 .appVersion(appVersion) 118 .appVersion(appVersion)
@@ -170,7 +170,7 @@ public class ShoppingServiceImpl implements IShoppingService { @@ -170,7 +170,7 @@ public class ShoppingServiceImpl implements IShoppingService {
170 response.setDamagesDesc(shoppingSupport.getDamagesDesc(compensate, skupType)); 170 response.setDamagesDesc(shoppingSupport.getDamagesDesc(compensate, skupType));
171 171
172 //推荐券(可用券个数) 172 //推荐券(可用券个数)
173 - response.setRecommendedCouponInfo(shoppingSupport.getRecommendedCouponInfo(chargeResult)); 173 + response.setRecommendedCouponInfo(couponSupport.getRecommendedCouponInfo(chargeResult));
174 174
175 //活动信息 175 //活动信息
176 response.setActivityInfo(shoppingSupport.getActivityInfo(chargeResult)); 176 response.setActivityInfo(shoppingSupport.getActivityInfo(chargeResult));
@@ -397,7 +397,6 @@ public class ShoppingServiceImpl implements IShoppingService { @@ -397,7 +397,6 @@ public class ShoppingServiceImpl implements IShoppingService {
397 response.setCouponInfo(couponSupport.getCouponInfo(chargeResult)); 397 response.setCouponInfo(couponSupport.getCouponInfo(chargeResult));
398 response.setPromotionFormulaList(shoppingSupport.getPromotionFormula(chargeResult)); 398 response.setPromotionFormulaList(shoppingSupport.getPromotionFormula(chargeResult));
399 response.setAmount(MathUtils.formatStr(chargeResult.getFinalAmount())); 399 response.setAmount(MathUtils.formatStr(chargeResult.getFinalAmount()));
400 -  
401 return response; 400 return response;
402 } 401 }
403 402
@@ -7,8 +7,10 @@ import com.yohoufo.common.utils.DateUtil; @@ -7,8 +7,10 @@ import com.yohoufo.common.utils.DateUtil;
7 import com.yohoufo.order.charge.model.ChargeResult; 7 import com.yohoufo.order.charge.model.ChargeResult;
8 import com.yohoufo.order.charge.model.CouponMatchResult; 8 import com.yohoufo.order.charge.model.CouponMatchResult;
9 import com.yohoufo.order.charge.model.CouponPayResult; 9 import com.yohoufo.order.charge.model.CouponPayResult;
  10 +import com.yohoufo.order.charge.model.CouponPayResultList;
10 import com.yohoufo.order.constants.CouponConstants; 11 import com.yohoufo.order.constants.CouponConstants;
11 import com.yohoufo.order.model.response.CouponInfo; 12 import com.yohoufo.order.model.response.CouponInfo;
  13 +import com.yohoufo.order.model.response.RecommendedCouponInfo;
12 import com.yohoufo.order.model.response.ShoppingCoupon; 14 import com.yohoufo.order.model.response.ShoppingCoupon;
13 import com.yohoufo.order.utils.CouponCodeUtils; 15 import com.yohoufo.order.utils.CouponCodeUtils;
14 import com.yohoufo.order.utils.MathUtils; 16 import com.yohoufo.order.utils.MathUtils;
@@ -85,4 +87,38 @@ public class CouponSupport { @@ -85,4 +87,38 @@ public class CouponSupport {
85 .build(); 87 .build();
86 } 88 }
87 } 89 }
  90 +
  91 + /**
  92 + * 券自动推荐结果
  93 + * @param chargeResult
  94 + * @return
  95 + */
  96 + public RecommendedCouponInfo getRecommendedCouponInfo(ChargeResult chargeResult) {
  97 + CouponPayResultList couponPayResultList = chargeResult.getCouponPayResultList();
  98 +
  99 + /**
  100 + * usableCouponCount 有可用张数,couponPayResults 实际使用的券
  101 + * 特殊场景
  102 + * usableCouponCount > 0 ,但couponPayResults为空
  103 + */
  104 + int usableCouponCount = couponPayResultList.getUsableCouponCount();
  105 + List<CouponPayResult> couponPayResults = couponPayResultList.getCouponPayResults();
  106 + if (CollectionUtils.isNotEmpty(couponPayResults)) {
  107 + int usedCouponCount = couponPayResults.size();
  108 + String couponPayAmountStr = MathUtils.formatCurrencyStr(couponPayResults.stream().mapToDouble(coupon -> coupon.getCouponAmount()).sum());
  109 + String couponCodes = CouponCodeUtils.asString(couponPayResults.stream().map(coupon -> coupon.getCouponCode()).collect(Collectors.toList()));
  110 + return RecommendedCouponInfo.builder()
  111 + .usableCouponCount(usableCouponCount)
  112 + .usedCouponCount(usedCouponCount)
  113 + .couponAmountStr(couponPayAmountStr)
  114 + .couponCode(couponCodes)
  115 + .desc(MessageFormat.format(CouponConstants.COUPON_AUTO_RECOMMENDED_DESC_FORMAT, usableCouponCount, usedCouponCount)).build();
  116 + } else {
  117 + return RecommendedCouponInfo.builder()
  118 + .usableCouponCount(usableCouponCount)
  119 + .usedCouponCount(0)
  120 + .desc(MessageFormat.format(CouponConstants.USABLE_COUPON_DESC_FORMAT, usableCouponCount))
  121 + .build();
  122 + }
  123 + }
88 } 124 }
@@ -236,39 +236,7 @@ public class ShoppingSupport { @@ -236,39 +236,7 @@ public class ShoppingSupport {
236 return ActivityInfo.builder().userActivityId(activityCutResult.getUserActivityId()).activityType(activityCutResult.getActivityType()).build(); 236 return ActivityInfo.builder().userActivityId(activityCutResult.getUserActivityId()).activityType(activityCutResult.getActivityType()).build();
237 } 237 }
238 238
239 - /**  
240 - * 券自动推荐结果  
241 - * @param chargeResult  
242 - * @return  
243 - */  
244 - public RecommendedCouponInfo getRecommendedCouponInfo(ChargeResult chargeResult) {  
245 - CouponPayResultList couponPayResultList = chargeResult.getCouponPayResultList();  
246 239
247 - /**  
248 - * usableCouponCount 有可用张数,couponPayResults 实际使用的券  
249 - * 特殊场景  
250 - * usableCouponCount > 0 ,但couponPayResults为空  
251 - */  
252 - int usableCouponCount = couponPayResultList.getUsableCouponCount();  
253 - List<CouponPayResult> couponPayResults = couponPayResultList.getCouponPayResults();  
254 - if (CollectionUtils.isNotEmpty(couponPayResults)) {  
255 - int usedCouponCount = couponPayResults.size();  
256 - String couponPayAmountStr = MathUtils.formatCurrencyStr(couponPayResults.stream().mapToDouble(coupon -> coupon.getCouponAmount()).sum());  
257 - String couponCodes = CouponCodeUtils.asString(couponPayResults.stream().map(coupon -> coupon.getCouponCode()).collect(Collectors.toList()));  
258 - return RecommendedCouponInfo.builder()  
259 - .usableCouponCount(usableCouponCount)  
260 - .usedCouponCount(usedCouponCount)  
261 - .couponAmountStr(couponPayAmountStr)  
262 - .couponCode(couponCodes)  
263 - .desc(MessageFormat.format(CouponConstants.COUPON_AUTO_RECOMMENDED_DESC_FORMAT, usableCouponCount, usedCouponCount)).build();  
264 - } else {  
265 - return RecommendedCouponInfo.builder()  
266 - .usableCouponCount(usableCouponCount)  
267 - .usedCouponCount(0)  
268 - .desc(MessageFormat.format(CouponConstants.USABLE_COUPON_DESC_FORMAT, usableCouponCount))  
269 - .build();  
270 - }  
271 - }  
272 240
273 public DepositResp getDepositResp(SkupType skupType){ 241 public DepositResp getDepositResp(SkupType skupType){
274 DepositResp depositResp = null; 242 DepositResp depositResp = null;
@@ -19,6 +19,14 @@ public class CouponCodeUtils { @@ -19,6 +19,14 @@ public class CouponCodeUtils {
19 return Lists.newArrayList(couponCode.split(CouponConstants.COUPON_CODE_SPLIT_TOKEN)); 19 return Lists.newArrayList(couponCode.split(CouponConstants.COUPON_CODE_SPLIT_TOKEN));
20 } 20 }
21 21
  22 + public static List<String> asListDefaultUseAutoRecommended(String couponCode) {
  23 + if (StringUtils.isEmpty(couponCode)) {
  24 + return CouponConstants.AUTO_RECOMMENDED_COUPON_CODES;
  25 + }
  26 +
  27 + return Lists.newArrayList(couponCode.split(CouponConstants.COUPON_CODE_SPLIT_TOKEN));
  28 + }
  29 +
22 public static String asString(List<String> list) { 30 public static String asString(List<String> list) {
23 return StringUtils.join(list, CouponConstants.COUPON_CODE_SPLIT_TOKEN); 31 return StringUtils.join(list, CouponConstants.COUPON_CODE_SPLIT_TOKEN);
24 } 32 }