Authored by caoyan

Merge branch 'test6.8.6' of http://git.yoho.cn/ufo/yohoufo-fore into test6.8.6

1 package com.yohoufo.order.service.handler; 1 package com.yohoufo.order.service.handler;
2 2
  3 +import com.yohobuy.ufo.model.order.constants.SkupType;
  4 +import com.yohoufo.dal.order.model.MetaConfig;
3 import com.yohoufo.order.model.dto.BuyerPenalty; 5 import com.yohoufo.order.model.dto.BuyerPenalty;
4 import com.yohoufo.order.model.dto.EarnestMoney; 6 import com.yohoufo.order.model.dto.EarnestMoney;
5 import com.yohoufo.order.model.dto.ServiceFeeRate; 7 import com.yohoufo.order.model.dto.ServiceFeeRate;
  8 +import com.yohoufo.order.service.impl.MetaConfigService;
6 import com.yohoufo.order.service.seller.AbsSellerOrderComputeHandler; 9 import com.yohoufo.order.service.seller.AbsSellerOrderComputeHandler;
7 import com.yohoufo.order.service.seller.OrderComputeHandler; 10 import com.yohoufo.order.service.seller.OrderComputeHandler;
  11 +import org.springframework.beans.factory.annotation.Autowired;
8 import org.springframework.stereotype.Component; 12 import org.springframework.stereotype.Component;
9 13
10 import java.math.BigDecimal; 14 import java.math.BigDecimal;
11 import java.util.Collection; 15 import java.util.Collection;
  16 +import java.util.Objects;
12 17
13 /** 18 /**
14 * Created by chenchao on 2018/9/14. 19 * Created by chenchao on 2018/9/14.
@@ -16,6 +21,8 @@ import java.util.Collection; @@ -16,6 +21,8 @@ import java.util.Collection;
16 @Component 21 @Component
17 public class SellerOrderComputeHandler extends AbsSellerOrderComputeHandler implements OrderComputeHandler { 22 public class SellerOrderComputeHandler extends AbsSellerOrderComputeHandler implements OrderComputeHandler {
18 23
  24 + @Autowired
  25 + private MetaConfigService metaConfigService;
19 /** 26 /**
20 * 相对独立 不涉及到计算其他费用 27 * 相对独立 不涉及到计算其他费用
21 * @param prdPrice 28 * @param prdPrice
@@ -24,7 +31,8 @@ public class SellerOrderComputeHandler extends AbsSellerOrderComputeHandler impl @@ -24,7 +31,8 @@ public class SellerOrderComputeHandler extends AbsSellerOrderComputeHandler impl
24 protected EarnestMoney calEarnestMoney(BigDecimal prdPrice){ 31 protected EarnestMoney calEarnestMoney(BigDecimal prdPrice){
25 BigDecimal[] EARNEST_MONEY_RANGE = orderDynamicConfig.getEMR(); 32 BigDecimal[] EARNEST_MONEY_RANGE = orderDynamicConfig.getEMR();
26 EarnestMoney earnestMoney = new EarnestMoney(); 33 EarnestMoney earnestMoney = new EarnestMoney();
27 - BigDecimal rate = new BigDecimal(0.05D).setScale(2, BigDecimal.ROUND_HALF_UP); 34 + EarnestMoney emc = metaConfigService.getSellerEarnestMoney(SkupType.IN_STOCK);
  35 + BigDecimal rate = (emc==null || Objects.isNull(rate = emc.getRate())) ? new BigDecimal(0.08D) : rate;
28 earnestMoney.setRate(rate); 36 earnestMoney.setRate(rate);
29 //TODO earnestMoney.rate 需要调整为动态可配 37 //TODO earnestMoney.rate 需要调整为动态可配
30 BigDecimal real = halfUp(prdPrice.multiply(rate)); 38 BigDecimal real = halfUp(prdPrice.multiply(rate));
@@ -5,6 +5,7 @@ import com.alibaba.fastjson.TypeReference; @@ -5,6 +5,7 @@ import com.alibaba.fastjson.TypeReference;
5 import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder; 5 import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
6 import com.yohobuy.ufo.model.order.common.EntrySellerType; 6 import com.yohobuy.ufo.model.order.common.EntrySellerType;
7 import com.yohobuy.ufo.model.order.common.MetaConfigKey; 7 import com.yohobuy.ufo.model.order.common.MetaConfigKey;
  8 +import com.yohobuy.ufo.model.order.constants.SkupType;
8 import com.yohobuy.ufo.model.order.resp.EntryThreshold; 9 import com.yohobuy.ufo.model.order.resp.EntryThreshold;
9 import com.yohoufo.common.cache.CacheClient; 10 import com.yohoufo.common.cache.CacheClient;
10 import com.yohoufo.dal.order.MetaConfigMapper; 11 import com.yohoufo.dal.order.MetaConfigMapper;
@@ -40,7 +41,7 @@ public class MetaConfigService { @@ -40,7 +41,7 @@ public class MetaConfigService {
40 @Autowired 41 @Autowired
41 private CacheClient cacheClient; 42 private CacheClient cacheClient;
42 /** 43 /**
43 - * TODO use cache 44 + * use cache
44 * @return 45 * @return
45 */ 46 */
46 public BuyerPenalty getBuyerPenalty(){ 47 public BuyerPenalty getBuyerPenalty(){
@@ -109,29 +110,46 @@ public class MetaConfigService { @@ -109,29 +110,46 @@ public class MetaConfigService {
109 } 110 }
110 111
111 /** 112 /**
112 - * {"advanceSale":{"max":400,"min":40,"rate":0.08}} 113 + * {
  114 + * "advanceSale":{"max":400,"min":40,"rate":0.08},
  115 + * "inStock":{"max":200,"min":20,"rate":0.04}
  116 + * }
113 */ 117 */
114 - public EarnestMoney getSellerEarnestMoney(){ 118 + public EarnestMoney getSellerEarnestMoney(SkupType skupType){
115 final String key = MetaConfigKey.SELLER_EARNEST_MONEY; 119 final String key = MetaConfigKey.SELLER_EARNEST_MONEY;
116 EarnestMoney em = null; 120 EarnestMoney em = null;
117 MetaConfig metaConfig = metaConfigMapper.selectByCode(key); 121 MetaConfig metaConfig = metaConfigMapper.selectByCode(key);
118 String metaVal = metaConfig.getValue(); 122 String metaVal = metaConfig.getValue();
119 -  
120 try{ 123 try{
121 JSONObject emjo = JSONObject.parseObject(metaVal); 124 JSONObject emjo = JSONObject.parseObject(metaVal);
122 - String advanceSale_key = "advanceSale";  
123 - JSONObject asJO = emjo.getJSONObject(advanceSale_key);  
124 - if (Objects.nonNull(asJO)){  
125 - em = new EarnestMoney();  
126 - em.setMin(asJO.getBigDecimal("min"));  
127 - em.setMax(asJO.getBigDecimal("max"));  
128 - em.setRate(asJO.getBigDecimal("rate")); 125 + String advanceSaleKey = "advanceSale", inStockKey = "inStock";
  126 + JSONObject asJO = emjo.getJSONObject(advanceSaleKey),
  127 + insJO = emjo.getJSONObject(inStockKey);
  128 + switch (skupType){
  129 + case ADVANCE:
  130 + if (Objects.nonNull(asJO)){
  131 + em = json2Bo(asJO);
  132 + }
  133 + break;
  134 + case IN_STOCK:
  135 + if (Objects.nonNull(insJO)){
  136 + em = json2Bo(insJO);
  137 + }
  138 + break;
129 } 139 }
  140 +
  141 +
130 }catch (Exception ex){ 142 }catch (Exception ex){
131 logger.warn("in getSellerEarnestMoney parseObject fail metaVal {}", metaVal); 143 logger.warn("in getSellerEarnestMoney parseObject fail metaVal {}", metaVal);
132 } 144 }
  145 + return em;
  146 + }
133 147
134 - 148 + private EarnestMoney json2Bo(JSONObject jo){
  149 + EarnestMoney em = new EarnestMoney();
  150 + em.setMin(jo.getBigDecimal("min"));
  151 + em.setMax(jo.getBigDecimal("max"));
  152 + em.setRate(jo.getBigDecimal("rate"));
135 return em; 153 return em;
136 } 154 }
137 155
1 package com.yohoufo.order.service.seller; 1 package com.yohoufo.order.service.seller;
2 2
  3 +import com.yohobuy.ufo.model.order.constants.SkupType;
3 import com.yohoufo.order.model.dto.BuyerPenalty; 4 import com.yohoufo.order.model.dto.BuyerPenalty;
4 import com.yohoufo.order.model.dto.EarnestMoney; 5 import com.yohoufo.order.model.dto.EarnestMoney;
5 import com.yohoufo.order.model.dto.ServiceFeeRate; 6 import com.yohoufo.order.model.dto.ServiceFeeRate;
@@ -23,12 +24,11 @@ public class SellerAdvanceOrderComputeHandler extends AbsSellerOrderComputeHandl @@ -23,12 +24,11 @@ public class SellerAdvanceOrderComputeHandler extends AbsSellerOrderComputeHandl
23 24
24 @Override 25 @Override
25 protected EarnestMoney calEarnestMoney(BigDecimal prdPrice) { 26 protected EarnestMoney calEarnestMoney(BigDecimal prdPrice) {
26 - //TODO 根据配置(来自于数据库或缓存 zk ,某一种数据存储方式) 27 + //根据配置(来自于数据库或缓存 zk ,某一种数据存储方式)
27 EarnestMoney earnestMoney = new EarnestMoney(); 28 EarnestMoney earnestMoney = new EarnestMoney();
28 earnestMoney.setPrdSalePrice(prdPrice); 29 earnestMoney.setPrdSalePrice(prdPrice);
29 -  
30 - //TODO earnestMoney.rate 需要调整为动态可配  
31 - EarnestMoney emc = metaConfigService.getSellerEarnestMoney(); 30 + //earnestMoney.rate 需要调整为动态可配
  31 + EarnestMoney emc = metaConfigService.getSellerEarnestMoney(SkupType.ADVANCE);
32 BigDecimal rate = (emc==null || Objects.isNull(rate = emc.getRate())) ? new BigDecimal(0.08D) : rate; 32 BigDecimal rate = (emc==null || Objects.isNull(rate = emc.getRate())) ? new BigDecimal(0.08D) : rate;
33 BigDecimal real = halfUp(prdPrice.multiply(rate)); 33 BigDecimal real = halfUp(prdPrice.multiply(rate));
34 BigDecimal min = (emc==null || Objects.isNull(min=emc.getMin())) ? new BigDecimal(56) : min; 34 BigDecimal min = (emc==null || Objects.isNull(min=emc.getMin())) ? new BigDecimal(56) : min;