MerchantService.java
15.8 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
package cn.com.glsx.merchants.service;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.merchants.convert.ConvertRequest;
import cn.com.glsx.merchants.convert.ConvertResponse;
import cn.com.glsx.merchants.model.request.*;
import cn.com.glsx.merchants.model.request.MerchantBrandRequest;
import cn.com.glsx.merchants.model.response.*;
import cn.com.glsx.merchants.remote.MerchantRemote;
import cn.com.glsx.merchants.request.accounttype.AccountTypeSearchRequest;
import cn.com.glsx.merchants.request.merchant.*;
import cn.com.glsx.merchants.request.role.RoleSearchRequest;
import cn.com.glsx.merchants.response.*;
import cn.com.glsx.merchants.util.Pagination;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
/**
* @author zhouhaibao
* @version 1.0
* @description: 商户服务
* @date 2021/7/21 17:06
*/
@Service
public class MerchantService {
@Autowired
private MerchantRemote merchantRemote;
@Autowired
private MerchantUserService merchantUserService;
/**
* 保存商户
*
* @param merchantSaveRequest 入参
*/
public Integer saveMerchant(MerchantSaveRequest merchantSaveRequest) {
RpcResponse<Integer> booleanRpcResponse = merchantRemote.saveMerchantRemote(converMerchant(merchantSaveRequest));
if (booleanRpcResponse.isSuccess()) {
return booleanRpcResponse.getResult();
}
throw new RpcServiceException(booleanRpcResponse.getException().getErrId(), booleanRpcResponse.getMessage());
}
private MerchantRequest converMerchant(MerchantSaveRequest merchantSaveRequest) {
MerchantRequest merchantRequest = ConvertRequest.convertRequest(merchantSaveRequest, new MerchantRequest());
String merchantFiles = merchantSaveRequest.getMerchantFiles();
String merchantBrandListJson = merchantSaveRequest.getMerchantBrandListJson();
if(StringUtils.isNotEmpty(merchantBrandListJson))
merchantRequest.setMerchantBrandList(JSONObject.parseArray(merchantBrandListJson, MerchantBrandRequest.class));
if (StringUtils.isNotEmpty(merchantFiles)) {
merchantRequest.setMerchantFiles(JSONObject.parseArray(merchantFiles, MerchantFileRequest.class));
}
return merchantRequest;
}
private MerchantRequest converUpdateMerchant(MerchantUpdateRequest merchantUpdateRequest) {
MerchantRequest merchantRequest = ConvertRequest.convertRequest(merchantUpdateRequest, new MerchantRequest());
String merchantFiles = merchantUpdateRequest.getMerchantFiles();
String merchantBrandListJson = merchantUpdateRequest.getMerchantBrandListJson();
if(StringUtils.isNotEmpty(merchantBrandListJson))
merchantRequest.setMerchantBrandList(JSONObject.parseArray(merchantBrandListJson, MerchantBrandRequest.class));
if (StringUtils.isNotEmpty(merchantFiles)) {
merchantRequest.setMerchantFiles(JSONObject.parseArray(merchantFiles, MerchantFileRequest.class));
}
return merchantRequest;
}
/**
* 更新商户
*
* @param merchantUpdateRequest 入参
*/
public void updateMerchant(MerchantUpdateRequest merchantUpdateRequest) {
RpcResponse<Boolean> booleanRpcResponse = merchantRemote.updateMerchantRemote(converUpdateMerchant(merchantUpdateRequest));
if (booleanRpcResponse.isFailed()) {
throw new RpcServiceException(booleanRpcResponse.getException().getErrId(), booleanRpcResponse.getMessage());
}
}
/**
* 保存商户权限
*
* @param merchantTreeRequest 入参
*/
public void savePermissions(MerchantTreeRopRequest merchantTreeRequest) {
MerchantTreeRequest merchantTree = ConvertRequest.convertRequest(merchantTreeRequest, new MerchantTreeRequest());
String accountTypes = merchantTreeRequest.getAccountTypes();
if (StringUtils.isNotEmpty(accountTypes)) {
merchantTree.setAccountTypes(JSONObject.parseArray(accountTypes, AccountTypeTreeRequest.class));
}
RpcResponse<Boolean> booleanRpcResponse = merchantRemote.savePermissionsRemote(merchantTree);
if (booleanRpcResponse.isFailed()) {
throw new RpcServiceException(booleanRpcResponse.getException().getErrId(), booleanRpcResponse.getMessage());
}
}
/**
* 更新商户权限
*
* @param merchantTreeRequest 入参
*/
public void updatePermissions(MerchantTreeRopRequest merchantTreeRequest) {
MerchantTreeRequest merchantTree = ConvertRequest.convertRequest(merchantTreeRequest, new MerchantTreeRequest());
String accountTypes = merchantTreeRequest.getAccountTypes();
if (StringUtils.isNotEmpty(accountTypes)) {
merchantTree.setAccountTypes(JSONObject.parseArray(accountTypes, AccountTypeTreeRequest.class));
}
RpcResponse<Boolean> booleanRpcResponse = merchantRemote.updatePermissionsRemote(merchantTree);
if (booleanRpcResponse.isFailed()) {
throw new RpcServiceException(booleanRpcResponse.getException().getErrId(), booleanRpcResponse.getMessage());
}
}
/**
* 查询商户详情
*
* @param merchantDetailRequest
* @return
*/
public MerchantRopResponse findMerchantDetail(MerchantDetailRequest merchantDetailRequest) {
RpcResponse<MerchantResponse> merchantDetailRemote = merchantRemote.findMerchantDetailRemote(ConvertRequest.convertRequest(merchantDetailRequest, new MerchantRequest()));
if (merchantDetailRemote.isSuccess()) {
return ConvertResponse.convertObject(merchantDetailRemote.getResult(), MerchantRopResponse.class);
}
throw new RpcServiceException(merchantDetailRemote.getException().getErrId(), merchantDetailRemote.getMessage());
}
/**
* 查询商户树
*
* @param merchantDetailRequest 入参
* @return
*/
public List<MerchantTreeRopResponse> findMerchantTree(MerchantDetailRequest merchantDetailRequest) {
RpcResponse<List<MerchantTreeResponse>> merchantDetailRemote = merchantRemote.findMerchantTreeRemote(ConvertRequest.convertRequest(merchantDetailRequest, new MerchantRequest()));
if (merchantDetailRemote.isSuccess()) {
return ConvertResponse.convertList(merchantDetailRemote.getResult(), MerchantTreeRopResponse.class);
}
throw new RpcServiceException(merchantDetailRemote.getException().getErrId(), merchantDetailRemote.getMessage());
}
/**
* 查询商户的菜单权限
*
* @param merchantDetailRequest 入参
* @return
*/
public List<AccountTypeTreeRopResponse> findPermissionsByMerId(MerchantDetailRequest merchantDetailRequest) {
RpcResponse<List<AccountTypeTreeResponse>> merchantDetailRemote = merchantRemote.findPermissionsByMerId(merchantDetailRequest.getId());
if (merchantDetailRemote.isSuccess()) {
return ConvertResponse.convertList(merchantDetailRemote.getResult(), AccountTypeTreeRopResponse.class);
}
throw new RpcServiceException(merchantDetailRemote.getException().getErrId(), merchantDetailRemote.getMessage());
}
/**
* 查询商户的菜单权限树
*
* @param merchantDetailRequest 入参
* @return
*/
public List<AccountTypeTreeRopResponse> findMenuFunTreeByMerId(MerchantDetailRequest merchantDetailRequest) {
RpcResponse<List<AccountTypeTreeResponse>> merchantDetailRemote = merchantRemote.findMenuFunTreeByMerId(merchantDetailRequest.getId(), merchantDetailRequest.getAccountlevel(), merchantDetailRequest.getParentId());
if (merchantDetailRemote.isSuccess()) {
return ConvertResponse.convertList(merchantDetailRemote.getResult(), AccountTypeTreeRopResponse.class);
}
throw new RpcServiceException(merchantDetailRemote.getException().getErrId(), merchantDetailRemote.getMessage());
}
/**
* 更新商户的有效期
*
* @param merchantUpdateValRequest 入参
* @return
*/
public void updateValPerByMerId(MerchantUpdateValRequest merchantUpdateValRequest) {
RpcResponse<Boolean> booleanRpcResponse = merchantRemote.updateValPerByMerId(ConvertRequest.convertRequest(merchantUpdateValRequest, new MerchantRequest()));
if (booleanRpcResponse.isFailed()) {
throw new RpcServiceException(booleanRpcResponse.getException().getErrId(), booleanRpcResponse.getMessage());
}
}
/**
* 查询商户的列表
*
* @param merchantSearchResquest 入参
* @return
*/
public Pagination<MerchantRopResponse> findMerchantByPage(MerchantSearchResquest merchantSearchResquest) {
RpcPagination<MerchantRequest> merchantRequestRpcPagination = ConvertRequest.convertPage(merchantSearchResquest, new MerchantRequest());
MerchantRequest condition = merchantRequestRpcPagination.getCondition();
Integer superMerchantNo = merchantSearchResquest.getSuperMerchantNo();
condition.setSuperMerchantNo(superMerchantNo);
RpcResponse<RpcPagination<MerchantResponse>> merProductByPageRemote = merchantRemote.findMerchantByPageRemote(merchantRequestRpcPagination);
if (merProductByPageRemote.isSuccess()) {
return ConvertResponse.convertPage(merProductByPageRemote.getResult(), MerchantRopResponse.class);
}
throw new RpcServiceException(merProductByPageRemote.getException().getErrId(), merProductByPageRemote.getMessage());
}
/**
* 查询所有商户
*
* @return
*/
public List<MerchantRopListRes> findAllMerchant(MerchantFindRequest merchantFindRequest) {
RpcResponse<List<MerchantResponse>> allMerchantRemote = merchantRemote.findAllMerchantRemote(ConvertRequest.convertRequest(merchantFindRequest, new MerchantRequest()));
if (allMerchantRemote.isSuccess()) {
return ConvertResponse.convertList(allMerchantRemote.getResult(), MerchantRopListRes.class);
}
throw new RpcServiceException(allMerchantRemote.getException().getErrId(), allMerchantRemote.getMessage());
}
/**
* 查询上下级商户
*
* @return
*/
public MerchantRopResponse findSubordinateRelationship(MerchantDetailRequest merchantDetailRequest) {
RpcResponse<MerchantResponse> allMerchantRemote = merchantRemote.findSubordinateRelationshipRemote(ConvertRequest.convertRequest(merchantDetailRequest, new MerchantRequest()));
if (allMerchantRemote.isSuccess()) {
return ConvertResponse.convertObject(allMerchantRemote.getResult(), MerchantRopResponse.class);
}
throw new RpcServiceException(allMerchantRemote.getException().getErrId(), allMerchantRemote.getMessage());
}
public List<AccountTypeTreeRopResponse> findMenuFunTreeByAccountType(AccountTypeSearchRequest accountTypeSearchRequest) {
String[] split = accountTypeSearchRequest.getIds().split(",");
List<Integer> strings = new ArrayList<>();
for (String s : split) {
strings.add(Integer.parseInt(s));
}
RpcResponse<List<AccountTypeTreeResponse>> response =
merchantRemote.findMenuFunTreeByAccountType(strings, accountTypeSearchRequest.getAccountLevel(), accountTypeSearchRequest.getMerchantId());
if (response.isSuccess()) {
return ConvertResponse.convertList(response.getResult(), AccountTypeTreeRopResponse.class);
}
throw new RpcServiceException(response.getException().getErrId(), response.getMessage());
}
public List<AccountTypeTreeRopResponse> findMenuFunTreeByRoleId(RoleSearchRequest roleSearchRequest) {
RpcResponse<List<AccountTypeTreeResponse>> response =
merchantRemote.findMenuFunTreeByRoleId(roleSearchRequest.getId());
if (response.isSuccess()) {
return ConvertResponse.convertList(response.getResult(), AccountTypeTreeRopResponse.class);
}
throw new RpcServiceException(response.getException().getErrId(), response.getMessage());
}
public MerchantBaseInfoRopResponse findMerchantBaseInfo(MerchantBaseInfoRequest merchantBaseInfoRequest) {
RpcResponse<MerchantBaseInfoResponse> merchantBaseInfo = merchantRemote.findMerchantBaseInfo(merchantBaseInfoRequest.getMerchantId());
if (merchantBaseInfo.isSuccess()) {
return ConvertResponse.convertObject(merchantBaseInfo.getResult(), MerchantBaseInfoRopResponse.class);
}
throw new RpcServiceException(merchantBaseInfo.getException().getErrId(), merchantBaseInfo.getMessage());
}
public void updateMerchantPath(MerchantUpdatePathRequest merchantUpdatePathRequest) {
MerchantUpdatePathApiRequest pathApiRequest = new MerchantUpdatePathApiRequest();
BeanUtils.copyProperties(merchantUpdatePathRequest, pathApiRequest);
RpcResponse<Boolean> rpcResponse = merchantRemote.merchantUpdatePath(pathApiRequest);
if(!rpcResponse.isSuccess()){
RpcServiceException exception = rpcResponse.getException();
if(null != exception)
throw new RpcServiceException(rpcResponse.getException().getErrId(), rpcResponse.getMessage());
throw new RpcServiceException(rpcResponse.getError().getValue(), rpcResponse.getError().getDisplayName());
}
}
public void updateAccessMode(MerchantAccessMode merchantAccessMode) {
MerchantApiAccessMode apiAccessMode = new MerchantApiAccessMode();
BeanUtils.copyProperties(merchantAccessMode, apiAccessMode);
RpcResponse<Boolean> rpcResponse = merchantRemote.updateAccessMode(apiAccessMode);
if (rpcResponse.isFailed()) {
throw new RpcServiceException(rpcResponse.getException().getErrId(), rpcResponse.getMessage());
}
}
public MerchantInfoDjRopResponse findMerchantInfoToDj(MerchantBaseInfoRequest merchantBaseInfoRequest) {
RpcResponse<MerchantInfoApiDjRopResponse> rpcResponse = merchantRemote.findMerchantInfoToDj(merchantBaseInfoRequest.getMerchantId());
if (rpcResponse.isSuccess()) {
return ConvertResponse.convertObject(rpcResponse.getResult(), MerchantInfoDjRopResponse.class);
}
throw new RpcServiceException(rpcResponse.getException().getErrId(), rpcResponse.getMessage());
}
public Pagination<MerchantSearchEntMicroResponse> findEntMicroMerchantsByPage(MerchantSearchEntMicroRequest merchantSearchEntMicroRequest) {
RpcPagination<MerchantEntMicroPageRequest> remoteRequest = ConvertRequest.convertPage(merchantSearchEntMicroRequest, new MerchantEntMicroPageRequest());
RpcResponse<RpcPagination<MerchantSearchEntMicroResponse>> response = merchantRemote.findEntMicroMerchantsByPage(remoteRequest);
if (response.isSuccess()) {
return ConvertResponse.convertPage(response.getResult(), MerchantSearchEntMicroResponse.class);
}
throw new RpcServiceException(response.getException().getErrId(), response.getMessage());
}
public Boolean checkMerchantNameRepeat(MerchantNameRopRequest request) {
RpcResponse<Boolean> rpcResponse = merchantRemote.checkMerchantNameRepeat(request.getMerchantName());
if (rpcResponse.isSuccess()) {
return rpcResponse.getResult();
}
throw new RpcServiceException(rpcResponse.getException().getErrId(), rpcResponse.getMessage());
}
}