AsyncMassService.java
6.24 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
package cn.com.glsx.entmicro.service;
import cn.com.glsx.entmicro.constants.Constants;
import cn.com.glsx.entmicro.manager.MassServiceComponent;
import cn.com.glsx.entmicro.model.request.CustListSearchRequest;
import cn.com.glsx.entmicro.model.response.CustomerInfoResponse;
import cn.com.glsx.entmicro.model.response.EntmicroStaffResponse;
import cn.com.glsx.entmicro.model.response.MassResponse;
import cn.com.glsx.entmicro.util.EmojiUtils;
import cn.com.glsx.marketing.model.request.activity.ActivityCustomerSendStatusUpdateRequest;
import cn.com.glsx.marketing.remote.activity.SolicitRemote;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Future;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @Author yelq
* @Version 1.0
* @Description:
* @Date 2022/6/4 18:34
*/
@Slf4j
@Service
public class AsyncMassService {
@Autowired
private MassService massService;
@Autowired
private MassServiceComponent massServiceComponent;
@Autowired
private SolicitRemote solicitRemote;
@Resource
private MassDetailStaffService massDetailStaffService;
@Autowired
private MassDetailCustomerService massDetailCustomerService;
@Autowired
private EntmicroStaffService entmicroStaffService;
@Autowired
private CustomerService customerService;
@Async
public Future<Map<Integer, CustomerInfoResponse>> getCustomerInfoResponseMapper(List<Integer> customerIds, Integer merchantId) {
try {
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 AsyncResult<>(new HashMap<>());
}
Map<Integer, CustomerInfoResponse> customerMapper = customerInfoResponseList.stream().collect(Collectors.toMap(CustomerInfoResponse::getId, Function.identity(), (item1, item2) -> item1));
return new AsyncResult<>(customerMapper);
} catch (Exception e) {
log.info("异步查询异常:{}",e);
}
return new AsyncResult<>(new HashMap<>());
}
@Async
public Future<Map<Integer, EntmicroStaffResponse>> getEntmicroStaffResponseMapper(List<Integer> staffIdLsit) {
try {
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 AsyncResult<>(new HashMap<>());
}
Map<Integer, EntmicroStaffResponse> staffMapper = staffResponseList.stream().collect(Collectors.toMap(EntmicroStaffResponse::getId, Function.identity(), (item1, item2) -> item1));
return new AsyncResult<>(staffMapper);
} catch (Exception e) {
log.info("异步查询异常:{}",e);
}
return new AsyncResult<>(new HashMap<>());
}
@Async
public void writeBackActivityCustomerSendStatus(Integer id) {
try {
MassResponse mass = massService.getDetailSingle(id);
if (mass != null && mass.getType() == 1 && mass.getSelectType() == Constants.MASS_ONECLICK_CONDITION && mass.getStatus() == 1) {
List<Integer> list = massService.getSendSuccessCustomerIdList(id);
List<Integer> mergeIdList = massServiceComponent.getMergeIdList(list, mass.getMerchantId());
ActivityCustomerSendStatusUpdateRequest request = new ActivityCustomerSendStatusUpdateRequest();
request.setCustomerIds(mergeIdList);
request.setMassId(id);
solicitRemote.updateCustomerSendStatus(request);
}
} catch (Exception e) {
log.info("一键营销客户接收状态回写失败:{}",e);
}
}
@Async
public Future<Map<Integer, Integer>> countStaffSender(Integer massId) {
try {
Map<Integer, Integer> massStaffCountMapper = massDetailStaffService.countStaffSender(massId);
return new AsyncResult<>(massStaffCountMapper);
} catch (Exception e) {
log.info("异步查询异常:{}",e);
}
return new AsyncResult<>(new HashMap<>());
}
@Async
public Future<Map<Integer, Integer>> countCustomerSender(Integer massId) {
try {
Map<Integer, Integer> massCustomerCountMapper = massDetailCustomerService.countCustomerSender(massId);
return new AsyncResult<>(massCustomerCountMapper);
} catch (Exception e) {
log.info("异步查询异常:{}",e);
}
return new AsyncResult<>(new HashMap<>());
}
@Async
public Future<Map<Integer, Integer>> countCustomerChatSender(Integer massId) {
try {
Map<Integer, Integer> massCustomerCountMapper = massDetailStaffService.countStaffSender(massId);
return new AsyncResult<>(massCustomerCountMapper);
} catch (Exception e) {
log.info("异步查询异常:{}",e);
}
return new AsyncResult<>(new HashMap<>());
}
}