refactor: 默认 skills 装到 .agents,并清空 example 旧演示实现
对齐安装目录与 opencode 扫描路径;按 confirmed plan 清掉与 iteration1 不对齐的示例业务代码与 as-built 文档,只留空壳与需求输入。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -2,15 +2,17 @@
|
||||
|
||||
描述系统 **当前真实状态** 的文档,随代码同步更新。
|
||||
|
||||
> 当前为 **工程空壳 as-built**。目标需求:`docs/features/iteration1/`。
|
||||
|
||||
| 位置 | 内容 |
|
||||
|---|---|
|
||||
| 本目录根 | 可从代码校准的技术事实:`api.yaml`、`db-schema.md`、`domain-model.md` |
|
||||
| 本目录根 | `api.yaml`、`db-schema.md`、`domain-model.md` |
|
||||
| [`business/`](./business/) | 业务事实(流程等) |
|
||||
| [`tech-topic/`](./tech-topic/) | 技术专题 / ADR / 实现说明 |
|
||||
|
||||
## 现有文档
|
||||
|
||||
- [api.yaml](./api.yaml) — API 接口定义
|
||||
- [db-schema.md](./db-schema.md) — 数据库规格
|
||||
- [domain-model.md](./domain-model.md) — 领域模型
|
||||
- [business/booking-flow.md](./business/booking-flow.md) — 预约业务流程
|
||||
- [api.yaml](./api.yaml) — API(仅 health)
|
||||
- [db-schema.md](./db-schema.md) — 数据库(无业务表)
|
||||
- [domain-model.md](./domain-model.md) — 领域模型(无业务聚合)
|
||||
- [business/](./business/) — 业务事实目录(待补充)
|
||||
|
||||
@@ -1,406 +1,22 @@
|
||||
openapi: "3.0.3"
|
||||
openapi: 3.0.0
|
||||
info:
|
||||
title: 咨询预约平台 API
|
||||
version: 0.1.0
|
||||
|
||||
title: Consultation Platform API (skeleton)
|
||||
version: 0.0.0
|
||||
description: |
|
||||
业务 API 尚未实现。目标需求见 docs/features/iteration1/。
|
||||
当前仅保留健康探针。
|
||||
paths:
|
||||
/api/v1/auth/register:
|
||||
post:
|
||||
tags: [Auth]
|
||||
summary: 用户注册
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
required: [email, password, name]
|
||||
properties:
|
||||
email: { type: string, format: email }
|
||||
password: { type: string, minLength: 8 }
|
||||
name: { type: string }
|
||||
phone: { type: string }
|
||||
responses:
|
||||
"200": { description: 注册成功, content: { application/json: { schema: { $ref: "#/components/schemas/AuthResponse" } } } }
|
||||
"400": { $ref: "#/components/responses/Error400" }
|
||||
|
||||
/api/v1/auth/login:
|
||||
post:
|
||||
tags: [Auth]
|
||||
summary: 用户登录
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
required: [email, password]
|
||||
properties:
|
||||
email: { type: string, format: email }
|
||||
password: { type: string }
|
||||
responses:
|
||||
"200": { description: 登录成功, content: { application/json: { schema: { $ref: "#/components/schemas/AuthResponse" } } } }
|
||||
"400": { $ref: "#/components/responses/Error400" }
|
||||
|
||||
/api/v1/home/info:
|
||||
/api/v1/health:
|
||||
get:
|
||||
tags: [Home]
|
||||
summary: 首页信息
|
||||
summary: 存活探针
|
||||
responses:
|
||||
"200": { description: 首页内容, content: { application/json: { schema: { type: object, properties: { title: { type: string }, description: { type: string } } } } } }
|
||||
|
||||
/api/v1/users/me:
|
||||
get:
|
||||
tags: [User]
|
||||
summary: 获取个人资料
|
||||
security: [{ BearerAuth: [] }]
|
||||
responses:
|
||||
"200": { description: 用户信息, content: { application/json: { schema: { $ref: "#/components/schemas/UserResponse" } } } }
|
||||
"401": { $ref: "#/components/responses/Error401" }
|
||||
put:
|
||||
tags: [User]
|
||||
summary: 更新个人资料
|
||||
security: [{ BearerAuth: [] }]
|
||||
requestBody:
|
||||
content: { application/json: { schema: { type: object, properties: { name: { type: string }, phone: { type: string } } } } }
|
||||
responses:
|
||||
"200": { description: 更新后的用户信息, content: { application/json: { schema: { $ref: "#/components/schemas/UserResponse" } } } }
|
||||
|
||||
/api/v1/users/me/password:
|
||||
put:
|
||||
tags: [User]
|
||||
summary: 修改密码
|
||||
security: [{ BearerAuth: [] }]
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
required: [oldPassword, newPassword]
|
||||
properties:
|
||||
oldPassword: { type: string }
|
||||
newPassword: { type: string, minLength: 8 }
|
||||
responses:
|
||||
"200": { description: 密码修改成功 }
|
||||
"400": { $ref: "#/components/responses/Error400" }
|
||||
|
||||
/api/v1/consultants:
|
||||
get:
|
||||
tags: [Consultant]
|
||||
summary: 获取咨询师列表
|
||||
responses:
|
||||
"200": { description: 咨询师列表, content: { application/json: { schema: { type: array, items: { $ref: "#/components/schemas/ConsultantResponse" } } } } }
|
||||
|
||||
/api/v1/consultants/{id}/slots:
|
||||
get:
|
||||
tags: [Consultant]
|
||||
summary: 获取咨询师可预约时间段
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
required: true
|
||||
schema: { type: string }
|
||||
- name: date
|
||||
in: query
|
||||
required: true
|
||||
schema: { type: string, format: date }
|
||||
responses:
|
||||
"200": { description: 可用时间段列表, content: { application/json: { schema: { type: array, items: { type: object, properties: { startTime: { type: string }, endTime: { type: string } } } } } } }
|
||||
|
||||
/api/v1/appointments:
|
||||
get:
|
||||
tags: [Appointment]
|
||||
summary: 获取我的预约列表
|
||||
security: [{ BearerAuth: [] }]
|
||||
responses:
|
||||
"200": { description: 预约列表, content: { application/json: { schema: { type: array, items: { $ref: "#/components/schemas/AppointmentResponse" } } } } }
|
||||
post:
|
||||
tags: [Appointment]
|
||||
summary: 创建预约
|
||||
security: [{ BearerAuth: [] }]
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
required: [consultantId, date, startTime, endTime]
|
||||
properties:
|
||||
consultantId: { type: string }
|
||||
branchId: { type: string }
|
||||
date: { type: string, format: date }
|
||||
startTime: { type: string }
|
||||
endTime: { type: string }
|
||||
note: { type: string }
|
||||
responses:
|
||||
"200": { description: 创建成功, content: { application/json: { schema: { $ref: "#/components/schemas/AppointmentResponse" } } } }
|
||||
"409": { $ref: "#/components/responses/Error409" }
|
||||
|
||||
/api/v1/appointments/{id}:
|
||||
get:
|
||||
tags: [Appointment]
|
||||
summary: 获取预约详情
|
||||
security: [{ BearerAuth: [] }]
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
required: true
|
||||
schema: { type: string }
|
||||
responses:
|
||||
"200": { description: 预约详情, content: { application/json: { schema: { $ref: "#/components/schemas/AppointmentResponse" } } } }
|
||||
|
||||
/api/v1/appointments/{id}/cancel:
|
||||
put:
|
||||
tags: [Appointment]
|
||||
summary: 取消预约
|
||||
security: [{ BearerAuth: [] }]
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
required: true
|
||||
schema: { type: string }
|
||||
requestBody:
|
||||
content: { application/json: { schema: { type: object, properties: { reason: { type: string } } } } }
|
||||
responses:
|
||||
"200": { description: 取消成功 }
|
||||
"409": { $ref: "#/components/responses/Error409" }
|
||||
|
||||
/admin/dashboard:
|
||||
get:
|
||||
tags: [Admin]
|
||||
summary: 管理仪表盘
|
||||
security: [{ BearerAuth: [] }]
|
||||
responses:
|
||||
"200": { description: 统计数据, content: { application/json: { schema: { type: object, properties: { totalUsers: { type: integer }, totalConsultants: { type: integer }, totalAppointments: { type: integer }, pendingAppointments: { type: integer }, totalBranches: { type: integer } } } } } }
|
||||
|
||||
/admin/users:
|
||||
get:
|
||||
tags: [Admin]
|
||||
summary: 用户列表(管理员)
|
||||
security: [{ BearerAuth: [] }]
|
||||
responses:
|
||||
"200": { description: 用户列表, content: { application/json: { schema: { type: array, items: { $ref: "#/components/schemas/UserResponse" } } } } }
|
||||
|
||||
/admin/users/{id}/toggle-status:
|
||||
put:
|
||||
tags: [Admin]
|
||||
summary: 启用/禁用用户
|
||||
security: [{ BearerAuth: [] }]
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
required: true
|
||||
schema: { type: string }
|
||||
responses:
|
||||
"200": { description: 操作成功 }
|
||||
|
||||
/admin/consultants:
|
||||
get:
|
||||
tags: [Admin]
|
||||
summary: 咨询师列表(管理员)
|
||||
security: [{ BearerAuth: [] }]
|
||||
responses:
|
||||
"200": { description: 咨询师列表, content: { application/json: { schema: { type: array, items: { $ref: "#/components/schemas/ConsultantResponse" } } } } }
|
||||
|
||||
/admin/appointments:
|
||||
get:
|
||||
tags: [Admin]
|
||||
summary: 预约列表(管理员,全量)
|
||||
security: [{ BearerAuth: [] }]
|
||||
responses:
|
||||
"200": { description: 预约列表, content: { application/json: { schema: { type: array, items: { $ref: "#/components/schemas/AppointmentResponse" } } } } }
|
||||
|
||||
/admin/branches:
|
||||
get:
|
||||
tags: [Admin]
|
||||
summary: 网点列表
|
||||
security: [{ BearerAuth: [] }]
|
||||
responses:
|
||||
"200": { description: 网点列表, content: { application/json: { schema: { type: array, items: { $ref: "#/components/schemas/BranchResponse" } } } } }
|
||||
post:
|
||||
tags: [Admin]
|
||||
summary: 创建网点
|
||||
security: [{ BearerAuth: [] }]
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
required: [name]
|
||||
properties:
|
||||
name: { type: string }
|
||||
address: { type: string }
|
||||
phone: { type: string }
|
||||
responses:
|
||||
"200": { description: 创建成功, content: { application/json: { schema: { $ref: "#/components/schemas/BranchResponse" } } } }
|
||||
|
||||
/admin/branches/{id}:
|
||||
put:
|
||||
tags: [Admin]
|
||||
summary: 更新网点
|
||||
security: [{ BearerAuth: [] }]
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
required: true
|
||||
schema: { type: string }
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
name: { type: string }
|
||||
address: { type: string }
|
||||
phone: { type: string }
|
||||
responses:
|
||||
"200": { description: 更新成功 }
|
||||
delete:
|
||||
tags: [Admin]
|
||||
summary: 删除网点
|
||||
security: [{ BearerAuth: [] }]
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
required: true
|
||||
schema: { type: string }
|
||||
responses:
|
||||
"200": { description: 删除成功 }
|
||||
|
||||
/api/v1/data-dictionaries:
|
||||
get:
|
||||
tags: [DataDictionary]
|
||||
summary: 获取所有数据字典类型列表
|
||||
responses:
|
||||
"200": { description: 字典类型列表, content: { application/json: { schema: { type: array, items: { $ref: "#/components/schemas/DataDictionaryResponse" } } } } }
|
||||
|
||||
/api/v1/data-dictionaries/{type}:
|
||||
get:
|
||||
tags: [DataDictionary]
|
||||
summary: 获取指定字典类型的条目列表
|
||||
parameters:
|
||||
- name: type
|
||||
in: path
|
||||
required: true
|
||||
schema: { type: string }
|
||||
responses:
|
||||
"200": { description: 字典条目列表, content: { application/json: { schema: { type: array, items: { type: object, properties: { code: { type: string }, description: { type: string } } } } } } }
|
||||
|
||||
/api/v1/business-rules:
|
||||
get:
|
||||
tags: [BusinessRule]
|
||||
summary: 获取所有业务规则
|
||||
responses:
|
||||
"200": { description: 业务规则列表, content: { application/json: { schema: { type: array, items: { $ref: "#/components/schemas/BusinessRuleResponse" } } } } }
|
||||
|
||||
components:
|
||||
securitySchemes:
|
||||
BearerAuth:
|
||||
type: http
|
||||
scheme: bearer
|
||||
bearerFormat: JWT
|
||||
|
||||
schemas:
|
||||
UserResponse:
|
||||
type: object
|
||||
properties:
|
||||
id: { type: string }
|
||||
email: { type: string }
|
||||
name: { type: string }
|
||||
phone: { type: string }
|
||||
role: { type: string, enum: [ROLE_USER, ROLE_ADMIN] }
|
||||
status: { type: string, enum: [ACTIVE, DISABLED] }
|
||||
|
||||
AuthResponse:
|
||||
type: object
|
||||
properties:
|
||||
token: { type: string }
|
||||
user: { $ref: "#/components/schemas/UserResponse" }
|
||||
|
||||
ConsultantResponse:
|
||||
type: object
|
||||
properties:
|
||||
id: { type: string }
|
||||
name: { type: string }
|
||||
title: { type: string }
|
||||
bio: { type: string }
|
||||
specialties: { type: string }
|
||||
avatar: { type: string }
|
||||
branchId: { type: string }
|
||||
status: { type: string, enum: [ACTIVE, DISABLED] }
|
||||
sortOrder: { type: integer }
|
||||
|
||||
AppointmentResponse:
|
||||
type: object
|
||||
properties:
|
||||
id: { type: string }
|
||||
userId: { type: string }
|
||||
consultantId: { type: string }
|
||||
branchId: { type: string }
|
||||
appointmentDate: { type: string, format: date }
|
||||
startTime: { type: string }
|
||||
endTime: { type: string }
|
||||
durationMinutes: { type: integer }
|
||||
status: { type: string, enum: [PENDING, CONFIRMED, COMPLETED, CANCELLED] }
|
||||
note: { type: string }
|
||||
cancelReason: { type: string }
|
||||
|
||||
BranchResponse:
|
||||
type: object
|
||||
properties:
|
||||
id: { type: string }
|
||||
name: { type: string }
|
||||
address: { type: string }
|
||||
phone: { type: string }
|
||||
status: { type: string, enum: [ACTIVE, DISABLED] }
|
||||
|
||||
DataDictionaryResponse:
|
||||
type: object
|
||||
properties:
|
||||
typeName: { type: string }
|
||||
description: { type: string }
|
||||
items:
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
code: { type: string }
|
||||
description: { type: string }
|
||||
|
||||
BusinessRuleResponse:
|
||||
type: object
|
||||
properties:
|
||||
ruleName: { type: string }
|
||||
description: { type: string }
|
||||
config: { type: object }
|
||||
|
||||
ErrorResponse:
|
||||
type: object
|
||||
properties:
|
||||
errorCode: { type: string }
|
||||
errorMessage: { type: string }
|
||||
data: { type: object, nullable: true }
|
||||
|
||||
responses:
|
||||
Error400:
|
||||
description: 请求参数错误
|
||||
content:
|
||||
application/json:
|
||||
schema: { $ref: "#/components/schemas/ErrorResponse" }
|
||||
Error401:
|
||||
description: 未授权
|
||||
content:
|
||||
application/json:
|
||||
schema: { $ref: "#/components/schemas/ErrorResponse" }
|
||||
Error404:
|
||||
description: 资源不存在
|
||||
content:
|
||||
application/json:
|
||||
schema: { $ref: "#/components/schemas/ErrorResponse" }
|
||||
Error409:
|
||||
description: 业务冲突
|
||||
content:
|
||||
application/json:
|
||||
schema: { $ref: "#/components/schemas/ErrorResponse" }
|
||||
'200':
|
||||
description: OK
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
example: UP
|
||||
|
||||
@@ -2,14 +2,10 @@
|
||||
|
||||
存放与业务语义直接相关的事实文档:流程、业务侧说明等。
|
||||
|
||||
与 `../` 根目录的技术事实(API / 库表 / 领域模型)以及 `../tech-topic/` 技术专题区分开:
|
||||
> 旧示例业务文档已清除。实现 iteration1 后在此补充(或从 spec 同步关键流程)。
|
||||
|
||||
| 目录 | 内容 |
|
||||
|---|---|
|
||||
| `docs/facts/` | 可从代码校准的技术事实 |
|
||||
| `docs/facts/tech-topic/` | 技术专题 / ADR / 实现说明 |
|
||||
| `docs/facts/business/` | 业务事实(本目录) |
|
||||
|
||||
## 现有文档
|
||||
|
||||
- [booking-flow.md](./booking-flow.md) — 预约业务流程
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
# 预约业务流程事实
|
||||
|
||||
## 1. 角色定义
|
||||
|
||||
| 角色 | 说明 | 系统表示 |
|
||||
|------|------|----------|
|
||||
| 普通用户(访客) | 未登录,可浏览首页与咨询师列表 | 无认证 / ROLE_USER |
|
||||
| 注册用户 | 已登录,可预约、查看/取消自己的预约、编辑资料 | ROLE_USER |
|
||||
| 管理员 | 已登录,可查看仪表盘统计、管理用户/咨询师/预约/网点 | ROLE_ADMIN |
|
||||
|
||||
## 2. 预约流程(4 步)
|
||||
|
||||
```
|
||||
Step 1: 选择咨询师
|
||||
- 系统展示所有 ACTIVE 状态的咨询师,按 sortOrder 升序
|
||||
- 用户点击选中一个
|
||||
|
||||
Step 2: 选择日期
|
||||
- 系统展示未来 7 天(含今日)的日期按钮
|
||||
- 日期连续,无间隔
|
||||
- 用户点击选中一个
|
||||
|
||||
Step 3: 选择时间
|
||||
- 系统根据选中的咨询师 + 日期,查询可用时段
|
||||
- 可用时段 = 09:00-18:00 内,每小时一个 slot(09:00, 10:00, ..., 17:00)
|
||||
- 排除已存在非取消状态的预约
|
||||
- 用户点击选中一个
|
||||
|
||||
Step 4: 确认预约
|
||||
- 用户可填写备注(选填)
|
||||
- 提交后系统创建预约,状态为 PENDING(待确认)
|
||||
- 系统检查同一咨询师、同一日期、同一时段是否已有非取消预约 → 冲突则拒绝(409)
|
||||
```
|
||||
|
||||
## 3. 预约状态机
|
||||
|
||||
```
|
||||
PENDING ──► CONFIRMED ──► COMPLETED
|
||||
│ │
|
||||
└──────┬───────┘
|
||||
▼
|
||||
CANCELLED
|
||||
```
|
||||
|
||||
| 状态 | 含义 | 可操作 |
|
||||
|------|------|--------|
|
||||
| PENDING | 待确认(用户已提交,管理员未确认) | 取消 |
|
||||
| CONFIRMED | 已确认(管理员已确认) | 取消、完成 |
|
||||
| COMPLETED | 已完成(终态) | 无 |
|
||||
| CANCELLED | 已取消(终态) | 无 |
|
||||
|
||||
注:从 PENDING 和 CONFIRMED 可取消,取消时需要填写原因。
|
||||
|
||||
## 4. 业务规则
|
||||
|
||||
### 预约相关
|
||||
|
||||
| 规则 | 描述 | 实施方式 |
|
||||
|------|------|----------|
|
||||
| 冲突检测 | 同一咨询师同一时段不可重复预约 | `uk_appointment_slot` 唯一索引 + `AppointmentConflictService` |
|
||||
| 时段间隔 | 预约时段间隔为 60 分钟 | 前端 time slot 按 1h 步进,后端 slot.intervalMinutes = 60 |
|
||||
| 可用时段 | 可预约时段为 09:00-18:00 | 前端展示 09:00-17:00,后端 slot.available.start/end |
|
||||
| 取消窗口 | PENDING 和 CONFIRMED 状态可取消 | `Appointment.canCancel()` 守卫方法 |
|
||||
|
||||
### 认证相关
|
||||
|
||||
| 规则 | 描述 | 实施方式 |
|
||||
|------|------|----------|
|
||||
| 密码最小长度 | 密码最少 8 位 | 前端 + 后端校验 |
|
||||
| JWT 有效期 | JWT 有效期 24 小时 | `jwt.expiration=86400000` |
|
||||
| 密码算法 | 密码使用 BCrypt 加密 | `PasswordService` → `BCryptPasswordEncoder` |
|
||||
|
||||
## 5. 前台 vs 后台功能划分
|
||||
|
||||
### 前台(/user/*,需 ROLE_USER)
|
||||
|
||||
| 页面 | 功能 |
|
||||
|------|------|
|
||||
| 仪表盘 | 展示本人预约统计:总预约数、待确认数、已完成数 |
|
||||
| 预约管理 | 列出本人预约,可取消 PENDING/CONFIRMED 状态的预约 |
|
||||
| 预约咨询 | 4 步预约流程 |
|
||||
| 个人中心 | 编辑姓名、手机号;修改密码 |
|
||||
|
||||
### 后台(/admin/*,需 ROLE_ADMIN)
|
||||
|
||||
| 页面 | 功能 |
|
||||
|------|------|
|
||||
| 仪表盘 | 全局统计:用户数、咨询师数、总预约数、待确认数、网点数 |
|
||||
| 用户管理 | 列出所有用户,可启用/禁用用户 |
|
||||
| 咨询师管理 | 列出所有咨询师 |
|
||||
| 预约管理 | 列出所有预约 |
|
||||
| 网点管理 | CRUD 网点(新增、编辑、删除) |
|
||||
|
||||
## 6. 种子数据
|
||||
|
||||
| 类型 | 数据 |
|
||||
|------|------|
|
||||
| 管理员账号 | admin@test.com / password |
|
||||
| 咨询师 | 张医生(资深心理咨询师)、李律师(法律顾问)、王教练(职业规划师) |
|
||||
| 网点 | 朝阳咨询中心、海淀咨询中心、浦东咨询中心 |
|
||||
@@ -1,77 +1,9 @@
|
||||
# 数据库设计
|
||||
# 数据库规格
|
||||
|
||||
> 所有表使用 InnoDB 引擎,字符集 utf8mb4,排序 utf8mb4_bin。
|
||||
> 当前为工程空壳:**无业务表**。
|
||||
> 目标需求:`docs/features/iteration1/`。实现各 feature 时通过 Flyway 新增表,并同步本文档。
|
||||
|
||||
## 公共字段
|
||||
## 迁移
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| created_by | VARCHAR(64) | 创建者 ID |
|
||||
| created_time | DATETIME | 创建时间,默认 CURRENT_TIMESTAMP |
|
||||
| updated_by | VARCHAR(64) | 最后修改者 ID |
|
||||
| updated_time | DATETIME | 最后修改时间,默认 CURRENT_TIMESTAMP,ON UPDATE 自动更新 |
|
||||
|
||||
## user — 用户表
|
||||
|
||||
| 字段 | 类型 | 约束 | 说明 |
|
||||
|------|------|------|------|
|
||||
| id | VARCHAR(64) | PK | UUID 主键 |
|
||||
| email | VARCHAR(100) | UNIQUE, NOT NULL | 邮箱 |
|
||||
| password | VARCHAR(255) | NOT NULL | BCrypt 加密密码 |
|
||||
| name | VARCHAR(50) | NOT NULL | 姓名 |
|
||||
| phone | VARCHAR(20) | | 手机号 |
|
||||
| role | VARCHAR(20) | NOT NULL, DEFAULT 'ROLE_USER' | 角色 |
|
||||
| status | VARCHAR(20) | NOT NULL, DEFAULT 'ACTIVE' | 状态 |
|
||||
|
||||
**索引**:`uk_user_email` UNIQUE on (email)
|
||||
|
||||
## consultant — 咨询师表
|
||||
|
||||
| 字段 | 类型 | 约束 | 说明 |
|
||||
|------|------|------|------|
|
||||
| id | VARCHAR(64) | PK | UUID 主键 |
|
||||
| name | VARCHAR(50) | NOT NULL | 姓名 |
|
||||
| title | VARCHAR(100) | NOT NULL | 职称 |
|
||||
| bio | TEXT | | 简介 |
|
||||
| specialties | VARCHAR(255) | | 专长领域 |
|
||||
| avatar | VARCHAR(255) | | 头像 URL |
|
||||
| branch_id | VARCHAR(64) | FK → branch(id) | 所属网点 |
|
||||
| status | VARCHAR(20) | NOT NULL, DEFAULT 'ACTIVE' | 状态 |
|
||||
| sort_order | INT | NOT NULL, DEFAULT 0 | 排序权重 |
|
||||
|
||||
## appointment — 预约表
|
||||
|
||||
| 字段 | 类型 | 约束 | 说明 |
|
||||
|------|------|------|------|
|
||||
| id | VARCHAR(64) | PK | UUID 主键 |
|
||||
| user_id | VARCHAR(64) | FK → user(id) | 预约用户 |
|
||||
| consultant_id | VARCHAR(64) | FK → consultant(id) | 咨询师 |
|
||||
| branch_id | VARCHAR(64) | FK → branch(id) | 所属网点 |
|
||||
| appointment_date | DATE | NOT NULL | 预约日期 |
|
||||
| start_time | VARCHAR(5) | NOT NULL | 开始时间 (HH:mm) |
|
||||
| end_time | VARCHAR(5) | NOT NULL | 结束时间 (HH:mm) |
|
||||
| duration_minutes | INT | NOT NULL | 时长(分钟) |
|
||||
| status | VARCHAR(20) | NOT NULL, DEFAULT 'PENDING' | 状态 |
|
||||
| note | VARCHAR(500) | | 备注 |
|
||||
| cancel_reason | VARCHAR(200) | | 取消原因 |
|
||||
|
||||
**索引**:
|
||||
- `uk_appointment_slot` UNIQUE on (consultant_id, appointment_date, start_time)
|
||||
- `idx_user_id` on (user_id)
|
||||
- `idx_consultant_date` on (consultant_id, appointment_date)
|
||||
|
||||
## branch — 网点表
|
||||
|
||||
| 字段 | 类型 | 约束 | 说明 |
|
||||
|------|------|------|------|
|
||||
| id | VARCHAR(64) | PK | UUID 主键 |
|
||||
| name | VARCHAR(100) | NOT NULL | 网点名称 |
|
||||
| address | VARCHAR(255) | | 地址 |
|
||||
| phone | VARCHAR(20) | | 电话 |
|
||||
| status | VARCHAR(20) | NOT NULL, DEFAULT 'ACTIVE' | 状态 |
|
||||
|
||||
## 表关系图
|
||||
|
||||
```
|
||||
user (1) ──→ (N) appointment (N) ←── (1) consultant (N) ←── (1) branch
|
||||
```
|
||||
- 目录:`apps/backend/src/main/resources/db/migration/`
|
||||
- 现状:无 migration 脚本(仅占位)
|
||||
|
||||
@@ -1,107 +1,13 @@
|
||||
# 领域模型设计
|
||||
# 领域模型
|
||||
|
||||
> 本文档描述咨询预约平台的领域模型事实(as-built)。
|
||||
> 当前为工程空壳:**无业务聚合**。
|
||||
> 目标需求:`docs/features/iteration1/`(ACC~PLT)。按 feature plan 落地后回写本文档。
|
||||
|
||||
## 聚合根 (Aggregate Root)
|
||||
## 平台骨架(非业务聚合)
|
||||
|
||||
### User
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| id | String | UUID |
|
||||
| email | String | 邮箱(登录名),唯一 |
|
||||
| password | String | BCrypt 编码 |
|
||||
| name | String | 姓名 |
|
||||
| phone | String | 手机号 |
|
||||
| role | UserRole | ROLE_USER / ROLE_ADMIN |
|
||||
| status | UserStatus | ACTIVE / DISABLED |
|
||||
|
||||
**方法**:
|
||||
- `isAdmin()` — role == ROLE_ADMIN
|
||||
- `isActive()` — status == ACTIVE
|
||||
|
||||
### Consultant
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| id | String | UUID |
|
||||
| name | String | 姓名 |
|
||||
| title | String | 职称 |
|
||||
| bio | String | 简介 |
|
||||
| specialties | String | 专长(逗号分隔) |
|
||||
| avatar | String | 头像 URL |
|
||||
| branchId | String | 所属网点 ID |
|
||||
| status | ConsultantStatus | ACTIVE / DISABLED |
|
||||
| sortOrder | int | 排序权重 |
|
||||
|
||||
**内联枚举**:`ConsultantStatus { ACTIVE, DISABLED }`
|
||||
|
||||
**方法**:
|
||||
- `isAvailable()` — status == ACTIVE
|
||||
|
||||
### Appointment
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| id | String | UUID |
|
||||
| userId | String | 预约用户 ID |
|
||||
| consultantId | String | 咨询师 ID |
|
||||
| branchId | String | 网点 ID(可选) |
|
||||
| appointmentDate | LocalDate | 预约日期 |
|
||||
| startTime | String | 开始时间 HH:mm |
|
||||
| endTime | String | 结束时间 HH:mm |
|
||||
| durationMinutes | int | 时长 |
|
||||
| status | AppointmentStatus | PENDING / CONFIRMED / COMPLETED / CANCELLED |
|
||||
| note | String | 用户备注 |
|
||||
| cancelReason | String | 取消原因 |
|
||||
|
||||
**方法**:
|
||||
- `isOwnedBy(userId)` — 判断是否属于该用户
|
||||
- `canCancel()` — status 不是 COMPLETED 也不是 CANCELLED
|
||||
|
||||
### Branch
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| id | String | UUID |
|
||||
| name | String | 网点名称 |
|
||||
| address | String | 地址 |
|
||||
| phone | String | 电话 |
|
||||
| status | BranchStatus | ACTIVE / DISABLED |
|
||||
|
||||
**内联枚举**:`BranchStatus { ACTIVE, DISABLED }`
|
||||
|
||||
## 值对象 (Value Object)
|
||||
|
||||
| 类 | 字段 | 说明 |
|
||||
|----|------|------|
|
||||
| UserRole | ROLE_USER, ROLE_ADMIN | 用户角色枚举 |
|
||||
| UserStatus | ACTIVE, DISABLED | 用户状态枚举 |
|
||||
| AppointmentStatus | PENDING, CONFIRMED, COMPLETED, CANCELLED | 预约状态枚举 |
|
||||
| TimeSlot | date, startTime, endTime | 时间段 VO,用于冲突检测 |
|
||||
|
||||
## 领域服务 (Domain Service)
|
||||
|
||||
| 服务 | 方法 | 说明 |
|
||||
|------|------|------|
|
||||
| PasswordService | encode(raw), matches(raw, encoded) | 密码编码/校验接口(infrastructure 实现 BCrypt) |
|
||||
| AppointmentConflictService | validateNoConflict(existing, requested) | 校验同一咨询师同一时段无冲突预约 |
|
||||
|
||||
## 仓储接口 (Repository)
|
||||
|
||||
| 接口 | 核心方法 | 说明 |
|
||||
|------|----------|------|
|
||||
| UserRepository | findById, findByEmail, findAll, save, update, existsByEmail | 用户持久化 |
|
||||
| ConsultantRepository | findById, findAllActive, findAll, save, update, deleteById, count | 咨询师持久化 |
|
||||
| AppointmentRepository | findById, findByUserId, findByConsultantIdAndDate, findAll, save, update, count, countByStatus, countByUserId | 预约持久化 |
|
||||
| BranchRepository | findById, findAll, save, update, deleteById, count | 网点持久化 |
|
||||
|
||||
## 聚合关系
|
||||
|
||||
```
|
||||
User (1) ──→ (N) Appointment (N) ←── (1) Consultant (N) ←── (1) Branch
|
||||
```
|
||||
|
||||
- User 创建 Appointment,Appointment 关联一个 User 和一个 Consultant
|
||||
- Consultant 属于一个 Branch
|
||||
- Branch 独立创建/停用,Consultant 依赖 Branch 存在
|
||||
| 组件 | 说明 |
|
||||
|------|------|
|
||||
| JWT / UserContext | 无状态鉴权骨架,待 ACC 接入登录签发 |
|
||||
| IBusinessRule / BusinessRuleConfig | 业务规则框架空注册 |
|
||||
| DataDictionary* | 数据字典框架类型,暂无注册枚举 |
|
||||
| PasswordService | 密码编码接口(BCrypt 实现) |
|
||||
|
||||
@@ -1,44 +1,6 @@
|
||||
# 业务规则清单(事实方案)
|
||||
# 业务规则
|
||||
|
||||
> 所有业务规则通过 `IBusinessRule` 接口定义,可通过 `GET /api/v1/business-rules` 动态查询。
|
||||
> 规则配置存储在 `resources/business-rules/*.yml` 中。
|
||||
> 空壳:示例规则已清除。框架类型保留(`IBusinessRule` / `BusinessRuleConfig` / `BusinessRuleProvider`)。
|
||||
> 实现 iteration1 时按 `docs/standards/business-rule.md` 注册规则并回写本文档。
|
||||
|
||||
## 认证规则
|
||||
|
||||
| 规则名 | 描述 | 当前值 | 配置路径 |
|
||||
|--------|------|--------|----------|
|
||||
| auth.password.minLength | 密码最小长度 | 8 | `auth.yml` → password.minLength |
|
||||
| auth.token.expirationMs | JWT Token 有效期(毫秒) | 86400000 (24h) | `auth.yml` → token.expirationMs |
|
||||
| auth.password.algorithm | 密码加密算法 | BCrypt | `auth.yml` → password.algorithm |
|
||||
|
||||
> 认证规则的取值来自 `business-rules/auth.yml`,通过 `GET /api/v1/business-rules`
|
||||
> 的 `config.auth` 子树对外暴露(结构见 `BusinessRuleConfig.AuthConfig`)。
|
||||
> 运行时真正生效的 JWT 有效期取 `application.yml` → `jwt.expiration`(`JwtTokenProvider` 读取),
|
||||
> 密码加密算法为 `PasswordServiceImpl` 里的 `BCryptPasswordEncoder`;
|
||||
> 这两处当前与 YAML 取值一致,改动时需同步。
|
||||
|
||||
## 预约规则
|
||||
|
||||
| 规则名 | 描述 | 当前值 | 代码位置 |
|
||||
|--------|------|--------|----------|
|
||||
| appointment.conflict.detection | 同一咨询师同一时段不可重复预约 | 唯一索引 + 代码校验 | AppointmentConflictService + uk_appointment_slot |
|
||||
| appointment.slot.minMinutes | 最短预约时长 | 30 (implicit) | TimeSlot 业务约定 |
|
||||
| appointment.slot.maxMinutes | 最长预约时长 | 120 (implicit) | TimeSlot 业务约定 |
|
||||
| appointment.available.start | 每日可预约开始时间 | 09:00 | ConsultantService.getAvailableSlots |
|
||||
| appointment.available.end | 每日可预约结束时间 | 18:00 | ConsultantService.getAvailableSlots |
|
||||
| appointment.slot.intervalMinutes | 时间段间隔 | 60 | ConsultantService.getAvailableSlots |
|
||||
|
||||
## 管理规则
|
||||
|
||||
| 规则名 | 描述 | 当前值 | 代码位置 |
|
||||
|--------|------|--------|----------|
|
||||
| admin.access.role | 管理后台权限角色 | ROLE_ADMIN | SecurityConfig + JwtAuthenticationFilter |
|
||||
| user.status.toggle | 用户启用/停用 | 允许,不可操作自身 | AdminService.toggleUserStatus |
|
||||
| branch.delete.guard | 删除网点前检查关联咨询师 | 暂未实现 | AdminService (待补充) |
|
||||
|
||||
## 字典规则
|
||||
|
||||
| 规则名 | 描述 | 当前值 | 代码位置 |
|
||||
|--------|------|----------|----------|
|
||||
| data.dictionary.queryable | 数据字典可通过 API 查询 | 所有注册的 DataDictionaryType | DataDictionaryController (Phase 3) |
|
||||
| enum.self.describing | 所有业务枚举实现 Description 接口 | 提供 getCode() / getDescription() | 各 enum 文件 (Phase 3) |
|
||||
当前注册规则:**无**。
|
||||
|
||||
@@ -1,62 +1,6 @@
|
||||
# 数据字典清单(事实方案)
|
||||
# 数据字典
|
||||
|
||||
> 所有枚举类型均实现 `Description` 接口,可通过 `GET /api/v1/data-dictionaries/{type}` 动态查询。
|
||||
> 空壳:示例字典枚举已清除。框架类型保留(`Description` / `DataDictionaryType` / `DataDictionaryUtil`)。
|
||||
> 实现 iteration1 时注册字典并回写本文档。
|
||||
|
||||
## UserRole — 用户角色
|
||||
|
||||
| Code | 描述 | 说明 |
|
||||
|------|------|------|
|
||||
| ROLE_USER | 普通用户 | 默认角色,可预约咨询 |
|
||||
| ROLE_ADMIN | 管理员 | 可访问管理后台 |
|
||||
|
||||
## UserStatus — 用户状态
|
||||
|
||||
| Code | 描述 | 说明 |
|
||||
|------|------|------|
|
||||
| ACTIVE | 正常 | 可用 |
|
||||
| DISABLED | 已停用 | 不可登录和操作 |
|
||||
|
||||
## AppointmentStatus — 预约状态
|
||||
|
||||
| Code | 描述 | 业务含义 |
|
||||
|------|------|----------|
|
||||
| PENDING | 待确认 | 初始状态,等待咨询师确认 |
|
||||
| CONFIRMED | 已确认 | 咨询师已确认,预约生效 |
|
||||
| COMPLETED | 已完成 | 咨询已结束,终态 |
|
||||
| CANCELLED | 已取消 | 用户或管理员取消,终态 |
|
||||
|
||||
**状态机流转**:
|
||||
|
||||
```
|
||||
PENDING ──→ CONFIRMED ──→ COMPLETED
|
||||
│ │
|
||||
└── CANCELLED ←──┘
|
||||
```
|
||||
|
||||
## ConsultantStatus — 咨询师状态
|
||||
|
||||
| Code | 描述 | 说明 |
|
||||
|------|------|------|
|
||||
| ACTIVE | 可预约 | 可在预约列表展示和选择 |
|
||||
| DISABLED | 不可预约 | 不展示在预约列表 |
|
||||
|
||||
## BranchStatus — 网点状态
|
||||
|
||||
| Code | 描述 | 说明 |
|
||||
|------|------|------|
|
||||
| ACTIVE | 营业中 | 正常运营 |
|
||||
| DISABLED | 已关闭 | 停止运营 |
|
||||
|
||||
## DataDictionaryType — 字典类型注册表
|
||||
|
||||
| Code | 关联枚举 | 描述 | 查询端点 |
|
||||
|------|----------|------|----------|
|
||||
| USER_ROLE | UserRole | 用户角色字典 | `/api/v1/data-dictionaries/USER_ROLE` |
|
||||
| USER_STATUS | UserStatus | 用户状态字典 | `/api/v1/data-dictionaries/USER_STATUS` |
|
||||
| APPOINTMENT_STATUS | AppointmentStatus | 预约状态字典 | `/api/v1/data-dictionaries/APPOINTMENT_STATUS` |
|
||||
| CONSULTANT_STATUS | Consultant.ConsultantStatus | 咨询师状态字典 | `/api/v1/data-dictionaries/CONSULTANT_STATUS` |
|
||||
| BRANCH_STATUS | Branch.BranchStatus | 网点状态字典 | `/api/v1/data-dictionaries/BRANCH_STATUS` |
|
||||
|
||||
## 同步策略
|
||||
|
||||
修改枚举后,运行 `DataDictionaryUtil.generateMarkdown()` 更新本文档。
|
||||
当前注册字典类型:**无**。
|
||||
|
||||
@@ -1,84 +1,17 @@
|
||||
# 错误码清单
|
||||
|
||||
> 本文档描述咨询预约平台的错误码体系事实(as-built)。
|
||||
> 框架约定(空壳 as-built)。业务专属错误码待 iteration1 实现后补充。
|
||||
> 与 `GlobalExceptionHandler` 及 `docs/standards/error.md` 对齐。
|
||||
|
||||
## 错误码结构
|
||||
## 当前 Handler 映射
|
||||
|
||||
```
|
||||
{ErrorGroup}_{SubCode}
|
||||
```
|
||||
| 抛出 | HTTP | errorCode | 说明 |
|
||||
|------|------|-----------|------|
|
||||
| `IllegalArgumentException` | 400 | `PARAM_ERROR` | 参数/资源不合法 |
|
||||
| `IllegalStateException` | 409 | `BUSINESS_CONFLICT` | 业务状态冲突 |
|
||||
| `MethodArgumentNotValidException` | 400 | `VALIDATION_ERROR` | `@Valid` 失败 |
|
||||
| 其它 `Exception` | 500 | `SYSTEM_ERROR` | 兜底(对外「系统繁忙」) |
|
||||
|
||||
- ErrorGroup(错误组):错误的来源分类
|
||||
- SubCode(子码):具体错误标识,可读性强
|
||||
鉴权失败由 Spring Security 直接返回 **401 / 403**,不走 `ErrorResponse`。
|
||||
|
||||
## ErrorGroup 定义
|
||||
|
||||
| Group | HTTP Status | 说明 |
|
||||
|-------|-------------|------|
|
||||
| COMMON | 400/404 | 通用参数/资源错误 |
|
||||
| AUTH | 401/400 | 认证/鉴权错误 |
|
||||
| BUSINESS | 409/400 | 业务逻辑冲突/错误 |
|
||||
| SYSTEM | 500 | 系统内部错误 |
|
||||
|
||||
## 全量错误码
|
||||
|
||||
### COMMON 组
|
||||
|
||||
| ErrorCode | HTTP Status | 说明 | 触发场景 |
|
||||
|-----------|-------------|------|----------|
|
||||
| COMMON_PARAM_ERROR | 400 | 参数校验失败 | @Valid 校验不通过 |
|
||||
| COMMON_RESOURCE_NOT_FOUND | 404 | 资源不存在 | 根据 ID 查询无结果 |
|
||||
| COMMON_VALIDATION_ERROR | 400 | 参数格式错误 | 字段级校验失败 |
|
||||
|
||||
### AUTH 组
|
||||
|
||||
| ErrorCode | HTTP Status | 说明 | 触发场景 |
|
||||
|-----------|-------------|------|----------|
|
||||
| AUTH_EMAIL_EXISTS | 400 | 邮箱已注册 | 重复 email 调用 register |
|
||||
| AUTH_WEAK_PASSWORD | 400 | 密码强度不足 | 密码 < 8 位 |
|
||||
| AUTH_INVALID_CREDENTIALS | 400 | 邮箱或密码错误 | login 时密码不匹配 |
|
||||
| AUTH_INVALID_TOKEN | 401 | Token 无效或过期 | JWT 解析失败 |
|
||||
| AUTH_TOKEN_EXPIRED | 401 | Token 已过期 | JWT 超时 |
|
||||
| AUTH_FORBIDDEN | 403 | 无权限 | 非 ADMIN 访问 /admin |
|
||||
| AUTH_USER_DISABLED | 401 | 用户已被停用 | status == DISABLED |
|
||||
|
||||
### BUSINESS 组
|
||||
|
||||
| ErrorCode | HTTP Status | 说明 | 触发场景 |
|
||||
|-----------|-------------|------|----------|
|
||||
| BUSINESS_CONFLICT_SLOT | 409 | 该时段已被预约 | 同一咨询师同一时段重复预约 |
|
||||
| BUSINESS_CONSULTANT_UNAVAILABLE | 400 | 咨询师不可预约 | consultant.isAvailable() == false |
|
||||
| BUSINESS_APPOINTMENT_CANNOT_CANCEL | 409 | 当前状态不允许取消 | status 为 COMPLETED 或 CANCELLED |
|
||||
| BUSINESS_APPOINTMENT_NOT_OWNER | 403 | 非本人预约不可操作 | userId 不匹配 |
|
||||
| BUSINESS_USER_DISABLED | 400 | 用户已被停用 | 尝试操作已 DISABLED 的用户 |
|
||||
| BUSINESS_BRANCH_HAS_CONSULTANTS | 409 | 网点有咨询师不可删除 | branch 关联的 consultant > 0 |
|
||||
|
||||
### SYSTEM 组
|
||||
|
||||
| ErrorCode | HTTP Status | 说明 | 触发场景 |
|
||||
|-----------|-------------|------|----------|
|
||||
| SYSTEM_INTERNAL_ERROR | 500 | 系统内部错误 | 未捕获的异常 |
|
||||
| SYSTEM_DB_ERROR | 500 | 数据库错误 | SQL 执行失败 |
|
||||
|
||||
## 返回格式
|
||||
|
||||
```json
|
||||
{
|
||||
"errorCode": "BUSINESS_CONFLICT_SLOT",
|
||||
"errorMessage": "该时间段已被预约",
|
||||
"data": null
|
||||
}
|
||||
```
|
||||
|
||||
## 当前实现映射
|
||||
|
||||
当前 `GlobalExceptionHandler` 使用简化 errorCode(无 ErrorGroup 前缀),映射关系:
|
||||
|
||||
| 当前 errorCode | 规范 errorCode | 异常类型 |
|
||||
|----------------|---------------|----------|
|
||||
| PARAM_ERROR | COMMON_PARAM_ERROR | IllegalArgumentException |
|
||||
| VALIDATION_ERROR | COMMON_VALIDATION_ERROR | MethodArgumentNotValidException |
|
||||
| BUSINESS_CONFLICT | BUSINESS_CONFLICT_SLOT | IllegalStateException |
|
||||
| SYSTEM_ERROR | SYSTEM_INTERNAL_ERROR | Exception |
|
||||
|
||||
**迁移计划**:Phase 2 后统一改用规范 errorCode 格式。
|
||||
响应体字段:`errorCode` / `errorMessage` / `data`。
|
||||
|
||||
@@ -1,90 +1,30 @@
|
||||
# 安全设计
|
||||
|
||||
> 本文档描述咨询预约平台的安全架构事实(as-built)。
|
||||
> 平台骨架 as-built。登录/注册等业务 API 待 ACC 实现。
|
||||
|
||||
## JWT Token
|
||||
|
||||
**算法**:HMAC-SHA256(`jjwt` 库 MAC 算法)
|
||||
**算法**:HMAC-SHA256(`jjwt`)
|
||||
|
||||
**密钥**:通过 `application.yml` 的 `jwt.secret` 配置,至少 256 位
|
||||
**配置**:`jwt.secret` / `jwt.expiration`(毫秒)
|
||||
|
||||
**有效期**:24 小时(`jwt.expiration` 配置,单位毫秒)
|
||||
**Claims(约定)**:`sub`=userId,`email`,`role`(如 `ROLE_USER` / `ROLE_ADMIN`),`iat`,`exp`
|
||||
|
||||
**Payload Claims**:
|
||||
|
||||
| Claim | 类型 | 值 | 说明 |
|
||||
|-------|------|-----|------|
|
||||
| sub | String | userId | 用户 UUID |
|
||||
| email | String | email | 用户邮箱 |
|
||||
| role | String | ROLE_USER / ROLE_ADMIN | 角色(与 Spring Security `hasRole()` 兼容) |
|
||||
| iat | Date | 签发时间戳 | -
|
||||
| exp | Date | 过期时间戳 | -
|
||||
|
||||
## JWT 处理流程
|
||||
## 处理流程
|
||||
|
||||
```
|
||||
请求 → JwtAuthenticationFilter (OncePerRequestFilter)
|
||||
1. 从 Authorization: Bearer <token> 提取 Token
|
||||
2. 解析 JWT → userId + email + role
|
||||
3. 设置 SecurityContextHolder (Spring Security)
|
||||
4. 设置 UserContextHolder (自定义 ThreadLocal)
|
||||
5. 放行请求
|
||||
6. 请求结束后清除 ThreadLocal
|
||||
请求 → JwtAuthenticationFilter
|
||||
提取 Bearer token → 校验 → UserContextHolder + SecurityContextHolder
|
||||
finally 清除 ThreadLocal / SecurityContext
|
||||
```
|
||||
|
||||
## Filter Chain 顺序
|
||||
## 当前放行
|
||||
|
||||
```
|
||||
Spring Security Filter Chain (SecurityConfig):
|
||||
1. JwtAuthenticationFilter (自定义, 提取 JWT 并设置上下文)
|
||||
2. UsernamePasswordAuthenticationFilter (内置, 不启用)
|
||||
3. ExceptionTranslationFilter (内置, 处理 AccessDenied)
|
||||
4. ...
|
||||
```
|
||||
- `GET /api/v1/health` — permitAll
|
||||
- 其它 `/api/**` — authenticated(无签发入口时仅能带有效 token 访问)
|
||||
|
||||
## SecurityConfig 规则矩阵
|
||||
## 相关类
|
||||
|
||||
| 路径模式 | 访问要求 |
|
||||
|----------|----------|
|
||||
| POST /api/v1/auth/register | 完全公开 |
|
||||
| POST /api/v1/auth/login | 完全公开 |
|
||||
| GET /api/v1/home/info | 完全公开 |
|
||||
| GET /api/v1/data-dictionaries** | 完全公开 |
|
||||
| GET /api/v1/business-rules** | 完全公开 |
|
||||
| GET /api/v1/consultants** | 完全公开 |
|
||||
| /admin/** | 仅 ROLE_ADMIN |
|
||||
| /api/v1/** | 需要认证(任何角色) |
|
||||
|
||||
## BCrypt 密码策略
|
||||
|
||||
- 编码器:`BCryptPasswordEncoder`(Spring Security 默认实现)
|
||||
- 强度:10(默认 rounds)
|
||||
- 密码要求:至少 8 位,由前端校验
|
||||
|
||||
## UserContext ThreadLocal
|
||||
|
||||
**类**:`UserContextHolder` — `ThreadLocal<UserContext>`
|
||||
|
||||
**UserContext 字段**:
|
||||
|
||||
| 字段 | 类型 | 来源 |
|
||||
|------|------|------|
|
||||
| userId | String | JWT sub |
|
||||
| email | String | JWT email |
|
||||
| role | String | JWT role |
|
||||
|
||||
**获取**:`SecurityUtils.currentUserId()` — 从 UserContextHolder 获取当前用户 ID
|
||||
|
||||
## CORS 配置
|
||||
|
||||
- 当前:`WebConfig.java` 允许所有 origin(开发阶段)
|
||||
- 生产:需限制为具体域名
|
||||
|
||||
## 密码修改流程
|
||||
|
||||
```
|
||||
1. 用户输入旧密码 + 新密码
|
||||
2. 从 DB 获取当前 BCrypt hash
|
||||
3. passwordService.matches(旧密码, 当前 hash) → 校验
|
||||
4. passwordService.encode(新密码) → 更新 DB
|
||||
```
|
||||
- `JwtTokenProvider` / `JwtAuthenticationFilter`
|
||||
- `UserContext` / `UserContextHolder` / `SecurityUtils`
|
||||
- `PasswordService` / `PasswordServiceImpl`(BCrypt)
|
||||
|
||||
@@ -1,67 +1,4 @@
|
||||
# 状态机设计
|
||||
# 状态机
|
||||
|
||||
> 本文档描述 AppointmentStatus 的完整状态机事实(as-built)。
|
||||
|
||||
## 状态定义
|
||||
|
||||
| Code | 描述 | 含义 |
|
||||
|------|------|------|
|
||||
| PENDING | 待确认 | 初始状态,用户已提交但等待确认 |
|
||||
| CONFIRMED | 已确认 | 咨询师/管理员已确认,预约生效 |
|
||||
| COMPLETED | 已完成 | 咨询已结束,**终态** |
|
||||
| CANCELLED | 已取消 | 用户或管理员取消,**终态** |
|
||||
|
||||
## 状态流转图
|
||||
|
||||
```
|
||||
┌──────────┐
|
||||
│ PENDING │ ← 创建预约后初始状态
|
||||
└────┬─────┘
|
||||
│
|
||||
┌──────┴──────┐
|
||||
│ │
|
||||
▼ ▼
|
||||
┌──────────┐ ┌──────────┐
|
||||
│CONFIRMED │ │CANCELLED │ ← 用户可取消
|
||||
└────┬─────┘ └──────────┘
|
||||
│
|
||||
▼
|
||||
┌──────────┐
|
||||
│COMPLETED │
|
||||
└──────────┘
|
||||
```
|
||||
|
||||
## 转换表
|
||||
|
||||
| 当前状态 | 目标状态 | 触发操作 | 守卫条件 | 代码位置 |
|
||||
|----------|----------|----------|----------|----------|
|
||||
| (新创建) | PENDING | 创建预约 (AppointmentService.create) | 咨询师可预约 + 无冲突 | `AppointmentService.java:50-53` |
|
||||
| PENDING | CONFIRMED | 管理员确认 (预留) | - | 未实现 |
|
||||
| PENDING | CANCELLED | 取消预约 (AppointmentService.cancel) | `!COMPLETED && !CANCELLED` | `Appointment.java` `canCancel()` |
|
||||
| CONFIRMED | COMPLETED | 管理员完成 (预留) | - | 未实现 |
|
||||
| CONFIRMED | CANCELLED | 取消预约 (AppointmentService.cancel) | `!COMPLETED && !CANCELLED` | `Appointment.java` `canCancel()` |
|
||||
|
||||
## 守卫条件
|
||||
|
||||
```
|
||||
canCancel() = status != COMPLETED && status != CANCELLED
|
||||
```
|
||||
|
||||
- PENDING 可取消
|
||||
- CONFIRMED 可取消
|
||||
- COMPLETED **不可取消**
|
||||
- CANCELLED **不可再次取消**
|
||||
|
||||
## 业务规则集成
|
||||
|
||||
**冲突检测**(AppointmentConflictService):
|
||||
- 创建预约时,排除 status == CANCELLED 的旧预约
|
||||
- 允许在同一咨询师同一时段重新预约(如果之前的预约已取消)
|
||||
- 由 `uk_appointment_slot` 唯一索引 + 代码双重校验
|
||||
|
||||
## 待实现状态转换
|
||||
|
||||
| 动作 | 优先级 | 说明 |
|
||||
|------|--------|------|
|
||||
| PENDING → CONFIRMED | 低 | 目前无确认端点,需管理后台功能 |
|
||||
| CONFIRMED → COMPLETED | 低 | 同上 |
|
||||
> 空壳:原 Appointment 状态机 as-built 已清除。
|
||||
> 状态流转以 `docs/features/iteration1/` 各 spec §9 为准,实现后回写本文档。
|
||||
|
||||
Reference in New Issue
Block a user