...
|
...
|
@@ -96,7 +96,8 @@ func (svr *UserService) UpdateUser(header *protocol.RequestHeader, request *prot |
|
|
return
|
|
|
}
|
|
|
}
|
|
|
if err = user.Update(common.ObjectToMap(request)); err != nil {
|
|
|
// common.ObjectToMap(request)
|
|
|
if err = user.Update(utils.LoadCustomFieldToMap(request, header.BodyKeys...)); err != nil {
|
|
|
err = application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
return
|
|
|
}
|
...
|
...
|
@@ -136,11 +137,13 @@ func (svr *UserService) GetUser(header *protocol.RequestHeader, request *protoco |
|
|
return
|
|
|
}
|
|
|
retMap := map[string]interface{}{"id": user.Id, "name": user.Name, "phone": user.Phone, "adminType": user.AdminType, "status": user.Status}
|
|
|
if len(user.Roles) > 0 {
|
|
|
if _, roles, e := RoleRepository.Find(map[string]interface{}{"inRoleIds": user.Roles}); len(roles) > 0 && e == nil {
|
|
|
retMap["roles"] = utils.LoadCustomField(roles, "Id", "RoleName")
|
|
|
var roles []*domain.Role
|
|
|
for _, v := range user.Roles {
|
|
|
if role, e := RoleRepository.FindOne(map[string]interface{}{"id": v}); e == nil {
|
|
|
roles = append(roles, role)
|
|
|
}
|
|
|
}
|
|
|
retMap["roles"] = utils.LoadCustomField(roles, "Id", "RoleName")
|
|
|
rsp = map[string]interface{}{"user": retMap}
|
|
|
if err = transactionContext.CommitTransaction(); err != nil {
|
|
|
err = application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -202,25 +205,31 @@ func (svr *UserService) ListUser(header *protocol.RequestHeader, request *protoc |
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
_, roles, _ := RoleRepository.Find(map[string]interface{}{})
|
|
|
roleMap := domain.Roles(roles).RoleMap()
|
|
|
getRoles := func(roleIds []int64) string {
|
|
|
if len(roleIds) == 0 {
|
|
|
return ""
|
|
|
}
|
|
|
var role []string
|
|
|
var roles []string
|
|
|
var mapRoles = make(map[int64]*domain.Role)
|
|
|
for _, id := range roleIds {
|
|
|
if v, ok := roleMap[id]; ok {
|
|
|
role = append(role, v.RoleName)
|
|
|
if _, ok := mapRoles[id]; ok {
|
|
|
continue
|
|
|
}
|
|
|
if roleItem, _ := RoleRepository.FindOne(map[string]interface{}{"id": id}); roleItem != nil {
|
|
|
roles = append(roles, roleItem.RoleName)
|
|
|
} else {
|
|
|
mapRoles[id] = nil
|
|
|
}
|
|
|
continue
|
|
|
}
|
|
|
return strings.Join(role, ",")
|
|
|
return strings.Join(roles, ",")
|
|
|
}
|
|
|
|
|
|
// TODO:可优化,每次只查询 user.id 列表 ,通过缓存查询user对象
|
|
|
var UserRepository, _ = factory.CreateUserRepository(transactionContext)
|
|
|
var user []*domain.Users
|
|
|
var total int64
|
|
|
if total, user, err = UserRepository.Find(map[string]interface{}{"offset": (request.PageNumber - 1) * request.PageSize, "limit": request.PageSize, "searchByText": request.SearchByText, "sortById": "DESC"}); err != nil {
|
|
|
if total, user, err = UserRepository.Find(common.ObjectToMap(request)); err != nil {
|
|
|
err = application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
return
|
|
|
}
|
...
|
...
|
|