Merge branch 'test6.9.10' of http://git.yoho.cn/ufo/yohoufo-fore into test6.9.10
Showing
1 changed file
with
19 additions
and
71 deletions
@@ -11,6 +11,7 @@ import com.yohoufo.order.service.support.SellerPlatformServiceFeeSupport; | @@ -11,6 +11,7 @@ import com.yohoufo.order.service.support.SellerPlatformServiceFeeSupport; | ||
11 | import com.yohoufo.order.utils.LoggerUtils; | 11 | import com.yohoufo.order.utils.LoggerUtils; |
12 | import com.yohoufo.order.utils.OrderAssist; | 12 | import com.yohoufo.order.utils.OrderAssist; |
13 | import com.yohoufo.order.utils.SellerGoodsHelper; | 13 | import com.yohoufo.order.utils.SellerGoodsHelper; |
14 | +import org.apache.commons.collections.CollectionUtils; | ||
14 | import org.slf4j.Logger; | 15 | import org.slf4j.Logger; |
15 | import org.springframework.beans.factory.annotation.Autowired; | 16 | import org.springframework.beans.factory.annotation.Autowired; |
16 | import org.springframework.stereotype.Service; | 17 | import org.springframework.stereotype.Service; |
@@ -29,33 +30,11 @@ public class GoodsAmountService { | @@ -29,33 +30,11 @@ public class GoodsAmountService { | ||
29 | @Autowired | 30 | @Autowired |
30 | private SellerPlatformServiceFeeSupport sellerPlatformServiceFeeSupport; | 31 | private SellerPlatformServiceFeeSupport sellerPlatformServiceFeeSupport; |
31 | 32 | ||
32 | - | ||
33 | @Autowired | 33 | @Autowired |
34 | private OrderDynamicConfig orderDynamicConfig; | 34 | private OrderDynamicConfig orderDynamicConfig; |
35 | 35 | ||
36 | - private static Comparator<GoodsServiceFeeRateWrapper> buildGoodsServiceFeeRateWrapperComp(){ | ||
37 | - return (GoodsServiceFeeRateWrapper o1, GoodsServiceFeeRateWrapper o2) -> { | ||
38 | - BigDecimal o1gpr = o1.getGoodsPaymentRate(), o2gpr = o2.getGoodsPaymentRate(); | ||
39 | - | ||
40 | - if (o1gpr == null){ | ||
41 | - if (o2gpr == null){ | ||
42 | - return 0; | ||
43 | - }else{ | ||
44 | - return 1; | ||
45 | - } | ||
46 | - }else{ | ||
47 | - if (o2gpr == null){ | ||
48 | - return -1; | ||
49 | - }else { | ||
50 | - return o1gpr.compareTo(o2gpr); | ||
51 | - } | ||
52 | - } | ||
53 | 36 | ||
54 | - }; | ||
55 | - } | ||
56 | - | ||
57 | - | ||
58 | - public SellerOrderComputeResult getGoodsServiceFeeRate(int uid, int storageId, PrdPrice prdPrice, SkupType skupType){ | 37 | + public SellerOrderComputeResult getGoodsServiceFeeRate(int uid, int storageId, PrdPrice prdPrice, SkupType skupType) { |
59 | logger.info("in GoodsAmountService.getGoodsServiceFeeRate uid {}, storageId {},prdPrice {} skupType {}", | 38 | logger.info("in GoodsAmountService.getGoodsServiceFeeRate uid {}, storageId {},prdPrice {} skupType {}", |
60 | uid, storageId, prdPrice, skupType); | 39 | uid, storageId, prdPrice, skupType); |
61 | ServiceFeeRate rate = orderDynamicConfig.getServiceFeeRate(skupType); | 40 | ServiceFeeRate rate = orderDynamicConfig.getServiceFeeRate(skupType); |
@@ -69,79 +48,48 @@ public class GoodsAmountService { | @@ -69,79 +48,48 @@ public class GoodsAmountService { | ||
69 | return highPriority; | 48 | return highPriority; |
70 | } | 49 | } |
71 | } | 50 | } |
72 | - List<ServiceFeeRate> allConfig = Lists.newArrayListWithCapacity(4); | 51 | + List<ServiceFeeRate> allConfig = Lists.newArrayListWithCapacity(3); |
73 | //build One User One GoodsType 卖家不同商品类型的指定费率 | 52 | //build One User One GoodsType 卖家不同商品类型的指定费率 |
74 | - allConfig.add(buildOneUserOneGoodsType(uid, skupType,rate)); | 53 | + CollectionUtils.addIgnoreNull(allConfig, buildOneUserOneGoodsType(uid, skupType, rate)); |
75 | // build by skn | 54 | // build by skn |
76 | - allConfig.add(buildWithSkn(prdPrice,rate)); | 55 | + CollectionUtils.addIgnoreNull(allConfig, buildWithSkn(prdPrice, rate)); |
77 | //build by goods type 不同商品类型指定的费率 | 56 | //build by goods type 不同商品类型指定的费率 |
78 | - allConfig.add(buildWithGoodsType(rate)); | 57 | + CollectionUtils.addIgnoreNull(allConfig, buildWithGoodsType(rate)); |
79 | logger.info("in GoodsAmountService.getGoodsServiceFeeRate uid {}, storageId {}, skupType {} prdPrice {} allConfig {}", | 58 | logger.info("in GoodsAmountService.getGoodsServiceFeeRate uid {}, storageId {}, skupType {} prdPrice {} allConfig {}", |
80 | uid, storageId, skupType, prdPrice, allConfig); | 59 | uid, storageId, skupType, prdPrice, allConfig); |
81 | 60 | ||
82 | -// Optional<GoodsServiceFeeRateWrapper> minGSFRW = allConfig.stream() | ||
83 | -// .min(buildGoodsServiceFeeRateWrapperComp()); | ||
84 | SellerOrderComputeResult socr = new SellerOrderComputeResult(); | 61 | SellerOrderComputeResult socr = new SellerOrderComputeResult(); |
85 | -// if(minGSFRW.isPresent()) { | ||
86 | -// rate.setGoodsPaymentRate(minGSFRW.get().getGoodsPaymentRate()); | ||
87 | -// } | ||
88 | socr.setServiceFeeRates(allConfig); | 62 | socr.setServiceFeeRates(allConfig); |
89 | return socr; | 63 | return socr; |
90 | } | 64 | } |
91 | 65 | ||
92 | - public GoodsServiceFeeRateWrapper buildWithSkn(PrdPrice prdPrice,ServiceFeeRate rate) { | ||
93 | - GoodsServiceFeeRateWrapper gsfrw = new GoodsServiceFeeRateWrapper(GoodsServiceFeeRateDimension.SKN,rate); | ||
94 | - if (Objects.nonNull(prdPrice)) { | 66 | + private GoodsServiceFeeRateWrapper buildWithSkn(PrdPrice prdPrice, ServiceFeeRate rate) { |
67 | + if (Objects.isNull(prdPrice) || Objects.isNull(prdPrice.getGoodsPaymentRateOfSkn())) { | ||
68 | + return null; | ||
69 | + } | ||
70 | + | ||
71 | + GoodsServiceFeeRateWrapper gsfrw = new GoodsServiceFeeRateWrapper(GoodsServiceFeeRateDimension.SKN, rate); | ||
95 | gsfrw.setGoodsPaymentRate(prdPrice.getGoodsPaymentRateOfSkn()); | 72 | gsfrw.setGoodsPaymentRate(prdPrice.getGoodsPaymentRateOfSkn()); |
96 | double min = Objects.isNull(prdPrice.getGoodsPaymentMinPriceOfSkn()) ? | 73 | double min = Objects.isNull(prdPrice.getGoodsPaymentMinPriceOfSkn()) ? |
97 | 0 : prdPrice.getGoodsPaymentMinPriceOfSkn().doubleValue(); | 74 | 0 : prdPrice.getGoodsPaymentMinPriceOfSkn().doubleValue(); |
98 | double max = Objects.isNull(prdPrice.getGoodsPaymentMaxPriceOfSkn()) ? | 75 | double max = Objects.isNull(prdPrice.getGoodsPaymentMaxPriceOfSkn()) ? |
99 | 1000000 : prdPrice.getGoodsPaymentMaxPriceOfSkn().doubleValue(); | 76 | 1000000 : prdPrice.getGoodsPaymentMaxPriceOfSkn().doubleValue(); |
100 | gsfrw.setGoodsPaymentPriceRange(PriceRange.builder().min(min).max(max).build()); | 77 | gsfrw.setGoodsPaymentPriceRange(PriceRange.builder().min(min).max(max).build()); |
101 | - } | ||
102 | return gsfrw; | 78 | return gsfrw; |
103 | } | 79 | } |
104 | 80 | ||
105 | - public GoodsServiceFeeRateWrapper buildWithGoodsType(ServiceFeeRate rate){ | ||
106 | - GoodsServiceFeeRateWrapper gsfrw = new GoodsServiceFeeRateWrapper(GoodsServiceFeeRateDimension.GOODS_TYPE,rate); | ||
107 | - gsfrw.setGoodsPaymentRate(rate == null ? null : rate.getGoodsPaymentRate()); | ||
108 | - return gsfrw; | 81 | + private GoodsServiceFeeRateWrapper buildWithGoodsType(ServiceFeeRate rate) { |
82 | + return new GoodsServiceFeeRateWrapper(GoodsServiceFeeRateDimension.GOODS_TYPE, rate); | ||
109 | } | 83 | } |
110 | 84 | ||
111 | - public GoodsServiceFeeRateWrapper buildOneUserOneGoodsType(int uid, SkupType skupType,ServiceFeeRate rate){ | 85 | + private GoodsServiceFeeRateWrapper buildOneUserOneGoodsType(int uid, SkupType skupType, ServiceFeeRate rate) { |
112 | BigDecimal feeRate = sellerPlatformServiceFeeSupport.getPlatformServiceFeeRate(uid, skupType); | 86 | BigDecimal feeRate = sellerPlatformServiceFeeSupport.getPlatformServiceFeeRate(uid, skupType); |
113 | - GoodsServiceFeeRateWrapper gsfrw = new GoodsServiceFeeRateWrapper(GoodsServiceFeeRateDimension.ONE_USER_ONE_GOODS_TYPE,rate); | 87 | + if (Objects.isNull(feeRate)) { |
88 | + return null; | ||
89 | + } | ||
90 | + GoodsServiceFeeRateWrapper gsfrw = new GoodsServiceFeeRateWrapper(GoodsServiceFeeRateDimension.ONE_USER_ONE_GOODS_TYPE, rate); | ||
114 | gsfrw.setGoodsPaymentRate(feeRate); | 91 | gsfrw.setGoodsPaymentRate(feeRate); |
115 | return gsfrw; | 92 | return gsfrw; |
116 | } | 93 | } |
117 | 94 | ||
118 | - | ||
119 | - | ||
120 | - public static void main(String[] args) { | ||
121 | - ServiceFeeRate rate = new ServiceFeeRate(); | ||
122 | - rate.setGoodsPaymentRate(BigDecimal.valueOf(0.05)); | ||
123 | - List<GoodsServiceFeeRateWrapper> allConfig = Lists.newArrayListWithCapacity(4); | ||
124 | - | ||
125 | - GoodsServiceFeeRateWrapper gsfrw4 = new GoodsServiceFeeRateWrapper(GoodsServiceFeeRateDimension.GOODS_TYPE,rate); | ||
126 | - gsfrw4.setGoodsPaymentRate(new BigDecimal(0.045D)); | ||
127 | - allConfig.add(gsfrw4); | ||
128 | - | ||
129 | - GoodsServiceFeeRateWrapper gsfrw3 = new GoodsServiceFeeRateWrapper(GoodsServiceFeeRateDimension.ONE_USER_ONE_SKN,rate); | ||
130 | - //gsfrw3.setGoodsPaymentRate(BigDecimal.ZERO); | ||
131 | - allConfig.add(gsfrw3); | ||
132 | - | ||
133 | - GoodsServiceFeeRateWrapper gsfrw2 = new GoodsServiceFeeRateWrapper(GoodsServiceFeeRateDimension.ONE_USER_ONE_GOODS_TYPE,rate); | ||
134 | - gsfrw2.setGoodsPaymentRate(new BigDecimal(0.05D)); | ||
135 | - allConfig.add(gsfrw2); | ||
136 | - | ||
137 | - GoodsServiceFeeRateWrapper gsfrw1 = new GoodsServiceFeeRateWrapper(GoodsServiceFeeRateDimension.SKN,rate); | ||
138 | - allConfig.add(gsfrw1); | ||
139 | - | ||
140 | - // | ||
141 | - GoodsServiceFeeRateWrapper minGSFRW = allConfig.stream() | ||
142 | - .min(buildGoodsServiceFeeRateWrapperComp()) | ||
143 | - .orElse(new GoodsServiceFeeRateWrapper(GoodsServiceFeeRateDimension.GOODS_TYPE,rate)); | ||
144 | - | ||
145 | - System.out.println("test getGoodsServiceFeeRate -> " + minGSFRW); | ||
146 | - } | ||
147 | } | 95 | } |
-
Please register or login to post a comment