Rework LLM classification around user categories

Move category CRUD into the config route so renames sync historical deals, feed per-user categories into the LLM prompt, cache clients per user, and drop the separate classify route.
This commit is contained in:
2026-11-15 11:32:26 +08:00
parent cb5915e2ce
commit 2c8473e9e0
14 changed files with 824 additions and 374 deletions
+6 -1
View File
@@ -67,9 +67,14 @@ router.get("/", (req, res) => {
"counterparty",
"category",
"match_count",
"abs_amount",
];
const safeSort = allowedSort.includes(sort_by) ? sort_by : "deal_date";
const safeOrder = sort_order === "ASC" ? "ASC" : "DESC";
// abs_amount:按金额绝对值排序(大额确认用,收/支混排时按体量从大到小)
const sortExpr =
safeSort === "abs_amount" ? "ABS(d.amount)" : `d.${safeSort}`;
const tieBreaker = safeSort === "abs_amount" ? ", d.id DESC" : "";
const total = db
.prepare(`SELECT COUNT(*) as c FROM deals d ${where}`)
@@ -90,7 +95,7 @@ router.get("/", (req, res) => {
LEFT JOIN transactions t ON t.id = dt.transaction_id
${where}
GROUP BY d.id
ORDER BY d.${safeSort} ${safeOrder}
ORDER BY ${sortExpr} ${safeOrder}${tieBreaker}
LIMIT ? OFFSET ?
`,
)