Files
PROJECT-CONTORL/openspec/changes/archive/2025-12-29-add-automation/proposal.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

53 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Change: Add Automation System
## Why
專案管理需要自動化功能來減少重複性工作:
- 當任務狀態變更時自動通知相關人員
- 每週自動生成進度報告發送給主管
- 減少人工追蹤與提醒的負擔
## What Changes
- **新增 Trigger 模型** - 定義觸發條件與動作
- **新增 TriggerService** - 觸發器評估與執行
- **新增 ReportService** - 週報生成邏輯
- **新增背景排程** - APScheduler 處理定時任務
- **整合任務 API** - 任務變更時評估觸發器
## Impact
- Affected specs: `automation`
- Affected code:
- `backend/app/models/` - 新增 trigger, scheduled_report 模型
- `backend/app/api/` - 新增 triggers, reports router
- `backend/app/services/` - 新增 trigger_service, report_service
- `backend/app/api/tasks/router.py` - 整合觸發器評估
- `frontend/src/` - 新增觸發器管理頁面
## Implementation Phases
### Phase 1: Event-Based Triggers
- Trigger 模型與 CRUD API
- 欄位變更觸發器status, assignee, priority
- 通知動作執行
- 整合任務更新流程
### Phase 2: Weekly Reports
- ScheduledReport 模型
- 週報生成邏輯(彙整任務統計)
- APScheduler 背景排程
- 系統內通知發送
### Phase 3: Advanced Features (Optional)
- 時間條件觸發器
- 複合條件支援
- 更新欄位動作
- 自動指派動作
## Dependencies
- notification (已完成) - 用於發送觸發通知
- audit-trail (已完成) - 記錄觸發器執行日誌
## Technical Decisions
- **使用 APScheduler** 而非 Celery - 輕量級,無需額外 worker 進程
- **同步觸發器評估** - 任務更新時同步執行,避免複雜的異步處理
- **JSON 欄位儲存條件** - 靈活的條件定義格式