feat: 添加用户统计功能,包括统计接口和相关数据结构
This commit is contained in:
@@ -107,3 +107,19 @@ func (t *user) UpdateStatus(ctx context.Context, userID int64, status consts.Use
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Statistics
|
||||
func (t *user) Statistics(ctx context.Context) ([]*dto.UserStatistics, error) {
|
||||
tbl, query := models.UserQuery.QueryContext(ctx)
|
||||
|
||||
var statistics []*dto.UserStatistics
|
||||
err := query.Select(tbl.Status, tbl.ID.Count().As("count")).Group(tbl.Status).Scan(&statistics)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return lo.Map(statistics, func(item *dto.UserStatistics, _ int) *dto.UserStatistics {
|
||||
item.StatusDescription = item.Status.Description()
|
||||
return item
|
||||
}), nil
|
||||
}
|
||||
|
||||
@@ -261,3 +261,15 @@ func (t *UserTestSuite) Test_Relations() {
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (t *UserTestSuite) Test_Statistics() {
|
||||
Convey("test page", t.T(), func() {
|
||||
Convey("filter tenant users", func() {
|
||||
m, err := User.Statistics(t.T().Context())
|
||||
So(err, ShouldBeNil)
|
||||
// So(m.OwnedTenant, ShouldNotBeNil)
|
||||
// So(m.Tenants, ShouldHaveLength, 10)
|
||||
t.T().Logf("%s", utils.MustJsonString(m))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user