Authored by LUOXC

refactor 发送消息

@@ -20,6 +20,7 @@ import com.yohoufo.order.event.BillLogEvent; @@ -20,6 +20,7 @@ import com.yohoufo.order.event.BillLogEvent;
20 import com.yohoufo.order.event.BuyerRefundCouponEvent; 20 import com.yohoufo.order.event.BuyerRefundCouponEvent;
21 import com.yohoufo.order.model.request.PaymentRequest; 21 import com.yohoufo.order.model.request.PaymentRequest;
22 import com.yohoufo.order.model.request.TransferMoneyRequest; 22 import com.yohoufo.order.model.request.TransferMoneyRequest;
  23 +import com.yohoufo.order.service.impl.function.BuyerNoticeSender;
23 import com.yohoufo.order.service.impl.function.SellerNoticeSender; 24 import com.yohoufo.order.service.impl.function.SellerNoticeSender;
24 import com.yohoufo.order.service.proxy.OrderStatusFlowService; 25 import com.yohoufo.order.service.proxy.OrderStatusFlowService;
25 import lombok.Data; 26 import lombok.Data;
@@ -61,6 +62,8 @@ class BuyerOrderCancelHandler { @@ -61,6 +62,8 @@ class BuyerOrderCancelHandler {
61 62
62 private NoticeSeller noticeSeller; 63 private NoticeSeller noticeSeller;
63 64
  65 + private NoticeBuyer noticeBuyer;
  66 +
64 private BuyerRefundCouponEvent.BizCase refundCouponCase; 67 private BuyerRefundCouponEvent.BizCase refundCouponCase;
65 68
66 private AlarmConfig failAlarm; 69 private AlarmConfig failAlarm;
@@ -96,8 +99,12 @@ class BuyerOrderCancelHandler { @@ -96,8 +99,12 @@ class BuyerOrderCancelHandler {
96 return new RefundGoodsMoney(goodsMoneyRefundConsumer); 99 return new RefundGoodsMoney(goodsMoneyRefundConsumer);
97 } 100 }
98 101
99 - public NoticeSeller withNoticeSeller(SellerNoticeSender sellerNoticeSender, int sellerNoticeSenderTimes) {  
100 - return new NoticeSeller(sellerNoticeSender, sellerNoticeSenderTimes); 102 + public NoticeSeller withNoticeSeller(SellerNoticeSender sellerNoticeSender) {
  103 + return new NoticeSeller(sellerNoticeSender);
  104 + }
  105 +
  106 + public NoticeBuyer withNoticeBuyer(BuyerNoticeSender buyerNoticeSender) {
  107 + return new NoticeBuyer(buyerNoticeSender);
101 } 108 }
102 109
103 public BuyerOrderCancelHandler withRefundCoupon(BuyerRefundCouponEvent.BizCase refundCouponCase) { 110 public BuyerOrderCancelHandler withRefundCoupon(BuyerRefundCouponEvent.BizCase refundCouponCase) {
@@ -131,6 +138,7 @@ class BuyerOrderCancelHandler { @@ -131,6 +138,7 @@ class BuyerOrderCancelHandler {
131 transfer(); 138 transfer();
132 refundPayGoodsMoney(buyerOrder); 139 refundPayGoodsMoney(buyerOrder);
133 noticeSeller(); 140 noticeSeller();
  141 + noticeBuyer(buyerOrder);
134 } else { 142 } else {
135 log.info("cancel order {} fail, order status has changed", orderCode); 143 log.info("cancel order {} fail, order status has changed", orderCode);
136 throwServiceException("当前状态不可取消订单"); 144 throwServiceException("当前状态不可取消订单");
@@ -213,7 +221,7 @@ class BuyerOrderCancelHandler { @@ -213,7 +221,7 @@ class BuyerOrderCancelHandler {
213 refundGoodsMoney.refundConsumer().accept(paymentRequest, billLogEventBuilder); 221 refundGoodsMoney.refundConsumer().accept(paymentRequest, billLogEventBuilder);
214 log.info("refund pay goods money by order {} success", orderCode); 222 log.info("refund pay goods money by order {} success", orderCode);
215 } catch (Exception e) { 223 } catch (Exception e) {
216 - log.info("refund pay goods money by order {} fail request is {}", orderCode, paymentRequest, e); 224 + log.warn("refund pay goods money by order {} fail request is {}", orderCode, paymentRequest, e);
217 BillLogEvent billLogEvent = billLogEventBuilder.tradeStatus(BillTradeStatus.FAIL.getCode()).build(); 225 BillLogEvent billLogEvent = billLogEventBuilder.tradeStatus(BillTradeStatus.FAIL.getCode()).build();
218 EventBusPublisher.publishEvent(billLogEvent); 226 EventBusPublisher.publishEvent(billLogEvent);
219 227
@@ -232,16 +240,30 @@ class BuyerOrderCancelHandler { @@ -232,16 +240,30 @@ class BuyerOrderCancelHandler {
232 if (Objects.nonNull(noticeSeller)) { 240 if (Objects.nonNull(noticeSeller)) {
233 try { 241 try {
234 log.info("notice seller buyer order has closed by order {}", orderCode); 242 log.info("notice seller buyer order has closed by order {}", orderCode);
235 - int times = noticeSeller.times();  
236 SellerOrderGoods sog = noticeSeller.sellerOrderGoods(); 243 SellerOrderGoods sog = noticeSeller.sellerOrderGoods();
237 if (Objects.isNull(sog)) { 244 if (Objects.isNull(sog)) {
238 val skup = skupSupplier().get(); 245 val skup = skupSupplier().get();
239 val sellerOrderGoodsMapper = noticeSeller.sellerOrderGoodsMapper(); 246 val sellerOrderGoodsMapper = noticeSeller.sellerOrderGoodsMapper();
240 sog = sellerOrderGoodsMapper.selectByPrimaryKey(skup); 247 sog = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
241 } 248 }
242 - noticeSeller.sellerNoticeSender().notice(sog, orderCode, times); 249 + noticeSeller.sellerNoticeSender().notice(sog, orderCode);
  250 + } catch (Exception e) {
  251 + log.warn("notice seller buyer order has closed by order {} fail", orderCode, e);
  252 + }
  253 + }
  254 + }
  255 +
  256 + private void noticeBuyer(BuyerOrder buyerOrder) {
  257 + if (Objects.nonNull(noticeBuyer)) {
  258 + log.info("notice buyer order has closed by order {}", orderCode);
  259 + try {
  260 + BuyerNoticeSender.Request request = BuyerNoticeSender.Request.builder()
  261 + .uid(buyerOrder.getUid())
  262 + .orderCode(buyerOrder.getOrderCode())
  263 + .build();
  264 + noticeBuyer.buyerNoticeSender().notice(request);
243 } catch (Exception e) { 265 } catch (Exception e) {
244 - log.info("notice seller buyer order has closed by order {} fail", orderCode, e); 266 + log.warn("notice buyer order has closed by order {} fail", orderCode, e);
245 } 267 }
246 } 268 }
247 } 269 }
@@ -277,7 +299,6 @@ class BuyerOrderCancelHandler { @@ -277,7 +299,6 @@ class BuyerOrderCancelHandler {
277 class NoticeSeller { 299 class NoticeSeller {
278 300
279 private final SellerNoticeSender sellerNoticeSender; 301 private final SellerNoticeSender sellerNoticeSender;
280 - private final int times;  
281 302
282 private SellerOrderGoods sellerOrderGoods; 303 private SellerOrderGoods sellerOrderGoods;
283 304
@@ -289,5 +310,17 @@ class BuyerOrderCancelHandler { @@ -289,5 +310,17 @@ class BuyerOrderCancelHandler {
289 } 310 }
290 } 311 }
291 312
  313 + @Data
  314 + @Accessors(fluent = true)
  315 + class NoticeBuyer {
  316 +
  317 + private final BuyerNoticeSender buyerNoticeSender;
  318 +
  319 + BuyerOrderCancelHandler and() {
  320 + BuyerOrderCancelHandler.this.noticeBuyer = this;
  321 + return BuyerOrderCancelHandler.this;
  322 + }
  323 + }
  324 +
292 325
293 } 326 }
1 package com.yohoufo.order.service.impl; 1 package com.yohoufo.order.service.impl;
2 2
3 import com.yohobuy.ufo.model.order.bo.MerchantOrderAttachInfo; 3 import com.yohobuy.ufo.model.order.bo.MerchantOrderAttachInfo;
4 -import com.yohobuy.ufo.model.order.common.*; 4 +import com.yohobuy.ufo.model.order.common.OrderStatus;
  5 +import com.yohobuy.ufo.model.order.common.SellerOrderStatus;
  6 +import com.yohobuy.ufo.model.order.common.SkupStatus;
  7 +import com.yohobuy.ufo.model.order.common.TabType;
5 import com.yohoufo.common.alarm.EventBusPublisher; 8 import com.yohoufo.common.alarm.EventBusPublisher;
6 import com.yohoufo.common.alarm.SmsAlarmEvent; 9 import com.yohoufo.common.alarm.SmsAlarmEvent;
7 import com.yohoufo.common.utils.DateUtil; 10 import com.yohoufo.common.utils.DateUtil;
@@ -149,7 +152,7 @@ public class BuyerOrderCancelService { @@ -149,7 +152,7 @@ public class BuyerOrderCancelService {
149 } 152 }
150 } 153 }
151 154
152 - public void cancelForSellerSendOutTimeout(int uid, long orderCode,int skup, SellerOrderGoods sellerOrderGoods){ 155 + public void cancelForSellerSendOutTimeout(int uid, long orderCode, int skup, SellerOrderGoods sellerOrderGoods) {
153 new BuyerOrderCancelHandler(uid, orderCode) 156 new BuyerOrderCancelHandler(uid, orderCode)
154 .withBuyerOrderSupplier(buyerOrderMapper, buyerOrderGoodsMapper) 157 .withBuyerOrderSupplier(buyerOrderMapper, buyerOrderGoodsMapper)
155 // 已付款 -> 超时未发货取消 158 // 已付款 -> 超时未发货取消
@@ -160,13 +163,15 @@ public class BuyerOrderCancelService { @@ -160,13 +163,15 @@ public class BuyerOrderCancelService {
160 .withRefundGoodsMoney(payRefundService::refund).refundCase(RefundCase.BUYER_GOODS_MONEY).skup(skup).and() 163 .withRefundGoodsMoney(payRefundService::refund).refundCase(RefundCase.BUYER_GOODS_MONEY).skup(skup).and()
161 .withFailAlarm(AlarmConfig.DELIVER_TIME_OUT) 164 .withFailAlarm(AlarmConfig.DELIVER_TIME_OUT)
162 // 通知卖家商品发货超时 165 // 通知卖家商品发货超时
163 - .withNoticeSeller(inBoxFacade::sellerDeliverNotice, 3).sellerOrderGoods(sellerOrderGoods).and() 166 + .withNoticeSeller((soa, code) -> inBoxFacade.sellerDeliverNotice(soa, code, 3)).sellerOrderGoods(sellerOrderGoods).and()
  167 + // 通知买家卖家商品发货超时
  168 + .withNoticeBuyer(inBoxFacade::noticeBuyerOfSellerSendOutTimeout).and()
164 // 退优惠券 169 // 退优惠券
165 .withRefundCoupon(BuyerRefundCouponEvent.BizCase.SELLER_DELIVER_TIMEOUT) 170 .withRefundCoupon(BuyerRefundCouponEvent.BizCase.SELLER_DELIVER_TIMEOUT)
166 .cancel(); 171 .cancel();
167 } 172 }
168 173
169 - public void cancelForSellerShamSendOut(int uid, long orderCode){ 174 + public void cancelForSellerShamSendOut(int uid, long orderCode) {
170 new BuyerOrderCancelHandler(uid, orderCode) 175 new BuyerOrderCancelHandler(uid, orderCode)
171 .withBuyerOrderSupplier(buyerOrderMapper, buyerOrderGoodsMapper) 176 .withBuyerOrderSupplier(buyerOrderMapper, buyerOrderGoodsMapper)
172 // 卖家发货 -> 鉴定中心收货前客服取消 177 // 卖家发货 -> 鉴定中心收货前客服取消
@@ -176,7 +181,9 @@ public class BuyerOrderCancelService { @@ -176,7 +181,9 @@ public class BuyerOrderCancelService {
176 // 退买家货款 181 // 退买家货款
177 .withRefundGoodsMoney(payRefundService::refund).refundCase(RefundCase.BUYER_GOODS_MONEY).and() 182 .withRefundGoodsMoney(payRefundService::refund).refundCase(RefundCase.BUYER_GOODS_MONEY).and()
178 // 通知卖家涉及虚假发货 183 // 通知卖家涉及虚假发货
179 - .withNoticeSeller(inBoxFacade::sellerDeliverNotice, 4).sellerOrderGoodsMapper(sellerOrderGoodsMapper).and() 184 + .withNoticeSeller(inBoxFacade::noticeSellerOfSellerShamSendOut).sellerOrderGoodsMapper(sellerOrderGoodsMapper).and()
  185 + // 通知买家卖家涉及虚假发货
  186 + .withNoticeBuyer(inBoxFacade::noticeBuyerOfSellerShamSendOut).and()
180 // 退优惠券 187 // 退优惠券
181 .withRefundCoupon(BuyerRefundCouponEvent.BizCase.SELLER_SHAM_SEND_OUT) 188 .withRefundCoupon(BuyerRefundCouponEvent.BizCase.SELLER_SHAM_SEND_OUT)
182 .withFailAlarm(AlarmConfig.SELLER_SHAM_SEND_OUT) 189 .withFailAlarm(AlarmConfig.SELLER_SHAM_SEND_OUT)
  1 +package com.yohoufo.order.service.impl.function;
  2 +
  3 +import lombok.AllArgsConstructor;
  4 +import lombok.Data;
  5 +import lombok.NoArgsConstructor;
  6 +import lombok.experimental.Builder;
  7 +
  8 +public interface BuyerNoticeSender {
  9 +
  10 + void notice(Request request);
  11 +
  12 + @Data
  13 + @Builder
  14 + @NoArgsConstructor
  15 + @AllArgsConstructor
  16 + class Request {
  17 + private Integer uid;
  18 + private Long orderCode;
  19 + }
  20 +
  21 +}
@@ -4,6 +4,6 @@ import com.yohoufo.dal.order.model.SellerOrderGoods; @@ -4,6 +4,6 @@ import com.yohoufo.dal.order.model.SellerOrderGoods;
4 4
5 public interface SellerNoticeSender { 5 public interface SellerNoticeSender {
6 6
7 - void notice(SellerOrderGoods sog, long orderCode, int times); 7 + void notice(SellerOrderGoods sog, long orderCode);
8 8
9 } 9 }
@@ -6,6 +6,7 @@ import com.yohoufo.dal.order.model.SellerOrderGoods; @@ -6,6 +6,7 @@ import com.yohoufo.dal.order.model.SellerOrderGoods;
6 import com.yohoufo.inboxclient.model.InBoxResponse; 6 import com.yohoufo.inboxclient.model.InBoxResponse;
7 import com.yohoufo.inboxclient.model.InboxReqVO; 7 import com.yohoufo.inboxclient.model.InboxReqVO;
8 import com.yohoufo.inboxclient.sdk.InBoxSDK; 8 import com.yohoufo.inboxclient.sdk.InBoxSDK;
  9 +import com.yohoufo.order.service.impl.function.BuyerNoticeSender;
9 import org.apache.commons.lang3.StringUtils; 10 import org.apache.commons.lang3.StringUtils;
10 import org.slf4j.Logger; 11 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory; 12 import org.slf4j.LoggerFactory;
@@ -654,6 +655,87 @@ public class InBoxFacade { @@ -654,6 +655,87 @@ public class InBoxFacade {
654 } 655 }
655 } 656 }
656 657
  658 + public void noticeSellerOfSellerShamSendOut(SellerOrderGoods sog,long orderCode){
  659 + Integer sellerUid = sog.getUid();
  660 + String prdName = sog.getProductName();
  661 + String sizeName = sog.getSizeName();
  662 + try {
  663 + executorService.execute(() -> {
  664 + // 发站内信
  665 + logger.info("record seller sham send out inbox sms msg for seller,sellerUid {}, prdName {}", sellerUid, prdName);
  666 + String params = buildParams(prdName, sizeName);
  667 + InboxReqVO req = buildInboxReqVO(sellerUid, params, InboxBusinessTypeEnum.NOTICE_SELLER_SELLER_SHAM_SEND_OUT);
  668 + InBoxResponse resp = inBoxSDK.addInbox(req);
  669 + logger.info("record seller sham send out inbox msg,sellerUid {}, prdName {},sizeName {} resp {}",
  670 + sellerUid, prdName, sizeName, resp);
  671 + // 发短信
  672 + String phone = userProxyService.getMobile(sellerUid);
  673 + if (StringUtils.isBlank(phone)){
  674 + logger.warn("seller sham send out sms send fail,sellerUid {}, prdName {}", sellerUid, prdName);
  675 + return;
  676 + }
  677 + List<String> mobileList = Arrays.asList(phone);
  678 + String content = getReplacedContent(InboxBusinessTypeEnum.SMS_NOTICE_SELLER_SELLER_SHAM_SEND_OUT.getContent(),prdName,orderCode);
  679 + sendSmsService.smsSendByMobile(content, mobileList);
  680 + logger.info("seller sham send out msg,sellerUid {}, prdName {}", sellerUid, prdName);
  681 + });
  682 + } catch (Exception e) {
  683 + logger.warn("InBoxFacade noticeSellerOfSellerShamSendOut error inbox msg, sellerUid {}, prdName {} ", sellerUid, prdName, e);
  684 + }
  685 + }
  686 +
  687 + public void noticeBuyerOfSellerShamSendOut(BuyerNoticeSender.Request request) {
  688 + Integer uid = request.getUid();
  689 + Long orderCode = request.getOrderCode();
  690 + String params = buildParams(orderCode);
  691 + InboxReqVO inboxMessage = buildInboxReqVO(uid, params, InboxBusinessTypeEnum.NOTICE_BUYER_SELLER_SHAM_SEND_OUT);
  692 +
  693 +
  694 + String smsContent = getReplacedContent(InboxBusinessTypeEnum.SMS_NOTICE_BUYER_SELLER_SHAM_SEND_OUT.getContent(), orderCode);
  695 + try {
  696 + logger.info("noticeBuyerOfSellerShamSendOut,uid {} request is {}", uid, request);
  697 + executorService.execute(() -> {
  698 + InBoxResponse inBoxResponse = inBoxSDK.addInbox(inboxMessage);
  699 + logger.info("noticeBuyerOfSellerShamSendOut inbox send success, message is {} res is {}", inboxMessage, inBoxResponse);
  700 + String phone = userProxyService.getMobile(uid);
  701 + if (StringUtils.isBlank(phone)) {
  702 + logger.warn("noticeBuyerOfSellerShamSendOut sms send fail,uid {} can not find phone", uid);
  703 + return;
  704 + }
  705 + sendSmsService.smsSendByMobile(smsContent, Arrays.asList(phone));
  706 + logger.info("noticeBuyerOfSellerShamSendOut sms send success,uid {}", uid);
  707 + });
  708 + } catch (Exception e) {
  709 + logger.warn("noticeBuyerOfSellerShamSendOut fail,uid {}", uid, e);
  710 + }
  711 + }
  712 +
  713 + public void noticeBuyerOfSellerSendOutTimeout(BuyerNoticeSender.Request request){
  714 + Integer uid = request.getUid();
  715 + Long orderCode = request.getOrderCode();
  716 + String params = buildParams(orderCode);
  717 + InboxReqVO inboxMessage = buildInboxReqVO(uid, params, InboxBusinessTypeEnum.NOTICE_BUYER_SELLER_SEND_OUT_TIMEOUT);
  718 +
  719 +
  720 + String smsContent = getReplacedContent(InboxBusinessTypeEnum.SMS_NOTICE_BUYER_SELLER_SEND_OUT_TIMEOUT.getContent(), orderCode);
  721 + try {
  722 + logger.info("noticeBuyerOfSellerSendOutTimeout,uid {} request is {}", uid, request);
  723 + executorService.execute(() -> {
  724 + InBoxResponse inBoxResponse = inBoxSDK.addInbox(inboxMessage);
  725 + logger.info("noticeBuyerOfSellerSendOutTimeout inbox send success, message is {} res is {}", inboxMessage, inBoxResponse);
  726 + String phone = userProxyService.getMobile(uid);
  727 + if (StringUtils.isBlank(phone)) {
  728 + logger.warn("noticeBuyerOfSellerSendOutTimeout sms send fail,uid {} can not find phone", uid);
  729 + return;
  730 + }
  731 + sendSmsService.smsSendByMobile(smsContent, Arrays.asList(phone));
  732 + logger.info("noticeBuyerOfSellerSendOutTimeout sms send success,uid {}", uid);
  733 + });
  734 + } catch (Exception e) {
  735 + logger.warn("noticeBuyerOfSellerSendOutTimeout fail,uid {}", uid, e);
  736 + }
  737 + }
  738 +
657 public void sellerDeliverNotice(SellerOrderGoods sog,long orderCode, int times) { 739 public void sellerDeliverNotice(SellerOrderGoods sog,long orderCode, int times) {
658 Integer sellerUid = sog.getUid(); 740 Integer sellerUid = sog.getUid();
659 String prdName = sog.getProductName(); 741 String prdName = sog.getProductName();
@@ -666,10 +748,7 @@ public class InBoxFacade { @@ -666,10 +748,7 @@ public class InBoxFacade {
666 } else if (times == 3) { 748 } else if (times == 3) {
667 ibt = InboxBusinessTypeEnum.NOTICE_SELLER_DELIVER_GOODS_FAIL; 749 ibt = InboxBusinessTypeEnum.NOTICE_SELLER_DELIVER_GOODS_FAIL;
668 smsInboxBusinessTypeEnum = InboxBusinessTypeEnum.SMS_NOTIFIED_SEND_FAILED; 750 smsInboxBusinessTypeEnum = InboxBusinessTypeEnum.SMS_NOTIFIED_SEND_FAILED;
669 - } else if (times == 4) {  
670 - ibt = InboxBusinessTypeEnum.NOTICE_SELLER_SELLER_SHAM_SEND_OUT;  
671 - smsInboxBusinessTypeEnum = InboxBusinessTypeEnum.SMS_NOTICE_SELLER_SELLER_SHAM_SEND_OUT;  
672 - }else { 751 + } else {
673 return; 752 return;
674 } 753 }
675 try { 754 try {