Skip to content

Commit 78729ef

Browse files
committed
feat(workstation): update bioyond config migration and coin cell material search logic
- Migrate bioyond_cell config to JSON structure and remove global variable dependencies - Implement material search confirmation dialog auto-handling - Add documentation: 20260113_物料搜寻确认弹窗自动处理功能.md and 20260113_配置迁移修改总结.md
1 parent 965bf36 commit 78729ef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+10013
-16105
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Bioyond Cell 工作站 - 多订单返回示例
2+
3+
本文档说明了 `create_orders` 函数如何收集并返回所有订单的完成报文。
4+
5+
## 问题描述
6+
7+
之前的实现只会等待并返回第一个订单的完成报文,如果有多个订单(例如从 Excel 解析出 3 个订单),只能得到第一个订单的推送信息。
8+
9+
## 解决方案
10+
11+
修改后的 `create_orders` 函数现在会:
12+
13+
1. **提取所有 orderCode**:从 LIMS 接口返回的 `data` 列表中提取所有订单编号
14+
2. **逐个等待完成**:遍历所有 orderCode,调用 `wait_for_order_finish` 等待每个订单完成
15+
3. **收集所有报文**:将每个订单的完成报文存入 `all_reports` 列表
16+
4. **统一返回**:返回包含所有订单报文的 JSON 格式数据
17+
18+
## 返回格式
19+
20+
```json
21+
{
22+
"status": "all_completed",
23+
"total_orders": 3,
24+
"reports": [
25+
{
26+
"token": "",
27+
"request_time": "2025-12-24T15:32:09.2148671+08:00",
28+
"data": {
29+
"orderId": "3a1e614d-a082-c44a-60be-68647a35e6f1",
30+
"orderCode": "BSO2025122400024",
31+
"orderName": "DP20251224001",
32+
"status": "30",
33+
"workflowStatus": "completed",
34+
"usedMaterials": [...]
35+
}
36+
},
37+
{
38+
"token": "",
39+
"request_time": "2025-12-24T15:32:09.9999039+08:00",
40+
"data": {
41+
"orderId": "3a1e614d-a0a2-f7a9-9360-610021c9479d",
42+
"orderCode": "BSO2025122400025",
43+
"orderName": "DP20251224002",
44+
"status": "30",
45+
"workflowStatus": "completed",
46+
"usedMaterials": [...]
47+
}
48+
},
49+
{
50+
"token": "",
51+
"request_time": "2025-12-24T15:34:00.4139986+08:00",
52+
"data": {
53+
"orderId": "3a1e614d-a0cd-81ca-9f7f-2f4e93af01cd",
54+
"orderCode": "BSO2025122400026",
55+
"orderName": "DP20251224003",
56+
"status": "30",
57+
"workflowStatus": "completed",
58+
"usedMaterials": [...]
59+
}
60+
}
61+
],
62+
"original_response": {...}
63+
}
64+
```
65+
66+
## 使用示例
67+
68+
```python
69+
# 调用 create_orders
70+
result = workstation.create_orders("20251224.xlsx")
71+
72+
# 访问返回数据
73+
print(f"总订单数: {result['total_orders']}")
74+
print(f"状态: {result['status']}")
75+
76+
# 遍历所有订单的报文
77+
for i, report in enumerate(result['reports'], 1):
78+
order_data = report.get('data', {})
79+
print(f"\n订单 {i}:")
80+
print(f" orderCode: {order_data.get('orderCode')}")
81+
print(f" orderName: {order_data.get('orderName')}")
82+
print(f" status: {order_data.get('status')}")
83+
print(f" 使用物料数: {len(order_data.get('usedMaterials', []))}")
84+
```
85+
86+
## 控制台输出示例
87+
88+
```
89+
[create_orders] 即将提交订单数量: 3
90+
[create_orders] 接口返回: {...}
91+
[create_orders] 等待 3 个订单完成: ['BSO2025122400024', 'BSO2025122400025', 'BSO2025122400026']
92+
[create_orders] 正在等待第 1/3 个订单: BSO2025122400024
93+
[create_orders] ✓ 订单 BSO2025122400024 完成
94+
[create_orders] 正在等待第 2/3 个订单: BSO2025122400025
95+
[create_orders] ✓ 订单 BSO2025122400025 完成
96+
[create_orders] 正在等待第 3/3 个订单: BSO2025122400026
97+
[create_orders] ✓ 订单 BSO2025122400026 完成
98+
[create_orders] 所有订单已完成,共收集 3 个报文
99+
实验记录本========================create_orders========================
100+
返回报文数量: 3
101+
报文 1: orderCode=BSO2025122400024, status=30
102+
报文 2: orderCode=BSO2025122400025, status=30
103+
报文 3: orderCode=BSO2025122400026, status=30
104+
========================
105+
```
106+
107+
## 关键改进
108+
109+
1.**等待所有订单**:不再只等待第一个订单,而是遍历所有 orderCode
110+
2.**收集完整报文**:每个订单的完整推送报文都被保存在 `reports` 数组中
111+
3.**详细日志**:清晰显示正在等待哪个订单,以及完成情况
112+
4.**错误处理**:即使某个订单失败,也会记录其状态信息
113+
5.**统一格式**:返回的 JSON 格式便于后续处理和分析
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
# BioyondCellWorkstation JSON 配置迁移经验总结
2+
3+
**日期**: 2026-01-13
4+
**目的**: 从 `config.py` 迁移到 JSON 配置文件
5+
6+
---
7+
8+
## 问题背景
9+
10+
原系统通过 `config.py` 管理配置,导致:
11+
1. HTTP 服务重复启动(父类 `BioyondWorkstation` 和子类都启动)
12+
2. 配置分散在代码中,不便于管理
13+
3. 无法通过 JSON 统一配置所有参数
14+
15+
---
16+
17+
## 解决方案:嵌套配置结构
18+
19+
### JSON 结构设计
20+
21+
**正确示例** (嵌套在 `config` 中):
22+
```json
23+
{
24+
"nodes": [{
25+
"id": "bioyond_cell_workstation",
26+
"config": {
27+
"deck": {...},
28+
"protocol_type": [],
29+
"bioyond_config": {
30+
"api_host": "http://172.16.11.219:44388",
31+
"api_key": "8A819E5C",
32+
"timeout": 30,
33+
"HTTP_host": "172.16.11.206",
34+
"HTTP_port": 8080,
35+
"debug_mode": false,
36+
"material_type_mappings": {...},
37+
"warehouse_mapping": {...},
38+
"solid_liquid_mappings": {...}
39+
}
40+
},
41+
"data": {}
42+
}]
43+
}
44+
```
45+
46+
**关键点**
47+
-`bioyond_config` 放在 `config` 中(会传递到 `__init__`
48+
-**不要**放在 `data` 中(`data` 是运行时状态,不会传递)
49+
50+
---
51+
52+
## Python 代码适配
53+
54+
### 1. 修改 `BioyondCellWorkstation.__init__` 签名
55+
56+
**文件**: `bioyond_cell_workstation.py`
57+
58+
```python
59+
def __init__(self, bioyond_config: dict = None, deck=None, protocol_type=None, **kwargs):
60+
"""
61+
Args:
62+
bioyond_config: 从 JSON 加载的配置字典
63+
deck: Deck 配置
64+
protocol_type: 协议类型
65+
"""
66+
# 验证配置
67+
if bioyond_config is None:
68+
raise ValueError("需要 bioyond_config 参数")
69+
70+
# 保存配置
71+
self.bioyond_config = bioyond_config
72+
73+
# 设置 HTTP 服务去重标志
74+
self.bioyond_config["_disable_auto_http_service"] = True
75+
76+
# 调用父类
77+
super().__init__(bioyond_config=self.bioyond_config, deck=deck, **kwargs)
78+
```
79+
80+
### 2. 替换全局变量引用
81+
82+
**修改前**(使用全局变量):
83+
```python
84+
from config import MATERIAL_TYPE_MAPPINGS, WAREHOUSE_MAPPING
85+
86+
def create_sample(self, board_type, ...):
87+
carrier_type_id = MATERIAL_TYPE_MAPPINGS[board_type][1]
88+
location_id = WAREHOUSE_MAPPING[warehouse_name]["site_uuids"][location_code]
89+
```
90+
91+
**修改后**(从配置读取):
92+
```python
93+
def create_sample(self, board_type, ...):
94+
carrier_type_id = self.bioyond_config['material_type_mappings'][board_type][1]
95+
location_id = self.bioyond_config['warehouse_mapping'][warehouse_name]["site_uuids"][location_code]
96+
```
97+
98+
### 3. 修复父类配置访问
99+
100+
`station.py` 中安全访问配置默认值:
101+
102+
```python
103+
# 修改前(会 KeyError)
104+
self._http_service_config = {
105+
"host": bioyond_config.get("http_service_host", HTTP_SERVICE_CONFIG["http_service_host"])
106+
}
107+
108+
# 修改后(安全访问)
109+
self._http_service_config = {
110+
"host": bioyond_config.get("http_service_host", HTTP_SERVICE_CONFIG.get("http_service_host", ""))
111+
}
112+
```
113+
114+
---
115+
116+
## 常见陷阱
117+
118+
### ❌ 错误1:将配置放在 `data` 字段
119+
```json
120+
"config": {"deck": {...}},
121+
"data": {"bioyond_config": {...}} // ❌ 不会传递到 __init__
122+
```
123+
124+
### ❌ 错误2:扁平化配置(已废弃方案)
125+
虽然扁平化也能工作,但不推荐:
126+
```json
127+
"config": {
128+
"deck": {...},
129+
"api_host": "...", // ❌ 不够清晰
130+
"api_key": "...",
131+
"HTTP_host": "..."
132+
}
133+
```
134+
135+
### ❌ 错误3:忘记替换全局变量引用
136+
代码中直接使用 `MATERIAL_TYPE_MAPPINGS` 等全局变量会导致 `NameError`
137+
138+
---
139+
140+
## 云端同步注意事项
141+
142+
使用 `--upload_registry` 时,云端配置可能覆盖本地配置:
143+
- 首次上传时确保 JSON 完整
144+
- 或使用新的 `ak/sk` 避免旧配置干扰
145+
- 调试时可暂时移除 `--upload_registry` 参数
146+
147+
---
148+
149+
## 验证清单
150+
151+
启动成功后应看到:
152+
```
153+
✅ 从 JSON 配置加载 bioyond_config 成功
154+
API Host: http://...
155+
HTTP Service: ...
156+
✅ BioyondCellWorkstation 初始化完成
157+
Loaded ResourceTreeSet with ... nodes
158+
```
159+
160+
运行时不应出现:
161+
-`NameError: name 'MATERIAL_TYPE_MAPPINGS' is not defined`
162+
-`KeyError: 'http_service_host'`
163+
-`bioyond_config 缺少必需参数`
164+
165+
---
166+
167+
## 调试经验
168+
169+
1. **添加调试日志**查看参数传递链路:
170+
- `graphio.py`: JSON 加载后的 config 内容
171+
- `initialize_device.py`: `device_config.res_content.config` 的键
172+
- `bioyond_cell_workstation.py`: `__init__` 接收到的参数
173+
174+
2. **config vs data 区别**
175+
- `config`: 初始化参数,传递给 `__init__`
176+
- `data`: 运行时状态,不传递给 `__init__`
177+
178+
3. **参数名必须匹配**
179+
- JSON 中的键名必须与 `__init__` 参数名完全一致
180+
181+
4. **调试代码清理**:完成后记得删除调试日志(🔍 DEBUG 标记)
182+
183+
---
184+
185+
## 修改文件清单
186+
187+
| 文件 | 修改内容 |
188+
|------|----------|
189+
| `yibin_electrolyte_config.json` | 创建嵌套 `config.bioyond_config` 结构 |
190+
| `bioyond_cell_workstation.py` | 修改 `__init__` 接收 `bioyond_config`,替换所有全局变量引用 |
191+
| `station.py` | 安全访问 `HTTP_SERVICE_CONFIG` 默认值 |
192+
193+
---
194+
195+
## 参考代码位置
196+
197+
- JSON 配置示例: `yibin_electrolyte_config.json` L12-L353
198+
- `__init__` 实现: `bioyond_cell_workstation.py` L39-L94
199+
- 全局变量替换示例: `bioyond_cell_workstation.py` L2005, L1863, L1966
200+
- HTTP 服务配置: `station.py` L629-L634
201+
202+
---
203+
204+
**总结**: 使用嵌套结构将所有配置放在 `config.bioyond_config` 中,修改 `__init__` 直接接收该参数,并替换所有全局变量引用为 `self.bioyond_config` 访问。

0 commit comments

Comments
 (0)