...
|
...
|
@@ -11,6 +11,7 @@ import com.yohoufo.order.service.support.SellerPlatformServiceFeeSupport; |
|
|
import com.yohoufo.order.utils.LoggerUtils;
|
|
|
import com.yohoufo.order.utils.OrderAssist;
|
|
|
import com.yohoufo.order.utils.SellerGoodsHelper;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
...
|
...
|
@@ -29,33 +30,11 @@ public class GoodsAmountService { |
|
|
@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){
|
|
|
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);
|
...
|
...
|
@@ -69,79 +48,48 @@ public class GoodsAmountService { |
|
|
return highPriority;
|
|
|
}
|
|
|
}
|
|
|
List<ServiceFeeRate> allConfig = Lists.newArrayListWithCapacity(4);
|
|
|
List<ServiceFeeRate> allConfig = Lists.newArrayListWithCapacity(3);
|
|
|
//build One User One GoodsType 卖家不同商品类型的指定费率
|
|
|
allConfig.add(buildOneUserOneGoodsType(uid, skupType,rate));
|
|
|
CollectionUtils.addIgnoreNull(allConfig, buildOneUserOneGoodsType(uid, skupType, rate));
|
|
|
// build by skn
|
|
|
allConfig.add(buildWithSkn(prdPrice,rate));
|
|
|
CollectionUtils.addIgnoreNull(allConfig, buildWithSkn(prdPrice, rate));
|
|
|
//build by goods type 不同商品类型指定的费率
|
|
|
allConfig.add(buildWithGoodsType(rate));
|
|
|
CollectionUtils.addIgnoreNull(allConfig, 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.setServiceFeeRates(allConfig);
|
|
|
return socr;
|
|
|
}
|
|
|
|
|
|
public GoodsServiceFeeRateWrapper buildWithSkn(PrdPrice prdPrice,ServiceFeeRate rate) {
|
|
|
GoodsServiceFeeRateWrapper gsfrw = new GoodsServiceFeeRateWrapper(GoodsServiceFeeRateDimension.SKN,rate);
|
|
|
if (Objects.nonNull(prdPrice)) {
|
|
|
private GoodsServiceFeeRateWrapper buildWithSkn(PrdPrice prdPrice, ServiceFeeRate rate) {
|
|
|
if (Objects.isNull(prdPrice) || Objects.isNull(prdPrice.getGoodsPaymentRateOfSkn())) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
GoodsServiceFeeRateWrapper gsfrw = new GoodsServiceFeeRateWrapper(GoodsServiceFeeRateDimension.SKN, rate);
|
|
|
gsfrw.setGoodsPaymentRate(prdPrice.getGoodsPaymentRateOfSkn());
|
|
|
double min = Objects.isNull(prdPrice.getGoodsPaymentMinPriceOfSkn()) ?
|
|
|
0 : prdPrice.getGoodsPaymentMinPriceOfSkn().doubleValue();
|
|
|
double max = Objects.isNull(prdPrice.getGoodsPaymentMaxPriceOfSkn()) ?
|
|
|
1000000 : prdPrice.getGoodsPaymentMaxPriceOfSkn().doubleValue();
|
|
|
gsfrw.setGoodsPaymentPriceRange(PriceRange.builder().min(min).max(max).build());
|
|
|
}
|
|
|
return gsfrw;
|
|
|
}
|
|
|
|
|
|
public GoodsServiceFeeRateWrapper buildWithGoodsType(ServiceFeeRate rate){
|
|
|
GoodsServiceFeeRateWrapper gsfrw = new GoodsServiceFeeRateWrapper(GoodsServiceFeeRateDimension.GOODS_TYPE,rate);
|
|
|
gsfrw.setGoodsPaymentRate(rate == null ? null : rate.getGoodsPaymentRate());
|
|
|
return gsfrw;
|
|
|
private GoodsServiceFeeRateWrapper buildWithGoodsType(ServiceFeeRate rate) {
|
|
|
return new GoodsServiceFeeRateWrapper(GoodsServiceFeeRateDimension.GOODS_TYPE, rate);
|
|
|
}
|
|
|
|
|
|
public GoodsServiceFeeRateWrapper buildOneUserOneGoodsType(int uid, SkupType skupType,ServiceFeeRate rate){
|
|
|
private GoodsServiceFeeRateWrapper buildOneUserOneGoodsType(int uid, SkupType skupType, ServiceFeeRate rate) {
|
|
|
BigDecimal feeRate = sellerPlatformServiceFeeSupport.getPlatformServiceFeeRate(uid, skupType);
|
|
|
GoodsServiceFeeRateWrapper gsfrw = new GoodsServiceFeeRateWrapper(GoodsServiceFeeRateDimension.ONE_USER_ONE_GOODS_TYPE,rate);
|
|
|
if (Objects.isNull(feeRate)) {
|
|
|
return null;
|
|
|
}
|
|
|
GoodsServiceFeeRateWrapper gsfrw = new GoodsServiceFeeRateWrapper(GoodsServiceFeeRateDimension.ONE_USER_ONE_GOODS_TYPE, rate);
|
|
|
gsfrw.setGoodsPaymentRate(feeRate);
|
|
|
return gsfrw;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
ServiceFeeRate rate = new ServiceFeeRate();
|
|
|
rate.setGoodsPaymentRate(BigDecimal.valueOf(0.05));
|
|
|
List<GoodsServiceFeeRateWrapper> allConfig = Lists.newArrayListWithCapacity(4);
|
|
|
|
|
|
GoodsServiceFeeRateWrapper gsfrw4 = new GoodsServiceFeeRateWrapper(GoodsServiceFeeRateDimension.GOODS_TYPE,rate);
|
|
|
gsfrw4.setGoodsPaymentRate(new BigDecimal(0.045D));
|
|
|
allConfig.add(gsfrw4);
|
|
|
|
|
|
GoodsServiceFeeRateWrapper gsfrw3 = new GoodsServiceFeeRateWrapper(GoodsServiceFeeRateDimension.ONE_USER_ONE_SKN,rate);
|
|
|
//gsfrw3.setGoodsPaymentRate(BigDecimal.ZERO);
|
|
|
allConfig.add(gsfrw3);
|
|
|
|
|
|
GoodsServiceFeeRateWrapper gsfrw2 = new GoodsServiceFeeRateWrapper(GoodsServiceFeeRateDimension.ONE_USER_ONE_GOODS_TYPE,rate);
|
|
|
gsfrw2.setGoodsPaymentRate(new BigDecimal(0.05D));
|
|
|
allConfig.add(gsfrw2);
|
|
|
|
|
|
GoodsServiceFeeRateWrapper gsfrw1 = new GoodsServiceFeeRateWrapper(GoodsServiceFeeRateDimension.SKN,rate);
|
|
|
allConfig.add(gsfrw1);
|
|
|
|
|
|
//
|
|
|
GoodsServiceFeeRateWrapper minGSFRW = allConfig.stream()
|
|
|
.min(buildGoodsServiceFeeRateWrapperComp())
|
|
|
.orElse(new GoodsServiceFeeRateWrapper(GoodsServiceFeeRateDimension.GOODS_TYPE,rate));
|
|
|
|
|
|
System.out.println("test getGoodsServiceFeeRate -> " + minGSFRW);
|
|
|
}
|
|
|
} |
...
|
...
|
|