From 066fae0b747c9d66f4b21270ae63dc8ba5ce28cd Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Wed, 20 Apr 2022 11:53:32 +0800 Subject: [PATCH] Organization --- internal/rpc/organization/organization.go | 10 +++++++ .../im_mysql_model/organization_model.go | 29 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/internal/rpc/organization/organization.go b/internal/rpc/organization/organization.go index 7f1de1cde..d9f503d69 100644 --- a/internal/rpc/organization/organization.go +++ b/internal/rpc/organization/organization.go @@ -140,6 +140,16 @@ func (s *organizationServer) GetSubDepartment(ctx context.Context, req *rpc.GetS v1 := open_im_sdk.Department{} utils.CopyStructFields(&v1, v) log.Debug(req.OperationID, "src ", v, "dst ", v1) + err, v1.MemberNum = imdb.GetDepartmentMemberNum(v1.DepartmentID) + if err != nil { + log.Error(req.OperationID, "GetDepartmentMemberNum failed ", err.Error(), v1.DepartmentID) + continue + } + err, v1.SubDepartmentNum = imdb.GetSubDepartmentNum(v1.DepartmentID) + if err != nil { + log.Error(req.OperationID, "GetSubDepartmentNum failed ", err.Error(), v1.DepartmentID) + continue + } resp.DepartmentList = append(resp.DepartmentList, &v1) } log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", *resp) diff --git a/pkg/common/db/mysql_model/im_mysql_model/organization_model.go b/pkg/common/db/mysql_model/im_mysql_model/organization_model.go index c3005fcec..2eacf7a44 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/organization_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/organization_model.go @@ -2,6 +2,7 @@ package im_mysql_model import ( "Open_IM/pkg/common/db" + "Open_IM/pkg/utils" "time" ) @@ -207,3 +208,31 @@ func GetAllOrganizationUserID() (error, []string) { var result []string return dbConn.Model(&OrganizationUser).Pluck("user_id", &result).Error, result } + +func GetDepartmentMemberNum(departmentID string) (error, uint32) { + dbConn, err := db.DB.MysqlDB.DefaultGormDB() + if err != nil { + return utils.Wrap(err, "DefaultGormDB failed"), 0 + } + var number uint32 + err = dbConn.Table("department_members").Where("department_id=?", departmentID).Count(&number).Error + if err != nil { + return utils.Wrap(err, ""), 0 + } + return nil, number + +} + +func GetSubDepartmentNum(departmentID string) (error, uint32) { + dbConn, err := db.DB.MysqlDB.DefaultGormDB() + if err != nil { + return utils.Wrap(err, "DefaultGormDB failed"), 0 + } + var number uint32 + err = dbConn.Table("departments").Where("parent_id=?", departmentID).Count(&number).Error + if err != nil { + return utils.Wrap(err, ""), 0 + } + return nil, number + +}