- {overview.sourceStats.map((s, i) => (
+ {overview.categoryBreakdown.map((cat, i) => (
|
-
- {s.source_type === "alipay" && "支付宝"}
- {s.source_type === "wechat" && "微信支付"}
- {s.source_type === "bank_debit" && "银行借记卡"}
- {s.source_type === "bank_credit" && "银行贷记卡"}
- {s.source_type === "abc" && "农业银行"}
-
+ {cat.category}
|
- {s.count} |
-
- {formatAmount(s.total_income)}
+ | {cat.deal_count} |
+
+ {cat.total_income > 0
+ ? formatAmount(cat.total_income)
+ : "--"}
|
-
- {formatAmount(s.total_expense)}
+ |
+ {cat.total_expense > 0
+ ? formatAmount(-cat.total_expense)
+ : "--"}
|
= 0
- ? "stat-value income"
- : "stat-value expense"
- }
+ style={{
+ textAlign: "right",
+ fontWeight: 600,
+ color:
+ cat.total_income - cat.total_expense >= 0
+ ? "var(--success)"
+ : "var(--danger)",
+ }}
>
- {formatAmount(s.total_income - s.total_expense)}
+ {formatAmount(cat.total_income - cat.total_expense)}
+ |
+
+ {cat.max_income ? (
+
+
+ {formatAmount(cat.max_income.amount)}
+
+
+ {cat.max_income.counterparty || ""}
+
+
+ ) : (
+
+ --
+
+ )}
+ |
+
+ {cat.max_expense ? (
+
+
+ {formatAmount(cat.max_expense.amount)}
+
+
+ {cat.max_expense.counterparty || ""}
+
+
+ ) : (
+
+ --
+
+ )}
|
))}
diff --git a/client/src/pages/Review.js b/client/src/pages/Review.js
index d34fd3e..2ab38a1 100644
--- a/client/src/pages/Review.js
+++ b/client/src/pages/Review.js
@@ -1,9 +1,8 @@
import React, { useState, useEffect } from "react";
-import { CheckCircle, Edit3, Loader2 } from "lucide-react";
+import { Edit3, Loader2 } from "lucide-react";
import {
getDeals,
updateDeal,
- batchConfirmDeals,
formatAmount,
formatDate,
SOURCE_TYPE_MAP,
@@ -21,7 +20,7 @@ export default function Review() {
const [totalPages, setTotalPages] = useState(0);
const [categories, setCategories] = useState([]);
const [editingDeal, setEditingDeal] = useState(null);
- const [showReviewed, setShowReviewed] = useState(false);
+ const [showReviewed, setShowReviewed] = useState(true);
const [keyword, setKeyword] = useState("");
useEffect(() => {
@@ -60,7 +59,6 @@ export default function Review() {
if (keyword) params.keyword = keyword;
const result = await getDeals(params);
-
if (append) {
setDeals((prev) => [...prev, ...result.deals]);
} else {
@@ -69,7 +67,6 @@ export default function Review() {
setTotal(result.total);
setPage(result.page);
setTotalPages(result.totalPages);
-
updateBadge(result, isFirstPage);
} catch (err) {}
setLoading(false);
@@ -98,13 +95,6 @@ export default function Review() {
loadReviewDeals(page + 1, true);
}
- async function handleConfirm(deal) {
- try {
- await updateDeal(deal.id, { reviewed: 1 });
- loadReviewDeals(1, false);
- } catch (err) {}
- }
-
async function handleUpdateDeal(id, updates) {
try {
await updateDeal(id, updates);
@@ -113,21 +103,6 @@ export default function Review() {
} catch (err) {}
}
- async function handleConfirmAll() {
- const unreviewed = deals.filter((d) => !d.reviewed);
- if (unreviewed.length === 0) return;
- if (
- !window.confirm(
- `确定要批量确认当前已加载的 ${unreviewed.length} 笔交易吗?(共 ${total} 笔待确认)`,
- )
- )
- return;
- try {
- await batchConfirmDeals(unreviewed.map((d) => d.id));
- loadReviewDeals(1, false);
- } catch (err) {}
- }
-
const hasMore = page < totalPages;
return (
@@ -181,11 +156,6 @@ export default function Review() {
)}
- {!showReviewed && deals.length > 0 && (
-
- )}
{/* Review List */}
@@ -206,7 +176,6 @@ export default function Review() {
>
{formatAmount(deal.amount)}
-
{deal.ai_description || deal.description || "无描述"}
@@ -237,7 +206,6 @@ export default function Review() {
)}
-
{deal.transactions && deal.transactions.length > 0 && (
setEditingDeal({ ...deal })}
>
- 编辑
+ {deal.reviewed ? "修改" : "编辑"}
- {!deal.reviewed && (
-
- )}
))}
@@ -278,12 +238,8 @@ export default function Review() {
<>
+ style={{ animation: "spin 0.8s linear infinite" }}
+ />{" "}
加载中...
>
) : (
@@ -362,7 +318,6 @@ export default function Review() {
)}
- {/* Show associated transactions in modal */}
{editingDeal.transactions &&
editingDeal.transactions.length > 0 && (
{
)
.get(...params);
- // 按分类统计支出(from deals)
+ // 按分类统计支出(用于饼图)
const catWhere = where
? where + " AND d.direction = 'expense' AND d.category IS NOT NULL"
: "WHERE d.direction = 'expense' AND d.category IS NOT NULL";
@@ -57,31 +57,45 @@ router.get("/overview", (req, res) => {
)
.all(...params);
- // 按来源统计(通过 deal_transactions 关联 transactions)
- const srcWhere = where ? where + "" : "";
+ // 按分类汇总(收入+支出),排除投资理财
+ const catBreakWhere = where
+ ? where + " AND d.category IS NOT NULL AND d.category != '投资理财'"
+ : "WHERE d.category IS NOT NULL AND d.category != '投资理财'";
- const sourceStats = db
+ const categoryBreakdown = db
.prepare(
`
SELECT
- t.source_type,
- s.source_name,
- COUNT(DISTINCT dt.deal_id) as deal_count,
- COUNT(*) as count,
- SUM(CASE WHEN t.direction = 'income' THEN t.amount ELSE 0 END) as total_income,
- SUM(CASE WHEN t.direction = 'expense' THEN ABS(t.amount) ELSE 0 END) as total_expense
- FROM deal_transactions dt
- JOIN deals d ON d.id = dt.deal_id
- JOIN transactions t ON t.id = dt.transaction_id
- LEFT JOIN sources s ON s.id = t.source_id
- ${srcWhere}
- GROUP BY t.source_type
- ORDER BY total_expense DESC
+ d.category,
+ COUNT(*) as deal_count,
+ SUM(CASE WHEN d.direction='income' THEN d.amount ELSE 0 END) as total_income,
+ SUM(CASE WHEN d.direction='expense' THEN ABS(d.amount) ELSE 0 END) as total_expense
+ FROM deals d
+ ${catBreakWhere}
+ GROUP BY d.category
+ ORDER BY (total_income + total_expense) DESC
`,
)
.all(...params);
- res.json({ overview: stats, categoryStats, sourceStats });
+ // 为每个分类查最大收入/支出 Deal
+ const maxIncomeStmt = db.prepare(
+ `SELECT id, amount, counterparty, deal_date, ai_description
+ FROM deals WHERE category=? AND direction='income'
+ ORDER BY amount DESC LIMIT 1`,
+ );
+ const maxExpenseStmt = db.prepare(
+ `SELECT id, amount, counterparty, deal_date, ai_description
+ FROM deals WHERE category=? AND direction='expense'
+ ORDER BY ABS(amount) DESC LIMIT 1`,
+ );
+
+ for (const cat of categoryBreakdown) {
+ cat.max_income = maxIncomeStmt.get(cat.category) || null;
+ cat.max_expense = maxExpenseStmt.get(cat.category) || null;
+ }
+
+ res.json({ overview: stats, categoryStats, categoryBreakdown });
});
// GET /api/stats/monthly — 月度趋势(基于 deals)