144 lines
4.3 KiB
Python
144 lines
4.3 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
测试从实验流程配置获取备注
|
|
"""
|
|
|
|
import json
|
|
from pathlib import Path
|
|
|
|
def check_experiment_process_config():
|
|
"""检查实验流程配置中的备注"""
|
|
print("检查实验流程配置")
|
|
print("=" * 40)
|
|
|
|
try:
|
|
config_path = Path(__file__).parent / "default.json"
|
|
|
|
with open(config_path, 'r', encoding='utf-8') as f:
|
|
config = json.load(f)
|
|
|
|
# 查看实验流程配置
|
|
exp_process = config.get('experimentProcess', {})
|
|
|
|
print("实验流程配置:")
|
|
print(f" 备注 (remark): '{exp_process.get('remark', '')}'")
|
|
print(f" 表头 (headers): {exp_process.get('headers', [])}")
|
|
print(f" 行数据 (rows): {len(exp_process.get('rows', []))} 行")
|
|
|
|
# 显示备注内容
|
|
remark = exp_process.get('remark', '')
|
|
if remark:
|
|
print(f"\n当前备注内容: '{remark}'")
|
|
print("✅ 备注不为空,将用于新建工单的备注字段")
|
|
else:
|
|
print("\n当前备注为空")
|
|
print("⚠️ 建议在实验流程配置中设置备注信息")
|
|
|
|
return remark
|
|
|
|
except Exception as e:
|
|
print(f"ERROR 检查配置失败: {e}")
|
|
return ""
|
|
|
|
def update_experiment_process_remark():
|
|
"""更新实验流程配置中的备注(用于测试)"""
|
|
print("\n更新实验流程备注")
|
|
print("=" * 40)
|
|
|
|
try:
|
|
config_path = Path(__file__).parent / "default.json"
|
|
|
|
with open(config_path, 'r', encoding='utf-8') as f:
|
|
config = json.load(f)
|
|
|
|
# 设置测试备注
|
|
test_remark = "PCM断路器性能测试实验"
|
|
|
|
if 'experimentProcess' not in config:
|
|
config['experimentProcess'] = {}
|
|
|
|
config['experimentProcess']['remark'] = test_remark
|
|
|
|
# 保存配置
|
|
with open(config_path, 'w', encoding='utf-8') as f:
|
|
json.dump(config, f, indent=2, ensure_ascii=False)
|
|
|
|
print(f"OK 已更新备注为: '{test_remark}'")
|
|
|
|
return test_remark
|
|
|
|
except Exception as e:
|
|
print(f"ERROR 更新失败: {e}")
|
|
return ""
|
|
|
|
def test_remark_logic():
|
|
"""测试备注获取逻辑"""
|
|
print("\n测试备注获取逻辑")
|
|
print("=" * 40)
|
|
|
|
# 模拟创建工单时的备注获取
|
|
config_path = Path(__file__).parent / "default.json"
|
|
|
|
try:
|
|
with open(config_path, 'r', encoding='utf-8') as f:
|
|
config = json.load(f)
|
|
|
|
# 模拟 self.config.experimentProcess.remark
|
|
remark = config.get('experimentProcess', {}).get('remark', '')
|
|
|
|
print("模拟创建工单:")
|
|
print(f" 工单号: TEST123")
|
|
print(f" 操作员: 测试员")
|
|
print(f" 备注: '{remark}'")
|
|
|
|
if remark:
|
|
print("✅ 备注获取成功")
|
|
else:
|
|
print("⚠️ 备注为空")
|
|
|
|
return remark
|
|
|
|
except Exception as e:
|
|
print(f"ERROR 测试失败: {e}")
|
|
return ""
|
|
|
|
def main():
|
|
print("备注从实验流程配置获取测试")
|
|
print("=" * 50)
|
|
print("目标: 创建工单时备注从实验流程配置中获取")
|
|
print("=" * 50)
|
|
|
|
# 1. 检查当前配置
|
|
current_remark = check_experiment_process_config()
|
|
|
|
# 2. 如果备注为空,设置测试备注
|
|
if not current_remark:
|
|
print("\n备注为空,设置测试备注...")
|
|
update_experiment_process_remark()
|
|
|
|
# 重新检查
|
|
current_remark = check_experiment_process_config()
|
|
|
|
# 3. 测试备注获取逻辑
|
|
test_remark_logic()
|
|
|
|
print("\n" + "=" * 50)
|
|
print("修改说明:")
|
|
print("✅ 修改了 _start_work_order 方法")
|
|
print("✅ 备注获取: remark = self.config.experimentProcess.remark")
|
|
print("✅ 不再使用空备注或固定格式")
|
|
|
|
print("\n使用方法:")
|
|
print("1. 在UI的实验流程配置中设置备注")
|
|
print("2. 创建新工单时会自动使用该备注")
|
|
print("3. 备注内容独立于工单号显示")
|
|
|
|
print("\n测试步骤:")
|
|
print("1. 重启程序")
|
|
print("2. 在实验流程页面设置备注")
|
|
print("3. 创建新工单")
|
|
print("4. 查看实验列表中的备注列")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|