From 88771a470ac1c729f46550f4f0d607814348017e Mon Sep 17 00:00:00 2001 From: guosl Date: Wed, 31 Jul 2024 19:31:02 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=84=E7=BB=87=E6=B7=BB=E5=8A=A0=E7=94=A8?= =?UTF-8?q?=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/repo/user_organization.go | 17 ++++++++++++++++- internal/service/organization/interface.go | 2 +- internal/service/organization/organization.go | 11 ++++++++++- server/organization/organization.go | 15 ++++++++++----- 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/internal/repo/user_organization.go b/internal/repo/user_organization.go index 2c89b49..7d68e9b 100644 --- a/internal/repo/user_organization.go +++ b/internal/repo/user_organization.go @@ -2,6 +2,7 @@ package repo import ( + "context" "time" "github.com/samber/do" @@ -29,7 +30,9 @@ func (m *UserOrganization) TableName() string { } type UserOrganizationRepo interface{ - + Create(ctx context.Context,userOrgs []UserOrganization)error + Delete(ctx context.Context,orgId uint,userIds []uint)error + SearchOrgUser(ctx context.Context,orgId uint,query Query)([]User,error) } type userOrganizationRepo struct{ @@ -40,4 +43,16 @@ func NewUserOrganizationRepo(i *do.Injector)(UserOrganizationRepo,error){ return &userOrganizationRepo{ db:do.MustInvoke[*gorm.DB](i), },nil +} + +func (u *userOrganizationRepo)Create(ctx context.Context,userOrgs []UserOrganization)error{ + return u.db.Create(userOrgs).Error +} + +func (u *userOrganizationRepo)Delete(ctx context.Context,orgId uint,userIds []uint)error{ + return u.db.Where("org_id = ? and user_id in ?",orgId,userIds).Delete(&UserOrganization{}).Error +} + +func (u *userOrganizationRepo)SearchOrgUser(ctx context.Context,orgId uint,query Query)([]User,error){ + return nil,nil } \ No newline at end of file diff --git a/internal/service/organization/interface.go b/internal/service/organization/interface.go index d92e43b..08f2138 100644 --- a/internal/service/organization/interface.go +++ b/internal/service/organization/interface.go @@ -17,5 +17,5 @@ type OrganizationService interface { 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) + SearchOrgUsers(ctx context.Context, query *orgModel.SearchOrgUserReq) ([]userModel.UserInfo, error) } diff --git a/internal/service/organization/organization.go b/internal/service/organization/organization.go index f70c022..d5d5214 100644 --- a/internal/service/organization/organization.go +++ b/internal/service/organization/organization.go @@ -187,7 +187,16 @@ func (o *organizationService) EnableOrganization(ctx context.Context, info *orgM } func (o *organizationService) AddUser(ctx context.Context, info *orgModel.AddUsersReq) error { + org, err := o.orgRepo.GetById(ctx, info.OrgId) + if err != nil && err != gorm.ErrRecordNotFound { + return err + } + if err == gorm.ErrRecordNotFound { + return fmt.Errorf("组织%d不存在", info.OrgId) + } + + o.orgRepo.Create() return nil } @@ -195,6 +204,6 @@ func (o *organizationService) RemoveUser(ctx context.Context, info *orgModel.Rem return nil } -func (o *organizationService) OrganizationUsers(ctx context.Context, orgId uint) ([]userModel.UserInfo, error) { +func (o *organizationService) SearchOrgUsers(ctx context.Context, query *orgModel.SearchOrgUserReq) ([]userModel.UserInfo, error) { return nil, nil } diff --git a/server/organization/organization.go b/server/organization/organization.go index 5615786..45cc2bc 100644 --- a/server/organization/organization.go +++ b/server/organization/organization.go @@ -4,6 +4,7 @@ import ( "context" orgModel "busniess-user-center/internal/models/organization" + userModel "busniess-user-center/internal/models/user" organizationService "busniess-user-center/internal/service/organization" ginUtil "busniess-user-center/pkg/utils/gin" @@ -38,6 +39,9 @@ func RegisterRoute(api *gin.RouterGroup) { api.GET("/orgs", ginUtil.WrapNoReq(server.OrganizationTree)) api.POST("/disenable", ginUtil.WrapNoRsp(server.DisableOrganization)) api.POST("/enable", ginUtil.WrapNoRsp(server.EnableOrganization)) + api.POST("/adduser", ginUtil.WrapNoRsp(server.AddUsers)) + api.DELETE("/removeuser", ginUtil.WrapNoRsp(server.RemoveUsers)) + api.GET("/search_org_user", ginUtil.WrapNoRsp(server.RemoveUsers)) } func (u *OrganizationServer) Create(ctx context.Context, req *orgModel.CreateOrgReq) (err error) { @@ -74,12 +78,13 @@ func (u *OrganizationServer) EnableOrganization(ctx context.Context, info *orgMo } func (u *OrganizationServer) AddUsers(ctx context.Context, info *orgModel.AddUsersReq) error { - - // todo - return nil + return u.organizationService.AddUser(ctx, info) } func (u *OrganizationServer) RemoveUsers(ctx context.Context, info *orgModel.RemoveUsersReq) error { - // todo - return nil + return u.organizationService.RemoveUser(ctx, info) +} + +func (u *OrganizationServer) SearchOrgUsers(ctx context.Context, query *orgModel.SearchOrgUserReq) ([]userModel.UserInfo, error) { + return u.organizationService.SearchOrgUsers(ctx, query) }