Authored by chenchao

in stock goods use global config 2 set rate

package com.yohoufo.order.service.handler;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohoufo.dal.order.model.MetaConfig;
import com.yohoufo.order.model.dto.BuyerPenalty;
import com.yohoufo.order.model.dto.EarnestMoney;
import com.yohoufo.order.model.dto.ServiceFeeRate;
import com.yohoufo.order.service.impl.MetaConfigService;
import com.yohoufo.order.service.seller.AbsSellerOrderComputeHandler;
import com.yohoufo.order.service.seller.OrderComputeHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.Objects;
/**
* Created by chenchao on 2018/9/14.
... ... @@ -16,6 +21,8 @@ import java.util.Collection;
@Component
public class SellerOrderComputeHandler extends AbsSellerOrderComputeHandler implements OrderComputeHandler {
@Autowired
private MetaConfigService metaConfigService;
/**
* 相对独立 不涉及到计算其他费用
* @param prdPrice
... ... @@ -24,7 +31,8 @@ public class SellerOrderComputeHandler extends AbsSellerOrderComputeHandler impl
protected EarnestMoney calEarnestMoney(BigDecimal prdPrice){
BigDecimal[] EARNEST_MONEY_RANGE = orderDynamicConfig.getEMR();
EarnestMoney earnestMoney = new EarnestMoney();
BigDecimal rate = new BigDecimal(0.05D).setScale(2, BigDecimal.ROUND_HALF_UP);
EarnestMoney emc = metaConfigService.getSellerEarnestMoney(SkupType.IN_STOCK);
BigDecimal rate = (emc==null || Objects.isNull(rate = emc.getRate())) ? new BigDecimal(0.08D) : rate;
earnestMoney.setRate(rate);
//TODO earnestMoney.rate 需要调整为动态可配
BigDecimal real = halfUp(prdPrice.multiply(rate));
... ...
... ... @@ -5,6 +5,7 @@ import com.alibaba.fastjson.TypeReference;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yohobuy.ufo.model.order.common.EntrySellerType;
import com.yohobuy.ufo.model.order.common.MetaConfigKey;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohobuy.ufo.model.order.resp.EntryThreshold;
import com.yohoufo.common.cache.CacheClient;
import com.yohoufo.dal.order.MetaConfigMapper;
... ... @@ -40,7 +41,7 @@ public class MetaConfigService {
@Autowired
private CacheClient cacheClient;
/**
* TODO use cache
* use cache
* @return
*/
public BuyerPenalty getBuyerPenalty(){
... ... @@ -109,29 +110,46 @@ public class MetaConfigService {
}
/**
* {"advanceSale":{"max":400,"min":40,"rate":0.08}}
* {
* "advanceSale":{"max":400,"min":40,"rate":0.08},
* "inStock":{"max":200,"min":20,"rate":0.04}
* }
*/
public EarnestMoney getSellerEarnestMoney(){
public EarnestMoney getSellerEarnestMoney(SkupType skupType){
final String key = MetaConfigKey.SELLER_EARNEST_MONEY;
EarnestMoney em = null;
MetaConfig metaConfig = metaConfigMapper.selectByCode(key);
String metaVal = metaConfig.getValue();
try{
JSONObject emjo = JSONObject.parseObject(metaVal);
String advanceSale_key = "advanceSale";
JSONObject asJO = emjo.getJSONObject(advanceSale_key);
if (Objects.nonNull(asJO)){
em = new EarnestMoney();
em.setMin(asJO.getBigDecimal("min"));
em.setMax(asJO.getBigDecimal("max"));
em.setRate(asJO.getBigDecimal("rate"));
String advanceSaleKey = "advanceSale", inStockKey = "inStock";
JSONObject asJO = emjo.getJSONObject(advanceSaleKey),
insJO = emjo.getJSONObject(inStockKey);
switch (skupType){
case ADVANCE:
if (Objects.nonNull(asJO)){
em = json2Bo(asJO);
}
break;
case IN_STOCK:
if (Objects.nonNull(insJO)){
em = json2Bo(insJO);
}
break;
}
}catch (Exception ex){
logger.warn("in getSellerEarnestMoney parseObject fail metaVal {}", metaVal);
}
return em;
}
private EarnestMoney json2Bo(JSONObject jo){
EarnestMoney em = new EarnestMoney();
em.setMin(jo.getBigDecimal("min"));
em.setMax(jo.getBigDecimal("max"));
em.setRate(jo.getBigDecimal("rate"));
return em;
}
... ...
package com.yohoufo.order.service.seller;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohoufo.order.model.dto.BuyerPenalty;
import com.yohoufo.order.model.dto.EarnestMoney;
import com.yohoufo.order.model.dto.ServiceFeeRate;
... ... @@ -23,12 +24,11 @@ public class SellerAdvanceOrderComputeHandler extends AbsSellerOrderComputeHandl
@Override
protected EarnestMoney calEarnestMoney(BigDecimal prdPrice) {
//TODO 根据配置(来自于数据库或缓存 zk ,某一种数据存储方式)
//根据配置(来自于数据库或缓存 zk ,某一种数据存储方式)
EarnestMoney earnestMoney = new EarnestMoney();
earnestMoney.setPrdSalePrice(prdPrice);
//TODO earnestMoney.rate 需要调整为动态可配
EarnestMoney emc = metaConfigService.getSellerEarnestMoney();
//earnestMoney.rate 需要调整为动态可配
EarnestMoney emc = metaConfigService.getSellerEarnestMoney(SkupType.ADVANCE);
BigDecimal rate = (emc==null || Objects.isNull(rate = emc.getRate())) ? new BigDecimal(0.08D) : rate;
BigDecimal real = halfUp(prdPrice.multiply(rate));
BigDecimal min = (emc==null || Objects.isNull(min=emc.getMin())) ? new BigDecimal(56) : min;
... ...