Authored by LUOXC

refactor

... ... @@ -1417,7 +1417,7 @@ public class AppraiseService {
//平台已发货给买家
Product product = Optional.ofNullable(sellerOrderGoods).map(SellerOrderGoods::getProductId).map(productMapper::selectByPrimaryKey).orElse(null);
inBoxFacade.appraisePassNoticeBuyer(buyerUid, orderCode, sellerOrderGoods);
inBoxFacade.appraisePassAndDeliveryGoodsToBuyerNoticeBuyer(buyerUid, orderCode, sellerOrderGoods);
inBoxFacade.appraisePassNoticeSeller(buyerUid, orderCode, sellerOrderGoods);
} catch (Exception ex) {
LOGGER.warn("in appraiseSuccess,refund fail, refundReqOfSeller {}", refundReqOfSeller, ex);
... ...
... ... @@ -44,7 +44,10 @@ public class BaseNoticeFacade {
private final int uid;
private InboxReqVO inBoxContent;
private Supplier<InboxReqVO> inBoxContentSupplier;
private String smsContent;
private Supplier<String> smsContentSupplier;
private Supplier<SendMessageRspBo> pushSupplier;
... ... @@ -57,11 +60,21 @@ public class BaseNoticeFacade {
return this;
}
public Notice withInBox(Supplier<InboxReqVO> inBoxContentSupplier) {
this.inBoxContentSupplier = inBoxContentSupplier;
return this;
}
public Notice withSms(InboxBusinessTypeEnum businessType, Object... args) {
smsContent = getReplacedContent(businessType.getContent(), args);
return this;
}
public Notice withSms(Supplier<String> smsContentSupplier) {
this.smsContentSupplier = smsContentSupplier;
return this;
}
public Notice withPush(Supplier<SendMessageRspBo> pushSupplier) {
this.pushSupplier = pushSupplier;
return this;
... ... @@ -70,16 +83,27 @@ public class BaseNoticeFacade {
public void send() {
executorService.execute(() -> {
log.warn("send, uid {} inBoxContent {} smsContent {}", uid, inBoxContent, smsContent);
try {
InboxReqVO inBoxContent = getInBoxContent();
if (Objects.nonNull(inBoxContent)) {
try {
InBoxResponse resp = inBoxSDK.addInbox(inBoxContent);
log.info("send in box success, uid {}, content {} response {}", uid, inBoxContent, resp);
} catch (Exception e) {
log.warn("send in box fail, uid {} content {}", uid, inBoxContent, e);
}
}
if (Objects.nonNull(pushSupplier)) {
try {
SendMessageRspBo resp = pushSupplier.get();
log.info("send push success, uid {}, response {}", uid, inBoxContent, resp);
} catch (Exception e) {
log.warn("send push fail, uid {}", uid, e);
}
}
String smsContent = getSmsContent();
if (Objects.nonNull(smsContent)) {
try {
String phone = userProxyService.getMobile(uid);
if (StringUtils.isBlank(phone)) {
log.warn("send sms fail, uid {} content {} phone is blank", uid, smsContent);
... ... @@ -88,14 +112,45 @@ public class BaseNoticeFacade {
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);
log.warn("send sms fail, uid {} content {}", uid, smsContent, e);
}
}
});
}
private String buildParams(Object... objects) {
private InboxReqVO getInBoxContent() {
if (Objects.nonNull(inBoxContentSupplier)) {
try {
return inBoxContentSupplier.get();
} catch (Exception e) {
log.warn("send in box fail, uid {} get content fail", uid, e);
return null;
}
} else {
return this.inBoxContent;
}
}
private String getSmsContent() {
if (Objects.nonNull(smsContentSupplier)) {
try {
return smsContentSupplier.get();
} catch (Exception e) {
log.warn("send sms fail, uid {} get content fail", uid, e);
return null;
}
} else {
return this.smsContent;
}
}
}
protected String buildParams(Object... objects) {
if (objects == null) {
return null;
}
... ... @@ -104,11 +159,10 @@ public class BaseNoticeFacade {
return objects[0].toString();
}
String params = StringUtils.join(objects, ",");
return params;
return StringUtils.join(objects, ",");
}
private InboxReqVO buildInboxReqVO(int uid, String params, InboxBusinessTypeEnum ibt) {
protected InboxReqVO buildInboxReqVO(int uid, String params, InboxBusinessTypeEnum ibt) {
InboxReqVO req = new InboxReqVO();
req.setType(ibt.getType());
req.setBusinessType(ibt.getBusinessType());
... ... @@ -117,10 +171,12 @@ public class BaseNoticeFacade {
return req;
}
private String getReplacedContent(String content, Object... params) {
protected String getReplacedContent(String content, Object... params) {
return MessageFormatter.arrayFormat(content, params).getMessage();
}
protected String replaceSMSContent(InboxBusinessTypeEnum ibte, Object... params){
return getReplacedContent(ibte.getContent(), params);
}
}
... ...
... ... @@ -64,7 +64,6 @@ public class BuyerNoticeFacade extends BaseNoticeFacade {
.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);
}
... ...
... ... @@ -40,7 +40,7 @@ import java.util.function.Supplier;
* Created by chenchao on 2018/10/8.
*/
@Service
public class InBoxFacade {
public class InBoxFacade extends BaseNoticeFacade{
private final Logger logger = LoggerFactory.getLogger(getClass());
... ... @@ -74,49 +74,25 @@ public class InBoxFacade {
* @param buyerUid
*/
public void buyerOrderNotPayed(int buyerUid, long orderCode) {
try {
executorService.execute(() -> {
String params = buildParams(orderCode);
InboxBusinessTypeEnum ibt = InboxBusinessTypeEnum.PURCHASE_UNPAID;
InboxReqVO req = buildInboxReqVO(buyerUid, params, ibt);
//
InBoxResponse resp = inBoxSDK.addInbox(req);
logger.info("record buyerOrderNotPayed inbox msg, buyerUid {}, orderCode {}, resp {}",
buyerUid, orderCode, resp);
//push
SendMessageRspBo bo = ufoSendService.buyerNotPay(String.valueOf(buyerUid),String.valueOf(orderCode));
logger.info("record buyerOrderNotPayed push buyer uid is {}, orderCode is {}, result is {}", buyerUid, orderCode, JSON.toJSONString(bo));
});
} catch (Exception e) {
logger.warn("InBoxFacade buyerOrderNotPayed error inbox msg, buyerUid {}, orderCode {} ",
buyerUid, orderCode, e);
}
logger.info("notice buyer not paid, buyerUid {}, orderCode {}", buyerUid, orderCode);
newNotice(buyerUid)
.withInBox(InboxBusinessTypeEnum.PURCHASE_UNPAID, orderCode)
.withPush(() -> ufoSendService.buyerNotPay(String.valueOf(buyerUid), String.valueOf(orderCode)))
.send();
}
/**
* 已通知卖家发货:买家支付订单
* 通知买家,已经支付成功已通知卖家发货
*
* @param buyerUid
* @param orderCode
*/
public void buyerFinishPaid(int buyerUid, long orderCode,int deliveryHours, String unit) {
try {
executorService.execute(() -> {
InboxBusinessTypeEnum ibt = InboxBusinessTypeEnum.PURCHASE_NOTIFIED_SELLER;
public void buyerFinishPaid(int buyerUid, long orderCode, int deliveryHours, String unit) {
logger.info("notice buyer finish paid, buyerUid {}, orderCode {}", buyerUid, orderCode);
String timelimitDesc = new StringBuilder().append(deliveryHours).append(unit).toString();
String params = buildParams(orderCode,timelimitDesc);
InboxReqVO req = buildInboxReqVO(buyerUid, params, ibt);
InBoxResponse resp = inBoxSDK.addInbox(req);
logger.info("record buyerFinishPaid inbox msg, buyerUid {}, orderCode {}, resp {}",
buyerUid, orderCode, resp);
});
} catch (Exception e) {
logger.warn("InBoxFacade buyerFinishPaid error inbox msg, buyerUid {}, orderCode {} ",
buyerUid, orderCode, e);
}
newNotice(buyerUid)
.withInBox(InboxBusinessTypeEnum.PURCHASE_NOTIFIED_SELLER, orderCode, timelimitDesc)
.send();
}
... ... @@ -126,43 +102,26 @@ public class InBoxFacade {
* @param buyerUid
* @param orderCode
*/
public void sellerDeliver2Depot(int buyerUid, long orderCode,SellerOrderGoods psog ){
executorService.execute(()-> {
public void sellerDeliver2Depot(int buyerUid, long orderCode, SellerOrderGoods psog) {
try {
String skupTypeText=SkupType.getSkupType(psog.getAttributes()).attrName();
String prdName = psog.getProductName();
InboxBusinessTypeEnum ibtOfBuyer = InboxBusinessTypeEnum.NOTICE_BUYER_WHEN_SELLER_DELIVER;
String params = buildParams(orderCode);
InboxReqVO req = buildInboxReqVO(buyerUid, params, ibtOfBuyer);
InBoxResponse resp = inBoxSDK.addInbox(req);
logger.info("record sellerDeliver2Depot inbox msg, buyerUid {}, orderCode {}, prdName {} resp {}",
buyerUid, orderCode, prdName, resp);
executorService.execute(() -> {
String sizeName= psog.getSizeName();
logger.info("notice buyer seller deliver 2 depot, buyerUid {}, orderCode {}", buyerUid, orderCode);
String skupTypeText = SkupType.getSkupType(psog.getAttributes()).attrName();
String prdName = psog.getProductName();
String sizeName = psog.getSizeName();
Product product = productMapper.selectByPrimaryKey(psog.getProductId());
String productCode = product.getProductCode();
//发push
SendMessageRspBo bo = ufoSendService.sellerDeliverNotice(String.valueOf(buyerUid),String.valueOf(orderCode));
logger.info("record sellerDeliver2Depot push buyer uid is {}, orderCode is {}, result is {}", buyerUid, orderCode, JSON.toJSONString(bo));
//sms
String phone = userProxyService.getMobile(buyerUid);
if (StringUtils.isBlank(phone)){
logger.warn("in sellerDeliver2Depot sms fail, buyerUid {} orderCode {} prdName {} ", buyerUid, orderCode,prdName);
return;
}
String content=getReplacedContent(InboxBusinessTypeEnum.SMS_NOTICE_BUYER_WHEN_SELLER_DELIVER.getContent(),skupTypeText,prdName,sizeName,productCode,orderCode);
List<String> mobileList = Arrays.asList(phone);
sendSmsService.smsSendByMobile(content,mobileList);
logger.info("record sellerDeliver2Depot inbox sms msg, buyerUid {}, orderCode {}, prdName {} phone {}",
buyerUid, orderCode, prdName, phone);
newNotice(buyerUid)
.withInBox(InboxBusinessTypeEnum.NOTICE_BUYER_WHEN_SELLER_DELIVER, orderCode)
.withPush(() -> ufoSendService.sellerDeliverNotice(String.valueOf(buyerUid), String.valueOf(orderCode)))
.withSms(InboxBusinessTypeEnum.SMS_NOTICE_BUYER_WHEN_SELLER_DELIVER, skupTypeText, prdName, sizeName, productCode, orderCode)
.send();
});
} catch (Exception ex) {
logger.warn("InBoxFacade depotDeliver2Buyer error inbox msg, buyerUid {}, orderCode {} ,prdName {}",
buyerUid, orderCode,psog, ex);
logger.warn("notice buyer seller deliver 2 depot fail, buyerUid {}, orderCode {}", buyerUid, orderCode, ex);
}
});
}
/**
... ... @@ -170,92 +129,49 @@ public class InBoxFacade {
*
* @return
*/
public void appraisePassNoticeBuyer(int buyerUid, long orderCode, SellerOrderGoods psog) {
executorService.execute(()->{
public void appraisePassAndDeliveryGoodsToBuyerNoticeBuyer(int buyerUid, long orderCode, SellerOrderGoods psog) {
try {
logger.info("record appraisePassNotice inbox msg, buyerUid {}, orderCode {}, psog {},SellerOrderGoods {} ",
buyerUid, orderCode, psog, JSON.toJSONString(psog));
executorService.execute(() -> {
logger.info("notice buyer appraise pass, buyerUid {}, orderCode {}", buyerUid, orderCode);
Product product = productMapper.selectByPrimaryKey(psog.getProductId());
String productCode = Optional.ofNullable(product).map(Product::getProductCode).orElse("");
String skupTypeText=SkupType.getSkupType(psog.getAttributes()).attrName();
String skupTypeText = SkupType.getSkupType(psog.getAttributes()).attrName();
String prdName = psog.getProductName();
String sizeName = psog.getSizeName();
InboxBusinessTypeEnum ibt = InboxBusinessTypeEnum.PURCHASE_SENDED;
String params = buildParams(orderCode);
InboxReqVO req = buildInboxReqVO(buyerUid, params, ibt);
InBoxResponse resp = inBoxSDK.addInbox(req);
logger.info("record appraisePassNotice inbox msg, buyerUid {}, orderCode {}, prdName {},SellerOrderGoods {} resp {}",
buyerUid, orderCode, prdName, JSON.toJSONString(psog), resp);
//短信
String phone = userProxyService.getMobile(buyerUid);
if (StringUtils.isBlank(phone)){
logger.warn("in appraisePassNotice 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 appraisePassNotice notice buyer sms msg, buyerUid {}, orderCode {}, prdName {} phone {}",
buyerUid, orderCode,prdName, phone);
}
newNotice(buyerUid)
.withInBox(InboxBusinessTypeEnum.PURCHASE_SENDED, orderCode)
.withSms(InboxBusinessTypeEnum.SMS_SEND, skupTypeText, prdName, sizeName, productCode, orderCode)
.send();
});
} catch (Exception e) {
logger.warn("InBoxFacade appraisePassNotice error inbox msg, buyerUid {}, orderCode {} ,psog {}",
buyerUid, orderCode, psog, e);
logger.warn("notice buyer appraise pass fail, buyerUid {}, orderCode {}", buyerUid, orderCode, e);
}
});
}
public void appraisePassNoticeSeller(int buyerUid, long orderCode, SellerOrderGoods psog) {
executorService.execute(()->{
try {
logger.info("record appraisePassNoticeSeller inbox msg, buyerUid {}, orderCode {}, psog {},SellerOrderGoods {} product {}",
buyerUid, orderCode, psog, JSON.toJSONString(psog));
executorService.execute(() -> {
logger.info("notice seller appraise pass, buyerUid {}, orderCode {}", buyerUid, orderCode);
String prdName = psog.getProductName();
Product product = productMapper.selectByPrimaryKey(psog.getProductId());
String productCode = Optional.ofNullable(product).map(Product::getProductCode).orElse("");
//seller notice
String sizeName = psog.getSizeName();
Integer sellerUid = psog.getUid();
String skupTypeText=SkupType.getSkupType(psog.getAttributes()).attrName();
InboxBusinessTypeEnum ibtOfSeller = InboxBusinessTypeEnum.NOTICE_SELLER_WHEN_APPRAISE_PASS;
String paramsOfSeller = buildParams(skupTypeText,prdName, sizeName,productCode);
InboxReqVO reqOfSeller = buildInboxReqVO(sellerUid, paramsOfSeller, ibtOfSeller);
String skupTypeText = SkupType.getSkupType(psog.getAttributes()).attrName();
InBoxResponse respOfSeller = inBoxSDK.addInbox(reqOfSeller);
logger.info("record appraisePassNoticeSeller inbox msg, buyerUid {}, orderCode {}, prdName {} ,sizeName {} ,resp {}",
buyerUid, orderCode, prdName,sizeName, respOfSeller);
String phoneOfSeller = userProxyService.getMobile(sellerUid);
if (StringUtils.isBlank(phoneOfSeller)){
logger.warn("in appraisePassNoticeSeller sms fail, buyerUid {} orderCode {} prdName {} ", buyerUid, orderCode,prdName);
}else{
List<String> mobileList = Arrays.asList(phoneOfSeller);
String contentOfSeller = getReplacedContent(InboxBusinessTypeEnum.SMS_NOTICE_SELLER_WHEN_APPRAISE_PASS.getContent(),skupTypeText, orderCode);
sendSmsService.smsSendByMobile(contentOfSeller, mobileList);
logger.info("record appraisePassNoticeSeller sms msg notice seller, sellerUid {}, orderCode {}, prdName {} sizeName {} phone {}",
sellerUid, orderCode, prdName, sizeName, phoneOfSeller);
}
newNotice(sellerUid)
.withInBox(InboxBusinessTypeEnum.NOTICE_SELLER_WHEN_APPRAISE_PASS, skupTypeText, prdName, sizeName, productCode)
.withSms(InboxBusinessTypeEnum.SMS_NOTICE_SELLER_WHEN_APPRAISE_PASS, skupTypeText, orderCode)
.send();
});
} catch (Exception e) {
logger.warn("InBoxFacade appraisePassNoticeSeller error inbox msg, buyerUid {}, orderCode {} ,psog {}",
buyerUid, orderCode, psog, e);
logger.warn("notice seller appraise pass fail, buyerUid {}, orderCode {}", buyerUid, orderCode, e);
}
});
}
private String replaceSMSContent(InboxBusinessTypeEnum ibte, Object... params){
return getReplacedContent(ibte.getContent(), params);
}
private String getReplacedContent(String content ,Object... params) {
return MessageFormatter.arrayFormat(content, params).getMessage();
}
/**
* 订单生成,卖家取消售卖
... ... @@ -1857,28 +1773,6 @@ public class InBoxFacade {
}
}
public 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;
}
public static String buildParams(Object... objects) {
if (objects == null) {
return null;
}
if (objects.length == 1) {
return objects[0].toString();
}
String params = StringUtils.join(objects, ",");
return params;
}
}
... ...