touyun-elderly-care/docs/superpowers/plans/2026-10-15-服务机构端-C5后台配置与文书补齐.md
liuyun f85b95e937 docs: 服务机构端 C5 后台配置与文书补齐实施计划
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-15 07:26:58 +08:00

140 lines
8.1 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.

# 服务机构端 C5 后台配置与文书补齐 实施计划
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** 补齐 admin 后台 7 个空菜单:服务机构设置 6 子项(机构信息/属地与目录/服务项目与配价/拍照分档配置/质控提醒配置/对接档位)+ 文书档案(一人一档导出)。
**Architecture:** 纯配置 + 前端 + 文书导出,无新表(svc_org + photo_tier、ltc_agency + 3 配置字段)。后端扩 agency/catalog + 新增 document 导出逻辑,前端 7 页。
**Tech Stack:** NestJS 12 + Prisma 6 + MySQL 8(utf8mb4_general_ci)、Vue 3 + Vite + Pinia + UnoCSS。
**Spec:** `openspec/changes/svc-org-c5-config/`;设计背景 `docs/superpowers/specs/2026-10-15-服务机构端-C5后台配置与文书补齐-design.md`。
## Global Constraints
- 机构=租户:业务表带 tenant_code、UUID v7、@map snake_case;utf8mb4_general_ci。
- 不动脚手架文件;前端不改 ty-* / components.d.ts / UnoCSS。
- 表命名:svc_org(已有)、ltc_agency(已有),只加字段。
- photo_tier 源在 svc_org,plan/order 快照溯源;放宽(must→free/optional)提示。
- 文书导出带水印(机构名+时间+操作人)+ 审计;措辞只用「日常留痕,随时可导出」。
- ⚠️ 迁移链损坏:migrate dev 不可用,用 migrate diff + 手工迁移目录 + deploy。
## Review Focus
1. **photo_tier 溯源**:plan 创建时 photo_tier 默认取 svc_org.photo_tier(不是前端硬编码);历史快照不改。
2. **放宽提示**:must→free/optional 批量改要返回提示,不静默。
3. **文书导出水印+审计**:每次导出必写操作日志 + 文件带机构名/时间/操作人。
4. **文书措辞纪律**:界面/导出不得出现「迎检/应对巡查/守住分值」。
5. **导出按老人/时间过滤**:不全表导出(防卡死)。
---
### Task 1: Prisma 字段 + 迁移
**Files:** `sources/ec-nest/prisma/schema.prisma`、`src/prisma/prisma.service.ts`(不改)
- [ ] **Step 1: svc_org + ltc_agency 加字段**
`SvcOrg` 加(模型内,字段后):
```prisma
photoTier String @default("free") @map("photo_tier") @db.VarChar(10)
```
`Agency` 加:
```prisma
qcThreshold Int @default(24) @map("qc_threshold")
dockingTier String @default("B") @map("docking_tier") @db.VarChar(10)
newNationalNotify Boolean @default(true) @map("new_national_notify")
```
- [ ] **Step 2: 迁移(utf8mb4_general_ci)**:`migrate diff --from-schema-datasource` + 手工目录 `20261015xxxxxx_c5_config/migration.sql`(unicode_ci→general_ci)+ `migrate deploy && prisma generate`。
- [ ] **Step 3: seed 默认 photo_tier 分档表**(可选,在 seed-catalog.ts 或迁移后):按 PRD——沐浴/转移/导管类/鼻饲喂食/压疮=must;擦身/如厕/失禁=optional;其余=free(默认 free 即可,must/optional 项 seed 时标注)。若 seed 未落,前端/后端按 svc_org.photoTier 默认 free,机构自行配置。
- [ ] **Step 4: Commit**
```bash
git -C sources/ec-nest add prisma/schema.prisma prisma/migrations
git -C sources/ec-nest commit -m "feat(c5): svc_org photo_tier + agency 机构配置字段"
```
---
### Task 2: 后端(photo-tier 批量 + agency 配置 + 文书导出)
**Files:** `src/catalog/{catalog.service,catalog.controller,dto}.ts`(photo-tier 批量)、`src/agency/{agency.service,dto}.ts`(配置扩展)、新建 `src/document/{document.module,document.controller,document.service,dto,document.service.spec}.ts`;注册 document module。
- [ ] **Step 1: 写失败测试**:photo-tier 批量更新(含放宽提示);agency 配置更新;document 导出(含水印字段 + 审计调用)。
- [ ] **Step 2: 跑测试确认失败**
- [ ] **Step 3: photo-tier 批量更新**
`catalog.service`:`updatePhotoTier(dto)`——dto `{ items: [{ id, photoTier }] }`;校验每个 id 落本机构 svc_org;`must→free/optional` 的项收集到 `warnings`(返回提示「已放宽 X 项,请确认」);逐条 `svcOrg.update({ photoTier })`。controller `@Post('org/photo-tier/batch')`。
- [ ] **Step 4: agency 配置扩展**
`agency.service.update` / `UpdateAgencyDto` 加 `qcThreshold`/`dockingTier`/`newNationalNotify`(可选)。`PATCH /agency` 已有。
- [ ] **Step 5: 文书导出 document 模块**
`document.service.export(elderId, startDate?, endDate?)`:
- `elder.findUnique` → 基本信息(name/gender/birthDate/idCardNo 掩码/phone/address/insurNo/careLevel/treatStatus)。
- `plan.findMany({ elderId })` → 计划(period/careMode/careLevel + plan_item 项目)。
- `record.findMany({ elderId, checkinTime 范围 })` → 服务记录(checkin/checkout/duration + record_item exec_result)。
- `recordAbnormal.findMany({ elderId })` → 异常(type/desc/handleStatus)。
- 组装一人一档(结构化对象或 Excel/CSV 字符串),加水印头(机构名+时间+操作人),`@AuditLog('document','export')`。
- controller `@Get('export')` 返回文件(`Content-Disposition` 下载)或 JSON(若实现为 JSON 结构化,前端组装导出)。**优先 Excel/CSV**:用轻量方案(`exceljs` 或手写 CSV),不引重型依赖。
- [ ] **Step 6: 注册 document module 到 app.module.ts;测试通过 + tsc + Commit**
```bash
git -C sources/ec-nest add src/catalog src/agency src/document src/app.module.ts package.json pnpm-lock.yaml
git -C sources/ec-nest commit -m "feat(c5): 拍照分档批量改 + 机构配置 + 文书导出"
```
---
### Task 3: 前端 7 页
**Files:** `src/api/catalog.ts`/`agency.ts`(扩展)+ 新建 `src/api/document.ts`;`src/pages/ltc/config/{info,loc,catalog,photo,qc,docking}/index.vue` + `src/pages/ltc/document/index.vue`(替换占位)。
- [ ] **Step 1: api 扩展**:catalog.ts 加 `updatePhotoTier`;agency.ts 类型加 3 配置字段;新建 document.ts(export 接口)。
- [ ] **Step 2: 机构信息页**(`defineOptions({name:'svc-config-info'})`):表单(名称/地址/法人/联系方式/参保地只读)+ 质控阈值/对接档位/新增项开关,`PATCH /agency`。
- [ ] **Step 3: 属地与目录页**(name 'svc-config-loc'):只读列表(L1 国家库/L2 属地库/L4 机构项目,复用 catalog api)+ 新增项提示开关。
- [ ] **Step 4: 服务项目与配价页**(name 'svc-config-catalog'):L4 项目列表 + 勾选/配价(复用 C0 svcOrg api)。
- [ ] **Step 5: 拍照分档配置页**(name 'svc-config-photo'):L4 项目列表 → 多选/批量改 photo_tier(must/free/optional),放宽时前端提示。
- [ ] **Step 6: 质控提醒配置页**(name 'svc-config-qc'):阈值编辑(qc_threshold)。
- [ ] **Step 7: 对接档位页**(name 'svc-config-docking'):档位显示 + A/B 切换,C 显示「待接口发布」。
- [ ] **Step 8: 文书档案页**(name 'document'):老人列表 → 详情(一人一档:基本信息+计划+记录+异常)→ 按老人/时间导出按钮(调 document export 下载)。措辞只用「日常留痕,随时可导出」。
- [ ] **Step 9: type-check + Commit**
```bash
git -C sources/ec-admin add src/api src/pages/ltc/config src/pages/ltc/document
git -C sources/ec-admin commit -m "feat(c5): 后台 7 个配置/文书页"
```
---
### Task 4: 端到端验证
- [ ] **Step 1:** 起后端 + 登录,冒烟:7 个页面可访问;photo_tier 批量改生效(放宽提示);agency 配置更新;文书导出返回一人一档(水印 + 审计落库)。
- [ ] **Step 2:** plan 创建时 photo_tier 默认取 svc_org.photo_tier(溯源验证)。
- [ ] **Step 3:** 停后端清理。
---
## Self-Review Notes
- Spec 覆盖:data-model 2 字段组→T1;api-contract→T2;backend/config→T2;frontend/ad/config→T3。
- Review Focus 5 条均有测试/校验(T2/T3)。
- 类型一致:`SvcOrg.photoTier`/`Agency.qcThreshold/dockingTier/newNationalNotify` 在 T1/T2/T3 一致。
- 文书导出措辞纪律(Review Focus #4):界面/导出文案检查。