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.
60 lines
1.4 KiB
60 lines
1.4 KiB
// Code scaffolded by goctl. Safe to edit.
|
|
// goctl 1.9.2
|
|
|
|
package dashboard
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/youruser/base/internal/svc"
|
|
"github.com/youruser/base/internal/types"
|
|
"github.com/youruser/base/model"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type GetDashboardStatsLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
// 获取仪表盘统计数据
|
|
func NewGetDashboardStatsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDashboardStatsLogic {
|
|
return &GetDashboardStatsLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *GetDashboardStatsLogic) GetDashboardStats() (resp *types.DashboardStatsResponse, err error) {
|
|
// 查询总用户数
|
|
var totalUsers int64
|
|
if err := l.svcCtx.DB.Model(&model.User{}).Count(&totalUsers).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// 查询活跃用户数(status = 1)
|
|
var activeUsers int64
|
|
if err := l.svcCtx.DB.Model(&model.User{}).Where("status = ?", 1).Count(&activeUsers).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// 模拟系统负载(可以根据实际系统指标计算)
|
|
systemLoad := 32
|
|
|
|
// 数据库状态
|
|
dbStatus := "正常"
|
|
|
|
// 用户增长率(模拟数据)
|
|
userGrowth := 65
|
|
|
|
return &types.DashboardStatsResponse{
|
|
TotalUsers: totalUsers,
|
|
ActiveUsers: activeUsers,
|
|
SystemLoad: systemLoad,
|
|
DbStatus: dbStatus,
|
|
UserGrowth: userGrowth,
|
|
}, nil
|
|
}
|
|
|