|
@@ -3,6 +3,8 @@ package allied_creation_user |
|
@@ -3,6 +3,8 @@ package allied_creation_user |
3
|
import (
|
3
|
import (
|
4
|
"encoding/json"
|
4
|
"encoding/json"
|
5
|
"fmt"
|
5
|
"fmt"
|
|
|
6
|
+ "net/url"
|
|
|
7
|
+ "strconv"
|
6
|
|
8
|
|
7
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway"
|
9
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway"
|
8
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
|
10
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
|
|
@@ -10,12 +12,12 @@ import ( |
|
@@ -10,12 +12,12 @@ import ( |
10
|
|
12
|
|
11
|
//RoleSearch 搜索角色列表
|
13
|
//RoleSearch 搜索角色列表
|
12
|
func (gateway HttplibAlliedCreationUser) RoleSearch(param ReqRoleSearch) (*DataRoleSearch, error) {
|
14
|
func (gateway HttplibAlliedCreationUser) RoleSearch(param ReqRoleSearch) (*DataRoleSearch, error) {
|
13
|
- url := gateway.baseUrL + "/role/search"
|
15
|
+ urlStr := gateway.baseUrL + "/role/search"
|
14
|
method := "post"
|
16
|
method := "post"
|
15
|
- req := gateway.CreateRequest(url, method)
|
17
|
+ req := gateway.CreateRequest(urlStr, method)
|
16
|
//TODO traceID
|
18
|
//TODO traceID
|
17
|
log.Logger.Debug("向用户模块请求数据:搜索角色列表。", map[string]interface{}{
|
19
|
log.Logger.Debug("向用户模块请求数据:搜索角色列表。", map[string]interface{}{
|
18
|
- "api": method + ":" + url,
|
20
|
+ "api": method + ":" + urlStr,
|
19
|
"param": param,
|
21
|
"param": param,
|
20
|
})
|
22
|
})
|
21
|
req, err := req.JSONBody(param)
|
23
|
req, err := req.JSONBody(param)
|
|
@@ -42,12 +44,12 @@ func (gateway HttplibAlliedCreationUser) RoleSearch(param ReqRoleSearch) (*DataR |
|
@@ -42,12 +44,12 @@ func (gateway HttplibAlliedCreationUser) RoleSearch(param ReqRoleSearch) (*DataR |
42
|
|
44
|
|
43
|
//RoleGet 获取角色
|
45
|
//RoleGet 获取角色
|
44
|
func (gateway HttplibAlliedCreationUser) RoleGet(param ReqRoleGet) (*DataRoleGet, error) {
|
46
|
func (gateway HttplibAlliedCreationUser) RoleGet(param ReqRoleGet) (*DataRoleGet, error) {
|
45
|
- url := fmt.Sprintf("%s%s%d", gateway.baseUrL, "/role/", param.RoleId)
|
47
|
+ urlStr := gateway.baseUrL + "/role/" + strconv.FormatInt(param.RoleId, 10)
|
46
|
method := "get"
|
48
|
method := "get"
|
47
|
- req := gateway.CreateRequest(url, method)
|
49
|
+ req := gateway.CreateRequest(urlStr, method)
|
48
|
//TODO traceID
|
50
|
//TODO traceID
|
49
|
log.Logger.Debug("向用户模块请求数据:获取角色。", map[string]interface{}{
|
51
|
log.Logger.Debug("向用户模块请求数据:获取角色。", map[string]interface{}{
|
50
|
- "api": method + ":" + url,
|
52
|
+ "api": method + ":" + urlStr,
|
51
|
"param": param,
|
53
|
"param": param,
|
52
|
})
|
54
|
})
|
53
|
req, err := req.JSONBody(param)
|
55
|
req, err := req.JSONBody(param)
|
|
@@ -71,3 +73,256 @@ func (gateway HttplibAlliedCreationUser) RoleGet(param ReqRoleGet) (*DataRoleGet |
|
@@ -71,3 +73,256 @@ func (gateway HttplibAlliedCreationUser) RoleGet(param ReqRoleGet) (*DataRoleGet |
71
|
err = gateway.GetResponseData(result, &data)
|
73
|
err = gateway.GetResponseData(result, &data)
|
72
|
return &data, err
|
74
|
return &data, err
|
73
|
}
|
75
|
}
|
|
|
76
|
+
|
|
|
77
|
+// RoleAssign 分配角色给多个用户
|
|
|
78
|
+func (gateway HttplibAlliedCreationUser) RoleAssign(param ReqRoleAssign) (*DataRoleAssign, error) {
|
|
|
79
|
+ urlStr := gateway.baseUrL + "/role/assign"
|
|
|
80
|
+ method := "post"
|
|
|
81
|
+ req := gateway.CreateRequest(urlStr, method)
|
|
|
82
|
+ log.Logger.Debug("向用户模块请求数据:分配角色给多个用户。", map[string]interface{}{
|
|
|
83
|
+ "api": method + ":" + urlStr,
|
|
|
84
|
+ "param": param,
|
|
|
85
|
+ })
|
|
|
86
|
+ req, err := req.JSONBody(param)
|
|
|
87
|
+ if err != nil {
|
|
|
88
|
+ return nil, fmt.Errorf("请求分配角色给多个用户失败:%w", err)
|
|
|
89
|
+ }
|
|
|
90
|
+
|
|
|
91
|
+ byteResult, err := req.Bytes()
|
|
|
92
|
+ if err != nil {
|
|
|
93
|
+ return nil, fmt.Errorf("获取分配角色给多个用户失败:%w", err)
|
|
|
94
|
+ }
|
|
|
95
|
+ log.Logger.Debug("获取用户模块请求数据:分配角色给多个用户。", map[string]interface{}{
|
|
|
96
|
+ "result": string(byteResult),
|
|
|
97
|
+ })
|
|
|
98
|
+ var result service_gateway.GatewayResponse
|
|
|
99
|
+ err = json.Unmarshal(byteResult, &result)
|
|
|
100
|
+ if err != nil {
|
|
|
101
|
+ return nil, fmt.Errorf("解析分配角色给多个用户:%w", err)
|
|
|
102
|
+ }
|
|
|
103
|
+ var data DataRoleAssign
|
|
|
104
|
+ err = gateway.GetResponseData(result, &data)
|
|
|
105
|
+ return &data, err
|
|
|
106
|
+}
|
|
|
107
|
+
|
|
|
108
|
+// Role 创建角色
|
|
|
109
|
+func (gateway HttplibAlliedCreationUser) Role(param ReqRole) (*DataRole, error) {
|
|
|
110
|
+ urlStr := gateway.baseUrL + "/role"
|
|
|
111
|
+ method := "post"
|
|
|
112
|
+ req := gateway.CreateRequest(urlStr, method)
|
|
|
113
|
+ log.Logger.Debug("向用户模块请求数据:创建角色。", map[string]interface{}{
|
|
|
114
|
+ "api": method + ":" + urlStr,
|
|
|
115
|
+ "param": param,
|
|
|
116
|
+ })
|
|
|
117
|
+ req, err := req.JSONBody(param)
|
|
|
118
|
+ if err != nil {
|
|
|
119
|
+ return nil, fmt.Errorf("请求创建角色失败:%w", err)
|
|
|
120
|
+ }
|
|
|
121
|
+
|
|
|
122
|
+ byteResult, err := req.Bytes()
|
|
|
123
|
+ if err != nil {
|
|
|
124
|
+ return nil, fmt.Errorf("获取创建角色失败:%w", err)
|
|
|
125
|
+ }
|
|
|
126
|
+ log.Logger.Debug("获取用户模块请求数据:创建角色。", map[string]interface{}{
|
|
|
127
|
+ "result": string(byteResult),
|
|
|
128
|
+ })
|
|
|
129
|
+ var result service_gateway.GatewayResponse
|
|
|
130
|
+ err = json.Unmarshal(byteResult, &result)
|
|
|
131
|
+ if err != nil {
|
|
|
132
|
+ return nil, fmt.Errorf("解析创建角色:%w", err)
|
|
|
133
|
+ }
|
|
|
134
|
+ var data DataRole
|
|
|
135
|
+ err = gateway.GetResponseData(result, &data)
|
|
|
136
|
+ return &data, err
|
|
|
137
|
+}
|
|
|
138
|
+
|
|
|
139
|
+// RoleUnassign 取消用户分配的角色
|
|
|
140
|
+func (gateway HttplibAlliedCreationUser) RoleUnassign(param ReqRoleUnassign) (*DataRoleUnassign, error) {
|
|
|
141
|
+ urlStr := gateway.baseUrL + "/role/unassign"
|
|
|
142
|
+ method := "post"
|
|
|
143
|
+ req := gateway.CreateRequest(urlStr, method)
|
|
|
144
|
+ log.Logger.Debug("向用户模块请求数据:取消用户分配的角色。", map[string]interface{}{
|
|
|
145
|
+ "api": method + ":" + urlStr,
|
|
|
146
|
+ "param": param,
|
|
|
147
|
+ })
|
|
|
148
|
+ req, err := req.JSONBody(param)
|
|
|
149
|
+ if err != nil {
|
|
|
150
|
+ return nil, fmt.Errorf("请求取消用户分配的角色失败:%w", err)
|
|
|
151
|
+ }
|
|
|
152
|
+
|
|
|
153
|
+ byteResult, err := req.Bytes()
|
|
|
154
|
+ if err != nil {
|
|
|
155
|
+ return nil, fmt.Errorf("获取取消用户分配的角色失败:%w", err)
|
|
|
156
|
+ }
|
|
|
157
|
+ log.Logger.Debug("获取用户模块请求数据:取消用户分配的角色。", map[string]interface{}{
|
|
|
158
|
+ "result": string(byteResult),
|
|
|
159
|
+ })
|
|
|
160
|
+ var result service_gateway.GatewayResponse
|
|
|
161
|
+ err = json.Unmarshal(byteResult, &result)
|
|
|
162
|
+ if err != nil {
|
|
|
163
|
+ return nil, fmt.Errorf("解析取消用户分配的角色:%w", err)
|
|
|
164
|
+ }
|
|
|
165
|
+ var data DataRoleUnassign
|
|
|
166
|
+ err = gateway.GetResponseData(result, &data)
|
|
|
167
|
+ return &data, err
|
|
|
168
|
+}
|
|
|
169
|
+
|
|
|
170
|
+// RoleUpdate 更新角色
|
|
|
171
|
+func (gateway HttplibAlliedCreationUser) RoleUpdate(param ReqRoleUpdate) (*DataRoleUpdate, error) {
|
|
|
172
|
+ urlStr := gateway.baseUrL + "/role/" + strconv.FormatInt(param.RoleId, 10)
|
|
|
173
|
+ method := "put"
|
|
|
174
|
+ req := gateway.CreateRequest(urlStr, method)
|
|
|
175
|
+ log.Logger.Debug("向用户模块请求数据:更新角色。", map[string]interface{}{
|
|
|
176
|
+ "api": method + ":" + urlStr,
|
|
|
177
|
+ "param": param,
|
|
|
178
|
+ })
|
|
|
179
|
+ req, err := req.JSONBody(param)
|
|
|
180
|
+ if err != nil {
|
|
|
181
|
+ return nil, fmt.Errorf("请求更新角色失败:%w", err)
|
|
|
182
|
+ }
|
|
|
183
|
+
|
|
|
184
|
+ byteResult, err := req.Bytes()
|
|
|
185
|
+ if err != nil {
|
|
|
186
|
+ return nil, fmt.Errorf("获取更新角色失败:%w", err)
|
|
|
187
|
+ }
|
|
|
188
|
+ log.Logger.Debug("获取用户模块请求数据:更新角色。", map[string]interface{}{
|
|
|
189
|
+ "result": string(byteResult),
|
|
|
190
|
+ })
|
|
|
191
|
+ var result service_gateway.GatewayResponse
|
|
|
192
|
+ err = json.Unmarshal(byteResult, &result)
|
|
|
193
|
+ if err != nil {
|
|
|
194
|
+ return nil, fmt.Errorf("解析更新角色:%w", err)
|
|
|
195
|
+ }
|
|
|
196
|
+ var data DataRoleUpdate
|
|
|
197
|
+ err = gateway.GetResponseData(result, &data)
|
|
|
198
|
+ return &data, err
|
|
|
199
|
+}
|
|
|
200
|
+
|
|
|
201
|
+// RoleRemove 移除角色
|
|
|
202
|
+func (gateway HttplibAlliedCreationUser) RoleRemove(param ReqRoleRemove) (*DataRoleRemove, error) {
|
|
|
203
|
+ urlStr := gateway.baseUrL + "/role/" + strconv.FormatInt(param.RoleId, 10)
|
|
|
204
|
+ method := "delete"
|
|
|
205
|
+ req := gateway.CreateRequest(urlStr, method)
|
|
|
206
|
+ log.Logger.Debug("向用户模块请求数据:移除角色。", map[string]interface{}{
|
|
|
207
|
+ "api": method + ":" + urlStr,
|
|
|
208
|
+ "param": param,
|
|
|
209
|
+ })
|
|
|
210
|
+ req, err := req.JSONBody(param)
|
|
|
211
|
+ if err != nil {
|
|
|
212
|
+ return nil, fmt.Errorf("请求移除角色失败:%w", err)
|
|
|
213
|
+ }
|
|
|
214
|
+
|
|
|
215
|
+ byteResult, err := req.Bytes()
|
|
|
216
|
+ if err != nil {
|
|
|
217
|
+ return nil, fmt.Errorf("获取移除角色失败:%w", err)
|
|
|
218
|
+ }
|
|
|
219
|
+ log.Logger.Debug("获取用户模块请求数据:移除角色。", map[string]interface{}{
|
|
|
220
|
+ "result": string(byteResult),
|
|
|
221
|
+ })
|
|
|
222
|
+ var result service_gateway.GatewayResponse
|
|
|
223
|
+ err = json.Unmarshal(byteResult, &result)
|
|
|
224
|
+ if err != nil {
|
|
|
225
|
+ return nil, fmt.Errorf("解析移除角色:%w", err)
|
|
|
226
|
+ }
|
|
|
227
|
+ var data DataRoleRemove
|
|
|
228
|
+ err = gateway.GetResponseData(result, &data)
|
|
|
229
|
+ return &data, err
|
|
|
230
|
+}
|
|
|
231
|
+
|
|
|
232
|
+// RoleGetRelatedUser 获取角色相关联的用户
|
|
|
233
|
+func (gateway HttplibAlliedCreationUser) RoleGetRelatedUser(param ReqRoleGetRelatedUser) (*DataRoleGetRelatedUser, error) {
|
|
|
234
|
+ orgId := strconv.FormatInt(param.OrgId, 10)
|
|
|
235
|
+ departmentId := strconv.FormatInt(param.DepartmentId, 10)
|
|
|
236
|
+ v := url.Values{}
|
|
|
237
|
+ v.Set("orgId", orgId)
|
|
|
238
|
+ v.Set("departmentId", departmentId)
|
|
|
239
|
+ urlStr := gateway.baseUrL + "/role/" + strconv.FormatInt(param.RoleId, 10) + "/related-user?" + v.Encode()
|
|
|
240
|
+ method := "get"
|
|
|
241
|
+ req := gateway.CreateRequest(urlStr, method)
|
|
|
242
|
+ log.Logger.Debug("向用户模块请求数据:获取角色相关联的用户。", map[string]interface{}{
|
|
|
243
|
+ "api": method + ":" + urlStr,
|
|
|
244
|
+ "param": param,
|
|
|
245
|
+ })
|
|
|
246
|
+ req, err := req.JSONBody(param)
|
|
|
247
|
+ if err != nil {
|
|
|
248
|
+ return nil, fmt.Errorf("请求获取角色相关联的用户失败:%w", err)
|
|
|
249
|
+ }
|
|
|
250
|
+
|
|
|
251
|
+ byteResult, err := req.Bytes()
|
|
|
252
|
+ if err != nil {
|
|
|
253
|
+ return nil, fmt.Errorf("获取获取角色相关联的用户失败:%w", err)
|
|
|
254
|
+ }
|
|
|
255
|
+ log.Logger.Debug("获取用户模块请求数据:获取角色相关联的用户。", map[string]interface{}{
|
|
|
256
|
+ "result": string(byteResult),
|
|
|
257
|
+ })
|
|
|
258
|
+ var result service_gateway.GatewayResponse
|
|
|
259
|
+ err = json.Unmarshal(byteResult, &result)
|
|
|
260
|
+ if err != nil {
|
|
|
261
|
+ return nil, fmt.Errorf("解析获取角色相关联的用户:%w", err)
|
|
|
262
|
+ }
|
|
|
263
|
+ var data DataRoleGetRelatedUser
|
|
|
264
|
+ err = gateway.GetResponseData(result, &data)
|
|
|
265
|
+ return &data, err
|
|
|
266
|
+}
|
|
|
267
|
+
|
|
|
268
|
+// RoleGetAccessMenus 获取角色菜单
|
|
|
269
|
+func (gateway HttplibAlliedCreationUser) RoleGetAccessMenus(param ReqRoleGetAccessMenus) (*DataRoleGetAccessMenus, error) {
|
|
|
270
|
+ urlStr := gateway.baseUrL + "/role/" + strconv.FormatInt(param.RoleId, 10) + "/access-menus"
|
|
|
271
|
+ method := "get"
|
|
|
272
|
+ req := gateway.CreateRequest(urlStr, method)
|
|
|
273
|
+ log.Logger.Debug("向用户模块请求数据:获取角色菜单。", map[string]interface{}{
|
|
|
274
|
+ "api": method + ":" + urlStr,
|
|
|
275
|
+ "param": param,
|
|
|
276
|
+ })
|
|
|
277
|
+ req, err := req.JSONBody(param)
|
|
|
278
|
+ if err != nil {
|
|
|
279
|
+ return nil, fmt.Errorf("请求获取角色菜单失败:%w", err)
|
|
|
280
|
+ }
|
|
|
281
|
+
|
|
|
282
|
+ byteResult, err := req.Bytes()
|
|
|
283
|
+ if err != nil {
|
|
|
284
|
+ return nil, fmt.Errorf("获取获取角色菜单失败:%w", err)
|
|
|
285
|
+ }
|
|
|
286
|
+ log.Logger.Debug("获取用户模块请求数据:获取角色菜单。", map[string]interface{}{
|
|
|
287
|
+ "result": string(byteResult),
|
|
|
288
|
+ })
|
|
|
289
|
+ var result service_gateway.GatewayResponse
|
|
|
290
|
+ err = json.Unmarshal(byteResult, &result)
|
|
|
291
|
+ if err != nil {
|
|
|
292
|
+ return nil, fmt.Errorf("解析获取角色菜单:%w", err)
|
|
|
293
|
+ }
|
|
|
294
|
+ var data DataRoleGetAccessMenus
|
|
|
295
|
+ err = gateway.GetResponseData(result, &data)
|
|
|
296
|
+ return &data, err
|
|
|
297
|
+}
|
|
|
298
|
+
|
|
|
299
|
+// ReqRoleSetAccessMenus 设置角色菜单
|
|
|
300
|
+func (gateway HttplibAlliedCreationUser) RoleSetAccessMenus(param ReqRoleSetAccessMenus) (*DataRoleSetAccessMenus, error) {
|
|
|
301
|
+ urlStr := gateway.baseUrL + "/role/" + strconv.FormatInt(param.RoleId, 10) + "/access-menus"
|
|
|
302
|
+ method := "put"
|
|
|
303
|
+ req := gateway.CreateRequest(urlStr, method)
|
|
|
304
|
+ log.Logger.Debug("向用户模块请求数据:设置角色菜单。", map[string]interface{}{
|
|
|
305
|
+ "api": method + ":" + urlStr,
|
|
|
306
|
+ "param": param,
|
|
|
307
|
+ })
|
|
|
308
|
+ req, err := req.JSONBody(param)
|
|
|
309
|
+ if err != nil {
|
|
|
310
|
+ return nil, fmt.Errorf("请求设置角色菜单失败:%w", err)
|
|
|
311
|
+ }
|
|
|
312
|
+
|
|
|
313
|
+ byteResult, err := req.Bytes()
|
|
|
314
|
+ if err != nil {
|
|
|
315
|
+ return nil, fmt.Errorf("获取设置角色菜单失败:%w", err)
|
|
|
316
|
+ }
|
|
|
317
|
+ log.Logger.Debug("获取用户模块请求数据:设置角色菜单。", map[string]interface{}{
|
|
|
318
|
+ "result": string(byteResult),
|
|
|
319
|
+ })
|
|
|
320
|
+ var result service_gateway.GatewayResponse
|
|
|
321
|
+ err = json.Unmarshal(byteResult, &result)
|
|
|
322
|
+ if err != nil {
|
|
|
323
|
+ return nil, fmt.Errorf("解析设置角色菜单:%w", err)
|
|
|
324
|
+ }
|
|
|
325
|
+ var data DataRoleSetAccessMenus
|
|
|
326
|
+ err = gateway.GetResponseData(result, &data)
|
|
|
327
|
+ return &data, err
|
|
|
328
|
+} |