|
@@ -17,9 +17,11 @@ import java.util.concurrent.ArrayBlockingQueue; |
|
@@ -17,9 +17,11 @@ import java.util.concurrent.ArrayBlockingQueue; |
17
|
import java.util.concurrent.ExecutorService;
|
17
|
import java.util.concurrent.ExecutorService;
|
18
|
import java.util.concurrent.ThreadPoolExecutor;
|
18
|
import java.util.concurrent.ThreadPoolExecutor;
|
19
|
import java.util.concurrent.TimeUnit;
|
19
|
import java.util.concurrent.TimeUnit;
|
|
|
20
|
+import java.util.function.Consumer;
|
|
|
21
|
+import java.util.function.Function;
|
20
|
import java.util.function.Supplier;
|
22
|
import java.util.function.Supplier;
|
21
|
|
23
|
|
22
|
-@Slf4j
|
24
|
+@Slf4j(topic = "notice")
|
23
|
public class BaseNoticeFacade {
|
25
|
public class BaseNoticeFacade {
|
24
|
|
26
|
|
25
|
private ExecutorService executorService = new ThreadPoolExecutor(5, 10,
|
27
|
private ExecutorService executorService = new ThreadPoolExecutor(5, 10,
|
|
@@ -42,6 +44,7 @@ public class BaseNoticeFacade { |
|
@@ -42,6 +44,7 @@ public class BaseNoticeFacade { |
42
|
public class Notice {
|
44
|
public class Notice {
|
43
|
|
45
|
|
44
|
private final int uid;
|
46
|
private final int uid;
|
|
|
47
|
+ private String logPrefix;
|
45
|
|
48
|
|
46
|
private InboxReqVO inBoxContent;
|
49
|
private InboxReqVO inBoxContent;
|
47
|
private Supplier<InboxReqVO> inBoxContentSupplier;
|
50
|
private Supplier<InboxReqVO> inBoxContentSupplier;
|
|
@@ -55,6 +58,11 @@ public class BaseNoticeFacade { |
|
@@ -55,6 +58,11 @@ public class BaseNoticeFacade { |
55
|
this.uid = uid;
|
58
|
this.uid = uid;
|
56
|
}
|
59
|
}
|
57
|
|
60
|
|
|
|
61
|
+ public Notice withLogPrefix(String logPrefix) {
|
|
|
62
|
+ this.logPrefix = logPrefix;
|
|
|
63
|
+ return this;
|
|
|
64
|
+ }
|
|
|
65
|
+
|
58
|
public Notice withInBox(InboxBusinessTypeEnum businessType, Object... args) {
|
66
|
public Notice withInBox(InboxBusinessTypeEnum businessType, Object... args) {
|
59
|
inBoxContent = buildInboxContent(businessType, args);
|
67
|
inBoxContent = buildInboxContent(businessType, args);
|
60
|
return this;
|
68
|
return this;
|
|
@@ -82,65 +90,76 @@ public class BaseNoticeFacade { |
|
@@ -82,65 +90,76 @@ public class BaseNoticeFacade { |
82
|
|
90
|
|
83
|
public void send() {
|
91
|
public void send() {
|
84
|
executorService.execute(() -> {
|
92
|
executorService.execute(() -> {
|
85
|
- log.warn("send, uid {} inBoxContent {} smsContent {}", uid, inBoxContent, smsContent);
|
|
|
86
|
- InboxReqVO inBoxContent = getInBoxContent();
|
93
|
+ final String logPrefix = getReplacedContent("{} send uid {}", this.logPrefix, this.uid);
|
|
|
94
|
+ log.warn("{}, inBoxContent {} smsContent {}", logPrefix, inBoxContent, smsContent);
|
|
|
95
|
+
|
|
|
96
|
+ // 发送站内信
|
|
|
97
|
+ InboxReqVO inBoxContent = getInBoxContentWhenExceptionAnd(e -> {
|
|
|
98
|
+ log.warn("{}, send in box fail, get content fail", logPrefix, e);
|
|
|
99
|
+ return null;
|
|
|
100
|
+ });
|
87
|
if (Objects.nonNull(inBoxContent)) {
|
101
|
if (Objects.nonNull(inBoxContent)) {
|
88
|
try {
|
102
|
try {
|
89
|
inBoxContent.setUid(uid);
|
103
|
inBoxContent.setUid(uid);
|
90
|
InBoxResponse resp = inBoxSDK.addInbox(inBoxContent);
|
104
|
InBoxResponse resp = inBoxSDK.addInbox(inBoxContent);
|
91
|
- log.info("send in box success, uid {}, content {} response {}", uid, inBoxContent, resp);
|
105
|
+ log.info("{}, send in box success content {} response {}", logPrefix, inBoxContent, resp);
|
92
|
} catch (Exception e) {
|
106
|
} catch (Exception e) {
|
93
|
- log.warn("send in box fail, uid {} content {}", uid, inBoxContent, e);
|
107
|
+ log.warn("{}, send in box fail content {}", logPrefix, inBoxContent, e);
|
94
|
}
|
108
|
}
|
95
|
}
|
109
|
}
|
|
|
110
|
+
|
|
|
111
|
+ // 发送PUSH
|
96
|
if (Objects.nonNull(pushSupplier)) {
|
112
|
if (Objects.nonNull(pushSupplier)) {
|
97
|
try {
|
113
|
try {
|
98
|
SendMessageRspBo resp = pushSupplier.get();
|
114
|
SendMessageRspBo resp = pushSupplier.get();
|
99
|
- log.info("send push success, uid {}, response {}", uid, inBoxContent, resp);
|
115
|
+ log.info("{}, send push success, response {}", logPrefix, resp);
|
100
|
} catch (Exception e) {
|
116
|
} catch (Exception e) {
|
101
|
- log.warn("send push fail, uid {}", uid, e);
|
117
|
+ log.warn("{}, send push fail", logPrefix, e);
|
102
|
}
|
118
|
}
|
103
|
}
|
119
|
}
|
104
|
|
120
|
|
105
|
- String smsContent = getSmsContent();
|
121
|
+ // 发送短信
|
|
|
122
|
+ String smsContent = getSmsContentWhenExceptionAnd(e -> {
|
|
|
123
|
+ log.warn("{}, send sms fail, get content fail", logPrefix, e);
|
|
|
124
|
+ return null;
|
|
|
125
|
+ });
|
106
|
if (Objects.nonNull(smsContent)) {
|
126
|
if (Objects.nonNull(smsContent)) {
|
107
|
try {
|
127
|
try {
|
108
|
String phone = userProxyService.getMobile(uid);
|
128
|
String phone = userProxyService.getMobile(uid);
|
109
|
if (StringUtils.isBlank(phone)) {
|
129
|
if (StringUtils.isBlank(phone)) {
|
110
|
- log.warn("send sms fail, uid {} content {} phone is blank", uid, smsContent);
|
130
|
+ log.warn("{}, send sms fail content {} phone is blank", logPrefix, smsContent);
|
111
|
} else {
|
131
|
} else {
|
112
|
List<String> mobileList = Arrays.asList(phone);
|
132
|
List<String> mobileList = Arrays.asList(phone);
|
113
|
sendSmsService.smsSendByMobile(smsContent, mobileList);
|
133
|
sendSmsService.smsSendByMobile(smsContent, mobileList);
|
114
|
- log.info("send sms success, uid {} content {} phone {} ", uid, smsContent, phone);
|
134
|
+ log.info("{}, send sms success content {} phone {} ", logPrefix, smsContent, phone);
|
115
|
}
|
135
|
}
|
116
|
} catch (Exception e) {
|
136
|
} catch (Exception e) {
|
117
|
- log.warn("send sms fail, uid {} content {}", uid, smsContent, e);
|
137
|
+ log.warn("{}, send sms fail content {}", logPrefix, smsContent, e);
|
118
|
}
|
138
|
}
|
119
|
}
|
139
|
}
|
120
|
|
140
|
|
|
|
141
|
+ // END
|
121
|
});
|
142
|
});
|
122
|
}
|
143
|
}
|
123
|
|
144
|
|
124
|
- private InboxReqVO getInBoxContent() {
|
145
|
+ private InboxReqVO getInBoxContentWhenExceptionAnd(Function<Exception, InboxReqVO> exceptionFunction) {
|
125
|
if (Objects.nonNull(inBoxContentSupplier)) {
|
146
|
if (Objects.nonNull(inBoxContentSupplier)) {
|
126
|
try {
|
147
|
try {
|
127
|
return inBoxContentSupplier.get();
|
148
|
return inBoxContentSupplier.get();
|
128
|
} catch (Exception e) {
|
149
|
} catch (Exception e) {
|
129
|
- log.warn("send in box fail, uid {} get content fail", uid, e);
|
|
|
130
|
- return null;
|
150
|
+ return exceptionFunction.apply(e);
|
131
|
}
|
151
|
}
|
132
|
} else {
|
152
|
} else {
|
133
|
return this.inBoxContent;
|
153
|
return this.inBoxContent;
|
134
|
}
|
154
|
}
|
135
|
}
|
155
|
}
|
136
|
|
156
|
|
137
|
- private String getSmsContent() {
|
157
|
+ private String getSmsContentWhenExceptionAnd(Function<Exception, String> exceptionFunction) {
|
138
|
if (Objects.nonNull(smsContentSupplier)) {
|
158
|
if (Objects.nonNull(smsContentSupplier)) {
|
139
|
try {
|
159
|
try {
|
140
|
return smsContentSupplier.get();
|
160
|
return smsContentSupplier.get();
|
141
|
} catch (Exception e) {
|
161
|
} catch (Exception e) {
|
142
|
- log.warn("send sms fail, uid {} get content fail", uid, e);
|
|
|
143
|
- return null;
|
162
|
+ return exceptionFunction.apply(e);
|
144
|
}
|
163
|
}
|
145
|
} else {
|
164
|
} else {
|
146
|
return this.smsContent;
|
165
|
return this.smsContent;
|
|
@@ -148,7 +167,6 @@ public class BaseNoticeFacade { |
|
@@ -148,7 +167,6 @@ public class BaseNoticeFacade { |
148
|
}
|
167
|
}
|
149
|
|
168
|
|
150
|
|
169
|
|
151
|
-
|
|
|
152
|
}
|
170
|
}
|
153
|
|
171
|
|
154
|
protected String buildParams(Object... objects) {
|
172
|
protected String buildParams(Object... objects) {
|
|
@@ -172,7 +190,7 @@ public class BaseNoticeFacade { |
|
@@ -172,7 +190,7 @@ public class BaseNoticeFacade { |
172
|
return req;
|
190
|
return req;
|
173
|
}
|
191
|
}
|
174
|
|
192
|
|
175
|
- protected InboxReqVO buildInboxContent(InboxBusinessTypeEnum ibt,Object... params) {
|
193
|
+ protected InboxReqVO buildInboxContent(InboxBusinessTypeEnum ibt, Object... params) {
|
176
|
InboxReqVO req = new InboxReqVO();
|
194
|
InboxReqVO req = new InboxReqVO();
|
177
|
req.setType(ibt.getType());
|
195
|
req.setType(ibt.getType());
|
178
|
req.setBusinessType(ibt.getBusinessType());
|
196
|
req.setBusinessType(ibt.getBusinessType());
|
|
@@ -184,7 +202,7 @@ public class BaseNoticeFacade { |
|
@@ -184,7 +202,7 @@ public class BaseNoticeFacade { |
184
|
return MessageFormatter.arrayFormat(content, params).getMessage();
|
202
|
return MessageFormatter.arrayFormat(content, params).getMessage();
|
185
|
}
|
203
|
}
|
186
|
|
204
|
|
187
|
- protected String buildSmsContent(InboxBusinessTypeEnum ibte, Object... params){
|
205
|
+ protected String buildSmsContent(InboxBusinessTypeEnum ibte, Object... params) {
|
188
|
return getReplacedContent(ibte.getContent(), params);
|
206
|
return getReplacedContent(ibte.getContent(), params);
|
189
|
}
|
207
|
}
|
190
|
|
208
|
|