tyt-api-nest/docs/tasks.md
2026-03-13 13:23:59 +08:00

41 lines
945 B
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.

# 调压任务模块说明(`src/tasks`
## 1. 目标
- 管理调压主任务 `Task` 与明细 `TaskItem`
- 支持状态机流转与事件触发,保证设备压力同步更新。
## 2. 状态机
- `PENDING -> ACCEPTED -> COMPLETED`
- `PENDING/ACCEPTED -> CANCELLED`
非法流转会返回 `409` 冲突错误(中文消息)。
## 3. 角色权限
- 医生/主任/组长:发布任务、取消自己创建的任务
- 工程师:接收任务、完成自己接收的任务
- 其他角色:默认拒绝
## 4. 事件触发
状态变化后会发出事件:
- `task.published`
- `task.accepted`
- `task.completed`
- `task.cancelled`
用于后续接入微信通知或消息中心。
## 5. 完成任务时的设备同步
`completeTask` 在单事务中执行:
1. 更新任务状态为 `COMPLETED`
2. 读取 `TaskItem.targetPressure`
3. 批量更新关联 `Device.currentPressure`
确保任务状态与设备压力一致性。