Authored by mali

Merge branch 'test6.9.9' of http://git.yoho.cn/ufo/yohoufo-fore into test6.9.9

@@ -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
@@ -229,7 +229,7 @@ public class SellerService { @@ -229,7 +229,7 @@ public class SellerService {
229 //下个周期 229 //下个周期
230 SellerOrderStatsEntry nextStatsEntry = SellerOrderStatsEntry.builder().sellerUid(uid).orderAttribute(OrderAttributes.COMMON_IN_STOCK).build(); 230 SellerOrderStatsEntry nextStatsEntry = SellerOrderStatsEntry.builder().sellerUid(uid).orderAttribute(OrderAttributes.COMMON_IN_STOCK).build();
231 SellerOrderStatsConfiguration nextStatsConfig = statsConfigurationManager.getStatsConfig(nextStatsEntry); 231 SellerOrderStatsConfiguration nextStatsConfig = statsConfigurationManager.getStatsConfig(nextStatsEntry);
232 - Pair<Integer, Integer> nextValidityTimeTuple = nextStatsConfig.getStatsUnit().getValidityTimeTuple(nextStatsConfig.getStatsPeriod(), nextStatsConfig.getStatsPeriod()); 232 + Pair<Integer, Integer> nextValidityTimeTuple = nextStatsConfig.getStatsUnit().nextPeriodTimeTuple(nextStatsConfig.getStatsPeriod(), nextStatsConfig.getStatsPeriod());
233 //设置查询时间为下个周期的开始时间 233 //设置查询时间为下个周期的开始时间
234 nextStatsEntry.setTime(nextValidityTimeTuple.getKey()); 234 nextStatsEntry.setTime(nextValidityTimeTuple.getKey());
235 return (SellerPlatformServiceFee) statsConfigurationManager.getStatsProcessor(nextStatsConfig.getStatsProcessorName()).apply(nextStatsEntry, nextStatsConfig); 235 return (SellerPlatformServiceFee) statsConfigurationManager.getStatsProcessor(nextStatsConfig.getStatsProcessorName()).apply(nextStatsEntry, nextStatsConfig);
@@ -25,24 +25,25 @@ public enum StatsUnit { @@ -25,24 +25,25 @@ public enum StatsUnit {
25 } 25 }
26 26
27 /** 27 /**
28 - * 根据delay,period,获取有效期元组 28 + * 下个周期的时间元组
  29 + * air<key,value> key:开始时间,value:结束时间
29 * 30 *
30 - * @param delay 从当前时间延时多长时间生效,即开始时间  
31 - * @param period 周期,在开始时间的基础上 + period Unit  
32 - * @return pair<key,value> key:开始时间,value:结束时间 31 + * @param period 从当前时间计算下个周期,即开始时间
  32 + * @param duration ,持续时间,在开始时间的基础上 + duration Unit = 结束时间
  33 + * @return p
33 */ 34 */
34 - public Pair<Integer, Integer> getValidityTimeTuple(int delay, int period) { 35 + public Pair<Integer, Integer> nextPeriodTimeTuple(int period, int duration) {
35 Date beginDate = null, endDate = null; 36 Date beginDate = null, endDate = null;
36 switch (this) { 37 switch (this) {
37 case HOUR: 38 case HOUR:
38 Date currentHour = DateUtil.getCurrentHourDate(new Date()); 39 Date currentHour = DateUtil.getCurrentHourDate(new Date());
39 - beginDate = DateUtil.calDateTime(currentHour, DateUtil.Operator.plus, delay, DateUtil.TimeUnit.hour); 40 + beginDate = DateUtil.calDateTime(currentHour, DateUtil.Operator.plus, period, DateUtil.TimeUnit.hour);
40 endDate = DateUtil.calDateTime(beginDate, DateUtil.Operator.plus, period, DateUtil.TimeUnit.hour); 41 endDate = DateUtil.calDateTime(beginDate, DateUtil.Operator.plus, period, DateUtil.TimeUnit.hour);
41 break; 42 break;
42 case MONTH: 43 case MONTH:
43 Date firstDayOfMonth = DateUtil.getFirstDayOfMonth(new Date()); 44 Date firstDayOfMonth = DateUtil.getFirstDayOfMonth(new Date());
44 - beginDate = DateUtil.calDateTime(firstDayOfMonth, DateUtil.Operator.plus, delay, DateUtil.TimeUnit.month);  
45 - endDate = DateUtil.calDateTime(beginDate, DateUtil.Operator.plus, period, DateUtil.TimeUnit.month); 45 + beginDate = DateUtil.calDateTime(firstDayOfMonth, DateUtil.Operator.plus, period, DateUtil.TimeUnit.month);
  46 + endDate = DateUtil.calDateTime(beginDate, DateUtil.Operator.plus, duration, DateUtil.TimeUnit.month);
46 break; 47 break;
47 } 48 }
48 //结束时间需要-1 49 //结束时间需要-1
@@ -30,9 +30,9 @@ public class SellerOrderQuantityStatsProcessor implements StatsProcessor<SellerO @@ -30,9 +30,9 @@ public class SellerOrderQuantityStatsProcessor implements StatsProcessor<SellerO
30 30
31 @Override 31 @Override
32 public void accept(SellerOrderStatsEntry entry, SellerOrderStatsConfiguration configuration) { 32 public void accept(SellerOrderStatsEntry entry, SellerOrderStatsConfiguration configuration) {
33 - logger.info("sellerOrderQuantityStatsProcessor accept entry:{},configuration:{}", entry, configuration); 33 + logger.info("[{}] sellerOrderQuantityStatsProcessor accept entry:{},configuration:{}", entry.getSellerUid(), entry, configuration);
34 34
35 - Pair<Integer, Integer> timeTuple = configuration.getStatsUnit().getValidityTimeTuple(configuration.getStatsPeriod(), configuration.getStatsPeriod()); 35 + Pair<Integer, Integer> timeTuple = configuration.getStatsUnit().nextPeriodTimeTuple(configuration.getStatsPeriod(), configuration.getStatsPeriod());
36 36
37 SellerOrderStatsResult quantityResult = new SellerOrderStatsResult(); 37 SellerOrderStatsResult quantityResult = new SellerOrderStatsResult();
38 quantityResult.setStatsCode(configuration.getStatsCode()); 38 quantityResult.setStatsCode(configuration.getStatsCode());
@@ -43,21 +43,20 @@ public class SellerOrderQuantityStatsProcessor implements StatsProcessor<SellerO @@ -43,21 +43,20 @@ public class SellerOrderQuantityStatsProcessor implements StatsProcessor<SellerO
43 43
44 int row = sellerOrderStatsResultMapper.insert(quantityResult); 44 int row = sellerOrderStatsResultMapper.insert(quantityResult);
45 if (row == 1) { 45 if (row == 1) {
46 - logger.info("stats process success"); 46 + logger.info("[{}] stats process success", entry.getSellerUid());
47 } else { 47 } else {
48 - logger.info("stats process fail"); 48 + logger.info("[{}] stats process fail", entry.getSellerUid());
49 } 49 }
50 -  
51 } 50 }
52 51
53 @Override 52 @Override
54 public SellerPlatformServiceFee apply(SellerOrderStatsEntry entry, SellerOrderStatsConfiguration configuration) { 53 public SellerPlatformServiceFee apply(SellerOrderStatsEntry entry, SellerOrderStatsConfiguration configuration) {
55 - logger.info("sellerOrderQuantityStatsProcessor apply entry:{},configuration:{}", entry, configuration); 54 + logger.info("[{}] sellerOrderQuantityStatsProcessor apply entry:{},configuration:{}", entry.getSellerUid(), entry, configuration);
56 SellerOrderStatsResult result = sellerOrderStatsResultMapper.selectStatsResult(entry.getSellerUid(), configuration.getStatsCode(), entry.getTime()); 55 SellerOrderStatsResult result = sellerOrderStatsResultMapper.selectStatsResult(entry.getSellerUid(), configuration.getStatsCode(), entry.getTime());
57 int quantity = (result != null) ? result.getQuantity() : 0; 56 int quantity = (result != null) ? result.getQuantity() : 0;
58 PlatformServiceFeeDefinition psfd = PlatformServiceFeeDefinition.convert(configuration.getActionParam()); 57 PlatformServiceFeeDefinition psfd = PlatformServiceFeeDefinition.convert(configuration.getActionParam());
59 SellerPlatformServiceFee serviceFee = new SellerPlatformServiceFee(quantity, psfd); 58 SellerPlatformServiceFee serviceFee = new SellerPlatformServiceFee(quantity, psfd);
60 - logger.info("[{}] seller platform service statsResult:{}", entry.getSellerUid(),result); 59 + logger.info("[{}] seller platform service statsResult:{}", entry.getSellerUid(), result);
61 return serviceFee; 60 return serviceFee;
62 } 61 }
63 } 62 }
@@ -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 }