组织用户
This commit is contained in:
parent
9a90c95be1
commit
c84626960c
|
|
@ -0,0 +1,22 @@
|
|||
package base
|
||||
|
||||
type Query struct {
|
||||
Page int `form:"page" json:"page" `
|
||||
PageSize int `form:"page_size" json:"page_size"`
|
||||
Keyword string `form:"keyword" Json:"keyword"`
|
||||
Sort string `form:"sort" json:"sort" binding:"sql_sort"`
|
||||
}
|
||||
|
||||
func (q *Query) Default() {
|
||||
if q.Page < 0 {
|
||||
q.Page = 0
|
||||
}
|
||||
|
||||
if q.PageSize <= 0 {
|
||||
q.PageSize = 20
|
||||
}
|
||||
|
||||
if len(q.Sort) == 0 {
|
||||
q.Sort = "created_on desc"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,9 @@
|
|||
package organization
|
||||
|
||||
import (
|
||||
"busniess-user-center/internal/models/base"
|
||||
)
|
||||
|
||||
type CreateOrgReq struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
ParentId uint `json:"parent_id"`
|
||||
|
|
@ -37,9 +41,16 @@ type EnableOrgReq struct {
|
|||
}
|
||||
|
||||
type AddUsersReq struct {
|
||||
Ids []uint `json:"ids"`
|
||||
OrgId uint `json:"org_id"`
|
||||
Ids []uint `json:"ids"`
|
||||
}
|
||||
|
||||
type RemoveUsersReq struct {
|
||||
Ids []uint `json:"ids"`
|
||||
OrgId uint `json:"org_id"`
|
||||
Ids []uint `json:"ids"`
|
||||
}
|
||||
|
||||
type SearchOrgUserReq struct {
|
||||
OrgId uint `json:"org_id"`
|
||||
base.Query
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,10 +74,12 @@ type RemoveOrgsReq struct {
|
|||
|
||||
type RoleUsersReq struct {
|
||||
Id uint `json:"id" binding:"required"`
|
||||
Query
|
||||
}
|
||||
|
||||
type RoleOrgsReq struct {
|
||||
Id uint `json:"id" binding:"required"`
|
||||
Query
|
||||
}
|
||||
|
||||
type AuthorRoleMenuReq struct {
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ type AddInfo struct {
|
|||
}
|
||||
|
||||
type UserInfo struct {
|
||||
Id uint
|
||||
Account string
|
||||
Name string
|
||||
Mobile string
|
||||
|
|
@ -36,7 +37,6 @@ type UserInfo struct {
|
|||
}
|
||||
|
||||
type User struct {
|
||||
Id uint
|
||||
UserInfo
|
||||
Roles []roleModel.Role
|
||||
Orgs []orgModel.Organization
|
||||
|
|
@ -48,13 +48,6 @@ type ModifyInfo struct {
|
|||
Sex int `json:"sex"`
|
||||
}
|
||||
|
||||
type Query struct {
|
||||
Page int `form:"page" json:"page" `
|
||||
PageSize int `form:"page_size" json:"page_size"`
|
||||
Keyword string `form:"keyword" Json:"keyword"`
|
||||
Sort string `form:"sort" json:"sort" binding:"sql_sort"`
|
||||
}
|
||||
|
||||
type ResetPwdReq struct {
|
||||
Id uint `json:"id" binding:"required"`
|
||||
OldPwd string `json:"old_pwd" binding:"required"`
|
||||
|
|
@ -66,20 +59,6 @@ type GetUserReq struct {
|
|||
AppCode string `form:"app_code" json:"app_code" binding:"required"`
|
||||
}
|
||||
|
||||
func (q *Query) Default() {
|
||||
if q.Page < 0 {
|
||||
q.Page = 0
|
||||
}
|
||||
|
||||
if q.PageSize <= 0 {
|
||||
q.PageSize = 20
|
||||
}
|
||||
|
||||
if len(q.Sort) == 0 {
|
||||
q.Sort = "created_on desc"
|
||||
}
|
||||
}
|
||||
|
||||
type Enable struct {
|
||||
Id uint `json:"id" binding:"required"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ type RoleRepo interface{
|
|||
CreateUserRole(ctx context.Context,items []UserRole)error
|
||||
GetUserRolesByAccount(ctx context.Context,account string)([]Role,error)
|
||||
RemoveUserRole(ctx context.Context,items []UserRole)error
|
||||
SearchRoleUsers(ctx context.Context,roleCode string,query Query)([]User,error)
|
||||
|
||||
// 组织角色
|
||||
GetOrgRolesByIDs(ctx context.Context,ids []uint)([]Role,error)
|
||||
|
|
@ -49,6 +50,7 @@ type RoleRepo interface{
|
|||
GetRoleAllOrgAuthorsByRoleId(ctx context.Context,roleid uint)([]OrganizationRoleAuthor,error)
|
||||
CreateOrgAuthor(ctx context.Context,authors []OrganizationRoleAuthor)error
|
||||
DeleteOrgAuthor(ctx context.Context,roleId uint,orgIds []uint)error
|
||||
SearchOrgAuthor(ctx context.Context,roleId uint,query Query)([]Organization,error)
|
||||
|
||||
CreateOrgRole(ctx context.Context,orgRoles []OrganizationRole)error
|
||||
DeleteOrgRole(ctx context.Context,roleId uint,orgIds []uint)error
|
||||
|
|
@ -176,3 +178,28 @@ func (r *roleRepo)GetRoleAllOrgAuthorsByRoleId(ctx context.Context,roleid uint)(
|
|||
return authors,err
|
||||
}
|
||||
|
||||
func (r *roleRepo)SearchRoleUsers(ctx context.Context,roleCode string,query Query)([]User,error){
|
||||
users := make([]User,0)
|
||||
db := r.db.Model(User{}).Joins("join user_role on user_role.user_account = user.account user_role.role_code = ?",roleCode)
|
||||
|
||||
if query.Keyword != "" {
|
||||
keyword := fmt.Sprintf("%%%s%%", query.Keyword)
|
||||
db = db.Where("user.account like ? or user.name like ?", keyword, keyword)
|
||||
}
|
||||
|
||||
err := db.Order("user_role.created_on desc").Limit(query.PageSize).Offset(query.Page * query.PageSize).Find(&users).Error
|
||||
return users,err
|
||||
}
|
||||
|
||||
func (r *roleRepo)SearchOrgAuthor(ctx context.Context,roleId uint,query Query)([]Organization,error){
|
||||
orgs := make([]Organization,0)
|
||||
db := r.db.Model(Organization{}).Joins("join organization_role_author on organization_role_author.org_id = organization.id and organization_role_author.role_id = ?",roleId)
|
||||
|
||||
if query.Keyword != "" {
|
||||
keyword := fmt.Sprintf("%%%s%%", query.Keyword)
|
||||
db = db.Where("organization.name like ? ", keyword)
|
||||
}
|
||||
|
||||
err := db.Order("organization_role_author.created_on desc,organization.sort").Limit(query.PageSize).Offset(query.Page * query.PageSize).Find(&orgs).Error
|
||||
return orgs,err
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package repo
|
||||
|
||||
import (
|
||||
"busniess-user-center/internal/models/base"
|
||||
userModel "busniess-user-center/internal/models/user"
|
||||
"context"
|
||||
"fmt"
|
||||
|
|
@ -41,8 +42,8 @@ type UserRepo interface {
|
|||
SaveUser(ctx context.Context, user User) error
|
||||
CreateUser(ctx context.Context, user *User) error
|
||||
SetUserStatus(ctx context.Context, id uint, status userModel.UserStatus) error
|
||||
Search(ctx context.Context, query *userModel.Query) ([]User, error)
|
||||
SearchCount(ctx context.Context, query *userModel.Query) (int64, error)
|
||||
Search(ctx context.Context, query *base.Query) ([]User, error)
|
||||
SearchCount(ctx context.Context, query *base.Query) (int64, error)
|
||||
ResetPwd(ctx context.Context, user User) error
|
||||
GetUserById(ctx context.Context, id uint) (user User, err error)
|
||||
BatchGetUserByIDs(ctx context.Context, ids []uint) (users []User, err error)
|
||||
|
|
@ -90,7 +91,7 @@ func (u *userRepoS) SetUserStatus(ctx context.Context, id uint, status userModel
|
|||
return err
|
||||
}
|
||||
|
||||
func (u *userRepoS) Search(ctx context.Context, query *userModel.Query) ([]User, error) {
|
||||
func (u *userRepoS) Search(ctx context.Context, query *base.Query) ([]User, error) {
|
||||
users := make([]User, 0)
|
||||
|
||||
keyword := fmt.Sprintf("%%%s%%", query.Keyword)
|
||||
|
|
@ -108,7 +109,7 @@ func (u *userRepoS) ResetPwd(ctx context.Context, user User) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func (u *userRepoS) SearchCount(ctx context.Context, query *userModel.Query) (int64, error) {
|
||||
func (u *userRepoS) SearchCount(ctx context.Context, query *base.Query) (int64, error) {
|
||||
keyword := fmt.Sprintf("%%%s%%", query.Keyword)
|
||||
|
||||
db := u.db.Model(&User{})
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package organization
|
|||
|
||||
import (
|
||||
orgModel "busniess-user-center/internal/models/organization"
|
||||
userModel "busniess-user-center/internal/models/user"
|
||||
"context"
|
||||
)
|
||||
|
||||
|
|
@ -14,4 +15,7 @@ type OrganizationService interface {
|
|||
OrganizationTree(ctx context.Context) (orgModel.OrgTree, error)
|
||||
DisableOrganization(ctx context.Context, info *orgModel.DisableOrgReq) error
|
||||
EnableOrganization(ctx context.Context, info *orgModel.EnableOrgReq) error
|
||||
AddUser(ctx context.Context, info *orgModel.AddUsersReq) error
|
||||
RemoveUser(ctx context.Context, info *orgModel.RemoveUsersReq) error
|
||||
OrganizationUsers(ctx context.Context, orgId uint) ([]userModel.UserInfo, error)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package organization
|
|||
import (
|
||||
"busniess-user-center/config"
|
||||
orgModel "busniess-user-center/internal/models/organization"
|
||||
userModel "busniess-user-center/internal/models/user"
|
||||
"busniess-user-center/internal/repo"
|
||||
"busniess-user-center/internal/service/util"
|
||||
"busniess-user-center/pkg/redis"
|
||||
|
|
@ -184,3 +185,16 @@ func (o *organizationService) EnableOrganization(ctx context.Context, info *orgM
|
|||
// todo 判断有没有权限
|
||||
return o.orgRepo.SetStatus(ctx, info.Id, repo.OrganizationEnableStatus)
|
||||
}
|
||||
|
||||
func (o *organizationService) AddUser(ctx context.Context, info *orgModel.AddUsersReq) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *organizationService) RemoveUser(ctx context.Context, info *orgModel.RemoveUsersReq) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *organizationService) OrganizationUsers(ctx context.Context, orgId uint) ([]userModel.UserInfo, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ type RoleService interface {
|
|||
RemoveUsers(ctx context.Context, info *roleModel.RemoveUsersReq) error
|
||||
AddOrgs(ctx context.Context, info *roleModel.AddOrgsReq) error
|
||||
RemoveOrgs(ctx context.Context, info *roleModel.RemoveOrgsReq) error
|
||||
RoleUsers(ctx context.Context, info *roleModel.RoleUsersReq) ([]userModel.User, error)
|
||||
RoleUsers(ctx context.Context, info *roleModel.RoleUsersReq) ([]userModel.UserInfo, error)
|
||||
RoleOrgs(ctx context.Context, info *roleModel.RoleOrgsReq) ([]roleModel.OrgRoleAuthor, error)
|
||||
AuthorRoleMenu(ctx context.Context, info *roleModel.AuthorRoleMenuReq) error
|
||||
RemoveRoleMenu(ctx context.Context, info *roleModel.RemoveReleMenuReq) error
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ func (o *roleService) AddUsers(ctx context.Context, info *roleModel.AddUsersReq)
|
|||
return err
|
||||
}
|
||||
|
||||
perssion, err := o.hasPerssion(ctx, session)
|
||||
perssion, err := o.hasPermission(ctx, session)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -172,7 +172,7 @@ func (o *roleService) RemoveUsers(ctx context.Context, info *roleModel.RemoveUse
|
|||
return err
|
||||
}
|
||||
|
||||
perssion, err := o.hasPerssion(ctx, session)
|
||||
perssion, err := o.hasPermission(ctx, session)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -218,7 +218,7 @@ func (o *roleService) AddOrgs(ctx context.Context, info *roleModel.AddOrgsReq) e
|
|||
return err
|
||||
}
|
||||
|
||||
perssion, err := o.hasPerssion(ctx, session)
|
||||
perssion, err := o.hasPermission(ctx, session)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -278,7 +278,7 @@ func (o *roleService) RemoveOrgs(ctx context.Context, info *roleModel.RemoveOrgs
|
|||
return err
|
||||
}
|
||||
|
||||
perssion, err := o.hasPerssion(ctx, session)
|
||||
perssion, err := o.hasPermission(ctx, session)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -321,12 +321,42 @@ func (o *roleService) RemoveOrgs(ctx context.Context, info *roleModel.RemoveOrgs
|
|||
return nil
|
||||
}
|
||||
|
||||
func (u *roleService) RoleUsers(ctx context.Context, info *roleModel.RoleUsersReq) ([]userModel.User, error) {
|
||||
return nil, nil
|
||||
func (o *roleService) RoleUsers(ctx context.Context, info *roleModel.RoleUsersReq) ([]userModel.UserInfo, error) {
|
||||
role, err := o.roleRepo.GetById(ctx, info.Id)
|
||||
if err != nil && err != gorm.ErrRecordNotFound {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return nil, fmt.Errorf("角色%d不存在", info.Id)
|
||||
}
|
||||
|
||||
info.Query.Default()
|
||||
dbQuery := repo.Query{}
|
||||
copier.Copy(&dbQuery, info.Query)
|
||||
users, err := o.roleRepo.SearchRoleUsers(ctx, role.Code, dbQuery)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rUsers := make([]userModel.UserInfo, 0)
|
||||
copier.Copy(&rUsers, users)
|
||||
|
||||
return rUsers, nil
|
||||
}
|
||||
|
||||
func (u *roleService) RoleOrgs(ctx context.Context, info *roleModel.RoleOrgsReq) ([]roleModel.OrgRoleAuthor, error) {
|
||||
return nil, nil
|
||||
info.Query.Default()
|
||||
dbQuery := repo.Query{}
|
||||
copier.Copy(&dbQuery, info.Query)
|
||||
authors, err := u.roleRepo.SearchOrgAuthor(ctx, info.Id, dbQuery)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rAuthors := make([]roleModel.OrgRoleAuthor, 0)
|
||||
copier.Copy(&rAuthors, authors)
|
||||
return rAuthors, nil
|
||||
}
|
||||
|
||||
func (u *roleService) AuthorRoleMenu(ctx context.Context, info *roleModel.AuthorRoleMenuReq) error {
|
||||
|
|
@ -341,7 +371,7 @@ func (u *roleService) RoleMenuAuthorList(ctx context.Context, info *roleModel.Ad
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
func (u *roleService) hasPerssion(ctx context.Context, session *session.Session) (bool, error) {
|
||||
func (u *roleService) hasPermission(ctx context.Context, session *session.Session) (bool, error) {
|
||||
user, err := u.userService.GetUser(ctx, &userModel.GetUserReq{Account: session.Account, AppCode: session.AppCode})
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package user
|
||||
|
||||
import (
|
||||
"busniess-user-center/internal/models/base"
|
||||
userModel "busniess-user-center/internal/models/user"
|
||||
|
||||
"context"
|
||||
|
|
@ -13,9 +14,9 @@ type UserService interface {
|
|||
Modify(ctx context.Context, mInfo *userModel.ModifyInfo) error
|
||||
Disable(ctx context.Context, req *userModel.Enable) error
|
||||
Enable(ctx context.Context, req *userModel.Enable) error
|
||||
Search(ctx context.Context, query *userModel.Query) (*userModel.SearchRsp, error)
|
||||
Search(ctx context.Context, query *base.Query) (*userModel.SearchRsp, error)
|
||||
ResetPwd(ctx context.Context, req *userModel.ResetPwdReq) error
|
||||
GetUser(ctx context.Context, req *userModel.GetUserReq) (user userModel.User, err error)
|
||||
ExistUserByAccount(ctx context.Context, account string) (uint, error)
|
||||
BatchGetUserByIDs(ctx context.Context,ids []uint)([]userModel.UserInfo,error)
|
||||
BatchGetUserByIDs(ctx context.Context, ids []uint) ([]userModel.UserInfo, error)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package user
|
|||
|
||||
import (
|
||||
"busniess-user-center/config"
|
||||
"busniess-user-center/internal/models/base"
|
||||
"busniess-user-center/internal/models/role"
|
||||
userModel "busniess-user-center/internal/models/user"
|
||||
"busniess-user-center/internal/repo"
|
||||
|
|
@ -189,7 +190,7 @@ func (u *userService) Enable(ctx context.Context, req *userModel.Enable) error {
|
|||
return u.repo.SetUserStatus(ctx, req.Id, userModel.EnableUserStatus)
|
||||
}
|
||||
|
||||
func (u *userService) Search(ctx context.Context, query *userModel.Query) (*userModel.SearchRsp, error) {
|
||||
func (u *userService) Search(ctx context.Context, query *base.Query) (*userModel.SearchRsp, error) {
|
||||
// 获取操作用户
|
||||
_, err := contextUtil.GetSession(ctx)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -85,8 +85,8 @@ func convertUserList(users []repo.User) []userModel.User {
|
|||
|
||||
func convertUser(user repo.User) userModel.User {
|
||||
return userModel.User{
|
||||
Id: user.ID,
|
||||
UserInfo: userModel.UserInfo{
|
||||
Id: user.ID,
|
||||
Name: user.Name,
|
||||
Account: user.Account,
|
||||
Mobile: user.Mobile,
|
||||
|
|
@ -118,4 +118,3 @@ func removeRepeatRole(sroles ...[]repo.Role) []repo.Role {
|
|||
|
||||
return roles
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -74,6 +74,7 @@ func (u *OrganizationServer) EnableOrganization(ctx context.Context, info *orgMo
|
|||
}
|
||||
|
||||
func (u *OrganizationServer) AddUsers(ctx context.Context, info *orgModel.AddUsersReq) error {
|
||||
|
||||
// todo
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ func (u *RoleServer) RemoveOrgs(ctx context.Context, info *roleModel.RemoveOrgsR
|
|||
return u.roleService.RemoveOrgs(ctx, info)
|
||||
}
|
||||
|
||||
func (u *RoleServer) RoleUsers(ctx context.Context, info *roleModel.RoleUsersReq) ([]userModel.User, error) {
|
||||
func (u *RoleServer) RoleUsers(ctx context.Context, info *roleModel.RoleUsersReq) ([]userModel.UserInfo, error) {
|
||||
return u.roleService.RoleUsers(ctx, info)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package user
|
||||
|
||||
import (
|
||||
"busniess-user-center/internal/models/base"
|
||||
userModel "busniess-user-center/internal/models/user"
|
||||
"busniess-user-center/internal/service/user"
|
||||
|
||||
|
|
@ -83,7 +84,7 @@ func (u *UserServer) Enable(ctx context.Context, req *userModel.Enable) error {
|
|||
return u.userService.Enable(ctx, req)
|
||||
}
|
||||
|
||||
func (u *UserServer) Search(ctx context.Context, query *userModel.Query) (*userModel.SearchRsp, error) {
|
||||
func (u *UserServer) Search(ctx context.Context, query *base.Query) (*userModel.SearchRsp, error) {
|
||||
query.Default()
|
||||
return u.userService.Search(ctx, query)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue