chore: 文档与 IDE 配置整理
- .kiro/specs/ → docs/specs/(41 个历史需求 spec 迁移,移除 .config.kiro) - CLAUDE.md 三层拆分:根文件精简 + apps/backend/CLAUDE.md + .claude/commands/ - 新增 /spec-close、/pre-change 两个工作流命令 - DDL 基线刷新(从测试库重新导出 11 个文件,dws 35→38 表,biz 18→21 表) - BD_Manual → BD_manual 命名统一(48 个文件) - 修复 3 处文档与数据库不一致(auth.users.status 默认值、scheduled_tasks 字段、RLS 视图数) - 新增 BD_manual_public_rbac_tables.md(public schema 8 张 RBAC/工作流表) - 合并 biz.trigger_jobs 文档(10→12 字段,归档独立文档) - docs/database/README.md 索引更新 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
76
docs/database/BD_manual_dws_assistant_task_monthly.md
Normal file
76
docs/database/BD_manual_dws_assistant_task_monthly.md
Normal file
@@ -0,0 +1,76 @@
|
||||
# BD 手册:biz.dws_assistant_task_monthly
|
||||
|
||||
> 助教任务月度统计汇总表
|
||||
|
||||
## 基本信息
|
||||
|
||||
| 属性 | 值 |
|
||||
|------|-----|
|
||||
| Schema | biz |
|
||||
| 表名 | dws_assistant_task_monthly |
|
||||
| 所属库 | zqyy_app |
|
||||
| 创建日期 | 2026-03-31 |
|
||||
| 写入方 | `task_generator._update_task_stats()` |
|
||||
| 读取方 | 看板 / 绩效报表(待接入) |
|
||||
| 幂等策略 | UPSERT(`ON CONFLICT (site_id, assistant_id, stat_month) DO UPDATE`) |
|
||||
|
||||
## 用途
|
||||
|
||||
按助教 + 自然月维度汇总任务引擎的创建/完成/放弃/转移数据。每次 `task_generator.run()` 执行时,对当前门店的所有助教重新计算当月统计并 upsert。
|
||||
|
||||
## 字段定义
|
||||
|
||||
| 字段名 | 类型 | 可空 | 默认值 | 说明 |
|
||||
|--------|------|------|--------|------|
|
||||
| id | BIGSERIAL | NOT NULL | 自增 | 主键 |
|
||||
| site_id | BIGINT | NOT NULL | — | 门店 ID |
|
||||
| assistant_id | BIGINT | NOT NULL | — | 助教 ID |
|
||||
| stat_month | DATE | NOT NULL | — | 统计月份(月初日期,如 2026-03-01) |
|
||||
| recall_created | INT | NOT NULL | 0 | 当月创建的召回任务数(high_priority + priority) |
|
||||
| follow_up_created | INT | NOT NULL | 0 | 当月创建的回访任务数 |
|
||||
| relationship_created | INT | NOT NULL | 0 | 当月创建的关系构建任务数 |
|
||||
| total_created | INT | NOT NULL | 0 | 当月创建的任务总数 |
|
||||
| recall_completed | INT | NOT NULL | 0 | 当月完成的召回任务数 |
|
||||
| follow_up_completed | INT | NOT NULL | 0 | 当月完成的回访任务数 |
|
||||
| total_completed | INT | NOT NULL | 0 | 当月完成的任务总数 |
|
||||
| abandoned_count | INT | NOT NULL | 0 | 当月放弃的任务数 |
|
||||
| transferred_count | INT | NOT NULL | 0 | 当月转移的任务数 |
|
||||
| updated_at | TIMESTAMPTZ | NOT NULL | NOW() | 最后更新时间 |
|
||||
|
||||
## 约束与索引
|
||||
|
||||
| 名称 | 类型 | 字段 |
|
||||
|------|------|------|
|
||||
| PK | PRIMARY KEY | id |
|
||||
| UQ | UNIQUE | (site_id, assistant_id, stat_month) |
|
||||
| idx_task_monthly_site_month | INDEX | (site_id, stat_month DESC) |
|
||||
| idx_task_monthly_assistant | INDEX | (assistant_id, stat_month DESC) |
|
||||
|
||||
## 数据来源
|
||||
|
||||
统计数据从 `biz.coach_tasks` 表聚合:
|
||||
- 按 `assigned_assistant_id` + `DATE_TRUNC('month', created_at)` 分组
|
||||
- `recall_created` = COUNT WHERE task_type IN ('high_priority_recall', 'priority_recall')
|
||||
- `follow_up_created` = COUNT WHERE task_type = 'follow_up_visit'
|
||||
- `relationship_created` = COUNT WHERE task_type = 'relationship_building'
|
||||
- `*_completed` = COUNT WHERE status = 'completed' AND 对应 task_type
|
||||
- `abandoned_count` = COUNT WHERE status = 'abandoned'
|
||||
- `transferred_count` = COUNT WHERE status = 'transferred'
|
||||
|
||||
## 兼容性
|
||||
|
||||
- ETL:无直接依赖(表由后端 task_generator 写入)
|
||||
- 后端 API:待接入看板/绩效接口
|
||||
- 小程序:无直接依赖
|
||||
|
||||
## 回滚策略
|
||||
|
||||
```sql
|
||||
DROP TABLE IF EXISTS biz.dws_assistant_task_monthly;
|
||||
```
|
||||
|
||||
## 关联变更
|
||||
|
||||
- 迁移脚本:`db/zqyy_app/migrations/2026-03-31__task_stats_tables.sql`
|
||||
- 审计记录:`docs/audit/changes/2026-03-31__task-engine-overhaul.md`
|
||||
- 关联表:`biz.coach_tasks`(数据源)、`dws.dws_member_assistant_relation_index`(C 层历史总计字段)
|
||||
Reference in New Issue
Block a user