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 {
List<String> couponCodes = chargeParam.getCouponCodes();
switch (chargeParam.getChargeStage()) {
case PAYMENT: {
case PAYMENT:
case COMPUTE:{
if (CollectionUtils.isEmpty(couponCodes)) {
//场景:砍价活动不需要推荐
return;
... ... @@ -352,7 +353,6 @@ public class ChargeService {
case SELECT_COUPON:
calculateSelectCoupons(chargeContext);
break;
case COMPUTE:
case SUBMIT: {
if (CollectionUtils.isEmpty(couponCodes)) {
return;
... ...
... ... @@ -112,7 +112,7 @@ public class ShoppingController {
ShoppingRequest req = ShoppingRequest.builder().uid(uid)
.skup(skup)
.couponCodes(activityTypeEnum.isCouponFlag() ? CouponCodeUtils.asList(couponCode) : null)
.couponCodes(activityTypeEnum.isCouponFlag() ? CouponCodeUtils.asListDefaultUseAutoRecommended(couponCode) : null)
.addressId(addressId)
.userActivityId(userActivityId).activityType(activityTypeEnum)
.appVersion(appVersion)
... ...
... ... @@ -170,7 +170,7 @@ public class ShoppingServiceImpl implements IShoppingService {
response.setDamagesDesc(shoppingSupport.getDamagesDesc(compensate, skupType));
//推荐券(可用券个数)
response.setRecommendedCouponInfo(shoppingSupport.getRecommendedCouponInfo(chargeResult));
response.setRecommendedCouponInfo(couponSupport.getRecommendedCouponInfo(chargeResult));
//活动信息
response.setActivityInfo(shoppingSupport.getActivityInfo(chargeResult));
... ... @@ -397,7 +397,6 @@ public class ShoppingServiceImpl implements IShoppingService {
response.setCouponInfo(couponSupport.getCouponInfo(chargeResult));
response.setPromotionFormulaList(shoppingSupport.getPromotionFormula(chargeResult));
response.setAmount(MathUtils.formatStr(chargeResult.getFinalAmount()));
return response;
}
... ...
... ... @@ -229,7 +229,7 @@ public class SellerService {
//下个周期
SellerOrderStatsEntry nextStatsEntry = SellerOrderStatsEntry.builder().sellerUid(uid).orderAttribute(OrderAttributes.COMMON_IN_STOCK).build();
SellerOrderStatsConfiguration nextStatsConfig = statsConfigurationManager.getStatsConfig(nextStatsEntry);
Pair<Integer, Integer> nextValidityTimeTuple = nextStatsConfig.getStatsUnit().getValidityTimeTuple(nextStatsConfig.getStatsPeriod(), nextStatsConfig.getStatsPeriod());
Pair<Integer, Integer> nextValidityTimeTuple = nextStatsConfig.getStatsUnit().nextPeriodTimeTuple(nextStatsConfig.getStatsPeriod(), nextStatsConfig.getStatsPeriod());
//设置查询时间为下个周期的开始时间
nextStatsEntry.setTime(nextValidityTimeTuple.getKey());
return (SellerPlatformServiceFee) statsConfigurationManager.getStatsProcessor(nextStatsConfig.getStatsProcessorName()).apply(nextStatsEntry, nextStatsConfig);
... ...
... ... @@ -25,24 +25,25 @@ public enum StatsUnit {
}
/**
* 根据delay,period,获取有效期元组
* 下个周期的时间元组
* air<key,value> key:开始时间,value:结束时间
*
* @param delay 从当前时间延时多长时间生效,即开始时间
* @param period 周期,在开始时间的基础上 + period Unit
* @return pair<key,value> key:开始时间,value:结束时间
* @param period 从当前时间计算下个周期,即开始时间
* @param duration ,持续时间,在开始时间的基础上 + duration Unit = 结束时间
* @return p
*/
public Pair<Integer, Integer> getValidityTimeTuple(int delay, int period) {
public Pair<Integer, Integer> nextPeriodTimeTuple(int period, int duration) {
Date beginDate = null, endDate = null;
switch (this) {
case HOUR:
Date currentHour = DateUtil.getCurrentHourDate(new Date());
beginDate = DateUtil.calDateTime(currentHour, DateUtil.Operator.plus, delay, DateUtil.TimeUnit.hour);
beginDate = DateUtil.calDateTime(currentHour, DateUtil.Operator.plus, period, DateUtil.TimeUnit.hour);
endDate = DateUtil.calDateTime(beginDate, DateUtil.Operator.plus, period, DateUtil.TimeUnit.hour);
break;
case MONTH:
Date firstDayOfMonth = DateUtil.getFirstDayOfMonth(new Date());
beginDate = DateUtil.calDateTime(firstDayOfMonth, DateUtil.Operator.plus, delay, DateUtil.TimeUnit.month);
endDate = DateUtil.calDateTime(beginDate, DateUtil.Operator.plus, period, DateUtil.TimeUnit.month);
beginDate = DateUtil.calDateTime(firstDayOfMonth, DateUtil.Operator.plus, period, DateUtil.TimeUnit.month);
endDate = DateUtil.calDateTime(beginDate, DateUtil.Operator.plus, duration, DateUtil.TimeUnit.month);
break;
}
//结束时间需要-1
... ...
... ... @@ -30,9 +30,9 @@ public class SellerOrderQuantityStatsProcessor implements StatsProcessor<SellerO
@Override
public void accept(SellerOrderStatsEntry entry, SellerOrderStatsConfiguration configuration) {
logger.info("sellerOrderQuantityStatsProcessor accept entry:{},configuration:{}", entry, configuration);
logger.info("[{}] sellerOrderQuantityStatsProcessor accept entry:{},configuration:{}", entry.getSellerUid(), entry, configuration);
Pair<Integer, Integer> timeTuple = configuration.getStatsUnit().getValidityTimeTuple(configuration.getStatsPeriod(), configuration.getStatsPeriod());
Pair<Integer, Integer> timeTuple = configuration.getStatsUnit().nextPeriodTimeTuple(configuration.getStatsPeriod(), configuration.getStatsPeriod());
SellerOrderStatsResult quantityResult = new SellerOrderStatsResult();
quantityResult.setStatsCode(configuration.getStatsCode());
... ... @@ -43,21 +43,20 @@ public class SellerOrderQuantityStatsProcessor implements StatsProcessor<SellerO
int row = sellerOrderStatsResultMapper.insert(quantityResult);
if (row == 1) {
logger.info("stats process success");
logger.info("[{}] stats process success", entry.getSellerUid());
} else {
logger.info("stats process fail");
logger.info("[{}] stats process fail", entry.getSellerUid());
}
}
@Override
public SellerPlatformServiceFee apply(SellerOrderStatsEntry entry, SellerOrderStatsConfiguration configuration) {
logger.info("sellerOrderQuantityStatsProcessor apply entry:{},configuration:{}", entry, configuration);
logger.info("[{}] sellerOrderQuantityStatsProcessor apply entry:{},configuration:{}", entry.getSellerUid(), entry, configuration);
SellerOrderStatsResult result = sellerOrderStatsResultMapper.selectStatsResult(entry.getSellerUid(), configuration.getStatsCode(), entry.getTime());
int quantity = (result != null) ? result.getQuantity() : 0;
PlatformServiceFeeDefinition psfd = PlatformServiceFeeDefinition.convert(configuration.getActionParam());
SellerPlatformServiceFee serviceFee = new SellerPlatformServiceFee(quantity, psfd);
logger.info("[{}] seller platform service statsResult:{}", entry.getSellerUid(),result);
logger.info("[{}] seller platform service statsResult:{}", entry.getSellerUid(), result);
return serviceFee;
}
}
\ No newline at end of file
... ...
... ... @@ -7,8 +7,10 @@ import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.order.charge.model.ChargeResult;
import com.yohoufo.order.charge.model.CouponMatchResult;
import com.yohoufo.order.charge.model.CouponPayResult;
import com.yohoufo.order.charge.model.CouponPayResultList;
import com.yohoufo.order.constants.CouponConstants;
import com.yohoufo.order.model.response.CouponInfo;
import com.yohoufo.order.model.response.RecommendedCouponInfo;
import com.yohoufo.order.model.response.ShoppingCoupon;
import com.yohoufo.order.utils.CouponCodeUtils;
import com.yohoufo.order.utils.MathUtils;
... ... @@ -85,4 +87,38 @@ public class CouponSupport {
.build();
}
}
/**
* 券自动推荐结果
* @param chargeResult
* @return
*/
public RecommendedCouponInfo getRecommendedCouponInfo(ChargeResult chargeResult) {
CouponPayResultList couponPayResultList = chargeResult.getCouponPayResultList();
/**
* usableCouponCount 有可用张数,couponPayResults 实际使用的券
* 特殊场景
* usableCouponCount > 0 ,但couponPayResults为空
*/
int usableCouponCount = couponPayResultList.getUsableCouponCount();
List<CouponPayResult> couponPayResults = couponPayResultList.getCouponPayResults();
if (CollectionUtils.isNotEmpty(couponPayResults)) {
int usedCouponCount = couponPayResults.size();
String couponPayAmountStr = MathUtils.formatCurrencyStr(couponPayResults.stream().mapToDouble(coupon -> coupon.getCouponAmount()).sum());
String couponCodes = CouponCodeUtils.asString(couponPayResults.stream().map(coupon -> coupon.getCouponCode()).collect(Collectors.toList()));
return RecommendedCouponInfo.builder()
.usableCouponCount(usableCouponCount)
.usedCouponCount(usedCouponCount)
.couponAmountStr(couponPayAmountStr)
.couponCode(couponCodes)
.desc(MessageFormat.format(CouponConstants.COUPON_AUTO_RECOMMENDED_DESC_FORMAT, usableCouponCount, usedCouponCount)).build();
} else {
return RecommendedCouponInfo.builder()
.usableCouponCount(usableCouponCount)
.usedCouponCount(0)
.desc(MessageFormat.format(CouponConstants.USABLE_COUPON_DESC_FORMAT, usableCouponCount))
.build();
}
}
}
... ...
... ... @@ -236,39 +236,7 @@ public class ShoppingSupport {
return ActivityInfo.builder().userActivityId(activityCutResult.getUserActivityId()).activityType(activityCutResult.getActivityType()).build();
}
/**
* 券自动推荐结果
* @param chargeResult
* @return
*/
public RecommendedCouponInfo getRecommendedCouponInfo(ChargeResult chargeResult) {
CouponPayResultList couponPayResultList = chargeResult.getCouponPayResultList();
/**
* usableCouponCount 有可用张数,couponPayResults 实际使用的券
* 特殊场景
* usableCouponCount > 0 ,但couponPayResults为空
*/
int usableCouponCount = couponPayResultList.getUsableCouponCount();
List<CouponPayResult> couponPayResults = couponPayResultList.getCouponPayResults();
if (CollectionUtils.isNotEmpty(couponPayResults)) {
int usedCouponCount = couponPayResults.size();
String couponPayAmountStr = MathUtils.formatCurrencyStr(couponPayResults.stream().mapToDouble(coupon -> coupon.getCouponAmount()).sum());
String couponCodes = CouponCodeUtils.asString(couponPayResults.stream().map(coupon -> coupon.getCouponCode()).collect(Collectors.toList()));
return RecommendedCouponInfo.builder()
.usableCouponCount(usableCouponCount)
.usedCouponCount(usedCouponCount)
.couponAmountStr(couponPayAmountStr)
.couponCode(couponCodes)
.desc(MessageFormat.format(CouponConstants.COUPON_AUTO_RECOMMENDED_DESC_FORMAT, usableCouponCount, usedCouponCount)).build();
} else {
return RecommendedCouponInfo.builder()
.usableCouponCount(usableCouponCount)
.usedCouponCount(0)
.desc(MessageFormat.format(CouponConstants.USABLE_COUPON_DESC_FORMAT, usableCouponCount))
.build();
}
}
public DepositResp getDepositResp(SkupType skupType){
DepositResp depositResp = null;
... ...
... ... @@ -19,6 +19,14 @@ public class CouponCodeUtils {
return Lists.newArrayList(couponCode.split(CouponConstants.COUPON_CODE_SPLIT_TOKEN));
}
public static List<String> asListDefaultUseAutoRecommended(String couponCode) {
if (StringUtils.isEmpty(couponCode)) {
return CouponConstants.AUTO_RECOMMENDED_COUPON_CODES;
}
return Lists.newArrayList(couponCode.split(CouponConstants.COUPON_CODE_SPLIT_TOKEN));
}
public static String asString(List<String> list) {
return StringUtils.join(list, CouponConstants.COUPON_CODE_SPLIT_TOKEN);
}
... ...