Authored by chenchao

change cal config

... ... @@ -25,7 +25,6 @@ import com.yohoufo.order.model.dto.BuyerPenaltyCalResult;
import com.yohoufo.order.model.request.PaymentRequest;
import com.yohoufo.order.model.request.TranseferCellNode;
import com.yohoufo.order.model.request.TransferMoneyRequest;
import com.yohoufo.order.service.IPaymentService;
import com.yohoufo.order.service.cache.CacheCleaner;
import com.yohoufo.order.service.cache.CacheKeyBuilder;
import com.yohoufo.order.service.concurrent.ThreadPoolFactory;
... ... @@ -38,7 +37,6 @@ import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Collection;
... ... @@ -53,9 +51,6 @@ import java.util.concurrent.Future;
public class BuyerOrderCancelService {
private Logger logger = LoggerUtils.getOrderCloseLogger();
@Resource(name = "orderDynamicConfig")
private OrderDynamicConfig orderDynamicConfig;
@Autowired
private BuyerOrderMapper buyerOrderMapper;
... ... @@ -197,19 +192,34 @@ public class BuyerOrderCancelService {
return mfee;
}
private BuyerPenaltyCalResult getBuyerPenaltyCalResult(BuyerOrder buyerOrder){
Integer buyerUid = buyerOrder.getUid();
Long orderCode = buyerOrder.getOrderCode();
OrderStatus orderStatus = OrderStatus.getOrderStatus(buyerOrder.getStatus());
BigDecimal orderActualAmount = buyerOrder.getAmount();
BigDecimal shipFee = buyerOrder.getShipFee();
OrderAttributes orderAttributes = OrderAttributes.getOrderAttributes(buyerOrder.getAttributes());
//TODO try catch to record fail transfer
BuyerPenaltyCalResult bpcr = calBuyerPenalty(buyerUid, orderCode, orderStatus, orderActualAmount, shipFee, orderAttributes);
return bpcr;
}
public void cancel(BeforeSellerDeliverEvent bsdEvent){
OrderDynamicConfig.BuyerCancelCompensateNode compensate = orderDynamicConfig.getBeforeSellerDeliverBCCN();
logger.info("in buyer cancel BeforeSellerDeliver, event {} compensate {}", bsdEvent, compensate);
//买家实付金额(货款+运费)小于赔偿金的额度,不够赔偿的,则不允许取消
if(bsdEvent.getAmount()==null||bsdEvent.getAmount().compareTo(compensate.getBuyerCompensateMoney()) < 0){
logger.warn("in buyer cancel BeforeSellerDeliver not allow cancel cause of buyer amount lower than BuyerCompensateMoney, event {} compensate {}", bsdEvent, compensate);
throw new com.yohoufo.common.exception.UfoServiceException(400,"买家赔偿金低于商品售价,不允许取消");
}
public void cancel(BeforeSellerDeliverEvent bsdEvent){
int buyerUid = bsdEvent.getBuyerUid();
int sellerUid = bsdEvent.getSellerUid();
long orderCode = bsdEvent.getOrderCode();
BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode);
logger.info("in buyer cancel BeforeSellerDeliver begin buyerOrderMapper.selectByOrderCode, buyerUid {}, orderCode {}, skup {} buyerOrder {}",
buyerUid, orderCode, buyerOrder );
BuyerPenaltyCalResult bpcr = getBuyerPenaltyCalResult(buyerOrder);
logger.info("in buyer cancel BeforeSellerDeliver, event {} BuyerPenaltyCalResult {}", bsdEvent, bpcr);
//买家实付金额(货款+运费)小于赔偿金的额度,不够赔偿的,则不允许取消
if(bsdEvent.getAmount()==null||bsdEvent.getAmount().compareTo(bpcr.getPenaltyAmount()) < 0){
logger.warn("in buyer cancel BeforeSellerDeliver not allow cancel cause of buyer amount lower than BuyerCompensateMoney, event {} compensate {}", bsdEvent, bpcr);
throw new com.yohoufo.common.exception.UfoServiceException(400,"买家赔偿金低于商品售价,不允许取消");
}
OrderStatus target = bsdEvent.getTarget();
OrderStatus expected = bsdEvent.getExpected();
int currentTime = DateUtil.getCurrentTimeSecond();
... ... @@ -230,14 +240,14 @@ public class BuyerOrderCancelService {
sellerOrderMapper.updateBySkups(soc, Arrays.asList(skup));
SellerOrderGoods psog = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
inBoxFacade.buyerCancelBeforeSellerDeliver(buyerUid, orderCode,
compensate.getBuyerCompensateMoney().toPlainString(), psog);
bpcr.getPenaltyAmount().toPlainString(), psog);
//TODO 整个过程异步去执行(考虑退费依赖订单状态)
//(退费)退保证金给卖家
//(转账)瓜分指定赔偿款给卖家和平台
TransferCase transferCase = TransferCase.BUYER_CANCEL_BEFORE_SELLER_DELIVER;
//(退费)扣除赔偿款,计算剩余的货款,退给买家
BuyerCancelAfterProcessTask bcapt = new BuyerCancelAfterProcessTask(buyerUid, orderCode, skup,
compensate, transferCase);
BuyerCancelAfterProcessTask bcapt = new BuyerCancelAfterProcessTask(buyerOrder, skup,
bpcr, transferCase);
bcapt.setSwdType(SellerWalletDetail.Type.BUYER_CANCEL_NO_DELIVERY);
Future<PayRefundBo> future = ThreadPoolFactory.getBuyerCancelThreadPool().submit(bcapt);
... ... @@ -252,25 +262,28 @@ public class BuyerOrderCancelService {
EventBusPublisher.publishEvent(event);
logger.info("use one thread to execute buyer cancel BeforeSellerDeliver buyerUid {}, orderCode {}, skup {}, compensate {}, transferCase {}",
buyerUid, orderCode, skup, compensate, transferCase);
buyerUid, orderCode, skup, bpcr, transferCase);
}
}
public void cancel(BeforeDepotReceiveEvent bdrEvent){
OrderDynamicConfig.BuyerCancelCompensateNode compensate = orderDynamicConfig.getBeforeDepotReceiveBCCN();
logger.info("in buyer cancel BeforeDepotReceive, event {} compensate {}", bdrEvent, compensate);
int buyerUid = bdrEvent.getBuyerUid();
int sellerUid = bdrEvent.getSellerUid();
long orderCode = bdrEvent.getOrderCode();
BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode);
logger.info("in buyer cancel BeforeDepotReceive begin buyerOrderMapper.selectByOrderCode, buyerUid {}, orderCode {}, skup {} buyerOrder {}",
buyerUid, orderCode, buyerOrder );
BuyerPenaltyCalResult bpcr = getBuyerPenaltyCalResult(buyerOrder);
logger.info("in buyer cancel BeforeDepotReceive, event {} compensate {}", bdrEvent, bpcr);
//买家实付金额(货款+运费)小于赔偿金的额度,不够赔偿的,则不允许取消
if(bdrEvent.getAmount()==null||bdrEvent.getAmount().compareTo(compensate.getBuyerCompensateMoney()) < 0){
logger.warn("in buyer cancel BeforeDepotReceive not allow cancel cause of buyer amount lower than BuyerCompensateMoney, event {} compensate {}", bdrEvent, compensate);
if(bdrEvent.getAmount()==null||bdrEvent.getAmount().compareTo(bpcr.getPenaltyAmount()) < 0){
logger.warn("in buyer cancel BeforeDepotReceive not allow cancel cause of buyer amount lower than BuyerCompensateMoney, event {} compensate {}", bdrEvent, bpcr);
throw new com.yohoufo.common.exception.UfoServiceException(400,"买家赔偿金低于商品售价,不允许取消");
}
OrderStatus target = bdrEvent.getTarget();
OrderStatus expected = bdrEvent.getExpected();
int buyerUid = bdrEvent.getBuyerUid();
int sellerUid = bdrEvent.getSellerUid();
long orderCode = bdrEvent.getOrderCode();
int currentTime = DateUtil.getCurrentTimeSecond();
int rows = buyerOrderMapper.updateStatusByOrderCode(orderCode, buyerUid, expected.getCode(), target.getCode(), currentTime);
if (rows>0) {
... ... @@ -290,14 +303,14 @@ public class BuyerOrderCancelService {
sellerOrderMapper.updateBySkups(soc, Arrays.asList(skup));
SellerOrderGoods psog = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
inBoxFacade.buyerCancelBeforeDepotReceive(buyerUid, orderCode,
compensate.getBuyerCompensateMoney().toPlainString(), psog);
bpcr.getPenaltyAmount().toPlainString(), psog);
//整个过程异步去执行(考虑退费依赖订单状态)
//(退费)退保证金给卖家
//(转账)瓜分指定赔偿款给卖家和平台
//(退费)扣除赔偿款,计算剩余的货款,退给买家
TransferCase transferCase = TransferCase.BUYER_CANCEL_BEFORE_DEPOT_RECEIVE;
BuyerCancelAfterProcessTask bcapt = new BuyerCancelAfterProcessTask(buyerUid, orderCode, skup,
compensate, transferCase);
BuyerCancelAfterProcessTask bcapt = new BuyerCancelAfterProcessTask(buyerOrder, skup,
bpcr, transferCase);
bcapt.setSwdType(SellerWalletDetail.Type.BUYER_CANCEL_DELIVERY);
Future<PayRefundBo> future = ThreadPoolFactory.getBuyerCancelThreadPool().submit(bcapt);
... ... @@ -312,7 +325,7 @@ public class BuyerOrderCancelService {
EventBusPublisher.publishEvent(event);
logger.info("use one thread to execute buyer cancel BeforeDepotReceive buyerUid {}, orderCode {}, skup {}, compensate {}, transferCase {}",
buyerUid, orderCode, skup, compensate, transferCase);
buyerUid, orderCode, skup, bpcr, transferCase);
}
}
... ... @@ -320,18 +333,18 @@ public class BuyerOrderCancelService {
int buyerUid;
long orderCode;
int skup;
OrderDynamicConfig.BuyerCancelCompensateNode compensate;
BuyerPenaltyCalResult bpcr;
BuyerOrder buyerOrder;
TransferCase transferCase;
@Setter
SellerWalletDetail.Type swdType;
public BuyerCancelAfterProcessTask(int buyerUid, long orderCode, int skup, OrderDynamicConfig.
BuyerCancelCompensateNode compensate, TransferCase transferCase) {
this.buyerUid = buyerUid;
this.orderCode = orderCode;
public BuyerCancelAfterProcessTask(BuyerOrder buyerOrder, int skup, BuyerPenaltyCalResult bpcr, TransferCase transferCase) {
this.buyerUid = buyerOrder.getUid();
this.orderCode = buyerOrder.getOrderCode();
this.skup = skup;
this.compensate = compensate;
this.bpcr = bpcr;
this.transferCase = transferCase;
}
... ... @@ -421,7 +434,7 @@ public class BuyerOrderCancelService {
// 整个过程异步去执行(考虑退费依赖订单状态)
//(退费)退保证金给卖家
logger.info("in BuyerCancelAfterProcessTask call buyerUid {}, orderCode {}, skup {}, transferCase {}, compensate {}",
buyerUid, orderCode, skup, transferCase, compensate);
buyerUid, orderCode, skup, transferCase, bpcr);
PayRefundBo prb = null;
try {
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(skup);
... ... @@ -430,23 +443,14 @@ public class BuyerOrderCancelService {
prb = refundSellerEarnestMoney(sellerOrder);
//(转账)瓜分指定赔偿款给卖家和平台
BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode);
logger.info("in BuyerCancelAfterProcessTask call begin buyerOrderMapper.selectByOrderCode, buyerUid {}, orderCode {}, skup {} buyerOrder {}",
buyerUid, orderCode, skup, buyerOrder );
OrderStatus orderStatus = OrderStatus.getOrderStatus(buyerOrder.getStatus());
BigDecimal orderActualAmount = buyerOrder.getAmount();
BigDecimal shipFee = buyerOrder.getShipFee();
OrderAttributes orderAttributes = OrderAttributes.getOrderAttributes(buyerOrder.getAttributes());
//TODO try catch to record fail transfer
BuyerPenaltyCalResult bpcr = calBuyerPenalty(buyerUid, orderCode, orderStatus, orderActualAmount, shipFee, orderAttributes);
transferPenalty(bpcr);
//(退费)扣除赔偿款,计算剩余的货款,退给买家
refundLeftOrderAmount(bpcr, buyerOrder);
logger.info("out BuyerCancelAfterProcessTask call buyerUid {}, orderCode {}, skup {}, transferCase {}, compensate {}",
buyerUid, orderCode, skup, transferCase, compensate);
buyerUid, orderCode, skup, transferCase, bpcr);
}catch (Exception ex){
logger.info("occur error BuyerCancelAfterProcessTask call buyerUid {}, orderCode {}, skup {}, transferCase {}, compensate {}",
buyerUid, orderCode, skup, transferCase, compensate, ex);
buyerUid, orderCode, skup, transferCase, bpcr, ex);
}
return prb;
}
... ...
... ... @@ -2,15 +2,18 @@ redis:
gwNoSyncRedis :
servers:
- 192.168.102.45:6379
auth: redis9646
gwRecoveryRedis :
servers:
- 192.168.102.45:6379
auth: redis9646
# cleanMq:
# addresses:
# ${rabbit.cacheclean.producer.host}
yohoNoSyncRedis :
servers:
- 192.168.102.45:6379
auth: redis9646
# cleanMq:
# addresses:
# 192.168.102.45:5672
... ...