Authored by qinchao

记录订单状态流程

... ... @@ -7,6 +7,7 @@ import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.alarm.SmsAlarmEvent;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.BuyerOrderMapper;
import com.yohoufo.dal.order.BuyerOrderStatusFlowMapper;
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.model.BuyerOrder;
import com.yohoufo.dal.order.model.SellerOrderGoods;
... ... @@ -24,6 +25,7 @@ import com.yohoufo.order.mq.TopicConstants;
import com.yohoufo.order.service.impl.PayRefundService;
import com.yohoufo.order.service.impl.TransferService;
import com.yohoufo.order.service.proxy.InBoxFacade;
import com.yohoufo.order.service.proxy.OrderStatusFlowService;
import com.yohoufo.order.utils.LoggerUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -55,6 +57,9 @@ public class SellerOrderCancelDeliverDelayMsgConsumer implements YhConsumer {
@Autowired
private SellerOrderGoodsMapper sellerOrderGoodsMapper;
@Autowired
private OrderStatusFlowService orderStatusFlowService;
public String getMessageTopic() {
return TopicConstants.SELLER_ORDER_AUTO_CANCEL_DELIVER;
}
... ... @@ -121,6 +126,10 @@ public class SellerOrderCancelDeliverDelayMsgConsumer implements YhConsumer {
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent(alarmConfig.getRefundName(), alarmConfig.name(), content);
EventBusPublisher.publishEvent(smsAlarmEvent);
}
//记录状态信息
logger.info("in SellerOrderCancelDeliverDelayMsgConsumer handle record status change, orderCode {},uid {} ,sellerUid {}", orderCode,buyerUid,sellerUid);
orderStatusFlowService.addAsy(orderCode,targetStatus.getCode());
}
}
... ...
... ... @@ -29,6 +29,7 @@ import com.yohoufo.order.service.cache.CacheCleaner;
import com.yohoufo.order.service.cache.CacheKeyBuilder;
import com.yohoufo.order.service.impl.SellerAddressService;
import com.yohoufo.order.service.proxy.InBoxFacade;
import com.yohoufo.order.service.proxy.OrderStatusFlowService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -65,6 +66,9 @@ public class BuyerOrderPaymentService extends AbstractOrderPaymentService {
@Autowired
private CacheCleaner cacheCleaner;
@Autowired
private OrderStatusFlowService orderStatusFlowService;
/**
* 更新订单状态
* @param orderInfo
... ... @@ -78,6 +82,11 @@ public class BuyerOrderPaymentService extends AbstractOrderPaymentService {
buyerOrder.setUpdateTime(DateUtil.getCurrentTimeSecond());
int result = buyerOrderMapper.updateByOrderCode(buyerOrder);
//
if(result>0){
//记录状态信息
logger.info("in updateOrderStatusPaid record status change, orderCode {}", orderInfo.getOrderCode());
orderStatusFlowService.addAsy(orderInfo.getOrderCode(), OrderStatus.HAS_PAYED.getCode());
}
orderInfo.setStatus(OrderStatus.HAS_PAYED.getCode());
return result;
}
... ...
... ... @@ -28,6 +28,7 @@ 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.proxy.InBoxFacade;
import com.yohoufo.order.service.proxy.OrderStatusFlowService;
import com.yohoufo.order.utils.PaymentHelper;
import com.yohoufo.order.utils.PubThreadFactory;
import org.apache.commons.lang3.StringUtils;
... ... @@ -57,6 +58,9 @@ public class AppraiseService {
private IExpressInfoService expressInfoService;
@Autowired
private OrderStatusFlowService orderStatusFlowService;
@Autowired
private BuyerOrderMapper buyerOrderMapper;
@Autowired
... ... @@ -189,6 +193,11 @@ public class AppraiseService {
//记录物流信息
//不发物流
//expressInfoService.appraiseSuccess(buyerUid, expressCompanyId, orderCode, wayBillCode, depotNum,mobile);
//记录订单的状态变更信息
LOGGER.info("in appraiseSuccess record status change, orderCode {},uid {} ,sellerUid {}", orderCode,buyerUid,sellerUid);
orderStatusFlowService.addAsy(buyerOrder.getOrderCode(),targetOrderStatus.getCode());
//平台已发货给买家
inBoxFacade.appraisePassNotice(buyerUid, orderCode, sellerOrderGoods);
}catch (Exception ex){
... ... @@ -327,6 +336,11 @@ public class AppraiseService {
//平台已发货给买家 TODO
//inBoxFacade.appraisePassNotice(buyerUid, orderCode, sellerOrderGoods);
//记录订单的状态变更信息
LOGGER.info("in deliverGoods record status change, orderCode {},uid {} ,sellerUid {}", orderCode,buyerUid,sellerUid);
orderStatusFlowService.addAsy(buyerOrder.getOrderCode(),targetStatus.getCode());
//清理
cacheCleaner.delete(Arrays.asList(CacheKeyBuilder.orderListKey(sellerUid, TabType.SELL.getValue()),
CacheKeyBuilder.orderListKey(buyerUid, TabType.BUY.getValue()),
... ... @@ -502,6 +516,9 @@ public class AppraiseService {
try{
payRefundService.refund(req, bleb);
//
//记录订单的状态变更信息
LOGGER.info("in appraiseFail record status change, orderCode {},uid {} ,sellerUid {}", orderCode,buyerUid,sellerUid);
orderStatusFlowService.addAsy(buyerOrder.getOrderCode(),targetStatus.getCode());
//TODO 消息
inBoxFacade.noticeSellerWhenAppraiseFail( sellerOrderGoods,orderCode,wayBillCode);
... ...
... ... @@ -44,6 +44,7 @@ import com.yohoufo.order.service.cache.CacheKeyBuilder;
import com.yohoufo.order.service.cache.OrderCacheService;
import com.yohoufo.order.service.pay.AbstractPayService;
import com.yohoufo.order.service.proxy.InBoxFacade;
import com.yohoufo.order.service.proxy.OrderStatusFlowService;
import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.utils.LoggerUtils;
import org.apache.commons.collections.CollectionUtils;
... ... @@ -102,6 +103,9 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
@Autowired
private IExpressInfoService expressInfoService;
@Autowired
private OrderStatusFlowService orderStatusFlowService;
/**
* 提交订单
* @param orderRequest
... ... @@ -122,6 +126,10 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
BuyerOrderGoods bog = buyerOrderGoodsMapper.selectByOrderCode(uid, orderCode);
SellerOrderGoods sog = sellerOrderGoodsMapper.selectByPrimaryKey(bog.getSkup());
//记录状态信息
logger.info("in seller confirm record status change, orderCode {},uid {} ,sellerUid {}", orderCode,uid,sellerUid);
orderStatusFlowService.addAsy(orderCode,OrderStatus.DONE.getCode());
cacheCleaner.delete(Arrays.asList(CacheKeyBuilder.orderListKey(sellerUid, TabType.SELL.getValue()),
CacheKeyBuilder.orderListKey(uid, TabType.BUY.getValue()),
CacheKeyBuilder.sellerOrderDetailKey(sog),
... ... @@ -314,6 +322,10 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
OrderStatus targetStatus = OrderStatus.BUYER_CANCEL_TIMEOUT;
DataNode node = checkBase(orderRequest);
cancelBeforePaid(orderRequest, node, expectStatus, targetStatus);
//记录状态变更信息
logger.info("in cancelByAuto record status change, orderRequest {}", orderRequest);
orderStatusFlowService.addAsy(orderRequest.getOrderCode(),targetStatus.getCode());
}
private void doCancel(OrderRequest orderRequest){
... ... @@ -335,6 +347,9 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
targetStatus = OrderStatus.BUYER_CANCEL_BEFORE_PAY;
cancelBeforePaid(orderRequest, node, expectStatus, targetStatus);
buyerOrderCancelService.refundCouponIfNeed(buyerOrder.getUid(), buyerOrder.getOrderCode());
//记录状态变更信息
logger.info("in doCancel record status WAITING_PAY change, orderRequest {}", orderRequest);
orderStatusFlowService.addAsy(buyerOrder.getOrderCode(),targetStatus.getCode());
break;
case HAS_PAYED:
BuyerOrderGoods bog = buyerOrderGoodsMapper.selectByOrderCode(orderRequest.getUid(),
... ... @@ -347,6 +362,9 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
.amount(buyerOrder.getAmount())
.build();
buyerOrderCancelService.cancel(bsde);
//记录状态变更信息
logger.info("in doCancel record status HAS_PAYED change, orderRequest {}", orderRequest);
orderStatusFlowService.addAsy(buyerOrder.getOrderCode(),targetStatus.getCode());
break;
case SELLER_SEND_OUT:
bog = buyerOrderGoodsMapper.selectByOrderCode(orderRequest.getUid(),
... ... @@ -359,6 +377,9 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
.amount(buyerOrder.getAmount())
.build();
buyerOrderCancelService.cancel(bdre);
//记录状态变更信息
logger.info("in doCancel record status HAS_PAYED change, orderRequest {}", orderRequest);
orderStatusFlowService.addAsy(buyerOrder.getOrderCode(),targetStatus.getCode());
break;
}
... ... @@ -638,9 +659,17 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
int uid = buyerOrder.getUid();
int sellerUid = buyerOrder.getSellerUid();
logger.info("in confirmReceive begin update status orderCode {},uid {} ,sellerUid {}", orderCode,uid,sellerUid);
buyerOrderMapper.updateStatusByOrderCode(orderCode, uid, expectStatus.getCode(),
int num = buyerOrderMapper.updateStatusByOrderCode(orderCode, uid, expectStatus.getCode(),
targetStatus.getCode(), DateUtil.getCurrentTimeSecond());
//记录订单的状态变更信息
if(num>=1){
logger.info("in confirmReceive record status change, orderCode {},uid {} ,sellerUid {}", orderCode,uid,sellerUid);
orderStatusFlowService.addAsy(buyerOrder.getOrderCode(),targetStatus.getCode());
}else{
logger.warn("in confirmReceive not record status change cause of update empty num , orderCode {},uid {} ,sellerUid {}", orderCode,uid,sellerUid);
}
//记录调拨信息(只保存卖家一条)
EnumExpressType expressType = EnumExpressType.EXPRESS_TYPE_JUDGE_CENTER;
EnumExpressDataType expressDataType = EnumExpressDataType.operate_transfer;
... ... @@ -678,9 +707,17 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
int uid = buyerOrder.getUid();
int sellerUid = buyerOrder.getSellerUid();
logger.info("in judgeBegin begin update status orderCode {},uid {} ,sellerUid {}", orderCode,uid,sellerUid);
buyerOrderMapper.updateStatusByOrderCode(orderCode, uid, expectStatus.getCode(),
int num=buyerOrderMapper.updateStatusByOrderCode(orderCode, uid, expectStatus.getCode(),
targetStatus.getCode(), DateUtil.getCurrentTimeSecond());
//记录订单的状态变更信息
if(num>=1){
logger.info("in judgeBegin record status change, orderCode {},uid {} ,sellerUid {}", orderCode,uid,sellerUid);
orderStatusFlowService.addAsy(buyerOrder.getOrderCode(),targetStatus.getCode());
}else{
logger.warn("in judgeBegin not record status change cause of update empty num , orderCode {},uid {} ,sellerUid {}", orderCode,uid,sellerUid);
}
//记录调拨信息(只保存卖家一条)
EnumExpressType expressType = EnumExpressType.EXPRESS_TYPE_JUDGE_CENTER;
EnumExpressDataType expressDataType = EnumExpressDataType.operate_transfer;
... ...
... ... @@ -26,6 +26,7 @@ import com.yohoufo.order.service.IExpressInfoService;
import com.yohoufo.order.service.cache.CacheCleaner;
import com.yohoufo.order.service.cache.CacheKeyBuilder;
import com.yohoufo.order.service.proxy.InBoxFacade;
import com.yohoufo.order.service.proxy.OrderStatusFlowService;
import com.yohoufo.order.service.proxy.ProductProxyService;
import lombok.AllArgsConstructor;
import lombok.Data;
... ... @@ -89,6 +90,9 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
@Autowired
private CacheCleaner cacheCleaner;
@Autowired
private OrderStatusFlowService orderStatusFlowService;
//private static String EXPRESS_MQ_SEND = "logistics.logistics_data";
//private static String EXPRESS_MQ_SEND = "order.updateChangeRefundOrderExpressInfo";
private static String EXPRESS_MQ_SEND = "third.logistics.logistics_data";
... ... @@ -160,6 +164,11 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
sendExpressMQ(sellerUid,expressCompanyId,orderCode,wayBillCode,mobile);
psog = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
LOGGER.info("deliverToDepot end ! send express to erp ");
//记录订单的状态变更信息
LOGGER.info("in deliverToDepot record status change, orderCode {},uid {} ,sellerUid {}", orderCode,buyerUid,sellerUid);
orderStatusFlowService.addAsy(buyerOrder.getOrderCode(),targetOrderStatus.getCode());
inBoxFacade.sellerDeliver2Depot(buyerUid, orderCode, psog.getProductName());
//
cacheCleaner.delete(Arrays.asList(CacheKeyBuilder.orderListKey(sellerUid, TabType.SELL.getValue()),
... ...
... ... @@ -32,6 +32,7 @@ import com.yohoufo.order.service.impl.visitor.OffShelveCancelCase;
import com.yohoufo.order.service.impl.visitor.UserCancelCase;
import com.yohoufo.order.service.pay.AbstractPayService;
import com.yohoufo.order.service.proxy.InBoxFacade;
import com.yohoufo.order.service.proxy.OrderStatusFlowService;
import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
... ... @@ -94,6 +95,9 @@ public class SellerOrderCancelService {
@Autowired
IPaymentService paymentService;
@Autowired
private OrderStatusFlowService orderStatusFlowService;
/**
* TODO 如何控制好并发,必须控制不能重复转账 退款
* 使用乐观锁,带着查询到的状态且符合条件时再去更新
... ... @@ -488,6 +492,10 @@ public class SellerOrderCancelService {
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent(alarmConfig.getRefundName(), alarmConfig.name(), content);
EventBusPublisher.publishEvent(smsAlarmEvent);
}
//记录状态信息
logger.info("in cancelAfterPayExistBuyAction record status change, orderCode {}", buyerOrderCode);
orderStatusFlowService.addAsy(buyerOrderCode,targetBOStatus.getCode());
}
return result;
... ...
... ... @@ -19,6 +19,7 @@ import com.yohoufo.order.model.dto.BuyerOrderSubmitResult;
import com.yohoufo.order.model.dto.OrderBuilder;
import com.yohoufo.order.service.ISubmitOrderService;
import com.yohoufo.order.service.proxy.CouponProxyService;
import com.yohoufo.order.service.proxy.OrderStatusFlowService;
import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.utils.LoggerUtils;
import org.slf4j.Logger;
... ... @@ -117,6 +118,9 @@ public class SubmitOrderServiceImpl implements ISubmitOrderService {
@Autowired
private ProductProxyService productProxyService;
@Autowired
private OrderStatusFlowService orderStatusFlowService;
/**
* 创建订单
* @param orderBuilder
... ... @@ -152,6 +156,10 @@ public class SubmitOrderServiceImpl implements ISubmitOrderService {
//6.插入优惠券 order_coupon
insertOrderCouponIfNeed(orderBuilder);
//7.记录状态变更信息
logger.info("in createOrder record status change, orderBuilder {}", orderBuilder);
orderStatusFlowService.addAsy(orderBuilder.getOrderCode(),OrderStatus.WAITING_PAY.getCode());
BuyerOrderSubmitResult result = BuyerOrderSubmitResult.builder()
.orderCode(orderBuilder.getOrderCode())
.sellerOrder(sellerOrder).sellerOrderGoods(sellerOrderGoods).build();
... ...