refactor: 默认 skills 装到 .agents,并清空 example 旧演示实现

对齐安装目录与 opencode 扫描路径;按 confirmed plan 清掉与 iteration1 不对齐的示例业务代码与 as-built 文档,只留空壳与需求输入。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
ning-inspire
2026-11-17 11:46:41 +08:00
parent e5abcd101d
commit 670e0c1fa1
155 changed files with 659 additions and 5620 deletions

View File

@@ -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) |
当前注册规则:**无**。

View File

@@ -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()` 更新本文档。
当前注册字典类型:**无**。

View File

@@ -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`。

View File

@@ -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)

View File

@@ -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 为准,实现后回写本文档。