This commit is contained in:
2026-03-08 03:30:55 +08:00
parent 942c6f93d7
commit 47f6cebc77
+36 -14
View File
@@ -111,27 +111,32 @@ class GeometryVerificationService:
logger.info(f"执行验证命令: {' '.join(cmd)}")
# 获取 STP 文件的绝对路径和目录
stp_abs_path = Path(stp_path_str).absolute()
stp_dir = stp_abs_path.parent
# 异步运行子进程
process = await asyncio.create_subprocess_exec(
*cmd,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
cwd=str(Path(__file__).parent.parent)
cwd=str(stp_dir) # 在 STP 文件所在目录运行
)
stdout, stderr = await process.communicate()
if process.returncode == 0:
# 尝试读取生成的报告文件
report_path = Path(stp_path_str).stem + "_verification_report.json"
if Path(report_path).exists():
# 尝试读取生成的报告文件(在 STP 文件目录下)
report_path = stp_dir / (stp_abs_path.stem + "_verification_report.json")
if report_path.exists():
with open(report_path, 'r', encoding='utf-8') as f:
result = json.load(f)
# 删除临时报告文件
Path(report_path).unlink()
report_path.unlink()
return result
else:
# 解析 stdout 获取结果
logger.warning(f"验证报告文件不存在: {report_path}")
return self._parse_verification_output(stdout.decode('utf-8'))
else:
logger.error(f"验证脚本执行失败 (returncode={process.returncode}): {stderr.decode('utf-8')}")
@@ -164,22 +169,39 @@ class GeometryVerificationService:
"""解析验证脚本输出"""
result = {
"status": "unknown",
"timestamp": datetime.now().isoformat()
"timestamp": datetime.now().isoformat(),
"comparison": {}
}
lines = output.split('\n')
for line in lines:
if '验证结果:' in line:
if '✅ 通过' in line:
if '✅ 通过' in line or '通过' in line:
result['status'] = 'passed'
elif '❌ 失败' in line:
elif '❌ 失败' in line or '失败' in line:
result['status'] = 'failed'
elif '体积对比:' in line:
# 解析体积差异
pass
elif '表面积对比:' in line:
# 解析表面积差异
pass
elif '体积对比:' in line or '体积差异' in line:
try:
if '差异:' in line:
parts = line.split('差异:')
if len(parts) > 1:
diff_part = parts[1].strip()
if '%' in diff_part:
percent = float(diff_part.split('%')[0].strip().split()[-1])
result['comparison']['volume'] = {'difference_percent': percent}
except:
pass
elif '表面积对比:' in line or '表面积差异' in line:
try:
if '差异:' in line:
parts = line.split('差异:')
if len(parts) > 1:
diff_part = parts[1].strip()
if '%' in diff_part:
percent = float(diff_part.split('%')[0].strip().split()[-1])
result['comparison']['surface_area'] = {'difference_percent': percent}
except:
pass
return result