MassRemoteImpl.java
18.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
package cn.com.glsx.entmicro.remote;
import cn.com.glsx.entmicro.constants.Constants;
import cn.com.glsx.entmicro.dto.mass.*;
import cn.com.glsx.entmicro.entity.Mass;
import cn.com.glsx.entmicro.entity.MassDetailStaff;
import cn.com.glsx.entmicro.entity.mass.MassDetailQyMsgSendResultEntity;
import cn.com.glsx.entmicro.entity.mass.MassTemplate;
import cn.com.glsx.entmicro.enums.EntmicroExceptionEnum;
import cn.com.glsx.entmicro.manager.MassSenderComponent;
import cn.com.glsx.entmicro.manager.QyWechatExternalContactMsgComponent;
import cn.com.glsx.entmicro.model.request.MassRequest;
import cn.com.glsx.entmicro.model.request.mass.*;
import cn.com.glsx.entmicro.model.response.MassResponse;
import cn.com.glsx.entmicro.model.response.MassStaffSendStatusResponse;
import cn.com.glsx.entmicro.model.response.MassTemplateApiResponse;
import cn.com.glsx.entmicro.service.EntmicroStaffService;
import cn.com.glsx.entmicro.service.MassService;
import cn.com.glsx.entmicro.service.MassTemplateService;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.enums.DefaultErrorEnum;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.framework.core.util.RpcAssert;
import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
/**
* @author think.wang
* @version 1.0.0
* @Title GroupOneTemplateRemoteImpl
* @Package cn.com.glsx.entmicro.remote
* @Description 客户/客户群群发数据远程调用实现
* @date 2021/11/1
*/
@Slf4j
@Component
@Service(version = "1.0.0", protocol = "dubbo", timeout = 10000)
public class MassRemoteImpl implements MassRemote{
@Autowired
private MassService massService;
@Autowired
private MassSenderComponent massSenderComponent;
@Autowired
private MassTemplateService massTemplateService;
@Autowired
private QyWechatExternalContactMsgComponent qyWechatExternalContactMsgComponent;
/**
* 新增保存客户/客户群群发数据
* @param massRequest
* @return
*/
@Override
public RpcResponse<Integer> insertRemote(MassRequest massRequest) {
RpcAssert.assertNotNull(massRequest, DefaultErrorEnum.PARAMETER_NULL, "params must not be null");
RpcAssert.assertNotNull(massRequest.getUserIdList(), DefaultErrorEnum.PARAMETER_NULL, "staffid is not be null");
if (massRequest.getCrowdFunding()!=null&&massRequest.getCrowdFunding()){
String userIdList = massRequest.getUserIdList();
String[] userIds = userIdList.split(",");
for (String userId : userIds) {
MassRequest req = new MassRequest();
BeanUtils.copyProperties(massRequest,req);
req.setUserIdList(userId);
try {
saveMass(req);
} catch (Exception e) {
log.info("============staffId={}=====众筹创建群发失败:{}",userId,e);
}
}
return RpcResponse.success(0);
}else {
Integer massId = null;
try {
massId = saveMass(massRequest);
}catch (RpcServiceException e) {
log.error("新增保存客户/客户群群发数据异常:{}", e);
return RpcResponse.error(DefaultErrorEnum.SERVICE_ERROR,e.getMessage());
}catch (Exception e) {
log.error("新增保存客户/客户群群发数据异常:{}", e);
return RpcResponse.error(DefaultErrorEnum.SERVICE_ERROR);
}
if(massId==null){ //插入失败
log.info("新增保存客户/客户群群发数据插入失败!");
return RpcResponse.error(DefaultErrorEnum.DATABASE_ERROR);
}
return RpcResponse.success(massId);
}
}
private Integer saveMass(MassRequest massRequest){
Mass saveMass = null;
try {
saveMass = massService.saveMassInfo(massRequest);
}catch (RpcServiceException e) {
log.error("新增保存客户/客户群群发数据异常:{}", e);
throw new RpcServiceException(DefaultErrorEnum.SERVICE_ERROR,e.getMessage());
}catch (Exception e) {
log.error("新增保存客户/客户群群发数据异常:{}", e);
throw new RpcServiceException(DefaultErrorEnum.SERVICE_ERROR);
}
if(saveMass==null){ //插入失败
log.info("新增保存客户/客户群群发数据插入失败!");
throw new RpcServiceException(DefaultErrorEnum.DATABASE_ERROR);
}
// 定时执行的走任务中心
if(massRequest.getSendType()==Constants.MASS_SEND_TIME) {
log.info("发送定时任务到任务中心:{}", JSONObject.toJSONString(massRequest));
massService.sendMassTaskToCenter(saveMass.getUuid(), saveMass.getId(), saveMass.getSendTime());
return saveMass.getId();
}
massSenderComponent.executorMassSender(saveMass.getId(),massRequest.getParameterList());
return saveMass.getId();
}
@Override
public RpcResponse<RpcPagination<MassResponse>> listMassByPage(RpcPagination<MassRequest> pagination) {
Page<MassResponse> page = massService.getMassPage(pagination);
return RpcResponse.success(RpcPagination.copyPage(page));
}
@Override
public RpcResponse<MassResponse> getByIdRemote(Integer id) {
return RpcResponse.success(massService.getDetailSingle(id));
}
/**
* 群发任务提醒
* @param id
* @return
*/
@Override
public RpcResponse<Boolean> sendRemind(Integer id) {
RpcAssert.assertNotNull(id, DefaultErrorEnum.PARAMETER_NULL, "params must not be null");
try {
massService.sendMassRemind(id);
} catch (RpcServiceException e) {
return RpcResponse.error(e);
}
return RpcResponse.success(Boolean.TRUE);
}
/**
* 群发任务单个员工或群主提醒
* @param id 群发员工纪录表id
* @param massType
* @return
*/
@Override
public RpcResponse<Boolean> remindUserGroup(Integer id, Integer massType) {
RpcAssert.assertNotNull(id, DefaultErrorEnum.PARAMETER_NULL, "params must not be null");
RpcAssert.assertNotNull(massType, DefaultErrorEnum.PARAMETER_NULL, "params must not be null");
try {
log.info("mass detail remindUserGroup id:{}, massType:{}", id, massType);
massService.sendMassRemindStaff(id, massType);
} catch (RpcServiceException e) {
return RpcResponse.error(DefaultErrorEnum.SERVICE_ERROR);
}
return RpcResponse.success(true);
}
/**
* 客户群发详情 - 统计
* @param massId
* @return
*/
@Override
public RpcResponse<MassDetailStatisticDTO> getMassDetailStatisticInfo(Integer massId) {
RpcAssert.assertNotNull(massId, DefaultErrorEnum.PARAMETER_NULL, "params must not be null");
MassDetailStatisticDTO massDetailStatisticDTO = null;
try {
massDetailStatisticDTO = massService.statisticMassDetail(massId);
} catch (RpcServiceException e) {
return RpcResponse.error(DefaultErrorEnum.SERVICE_ERROR);
}
return RpcResponse.success(massDetailStatisticDTO);
}
/**
* 客户群发详情 - 员工列表
* @param massRequest
* @return
*/
@Override
public RpcResponse<List<MassStaffSenderItemDTO>> getMassDetailStaffList(MassDetailListRequest massRequest) {
RpcAssert.assertNotNull(massRequest, DefaultErrorEnum.PARAMETER_NULL, "params must not be null");
RpcAssert.assertNotNull(massRequest.getMassId(), DefaultErrorEnum.PARAMETER_NULL, "massId is not be null");
List<MassStaffSenderItemDTO> resultList = null;
try {
resultList = massService.getMassDetailStaffList(massRequest);
} catch (RpcServiceException e) {
return RpcResponse.error(DefaultErrorEnum.SERVICE_ERROR);
}
return RpcResponse.success(resultList);
}
/**
* 客户群发详情 - 客户列表
* @param massRequest
* @return
*/
@Override
public RpcResponse<List<MassCustomerSenderItemDTO>> getMassDetailCustomerList(MassDetailListRequest massRequest) {
RpcAssert.assertNotNull(massRequest, DefaultErrorEnum.PARAMETER_NULL, "params must not be null");
RpcAssert.assertNotNull(massRequest.getMassId(), DefaultErrorEnum.PARAMETER_NULL, "massId is not be null");
List<MassCustomerSenderItemDTO> resultList = null;
try {
resultList = massService.getMassDetailCustomerList(massRequest);
} catch (RpcServiceException e) {
return RpcResponse.error(DefaultErrorEnum.SERVICE_ERROR);
}
return RpcResponse.success(resultList);
}
/**
* 客户群群发详情 - 统计
* @param massId
* @return
*/
@Override
public RpcResponse<MassGroupDetailStatisticDTO> getMassGroupDetailStatisticInfo(Integer massId) {
RpcAssert.assertNotNull(massId, DefaultErrorEnum.PARAMETER_NULL, "params must not be null");
MassGroupDetailStatisticDTO massGroupDetailStatisticDTO = null;
try {
massGroupDetailStatisticDTO = massService.statisticMassGroupDetail(massId);
} catch (RpcServiceException e) {
return RpcResponse.error(DefaultErrorEnum.SERVICE_ERROR);
}
return RpcResponse.success(massGroupDetailStatisticDTO);
}
/**
* 客户群群发详情 - 列表
* @param massSearchRequest
* @return
*/
@Override
public RpcResponse<List<MassGroupDetailSenderDTO>> getMassGroupDetailStaffList(MassGroupStatusSearchRequest massSearchRequest) {
RpcAssert.assertNotNull(massSearchRequest, DefaultErrorEnum.PARAMETER_NULL, "params must not be null");
RpcAssert.assertNotNull(massSearchRequest.getMassId(), DefaultErrorEnum.PARAMETER_NULL, "massId is not be null");
List<MassGroupDetailSenderDTO> resultList = null;
try {
resultList = massService.getMassGroupDetailStaffList(massSearchRequest);
} catch (RpcServiceException e) {
return RpcResponse.error(DefaultErrorEnum.SERVICE_ERROR);
}
return RpcResponse.success(resultList);
}
@Override
public RpcResponse<Integer> screenCustomerCount(MassRequest massRequest) {
RpcAssert.assertNotNull(massRequest, DefaultErrorEnum.PARAMETER_NULL, "params must not be null");
RpcAssert.assertNotNull(massRequest.getUserIdList(), DefaultErrorEnum.PARAMETER_NULL, "staffid is not be null");
Integer saveMass = 0;
try {
saveMass = massService.screenCustomerCount(massRequest);
} catch (Exception e) {
log.error("客户群发 - 筛选客户数数据异常:{}", e);
RpcResponse.error(DefaultErrorEnum.SERVICE_ERROR,"客户群发 - 筛选客户数数据异常!");
}
return RpcResponse.success(saveMass);
}
@Override
public RpcResponse<MassResponse> updateMassGroupDetailList(Integer massId) {
RpcAssert.assertNotNull(massId,DefaultErrorEnum.PARAMETER_NULL,"massId param is not be null!");
try {
List<MassDetailQyMsgSendResultEntity> massDetailSendList = massService.getMassDetailSendResultByMassId(massId);
if (massDetailSendList==null||massDetailSendList.isEmpty()){
log.info("群发助手 - 发送结果和状态回收:获取未执行成功的任务列表为空!");
MassResponse response = new MassResponse();
response.setId(massId);
response.setCreatedTime(new Date());
return RpcResponse.success(response);
}
for (MassDetailQyMsgSendResultEntity msgSendResultEntity:massDetailSendList) {
qyWechatExternalContactMsgComponent.statisticQyWechatContactMessage(msgSendResultEntity);
}
} catch (Exception e) {
log.error("群发助手 - 发送结果和状态回收异常:{}", e);
RpcResponse.error(DefaultErrorEnum.SERVICE_ERROR,"群发助手 - 数据更新异常!");
}
MassResponse response = new MassResponse();
response.setId(massId);
response.setCreatedTime(new Date());
return RpcResponse.success(response);
}
@Override
public RpcResponse<List<MassTemplateApiResponse>> selectMassTemplateCreatedNameListByMerchantId(MassTemplateCreatedNamesRequest massTemplateCreatedNamesRequest) {
List<MassTemplateApiResponse> massTemplates=null;
try {
massTemplates = massTemplateService.selectMassTemplateCreatedNameListByMerchantId(massTemplateCreatedNamesRequest.getMerchantId());
} catch (Exception e) {
log.error("获取群发模板创建者列表异常:{}",e);
RpcResponse.error(DefaultErrorEnum.SERVICE_ERROR,"获取群发模板创建者列表异常!");
}
return RpcResponse.success(massTemplates);
}
@Override
public RpcResponse<Boolean> massTemplateSave(MassTemplateInsertApiRequest apiRequest) {
MassTemplate massTemplate = new MassTemplate();
BeanUtils.copyProperties(apiRequest,massTemplate);
Boolean aBoolean = null;
try {
massTemplate.setCreatedTime(new Date());
aBoolean = massTemplateService.saveMassTemplate(massTemplate);
} catch (Exception e) {
log.error("群发模板创建失败:{}",e);
return RpcResponse.error(DefaultErrorEnum.SERVICE_ERROR,"群发模板创建异常!");
}
return RpcResponse.success(aBoolean);
}
@Override
public RpcResponse<RpcPagination<MassTemplateApiResponse>> massTemplatePageSearch(RpcPagination<MassTemplateSearchApiRequest> pagination) {
Page<MassTemplateApiResponse> page = massTemplateService.massTemplatePageSearch(pagination);
return RpcResponse.success(RpcPagination.copyPage(page));
}
@Override
public RpcResponse<Boolean> massTemplateUpdate(MassTemplateUpdateApiRequest apiRequest) {
MassTemplate massTemplate = new MassTemplate();
BeanUtils.copyProperties(apiRequest,massTemplate);
Boolean aBoolean = null;
try {
aBoolean = massTemplateService.massTemplateUpdate(massTemplate);
} catch (Exception e) {
log.error("群发模板修改失败:{}",e);
return RpcResponse.error(DefaultErrorEnum.SERVICE_ERROR,"群发模板修改异常!");
}
return RpcResponse.success(aBoolean);
}
@Override
public RpcResponse<MassTemplateApiResponse> massTemplateDetail(MassTemplateSearchApiRequest apiRequest) {
RpcAssert.assertNotNull(apiRequest.getId(),DefaultErrorEnum.PARAMETER_NULL,"id param is not be null!");
MassTemplateApiResponse response=null;
try {
response = massTemplateService.massTemplateDetail(apiRequest.getId());
} catch (Exception e) {
log.error("群发模板详情查询异常:{}",e);
return RpcResponse.error(DefaultErrorEnum.SERVICE_ERROR,"群发模板详情查询异常!");
}
return RpcResponse.success(response);
}
/**
* 人群筛选条件回显跟进人列表
* @param massRequest
* @return
*/
@Override
public RpcResponse<List<MassFollowStaffEchoApi>> followerEcho(MassRequest massRequest) {
RpcAssert.assertNotEmpty(massRequest.getCrowdCondition(),DefaultErrorEnum.PARAMETER_NULL,"crowdCondition not be empty!");
try {
List<MassFollowStaffEchoApi> resp = massService.followerEcho(massRequest);
return RpcResponse.success(resp);
} catch (Exception e) {
log.info("人群筛选条件回显跟进人列表:{}",e);
return RpcResponse.error(e);
}
}
@Override
public RpcResponse<MassStaffSendStatusResponse> selectMassStaffDetail(MassStaffDetailListRpcRequest request) {
try {
MassStaffSendStatusResponse detail = massService.selectMassStaffDetail(request);
return RpcResponse.success(detail);
} catch (Exception e) {
log.info("群发员工发送状态详情查询异常:{}",e);
return RpcResponse.error(e);
}
}
@Override
public RpcResponse<MassResponse> updateMassByMerchant(MassDefaultRpcRequest request) {
try {
List<MassDetailQyMsgSendResultEntity> massDetailSendList = massService.getMassDetailSendResultJobList(request.getMerchantId());
if (massDetailSendList==null||massDetailSendList.isEmpty()){
log.info("群发助手 - 发送结果和状态回收:获取未执行成功的任务列表为空!");
MassResponse response = new MassResponse();
response.setCreatedTime(new Date());
return RpcResponse.success(response);
}
for (MassDetailQyMsgSendResultEntity msgSendResultEntity:massDetailSendList) {
qyWechatExternalContactMsgComponent.statisticQyWechatContactMessage(msgSendResultEntity);
}
} catch (RpcServiceException e) {
log.error("群发助手 - 发送结果和状态回收异常:{}", e);
RpcResponse.error(e);
}catch (Exception e) {
log.error("群发助手 - 发送结果和状态回收异常:{}", e);
RpcResponse.error(EntmicroExceptionEnum.ENTMICRO_MASS_MERCHANT_UPDATE_ERR);
}
MassResponse response = new MassResponse();
response.setCreatedTime(new Date());
return RpcResponse.success(response);
}
/**
* 客户群发客户分页列表
* @param pagination
* @return
*/
@Override
public RpcResponse<RpcPagination<MassCustomerSenderItemDTO>> getMassDetailCustomerListPage(RpcPagination<MassCustomerStatusPageRpcRequest> pagination) {
try {
Page<MassCustomerSenderItemDTO> page = massService.getMassDetailCustomerListPage(pagination);
return RpcResponse.success(RpcPagination.copyPage(page));
} catch (RpcServiceException e) {
log.info("客户群发客户分页列表查询异常:{}",e);
return RpcResponse.error(e);
}catch (Exception e) {
log.info("客户群发客户分页列表查询异常:{}",e);
return RpcResponse.error(DefaultErrorEnum.SERVICE_ERROR);
}
}
}