Initial commit: ai4se-harness-suite
Import harness suite (skills, installers, overnight-runner, docs) as a fresh history for InspireChina. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
100
example-project/.agent/skills/ba-gen-facts/SKILL.md
Normal file
100
example-project/.agent/skills/ba-gen-facts/SKILL.md
Normal file
@@ -0,0 +1,100 @@
|
||||
---
|
||||
name: ba-gen-facts
|
||||
description: 从代码与设计文档生成或校准事实文档(API、库表、领域模型、专题)。当实现发生变化后 docs/designs/ 与代码不一致时使用。
|
||||
---
|
||||
|
||||
# BA:生成事实文档
|
||||
|
||||
**事实文档**(`docs/designs/`)描述系统 **当前的真实状态**,不是计划、不是意图。
|
||||
它的唯一判据是:**和代码对得上吗?**
|
||||
|
||||
## 与过程文档的区别
|
||||
|
||||
| | 过程文档 | 事实文档 |
|
||||
|---|---|---|
|
||||
| 位置 | `docs/features/`、`docs/plans/` | `docs/designs/` |
|
||||
| 描述 | 需求与方案(会变) | 系统现状(跟着代码变) |
|
||||
| 变更时机 | 迭代推进时 | **代码一变就变** |
|
||||
| 写法 | 可以写"待定" | **不许写"待定"** |
|
||||
|
||||
## 每份文档的事实来源
|
||||
|
||||
**不要凭记忆写,去读源头。**
|
||||
|
||||
| 文档 | 事实来源(按可信度排序) |
|
||||
|---|---|
|
||||
| `docs/designs/api.yaml` | Controller 的路由与方法签名、DTO 字段、错误码 |
|
||||
| `docs/designs/db-schema.md` | 迁移脚本 `db/migration/*.sql`、PO 类 |
|
||||
| `docs/designs/domain-model.md` | 聚合类、值对象、领域服务 |
|
||||
| `docs/designs/topic/businessrule.md` | `IBusinessRule` 实现类 + 规则配置文件 |
|
||||
| `docs/designs/topic/data-dict.md` | 枚举类 + 数据字典注册类 |
|
||||
| `topic/*.md` | 对应模块的实现 |
|
||||
|
||||
## 生成流程
|
||||
|
||||
```
|
||||
1. 确定范围 —— 这次变更动了哪些模块?
|
||||
2. 读源头 —— 从代码/迁移脚本/配置里读出真实状态
|
||||
3. 逐份对照 —— 现有文档哪里对、哪里不对、哪里缺
|
||||
4. 改文档 —— 只改与代码不符的部分,不重写风格
|
||||
5. 反向验证 —— 把文档当输入,逐条核对代码
|
||||
6. 报告 —— 列出改了哪些文档、每处对应的代码依据
|
||||
```
|
||||
|
||||
## 各文档的检查点
|
||||
|
||||
### API
|
||||
|
||||
- 路径、方法、请求参数、响应字段、状态码、错误码,与 Controller 逐一对上
|
||||
- 分页参数、鉴权要求(哪些接口要登录/要管理员)
|
||||
- 新增接口要标清楚 **用途**,不要只抄签名
|
||||
|
||||
### 数据库
|
||||
|
||||
- 表名、字段名、类型、是否可空、主键、索引、默认值
|
||||
- 迁移脚本版本号与内容对应
|
||||
- 字段含义写中文说明,不要只列结构
|
||||
- **敏感字段**(密码、手机号)标注存储方式(加密/脱敏)
|
||||
|
||||
### 领域模型
|
||||
|
||||
- 聚合根、实体、值对象、聚合之间的关系
|
||||
- 每个聚合的业务不变量(哪些操作非法)
|
||||
- 状态机:状态集合 + 允许的流转
|
||||
|
||||
### 业务规则与数据字典
|
||||
|
||||
- 规则:编号、分类、条件、动作,与实现枚举一一对应
|
||||
- 字典:每个枚举类型的取值、含义、注册位置
|
||||
|
||||
## 写法
|
||||
|
||||
- 用 **陈述句**:"预约状态包含 PENDING / CONFIRMED / COMPLETED / CANCELLED"
|
||||
- 不要用 "应该"、"计划"、"预计" —— 事实文档里没有将来时
|
||||
- 有例外就在同处说明,不要分散在多处
|
||||
- 每个结论都要能指到代码位置(类名 / 文件名),方便复核
|
||||
|
||||
## 与需求规格的关系
|
||||
|
||||
- 需求规格写的、但 **还没实现** 的,不进事实文档
|
||||
- 实现里 **多出来** 的行为:要么补进需求规格(并确认),要么改掉 —— 不能只躺在事实文档里
|
||||
- 两者冲突时,**以需求规格为准**(业务规则),但要修实现
|
||||
|
||||
## 输出
|
||||
|
||||
改完后在提交描述里写清楚:
|
||||
|
||||
```
|
||||
事实文档同步:
|
||||
- docs/designs/api.yaml — 新增 GET /api/v1/xxx(依据 XxxController#getXxx)
|
||||
- docs/designs/db-schema.md — appointments 表新增 remark 字段(依据 V2026xxxx__add_remark.sql)
|
||||
```
|
||||
|
||||
## 自检清单
|
||||
|
||||
- [ ] 每条结论都能指到代码/脚本位置
|
||||
- [ ] 没有"应该"、"计划"、"待补充"
|
||||
- [ ] 没实现的内容没有写进去
|
||||
- [ ] 错误码、枚举值与代码完全一致
|
||||
- [ ] 敏感字段已标注
|
||||
- [ ] `docs/designs/README.md` 的专题索引已同步
|
||||
120
example-project/.agent/skills/ba-grill-me/SKILL.md
Normal file
120
example-project/.agent/skills/ba-grill-me/SKILL.md
Normal file
@@ -0,0 +1,120 @@
|
||||
---
|
||||
name: ba-grill-me
|
||||
description: 拷问需求,把模糊的一句话需求逼成可验收的规格。当收到的需求描述含糊、有多种理解、验收标准不可测时,在写需求规格之前使用。
|
||||
---
|
||||
|
||||
# BA:拷问需求
|
||||
|
||||
需求写不清楚,是后面所有返工的根源。这个 skill 的唯一目的:**在动手写规格之前,把歧义问干净**。
|
||||
|
||||
## 什么时候用
|
||||
|
||||
- 需求只有一两句话,没有明确验收标准
|
||||
- 同一句话有 **两种以上** 合理解释
|
||||
- 需求里出现"支持"、"优化"、"友好"、"快速" 这类不可测的词
|
||||
- 涉及 **权限、状态流转、数据迁移、金额/库存** 等高风险面
|
||||
|
||||
**已经澄清过的不用再问一遍。** 先读 `docs/features/` 里已有的规格和 `docs/designs/` 里的事实文档。
|
||||
|
||||
## 拷问协议
|
||||
|
||||
### 一次问 3~5 个,不要一次甩 30 个
|
||||
|
||||
一次给太多问题,对方会随便答,答案质量会塌。分批问,每批之后确认理解一致。
|
||||
|
||||
### 按主题推进,一个主题问透
|
||||
|
||||
推荐顺序:
|
||||
|
||||
1. **业务目的** —— 这件事做完,谁的什么问题被解决了?
|
||||
2. **角色与权限** —— 谁能看到、谁能改、谁不能碰?
|
||||
3. **数据与字段** —— 有哪些字段?谁填?校验规则?默认值?
|
||||
4. **流程与状态** —— 有状态流转吗?谁能触发?非法流转怎么办?
|
||||
5. **异常与边界** —— 重复提交、超时、并发、数据不存在?
|
||||
6. **验收标准** —— 怎么算做完了?
|
||||
|
||||
### 只问"代码里查不到"的
|
||||
|
||||
能自己查到的别问:
|
||||
|
||||
| 问题 | 先查 |
|
||||
|---|---|
|
||||
| 现有接口长什么样 | `docs/designs/api.yaml`、Controller |
|
||||
| 表结构 | `docs/designs/db-schema.md`、迁移脚本 |
|
||||
| 领域模型 | `docs/designs/domain-model.md`、聚合类 |
|
||||
| 已有业务规则 | `docs/designs/topic/businessrule.md` |
|
||||
| 现有枚举取值 | `docs/designs/topic/data-dict.md` |
|
||||
|
||||
查完再问,问的是 **产品决策**,不是事实。
|
||||
|
||||
### 阻塞性问题必须问到答案
|
||||
|
||||
下面这些没答案就不能往下走,必须停下来问:
|
||||
|
||||
- 需求范围边界(做什么、明确不做什么)
|
||||
- 权限归属(谁能做)
|
||||
- 关键校验规则的具体取值
|
||||
- 验收标准
|
||||
|
||||
其余可以记录为"待确认",在规格里标 `TODO(待确认)`。
|
||||
|
||||
## 提问模板
|
||||
|
||||
一次问一批,每条给一个具体场景,别问开放式的"你想要什么":
|
||||
|
||||
```
|
||||
1. 谁可以使用这个功能?(普通用户 / 管理员 / 两者)
|
||||
2. 管理员操作后,普通用户应该看到什么?
|
||||
3. 提交时如果同一时段已被预约,期望是"拒绝"还是"覆盖"?
|
||||
4. 这条记录创建后可以修改吗?已完成的还能改吗?
|
||||
5. "做完了"的判定标准是什么?请给一个能自动验证的例子。
|
||||
```
|
||||
|
||||
## 反模式
|
||||
|
||||
| 别做 | 为什么 |
|
||||
|---|---|
|
||||
| 一次问 30 个问题 | 对方会乱答 |
|
||||
| 问"你想要什么功能" | 开放式问题拿不到可验收的答案 |
|
||||
| 自己替对方做决定 | 猜错了后面全白做 —— **猜也要问** |
|
||||
| 问完不记录 | 结论丢失,规格又要重新推一遍 |
|
||||
| 把技术方案问题拿去问业务 | 那是 TL 的事,不是 PO 的事 |
|
||||
|
||||
## 产出:澄清纪要
|
||||
|
||||
把结论写成结构化的纪要,直接交给 `ba-write-spec` 使用。存到 `docs/features/` 下与规格同名的草稿,或直接作为规格的输入。
|
||||
|
||||
```markdown
|
||||
# 澄清纪要:{需求名称}
|
||||
|
||||
- 日期:YYYY-MM-DD
|
||||
- 原始需求:<原话>
|
||||
|
||||
## 已确认
|
||||
|
||||
| # | 问题 | 结论 | 依据 |
|
||||
|---|---|---|---|
|
||||
| Q1 | 谁能用? | 管理员与普通用户 | 需求方确认 |
|
||||
|
||||
## 待确认(不阻塞)
|
||||
|
||||
| # | 问题 | 当前假设 | 待谁确认 |
|
||||
|---|---|---|---|
|
||||
|
||||
## 范围边界
|
||||
|
||||
**做**:
|
||||
- ...
|
||||
|
||||
**明确不做**:
|
||||
- ...
|
||||
|
||||
## 验收标准(已达成可测)
|
||||
|
||||
1. 给定 …,当 …,则 …
|
||||
```
|
||||
|
||||
## 交给下一步
|
||||
|
||||
澄清纪要完成后,用 `ba-write-spec` 把它落成 `docs/features/{模块}.md`。
|
||||
如果还有阻塞性待确认项,**不要**开始写规格。
|
||||
117
example-project/.agent/skills/ba-write-spec/SKILL.md
Normal file
117
example-project/.agent/skills/ba-write-spec/SKILL.md
Normal file
@@ -0,0 +1,117 @@
|
||||
---
|
||||
name: ba-write-spec
|
||||
description: 编写需求规格说明书(字段表、业务规则、权限矩阵、验收标准)。当需求已澄清,需要把需求落成 docs/features/ 下的规格文档时使用。
|
||||
---
|
||||
|
||||
# BA:编写需求规格
|
||||
|
||||
把澄清好的需求落成 **可验收、可实现、可测试** 的规格文档。
|
||||
|
||||
## 前置
|
||||
|
||||
- 需求已经过 `ba-grill-me` 澄清,阻塞项都有结论
|
||||
- 已读过 `docs/features/_template.md`(规格模板)与 `AGENTS.md`
|
||||
- 已查过 `docs/designs/` 下的事实文档,避免和现状冲突
|
||||
|
||||
## 输出位置
|
||||
|
||||
`docs/features/{模块}.md`
|
||||
|
||||
- 命名用模块名(如 `booking.md`、`account.md`),可按迭代放在 `docs/features/iterationN/`;不要用日期
|
||||
- 一个模块一份,不要把多个模块塞进一个文件
|
||||
- 更新已有模块时基于当前版本改,写明基线版本与目标版本
|
||||
|
||||
## 各章节怎么写
|
||||
|
||||
### §1 需求说明
|
||||
|
||||
- 背景:为什么要做(业务动机,不是技术动机)
|
||||
- 目标:做完之后什么变了
|
||||
- 范围:**明确写出"不做什么"** —— 这一节最容易被跳过,也最容易吵架
|
||||
|
||||
### §2~3 功能与权限
|
||||
|
||||
- 适用用户表列出角色与场景
|
||||
- 权限矩阵用 ✅/❌ 逐格填写,不要留空
|
||||
- 补一条通用规则:**未提及的操作一律不允许**
|
||||
|
||||
### §4 业务流程
|
||||
|
||||
主流程按步骤写;异常流程单独列:
|
||||
|
||||
| 编号 | 触发条件 | 系统行为 | 结果 |
|
||||
|---|---|---|---|
|
||||
| EX-001 | 条件 | 行为 | 结果 |
|
||||
|
||||
### §5 字段表
|
||||
|
||||
这是规格里最容易被写错的部分:
|
||||
|
||||
| 字段名 | 中文名 | 类型 | 必填 | 描述 | 取值/枚举/来源 | 创建时必填 | 可修改 |
|
||||
|---|---|---|---:|---|---|---:|---:|
|
||||
|
||||
- **枚举字段要在"取值"列直接写全枚举值和中文含义**,不要写"见字典"
|
||||
- 字段名用英文(与代码一致),中文名单独一列
|
||||
- "创建时必填"与"必填"不同:更新时可能允许留空
|
||||
|
||||
### §7 业务规则
|
||||
|
||||
**每条规则必须有编号**,格式:
|
||||
|
||||
```
|
||||
R-CREATE-001:必填字段校验
|
||||
- 适用场景:CREATE
|
||||
- 条件:…
|
||||
- 动作:…
|
||||
```
|
||||
|
||||
规则要按场景分组(COMMON / CREATE / QUERY / UPDATE / DELETE),每组都要覆盖:
|
||||
|
||||
- 权限校验
|
||||
- 字段校验(必填、唯一、格式)
|
||||
- 状态/终态校验
|
||||
- 审计信息记录
|
||||
- 引用约束(被引用的数据不能删)
|
||||
|
||||
编号是 QA 用例和代码注释的锚点 —— 没有编号的规则在实现阶段一定会走样。
|
||||
|
||||
### §9 状态流转
|
||||
|
||||
| 当前状态 | 触发动作 | 目标状态 | 允许角色 | 规则编号 |
|
||||
|---|---|---|---|---|
|
||||
|
||||
必须写清 **非法流转** 的处理(拒绝 + 错误码)。
|
||||
|
||||
### §12 验收标准
|
||||
|
||||
用 Given-When-Then,一条一个编号(`AC-xxx`):
|
||||
|
||||
```
|
||||
AC-001:正常创建
|
||||
- 给定:用户具备创建权限
|
||||
- 当:用户输入合法字段并提交
|
||||
- 则:系统创建成功,并返回创建后的数据
|
||||
```
|
||||
|
||||
三类都要写:功能验收、数据验收、权限验收。
|
||||
|
||||
### §14 原型引用
|
||||
|
||||
写清原型路径/链接,并声明冲突时以本规格为准。
|
||||
|
||||
## 自检清单
|
||||
|
||||
- [ ] 每条规则有编号、适用场景、条件、动作
|
||||
- [ ] 每条验收标准有编号,且可测
|
||||
- [ ] 字段表里枚举值写全
|
||||
- [ ] 权限矩阵无空格,"未提及即不允许"已写明
|
||||
- [ ] 状态流转表完整,含非法流转处理
|
||||
- [ ] 范围里写了"明确不做什么"
|
||||
- [ ] NEW / UPDATE 标注正确,UPDATE 有基线版本
|
||||
- [ ] 没有出现表名、类名、SQL(那是技术方案,不是规格)
|
||||
- [ ] 没有根据原型 UI 反推业务规则
|
||||
|
||||
## 交付后
|
||||
|
||||
1. 交给 QA 用 `qa-write-cases` 把验收标准与业务规则转成 `TC-xxx` 用例
|
||||
2. 交给 TL / 开发用 `dev-plan` 写技术方案
|
||||
39
example-project/.agent/skills/dev-build/SKILL.md
Normal file
39
example-project/.agent/skills/dev-build/SKILL.md
Normal file
@@ -0,0 +1,39 @@
|
||||
---
|
||||
name: dev-build
|
||||
description: 遵循四层 DDD 架构实现功能。当为 咨询预约平台 编写后端或前端代码时使用。
|
||||
---
|
||||
|
||||
# 开发:构建实现
|
||||
|
||||
按照 `AGENTS.md` 中的架构约定编写代码。
|
||||
|
||||
## 后端
|
||||
|
||||
- `backend/adapter/rest/` — Controller:仅做协议转换,不含业务逻辑
|
||||
- `backend/application/service/` — AppService:用例编排,`@Transactional`
|
||||
- `backend/domain/` — 聚合、值对象、领域服务:业务不变量
|
||||
- `backend/infrastructure/` — 持久化、安全、配置
|
||||
|
||||
层依赖关系:adapter → application → domain ← infrastructure
|
||||
|
||||
## 前端
|
||||
|
||||
- Vue 3 Composition API + `<script setup>`
|
||||
- Pinia store 管理认证状态,位于 `frontend/src/stores/auth.ts`
|
||||
- 视图位于 `frontend/src/views/user/` 或 `frontend/src/views/admin/`
|
||||
- Axios 拦截器处理 JWT 和 401 跳转
|
||||
|
||||
## 验证
|
||||
|
||||
```bash
|
||||
cd backend && mvn test
|
||||
cd frontend && npm run build
|
||||
```
|
||||
|
||||
## 文档同步
|
||||
|
||||
实现完成后检查是否需要更新:
|
||||
- `docs/designs/api.yaml` — API 变更
|
||||
- `docs/designs/db-schema.md` — 数据库变更
|
||||
- `docs/designs/topic/businessrule.md` — 业务规则变更
|
||||
- `docs/designs/topic/data-dict.md` — 数据字典变更
|
||||
112
example-project/.agent/skills/dev-code-review/SKILL.md
Normal file
112
example-project/.agent/skills/dev-code-review/SKILL.md
Normal file
@@ -0,0 +1,112 @@
|
||||
---
|
||||
name: dev-code-review
|
||||
description: 按项目规范做代码评审。当提交前自查、或评审别人的 PR/MR 时使用。
|
||||
---
|
||||
|
||||
# Dev:代码评审
|
||||
|
||||
评审的标准来自项目自己的规范,不来自评审者的口味。
|
||||
|
||||
## 先读规范,再看代码
|
||||
|
||||
```
|
||||
1. AGENTS.md —— 架构边界、分层规则、工程规范
|
||||
2. docs/standards/ —— 命名、分层、API、数据库、错误、安全、测试规范
|
||||
3. docs/designs/ —— 系统现状(对照实现是否与设计一致)
|
||||
4. 再看 diff
|
||||
```
|
||||
|
||||
**不要跳过第 1~3 步。** 没读规范就评审,只能评审代码风格。
|
||||
|
||||
## 评审前确认范围
|
||||
|
||||
```bash
|
||||
git diff main...HEAD # 本次改动全貌
|
||||
git diff main...HEAD --stat # 改动文件清单
|
||||
```
|
||||
|
||||
先看清单 —— **改了不该改的文件** 是最常见的问题:
|
||||
|
||||
- 顺手重构了无关模块 → 要求拆开
|
||||
- 改了格式化整个文件 → 要求还原无关行
|
||||
- 改了测试期望值来迁就实现 → 要求改实现
|
||||
|
||||
## 检查清单
|
||||
|
||||
### 分层(`AGENTS.md` §3)
|
||||
|
||||
- [ ] `adapter` 层只有协议转换与参数校验,没有业务逻辑
|
||||
- [ ] `application` 层用例编排完整,事务边界在这里
|
||||
- [ ] `domain` 层没有依赖 infrastructure / adapter / Web 框架
|
||||
- [ ] `infrastructure` 实现 domain 定义的接口,没有反向依赖
|
||||
|
||||
### 依赖与持久化
|
||||
|
||||
- [ ] 写操作走聚合行为 + repository,没有直接操作 PO
|
||||
- [ ] 主键策略与项目一致
|
||||
- [ ] 没有在 Controller / Repository 上写 `@Transactional`
|
||||
|
||||
### 错误处理
|
||||
|
||||
- [ ] 业务错误用 `BusinessException`,不是裸 `RuntimeException`
|
||||
- [ ] 参数错误能被统一异常处理转成 400
|
||||
- [ ] 权限不足返回 401/403,不是 500
|
||||
- [ ] 没有把异常堆栈或敏感信息返回给前端
|
||||
|
||||
### 安全
|
||||
|
||||
- [ ] 没有硬编码密钥、密码、token
|
||||
- [ ] 日志没有打印 token / 密码 / 身份证
|
||||
- [ ] 对外接口都做了鉴权检查
|
||||
- [ ] SQL 用参数绑定,没有字符串拼接
|
||||
|
||||
### 命名与风格
|
||||
|
||||
- [ ] 类名、方法名、字段名符合 `docs/standards/naming.md`
|
||||
- [ ] REST 路径符合 `docs/standards/api-design.md`(`/api/v1/resource`,admin 用 `/admin/xxx`)
|
||||
- [ ] 没有无用 import、没有 `TODO` 残留、没有调试 `console.log`
|
||||
- [ ] 复用了现有的 assembler / converter / repository 模式,没有自创一套
|
||||
|
||||
### 测试
|
||||
|
||||
- [ ] 新增/修改的 API 有对应集成测试
|
||||
- [ ] 至少覆盖 Happy Path + 关键失败分支
|
||||
- [ ] 测试之间无顺序依赖,可重复执行
|
||||
- [ ] 没有为了让测试变绿而弱化断言
|
||||
|
||||
### 文档
|
||||
|
||||
- [ ] API 变更 → `docs/designs/api.yaml` 已更新
|
||||
- [ ] 表结构变更 → `docs/designs/db-schema.md` 已更新
|
||||
- [ ] 业务规则变更 → `docs/designs/topic/businessrule.md` 已更新
|
||||
- [ ] 枚举变更 → `docs/designs/topic/data-dict.md` 已更新
|
||||
- [ ] 迁移脚本 + 测试 `schema.sql` 同步
|
||||
|
||||
## 严重级别
|
||||
|
||||
| 级别 | 含义 | 处理 |
|
||||
|---|---|---|
|
||||
| **Blocker** | 安全漏洞、数据损坏、违反分层、需求没实现 | 必须改,不合并 |
|
||||
| **Major** | 边界没覆盖、错误处理不对、文档没同步 | 必须改 |
|
||||
| **Minor** | 命名不一致、重复代码、注释缺失 | 建议改 |
|
||||
| **Nit** | 纯风格偏好 | 作者自行决定 |
|
||||
|
||||
**不要用 Minor / Nit 掩盖 Major。** 评审意见要指向 **规则**,不是"我觉得"。
|
||||
|
||||
## 评审意见写法
|
||||
|
||||
```
|
||||
[Blocker] backend/.../AppointmentService.java:42
|
||||
事务边界放错了:@Transactional 标在 repository 实现上,违反 AGENTS.md §6。
|
||||
应移到 AppService 的用例方法上。
|
||||
```
|
||||
|
||||
每条意见包含:**位置 + 违反了哪条规则 + 应该怎么改**。
|
||||
|
||||
## 评审结论
|
||||
|
||||
- ✅ **通过** —— 无 Blocker / Major
|
||||
- 🔄 **需修改** —— 有 Blocker / Major,列出清单
|
||||
- ❓ **有疑问** —— 需要作者解释才能判断(写清楚问什么)
|
||||
|
||||
对事不对人。评审的是 **代码**,不是作者。
|
||||
145
example-project/.agent/skills/dev-create-mr/SKILL.md
Normal file
145
example-project/.agent/skills/dev-create-mr/SKILL.md
Normal file
@@ -0,0 +1,145 @@
|
||||
---
|
||||
name: dev-create-mr
|
||||
description: 创建 Merge Request / Pull Request。当分支开发完成、自测通过、准备提交评审时使用。
|
||||
---
|
||||
|
||||
# Dev:创建 Merge Request
|
||||
|
||||
## 提交前闸门(不满足就别提)
|
||||
|
||||
```
|
||||
[ ] 自测全绿 —— dev-self-test
|
||||
[ ] 代码评审自查通过 —— dev-code-review
|
||||
[ ] 事实文档已同步 —— ba-gen-facts(API / 库表 / 规则 / 字典)
|
||||
[ ] diff 里没有无关文件
|
||||
[ ] 没有调试代码、console.log、TODO 残留
|
||||
[ ] 没有硬编码密钥
|
||||
```
|
||||
|
||||
**任一不满足,先修。** 提一个明知过不了的 MR 只会浪费评审时间。
|
||||
|
||||
## 识别平台
|
||||
|
||||
```bash
|
||||
git remote -v
|
||||
```
|
||||
|
||||
| remote 形态 | 平台 | 工具 |
|
||||
|---|---|---|
|
||||
| `github.com` | GitHub | `gh pr create` |
|
||||
| `gitlab` | GitLab | `glab mr create` |
|
||||
| 其他 / 无 | 通用 | 推分支 + 输出手动创建链接 |
|
||||
|
||||
工具缺失时:装 CLI(`gh auth login` / `glab auth login`),或退化成 **推分支 + 给出创建链接**。
|
||||
|
||||
## 分支
|
||||
|
||||
```bash
|
||||
git checkout -b feature/<简述-slug>
|
||||
```
|
||||
|
||||
| 类型 | 前缀 | 例 |
|
||||
|---|---|---|
|
||||
| 功能 | `feature/` | `feature/appointment-cancel` |
|
||||
| 缺陷 | `fix/` | `fix/token-refresh-loop` |
|
||||
| 重构 | `refactor/` | `refactor/appointment-aggregate` |
|
||||
| 文档 | `docs/` | `docs/testing-standard` |
|
||||
| 发布 | `release/` | `release/v1.2.0` |
|
||||
|
||||
从 `main` 切出。**不要**把无关改动混进来。
|
||||
|
||||
## 提交信息
|
||||
|
||||
Conventional Commits:
|
||||
|
||||
```
|
||||
<type>(<scope>): <描述>
|
||||
|
||||
<正文:为什么这么改,不是改了什么>
|
||||
|
||||
<脚注:关联需求/规则/用例>
|
||||
```
|
||||
|
||||
| type | 用于 |
|
||||
|---|---|
|
||||
| `feat` | 新功能 |
|
||||
| `fix` | 缺陷修复 |
|
||||
| `refactor` | 不改行为的重构 |
|
||||
| `docs` | 文档 |
|
||||
| `test` | 测试 |
|
||||
| `chore` | 构建/依赖/杂项 |
|
||||
| `perf` | 性能 |
|
||||
|
||||
脚注要挂上可追溯的锚点:
|
||||
|
||||
```
|
||||
Refs: R-CANCEL-003
|
||||
Refs: AC-007
|
||||
Refs: TC-013
|
||||
```
|
||||
|
||||
## 创建
|
||||
|
||||
```bash
|
||||
# GitHub
|
||||
gh pr create --base main --title "feat(appointment): 支持取消预约" --body-file /tmp/mr-body.md
|
||||
|
||||
# GitLab
|
||||
glab mr create --target-branch main --title "feat(appointment): 支持取消预约" --description "$(cat /tmp/mr-body.md)"
|
||||
```
|
||||
|
||||
## MR 描述模板
|
||||
|
||||
```markdown
|
||||
## 变更内容
|
||||
|
||||
- 新增:取消预约用例(`Appointment.canCancel()` 守卫)
|
||||
- 修改:预约列表增加"取消"按钮
|
||||
- 影响:仅前端 + application 层,domain 无破坏性变更
|
||||
|
||||
## 关联
|
||||
|
||||
- 需求:`docs/features/iteration1/booking.md`
|
||||
- 规则:R-CANCEL-003
|
||||
- 用例:TC-013
|
||||
|
||||
## 自测结果
|
||||
|
||||
- 后端单元:N/N 通过
|
||||
- 后端集成:N/N 通过
|
||||
- 前端构建:通过
|
||||
- 前端单元:N/N 通过
|
||||
- E2E 自测:N/N 通过
|
||||
|
||||
## 事实文档同步
|
||||
|
||||
- [x] `docs/designs/api.yaml` —— 新增 DELETE /api/v1/appointments/{id}
|
||||
- [x] `docs/designs/db-schema.md` —— 不涉及
|
||||
- [ ] `docs/designs/topic/businessrule.md` —— 不涉及
|
||||
- [ ] `docs/designs/topic/data-dict.md` —— 不涉及
|
||||
|
||||
## 风险与回滚
|
||||
|
||||
- 风险:低。改动集中在新增路径,旧路径未改。
|
||||
- 回滚:revert 本 MR 即可,无数据迁移。
|
||||
|
||||
## 截图 / 演示
|
||||
|
||||
<有 UI 变化时附截图>
|
||||
```
|
||||
|
||||
## 拆分原则
|
||||
|
||||
一个 MR 做 **一件事**。
|
||||
|
||||
| 该拆 | 不该拆 |
|
||||
|---|---|
|
||||
| 功能 + 顺带重构 | 功能 + 格式化全文件 |
|
||||
| 后端 + 无关的前端改动 | 功能 + 修 bug + 加日志 |
|
||||
| 数据库迁移 + 大量业务改动 | 多个独立功能 |
|
||||
|
||||
实在要一起提,在描述里 **分节说明** 每部分为什么不能拆。
|
||||
|
||||
## 输出
|
||||
|
||||
把 MR 链接作为最终产出返回,并在描述里附上自测结果与文档同步勾选。
|
||||
36
example-project/.agent/skills/dev-debug/SKILL.md
Normal file
36
example-project/.agent/skills/dev-debug/SKILL.md
Normal file
@@ -0,0 +1,36 @@
|
||||
---
|
||||
name: dev-debug
|
||||
description: 使用 chrome-devtools-mcp 调试前端和后端问题。当浏览器显示错误、UI 异常或网络请求失败时使用。
|
||||
---
|
||||
|
||||
# 开发:调试
|
||||
|
||||
## 启动服务栈
|
||||
|
||||
```bash
|
||||
./e2e-run.sh
|
||||
```
|
||||
|
||||
如需要可仅启动服务而不运行测试。
|
||||
|
||||
## chrome-devtools-mcp 工具
|
||||
|
||||
MCP 服务器(`.mcp.json` 中的 `chrome-devtools`)提供:
|
||||
|
||||
- `navigate_page` — 导航到 URL
|
||||
- `take_screenshot` — 截取页面/元素截图
|
||||
- `take_snapshot` — 获取无障碍树(带 uid 的文本 DOM 快照)
|
||||
- `click`、`fill`、`fill_form` — 与元素交互
|
||||
- `list_console_messages`、`get_console_message` — 读取浏览器控制台
|
||||
- `list_network_requests`、`get_network_request` — 检查网络请求
|
||||
- `evaluate_script` — 在页面上下文中运行 JS
|
||||
- `performance_start_trace` — 记录性能追踪
|
||||
|
||||
## 调试流程
|
||||
|
||||
1. 导航到问题页面
|
||||
2. 检查控制台错误(`list_console_messages`)
|
||||
3. 检查网络失败的请求(`list_network_requests`)
|
||||
4. 获取 DOM 快照检查状态(`take_snapshot`)
|
||||
5. 如果是 UI 问题,截图查看(`take_screenshot`)
|
||||
6. 如果是性能问题,开始追踪(`performance_start_trace`)
|
||||
35
example-project/.agent/skills/dev-plan/SKILL.md
Normal file
35
example-project/.agent/skills/dev-plan/SKILL.md
Normal file
@@ -0,0 +1,35 @@
|
||||
---
|
||||
name: dev-plan
|
||||
description: 在编写任何代码之前在 docs/plans/ 中创建开发计划。当开始新功能、重构或任何非简单变更时使用。
|
||||
---
|
||||
|
||||
# 开发:制定计划
|
||||
|
||||
在实现前在 `docs/plans/` 中创建计划。
|
||||
|
||||
## 模板
|
||||
|
||||
使用 `docs/plans/_template.md` 作为模板,包含以下核心章节:
|
||||
|
||||
1. 文档说明(背景、目标)
|
||||
2. 领域模型(PlantUML)
|
||||
3. 数据库设计(SQL DDL)
|
||||
4. API 设计(OpenAPI)
|
||||
5. 时序图(PlantUML)
|
||||
6. 专题设计(权限、并发、事务、异常、性能、扩展性)
|
||||
7. 一致性约束
|
||||
8. 单元测试设计
|
||||
9. API 集成测试设计
|
||||
10. E2E 测试设计
|
||||
11. 修改清单(代码、接口、数据库变更)
|
||||
12. 验证步骤
|
||||
13. 风险与回滚
|
||||
14. 实施后需更新的 design 文档
|
||||
|
||||
## 规则
|
||||
|
||||
- 计划必须经用户审核确认后方可继续(AGENTS.md §14 第 1 步)
|
||||
- 包含每个需要变更的文件的路径
|
||||
- 参考现有模式(assembler、converter、service)以保持一致性
|
||||
- 考虑文档同步:本次变更是否会影响 `docs/designs/` 中的文件?
|
||||
- **plan 一旦定稿就不修改**,同一资源的二次改造新建 `YYYYMMDD-{slug}.md`
|
||||
149
example-project/.agent/skills/dev-release-plan/SKILL.md
Normal file
149
example-project/.agent/skills/dev-release-plan/SKILL.md
Normal file
@@ -0,0 +1,149 @@
|
||||
---
|
||||
name: dev-release-plan
|
||||
description: 整理当前迭代的上线准备清单。当迭代收尾、准备发版时使用。
|
||||
---
|
||||
|
||||
# Dev:上线准备清单
|
||||
|
||||
把"能不能发"从口头感觉,变成 **一张逐项打勾的清单**。
|
||||
|
||||
## 输出位置
|
||||
|
||||
`docs/releases/{version}.md`(如 `docs/releases/v1.2.0.md`)
|
||||
|
||||
版本号用 `vX.Y.Z`;发版前先建文件,随检查推进逐项打勾。
|
||||
|
||||
## 第一步:确定范围
|
||||
|
||||
```bash
|
||||
git log --oneline main..HEAD
|
||||
git diff main...HEAD --stat
|
||||
```
|
||||
|
||||
列出本次要发的所有变更,并归类:
|
||||
|
||||
| 类别 | 影响 | 需要谁确认 |
|
||||
|---|---|---|
|
||||
| 新功能 | 无兼容问题 | QA |
|
||||
| 缺陷修复 | — | QA |
|
||||
| DB 变更 | **有风险** | TL + DBA |
|
||||
| 接口变更 | 下游可能受影响 | TL |
|
||||
| 配置/开关变更 | 行为变化 | TL |
|
||||
| 依赖升级 | 可能引入回归 | 全员 |
|
||||
|
||||
**只要有 DB 变更或接口不兼容变更,这一项就必须单独列出来并写回滚方案。**
|
||||
|
||||
## 清单模板
|
||||
|
||||
```markdown
|
||||
# 上线准备:v1.2.0
|
||||
|
||||
- 日期:YYYY-MM-DD
|
||||
- 分支/提交:<branch @ sha>
|
||||
- 目标分支:main
|
||||
- 发布负责人:
|
||||
- 回滚负责人:
|
||||
|
||||
## 1. 代码冻结
|
||||
|
||||
- [ ] 本次发布的分支已冻结,不再接受功能改动
|
||||
- [ ] 紧急修复走 hotfix 分支,单独发
|
||||
- [ ] diff 中没有调试代码 / console.log / TODO 残留
|
||||
- [ ] 没有硬编码密钥
|
||||
|
||||
## 2. 测试通过
|
||||
|
||||
- [ ] 后端单元测试全绿(`cd backend && mvn test`)
|
||||
- [ ] 前端构建通过(`cd frontend && npm run build`)
|
||||
- [ ] **QA 验收用例集全绿**(`cd e2e && npm run test:qa`)
|
||||
- [ ] QA 已逐条验收 `docs/test-cases/e2e-cases/test-cases.md`
|
||||
- [ ] 冒烟用例全绿(`docs/test-cases/smoking-cases/smoking-test-cases.md`)
|
||||
- [ ] 手动用例已执行(`docs/test-cases/manual-cases/manual-test-cases.md`)
|
||||
|
||||
## 3. 文档同步
|
||||
|
||||
- [ ] `docs/designs/api.yaml` 已更新
|
||||
- [ ] `docs/designs/db-schema.md` 已更新
|
||||
- [ ] `docs/designs/topic/businessrule.md` 已更新
|
||||
- [ ] `docs/designs/topic/data-dict.md` 已更新
|
||||
- [ ] `docs/features/` 规格已标注已实现
|
||||
- [ ] 本清单已建立
|
||||
|
||||
## 4. 数据变更
|
||||
|
||||
- [ ] 迁移脚本已合并(列出版本号:<V...>)
|
||||
- [ ] 迁移脚本在 **生产数据量级** 上演练过
|
||||
- [ ] 大表变更评估过锁表时间
|
||||
- [ ] 回滚脚本已准备(或明确说明"靠代码回退")
|
||||
- [ ] 数据订正脚本已准备并备份
|
||||
|
||||
## 5. 配置与环境
|
||||
|
||||
- [ ] 新增配置项已写入各环境配置模板
|
||||
- [ ] 密钥已通过配置中心/环境变量注入,未进仓库
|
||||
- [ ] 开关(feature flag)默认值正确
|
||||
- [ ] 依赖服务版本已确认兼容
|
||||
|
||||
## 6. 部署
|
||||
|
||||
- [ ] 部署脚本/流水线已就绪
|
||||
- [ ] 备份已完成(数据库 / 文件 / 配置)
|
||||
- [ ] 部署顺序已确认(先兼容后切换)
|
||||
- [ ] 回滚步骤已写明,且演练过
|
||||
|
||||
## 7. 发布后验证
|
||||
|
||||
- [ ] 服务健康检查通过
|
||||
- [ ] 冒烟用例在生产环境跑一遍
|
||||
- [ ] 关键指标正常(错误率、延迟、业务量)
|
||||
- [ ] 日志无异常堆栈
|
||||
|
||||
## 8. 通知与收尾
|
||||
|
||||
- [ ] 已通知相关方(业务/客服/上下游)
|
||||
- [ ] 已同步线上版本与变更内容
|
||||
- [ ] 已归档本清单
|
||||
|
||||
## 回滚方案
|
||||
|
||||
- 触发条件:
|
||||
- 回滚步骤:
|
||||
- 回滚耗时预估:
|
||||
- 回滚后需要补做的事:
|
||||
```
|
||||
|
||||
## 关键检查点
|
||||
|
||||
### DB 变更必须单独评估
|
||||
|
||||
```bash
|
||||
ls ./**/db/migration/*.sql # 确认脚本清单
|
||||
```
|
||||
|
||||
每个脚本问:
|
||||
|
||||
- 加字段有默认值吗?大表加字段要多久?
|
||||
- 加索引会锁表吗?在生产数据量下要多久?
|
||||
- 删字段/删表 —— **不可逆**,必须有回滚方案
|
||||
- 数据订正脚本幂等吗?重跑会不会出事?
|
||||
|
||||
### 发布后 30 分钟是黄金窗口
|
||||
|
||||
发布后立刻看:
|
||||
|
||||
- 健康检查
|
||||
- **冒烟用例**(`docs/test-cases/smoking-cases/`)
|
||||
- 错误日志(不是只看进程活着)
|
||||
|
||||
发现异常 **立即回滚**,不要"再观察观察"。
|
||||
|
||||
## 输出
|
||||
|
||||
填好的 `docs/releases/{version}.md` + 一句话结论:
|
||||
|
||||
```
|
||||
上线准备:v1.2.0 —— 8/8 项通过,无 DB 变更,可发布
|
||||
```
|
||||
|
||||
有未完成项时,明确说清 **哪几项未完成、卡在谁那里**。
|
||||
不要用"基本没问题"这种话。
|
||||
97
example-project/.agent/skills/dev-self-test/SKILL.md
Normal file
97
example-project/.agent/skills/dev-self-test/SKILL.md
Normal file
@@ -0,0 +1,97 @@
|
||||
---
|
||||
name: dev-self-test
|
||||
description: 运行并修复开发自测(后端单元/集成测试、前端构建与单元测试、E2E 自测)。当实现完成后、交给 QA 之前,需要自证代码按 Plan 工作时使用。
|
||||
---
|
||||
|
||||
# Dev:开发自测
|
||||
|
||||
**自测**验证"代码按 Plan 的设计工作"。它 **不是** QA 测试,不能替代验收 —— 详见项目 `AGENTS.md` §10。
|
||||
|
||||
| | 开发自测 | QA 测试 |
|
||||
|---|---|---|
|
||||
| 依据 | Plan | 需求规格 |
|
||||
| 判定人 | 开发本人 | QA |
|
||||
| 编号 | 无 | `TC-xxx` |
|
||||
| 位置 | 源码旁、`e2e/tests/dev/` | `docs/` 用例库、`e2e/tests/qa/` |
|
||||
| 合并闸门 | 否 | **是** |
|
||||
|
||||
## 执行顺序
|
||||
|
||||
由快到慢,**先跑快的**,不要一上来就等 E2E:
|
||||
|
||||
```
|
||||
1. 后端单元测试 → 秒级,先跑
|
||||
2. 后端集成测试 → 分钟级
|
||||
3. 前端类型/构建 → 秒级
|
||||
4. 前端单元测试 → 秒级
|
||||
5. E2E 自测 → 最慢,最后跑
|
||||
```
|
||||
|
||||
```bash
|
||||
cd backend && mvn test
|
||||
cd frontend && npm run build
|
||||
|
||||
cd e2e && npm run test:dev # 开发自测 E2E,不含 QA 用例
|
||||
```
|
||||
|
||||
## 失败处理
|
||||
|
||||
### 先分类,再动手
|
||||
|
||||
| 症状 | 多半是 | 动作 |
|
||||
|---|---|---|
|
||||
| 断言失败,但代码逻辑看着对 | **实现错了**,不是测试错了 | 改实现 |
|
||||
| 断言失败,值差一点点 | 边界没考虑到 | 补实现 + 补边界用例 |
|
||||
| 测试报空指针 / NPE | 测试前置数据缺失 | 补测试数据准备 |
|
||||
| 整类用例一起挂 | 环境问题(DB 没起、端口占用、依赖服务) | 先修环境,别改代码 |
|
||||
| 用例之间互相影响 | **测试没有隔离** | 修测试隔离(数据清理) |
|
||||
| 昨天绿今天红 | 时间/顺序依赖 | 加显式等待,去掉硬等待 |
|
||||
|
||||
### 绝对不要做的事
|
||||
|
||||
- ❌ 为了让测试变绿而 **修改断言去迁就实现**
|
||||
- ❌ 删掉失败的用例
|
||||
- ❌ 加 `@Disabled` / `test.skip` 掩盖问题(除非明确记录原因)
|
||||
- ❌ 改 **QA 用例**(`e2e/tests/qa/`)—— 那是 QA 的判定依据
|
||||
- ❌ 放宽断言(比如把 `toBe` 改成 `toBeTruthy`)来"通过"
|
||||
|
||||
如果确实是 Plan 错了:**回到 Plan 步骤**,改 Plan,不要在代码里悄悄按自己的理解实现。
|
||||
|
||||
### 硬等待要改掉
|
||||
|
||||
```ts
|
||||
// ❌ 硬等待,CI 上必 flaky
|
||||
await page.waitForTimeout(3000)
|
||||
|
||||
// ✅ 等具体状态
|
||||
await expect(page.locator('.result')).toBeVisible({ timeout: 10000 })
|
||||
```
|
||||
|
||||
## 覆盖自查
|
||||
|
||||
| 项 | 要求 |
|
||||
|---|---|
|
||||
| 每个新增/修改的 API | 1 个 Happy Path + 关键失败分支(参数错误 / 权限不足 / 业务冲突) |
|
||||
| 每个新聚合 | 业务不变量有对应用例 |
|
||||
| 每个状态流转 | 合法流转 + 非法流转各一条 |
|
||||
| 前端新组件/composable | 单元测试(Vitest,与源码同目录 `*.test.ts`) |
|
||||
| DB 变更 | 迁移脚本 + 测试 `schema.sql` 同步 |
|
||||
|
||||
## 输出:自测报告
|
||||
|
||||
```
|
||||
自测结果:<通过 / 有失败>
|
||||
- 后端单元:N/N 通过
|
||||
- 后端集成:N/N 通过
|
||||
- 前端构建:通过
|
||||
- 前端单元:N/N 通过
|
||||
- E2E 自测:N/N 通过
|
||||
|
||||
修复记录:
|
||||
- <失败用例> —— 原因 —— 处理
|
||||
|
||||
遗留问题:
|
||||
- <已知但本次不修的,写明影响与后续安排>
|
||||
```
|
||||
|
||||
如实报告。**测试没过就说没过**,不要用"应该没问题"。
|
||||
128
example-project/.agent/skills/dev-ui-review/SKILL.md
Normal file
128
example-project/.agent/skills/dev-ui-review/SKILL.md
Normal file
@@ -0,0 +1,128 @@
|
||||
---
|
||||
name: dev-ui-review
|
||||
description: 用 chrome-devtools-mcp 做界面与交互评审。当前端界面需要实机检查视觉、响应式、报错时使用。
|
||||
---
|
||||
|
||||
# Dev:界面评审
|
||||
|
||||
界面评审 **必须实机看**,不能只读代码。工具:chrome-devtools-mcp(配置在 `.mcp.json`)。
|
||||
|
||||
## 准备
|
||||
|
||||
```bash
|
||||
./e2e-run.sh
|
||||
```
|
||||
|
||||
- 前端:`http://localhost:5173`
|
||||
- 后端:`http://localhost:8080`
|
||||
|
||||
服务没起来就先修服务,不要在报错页面上做评审。
|
||||
|
||||
## 评审流程(按顺序,别跳步)
|
||||
|
||||
```
|
||||
1. 导航到页面 → navigate_page
|
||||
2. 看无障碍树 → take_snapshot (先确认结构对不对)
|
||||
3. 截图看视觉 → take_screenshot
|
||||
4. 看控制台 → list_console_messages
|
||||
5. 看网络请求 → list_network_requests
|
||||
6. 换视口再看 → resize / 多视口各截一次
|
||||
7. 交互走一遍 → click / fill / fill_form
|
||||
```
|
||||
|
||||
**先结构、再视觉、最后交互。** 结构错了,视觉截图再好看也没意义。
|
||||
|
||||
## 检查清单
|
||||
|
||||
### 结构与语义
|
||||
|
||||
- [ ] 标题层级正确(一个 h1)
|
||||
- [ ] 语义标签用对了(`nav` / `main` / `button` / `label`)
|
||||
- [ ] 表单控件有关联 `label`
|
||||
- [ ] 表格有 `th`,行有语义
|
||||
- [ ] 图片有 `alt`
|
||||
|
||||
### 视觉
|
||||
|
||||
- [ ] 颜色、间距来自全局 CSS 变量,没有硬编码
|
||||
- [ ] 长文本不溢出、不撑破布局
|
||||
- [ ] 中英文混排不出现奇怪的字距
|
||||
- [ ] 深浅色对比度足够
|
||||
|
||||
### 状态覆盖(最容易漏)
|
||||
|
||||
每个列表/表单都要有这三种状态:
|
||||
|
||||
| 状态 | 表现 |
|
||||
|---|---|
|
||||
| 加载中 | 有骨架或 spinner,不是空白 |
|
||||
| 空数据 | 有引导文案 + 下一步操作 |
|
||||
| 出错 | 有错误提示 + 可重试 |
|
||||
|
||||
- [ ] 三种状态都实机看过
|
||||
|
||||
### 交互
|
||||
|
||||
- [ ] 按钮点击有反馈(loading / 禁用 / 提交中)
|
||||
- [ ] 重复点击不会重复提交
|
||||
- [ ] 401 自动跳登录
|
||||
- [ ] 403 有明确提示,不是空白页
|
||||
- [ ] 表单校验错误定位到字段
|
||||
- [ ] 键盘可达(Tab 顺序、Esc 关闭弹层)
|
||||
|
||||
### 响应式
|
||||
|
||||
至少看三档:
|
||||
|
||||
| 视口 | 宽度 | 关注 |
|
||||
|---|---|---|
|
||||
| 移动 | 375px | 单列、导航折叠、按钮可点区域 |
|
||||
| 平板 | 768px | 两列 / 侧栏收起 |
|
||||
| 桌面 | 1280px | 布局与最大宽度 |
|
||||
|
||||
- [ ] 三档都没有横向滚动条
|
||||
- [ ] 移动端没有 hover-only 的操作(手点不到)
|
||||
|
||||
### 干净度
|
||||
|
||||
- [ ] 控制台无 error / warning(`list_console_messages`)
|
||||
- [ ] 网络请求无意外 4xx/5xx(`list_network_requests`)
|
||||
- [ ] 没有残留的 `console.log`
|
||||
- [ ] 没有 404 的静态资源
|
||||
|
||||
## 证据
|
||||
|
||||
每条问题都要有 **可复现的证据**:
|
||||
|
||||
| 级别 | 要求 |
|
||||
|---|---|
|
||||
| Blocker | 截图 + 复现步骤 + 控制台/网络报错原文 |
|
||||
| Major | 截图 + 复现步骤 |
|
||||
| Minor | 截图 |
|
||||
|
||||
问题格式:
|
||||
|
||||
```
|
||||
[Major] 预约列表移动端横向溢出
|
||||
复现:视口 375px → 访问 /user/appointments
|
||||
期望:表格转为卡片布局,页面无横向滚动
|
||||
实际:表格宽度固定 800px,页面出现横向滚动条
|
||||
证据:<截图路径>
|
||||
```
|
||||
|
||||
## 输出
|
||||
|
||||
```
|
||||
界面评审:<结论>
|
||||
- 视口:375 / 768 / 1280
|
||||
- 页面:/xxx、/yyy
|
||||
|
||||
Blocker:
|
||||
- ...
|
||||
|
||||
Major:
|
||||
- ...
|
||||
|
||||
已确认正常:
|
||||
- 三种状态、键盘可达、控制台干净、网络无 4xx/5xx
|
||||
```
|
||||
109
example-project/.agent/skills/pm-estimate/SKILL.md
Normal file
109
example-project/.agent/skills/pm-estimate/SKILL.md
Normal file
@@ -0,0 +1,109 @@
|
||||
---
|
||||
name: pm-estimate
|
||||
description: 基于需求分类基线表格做工作量估算。当需求进入迭代前需要给工作量与排期时使用。
|
||||
---
|
||||
|
||||
# PM:工作量估算
|
||||
|
||||
估算不靠拍脑袋,靠 **分类 + 基线表 + 调整系数**。
|
||||
|
||||
## 方法
|
||||
|
||||
```
|
||||
基线点数 = 按需求分类查表得到
|
||||
最终点数 = 基线点数 × 复杂度系数 × 风险系数
|
||||
人日 = 最终点数 × 团队基线人日/点
|
||||
```
|
||||
|
||||
**基线表**见同目录的 [`baseline.md`](baseline.md)。表里的数字是 **起点**,不是真理 ——
|
||||
每次迭代结束后用 `pm-retro` 校准它。
|
||||
|
||||
## 三步
|
||||
|
||||
### 第一步:把需求拆成可独立估算的条目
|
||||
|
||||
一条需求如果混了多个类型("加个预约功能,包含列表、详情、取消"),**拆开估**。
|
||||
|
||||
拆到每个条目能归入 **一个** 分类为止。拆不动的条目通常说明需求本身没想清楚 —— 先用 `ba-grill-me`。
|
||||
|
||||
### 第二步:查基线表
|
||||
|
||||
对每个条目:
|
||||
|
||||
1. 在 `baseline.md` 找到匹配的分类 → 拿到基线点数
|
||||
2. 定 **复杂度系数**:简单 0.8 / 标准 1.0 / 复杂 1.4
|
||||
3. 定 **风险系数**:低 1.0 / 中 1.2 / 高 1.5
|
||||
|
||||
判定依据见 `baseline.md` 的"复杂度判定"与"风险判定"。
|
||||
|
||||
### 第三步:汇总并给缓冲
|
||||
|
||||
```
|
||||
原始点数 = Σ 各条目最终点数
|
||||
缓冲 = 原始点数 × 0.2 # 20% 缓冲
|
||||
迭代点数 = 原始点数 + 缓冲
|
||||
```
|
||||
|
||||
缓冲不是用来藏估不准的,是用来装 **没预见到的事**(联调、环境问题、需求小改)。
|
||||
|
||||
## 输出格式
|
||||
|
||||
```markdown
|
||||
# 估算:{需求名称}
|
||||
|
||||
- 日期:YYYY-MM-DD
|
||||
- 迭代:{迭代名}
|
||||
- 参与估算:{角色}
|
||||
|
||||
## 拆解与估算
|
||||
|
||||
| # | 条目 | 分类 | 基线点数 | 复杂度 | 风险 | 最终点数 | 说明 |
|
||||
|---|---|---|---:|---:|---:|---:|---|
|
||||
| 1 | 预约列表页 | 列表查询型 | 3 | 标准 1.0 | 低 1.0 | 3.0 | 复用现有表格 |
|
||||
| 2 | 取消预约 | 状态流转型 | 5 | 复杂 1.4 | 中 1.2 | 8.4 | 含并发冲突处理 |
|
||||
| 3 | 取消确认弹窗 | 展示型 | 1 | 简单 0.8 | 低 1.0 | 0.8 | 用现成 Modal |
|
||||
|
||||
## 汇总
|
||||
|
||||
- 原始点数:12.2
|
||||
- 缓冲(20%):2.4
|
||||
- **迭代点数:14.6**
|
||||
|
||||
## 团队基线
|
||||
|
||||
- 团队基线人日/点:0.5
|
||||
- **预估人日:7.3 人日**
|
||||
|
||||
## 假设与风险
|
||||
|
||||
- 假设:复用现有 Modal 与表格组件
|
||||
- 风险:取消预约的并发冲突处理可能超期(已在复杂度系数中体现)
|
||||
- 若假设不成立:+2 人日
|
||||
|
||||
## 未计入
|
||||
|
||||
- QA 用例编写与验收(见 `qa-write-cases`)
|
||||
- 文档同步(见 `ba-gen-facts`)
|
||||
- 发布准备(见 `dev-release-plan`)
|
||||
```
|
||||
|
||||
## 校准(重要)
|
||||
|
||||
估算不准是常态,但 **不准要知道原因**:
|
||||
|
||||
- 估完记下 **实际耗时**,下次迭代开始前对比
|
||||
- 某类需求连续两次偏差 > 30% → 基线表的点数该改了
|
||||
- 改基线表时说明原因,别默默调数字
|
||||
|
||||
基线表在 `../` 的套件源码里(`agile-team-sdd/skills/pm-estimate-template/baseline.md`),
|
||||
改完重新 `install.sh --force --skill pm-estimate` 下发到各项目。
|
||||
|
||||
## 反模式
|
||||
|
||||
| 别做 | 为什么 |
|
||||
|---|---|
|
||||
| 按人天直接拍 | 没有基线,无法校准,越估越飘 |
|
||||
| 一条需求一个数 | 大需求会掩盖小任务的复杂度差异 |
|
||||
| 不加缓冲 | 第一个意外就爆 |
|
||||
| 估完了不记录实际值 | 下次还是估不准 |
|
||||
| 把 QA、文档、发布的时间忘掉 | 这部分一定会占时间 |
|
||||
96
example-project/.agent/skills/pm-estimate/baseline.md
Normal file
96
example-project/.agent/skills/pm-estimate/baseline.md
Normal file
@@ -0,0 +1,96 @@
|
||||
# 估算基线表
|
||||
|
||||
> 需求分类 → 基线点数。数字是 **起点**,靠 `pm-retro` 校准。
|
||||
>
|
||||
> 点数单位是"相对点数",不是人日。转人日要用团队基线(见 `pm-estimate`)。
|
||||
|
||||
## 一、基线表
|
||||
|
||||
| 分类 | 基线点数 | 包含什么(默认范围) |
|
||||
|---|---:|---|
|
||||
| **展示型** | 1 | 静态页面/只读列表,无交互逻辑、无新接口 |
|
||||
| **表单型** | 2 | 单表单增改改,前端校验 + 1 个 CRUD 接口,无状态流转 |
|
||||
| **列表查询型** | 3 | 带筛选/排序/分页的列表,复用现有列表组件与查询模式 |
|
||||
| **详情型** | 3 | 单条详情展示,含空态/加载态,无写操作 |
|
||||
| **CRUD 型** | 5 | 完整增删改查,后端含持久化、校验、权限 |
|
||||
| **状态流转型** | 5 | 引入状态机与流转守卫,含非法流转处理与并发冲突 |
|
||||
| **规则型** | 5 | 引入业务规则引擎、规则配置或数据字典注册 |
|
||||
| **集成型** | 8 | 对接外部服务/第三方 API,含鉴权、失败重试、幂等 |
|
||||
| **报表型** | 8 | 统计聚合、跨表查询、导出 |
|
||||
| **权限型** | 8 | 新增角色或细粒度权限模型,含数据范围控制 |
|
||||
| **数据迁移型** | 8 | 历史数据订正、字段回填、双写兼容期 |
|
||||
| **性能型** | 8 | 明确性能瓶颈的优化(需先有基线数据) |
|
||||
| **缺陷修复型** | 1 | 明确根因、改动范围小的缺陷(1 点起,按复杂度调整) |
|
||||
| **缺陷排查型** | 2 | 根因不明、需要先定位的缺陷(定位 + 修复) |
|
||||
| **技术重构型** | 5 | 不改外部行为、只改内部结构的重构 |
|
||||
| **架构级改造** | 13 | 分层调整、框架替换、数据模型重构 |
|
||||
|
||||
## 二、复杂度系数
|
||||
|
||||
在基线点数上乘。
|
||||
|
||||
| 系数 | 判定 |
|
||||
|---:|---|
|
||||
| 0.8 | 简单。改动 < 3 个文件,无新概念,有现成实现可复制 |
|
||||
| 1.0 | 标准。改动 3~8 个文件,涉及 1~2 层,可能新增 1 个接口 |
|
||||
| 1.4 | 复杂。改动 > 8 个文件,跨 3 层以上,有并发/事务/兼容性考虑 |
|
||||
|
||||
## 三、风险系数
|
||||
|
||||
在基线点数上乘。
|
||||
|
||||
| 系数 | 判定 |
|
||||
|---:|---|
|
||||
| 1.0 | 低。技术成熟、有现成模式、依赖稳定 |
|
||||
| 1.2 | 中。存在未知点、需联调、依赖第三方、历史数据不干净 |
|
||||
| 1.5 | 高。核心链路、有数据迁移、需求本身可能变、依赖外部团队 |
|
||||
|
||||
## 四、分类选择决策
|
||||
|
||||
```
|
||||
只读展示,无新接口 → 展示型
|
||||
一个表单,无状态流转 → 表单型
|
||||
列表要筛选/分页/排序 → 列表查询型
|
||||
新角色 / 数据范围 / 权限矩阵 → 权限型
|
||||
状态会变,且有非法流转 → 状态流转型
|
||||
要落新业务规则或枚举字典 → 规则型
|
||||
要改库表结构或回填历史数据 → 数据迁移型
|
||||
要调外部 API → 集成型
|
||||
没有外部行为变化的重构 → 技术重构型
|
||||
```
|
||||
|
||||
**同时命中多个**:按 **点数最高的那个** 估,并在说明里写清命中了哪些。
|
||||
|
||||
## 五、常见条目组合示例
|
||||
|
||||
| 需求 | 拆解 | 基线 | 最终 |
|
||||
|---|---|---|---:|
|
||||
| 预约列表 + 取消预约 | 列表查询型 3 + 状态流转型 5 | | 3.0 + 8.4 = 11.4 |
|
||||
| 后台加一个统计看板 | 报表型 8 + 展示型 1 | | 8.0 + 0.8 = 8.8 |
|
||||
| 接入短信验证码 | 集成型 8 + 表单型 2 | | 11.2 + 1.6 = 12.8 |
|
||||
| 修一个日期显示错位 | 缺陷修复型 1 | 复杂 1.4 | 1.4 |
|
||||
| 用户表加字段并回填 | 数据迁移型 8 + 规则型 5 | | 8.0 + 5.0 = 13.0 |
|
||||
|
||||
## 六、团队基线
|
||||
|
||||
点数转人日需要一个 **团队基线**(1 点 = 多少人日),它随团队熟练度变化:
|
||||
|
||||
| 团队状态 | 建议基线 |
|
||||
|---|---|
|
||||
| 熟悉本代码库 | 0.4 ~ 0.5 人日/点 |
|
||||
| 一般熟悉 | 0.5 ~ 0.7 人日/点 |
|
||||
| 刚接触 | 0.7 ~ 1.0 人日/点 |
|
||||
|
||||
**首次使用时先估 5 条有历史记录的需求,反推基线**,不要直接套上表。
|
||||
|
||||
## 七、校准规则
|
||||
|
||||
每次迭代结束:
|
||||
|
||||
1. 对比估算点数与实际耗时
|
||||
2. 偏差 > 30% 的条目,逐条写原因
|
||||
3. 连续两次同类偏差 > 30% → 调整该分类的基线点数
|
||||
4. 调整要 **改基线表 + 写明原因**,不要只改一次估算
|
||||
|
||||
基线表位置:`../agile-team-sdd/skills/pm-estimate-template/baseline.md`
|
||||
(安装到项目后为 `.agent/skills/pm-estimate/baseline.md`)
|
||||
147
example-project/.agent/skills/pm-retro/SKILL.md
Normal file
147
example-project/.agent/skills/pm-retro/SKILL.md
Normal file
@@ -0,0 +1,147 @@
|
||||
---
|
||||
name: pm-retro
|
||||
description: 复盘并把改进项回写到 harness 本身。当迭代结束、或流程反复出问题需要修 harness(技能、模板、规范)时使用。
|
||||
---
|
||||
|
||||
# PM:复盘并改进 harness
|
||||
|
||||
复盘的产出 **不是** "大家要更认真",而是 **对 harness 的具体修改**。
|
||||
harness 指:技能模板、规范文档、目录结构、模板文件、脚本。
|
||||
|
||||
## 核心原则
|
||||
|
||||
> **人一次不会变,harness 会变。**
|
||||
> 复盘发现的问题,如果靠"下次注意"解决,就是没解决 —— 必须落到 harness 的某个文件上。
|
||||
|
||||
## 第一步:收集事实
|
||||
|
||||
复盘前先把这些材料拉齐(不要凭印象):
|
||||
|
||||
```bash
|
||||
git log --oneline main..HEAD
|
||||
git log --format="%h %s" --since="2 weeks ago"
|
||||
```
|
||||
|
||||
- 本迭代实际提交的 MR/PR 列表与它们的返工次数
|
||||
- 跳过步骤的记录(哪些步骤被绕过、为什么)
|
||||
- 反复出现的问题(同一类错误出现几次)
|
||||
- 估算偏差(用 `pm-estimate` 的记录对比实际)
|
||||
- `docs/` 同步检查被勾掉的次数(勾了但没真同步的)
|
||||
|
||||
**重点找"重复发生"的事。** 一次是偶发,两次以上就是 harness 的问题。
|
||||
|
||||
## 第二步:分类问题
|
||||
|
||||
| 类别 | 含义 | 归属 |
|
||||
|---|---|---|
|
||||
| **流程缺失** | 少了某一步,或某步没有明确产物 | 加 skill 步骤 / 加检查清单 |
|
||||
| **规范缺失** | 规则没写,或写了但不好查 | 改 `AGENTS.md` / `docs/standards/` |
|
||||
| **模板缺失** | 每次都要从头写的东西 | 加模板文件 |
|
||||
| **Skill 缺失** | 需要一个反复出现的动作,没有对应 skill | 加 skill |
|
||||
| **Skill 不好用** | 有 skill,但步骤不清楚 / 输出不对口 | 改 skill 模板 |
|
||||
| **工具缺失** | 需要脚本能自动做的事 | 加脚本 |
|
||||
| **认知偏差** | 大家理解不一致 | 写进规范 + 培训,不是改工具 |
|
||||
|
||||
**"认知偏差" 是唯一不能靠改 harness 解决的** —— 但也要落到"写进规范哪一节"。
|
||||
|
||||
## 第三步:产出改进项
|
||||
|
||||
每条改进项必须有:**问题证据 + 改哪个文件 + 改成什么**。
|
||||
|
||||
```markdown
|
||||
### 改进项 1:Plan 缺少"接口不兼容变更"检查
|
||||
|
||||
- 证据:迭代中 2 次接口变更没同步 `docs/designs/api.yaml`,QA 验收时才发现
|
||||
- 归类:流程缺失
|
||||
- 改哪里:`../agile-team-sdd/skills/dev-plan-template/SKILL.md` §规则
|
||||
- 改成什么:加一条 —— "若新增/修改/删除接口,在 Plan 的'修改清单 → 接口变更'表中必须逐条列出,并在'实施后需更新的 design 文档'中写明 `docs/designs/api.yaml`"
|
||||
- 谁改:TL
|
||||
- 怎么验证:下个迭代 Plan 评审时检查这条是否被填
|
||||
```
|
||||
|
||||
**"改哪里"必须指向真实存在的文件路径。** 说不清改哪个文件的改进项,等于没结论。
|
||||
|
||||
## 第四步:回写 harness
|
||||
|
||||
改进项确认后:
|
||||
|
||||
1. 改 **套件源码**:`../agile-team-sdd/skills/<skill>-template/SKILL.md` 等
|
||||
2. 同步改 **已安装副本**:目标项目的 `.agent/skills/<skill>/SKILL.md`
|
||||
3. 改动要 **重新下发** 才生效:
|
||||
|
||||
```bash
|
||||
./agile-team-sdd/install.sh <目标项目> --skill <skill> --force
|
||||
```
|
||||
|
||||
只改已安装副本 = 下次重装会丢;只改套件源码 = 本次不生效。**两边都要改。**
|
||||
|
||||
## 第五步:验证改进有效
|
||||
|
||||
改进项要 **可观测**:
|
||||
|
||||
| 改进项 | 怎么验证 |
|
||||
|---|---|
|
||||
| 加了检查清单 | 下个迭代评审时该清单被打勾 |
|
||||
| 加了模板 | 下个迭代该模板被使用(不是被手写替代) |
|
||||
| 改了 skill | 下个迭代该步骤耗时下降 / 不再被跳过 |
|
||||
| 加了脚本 | 脚本被执行过,产出被使用 |
|
||||
|
||||
**验证不了就说明改进项没落地**,要么改法不对,要么问题判断错了。
|
||||
|
||||
## 复盘记录模板
|
||||
|
||||
```markdown
|
||||
# 复盘:{迭代名}
|
||||
|
||||
- 日期:YYYY-MM-DD
|
||||
- 参与角色:{列出}
|
||||
- 数据来源:{提交记录 / 跳过步骤记录 / 估算对比}
|
||||
|
||||
## 事实
|
||||
|
||||
- 交付需求:N 条
|
||||
- 估算点数:X(实际 Y,偏差 Z%)
|
||||
- 返工 MR:N 个
|
||||
- 被跳过的步骤:{步骤名 → 次数}
|
||||
- 重复发生的问题:
|
||||
|
||||
| 问题 | 次数 | 影响 |
|
||||
|---|---:|---|
|
||||
|
||||
## 做得好(保留)
|
||||
|
||||
- {流程/规范/工具} —— {为什么有效}
|
||||
|
||||
## 做得不好(改进项)
|
||||
|
||||
见下方改进项表。
|
||||
|
||||
## 改进项
|
||||
|
||||
| # | 问题证据 | 归类 | 改哪里 | 改成什么 | 谁改 | 怎么验证 | 状态 |
|
||||
|---|---|---|---|---|---|---|---|
|
||||
|
||||
## 下次迭代要盯的 3 件事
|
||||
|
||||
1.
|
||||
2.
|
||||
3.
|
||||
```
|
||||
|
||||
## 反模式
|
||||
|
||||
| 别做 | 为什么 |
|
||||
|---|---|
|
||||
| "大家要更仔细" | 不是改进项,无法验证 |
|
||||
| 只写不改 | 复盘记录不产生价值 |
|
||||
| 改了不验证 | 改进没落地,下次照旧 |
|
||||
| 一次改 20 项 | 改不完,最后一项都没生效。**一次改 3 项以内** |
|
||||
| 改进项没有"改哪里" | 无法执行 |
|
||||
| 改完不重新下发 | 项目里还是旧版本 |
|
||||
|
||||
## 与其他 skill 的关系
|
||||
|
||||
- `pm-estimate` —— 复盘时用它的记录校准基线表
|
||||
- `pm-retro` 产出的改进项如果涉及用例体系 → `qa-write-cases`
|
||||
- 涉及规范 → 改 `AGENTS.md` / `docs/standards/`
|
||||
- 涉及新动作 → 在 `../agile-team-sdd/skills/` 加 skill 模板,并更新 `catalog.json`
|
||||
112
example-project/.agent/skills/qa-run-e2e/SKILL.md
Normal file
112
example-project/.agent/skills/qa-run-e2e/SKILL.md
Normal file
@@ -0,0 +1,112 @@
|
||||
---
|
||||
name: qa-run-e2e
|
||||
description: 运行 E2E 用例集并定位失败原因。当验收前跑 QA 用例集,或用例失败需要排查时使用。
|
||||
---
|
||||
|
||||
# QA:运行 E2E
|
||||
|
||||
跑 QA 用例集,判通过,失败时定位到 **根因** 而不是症状。
|
||||
|
||||
## 运行
|
||||
|
||||
```bash
|
||||
cd e2e && npm run test:qa
|
||||
```
|
||||
|
||||
完整流程(含启动前后端):
|
||||
|
||||
```bash
|
||||
./e2e-run.sh
|
||||
```
|
||||
|
||||
| 命令 | 作用 |
|
||||
|---|---|
|
||||
| `npm run test:qa` | 只跑 QA 验收用例(合并闸门) |
|
||||
| `npm run test:dev` | 只跑开发自测用例(不阻塞合并) |
|
||||
| `npm test` | 全部 |
|
||||
|
||||
调试单个用例:
|
||||
|
||||
```bash
|
||||
cd e2e
|
||||
npx playwright test --project=qa --grep "TC-013"
|
||||
npx playwright test --project=qa --headed --debug # 有头 + 调试器
|
||||
```
|
||||
|
||||
## 前置检查
|
||||
|
||||
跑之前先确认环境,别把环境问题当成用例失败:
|
||||
|
||||
- [ ] 后端已启动,`http://localhost:8080` 可访问
|
||||
- [ ] 前端已启动,`http://localhost:5173` 可访问
|
||||
- [ ] 数据库可用(测试库已初始化)
|
||||
- [ ] 种子数据存在(咨询师、网点等)
|
||||
- [ ] 上一次运行没留下脏数据
|
||||
|
||||
## 失败分类(先分类,再处理)
|
||||
|
||||
| 现象 | 归类 | 处理 |
|
||||
|---|---|---|
|
||||
| 所有用例都失败,连首页都打不开 | **环境** | 修环境,不要动用例 |
|
||||
| 某一条失败,单独跑也失败 | **实现 bug** | 提缺陷给开发 |
|
||||
| 某一条失败,单独跑能过 | **用例没隔离** | 修用例(数据清理/顺序依赖) |
|
||||
| 时好时坏 | **Flaky** | 找硬等待/时间依赖,**不能靠重试掩盖** |
|
||||
| 报错信息不明确 | **断言太弱** | 补具体断言,让失败可读 |
|
||||
| 需求本身有歧义 | **规格问题** | 找 PO 澄清,不在代码里猜 |
|
||||
|
||||
**"重试一次就过了" 不等于通过。** Flaky 用例必须修,否则闸门形同虚设。
|
||||
|
||||
## 定位流程
|
||||
|
||||
```
|
||||
1. 看失败用例的名字与编号 → 确定是哪条 TC
|
||||
2. 单独重跑,确认是否稳定失败 → 排除偶发
|
||||
3. 看 trace / 截图 → playwright-report/ 里看
|
||||
4. 看控制台报错 → list_console_messages
|
||||
5. 看失败的网络请求 → list_network_requests
|
||||
6. 看页面快照 → take_snapshot
|
||||
7. 对照规格 → 是实现不符还是用例写错
|
||||
```
|
||||
|
||||
判定归属:
|
||||
|
||||
- 规则编号明确、实现不符 → **实现 bug**
|
||||
- 规则编号明确、实现符合但与理解不一致 → **用例写错**,改用例
|
||||
- 规则编号不明确 / 规格没覆盖 → **规格有歧义**,找 PO
|
||||
|
||||
## Flaky 常见原因
|
||||
|
||||
| 原因 | 修法 |
|
||||
|---|---|
|
||||
| 硬等待 `waitForTimeout` | 换成显式等待(`expect(...).toBeVisible({timeout})`) |
|
||||
| 依赖上一条用例的数据 | 每条用例自己准备数据 |
|
||||
| 依赖当前时间/日期 | 固定时间(注入或 mock) |
|
||||
| 动画未结束就断言 | 等元素稳定,或用 `toHaveText` 而非 `toBeVisible` |
|
||||
| 并发用例抢数据 | 用例串行化,或数据加唯一后缀 |
|
||||
| 重试掩盖了真问题 | 找到根因,不要靠 `retries` |
|
||||
|
||||
## 报告
|
||||
|
||||
```
|
||||
E2E 验收:<通过 / 有失败>
|
||||
- QA 用例:N/N 通过(对应 docs/test-cases/e2e-cases/test-cases.md)
|
||||
- 耗时:X 分 Y 秒
|
||||
|
||||
失败明细:
|
||||
| 用例 | 归类 | 现象 | 证据 | 归属 |
|
||||
|---|---|---|---|---|
|
||||
| TC-013 预约 + 取消 | 实现 bug | 取消后状态仍为 PENDING | trace + 截图 | 开发 |
|
||||
|
||||
未覆盖:
|
||||
- TC-018 预约管理(用例尚未实现)
|
||||
```
|
||||
|
||||
**如实报告。** 没跑的用例要写进"未覆盖",不能默认算通过。
|
||||
|
||||
## 结论
|
||||
|
||||
| 结论 | 条件 |
|
||||
|---|---|
|
||||
| ✅ 通过 | QA 用例集全绿 + 文本用例逐条勾选 |
|
||||
| 🔄 有失败 | 列出失败明细与归属 |
|
||||
| ⚠️ 未覆盖 | 有用例未实现或有锚点无用例 —— **不能判通过** |
|
||||
117
example-project/.agent/skills/qa-write-cases/SKILL.md
Normal file
117
example-project/.agent/skills/qa-write-cases/SKILL.md
Normal file
@@ -0,0 +1,117 @@
|
||||
---
|
||||
name: qa-write-cases
|
||||
description: 编写 QA 测试用例(TC-xxx 文本用例 + Playwright 自动化实现)。当需求规格已确认,需要把验收标准与业务规则转成可执行用例时使用。
|
||||
---
|
||||
|
||||
# QA:编写测试用例
|
||||
|
||||
QA 用例验证 **系统符合需求规格**,判定权归 QA。它是 **合并闸门**。
|
||||
|
||||
| | QA 测试 | 开发自测 |
|
||||
|---|---|---|
|
||||
| 依据 | 需求规格 | Plan |
|
||||
| 编号 | `TC-xxx` | 无 |
|
||||
| 位置 | `docs/test-cases/e2e-cases/`、`e2e/tests/qa/` | 源码旁、`e2e/tests/dev/` |
|
||||
| 判定 | QA | 开发 |
|
||||
|
||||
## 顺序不能反
|
||||
|
||||
```
|
||||
1. 先写文本用例 → docs/test-cases/e2e-cases/test-cases.md
|
||||
2. 再写自动化实现 → e2e/tests/qa/*.spec.ts
|
||||
```
|
||||
|
||||
**反过来做会漏场景** —— 照着实现写断言,测的是"实现做了什么",不是"需求要求什么"。
|
||||
|
||||
## 第一步:建覆盖矩阵
|
||||
|
||||
从需求规格抽出所有锚点,逐条映射:
|
||||
|
||||
| 规格来源 | 编号 | 对应用例 |
|
||||
|---|---|---|
|
||||
| 验收标准 | `AC-001` | `TC-001` |
|
||||
| 业务规则 | `R-CREATE-001` | `TC-004` |
|
||||
| 权限矩阵 | 角色 × 操作 | `TC-012` |
|
||||
|
||||
**每个锚点至少一条用例。** 有锚点没用例 = 覆盖缺口,不能进验收。
|
||||
|
||||
规格位置:`docs/features/{模块}.md`。
|
||||
|
||||
## 第二步:写文本用例
|
||||
|
||||
`docs/test-cases/e2e-cases/test-cases.md`,格式:
|
||||
|
||||
```markdown
|
||||
## 2. 认证
|
||||
|
||||
| # | 用例 | 步骤 | 预期 | 关联 |
|
||||
|---|---|---|---|---|
|
||||
| TC-006 | 管理员登录成功 | 填写 admin@test.com / password → 提交 | 跳转到 `/admin/dashboard`,显示"管理仪表盘" | AC-002, R-AUTH-001 |
|
||||
| TC-007 | 错误密码提示 | 填写 admin@test.com / wrongpassword → 提交 | 显示错误提示 | AC-003 |
|
||||
```
|
||||
|
||||
| 列 | 要求 |
|
||||
|---|---|
|
||||
| `#` | `TC-xxx`,全局唯一,不复用编号 |
|
||||
| 用例 | 一句话说明场景 |
|
||||
| 步骤 | 可执行的动作,**不含"点击那个按钮"这种模糊表述** |
|
||||
| 预期 | **可观察的结果**,不是"正常工作" |
|
||||
| 关联 | 对应的 `AC-xxx` / `R-xxx` |
|
||||
|
||||
编号规则:
|
||||
|
||||
- 编号 **不复用**:用例删掉了,编号作废,不给新用例用
|
||||
- 编号 **连续分配**,便于看覆盖情况
|
||||
- 手动用例用 `TC-Mxx`,冒烟用 `TC-Sxx`
|
||||
|
||||
## 第三步:写自动化实现
|
||||
|
||||
放在 `e2e/tests/qa/`:
|
||||
|
||||
```ts
|
||||
test('TC-006 管理员登录成功', async ({ page }) => {
|
||||
await page.goto('/login')
|
||||
await page.fill('input[type="email"]', ADMIN_EMAIL)
|
||||
await page.fill('input[type="password"]', ADMIN_PASSWORD)
|
||||
await page.click('button[type="submit"]')
|
||||
await page.waitForURL('**/admin/dashboard', { timeout: 10000 })
|
||||
await expect(page.locator('h1')).toHaveText('管理仪表盘')
|
||||
})
|
||||
```
|
||||
|
||||
要求:
|
||||
|
||||
- **标题必须带编号**,与文本用例一一对应,可双向追溯
|
||||
- 断言要 **具体**:断言文本值、URL、元素可见性,而不是"页面加载成功"
|
||||
- **禁止硬等待**(`waitForTimeout`),用 `expect(...).toBeVisible()` 等显式等待
|
||||
- 用例之间 **不能有顺序依赖**,各自准备数据
|
||||
- 数据准备用共享 helper,不要复制粘贴
|
||||
|
||||
## 覆盖要求
|
||||
|
||||
| 类别 | 必须覆盖 |
|
||||
|---|---|
|
||||
| Happy Path | 每个主流程至少一条 |
|
||||
| 参数错误 | 缺字段、类型错、超长、非法枚举值 |
|
||||
| 权限 | 未登录、角色不足、越权访问他人数据 |
|
||||
| 业务冲突 | 重复提交、时间/库存冲突、状态非法流转 |
|
||||
| 边界 | 空列表、最大分页、临界值 |
|
||||
|
||||
## 自检清单
|
||||
|
||||
- [ ] 每个 `AC-xxx` / `R-xxx` 至少一条用例
|
||||
- [ ] 文本用例与自动化用例编号一一对应
|
||||
- [ ] 自动化标题带 `TC-xxx`
|
||||
- [ ] 预期是可观察的具体结果
|
||||
- [ ] 无硬等待
|
||||
- [ ] 用例可独立重复执行
|
||||
- [ ] 断言够强(不是"不为空"这种)
|
||||
- [ ] `e2e/tests/qa/` 下 **只有** QA 用例,开发自测在 `tests/dev/`
|
||||
|
||||
## 运行
|
||||
|
||||
```bash
|
||||
cd e2e && npm run test:qa
|
||||
```
|
||||
|
||||
用例失败时用 `qa-run-e2e` 定位原因。
|
||||
105
example-project/.agent/skills/qa-write-manual-plan/SKILL.md
Normal file
105
example-project/.agent/skills/qa-write-manual-plan/SKILL.md
Normal file
@@ -0,0 +1,105 @@
|
||||
---
|
||||
name: qa-write-manual-plan
|
||||
description: 编写手动测试计划与冒烟用例集。当自动化覆盖不到的场景、或需要发版前最小回归集时使用。
|
||||
---
|
||||
|
||||
# QA:编写手动测试与冒烟计划
|
||||
|
||||
自动化的盲区用手动补,发版前的判断用冒烟做。
|
||||
|
||||
## 输出位置
|
||||
|
||||
| 产物 | 位置 | 编号 |
|
||||
|---|---|---|
|
||||
| 手动测试用例 | `docs/test-cases/manual-cases/manual-test-cases.md` | `TC-Mxx` |
|
||||
| 冒烟用例 | `docs/test-cases/smoking-cases/smoking-test-cases.md` | `TC-Sxx` |
|
||||
|
||||
## 一、什么场景需要手动
|
||||
|
||||
| 场景 | 为什么自动化不了 |
|
||||
|---|---|
|
||||
| 视觉判断(好不好看、像不像原型) | 断言不了"好看" |
|
||||
| 主观体验(流畅度、易用性) | 没有客观判据 |
|
||||
| 跨设备/跨浏览器差异 | 环境成本高 |
|
||||
| 弱网/断网/异常权限组合 | 难以稳定构造 |
|
||||
| 第三方服务真实交互 | 沙箱不稳定 |
|
||||
|
||||
**先自查:真的自动化不了吗?** 能自动化的不要塞进手动 —— 手动用例会烂尾。
|
||||
|
||||
## 二、手动用例格式
|
||||
|
||||
```markdown
|
||||
| # | 用例 | 前置条件 | 步骤 | 预期 | 执行人 |
|
||||
|---|---|---|---|---|---|
|
||||
| TC-M01 | 后台禁用用户后其登录态失效 | 存在普通用户 user@test.com | 管理员禁用该用户 → 用户端刷新页面 | 用户被强制登出,跳转登录页 | |
|
||||
```
|
||||
|
||||
| 列 | 要求 |
|
||||
|---|---|
|
||||
| `#` | `TC-Mxx`,与 `TC-xxx` 不共用编号空间 |
|
||||
| 前置条件 | **可复现**的初始状态(账号、数据、时间) |
|
||||
| 步骤 | 编号步骤,执行人不需要问"然后呢" |
|
||||
| 预期 | 可观察的具体结果 |
|
||||
| 执行人 | 执行后签字 |
|
||||
|
||||
要求:
|
||||
|
||||
- 每条用例 **独立可执行**,不依赖上一条的结果
|
||||
- 前置数据写清楚怎么准备(种子数据 / 手工造数)
|
||||
- 写明 **环境**:哪个环境、哪个分支
|
||||
- 一次执行完一批,逐条打勾
|
||||
|
||||
## 三、冒烟用例集
|
||||
|
||||
目标:**5 分钟内跑完**,回答一个问题 —— **能不能发**。
|
||||
|
||||
选择原则:
|
||||
|
||||
- 只选 **P0 冒烟点**:服务起不来、登录不了、核心链路断了、数据库连不上
|
||||
- 不选业务细节(那些是回归的事,不是冒烟的事)
|
||||
- 每个冒烟点尽量能自动化 → 在 `e2e/tests/qa/` 里也有对应自动化
|
||||
|
||||
```markdown
|
||||
| # | 用例 | 冒烟点 | 预期 | 自动化 |
|
||||
|---|---|---|---|---|
|
||||
| TC-S01 | 服务启动 | 后端可启动、前端可加载 | 无启动错误,首页 200 | `qa/app.spec.ts` → Public Pages |
|
||||
| TC-S02 | 登录 | 管理员正确凭据登录 | 跳转到 `/admin/dashboard` | `qa/app.spec.ts` → Auth |
|
||||
| TC-S03 | 核心预约链路 | 选咨询师 → 选时间 → 提交 | 预约成功,出现在预约列表 | `qa/app.spec.ts` → User Flows |
|
||||
| TC-S04 | 管理端可读 | 管理员查看用户/预约列表 | 列表正常渲染 | `qa/app.spec.ts` → Admin Flows |
|
||||
| TC-S05 | 数据库连通 | 写入后可读回 | 无连接错误 | `qa/app.spec.ts` |
|
||||
```
|
||||
|
||||
**5 条以内。** 超过 5 分钟就不是冒烟了。
|
||||
|
||||
## 四、两者与 QA 自动化用例的关系
|
||||
|
||||
| | 手动 `TC-Mxx` | 冒烟 `TC-Sxx` | 自动化 `TC-xxx` |
|
||||
|---|---|---|---|
|
||||
| 位置 | `docs/test-cases/manual-cases/` | `docs/test-cases/smoking-cases/` | `docs/test-cases/e2e-cases/` + `e2e/tests/qa/` |
|
||||
| 频率 | 每次验收 | 每次发版 | 每次提交 |
|
||||
| 覆盖 | 自动化的盲区 | P0 最小集 | 需求全量 |
|
||||
| 判定 | QA | QA | QA |
|
||||
|
||||
**冒烟用例应该是自动化用例的子集**,不是另一套。
|
||||
|
||||
## 五、与发布的关系
|
||||
|
||||
冒烟用例是发版准备的最后一关:
|
||||
|
||||
1. 开发自测全绿 → `dev-self-test`
|
||||
2. QA 验收用例集全绿 → `qa-run-e2e`
|
||||
3. 手动用例执行完毕 → 本 skill
|
||||
4. 冒烟用例全绿 → 允许发布 → `dev-release-plan`
|
||||
|
||||
**手动用例没执行完,不能发版。** 不要用"自动化都过了"替代。
|
||||
|
||||
## 自检清单
|
||||
|
||||
- [ ] 每条手动用例独立可执行,前置条件写清楚
|
||||
- [ ] 步骤是编号步骤,执行人不用追问
|
||||
- [ ] 预期是可观察结果
|
||||
- [ ] 冒烟用例 ≤ 5 条、≤ 5 分钟
|
||||
- [ ] 冒烟点都是 P0,不是业务细节
|
||||
- [ ] 能自动化的冒烟点已关联到自动化用例
|
||||
- [ ] 编号空间不混用(`TC-` / `TC-M` / `TC-S`)
|
||||
- [ ] 与 `docs/test-cases/e2e-cases/test-cases.md` 的编号不重复
|
||||
74
example-project/.gitignore
vendored
Normal file
74
example-project/.gitignore
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs
|
||||
hs_err_pid*
|
||||
replay_pid*
|
||||
|
||||
# Maven
|
||||
target/
|
||||
pom.xml.tag
|
||||
pom.xml.releaseBackup
|
||||
pom.xml.versionsBackup
|
||||
pom.xml.next
|
||||
release.properties
|
||||
dependency-reduced-pom.xml
|
||||
buildNumber.properties
|
||||
.mvn/timing.properties
|
||||
.mvn/wrapper/maven-wrapper.jar
|
||||
*.flattened-pom.xml
|
||||
|
||||
# IDE
|
||||
.idea/
|
||||
*.iml
|
||||
*.iws
|
||||
*.ipr
|
||||
.vscode/
|
||||
.settings/
|
||||
.project
|
||||
.classpath
|
||||
.factorypath
|
||||
.springBeans
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# Frontend
|
||||
node_modules/
|
||||
frontend/dist/
|
||||
frontend/.env.local
|
||||
frontend/.env.*.local
|
||||
|
||||
# Env
|
||||
.env
|
||||
.env.local
|
||||
|
||||
# E2E artifacts
|
||||
e2e/playwright-report/
|
||||
e2e/test-results/
|
||||
e2e/screenshots/
|
||||
|
||||
# TypeScript build info
|
||||
*.tsbuildinfo
|
||||
|
||||
# Secret config (use application.yml.example as template)
|
||||
backend/src/main/resources/application.yml
|
||||
8
example-project/.mcp.json
Normal file
8
example-project/.mcp.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"mcpServers": {
|
||||
"chrome-devtools": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "chrome-devtools-mcp@latest"]
|
||||
}
|
||||
}
|
||||
}
|
||||
75
example-project/.overnight-runner/project.yaml
Normal file
75
example-project/.overnight-runner/project.yaml
Normal file
@@ -0,0 +1,75 @@
|
||||
# overnight-runner 项目配置
|
||||
#
|
||||
# 这个文件回答两个问题:
|
||||
# 1. agent 是什么 —— command / args / env
|
||||
# 2. 无人值守时,**默认怎么决策** —— default.prompt + decisions
|
||||
#
|
||||
# 每次用到决策,都会写一条记录到
|
||||
# .overnight-runner/queue/<队列名>/decisions.jsonl
|
||||
# 方便事后回溯"昨晚它替我做了什么决定"。
|
||||
#
|
||||
# 这里的规则是 **全队列共享** 的 —— 决策记录才是 per-queue 的。
|
||||
|
||||
project:
|
||||
name: example-project
|
||||
agent:
|
||||
command: opencode
|
||||
args: ["run", "--dangerously-skip-permissions"]
|
||||
env: {}
|
||||
|
||||
default:
|
||||
# 每次任务都会用的默认提示词。
|
||||
# 占位符:
|
||||
# {{PLAN}} —— plan 文件的全文
|
||||
# {{DECISIONS}} —— 下面的默认决策清单
|
||||
prompt: |
|
||||
你在无人值守模式下工作,不要停下来等待人工确认。
|
||||
|
||||
按下面的方案执行,遇到需要决策的问题,按"默认决策"处理:
|
||||
|
||||
{{DECISIONS}}
|
||||
|
||||
{{PLAN}}
|
||||
|
||||
执行要求:
|
||||
1. 每做出一个决策,输出一行:DECISION: <问题> → <决策>
|
||||
2. 全部完成后输出一行:DONE: <一句话总结>
|
||||
3. 如果无法继续,输出一行:BLOCKED: <原因>
|
||||
|
||||
# 命中不了任何规则时的兜底策略。
|
||||
# 可选:跳过并记录到决策日志 / 采用最安全可回滚的方案 / 停止任务并标记为阻塞
|
||||
onUnknownDecision: 采用最安全、可回滚的方案(优先只改测试代码,不动生产代码),并在最终总结里明确标注这个假设
|
||||
|
||||
# 默认决策规则:agent 遇到这类问题时,直接用这里的答案,不要等人。
|
||||
#
|
||||
# match 是正则(大小写不敏感时用 (?i) 前缀),question 是精确/包含匹配。
|
||||
decisions:
|
||||
- id: test-failure
|
||||
question: 测试失败了,是断言写错还是实现有 bug?
|
||||
match: "测试失败|断言失败|用例失败|mvn test"
|
||||
answer: 先读失败输出定位根因——断言与实际契约不符就按 Plan §9.5 用例清单修断言;确实是实现 bug 就做最小修复并在总结里说明,不要扩大改动范围
|
||||
enabled: true
|
||||
|
||||
- id: db-migration
|
||||
question: 是否执行数据库迁移脚本?
|
||||
match: "数据库迁移|flyway|migration"
|
||||
answer: 先写好回滚脚本,再执行迁移;迁移后跑一遍冒烟用例
|
||||
enabled: true
|
||||
|
||||
- id: missing-plan
|
||||
question: plan 里没有写清楚的部分
|
||||
match: "plan.*(缺失|没有写|不明确)"
|
||||
answer: 按项目现有实现的模式推断,并在最终总结里明确标注这个假设
|
||||
enabled: true
|
||||
|
||||
- id: flaky-test
|
||||
question: 测试偶发失败
|
||||
match: "flaky|偶发|时好时坏"
|
||||
answer: 不要靠重试掩盖,定位根因后修复;在总结里写明根因
|
||||
enabled: true
|
||||
|
||||
- id: scope-creep
|
||||
question: 是否扩大改动范围
|
||||
match: "范围外|额外的改动|顺便"
|
||||
answer: 不扩大范围,把发现的问题记录下来,不要顺手改
|
||||
enabled: true
|
||||
@@ -0,0 +1,6 @@
|
||||
{"at": "2026-11-06T16:34:29+08:00", "task_id": "20261106-20261106-businessrule-datadictionary-api-tests", "question": "测试失败根因判定(Plan §9.5 用例4)", "answer": "实现 bug,不是断言写错:resources/business-rules/*.yml 从未被加载进 Environment(测试中 mybatis-plus.mapper-locations=null 证明 test 的 application.yml 遮蔽了 main 的,且无 spring.config.import 引用这两个 YAML),导致 BusinessRuleConfig 恒为空、BusinessRuleProvider 的 if(!ruleConfig.isEmpty()) 分支永不进入,接口响应永远没有 config 字段;与 docs/designs/api.yaml、docs/designs/topic/businessrule.md、docs/standards/business-rule.md 三处事实文档矛盾 → 做最小修复(不改 API 契约、不改 YAML 文件内容)", "source": "agent", "rule_id": ""}
|
||||
{"at": "2026-11-06T16:41:40+08:00", "task_id": "20261106-20261106-businessrule-datadictionary-api-tests", "question": "db-migration(是否执行数据库迁移脚本)", "answer": "本轮无任何 DDL/表结构变更,目标接口不读写数据库,schema.sql/data.sql 未改动,因此不执行迁移、无需回滚脚本;仅复用 TestBase 既有的 resetAll() 隔离机制", "source": "agent", "rule_id": ""}
|
||||
{"at": "2026-11-06T16:41:40+08:00", "task_id": "20261106-20261106-businessrule-datadictionary-api-tests", "question": "missing-plan(plan 未写清的部分)", "answer": "① Plan §9.5 用例4 的断言以 docs/designs/api.yaml + docs/standards/business-rule.md 定义的契约为准(config 必须存在),而非以当前运行时行为为准——这是本轮唯一的实现侧改动;② RestAssured 5.3.2 的 JsonPath 走 Jayway/GPath,$[*] 写法不被支持,改用隐式遍历路径 ruleName / config.appointment.slot.minMinutes / items.code(已在实现前用探针实测确认);③ 探针文件 ProbeTmpTest.java 仅用于取事实,已删除,未留在仓库", "source": "agent", "rule_id": ""}
|
||||
{"at": "2026-11-06T16:41:40+08:00", "task_id": "20261106-20261106-businessrule-datadictionary-api-tests", "question": "flaky-test(测试偶发失败)", "answer": "未观察到偶发失败:新用例连续 3 轮 10/10 全绿,全量 28/28 全绿;根因排查集中在配置装载一次性完成(@PostConstruct 缓存),无并发写入,不存在竞态,无需修复", "source": "agent", "rule_id": ""}
|
||||
{"at": "2026-11-06T16:41:40+08:00", "task_id": "20261106-20261106-businessrule-datadictionary-api-tests", "question": "scope-creep(是否扩大改动范围)", "answer": "不扩大,记录 3 项发现不修:① AGENTS.md §7 示例 JSON 写 message/timestamp,与代码实际 ErrorResponse(errorCode/errorMessage/data) 不符(Plan §6.4 已记录,建议单独开一轮);② config.auth.publicEndpoints 因 Map<String,Object> 绑定被序列化为 {\"0\":...} 而非数组(属既有 Map 绑定设计的固有结果,非本轮引入);③ docs/designs/topic/businessrule.md 的\"配置路径\"列指向 application.yml→jwt.expiration / SecurityConfig(hardcoded),与现在对外暴露的 config.auth.* 来源(business-rules/auth.yml)不完全一致", "source": "agent", "rule_id": ""}
|
||||
{"at": "2026-11-06T16:41:40+08:00", "task_id": "20261106-20261106-businessrule-datadictionary-api-tests", "question": "文档同步检查", "answer": "已更新:docs/standards/business-rule.md 补 4 行\"加载方式\"说明(防同类静默回归);application.yml.example 补 spring.config.import(该文件才是入库版本,真实 application.yml 被 gitignore);docs/designs/api.yaml、db-schema.md、topic/businessrule.md、topic/data-dict.md、docs/e2e-cases/ 均不涉及(契约、库表、规则与字典定义均未变)", "source": "agent", "rule_id": ""}
|
||||
@@ -0,0 +1,9 @@
|
||||
queue:
|
||||
- id: 20261106-20261106-businessrule-datadictionary-api-tests
|
||||
plan: docs/plans/20261106-businessrule-datadictionary-api-tests.md
|
||||
priority: 10
|
||||
role: DEV
|
||||
- id: 20261106-20261106-fix-public-endpoints-and-error-doc
|
||||
plan: docs/plans/20261106-fix-public-endpoints-and-error-doc.md
|
||||
priority: 10
|
||||
role: DEV
|
||||
354
example-project/AGENTS.md
Normal file
354
example-project/AGENTS.md
Normal file
@@ -0,0 +1,354 @@
|
||||
# 架构与工程规范(咨询预约单体应用)
|
||||
|
||||
本文件定义本代码库的架构边界、分层规则、模块职责与工程规范。目标是让新成员与自动化工具在不了解上下文的情况下,也能按一致方式新增功能、扩展模块并避免破坏依赖关系。
|
||||
|
||||
## 1. 仓库拓扑
|
||||
|
||||
这是一个全栈工程(Java 17 / Spring Boot 3.2.x / Vue 3 + TypeScript),主要模块如下:
|
||||
|
||||
- `backend/`:Spring Boot 后端(四层 DDD 单体)
|
||||
- `frontend/`:Vue 3 + TypeScript 前端(Vite 构建)
|
||||
|
||||
运行时形态:
|
||||
|
||||
- Client → Vue 前端 (Vite dev server :5173) → 反向代理 `/api` → Spring Boot 后端 (:8080)
|
||||
- 后端直连 MySQL,不经过 BFF 层
|
||||
- JWT 由后端直接签发与校验(HMAC-SHA256)
|
||||
|
||||
## 2. 横切关注点:鉴权与用户上下文
|
||||
|
||||
当前约定的鉴权与上下文传递:
|
||||
|
||||
- 前端登录后获得 JWT token,存储于 Pinia store / localStorage
|
||||
- Axios 拦截器在请求头添加 `Authorization: Bearer <token>`
|
||||
- 后端 `JwtAuthenticationFilter` 解析 token,将 `UserContext` 写入 `UserContextHolder`(ThreadLocal)
|
||||
- 应用层通过 `SecurityUtils` / `UserContextHolder` 获取当前用户上下文
|
||||
|
||||
约束:
|
||||
|
||||
- 后端自行校验 JWT(不在前端或网关层做)
|
||||
- 应用层/领域层不得依赖 Web 框架对象(Request/Response),只能依赖 `UserContextHolder` 或方法参数传入的 `userId`
|
||||
- Admin 端路由使用 `/admin/**` 路径,后端 `SecurityConfig` 限制为 `ROLE_ADMIN`
|
||||
|
||||
## 3. 标准分层
|
||||
|
||||
业务代码遵循四层结构(包路径 `com.consultation.*`):
|
||||
|
||||
- `adapter`:对外适配层(HTTP Controller),只做协议转换与参数校验(`adapter/rest/`)
|
||||
- `application`:用例编排层(AppService / Service),组合 domain 行为、调用 repository、管理事务边界
|
||||
- `domain`:领域模型层(aggregate / vo / DomainService),承载业务不变量与状态机
|
||||
- `infrastructure`:基础设施层(`infrastructure/persistence/`),提供 repository 实现、MyBatis-Plus mapper、PO 等
|
||||
|
||||
依赖方向(强制):
|
||||
|
||||
- adapter → application → domain
|
||||
- infrastructure → domain(实现 domain 定义的接口)
|
||||
- domain 不得依赖 infrastructure / adapter / Web 框架
|
||||
|
||||
## 4. DTO、Assembler 与 Converter 约定
|
||||
|
||||
DTO 约定:
|
||||
|
||||
- 写操作入参使用 `*Command` 或 Request DTO(`adapter/rest/dto/`)
|
||||
- 对外返回使用 `*Response`(`adapter/rest/dto/`)
|
||||
- domain 与 infrastructure 之间使用 `*Converter` 做 PO ⟷ domain 转换
|
||||
- application 层使用 `*Assembler` 做 domain ⟷ DTO 转换
|
||||
|
||||
映射约定:
|
||||
|
||||
- adapter 不直接操作 domain 实体
|
||||
- 入参先在 Controller 中校验(`@Valid`),以 DTO 传入 application 层
|
||||
- 使用手动转换(非 MapStruct),遵循现有 Converter/Assembler 命名
|
||||
|
||||
## 5. 持久化规则(MyBatis-Plus)
|
||||
|
||||
当前技术栈:
|
||||
|
||||
- MyBatis-Plus 3.5.5(Spring Boot 3 starter)
|
||||
- PO(持久化对象)放在 `infrastructure/persistence/po/`
|
||||
- Mapper 放在 `infrastructure/persistence/mapper/`
|
||||
- Repository:domain 只定义 repository 接口(聚合根维度),infrastructure 提供实现(`*RepositoryImpl`)
|
||||
- 主键使用 UUID 字符串(`VARCHAR(64)`),由应用层生成
|
||||
|
||||
聚合与一致性:
|
||||
|
||||
- 聚合内的子实体由 repository 在同一事务内完成装配与持久化
|
||||
- 复杂查询优先走 Mapper + DTO,写操作必须通过聚合行为与 repository
|
||||
|
||||
## 6. 事务边界
|
||||
|
||||
事务边界统一放在 application 层:
|
||||
|
||||
- 以一个用例为单位在 AppService 方法上标注 `@Transactional`
|
||||
- domain 方法不直接开启/提交事务
|
||||
- `@Transactional` 不在 Controller 或 Repository 层使用
|
||||
|
||||
## 7. 错误模型与异常处理
|
||||
|
||||
所有异常由 `GlobalExceptionHandler`(`@RestControllerAdvice`)统一转换为 `ErrorResponse`:
|
||||
|
||||
| 抛出什么 | HTTP | errorCode | 什么时候用 |
|
||||
|---|---|---|---|
|
||||
| `IllegalArgumentException` | 400 | `PARAM_ERROR` | 参数不合法、查不到的资源(异常消息即 `errorMessage`) |
|
||||
| `IllegalStateException` | 409 | `BUSINESS_CONFLICT` | 业务状态冲突(如同一时段被占用) |
|
||||
| `MethodArgumentNotValidException` | 400 | `VALIDATION_ERROR` | `@Valid` 字段级校验失败(自动抛出,不手写) |
|
||||
| 其它 `Exception` | 500 | `SYSTEM_ERROR` | 兜底,消息固定为「系统繁忙」 |
|
||||
|
||||
写新代码时的约定:
|
||||
|
||||
- 参数不合法 / 资源不存在 → 抛 `IllegalArgumentException`
|
||||
- 业务状态冲突 → 抛 `IllegalStateException`
|
||||
- 不要裸抛 `RuntimeException`:会落到 500 兜底,业务语义丢失
|
||||
|
||||
鉴权失败由 Spring Security 直接返回 **401 / 403**,**不走** `ErrorResponse` 包装。
|
||||
|
||||
对外响应体为 `GlobalExceptionHandler.ErrorResponse`,字段是 `errorMessage`(**不是** `message`):
|
||||
|
||||
```json
|
||||
{
|
||||
"errorCode": "BUSINESS_CONFLICT",
|
||||
"errorMessage": "该时段已被占用",
|
||||
"data": null
|
||||
}
|
||||
```
|
||||
|
||||
错误码清单与"当前实现映射"见 `docs/designs/topic/error-code.md`。
|
||||
|
||||
## 8. 领域设计:聚合与规则
|
||||
|
||||
当前定义的聚合:
|
||||
|
||||
- `User`:用户(email + password + role + status)
|
||||
- `Consultant`:咨询师(name + title + specialties + status)
|
||||
- `Appointment`:预约(user + consultant + date + time + status)
|
||||
- `Branch`:网点(name + address + phone + status)
|
||||
|
||||
业务规则引擎(`domain/businessrule/`):
|
||||
|
||||
- `IBusinessRule` 接口:getCode() / getDescription() / getCategory()
|
||||
- 规则以枚举实现 `IBusinessRule`(`AppointmentRule`、`AuthRule`)
|
||||
- 规则配置 YAML 文件位于 `resources/business-rules/`
|
||||
- `BusinessRuleController` 提供 GET 查询接口
|
||||
|
||||
数据字典(`domain/datadictionary/`):
|
||||
|
||||
- `Description` 接口:枚举实现,提供 getCode() / getDescription()
|
||||
- 5 个注册字典类型:USER_ROLE / USER_STATUS / APPOINTMENT_STATUS / CONSULTANT_STATUS / BRANCH_STATUS
|
||||
- `DemoDataDictionaryType` 完成注册
|
||||
- `DataDictionaryController` 提供 GET 查询接口
|
||||
|
||||
## 9. 预约状态机
|
||||
|
||||
```
|
||||
┌──────────┐
|
||||
┌────►│ CANCELLED │◄────┐
|
||||
│ └──────────┘ │
|
||||
┌─────────┐ │ ┌──────────┐ │
|
||||
│ PENDING │─────┼────►│CONFIRMED │────►│ COMPLETED
|
||||
└─────────┘ │ └──────────┘ │
|
||||
│ │
|
||||
└──────────────────────┘
|
||||
```
|
||||
|
||||
- PENDING:初始状态
|
||||
- CONFIRMED:管理员确认
|
||||
- COMPLETED:完成(终态)
|
||||
- CANCELLED:从任意非终态取消
|
||||
- 状态变更由 domain 层 `Appointment.canCancel()` 等守卫方法控制
|
||||
|
||||
## 10. 测试规范
|
||||
|
||||
### 两类用例的归属
|
||||
|
||||
测试用例分两层,**归属看"谁定义、谁判定",不是"谁敲的代码"**:
|
||||
|
||||
| | 开发自测 | QA 测试 |
|
||||
|---|---|---|
|
||||
| 验证什么 | 代码按 Plan 的设计工作 | 系统符合需求规格 |
|
||||
| 谁定义 / 谁判定 | 开发本人 | **QA** |
|
||||
| 用例编号 | 无编号,命名表达意图 | `TC-xxx`,与文本用例一一对应 |
|
||||
| 存放位置 | 源码旁(`*Test.java`、`*.test.ts`) | `docs/` 用例库 + `e2e/tests/qa/` |
|
||||
| 合并闸门 | 否 | **是** |
|
||||
| 失败意味着 | 代码写错了 | 需求没实现 / 理解有偏差 / 规格有歧义 |
|
||||
|
||||
约定:
|
||||
|
||||
- QA 用例的自动化实现可由开发代写,但定义权与判定权归 QA
|
||||
- 开发自测全绿 ≠ 需求被实现,不能替代 QA 测试
|
||||
- QA 用例必须先有文本用例(`docs/test-cases/e2e-cases/`),再写自动化
|
||||
|
||||
完整规范见 `docs/standards/test.md`。
|
||||
|
||||
### 测试技术栈
|
||||
|
||||
- JUnit 5 + SpringBootTest + RANDOM_PORT
|
||||
- RestAssured 做 API 集成测试
|
||||
- MariaDB4j 启动临时 MySQL 实例(替代 H2),确保 MySQL 方言兼容
|
||||
- 测试使用 `schema.sql` + `data.sql` 初始化数据
|
||||
- ResetDbService 在每个 `@BeforeEach` 中 TRUNCATE 全表
|
||||
|
||||
### 测试环境配置
|
||||
|
||||
- 测试使用 `application.yml`(test resources),配置 MariaDB4j
|
||||
- Flyway 在测试中禁用(`spring.flyway.enabled=false`)
|
||||
- `@ActiveProfiles("test")` 在 TestBase 中设置
|
||||
|
||||
### 开发自测覆盖要求
|
||||
|
||||
- 每个 API **必须** 有对应的集成测试
|
||||
- 至少覆盖:
|
||||
- 1 个 Happy Path
|
||||
- 关键失败分支(参数错误 / 权限不足 / 业务冲突)
|
||||
- DB 相关用例必须可重复执行,不依赖执行顺序
|
||||
- 前端 Component/Composable 单元测试使用 Vitest(与源码同目录,`*.test.ts`)
|
||||
- 命名:类名 `{被测Controller}Test`,方法名 `should_{action}_{expectedResult}`(不写 `TC-` 编号)
|
||||
|
||||
### QA 测试要求
|
||||
|
||||
- 需求规格的每条验收标准、每条业务规则 → 至少 1 条 QA 用例
|
||||
- 编号统一 `TC-xxx`,文本用例与自动化用例共用同一编号
|
||||
- 文本用例集中在 `docs/test-cases/`:`e2e-cases/`、`manual-cases/`、`smoking-cases/`(QA)与 `dev-self-cases/`(开发自测索引);E2E 自动化在 `e2e/tests/qa/`
|
||||
- 用例可独立重复执行,不依赖执行顺序
|
||||
|
||||
### E2E 测试
|
||||
|
||||
- Playwright + Chromium,按归属分两层:
|
||||
|
||||
| 目录 | 归属 | 说明 |
|
||||
|---|---|---|
|
||||
| `e2e/tests/qa/` | **QA 测试** | 验收用例的自动化实现,与 `docs/test-cases/e2e-cases/test-cases.md` 一一对应,合并闸门 |
|
||||
| `e2e/tests/dev/` | 开发自测 | 开发期快速反馈,不作为验收依据 |
|
||||
|
||||
- 运行命令:
|
||||
|
||||
```bash
|
||||
bash e2e-run.sh # 启动前后端 + 执行全部 E2E
|
||||
cd e2e && npm run test:qa # 只跑 QA 验收用例(合并闸门)
|
||||
cd e2e && npm run test:dev # 只跑开发自测用例
|
||||
```
|
||||
|
||||
## 11. 前端规范
|
||||
|
||||
- Vue 3 Composition API + `<script setup>` 语法
|
||||
- UI 组件库:**Element Plus**(业务前端;需求演示原型为独立 Vite 工程 `docs/features/iteration1/prototypes/`)
|
||||
- Pinia 管理全局状态(auth store 位于 `src/stores/auth.ts`)
|
||||
- Vue Router 4 管理路由,布局文件位于 `src/layouts/`
|
||||
- Axios 统一封装,请求拦截器自动添加 JWT,响应拦截器处理 401 跳转
|
||||
- 全局 CSS 变量位于 `src/styles/variables.css`
|
||||
- 视图文件按子系统分组:`src/views/user/`、`src/views/admin/`(咨询师端后续按 `consultant/` 扩展)
|
||||
- Service 层封装 API 调用(`src/services/xxxService.ts`),每个领域一个文件
|
||||
- Composable 封装可复用逻辑(`src/composables/useXxx.ts`),如 `useBooking`、`useAuth`
|
||||
- 页面级组件组合 Composable + UI 组件,视图内不含直接 API 调用
|
||||
|
||||
## 12. PR / 变更检查清单
|
||||
|
||||
- 分层检查:adapter 不含业务逻辑;domain 不依赖 infrastructure;事务边界在 application
|
||||
- 错误处理:参数/资源错误抛 `IllegalArgumentException`,业务冲突抛 `IllegalStateException`,避免裸 `RuntimeException`
|
||||
- API 设计:RESTful 风格,路径统一 `/api/v1/resource`,admin 使用 `/admin/resource`
|
||||
- 安全:不记录 token / 敏感信息;对外接口做鉴权检查
|
||||
- 数据字典:新增枚举需要同时更新 `DemoDataDictionaryType` 与 `docs/designs/topic/data-dict.md`
|
||||
- 业务规则:新增规则需要同时更新 YAML 配置与 `docs/designs/topic/businessrule.md`
|
||||
- 数据库变更:新增 DDL 需同时更新 Flyway migration 文件、测试 `schema.sql`、以及 `docs/designs/db-schema.md`
|
||||
- 验证:本地运行 `mvn test` 确认全部通过,`npm run build` 确认前端编译通过
|
||||
|
||||
## 13. 文档结构
|
||||
|
||||
文档体系位于 `docs/` 目录,所有 AI Agent 及开发人员必须遵守以下路径约定:
|
||||
|
||||
```
|
||||
docs/
|
||||
├── features/ # 需求规格(过程文档)
|
||||
│ ├── _template.md # 需求规格模板
|
||||
│ └── iteration1/ # 咨询师预约平台样例(骨架)
|
||||
│ ├── README.md # 迭代索引
|
||||
│ ├── account.md
|
||||
│ ├── consultant-discovery.md
|
||||
│ ├── booking.md
|
||||
│ ├── consultant-onboarding.md
|
||||
│ ├── consultant-schedule.md
|
||||
│ ├── consultant-fulfillment.md
|
||||
│ ├── settlement.md
|
||||
│ ├── admin-ops.md
|
||||
│ ├── platform-capability.md
|
||||
│ └── prototypes/ # 独立 Vite 原型 demo(Element Plus,:5174)
|
||||
├── plans/ # 技术方案(过程文档)
|
||||
│ ├── _template.md # 技术方案模板
|
||||
│ └── 20260619-project-plan.md
|
||||
├── designs/ # 设计文档(事实文档)
|
||||
│ ├── api.yaml # API 接口定义
|
||||
│ ├── db-schema.md # 数据库规格
|
||||
│ ├── domain-model.md # 领域模型
|
||||
│ ├── booking-flow.md # 业务流程
|
||||
│ └── topic/ # 其他技术主题
|
||||
│ ├── authentication.md
|
||||
│ ├── architecture.md
|
||||
│ ├── 001-4-layer-ddd.md
|
||||
│ ├── 002-uuid-string-pk.md
|
||||
│ ├── 003-mybatis-plus-vs-jpa.md
|
||||
│ ├── 004-jwt-stateless-auth.md
|
||||
│ ├── 005-threadlocal-usercontext.md
|
||||
│ ├── businessrule.md
|
||||
│ └── data-dict.md
|
||||
├── standards/ # 代码规范(事实文档)
|
||||
│ ├── architecture.md # 架构规范
|
||||
│ ├── naming.md # 命名规范
|
||||
│ ├── security.md # 安全规范
|
||||
│ ├── api-design.md # API 设计规范
|
||||
│ ├── layers.md # 分层规范
|
||||
│ ├── db.md # 数据库规范
|
||||
│ ├── error.md # 错误处理规范
|
||||
│ ├── test.md # 测试规范
|
||||
│ ├── business-rule.md # 业务规则规范
|
||||
│ ├── data-dictionary.md # 数据字典规范
|
||||
│ └── templates/ # 代码模版
|
||||
│ ├── 01-ddd-controller.md
|
||||
│ ├── 02-ddd-appservice.md
|
||||
│ ├── 03-ddd-assembler.md
|
||||
│ ├── 04-ddd-aggregate.md
|
||||
│ ├── 05-ddd-domain-service.md
|
||||
│ ├── 06-ddd-repository-interface.md
|
||||
│ ├── 07-ddd-repository-impl.md
|
||||
│ ├── 08-ddd-converter.md
|
||||
│ ├── 09-ddd-po-mapper.md
|
||||
│ └── 10-global-exception-handler.md
|
||||
└── test-cases/ # 测试用例文本基线
|
||||
├── e2e-cases/ # QA:E2E 验收用例文本基线(TC-xxx)
|
||||
│ └── test-cases.md
|
||||
├── manual-cases/ # QA:手动执行用例(TC-Mxx)
|
||||
│ └── manual-test-cases.md
|
||||
├── smoking-cases/ # QA:冒烟用例(TC-Sxx)
|
||||
│ └── smoking-test-cases.md
|
||||
└── dev-self-cases/ # 开发自测:可选场景索引
|
||||
└── README.md
|
||||
```
|
||||
|
||||
> `docs/test-cases/` 下 `e2e-cases/`、`manual-cases/`、`smoking-cases/` 为 **QA 测试** 产物(定义权与判定权归 QA);
|
||||
> `dev-self-cases/` 为开发自测可选索引;可执行自测仍在源码旁与 `e2e/tests/dev/`。归属详见 §10 与 `docs/standards/test.md`。
|
||||
|
||||
### 同步要求
|
||||
|
||||
- 每轮任务完成后,必须检查 `docs/designs/` 中的内容是否因本次变更而需要更新
|
||||
- 新增/修改 API → 更新 `docs/designs/api.yaml`
|
||||
- 新增/修改数据表 → 更新 `docs/designs/db-schema.md`
|
||||
- 新增/修改业务规则 → 更新 `docs/designs/topic/businessrule.md`
|
||||
- 新增/修改数据字典 → 更新 `docs/designs/topic/data-dict.md`
|
||||
|
||||
### 执行检查点
|
||||
|
||||
每轮任务提交描述中必须包含:
|
||||
|
||||
- [ ] `docs/` 同步检查(已更新 / 不涉及)
|
||||
|
||||
## 14. 开发流程(每轮需求的标准执行步骤)
|
||||
|
||||
每轮需求开发必须按以下顺序执行,严禁跳过或调换步骤:
|
||||
|
||||
1. **Plan 等待确认**:在 `docs/plans/` 下根据模版创建 Plan,包含技术方案与任务拆分,等待人工确认后再继续。
|
||||
2. **编写 QA 测试用例**:在 `docs/test-cases/e2e-cases/` 下编写本轮需求的 E2E 测试用例(文本格式,编号 `TC-xxx`),由 QA 主导判定。**先写文本用例,再写自动化**。
|
||||
3. **编写开发自测(API 测试)**:根据 Plan 在 `backend/src/test/` 中编写 RestAssured 集成测试(API 级别),运行成功但断言失败(TDD 红牌阶段)。
|
||||
4. **编写实现**:编写单元测试 + 实现代码(后端 application/domain/adapter 层),通过 `mvn compile` 编译。
|
||||
5. **运行开发自测**:运行 `mvn test` 修复失败的测试及其他错误,直至全部通过;同时补齐 `e2e/tests/qa/` 中本轮需求的自动化实现。
|
||||
6. **浏览器调试**:使用 Playwright(`./e2e-run.sh`)启动前后端并调试,确认前端视觉效果和交互功能正常。如果报错使用 chrome-devtool-mcp 查看错误。
|
||||
7. **运行 QA 验收**:`cd e2e && npm run test:qa` 全部通过,并交由 QA 对照 `docs/test-cases/e2e-cases/` 逐条验收。
|
||||
|
||||
> 第 3~6 步是 **开发自测**(对开发负责);第 2、7 步是 **QA 测试**(对需求负责,是合并闸门)。开发自测全绿不等于需求已实现。
|
||||
128
example-project/README.md
Normal file
128
example-project/README.md
Normal file
@@ -0,0 +1,128 @@
|
||||
# 咨询预约平台 / Consultation Booking Platform
|
||||
|
||||
基于 DDD 四层架构的全栈咨询预约单体应用,支持用户注册登录、咨询师浏览、预约管理及后台管理。
|
||||
|
||||
## 技术栈
|
||||
|
||||
| 层级 | 技术 |
|
||||
|------|------|
|
||||
| 前端 | Vue 3 + TypeScript + Vite + Pinia + Vue Router 4 |
|
||||
| 后端 | Java 17 + Spring Boot 3.2 + Spring Security + MyBatis-Plus 3.5 |
|
||||
| 数据库 | MySQL 8.0 + Flyway 迁移 |
|
||||
| 认证 | JWT(HMAC-SHA256,jjwt 0.12) |
|
||||
| 测试 | JUnit 5 + RestAssured + MariaDB4j / Playwright |
|
||||
|
||||
## 项目结构
|
||||
|
||||
```
|
||||
├── backend/ # Spring Boot 后端
|
||||
│ └── src/main/java/com/consultation/
|
||||
│ ├── adapter/rest/ # HTTP 适配层(Controller)
|
||||
│ ├── application/ # 用例编排层(Service + Assembler)
|
||||
│ ├── domain/ # 领域模型层(Aggregate + VO + DomainService)
|
||||
│ └── infrastructure/ # 基础设施层(Persistence + Security + Config)
|
||||
├── frontend/ # Vue 3 前端
|
||||
│ └── src/
|
||||
│ ├── views/ # 页面视图(user / admin / auth / home)
|
||||
│ ├── components/ # 通用组件
|
||||
│ ├── composables/ # 可复用逻辑
|
||||
│ ├── stores/ # Pinia 状态管理
|
||||
│ ├── api/ # API 封装
|
||||
│ └── router/ # 路由配置
|
||||
├── e2e/ # Playwright E2E 测试
|
||||
│ └── tests/
|
||||
│ ├── qa/ # QA 验收用例(合并闸门)
|
||||
│ └── dev/ # 开发自测用例
|
||||
├── docs/ # 文档体系
|
||||
│ ├── features/ # 需求规格(iteration1 样例骨架)
|
||||
│ ├── plans/ # 技术方案
|
||||
│ ├── designs/ # 设计文档
|
||||
│ ├── standards/ # 代码规范
|
||||
│ └── test-cases/ # 测试用例文本基线
|
||||
│ ├── e2e-cases/ # QA 验收用例(TC-xxx)
|
||||
│ ├── manual-cases/ # QA 手动用例
|
||||
│ ├── smoking-cases/ # QA 冒烟用例
|
||||
│ └── dev-self-cases/ # 开发自测索引
|
||||
└── AGENTS.md # AI Agent 工程规范
|
||||
```
|
||||
|
||||
## 环境要求
|
||||
|
||||
- Java 17+
|
||||
- Node.js 18+ / npm 9+
|
||||
- MySQL 8.0(或使用 MariaDB4j 自动启动本地实例)
|
||||
|
||||
## 快速开始
|
||||
|
||||
### 1. 配置后端
|
||||
|
||||
```bash
|
||||
cd backend
|
||||
cp src/main/resources/application.yml.example src/main/resources/application.yml
|
||||
# 编辑 application.yml,填入 MySQL 密码和 JWT 密钥
|
||||
```
|
||||
|
||||
### 2. 启动后端
|
||||
|
||||
```bash
|
||||
cd backend
|
||||
mvn spring-boot:run
|
||||
# 后端启动于 http://localhost:8080
|
||||
```
|
||||
|
||||
### 3. 启动前端
|
||||
|
||||
```bash
|
||||
cd frontend
|
||||
npm install
|
||||
npm run dev
|
||||
# 前端启动于 http://localhost:5173,/api 请求自动代理到后端
|
||||
```
|
||||
|
||||
## 测试
|
||||
|
||||
用例分两层:**开发自测**(对开发负责)与 **QA 测试**(对需求负责,合并闸门)。详见 [`docs/standards/test.md`](docs/standards/test.md)。
|
||||
|
||||
### 开发自测
|
||||
|
||||
```bash
|
||||
cd backend
|
||||
mvn test
|
||||
# 使用 MariaDB4j 自动启动临时 MySQL,无需手动建库
|
||||
|
||||
cd e2e
|
||||
npm run test:dev
|
||||
# 只跑开发自测的 E2E 用例(视觉冒烟等),不阻塞合并
|
||||
```
|
||||
|
||||
### QA 测试(合并闸门)
|
||||
|
||||
```bash
|
||||
cd e2e
|
||||
npm run test:qa
|
||||
# QA 验收用例集,与 docs/test-cases/e2e-cases/test-cases.md 的 TC-xxx 一一对应
|
||||
|
||||
# 一键启动前后端 + 执行全部 E2E
|
||||
bash e2e-run.sh
|
||||
```
|
||||
|
||||
## 架构概览
|
||||
|
||||
```
|
||||
Client → Vue 前端 (:5173) → /api 代理 → Spring Boot 后端 (:8080) → MySQL
|
||||
```
|
||||
|
||||
- **adapter**:协议转换与参数校验,不含业务逻辑
|
||||
- **application**:用例编排,组合 domain 行为,管理事务边界
|
||||
- **domain**:领域模型与业务不变量,不依赖任何基础设施
|
||||
- **infrastructure**:持久化实现、安全配置、异常处理
|
||||
|
||||
## 文档
|
||||
|
||||
详见 [`docs/`](docs/) 目录:
|
||||
|
||||
- **需求规格**:`docs/features/iteration1/` — 咨询师预约平台样例(v0.1;独立 Vite 原型:`prototypes/`,`npm run dev` :5174)
|
||||
- **技术方案**:`docs/plans/` — 技术实现方案与任务拆分
|
||||
- **设计文档**:`docs/designs/` — API 定义、数据库设计、领域模型、技术主题
|
||||
- **代码规范**:`docs/standards/` — 架构、命名、安全、分层等规范及代码模板
|
||||
- **测试用例**:`docs/test-cases/{e2e,manual,smoking,dev-self}-cases/`
|
||||
105
example-project/backend/pom.xml
Normal file
105
example-project/backend/pom.xml
Normal file
@@ -0,0 +1,105 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
<groupId>com.consultation</groupId>
|
||||
<artifactId>consultation-backend</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<mybatis-plus.version>3.5.5</mybatis-plus.version>
|
||||
<jjwt.version>0.12.3</jjwt.version>
|
||||
<lombok.version>1.18.38</lombok.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
|
||||
<version>${mybatis-plus.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.flywaydb</groupId>
|
||||
<artifactId>flyway-mysql</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-api</artifactId>
|
||||
<version>${jjwt.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-impl</artifactId>
|
||||
<version>${jjwt.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-jackson</artifactId>
|
||||
<version>${jjwt.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.rest-assured</groupId>
|
||||
<artifactId>rest-assured</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration><excludes><exclude><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></exclude></excludes></configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.38</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.consultation;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class ConsultationApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ConsultationApplication.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.consultation.adapter.rest;
|
||||
|
||||
import com.consultation.application.assembler.AppointmentAssembler;
|
||||
import com.consultation.application.assembler.BranchAssembler;
|
||||
import com.consultation.application.assembler.ConsultantAssembler;
|
||||
import com.consultation.application.assembler.UserAssembler;
|
||||
import com.consultation.application.service.AdminService;
|
||||
import com.consultation.application.service.AppointmentService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/admin")
|
||||
@RequiredArgsConstructor
|
||||
@PreAuthorize("hasRole('ADMIN')")
|
||||
public class AdminController {
|
||||
|
||||
private final AdminService adminService;
|
||||
private final AppointmentService appointmentService;
|
||||
private final ConsultantAssembler consultantAssembler;
|
||||
private final UserAssembler userAssembler;
|
||||
private final BranchAssembler branchAssembler;
|
||||
private final AppointmentAssembler appointmentAssembler;
|
||||
|
||||
|
||||
@GetMapping("/dashboard")
|
||||
public Map<String, Object> dashboard() { return adminService.dashboard(); }
|
||||
|
||||
@GetMapping("/users")
|
||||
public List<UserAssembler.UserResponse> users() { return adminService.allUsers(); }
|
||||
|
||||
@PutMapping("/users/{id}/toggle-status")
|
||||
public ResponseEntity<Void> toggleUserStatus(@PathVariable String id) { adminService.toggleUserStatus(id); return ResponseEntity.ok().build(); }
|
||||
|
||||
@GetMapping("/consultants")
|
||||
public ResponseEntity<List<ConsultantAssembler.ConsultantResponse>> consultants() {
|
||||
return ResponseEntity.ok(adminService.allConsultants().stream().map(consultantAssembler::toResponse).toList());
|
||||
}
|
||||
|
||||
@GetMapping("/appointments")
|
||||
public List<AppointmentAssembler.AppointmentResponse> appointments() {
|
||||
return appointmentService.getAllAppointments();
|
||||
}
|
||||
|
||||
@GetMapping("/branches")
|
||||
public List<BranchAssembler.BranchResponse> branches() {
|
||||
return adminService.allBranches();
|
||||
}
|
||||
|
||||
@PostMapping("/branches")
|
||||
public BranchAssembler.BranchResponse createBranch(@RequestBody Map<String, String> body) {
|
||||
return adminService.createBranch(body.get("name"), body.get("address"), body.get("phone"));
|
||||
}
|
||||
|
||||
@PutMapping("/branches/{id}")
|
||||
public ResponseEntity<Void> updateBranch(@PathVariable String id, @RequestBody Map<String, String> body) {
|
||||
adminService.updateBranch(id, body.get("name"), body.get("address"), body.get("phone")); return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
@DeleteMapping("/branches/{id}")
|
||||
public ResponseEntity<Void> deleteBranch(@PathVariable String id) { adminService.deleteBranch(id); return ResponseEntity.ok().build(); }
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.consultation.adapter.rest;
|
||||
|
||||
import com.consultation.application.service.AppointmentService;
|
||||
import com.consultation.infrastructure.security.SecurityUtils;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/appointments")
|
||||
@RequiredArgsConstructor
|
||||
public class AppointmentController {
|
||||
|
||||
private final AppointmentService appointmentService;
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity<?> list() {
|
||||
return ResponseEntity.ok(appointmentService.getMyAppointments(SecurityUtils.currentUserId()));
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<?> get(@PathVariable String id) { return ResponseEntity.ok(appointmentService.getById(id)); }
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<?> create(@Valid @RequestBody CreateRequest r) {
|
||||
return ResponseEntity.ok(appointmentService.create(SecurityUtils.currentUserId(),
|
||||
r.consultantId, r.branchId, r.date, r.startTime, r.endTime, r.note));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}/cancel")
|
||||
public ResponseEntity<Void> cancel(@PathVariable String id, @RequestBody Map<String, String> body) {
|
||||
appointmentService.cancel(id, SecurityUtils.currentUserId(), body.getOrDefault("reason", "用户取消"));
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class CreateRequest {
|
||||
@NotBlank String consultantId;
|
||||
String branchId;
|
||||
@NotBlank String date;
|
||||
@NotBlank String startTime;
|
||||
@NotBlank String endTime;
|
||||
String note;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.consultation.adapter.rest;
|
||||
|
||||
import com.consultation.application.service.AuthService;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.Email;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/auth")
|
||||
@RequiredArgsConstructor
|
||||
public class AuthController {
|
||||
|
||||
private final AuthService authService;
|
||||
|
||||
@PostMapping("/register")
|
||||
public ResponseEntity<?> register(@Valid @RequestBody RegisterRequest r) {
|
||||
return ResponseEntity.ok(authService.register(r.email, r.password, r.name, r.phone));
|
||||
}
|
||||
|
||||
@PostMapping("/login")
|
||||
public ResponseEntity<?> login(@Valid @RequestBody LoginRequest r) {
|
||||
return ResponseEntity.ok(authService.login(r.email, r.password));
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class RegisterRequest {
|
||||
@NotBlank @Email String email;
|
||||
@NotBlank @Size(min = 8) String password;
|
||||
@NotBlank String name;
|
||||
String phone;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class LoginRequest {
|
||||
@NotBlank @Email String email;
|
||||
@NotBlank String password;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.consultation.adapter.rest;
|
||||
|
||||
import com.consultation.application.service.BusinessRuleAppService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/business-rules")
|
||||
@RequiredArgsConstructor
|
||||
public class BusinessRuleController {
|
||||
|
||||
private final BusinessRuleAppService service;
|
||||
|
||||
@GetMapping
|
||||
public List<Map<String, Object>> list() {
|
||||
return service.getAllRules();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.consultation.adapter.rest;
|
||||
|
||||
import com.consultation.application.service.ConsultantService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/consultants")
|
||||
@RequiredArgsConstructor
|
||||
public class ConsultantController {
|
||||
|
||||
private final ConsultantService consultantService;
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity<?> list() { return ResponseEntity.ok(consultantService.findAllActive()); }
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<?> get(@PathVariable String id) { return ResponseEntity.ok(consultantService.getById(id)); }
|
||||
|
||||
@GetMapping("/{id}/slots")
|
||||
public ResponseEntity<List<Map<String, String>>> slots(@PathVariable String id, @RequestParam String date) {
|
||||
return ResponseEntity.ok(consultantService.getAvailableSlots(id, date));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.consultation.adapter.rest;
|
||||
|
||||
import com.consultation.application.service.DataDictionaryAppService;
|
||||
import com.consultation.domain.datadictionary.DataDictionary;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/data-dictionaries")
|
||||
@RequiredArgsConstructor
|
||||
public class DataDictionaryController {
|
||||
|
||||
private final DataDictionaryAppService service;
|
||||
|
||||
@GetMapping
|
||||
public List<DataDictionary> list() {
|
||||
return service.getAll();
|
||||
}
|
||||
|
||||
@GetMapping("/{type}")
|
||||
public DataDictionary getByType(@PathVariable String type) {
|
||||
return service.getByType(type);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.consultation.adapter.rest;
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/home")
|
||||
public class HomeController {
|
||||
|
||||
@GetMapping("/info")
|
||||
public ResponseEntity<Map<String, Object>> info() {
|
||||
return ResponseEntity.ok(Map.of(
|
||||
"title", "专业咨询服务",
|
||||
"description", "我们提供专业的在线咨询服务,预约方便快捷。",
|
||||
"consultants", java.util.List.of()
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.consultation.adapter.rest;
|
||||
|
||||
import com.consultation.application.service.UserService;
|
||||
import com.consultation.infrastructure.security.SecurityUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/users")
|
||||
@RequiredArgsConstructor
|
||||
public class UserController {
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
@GetMapping("/me")
|
||||
public ResponseEntity<?> profile() { return ResponseEntity.ok(userService.getProfile(SecurityUtils.currentUserId())); }
|
||||
|
||||
@PutMapping("/me")
|
||||
public ResponseEntity<?> update(@RequestBody Map<String, String> body) {
|
||||
return ResponseEntity.ok(userService.updateProfile(SecurityUtils.currentUserId(), body.get("name"), body.get("phone")));
|
||||
}
|
||||
|
||||
@PutMapping("/me/password")
|
||||
public ResponseEntity<Void> changePw(@RequestBody Map<String, String> body) {
|
||||
userService.changePassword(SecurityUtils.currentUserId(), body.get("oldPassword"), body.get("newPassword"));
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.consultation.application.assembler;
|
||||
|
||||
import com.consultation.domain.aggregate.Appointment;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class AppointmentAssembler {
|
||||
public AppointmentResponse toResponse(Appointment a) {
|
||||
if (a == null) return null;
|
||||
return AppointmentResponse.builder().id(a.getId()).userId(a.getUserId()).consultantId(a.getConsultantId())
|
||||
.branchId(a.getBranchId()).appointmentDate(a.getAppointmentDate().toString())
|
||||
.startTime(a.getStartTime()).endTime(a.getEndTime()).durationMinutes(a.getDurationMinutes())
|
||||
.status(a.getStatus().name()).note(a.getNote()).cancelReason(a.getCancelReason()).build();
|
||||
}
|
||||
|
||||
@Data @Builder
|
||||
public static class AppointmentResponse {
|
||||
String id; String userId; String consultantId; String branchId;
|
||||
String appointmentDate; String startTime; String endTime;
|
||||
int durationMinutes; String status; String note; String cancelReason;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.consultation.application.assembler;
|
||||
|
||||
import com.consultation.domain.aggregate.Branch;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class BranchAssembler {
|
||||
public BranchResponse toResponse(Branch b) {
|
||||
if (b == null) return null;
|
||||
return BranchResponse.builder().id(b.getId()).name(b.getName()).address(b.getAddress())
|
||||
.phone(b.getPhone()).status(b.getStatus().name()).build();
|
||||
}
|
||||
|
||||
@Data @Builder
|
||||
public static class BranchResponse { String id; String name; String address; String phone; String status; }
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.consultation.application.assembler;
|
||||
|
||||
import com.consultation.domain.aggregate.Consultant;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ConsultantAssembler {
|
||||
public ConsultantResponse toResponse(Consultant c) {
|
||||
if (c == null) return null;
|
||||
return ConsultantResponse.builder().id(c.getId()).name(c.getName()).title(c.getTitle()).bio(c.getBio())
|
||||
.specialties(c.getSpecialties()).avatar(c.getAvatar()).branchId(c.getBranchId())
|
||||
.status(c.getStatus().name()).sortOrder(c.getSortOrder()).build();
|
||||
}
|
||||
|
||||
@Data @Builder
|
||||
public static class ConsultantResponse {
|
||||
String id; String name; String title; String bio; String specialties;
|
||||
String avatar; String branchId; String status; int sortOrder;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.consultation.application.assembler;
|
||||
|
||||
import com.consultation.domain.aggregate.User;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class UserAssembler {
|
||||
public UserResponse toResponse(User u) {
|
||||
if (u == null) return null;
|
||||
return UserResponse.builder().id(u.getId()).email(u.getEmail()).name(u.getName())
|
||||
.phone(u.getPhone()).role(u.getRole().name()).status(u.getStatus().name()).build();
|
||||
}
|
||||
public AuthResponse toAuth(User u, String token) {
|
||||
return AuthResponse.builder().token(token).user(toResponse(u)).build();
|
||||
}
|
||||
|
||||
@Data @Builder
|
||||
public static class UserResponse { String id; String email; String name; String phone; String role; String status; }
|
||||
@Data @Builder
|
||||
public static class AuthResponse { String token; UserResponse user; }
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.consultation.application.service;
|
||||
|
||||
import com.consultation.application.assembler.BranchAssembler;
|
||||
import com.consultation.application.assembler.UserAssembler;
|
||||
import com.consultation.domain.aggregate.Branch;
|
||||
import com.consultation.domain.aggregate.Consultant;
|
||||
import com.consultation.domain.aggregate.User;
|
||||
import com.consultation.domain.repository.AppointmentRepository;
|
||||
import com.consultation.domain.repository.BranchRepository;
|
||||
import com.consultation.domain.repository.ConsultantRepository;
|
||||
import com.consultation.domain.repository.UserRepository;
|
||||
import com.consultation.domain.vo.UserStatus;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class AdminService {
|
||||
|
||||
private final UserRepository userRepo;
|
||||
private final BranchRepository branchRepo;
|
||||
private final ConsultantRepository consultantRepo;
|
||||
private final AppointmentRepository appointmentRepo;
|
||||
private final BranchAssembler branchAssembler;
|
||||
private final UserAssembler userAssembler;
|
||||
|
||||
public Map<String, Object> dashboard() {
|
||||
return Map.of("totalUsers", userRepo.findAll().size(), "totalConsultants", consultantRepo.count(),
|
||||
"totalAppointments", appointmentRepo.count(), "pendingAppointments", appointmentRepo.countByStatus("PENDING"),
|
||||
"totalBranches", branchRepo.count());
|
||||
}
|
||||
|
||||
public List<UserAssembler.UserResponse> allUsers() { return userRepo.findAll().stream().map(userAssembler::toResponse).toList(); }
|
||||
public List<Consultant> allConsultants() { return consultantRepo.findAll(); }
|
||||
public List<BranchAssembler.BranchResponse> allBranches() { return branchRepo.findAll().stream().map(branchAssembler::toResponse).toList(); }
|
||||
|
||||
@Transactional
|
||||
public void toggleUserStatus(String id) {
|
||||
User u = userRepo.findById(id).orElseThrow(() -> new IllegalArgumentException("用户不存在"));
|
||||
User upd = User.builder().id(u.getId()).email(u.getEmail()).password(u.getPassword())
|
||||
.name(u.getName()).phone(u.getPhone()).role(u.getRole())
|
||||
.status(u.getStatus() == UserStatus.ACTIVE ? UserStatus.DISABLED : UserStatus.ACTIVE).build();
|
||||
userRepo.update(upd);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public BranchAssembler.BranchResponse createBranch(String name, String address, String phone) {
|
||||
return branchAssembler.toResponse(branchRepo.save(Branch.builder().id(UUID.randomUUID().toString())
|
||||
.name(name).address(address).phone(phone).status(Branch.BranchStatus.ACTIVE).build()));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void updateBranch(String id, String name, String address, String phone) {
|
||||
Branch b = branchRepo.findById(id).orElseThrow(() -> new IllegalArgumentException("网点不存在"));
|
||||
branchRepo.update(Branch.builder().id(id).name(name != null ? name : b.getName())
|
||||
.address(address != null ? address : b.getAddress()).phone(phone != null ? phone : b.getPhone())
|
||||
.status(b.getStatus()).build());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteBranch(String id) { branchRepo.deleteById(id); }
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.consultation.application.service;
|
||||
|
||||
import com.consultation.application.assembler.AppointmentAssembler;
|
||||
import com.consultation.domain.aggregate.Appointment;
|
||||
import com.consultation.domain.aggregate.Consultant;
|
||||
import com.consultation.domain.repository.AppointmentRepository;
|
||||
import com.consultation.domain.repository.ConsultantRepository;
|
||||
import com.consultation.domain.service.AppointmentConflictService;
|
||||
import com.consultation.domain.vo.AppointmentStatus;
|
||||
import com.consultation.domain.vo.TimeSlot;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class AppointmentService {
|
||||
|
||||
private final AppointmentRepository appointmentRepo;
|
||||
private final ConsultantRepository consultantRepo;
|
||||
private final AppointmentConflictService conflictService = new AppointmentConflictService();
|
||||
private final AppointmentAssembler assembler;
|
||||
|
||||
public AppointmentAssembler.AppointmentResponse getById(String id) {
|
||||
return assembler.toResponse(appointmentRepo.findById(id).orElseThrow(() -> new IllegalArgumentException("预约不存在")));
|
||||
}
|
||||
|
||||
public List<AppointmentAssembler.AppointmentResponse> getMyAppointments(String userId) {
|
||||
return appointmentRepo.findByUserId(userId, 1, 100).stream().map(assembler::toResponse).toList();
|
||||
}
|
||||
|
||||
public List<AppointmentAssembler.AppointmentResponse> getAllAppointments() {
|
||||
return appointmentRepo.findAll(1, 1000).stream().map(assembler::toResponse).toList();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public AppointmentAssembler.AppointmentResponse create(String userId, String consultantId, String branchId,
|
||||
String date, String startTime, String endTime, String note) {
|
||||
Consultant consultant = consultantRepo.findById(consultantId)
|
||||
.orElseThrow(() -> new IllegalArgumentException("咨询师不存在"));
|
||||
if (!consultant.isAvailable()) throw new IllegalStateException("该咨询师当前不可预约");
|
||||
|
||||
LocalDate ld = LocalDate.parse(date);
|
||||
LocalTime st = LocalTime.parse(startTime);
|
||||
LocalTime et = LocalTime.parse(endTime);
|
||||
var existing = appointmentRepo.findByConsultantIdAndDate(consultantId, ld);
|
||||
conflictService.validateNoConflict(existing, new TimeSlot(ld, st, et));
|
||||
|
||||
Appointment a = appointmentRepo.save(Appointment.builder().id(UUID.randomUUID().toString())
|
||||
.userId(userId).consultantId(consultantId).branchId(branchId)
|
||||
.appointmentDate(ld).startTime(startTime).endTime(endTime)
|
||||
.durationMinutes((int) java.time.Duration.between(st, et).toMinutes())
|
||||
.status(AppointmentStatus.PENDING).note(note).build());
|
||||
return assembler.toResponse(a);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void cancel(String id, String userId, String reason) {
|
||||
Appointment a = appointmentRepo.findById(id).orElseThrow(() -> new IllegalArgumentException("预约不存在"));
|
||||
if (!a.canCancel()) throw new IllegalStateException("当前状态不允许取消");
|
||||
Appointment upd = Appointment.builder().id(a.getId()).userId(a.getUserId()).consultantId(a.getConsultantId())
|
||||
.branchId(a.getBranchId()).appointmentDate(a.getAppointmentDate()).startTime(a.getStartTime())
|
||||
.endTime(a.getEndTime()).durationMinutes(a.getDurationMinutes()).status(AppointmentStatus.CANCELLED)
|
||||
.note(a.getNote()).cancelReason(reason != null ? reason : "用户取消").build();
|
||||
appointmentRepo.update(upd);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.consultation.application.service;
|
||||
|
||||
import com.consultation.application.assembler.UserAssembler;
|
||||
import com.consultation.domain.aggregate.User;
|
||||
import com.consultation.domain.repository.UserRepository;
|
||||
import com.consultation.domain.service.PasswordService;
|
||||
import com.consultation.domain.vo.UserRole;
|
||||
import com.consultation.domain.vo.UserStatus;
|
||||
import com.consultation.infrastructure.security.JwtTokenProvider;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class AuthService {
|
||||
|
||||
private final UserRepository userRepo;
|
||||
private final PasswordService passwordService;
|
||||
private final JwtTokenProvider tokenProvider;
|
||||
private final UserAssembler assembler;
|
||||
|
||||
@Transactional
|
||||
public UserAssembler.AuthResponse register(String email, String password, String name, String phone) {
|
||||
if (userRepo.existsByEmail(email)) throw new IllegalArgumentException("邮箱已被注册");
|
||||
User user = userRepo.save(User.builder().id(UUID.randomUUID().toString()).email(email)
|
||||
.password(passwordService.encode(password)).name(name).phone(phone)
|
||||
.role(UserRole.ROLE_USER).status(UserStatus.ACTIVE).build());
|
||||
return assembler.toAuth(user, tokenProvider.generate(user.getId(), user.getEmail(), user.getRole().name()));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public UserAssembler.AuthResponse login(String email, String password) {
|
||||
User user = userRepo.findByEmail(email).orElseThrow(() -> new IllegalArgumentException("邮箱或密码错误"));
|
||||
if (!user.isActive()) throw new IllegalStateException("账户已被停用");
|
||||
if (!passwordService.matches(password, user.getPassword())) throw new IllegalArgumentException("邮箱或密码错误");
|
||||
return assembler.toAuth(user, tokenProvider.generate(user.getId(), user.getEmail(), user.getRole().name()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.consultation.application.service;
|
||||
|
||||
import com.consultation.infrastructure.config.BusinessRuleProvider;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class BusinessRuleAppService {
|
||||
|
||||
private final BusinessRuleProvider provider;
|
||||
|
||||
public List<Map<String, Object>> getAllRules() {
|
||||
return provider.getAllRules();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.consultation.application.service;
|
||||
|
||||
import com.consultation.application.assembler.ConsultantAssembler;
|
||||
import com.consultation.domain.aggregate.Consultant;
|
||||
import com.consultation.domain.repository.AppointmentRepository;
|
||||
import com.consultation.domain.repository.ConsultantRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ConsultantService {
|
||||
|
||||
private final ConsultantRepository consultantRepo;
|
||||
private final AppointmentRepository appointmentRepo;
|
||||
private final ConsultantAssembler assembler;
|
||||
|
||||
public List<ConsultantAssembler.ConsultantResponse> findAllActive() {
|
||||
return consultantRepo.findAllActive().stream().map(assembler::toResponse).toList();
|
||||
}
|
||||
|
||||
public ConsultantAssembler.ConsultantResponse getById(String id) {
|
||||
return assembler.toResponse(consultantRepo.findById(id).orElseThrow(() -> new IllegalArgumentException("咨询师不存在")));
|
||||
}
|
||||
|
||||
public List<Map<String, String>> getAvailableSlots(String consultantId, String date) {
|
||||
if (!consultantRepo.existsById(consultantId)) return List.of();
|
||||
LocalDate localDate = LocalDate.parse(date);
|
||||
var booked = new HashSet<String>();
|
||||
appointmentRepo.findByConsultantIdAndDate(consultantId, localDate).stream()
|
||||
.filter(a -> a.getStatus() != com.consultation.domain.vo.AppointmentStatus.CANCELLED)
|
||||
.forEach(a -> booked.add(a.getStartTime()));
|
||||
|
||||
List<Map<String, String>> slots = new ArrayList<>();
|
||||
for (int h = 9; h < 18; h++) {
|
||||
String s = String.format("%02d:00", h);
|
||||
String e = String.format("%02d:00", h + 1);
|
||||
if (!booked.contains(s)) slots.add(Map.of("startTime", s, "endTime", e));
|
||||
}
|
||||
return slots;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public ConsultantAssembler.ConsultantResponse create(String name, String title, String bio, String specialties, String avatar, String branchId, int sortOrder) {
|
||||
Consultant c = consultantRepo.save(Consultant.builder().id(UUID.randomUUID().toString()).name(name)
|
||||
.title(title).bio(bio).specialties(specialties).avatar(avatar).branchId(branchId)
|
||||
.status(Consultant.ConsultantStatus.ACTIVE).sortOrder(sortOrder).build());
|
||||
return assembler.toResponse(c);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public ConsultantAssembler.ConsultantResponse update(String id, String name, String title, String bio, String specialties) {
|
||||
Consultant existing = consultantRepo.findById(id).orElseThrow(() -> new IllegalArgumentException("咨询师不存在"));
|
||||
Consultant upd = Consultant.builder().id(id).name(name != null ? name : existing.getName())
|
||||
.title(title != null ? title : existing.getTitle()).bio(bio != null ? bio : existing.getBio())
|
||||
.specialties(specialties != null ? specialties : existing.getSpecialties())
|
||||
.avatar(existing.getAvatar()).branchId(existing.getBranchId()).status(existing.getStatus())
|
||||
.sortOrder(existing.getSortOrder()).build();
|
||||
consultantRepo.update(upd);
|
||||
return assembler.toResponse(upd);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void delete(String id) { consultantRepo.deleteById(id); }
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.consultation.application.service;
|
||||
|
||||
import com.consultation.domain.datadictionary.DataDictionary;
|
||||
import com.consultation.domain.datadictionary.DataDictionaryUtil;
|
||||
import com.consultation.domain.datadictionary.DemoDataDictionaryType;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class DataDictionaryAppService {
|
||||
|
||||
public List<DataDictionary> getAll() {
|
||||
return DataDictionaryUtil.allDictionaries(DemoDataDictionaryType.values());
|
||||
}
|
||||
|
||||
public DataDictionary getByType(String typeName) {
|
||||
return Arrays.stream(DemoDataDictionaryType.values())
|
||||
.filter(t -> t.name().equalsIgnoreCase(typeName))
|
||||
.findFirst()
|
||||
.map(DataDictionaryUtil::toDataDictionary)
|
||||
.orElseThrow(() -> new IllegalArgumentException("字典类型不存在: " + typeName));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.consultation.application.service;
|
||||
|
||||
import com.consultation.application.assembler.UserAssembler;
|
||||
import com.consultation.domain.aggregate.User;
|
||||
import com.consultation.domain.repository.UserRepository;
|
||||
import com.consultation.domain.service.PasswordService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class UserService {
|
||||
|
||||
private final UserRepository userRepo;
|
||||
private final PasswordService passwordService;
|
||||
private final UserAssembler assembler;
|
||||
|
||||
public UserAssembler.UserResponse getProfile(String userId) {
|
||||
return assembler.toResponse(userRepo.findById(userId).orElseThrow(() -> new IllegalArgumentException("用户不存在")));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public UserAssembler.UserResponse updateProfile(String userId, String name, String phone) {
|
||||
User u = userRepo.findById(userId).orElseThrow(() -> new IllegalArgumentException("用户不存在"));
|
||||
User upd = User.builder().id(u.getId()).email(u.getEmail()).password(u.getPassword())
|
||||
.name(name != null ? name : u.getName()).phone(phone != null ? phone : u.getPhone())
|
||||
.role(u.getRole()).status(u.getStatus()).build();
|
||||
userRepo.update(upd);
|
||||
return assembler.toResponse(upd);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void changePassword(String userId, String oldPw, String newPw) {
|
||||
User u = userRepo.findById(userId).orElseThrow(() -> new IllegalArgumentException("用户不存在"));
|
||||
if (!passwordService.matches(oldPw, u.getPassword())) throw new IllegalArgumentException("原密码错误");
|
||||
User upd = User.builder().id(u.getId()).email(u.getEmail()).password(passwordService.encode(newPw))
|
||||
.name(u.getName()).phone(u.getPhone()).role(u.getRole()).status(u.getStatus()).build();
|
||||
userRepo.update(upd);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.consultation.domain.aggregate;
|
||||
|
||||
import com.consultation.domain.vo.AppointmentStatus;
|
||||
import lombok.Builder;
|
||||
import lombok.Value;
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Value @Builder
|
||||
public class Appointment {
|
||||
String id; String userId; String consultantId; String branchId;
|
||||
LocalDate appointmentDate; String startTime; String endTime;
|
||||
int durationMinutes; AppointmentStatus status; String note; String cancelReason;
|
||||
|
||||
public boolean isOwnedBy(String uid) { return userId.equals(uid); }
|
||||
public boolean canCancel() { return status == AppointmentStatus.PENDING || status == AppointmentStatus.CONFIRMED; }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.consultation.domain.aggregate;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Value;
|
||||
|
||||
@Value @Builder
|
||||
public class Branch {
|
||||
String id; String name; String address; String phone; BranchStatus status;
|
||||
public enum BranchStatus implements com.consultation.domain.datadictionary.Description {
|
||||
ACTIVE("营业中"), DISABLED("已关闭");
|
||||
private final String description;
|
||||
BranchStatus(String description) { this.description = description; }
|
||||
@Override public String getCode() { return name(); }
|
||||
@Override public String getDescription() { return description; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.consultation.domain.aggregate;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Value;
|
||||
|
||||
@Value @Builder
|
||||
public class Consultant {
|
||||
String id; String name; String title; String bio; String specialties;
|
||||
String avatar; String branchId; ConsultantStatus status; int sortOrder;
|
||||
|
||||
public enum ConsultantStatus implements com.consultation.domain.datadictionary.Description {
|
||||
ACTIVE("可预约"), DISABLED("不可预约");
|
||||
private final String description;
|
||||
ConsultantStatus(String description) { this.description = description; }
|
||||
@Override public String getCode() { return name(); }
|
||||
@Override public String getDescription() { return description; }
|
||||
}
|
||||
public boolean isAvailable() { return status == ConsultantStatus.ACTIVE; }
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.consultation.domain.aggregate;
|
||||
|
||||
import com.consultation.domain.vo.UserRole;
|
||||
import com.consultation.domain.vo.UserStatus;
|
||||
import lombok.Builder;
|
||||
import lombok.Value;
|
||||
|
||||
@Value @Builder
|
||||
public class User {
|
||||
String id;
|
||||
String email;
|
||||
String password;
|
||||
String name;
|
||||
String phone;
|
||||
UserRole role;
|
||||
UserStatus status;
|
||||
|
||||
public boolean isAdmin() { return role == UserRole.ROLE_ADMIN; }
|
||||
public boolean isActive() { return status == UserStatus.ACTIVE; }
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.consultation.domain.businessrule;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public enum AppointmentRule implements IBusinessRule {
|
||||
CONFLICT_DETECTION("appointment_conflict_detection", "同一咨询师同一时段不可重复预约"),
|
||||
SLOT_INTERVAL("appointment_slot_interval", "预约时段间隔为 60 分钟"),
|
||||
AVAILABLE_HOURS("appointment_available_hours", "可预约时段为 09:00-18:00"),
|
||||
CANCEL_WINDOW("appointment_cancel_window", "PENDING / CONFIRMED 状态可取消");
|
||||
|
||||
private final String ruleName;
|
||||
private final String description;
|
||||
|
||||
@Override public String getRuleName() { return ruleName; }
|
||||
@Override public String getDescription() { return description; }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.consultation.domain.businessrule;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public enum AuthRule implements IBusinessRule {
|
||||
PASSWORD_MIN_LENGTH("auth_password_min_length", "密码最少 8 位"),
|
||||
TOKEN_EXPIRATION("auth_token_expiration", "JWT 有效期 24 小时"),
|
||||
PASSWORD_ALGORITHM("auth_password_algorithm", "密码使用 BCrypt 加密");
|
||||
|
||||
private final String ruleName;
|
||||
private final String description;
|
||||
|
||||
@Override public String getRuleName() { return ruleName; }
|
||||
@Override public String getDescription() { return description; }
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.consultation.domain.businessrule;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
@Component
|
||||
@ConfigurationProperties
|
||||
public class BusinessRuleConfig {
|
||||
|
||||
private Map<String, Object> appointment = new HashMap<>();
|
||||
|
||||
private AuthConfig auth = new AuthConfig();
|
||||
|
||||
@Data
|
||||
public static class AuthConfig {
|
||||
|
||||
private PasswordConfig password = new PasswordConfig();
|
||||
|
||||
private TokenConfig token = new TokenConfig();
|
||||
|
||||
/**
|
||||
* 免鉴权端点列表。YAML 里写成序列,若这里声明为 Map<String, Object>,
|
||||
* 会被 Spring Boot 的 binder 绑成以 0/1/2… 为键的 Map,序列化出错误结构。
|
||||
*/
|
||||
private List<String> publicEndpoints = new ArrayList<>(List.of(
|
||||
"/api/v1/auth/**",
|
||||
"/api/v1/home/**",
|
||||
"/api/v1/consultants/**",
|
||||
"/api/v1/data-dictionaries/**",
|
||||
"/api/v1/business-rules/**"));
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class PasswordConfig {
|
||||
|
||||
private int minLength = 8;
|
||||
|
||||
private String algorithm = "BCrypt";
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class TokenConfig {
|
||||
|
||||
private long expirationMs = 86400000L;
|
||||
|
||||
private String algorithm = "HMAC-SHA256";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.consultation.domain.businessrule;
|
||||
|
||||
public interface IBusinessRule {
|
||||
String getRuleName();
|
||||
String getDescription();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.consultation.domain.datadictionary;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Value;
|
||||
import java.util.List;
|
||||
|
||||
@Value @Builder
|
||||
public class DataDictionary {
|
||||
String typeName;
|
||||
String description;
|
||||
List<Item> items;
|
||||
|
||||
@Value @Builder
|
||||
public static class Item {
|
||||
String code;
|
||||
String description;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.consultation.domain.datadictionary;
|
||||
|
||||
public interface DataDictionaryType {
|
||||
Class<? extends Description> getClazz();
|
||||
String getDescription();
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.consultation.domain.datadictionary;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public final class DataDictionaryUtil {
|
||||
|
||||
private DataDictionaryUtil() {}
|
||||
|
||||
public static DataDictionary toDataDictionary(DataDictionaryType type) {
|
||||
var items = Arrays.stream(type.getClazz().getEnumConstants())
|
||||
.map(e -> DataDictionary.Item.builder().code(e.getCode()).description(e.getDescription()).build())
|
||||
.toList();
|
||||
return DataDictionary.builder().typeName(((Enum<?>) type).name()).description(type.getDescription()).items(items).build();
|
||||
}
|
||||
|
||||
public static List<DataDictionary> allDictionaries(DataDictionaryType[] types) {
|
||||
return Arrays.stream(types).map(DataDictionaryUtil::toDataDictionary).toList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.consultation.domain.datadictionary;
|
||||
|
||||
import com.consultation.domain.aggregate.Branch;
|
||||
import com.consultation.domain.aggregate.Consultant;
|
||||
import com.consultation.domain.vo.AppointmentStatus;
|
||||
import com.consultation.domain.vo.UserRole;
|
||||
import com.consultation.domain.vo.UserStatus;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public enum DemoDataDictionaryType implements DataDictionaryType {
|
||||
USER_ROLE(UserRole.class, "用户角色"),
|
||||
USER_STATUS(UserStatus.class, "用户状态"),
|
||||
APPOINTMENT_STATUS(AppointmentStatus.class, "预约状态"),
|
||||
CONSULTANT_STATUS(Consultant.ConsultantStatus.class, "咨询师状态"),
|
||||
BRANCH_STATUS(Branch.BranchStatus.class, "网点状态");
|
||||
|
||||
private final Class<? extends Description> clazz;
|
||||
private final String description;
|
||||
|
||||
@Override public Class<? extends Description> getClazz() { return clazz; }
|
||||
@Override public String getDescription() { return description; }
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.consultation.domain.datadictionary;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
public interface Description {
|
||||
String getCode();
|
||||
String getDescription();
|
||||
default Map<String, String> getExtraFields() { return Collections.emptyMap(); }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.consultation.domain.repository;
|
||||
|
||||
import com.consultation.domain.aggregate.Appointment;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface AppointmentRepository {
|
||||
Optional<Appointment> findById(String id);
|
||||
List<Appointment> findByUserId(String userId, int page, int pageSize);
|
||||
List<Appointment> findByConsultantIdAndDate(String consultantId, LocalDate date);
|
||||
List<Appointment> findAll(int page, int pageSize);
|
||||
Appointment save(Appointment a);
|
||||
void update(Appointment a);
|
||||
long count();
|
||||
long countByStatus(String status);
|
||||
long countByUserId(String userId);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.consultation.domain.repository;
|
||||
|
||||
import com.consultation.domain.aggregate.Branch;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface BranchRepository {
|
||||
Optional<Branch> findById(String id);
|
||||
List<Branch> findAll();
|
||||
Branch save(Branch b);
|
||||
void update(Branch b);
|
||||
void deleteById(String id);
|
||||
long count();
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.consultation.domain.repository;
|
||||
|
||||
import com.consultation.domain.aggregate.Consultant;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface ConsultantRepository {
|
||||
Optional<Consultant> findById(String id);
|
||||
List<Consultant> findAllActive();
|
||||
List<Consultant> findAll();
|
||||
Consultant save(Consultant c);
|
||||
void update(Consultant c);
|
||||
void deleteById(String id);
|
||||
long count();
|
||||
boolean existsById(String id);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.consultation.domain.repository;
|
||||
|
||||
import com.consultation.domain.aggregate.User;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface UserRepository {
|
||||
Optional<User> findById(String id);
|
||||
Optional<User> findByEmail(String email);
|
||||
List<User> findAll();
|
||||
User save(User user);
|
||||
void update(User user);
|
||||
boolean existsByEmail(String email);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.consultation.domain.service;
|
||||
|
||||
import com.consultation.domain.aggregate.Appointment;
|
||||
import com.consultation.domain.vo.AppointmentStatus;
|
||||
import com.consultation.domain.vo.TimeSlot;
|
||||
import java.util.List;
|
||||
|
||||
public class AppointmentConflictService {
|
||||
|
||||
public void validateNoConflict(List<Appointment> existing, TimeSlot requested) {
|
||||
boolean conflict = existing.stream().anyMatch(a ->
|
||||
a.getAppointmentDate().equals(requested.date()) &&
|
||||
a.getStartTime().equals(requested.startTime().toString()) &&
|
||||
a.getStatus() != AppointmentStatus.CANCELLED);
|
||||
if (conflict) throw new IllegalStateException("该时间段已被预约");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.consultation.domain.service;
|
||||
|
||||
public interface PasswordService {
|
||||
String encode(String raw);
|
||||
boolean matches(String raw, String encoded);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.consultation.domain.vo;
|
||||
|
||||
import com.consultation.domain.datadictionary.Description;
|
||||
|
||||
public enum AppointmentStatus implements Description {
|
||||
PENDING("待确认"),
|
||||
CONFIRMED("已确认"),
|
||||
COMPLETED("已完成"),
|
||||
CANCELLED("已取消");
|
||||
|
||||
private final String description;
|
||||
AppointmentStatus(String description) { this.description = description; }
|
||||
@Override public String getCode() { return name(); }
|
||||
@Override public String getDescription() { return description; }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.consultation.domain.vo;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
|
||||
public record TimeSlot(LocalDate date, LocalTime startTime, LocalTime endTime) {
|
||||
public int durationMinutes() { return (int) Duration.between(startTime, endTime).toMinutes(); }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.consultation.domain.vo;
|
||||
|
||||
import com.consultation.domain.datadictionary.Description;
|
||||
|
||||
public enum UserRole implements Description {
|
||||
ROLE_USER("普通用户"),
|
||||
ROLE_ADMIN("管理员");
|
||||
|
||||
private final String description;
|
||||
UserRole(String description) { this.description = description; }
|
||||
@Override public String getCode() { return name(); }
|
||||
@Override public String getDescription() { return description; }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.consultation.domain.vo;
|
||||
|
||||
import com.consultation.domain.datadictionary.Description;
|
||||
|
||||
public enum UserStatus implements Description {
|
||||
ACTIVE("正常"),
|
||||
DISABLED("已停用");
|
||||
|
||||
private final String description;
|
||||
UserStatus(String description) { this.description = description; }
|
||||
@Override public String getCode() { return name(); }
|
||||
@Override public String getDescription() { return description; }
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.consultation.infrastructure.config;
|
||||
|
||||
import com.consultation.domain.businessrule.BusinessRuleConfig;
|
||||
import com.consultation.domain.businessrule.IBusinessRule;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class BusinessRuleProvider {
|
||||
|
||||
private final BusinessRuleConfig config;
|
||||
private final List<IBusinessRule> ruleDefinitions;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final Map<String, Map<String, Object>> ruleCache = new LinkedHashMap<>();
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
Map<String, Object> projected = projectConfig();
|
||||
for (IBusinessRule rule : ruleDefinitions) {
|
||||
Map<String, Object> detail = new LinkedHashMap<>();
|
||||
detail.put("ruleName", rule.getRuleName());
|
||||
detail.put("description", rule.getDescription());
|
||||
|
||||
Map<String, Object> ruleConfig = new LinkedHashMap<>();
|
||||
addIfPresent(ruleConfig, "appointment", projected.get("appointment"));
|
||||
addIfPresent(ruleConfig, "auth", projected.get("auth"));
|
||||
if (!ruleConfig.isEmpty()) detail.put("config", ruleConfig);
|
||||
|
||||
ruleCache.put(rule.getRuleName(), detail);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> getAllRules() {
|
||||
return new ArrayList<Map<String, Object>>(ruleCache.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* 把强类型的配置对象投影成 Map,保持对外返回结构为 {@code List<Map<String, Object>>}。
|
||||
* JSON 形状属于基础设施关注点,故投影放在 infrastructure 层,domain 不依赖 ObjectMapper。
|
||||
*/
|
||||
private Map<String, Object> projectConfig() {
|
||||
return objectMapper.convertValue(config, new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
}
|
||||
|
||||
private void addIfPresent(Map<String, Object> target, String key, Object source) {
|
||||
if (source instanceof Map<?, ?> map && !map.isEmpty()) target.put(key, map);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.consultation.infrastructure.config;
|
||||
|
||||
import com.consultation.domain.businessrule.AppointmentRule;
|
||||
import com.consultation.domain.businessrule.AuthRule;
|
||||
import com.consultation.domain.businessrule.IBusinessRule;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class BusinessRuleRegistration {
|
||||
|
||||
@Bean
|
||||
public IBusinessRule appointmentConflictDetection() {
|
||||
return AppointmentRule.CONFLICT_DETECTION;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public IBusinessRule appointmentSlotInterval() {
|
||||
return AppointmentRule.SLOT_INTERVAL;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public IBusinessRule appointmentAvailableHours() {
|
||||
return AppointmentRule.AVAILABLE_HOURS;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public IBusinessRule appointmentCancelWindow() {
|
||||
return AppointmentRule.CANCEL_WINDOW;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public IBusinessRule authPasswordMinLength() {
|
||||
return AuthRule.PASSWORD_MIN_LENGTH;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public IBusinessRule authTokenExpiration() {
|
||||
return AuthRule.TOKEN_EXPIRATION;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public IBusinessRule authPasswordAlgorithm() {
|
||||
return AuthRule.PASSWORD_ALGORITHM;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.consultation.infrastructure.config;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
@Slf4j
|
||||
@RestControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
@ExceptionHandler(IllegalArgumentException.class)
|
||||
public ResponseEntity<ErrorResponse> handleBadArg(IllegalArgumentException e) {
|
||||
return ResponseEntity.badRequest().body(new ErrorResponse("PARAM_ERROR", e.getMessage()));
|
||||
}
|
||||
|
||||
@ExceptionHandler(IllegalStateException.class)
|
||||
public ResponseEntity<ErrorResponse> handleConflict(IllegalStateException e) {
|
||||
return ResponseEntity.status(HttpStatus.CONFLICT).body(new ErrorResponse("BUSINESS_CONFLICT", e.getMessage()));
|
||||
}
|
||||
|
||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||
public ResponseEntity<ErrorResponse> handleValidation(MethodArgumentNotValidException e) {
|
||||
var msg = e.getBindingResult().getFieldError();
|
||||
return ResponseEntity.badRequest().body(new ErrorResponse("VALIDATION_ERROR", msg != null ? msg.getDefaultMessage() : "参数错误"));
|
||||
}
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
public ResponseEntity<ErrorResponse> handleOther(Exception e) {
|
||||
log.error("Unexpected error", e);
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new ErrorResponse("SYSTEM_ERROR", "系统繁忙"));
|
||||
}
|
||||
|
||||
public record ErrorResponse(String errorCode, String errorMessage, Object data) {
|
||||
public ErrorResponse(String errorCode, String errorMessage) {
|
||||
this(errorCode, errorMessage, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.consultation.infrastructure.config;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class JacksonConfig {
|
||||
@Bean
|
||||
public ObjectMapper objectMapper() {
|
||||
ObjectMapper m = new ObjectMapper();
|
||||
m.registerModule(new JavaTimeModule());
|
||||
m.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
return m;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.consultation.infrastructure.config;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class MybatisPlusConfig {
|
||||
@Bean
|
||||
public MybatisPlusInterceptor interceptor() {
|
||||
MybatisPlusInterceptor i = new MybatisPlusInterceptor();
|
||||
i.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.consultation.infrastructure.config;
|
||||
|
||||
import com.consultation.infrastructure.security.JwtAuthenticationFilter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.http.SessionCreationPolicy;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
@EnableMethodSecurity
|
||||
@RequiredArgsConstructor
|
||||
public class SecurityConfig {
|
||||
|
||||
private final JwtAuthenticationFilter jwtFilter;
|
||||
|
||||
@Bean
|
||||
public SecurityFilterChain chain(HttpSecurity http) throws Exception {
|
||||
http.csrf(c -> c.disable())
|
||||
.sessionManagement(s -> s.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
||||
.authorizeHttpRequests(a -> a
|
||||
.requestMatchers("/api/v1/auth/**").permitAll()
|
||||
.requestMatchers("/api/v1/home/**").permitAll()
|
||||
.requestMatchers("/api/v1/data-dictionaries/**").permitAll()
|
||||
.requestMatchers("/api/v1/business-rules/**").permitAll()
|
||||
.requestMatchers(HttpMethod.GET, "/api/v1/consultants", "/api/v1/consultants/*/slots").permitAll()
|
||||
.requestMatchers("/api/v1/admin/**").hasRole("ADMIN")
|
||||
.requestMatchers("/admin/**").hasRole("ADMIN")
|
||||
.anyRequest().authenticated()
|
||||
)
|
||||
.addFilterBefore(jwtFilter, UsernamePasswordAuthenticationFilter.class);
|
||||
return http.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.consultation.infrastructure.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/api/**")
|
||||
.allowedOrigins("http://localhost:5173")
|
||||
.allowedMethods("GET","POST","PUT","DELETE","OPTIONS")
|
||||
.allowedHeaders("*")
|
||||
.allowCredentials(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.consultation.infrastructure.persistence.converter;
|
||||
|
||||
import com.consultation.domain.aggregate.Appointment;
|
||||
import com.consultation.domain.vo.AppointmentStatus;
|
||||
import com.consultation.infrastructure.persistence.po.AppointmentPO;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class AppointmentConverter {
|
||||
public Appointment toDomain(AppointmentPO po) {
|
||||
if (po == null) return null;
|
||||
return Appointment.builder().id(po.getId()).userId(po.getUserId()).consultantId(po.getConsultantId())
|
||||
.branchId(po.getBranchId()).appointmentDate(po.getAppointmentDate())
|
||||
.startTime(po.getStartTime()).endTime(po.getEndTime()).durationMinutes(po.getDurationMinutes())
|
||||
.status(AppointmentStatus.valueOf(po.getStatus())).note(po.getNote()).cancelReason(po.getCancelReason()).build();
|
||||
}
|
||||
public AppointmentPO toPO(Appointment a) {
|
||||
if (a == null) return null;
|
||||
AppointmentPO po = new AppointmentPO();
|
||||
po.setId(a.getId()); po.setUserId(a.getUserId()); po.setConsultantId(a.getConsultantId());
|
||||
po.setBranchId(a.getBranchId()); po.setAppointmentDate(a.getAppointmentDate());
|
||||
po.setStartTime(a.getStartTime()); po.setEndTime(a.getEndTime()); po.setDurationMinutes(a.getDurationMinutes());
|
||||
po.setStatus(a.getStatus().name()); po.setNote(a.getNote()); po.setCancelReason(a.getCancelReason());
|
||||
return po;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.consultation.infrastructure.persistence.converter;
|
||||
|
||||
import com.consultation.domain.aggregate.Branch;
|
||||
import com.consultation.infrastructure.persistence.po.BranchPO;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class BranchConverter {
|
||||
public Branch toDomain(BranchPO po) {
|
||||
if (po == null) return null;
|
||||
return Branch.builder().id(po.getId()).name(po.getName()).address(po.getAddress())
|
||||
.phone(po.getPhone()).status(Branch.BranchStatus.valueOf(po.getStatus())).build();
|
||||
}
|
||||
public BranchPO toPO(Branch b) {
|
||||
if (b == null) return null;
|
||||
BranchPO po = new BranchPO();
|
||||
po.setId(b.getId()); po.setName(b.getName()); po.setAddress(b.getAddress());
|
||||
po.setPhone(b.getPhone()); po.setStatus(b.getStatus().name());
|
||||
return po;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.consultation.infrastructure.persistence.converter;
|
||||
|
||||
import com.consultation.domain.aggregate.Consultant;
|
||||
import com.consultation.infrastructure.persistence.po.ConsultantPO;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ConsultantConverter {
|
||||
public Consultant toDomain(ConsultantPO po) {
|
||||
if (po == null) return null;
|
||||
return Consultant.builder().id(po.getId()).name(po.getName()).title(po.getTitle()).bio(po.getBio())
|
||||
.specialties(po.getSpecialties()).avatar(po.getAvatar()).branchId(po.getBranchId())
|
||||
.status(Consultant.ConsultantStatus.valueOf(po.getStatus())).sortOrder(po.getSortOrder()).build();
|
||||
}
|
||||
public ConsultantPO toPO(Consultant c) {
|
||||
if (c == null) return null;
|
||||
ConsultantPO po = new ConsultantPO();
|
||||
po.setId(c.getId()); po.setName(c.getName()); po.setTitle(c.getTitle()); po.setBio(c.getBio());
|
||||
po.setSpecialties(c.getSpecialties()); po.setAvatar(c.getAvatar()); po.setBranchId(c.getBranchId());
|
||||
po.setStatus(c.getStatus().name()); po.setSortOrder(c.getSortOrder());
|
||||
return po;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.consultation.infrastructure.persistence.converter;
|
||||
|
||||
import com.consultation.domain.aggregate.User;
|
||||
import com.consultation.domain.vo.UserRole;
|
||||
import com.consultation.domain.vo.UserStatus;
|
||||
import com.consultation.infrastructure.persistence.po.UserPO;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class UserConverter {
|
||||
public User toDomain(UserPO po) {
|
||||
if (po == null) return null;
|
||||
return User.builder().id(po.getId()).email(po.getEmail()).password(po.getPassword())
|
||||
.name(po.getName()).phone(po.getPhone())
|
||||
.role(UserRole.valueOf(po.getRole())).status(UserStatus.valueOf(po.getStatus())).build();
|
||||
}
|
||||
public UserPO toPO(User u) {
|
||||
if (u == null) return null;
|
||||
UserPO po = new UserPO();
|
||||
po.setId(u.getId()); po.setEmail(u.getEmail()); po.setPassword(u.getPassword());
|
||||
po.setName(u.getName()); po.setPhone(u.getPhone());
|
||||
po.setRole(u.getRole().name()); po.setStatus(u.getStatus().name());
|
||||
return po;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.consultation.infrastructure.persistence.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.consultation.infrastructure.persistence.po.AppointmentPO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface AppointmentMapper extends BaseMapper<AppointmentPO> {}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.consultation.infrastructure.persistence.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.consultation.infrastructure.persistence.po.BranchPO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface BranchMapper extends BaseMapper<BranchPO> {}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.consultation.infrastructure.persistence.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.consultation.infrastructure.persistence.po.ConsultantPO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface ConsultantMapper extends BaseMapper<ConsultantPO> {}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.consultation.infrastructure.persistence.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.consultation.infrastructure.persistence.po.UserPO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface UserMapper extends BaseMapper<UserPO> {}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.consultation.infrastructure.persistence.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@TableName("appointment")
|
||||
public class AppointmentPO {
|
||||
private String id; private String userId; private String consultantId; private String branchId;
|
||||
private LocalDate appointmentDate; private String startTime; private String endTime;
|
||||
private Integer durationMinutes; private String status; private String note; private String cancelReason;
|
||||
private String createdBy; private LocalDateTime createdTime;
|
||||
private String updatedBy; private LocalDateTime updatedTime;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.consultation.infrastructure.persistence.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@TableName("branch")
|
||||
public class BranchPO {
|
||||
private String id; private String name; private String address; private String phone;
|
||||
private String status;
|
||||
private String createdBy; private LocalDateTime createdTime;
|
||||
private String updatedBy; private LocalDateTime updatedTime;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.consultation.infrastructure.persistence.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@TableName("consultant")
|
||||
public class ConsultantPO {
|
||||
private String id; private String name; private String title; private String bio;
|
||||
private String specialties; private String avatar; private String branchId;
|
||||
private String status; private Integer sortOrder;
|
||||
private String createdBy; private LocalDateTime createdTime;
|
||||
private String updatedBy; private LocalDateTime updatedTime;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.consultation.infrastructure.persistence.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@TableName("user")
|
||||
public class UserPO {
|
||||
private String id; private String email; private String password; private String name;
|
||||
private String phone; private String role; private String status; private Integer deleted;
|
||||
private String createdBy; private LocalDateTime createdTime;
|
||||
private String updatedBy; private LocalDateTime updatedTime;
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.consultation.infrastructure.repositoryimpl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.consultation.domain.aggregate.Appointment;
|
||||
import com.consultation.domain.repository.AppointmentRepository;
|
||||
import com.consultation.infrastructure.persistence.converter.AppointmentConverter;
|
||||
import com.consultation.infrastructure.persistence.mapper.AppointmentMapper;
|
||||
import com.consultation.infrastructure.persistence.po.AppointmentPO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
@RequiredArgsConstructor
|
||||
public class AppointmentRepositoryImpl implements AppointmentRepository {
|
||||
|
||||
private final AppointmentMapper mapper;
|
||||
private final AppointmentConverter converter;
|
||||
|
||||
@Override public Optional<Appointment> findById(String id) { return Optional.ofNullable(converter.toDomain(mapper.selectById(id))); }
|
||||
|
||||
@Override
|
||||
public List<Appointment> findByUserId(String userId, int page, int pageSize) {
|
||||
return mapper.selectPage(new Page<>(page, pageSize),
|
||||
new LambdaQueryWrapper<AppointmentPO>().eq(AppointmentPO::getUserId, userId).orderByDesc(AppointmentPO::getCreatedTime))
|
||||
.getRecords().stream().map(converter::toDomain).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Appointment> findByConsultantIdAndDate(String consultantId, LocalDate date) {
|
||||
return mapper.selectList(new LambdaQueryWrapper<AppointmentPO>()
|
||||
.eq(AppointmentPO::getConsultantId, consultantId).eq(AppointmentPO::getAppointmentDate, date))
|
||||
.stream().map(converter::toDomain).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Appointment> findAll(int page, int pageSize) {
|
||||
return mapper.selectPage(new Page<>(page, pageSize), null).getRecords().stream().map(converter::toDomain).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Appointment save(Appointment a) {
|
||||
AppointmentPO po = converter.toPO(a);
|
||||
po.setCreatedBy(a.getUserId()); po.setCreatedTime(LocalDateTime.now());
|
||||
po.setUpdatedBy(a.getUserId()); po.setUpdatedTime(LocalDateTime.now());
|
||||
mapper.insert(po); return a;
|
||||
}
|
||||
|
||||
@Override public void update(Appointment a) { AppointmentPO po = converter.toPO(a); po.setUpdatedTime(LocalDateTime.now()); mapper.updateById(po); }
|
||||
|
||||
@Override public long count() { return mapper.selectCount(null); }
|
||||
@Override public long countByStatus(String s) { return mapper.selectCount(new LambdaQueryWrapper<AppointmentPO>().eq(AppointmentPO::getStatus, s)); }
|
||||
@Override public long countByUserId(String u) { return mapper.selectCount(new LambdaQueryWrapper<AppointmentPO>().eq(AppointmentPO::getUserId, u)); }
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.consultation.infrastructure.repositoryimpl;
|
||||
|
||||
import com.consultation.domain.aggregate.Branch;
|
||||
import com.consultation.domain.repository.BranchRepository;
|
||||
import com.consultation.infrastructure.persistence.converter.BranchConverter;
|
||||
import com.consultation.infrastructure.persistence.mapper.BranchMapper;
|
||||
import com.consultation.infrastructure.persistence.po.BranchPO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
@RequiredArgsConstructor
|
||||
public class BranchRepositoryImpl implements BranchRepository {
|
||||
|
||||
private final BranchMapper mapper;
|
||||
private final BranchConverter converter;
|
||||
|
||||
@Override public Optional<Branch> findById(String id) { return Optional.ofNullable(converter.toDomain(mapper.selectById(id))); }
|
||||
@Override public List<Branch> findAll() { return mapper.selectList(null).stream().map(converter::toDomain).toList(); }
|
||||
|
||||
@Override
|
||||
public Branch save(Branch b) {
|
||||
BranchPO po = converter.toPO(b);
|
||||
po.setCreatedBy(b.getId()); po.setCreatedTime(LocalDateTime.now()); po.setUpdatedBy(b.getId()); po.setUpdatedTime(LocalDateTime.now());
|
||||
mapper.insert(po); return b;
|
||||
}
|
||||
|
||||
@Override public void update(Branch b) { BranchPO po = converter.toPO(b); po.setUpdatedTime(LocalDateTime.now()); mapper.updateById(po); }
|
||||
@Override public void deleteById(String id) { mapper.deleteById(id); }
|
||||
@Override public long count() { return mapper.selectCount(null); }
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.consultation.infrastructure.repositoryimpl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.consultation.domain.aggregate.Consultant;
|
||||
import com.consultation.domain.repository.ConsultantRepository;
|
||||
import com.consultation.infrastructure.persistence.converter.ConsultantConverter;
|
||||
import com.consultation.infrastructure.persistence.mapper.ConsultantMapper;
|
||||
import com.consultation.infrastructure.persistence.po.ConsultantPO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
@RequiredArgsConstructor
|
||||
public class ConsultantRepositoryImpl implements ConsultantRepository {
|
||||
|
||||
private final ConsultantMapper mapper;
|
||||
private final ConsultantConverter converter;
|
||||
|
||||
@Override public Optional<Consultant> findById(String id) { return Optional.ofNullable(converter.toDomain(mapper.selectById(id))); }
|
||||
@Override public List<Consultant> findAll() { return mapper.selectList(null).stream().map(converter::toDomain).toList(); }
|
||||
|
||||
@Override
|
||||
public List<Consultant> findAllActive() {
|
||||
return mapper.selectList(new LambdaQueryWrapper<ConsultantPO>()
|
||||
.eq(ConsultantPO::getStatus, Consultant.ConsultantStatus.ACTIVE.name())
|
||||
.orderByAsc(ConsultantPO::getSortOrder)).stream().map(converter::toDomain).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Consultant save(Consultant c) {
|
||||
ConsultantPO po = converter.toPO(c);
|
||||
po.setCreatedBy(c.getId()); po.setCreatedTime(LocalDateTime.now()); po.setUpdatedBy(c.getId()); po.setUpdatedTime(LocalDateTime.now());
|
||||
mapper.insert(po); return c;
|
||||
}
|
||||
|
||||
@Override public void update(Consultant c) { ConsultantPO po = converter.toPO(c); po.setUpdatedTime(LocalDateTime.now()); mapper.updateById(po); }
|
||||
@Override public void deleteById(String id) { mapper.deleteById(id); }
|
||||
@Override public long count() { return mapper.selectCount(null); }
|
||||
@Override public boolean existsById(String id) { return mapper.selectCount(new LambdaQueryWrapper<ConsultantPO>().eq(ConsultantPO::getId, id)) > 0; }
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.consultation.infrastructure.repositoryimpl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.consultation.domain.aggregate.User;
|
||||
import com.consultation.domain.repository.UserRepository;
|
||||
import com.consultation.infrastructure.persistence.converter.UserConverter;
|
||||
import com.consultation.infrastructure.persistence.mapper.UserMapper;
|
||||
import com.consultation.infrastructure.persistence.po.UserPO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
@RequiredArgsConstructor
|
||||
public class UserRepositoryImpl implements UserRepository {
|
||||
|
||||
private final UserMapper mapper;
|
||||
private final UserConverter converter;
|
||||
|
||||
@Override
|
||||
public Optional<User> findById(String id) { return Optional.ofNullable(converter.toDomain(mapper.selectById(id))); }
|
||||
|
||||
@Override
|
||||
public Optional<User> findByEmail(String email) {
|
||||
return Optional.ofNullable(converter.toDomain(mapper.selectOne(new LambdaQueryWrapper<UserPO>().eq(UserPO::getEmail, email))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<User> findAll() { return mapper.selectList(null).stream().map(converter::toDomain).toList(); }
|
||||
|
||||
@Override
|
||||
public User save(User u) {
|
||||
UserPO po = converter.toPO(u);
|
||||
po.setCreatedBy(u.getId()); po.setCreatedTime(LocalDateTime.now());
|
||||
po.setUpdatedBy(u.getId()); po.setUpdatedTime(LocalDateTime.now());
|
||||
mapper.insert(po);
|
||||
return u;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(User u) {
|
||||
UserPO po = converter.toPO(u);
|
||||
po.setUpdatedTime(LocalDateTime.now());
|
||||
mapper.updateById(po);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsByEmail(String email) { return mapper.selectCount(new LambdaQueryWrapper<UserPO>().eq(UserPO::getEmail, email)) > 0; }
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.consultation.infrastructure.security;
|
||||
|
||||
import jakarta.servlet.FilterChain;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.filter.OncePerRequestFilter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class JwtAuthenticationFilter extends OncePerRequestFilter {
|
||||
|
||||
private final JwtTokenProvider tokenProvider;
|
||||
|
||||
@Override
|
||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
|
||||
throws ServletException, IOException {
|
||||
String bearer = request.getHeader("Authorization");
|
||||
if (StringUtils.hasText(bearer) && bearer.startsWith("Bearer ")) {
|
||||
String token = bearer.substring(7);
|
||||
if (tokenProvider.validate(token)) {
|
||||
var claims = tokenProvider.parse(token);
|
||||
String role = claims.get("role", String.class);
|
||||
UserContextHolder.set(UserContext.builder()
|
||||
.userId(claims.getSubject())
|
||||
.email(claims.get("email", String.class))
|
||||
.role(role)
|
||||
.build());
|
||||
SecurityContextHolder.getContext().setAuthentication(
|
||||
new UsernamePasswordAuthenticationToken(
|
||||
claims.getSubject(), null,
|
||||
role != null ? Collections.singletonList(new SimpleGrantedAuthority(role))
|
||||
: Collections.emptyList()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
try { chain.doFilter(request, response); } finally { UserContextHolder.clear(); SecurityContextHolder.clearContext(); }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.consultation.infrastructure.security;
|
||||
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.security.Keys;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.crypto.SecretKey;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Date;
|
||||
|
||||
@Component
|
||||
public class JwtTokenProvider {
|
||||
|
||||
private final SecretKey key;
|
||||
private final long expiration;
|
||||
|
||||
public JwtTokenProvider(@Value("${jwt.secret}") String secret, @Value("${jwt.expiration}") long exp) {
|
||||
this.key = Keys.hmacShaKeyFor(secret.getBytes(StandardCharsets.UTF_8));
|
||||
this.expiration = exp;
|
||||
}
|
||||
|
||||
public String generate(String userId, String email, String role) {
|
||||
Date now = new Date();
|
||||
return Jwts.builder().subject(userId).claim("email", email).claim("role", role)
|
||||
.issuedAt(now).expiration(new Date(now.getTime() + expiration)).signWith(key).compact();
|
||||
}
|
||||
|
||||
public io.jsonwebtoken.Claims parse(String token) {
|
||||
return Jwts.parser().verifyWith(key).build().parseSignedClaims(token).getPayload();
|
||||
}
|
||||
|
||||
public boolean validate(String token) {
|
||||
try { parse(token); return true; } catch (Exception e) { return false; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.consultation.infrastructure.security;
|
||||
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class PasswordServiceImpl implements com.consultation.domain.service.PasswordService {
|
||||
|
||||
private final BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
|
||||
|
||||
@Override
|
||||
public String encode(String raw) { return encoder.encode(raw); }
|
||||
|
||||
@Override
|
||||
public boolean matches(String raw, String encoded) { return encoder.matches(raw, encoded); }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.consultation.infrastructure.security;
|
||||
|
||||
public class SecurityUtils {
|
||||
public static UserContext currentUser() {
|
||||
UserContext c = UserContextHolder.get();
|
||||
if (c == null) throw new IllegalStateException("未登录");
|
||||
return c;
|
||||
}
|
||||
public static String currentUserId() { return currentUser().getUserId(); }
|
||||
public static boolean isAdmin() {
|
||||
UserContext c = UserContextHolder.get();
|
||||
return c != null && "ROLE_ADMIN".equals(c.getRole());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.consultation.infrastructure.security;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Data @Builder @AllArgsConstructor
|
||||
public class UserContext {
|
||||
private String userId;
|
||||
private String email;
|
||||
private String role;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.consultation.infrastructure.security;
|
||||
|
||||
public class UserContextHolder {
|
||||
private static final ThreadLocal<UserContext> CTX = new ThreadLocal<>();
|
||||
public static void set(UserContext c) { CTX.set(c); }
|
||||
public static UserContext get() { return CTX.get(); }
|
||||
public static void clear() { CTX.remove(); }
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
server:
|
||||
port: 8080
|
||||
spring:
|
||||
application:
|
||||
name: consultation-backend
|
||||
config:
|
||||
import: "classpath:/business-rules/appointment.yml,classpath:/business-rules/auth.yml"
|
||||
datasource:
|
||||
url: jdbc:mysql://localhost:3306/consultation?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: <your-mysql-password>
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
flyway:
|
||||
enabled: true
|
||||
locations: classpath:db/migration
|
||||
baseline-on-migrate: true
|
||||
mybatis-plus:
|
||||
mapper-locations: classpath:mapper/**/*.xml
|
||||
type-aliases-package: com.consultation.infrastructure.persistence.po
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
global-config:
|
||||
db-config:
|
||||
id-type: INPUT
|
||||
jwt:
|
||||
secret: <your-jwt-secret>
|
||||
expiration: 86400000
|
||||
@@ -0,0 +1,14 @@
|
||||
appointment:
|
||||
conflict:
|
||||
detection: "同一咨询师同一时段不可重复预约"
|
||||
enforcement: "uk_appointment_slot 唯一索引 + AppointmentConflictService 双重校验"
|
||||
slot:
|
||||
minMinutes: 30
|
||||
maxMinutes: 120
|
||||
intervalMinutes: 60
|
||||
available:
|
||||
start: "09:00"
|
||||
end: "18:00"
|
||||
cancel:
|
||||
allowedStatuses: "PENDING, CONFIRMED"
|
||||
reasonRequired: true
|
||||
@@ -0,0 +1,13 @@
|
||||
auth:
|
||||
password:
|
||||
minLength: 8
|
||||
algorithm: "BCrypt"
|
||||
token:
|
||||
expirationMs: 86400000
|
||||
algorithm: "HMAC-SHA256"
|
||||
publicEndpoints:
|
||||
- "/api/v1/auth/**"
|
||||
- "/api/v1/home/**"
|
||||
- "/api/v1/consultants/**"
|
||||
- "/api/v1/data-dictionaries/**"
|
||||
- "/api/v1/business-rules/**"
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user