Authored by chenchao

select optimized goods service rate

package com.yohoufo.order.service.impl;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohoufo.common.utils.BigDecimalHelper;
import com.yohoufo.order.model.dto.ServiceFeeRate;
import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -69,8 +67,6 @@ public class OrderDynamicConfig {
private String sellerGetRateDelivery;
private ServiceFeeRate serviceFeeRate;
public ServiceFeeRate getServiceFeeRate(SkupType skupType){
... ...
... ... @@ -188,6 +188,7 @@ public class ProductProxyService extends AbsProxyService{
.hkLeasePrice(storage.getHkLeastPrice())
.quickDeliverLeasePrice(storage.getHkLeastPrice())
*/
.goodsPaymentRateOfSkn(productInfo.getProductProfitRate())
.goodsPaymentRate(productInfo.getSellerServiceFeeRate())
.canPublish(productInfo.isSellerCanPublish())
.build();
... ...
... ... @@ -213,17 +213,11 @@ public abstract class AbsSellerOrderComputeHandler implements OrderComputeHandle
*/
protected ServiceFeeRate buildServiceFeeRate(ServiceFeeRate psfr) {
//
ServiceFeeRate serviceFeeRate = orderDynamicConfig.getServiceFeeRate(getSkupType());
BigDecimal pgpr;
if (psfr !=null
&& (pgpr = psfr.getGoodsPaymentRate()) !=null){
serviceFeeRate.setGoodsPaymentRate(pgpr);
}
if (Objects.isNull(serviceFeeRate)){
serviceFeeRate = buildDefaultServiceFeeRate();
if (Objects.isNull(psfr)){
return buildDefaultServiceFeeRate();
}
return serviceFeeRate;
return psfr;
}
protected abstract ServiceFeeRate buildDefaultServiceFeeRate();
... ...
package com.yohoufo.order.service.seller.fee;
import com.google.common.collect.Lists;
import com.yohobuy.ufo.model.order.bo.PrdPrice;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohoufo.order.model.dto.SellerOrderComputeResult;
import com.yohoufo.order.model.dto.ServiceFeeRate;
import com.yohoufo.order.service.impl.OrderDynamicConfig;
import com.yohoufo.order.service.support.SellerPlatformServiceFeeSupport;
import com.yohoufo.order.utils.LoggerUtils;
import com.yohoufo.order.utils.OrderAssist;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
@Service
public class GoodsAmountService {
private final Logger logger = LoggerUtils.getSellerOrderLogger();
@Autowired
private SellerPlatformServiceFeeSupport sellerPlatformServiceFeeSupport;
@Autowired
private OrderDynamicConfig orderDynamicConfig;
private static Comparator<GoodsServiceFeeRateWrapper> buildGoodsServiceFeeRateWrapperComp(){
return (GoodsServiceFeeRateWrapper o1, GoodsServiceFeeRateWrapper o2) -> {
BigDecimal o1gpr = o1.getGoodsPaymentRate(), o2gpr = o2.getGoodsPaymentRate();
if (o1gpr == null){
if (o2gpr == null){
return 0;
}else{
return 1;
}
}else{
if (o2gpr == null){
return 1;
}else {
return o1gpr.compareTo(o2gpr);
}
}
};
}
public SellerOrderComputeResult getGoodsServiceFeeRate(int uid, int storageId, PrdPrice prdPrice, SkupType skupType){
logger.info("in GoodsAmountService.getGoodsServiceFeeRate uid {}, storageId {},prdPrice {} skupType {}",
uid, storageId, prdPrice, skupType);
ServiceFeeRate rate = orderDynamicConfig.getServiceFeeRate(skupType);
SellerOrderComputeResult highPriority = OrderAssist.buildHighestPriorityConfig(prdPrice, rate);
if (highPriority != null){
return highPriority;
}
List<GoodsServiceFeeRateWrapper> allConfig = Lists.newArrayListWithCapacity(4);
//build One User One GoodsType
allConfig.add(buildOneUserOneGoodsType(uid, skupType));
// build by skn
allConfig.add(buildWithSkn(prdPrice));
//build by goods type
allConfig.add(buildWithGoodsType(rate));
logger.info("in GoodsAmountService.getGoodsServiceFeeRate uid {}, storageId {}, skupType {} prdPrice {} allConfig {}",
uid, storageId, skupType, prdPrice, allConfig);
Optional<GoodsServiceFeeRateWrapper> minGSFRW = allConfig.stream()
.min(buildGoodsServiceFeeRateWrapperComp());
SellerOrderComputeResult socr = new SellerOrderComputeResult();
if(minGSFRW.isPresent()) {
rate.setGoodsPaymentRate(minGSFRW.get().getGoodsPaymentRate());
}
socr.setServiceFeeRate(rate);
return socr;
}
public GoodsServiceFeeRateWrapper buildWithSkn(PrdPrice prdPrice){
BigDecimal rate = prdPrice != null ? prdPrice.getGoodsPaymentRateOfSkn() : null;
GoodsServiceFeeRateWrapper gsfrw = new GoodsServiceFeeRateWrapper();
gsfrw.setGoodsServiceFeeRateDimension(GoodsServiceFeeRateDimension.SKN);
gsfrw.setGoodsPaymentRate(rate);
return gsfrw;
}
public GoodsServiceFeeRateWrapper buildWithGoodsType(ServiceFeeRate rate){
GoodsServiceFeeRateWrapper gsfrw = new GoodsServiceFeeRateWrapper();
gsfrw.setGoodsServiceFeeRateDimension(GoodsServiceFeeRateDimension.ONE_USER_ONE_GOODS_TYPE);
gsfrw.setGoodsPaymentRate(rate == null ? null : rate.getGoodsPaymentRate());
return gsfrw;
}
public GoodsServiceFeeRateWrapper buildOneUserOneGoodsType(int uid, SkupType skupType){
BigDecimal rate = sellerPlatformServiceFeeSupport.getPlatformServiceFeeRate(uid, skupType);
GoodsServiceFeeRateWrapper gsfrw = new GoodsServiceFeeRateWrapper();
gsfrw.setGoodsServiceFeeRateDimension(GoodsServiceFeeRateDimension.ONE_USER_ONE_GOODS_TYPE);
gsfrw.setGoodsPaymentRate(rate);
return gsfrw;
}
public static void main(String[] args) {
List<GoodsServiceFeeRateWrapper> allConfig = Lists.newArrayListWithCapacity(4);
GoodsServiceFeeRateWrapper gsfrw4 = new GoodsServiceFeeRateWrapper();
gsfrw4.setGoodsServiceFeeRateDimension(GoodsServiceFeeRateDimension.GOODS_TYPE);
allConfig.add(gsfrw4);
GoodsServiceFeeRateWrapper gsfrw3 = new GoodsServiceFeeRateWrapper();
gsfrw3.setGoodsServiceFeeRateDimension(GoodsServiceFeeRateDimension.ONE_USER_ONE_SKN);
gsfrw3.setGoodsPaymentRate(BigDecimal.ZERO);
allConfig.add(gsfrw3);
GoodsServiceFeeRateWrapper gsfrw2 = new GoodsServiceFeeRateWrapper();
gsfrw2.setGoodsServiceFeeRateDimension(GoodsServiceFeeRateDimension.ONE_USER_ONE_GOODS_TYPE);
gsfrw2.setGoodsPaymentRate(new BigDecimal(2));
allConfig.add(gsfrw2);
GoodsServiceFeeRateWrapper gsfrw1 = new GoodsServiceFeeRateWrapper();
gsfrw1.setGoodsServiceFeeRateDimension(GoodsServiceFeeRateDimension.SKN);
gsfrw1.setGoodsPaymentRate(new BigDecimal(1));
allConfig.add(gsfrw1);
//
GoodsServiceFeeRateWrapper minGSFRW = allConfig.stream().min(buildGoodsServiceFeeRateWrapperComp()).orElse(new GoodsServiceFeeRateWrapper());
System.out.println("test getGoodsServiceFeeRate -> " + minGSFRW);
}
}
... ...
package com.yohoufo.order.service.seller.fee;
import lombok.Getter;
public enum GoodsServiceFeeRateDimension {
GOODS_TYPE(1),
ONE_USER_ONE_SKN(2),
ONE_USER_ONE_GOODS_TYPE(3),
SKN(4);
@Getter
int code;
GoodsServiceFeeRateDimension(int code) {
this.code = code;
}
}
... ...
package com.yohoufo.order.service.seller.fee;
import com.yohoufo.order.model.dto.ServiceFeeRate;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.math.BigDecimal;
@ToString
public class GoodsServiceFeeRateWrapper {
@Getter@Setter
private GoodsServiceFeeRateDimension goodsServiceFeeRateDimension;
@Getter@Setter
private BigDecimal goodsPaymentRate;
public ServiceFeeRate getServiceFeeRate(){
ServiceFeeRate sfr = new ServiceFeeRate();
sfr.setGoodsPaymentRate(goodsPaymentRate);
return sfr;
}
}
... ...
... ... @@ -64,7 +64,8 @@ public class OrderAssist {
PlatformFeeDto platformFee;
ServiceFeeRate serviceFeeRate;
BigDecimal goodsPaymentRate;
if ((goodsPaymentRate = prdPrice.getGoodsPaymentRate()) != null){ //如果基础商品已经设置了抽成比率,则鉴定费和包装费免除
if ((goodsPaymentRate = prdPrice.getGoodsPaymentRate()) != null){
//如果基础商品已经设置了抽成比率,则鉴定费和包装费免除
platformFee = new PlatformFeeDto();
platformFee.setAppraiseFee(new BigDecimal(0));
platformFee.setPackageFee(new BigDecimal(0));
... ... @@ -79,4 +80,22 @@ public class OrderAssist {
return socr;
}
public static SellerOrderComputeResult buildHighestPriorityConfig(PrdPrice prdPrice, ServiceFeeRate serviceFeeRate){
SellerOrderComputeResult socr = new SellerOrderComputeResult();
PlatformFeeDto platformFee;
BigDecimal goodsPaymentRate;
if (Objects.nonNull(prdPrice) && Objects.nonNull(goodsPaymentRate = prdPrice.getGoodsPaymentRate())){
//
serviceFeeRate.setGoodsPaymentRate(goodsPaymentRate);
//如果基础商品已经设置了抽成比率,则鉴定费和包装费免除
platformFee = new PlatformFeeDto();
platformFee.setAppraiseFee(new BigDecimal(0));
platformFee.setPackageFee(new BigDecimal(0));
//
socr.setPlatformFee(platformFee);
}
socr.setServiceFeeRate(serviceFeeRate);
return socr;
}
}
... ...