...
|
...
|
@@ -17,9 +17,11 @@ import java.util.concurrent.ArrayBlockingQueue; |
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.function.Consumer;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
|
@Slf4j
|
|
|
@Slf4j(topic = "notice")
|
|
|
public class BaseNoticeFacade {
|
|
|
|
|
|
private ExecutorService executorService = new ThreadPoolExecutor(5, 10,
|
...
|
...
|
@@ -42,6 +44,7 @@ public class BaseNoticeFacade { |
|
|
public class Notice {
|
|
|
|
|
|
private final int uid;
|
|
|
private String logPrefix;
|
|
|
|
|
|
private InboxReqVO inBoxContent;
|
|
|
private Supplier<InboxReqVO> inBoxContentSupplier;
|
...
|
...
|
@@ -55,6 +58,11 @@ public class BaseNoticeFacade { |
|
|
this.uid = uid;
|
|
|
}
|
|
|
|
|
|
public Notice withLogPrefix(String logPrefix) {
|
|
|
this.logPrefix = logPrefix;
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
public Notice withInBox(InboxBusinessTypeEnum businessType, Object... args) {
|
|
|
inBoxContent = buildInboxContent(businessType, args);
|
|
|
return this;
|
...
|
...
|
@@ -82,65 +90,76 @@ public class BaseNoticeFacade { |
|
|
|
|
|
public void send() {
|
|
|
executorService.execute(() -> {
|
|
|
log.warn("send, uid {} inBoxContent {} smsContent {}", uid, inBoxContent, smsContent);
|
|
|
InboxReqVO inBoxContent = getInBoxContent();
|
|
|
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, uid {}, content {} response {}", uid, inBoxContent, resp);
|
|
|
log.info("{}, send in box success content {} response {}", logPrefix, inBoxContent, resp);
|
|
|
} catch (Exception e) {
|
|
|
log.warn("send in box fail, uid {} content {}", uid, inBoxContent, 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, uid {}, response {}", uid, inBoxContent, resp);
|
|
|
log.info("{}, send push success, response {}", logPrefix, resp);
|
|
|
} catch (Exception e) {
|
|
|
log.warn("send push fail, uid {}", uid, e);
|
|
|
log.warn("{}, send push fail", logPrefix, e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
String smsContent = getSmsContent();
|
|
|
// 发送短信
|
|
|
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, uid {} content {} phone is blank", uid, smsContent);
|
|
|
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, uid {} content {} phone {} ", uid, smsContent, phone);
|
|
|
log.info("{}, send sms success content {} phone {} ", logPrefix, smsContent, phone);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
log.warn("send sms fail, uid {} content {}", uid, smsContent, e);
|
|
|
log.warn("{}, send sms fail content {}", logPrefix, smsContent, e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// END
|
|
|
});
|
|
|
}
|
|
|
|
|
|
private InboxReqVO getInBoxContent() {
|
|
|
private InboxReqVO getInBoxContentWhenExceptionAnd(Function<Exception, InboxReqVO> exceptionFunction) {
|
|
|
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;
|
|
|
return exceptionFunction.apply(e);
|
|
|
}
|
|
|
} else {
|
|
|
return this.inBoxContent;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private String getSmsContent() {
|
|
|
private String getSmsContentWhenExceptionAnd(Function<Exception, String> exceptionFunction) {
|
|
|
if (Objects.nonNull(smsContentSupplier)) {
|
|
|
try {
|
|
|
return smsContentSupplier.get();
|
|
|
} catch (Exception e) {
|
|
|
log.warn("send sms fail, uid {} get content fail", uid, e);
|
|
|
return null;
|
|
|
return exceptionFunction.apply(e);
|
|
|
}
|
|
|
} else {
|
|
|
return this.smsContent;
|
...
|
...
|
@@ -148,7 +167,6 @@ public class BaseNoticeFacade { |
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
protected String buildParams(Object... objects) {
|
...
|
...
|
@@ -172,7 +190,7 @@ public class BaseNoticeFacade { |
|
|
return req;
|
|
|
}
|
|
|
|
|
|
protected InboxReqVO buildInboxContent(InboxBusinessTypeEnum ibt,Object... params) {
|
|
|
protected InboxReqVO buildInboxContent(InboxBusinessTypeEnum ibt, Object... params) {
|
|
|
InboxReqVO req = new InboxReqVO();
|
|
|
req.setType(ibt.getType());
|
|
|
req.setBusinessType(ibt.getBusinessType());
|
...
|
...
|
@@ -184,7 +202,7 @@ public class BaseNoticeFacade { |
|
|
return MessageFormatter.arrayFormat(content, params).getMessage();
|
|
|
}
|
|
|
|
|
|
protected String buildSmsContent(InboxBusinessTypeEnum ibte, Object... params){
|
|
|
protected String buildSmsContent(InboxBusinessTypeEnum ibte, Object... params) {
|
|
|
return getReplacedContent(ibte.getContent(), params);
|
|
|
}
|
|
|
|
...
|
...
|
|