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/mysql/group_model_k.go

81 lines
3.1 KiB

2 years ago
package mysql
2 years ago
import (
2 years ago
"Open_IM/pkg/common/trace_log"
2 years ago
"Open_IM/pkg/utils"
2 years ago
"context"
2 years ago
"gorm.io/gorm"
2 years ago
"time"
)
type Group struct {
GroupID string `gorm:"column:group_id;primary_key;size:64" json:"groupID" binding:"required"`
GroupName string `gorm:"column:name;size:255" json:"groupName"`
Notification string `gorm:"column:notification;size:255" json:"notification"`
Introduction string `gorm:"column:introduction;size:255" json:"introduction"`
FaceURL string `gorm:"column:face_url;size:255" json:"faceURL"`
CreateTime time.Time `gorm:"column:create_time;index:create_time"`
Ex string `gorm:"column:ex" json:"ex;size:1024" json:"ex"`
Status int32 `gorm:"column:status"`
CreatorUserID string `gorm:"column:creator_user_id;size:64"`
GroupType int32 `gorm:"column:group_type"`
NeedVerification int32 `gorm:"column:need_verification"`
LookMemberInfo int32 `gorm:"column:look_member_info" json:"lookMemberInfo"`
ApplyMemberFriend int32 `gorm:"column:apply_member_friend" json:"applyMemberFriend"`
NotificationUpdateTime time.Time `gorm:"column:notification_update_time"`
NotificationUserID string `gorm:"column:notification_user_id;size:64"`
2 years ago
DB *gorm.DB
}
func NewGroupDB() *Group {
var group Group
group.DB = initMysqlDB(&group)
return &group
2 years ago
}
func (*Group) Create(ctx context.Context, groups []*Group) (err error) {
defer func() {
2 years ago
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groups", groups)
}()
2 years ago
err = utils.Wrap(GroupDB.Create(&groups).Error, "")
2 years ago
return err
2 years ago
}
func (*Group) Delete(ctx context.Context, groupIDs []string) (err error) {
defer func() {
2 years ago
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupIDs", groupIDs)
}()
2 years ago
return utils.Wrap(GroupDB.Where("group_id in (?)", groupIDs).Delete(&Group{}).Error, "")
2 years ago
}
2 years ago
func (*Group) UpdateByMap(ctx context.Context, groupID string, args map[string]interface{}) (err error) {
defer func() {
2 years ago
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "args", args)
}()
2 years ago
return utils.Wrap(GroupDB.Where("group_id = ?", groupID).Updates(args).Error, "")
2 years ago
}
2 years ago
func (*Group) Update(ctx context.Context, groups []*Group) (err error) {
defer func() {
2 years ago
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groups", groups)
}()
2 years ago
return utils.Wrap(GroupDB.Updates(&groups).Error, "")
2 years ago
}
func (*Group) Find(ctx context.Context, groupIDs []string) (groups []*Group, err error) {
defer func() {
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupIDs", groupIDs, "groups", groups)
}()
err = utils.Wrap(GroupDB.Where("group_id in (?)", groupIDs).Find(&groups).Error, "")
return groups, err
2 years ago
}
2 years ago
func (*Group) Take(ctx context.Context, groupID string) (group *Group, err error) {
group = &Group{}
defer func() {
2 years ago
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "group", *group)
}()
2 years ago
err = utils.Wrap(GroupDB.Where("group_id = ?", groupID).Take(group).Error, "")
2 years ago
return group, err
2 years ago
}