DataCustomerService.java
4.1 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
package cn.com.glsx.entmicro.service;
import cn.com.glsx.entmicro.constants.Constants;
import cn.com.glsx.entmicro.dto.DataTotalCustomerDTO;
import cn.com.glsx.entmicro.model.CustomerStaticRequest;
import cn.com.glsx.entmicro.model.CustomerStatisticModel;
import cn.com.glsx.entmicro.model.request.CustomerSearchRequest;
import cn.com.glsx.entmicro.model.response.CustomerListResponse;
import cn.com.glsx.entmicro.util.DateFormatUtil;
import cn.com.glsx.framework.core.enums.DefaultErrorEnum;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import com.alibaba.metrics.StringUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.netty.util.internal.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author wangxw
* @version 1.0.0
* @ClassName DataCustomerService.java
* @description: ${description}
* @createTime 2021年11月21日 16:38:00
*/
@Service
public class DataCustomerService {
@Autowired
private CustomerStatisticsService customerStatisticsService;
@Autowired
private CustomerService customerService;
/**
* 统计客户数量
*
* @param merchantId
*/
public DataTotalCustomerDTO statisticCustomerTotalCount(Integer merchantId) {
DataTotalCustomerDTO resultDTO = new DataTotalCustomerDTO();
CustomerSearchRequest customerSearchRequest = new CustomerSearchRequest();
customerSearchRequest.setMerchantId(merchantId);
customerSearchRequest.setDatalist(Arrays.asList(merchantId));
customerSearchRequest.setAddWay(101);
customerSearchRequest.setUserType(1);
List<CustomerListResponse> customerListResponses = customerService.customerList(customerSearchRequest);
if (null != customerListResponses){
//魔方导入客户数
resultDTO.setMagicCount(customerListResponses.size());
List<CustomerListResponse> collect = customerListResponses.stream().filter(index -> null != index.getIsJoin()
&& index.getIsJoin() == Constants.CUSTOMER_BASE_CONSTANTS.IS_ADD_CONTACT).collect(Collectors.toList());
//魔方已加企微客户数
resultDTO.setQyCount(collect.size());
//魔方未加企微客户数
resultDTO.setUnQyCount(customerListResponses.size() - collect.size());
}else {
resultDTO.setMagicCount(0);
resultDTO.setUnQyCount(0);
resultDTO.setQyCount(0);
}
return resultDTO;
}
/**
* 统计客户数量 - 数据整理
*
* @param merchantIds
* @param startDate
* @param endDate
* @return
*/
public DataTotalCustomerDTO staticCustomerListByTime(List<Integer> merchantIds, Date startDate, Date endDate) {
DataTotalCustomerDTO resultDTO = new DataTotalCustomerDTO(0, 0, 0, 0);
if (CollectionUtils.isEmpty(merchantIds)) {
throw new RpcServiceException(DefaultErrorEnum.PARAMETER_NULL);
}
CustomerStaticRequest staticRequest = new CustomerStaticRequest();
staticRequest.setMerchantIds(merchantIds);
staticRequest.setStartTime((startDate != null) ? DateFormatUtil.toString(startDate, DateFormatUtil.pattern10) : null);
staticRequest.setEndTime((endDate != null) ? DateFormatUtil.toString(endDate, DateFormatUtil.pattern10) : null);
List<CustomerStatisticModel> customerList = customerStatisticsService.findTimeCustomerStatistic(staticRequest);
if (CollectionUtils.isEmpty(customerList)) {
return resultDTO;
}
int qyCount = (int) customerList.stream().filter(cus -> StringUtils.isNotBlank(cus.getUserId()) && cus.getFlag() == 0).count();
resultDTO.setTotalCount(customerList.size());
resultDTO.setQyCount(qyCount);//TODO 从合并表拿
resultDTO.setUnQyCount(customerList.size() - qyCount);
return resultDTO;
}
}