feat: 完善平台总后台模块
This commit is contained in:
@@ -2,28 +2,28 @@ package models
|
||||
|
||||
import "git.apinb.com/heqiapp/platforms/backend/api/internal/impl"
|
||||
|
||||
// DashboardOverview 是平台总后台的安全与组织聚合指标。
|
||||
// DashboardOverview 是平台总后台的跨组织运营概览指标。
|
||||
type DashboardOverview struct {
|
||||
GasStationCount int64 `json:"gas_station_count"` // 启用气站数量
|
||||
DeliveryPointCount int64 `json:"delivery_point_count"` // 启用配送点数量
|
||||
ServicePersonCount int64 `json:"service_person_count"` // 在岗服务人员数量
|
||||
UserCount int64 `json:"user_count"` // 启用普通用户数量
|
||||
GasBasicCount int64 `json:"gas_basic_count"` // 启用可燃气体站数量
|
||||
DeliveryBasicCount int64 `json:"delivery_basic_count"` // 启用配送点数量
|
||||
StaffCount int64 `json:"staff_count"` // 在岗服务人员数量
|
||||
UserCount int64 `json:"user_count"` // 启用业主客户数量
|
||||
PendingSafetyCount int64 `json:"pending_safety_count"` // 待处理安全事件数量
|
||||
}
|
||||
|
||||
// GetDashboardOverview 通过独立查询返回首期仪表盘指标。
|
||||
// GetDashboardOverview 通过独立查询返回首页概览指标。
|
||||
func GetDashboardOverview() (DashboardOverview, error) {
|
||||
var overview DashboardOverview
|
||||
if err := impl.DBService.Model(&OrgGasStation{}).Where("status = ?", "enabled").Count(&overview.GasStationCount).Error; err != nil {
|
||||
if err := impl.DBService.Model(&GasBasic{}).Where("status = ?", "enabled").Count(&overview.GasBasicCount).Error; err != nil {
|
||||
return DashboardOverview{}, err
|
||||
}
|
||||
if err := impl.DBService.Model(&OrgDeliveryPoint{}).Where("status = ?", "enabled").Count(&overview.DeliveryPointCount).Error; err != nil {
|
||||
if err := impl.DBService.Model(&DeliveryBasic{}).Where("status = ?", "enabled").Count(&overview.DeliveryBasicCount).Error; err != nil {
|
||||
return DashboardOverview{}, err
|
||||
}
|
||||
if err := impl.DBService.Model(&OrgServicePerson{}).Where("work_status = ?", "on_duty").Count(&overview.ServicePersonCount).Error; err != nil {
|
||||
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(&IdnAccount{}).Where("account_type = ? AND status = ?", "user", "enabled").Count(&overview.UserCount).Error; err != nil {
|
||||
if err := impl.DBService.Model(&UserAccount{}).Where("status = ?", "enabled").Count(&overview.UserCount).Error; err != nil {
|
||||
return DashboardOverview{}, err
|
||||
}
|
||||
if err := impl.DBService.Model(&SafEvent{}).Where("status = ?", "pending").Count(&overview.PendingSafetyCount).Error; err != nil {
|
||||
@@ -32,11 +32,11 @@ func GetDashboardOverview() (DashboardOverview, error) {
|
||||
return overview, nil
|
||||
}
|
||||
|
||||
// ListOrgDeliveryPoint 返回配送点分页列表。
|
||||
func ListOrgDeliveryPoint(page, size int) ([]OrgDeliveryPoint, int64, error) {
|
||||
var list []OrgDeliveryPoint
|
||||
// ListPlatfromAccount 返回平台账号分页列表,敏感字段由接口展示层脱敏。
|
||||
func ListPlatfromAccount(page, size int) ([]PlatfromAccount, int64, error) {
|
||||
var list []PlatfromAccount
|
||||
var total int64
|
||||
databaseQuery := impl.DBService.Model(&OrgDeliveryPoint{})
|
||||
databaseQuery := impl.DBService.Model(&PlatfromAccount{})
|
||||
if err := databaseQuery.Count(&total).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
@@ -45,45 +45,3 @@ func ListOrgDeliveryPoint(page, size int) ([]OrgDeliveryPoint, int64, error) {
|
||||
}
|
||||
return list, total, nil
|
||||
}
|
||||
|
||||
// ListOrgServicePerson 返回服务人员分页列表。
|
||||
func ListOrgServicePerson(page, size int) ([]OrgServicePerson, int64, error) {
|
||||
var list []OrgServicePerson
|
||||
var total int64
|
||||
databaseQuery := impl.DBService.Model(&OrgServicePerson{})
|
||||
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
|
||||
}
|
||||
|
||||
// ListIdnAccount 返回普通用户分页列表,手机号脱敏由前端展示层处理。
|
||||
func ListIdnAccount(page, size int) ([]IdnAccount, int64, error) {
|
||||
var list []IdnAccount
|
||||
var total int64
|
||||
databaseQuery := impl.DBService.Model(&IdnAccount{}).Where("account_type = ?", "user")
|
||||
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
|
||||
}
|
||||
|
||||
// ListSafEvent 返回安全事件分页列表。
|
||||
func ListSafEvent(page, size int) ([]SafEvent, int64, error) {
|
||||
var list []SafEvent
|
||||
var total int64
|
||||
databaseQuery := impl.DBService.Model(&SafEvent{})
|
||||
if err := databaseQuery.Count(&total).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
if err := databaseQuery.Order("level asc, created_at desc").Offset((page - 1) * size).Limit(size).Find(&list).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return list, total, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user