44 lines
1.9 KiB
Go
44 lines
1.9 KiB
Go
package models
|
|
|
|
import "git.apinb.com/heqiapp/platforms/backend/api/internal/impl"
|
|
|
|
// DashboardOverview 是平台总后台的跨组织运营概览指标。
|
|
type DashboardOverview struct {
|
|
GasBasicCount int64 `json:"gas_basic_count"` // 启用可燃气体站数量
|
|
DeliveryBasicCount int64 `json:"delivery_basic_count"` // 启用配送点数量
|
|
StaffCount int64 `json:"staff_count"` // 在岗服务人员数量
|
|
UserCount int64 `json:"user_count"` // 启用业主客户数量
|
|
}
|
|
|
|
// GetDashboardOverview 通过独立查询返回首页概览指标。
|
|
func GetDashboardOverview() (DashboardOverview, error) {
|
|
var overview DashboardOverview
|
|
if err := impl.DBService.Model(&GasBasic{}).Where("status = ?", "enabled").Count(&overview.GasBasicCount).Error; err != nil {
|
|
return DashboardOverview{}, err
|
|
}
|
|
if err := impl.DBService.Model(&DeliveryBasic{}).Where("status = ?", "enabled").Count(&overview.DeliveryBasicCount).Error; err != nil {
|
|
return DashboardOverview{}, err
|
|
}
|
|
if err := impl.DBService.Model(&StaffAccount{}).Where("work_status = ?", "on_duty").Count(&overview.StaffCount).Error; err != nil {
|
|
return DashboardOverview{}, err
|
|
}
|
|
if err := impl.DBService.Model(&UserAccount{}).Where("status = ?", "enabled").Count(&overview.UserCount).Error; err != nil {
|
|
return DashboardOverview{}, err
|
|
}
|
|
return overview, nil
|
|
}
|
|
|
|
// ListPlatfromAccount 返回平台账号分页列表,敏感字段由接口展示层脱敏。
|
|
func ListPlatfromAccount(page, size int) ([]PlatfromAccount, int64, error) {
|
|
var list []PlatfromAccount
|
|
var total int64
|
|
databaseQuery := impl.DBService.Model(&PlatfromAccount{})
|
|
if err := databaseQuery.Count(&total).Error; err != nil {
|
|
return nil, 0, err
|
|
}
|
|
if err := databaseQuery.Order("created_at desc").Offset((page - 1) * size).Limit(size).Find(&list).Error; err != nil {
|
|
return nil, 0, err
|
|
}
|
|
return list, total, nil
|
|
}
|