CommonService.java
7.73 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
package cn.com.glsx.entmicro.service;
import cn.com.glsx.entmicro.convert.ConvertRequest;
import cn.com.glsx.entmicro.model.request.RelevanceEntmicroBaseRequest;
import cn.com.glsx.entmicro.model.request.customer.CustomerExcelInputRpcRequest;
import cn.com.glsx.entmicro.remote.CommonRemote;
import cn.com.glsx.entmicro.remote.EntmicroDepartmentRemote;
import cn.com.glsx.entmicro.remote.EntmicroLoginRemote;
import cn.com.glsx.entmicro.request.common.EntmicroAuthorizeRequest;
import cn.com.glsx.entmicro.request.common.InputExcelRopRequest;
import cn.com.glsx.entmicro.request.common.LoginRequest;
import cn.com.glsx.entmicro.request.common.MerchantTreeOpenRequest;
import cn.com.glsx.entmicro.request.entmicro.RelevanceRopEntmicroBaseRequest;
import cn.com.glsx.entmicro.response.common.DictDataResponse;
import cn.com.glsx.entmicro.response.common.MerchantBaseInfoRopResponse;
import cn.com.glsx.entmicro.response.common.MerchantTreeOpenResponse;
import cn.com.glsx.entmicro.utils.RopHttpUtil;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.framework.rop.response.RopResponse;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author zhouhaibao
* @version 1.0
* @description: TODO
* @date 2021/9/27 20:02
*/
@Service
@Slf4j
public class CommonService {
@Autowired
private EntmicroDepartmentRemote entmicroDepartmentRemote;
@Autowired
private EntmicroLoginRemote entmicroLoginRemote;
@Value("${merchant.baseurl}")
private String baseurl;
@Value("${merchant.findAllDictDataMethod}")
private String findAllDictDataMethod;
@Value("${merchant.findMerchantTreeByMerchantNoMethod}")
private String findMerchantTreeByMerchantNoMethod;
@Value("${merchant.findMerchantBaseInfoMethod}")
private String findMerchantBaseInfoMethod;
@Autowired
private CommonRemote commonRemote;
// 客户来源归纳为企业微信
private static final List<Integer> WECOM_ADD_WAY_List = Arrays.asList(0,2,3,4,5,6,7,8,9,109);
/**
* 查询字典
*
* @param dictType 字典类型
* @return
*/
public List<DictDataResponse> findAllByDictType(String dictType) {
List<DictDataResponse> dictDataResponseList = null;
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(4);
params.set("dictType", dictType);
try {
RopResponse ropResponse = RopHttpUtil.get(params, RopResponse.class, baseurl, findAllDictDataMethod);
if (("0").equals(ropResponse.getCode())) {
dictDataResponseList = (List<DictDataResponse>) ropResponse.getData();
if (Objects.equals(dictType,"add_way")){
dictDataResponseList = JSON.parseArray(JSON.toJSONString(dictDataResponseList), DictDataResponse.class);
dictDataResponseList = dictDataResponseList.stream().filter(s -> !WECOM_ADD_WAY_List.contains(s.getDictValue())).collect(Collectors.toList());
DictDataResponse response = new DictDataResponse();
response.setDictType("add_way");
response.setDictValue(-1);
response.setDictLabel("企业微信");
dictDataResponseList.add(response);
}
}
} catch (Exception e) {
e.printStackTrace();
log.info("字典数据查询异常,{}", e);
}
return dictDataResponseList;
}
public List<MerchantTreeOpenResponse> findMerchantTreeByMerchantNo(MerchantTreeOpenRequest merchantTreeOpenRequest) {
List<MerchantTreeOpenResponse> merchantTreeOpenResponses = null;
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(4);
params.set("merchantId", merchantTreeOpenRequest.getMerchantId() + "");
params.set("flag", "false");
try {
RopResponse ropResponse = RopHttpUtil.get(params, RopResponse.class, baseurl, findMerchantTreeByMerchantNoMethod);
if (("0").equals(ropResponse.getCode())) {
merchantTreeOpenResponses = (List<MerchantTreeOpenResponse>) ropResponse.getData();
}
} catch (Exception e) {
e.printStackTrace();
log.info("查询商户树异常,{}", e);
}
return merchantTreeOpenResponses;
}
public Boolean relevanceEntmicro(RelevanceRopEntmicroBaseRequest relevanceRopEntmicroBaseRequest) {
log.info("企微商户关联{}", relevanceRopEntmicroBaseRequest.getList());
RpcResponse<Boolean> booleanRpcResponse = entmicroDepartmentRemote.relevanceEntmicro(ConvertRequest.convertRequest(relevanceRopEntmicroBaseRequest, new RelevanceEntmicroBaseRequest()));
if (null != booleanRpcResponse && booleanRpcResponse.isSuccess()) {
return booleanRpcResponse.getResult();
}
throw new RpcServiceException(booleanRpcResponse.getException().getErrId(), booleanRpcResponse.getMessage());
}
public Boolean findLoginCount(LoginRequest loginRequest) {
RpcResponse<Boolean> loginCount = entmicroLoginRemote.findLoginCount(loginRequest.getUuid(), loginRequest.getLoginType());
if (null != loginCount && loginCount.isSuccess()) {
return loginCount.getResult();
}
throw new RpcServiceException(loginCount.getException().getErrId(), loginCount.getMessage());
}
public MerchantBaseInfoRopResponse findMerchantInfoByMerchantNo(MerchantTreeOpenRequest merchantTreeOpenRequest) {
MerchantBaseInfoRopResponse merchantTreeOpenResponses = new MerchantBaseInfoRopResponse();
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(4);
params.set("merchantId", merchantTreeOpenRequest.getMerchantId() + "");
try {
RopResponse ropResponse = RopHttpUtil.get(params, RopResponse.class, baseurl, findMerchantBaseInfoMethod);
if (("0").equals(ropResponse.getCode())) {
Map data = (Map) ropResponse.getData();
BeanUtils.populate(merchantTreeOpenResponses, data);
}
} catch (Exception e) {
e.printStackTrace();
log.info("查询商户树异常,{}", e);
}
return merchantTreeOpenResponses;
}
public Boolean authorizeEntmicro(EntmicroAuthorizeRequest entmicroAuthorizeRequest) {
RpcResponse<Boolean> booleanRpcResponse = entmicroDepartmentRemote.authorizeEntmicro(ConvertRequest.convertRequest(entmicroAuthorizeRequest, new cn.com.glsx.entmicro.model.request.EntmicroAuthorizeRequest()));
if (null != booleanRpcResponse && booleanRpcResponse.isSuccess()) {
return booleanRpcResponse.getResult();
}
throw new RpcServiceException(booleanRpcResponse.getException().getErrId(), booleanRpcResponse.getMessage());
}
/**
* 导入excel匹配信息
* @return
*/
public Boolean inputExcelInfo(InputExcelRopRequest request) {
CustomerExcelInputRpcRequest rpcRequest = ConvertRequest.convertRequest(request, new CustomerExcelInputRpcRequest());
RpcResponse<Boolean> response = commonRemote.exportExcelRemarkExternalContact(rpcRequest);
if (response.isSuccess()) {
return response.getResult();
}
throw new RpcServiceException(response.getException().getErrId(), response.getException().getMessage());
}
}