diff --git a/README.md b/README.md index f5fea10..ada8f28 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,8 @@ v0.1.0 3> 用户中心的登陆单独处理 v0.1.1 - 1> 用户中心的登陆和其他应用的登陆统一做成sso + 1> 用户中心的登陆和其他应用的登陆统一做成sso + 2> 支持同步企业微信,钉钉等第三方的用户,组织等信息 v0.2.0 diff --git a/deploy/sql/init/user.sql b/deploy/sql/init/user.sql index f51bfa9..4ba0c5a 100644 --- a/deploy/sql/init/user.sql +++ b/deploy/sql/init/user.sql @@ -9,6 +9,7 @@ CREATE TABLE IF NOT EXISTS `user` ( `salt` varchar(32) NOT NULL COMMENT '盐', `sex` TINYINT DEFAULT 0 COMMENT '性别:0-女,1-男', `status` TINYINT DEFAULT 1 NOT NULL COMMENT '状态:0-禁用,1-启用', + `direct_leaders` VARCHAR(64) DEFAULT'' COMMENT '直属领导账号', `created_by` VARCHAR(64) DEFAULT '' COMMENT '创建人', `created_on` DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL COMMENT '记录创建时间', `modified_by` VARCHAR(64) DEFAULT '' COMMENT '修改人', @@ -28,6 +29,7 @@ CREATE TABLE IF NOT EXISTS `organization` ( `sort` SMALLINT UNSIGNED DEFAULT 0 COMMENT '层级序号', `status` TINYINT DEFAULT 1 COMMENT '状态:0-无效,1-有效', `path` VARCHAR(1024) COMMENT '全路径', + `leaders` VARCHAR(1024) COMMENT '领导账号列表:["user1","user2"]', `created_by` VARCHAR(64) DEFAULT '' COMMENT '创建人', `created_on` DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL COMMENT '记录创建时间', `modified_by` VARCHAR(64) DEFAULT '' COMMENT '修改人', @@ -143,7 +145,8 @@ CREATE TABLE IF NOT EXISTS `role_menu_permission`( `created_on` DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL COMMENT '记录创建时间', `modified_by` VARCHAR(64) DEFAULT '' COMMENT '修改人', `modified_on` DATETIME DEFAULT CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP COMMENT '记录修改时间', - PRIMARY KEY (`id`) + PRIMARY KEY (`id`), + UNIQUE KEY `uk_role_menu`(`role_id`,`menu_id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb3 COMMENT='角色菜单权限表'; diff --git a/internal/models/organization/organization.go b/internal/models/organization/organization.go index dac1986..253ff33 100644 --- a/internal/models/organization/organization.go +++ b/internal/models/organization/organization.go @@ -3,12 +3,13 @@ package organization import "time" type Organization struct { - ID uint `json:"id"` // id - Name string `json:"name"` // 组织名 - ParentID uint `json:"parent_id"` // 上级组织id - Sort uint `json:"sort"` // 层级序号 - Status int `json:"status"` // 状态:0-无效,1-有效 - Path string `json:"path"` // 全路径 + ID uint `json:"id"` // id + Name string `json:"name"` // 组织名 + ParentID uint `json:"parent_id"` // 上级组织id + Sort uint `json:"sort"` // 层级序号 + Status int `json:"status"` // 状态:0-无效,1-有效 + Path string `json:"path"` // 全路径 + Leaders []string `json:"leaders"` CreatedOn time.Time `json:"created_on"` // 记录创建时间 Children []Organization `json:"children"` } diff --git a/internal/models/organization/request.go b/internal/models/organization/request.go index 8620fab..102eda8 100644 --- a/internal/models/organization/request.go +++ b/internal/models/organization/request.go @@ -1,9 +1,10 @@ package organization type CreateOrgReq struct { - Name string `json:"name" binding:"required"` - ParentId uint `json:"parent_id" binding:"required"` - Sort int `json:"sort" binding:"required"` + Name string `json:"name" binding:"required"` + ParentId uint `json:"parent_id" binding:"required"` + Sort int `json:"sort" binding:"required"` + Leaders []string `json:"leaders"` } type DelOrgReq struct { @@ -20,10 +21,11 @@ type MoveOrgReq struct { } type SaveOrgReq struct { - Id uint `json:"id" binding:"required"` - Name string `json:"name" binding:"required"` - ParentId uint `json:"parent_id" binding:"required"` - Sort int `json:"sort" binding:"required"` + Id uint `json:"id" binding:"required"` + Name string `json:"name" binding:"required"` + ParentId uint `json:"parent_id" binding:"required"` + Sort int `json:"sort" binding:"required"` + Leaders []string `json:"leaders"` } type DisableOrgReq struct { @@ -33,3 +35,11 @@ type DisableOrgReq struct { type EnableOrgReq struct { Id uint `json:"id" binding:"required"` } + +type AddUsersReq struct { + Ids []uint `json:"ids"` +} + +type RemoveUsersReq struct { + Ids []uint `json:"ids"` +} diff --git a/internal/models/role/request.go b/internal/models/role/request.go index d5aa830..b60f8ff 100644 --- a/internal/models/role/request.go +++ b/internal/models/role/request.go @@ -39,3 +39,53 @@ type DelReq struct { type GetReq struct { Id uint `form:"id" json:"id" binding:"required"` } + +type AddUsersReq struct { + Ids []uint `json:"ids"` +} + +type RemoveUsersReq struct { + Ids []uint `json:"ids"` +} + +type OrgAuthorRoleType int + +const ( + ExcludeChildrenOrgAuthor OrgAuthorRoleType = 0 + IncludeChildrenOrgAuthor OrgAuthorRoleType = 1 +) + +type OrgAuthorBrief struct { + Id uint `json:"id" binding:"required"` + Type OrgAuthorRoleType `json:"type"` +} + +type AddOrgsReq struct { + Orgs OrgAuthorBrief `json:"orgs"` +} + +type RemoveOrgsReq struct { + Ids []uint `json:"ids"` +} + +type RoleUsersReq struct { + Id uint `json:"id" binding:"required"` +} + +type RoleOrgsReq struct { + Id uint `json:"id" binding:"required"` +} + +type AuthorRoleMenuReq struct { + AppCode string `json:"app_code" binding:"required"` + Ids []uint `json:"ids" binding:"required"` +} + +type RemoveReleMenuReq struct { + Ids []uint `json:"ids"` +} + +type RoleMenuListReq struct { + AppCode string `json:"app_code" binding:"required"` + RoleId uint `json:"role_id" binding:"required"` +} diff --git a/internal/models/role/role.go b/internal/models/role/role.go index 302a4d7..25a684f 100644 --- a/internal/models/role/role.go +++ b/internal/models/role/role.go @@ -1,6 +1,9 @@ package role -import "time" +import ( + appModel "busniess-user-center/internal/models/application" + "time" +) type Role struct { ID uint `json:"id"` // id @@ -8,3 +11,20 @@ type Role struct { Name string `json:"name"` // 名称 CreatedOn time.Time `json:"created_on"` // 记录创建时间 } + +type OrgRoleAuthor struct { + ID uint `json:"id"` // id + OrgId uint `json:"org_id"` + OrgName string `json:"org_name"` + RoleId uint `json:"role_id"` + RoleName string `json:"role_name"` + Option int `json:"option"` //选择:0-选择组织,1-选择组织含下级 +} + +type RoleMenu struct { + appModel.Menu + RoleId uint `json:"role_id"` + RoleName uint `json:"role_name"` + RoleCode uint `json:"role_code"` + Author bool `json:"author"` +} diff --git a/internal/models/user/user.go b/internal/models/user/user.go index 02737e8..3325bff 100644 --- a/internal/models/user/user.go +++ b/internal/models/user/user.go @@ -1,5 +1,11 @@ package models +import ( + appModel "busniess-user-center/internal/models/application" + orgModel "busniess-user-center/internal/models/organization" + roleModel "busniess-user-center/internal/models/role" +) + type UserStatus int const ( @@ -32,6 +38,9 @@ type UserInfo struct { type User struct { Id uint UserInfo + Roles []roleModel.Role + Orgs []orgModel.Organization + Menus appModel.MenuTree } type ModifyInfo struct { @@ -54,6 +63,7 @@ type ResetPwdReq struct { type GetUserReq struct { Account string `form:"account" json:"account" binding:"required"` + AppCode string `form:"app_code" json:"app_code" binding:"required"` } func (q *Query) Default() { diff --git a/internal/repo/organization.go b/internal/repo/organization.go index 802b301..f438d39 100644 --- a/internal/repo/organization.go +++ b/internal/repo/organization.go @@ -28,6 +28,7 @@ type Organization struct { Sort uint `gorm:"column:sort;default:0"` // 层级序号 Status int `gorm:"column:status;default:1"` // 状态:0-无效,1-有效 Path string `gorm:"column:path"` // 全路径 + Leaders string `gorm:"column:leaders"` CreatedBy string `gorm:"column:created_by"` // 创建人 CreatedOn time.Time `gorm:"column:created_on;default:CURRENT_TIMESTAMP;NOT NULL"` // 记录创建时间 ModifiedBy string `gorm:"column:modified_by"` // 修改人 diff --git a/server/organization/organization.go b/server/organization/organization.go index e0ea021..e348b74 100644 --- a/server/organization/organization.go +++ b/server/organization/organization.go @@ -72,3 +72,13 @@ func (u *OrganizationServer) DisableOrganization(ctx context.Context, info *orgM func (u *OrganizationServer) EnableOrganization(ctx context.Context, info *orgModel.EnableOrgReq) error { return u.organizationService.EnableOrganization(ctx, info) } + +func (u *OrganizationServer) AddUsers(ctx context.Context, info *orgModel.AddUsersReq) error { + // todo + return nil +} + +func (u *OrganizationServer) RemoveUsers(ctx context.Context, info *orgModel.RemoveUsersReq) error { + // todo + return nil +} diff --git a/server/role/role.go b/server/role/role.go index 8f27b18..00b0766 100644 --- a/server/role/role.go +++ b/server/role/role.go @@ -4,6 +4,7 @@ import ( "context" roleModel "busniess-user-center/internal/models/role" + userModel "busniess-user-center/internal/models/user" roleService "busniess-user-center/internal/service/role" ginUtil "busniess-user-center/pkg/utils/gin" @@ -57,3 +58,39 @@ func (u *RoleServer) Role(ctx context.Context, info *roleModel.GetReq) (roleMode func (u *RoleServer) Search(ctx context.Context, info *roleModel.Query) ([]roleModel.Role, error) { return u.roleService.Search(ctx, info) } + +func (u *RoleServer) AddUsers(ctx context.Context, info *roleModel.AddUsersReq) error { + return nil +} + +func (u *RoleServer) RemoveUsers(ctx context.Context, info *roleModel.RemoveUsersReq) error { + return nil +} + +func (u *RoleServer) AddOrgs(ctx context.Context, info *roleModel.AddOrgsReq) error { + return nil +} + +func (u *RoleServer) RemoveOrgs(ctx context.Context, info *roleModel.RemoveOrgsReq) error { + return nil +} + +func (u *RoleServer) RoleUsers(ctx context.Context, info *roleModel.RoleUsersReq) ([]userModel.User, error) { + return nil, nil +} + +func (u *RoleServer) RoleOrgs(ctx context.Context, info *roleModel.RoleOrgsReq) ([]roleModel.OrgRoleAuthor, error) { + return nil, nil +} + +func (u *RoleServer) AuthorRoleMenu(ctx context.Context, info *roleModel.AuthorRoleMenuReq) error { + return nil +} + +func (u *RoleServer) RemoveRoleMenu(ctx context.Context, info *roleModel.RemoveReleMenuReq) error { + return nil +} + +func (u *RoleServer) RoleMenuAuthorList(ctx context.Context, info *roleModel.AddOrgsReq) ([]roleModel.RoleMenu, error) { + return nil, nil +}