63 lines
2.0 KiB
Markdown
63 lines
2.0 KiB
Markdown
# 订单详情样品查询修复说明
|
||
|
||
## 问题描述
|
||
从工单生成的新订单,点击查看详情时看不到对应的样品列表。
|
||
|
||
## 原因分析
|
||
|
||
### 数据关系
|
||
- **旧流程**:样品 → 订单 → 工单
|
||
- `test_eut.test_order_id` → 订单ID
|
||
- 订单详情查询:`SELECT * FROM test_eut WHERE test_order_id = ?`
|
||
|
||
- **新流程**:样品 → 工单 → 订单(从工单生成)
|
||
- `test_eut.test_order_id` → 原始订单ID(不变)
|
||
- `test_work_order.test_eut_id` → 样品ID
|
||
- `test_work_order.order_id` → 新生成的订单ID
|
||
- 需要通过工单来查询样品
|
||
|
||
### 问题
|
||
新订单(ID 36-39)的详情页查询 `test_eut WHERE test_order_id = 36` 返回空,因为样品的 `test_order_id` 仍然指向原始订单。
|
||
|
||
## 解决方案
|
||
|
||
修改订单详情的样品查询逻辑,通过工单的 `order_id` 来查询:
|
||
|
||
```sql
|
||
SELECT DISTINCT test_eut.*
|
||
FROM test_eut
|
||
INNER JOIN test_work_order ON test_eut.id = test_work_order.test_eut_id
|
||
WHERE test_work_order.order_id = ?
|
||
```
|
||
|
||
这样可以查询到所有关联到该订单的工单对应的样品。
|
||
|
||
## 实现步骤
|
||
|
||
### 1. 后端:创建新的查询方法
|
||
在 `test_eut_dao.py` 中添加方法:
|
||
```python
|
||
@classmethod
|
||
async def get_eut_list_by_order_id(cls, db: AsyncSession, order_id: int):
|
||
"""
|
||
根据订单ID通过工单查询样品列表
|
||
"""
|
||
```
|
||
|
||
### 2. 前端:修改查询逻辑
|
||
在 `test_order/index.vue` 的 `eut_getList` 方法中:
|
||
- 检查是否是从工单生成的订单
|
||
- 如果是,使用新的API查询
|
||
- 如果不是,使用原有的查询方式
|
||
|
||
## 兼容性
|
||
修改后的查询逻辑需要兼容两种情况:
|
||
1. 旧订单:直接通过 test_order_id 查询
|
||
2. 新订单:通过工单的 order_id 查询
|
||
|
||
## 相关文件
|
||
- `ruoyi-fastapi-backend/module_admin/system/dao/test_eut_dao.py`
|
||
- `ruoyi-fastapi-backend/module_admin/system/controller/test_eut_controller.py`
|
||
- `ruoyi-fastapi-frontend/src/views/system/test_order/index.vue`
|
||
- `ruoyi-fastapi-frontend/src/api/system/test_eut.js`
|