Files
PROJECT-CONTORL/openspec/changes/archive/2025-12-29-add-automation/tasks.md
beabigegg 95c281d8e1 feat: implement automation module
- Event-based triggers (Phase 1):
  - Trigger/TriggerLog models with field_change type
  - TriggerService for condition evaluation and action execution
  - Trigger CRUD API endpoints
  - Task integration (status, assignee, priority changes)
  - Frontend: TriggerList, TriggerForm components

- Weekly reports (Phase 2):
  - ScheduledReport/ReportHistory models
  - ReportService for stats generation
  - APScheduler for Friday 16:00 job
  - Report preview/generate/history API
  - Frontend: WeeklyReportPreview, ReportHistory components

- Tests: 23 new tests (14 triggers + 9 reports)
- OpenSpec: add-automation change archived

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-29 22:59:00 +08:00

91 lines
3.2 KiB
Markdown

## Phase 1: Event-Based Triggers
### 1.1 Database Schema
- [x] 1.1.1 建立 Trigger model (`pjctrl_triggers`)
- [x] 1.1.2 建立 TriggerLog model (`pjctrl_trigger_logs`)
- [x] 1.1.3 建立 Alembic migration
- [x] 1.1.4 定義 TriggerType enum (field_change, schedule)
### 1.2 Trigger Service
- [x] 1.2.1 建立 TriggerService 類別
- [x] 1.2.2 實作 evaluate_triggers(task, old_values, new_values) 方法
- [x] 1.2.3 實作 check_condition(condition, old_value, new_value) 方法
- [x] 1.2.4 實作 execute_action(action, task, user) 方法
- [x] 1.2.5 實作 log_execution(trigger, task, status, error) 方法
### 1.3 Trigger API
- [x] 1.3.1 建立 Trigger schemas (request/response)
- [x] 1.3.2 實作 POST `/api/projects/{project_id}/triggers` - 建立
- [x] 1.3.3 實作 GET `/api/projects/{project_id}/triggers` - 列表
- [x] 1.3.4 實作 GET `/api/triggers/{id}` - 詳情
- [x] 1.3.5 實作 PUT `/api/triggers/{id}` - 更新
- [x] 1.3.6 實作 DELETE `/api/triggers/{id}` - 刪除
- [x] 1.3.7 實作 GET `/api/triggers/{id}/logs` - 執行日誌
### 1.4 Task Integration
- [x] 1.4.1 修改 update_task endpoint 整合觸發器評估
- [x] 1.4.2 修改 update_task_status endpoint 整合觸發器評估
- [x] 1.4.3 修改 assign_task endpoint 整合觸發器評估
### 1.5 Frontend - Triggers
- [x] 1.5.1 建立 triggers.ts service
- [x] 1.5.2 建立 TriggerList 元件
- [x] 1.5.3 建立 TriggerForm 元件(條件/動作設定)
- [x] 1.5.4 整合至 Project 設定頁面
### 1.6 Testing - Phase 1
- [x] 1.6.1 TriggerService 單元測試
- [x] 1.6.2 Trigger API 端點測試
- [x] 1.6.3 觸發器執行整合測試
## Phase 2: Weekly Reports
### 2.1 Database Schema
- [x] 2.1.1 建立 ScheduledReport model (`pjctrl_scheduled_reports`)
- [x] 2.1.2 建立 ReportHistory model (`pjctrl_report_history`)
- [x] 2.1.3 建立 Alembic migration
### 2.2 Report Service
- [x] 2.2.1 建立 ReportService 類別
- [x] 2.2.2 實作 generate_weekly_report(user_id) 方法
- [x] 2.2.3 實作 get_weekly_stats(user_id, week_start) 方法
- [x] 2.2.4 實作 send_report_notification(user_id, report) 方法
- [x] 2.2.5 實作 save_report_history(report) 方法
### 2.3 Scheduler Setup
- [x] 2.3.1 安裝 APScheduler
- [x] 2.3.2 建立 scheduler.py 設定檔
- [x] 2.3.3 設定週五 16:00 排程任務
- [x] 2.3.4 整合至 main.py 啟動流程
### 2.4 Report API
- [x] 2.4.1 建立 Report schemas
- [x] 2.4.2 實作 GET `/api/reports/weekly/preview` - 預覽
- [x] 2.4.3 實作 POST `/api/reports/weekly/generate` - 手動觸發
- [x] 2.4.4 實作 GET `/api/reports/history` - 歷史紀錄
### 2.5 Frontend - Reports
- [x] 2.5.1 建立 reports.ts service
- [x] 2.5.2 建立 WeeklyReportPreview 元件
- [x] 2.5.3 建立 ReportHistory 元件
- [x] 2.5.4 新增管理員報告頁面
### 2.6 Testing - Phase 2
- [x] 2.6.1 ReportService 單元測試
- [x] 2.6.2 週報生成測試
- [x] 2.6.3 排程執行測試
## Phase 3: Advanced Features (Optional)
### 3.1 Schedule Triggers
- [ ] 3.1.1 支援 cron 表達式觸發器
- [ ] 3.1.2 截止日期提醒觸發器
### 3.2 Additional Actions
- [ ] 3.2.1 更新欄位動作
- [ ] 3.2.2 自動指派動作
### 3.3 Complex Conditions
- [ ] 3.3.1 AND/OR 複合條件
- [ ] 3.3.2 多欄位條件