x
This commit is contained in:
+27
-3
@@ -189,8 +189,8 @@ async def get_status(task_id: str, db_session: AsyncSession = Depends(get_db_ses
|
||||
"geometry_data": geometry_json,
|
||||
"detected_features": features_json,
|
||||
"design_recommendations": recommendations_json,
|
||||
"quality_metrics": {},
|
||||
"analysis_summary": "分析完成"
|
||||
"quality_metrics": file_with_data.get("analysis_metrics", {}) or {},
|
||||
"analysis_summary": file_with_data.get("analysis_metrics", {}).get("analysis_summary", "分析完成")
|
||||
} if features_json or recommendations_json else None,
|
||||
"error": processing_task.error_message or stp_file.error_message or None,
|
||||
}
|
||||
@@ -403,6 +403,27 @@ async def process_file_with_storage(
|
||||
tasks[task_id]["status"] = ProcessingStatus.FAILED
|
||||
tasks[task_id]["error"] = str(e)
|
||||
tasks[task_id]["completed_at"] = str(datetime.now())
|
||||
|
||||
|
||||
async def _save_analysis_metrics(session, stp_file_id, analysis_result):
|
||||
"""保存分析指标到数据库"""
|
||||
from models.database import AnalysisMetrics
|
||||
|
||||
quality_metrics = analysis_result.get("quality_metrics", {})
|
||||
analysis_summary = analysis_result.get("analysis_summary", "")
|
||||
|
||||
# 创建分析指标记录
|
||||
metrics = AnalysisMetrics(
|
||||
stp_file_id=stp_file_id,
|
||||
volume_utilization=quality_metrics.get("volume_utilization", 0),
|
||||
topology_complexity=quality_metrics.get("topology_complexity", 0),
|
||||
wall_uniformity=quality_metrics.get("wall_uniformity", 0),
|
||||
analysis_summary=analysis_summary
|
||||
)
|
||||
|
||||
session.add(metrics)
|
||||
await session.commit()
|
||||
logger.info(f"分析指标保存成功: {metrics.id}")
|
||||
return
|
||||
|
||||
|
||||
@@ -644,7 +665,7 @@ async def process_file_core(
|
||||
# 9. 分析模具设计
|
||||
analysis_result = geometry_analyzer.analyze_mold_design(geometry_data)
|
||||
|
||||
# 9.5 保存特征和建议到数据库
|
||||
# 9.5 保存完整的分析结果到数据库
|
||||
if analysis_result:
|
||||
await storage_service.save_features_and_recommendations(
|
||||
db_session,
|
||||
@@ -652,6 +673,9 @@ async def process_file_core(
|
||||
analysis_result.get("detected_features", []),
|
||||
analysis_result.get("design_recommendations", [])
|
||||
)
|
||||
|
||||
# 保存质量指标和分析摘要到数据库
|
||||
await self._save_analysis_metrics(db_session, stp_file_id, analysis_result)
|
||||
|
||||
# 10. 完成处理
|
||||
await storage_service.update_stp_file_status(db_session, stp_file_id, "completed")
|
||||
|
||||
@@ -152,6 +152,7 @@ class STPFile(Base):
|
||||
mesh_data = relationship("MeshData", back_populates="stp_file", uselist=False)
|
||||
mold_cavity_data = relationship("MoldCavityData", back_populates="stp_file", uselist=False)
|
||||
html_file = relationship("HTMLFile", back_populates="stp_file", uselist=False)
|
||||
analysis_metrics = relationship("AnalysisMetrics", back_populates="stp_file", uselist=False)
|
||||
|
||||
def __repr__(self):
|
||||
return f"<STPFile(id={self.id}, object_key='{self.object_key}', status='{self.status}')>"
|
||||
@@ -661,6 +662,31 @@ class SalesOrder(Base):
|
||||
return f"<SalesOrder(order_no='{self.order_no}', status='{self.status}')>"
|
||||
|
||||
|
||||
class AnalysisMetrics(Base):
|
||||
"""分析指标表"""
|
||||
__tablename__ = "analysis_metrics"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
stp_file_id = Column(Integer, ForeignKey("stp_files.id"), nullable=False, index=True)
|
||||
|
||||
# 质量指标
|
||||
volume_utilization = Column(Float, default=0) # 体积利用率
|
||||
topology_complexity = Column(Float, default=0) # 拓扑复杂度
|
||||
wall_uniformity = Column(Float, default=0) # 壁厚均匀性
|
||||
|
||||
# 分析摘要
|
||||
analysis_summary = Column(Text, nullable=True)
|
||||
|
||||
# 时间戳
|
||||
created_at = Column(DateTime, default=func.now())
|
||||
|
||||
# 关联关系
|
||||
stp_file = relationship("STPFile", back_populates="analysis_metrics")
|
||||
|
||||
def __repr__(self):
|
||||
return f"<AnalysisMetrics(stp_file_id={self.stp_file_id}, volume_utilization={self.volume_utilization})>"
|
||||
|
||||
|
||||
class SalesOrderItem(Base):
|
||||
"""销售订单明细表"""
|
||||
__tablename__ = "sales_order_items"
|
||||
|
||||
@@ -448,7 +448,8 @@ class StorageIntegrationService:
|
||||
'mold_cavity_data': None,
|
||||
'html_content': None,
|
||||
'features': [],
|
||||
'recommendations': []
|
||||
'recommendations': [],
|
||||
'analysis_metrics': None # 新增分析指标字段
|
||||
}
|
||||
|
||||
# 2. 从RustFS获取数据
|
||||
@@ -508,7 +509,7 @@ class StorageIntegrationService:
|
||||
)
|
||||
result['recommendations'] = [
|
||||
{
|
||||
'rec_type': r.rec_type,
|
||||
'type': r.rec_type, # 改为 type 以匹配前端期望的字段名
|
||||
'priority': r.priority,
|
||||
'description': r.description,
|
||||
'reason': r.reason,
|
||||
@@ -517,6 +518,15 @@ class StorageIntegrationService:
|
||||
for r in recommendations.scalars().all()
|
||||
]
|
||||
|
||||
# 4. 获取分析指标
|
||||
if stp_file.analysis_metrics:
|
||||
result['analysis_metrics'] = {
|
||||
'volume_utilization': stp_file.analysis_metrics.volume_utilization,
|
||||
'topology_complexity': stp_file.analysis_metrics.topology_complexity,
|
||||
'wall_uniformity': stp_file.analysis_metrics.wall_uniformity,
|
||||
'analysis_summary': stp_file.analysis_metrics.analysis_summary
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
async def delete_stp_file_cascade(self, session: AsyncSession,
|
||||
|
||||
Reference in New Issue
Block a user