deving
This commit is contained in:
@@ -8,7 +8,7 @@ import json
|
||||
from datetime import datetime
|
||||
|
||||
from models.database import (
|
||||
STPFile, GeometryData, MoldCavityData,
|
||||
STPFile, GeometryData, MeshData, MoldCavityData,
|
||||
HTMLFile, ProcessingTask, User,
|
||||
FeatureDetection, DesignRecommendation,
|
||||
UserActivity, SystemLog
|
||||
@@ -200,6 +200,62 @@ class StorageIntegrationService:
|
||||
logger.info(f"几何数据保存成功 RustFS: {geometry_data.id}")
|
||||
return geometry_data
|
||||
|
||||
async def save_mesh_data(
|
||||
self,
|
||||
session: AsyncSession,
|
||||
stp_file_id: int,
|
||||
mesh_json: Dict[str, Any],
|
||||
quality: str = "medium"
|
||||
) -> MeshData:
|
||||
"""保存网格数据到 PostgreSQL 元数据 + RustFS 对象存储
|
||||
|
||||
mesh_json 为完整网格 JSON(顶点、面、点云等),
|
||||
PostgreSQL 只存 object_key 和一些摘要字段,详细数据放在 RustFS。
|
||||
"""
|
||||
|
||||
# 1. 获取文件哈希
|
||||
stp_file = await session.get(STPFile, stp_file_id)
|
||||
file_hash = stp_file.file_hash
|
||||
|
||||
# 2. 上传网格 JSON 到 RustFS
|
||||
upload_result = await rustfs_manager.upload_json_data(
|
||||
file_type='mesh_data',
|
||||
json_data=mesh_json,
|
||||
file_hash=file_hash
|
||||
)
|
||||
|
||||
# 3. 提取摘要信息
|
||||
mesh_section = mesh_json.get('mesh', {})
|
||||
pointcloud_section = mesh_json.get('pointcloud', {})
|
||||
bbox = mesh_json.get('bounding_box', {})
|
||||
|
||||
vertices = mesh_section.get('vertices') or []
|
||||
faces = mesh_section.get('faces') or []
|
||||
|
||||
vertex_count = len(vertices)
|
||||
face_count = len(faces)
|
||||
point_count = pointcloud_section.get('count')
|
||||
|
||||
# 4. 创建 PostgreSQL 记录
|
||||
mesh_data = MeshData(
|
||||
stp_file_id=stp_file_id,
|
||||
object_key=upload_result['object_key'],
|
||||
storage_bucket=upload_result['bucket'],
|
||||
quality=quality,
|
||||
vertex_count=vertex_count,
|
||||
face_count=face_count,
|
||||
point_count=point_count,
|
||||
bounding_box_min=bbox.get('min'),
|
||||
bounding_box_max=bbox.get('max')
|
||||
)
|
||||
|
||||
session.add(mesh_data)
|
||||
await session.commit()
|
||||
await session.refresh(mesh_data)
|
||||
|
||||
logger.info(f"网格数据保存成功 RustFS: {mesh_data.id}")
|
||||
return mesh_data
|
||||
|
||||
async def save_mold_cavity_data(self, session: AsyncSession,
|
||||
stp_file_id: int,
|
||||
cavity_json: Dict[str, Any]) -> MoldCavityData:
|
||||
@@ -388,6 +444,7 @@ class StorageIntegrationService:
|
||||
'user_id': stp_file.user_id
|
||||
},
|
||||
'geometry_data': None,
|
||||
'mesh_data': None,
|
||||
'mold_cavity_data': None,
|
||||
'html_content': None,
|
||||
'features': [],
|
||||
@@ -412,6 +469,14 @@ class StorageIntegrationService:
|
||||
)
|
||||
result['mold_cavity_data'] = json.loads(cavity_data_bytes.decode('utf-8'))
|
||||
|
||||
# 网格数据
|
||||
if stp_file.mesh_data:
|
||||
mesh_bytes = await rustfs_manager.download_file(
|
||||
file_type='mesh_data',
|
||||
object_key=stp_file.mesh_data.object_key
|
||||
)
|
||||
result['mesh_data'] = json.loads(mesh_bytes.decode('utf-8'))
|
||||
|
||||
# HTML文件
|
||||
if stp_file.html_file:
|
||||
html_bytes = await rustfs_manager.download_file(
|
||||
@@ -481,6 +546,12 @@ class StorageIntegrationService:
|
||||
except Exception as e:
|
||||
logger.error(f"删除型腔数据失败: {e}")
|
||||
|
||||
try:
|
||||
if stp_file.mesh_data:
|
||||
await rustfs_manager.delete_file('mesh_data', stp_file.mesh_data.object_key)
|
||||
except Exception as e:
|
||||
logger.error(f"删除网格数据失败: {e}")
|
||||
|
||||
try:
|
||||
if stp_file.html_file:
|
||||
await rustfs_manager.delete_file('html_files', stp_file.html_file.object_key)
|
||||
|
||||
Reference in New Issue
Block a user