MassServiceComponent.java
15.3 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
package cn.com.glsx.entmicro.manager;
import cn.com.glsx.datahub.dto.UserQueryByCrowIdListDTO;
import cn.com.glsx.datahub.remote.UserProfileRemote;
import cn.com.glsx.entmicro.entity.MassCondition;
import cn.com.glsx.entmicro.entity.mass.MassChatItemEntity;
import cn.com.glsx.entmicro.model.request.CustBaseSearchRequest;
import cn.com.glsx.entmicro.model.request.CustListSearchRequest;
import cn.com.glsx.entmicro.model.request.mass.LabelRequest;
import cn.com.glsx.entmicro.model.request.mass.MassConditionCrowdRequest;
import cn.com.glsx.entmicro.model.response.*;
import cn.com.glsx.entmicro.service.*;
import cn.com.glsx.entmicro.service.common.CommonService;
import cn.com.glsx.entmicro.util.EmojiUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.metrics.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @author wangxw
* @version 1.0.0
* @ClassName MassServiceComponent.java
* @description: 客户群发 员工数据整合
* @createTime 2021年11月17日 20:18:00
*/
@Slf4j
@Component
public class MassServiceComponent {
@Autowired
private EntmicroStaffService entmicroStaffService;
@Autowired
private CustomerService customerService;
@Autowired
private CustomerBaseService customerBaseService;
@Autowired
private EntmicroDepartmentService entmicroDepartmentService;
@Autowired
private RopCommonServie ropCommonServie;
@Autowired
private UserProfileRemote userProfileRemote;
@Autowired
private CommonService commonService;
public Map<Integer, EntmicroStaffResponse> getEntmicroStaffResponseMapper(List<Integer> staffIdLsit) {
List<EntmicroStaffResponse> staffResponseList = entmicroStaffService.findStaffByStaffIds(staffIdLsit);
staffResponseList.forEach(index -> {
//Emoji转化
index.setStaffName(com.glsx.plat.common.utils.StringUtils.isNotEmpty(index.getStaffName()) ? EmojiUtils.parseToUnicode(index.getStaffName()) : null);
index.setEntmicroName(com.glsx.plat.common.utils.StringUtils.isNotEmpty(index.getEntmicroName()) ? EmojiUtils.parseToUnicode(index.getEntmicroName()) : null);
});
if (CollectionUtils.isEmpty(staffResponseList)) {
return new HashMap<>();
}
Map<Integer, EntmicroStaffResponse> staffMapper = staffResponseList.stream().collect(Collectors.toMap(EntmicroStaffResponse::getId, Function.identity(), (item1, item2) -> item1));
return staffMapper;
}
public Map<Integer, CustomerInfoResponse> getCustomerInfoResponseMapper(List<Integer> customerIds, Integer merchantId) {
CustListSearchRequest custSearchRequest = new CustListSearchRequest();
custSearchRequest.setCustIds(customerIds);
custSearchRequest.setMerchantId(merchantId);
List<CustomerInfoResponse> customerInfoResponseList = customerService.findCustomerByCondition(custSearchRequest);
customerInfoResponseList.forEach(index -> {
index.setCustomerName(com.glsx.plat.common.utils.StringUtils.isNotEmpty(index.getCustomerName()) ? EmojiUtils.parseToUnicode(index.getCustomerName()) : null);
});
if (CollectionUtils.isEmpty(customerInfoResponseList)) {
return new HashMap<>();
}
Map<Integer, CustomerInfoResponse> customerMapper = customerInfoResponseList.stream().collect(Collectors.toMap(CustomerInfoResponse::getId, Function.identity(), (item1, item2) -> item1));
return customerMapper;
}
public Map<String, CustomerInfoResponse> getCustomerInfoResponseMapperByExternalUserIds(List<String> customerUserIds) {
if (CollectionUtils.isEmpty(customerUserIds)) {
return new HashMap<>();
}
List<CustomerInfoResponse> customerInfoList = new ArrayList<>();
for (String userId : customerUserIds) {
CustomerInfoResponse customerInfoResponse = customerService.getCustomerInfoByExternalUserId(userId);
if (customerInfoResponse == null) {
continue;
}
customerInfoList.add(customerInfoResponse);
}
if (CollectionUtils.isEmpty(customerInfoList)) {
return new HashMap<>();
}
Map<String, CustomerInfoResponse> customerInfoResponseMap = customerInfoList.stream().collect(Collectors.toMap(CustomerInfoResponse::getUserid, Function.identity(), (item1, item2) -> item1));
return customerInfoResponseMap;
}
public Map<String, CustomerBaseInfoResponse> getCustomerBaseInfoByChatIds(List<String> chatIds, Integer merchantId) {
if (CollectionUtils.isEmpty(chatIds)) {
return new HashMap<>();
}
CustBaseSearchRequest custBaseSearchRequest = new CustBaseSearchRequest();
custBaseSearchRequest.setChantIds(chatIds);
custBaseSearchRequest.setMerchantId(merchantId);
List<CustomerBaseInfoResponse> customerBaseInfoResponseList = customerBaseService.findCustBaseByContion(custBaseSearchRequest);
if (CollectionUtils.isEmpty(customerBaseInfoResponseList)) {
return new HashMap<>();
}
Map<String, CustomerBaseInfoResponse> customerBaseMap = customerBaseInfoResponseList.stream().collect(Collectors.toMap(CustomerBaseInfoResponse::getChatId, Function.identity(), (item1, item2) -> item1));
return customerBaseMap;
}
public List<CustomerInfoResponse> filterCustomerListByCondtion(MassCondition condition, Integer merchantId, List<Integer> staffIds) {
CustListSearchRequest searchRequest = new CustListSearchRequest();
List<Integer> chatIds = null;
if (condition != null) {
if (StringUtils.isNotBlank(condition.getChatId())) {
String[] idsArray = condition.getChatId().split(",");
chatIds = new ArrayList<>(idsArray.length);
for (String idStr : idsArray) {
chatIds.add(Integer.parseInt(idStr));
}
}
searchRequest.setSex((condition.getSex() != null) ? condition.getSex().intValue() : null);
searchRequest.setStartTime(condition.getStartTime());
searchRequest.setEndTime(condition.getEndTime());
}
searchRequest.setMerchantId(merchantId);
searchRequest.setStaffIds(staffIds);
searchRequest.setChantIds(chatIds);
List<CustomerInfoResponse> infoResponseList = customerService.findCustomerByCondition(searchRequest);
if (condition != null && !infoResponseList.isEmpty() && condition.getLabelList() != null && !condition.getLabelList().isEmpty()) {
return labelFilteringCustomers(infoResponseList, condition.getLabelList(), merchantId,condition.getCombineType());
}
return infoResponseList;
}
/**
* 根据条件删选客户
*
* @param searchRequest 入参
* @return
*/
public List<CustomerInfoResponse> findCustomerByCondition(CustListSearchRequest searchRequest) {
List<CustomerInfoResponse> infoResponseList = customerService.findCustomerByCondition(searchRequest);
if (!infoResponseList.isEmpty() && searchRequest.getLabelList() != null && !searchRequest.getLabelList().isEmpty()) {
return labelFilteringCustomers(infoResponseList, searchRequest.getLabelList(), searchRequest.getMerchantId(),searchRequest.getCombineType());
}
return infoResponseList;
}
/**
* 根据标签筛选客户列表
*
* @param customers 原始客户列表
* @param labelList 标签列表
* @param merchantId 门店商户号
* @Return 筛选后的客户列表
*/
public List<CustomerInfoResponse> labelFilteringCustomers(List<CustomerInfoResponse> customers, List<LabelRequest> labelList, Integer merchantId,Integer combineType) {
log.info("标签筛选客户入参:customers:{},=====labelList:{},======merchantId:{},=======combineType:{}", JSON.toJSONString(customers), JSON.toJSONString(labelList), merchantId,combineType);
if (customers == null || labelList == null || customers.isEmpty() || labelList.isEmpty()) {
return customers;
}
List<String> oneIds = customers.stream().map(CustomerInfoResponse::getOneId).collect(Collectors.toList());
if (oneIds.isEmpty()) {
log.info("标签筛选客户oneId列表为空!");
return customers;
}
List<String> oneIdsResp = ropCommonServie.labelFilterCustomersOneId(labelList, merchantId,combineType);
if (oneIdsResp == null || oneIdsResp.isEmpty()) {
return new ArrayList<>();
}
List<CustomerInfoResponse> collect = customers.stream().filter(s -> oneIdsResp.contains(s.getOneId())).collect(Collectors.toList());
return collect;
}
public Map<Integer, CustomerBaseInfoResponse> getCustomerBaseInfoByIds(List<Integer> ids, Integer merchantId) {
if (CollectionUtils.isEmpty(ids)) {
return new HashMap<>();
}
CustBaseSearchRequest custBaseSearchRequest = new CustBaseSearchRequest();
custBaseSearchRequest.setIds(ids);
custBaseSearchRequest.setMerchantId(merchantId);
List<CustomerBaseInfoResponse> customerBaseInfoResponseList = customerBaseService.findCustBaseByContion(custBaseSearchRequest);
if (CollectionUtils.isEmpty(customerBaseInfoResponseList)) {
return new HashMap<>();
}
Map<Integer, CustomerBaseInfoResponse> customerBaseMap = customerBaseInfoResponseList.stream().collect(Collectors.toMap(CustomerBaseInfoResponse::getId, Function.identity(), (item1, item2) -> item1));
return customerBaseMap;
}
/**
* 根据客户群表主键查询群名称、群成员数量
*
* @param ids
* @param merchantId
* @return
*/
public Map<Integer, MassChatItemEntity> getMassChatItemEntityInfoByIds(List<Integer> ids, Integer merchantId) {
Map<Integer, MassChatItemEntity> massChatItemEntityInfoByIds = customerBaseService.getMassChatItemEntityInfoByIds(ids, merchantId);
return massChatItemEntityInfoByIds;
}
/**
* 根据员工id列表查询部门名称
*
* @param staffIds
* @param merchantId
* @return
*/
public Map<Integer, EntmicroStaffResponse> getMassDepartmentName(List<Integer> staffIds, Integer merchantId) {
Map<Integer, EntmicroStaffResponse> massDepartmentName = entmicroDepartmentService.getMassDepartmentName(staffIds, merchantId);
return (massDepartmentName == null) ? new HashMap<>() : massDepartmentName;
}
/**
* 人群条件和员工信息查询客户列表
* @param crowdRequests
* @param merchantId
* @param staffIds
* @return
*/
public List<CustomerInfoResponse> filterCustomerListByDCrowdCondtion(Integer combineType,List<MassConditionCrowdRequest> crowdRequests, Integer merchantId, List<Integer> staffIds) {
CustListSearchRequest searchRequest = new CustListSearchRequest();
searchRequest.setMerchantId(merchantId);
searchRequest.setStaffIds(staffIds);
List<CustomerInfoResponse> infoResponseList = customerService.findCustomerByCondition(searchRequest);
if (!infoResponseList.isEmpty() && crowdRequests != null && !crowdRequests.isEmpty()) {
return labelFilteringCustomersBycrowd(infoResponseList, combineType,crowdRequests, merchantId);
}
return infoResponseList;
}
private List<CustomerInfoResponse> labelFilteringCustomersBycrowd(List<CustomerInfoResponse> infoResponseList, Integer combineType,List<MassConditionCrowdRequest> crowdRequests, Integer merchantId) {
List<String> customerOneIds = infoResponseList.stream().map(CustomerInfoResponse::getOneId).collect(Collectors.toList());
if (customerOneIds==null||customerOneIds.isEmpty()){
log.info("员工下客户oneId列表为空!");
return new ArrayList<>();
}
List<String> oneIdsResp = labelFilterCustomersOneIdBycrowd(combineType,crowdRequests, merchantId);
if (oneIdsResp == null || oneIdsResp.isEmpty()) {
return new ArrayList<>();
}
List<CustomerInfoResponse> collect = infoResponseList.stream().filter(s -> oneIdsResp.contains(s.getOneId())).collect(Collectors.toList());
return collect;
}
/**
* 人群筛选返回跟进人列表
*
* @param combineType
* @param crowdRequests
* @param merchantId
* @return
*/
public List<StaffFollowResponse> filterFollowerListByCondition(Integer combineType, List<MassConditionCrowdRequest> crowdRequests, Integer merchantId) {
//人群筛选客户oneId列表
List<String> oneIdsResp = labelFilterCustomersOneIdBycrowd(combineType, crowdRequests, merchantId);
if (oneIdsResp == null || oneIdsResp.isEmpty()) {
return new ArrayList<>();
}
//查询跟进人列表
List<StaffFollowResponse> list = entmicroStaffService.filterFollowerListByCondition(oneIdsResp,merchantId);
return weightRemoval(list);
}
//跟进人去重
public List<StaffFollowResponse> weightRemoval(List<StaffFollowResponse> list){
if (list==null||list.isEmpty()){
return list;
}
List<StaffFollowResponse> responses = new ArrayList<>();
Set<Integer> set = new HashSet<>();
list.forEach(s->{
if (set.add(s.getStaffId())){
s.setStaffName(EmojiUtils.parseToUnicode(s.getStaffName()));
s.setId(s.getStaffId());
responses.add(s);
}
});
return responses;
}
public List<String> labelFilterCustomersOneIdBycrowd(Integer combineType,List<MassConditionCrowdRequest> crowdRequests, Integer merchantId){
UserQueryByCrowIdListDTO.UserQueryByCrowIdListReq req = new UserQueryByCrowIdListDTO.UserQueryByCrowIdListReq();
req.setMerchantId(merchantId);
req.setPageNum(1);
req.setPageSize(Integer.MAX_VALUE);
req.setCombineType(combineType);
List<Integer> crowIdList = new ArrayList<>();
crowdRequests.forEach(s->crowIdList.add(s.getCrowdId()));
req.setCrowIdList(crowIdList);
log.info("调用标签的人群筛选参数:{}",JSON.toJSONString(req,true));
UserQueryByCrowIdListDTO.UserQueryByCrowIdListRet response = userProfileRemote.queryOneIdListByCrowIdList(req);
log.info("调用标签的人群筛选返回:{}",JSON.toJSONString(response,true));
if (response!=null&&response.getCode()==0){
return response.getOneIdList();
}
return null;
}
/**
* 根据员工id列表查询员工为群主的群所对应表id列表
* @param merchantId
* @param staffIds
* @return
*/
public List<CustGroupResponse> filterCustomerChatIdsByStaffIds(Integer merchantId, List<Integer> staffIds) {
List<CustGroupResponse> chatIds = customerService.filterCustomerChatIdsByStaffIds(merchantId,staffIds);
return chatIds;
}
/**
* 根据客户表id列表查询客户合并表id列表
* @param customerIds
* @return
*/
public List<Integer> getMergeIdList(List<Integer> customerIds,Integer merchantId){
return customerService.getMergeIdList(customerIds,merchantId);
}
}