Authored by chenchao

add cancel by audit failed

package com.yohoufo.order.controller;
import com.yohobuy.ufo.model.order.req.BatchImportPrdReq;
import com.yohobuy.ufo.model.order.req.SellerOrderCancelReq;
import com.yohobuy.ufo.model.request.product.ProductImportTranItemBo;
import com.yohoufo.common.annotation.IgnoreSession;
import com.yohoufo.common.annotation.IgnoreSignature;
import com.yohoufo.order.event.AuditFailedEvent;
import com.yohoufo.order.service.impl.SellerOrderCancelService;
import com.yohoufo.order.service.impl.visitor.AuditCancelCase;
import com.yohoufo.order.service.seller.ImportPublishExcutor;
import com.yohoufo.order.utils.LoggerUtils;
import org.slf4j.Logger;
... ... @@ -24,6 +28,9 @@ public class ErpSellerGoodsController {
@Autowired
private ImportPublishExcutor importPublishExcutor;
@Autowired
private SellerOrderCancelService sellerOrderCancelService;
/**
* 批量导入skup
* @param req
... ... @@ -35,4 +42,16 @@ public class ErpSellerGoodsController {
logger.info("in batchImportPrds req {}", req);
importPublishExcutor.publish(req);
}
@IgnoreSignature
@IgnoreSession
@RequestMapping("/auditFailed")
public void auditFailed(@RequestBody SellerOrderCancelReq req){
logger.info("in auditFailed req {}", req);
AuditFailedEvent afe = AuditFailedEvent.builder().skup(req.getSkup())
.rejectReason(req.getRejectReason())
.build();
AuditCancelCase acc = new AuditCancelCase(afe);
acc.accept(sellerOrderCancelService);
}
}
... ...
package com.yohoufo.order.event;
import com.yohoufo.common.alarm.Event;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Builder;
import org.springframework.beans.factory.annotation.Autowired;
/**
* Created by chao.chen on 2019/4/12.
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class AuditFailedEvent extends Event {
private int skup;
private String rejectReason;
}
... ...
... ... @@ -36,9 +36,7 @@ import com.yohoufo.order.service.handler.RefundEarnestMoneyHandler;
import com.yohoufo.order.service.handler.RefundGoodsMoneyHandler;
import com.yohoufo.order.service.handler.penalty.PenaltyResult;
import com.yohoufo.order.service.handler.penalty.SellerEarnestMoney2BuyerPenaltyCalculator;
import com.yohoufo.order.service.impl.visitor.AutoCancelCase;
import com.yohoufo.order.service.impl.visitor.OffShelveCancelCase;
import com.yohoufo.order.service.impl.visitor.UserCancelCase;
import com.yohoufo.order.service.impl.visitor.*;
import com.yohoufo.order.service.pay.AbstractPayService;
import com.yohoufo.order.service.proxy.InBoxFacade;
import com.yohoufo.order.service.proxy.OrderStatusFlowService;
... ... @@ -700,9 +698,13 @@ public class SellerOrderCancelService {
* @param offShelveCancelCase
*/
public void cancel(OffShelveCancelCase offShelveCancelCase){
logger.info("in cancel offShelveCancelCase {}", offShelveCancelCase);
ErpCancelSellerOrderEvent event = (ErpCancelSellerOrderEvent)offShelveCancelCase.getEvent();
final int skup = event.getSkup();
logger.info("in cancel offShelveCancelCase {}", skup);
SkupStatus expectSkupStatus = SkupStatus.CAN_SELL;
final SellerOrderStatus targetSellerOrderStatus = SellerOrderStatus.YOHO_CANCEL_SELL;
/*
if (skup <= 0){
logger.warn("in offShelveCancelCase ,skup is illegal, skup {}", skup);
return;
... ... @@ -714,14 +716,14 @@ public class SellerOrderCancelService {
return;
}
SkupStatus expectSkupStatus = SkupStatus.CAN_SELL;
boolean earnestMoneyPaidFlag = expectSkupStatus.getCode() == skupStatus;
if (!earnestMoneyPaidFlag){
logger.warn("in offShelveCancelCase, SellerOrderGoods status illegal, skup {}, status {}", skup, skupStatus);
return;
}
final SellerOrderStatus targetSellerOrderStatus = SellerOrderStatus.YOHO_CANCEL_SELL;
SellerOrderGoods targetGoods = new SellerOrderGoods();
targetGoods.setId(skup);
targetGoods.setStatus(targetSellerOrderStatus.getSkupStatus().getCode());
... ... @@ -782,8 +784,134 @@ public class SellerOrderCancelService {
.loadSeller(sellerUid, sellerIsSuper, orderCode, targetSellerOrderStatus)
.loadLogger(logger)
.refund();
*/
CancelStatusNode csn = new CancelStatusNode();
csn.skup = skup;
csn.expectSkupStatus = expectSkupStatus;
csn.targetSellerOrderStatus = targetSellerOrderStatus;
CancelPreparedNode cpn = doCancelByErp(csn, offShelveCancelCase);
SellerOrderGoods psog = cpn.psog;
Integer sellerUid = psog.getUid();
inBoxFacade.notifyUnshelfCauseBySpecialReason(sellerUid, psog);
}
private static class CancelStatusNode{
int skup;
SkupStatus expectSkupStatus;
SellerOrderStatus targetSellerOrderStatus;
}
private static class CancelPreparedNode{
SellerOrderGoods psog;
}
private CancelPreparedNode doCancelByErp(CancelStatusNode csn, OrderCancelCase orderCancelCase){
int skup = csn.skup;
String caseName = orderCancelCase.caseName();
logger.info("in cancel {} skup {}", caseName, skup);
CancelPreparedNode cpn = null;
if (skup <= 0){
logger.warn("in {} ,skup is illegal, skup {}", caseName, skup);
return cpn;
}
SellerOrderGoods psog = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
Integer skupStatus;
if (psog == null || (skupStatus = psog.getStatus() )== null){
logger.warn("in {}, SellerOrderGoods or it's status illegal, skup {}", caseName,skup);
return cpn;
}
SkupStatus expectSkupStatus = SkupStatus.CAN_SELL;
boolean earnestMoneyPaidFlag = expectSkupStatus.getCode() == skupStatus;
if (!earnestMoneyPaidFlag){
logger.warn("in {}, SellerOrderGoods status illegal, skup {}, status {}", caseName, skup, skupStatus);
return cpn;
}
final SellerOrderStatus targetSellerOrderStatus = SellerOrderStatus.YOHO_CANCEL_SELL;
SellerOrderGoods targetGoods = new SellerOrderGoods();
targetGoods.setId(skup);
targetGoods.setStatus(targetSellerOrderStatus.getSkupStatus().getCode());
targetGoods.setExceptStatus(skupStatus);
//利用数据库做并发控制
int result = sellerOrderGoodsMapper.updateStatusBySkpu(targetGoods);
if (result == 0) {
logger.warn("in {}, update status fail, skup {}, skupStatus {}", caseName, skup, skupStatus);
return cpn;
}
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(skup);
Integer sellerUid = sellerOrder.getUid();
final Long orderCode = sellerOrder.getOrderCode();
//update
SellerOrder tso = new SellerOrder();
tso.setOrderCode(orderCode);
tso.setExceptStatus(sellerOrder.getStatus());
tso.setStatus(targetSellerOrderStatus.getCode());
tso.setUid(sellerUid);
tso.setUpdateTime(DateUtil.getCurrentTimeSecond());
sellerOrderMapper.updateByOrderCode(tso);
//
cacheCleaner.cleanList(sellerUid, TabType.SELL.getValue());
cacheCleaner.cleanSellerDetail(psog);
double earnestMoney = sellerOrder.getEarnestMoney().doubleValue();
Integer sop = sellerOrder.getPayment() == null ? 0 : sellerOrder.getPayment();
boolean sellerIsSuper = sellerService.isSuperEntrySeller(sellerUid);
//不是超级卖家 ,上架商品用钱包支付保证金
MerchantOrderAttachInfo moai = null;
if(!sellerIsSuper && PaymentHelper.isWallet(sop)){
moai = MerchantOrderAttachInfo.builder().uid(sellerUid)
.orderCode(orderCode).skup(skup).earnestMoney(sellerOrder.getEarnestMoney())
.type(SellerWalletDetail.Type.SYSTEM_OFF.getValue()).build();
}
BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
.sellerUid(sellerUid).orderCode(orderCode)
.payType(sellerOrder.getPayment())
.refundCase(RefundCase.SELLER_EARNEST_MONEY)
.skup(skup);
PaymentRequest refundReq = PaymentRequest.builder().uid(sellerUid)
.orderCode(orderCode)
.refundCase(RefundCase.SELLER_EARNEST_MONEY)
.payment(sop)
.refundAmount(earnestMoney)
.isSuper(sellerIsSuper)
.refundattch(moai)
.build();
boolean refundEarnMoneyFlag = new RefundEarnestMoneyHandler()
.loadRefundAction(payRefundService::refund)
.loadBillLogEventBuilder(bleb)
.loadPaymentRequest(refundReq)
.loadSeller(sellerUid, sellerIsSuper, orderCode, targetSellerOrderStatus)
.loadLogger(logger)
.refund();
cpn = new CancelPreparedNode();
cpn.psog = psog;
return cpn;
}
/**
* 审核不通过
* @param auditCancelCase
*/
public void cancel(AuditCancelCase auditCancelCase){
AuditFailedEvent afe = (AuditFailedEvent)auditCancelCase.getEvent();
final int skup = afe.getSkup();
logger.info("in cancel offShelveCancelCase {}", afe);
SkupStatus expectSkupStatus = SkupStatus.CAN_SELL;
final SellerOrderStatus targetSellerOrderStatus = SellerOrderStatus.AUDIT_FAIL;
CancelStatusNode csn = new CancelStatusNode();
csn.skup = skup;
csn.expectSkupStatus = expectSkupStatus;
csn.targetSellerOrderStatus = targetSellerOrderStatus;
CancelPreparedNode cpn = doCancelByErp(csn, auditCancelCase);
SellerOrderGoods psog = cpn.psog;
Integer sellerUid = psog.getUid();
inBoxFacade.noticeSellerWhenSecondHandProductApplyAuditReject(sellerUid, psog, afe.getRejectReason());
}
}
... ...
... ... @@ -30,4 +30,9 @@ public abstract class AbsSellerOrderCancelCase<T extends SellerOrderCancelServic
sb.append('}');
return sb.toString();
}
@Override
public String caseName() {
return getClass().getSimpleName();
}
}
... ...
package com.yohoufo.order.service.impl.visitor;
import com.yohoufo.order.event.AuditFailedEvent;
import com.yohoufo.order.service.impl.SellerOrderCancelService;
/**
* Created by chao.chen on 2019/4/12.
*/
public class AuditCancelCase<T extends SellerOrderCancelService> extends AbsSellerOrderCancelCase<T> {
public AuditCancelCase(AuditFailedEvent auditFailedEvent){
super(auditFailedEvent);
}
@Override
public void accept(SellerOrderCancelService visitor) {
visitor.cancel(this);
}
}
... ...
... ... @@ -8,17 +8,17 @@ import com.yohoufo.order.service.impl.SellerOrderCancelService;
*/
public class OffShelveCancelCase<T extends SellerOrderCancelService> extends AbsSellerOrderCancelCase<T> {
public OffShelveCancelCase(ErpCancelSellerOrderEvent orderCancelEvent) {
super(orderCancelEvent);
}
@Override
public void accept(T visitor) {
visitor.cancel(this);
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("OffShelveCancelCase{");
... ...
... ... @@ -6,4 +6,6 @@ package com.yohoufo.order.service.impl.visitor;
public interface OrderCancelCase<T> {
void accept(T visitor);
String caseName();
}
... ...