- [P20260221-111628] 2026-02-21 11:16:28 +0800
  - summary: CONTEXT TRANSFER: We are continuing a conversation that had gotten too long. Here is a summary: --- ## TASK 1: Seed DWS …
  - prompt:
```text
CONTEXT TRANSFER: We are continuing a conversation that had gotten too long. Here is a summary:

---
## TASK 1: Seed DWS Config Tables with Data + New Salary Rules

**STATUS**: in-progress

**USER QUERIES**: 1 ("分析seed_dws_config.sql内容，写入DWS，增加2025-01-01到2026-03-01的助教工资规则"), 2 ("保底概念澄清"), 3 ("这些种子规则，对应的计算方式，是否也实现？")

**DETAILS**:

### What was completed:
1. **Seed data written to `test_etl_feiqiu` database** via `scripts/ops/seed_dws_config.py` - all 5 cfg_* tables populated successfully:
   - `dws.cfg_performance_tier` - 12 rows (3 time periods)
   - `dws.cfg_assistant_level_price` - 5 rows
   - `dws.cfg_bonus_rules` - 9 rows (SPRINT + GUARANTEE + TOP_RANK)
   - `dws.cfg_area_category` - 21 rows
   - `dws.cfg_skill_type` - 3 rows

2. **Seed SQL file updated** (`db/etl_feiqiu/seeds/seed_dws_config.sql`) - v4.0, comments removed, new rules added

3. **Three time periods for `cfg_performance_tier`**:
   - `2000-01-01 ~ 2024-12-31`: Old 6-tier system (T0-T5)
   - `2025-01-01 ~ 2026-02-28`: **Unified tier** - single T0 tier, base_deduction=18元/hr, bonus_deduction_ratio=0.40, no hour thresholds (max_hours=NULL)
   - `2026-03-01 ~ 9999-12-31`: New 5-tier system (T0-T4)

4. **New GUARANTEE bonus rules** in `cfg_bonus_rules`:
   - `GUAR_LV10` (初级): 130h threshold, 12000元
   - `GUAR_LV20` (中级): 150h threshold, 16000元
   - `GUAR_LV30` (高级): 160h threshold, 18000元
   - `GUAR_LV40` (星级): 170h threshold, 23000元
   - All require ≥10h bonus/打赏课 (this constraint is in description text, not a separate column)
   - Effective: 2025-01-01 ~ 2026-02-28

### Critical business rule clarification (User Query 2):
The GUARANTEE bonus is a **salary floor guarantee**, NOT an additional bonus:
- `gross_salary = MAX(total_course_income, guarantee_amount)` when conditions are met
- If course income < guarantee → pay guarantee amount (补差额)
- If course income ≥ guarantee → pay course income normally
- Conditions: total hours ≥ threshold AND bonus_hours ≥ 10

### What needs to be done (User Query 3):
The user asked whether the calculation code properly implements these new rules. After extensive code review, the following gaps were identified:

**Gap 1: `AssistantSalaryTask._calculate_salary()` does NOT handle GUARANTEE rules**
- Current code only calls `calculate_sprint_bonus()` and `calculate_top_rank_bonus()`
- No `calculate_guarantee_bonus()` method exists
- Need to add guarantee logic: check if salary_month falls in GUARANTEE effective period, match rule by level_code, verify conditions (total hours + bonus hours ≥ 10), then apply `MAX(course_income, guarantee_amount)` logic

**Gap 2: `BaseDwsTask` has no `calculate_guarantee_bonus()` method**
- Need to add a method similar to `calculate_sprint_bonus()` that:
  1. Filters `cfg_bonus_rules` by `rule_type='GUARANTEE'` and effective_date
  2. Matches by assistant level_code (extracted from rule_code: `GUAR_LV{level_code}`)
  3. Checks threshold_hours AND bonus_hours ≥ 10
  4. Returns guarantee amount (or 0 if not eligible)

**Gap 3: Salary calculation formula needs restructuring for guarantee period**
- During 2025-01-01~2026-02-28, `gross_salary` should be `MAX(total_course_income + other_bonuses, guarantee_amount)` not just `total_course_income + total_bonus`
- The `dws_assistant_salary_calc` table has no dedicated column for guarantee; could use `other_bonus` or `calc_notes` to record it

**Gap 4: Seed SQL description text needs updating**
- The descriptions say "保底奖金12000元" but should clarify it's a salary floor: "保底月薪线12000元（实发=MAX(课时收入, 保底金额)）"

**Gap 5: Index calculations (WBI/NCI/RS/OS/MS/ML) are NOT affected**
- These are member-facing indices, completely independent of salary/bonus rules
- No changes needed for index tasks

**NEXT STEPS**:
1. Add `calculate_guarantee_bonus()` method to `apps/etl/connectors/feiqiu/tasks/dws/base_dws_task.py` (around line 794, after `calculate_top_rank_bonus`)
2. Modify `_calculate_salary()` in `apps/etl/connectors/feiqiu/tasks/dws/assistant_salary_task.py` to:
   - Call new guarantee method
   - Apply `MAX(course_income, guarantee_amount)` logic for gross_salary
   - Record guarantee info in `calc_notes`
3. Update seed SQL descriptions in `db/etl_feiqiu/seeds/seed_dws_config.sql` to clarify guarantee = salary floor
4. Update seed Python script `scripts/ops/seed_dws_config.py` descriptions to match
5. Re-run seed script to update descriptions in database
6. Run `/audit` (governance requires it - db/sql changes + business logic/salary calculation changes)

**FILEPATHS**:
- `db/etl_feiqiu/seeds/seed_dws_config.sql` - seed SQL (updated, needs description fix)
- `scripts/ops/seed_dws_config.py` - execution script (completed, needs description fix)
- `apps/etl/connectors/feiqiu/tasks/dws/base_dws_task.py` - base class with config loading, tier matching, bonus calculation methods
- `apps/etl/connectors/feiqiu/tasks/dws/assistant_salary_task.py` - salary calculation task (needs GUARANTEE logic)
- `apps/etl/connectors/feiqiu/tasks/dws/assistant_monthly_task.py` - monthly summary (no changes needed)
- `apps/etl/connectors/feiqiu/tasks/dws/assistant_daily_task.py` - daily detail (no changes needed)
- `db/etl_feiqiu/schemas/dws.sql` - DWS DDL (reference, no changes needed)

---

## USER CORRECTIONS AND INSTRUCTIONS:
- All responses must be in **简体中文** (Simplified Chinese) per `language-zh.md`
- Database operations must target **test_etl_feiqiu** (test database), never production
- Python scripts for DB operations go in `scripts/ops/`, must use `load_dotenv` from root `.env`
- Output paths must use `.env` variables, never hardcoded
- Changes to `db/` files and salary/business logic require `/audit` (governance rule)
- The GUARANTEE bonus is a **salary floor** (保底月薪线), NOT an extra bonus on top. Formula: `实发 = MAX(课时收入, 保底金额)` when conditions met
- Conditions for guarantee: total effective hours ≥ threshold AND bonus_hours ≥ 10小时打赏课
- The `rule_code` pattern `GUAR_LV{level_code}` maps to `cfg_assistant_level_price.level_code` (10=初级, 20=中级, 30=高级, 40=星级)

---

## Files to read
- `apps/etl/connectors/feiqiu/tasks/dws/base_dws_task.py` (lines 757-830 for bonus methods, lines 580-700 for config loading)
- `apps/etl/connectors/feiqiu/tasks/dws/assistant_salary_task.py` (full file - needs GUARANTEE logic added)
- `db/etl_feiqiu/seeds/seed_dws_config.sql` (full file - current state of seed data)
- `db/etl_feiqiu/schemas/dws.sql` (lines 1-200 for cfg table DDL, lines 300-500 for salary_calc table DDL)

USER QUERIES(most recent first):
1. 对的，是这个意思。这些种子规则，对应的计算方式，是否也实现？是否能通过正确的算法，计算相应的DWS/INDEX数据？
2. Output:
Command executed successfully with no output.

Exit Code: 0
3. Output:
Command executed successfully with no output.

Exit Code: 0
4. 对的，是这个意思。这些种子规则，对应的计算方式，是否也实现？是否能通过正确的算法，计算相应的DWS/INDEX数据？
5. Output:
Hook execution failed with exit code 1.

Error output:
[AUDIT REMINDER] Pending audit detected (root-file, dir:admin-web, dir:backend, dir:db, db-schema-change). Run /audit (Manual: Run /audit hook) to sync docs & write audit artifacts. (rate limit: 15min)



Exit Code: 1
6. Output:
Command executed successfully with no output.

Exit Code: 0
7. Output:
Command executed successfully with no output.

Exit Code: 0
8. 注意，2025-01-01 ~ 2026-02-28的保底概念为：满足保底条件后，直接发放保底奖金。后续的服务产生的费用依然正常计费但不超过保底奖金的部分不会发放额外的薪酬，意味着保底线达到后继续服务会有一部分的薪酬被覆盖掉，不产生新收入，我表达清楚么？
9. Output:
Command executed successfully with no output.

Exit Code: 0
10. Output:
Command executed successfully with no output.

Exit Code: 0
11. Output:
Command executed successfully with no output.

Exit Code: 0
12. db\etl_feiqiu\seeds\seed_dws_config.sql这个是有效的种子文件，只不过都被注释掉了。分析下内容，写入DWS，并让字段意义可以正常的被使用，在统计和财务薪酬计算等过程中起到应有的作用。此外，增加2025-01-01到2026-03-01的助教工资规则为：基础课，球房一律提成18元/小时。打赏课，球房一律提成40%客户支付价格不变。保底规则初级：完成130小时课程，其中必须含有10个小时打赏课。则保底奖金为12000元中级：完成150小时课程，其中必须含有10个小时打赏课。则保底奖金为16000元高级：完成160小时课程，其中必须含有10个小时打赏课。则保底奖金为18000元星级：完成170小时课程，其中必须含有10个小时打赏课。则保底奖金为23000元
---

METADATA:
The previous conversation had 6 messages.

INSTRUCTIONS:
Continue working until the user query has been fully addressed. Do not ask for clarification - proceed with the work based on the context provided.
IMPORTANT: you need to read from the files to Read section
```
