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
+1 -1
View File
@@ -1,5 +1,5 @@
appname = server
httpport = 8081
httpport = 9000
runmode = dev
# 启用请求体复制(允许多次读取请求体)
+6 -6
View File
@@ -55,7 +55,7 @@ func (c *ApiGetCardController) cardOK(text string) {
// - type (必填) 来源平台:xianyu / taobao / pinduoduo / jingdong / local / xubei
// - module (必填) 号池模块:cursor / windsurf / krio / codex
// - data_type (可选) 账号类型:account / tk / account_tk,不传则取任意未提取的
// - id/start_id/current_id (可选) 起始 ID从该 ID 开始向后提取,避免传 896 却取到 892
// - id/start_id/current_id (可选) 起始 ID仅取 id >= 起始值 的记录,按 id 从大到小提取
func (c *ApiGetCardController) GetCard() {
platform := c.GetString("type")
module := c.GetString("module")
@@ -159,7 +159,7 @@ func (c *ApiGetCardController) extractCursor(platform, dataType string, startID
if dataType != "" {
qs = qs.Filter("data_type", dataType)
}
if err := qs.OrderBy("id").One(&row); err != nil {
if err := qs.OrderBy("-id").One(&row); err != nil {
return 0, nil, nil, "", "", nil, err
}
return row.ID, &row.Account, &row.Password, row.Token, row.DataType, row.IsUsed, nil
@@ -178,7 +178,7 @@ func (c *ApiGetCardController) extractWindsurf(platform, dataType string, startI
if dataType != "" {
qs = qs.Filter("data_type", dataType)
}
if err := qs.OrderBy("id").One(&row); err != nil {
if err := qs.OrderBy("-id").One(&row); err != nil {
return 0, nil, nil, "", "", nil, err
}
return row.ID, &row.Account, &row.Password, row.Token, row.DataType, nil, nil
@@ -197,7 +197,7 @@ func (c *ApiGetCardController) extractKrio(platform, dataType string, startID ui
if dataType != "" {
qs = qs.Filter("data_type", dataType)
}
if err := qs.OrderBy("id").One(&row); err != nil {
if err := qs.OrderBy("-id").One(&row); err != nil {
return 0, nil, nil, "", "", nil, err
}
return row.ID, &row.Account, &row.Password, row.Token, row.DataType, nil, nil
@@ -216,7 +216,7 @@ func (c *ApiGetCardController) extractCodex(platform, dataType string, startID u
if dataType != "" {
qs = qs.Filter("data_type", dataType)
}
if err := qs.OrderBy("id").One(&row); err != nil {
if err := qs.OrderBy("-id").One(&row); err != nil {
return 0, nil, nil, "", "", nil, err
}
return row.ID, &row.Account, &row.Password, row.Token, row.DataType, nil, nil
@@ -225,7 +225,7 @@ func (c *ApiGetCardController) extractCodex(platform, dataType string, startID u
type poolRowFetcher func() (id uint64, account, password *string, token, rowDataType string, isUsed *int8, err error)
// extractWithProbe 按 id 顺序提取并探测 Token 可用性;不可用则标记已提取并继续下一条。
// extractWithProbe 按 id 从大到小提取并探测 Token 可用性;不可用则标记已提取并继续下一条。
func (c *ApiGetCardController) extractWithProbe(
module, platform, dataType string,
now time.Time,
@@ -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 {
+1
View File
@@ -180,6 +180,7 @@ func Register() {
// Cursor 设备管理(yz_platform_cursor_equipment
beego.Router("/platform/cursor/equipment/list", &controllers.PlatformCursorEquipmentController{}, "get:List")
beego.Router("/platform/cursor/equipment/stats", &controllers.PlatformCursorEquipmentController{}, "get:Stats")
beego.Router("/platform/cursor/equipment/detail/:id", &controllers.PlatformCursorEquipmentController{}, "get:Detail")
beego.Router("/platform/cursor/equipment/add", &controllers.PlatformCursorEquipmentController{}, "post:Add")
beego.Router("/platform/cursor/equipment/update", &controllers.PlatformCursorEquipmentController{}, "post:Update")