select optimized goods service rate
Showing
7 changed files
with
207 additions
and
15 deletions
1 | package com.yohoufo.order.service.impl; | 1 | package com.yohoufo.order.service.impl; |
2 | 2 | ||
3 | import com.yohobuy.ufo.model.order.constants.SkupType; | 3 | import com.yohobuy.ufo.model.order.constants.SkupType; |
4 | -import com.yohoufo.common.utils.BigDecimalHelper; | ||
5 | import com.yohoufo.order.model.dto.ServiceFeeRate; | 4 | import com.yohoufo.order.model.dto.ServiceFeeRate; |
6 | -import lombok.Data; | ||
7 | import org.slf4j.Logger; | 5 | import org.slf4j.Logger; |
8 | import org.slf4j.LoggerFactory; | 6 | import org.slf4j.LoggerFactory; |
9 | import org.springframework.beans.factory.annotation.Autowired; | 7 | import org.springframework.beans.factory.annotation.Autowired; |
@@ -69,8 +67,6 @@ public class OrderDynamicConfig { | @@ -69,8 +67,6 @@ public class OrderDynamicConfig { | ||
69 | private String sellerGetRateDelivery; | 67 | private String sellerGetRateDelivery; |
70 | 68 | ||
71 | 69 | ||
72 | - | ||
73 | - | ||
74 | private ServiceFeeRate serviceFeeRate; | 70 | private ServiceFeeRate serviceFeeRate; |
75 | 71 | ||
76 | public ServiceFeeRate getServiceFeeRate(SkupType skupType){ | 72 | public ServiceFeeRate getServiceFeeRate(SkupType skupType){ |
@@ -188,6 +188,7 @@ public class ProductProxyService extends AbsProxyService{ | @@ -188,6 +188,7 @@ public class ProductProxyService extends AbsProxyService{ | ||
188 | .hkLeasePrice(storage.getHkLeastPrice()) | 188 | .hkLeasePrice(storage.getHkLeastPrice()) |
189 | .quickDeliverLeasePrice(storage.getHkLeastPrice()) | 189 | .quickDeliverLeasePrice(storage.getHkLeastPrice()) |
190 | */ | 190 | */ |
191 | + .goodsPaymentRateOfSkn(productInfo.getProductProfitRate()) | ||
191 | .goodsPaymentRate(productInfo.getSellerServiceFeeRate()) | 192 | .goodsPaymentRate(productInfo.getSellerServiceFeeRate()) |
192 | .canPublish(productInfo.isSellerCanPublish()) | 193 | .canPublish(productInfo.isSellerCanPublish()) |
193 | .build(); | 194 | .build(); |
@@ -213,17 +213,11 @@ public abstract class AbsSellerOrderComputeHandler implements OrderComputeHandle | @@ -213,17 +213,11 @@ public abstract class AbsSellerOrderComputeHandler implements OrderComputeHandle | ||
213 | */ | 213 | */ |
214 | 214 | ||
215 | protected ServiceFeeRate buildServiceFeeRate(ServiceFeeRate psfr) { | 215 | protected ServiceFeeRate buildServiceFeeRate(ServiceFeeRate psfr) { |
216 | - // | ||
217 | - ServiceFeeRate serviceFeeRate = orderDynamicConfig.getServiceFeeRate(getSkupType()); | ||
218 | - BigDecimal pgpr; | ||
219 | - if (psfr !=null | ||
220 | - && (pgpr = psfr.getGoodsPaymentRate()) !=null){ | ||
221 | - serviceFeeRate.setGoodsPaymentRate(pgpr); | ||
222 | - } | ||
223 | - if (Objects.isNull(serviceFeeRate)){ | ||
224 | - serviceFeeRate = buildDefaultServiceFeeRate(); | 216 | + |
217 | + if (Objects.isNull(psfr)){ | ||
218 | + return buildDefaultServiceFeeRate(); | ||
225 | } | 219 | } |
226 | - return serviceFeeRate; | 220 | + return psfr; |
227 | } | 221 | } |
228 | 222 | ||
229 | protected abstract ServiceFeeRate buildDefaultServiceFeeRate(); | 223 | protected abstract ServiceFeeRate buildDefaultServiceFeeRate(); |
1 | +package com.yohoufo.order.service.seller.fee; | ||
2 | + | ||
3 | +import com.google.common.collect.Lists; | ||
4 | +import com.yohobuy.ufo.model.order.bo.PrdPrice; | ||
5 | +import com.yohobuy.ufo.model.order.constants.SkupType; | ||
6 | +import com.yohoufo.order.model.dto.SellerOrderComputeResult; | ||
7 | +import com.yohoufo.order.model.dto.ServiceFeeRate; | ||
8 | +import com.yohoufo.order.service.impl.OrderDynamicConfig; | ||
9 | +import com.yohoufo.order.service.support.SellerPlatformServiceFeeSupport; | ||
10 | +import com.yohoufo.order.utils.LoggerUtils; | ||
11 | +import com.yohoufo.order.utils.OrderAssist; | ||
12 | +import org.slf4j.Logger; | ||
13 | +import org.springframework.beans.factory.annotation.Autowired; | ||
14 | +import org.springframework.stereotype.Service; | ||
15 | + | ||
16 | +import java.math.BigDecimal; | ||
17 | +import java.util.Comparator; | ||
18 | +import java.util.List; | ||
19 | +import java.util.Optional; | ||
20 | + | ||
21 | +@Service | ||
22 | +public class GoodsAmountService { | ||
23 | + | ||
24 | + private final Logger logger = LoggerUtils.getSellerOrderLogger(); | ||
25 | + | ||
26 | + @Autowired | ||
27 | + private SellerPlatformServiceFeeSupport sellerPlatformServiceFeeSupport; | ||
28 | + | ||
29 | + | ||
30 | + @Autowired | ||
31 | + private OrderDynamicConfig orderDynamicConfig; | ||
32 | + | ||
33 | + private static Comparator<GoodsServiceFeeRateWrapper> buildGoodsServiceFeeRateWrapperComp(){ | ||
34 | + return (GoodsServiceFeeRateWrapper o1, GoodsServiceFeeRateWrapper o2) -> { | ||
35 | + BigDecimal o1gpr = o1.getGoodsPaymentRate(), o2gpr = o2.getGoodsPaymentRate(); | ||
36 | + | ||
37 | + if (o1gpr == null){ | ||
38 | + if (o2gpr == null){ | ||
39 | + return 0; | ||
40 | + }else{ | ||
41 | + return 1; | ||
42 | + } | ||
43 | + }else{ | ||
44 | + if (o2gpr == null){ | ||
45 | + return 1; | ||
46 | + }else { | ||
47 | + return o1gpr.compareTo(o2gpr); | ||
48 | + } | ||
49 | + } | ||
50 | + | ||
51 | + }; | ||
52 | + } | ||
53 | + | ||
54 | + | ||
55 | + public SellerOrderComputeResult getGoodsServiceFeeRate(int uid, int storageId, PrdPrice prdPrice, SkupType skupType){ | ||
56 | + logger.info("in GoodsAmountService.getGoodsServiceFeeRate uid {}, storageId {},prdPrice {} skupType {}", | ||
57 | + uid, storageId, prdPrice, skupType); | ||
58 | + ServiceFeeRate rate = orderDynamicConfig.getServiceFeeRate(skupType); | ||
59 | + SellerOrderComputeResult highPriority = OrderAssist.buildHighestPriorityConfig(prdPrice, rate); | ||
60 | + if (highPriority != null){ | ||
61 | + return highPriority; | ||
62 | + } | ||
63 | + | ||
64 | + List<GoodsServiceFeeRateWrapper> allConfig = Lists.newArrayListWithCapacity(4); | ||
65 | + //build One User One GoodsType | ||
66 | + allConfig.add(buildOneUserOneGoodsType(uid, skupType)); | ||
67 | + // build by skn | ||
68 | + allConfig.add(buildWithSkn(prdPrice)); | ||
69 | + //build by goods type | ||
70 | + | ||
71 | + allConfig.add(buildWithGoodsType(rate)); | ||
72 | + logger.info("in GoodsAmountService.getGoodsServiceFeeRate uid {}, storageId {}, skupType {} prdPrice {} allConfig {}", | ||
73 | + uid, storageId, skupType, prdPrice, allConfig); | ||
74 | + | ||
75 | + Optional<GoodsServiceFeeRateWrapper> minGSFRW = allConfig.stream() | ||
76 | + .min(buildGoodsServiceFeeRateWrapperComp()); | ||
77 | + SellerOrderComputeResult socr = new SellerOrderComputeResult(); | ||
78 | + if(minGSFRW.isPresent()) { | ||
79 | + rate.setGoodsPaymentRate(minGSFRW.get().getGoodsPaymentRate()); | ||
80 | + } | ||
81 | + socr.setServiceFeeRate(rate); | ||
82 | + return socr; | ||
83 | + } | ||
84 | + | ||
85 | + public GoodsServiceFeeRateWrapper buildWithSkn(PrdPrice prdPrice){ | ||
86 | + BigDecimal rate = prdPrice != null ? prdPrice.getGoodsPaymentRateOfSkn() : null; | ||
87 | + GoodsServiceFeeRateWrapper gsfrw = new GoodsServiceFeeRateWrapper(); | ||
88 | + gsfrw.setGoodsServiceFeeRateDimension(GoodsServiceFeeRateDimension.SKN); | ||
89 | + gsfrw.setGoodsPaymentRate(rate); | ||
90 | + return gsfrw; | ||
91 | + } | ||
92 | + | ||
93 | + public GoodsServiceFeeRateWrapper buildWithGoodsType(ServiceFeeRate rate){ | ||
94 | + | ||
95 | + | ||
96 | + GoodsServiceFeeRateWrapper gsfrw = new GoodsServiceFeeRateWrapper(); | ||
97 | + gsfrw.setGoodsServiceFeeRateDimension(GoodsServiceFeeRateDimension.ONE_USER_ONE_GOODS_TYPE); | ||
98 | + gsfrw.setGoodsPaymentRate(rate == null ? null : rate.getGoodsPaymentRate()); | ||
99 | + return gsfrw; | ||
100 | + } | ||
101 | + | ||
102 | + public GoodsServiceFeeRateWrapper buildOneUserOneGoodsType(int uid, SkupType skupType){ | ||
103 | + BigDecimal rate = sellerPlatformServiceFeeSupport.getPlatformServiceFeeRate(uid, skupType); | ||
104 | + GoodsServiceFeeRateWrapper gsfrw = new GoodsServiceFeeRateWrapper(); | ||
105 | + gsfrw.setGoodsServiceFeeRateDimension(GoodsServiceFeeRateDimension.ONE_USER_ONE_GOODS_TYPE); | ||
106 | + gsfrw.setGoodsPaymentRate(rate); | ||
107 | + return gsfrw; | ||
108 | + } | ||
109 | + | ||
110 | + | ||
111 | + | ||
112 | + public static void main(String[] args) { | ||
113 | + List<GoodsServiceFeeRateWrapper> allConfig = Lists.newArrayListWithCapacity(4); | ||
114 | + | ||
115 | + GoodsServiceFeeRateWrapper gsfrw4 = new GoodsServiceFeeRateWrapper(); | ||
116 | + gsfrw4.setGoodsServiceFeeRateDimension(GoodsServiceFeeRateDimension.GOODS_TYPE); | ||
117 | + allConfig.add(gsfrw4); | ||
118 | + | ||
119 | + GoodsServiceFeeRateWrapper gsfrw3 = new GoodsServiceFeeRateWrapper(); | ||
120 | + gsfrw3.setGoodsServiceFeeRateDimension(GoodsServiceFeeRateDimension.ONE_USER_ONE_SKN); | ||
121 | + gsfrw3.setGoodsPaymentRate(BigDecimal.ZERO); | ||
122 | + allConfig.add(gsfrw3); | ||
123 | + | ||
124 | + GoodsServiceFeeRateWrapper gsfrw2 = new GoodsServiceFeeRateWrapper(); | ||
125 | + gsfrw2.setGoodsServiceFeeRateDimension(GoodsServiceFeeRateDimension.ONE_USER_ONE_GOODS_TYPE); | ||
126 | + gsfrw2.setGoodsPaymentRate(new BigDecimal(2)); | ||
127 | + allConfig.add(gsfrw2); | ||
128 | + | ||
129 | + GoodsServiceFeeRateWrapper gsfrw1 = new GoodsServiceFeeRateWrapper(); | ||
130 | + gsfrw1.setGoodsServiceFeeRateDimension(GoodsServiceFeeRateDimension.SKN); | ||
131 | + gsfrw1.setGoodsPaymentRate(new BigDecimal(1)); | ||
132 | + allConfig.add(gsfrw1); | ||
133 | + | ||
134 | + // | ||
135 | + GoodsServiceFeeRateWrapper minGSFRW = allConfig.stream().min(buildGoodsServiceFeeRateWrapperComp()).orElse(new GoodsServiceFeeRateWrapper()); | ||
136 | + | ||
137 | + System.out.println("test getGoodsServiceFeeRate -> " + minGSFRW); | ||
138 | + } | ||
139 | +} |
order/src/main/java/com/yohoufo/order/service/seller/fee/GoodsServiceFeeRateDimension.java
0 → 100644
1 | +package com.yohoufo.order.service.seller.fee; | ||
2 | + | ||
3 | +import lombok.Getter; | ||
4 | + | ||
5 | +public enum GoodsServiceFeeRateDimension { | ||
6 | + | ||
7 | + GOODS_TYPE(1), | ||
8 | + ONE_USER_ONE_SKN(2), | ||
9 | + ONE_USER_ONE_GOODS_TYPE(3), | ||
10 | + SKN(4); | ||
11 | + | ||
12 | + @Getter | ||
13 | + int code; | ||
14 | + | ||
15 | + GoodsServiceFeeRateDimension(int code) { | ||
16 | + this.code = code; | ||
17 | + } | ||
18 | +} |
1 | +package com.yohoufo.order.service.seller.fee; | ||
2 | + | ||
3 | +import com.yohoufo.order.model.dto.ServiceFeeRate; | ||
4 | +import lombok.Getter; | ||
5 | +import lombok.Setter; | ||
6 | +import lombok.ToString; | ||
7 | + | ||
8 | +import java.math.BigDecimal; | ||
9 | + | ||
10 | +@ToString | ||
11 | +public class GoodsServiceFeeRateWrapper { | ||
12 | + @Getter@Setter | ||
13 | + private GoodsServiceFeeRateDimension goodsServiceFeeRateDimension; | ||
14 | + | ||
15 | + @Getter@Setter | ||
16 | + private BigDecimal goodsPaymentRate; | ||
17 | + | ||
18 | + | ||
19 | + public ServiceFeeRate getServiceFeeRate(){ | ||
20 | + ServiceFeeRate sfr = new ServiceFeeRate(); | ||
21 | + sfr.setGoodsPaymentRate(goodsPaymentRate); | ||
22 | + return sfr; | ||
23 | + } | ||
24 | + | ||
25 | +} |
@@ -64,7 +64,8 @@ public class OrderAssist { | @@ -64,7 +64,8 @@ public class OrderAssist { | ||
64 | PlatformFeeDto platformFee; | 64 | PlatformFeeDto platformFee; |
65 | ServiceFeeRate serviceFeeRate; | 65 | ServiceFeeRate serviceFeeRate; |
66 | BigDecimal goodsPaymentRate; | 66 | BigDecimal goodsPaymentRate; |
67 | - if ((goodsPaymentRate = prdPrice.getGoodsPaymentRate()) != null){ //如果基础商品已经设置了抽成比率,则鉴定费和包装费免除 | 67 | + if ((goodsPaymentRate = prdPrice.getGoodsPaymentRate()) != null){ |
68 | + //如果基础商品已经设置了抽成比率,则鉴定费和包装费免除 | ||
68 | platformFee = new PlatformFeeDto(); | 69 | platformFee = new PlatformFeeDto(); |
69 | platformFee.setAppraiseFee(new BigDecimal(0)); | 70 | platformFee.setAppraiseFee(new BigDecimal(0)); |
70 | platformFee.setPackageFee(new BigDecimal(0)); | 71 | platformFee.setPackageFee(new BigDecimal(0)); |
@@ -79,4 +80,22 @@ public class OrderAssist { | @@ -79,4 +80,22 @@ public class OrderAssist { | ||
79 | return socr; | 80 | return socr; |
80 | } | 81 | } |
81 | 82 | ||
83 | + public static SellerOrderComputeResult buildHighestPriorityConfig(PrdPrice prdPrice, ServiceFeeRate serviceFeeRate){ | ||
84 | + SellerOrderComputeResult socr = new SellerOrderComputeResult(); | ||
85 | + PlatformFeeDto platformFee; | ||
86 | + BigDecimal goodsPaymentRate; | ||
87 | + if (Objects.nonNull(prdPrice) && Objects.nonNull(goodsPaymentRate = prdPrice.getGoodsPaymentRate())){ | ||
88 | + // | ||
89 | + serviceFeeRate.setGoodsPaymentRate(goodsPaymentRate); | ||
90 | + //如果基础商品已经设置了抽成比率,则鉴定费和包装费免除 | ||
91 | + platformFee = new PlatformFeeDto(); | ||
92 | + platformFee.setAppraiseFee(new BigDecimal(0)); | ||
93 | + platformFee.setPackageFee(new BigDecimal(0)); | ||
94 | + // | ||
95 | + socr.setPlatformFee(platformFee); | ||
96 | + } | ||
97 | + socr.setServiceFeeRate(serviceFeeRate); | ||
98 | + return socr; | ||
99 | + } | ||
100 | + | ||
82 | } | 101 | } |
-
Please register or login to post a comment