x
This commit is contained in:
@@ -5,6 +5,7 @@ from fastapi import APIRouter, Depends, HTTPException, Request
|
||||
|
||||
from services.auth_service import get_current_active_user
|
||||
from services.redis_task_manager import redis_task_manager
|
||||
from services.processing_service import processing_service
|
||||
from models.database import User
|
||||
from utils.logger import get_logger
|
||||
|
||||
@@ -281,6 +282,7 @@ async def export_mold_results(
|
||||
):
|
||||
body = await request.json()
|
||||
task_id = body.get("task_id")
|
||||
scheme_id = body.get("scheme_id")
|
||||
formats = body.get("formats", ["step", "stl"])
|
||||
components = body.get("components", ["cavity", "core"])
|
||||
|
||||
@@ -291,16 +293,17 @@ async def export_mold_results(
|
||||
if not task_data:
|
||||
raise HTTPException(404, "任务不存在")
|
||||
|
||||
cavity_shapes = task_data.get("cavity_shapes")
|
||||
cavity_shapes = processing_service.get_export_shapes(
|
||||
task_id,
|
||||
scheme_id or task_data.get("best_scheme_id"),
|
||||
)
|
||||
filename = task_data.get("filename", f"mold_{task_id}")
|
||||
|
||||
if not cavity_shapes:
|
||||
file_path = task_data.get("file_path")
|
||||
if file_path and os.path.exists(str(file_path)):
|
||||
cavity_shapes = await _reparse_stp_for_export(str(file_path), task_data.get("material", "ABS"))
|
||||
|
||||
if not cavity_shapes:
|
||||
raise HTTPException(400, "该任务尚未完成模具生成或形状数据不可用")
|
||||
raise HTTPException(
|
||||
409,
|
||||
"导出缓存已失效或任务尚未完成,请重新分析后再导出以保证方案一致性",
|
||||
)
|
||||
|
||||
exporter = _get_cached("cad_exporter")
|
||||
if not exporter:
|
||||
@@ -352,17 +355,3 @@ async def get_export_recommendations(
|
||||
return {"status": "success", "data": result}
|
||||
|
||||
|
||||
async def _reparse_stp_for_export(file_path: str, material: str = "ABS") -> dict:
|
||||
try:
|
||||
from core.stp_parser import STPParser
|
||||
from core.mold_generator import MoldCavityGenerator
|
||||
stp_parser = STPParser()
|
||||
shape = stp_parser.load_step_file(Path(file_path))
|
||||
mold_gen = MoldCavityGenerator(shrinkage_rate=0.005)
|
||||
mold_gen.set_material(material)
|
||||
cavity_result = mold_gen.generate_mold_cavities(shape)
|
||||
logger.info(f"重新解析 STP 用于导出: {file_path}")
|
||||
return cavity_result
|
||||
except Exception as e:
|
||||
logger.warning(f"重新解析 STP 导出失败: {e}")
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user