Authored by sailing-PC\sailing

add delay

package com.yohoufo.order.event;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Builder;
/**
* Created by chenchao on 2018/10/15.
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class DeliverNoticeEvent extends Event {
private int uid;
private String prdName;
}
... ...
... ... @@ -16,5 +16,11 @@ public class SellerCancelDeliverEvent extends Event {
private int uid;
private int sellerUid;
private int skup;
private String productName;
private long orderCode;
}
... ...
... ... @@ -29,4 +29,7 @@ public interface TopicConstants {
*/
String ORDER_NOT_PAID_NOTICE = "order.notPaidNotice";
String ORDER_NOT_DELIVER_NOTICE = "order.notDeliver";
}
... ...
package com.yohoufo.order.mq.consumer;
import com.alibaba.fastjson.JSONObject;
import com.yoho.core.rabbitmq.YhConsumer;
import com.yohoufo.order.event.DeliverNoticeEvent;
import com.yohoufo.order.mq.TopicConstants;
import com.yohoufo.order.service.proxy.InBoxFacade;
import com.yohoufo.order.utils.LoggerUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Objects;
/**
* Created by chenchao on 2018/10/15.
*/
@Component
public class NotDeliverNoticeDelayMsgConsumer implements YhConsumer {
private static final Logger LOGGER = LoggerUtils.getMqConsumerLogger();
@Autowired
private InBoxFacade inBoxFacade;
@Override
public void handleMessage(Object o) throws Exception {
LOGGER.info("in topic {}, msg {}", TopicConstants.ORDER_NOT_DELIVER_NOTICE, o);
if (Objects.isNull(o)){
return;
}
DeliverNoticeEvent msg = JSONObject.parseObject(o.toString(), DeliverNoticeEvent.class);
inBoxFacade.sellerDeliverNotice(msg.getUid(), msg.getPrdName(), 2);
}
}
... ...
package com.yohoufo.order.mq.consumer;
import com.alibaba.fastjson.JSONObject;
import com.yoho.core.rabbitmq.YhConsumer;
import com.yohoufo.order.common.TabType;
import com.yohoufo.order.event.NotPaidNoticeEvent;
... ... @@ -32,7 +33,7 @@ public class NotPaidNoticeDelayMsgConsumer implements YhConsumer {
return;
}
NotPaidNoticeEvent event = (NotPaidNoticeEvent)o;
NotPaidNoticeEvent event = JSONObject.parseObject(o.toString(), NotPaidNoticeEvent.class);
TabType actorType;
if (Objects.nonNull(actorType=event.getActorType())){
switch (actorType){
... ...
... ... @@ -2,13 +2,28 @@ package com.yohoufo.order.mq.consumer;
import com.alibaba.fastjson.JSONObject;
import com.yoho.core.rabbitmq.YhConsumer;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.BuyerOrderMapper;
import com.yohoufo.dal.order.model.BuyerOrder;
import com.yohoufo.order.common.OrderStatus;
import com.yohoufo.order.common.RefundCase;
import com.yohoufo.order.common.TransferCase;
import com.yohoufo.order.event.BillLogEvent;
import com.yohoufo.order.event.EventBusPublisher;
import com.yohoufo.order.event.SellerCancelDeliverEvent;
import com.yohoufo.order.model.request.PaymentRequest;
import com.yohoufo.order.model.request.TransferMoneyRequest;
import com.yohoufo.order.mq.TopicConstants;
import com.yohoufo.order.service.IPaymentService;
import com.yohoufo.order.service.proxy.InBoxFacade;
import com.yohoufo.order.utils.LoggerUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
/**
* Created by chenchao on 2018/9/30.
*/
... ... @@ -18,6 +33,14 @@ public class SellerOrderCancelDeliverDelayMsgConsumer implements YhConsumer {
final Logger logger = LoggerUtils.getMqConsumerLogger();
@Autowired
private BuyerOrderMapper buyerOrderMapper;
@Autowired
private InBoxFacade inBoxFacade;
@Autowired
private IPaymentService paymentService;
public String getMessageTopic() {
... ... @@ -34,7 +57,50 @@ public class SellerOrderCancelDeliverDelayMsgConsumer implements YhConsumer {
SellerCancelDeliverEvent event = JSONObject.parseObject(o.toString(), SellerCancelDeliverEvent.class);
Integer buyerUid = event.getUid();
Long orderCode = event.getOrderCode();
//TODO 更新买家订单状态:发火超市;成功后 对保证金进行分账;
//更新买家订单状态:发货超时;成功后 对保证金进行分账;
BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCodeUid(orderCode, buyerUid);
int skup = event.getSkup();
int sellerUid = event.getSellerUid();
OrderStatus expectStatus = OrderStatus.HAS_PAYED;
if (expectStatus.getCode() == buyerOrder.getStatus()){
//将卖家的保证金分账给平台和买家
TransferMoneyRequest tmReq = TransferMoneyRequest.builder().buyerOrderCode(orderCode)
.type(TransferCase.SELLER_PLAY_BUYER.getCode()).build();
BigDecimal goodsMoney = buyerOrder.getAmount();
PaymentRequest req = PaymentRequest.builder().uid(buyerUid)
.orderCode(orderCode).refundAmount(goodsMoney.doubleValue())
.build();
BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
.buyerUid(buyerUid).sellerUid(sellerUid).orderCode(orderCode)
.payType(buyerOrder.getPayment()).refundCase(RefundCase.BUYER_GOODS_MONEY)
.amount(goodsMoney)
.skup(skup);
try{
paymentService.transferMon(tmReq);
paymentService.refund(req);
BillLogEvent buyererBillLogEvent = bleb.tradeStatus(100)
.build();
EventBusPublisher.publishEvent(buyererBillLogEvent);
//
inBoxFacade.sellerDeliverNotice(event.getSellerUid(), event.getProductName(), 3);
}catch (Exception ex){
logger.warn("in topic {} , refund fail,req {}", getMessageTopic(), req, ex);
BillLogEvent buyererBillLogEvent = bleb.tradeStatus(200)
.build();
EventBusPublisher.publishEvent(buyererBillLogEvent);
}finally {
OrderStatus targetStatus = OrderStatus.SEND_OUT_TIMEOUT;
buyerOrderMapper.updateStatusByOrderCode(orderCode, buyerUid, expectStatus.getCode(), targetStatus.getCode(),
DateUtil.getCurrentTimeSecond());
}
}
}
}
... ...
... ... @@ -5,14 +5,19 @@ import com.alibaba.fastjson.JSONObject;
import com.yoho.core.common.utils.DateUtil;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
import com.yohoufo.dal.order.BuyerOrderMapper;
import com.yohoufo.dal.order.BuyerOrderMetaMapper;
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.model.BuyerOrder;
import com.yohoufo.dal.order.model.BuyerOrderGoods;
import com.yohoufo.dal.order.model.BuyerOrderMeta;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.common.OrderCodeType;
import com.yohoufo.order.common.OrderStatus;
import com.yohoufo.order.constants.MetaKey;
import com.yohoufo.order.constants.OrderConstant;
import com.yohoufo.order.event.DeliverNoticeEvent;
import com.yohoufo.order.event.EventBusPublisher;
import com.yohoufo.order.event.SellerCancelDeliverEvent;
import com.yohoufo.order.model.OrderInfo;
... ... @@ -40,6 +45,11 @@ public class BuyerOrderPaymentService extends AbstractOrderPaymentService {
@Autowired
InBoxFacade inBoxFacade;
@Autowired
private BuyerOrderGoodsMapper buyerOrderGoodsMapper;
@Autowired
private SellerOrderGoodsMapper sellerOrderGoodsMapper;
/**
* 更新订单状态
... ... @@ -57,11 +67,20 @@ public class BuyerOrderPaymentService extends AbstractOrderPaymentService {
orderInfo.setStatus(OrderStatus.HAS_PAYED.getCode());
//TODO 通知卖家发货
BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMapper.selectByOrderCode(uid, orderInfo.getOrderCode());
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(buyerOrderGoods.getSkup());
inBoxFacade.sellerSkupPaidByBuyer(buyerOrder.getSellerUid(), sellerOrderGoods.getProductName());
DeliverNoticeEvent deliverNoticeEvent = DeliverNoticeEvent.builder()
.uid(orderInfo.getSellerUid()).prdName(sellerOrderGoods.getProductName()).build();
EventBusPublisher.publishEvent(deliverNoticeEvent);
//卖家48小时不发货取消
SellerCancelDeliverEvent event = SellerCancelDeliverEvent.builder()
.uid(uid)
.uid(uid).sellerUid(orderInfo.getSellerUid()).skup(sellerOrderGoods.getId())
.orderCode(orderInfo.getOrderCode()).build();
EventBusPublisher.publishEvent(event);
}
@Override
... ...
package com.yohoufo.order.service.handler;
import com.google.common.eventbus.Subscribe;
import com.yohoufo.order.event.DeliverNoticeEvent;
import com.yohoufo.order.event.IEventHandler;
import com.yohoufo.order.mq.TopicConstants;
import com.yohoufo.order.mq.producer.TradeMqSender;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* Created by chenchao on 2018/10/15.
*/
@Component
public class DeliverNoticeAsyncHandler implements IEventHandler<DeliverNoticeEvent> {
final Logger logger = LoggerFactory.getLogger(getClass());
public static final int DELAY_MINUTES_36_HOURS = 36*60;
@Autowired
private TradeMqSender tradeMqSender;
@Override
@Subscribe
public void handle(DeliverNoticeEvent event) {
logger.info("in DeliverNoticeAsyncHandler handler, msg {}", event);
tradeMqSender.send(TopicConstants.ORDER_NOT_DELIVER_NOTICE, event, DELAY_MINUTES_36_HOURS);
}
}
... ...
... ... @@ -93,7 +93,7 @@ public class AppraiseService {
BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
.buyerUid(buyerUid).sellerUid(sellerUid).orderCode(orderCode)
.buyerUid(buyerUid).sellerUid(sellerUid).orderCode(sellerOrder.getOrderCode())
.payType(sellerOrder.getPayment()).refundCase(RefundCase.SELLER_EARNEST_MONEY)
.skup(skup);
try {
... ... @@ -179,6 +179,14 @@ public class AppraiseService {
LOGGER.warn("appraiseFail getOrderInfo order not exist, orderCode {}", orderCode);
throw new ServiceException(ServiceError.ORDER_NULL);
}
OrderStatus expectStatus = OrderStatus.PLATFORM_CHECKING;
if (buyerOrder.getStatus() != expectStatus.getCode()){
LOGGER.warn("appraiseFail expectStatus {}, actual status {}, ordercode {}", expectStatus,
buyerOrder.getStatus(), orderCode);
throw new ServiceException(ServiceError.ORDER_STATUS_INVALIDATE);
}
int buyerUid = buyerOrder.getUid();
int sellerUid = buyerOrder.getSellerUid();
BuyerOrderGoods bog = buyerOrderGoodsMapper.selectByOrderCode(buyerUid, orderCode);
... ... @@ -187,11 +195,7 @@ public class AppraiseService {
//将卖家的保证金分账给平台和买家
TransferMoneyRequest tmReq = TransferMoneyRequest.builder().buyerOrderCode(orderCode)
.type(TransferCase.APPRAISE_FAIL.getCode()).build();
try{
paymentService.transferMon(tmReq);
}catch (Exception ex){
return false;
}
BigDecimal goodsMoney = buyerOrder.getAmount();
PaymentRequest req = PaymentRequest.builder().uid(buyerUid)
.orderCode(orderCode).refundAmount(goodsMoney.doubleValue())
... ... @@ -202,34 +206,41 @@ public class AppraiseService {
.amount(goodsMoney)
.skup(skup);
try{
paymentService.transferMon(tmReq);
paymentService.refund(req);
BillLogEvent buyererBillLogEvent = bleb.tradeStatus(100)
.build();
EventBusPublisher.publishEvent(buyererBillLogEvent);
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
inBoxFacade.noticeSellerWhenAppraiseFail(sellerUid, sellerOrderGoods.getProductName());
inBoxFacade.buyerGetEarnestMoneyWhenAppraiseFail(buyerUid, buyerOrder.getOrderCode());
}catch (Exception ex){
LOGGER.warn("in appraiseFail , refund fail,req {}", req, ex);
LOGGER.warn("in appraiseFail ,Transfer or refund fail,req {}", req, ex);
BillLogEvent buyererBillLogEvent = bleb.tradeStatus(200)
.build();
EventBusPublisher.publishEvent(buyererBillLogEvent);
return false;
}finally {
// 更新买家订单状态 为鉴定不通过
OrderStatus targetStatus = OrderStatus.CHECKING_FAKE;
LOGGER.info("appraiseFail update buyer order {} ", buyerOrder);
// TODO 最好把其他不用更新的值置为null,以免并发修改其他无关此场景的字段
// TODO 通过修改记录状态来控制并发操作“鉴定不通过” 修改状态带上原始状态,成功修改完状态后再调用分账接口
buyerOrderMapper.updateStatusByOrderCode(orderCode, buyerUid, expectStatus.getCode(), targetStatus.getCode(),
DateUtil.getCurrentTimeSecond());
//更新物流信息,写到最后
expressInfoService.appraiseFail(sellerUid, expressCompanyId, orderCode, wayBillCode, depotNum);
return true;
}
BillLogEvent buyererBillLogEvent = bleb.tradeStatus(100)
.build();
EventBusPublisher.publishEvent(buyererBillLogEvent);
// 更新买家订单状态 为鉴定不通过
buyerOrder.setStatus(OrderStatus.CHECKING_FAKE.getCode());
buyerOrder.setUpdateTime(DateUtil.getCurrentTimeSecond());
LOGGER.info("appraiseFail update buyer order {} ", buyerOrder);
// TODO 最好把其他不用更新的值置为null,以免并发修改其他无关此场景的字段
// TODO 通过修改记录状态来控制并发操作“鉴定不通过” 修改状态带上原始状态,成功修改完状态后再调用分账接口
buyerOrderMapper.updateByPrimaryKeySelective(buyerOrder);
//更新物流信息,写到最后
expressInfoService.appraiseFail(buyerOrder.getSellerUid(), expressCompanyId, orderCode, wayBillCode, depotNum);
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
inBoxFacade.noticeSellerWhenAppraiseFail(sellerUid, sellerOrderGoods.getProductName());
inBoxFacade.buyerGetEarnestMoneyWhenAppraiseFail(buyerUid, buyerOrder.getOrderCode());
return true;
}
}
... ...
... ... @@ -132,7 +132,7 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
//
SellerOrderGoods psog = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
inBoxFacade.sellerSkupPaidByBuyer(buyerOrder.getSellerUid(), psog.getProductName());
}
... ...
... ... @@ -9,9 +9,11 @@ import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.common.OrderCodeType;
import com.yohoufo.order.common.SkupStatus;
import com.yohoufo.order.common.TabType;
import com.yohoufo.order.constants.OrderConstant;
import com.yohoufo.order.event.BuyerCancelEvent;
import com.yohoufo.order.event.EventBusPublisher;
import com.yohoufo.order.event.NotPaidNoticeEvent;
import com.yohoufo.order.model.AddressInfo;
import com.yohoufo.order.model.dto.BuyerOrderSubmitResult;
import com.yohoufo.order.model.dto.OrderBuilder;
... ... @@ -166,6 +168,10 @@ public class ShoppingServiceImpl implements IShoppingService {
inBoxFacade.buyerOrderNotPayed(shoppingRequest.getUid(), orderCode);
if (submitResult != null){
NotPaidNoticeEvent notPaidNoticeEvent = NotPaidNoticeEvent.builder().actorType(TabType.BUY)
.uid(shoppingRequest.getUid()).orderCode(orderCode).build();
EventBusPublisher.publishEvent(notPaidNoticeEvent);
//
inBoxFacade.sellerSkupCreateOrderByBuyer(submitResult.getSellerOrder().getUid(), skup.getProductName());
}
// 返回结果
... ...
... ... @@ -214,7 +214,29 @@ public class InBoxFacade {
InboxReqVO smsIbtReq = buildInboxReqVO(sellerUid, smsparams, smsIbt);
InBoxResponse smsresp = inBoxSDK.addInbox(smsIbtReq);
logger.info("record sellerSkupPaidByBuyer inbox sms msg,sellerUid {}, prdName {}, resp {}",
sellerUid, prdName, resp);
sellerUid, prdName, smsresp);
}
public void sellerDeliverNotice(int sellerUid, String prdName, int times){
logger.info("record sellerDeliverNotice inbox sms msg,sellerUid {}, prdName {}, times {}",
sellerUid, prdName, times);
if (times == 2){
InboxBusinessTypeEnum ibt = InboxBusinessTypeEnum.SMS_NOTIFIED_SEND_SECOND;
String params = buildParams(prdName);
InboxReqVO req = buildInboxReqVO(sellerUid, params, ibt);
InBoxResponse resp = inBoxSDK.addInbox(req);
}
if (times == 3){
InboxBusinessTypeEnum ibt = InboxBusinessTypeEnum.SMS_NOTIFIED_SEND_FAILED;
String params = buildParams(prdName);
InboxReqVO req = buildInboxReqVO(sellerUid, params, ibt);
InBoxResponse resp = inBoxSDK.addInbox(req);
}
}
/**
... ... @@ -245,6 +267,13 @@ public class InBoxFacade {
InBoxResponse resp = inBoxSDK.addInbox(req);
logger.info("record noticSellerWhenBuyerCancel inbox msg, sellerUid {}, prdName {}, resp {}",
sellerUid, prdName, resp);
InboxBusinessTypeEnum smsibt = InboxBusinessTypeEnum.SMS_CLOSED_BUYER;
InboxReqVO smsReq = buildInboxReqVO(sellerUid, params, smsibt);
InBoxResponse smsResp = inBoxSDK.addInbox(smsReq);
logger.info("record noticSellerWhenBuyerCancel sms inbox msg, sellerUid {}, prdName {}, resp {}",
sellerUid,prdName , smsResp);
}
/**
... ...
... ... @@ -33,6 +33,11 @@ consumer:
delay:
interval: 10
- class: com.yohoufo.order.mq.consumer.NotDeliverNoticeDelayMsgConsumer
topic: order.notDeliver
delay:
interval: 2160
producer:
- address: ${rabbit_order}
username: ${rabbit_order_user}
... ...