Authored by LUOXC

refactor

... ... @@ -95,57 +95,30 @@ public class BaseNoticeFacade {
public void send() {
executorService.execute(() -> {
final Logger log = getLogger();
final String logPrefix = getReplacedContent("{} send uid {}", this.logPrefix, this.uid);
log.warn("{}, inBoxContent {} smsContent {}", logPrefix, inBoxContent, smsContent);
// 发送站内信
InboxReqVO inBoxContent = getInBoxContentWhenExceptionAnd(e -> {
log.warn("{}, send in box fail, get content fail", logPrefix, e);
return null;
});
if (Objects.nonNull(inBoxContent)) {
try {
inBoxContent.setUid(uid);
InBoxResponse resp = inBoxSDK.addInbox(inBoxContent);
log.info("{}, send in box success content {} response {}", logPrefix, inBoxContent, JSON.toJSON(resp));
} catch (Exception e) {
log.warn("{}, send in box fail content {}", logPrefix, inBoxContent, e);
}
}
// 发送PUSH
if (Objects.nonNull(pushSupplier)) {
try {
SendMessageRspBo resp = pushSupplier.get();
log.info("{}, send push success, response {}", logPrefix, JSON.toJSON(resp));
} catch (Exception e) {
log.warn("{}, send push fail", logPrefix, e);
}
}
// 发送短信
String smsContent = getSmsContentWhenExceptionAnd(e -> {
log.warn("{}, send sms fail, get content fail", logPrefix, e);
return null;
});
if (Objects.nonNull(smsContent)) {
try {
String phone = userProxyService.getMobile(uid);
if (StringUtils.isBlank(phone)) {
log.warn("{}, send sms fail content {} phone is blank", logPrefix, smsContent);
} else {
List<String> mobileList = Arrays.asList(phone);
sendSmsService.smsSendByMobile(smsContent, mobileList);
log.info("{}, send sms success content {} phone {} ", logPrefix, smsContent, phone);
}
} catch (Exception e) {
log.warn("{}, send sms fail content {}", logPrefix, smsContent, e);
}
}
log.info("{}, start", logPrefix);
sendInbox(logPrefix);
sendPush(logPrefix);
sendSms(logPrefix);
log.info("{}, end", logPrefix);
});
}
// END
private void sendInbox(String logPrefix) {
final Logger log = getLogger();
InboxReqVO inBoxContent = getInBoxContentWhenExceptionAnd(e -> {
log.warn("{}, send in box fail, get content fail", logPrefix, e);
return null;
});
if (Objects.nonNull(inBoxContent)) {
try {
inBoxContent.setUid(uid);
InBoxResponse resp = inBoxSDK.addInbox(inBoxContent);
log.info("{}, send in box success content {} response {}", logPrefix, JSON.toJSON(inBoxContent), JSON.toJSON(resp));
} catch (Exception e) {
log.warn("{}, send in box fail content {}", logPrefix, JSON.toJSON(inBoxContent), e);
}
}
}
private InboxReqVO getInBoxContentWhenExceptionAnd(Function<Exception, InboxReqVO> exceptionFunction) {
... ... @@ -160,6 +133,40 @@ public class BaseNoticeFacade {
}
}
private void sendPush(String logPrefix) {
final Logger log = getLogger();
if (Objects.nonNull(pushSupplier)) {
try {
SendMessageRspBo resp = pushSupplier.get();
log.info("{}, send push success, response {}", logPrefix, JSON.toJSON(resp));
} catch (Exception e) {
log.warn("{}, send push fail", logPrefix, e);
}
}
}
private void sendSms(String logPrefix) {
final Logger log = getLogger();
String smsContent = getSmsContentWhenExceptionAnd(e -> {
log.warn("{}, send sms fail, get content fail", logPrefix, e);
return null;
});
if (Objects.nonNull(smsContent)) {
try {
String phone = userProxyService.getMobile(uid);
if (StringUtils.isBlank(phone)) {
log.warn("{}, send sms fail content {} phone is blank", logPrefix, smsContent);
} else {
List<String> mobileList = Arrays.asList(phone);
sendSmsService.smsSendByMobile(smsContent, mobileList);
log.info("{}, send sms success content {} phone {} ", logPrefix, smsContent, phone);
}
} catch (Exception e) {
log.warn("{}, send sms fail content {}", logPrefix, smsContent, e);
}
}
}
private String getSmsContentWhenExceptionAnd(Function<Exception, String> exceptionFunction) {
if (Objects.nonNull(smsContentSupplier)) {
try {
... ...