# Project 40 Large Transaction Data Backend Implementation Plan

> **For Claude:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.

**Goal:** 为开发库 `project_id=40` 直接插入一批符合大额交易模型口径的银行流水，并完成 SQL 级命中验证。

**Architecture:** 通过独立 SQL 脚本管理测试数据生命周期，只操作 `ccdi_bank_statement`。脚本先清理项目 40 旧流水，再按既定身份、账户、日期和金额批量插入命中流水与少量噪声流水，最后执行核验 SQL 确认每个指标至少命中一次。

**Tech Stack:** MySQL 5.7, PowerShell, 项目现有 `ccdi_bank_statement` 表结构, `assets/大额交易.csv`

---

### Task 1: 固化设计与目标数据清单

**Files:**
- Modify: `D:\ccdi\ccdi\docs\plans\2026-03-16-large-transaction-project40-design.md`
- Create: `D:\ccdi\ccdi\assets\database\2026-03-16-project40-large-transaction-seed.sql`

**Step 1: 复核命中口径**

对照 `assets/大额交易.csv` 和库内默认参数，整理每个指标的命中条件、阈值和使用身份。

**Step 2: 写出目标数据清单**

在 SQL 脚本注释区列出每类指标对应的样本数量、证件号、金额范围、关键词和日期范围。

**Step 3: 自检唯一键策略**

确认每条插入记录的 `(project_id, LE_ACCOUNT_NO, ACCOUNTING_DATE_ID, AMOUNT_DR, AMOUNT_CR)` 组合唯一。

**Step 4: Commit**

```bash
git add docs/design/2026-03-16-large-transaction-project40-design.md assets/database/2026-03-16-project40-large-transaction-seed.sql
git commit -m "文档: 补充项目40大额交易测试数据设计"
```

### Task 2: 编写清理与插入 SQL

**Files:**
- Modify: `D:\ccdi\ccdi\assets\database\2026-03-16-project40-large-transaction-seed.sql`

**Step 1: 写清理语句**

添加只针对 `project_id=40` 的删除语句：

```sql
DELETE FROM ccdi_bank_statement
WHERE project_id = 40;
```

**Step 2: 编写最小插入块**

先写 1 到 2 条房车消费和税务支出的插入语句，确认字段完整：

```sql
INSERT INTO ccdi_bank_statement (
  project_id, LE_ID, ACCOUNT_ID, group_id, LE_ACCOUNT_NAME, LE_ACCOUNT_NO,
  ACCOUNTING_DATE_ID, ACCOUNTING_DATE, TRX_DATE, CURRENCY,
  AMOUNT_DR, AMOUNT_CR, AMOUNT_BALANCE, CASH_TYPE, CUSTOMER_LE_ID,
  CUSTOMER_ACCOUNT_NAME, CUSTOMER_ACCOUNT_NO, customer_bank, customer_reference,
  USER_MEMO, BANK_COMMENTS, BANK_TRX_NUMBER, BANK, TRX_FLAG, TRX_TYPE,
  EXCEPTION_TYPE, internal_flag, batch_id, batch_sequence, CREATE_DATE,
  created_by, meta_json, no_balance, begin_balance, end_balance,
  override_bs_id, payment_method, cret_no
) VALUES (...);
```

**Step 3: 扩展全部指标数据**

补全单笔大额收入、累计收入、年流水超限、大额存现、多次存现、大额转账和噪声流水。

**Step 4: 运行脚本**

Run:

```bash
mysql --host=116.62.17.81 --user=root --password=*** --database=ccdi < assets/database/2026-03-16-project40-large-transaction-seed.sql
```

Expected: 执行成功，无唯一键冲突。

**Step 5: Commit**

```bash
git add assets/database/2026-03-16-project40-large-transaction-seed.sql
git commit -m "数据: 生成项目40大额交易测试流水"
```

### Task 3: 编写并执行核验 SQL

**Files:**
- Modify: `D:\ccdi\ccdi\assets\database\2026-03-16-project40-large-transaction-seed.sql`
- Create: `D:\ccdi\ccdi\docs\implementation-reports\2026-03-16-project40-large-transaction-report.md`

**Step 1: 添加核验查询**

在脚本末尾添加按 `大额交易.csv` 口径改写后的项目 40 验证查询，覆盖全部指标。

**Step 2: 执行核验**

Run:

```bash
mysql --host=116.62.17.81 --user=root --password=*** --database=ccdi -e "/* verify queries */"
```

Expected: 每个指标返回至少 1 条命中记录或 1 个命中分组。

**Step 3: 记录结果**

把每个指标的命中数量、示例流水编号和涉及人员写入报告文档。

**Step 4: Commit**

```bash
git add assets/database/2026-03-16-project40-large-transaction-seed.sql docs/reports/implementation2026-03-16-project40-large-transaction-report.md
git commit -m "验证: 完成项目40大额交易测试流水校验"
```

### Task 4: 回归检查与收尾

**Files:**
- Modify: `D:\ccdi\ccdi\docs\implementation-reports\2026-03-16-project40-large-transaction-report.md`

**Step 1: 检查项目总量**

Run:

```bash
mysql --host=116.62.17.81 --user=root --password=*** --database=ccdi -e "SELECT project_id, COUNT(*) FROM ccdi_bank_statement WHERE project_id=40 GROUP BY project_id;"
```

Expected: `project_id=40` 存在稳定数量的测试流水。

**Step 2: 抽样检查页面关键字段**

确认 `TRX_DATE`、`USER_MEMO`、`CUSTOMER_ACCOUNT_NAME`、`AMOUNT_DR`、`AMOUNT_CR` 等字段适合前端展示。

**Step 3: 补充最终说明**

在报告中注明依赖的默认阈值、复用的测试身份和复跑方式。

**Step 4: Commit**

```bash
git add docs/reports/implementation2026-03-16-project40-large-transaction-report.md
git commit -m "文档: 完善项目40大额交易测试流水报告"
```
