MassDetailCustomerService.java
4.94 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
package cn.com.glsx.entmicro.service;
import cn.com.glsx.entmicro.constants.Constants;
import cn.com.glsx.entmicro.entity.MassChatDetail;
import cn.com.glsx.entmicro.entity.MassDetailCustomer;
import cn.com.glsx.entmicro.entity.mass.MassCustomerItemEntity;
import cn.com.glsx.entmicro.entity.mass.MassStatisticItemEntity;
import cn.com.glsx.entmicro.mapper.MassDetailCustomerMapper;
import cn.com.glsx.entmicro.model.response.MassDetailStaffResponse;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.scrm.wechat.dto.workwechat.externalmsg.response.GetWorkWechatExternalContactGroupMsgSendResultDTO;
import com.github.pagehelper.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import tk.mybatis.mapper.entity.Example;
import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Slf4j
@Service
public class MassDetailCustomerService {
@Resource
private MassDetailCustomerMapper massDetailCustomerMapper;
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = {RpcServiceException.class})
public Boolean batchSaveMassDetailCustomer(List<MassDetailCustomer> massDetailCustomerList) {
massDetailCustomerMapper.insertList(massDetailCustomerList);
return true;
}
/**
* 获取 群发中的客户列表
* @param relationId
* @return
*/
public List<MassDetailCustomer> getMassDetailCustomerListByRelationId(Integer relationId) {
Example selectCondition = new Example(MassDetailCustomer.class);
selectCondition.createCriteria().andEqualTo("staffRelationId", relationId);
List<MassDetailCustomer> customerList = massDetailCustomerMapper.selectByExample(selectCondition);
return customerList;
}
public Map<Integer, Integer> countCustomerSender(Integer massId) {
List<MassStatisticItemEntity> massStatisticItemEntityList = massDetailCustomerMapper.countCustomerSender(massId);
if (CollectionUtils.isEmpty(massStatisticItemEntityList)) {
return new HashMap<>();
}
Map<Integer, Integer> result = massStatisticItemEntityList.stream().collect(Collectors.toMap(MassStatisticItemEntity::getDataType, MassStatisticItemEntity::getDataCount, (item1, item2) -> item1));
return result;
}
public List<MassCustomerItemEntity> getCustomerListByMassIdAndStatus(Integer massId, Integer status) {
List<MassCustomerItemEntity> result = massDetailCustomerMapper.getCustomerListByMassIdAndStatus(massId, status);
return result;
}
public Page<MassCustomerItemEntity> getCustomerListByMassIdAndStatusPage(Integer massId, Integer status) {
Page<MassCustomerItemEntity> result = massDetailCustomerMapper.getCustomerListByMassIdAndStatusPage(massId, status);
return result;
}
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = {RpcServiceException.class})
public void updateMassDetailCustomerSendResult(Integer staffRelationId, Integer customerId, GetWorkWechatExternalContactGroupMsgSendResultDTO msgSendResultDTO) {
Date sendTime = (msgSendResultDTO.getSendTime()!=null)?new Date(msgSendResultDTO.getSendTime()*1000L):null;
massDetailCustomerMapper.updateMassDetailCustomerSendResult(staffRelationId, customerId, msgSendResultDTO.getStatus(), sendTime);
}
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = {RpcServiceException.class})
public void updateMassDetailCustomerSendResult(Integer staffRelationId, String external_user_id, Integer status) {
massDetailCustomerMapper.updateMassDetailCustomerStatusByExternalUserId(staffRelationId, external_user_id, status);
}
/**
* 根据massId统计客户数量
* @param massId
* @return
*/
public Integer countCustomers(Integer massId) {
if (massId==null){
return null;
}
Integer num = massDetailCustomerMapper.countCustomers(massId);
return num;
}
@Async
public void updateFailListCustomer(List<String> failList, MassDetailStaffResponse staffResponse) {
try {
if (failList!=null&&!failList.isEmpty()){
for (String s : failList) {
updateMassDetailCustomerSendResult(staffResponse.getId(),s, Constants.MASS_DETAIL_CUSTOMER_STATUS.SEND_ERROR_FOR_UNFRIEND);
}
}
} catch (Exception e) {
log.info("更新客户接收失败异常:{}",e);
}
}
public List<Integer> getSendSuccessCustomerIdList(Integer massId){
if (massId==null){return null;}
return massDetailCustomerMapper.getSendSuccessCustomerIdList(massId);
}
}