MerchantService.java
7.03 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
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.MerchantProductRequest;
import cn.com.glsx.merchants.model.request.MerchantRequest;
import cn.com.glsx.merchants.model.request.MerchantTreeRequest;
import cn.com.glsx.merchants.model.response.AccountTypeTreeResponse;
import cn.com.glsx.merchants.model.response.MerchantProductResponse;
import cn.com.glsx.merchants.model.response.MerchantResponse;
import cn.com.glsx.merchants.model.response.MerchantTreeResponse;
import cn.com.glsx.merchants.remote.MerchantRemote;
import cn.com.glsx.merchants.request.merchant.*;
import cn.com.glsx.merchants.response.*;
import cn.com.glsx.merchants.util.Pagination;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
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 void saveMerchant(MerchantSaveRequest merchantSaveRequest) {
merchantUserService.setUser(merchantSaveRequest);
RpcResponse<Boolean> booleanRpcResponse = merchantRemote.saveMerchantRemote(ConvertRequest.convertRequest(merchantSaveRequest, new MerchantRequest()));
if (booleanRpcResponse.isFailed()) {
throw new RpcServiceException(booleanRpcResponse.getException().getErrId(), booleanRpcResponse.getMessage());
}
}
/**
* 更新商户
*
* @param merchantUpdateRequest 入参
*/
public void updateMerchant(MerchantUpdateRequest merchantUpdateRequest) {
merchantUserService.setUser(merchantUpdateRequest);
RpcResponse<Boolean> booleanRpcResponse = merchantRemote.saveMerchantRemote(ConvertRequest.convertRequest(merchantUpdateRequest, new MerchantRequest()));
if (booleanRpcResponse.isFailed()) {
throw new RpcServiceException(booleanRpcResponse.getException().getErrId(), booleanRpcResponse.getMessage());
}
}
/**
* 保存商户权限喜喜
*
* @param merchantTreeRequest 入参
*/
public void savePermissions(MerchantTreeRopRequest merchantTreeRequest) {
MerchantTreeRequest merchantTreeRequest1 = ConvertRequest.convertRequest(merchantTreeRequest, new MerchantTreeRequest());
RpcResponse<Boolean> booleanRpcResponse = merchantRemote.savePermissionsRemote(merchantTreeRequest1);
if (booleanRpcResponse.isFailed()) {
throw new RpcServiceException(booleanRpcResponse.getException().getErrId(), booleanRpcResponse.getMessage());
}
}
/**
* 更新商户权限
*
* @param merchantTreeRequest 入参
*/
public void updatePermissions(MerchantTreeRopRequest merchantTreeRequest) {
RpcResponse<Boolean> booleanRpcResponse = merchantRemote.updatePermissionsRemote(ConvertRequest.convertRequest(merchantTreeRequest, new MerchantTreeRequest()));
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 void updateValPerByMerId(MerchantDetailRequest merchantDetailRequest) {
merchantUserService.setUser(merchantDetailRequest);
RpcResponse<Boolean> booleanRpcResponse = merchantRemote.saveMerchantRemote(ConvertRequest.convertRequest(merchantDetailRequest, new MerchantRequest()));
if (booleanRpcResponse.isFailed()) {
throw new RpcServiceException(booleanRpcResponse.getException().getErrId(), booleanRpcResponse.getMessage());
}
}
/**
* 查询商户的列表
*
* @param merchantSearchResquest 入参
* @return
*/
public Pagination<MerchantRopResponse> findMerchantByPage(MerchantSearchResquest merchantSearchResquest) {
RpcResponse<RpcPagination<MerchantResponse>> merProductByPageRemote = merchantRemote.findMerchantByPageRemote(ConvertRequest.convertPage(merchantSearchResquest, new MerchantRequest()));
if (merProductByPageRemote.isSuccess()) {
return ConvertResponse.convertPage(merProductByPageRemote.getResult(), MerchantRopResponse.class);
}
throw new RpcServiceException(merProductByPageRemote.getException().getErrId(), merProductByPageRemote.getMessage());
}
}