# Bank Tag Real Rule Phase 2 Backend Implementation Plan

> **For agentic workers:** REQUIRED: Use superpowers:subagent-driven-development (if subagents available) or superpowers:executing-plans to implement this plan. Steps use checkbox (`- [ ]`) syntax for tracking.

**Goal:** 将第二期 10 条复杂对象聚合与跨表比对规则替换为真实 SQL，完成 19 条目标银行流水模型的后端真实落地收口。

**Architecture:** 继续沿用现有 `CcdiBankTagServiceImpl + CcdiBankTagAnalysisMapper.xml + BankTagRuleConfigResolver` 链路，不新增平行计算模块。第二期重点放在聚合口径、关系人归并、资产登记比对和时间窗口判断，所有真实规则仍统一落在 XML 中完成。

**Tech Stack:** Java 21, Spring Boot 3, MyBatis XML, Maven, JUnit 5, Mockito, MySQL

---

### Task 1: 先锁定第二期参数与聚合边界

**Files:**
- Modify: `ccdi-project/src/test/java/com/ruoyi/ccdi/project/service/impl/BankTagRuleConfigResolverTest.java`
- Modify: `ccdi-project/src/main/java/com/ruoyi/ccdi/project/service/impl/BankTagRuleConfigResolver.java`
- Modify: `sql/ccdi_model_param.sql`
- Modify: `sql/2026-03-16-update-ccdi-model-param-defaults.sql`

- [ ] **Step 1: Write the failing test**

为以下规则补参数与无参数边界断言：

- `MULTI_PARTY_GAMBLING_TRANSFER` -> `MULTI_PARTY_AMT_MIN`、`MULTI_PARTY_AMT_MAX`
- `MONTHLY_FIXED_INCOME` -> `MONTHLY_FIXED_INCOME`
- `FIXED_COUNTERPARTY_TRANSFER` -> `FIXED_COUNTERPARTY_TRANSFER_MIN`、`FIXED_COUNTERPARTY_TRANSFER_MAX`
- `SALARY_QUICK_TRANSFER`、`SALARY_UNUSED` 为无参数规则
- `LOW_INCOME_RELATIVE_LARGE_TRANSACTION`、`SUPPLIER_CONCENTRATION`、三条资产不匹配规则为无参数规则

- [ ] **Step 2: Run test to verify it fails**

Run:

```bash
mvn test -pl ccdi-project -Dtest=BankTagRuleConfigResolverTest
```

Expected:

- `FAIL`

- [ ] **Step 3: Write minimal implementation**

补齐第二期规则参数映射和默认值脚本，要求：

- 只补设计文档明确需要阈值的规则
- 不为无参数规则制造虚假参数
- 继续保持大小写统一

- [ ] **Step 4: Run test to verify it passes**

Run:

```bash
mvn test -pl ccdi-project -Dtest=BankTagRuleConfigResolverTest
```

Expected:

- `PASS`

- [ ] **Step 5: Commit**

```bash
git add ccdi-project/src/main/java/com/ruoyi/ccdi/project/service/impl/BankTagRuleConfigResolver.java ccdi-project/src/test/java/com/ruoyi/ccdi/project/service/impl/BankTagRuleConfigResolverTest.java sql/ccdi_model_param.sql sql/2026-03-16-update-ccdi-model-param-defaults.sql
git commit -m "补齐第二期流水模型参数映射"
```

### Task 2: 实现第二期跨表比对型流水规则

**Files:**
- Modify: `ccdi-project/src/main/resources/mapper/ccdi/project/CcdiBankTagAnalysisMapper.xml`
- Modify: `ccdi-project/src/test/java/com/ruoyi/ccdi/project/mapper/CcdiBankTagAnalysisMapperXmlTest.java`

- [ ] **Step 1: Write the failing test**

为以下规则补结构断言：

- `selectHouseRegistrationMismatchStatements`
- `selectPropertyFeeRegistrationMismatchStatements`
- `selectTaxAssetRegistrationMismatchStatements`

断言要求：

- 不再出现 `where 1 = 0`
- SQL 中显式使用 `ccdi_asset_info`
- 仍返回标准 `STATEMENT` 命中字段

- [ ] **Step 2: Run test to verify it fails**

Run:

```bash
mvn test -pl ccdi-project -Dtest=CcdiBankTagAnalysisMapperXmlTest
```

Expected:

- `FAIL`

- [ ] **Step 3: Write minimal implementation**

在 XML 中实现三条资产不匹配规则：

- 购房交易与房产登记不匹配
- 物业缴费与房产登记不匹配
- 大额纳税与资产登记不匹配

要求：

- 使用当前环境已确认可执行的 `ccdi_asset_info` 字段口径
- 资产类型、状态值以当前仓库和现网样例已确认值为准
- 关系人和员工本人都纳入比对
- `reasonDetail` 能反映交易类型、金额或登记缺失事实

- [ ] **Step 4: Run test to verify it passes**

Run:

```bash
mvn test -pl ccdi-project -Dtest=CcdiBankTagAnalysisMapperXmlTest
```

Expected:

- `PASS`

- [ ] **Step 5: Commit**

```bash
git add ccdi-project/src/main/resources/mapper/ccdi/project/CcdiBankTagAnalysisMapper.xml ccdi-project/src/test/java/com/ruoyi/ccdi/project/mapper/CcdiBankTagAnalysisMapperXmlTest.java
git commit -m "实现第二期资产比对规则真实SQL"
```

### Task 3: 实现第二期对象聚合规则

**Files:**
- Modify: `ccdi-project/src/main/resources/mapper/ccdi/project/CcdiBankTagAnalysisMapper.xml`
- Modify: `ccdi-project/src/test/java/com/ruoyi/ccdi/project/mapper/CcdiBankTagAnalysisMapperXmlTest.java`
- Modify: `ccdi-project/src/test/java/com/ruoyi/ccdi/project/service/impl/CcdiBankTagServiceImplTest.java`

- [ ] **Step 1: Write the failing test**

覆盖以下规则的 SQL 结构与 Service 分发断言：

- `LOW_INCOME_RELATIVE_LARGE_TRANSACTION`
- `MULTI_PARTY_GAMBLING_TRANSFER`
- `MONTHLY_FIXED_INCOME`
- `FIXED_COUNTERPARTY_TRANSFER`
- `SUPPLIER_CONCENTRATION`
- `SALARY_QUICK_TRANSFER`
- `SALARY_UNUSED`

锁定要点：

- `objectType/objectKey/reasonDetail` 字段完整
- SQL 不再占位
- Service 命中正确 Mapper 方法

- [ ] **Step 2: Run test to verify it fails**

Run:

```bash
mvn test -pl ccdi-project -Dtest=CcdiBankTagAnalysisMapperXmlTest,CcdiBankTagServiceImplTest
```

Expected:

- `FAIL`

- [ ] **Step 3: Write minimal implementation**

在 XML 中按规则口径实现对象型聚合：

- 低收入亲属大额交易：先算月均收入，再判断累计交易额
- 疑似赌博交易：按日期、不同对手方和区间金额聚合
- 疑似兼职两条：按月份或季度聚合并做稳定性/区间判断
- 供应商集中度：基于 `ccdi_purchase_transaction` 计算集中度
- 工资快速转出：工资入账后 24h 内转出比例判断
- 工资无使用记录：工资入账后 30 天内无消费/转账支出口径判断

要求：

- 对象维度统一为员工身份证号
- 不在 Java 层做二次业务判断
- 保留 `reasonDetail` 解释性信息，便于后续结果总览和排障

- [ ] **Step 4: Run test to verify it passes**

Run:

```bash
mvn test -pl ccdi-project -Dtest=CcdiBankTagAnalysisMapperXmlTest,CcdiBankTagServiceImplTest
```

Expected:

- `PASS`

- [ ] **Step 5: Commit**

```bash
git add ccdi-project/src/main/resources/mapper/ccdi/project/CcdiBankTagAnalysisMapper.xml ccdi-project/src/test/java/com/ruoyi/ccdi/project/mapper/CcdiBankTagAnalysisMapperXmlTest.java ccdi-project/src/test/java/com/ruoyi/ccdi/project/service/impl/CcdiBankTagServiceImplTest.java
git commit -m "实现第二期对象聚合规则真实SQL"
```

### Task 4: 完成第二期回归与全量收口

**Files:**
- Modify: `sql/2026-03-16-bank-tagging.sql`
- Create: `docs/reports/implementation/2026-03-20-bank-tag-real-rule-phase2-backend-record.md`
- Create: `docs/tests/records/2026-03-20-bank-tag-real-rule-phase2-backend-verification.md`
- Test: `ccdi-project/src/test/java/com/ruoyi/ccdi/project/service/impl/CcdiBankTagServiceRiskCountRefreshTest.java`

- [ ] **Step 1: Align metadata and remarks**

校对第二期规则在 `sql/2026-03-16-bank-tagging.sql` 中的元数据，要求：

- 真实规则不再误写为“占位规则”
- 风险等级、结果类型与设计文档一致
- 第二期规则与第一期规则口径不冲突

- [ ] **Step 2: Run final backend regression**

Run:

```bash
mvn test -pl ccdi-project -Dtest=CcdiBankTagAnalysisMapperXmlTest,BankTagRuleConfigResolverTest,CcdiBankTagServiceImplTest,CcdiBankTagServiceRiskCountRefreshTest,CcdiProjectOverviewServiceStructureTest,CcdiProjectOverviewMapperSqlTest,CcdiProjectOverviewServiceImplTest,CcdiProjectOverviewControllerTest
```

Expected:

- `PASS`
- 19 条目标规则替换完成后，结果总览相关后端链路不回退

- [ ] **Step 3: Write implementation record**

在 `docs/reports/implementation/2026-03-20-bank-tag-real-rule-phase2-backend-record.md` 中记录：

- 第二期 10 条规则范围
- 跨表比对与对象聚合口径
- 参数和元数据调整
- 与第一期衔接关系
- 全量收口结论

- [ ] **Step 4: Write verification record**

在 `docs/tests/records/2026-03-20-bank-tag-real-rule-phase2-backend-verification.md` 中记录：

- 执行命令
- 执行时间
- 结果摘要
- 最终结论

- [ ] **Step 5: Commit**

```bash
git add sql/2026-03-16-bank-tagging.sql docs/reports/implementation/2026-03-20-bank-tag-real-rule-phase2-backend-record.md docs/tests/records/2026-03-20-bank-tag-real-rule-phase2-backend-verification.md
git commit -m "补充第二期流水模型后端实施记录"
```
