mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-02 16:15:59 +08:00
style: add format
Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>
This commit is contained in:
@@ -6,9 +6,10 @@ import (
|
||||
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type UserGorm struct {
|
||||
@@ -48,12 +49,23 @@ func (u *UserGorm) Take(ctx context.Context, userID string) (user *relation.User
|
||||
}
|
||||
|
||||
// 获取用户信息 不存在,不返回错误
|
||||
func (u *UserGorm) Page(ctx context.Context, pageNumber, showNumber int32) (users []*relation.UserModel, count int64, err error) {
|
||||
func (u *UserGorm) Page(
|
||||
ctx context.Context,
|
||||
pageNumber, showNumber int32,
|
||||
) (users []*relation.UserModel, count int64, err error) {
|
||||
err = utils.Wrap(u.db(ctx).Count(&count).Error, "")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = utils.Wrap(u.db(ctx).Limit(int(showNumber)).Offset(int((pageNumber-1)*showNumber)).Find(&users).Order("create_time DESC").Error, "")
|
||||
err = utils.Wrap(
|
||||
u.db(ctx).
|
||||
Limit(int(showNumber)).
|
||||
Offset(int((pageNumber-1)*showNumber)).
|
||||
Find(&users).
|
||||
Order("create_time DESC").
|
||||
Error,
|
||||
"",
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -73,12 +85,22 @@ func (u *UserGorm) CountTotal(ctx context.Context) (count int64, err error) {
|
||||
return count, errs.Wrap(err)
|
||||
}
|
||||
|
||||
func (u *UserGorm) CountRangeEverydayTotal(ctx context.Context, start time.Time, end time.Time) (map[string]int64, error) {
|
||||
func (u *UserGorm) 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 := u.db(ctx).Model(&relation.UserModel{}).Select("DATE(create_time) AS date, count(1) AS count").Where("create_time >= ? and create_time < ?", start, end).Group("date").Find(&res).Error
|
||||
err := u.db(ctx).
|
||||
Model(&relation.UserModel{}).
|
||||
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