fix(api): 修正看板和历史统计口径

This commit is contained in:
2026-05-12 00:48:16 +08:00
parent 58b615a327
commit 25d7f1c315
3 changed files with 28 additions and 8 deletions
+7 -6
View File
@@ -15,8 +15,6 @@ import { env } from '@/env'
const historyLimit = 500
const predictionHistoryLimit = 10
const dashboardLatestLimit = 100
type BatteryInfoMysqlRow = RowDataPacket & BatteryInfoSourceRow
type CountMysqlRow = RowDataPacket & {
total: number
@@ -314,16 +312,19 @@ export async function getLatestBatteryPage(input: LatestBatteryPageInput): Promi
}
}
export async function getLatestBatteryPerDevice(limit = dashboardLatestLimit): Promise<BatteryInfo[]> {
export async function getLatestBatteryPerDevice(limit?: number): Promise<BatteryInfo[]> {
const appliedLimit = typeof limit === 'number' && limit > 0 ? limit : undefined
const limitSql = appliedLimit ? '\n LIMIT :limit' : ''
const queryParams = appliedLimit ? { limit: appliedLimit } : {}
const [rows] = await getBatteryPool().query<BatteryInfoMysqlRow[]>(
`
SELECT ${sourceColumns}
FROM ls_battery_info AS current_record
WHERE ${latestRecordPredicate}
ORDER BY current_record.create_time DESC, current_record.id DESC
LIMIT :limit
ORDER BY current_record.create_time DESC, current_record.id DESC${limitSql}
`,
{ limit: Math.min(Math.max(limit, 1), dashboardLatestLimit) },
queryParams,
)
return rows.map(toBatteryInfo)