|
|
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);
|
|
|
}
|
|
|
} |
...
|
...
|
|