Authored by LUOXC

Merge branch 'hotfix-buyerpenalty' into test6.9.7

... ... @@ -5,6 +5,7 @@ import com.yohobuy.ufo.model.order.common.OrderStatus;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.common.utils.BigDecimalHelper;
import com.yohoufo.dal.order.model.BuyerOrder;
import com.yohoufo.dal.order.model.BuyerOrderGoods;
import com.yohoufo.order.common.ActionStatusHold;
import com.yohoufo.order.model.dto.BuyerPenalty;
import com.yohoufo.order.model.dto.BuyerPenaltyCalResult;
... ... @@ -33,7 +34,7 @@ public class BuyerCancelCompensateComputeHandler {
@Autowired
private BuyerOrderPayDiffTimeHandler buyerOrderPayDiffTimeHandler;
public BuyerPenaltyCalResult calBuyerPenaltyCalResult(BuyerOrder buyerOrder,OrderStatus targetStatus){
public BuyerPenaltyCalResult calBuyerPenaltyCalResult(BuyerOrder buyerOrder, BuyerOrderGoods buyerOrderGoods, OrderStatus targetStatus){
Integer buyerUid = buyerOrder.getUid();
Long orderCode = buyerOrder.getOrderCode();
if (!ActionStatusHold.isBuyerSelfCancel(targetStatus.getCode())){
... ... @@ -45,21 +46,20 @@ public class BuyerCancelCompensateComputeHandler {
return BuyerPenaltyCalResult.getDefault();
}
BigDecimal orderActualAmount = buyerOrder.getAmount();
BigDecimal shipFee = buyerOrder.getShipFee();
BigDecimal goodsActualAmount = orderActualAmount.subtract(buyerOrder.getShipFee());
OrderAttributes orderAttributes = OrderAttributes.getOrderAttributes(buyerOrder.getAttributes());
//TODO try catch to record fail transfer
BuyerPenaltyCalResult bpcr = calBuyerPenalty(buyerUid, orderCode, targetStatus, orderActualAmount, shipFee, orderAttributes);
BuyerPenaltyCalResult bpcr = calBuyerPenalty(buyerUid, orderCode, targetStatus, orderActualAmount, goodsActualAmount, orderAttributes);
return bpcr;
}
/**
* @param buyerUid
* @param orderActualAmount 订单实付金额
* @param orderActualAmount
* @return
*/
public BuyerPenaltyCalResult calBuyerPenalty(Integer buyerUid, Long orderCode, OrderStatus orderStatus,
BigDecimal orderActualAmount,
BigDecimal shipFee,
BigDecimal goodsActualAmount,
OrderAttributes orderAttributes
) {
if (Objects.isNull(orderAttributes)) {
... ... @@ -78,7 +78,7 @@ public class BuyerCancelCompensateComputeHandler {
.diffTime(diffTime)
.select()
.orElseThrow(() -> new UfoServiceException(501, "not match calFee"));
BuyerPenaltyCalResult bpcr = calBuyerPenalty(penaltyRule, buyerUid, orderCode, orderActualAmount, shipFee);
BuyerPenaltyCalResult bpcr = calBuyerPenalty(penaltyRule, buyerUid, orderCode, orderActualAmount, goodsActualAmount);
if (bpcr.getLeftAmount().compareTo(BigDecimal.ZERO) <= 0) {
throw new UfoServiceException(501, "left amount not enough");
}
... ... @@ -86,9 +86,8 @@ public class BuyerCancelCompensateComputeHandler {
}
public BuyerPenaltyCalResult calBuyerPenalty(PenaltyRule penaltyRule, Integer buyerUid, Long orderCode,
BigDecimal orderActualAmount, BigDecimal shipFee) {
BigDecimal orderActualAmount, BigDecimal goodsActualAmount) {
BigDecimal penaltyRate = penaltyRule.getPenaltyRate();
BigDecimal goodsActualAmount = orderActualAmount.subtract(shipFee);
BigDecimal penaltyAmount = BigDecimalHelper.halfUp(goodsActualAmount.multiply(penaltyRate));
if (Objects.nonNull(penaltyRule.getPenaltyMinAmount()) && penaltyAmount.compareTo(penaltyRule.getPenaltyMinAmount()) < 0) {
penaltyAmount = penaltyRule.getPenaltyMinAmount();
... ...
... ... @@ -5,8 +5,10 @@ import com.yohobuy.ufo.model.order.bo.ButtonShowBo;
import com.yohobuy.ufo.model.order.common.OrderStatus;
import com.yohobuy.ufo.model.order.resp.OrderListInfo;
import com.yohoufo.dal.order.model.BuyerOrder;
import com.yohoufo.dal.order.model.BuyerOrderGoods;
import com.yohoufo.order.constants.ViewType;
import com.yohoufo.order.model.response.OrderDetailInfo;
import com.yohoufo.order.service.support.BuyerOrderButtonFormatFunction;
import com.yohoufo.order.service.support.ThreeFunction;
import com.yohoufo.order.utils.LoggerUtils;
import org.apache.commons.collections.CollectionUtils;
... ... @@ -34,6 +36,8 @@ public class BuyerOrderButtonsHandler {
private BiFunction<List<Long>, List<Integer>, List<BuyerOrder>> buyerOrderDS;
private BiFunction<Integer, List<Long>, List<BuyerOrderGoods>> buyerOrderGoodsDS;
public BuyerOrderButtonsHandler(List<OrderListInfo> orderListInfos){
this.orderListInfos = orderListInfos;
}
... ... @@ -43,14 +47,15 @@ public class BuyerOrderButtonsHandler {
}
public BuyerOrderButtonsHandler loadBuyerOrderDS(BiFunction<List<Long>, List<Integer>, List<BuyerOrder>> buyerOrderDS){
public BuyerOrderButtonsHandler loadBuyerOrderDS(BiFunction<List<Long>, List<Integer>, List<BuyerOrder>> buyerOrderDS,BiFunction<Integer, List<Long>, List<BuyerOrderGoods>> buyerOrderGoodsDS){
this.buyerOrderDS = buyerOrderDS;
this.buyerOrderGoodsDS = buyerOrderGoodsDS;
return this;
}
ThreeFunction<BuyerOrder, List<ButtonShowBo>, ViewType, List<ButtonShowBo>> fmtBtnFunc;
BuyerOrderButtonFormatFunction fmtBtnFunc;
public BuyerOrderButtonsHandler loadFmtBtnFunc(ThreeFunction<BuyerOrder,List<ButtonShowBo>, ViewType, List<ButtonShowBo>> fmtBtnFunc){
public BuyerOrderButtonsHandler loadFmtBtnFunc(BuyerOrderButtonFormatFunction fmtBtnFunc){
this.fmtBtnFunc = fmtBtnFunc;
return this;
}
... ... @@ -71,7 +76,8 @@ public class BuyerOrderButtonsHandler {
pbos = buyerOrderDS.apply(paidOrderCodes, statusList);
if (CollectionUtils.isNotEmpty(pbos)){
BuyerOrder pbo = pbos.get(0);
List<ButtonShowBo> fbsbs = fmtBtnFunc.apply(pbo, orderDetailInfo.getButtons(), ViewType.DETAIL);
BuyerOrderGoods bog = buyerOrderGoodsDS.apply(pbo.getUid(),Lists.newArrayList(pbo.getOrderCode())).stream().findFirst().orElse(null);
List<ButtonShowBo> fbsbs = fmtBtnFunc.format(orderDetailInfo.getButtons(), pbo, bog, ViewType.DETAIL);
orderDetailInfo.setButtons(fbsbs);
}
}
... ... @@ -98,19 +104,24 @@ public class BuyerOrderButtonsHandler {
.map(OrderListInfo::getOrderCode).collect(Collectors.toList());
List<BuyerOrder> pbos = null;
if (CollectionUtils.isNotEmpty(paidOrderCodes)){
List<Integer> statusList = Lists.newArrayList(OrderStatus.HAS_PAYED.getCode());
pbos = buyerOrderDS.apply(paidOrderCodes, statusList);
}
if (CollectionUtils.isNotEmpty(pbos)){
Integer uid = pbos.get(0).getUid();
List<Long> orderCodes = pbos.stream().map(BuyerOrder::getOrderCode).collect(Collectors.toList());
Map<Long, BuyerOrder> codeBuyorderMap = pbos.parallelStream()
.collect(Collectors.toMap(BuyerOrder::getOrderCode, Function.identity()));
Map<Long, BuyerOrderGoods> buyerOrderGoodsMap = buyerOrderGoodsDS.apply(uid, orderCodes).stream().collect(Collectors.toMap(BuyerOrderGoods::getOrderCode,Function.identity()));
for(OrderListInfo oli : orderListInfos){
if(olip.test(oli)) {
Long orderCode = oli.getOrderCode();
BuyerOrder pbo = codeBuyorderMap.get(orderCode);
List<ButtonShowBo> fbsbs = fmtBtnFunc.apply(pbo, oli.getButtons(), ViewType.LIST);
BuyerOrderGoods bog = buyerOrderGoodsMap.get(orderCode);
List<ButtonShowBo> fbsbs = fmtBtnFunc.format(oli.getButtons(),pbo,bog , ViewType.LIST);
oli.setButtons(fbsbs);
}
}
... ...
... ... @@ -173,7 +173,7 @@ public abstract class AbsOrderDetailService extends AbsOrderViewService implemen
orderDetailInfo.setOrderCode(orderCode = buyerOrder.getOrderCode());
orderDetailInfo.setSubmitOrderTimeStr(DateUtil.formatDate(buyerOrder.getCreateTime(), DateUtil.yyyy_MM_dd_HH_mm_SS));
List<ButtonShowBo> buttonShowList = orderStatus.getDetailButtons(tabType);
orderDetailInfo.setButtons(formatButtons(buyerOrder, buttonShowList==null? Lists.newArrayList() : new ArrayList<>(buttonShowList), ViewType.DETAIL));
orderDetailInfo.setButtons(formatButtons(buyerOrder, buyerOrderGoods, buttonShowList==null? Lists.newArrayList() : new ArrayList<>(buttonShowList), ViewType.DETAIL));
// 买家 买家订单号 需要处理立即支付
// 卖家 卖家订单号 不存在立即支付的按钮
... ...
... ... @@ -308,10 +308,17 @@ public abstract class AbsOrderListService extends AbsOrderViewService implements
Integer leftTime = timeoutBo.getLeftTime();
orderListInfo.setLeftTime(leftTime);
orderListInfo.setTimeLimit(timeoutBo.getTimelimit());
BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMap.get(buyerOrder.getOrderCode());
if (buyerOrderGoods == null){
getLogger().warn("getOrderList buyer goods not exist, uid is {}, orderCode is {}",
buyerOrder.getUid(), orderListInfo.getOrderCode());
return null;
}
// 按钮显示
List<ButtonShowBo> buttonShowBos = orderStatus.getListButtons(tabType);
orderListInfo.setButtons(formatButtons(buyerOrder, buttonShowBos == null ? new ArrayList<>() : new ArrayList<>(buttonShowBos), ViewType.LIST));
orderListInfo.setButtons(formatButtons(buyerOrder, buyerOrderGoods, buttonShowBos == null ? new ArrayList<>() : new ArrayList<>(buttonShowBos), ViewType.LIST));
// 当剩余时间小于0
if (!CollectionUtils.isEmpty(orderListInfo.getButtons())){
... ... @@ -320,12 +327,7 @@ public abstract class AbsOrderListService extends AbsOrderViewService implements
}
}
BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMap.get(buyerOrder.getOrderCode());
if (buyerOrderGoods == null){
getLogger().warn("getOrderList buyer goods not exist, uid is {}, orderCode is {}",
buyerOrder.getUid(), orderListInfo.getOrderCode());
return null;
}
orderListInfo.setSkup(buyerOrderGoods.getSkup());
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMap.get(buyerOrderGoods.getSkup());
... ...
... ... @@ -8,10 +8,12 @@ import com.yohobuy.ufo.model.order.common.OrderStatus;
import com.yohobuy.ufo.model.order.common.TabType;
import com.yohoufo.dal.order.model.BuyerOrder;
import com.yohobuy.ufo.model.order.common.Payment;
import com.yohoufo.dal.order.model.BuyerOrderGoods;
import com.yohoufo.order.constants.ViewType;
import com.yohoufo.order.model.dto.BuyerPenaltyCalResult;
import com.yohoufo.order.model.response.OrderDetailInfo;
import com.yohoufo.order.service.handler.BuyerCancelCompensateComputeHandler;
import com.yohoufo.order.service.support.BuyerOrderButtonFormatFunction;
import com.yohoufo.order.service.wrapper.OrderTimeoutContext;
import com.yohoufo.order.service.wrapper.OrderTimeoutFactory;
import com.yohoufo.order.service.wrapper.TimeoutWrapper;
... ... @@ -42,6 +44,12 @@ public abstract class AbsOrderViewService {
abstract Logger getLogger();
BuyerOrderButtonFormatFunction buyerOrderButtonFormatFunction() {
return (buttons, buyerOrder, buyerOrderGoods, viewType) -> formatButtons(buyerOrder, buyerOrderGoods, buttons, viewType);
}
/**
*
* @param buyerOrder
... ... @@ -49,7 +57,7 @@ public abstract class AbsOrderViewService {
* @param viewType 1:订单列表; 2:订单详情
* @return
*/
List<ButtonShowBo> formatButtons(BuyerOrder buyerOrder, List<ButtonShowBo> buttons, ViewType viewType){
List<ButtonShowBo> formatButtons(BuyerOrder buyerOrder, BuyerOrderGoods buyerOrderGoods, List<ButtonShowBo> buttons, ViewType viewType){
if (CollectionUtils.isEmpty(buttons) || Objects.isNull(buyerOrder)){
return buttons;
}
... ... @@ -70,7 +78,7 @@ public abstract class AbsOrderViewService {
BuyerPenaltyCalResult bpcr = null;
if (Objects.nonNull(targetOrderStatus)) {
try {
bpcr = buyerCancelCompensateComputeHandler.calBuyerPenaltyCalResult(buyerOrder, targetOrderStatus);
bpcr = buyerCancelCompensateComputeHandler.calBuyerPenaltyCalResult(buyerOrder, buyerOrderGoods, targetOrderStatus);
}catch (Exception ex){
getLogger().warn("in formatButtons error buyerOrder {} buttons {}", buyerOrder, buttons, ex);
}
... ...
... ... @@ -108,9 +108,10 @@ public class BuyerOrderCancelService {
long orderCode = bsdEvent.getOrderCode();
OrderStatus targetOrderStatus = bsdEvent.getTarget();
BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode);
BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMapper.selectByOrderCode(buyerOrder.getUid(),buyerOrder.getOrderCode());
logger.info("in buyer cancel BeforeSellerDeliver begin buyerOrderMapper.selectByOrderCode, buyerUid {}, orderCode {}, skup {} buyerOrder {}",
buyerUid, orderCode, buyerOrder );
BuyerPenaltyCalResult bpcr = buyerCancelCompensateComputeHandler.calBuyerPenaltyCalResult(buyerOrder, targetOrderStatus);
BuyerPenaltyCalResult bpcr = buyerCancelCompensateComputeHandler.calBuyerPenaltyCalResult(buyerOrder,buyerOrderGoods, targetOrderStatus);
logger.info("in buyer cancel BeforeSellerDeliver, event {} BuyerPenaltyCalResult {}", bsdEvent, bpcr);
//买家实付金额(货款+运费)小于赔偿金的额度,不够赔偿的,则不允许取消
BigDecimal penaltyAmount;
... ... @@ -246,9 +247,10 @@ public class BuyerOrderCancelService {
long orderCode = bdrEvent.getOrderCode();
OrderStatus targetOrderStatus = bdrEvent.getTarget();
BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode);
BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMapper.selectByOrderCode(buyerOrder.getUid(),buyerOrder.getOrderCode());
logger.info("in buyer cancel BeforeDepotReceive begin buyerOrderMapper.selectByOrderCode, buyerUid {}, orderCode {}, skup {} buyerOrder {}",
buyerUid, orderCode, buyerOrder );
BuyerPenaltyCalResult bpcr = buyerCancelCompensateComputeHandler.calBuyerPenaltyCalResult(buyerOrder, targetOrderStatus);
BuyerPenaltyCalResult bpcr = buyerCancelCompensateComputeHandler.calBuyerPenaltyCalResult(buyerOrder, buyerOrderGoods, targetOrderStatus);
logger.info("in buyer cancel BeforeDepotReceive, event {} compensate {}", bdrEvent, bpcr);
//买家实付金额(货款+运费)小于赔偿金的额度,不够赔偿的,则不允许取消
BigDecimal penaltyAmount;
... ...
... ... @@ -161,8 +161,8 @@ public class BuyerOrderDetailService extends AbsOrderDetailService implements IO
private void procsessButtons(OrderDetailInfo orderDetailInfo){
new BuyerOrderButtonsHandler(orderDetailInfo)
.loadBuyerOrderDS(buyerOrderMapper::selectByOrderCodes)
.loadFmtBtnFunc(this::formatButtons)
.loadBuyerOrderDS(buyerOrderMapper::selectByOrderCodes,buyerOrderGoodsMapper::selectByOrderCodeList)
.loadFmtBtnFunc(this.buyerOrderButtonFormatFunction())
.processDetail();
}
... ...
... ... @@ -126,8 +126,8 @@ public class BuyerOrderListServiceImpl extends AbsOrderListService implements IO
private void processButtons(List<OrderListInfo> list){
new BuyerOrderButtonsHandler(list)
.loadBuyerOrderDS(buyerOrderMapper::selectByOrderCodes)
.loadFmtBtnFunc(this::formatButtons)
.loadBuyerOrderDS(buyerOrderMapper::selectByOrderCodes,buyerOrderGoodsMapper::selectByOrderCodeList)
.loadFmtBtnFunc(this.buyerOrderButtonFormatFunction())
.process();
}
... ...
... ... @@ -892,13 +892,17 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
break;
case HAS_PAYED:
targetStatus = OrderStatus.BUYER_CANCEL_BEFORE_SELLER_DELIVER;
bpcr = buyerCancelCompensateComputeHandler.calBuyerPenaltyCalResult(buyerOrder, targetStatus);
bpcr = buyerCancelCompensateComputeHandler.calBuyerPenaltyCalResult(buyerOrder,
buyerOrderGoodsMapper.selectByOrderCode(buyerOrder.getUid(),buyerOrder.getOrderCode()),
targetStatus);
occr = bpcr2occr(bpcr);
occr.setNeedPenalty(true);
break;
case SELLER_SEND_OUT:
targetStatus = OrderStatus.BUYER_CANCEL_BEFORE_DEPOT_RECEIVE;
bpcr = buyerCancelCompensateComputeHandler.calBuyerPenaltyCalResult(buyerOrder, targetStatus);
bpcr = buyerCancelCompensateComputeHandler.calBuyerPenaltyCalResult(buyerOrder,
buyerOrderGoodsMapper.selectByOrderCode(buyerOrder.getUid(),buyerOrder.getOrderCode()),
targetStatus);
occr = bpcr2occr(bpcr);
occr.setNeedPenalty(true);
break;
... ...
package com.yohoufo.order.service.support;
import com.yohobuy.ufo.model.order.bo.ButtonShowBo;
import com.yohoufo.dal.order.model.BuyerOrder;
import com.yohoufo.dal.order.model.BuyerOrderGoods;
import com.yohoufo.order.constants.ViewType;
import java.util.List;
public interface BuyerOrderButtonFormatFunction {
List<ButtonShowBo> format(List<ButtonShowBo> srcButtons, BuyerOrder buyerOrder, BuyerOrderGoods buyerOrderGoods, ViewType viewType);
}
\ No newline at end of file
... ...