feat(ai): 建议状态生命周期 — 转换验证 + 执行端点 + 事件发布
建议(ai_suggestion)原有状态枚举完整但缺乏生命周期管理:
- 无转换验证(可从 Rejected 跳到 Approved)
- 无执行端点(护士无法标记"已执行")
- 无状态变更事件
变更:
1. SuggestionStatus.can_transition_to() — 仅允许合法单向转换
Pending → Approved/Rejected/Expired → Approved → Executed/Rejected/Expired
2. SuggestionService.execute_suggestion() — 记录执行结果
3. SuggestionService.expire_stale_suggestions() — 批量过期超时建议
4. POST /ai/suggestions/{id}/execute — 新执行端点
5. publish_status_event() — 状态变更时发布 ai.suggestion.status_changed 事件
6. 9 个新单元测试覆盖所有转换规则
This commit is contained in:
@@ -219,6 +219,10 @@ impl AiModule {
|
||||
"/ai/suggestions/{id}/approve",
|
||||
axum::routing::post(crate::handler::suggestion_handler::approve_suggestion),
|
||||
)
|
||||
.route(
|
||||
"/ai/suggestions/{id}/execute",
|
||||
axum::routing::post(crate::handler::suggestion_handler::execute_suggestion),
|
||||
)
|
||||
.route(
|
||||
"/ai/suggestions/{id}/comparison",
|
||||
axum::routing::get(crate::handler::suggestion_handler::get_comparison),
|
||||
|
||||
Reference in New Issue
Block a user