Authored by LUOXC

refactor 发送消息

... ... @@ -20,6 +20,7 @@ import com.yohoufo.order.event.BillLogEvent;
import com.yohoufo.order.event.BuyerRefundCouponEvent;
import com.yohoufo.order.model.request.PaymentRequest;
import com.yohoufo.order.model.request.TransferMoneyRequest;
import com.yohoufo.order.service.impl.function.BuyerNoticeSender;
import com.yohoufo.order.service.impl.function.SellerNoticeSender;
import com.yohoufo.order.service.proxy.OrderStatusFlowService;
import lombok.Data;
... ... @@ -61,6 +62,8 @@ class BuyerOrderCancelHandler {
private NoticeSeller noticeSeller;
private NoticeBuyer noticeBuyer;
private BuyerRefundCouponEvent.BizCase refundCouponCase;
private AlarmConfig failAlarm;
... ... @@ -96,8 +99,12 @@ class BuyerOrderCancelHandler {
return new RefundGoodsMoney(goodsMoneyRefundConsumer);
}
public NoticeSeller withNoticeSeller(SellerNoticeSender sellerNoticeSender, int sellerNoticeSenderTimes) {
return new NoticeSeller(sellerNoticeSender, sellerNoticeSenderTimes);
public NoticeSeller withNoticeSeller(SellerNoticeSender sellerNoticeSender) {
return new NoticeSeller(sellerNoticeSender);
}
public NoticeBuyer withNoticeBuyer(BuyerNoticeSender buyerNoticeSender) {
return new NoticeBuyer(buyerNoticeSender);
}
public BuyerOrderCancelHandler withRefundCoupon(BuyerRefundCouponEvent.BizCase refundCouponCase) {
... ... @@ -131,6 +138,7 @@ class BuyerOrderCancelHandler {
transfer();
refundPayGoodsMoney(buyerOrder);
noticeSeller();
noticeBuyer(buyerOrder);
} else {
log.info("cancel order {} fail, order status has changed", orderCode);
throwServiceException("当前状态不可取消订单");
... ... @@ -213,7 +221,7 @@ class BuyerOrderCancelHandler {
refundGoodsMoney.refundConsumer().accept(paymentRequest, billLogEventBuilder);
log.info("refund pay goods money by order {} success", orderCode);
} catch (Exception e) {
log.info("refund pay goods money by order {} fail request is {}", orderCode, paymentRequest, e);
log.warn("refund pay goods money by order {} fail request is {}", orderCode, paymentRequest, e);
BillLogEvent billLogEvent = billLogEventBuilder.tradeStatus(BillTradeStatus.FAIL.getCode()).build();
EventBusPublisher.publishEvent(billLogEvent);
... ... @@ -232,16 +240,30 @@ class BuyerOrderCancelHandler {
if (Objects.nonNull(noticeSeller)) {
try {
log.info("notice seller buyer order has closed by order {}", orderCode);
int times = noticeSeller.times();
SellerOrderGoods sog = noticeSeller.sellerOrderGoods();
if (Objects.isNull(sog)) {
val skup = skupSupplier().get();
val sellerOrderGoodsMapper = noticeSeller.sellerOrderGoodsMapper();
sog = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
}
noticeSeller.sellerNoticeSender().notice(sog, orderCode, times);
noticeSeller.sellerNoticeSender().notice(sog, orderCode);
} catch (Exception e) {
log.warn("notice seller buyer order has closed by order {} fail", orderCode, e);
}
}
}
private void noticeBuyer(BuyerOrder buyerOrder) {
if (Objects.nonNull(noticeBuyer)) {
log.info("notice buyer order has closed by order {}", orderCode);
try {
BuyerNoticeSender.Request request = BuyerNoticeSender.Request.builder()
.uid(buyerOrder.getUid())
.orderCode(buyerOrder.getOrderCode())
.build();
noticeBuyer.buyerNoticeSender().notice(request);
} catch (Exception e) {
log.info("notice seller buyer order has closed by order {} fail", orderCode, e);
log.warn("notice buyer order has closed by order {} fail", orderCode, e);
}
}
}
... ... @@ -277,7 +299,6 @@ class BuyerOrderCancelHandler {
class NoticeSeller {
private final SellerNoticeSender sellerNoticeSender;
private final int times;
private SellerOrderGoods sellerOrderGoods;
... ... @@ -289,5 +310,17 @@ class BuyerOrderCancelHandler {
}
}
@Data
@Accessors(fluent = true)
class NoticeBuyer {
private final BuyerNoticeSender buyerNoticeSender;
BuyerOrderCancelHandler and() {
BuyerOrderCancelHandler.this.noticeBuyer = this;
return BuyerOrderCancelHandler.this;
}
}
}
... ...
package com.yohoufo.order.service.impl;
import com.yohobuy.ufo.model.order.bo.MerchantOrderAttachInfo;
import com.yohobuy.ufo.model.order.common.*;
import com.yohobuy.ufo.model.order.common.OrderStatus;
import com.yohobuy.ufo.model.order.common.SellerOrderStatus;
import com.yohobuy.ufo.model.order.common.SkupStatus;
import com.yohobuy.ufo.model.order.common.TabType;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.alarm.SmsAlarmEvent;
import com.yohoufo.common.utils.DateUtil;
... ... @@ -149,7 +152,7 @@ public class BuyerOrderCancelService {
}
}
public void cancelForSellerSendOutTimeout(int uid, long orderCode,int skup, SellerOrderGoods sellerOrderGoods){
public void cancelForSellerSendOutTimeout(int uid, long orderCode, int skup, SellerOrderGoods sellerOrderGoods) {
new BuyerOrderCancelHandler(uid, orderCode)
.withBuyerOrderSupplier(buyerOrderMapper, buyerOrderGoodsMapper)
// 已付款 -> 超时未发货取消
... ... @@ -160,13 +163,15 @@ public class BuyerOrderCancelService {
.withRefundGoodsMoney(payRefundService::refund).refundCase(RefundCase.BUYER_GOODS_MONEY).skup(skup).and()
.withFailAlarm(AlarmConfig.DELIVER_TIME_OUT)
// 通知卖家商品发货超时
.withNoticeSeller(inBoxFacade::sellerDeliverNotice, 3).sellerOrderGoods(sellerOrderGoods).and()
.withNoticeSeller((soa, code) -> inBoxFacade.sellerDeliverNotice(soa, code, 3)).sellerOrderGoods(sellerOrderGoods).and()
// 通知买家卖家商品发货超时
.withNoticeBuyer(inBoxFacade::noticeBuyerOfSellerSendOutTimeout).and()
// 退优惠券
.withRefundCoupon(BuyerRefundCouponEvent.BizCase.SELLER_DELIVER_TIMEOUT)
.cancel();
}
public void cancelForSellerShamSendOut(int uid, long orderCode){
public void cancelForSellerShamSendOut(int uid, long orderCode) {
new BuyerOrderCancelHandler(uid, orderCode)
.withBuyerOrderSupplier(buyerOrderMapper, buyerOrderGoodsMapper)
// 卖家发货 -> 鉴定中心收货前客服取消
... ... @@ -176,7 +181,9 @@ public class BuyerOrderCancelService {
// 退买家货款
.withRefundGoodsMoney(payRefundService::refund).refundCase(RefundCase.BUYER_GOODS_MONEY).and()
// 通知卖家涉及虚假发货
.withNoticeSeller(inBoxFacade::sellerDeliverNotice, 4).sellerOrderGoodsMapper(sellerOrderGoodsMapper).and()
.withNoticeSeller(inBoxFacade::noticeSellerOfSellerShamSendOut).sellerOrderGoodsMapper(sellerOrderGoodsMapper).and()
// 通知买家卖家涉及虚假发货
.withNoticeBuyer(inBoxFacade::noticeBuyerOfSellerShamSendOut).and()
// 退优惠券
.withRefundCoupon(BuyerRefundCouponEvent.BizCase.SELLER_SHAM_SEND_OUT)
.withFailAlarm(AlarmConfig.SELLER_SHAM_SEND_OUT)
... ...
package com.yohoufo.order.service.impl.function;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Builder;
public interface BuyerNoticeSender {
void notice(Request request);
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
class Request {
private Integer uid;
private Long orderCode;
}
}
... ...
... ... @@ -4,6 +4,6 @@ import com.yohoufo.dal.order.model.SellerOrderGoods;
public interface SellerNoticeSender {
void notice(SellerOrderGoods sog, long orderCode, int times);
void notice(SellerOrderGoods sog, long orderCode);
}
... ...
... ... @@ -6,6 +6,7 @@ import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.inboxclient.model.InBoxResponse;
import com.yohoufo.inboxclient.model.InboxReqVO;
import com.yohoufo.inboxclient.sdk.InBoxSDK;
import com.yohoufo.order.service.impl.function.BuyerNoticeSender;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -654,6 +655,87 @@ public class InBoxFacade {
}
}
public void noticeSellerOfSellerShamSendOut(SellerOrderGoods sog,long orderCode){
Integer sellerUid = sog.getUid();
String prdName = sog.getProductName();
String sizeName = sog.getSizeName();
try {
executorService.execute(() -> {
// 发站内信
logger.info("record seller sham send out inbox sms msg for seller,sellerUid {}, prdName {}", sellerUid, prdName);
String params = buildParams(prdName, sizeName);
InboxReqVO req = buildInboxReqVO(sellerUid, params, InboxBusinessTypeEnum.NOTICE_SELLER_SELLER_SHAM_SEND_OUT);
InBoxResponse resp = inBoxSDK.addInbox(req);
logger.info("record seller sham send out inbox msg,sellerUid {}, prdName {},sizeName {} resp {}",
sellerUid, prdName, sizeName, resp);
// 发短信
String phone = userProxyService.getMobile(sellerUid);
if (StringUtils.isBlank(phone)){
logger.warn("seller sham send out sms send fail,sellerUid {}, prdName {}", sellerUid, prdName);
return;
}
List<String> mobileList = Arrays.asList(phone);
String content = getReplacedContent(InboxBusinessTypeEnum.SMS_NOTICE_SELLER_SELLER_SHAM_SEND_OUT.getContent(),prdName,orderCode);
sendSmsService.smsSendByMobile(content, mobileList);
logger.info("seller sham send out msg,sellerUid {}, prdName {}", sellerUid, prdName);
});
} catch (Exception e) {
logger.warn("InBoxFacade noticeSellerOfSellerShamSendOut error inbox msg, sellerUid {}, prdName {} ", sellerUid, prdName, e);
}
}
public void noticeBuyerOfSellerShamSendOut(BuyerNoticeSender.Request request) {
Integer uid = request.getUid();
Long orderCode = request.getOrderCode();
String params = buildParams(orderCode);
InboxReqVO inboxMessage = buildInboxReqVO(uid, params, InboxBusinessTypeEnum.NOTICE_BUYER_SELLER_SHAM_SEND_OUT);
String smsContent = getReplacedContent(InboxBusinessTypeEnum.SMS_NOTICE_BUYER_SELLER_SHAM_SEND_OUT.getContent(), orderCode);
try {
logger.info("noticeBuyerOfSellerShamSendOut,uid {} request is {}", uid, request);
executorService.execute(() -> {
InBoxResponse inBoxResponse = inBoxSDK.addInbox(inboxMessage);
logger.info("noticeBuyerOfSellerShamSendOut inbox send success, message is {} res is {}", inboxMessage, inBoxResponse);
String phone = userProxyService.getMobile(uid);
if (StringUtils.isBlank(phone)) {
logger.warn("noticeBuyerOfSellerShamSendOut sms send fail,uid {} can not find phone", uid);
return;
}
sendSmsService.smsSendByMobile(smsContent, Arrays.asList(phone));
logger.info("noticeBuyerOfSellerShamSendOut sms send success,uid {}", uid);
});
} catch (Exception e) {
logger.warn("noticeBuyerOfSellerShamSendOut fail,uid {}", uid, e);
}
}
public void noticeBuyerOfSellerSendOutTimeout(BuyerNoticeSender.Request request){
Integer uid = request.getUid();
Long orderCode = request.getOrderCode();
String params = buildParams(orderCode);
InboxReqVO inboxMessage = buildInboxReqVO(uid, params, InboxBusinessTypeEnum.NOTICE_BUYER_SELLER_SEND_OUT_TIMEOUT);
String smsContent = getReplacedContent(InboxBusinessTypeEnum.SMS_NOTICE_BUYER_SELLER_SEND_OUT_TIMEOUT.getContent(), orderCode);
try {
logger.info("noticeBuyerOfSellerSendOutTimeout,uid {} request is {}", uid, request);
executorService.execute(() -> {
InBoxResponse inBoxResponse = inBoxSDK.addInbox(inboxMessage);
logger.info("noticeBuyerOfSellerSendOutTimeout inbox send success, message is {} res is {}", inboxMessage, inBoxResponse);
String phone = userProxyService.getMobile(uid);
if (StringUtils.isBlank(phone)) {
logger.warn("noticeBuyerOfSellerSendOutTimeout sms send fail,uid {} can not find phone", uid);
return;
}
sendSmsService.smsSendByMobile(smsContent, Arrays.asList(phone));
logger.info("noticeBuyerOfSellerSendOutTimeout sms send success,uid {}", uid);
});
} catch (Exception e) {
logger.warn("noticeBuyerOfSellerSendOutTimeout fail,uid {}", uid, e);
}
}
public void sellerDeliverNotice(SellerOrderGoods sog,long orderCode, int times) {
Integer sellerUid = sog.getUid();
String prdName = sog.getProductName();
... ... @@ -666,10 +748,7 @@ public class InBoxFacade {
} else if (times == 3) {
ibt = InboxBusinessTypeEnum.NOTICE_SELLER_DELIVER_GOODS_FAIL;
smsInboxBusinessTypeEnum = InboxBusinessTypeEnum.SMS_NOTIFIED_SEND_FAILED;
} else if (times == 4) {
ibt = InboxBusinessTypeEnum.NOTICE_SELLER_SELLER_SHAM_SEND_OUT;
smsInboxBusinessTypeEnum = InboxBusinessTypeEnum.SMS_NOTICE_SELLER_SELLER_SHAM_SEND_OUT;
}else {
} else {
return;
}
try {
... ...