|
@@ -26,9 +26,9 @@ func (service UsersService) UserLoginBySecretKey(cmd command.LoginBySecretKeyCom |
|
@@ -26,9 +26,9 @@ func (service UsersService) UserLoginBySecretKey(cmd command.LoginBySecretKeyCom |
26
|
}
|
26
|
}
|
27
|
//向统一用户中心确认密钥信息并获取用户数据
|
27
|
//向统一用户中心确认密钥信息并获取用户数据
|
28
|
ucenterService := serviceGateway.NewMmmUserCenterServiceGateway()
|
28
|
ucenterService := serviceGateway.NewMmmUserCenterServiceGateway()
|
29
|
- loginResp, err := ucenterService.RequestUCenterLoginBySecret(cmd.Secret)
|
29
|
+ loginResp, err := ucenterService.RequestUCenterLoginBySecret(cmd.Code)
|
30
|
if err != nil {
|
30
|
if err != nil {
|
31
|
- e := fmt.Sprintf("通过密钥(secret=%s)从统一用户中心获取数据失败:%s", cmd.Secret, err.Error())
|
31
|
+ e := fmt.Sprintf("通过密钥(code=%s)从统一用户中心获取数据失败:%s", cmd.Code, err.Error())
|
32
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
32
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
33
|
}
|
33
|
}
|
34
|
var (
|
34
|
var (
|
|
@@ -215,3 +215,83 @@ func (service UsersService) ValidateAdminpPermission(queryOption query.ValidateP |
|
@@ -215,3 +215,83 @@ func (service UsersService) ValidateAdminpPermission(queryOption query.ValidateP |
215
|
ok := usersData.HasPermissionByCode(queryOption.PermissionCode)
|
215
|
ok := usersData.HasPermissionByCode(queryOption.PermissionCode)
|
216
|
return ok, nil
|
216
|
return ok, nil
|
217
|
}
|
217
|
}
|
|
|
218
|
+
|
|
|
219
|
+//获取用户列表
|
|
|
220
|
+func (service UsersService) GetUserList(queryOption query.UserListQuery) (int, []map[string]interface{}, error) {
|
|
|
221
|
+ var (
|
|
|
222
|
+ transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
223
|
+ err error
|
|
|
224
|
+ )
|
|
|
225
|
+ if err = transactionContext.StartTransaction(); err != nil {
|
|
|
226
|
+ return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
227
|
+ }
|
|
|
228
|
+ defer func() {
|
|
|
229
|
+ transactionContext.RollbackTransaction()
|
|
|
230
|
+ }()
|
|
|
231
|
+ var (
|
|
|
232
|
+ userRespository domain.UsersRepository
|
|
|
233
|
+ usersData []domain.Users
|
|
|
234
|
+ cnt int
|
|
|
235
|
+ permissionRepository domain.AdminPermissionRepository
|
|
|
236
|
+ permissionList []domain.AdminPermission
|
|
|
237
|
+ )
|
|
|
238
|
+ if userRespository, err = factory.CreateUsersRepository(map[string]interface{}{
|
|
|
239
|
+ "transactionContext": transactionContext,
|
|
|
240
|
+ }); err != nil {
|
|
|
241
|
+ return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
242
|
+ }
|
|
|
243
|
+ if permissionRepository, err = factory.CreateAdminPermissionRepository(map[string]interface{}{
|
|
|
244
|
+ "transactionContext": transactionContext,
|
|
|
245
|
+ }); err != nil {
|
|
|
246
|
+ return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
247
|
+ }
|
|
|
248
|
+ cnt, usersData, err = userRespository.Find(domain.UsersFindQuery{
|
|
|
249
|
+ UserNameMatch: queryOption.UserNameMatch,
|
|
|
250
|
+ Offset: queryOption.Offset,
|
|
|
251
|
+ Limit: queryOption.Limit,
|
|
|
252
|
+ })
|
|
|
253
|
+ var permissionQuery domain.PermissionFindOption
|
|
|
254
|
+ permissionList, err = permissionRepository.Find(permissionQuery)
|
|
|
255
|
+ if err != nil {
|
|
|
256
|
+ return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
257
|
+ }
|
|
|
258
|
+ err = transactionContext.CommitTransaction()
|
|
|
259
|
+ result := service.buildGetUserList(usersData, permissionList)
|
|
|
260
|
+ return cnt, result, nil
|
|
|
261
|
+}
|
|
|
262
|
+
|
|
|
263
|
+//buildGetUserList 组装构建前端需要的用户列表数据
|
|
|
264
|
+func (service UsersService) buildGetUserList(usersData []domain.Users, permissionData []domain.AdminPermission) []map[string]interface{} {
|
|
|
265
|
+ result := make([]map[string]interface{}, len(usersData))
|
|
|
266
|
+ permissionMap := map[int64]domain.AdminPermission{}
|
|
|
267
|
+ for i := range permissionData {
|
|
|
268
|
+ permissionMap[permissionData[i].Id] = permissionData[i]
|
|
|
269
|
+ }
|
|
|
270
|
+ for i := range usersData {
|
|
|
271
|
+ permissionTypes := []string{}
|
|
|
272
|
+ if usersData[i].IsSuperAdmin() {
|
|
|
273
|
+ for _, pp := range permissionData {
|
|
|
274
|
+ permissionTypes = append(permissionTypes, pp.Name)
|
|
|
275
|
+ }
|
|
|
276
|
+ } else {
|
|
|
277
|
+ for _, vv := range usersData[i].Permission {
|
|
|
278
|
+ if pm, ok := permissionMap[vv.Id]; ok {
|
|
|
279
|
+ permissionTypes = append(permissionTypes, pm.Name)
|
|
|
280
|
+ }
|
|
|
281
|
+ }
|
|
|
282
|
+ }
|
|
|
283
|
+ m := map[string]interface{}{
|
|
|
284
|
+ "id": usersData[i].Id,
|
|
|
285
|
+ "account": usersData[i].Phone,
|
|
|
286
|
+ "name": usersData[i].Name,
|
|
|
287
|
+ "permission": permissionTypes,
|
|
|
288
|
+ "isAdmin": 0,
|
|
|
289
|
+ "partnership": len(usersData[i].AccessPartners),
|
|
|
290
|
+ }
|
|
|
291
|
+ if usersData[i].IsSuperAdmin() {
|
|
|
292
|
+ m["isAdmin"] = 1
|
|
|
293
|
+ }
|
|
|
294
|
+ result = append(result, m)
|
|
|
295
|
+ }
|
|
|
296
|
+ return result
|
|
|
297
|
+} |