mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-07 02:26:00 +08:00
feat: add scripts (#525)
This commit is contained in:
@@ -2,12 +2,14 @@ package relation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/ormutil"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
var _ relation.GroupModelInterface = (*GroupGorm)(nil)
|
||||
@@ -33,7 +35,13 @@ func (g *GroupGorm) UpdateMap(ctx context.Context, groupID string, args map[stri
|
||||
}
|
||||
|
||||
func (g *GroupGorm) UpdateStatus(ctx context.Context, groupID string, status int32) (err error) {
|
||||
return utils.Wrap(g.DB.Where("group_id = ?", groupID).Model(&relation.GroupModel{}).Updates(map[string]any{"status": status}).Error, "")
|
||||
return utils.Wrap(
|
||||
g.DB.Where("group_id = ?", groupID).
|
||||
Model(&relation.GroupModel{}).
|
||||
Updates(map[string]any{"status": status}).
|
||||
Error,
|
||||
"",
|
||||
)
|
||||
}
|
||||
|
||||
func (g *GroupGorm) Find(ctx context.Context, groupIDs []string) (groups []*relation.GroupModel, err error) {
|
||||
@@ -45,12 +53,19 @@ func (g *GroupGorm) Take(ctx context.Context, groupID string) (group *relation.G
|
||||
return group, utils.Wrap(g.DB.Where("group_id = ?", groupID).Take(group).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupGorm) Search(ctx context.Context, keyword string, pageNumber, showNumber int32) (total uint32, groups []*relation.GroupModel, err error) {
|
||||
func (g *GroupGorm) Search(
|
||||
ctx context.Context,
|
||||
keyword string,
|
||||
pageNumber, showNumber int32,
|
||||
) (total uint32, groups []*relation.GroupModel, err error) {
|
||||
return ormutil.GormSearch[relation.GroupModel](g.DB, []string{"name"}, keyword, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
func (g *GroupGorm) GetGroupIDsByGroupType(ctx context.Context, groupType int) (groupIDs []string, err error) {
|
||||
return groupIDs, utils.Wrap(g.DB.Model(&relation.GroupModel{}).Where("group_type = ? ", groupType).Pluck("group_id", &groupIDs).Error, "")
|
||||
return groupIDs, utils.Wrap(
|
||||
g.DB.Model(&relation.GroupModel{}).Where("group_type = ? ", groupType).Pluck("group_id", &groupIDs).Error,
|
||||
"",
|
||||
)
|
||||
}
|
||||
|
||||
func (g *GroupGorm) CountTotal(ctx context.Context, before *time.Time) (count int64, err error) {
|
||||
@@ -64,12 +79,22 @@ func (g *GroupGorm) CountTotal(ctx context.Context, before *time.Time) (count in
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (g *GroupGorm) CountRangeEverydayTotal(ctx context.Context, start time.Time, end time.Time) (map[string]int64, error) {
|
||||
func (g *GroupGorm) CountRangeEverydayTotal(
|
||||
ctx context.Context,
|
||||
start time.Time,
|
||||
end time.Time,
|
||||
) (map[string]int64, error) {
|
||||
var res []struct {
|
||||
Date time.Time `gorm:"column:date"`
|
||||
Count int64 `gorm:"column:count"`
|
||||
}
|
||||
err := g.db(ctx).Model(&relation.GroupModel{}).Select("DATE(create_time) AS date, count(1) AS count").Where("create_time >= ? and create_time < ?", start, end).Group("date").Find(&res).Error
|
||||
err := g.db(ctx).
|
||||
Model(&relation.GroupModel{}).
|
||||
Select("DATE(create_time) AS date, count(1) AS count").
|
||||
Where("create_time >= ? and create_time < ?", start, end).
|
||||
Group("date").
|
||||
Find(&res).
|
||||
Error
|
||||
if err != nil {
|
||||
return nil, errs.Wrap(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user