feat: gift card breakdown - migrations, fdw queries, finance recharge task, board-finance page updates

This commit is contained in:
Neo
2026-03-20 03:24:17 +08:00
parent 8f8abad4c9
commit 675301f38b
15 changed files with 473 additions and 185 deletions

View File

@@ -42,74 +42,74 @@
- 当某种卡类型无充值记录时,对应新增为 0
- **Validates: Requirements 3.1, 3.2, 3.3, 10.2**
- [ ] 4. ETL transform 合并细分字段
- [-] 4.1 修改 `extract()` 调用新方法并传递结果
- [x] 4. ETL transform 合并细分字段
- [x] 4.1 修改 `extract()` 调用新方法并传递结果
- 文件:`apps/etl/connectors/feiqiu/tasks/dws/finance_recharge_task.py`
- 在 extract 返回值中新增 `gift_recharge_breakdown` key
- _Requirements: 4.1_
- [-] 4.2 修改 `transform()` 将 6 个新字段写入 record dict
- [x] 4.2 修改 `transform()` 将 6 个新字段写入 record dict
- 使用 `self.safe_decimal()` 处理值,缺失 key 时填充 0
- 沿用现有 delete-before-insert 幂等策略
- _Requirements: 4.1, 4.2, 4.3_
- [~] 4.3 编写属性测试transform 正确合并细分字段
- [x] 4.3 编写属性测试transform 正确合并细分字段
- **Property 5: transform 正确合并细分字段**
- 生成随机 `card_balances` dict 和 `gift_recharge_breakdown` dict验证 record 包含 6 个字段且值正确
- 输入 dict 缺少某个 key 时,对应字段为 0
- **Validates: Requirements 4.1, 4.2**
- [ ] 5. Checkpoint — ETL 层验证
- [x] 5. Checkpoint — ETL 层验证
- Ensure all tests pass, ask the user if questions arise.
- [ ] 6. 数据库视图层同步
- [~] 6.1 RLS 视图重建 `app.v_dws_finance_recharge_summary`
- [x] 6.1 RLS 视图重建 `app.v_dws_finance_recharge_summary`
- 创建迁移脚本 `db/zqyy_app/migrations/`
- `CREATE OR REPLACE VIEW` 包含全部 6 个新字段
- 保持 `site_id` 行级安全过滤策略不变
- _Requirements: 5.1, 5.2, 5.3_
- [~] 6.2 FDW 外部表同步
- [x] 6.2 FDW 外部表同步
- 创建/更新幂等脚本(先 DROP 再 `IMPORT FOREIGN SCHEMA`
- 支持重复执行不报错
- _Requirements: 6.1, 6.2_
- [ ] 7. 后端接口修改
- [~] 7.1 修改 `fdw_queries.get_finance_recharge()` SQL 查询
- [x] 7.1 修改 `fdw_queries.get_finance_recharge()` SQL 查询
- 文件:`apps/backend/app/services/fdw_queries.py`
- SQL 新增 6 个字段的 SUM 聚合
- _Requirements: 7.1_
- [~] 7.2 修改 `gift_rows` 构建逻辑
- [x] 7.2 修改 `gift_rows` 构建逻辑
- 余额行:`liquor`/`table_fee`/`voucher` 填充对应细分余额
- 新增行:`liquor`/`table_fee`/`voucher` 填充对应细分新增,`total` 使用三个细分之和
- 消费行:`liquor`/`table_fee`/`voucher` 保持 0`total` 返回消费总额
- _Requirements: 7.2, 7.3, 7.4, 8.1, 8.2_
- [~] 7.3 修改 `_empty_recharge_data()` 空默认值同步
- [x] 7.3 修改 `_empty_recharge_data()` 空默认值同步
- 确保新增 6 个字段在空数据结构中默认为 0
- _Requirements: 7.5_
- [~] 7.4 编写属性测试:余额恒等式
- [x] 7.4 编写属性测试:余额恒等式
- **Property 1: 余额恒等式**
- 生成随机三种余额,验证 `gift_card_balance = gift_liquor_balance + gift_table_fee_balance + gift_voucher_balance`
- **Validates: Requirements 1.3, 10.3**
- [~] 7.5 编写属性测试:新增恒等式
- [x] 7.5 编写属性测试:新增恒等式
- **Property 2: 新增恒等式**
- 生成随机三种新增,验证 `recharge_gift = gift_liquor_recharge + gift_table_fee_recharge + gift_voucher_recharge`
- **Validates: Requirements 1.4**
- [~] 7.6 编写属性测试:后端接口返回正确细分数据
- [x] 7.6 编写属性测试:后端接口返回正确细分数据
- **Property 6: 后端接口返回正确的细分数据**
- 生成随机 DWS 行mock FDW 查询,验证 gift_rows 余额行和新增行的细分值等于对应字段 SUM
- **Validates: Requirements 7.2, 7.3**
- [~] 7.7 编写属性测试:消费行细分列始终为 0
- [x] 7.7 编写属性测试:消费行细分列始终为 0
- **Property 7: 消费行细分列始终为 0**
- 验证 gift_rows 消费行的 `liquor.value``table_fee.value``voucher.value` 始终为 0
- **Validates: Requirements 7.4, 8.1, 8.2**
- [~] 7.8 编写属性测试:环比计算对新字段正确适配
- [x] 7.8 编写属性测试:环比计算对新字段正确适配
- **Property 8: 环比计算对新字段正确适配**
- 生成随机当期/上期数据,验证 `compare=1` 时 gift_rows 每个 cell 的 compare 等于 `calc_compare(当期值, 上期值)`
- **Validates: Requirements 7.6**
- [ ] 8. Checkpoint — 后端层验证
- [x] 8. Checkpoint — 后端层验证
- Ensure all tests pass, ask the user if questions arise.
- [ ] 9. 小程序联调
- [~] 9.1 替换 `board-finance.ts` 中 mock 数据为真实 API 调用
- [x] 9.1 替换 `board-finance.ts` 中 mock 数据为真实 API 调用
- 文件:`apps/miniprogram/miniprogram/pages/board-finance/board-finance.ts`
- 移除 `giftRows` 硬编码 mock 数据
- 使用 Finance_Board_API 返回的真实数据
@@ -118,7 +118,7 @@
- _Requirements: 9.1, 9.2, 9.3, 9.4_
- [ ] 10. 数据一致性验证
- [~] 10.1 创建验证 SQL 脚本
- [x] 10.1 创建验证 SQL 脚本
- 验证余额恒等式:`gift_card_balance = 三种余额之和`
- 验证新增恒等式:`recharge_gift = 三种新增之和`
- 验证 DWS 与 DWD 源数据一致DWS 各类型余额 = DWD `dim_member_card_account` 对应 card_type_id 的 balance 之和
@@ -126,14 +126,14 @@
- _Requirements: 10.1, 10.2, 10.3_
- [ ] 11. BD 手册更新
- [~] 11.1 更新 `BD_manual_dws_finance_recharge_summary.md`
- [x] 11.1 更新 `BD_manual_dws_finance_recharge_summary.md`
- 文件:`apps/etl/connectors/feiqiu/docs/database/DWS/main/BD_manual_dws_finance_recharge_summary.md`
- 新增 6 个字段的说明(字段名、类型、含义、数据来源)
- 更新恒等式约束说明
- 更新数据流向描述
- _Requirements: 1.1, 1.3, 1.4_
- [ ] 12. Final checkpoint — 全链路验证
- [x] 12. Final checkpoint — 全链路验证
- Ensure all tests pass, ask the user if questions arise.
## Notes

File diff suppressed because one or more lines are too long

View File

@@ -1,9 +1,26 @@
{
"audit_required": false,
"db_docs_required": false,
"reasons": [],
"changed_files": [],
"change_fingerprint": "",
"marked_at": "2026-03-20T01:48:07.860062+08:00",
"audit_required": true,
"db_docs_required": true,
"reasons": [
"dir:backend",
"dir:etl",
"dir:miniprogram",
"dir:db",
"db-schema-change",
"root-file"
],
"changed_files": [
"apps/backend/app/services/fdw_queries.py",
"apps/etl/connectors/feiqiu/docs/database/DWS/main/BD_manual_dws_finance_recharge_summary.md",
"apps/etl/connectors/feiqiu/tasks/dws/finance_recharge_task.py",
"apps/miniprogram/miniprogram/pages/board-finance/board-finance.ts",
"db/zqyy_app/migrations/2026-03-20_rebuild_rls_view_gift_breakdown.sql",
"db/zqyy_app/migrations/2026-03-20_refresh_fdw_finance_recharge_summary.sql",
"docs/database/ddl/etl_feiqiu__app.sql",
"scripts/ops/verify_gift_card_breakdown.sql",
"xmkiro.zip"
],
"change_fingerprint": "7b13e291960c1287835fbbde36ce895c1d95eb5b",
"marked_at": "2026-03-20T03:23:40.279993+08:00",
"last_reminded_at": null
}

View File

@@ -1,9 +1,18 @@
{
"needs_check": false,
"scanned_at": "2026-03-19T21:59:42.593964+08:00",
"needs_check": true,
"scanned_at": "2026-03-20T03:09:56.627304+08:00",
"new_migration_sql": [],
"new_or_modified_sql": [],
"code_without_docs": [],
"new_or_modified_sql": [
"scripts/ops/verify_gift_card_breakdown.sql"
],
"code_without_docs": [
{
"file": "apps/miniprogram/miniprogram/pages/board-finance/board-finance.ts",
"expected_docs": [
"apps/miniprogram/README.md"
]
}
],
"new_files": [],
"has_bd_manual": false,
"has_audit_record": false,

File diff suppressed because one or more lines are too long

View File

@@ -1,4 +1,4 @@
{
"prompt_id": "P20260320-014807",
"at": "2026-03-20T01:48:07.860062+08:00"
"prompt_id": "P20260320-032340",
"at": "2026-03-20T03:23:40.279993+08:00"
}