diff --git a/client/src/hooks/useApi.js b/client/src/hooks/useApi.js
index 6cfe3ec..cf2cbd7 100644
--- a/client/src/hooks/useApi.js
+++ b/client/src/hooks/useApi.js
@@ -60,6 +60,22 @@ export async function deleteSource(id) {
return res.data;
}
+// Deals
+export async function getDeals(params = {}) {
+ const res = await api.get("/deals", { params });
+ return res.data;
+}
+
+export async function updateDeal(id, data) {
+ const res = await api.put(`/deals/${id}`, data);
+ return res.data;
+}
+
+export async function batchConfirmDeals(ids) {
+ const res = await api.post("/deals/batch-confirm", { ids });
+ return res.data;
+}
+
// Transactions
export async function getTransactions(params = {}) {
const res = await api.get("/transactions", { params });
diff --git a/client/src/pages/Review.js b/client/src/pages/Review.js
index e870e52..0e840ad 100644
--- a/client/src/pages/Review.js
+++ b/client/src/pages/Review.js
@@ -1,19 +1,31 @@
-import React, { useState, useEffect } from 'react';
-import { CheckCircle, X, Edit3, Brain, Search, Filter } from 'lucide-react';
-import { getTransactions, updateTransaction, formatAmount, formatDate, SOURCE_TYPE_MAP, getCategories } from '../hooks/useApi';
+import React, { useState, useEffect, useCallback } from "react";
+import { CheckCircle, X, Edit3, ChevronDown, ChevronRight } from "lucide-react";
+import {
+ getDeals,
+ updateDeal,
+ batchConfirmDeals,
+ formatAmount,
+ formatDate,
+ SOURCE_TYPE_MAP,
+ getCategories,
+} from "../hooks/useApi";
export default function Review() {
- const [transactions, setTransactions] = useState([]);
+ const [deals, setDeals] = useState([]);
const [loading, setLoading] = useState(true);
const [total, setTotal] = useState(0);
const [categories, setCategories] = useState([]);
- const [editingTx, setEditingTx] = useState(null);
+ const [editingDeal, setEditingDeal] = useState(null);
const [showReviewed, setShowReviewed] = useState(false);
- const [keyword, setKeyword] = useState('');
+ const [keyword, setKeyword] = useState("");
+ const [expandedDeals, setExpandedDeals] = useState(new Set());
useEffect(() => {
loadCategories();
- loadReviewTransactions();
+ }, []);
+
+ useEffect(() => {
+ loadReviewDeals();
}, [showReviewed, keyword]);
async function loadCategories() {
@@ -23,177 +35,399 @@ export default function Review() {
} catch (err) {}
}
- async function loadReviewTransactions() {
+ async function loadReviewDeals() {
setLoading(true);
try {
const params = {
- min_amount: 100, // Only >= 100 RMB
+ min_amount: 100,
limit: 200,
- sort_by: 'amount',
- sort_order: 'DESC'
+ sort_by: "amount",
+ sort_order: "DESC",
};
if (!showReviewed) params.reviewed = 0;
if (keyword) params.keyword = keyword;
- const result = await getTransactions(params);
- setTransactions(result.transactions);
+ const result = await getDeals(params);
+ setDeals(result.deals);
setTotal(result.total);
// Update badge count in sidebar
try {
- const badge = document.getElementById('review-badge');
+ const badge = document.getElementById("review-badge");
if (badge) {
- // Get fresh unreviewed count
- const { getOverview } = require('../hooks/useApi');
- // Just use local count
- if (!showReviewed) badge.textContent = result.total;
+ if (!showReviewed) {
+ badge.textContent = result.total;
+ } else {
+ // When showing reviewed, fetch unreviewed count for badge
+ const unreviewed = await getDeals({
+ min_amount: 100,
+ reviewed: 0,
+ limit: 1,
+ });
+ badge.textContent = unreviewed.total;
+ }
}
} catch (e) {}
} catch (err) {}
setLoading(false);
}
- async function handleConfirm(tx) {
+ async function handleConfirm(deal) {
try {
- await updateTransaction(tx.id, { reviewed: 1 });
- loadReviewTransactions();
+ await updateDeal(deal.id, { reviewed: 1 });
+ loadReviewDeals();
} catch (err) {}
}
- async function handleUpdateTx(id, updates) {
+ async function handleUpdateDeal(id, updates) {
try {
- await updateTransaction(id, updates);
- setEditingTx(null);
- loadReviewTransactions();
+ await updateDeal(id, updates);
+ setEditingDeal(null);
+ loadReviewDeals();
} catch (err) {}
}
async function handleConfirmAll() {
- if (!window.confirm(`确定要批量确认当前显示的 ${transactions.length} 笔交易吗?`)) return;
- for (const tx of transactions) {
- if (!tx.reviewed) {
- try { await updateTransaction(tx.id, { reviewed: 1 }); } catch (err) {}
- }
- }
- loadReviewTransactions();
+ const unreviewed = deals.filter((d) => !d.reviewed);
+ if (unreviewed.length === 0) return;
+ if (
+ !window.confirm(
+ `确定要批量确认当前显示的 ${unreviewed.length} 笔交易吗?`,
+ )
+ )
+ return;
+ try {
+ await batchConfirmDeals(unreviewed.map((d) => d.id));
+ loadReviewDeals();
+ } catch (err) {}
+ }
+
+ function toggleExpand(dealId) {
+ setExpandedDeals((prev) => {
+ const next = new Set(prev);
+ if (next.has(dealId)) next.delete(dealId);
+ else next.add(dealId);
+ return next;
+ });
}
return (
🔍 大额交易确认
-
逐笔确认 ≥100 元的交易,核对AI分类和描述是否正确
+
逐笔确认 ≥100 元的 Deal(关联交易组),核对AI分类和描述是否正确
{/* Toolbar */}
-
+
{/* Review List */}
{loading ? (
-
- ) : transactions.length > 0 ? (
+
+ ) : deals.length > 0 ? (
- {transactions.map(tx => (
-
-
- {formatAmount(tx.amount)}
+ {deals.map((deal) => (
+
+
+ {formatAmount(deal.amount)}
- {tx.ai_description || tx.description || '无描述'}
+ {deal.ai_description || deal.description || "无描述"}
- {formatDate(tx.transaction_date)} ·
-
- {SOURCE_TYPE_MAP[tx.source_type] || tx.source_type}
-
- {tx.counterparty && · {tx.counterparty}}
- {tx.category && (
- {tx.category}
+ {formatDate(deal.deal_date)} ·
+ {deal.counterparty && {deal.counterparty} ·}
+ {deal.category && (
+
+ {deal.category}
+
)}
- {tx.reviewed && ✓ 已确认}
- {tx.matched_transaction_id && (
- 已对账
+ {deal.reviewed && (
+
+ ✓ 已确认
+
+ )}
+ {deal.match_count > 1 && (
+
+ 关联×{deal.match_count}
+
)}
-
+
+ {/* Expanded transactions detail */}
+ {expandedDeals.has(deal.id) && deal.transactions && (
+
+ {deal.transactions.map((tx, i) => (
+
+
+ {SOURCE_TYPE_MAP[tx.source_type] || tx.source_type}
+
+
+ {tx.description || "无描述"}
+
+
+ {formatAmount(tx.amount)}
+
+
+ {formatDate(tx.transaction_date)}
+
+
+ ))}
+
+ )}
))}
) : (
✅
-
{showReviewed ? '没有已确认的大额交易' : '所有大额交易已确认!'}
+
+ {showReviewed
+ ? "没有已确认的大额 Deal"
+ : "所有大额 Deal 已确认!"}
+
- {showReviewed ? '尝试切换显示模式' : '可以去交易明细页面查看所有记录'}
+ {showReviewed
+ ? "尝试切换显示模式"
+ : "可以去交易明细页面查看所有记录"}
)}
{/* Edit Modal */}
- {editingTx && (
-
setEditingTx(null)}>
-
e.stopPropagation()}>
-
编辑交易分类与描述
+ {editingDeal && (
+
setEditingDeal(null)}>
+
e.stopPropagation()}>
+
编辑 Deal 分类与描述
-
+
- {formatAmount(editingTx.amount)} · {formatDate(editingTx.transaction_date)}
+ {formatAmount(editingDeal.amount)} ·{" "}
+ {formatDate(editingDeal.deal_date)}
-
- {editingTx.counterparty} · {editingTx.description}
-
-
- 编码: {editingTx.transaction_code}
+
+ {editingDeal.counterparty} ·{" "}
+ {editingDeal.description || "无描述"}
+ {editingDeal.match_count > 1 && (
+
+ 关联 {editingDeal.match_count} 笔原始交易
+
+ )}
+ {/* Show associated transactions in modal */}
+ {editingDeal.transactions &&
+ editingDeal.transactions.length > 0 && (
+
+
+ 关联原始交易明细:
+
+ {editingDeal.transactions.map((tx, i) => (
+
+
+ {SOURCE_TYPE_MAP[tx.source_type] || tx.source_type}
+
+
+ {tx.description || "无描述"} ·{" "}
+ {tx.counterparty || "未知"}
+
+
+ {formatAmount(tx.amount)}
+
+
+ ))}
+
+ )}
+
-
@@ -203,8 +437,13 @@ export default function Review() {
setEditingTx({ ...editingTx, ai_description: e.target.value })}
+ value={editingDeal.ai_description || ""}
+ onChange={(e) =>
+ setEditingDeal({
+ ...editingDeal,
+ ai_description: e.target.value,
+ })
+ }
placeholder="简要描述这笔交易..."
/>
@@ -214,20 +453,42 @@ export default function Review() {
setEditingTx({ ...editingTx, review_notes: e.target.value })}
+ value={editingDeal.review_notes || ""}
+ onChange={(e) =>
+ setEditingDeal({
+ ...editingDeal,
+ review_notes: e.target.value,
+ })
+ }
placeholder="人工备注(可选)"
/>
-
-
setEditingTx(null)}>取消
-
handleUpdateTx(editingTx.id, {
- category: editingTx.category,
- ai_description: editingTx.ai_description,
- review_notes: editingTx.review_notes,
- reviewed: 1
- })}>
+
+ setEditingDeal(null)}
+ >
+ 取消
+
+
+ handleUpdateDeal(editingDeal.id, {
+ category: editingDeal.category,
+ ai_description: editingDeal.ai_description,
+ review_notes: editingDeal.review_notes,
+ reviewed: 1,
+ })
+ }
+ >
保存并确认
diff --git a/server/routes/deals.js b/server/routes/deals.js
index 225697f..0f1553f 100644
--- a/server/routes/deals.js
+++ b/server/routes/deals.js
@@ -13,6 +13,9 @@ router.get("/", (req, res) => {
category,
direction,
keyword,
+ min_amount,
+ max_amount,
+ reviewed,
sort_by = "deal_date",
sort_order = "DESC",
} = req.query;
@@ -42,6 +45,18 @@ router.get("/", (req, res) => {
);
params.push("%" + keyword + "%", "%" + keyword + "%", "%" + keyword + "%");
}
+ if (min_amount) {
+ conditions.push("ABS(d.amount) >= ?");
+ params.push(parseFloat(min_amount));
+ }
+ if (max_amount) {
+ conditions.push("ABS(d.amount) <= ?");
+ params.push(parseFloat(max_amount));
+ }
+ if (reviewed !== undefined) {
+ conditions.push("d.reviewed = ?");
+ params.push(parseInt(reviewed));
+ }
const where = conditions.length ? "WHERE " + conditions.join(" AND ") : "";
const allowedSort = [
@@ -141,6 +156,20 @@ router.put("/:id", (req, res) => {
res.json({ success: true });
});
+// POST /api/deals/batch-confirm — 批量确认大额交易
+router.post("/batch-confirm", (req, res) => {
+ const db = getDB();
+ const { ids } = req.body;
+ if (!ids || !Array.isArray(ids) || ids.length === 0) {
+ return res.status(400).json({ error: "请提供交易ID列表" });
+ }
+ const ph = ids.map(() => "?").join(",");
+ db.prepare(
+ `UPDATE deals SET reviewed=1, reviewed_at=CURRENT_TIMESTAMP, updated_at=CURRENT_TIMESTAMP WHERE id IN (${ph})`,
+ ).run(...ids);
+ res.json({ success: true, confirmed: ids.length });
+});
+
// POST /api/deals/clear
router.post("/clear", (req, res) => {
const db = getDB();