Authored by LUOXC

refactor

... ... @@ -16,6 +16,7 @@ import java.util.stream.Collectors;
import javax.annotation.Resource;
import com.yohoufo.order.service.DepositService;
import com.yohoufo.order.service.proxy.*;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
... ... @@ -91,10 +92,6 @@ import com.yohoufo.order.service.handler.penalty.PenaltyResult;
import com.yohoufo.order.service.handler.penalty.SellerEarnestMoney2BuyerPenaltyCalculator;
import com.yohoufo.order.service.impl.function.BuyerNoticeSender;
import com.yohoufo.order.service.listener.OrderChangeListenerContainer;
import com.yohoufo.order.service.proxy.InBoxFacade;
import com.yohoufo.order.service.proxy.OrderOperateRecordService;
import com.yohoufo.order.service.proxy.OrderStatusFlowService;
import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.service.seller.setting.SellerService;
import com.yohoufo.order.utils.BuyerOrderUtils;
import com.yohoufo.order.utils.PaymentHelper;
... ... @@ -142,6 +139,9 @@ public class AppraiseService {
@Autowired
private InBoxFacade inBoxFacade;
@Autowired
private BuyerNoticeFacade buyerNoticeFacade;
@Autowired
TransferService transferService;
... ... @@ -284,7 +284,7 @@ public class AppraiseService {
appraiseExpressInfoBo.getDepotNum(),
appraiseExpressInfoBo.getMobile());
// 通知买家已发货
inBoxFacade.noticeBuyerWhenDeliveryDepositGoodsToBuyer(buyerOrder.getUid(), appraiseExpressInfoBo.getWayBillCode(),
buyerNoticeFacade.deliveryDepositGoodsToBuyer(buyerOrder.getUid(), appraiseExpressInfoBo.getWayBillCode(),
() -> cleanCacheAfterUpdateStatus(buyerOrder.getOrderCode(), buyerOrder.getUid(), buyerOrder.getSellerUid()),
sellerOrderGoods -> Optional.ofNullable(sellerOrderGoods).map(SellerOrderGoods::getProductId).map(productMapper::selectByPrimaryKey).orElse(null));
}else {
... ... @@ -331,7 +331,7 @@ public class AppraiseService {
//清缓存
SellerOrderGoods sellerOrderGoods = cleanCacheAfterUpdateStatus(buyerOrder.getOrderCode(), buyerOrder.getUid(), buyerOrder.getSellerUid());
Product product = Optional.ofNullable(sellerOrderGoods).map(SellerOrderGoods::getProductId).map(productMapper::selectByPrimaryKey).orElse(null);
inBoxFacade.noticeBuyerWhenDeliveryGoodsToBuyer(buyerUid, orderCode, sellerOrderGoods, product);
buyerNoticeFacade.deliveryGoodsToBuyer(buyerUid, orderCode, sellerOrderGoods, product);
} else {
LOGGER.warn("in deliveryGoodsToBuyer update status number zero, buyer Order orderCode {} pstatus {}, expect Order Status {}",
orderCode, buyerOrder.getStatus(), expectOrderStatus);
... ...
package com.yohoufo.order.service.proxy;
import com.yoho.message.sdk.common.model.SendMessageRspBo;
import com.yohobuy.ufo.model.enums.InboxBusinessTypeEnum;
import com.yohoufo.inboxclient.model.InBoxResponse;
import com.yohoufo.inboxclient.model.InboxReqVO;
import com.yohoufo.inboxclient.sdk.InBoxSDK;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.helpers.MessageFormatter;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
@Slf4j
public class BaseNoticeFacade {
private ExecutorService executorService = new ThreadPoolExecutor(5, 10,
60, TimeUnit.SECONDS,
new ArrayBlockingQueue<>(1000), new InBoxThreadFactory());
@Autowired
private InBoxSDK inBoxSDK;
@Autowired
private SendSmsService sendSmsService;
@Autowired
private UserProxyService userProxyService;
public Notice newNotice(int uid) {
return new Notice(uid);
}
public class Notice {
private final int uid;
private InboxReqVO inBoxContent;
private String smsContent;
private Supplier<SendMessageRspBo> pushSupplier;
public Notice(int uid) {
this.uid = uid;
}
public Notice withInBox(InboxBusinessTypeEnum businessType, Object... args) {
inBoxContent = buildInboxReqVO(uid, buildParams(args), businessType);
return this;
}
public Notice withSms(InboxBusinessTypeEnum businessType, Object... args) {
smsContent = getReplacedContent(businessType.getContent(), args);
return this;
}
public Notice withPush(Supplier<SendMessageRspBo> pushSupplier) {
this.pushSupplier = pushSupplier;
return this;
}
public void send() {
executorService.execute(() -> {
log.warn("send, uid {} inBoxContent {} smsContent {}", uid, inBoxContent, smsContent);
try {
if (Objects.nonNull(inBoxContent)) {
InBoxResponse resp = inBoxSDK.addInbox(inBoxContent);
log.info("send in box success, uid {}, content {} response {}", uid, inBoxContent, resp);
}
if (Objects.nonNull(pushSupplier)) {
SendMessageRspBo resp = pushSupplier.get();
log.info("send push success, uid {}, response {}", uid, inBoxContent, resp);
}
if (Objects.nonNull(smsContent)) {
String phone = userProxyService.getMobile(uid);
if (StringUtils.isBlank(phone)) {
log.warn("send sms fail, uid {} content {} phone is blank", uid, smsContent);
} else {
List<String> mobileList = Arrays.asList(phone);
sendSmsService.smsSendByMobile(smsContent, mobileList);
log.info("send sms success, uid {} content {} phone {} ", uid, smsContent, phone);
}
}
} catch (Exception e) {
log.warn("send fail, uid {} inBoxContent {} smsContent {}", uid, inBoxContent, smsContent, e);
}
});
}
private String buildParams(Object... objects) {
if (objects == null) {
return null;
}
if (objects.length == 1) {
return objects[0].toString();
}
String params = StringUtils.join(objects, ",");
return params;
}
private InboxReqVO buildInboxReqVO(int uid, String params, InboxBusinessTypeEnum ibt) {
InboxReqVO req = new InboxReqVO();
req.setType(ibt.getType());
req.setBusinessType(ibt.getBusinessType());
req.setUid(uid);
req.setParams(params);
return req;
}
private String getReplacedContent(String content, Object... params) {
return MessageFormatter.arrayFormat(content, params).getMessage();
}
}
}
... ...
package com.yohoufo.order.service.proxy;
import com.yoho.message.sdk.service.ufo.IUFOSendService;
import com.yohobuy.ufo.model.enums.InboxBusinessTypeEnum;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.dal.product.model.Product;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;
@Service
@Slf4j
public class BuyerNoticeFacade extends BaseNoticeFacade {
@Autowired
private IUFOSendService ufoSendService;
/**
* 平台发货给买家
*
* @return
*/
public void deliveryDepositGoodsToBuyer(int buyerUid, String wayBillCode, Supplier<SellerOrderGoods> psogSupplier, Function<SellerOrderGoods, Product> productFunction) {
try {
log.info("notice buyer delivery deposit goods to buyer, uid {}, wayBillCode {}", buyerUid, wayBillCode);
SellerOrderGoods psog = psogSupplier.get();
Product product = productFunction.apply(psog);
String prdName = psog.getProductName();
String sizeName = psog.getSizeName();
String productCode = Optional.ofNullable(product).map(Product::getProductCode).orElse("");
newNotice(buyerUid)
.withInBox(InboxBusinessTypeEnum.NOTICE_BUYER_WHEN_DEPOSIT_GOODS_PURCHASE_SENDED, prdName, sizeName, productCode)
.withSms(InboxBusinessTypeEnum.SMS_NOTICE_BUYER_WHEN_DEPOSIT_GOODS_PURCHASE_SENDED, prdName, sizeName, productCode, wayBillCode)
.send();
log.info("notice buyer delivery deposit goods to buyer success, uid {}, wayBillCode {}", buyerUid, wayBillCode);
} catch (Exception e) {
log.warn("notice buyer delivery deposit goods to buyer fail, uid {}, wayBillCode {}", buyerUid, wayBillCode, e);
}
}
/**
* 平台发货给买家
*
* @return
*/
public void deliveryGoodsToBuyer(int buyerUid, long orderCode, SellerOrderGoods psog, Product product) {
try {
log.info("notice buyer delivery goods to buyer, buyerUid {}, orderCode {}", buyerUid, orderCode);
String skupTypeText = SkupType.getSkupType(psog.getAttributes()).attrName();
String prdName = psog.getProductName();
String sizeName = psog.getSizeName();
String productCode = Optional.ofNullable(product).map(Product::getProductCode).orElse("");
newNotice(buyerUid)
.withInBox(InboxBusinessTypeEnum.PURCHASE_SENDED, orderCode)
.withSms(InboxBusinessTypeEnum.SMS_SEND, skupTypeText, prdName, sizeName, productCode, orderCode)
.withPush(() -> ufoSendService.platformDeliverBuyer(String.valueOf(buyerUid), String.valueOf(orderCode)))
.send();
log.info("notice buyer delivery goods to buyer success, buyerUid {}, orderCode {}", buyerUid, orderCode);
} catch (Exception e) {
log.warn("notice buyer delivery goods to buyer fail, buyerUid {}, orderCode {}", buyerUid, orderCode, e);
}
}
}
... ...
... ... @@ -166,103 +166,6 @@ public class InBoxFacade {
}
/**
* 平台发货给买家
*
* @return
*/
public void noticeBuyerWhenDeliveryGoodsToBuyer(int buyerUid, long orderCode, SellerOrderGoods psog,Product product) {
executorService.execute(()->{
try {
logger.info("record noticeBuyerWhenDeliveryGoodsToBuyer inbox msg, buyerUid {}, orderCode {}, psog {},SellerOrderGoods {} product {}",
buyerUid, orderCode, psog, JSON.toJSONString(psog), JSON.toJSONString(product));
String skupTypeText=SkupType.getSkupType(psog.getAttributes()).attrName();
String prdName = psog.getProductName();
String sizeName = psog.getSizeName();
String productCode = Optional.ofNullable(product).map(Product::getProductCode).orElse("");
InboxBusinessTypeEnum ibt = InboxBusinessTypeEnum.PURCHASE_SENDED;
String params = buildParams(orderCode);
InboxReqVO req = buildInboxReqVO(buyerUid, params, ibt);
InBoxResponse resp = inBoxSDK.addInbox(req);
logger.info("record noticeBuyerWhenDeliveryGoodsToBuyer inbox msg, buyerUid {}, orderCode {}, prdName {},SellerOrderGoods {} resp {}",
buyerUid, orderCode, prdName, JSON.toJSONString(psog), resp);
//发push
SendMessageRspBo bo = ufoSendService.platformDeliverBuyer(String.valueOf(buyerUid),String.valueOf(orderCode));
logger.info("record noticeBuyerWhenDeliveryGoodsToBuyer push buyer uid is {}, orderCode is {}, result is {}", buyerUid, orderCode, JSON.toJSONString(bo));
//seller notice
//短信
String phone = userProxyService.getMobile(buyerUid);
if (StringUtils.isBlank(phone)){
logger.warn("in noticeBuyerWhenDeliveryGoodsToBuyer notice buyer sms fail, buyerUid {} orderCode {} prdName {} ", buyerUid, orderCode,prdName);
}else{
List<String> mobileList = Arrays.asList(phone);
String content = getReplacedContent(InboxBusinessTypeEnum.SMS_SEND.getContent(),skupTypeText,prdName,sizeName,productCode,orderCode);
sendSmsService.smsSendByMobile(content,mobileList);
logger.info("record noticeBuyerWhenDeliveryGoodsToBuyer notice buyer sms msg, buyerUid {}, orderCode {}, prdName {} phone {}",
buyerUid, orderCode,prdName, phone);
}
} catch (Exception e) {
logger.warn("InBoxFacade noticeBuyerWhenDeliveryGoodsToBuyer error inbox msg, buyerUid {}, orderCode {} ,psog {}",
buyerUid, orderCode, psog, e);
}
});
}
/**
* 平台发货给买家
*
* @return
*/
public void noticeBuyerWhenDeliveryDepositGoodsToBuyer(int buyerUid, String wayBillCode, Supplier<SellerOrderGoods> psogSupplier, Function<SellerOrderGoods,Product> productFunction) {
executorService.execute(()->{
try {
SellerOrderGoods psog = psogSupplier.get();
Product product = productFunction.apply(psog);
logger.info("noticeBuyerWhenDeliveryDepositGoodsToBuyer, buyerUid {}, wayBillCode {}, psog {},SellerOrderGoods {} product {}",
buyerUid, wayBillCode, psog, JSON.toJSONString(psog), JSON.toJSONString(product));
String prdName = psog.getProductName();
String sizeName = psog.getSizeName();
String productCode = Optional.ofNullable(product).map(Product::getProductCode).orElse("");
InboxBusinessTypeEnum ibt = InboxBusinessTypeEnum.NOTICE_BUYER_WHEN_DEPOSIT_GOODS_PURCHASE_SENDED;
String params = buildParams(prdName,sizeName,productCode);
InboxReqVO req = buildInboxReqVO(buyerUid, params, ibt);
InBoxResponse resp = inBoxSDK.addInbox(req);
logger.info("noticeBuyerWhenDeliveryDepositGoodsToBuyer, buyerUid {}, wayBillCode {}, prdName {},SellerOrderGoods {} resp {}",
buyerUid, wayBillCode, prdName, JSON.toJSONString(psog), resp);
//短信
String phone = userProxyService.getMobile(buyerUid);
if (StringUtils.isBlank(phone)){
logger.warn("noticeBuyerWhenDeliveryDepositGoodsToBuyer notice buyer sms fail, buyerUid {} wayBillCode {} prdName {} ",
buyerUid, wayBillCode,prdName);
}else{
List<String> mobileList = Arrays.asList(phone);
String content = getReplacedContent(InboxBusinessTypeEnum.SMS_NOTICE_BUYER_WHEN_DEPOSIT_GOODS_PURCHASE_SENDED.getContent(),prdName,sizeName,productCode,wayBillCode);
sendSmsService.smsSendByMobile(content,mobileList);
logger.info("noticeBuyerWhenDeliveryDepositGoodsToBuyer notice buyer sms msg, buyerUid {}, wayBillCode {}, prdName {} phone {}",
buyerUid, wayBillCode,prdName, phone);
}
} catch (Exception e) {
logger.warn("noticeBuyerWhenDeliveryDepositGoodsToBuyer fail, buyerUid {}, wayBillCode {}", buyerUid, wayBillCode, e);
}
});
}
/**
* 平台已发货给买家
*
* @return
... ...