Files
his/MD/bugs/BUG_726_ANALYSIS.md

135 lines
5.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Bug #726 诸葛亮分析报告
> **文档类型**: Bug分析
> **分析时间**: 2026-06-13 01:12:01
> **分析模型**: mimo-v2.5 (LLM深度分析)
---
## 基本信息
- **Bug #**: 726
- **标题**: 【病理管理】开病历医嘱出现报错
- **模块**: 疾病报告管理
- **提出人**: 王栩坤
---
Now I have all the information needed for a complete analysis. Let me compile the findings.
---
### 一、Bug 理解
**禅道 Bug #726【病理管理】开病历医嘱出现报错**
- **重现步骤**: 登录内科医生1账号doctor1/123456进入病理管理→病理医嘱→点击"开病理医嘱"报卡→点击确定
- **结果**: 出现报错 `ERROR: null value in column "patient_id" of relation "pathology_order" violates not-null constraint`
- **期望**: 能够正常进行该项操作
**附图关键信息**:
- 弹窗表单中"患者ID"、"患者姓名"、"就诊ID"三个字段均为空
- `el-input-number` 控件未填入值,`patientId``null`
- 后端执行的 INSERT SQL 中**完全没有 `patient_id` 列**,说明 MyBatis-Plus 对 null 值字段执行了跳过策略
**综合总结**: 用户在"开病理医嘱"弹窗中未填写患者ID或系统未自动填充导致提交时 `patientId=null`。MyBatis-Plus 的默认 insert 策略跳过了 null 字段INSERT SQL 中无 `patient_id` 列),而数据库 `pathology_order.patient_id` 列有 `NOT NULL` 约束,导致插入失败。
---
### 二、根因分析
**直接原因**: 前端表单提交了 `patientId: null`,后端 Controller `addOrder()` 未做任何校验直接调用 `orderService.save(order)`MyBatis-Plus 生成的 INSERT 不包含 `patient_id` 列,触发 PostgreSQL NOT NULL 约束。
**根因链条**:
1. **前端** `healthlink-his-ui/src/views/pathology/order/index.vue`: `el-input-number``v-model="form.patientId"` 初始值为 `null`,用户未手动输入时保持 `null`
2. **前端** `submitForm()`: 无任何校验逻辑,直接调用 `add(form.value)`
3. **后端** `PathologyController.addOrder()`: 无参数校验(无 `@Valid`、无手动检查),直接 `orderService.save(order)`
4. **DB**: `pathology_order.patient_id BIGINT NOT NULL`V32 迁移脚本定义)
**涉及文件**:
| 文件 | 问题 |
|------|------|
| `healthlink-his-ui/src/views/pathology/order/index.vue` | 表单无校验,`patientId` 可为 null |
| `healthlink-his-server/.../web/pathology/controller/PathologyController.java` | `addOrder()` 无参数校验 |
| `healthlink-his-domain/.../pathology/domain/PathologyOrder.java` | Entity 无 `@NotNull` 注解 |
---
### 三、修复方案
**方案:前后端双重校验 + 自动获取患者信息**
#### 1. 后端Controller 加校验1 个文件)
**文件**: `PathologyController.java``addOrder()` 方法
**修改内容**: 在保存前校验必填字段 `patientId``patientName`
```java
@PostMapping("/order/add")
@Transactional(rollbackFor = Exception.class)
public R<?> addOrder(@RequestBody PathologyOrder order) {
if (order.getPatientId() == null) {
return R.fail("患者ID不能为空");
}
if (!StringUtils.hasText(order.getPatientName())) {
return R.fail("患者姓名不能为空");
}
if (!StringUtils.hasText(order.getOrderStatus())) {
order.setOrderStatus("PENDING");
}
order.setApplyTime(new Date());
order.setCreateTime(new Date());
orderService.save(order);
return R.ok(order);
}
```
#### 2. 前端表单提交前校验1 个文件)
**文件**: `healthlink-his-ui/src/views/pathology/order/index.vue`
**修改内容**: 在 `submitForm()` 中增加校验逻辑:
```javascript
const submitForm = async () => {
if (!form.value.patientId) { ElMessage.warning('请选择患者'); return }
if (!form.value.patientName) { ElMessage.warning('请填写患者姓名'); return }
if (isEdit.value) {
await update(form.value)
} else {
await add(form.value)
}
ElMessage.success('操作成功')
dlgVisible.value = false
loadData()
}
```
**修改总结**:
| 文件 | 修改内容 | 影响范围 |
|------|---------|---------|
| `PathologyController.java:~addOrder()` | 增加 `patientId``patientName` 非空校验 | 仅影响新增病理医嘱接口 |
| `pathology/order/index.vue:submitForm()` | 增加前端提交前校验 | 仅影响病理医嘱表单 |
**验证步骤**:
1. `mvn clean compile -DskipTests` → 编译通过
2. 不填 patientId 点确定 → 前端提示"请选择患者"
3. 填入 patientId 后提交 → 后端正常保存INSERT 包含 `patient_id`
---
### 四、路由决策
- **FIXER**: `guanyu`(后端修复 Controller 校验)+ `zhaoyun`(前端修复表单校验)
- **REASON**: 此 Bug 涉及后端 Controller 缺少参数校验和前端表单缺少提交前校验两个独立修改点,后端修复归属关羽,前端修复归属赵云,可并行处理。
---
## 路由决策
- **FIXER_ID**: guanyu
- **修复 Agent**: guanyu后端
- **原因**: LLM 分析决策
> ⚠️ 修复人员请先验证以上分析是否正确,再执行修复。