touyun-elderly-care/docs/superpowers/specs/2026-10-14-服务机构端-C2派单工单-design.md
liuyun 4fa03ab69d docs: 服务机构端 C2 派单工单设计文档
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-14 21:52:49 +08:00

64 lines
4.8 KiB
Markdown
Raw Permalink 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.

# 服务机构端 · C2 派单工单 · 设计文档
> 日期:2026-10-14
> 范围:派单工单域——服务计划(svc_plan/svc_plan_item)+ 八态工单(svc_order)+ 老人个人项目库(ltc_elder_svc)+ 后台排班派单(B2)。
> 依据:P0 PRD §2.5/§3.2/§5.2/§5.3/§5.5.1(B1-C)/§7.2/§7.4/§8.2;C0/C1 设计。
> 后续:C3 履约留痕(垫付 is_prepaid + 结转在 C3)。
## 1. 背景与目标
在 C1(老人档案 + 十态状态机)之上,落地「派单工单」:服务计划制定/变更、排班派单、八态工单、老人个人项目库。L1 硬锁(无有效待遇不可派单)在此消费。
## 2. 已定决策(用户 2026-10-14 拍板)
- 垫付台账只做**派单例外**(waiting_period 允许派单),`is_prepaid` 标记 + 结转放 C3。
- 排班派单做**完整 B2**(日视图、调单≤3步、时间冲突硬拦、批量推荐需人工确认)。
- 属地项数校验 **C2 做**(昆明 ≥13/15/18 + 附加≤5;州市只提示不拦)。
- `elder_svc` 放 C2(与「制定计划时带入」一起)。
- 表命名:`svc_plan`/`svc_plan_item`/`svc_order`(服务域)、`ltc_elder_svc`(老人域)。
## 3. 数据模型(新增 4 张表)
通用字段 `created_at/by`、`updated_at`、`deleted_at`;主键 UUID v7;tenantCode 多租户;软删。
**`svc_plan` 计划头**:id、tenant_code、elder_id、plan_period_start/end、care_level、care_mode、item_count、item_count_rule、extra_item_count、week_freq、month_hours、plan_status(draft/active/changed/ended)、confirm_elder、confirm_guardian、confirm_time、plan_basis(json)、change_from_plan_id、biz_line(ltci)。
**`svc_plan_item` 计划项**:id、plan_id、svc_id(引 L4 svc_org)、svc_name_snapshot、svc_code_snapshot、freq_type、freq_value、duration_min、photo_tier(must/optional/free)、caution_note、is_medical、need_cert。
**`svc_order` 工单**:id、tenant_code、elder_id、plan_id、service_date、time_slot_start/end、assignee_id(staff)、assign_time、assign_mode(manual/batch_recommend)、order_status(八态)、item_list(json)、need_photo、cancel_reason、reschedule_log(json)、qualification_check(预留)、billable/price_snapshot/settle_period(预留)、not_met_reason、not_met_at、biz_line(ltci)。
**`ltc_elder_svc` 老人个人项目库**:id、tenant_code、elder_id、svc_id(引 L4)、svc_name_snapshot、svc_code_snapshot、care_mode、is_active。
## 4. 状态机
- **order 八态**:`to_assign`(待派单)/`assigned`(已派单)/`serving`(服务中)/`done`(已完成)/`abnormal`(异常)/`cancelled`(已取消)/`overdue`(逾期未做)/`not_met`(未遇·扑空)。
- **plan 四态**:`draft/active/changed/ended`;**变更=新建 + change_from_plan_id 指向旧,不原地改**(留旧版=留证据)。
- 派单前置校验按序:工单态 → 老人态(L1) → 有计划(L2) → 护理员当班 → 时间冲突(2001硬拦) → 资质(1006提示) → 本组过滤。
## 5. 硬锁与校验
- **L1**:`/order/assign` 时 `elder.treat_status ∈ {active, waiting_period}`,否则 1001。waiting_period 是垫付例外(C3 再落 is_prepaid)。
- **L2**:`/order/generate` 需 `plan_status=active`,否则 1002。
- **时间冲突(2001 硬拦)**:同 `assignee_id` 且 `time_slot` 重叠。
- **属地项数(2002 提示级)**:昆明 `care_mode×care_level` 规则(一级≥18/二级≥15/三级≥13,附加≤5;居家按周次/月时长);州市不校验只提示。
- **快照纪律**:plan_item/order.item_list 存 `svc_name_snapshot`,防目录改名。
## 6. 接口
`POST /plan`、`POST /plan/change`、`GET /plan/:id`、`POST /plan/:id/confirm`、`GET /plan/by-elder/:elderId`;`POST /order/generate`、`POST /order/assign`、`POST /order/:id/reassign`、`GET /order/batch-recommend`、`GET /order/today`、`POST /order/:id/cancel`、`GET /order/:id`;`GET /elder-svc/:elderId`、`PUT /elder-svc/:elderId`(整表覆盖)。
## 7. 前端
- **排班派单页(ltc/schedule)**:日视图(横轴时间段/纵轴护理员)、卡片点击调单面板≤3步、冲突红框、空缺橙框、批量推荐列表(需逐条/整批人工确认)。
- **服务对象页**:档案加「个人项目库」区块(勾选 L4 项目 + 可空)+ 「制定计划」入口(一键从个人项目库带入,可改;校验属地项数)。
## 8. 横切
- 审计:派单/调单/取消/制定/变更计划/个人项目库保存。
- 调单记录 `reschedule_log`(谁改、改前改后、时间)。
- 批量推荐**只推荐不自动派**,权重参数可配置(默认:同资质→历史服务过→距离近→负荷低)。
## 9. 非目标(本期不做)
垫付 `is_prepaid` 标记与结转(C3)、护理员 APP(M1 今日任务)、自动派单、跨机构冲突检测、`qualification_check` 自动校验(预留字段)。