UserRegisterCount

This commit is contained in:
withchao
2023-07-03 15:59:42 +08:00
parent 840e79ca16
commit 3de21d13bd
6 changed files with 104 additions and 82 deletions
+3 -3
View File
@@ -31,7 +31,7 @@ type UserDatabase interface {
//函数内部先查询db中是否存在,存在则什么都不做;不存在则插入
InitOnce(ctx context.Context, users []*relation.UserModel) (err error)
// 获取用户总数
CountTotal(ctx context.Context) (int64, error)
CountTotal(ctx context.Context, before *time.Time) (int64, error)
// 获取范围内用户增量
CountRangeEverydayTotal(ctx context.Context, start time.Time, end time.Time) (map[string]int64, error)
}
@@ -134,8 +134,8 @@ func (u *userDatabase) GetAllUserID(ctx context.Context) (userIDs []string, err
return u.userDB.GetAllUserID(ctx)
}
func (u *userDatabase) CountTotal(ctx context.Context) (count int64, err error) {
return u.userDB.CountTotal(ctx)
func (u *userDatabase) CountTotal(ctx context.Context, before *time.Time) (count int64, err error) {
return u.userDB.CountTotal(ctx, before)
}
func (u *userDatabase) CountRangeEverydayTotal(ctx context.Context, start time.Time, end time.Time) (map[string]int64, error) {
+9 -3
View File
@@ -67,9 +67,15 @@ func (u *UserGorm) GetUserGlobalRecvMsgOpt(ctx context.Context, userID string) (
return opt, err
}
func (u *UserGorm) CountTotal(ctx context.Context) (count int64, err error) {
err = u.db(ctx).Model(&relation.UserModel{}).Count(&count).Error
return count, errs.Wrap(err)
func (u *UserGorm) CountTotal(ctx context.Context, before *time.Time) (count int64, err error) {
db := u.db(ctx).Model(&relation.UserModel{})
if before != nil {
db = db.Where("create_time < ?", before)
}
if err := db.Count(&count).Error; err != nil {
return 0, err
}
return count, nil
}
func (u *UserGorm) CountRangeEverydayTotal(ctx context.Context, start time.Time, end time.Time) (map[string]int64, error) {
+1 -1
View File
@@ -52,7 +52,7 @@ type UserModelInterface interface {
GetAllUserID(ctx context.Context) (userIDs []string, err error)
GetUserGlobalRecvMsgOpt(ctx context.Context, userID string) (opt int, err error)
// 获取用户总数
CountTotal(ctx context.Context) (count int64, err error)
CountTotal(ctx context.Context, before *time.Time) (count int64, err error)
// 获取范围内用户增量
CountRangeEverydayTotal(ctx context.Context, start time.Time, end time.Time) (map[string]int64, error)
}