feat:导出面板动态编写一半
This commit is contained in:
@@ -5,8 +5,8 @@ AgentCoord 数据库模块
|
||||
"""
|
||||
|
||||
from .database import get_db, get_db_context, test_connection, engine, text
|
||||
from .models import MultiAgentTask, UserAgent, TaskStatus
|
||||
from .crud import MultiAgentTaskCRUD, UserAgentCRUD
|
||||
from .models import MultiAgentTask, UserAgent, ExportRecord, TaskStatus
|
||||
from .crud import MultiAgentTaskCRUD, UserAgentCRUD, ExportRecordCRUD
|
||||
|
||||
__all__ = [
|
||||
# 连接管理
|
||||
@@ -18,8 +18,10 @@ __all__ = [
|
||||
# 模型
|
||||
"MultiAgentTask",
|
||||
"UserAgent",
|
||||
"ExportRecord",
|
||||
"TaskStatus",
|
||||
# CRUD
|
||||
"MultiAgentTaskCRUD",
|
||||
"UserAgentCRUD",
|
||||
"ExportRecordCRUD",
|
||||
]
|
||||
|
||||
@@ -9,7 +9,7 @@ from datetime import datetime, timezone
|
||||
from typing import List, Optional
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .models import MultiAgentTask, UserAgent
|
||||
from .models import MultiAgentTask, UserAgent, ExportRecord
|
||||
|
||||
|
||||
class MultiAgentTaskCRUD:
|
||||
@@ -414,3 +414,85 @@ class UserAgentCRUD:
|
||||
db.commit()
|
||||
db.refresh(agent)
|
||||
return agent
|
||||
|
||||
|
||||
class ExportRecordCRUD:
|
||||
"""导出记录 CRUD 操作"""
|
||||
|
||||
@staticmethod
|
||||
def create(
|
||||
db: Session,
|
||||
task_id: str,
|
||||
user_id: str,
|
||||
export_type: str,
|
||||
file_name: str,
|
||||
file_path: str,
|
||||
file_url: str = "",
|
||||
file_size: int = 0,
|
||||
) -> ExportRecord:
|
||||
"""创建导出记录"""
|
||||
record = ExportRecord(
|
||||
task_id=task_id,
|
||||
user_id=user_id,
|
||||
export_type=export_type,
|
||||
file_name=file_name,
|
||||
file_path=file_path,
|
||||
file_url=file_url,
|
||||
file_size=file_size,
|
||||
)
|
||||
db.add(record)
|
||||
db.commit()
|
||||
db.refresh(record)
|
||||
return record
|
||||
|
||||
@staticmethod
|
||||
def get_by_id(db: Session, record_id: int) -> Optional[ExportRecord]:
|
||||
"""根据 ID 获取记录"""
|
||||
return db.query(ExportRecord).filter(ExportRecord.id == record_id).first()
|
||||
|
||||
@staticmethod
|
||||
def get_by_task_id(
|
||||
db: Session, task_id: str, limit: int = 50
|
||||
) -> List[ExportRecord]:
|
||||
"""根据任务 ID 获取导出记录列表"""
|
||||
return (
|
||||
db.query(ExportRecord)
|
||||
.filter(ExportRecord.task_id == task_id)
|
||||
.order_by(ExportRecord.created_at.desc())
|
||||
.limit(limit)
|
||||
.all()
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_by_user_id(
|
||||
db: Session, user_id: str, limit: int = 50
|
||||
) -> List[ExportRecord]:
|
||||
"""根据用户 ID 获取导出记录列表"""
|
||||
return (
|
||||
db.query(ExportRecord)
|
||||
.filter(ExportRecord.user_id == user_id)
|
||||
.order_by(ExportRecord.created_at.desc())
|
||||
.limit(limit)
|
||||
.all()
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def delete(db: Session, record_id: int) -> bool:
|
||||
"""删除导出记录"""
|
||||
record = db.query(ExportRecord).filter(ExportRecord.id == record_id).first()
|
||||
if record:
|
||||
db.delete(record)
|
||||
db.commit()
|
||||
return True
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def delete_by_task_id(db: Session, task_id: str) -> bool:
|
||||
"""删除任务的所有导出记录"""
|
||||
records = db.query(ExportRecord).filter(ExportRecord.task_id == task_id).all()
|
||||
if records:
|
||||
for record in records:
|
||||
db.delete(record)
|
||||
db.commit()
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -81,6 +81,39 @@ class MultiAgentTask(Base):
|
||||
}
|
||||
|
||||
|
||||
class ExportRecord(Base):
|
||||
"""导出记录模型"""
|
||||
__tablename__ = "export_records"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
task_id = Column(String(64), nullable=False, index=True) # 关联任务ID
|
||||
user_id = Column(String(64), nullable=False, index=True) # 用户ID
|
||||
export_type = Column(String(32), nullable=False) # 导出类型: doc/markdown/mindmap/infographic/excel/ppt
|
||||
file_name = Column(String(256), nullable=False) # 文件名
|
||||
file_path = Column(String(512), nullable=False) # 服务器存储路径
|
||||
file_url = Column(String(512)) # 访问URL
|
||||
file_size = Column(Integer, default=0) # 文件大小(字节)
|
||||
created_at = Column(DateTime(timezone=True), default=utc_now)
|
||||
|
||||
__table_args__ = (
|
||||
Index("idx_export_records_task_user", "task_id", "user_id"),
|
||||
)
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
"""转换为字典"""
|
||||
return {
|
||||
"id": self.id,
|
||||
"task_id": self.task_id,
|
||||
"user_id": self.user_id,
|
||||
"export_type": self.export_type,
|
||||
"file_name": self.file_name,
|
||||
"file_path": self.file_path,
|
||||
"file_url": self.file_url,
|
||||
"file_size": self.file_size,
|
||||
"created_at": self.created_at.isoformat() if self.created_at else None,
|
||||
}
|
||||
|
||||
|
||||
class UserAgent(Base):
|
||||
"""用户保存的智能体配置模型 (可选表)"""
|
||||
__tablename__ = "user_agents"
|
||||
|
||||
Reference in New Issue
Block a user