Authored by chenchao

Merge branch 'dev_order_6.8.6' into test6.8.6

... ... @@ -13,11 +13,11 @@ public class EarnestMoney {
private BigDecimal prdSalePrice;
private BigDecimal min = new BigDecimal(28);
private BigDecimal min;
private BigDecimal max = new BigDecimal(200);
private BigDecimal max;
private BigDecimal rate = new BigDecimal(0.05D).setScale(2, BigDecimal.ROUND_HALF_UP);
private BigDecimal rate;
private BigDecimal earnestMoney;
}
... ...
... ... @@ -3,6 +3,7 @@ package com.yohoufo.order.model.dto;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Collection;
/**
* Created by chenchao on 2018/9/14.
... ... @@ -17,5 +18,8 @@ public class SellerOrderComputeResult {
BigDecimal income;
ServiceFeeRate serviceFeeRate;
/**
* 处罚规则
*/
Collection<BuyerPenalty.Fee> penaltyFeeRate;
}
... ...
package com.yohoufo.order.service.handler;
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.seller.AbsSellerOrderComputeHandler;
... ... @@ -7,6 +8,7 @@ import com.yohoufo.order.service.seller.OrderComputeHandler;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.Collection;
/**
* Created by chenchao on 2018/9/14.
... ... @@ -22,26 +24,31 @@ 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.setRate(rate);
//TODO earnestMoney.rate 需要调整为动态可配
BigDecimal real = halfUp(prdPrice.multiply(earnestMoney.getRate()));
BigDecimal real = halfUp(prdPrice.multiply(rate));
final BigDecimal min = EARNEST_MONEY_RANGE[0] == null ? earnestMoney.getMin() : EARNEST_MONEY_RANGE[0];
final BigDecimal max = EARNEST_MONEY_RANGE[1] == null ? earnestMoney.getMax() : EARNEST_MONEY_RANGE[1];
real = calCrossWithThreshold(min, max, real);
earnestMoney.setMin(min);
earnestMoney.setMax(max);
earnestMoney.setEarnestMoney(real);
earnestMoney.setPrdSalePrice(prdPrice);
return earnestMoney;
}
@Override
protected ServiceFeeRate buildServiceFeeRate() {
ServiceFeeRate serviceFeeRate = orderDynamicConfig.getServiceFeeRate();
return serviceFeeRate;
}
@Override
protected Collection<BuyerPenalty.Fee> buildStagedCollection() {
return null;
}
}
... ...
... ... @@ -10,6 +10,7 @@ import com.yohoufo.common.cache.CacheClient;
import com.yohoufo.dal.order.MetaConfigMapper;
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.service.cache.CacheKeyBuilder;
import com.yohoufo.order.service.cache.ExpiredTime;
import org.apache.commons.lang3.StringUtils;
... ... @@ -104,4 +105,83 @@ public class MetaConfigService {
return map;
}
/**
* {"advanceSale":{"max":400,"min":40,"rate":0.08}}
*/
public EarnestMoney getSellerEarnestMoney(){
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"));
}
}catch (Exception ex){
logger.warn("in getSellerEarnestMoney parseObject fail metaVal {}", metaVal);
}
return em;
}
/**
* {"goodsInStock":{},"advanceSale":{"beforeSellerDeliver": {"stagedCollection": [{"index": 1,"moneyRange":{"min":40,"max":400},"rate": 0.04,"timeRange": {"max":172800,"min":0}},{"index": 2,"moneyRange":{"min":40,"max":400},"rate": 0.08,"timeRange": {"min":172800}}]}}}
* @return
*/
public BuyerPenalty getSellerPenalty(){
/*
* {
"goodsInStock": {},
"advanceSale": {
"beforeSellerDeliver": {
"stagedCollection": [
{
"index": 1,
"moneyRange": {
"min": 40,
"max": 400
},
"rate": 0.04,
"timeRange": {
"max": 172800,
"min": 0
}
},
{
"index": 2,
"moneyRange": {
"min": 40,
"max": 400
},
"rate": 0.08,
"timeRange": {
"min": 172800
}
}
]
}
}
}
* */
final String key = MetaConfigKey.SELLER_PENALTY;
MetaConfig metaConfig = metaConfigMapper.selectByCode(key);
String metaVal = metaConfig.getValue();
BuyerPenalty sellerPenalty = new BuyerPenalty();
try{
sellerPenalty = JSONObject.parseObject(metaVal, BuyerPenalty.class);
}catch (Exception ex){
logger.warn("in getSellerPenalty parseObject fail, metaVal {}", metaVal);
}
return sellerPenalty;
}
}
... ...
package com.yohoufo.order.service.seller;
import com.yohoufo.common.utils.BigDecimalHelper;
import com.yohoufo.order.model.dto.EarnestMoney;
import com.yohoufo.order.model.dto.PlatformFeeDto;
import com.yohoufo.order.model.dto.SellerOrderComputeResult;
import com.yohoufo.order.model.dto.ServiceFeeRate;
import com.yohoufo.order.model.dto.*;
import com.yohoufo.order.service.impl.OrderDynamicConfig;
import com.yohoufo.order.utils.LoggerUtils;
import org.slf4j.Logger;
... ... @@ -12,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import java.math.BigDecimal;
import java.util.Collection;
/**
* Created by chao.chen on 2019/2/1.
... ... @@ -54,6 +52,7 @@ public abstract class AbsSellerOrderComputeHandler implements OrderComputeHandle
//TODO 根据配置文件
result.setServiceFeeRate(serviceFeeRate);
result.setBankTransferfee(bankTransferFee);
result.setPenaltyFeeRate(buildStagedCollection());
return result;
}
... ... @@ -127,4 +126,6 @@ public abstract class AbsSellerOrderComputeHandler implements OrderComputeHandle
}
protected abstract ServiceFeeRate buildServiceFeeRate();
protected abstract Collection<BuyerPenalty.Fee> buildStagedCollection();
}
... ...
package com.yohoufo.order.service.seller;
import com.alibaba.fastjson.JSONObject;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
/**
* Created by chao.chen on 2019/2/1.
*/
@Component
public class SellerAdvanceOrderComputeHandler extends AbsSellerOrderComputeHandler implements OrderComputeHandler {
@Autowired
private MetaConfigService metaConfigService;
@Override
protected EarnestMoney calEarnestMoney(BigDecimal prdPrice) {
//TODO 根据配置(来自于数据库或缓存 zk ,某一种数据存储方式)
... ... @@ -19,10 +28,11 @@ public class SellerAdvanceOrderComputeHandler extends AbsSellerOrderComputeHandl
earnestMoney.setPrdSalePrice(prdPrice);
//TODO earnestMoney.rate 需要调整为动态可配
final BigDecimal rate = new BigDecimal(0.08D);
EarnestMoney emc = metaConfigService.getSellerEarnestMoney();
BigDecimal rate = (emc==null || Objects.isNull(rate = emc.getRate())) ? new BigDecimal(0.08D) : rate;
BigDecimal real = halfUp(prdPrice.multiply(rate));
final BigDecimal min = new BigDecimal(56);
final BigDecimal max = new BigDecimal(438);
BigDecimal min = (emc==null || Objects.isNull(min=emc.getMin())) ? new BigDecimal(56) : min;
BigDecimal max = (emc==null || Objects.isNull(max=emc.getMax())) ? new BigDecimal(438) : max;
real = calCrossWithThreshold(min, max, real);
earnestMoney.setMin(min);
earnestMoney.setMax(max);
... ... @@ -31,13 +41,22 @@ public class SellerAdvanceOrderComputeHandler extends AbsSellerOrderComputeHandl
return earnestMoney;
}
public static void main(String[] args) {
System.out.println(JSONObject.toJSONString(new EarnestMoney()));
}
@Override
protected ServiceFeeRate buildServiceFeeRate() {
ServiceFeeRate serviceFeeRate = orderDynamicConfig.getServiceFeeRate();
return serviceFeeRate;
}
@Override
protected Collection<BuyerPenalty.Fee> buildStagedCollection() {
return Optional.ofNullable(metaConfigService.getSellerPenalty())
.map((bp) -> {
Map<String, BuyerPenalty.StockCase> scMap = bp.getStockCaseMap();
BuyerPenalty.StockCase sc = scMap.get("advanceSale");
Map<String, BuyerPenalty.TriggerCase> tcMap = sc.getTriggerCaseMap();
BuyerPenalty.TriggerCase tc = tcMap.get("beforeSellerDeliver");
return tc.getStagedCollection();
}).orElse(null);
}
}
... ...
... ... @@ -82,4 +82,75 @@ public class BuyerPenaltyTest extends BaseTest {
JSONObject.toJSONString(bp)}).getMessage();
System.out.println(message);
}
@Test
public void createValue4SellerPenalty(){
BigDecimal mmin = new BigDecimal(40), mmax = new BigDecimal(400);
int index = 0;
BuyerPenalty bp = new BuyerPenalty();
BuyerPenalty.TriggerCase triggerCase = new BuyerPenalty.TriggerCase();
triggerCase.setName("beforeSellerDeliver");
Collection<BuyerPenalty.Fee> fees = new ArrayList<>();
BuyerPenalty.Fee before48HFee = new BuyerPenalty.Fee();
BuyerPenalty.Range mr = new BuyerPenalty.Range();
mr.setMin(mmin);
mr.setMax(mmax);
before48HFee.setMoneyRange(mr);
BuyerPenalty.Range tr = new BuyerPenalty.Range();
tr.setMin(new BigDecimal(0));
tr.setMax(new BigDecimal(172800));
before48HFee.setTimeRange(tr);
before48HFee.setRate(new BigDecimal(0.04).setScale(2, BigDecimal.ROUND_HALF_UP));
before48HFee.setIndex(++index);
fees.add(before48HFee);
//after 172800s
BuyerPenalty.Fee after48H = new BuyerPenalty.Fee();
BuyerPenalty.Range mr1 = new BuyerPenalty.Range();
mr1.setMin(mmin);
mr1.setMax(mmax);
after48H.setMoneyRange(mr1);
BuyerPenalty.Range tr1 = new BuyerPenalty.Range();
tr1.setMin(new BigDecimal(172800));
after48H.setTimeRange(tr1);
after48H.setRate(new BigDecimal(0.08).setScale(2, BigDecimal.ROUND_HALF_UP));
after48H.setIndex(++index);
fees.add(after48H);
triggerCase.setStagedCollection(fees);
//BuyerPenalty.TriggerCase triggerCase1 = new BuyerPenalty.TriggerCase();
//triggerCase1.setName("beforeDepotReceive");
//BuyerPenalty.Fee bdrFee = new BuyerPenalty.Fee();
//BuyerPenalty.Range bdrmr = new BuyerPenalty.Range();
//bdrmr.setMin(new BigDecimal(88));
//bdrFee.setMoneyRange(bdrmr);
//bdrFee.setRate(new BigDecimal(0.03).setScale(2, BigDecimal.ROUND_HALF_UP));
//Collection<BuyerPenalty.Fee> bdrfees = new ArrayList<>();
//bdrfees.add(bdrFee);
//triggerCase1.setStagedCollection(bdrfees);
Map<String,BuyerPenalty.TriggerCase> map = new HashMap<>();
map.put(triggerCase.getName(), triggerCase);
//map.put(triggerCase1.getName(), triggerCase1);
BuyerPenalty.StockCase stockCase = new BuyerPenalty.StockCase();
stockCase.setStockTypeName("advanceSale");
stockCase.setTriggerCaseMap(map);
Map<String,BuyerPenalty.StockCase> stockCaseMap = new HashMap<>();
stockCaseMap.put(stockCase.getStockTypeName(), stockCase);
bp.setStockCaseMap(stockCaseMap);
String message = MessageFormatter.arrayFormat("meta config key {} =========> value {}",
new Object[]{MetaConfigKey.SELLER_PENALTY,
JSONObject.toJSONString(bp)}).getMessage();
System.out.println(message);
}
}
... ...