BusiAssistantMerchantService.java
9.81 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
package cn.com.glsx.busassistant.service;
import cn.com.glsx.busassistant.converter.ConvertRequest;
import cn.com.glsx.busassistant.converter.ConvertResponse;
import cn.com.glsx.busassistant.model.request.activity.CoProductRpcRequest;
import cn.com.glsx.busassistant.model.request.activity.MerchantBySceneRemoteRpcRequest;
import cn.com.glsx.busassistant.model.request.merchant.MerchantApplyPageRequest;
import cn.com.glsx.busassistant.model.request.merchant.MerchantApplyRpcRequest;
import cn.com.glsx.busassistant.model.request.merchant.MerchantBySceneRpcRequest;
import cn.com.glsx.busassistant.model.request.merchant.MerchantConfirmRpcRequest;
import cn.com.glsx.busassistant.model.request.messageBox.MessageBoxPageRpcRequest;
import cn.com.glsx.busassistant.model.response.merchant.MerchantApplyRpcResponse;
import cn.com.glsx.busassistant.model.response.merchant.MerchantBaseRpcResponse;
import cn.com.glsx.busassistant.model.response.merchant.MerchantBySceneRpcResponse;
import cn.com.glsx.busassistant.model.response.messageBox.MessageBoxPageRpcResponse;
import cn.com.glsx.busassistant.remote.BusiAssistantMerchantRemote;
import cn.com.glsx.busassistant.remote.BusiAssistantMessageBoxRemote;
import cn.com.glsx.busassistant.request.merchant.CoProductRopRequest;
import cn.com.glsx.busassistant.request.merchant.*;
import cn.com.glsx.busassistant.request.messageBox.MessageBoxPageRopRequest;
import cn.com.glsx.busassistant.response.ServiceMerchantRopResponse;
import cn.com.glsx.busassistant.response.merchant.MerchantBaseRopResponse;
import cn.com.glsx.busassistant.response.merchant.MerchantBySceneRopResponse;
import cn.com.glsx.busassistant.response.merchant.MerchantPageRopResponse;
import cn.com.glsx.busassistant.response.merchant.MerchantRopResponse;
import cn.com.glsx.busassistant.response.messageBox.MessageBoxPageRopResponse;
import cn.com.glsx.busassistant.util.Pagination;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.enums.DefaultErrorEnum;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.merchants.model.request.serviceCenter.SearchMerchantRpcRequest;
import cn.com.glsx.merchants.model.response.serviceCenter.SearchMerchantRpcResponse;
import cn.com.glsx.merchants.remote.MerchantRemote;
import cn.com.glsx.scrm.proxy.enums.ProxyRequestSourceEnum;
import cn.com.glsx.scrm.proxy.model.CommonProxyRequest;
import cn.com.glsx.scrm.proxy.model.ProxyBaseResponse;
import cn.com.glsx.scrm.proxy.remote.CommonProxyRemote;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import java.util.ArrayList;
import java.util.List;
/**
* @Author xiongzs
* @Description 生意助手-门店服务
* @date 2022/10/16 15:18
* @Version 1.0
*/
@Service
@Slf4j
public class BusiAssistantMerchantService {
@Autowired
private BusiAssistantMerchantRemote merchantRemote;
@Autowired
private BusiAssistantMessageBoxRemote messageBoxRemote;
@Autowired
private CommonProxyRemote commonProxyRemote;
@Autowired
private MerchantRemote platformMerchantRemote;
/**
* 门店申请列表
*
* @param ropRequest
* @return
*/
public Pagination<MerchantPageRopResponse> getApplyMerchantPage(MerchantPageRopRequest ropRequest) {
MerchantApplyPageRequest rpcRequest = ConvertRequest.convertRequest(ropRequest, new MerchantApplyPageRequest());
RpcResponse<RpcPagination<MerchantApplyRpcResponse>> rpcResponse = merchantRemote.getApplyMerchantPage(rpcRequest);
if (rpcResponse.isSuccess()) {
return ConvertResponse.convertPage(rpcResponse.getResult(), MerchantPageRopResponse.class);
}
throw new RpcServiceException(rpcResponse.getError(), rpcResponse.getMessage());
}
/**
* 申请门店
*
* @param request
* @return
*/
public void addApplyMerchant(MerchantApplyRopRequest request) {
MerchantApplyRpcRequest rpcRequest = ConvertRequest.convertRequest(request, new MerchantApplyRpcRequest());
RpcResponse<Boolean> response = merchantRemote.addApplyMerchant(rpcRequest);
if (response.isFailed()) {
throw new RpcServiceException(response.getException().getErrId(), response.getMessage());
}
}
/**
* 确认开通门店
*
* @param ropRequest
*/
public void confirmMerchant(MerchantConfirmRopRequest ropRequest) {
MerchantConfirmRpcRequest rpcRequest = ConvertRequest.convertRequest(ropRequest, new MerchantConfirmRpcRequest());
RpcResponse<Boolean> response = merchantRemote.confirmMerchant(rpcRequest);
if (response.isFailed()) {
throw new RpcServiceException(response.getException().getErrId(), response.getMessage());
}
}
/**
* 根据场景查询已开通的商户
*
* @param ropRequest
*/
public List<MerchantBySceneRopResponse> findMerchantByScene(MerchantBySceneRopRequest ropRequest) {
MerchantBySceneRpcRequest rpcRequest = ConvertRequest.convertRequest(ropRequest, new MerchantBySceneRpcRequest());
RpcResponse<List<MerchantBySceneRpcResponse>> response = merchantRemote.findMerchantByScene(rpcRequest);
if (response.isSuccess()) {
return ConvertResponse.convertList(response.getResult(), MerchantBySceneRopResponse.class);
}
throw new RpcServiceException(response.getException().getErrId(), response.getMessage());
}
/**
* 查询消息列表
*
* @param pageReuest
* @return
*/
public Pagination<MessageBoxPageRopResponse> getMessageBoxPage(MessageBoxPageRopRequest pageReuest) {
MessageBoxPageRpcRequest rpcRequest = ConvertRequest.convertRequest(pageReuest, new MessageBoxPageRpcRequest());
RpcResponse<RpcPagination<MessageBoxPageRpcResponse>> rpcResponse = messageBoxRemote.getMessageBoxPage(rpcRequest);
if (rpcResponse.isSuccess()) {
return ConvertResponse.convertPage(rpcResponse.getResult(), MessageBoxPageRopResponse.class);
}
throw new RpcServiceException(rpcResponse.getError(), rpcResponse.getMessage());
}
/**
* 查询是否有未读消息
*
* @param serviceMerchantId
*/
public Boolean checkMessageReadStatus(Integer serviceMerchantId) {
RpcResponse<Boolean> response = messageBoxRemote.checkMessageReadStatus(serviceMerchantId);
if (response.isSuccess()) {
return response.getResult();
}
throw new RpcServiceException(response.getException().getErrId(), response.getMessage());
}
public MessageBoxPageRopResponse getNewestMessage(Integer serviceMerchantId) {
RpcResponse<MessageBoxPageRpcResponse> response = messageBoxRemote.getNewestMessage(serviceMerchantId);
if (response.isSuccess()) {
return ConvertResponse.convertObject(response.getResult(), MessageBoxPageRopResponse.class);
}
throw new RpcServiceException(response.getException().getErrId(), response.getMessage());
}
public Boolean addCoProduct(CoProductRopRequest ropRequest){
CoProductRpcRequest rpcRequest = ConvertRequest.convertRequest(ropRequest, new CoProductRpcRequest());
RpcResponse<Boolean> response = merchantRemote.addCoProduct(rpcRequest);
if (response.isSuccess()) {
return response.getResult();
}
throw new RpcServiceException(response.getException().getErrId(), response.getMessage());
}
public List<MerchantBaseRopResponse> getMerchantListBySceneRemote(MerchantBySceneRemoteRopRequest ropRequest){
MerchantBySceneRemoteRpcRequest rpcRequest = ConvertRequest.convertRequest(ropRequest, new MerchantBySceneRemoteRpcRequest());
RpcResponse<List<MerchantBaseRpcResponse>> response = merchantRemote.getMerchantListBySceneRemote(rpcRequest);
if (response.isSuccess()) {
return ConvertResponse.convertList(response.getResult(), MerchantBaseRopResponse.class);
}
throw new RpcServiceException(response.getException().getErrId(), response.getMessage());
}
public List<MerchantRopResponse> getMerchantIdByMerchantNo(MerchantRopRequest request){
final String requestMethod = "merchants.api.open.findMerchantList";
CommonProxyRequest proxyRequest = new CommonProxyRequest();
LinkedMultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("merchantNoStr",request.getMerchantNos());
proxyRequest.setRequestMethod(requestMethod);
proxyRequest.setRequestSource(ProxyRequestSourceEnum.MERCHANT.getSource());
proxyRequest.setParams(params);
RpcResponse<ProxyBaseResponse> response = commonProxyRemote.proxyRequest(proxyRequest);
if (!response.hasResult()){
throw new RpcServiceException(DefaultErrorEnum.RPC_ERROR.getValue(),"查询商户详情失败");
}
return response.getResult().getList(MerchantRopResponse.class);
}
public List<ServiceMerchantRopResponse> selectMerchantPage(SearchMerchantRpcRequest rpcRequest){
RpcResponse<RpcPagination<SearchMerchantRpcResponse>> merchantRpcPage = platformMerchantRemote.searchByMerchantNos(rpcRequest);
List<ServiceMerchantRopResponse> resultList = new ArrayList<>();
if (!merchantRpcPage.hasResult()){
log.error("查询商户分页失败");
return resultList;
}
List<SearchMerchantRpcResponse> list = merchantRpcPage.getResult().getList();
list.forEach(v->{
ServiceMerchantRopResponse response = new ServiceMerchantRopResponse();
BeanUtils.copyProperties(v,response);
resultList.add(response);
});
return resultList;
}
}