后端可视化调试

This commit is contained in:
yml2213
2026-04-14 00:21:32 +08:00
parent 0c2f2e0a12
commit fa36be6539
14 changed files with 617 additions and 34 deletions
@@ -193,6 +193,54 @@ export async function listInventoryItems({
}
}
export async function listInventorySkuSuggestions({
credentialType = '',
keyword = '',
limit = 50,
} = {}) {
const filters = []
const params = []
if (credentialType) {
params.push(credentialType)
filters.push(`credential_type = $${params.length}`)
}
if (keyword) {
params.push(`%${keyword}%`)
filters.push(`sku_code ILIKE $${params.length}`)
}
const normalizedLimit = Number.isFinite(Number(limit))
? Math.max(1, Math.min(Number(limit), 100))
: 50
params.push(normalizedLimit)
const whereClause = filters.length > 0 ? `WHERE ${filters.join(' AND ')}` : ''
const result = await query(
`
SELECT
sku_code,
credential_type,
COUNT(*)::int AS total_count,
COUNT(*) FILTER (WHERE status = 'available')::int AS available_count,
MAX(updated_at) AS latest_updated_at
FROM inventory_items
${whereClause}
GROUP BY sku_code, credential_type
ORDER BY
COUNT(*) FILTER (WHERE status = 'available') DESC,
COUNT(*) DESC,
MAX(updated_at) DESC,
sku_code ASC
LIMIT $${params.length}
`,
params,
)
return result.rows
}
export async function createInventoryItems(rows) {
let created = 0