...
|
...
|
@@ -26,9 +26,9 @@ func (service UsersService) UserLoginBySecretKey(cmd command.LoginBySecretKeyCom |
|
|
}
|
|
|
//向统一用户中心确认密钥信息并获取用户数据
|
|
|
ucenterService := serviceGateway.NewMmmUserCenterServiceGateway()
|
|
|
loginResp, err := ucenterService.RequestUCenterLoginBySecret(cmd.Secret)
|
|
|
loginResp, err := ucenterService.RequestUCenterLoginBySecret(cmd.Code)
|
|
|
if err != nil {
|
|
|
e := fmt.Sprintf("通过密钥(secret=%s)从统一用户中心获取数据失败:%s", cmd.Secret, err.Error())
|
|
|
e := fmt.Sprintf("通过密钥(code=%s)从统一用户中心获取数据失败:%s", cmd.Code, err.Error())
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
|
|
}
|
|
|
var (
|
...
|
...
|
@@ -215,3 +215,83 @@ func (service UsersService) ValidateAdminpPermission(queryOption query.ValidateP |
|
|
ok := usersData.HasPermissionByCode(queryOption.PermissionCode)
|
|
|
return ok, nil
|
|
|
}
|
|
|
|
|
|
//获取用户列表
|
|
|
func (service UsersService) GetUserList(queryOption query.UserListQuery) (int, []map[string]interface{}, error) {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
err error
|
|
|
)
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var (
|
|
|
userRespository domain.UsersRepository
|
|
|
usersData []domain.Users
|
|
|
cnt int
|
|
|
permissionRepository domain.AdminPermissionRepository
|
|
|
permissionList []domain.AdminPermission
|
|
|
)
|
|
|
if userRespository, err = factory.CreateUsersRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if permissionRepository, err = factory.CreateAdminPermissionRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
cnt, usersData, err = userRespository.Find(domain.UsersFindQuery{
|
|
|
UserNameMatch: queryOption.UserNameMatch,
|
|
|
Offset: queryOption.Offset,
|
|
|
Limit: queryOption.Limit,
|
|
|
})
|
|
|
var permissionQuery domain.PermissionFindOption
|
|
|
permissionList, err = permissionRepository.Find(permissionQuery)
|
|
|
if err != nil {
|
|
|
return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
result := service.buildGetUserList(usersData, permissionList)
|
|
|
return cnt, result, nil
|
|
|
}
|
|
|
|
|
|
//buildGetUserList 组装构建前端需要的用户列表数据
|
|
|
func (service UsersService) buildGetUserList(usersData []domain.Users, permissionData []domain.AdminPermission) []map[string]interface{} {
|
|
|
result := make([]map[string]interface{}, len(usersData))
|
|
|
permissionMap := map[int64]domain.AdminPermission{}
|
|
|
for i := range permissionData {
|
|
|
permissionMap[permissionData[i].Id] = permissionData[i]
|
|
|
}
|
|
|
for i := range usersData {
|
|
|
permissionTypes := []string{}
|
|
|
if usersData[i].IsSuperAdmin() {
|
|
|
for _, pp := range permissionData {
|
|
|
permissionTypes = append(permissionTypes, pp.Name)
|
|
|
}
|
|
|
} else {
|
|
|
for _, vv := range usersData[i].Permission {
|
|
|
if pm, ok := permissionMap[vv.Id]; ok {
|
|
|
permissionTypes = append(permissionTypes, pm.Name)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
m := map[string]interface{}{
|
|
|
"id": usersData[i].Id,
|
|
|
"account": usersData[i].Phone,
|
|
|
"name": usersData[i].Name,
|
|
|
"permission": permissionTypes,
|
|
|
"isAdmin": 0,
|
|
|
"partnership": len(usersData[i].AccessPartners),
|
|
|
}
|
|
|
if usersData[i].IsSuperAdmin() {
|
|
|
m["isAdmin"] = 1
|
|
|
}
|
|
|
result = append(result, m)
|
|
|
}
|
|
|
return result
|
|
|
} |
...
|
...
|
|