cursor从大到小获取

This commit is contained in:
2026-07-08 09:56:50 +08:00
parent 0f961789dc
commit 3da6718729
8 changed files with 141 additions and 24 deletions
@@ -520,6 +520,56 @@ func (c *PlatformCursorEquipmentController) List() {
})
}
// Stats GET /platform/cursor/equipment/stats
// 全量设备统计(不受分页与列表筛选影响)
func (c *PlatformCursorEquipmentController) Stats() {
if _, err := c.platformClaims(); err != nil {
c.jsonErr(401, 401, err.Error())
return
}
onlineSince := time.Now().Add(-5 * time.Minute)
type statsRow struct {
Total int64
Inactive int64
Active int64
Expired int64
Disabled int64
Online int64
}
var row statsRow
err := models.Orm.Raw(
"SELECT COUNT(*) AS total,"+
" SUM(CASE WHEN status = 0 THEN 1 ELSE 0 END) AS inactive,"+
" SUM(CASE WHEN status = 1 THEN 1 ELSE 0 END) AS active,"+
" SUM(CASE WHEN status = 2 THEN 1 ELSE 0 END) AS expired,"+
" SUM(CASE WHEN status = 3 THEN 1 ELSE 0 END) AS disabled,"+
" SUM(CASE WHEN last_heartbeat_at IS NOT NULL AND last_heartbeat_at >= ? THEN 1 ELSE 0 END) AS online"+
" FROM yz_platform_cursor_equipment WHERE delete_time IS NULL",
onlineSince,
).QueryRow(&row)
if err != nil {
c.jsonErr(500, 500, "获取设备统计失败: "+err.Error())
return
}
offline := row.Total - row.Online
if offline < 0 {
offline = 0
}
c.ok(map[string]interface{}{
"total": row.Total,
"online": row.Online,
"offline": offline,
"active": row.Active,
"inactive": row.Inactive,
"expired": row.Expired,
"disabled": row.Disabled,
})
}
// Detail GET /platform/cursor/equipment/detail/:id
func (c *PlatformCursorEquipmentController) Detail() {
if _, err := c.platformClaims(); err != nil {