liuyun bec32cf223 docs(openspec): C2 派单工单 change 提案
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-14 21:53:59 +08:00

48 lines
3.6 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.

## Context
C1 已有 elder(十态状态机)、svc_org(L4 目录)、staff(护理员)。C2 新增派单工单域,纯新增、不侵入脚手架。设计背景见 `docs/superpowers/specs/2026-10-14-服务机构端-C2派单工单-design.md`。
## Goals / Non-Goals
**Goals:** 服务计划(制定/变更/项数校验)、八态工单(派单/调单/冲突/批量推荐)、老人个人项目库、后台排班派单页。
**Non-Goals:** 垫付 is_prepaid 与结转(C3)、护理员 APP、自动派单、跨机构冲突检测。
## Decisions
1. **表命名**:`svc_plan`/`svc_plan_item`/`svc_order`(服务域)、`ltc_elder_svc`(老人域)。
2. **垫付切分**:C2 只做派单例外(waiting_period 允许派单),is_prepaid/结转 C3。
3. **项数校验为配置数据**:昆明规则表内置为常量(care_mode×care_level → 项数/周次/月时长),州市 `loc_config.item_count_rule` 为空则只提示。
4. **时间冲突检测**:同 assignee_id 且 `time_slot_start < 他人 time_slot_end AND 他人 time_slot_start < time_slot_end` 重叠 → 2001。
5. **快照**:plan_item/order.item_list 存 `svc_name_snapshot`/`svc_code_snapshot`。
6. **批量推荐只读**:权重常量可配置,返回推荐列表 + 理由,不自动派。
## 数据模型(DDL 概览)
通用字段 + UUID v7 + tenantCode + 软删。
- **svc_plan**:id、tenant_code、elder_id、plan_period_start/end(@db.Date)、care_level、care_mode、item_count、item_count_rule、extra_item_count、week_freq、month_hours、plan_status、confirm_elder、confirm_guardian、confirm_time、plan_basis(json)、change_from_plan_id、biz_line。索引 (tenant_code, elder_id)。
- **svc_plan_item**:id、plan_id、svc_id、svc_name_snapshot、svc_code_snapshot、freq_type、freq_value、duration_min、photo_tier、caution_note、is_medical、need_cert。索引 (plan_id)。
- **svc_order**:id、tenant_code、elder_id、plan_id、service_date(@db.Date)、time_slot_start/end(datetime)、assignee_id、assign_time、assign_mode、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。索引 (tenant_code, assignee_id, service_date)、(tenant_code, elder_id)。
- **ltc_elder_svc**:id、tenant_code、elder_id、svc_id、svc_name_snapshot、svc_code_snapshot、care_mode、is_active。索引 (tenant_code, elder_id)。
PrismaService:四表均为租户级(tenantCode 自动注入);svc_plan/svc_plan_item/svc_order/ltc_elder_svc 加入 SOFT_DELETE。
## 接口(`@Controller('plan')` / `@Controller('order')` / `@Controller('elder-svc')`)
plan:POST `/plan`、POST `/plan/change`、GET `/plan/:id`、POST `/plan/:id/confirm`、GET `/plan/by-elder/:elderId`。
order:POST `/order/generate`、POST `/order/assign`、POST `/order/:id/reassign`、GET `/order/batch-recommend`、GET `/order/today`、POST `/order/:id/cancel`、GET `/order/:id`。
elder-svc:GET `/elder-svc/:elderId`、PUT `/elder-svc/:elderId`。
权限码:plan.create/change/detail/confirm、order.generate/assign/reassign/cancel/detail/today、elder.svcSave(复用)。APIS 登记资源。
## Risks / Trade-offs
- [昆明项数规则可能随细则变化] → 规则为常量配置,改常量即可;州市不校验。
- [时间冲突只做单机构内] → 跨机构冲突 C2 不做(PRD 明确)。
- [快照冗余存储] → 必要(目录改名后历史计划/工单仍显示当时项目名)。
## Migration Plan
新增迁移建 4 张表(utf8mb4_general_ci,手改 collation)。回滚=删除迁移。