You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/pkg/common/db/relation/group_member_model.go

235 lines
8.0 KiB

2 years ago
package relation
3 years ago
//type GroupMember struct {
// GroupID string `gorm:"column:group_id;primaryKey;"`
// UserID string `gorm:"column:user_id;primaryKey;"`
// NickName string `gorm:"column:nickname"`
// FaceUrl string `gorm:"user_group_face_url"`
// RoleLevel int32 `gorm:"column:role_level"`
// JoinTime time.Time `gorm:"column:join_time"`
// JoinSource int32 `gorm:"column:join_source"`
// OperatorUserID string `gorm:"column:operator_user_id"`
// Ex string `gorm:"column:ex"`
//}
//func InsertIntoGroupMember(toInsertInfo GroupMember) error {
// toInsertInfo.JoinTime = time.Now()
// if toInsertInfo.RoleLevel == 0 {
// toInsertInfo.RoleLevel = constant.GroupOrdinaryUsers
// }
// toInsertInfo.MuteEndTime = time.Unix(int64(time.Now().Second()), 0)
2 years ago
// err := DB.DB.MysqlDB.DefaultGormDB().Table("group_members").Create(toInsertInfo).Error
// if err != nil {
// return err
// }
// return nil
//}
2 years ago
//func BatchInsertIntoGroupMember(toInsertInfoList []*GroupMember) error {
// for _, toInsertInfo := range toInsertInfoList {
// toInsertInfo.JoinTime = time.Now()
// if toInsertInfo.RoleLevel == 0 {
// toInsertInfo.RoleLevel = constant.GroupOrdinaryUsers
// }
// toInsertInfo.MuteEndTime = time.Unix(int64(time.Now().Second()), 0)
// }
2 years ago
// return DB.DB.MysqlDB.DefaultGormDB().Create(toInsertInfoList).Error
2 years ago
//
//}
//
//func GetGroupMemberListByUserID(userID string) ([]GroupMember, error) {
// var groupMemberList []GroupMember
2 years ago
// err := DB.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("user_id=?", userID).Find(&groupMemberList).Error
2 years ago
// if err != nil {
// return nil, err
// }
// return groupMemberList, nil
//}
//
//func GetGroupMemberListByGroupID(groupID string) ([]GroupMember, error) {
// var groupMemberList []GroupMember
2 years ago
// err := DB.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupID).Find(&groupMemberList).Error
2 years ago
// if err != nil {
// return nil, err
// }
// return groupMemberList, nil
//}
//
//func GetGroupMemberIDListByGroupID(groupID string) ([]string, error) {
// var groupMemberIDList []string
2 years ago
// err := DB.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupID).Pluck("user_id", &groupMemberIDList).Error
2 years ago
// if err != nil {
// return nil, err
// }
// return groupMemberIDList, nil
//}
//
//func GetGroupMemberListByGroupIDAndRoleLevel(groupID string, roleLevel int32) ([]GroupMember, error) {
// var groupMemberList []GroupMember
2 years ago
// err := DB.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and role_level=?", groupID, roleLevel).Find(&groupMemberList).Error
2 years ago
// if err != nil {
// return nil, err
// }
// return groupMemberList, nil
//}
//
//func GetGroupMemberInfoByGroupIDAndUserID(groupID, userID string) (*GroupMember, error) {
// var groupMember GroupMember
2 years ago
// err := DB.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and user_id=? ", groupID, userID).Limit(1).Take(&groupMember).Error
2 years ago
// if err != nil {
// return nil, err
// }
// return &groupMember, nil
//}
//
//func DeleteGroupMemberByGroupIDAndUserID(groupID, userID string) error {
2 years ago
// return DB.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and user_id=? ", groupID, userID).Delete(GroupMember{}).Error
2 years ago
//}
//
//func DeleteGroupMemberByGroupID(groupID string) error {
2 years ago
// return DB.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? ", groupID).Delete(GroupMember{}).Error
2 years ago
//}
//
//func UpdateGroupMemberInfo(groupMemberInfo GroupMember) error {
2 years ago
// return DB.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and user_id=?", groupMemberInfo.GroupID, groupMemberInfo.UserID).Updates(&groupMemberInfo).Error
2 years ago
//}
//
//func UpdateGroupMemberInfoByMap(groupMemberInfo GroupMember, m map[string]interface{}) error {
2 years ago
// return DB.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and user_id=?", groupMemberInfo.GroupID, groupMemberInfo.UserID).Updates(m).Error
2 years ago
//}
//
//func GetOwnerManagerByGroupID(groupID string) ([]GroupMember, error) {
// var groupMemberList []GroupMember
2 years ago
// err := DB.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and role_level>?", groupID, constant.GroupOrdinaryUsers).Find(&groupMemberList).Error
2 years ago
// if err != nil {
// return nil, err
// }
// return groupMemberList, nil
//}
//
//func GetGroupMemberNumByGroupID(groupID string) (int64, error) {
// var number int64
2 years ago
// err := DB.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupID).Count(&number).Error
2 years ago
// if err != nil {
// return 0, utils.Wrap(err, "")
// }
// return number, nil
//}
3 years ago
//func GetGroupOwnerInfoByGroupID(groupID string) (*GroupMember, error) {
// omList, err := GetOwnerManagerByGroupID(groupID)
// if err != nil {
// return nil, err
// }
// for _, v := range omList {
// if v.RoleLevel == constant.GroupOwner {
// return &v, nil
// }
// }
// return nil, utils.Wrap(constant.ErrNoGroupOwner, "")
//}
//
//func IsExistGroupMember(groupID, userID string) bool {
// var number int64
2 years ago
// err := DB.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id = ? and user_id = ?", groupID, userID).Count(&number).Error
// if err != nil {
// return false
// }
// if number != 1 {
// return false
// }
// return true
//}
//
//func GetGroupMemberByGroupID(groupID string, filter int32, begin int32, maxNumber int32) ([]GroupMember, error) {
// var memberList []GroupMember
// var err error
// if filter >= 0 {
// memberList, err = GetGroupMemberListByGroupIDAndRoleLevel(groupID, filter) //sorted by join time
// } else {
// memberList, err = GetGroupMemberListByGroupID(groupID)
// }
//
// if err != nil {
// return nil, err
// }
// if begin >= int32(len(memberList)) {
// return nil, nil
// }
//
// var end int32
// if begin+int32(maxNumber) < int32(len(memberList)) {
// end = begin + maxNumber
// } else {
// end = int32(len(memberList))
// }
// return memberList[begin:end], nil
//}
//
//func GetJoinedGroupIDListByUserID(userID string) ([]string, error) {
// memberList, err := GetGroupMemberListByUserID(userID)
// if err != nil {
// return nil, err
// }
// var groupIDList []string
// for _, v := range memberList {
// groupIDList = append(groupIDList, v.GroupID)
// }
// return groupIDList, nil
//}
//
//func IsGroupOwnerAdmin(groupID, UserID string) bool {
// groupMemberList, err := GetOwnerManagerByGroupID(groupID)
// if err != nil {
// return false
// }
// for _, v := range groupMemberList {
// if v.UserID == UserID && v.RoleLevel > constant.GroupOrdinaryUsers {
// return true
// }
// }
// return false
//}
//
//func GetGroupMembersByGroupIdCMS(groupId string, userName string, showNumber, pageNumber int32) ([]GroupMember, error) {
// var groupMembers []GroupMember
2 years ago
// err := DB.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupId).Where(fmt.Sprintf(" nickname like '%%%s%%' ", userName)).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&groupMembers).Error
// if err != nil {
// return nil, err
// }
// return groupMembers, nil
//}
//
//func GetGroupMembersCount(groupID, userName string) (int64, error) {
// var count int64
2 years ago
// if err := DB.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupID).Where(fmt.Sprintf(" nickname like '%%%s%%' ", userName)).Count(&count).Error; err != nil {
// return count, err
// }
// return count, nil
//}
//
//func UpdateGroupMemberInfoDefaultZero(groupMemberInfo GroupMember, args map[string]interface{}) error {
2 years ago
// return DB.DB.MysqlDB.DefaultGormDB().Model(groupMemberInfo).Updates(args).Error
//}
3 years ago
3 years ago
//
//func SelectGroupList(groupID string) ([]string, error) {
// var groupUserID string
// var groupList []string
2 years ago
// dbConn, err := DB.DB.MysqlDB.DefaultGormDB()
3 years ago
// if err != nil {
// return groupList, err
// }
//
// rows, err := dbConn.Model(&GroupMember{}).Where("group_id = ?", groupID).Select("user_id").Rows()
// if err != nil {
// return groupList, err
// }
// defer rows.Close()
// for rows.Next() {
// rows.Scan(&groupUserID)
// groupList = append(groupList, groupUserID)
// }
// return groupList, nil
//}