|
@@ -76,94 +76,144 @@ public class MiniAppServiceImpl implements IMiniAppService {
|
76
|
76
|
|
77
|
77
|
@Override
|
78
|
78
|
public void sendNoticeMessage(TaPerson toUser, String link, String name, String phone, String content, LocalDateTime dt) {
|
79
|
|
- List<String> data = new ArrayList<String>(){{
|
80
|
|
- add(name);
|
81
|
|
- add(phone);
|
82
|
|
- add(content);
|
83
|
|
- add(DateUtils.cutSecond(dt));
|
84
|
|
- }};
|
85
|
|
-
|
86
|
|
- ResponseBean res = sendSubscribeMessage(CommConstant.MINIAPP_TPL_NOTICE, toUser, link, data);
|
87
|
|
- if (res.getCode() != ResponseBean.CODE_SUCCESS) {
|
|
79
|
+ TaMiniappTemplate tpl = getTplByType(CommConstant.MINIAPP_TPL_NOTICE, toUser.getMiniappId());
|
|
80
|
+ if (null == tpl) {
|
|
81
|
+ log.error("小程序 {} 无通知消息模板 {}", toUser.getMiniappId(), CommConstant.MINIAPP_TPL_NOTICE);
|
|
82
|
+
|
88
|
83
|
// TODO
|
89
|
|
- // 使用短信发送
|
|
84
|
+ // 短信发送
|
|
85
|
+ };
|
|
86
|
+
|
|
87
|
+ if (((Boolean) true).equals(tpl.getIsSubscribe())) {
|
|
88
|
+ String[] data = new String[] { name, content, DateUtils.cutSecond(dt) };
|
|
89
|
+ ResponseBean res = sendSubscribeMessage(tpl, toUser, link, data);
|
|
90
|
+ if (res.getCode() != ResponseBean.CODE_SUCCESS) {
|
|
91
|
+ // TODO
|
|
92
|
+ // 使用短信发送
|
|
93
|
+ }
|
|
94
|
+ } else {
|
|
95
|
+ List<WxMaTemplateData> data = new ArrayList<>();
|
|
96
|
+ data.add(new WxMaTemplateData("keyword1", name, "#fffff"));
|
|
97
|
+ data.add(new WxMaTemplateData("keyword2", phone, "#fffff"));
|
|
98
|
+ data.add(new WxMaTemplateData("keyword3", content, "#fffff"));
|
|
99
|
+ data.add(new WxMaTemplateData("keyword4", DateUtils.cutSecond(dt), "#fffff"));
|
|
100
|
+
|
|
101
|
+ sendMessage(CommConstant.MINIAPP_TPL_NOTICE, toUser, link, data);
|
|
102
|
+ return;
|
90
|
103
|
}
|
91
|
104
|
}
|
92
|
105
|
|
93
|
106
|
@Override
|
94
|
107
|
public void sendHelpMessage(TaPerson toUser, String link, String result, String activityName, LocalDateTime dt) {
|
95
|
|
-// List<WxMaSubscribeData> data = new ArrayList<>();
|
96
|
|
-// data.add(new WxMaSubscribeData("keyword1", result, "#fffff"));
|
97
|
|
-// data.add(new WxMaSubscribeData("keyword2", activityName, "#fffff"));
|
98
|
|
-// data.add(new WxMaSubscribeData("keyword3", DateUtils.cutSecond(dt), "#fffff"));
|
99
|
|
-
|
100
|
|
- // WARN: break change
|
101
|
|
- List<String> data = new ArrayList<String>(){{
|
102
|
|
- add(activityName);
|
103
|
|
- add(result);
|
104
|
|
- add(DateUtils.cutSecond(dt));
|
105
|
|
- }};
|
106
|
|
-
|
107
|
|
- ResponseBean res = sendSubscribeMessage(CommConstant.MINIAPP_TPL_HELP, toUser, link, data);
|
108
|
|
- if (res.getCode() != ResponseBean.CODE_SUCCESS) {
|
|
108
|
+ TaMiniappTemplate tpl = getTplByType(CommConstant.MINIAPP_TPL_HELP, toUser.getMiniappId());
|
|
109
|
+ if (null == tpl) {
|
|
110
|
+ log.error("小程序 {} 无通知消息模板 {}", toUser.getMiniappId(), CommConstant.MINIAPP_TPL_HELP);
|
|
111
|
+
|
109
|
112
|
// TODO
|
110
|
|
- // 使用短信发送
|
|
113
|
+ // 短信发送
|
|
114
|
+ };
|
|
115
|
+
|
|
116
|
+ if (((Boolean) true).equals(tpl.getIsSubscribe())) {
|
|
117
|
+ String[] data = new String[] { activityName, result };
|
|
118
|
+ ResponseBean res = sendSubscribeMessage(tpl, toUser, link, data);
|
|
119
|
+ if (res.getCode() != ResponseBean.CODE_SUCCESS) {
|
|
120
|
+ // TODO
|
|
121
|
+ // 使用短信发送
|
|
122
|
+ }
|
|
123
|
+ } else {
|
|
124
|
+ List<WxMaTemplateData> data = new ArrayList<>();
|
|
125
|
+ data.add(new WxMaTemplateData("keyword1", result, "#fffff"));
|
|
126
|
+ data.add(new WxMaTemplateData("keyword2", activityName, "#fffff"));
|
|
127
|
+ data.add(new WxMaTemplateData("keyword3", DateUtils.cutSecond(dt), "#fffff"));
|
|
128
|
+ sendMessage(CommConstant.MINIAPP_TPL_HELP, toUser, link, data);
|
|
129
|
+ return;
|
111
|
130
|
}
|
112
|
131
|
}
|
113
|
|
-
|
|
132
|
+
|
114
|
133
|
@Override
|
115
|
134
|
public void sendGroupMessage(TaPerson toUser, String link, String result, String activityName, LocalDateTime dt) {
|
116
|
|
-// List<WxMaSubscribeData> data = new ArrayList<>();
|
117
|
|
-// data.add(new WxMaSubscribeData("keyword1", result, "#fffff"));
|
118
|
|
-// data.add(new WxMaSubscribeData("keyword2", activityName, "#fffff"));
|
119
|
|
-// data.add(new WxMaSubscribeData("keyword3", DateUtils.cutSecond(dt), "#fffff"));
|
120
|
|
-
|
121
|
|
- // WARN: break change
|
122
|
|
- List<String> data = new ArrayList<String>(){{
|
123
|
|
- add(activityName);
|
124
|
|
- add(result);
|
125
|
|
- add(DateUtils.cutSecond(dt));
|
126
|
|
- }};
|
127
|
|
-
|
|
135
|
+ TaMiniappTemplate tpl = getTplByType(CommConstant.MINIAPP_TPL_GROUP, toUser.getMiniappId());
|
|
136
|
+ if (null == tpl) {
|
|
137
|
+ log.error("小程序 {} 无通知消息模板 {}", toUser.getMiniappId(), CommConstant.MINIAPP_TPL_GROUP);
|
128
|
138
|
|
129
|
|
- ResponseBean res = sendSubscribeMessage(CommConstant.MINIAPP_TPL_GROUP, toUser, link, data);
|
130
|
|
- if (res.getCode() != ResponseBean.CODE_SUCCESS) {
|
131
|
139
|
// TODO
|
132
|
|
- // 使用短信发送
|
|
140
|
+ // 短信发送
|
|
141
|
+ };
|
|
142
|
+
|
|
143
|
+ if (((Boolean) true).equals(tpl.getIsSubscribe())) {
|
|
144
|
+ String[] data = new String[] { activityName, result };
|
|
145
|
+ ResponseBean res = sendSubscribeMessage(tpl, toUser, link, data);
|
|
146
|
+ if (res.getCode() != ResponseBean.CODE_SUCCESS) {
|
|
147
|
+ // TODO
|
|
148
|
+ // 使用短信发送
|
|
149
|
+ }
|
|
150
|
+ } else {
|
|
151
|
+ List<WxMaTemplateData> data = new ArrayList<>();
|
|
152
|
+ data.add(new WxMaTemplateData("keyword1", result, "#fffff"));
|
|
153
|
+ data.add(new WxMaTemplateData("keyword2", activityName, "#fffff"));
|
|
154
|
+ data.add(new WxMaTemplateData("keyword3", DateUtils.cutSecond(dt), "#fffff"));
|
|
155
|
+ sendMessage(CommConstant.MINIAPP_TPL_GROUP, toUser, link, data);
|
|
156
|
+ return;
|
133
|
157
|
}
|
134
|
158
|
}
|
135
|
159
|
|
136
|
160
|
@Override
|
137
|
161
|
public void sendMainBizMessage(TaPerson toUser, String link, String custName, String phone, String sex, String fromName, String bizType, String content) {
|
138
|
|
- List<String> data = new ArrayList<String>(){{
|
139
|
|
- add(custName);
|
140
|
|
- add(StringUtils.ifNull(phone, "未知"));
|
141
|
|
- add(StringUtils.ifNull(sex, "未知"));
|
142
|
|
- add(fromName);
|
143
|
|
- add(bizType);
|
144
|
|
- add(content);
|
145
|
|
- }};
|
146
|
|
-
|
147
|
|
- ResponseBean res = sendSubscribeMessage("mainbiz", toUser, link, data);
|
148
|
|
- if (res.getCode() != ResponseBean.CODE_SUCCESS) {
|
|
162
|
+ TaMiniappTemplate tpl = getTplByType("mainbiz", toUser.getMiniappId());
|
|
163
|
+ if (null == tpl) {
|
|
164
|
+ log.error("小程序 {} 无通知消息模板 {}", toUser.getMiniappId(), "mainbiz");
|
|
165
|
+
|
149
|
166
|
// TODO
|
150
|
|
- // 使用短信发送
|
|
167
|
+ // 短信发送
|
|
168
|
+ };
|
|
169
|
+
|
|
170
|
+ if (((Boolean) true).equals(tpl.getIsSubscribe())) {
|
|
171
|
+ String[] data = new String[] { custName, phone, sex, fromName, bizType, content };
|
|
172
|
+ ResponseBean res = sendSubscribeMessage(tpl, toUser, link, data);
|
|
173
|
+ if (res.getCode() != ResponseBean.CODE_SUCCESS) {
|
|
174
|
+ // TODO
|
|
175
|
+ // 使用短信发送
|
|
176
|
+ }
|
|
177
|
+ } else {
|
|
178
|
+ List<WxMaTemplateData> data = new ArrayList<>();
|
|
179
|
+ data.add(new WxMaTemplateData("keyword1", custName, "#fffff"));
|
|
180
|
+ data.add(new WxMaTemplateData("keyword2", StringUtils.ifNull(phone, "未知"), "#fffff"));
|
|
181
|
+ data.add(new WxMaTemplateData("keyword3",StringUtils.ifNull(sex, "未知"), "#fffff"));
|
|
182
|
+ data.add(new WxMaTemplateData("keyword4", fromName, "#fffff"));
|
|
183
|
+ data.add(new WxMaTemplateData("keyword5", bizType, "#fffff"));
|
|
184
|
+ data.add(new WxMaTemplateData("keyword6", content, "#fffff"));
|
|
185
|
+
|
|
186
|
+ sendMessage("mainbiz", toUser, link, data);
|
|
187
|
+ return;
|
151
|
188
|
}
|
152
|
189
|
}
|
153
|
190
|
|
154
|
191
|
@Override
|
155
|
192
|
public void sendNewCustomerMessage(TaPerson toUser, String link, String custName, String phone, String sex, String fromName) {
|
156
|
|
- List<String> data = new ArrayList<String>(){{
|
157
|
|
- add(custName);
|
158
|
|
- add(StringUtils.ifNull(phone, "未知"));
|
159
|
|
- add(StringUtils.ifNull(sex, "未知"));
|
160
|
|
- add(fromName);
|
161
|
|
- }};
|
162
|
|
-
|
163
|
|
- ResponseBean res = sendSubscribeMessage("newCustomer", toUser, link, data);
|
164
|
|
- if (res.getCode() != ResponseBean.CODE_SUCCESS) {
|
|
193
|
+ TaMiniappTemplate tpl = getTplByType("newCustomer", toUser.getMiniappId());
|
|
194
|
+ if (null == tpl) {
|
|
195
|
+ log.error("小程序 {} 无通知消息模板 {}", toUser.getMiniappId(), "newCustomer");
|
|
196
|
+
|
165
|
197
|
// TODO
|
166
|
|
- // 使用短信发送
|
|
198
|
+ // 短信发送
|
|
199
|
+ };
|
|
200
|
+
|
|
201
|
+ if (((Boolean) true).equals(tpl.getIsSubscribe())) {
|
|
202
|
+ String[] data = new String[] { custName, phone, sex, fromName };
|
|
203
|
+ ResponseBean res = sendSubscribeMessage(tpl, toUser, link, data);
|
|
204
|
+ if (res.getCode() != ResponseBean.CODE_SUCCESS) {
|
|
205
|
+ // TODO
|
|
206
|
+ // 使用短信发送
|
|
207
|
+ }
|
|
208
|
+ } else {
|
|
209
|
+ List<WxMaTemplateData> data = new ArrayList<>();
|
|
210
|
+ data.add(new WxMaTemplateData("keyword1", custName, "#fffff"));
|
|
211
|
+ data.add(new WxMaTemplateData("keyword2", StringUtils.ifNull(phone, "未知"), "#fffff"));
|
|
212
|
+ data.add(new WxMaTemplateData("keyword3",StringUtils.ifNull(sex, "未知"), "#fffff"));
|
|
213
|
+ data.add(new WxMaTemplateData("keyword4", fromName, "#fffff"));
|
|
214
|
+
|
|
215
|
+ sendMessage("newCustomer", toUser, link, data);
|
|
216
|
+ return;
|
167
|
217
|
}
|
168
|
218
|
}
|
169
|
219
|
|
|
@@ -289,20 +339,22 @@ public class MiniAppServiceImpl implements IMiniAppService {
|
289
|
339
|
}
|
290
|
340
|
}
|
291
|
341
|
|
292
|
|
- private ResponseBean sendSubscribeMessage(String tplName, TaPerson toUser, String link, List<String> data) {
|
|
342
|
+ private ResponseBean sendSubscribeMessage(TaMiniappTemplate tpl, TaPerson toUser, String link, String[] data) {
|
293
|
343
|
String appid = toUser.getMiniappId();
|
294
|
344
|
if (StringUtils.isEmpty(appid)) {
|
295
|
345
|
log.error("人员 {} 无对应来源小程序信息", toUser);
|
296
|
346
|
return ResponseBean.error("消息接收人无 appid 信息", ResponseBean.ERROR_ILLEGAL_PARAMS);
|
297
|
347
|
}
|
298
|
348
|
|
299
|
|
- TaMiniappTemplate tpl = getTplByType(tplName, toUser.getMiniappId());
|
300
|
349
|
if (null == tpl) {
|
301
|
|
- log.error("模板 {} 不存在", tplName);
|
302
|
|
- return ResponseBean.error("消息模板不存在", ResponseBean.ERROR_ILLEGAL_PARAMS);
|
|
350
|
+ return ResponseBean.error("小程序未设置消息模板", ResponseBean.ERROR_ILLEGAL_PARAMS);
|
303
|
351
|
}
|
304
|
352
|
|
305
|
|
- List<WxMaSubscribeData> sendData = createMessageData(data, tpl.getFieldNum());
|
|
353
|
+ if (StringUtils.isEmpty(tpl.getTplFields())) {
|
|
354
|
+ return ResponseBean.error("小程序消息模板未设置字段内容", ResponseBean.ERROR_ILLEGAL_PARAMS);
|
|
355
|
+ }
|
|
356
|
+
|
|
357
|
+ List<WxMaSubscribeData> sendData = createMessageData(data, tpl.getTplFields());
|
306
|
358
|
|
307
|
359
|
WxMaSubscribeMessage message = WxMaSubscribeMessage.builder()
|
308
|
360
|
.templateId(tpl.getTplId())
|
|
@@ -322,13 +374,15 @@ public class MiniAppServiceImpl implements IMiniAppService {
|
322
|
374
|
}
|
323
|
375
|
}
|
324
|
376
|
|
325
|
|
- private List<WxMaSubscribeData> createMessageData(List<String> list, Integer count) {
|
|
377
|
+ private List<WxMaSubscribeData> createMessageData(String[] list, String fieldsStr) {
|
326
|
378
|
List<WxMaSubscribeData> data = new ArrayList<>();
|
327
|
|
- if (list == null || list.size() == 0 || count == null || count == 0) return data;
|
|
379
|
+ if (list == null || list.length == 0 || StringUtils.isEmpty(fieldsStr)) return data;
|
|
380
|
+
|
|
381
|
+ String[] fileds = fieldsStr.split("\\|");
|
328
|
382
|
|
329
|
|
- int length = count > list.size() ? list.size() : count;
|
|
383
|
+ int length = fileds.length > list.length ? list.length : fileds.length;
|
330
|
384
|
for (int i = 0; i < length; i++) {
|
331
|
|
- data.add(new WxMaSubscribeData("keyword"+ (i+1), list.get(i), "#fffff"));
|
|
385
|
+ data.add(new WxMaSubscribeData(fileds[i], list[i], "#fffff"));
|
332
|
386
|
}
|
333
|
387
|
return data;
|
334
|
388
|
}
|