mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-04 09:05:59 +08:00
organization
This commit is contained in:
committed by
Xinwei Xiong(cubxxw-openim)
parent
143c0e022c
commit
a5455feff4
@@ -388,6 +388,11 @@ type config struct {
|
||||
OfflinePush POfflinePush `yaml:"offlinePush"`
|
||||
DefaultTips PDefaultTips `yaml:"defaultTips"`
|
||||
} `yaml:"workMomentsNotification"`
|
||||
JoinDepartmentNotification struct {
|
||||
Conversation PConversation `yaml:"conversation"`
|
||||
OfflinePush POfflinePush `yaml:"offlinePush"`
|
||||
DefaultTips PDefaultTips `yaml:"defaultTips"`
|
||||
} `yaml:"joinDepartmentNotification"`
|
||||
}
|
||||
Demo struct {
|
||||
Port []int `yaml:"openImDemoPort"`
|
||||
@@ -406,6 +411,7 @@ type config struct {
|
||||
SmtpAddr string `yaml:"smtpAddr"`
|
||||
SmtpPort int `yaml:"smtpPort"`
|
||||
}
|
||||
TestDepartMentID string `yaml:"testDepartMentID"`
|
||||
}
|
||||
Rtc struct {
|
||||
Port int `yaml:"port"`
|
||||
|
||||
@@ -148,6 +148,10 @@ const (
|
||||
GroupStatusDismissed = 2
|
||||
GroupStatusMuted = 3
|
||||
|
||||
//GroupType
|
||||
NormalGroup = 0
|
||||
DepartmentGroup = 1
|
||||
|
||||
GroupBaned = 3
|
||||
GroupBanPrivateChat = 4
|
||||
|
||||
|
||||
@@ -232,6 +232,7 @@ type Department struct {
|
||||
ParentID string `gorm:"column:parent_id;size:64" json:"parentID" binding:"required"` // "0" or Real parent id
|
||||
Order int32 `gorm:"column:order" json:"order" ` // 1, 2, ...
|
||||
DepartmentType int32 `gorm:"column:department_type" json:"departmentType"` //1, 2...
|
||||
RelatedGroupID string `gorm:"column:related_group_id;size:64" json:"relatedGroupID"`
|
||||
CreateTime time.Time `gorm:"column:create_time" json:"createTime"`
|
||||
Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ func initMysqlDB() {
|
||||
&GroupMember{},
|
||||
&GroupRequest{},
|
||||
&User{},
|
||||
&Black{}, &ChatLog{}, &Register{}, &Conversation{}, &AppVersion{})
|
||||
&Black{}, &ChatLog{}, &Register{}, &Conversation{}, &AppVersion{}, &Department{})
|
||||
db.Set("gorm:table_options", "CHARSET=utf8")
|
||||
db.Set("gorm:table_options", "collation=utf8_unicode_ci")
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package im_mysql_model
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/utils"
|
||||
"github.com/jinzhu/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -234,5 +235,48 @@ func GetSubDepartmentNum(departmentID string) (error, uint32) {
|
||||
return utils.Wrap(err, ""), 0
|
||||
}
|
||||
return nil, number
|
||||
|
||||
}
|
||||
|
||||
func GetDepartmentRelatedGroupIDList(departmentIDList []string) ([]string, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "DefaultGormDB failed")
|
||||
}
|
||||
var groupIDList []string
|
||||
err = dbConn.Table("departments").Where("department_id IN (?) ", departmentIDList).Pluck("related_group_id", &groupIDList).Error
|
||||
return groupIDList, err
|
||||
}
|
||||
|
||||
func getDepartmentParent(departmentID string, dbConn *gorm.DB) (*db.Department, error) {
|
||||
var department db.Department
|
||||
var parentID string
|
||||
dbConn.LogMode(true)
|
||||
// select * from departments where department_id = (select parent_id from departments where department_id= zx234fd);
|
||||
err := dbConn.Table("departments").Where("department_id=?", dbConn.Table("departments").Where("department_id=?", departmentID).Pluck("parent_id", parentID)).Error
|
||||
return &department, err
|
||||
}
|
||||
|
||||
func GetDepartmentParent(departmentID string, dbConn *gorm.DB, parentIDList []string) (*db.Department, error) {
|
||||
department, err := getDepartmentParent(departmentID, dbConn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if department.ParentID != "" {
|
||||
parentIDList = append(parentIDList, department.ParentID)
|
||||
_, err = GetDepartmentParent(departmentID, dbConn, parentIDList)
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func GetDepartmentParentIDList(departmentID string) ([]string, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var parentIDList []string
|
||||
_, err = GetDepartmentParent(departmentID, dbConn, parentIDList)
|
||||
return parentIDList, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user