Add filtering, sorting and pagination to deals page
Add filtering, sorting, and pagination to deals page Replace alert calls with toast notifications and add a clear deals button with confirmation dialog
This commit is contained in:
@@ -11,7 +11,7 @@ router.get("/", (req, res) => {
|
||||
|
||||
const {
|
||||
page = 1,
|
||||
limit = 50,
|
||||
limit = 20,
|
||||
start_date,
|
||||
end_date,
|
||||
source_type,
|
||||
@@ -74,6 +74,7 @@ router.get("/", (req, res) => {
|
||||
|
||||
// 安全的白名单排序
|
||||
const allowedSortFields = [
|
||||
"id",
|
||||
"transaction_time",
|
||||
"transaction_date",
|
||||
"amount",
|
||||
@@ -120,6 +121,38 @@ router.get("/needs-classify", (req, res) => {
|
||||
res.json({ ids: stale.map(r => r.id), total: stale.length });
|
||||
});
|
||||
|
||||
// POST /api/transactions/reconcile - 全量清除后重新对账
|
||||
router.post('/reconcile', (req, res) => {
|
||||
const db = getDB();
|
||||
db.prepare('DELETE FROM deal_transactions').run();
|
||||
db.prepare('DELETE FROM deals').run();
|
||||
db.prepare('UPDATE transactions SET matched_transaction_id=NULL, match_score=NULL').run();
|
||||
const result = runAutoReconciliation();
|
||||
const allTxs = db.prepare('SELECT id,transaction_date,transaction_time,amount,direction,counterparty,description,matched_transaction_id FROM transactions ORDER BY transaction_date,transaction_time').all();
|
||||
const visited = new Set(); const groups = [];
|
||||
for (const tx of allTxs) {
|
||||
if (visited.has(tx.id)) continue; visited.add(tx.id);
|
||||
const group = [tx];
|
||||
for (const other of allTxs) {
|
||||
if (visited.has(other.id)) continue;
|
||||
if (other.matched_transaction_id===tx.id||tx.matched_transaction_id===other.id||(tx.matched_transaction_id&&tx.matched_transaction_id===other.matched_transaction_id)) {
|
||||
group.push(other); visited.add(other.id);
|
||||
}
|
||||
}
|
||||
groups.push(group);
|
||||
}
|
||||
const insD=db.prepare('INSERT INTO deals(deal_date,amount,direction,counterparty,description,match_count)VALUES(?,?,?,?,?,?)');
|
||||
const insT=db.prepare('INSERT INTO deal_transactions(deal_id,transaction_id)VALUES(?,?)');
|
||||
let dc=0;
|
||||
for(const group of groups){
|
||||
const e=group.reduce((a,b)=>(a.transaction_time||a.transaction_date)<(b.transaction_time||b.transaction_date)?a:b);
|
||||
const r=insD.run(e.transaction_time||e.transaction_date,e.amount,e.direction,e.counterparty,e.description,group.length);
|
||||
for(const tx of group)insT.run(r.lastInsertRowid,tx.id);
|
||||
dc++;
|
||||
}
|
||||
res.json({success:true,matched:result.matched,total:result.total,deals:dc});
|
||||
});
|
||||
|
||||
// POST /api/transactions/classify-all — 重分类 deals
|
||||
router.post("/classify-all", async (req, res) => {
|
||||
const db = getDB();
|
||||
|
||||
Reference in New Issue
Block a user