feat(file-check): 新增文件资产管理与清理功能,支持上传、查询、删除及下载

This commit is contained in:
hugo committed 2026-07-14 09:14:44 +08:00
1 parent 143e054d86
commit 729546a7b7
52 files changed
+3420 -34

No files matched your search

+4
View File
@@ -16,10 +16,12 @@ from app.models.kb import KbDifySyncRecord, KbDocument, KbDocumentVersion, KbGro
from app.models.maintenance import MaintenanceAuditLog, MaintenanceDevice, MaintenanceRecord
from app.models.schedule import ScheduleRun, ScheduleTask, ScheduleTaskConfig
from app.models.settings import AppSetting
from app.models.file_asset import FileAsset
from app.models.shipping import (
ShippingBatch,
ShippingInventoryFile,
ShippingInventoryMapping,
ShippingNoticeIntake,
ShippingTask,
ShippingTaskEvent,
ShippingTaskInventoryLink,
@@ -66,6 +68,8 @@ __all__ = [
'ShippingInventoryFile',
'ShippingTaskInventoryLink',
'ShippingInventoryMapping',
'ShippingNoticeIntake',
'FileAsset',
'AgentGuide',
'AgentDirectoryMember',
'TrainingRecord',
+49
View File
@@ -0,0 +1,49 @@
"""
backend/app/models/file_asset.py
用途:平台级通用文件资产模型,承载私有 MinIO 存储元数据与生命周期。
依赖:models.base.Base。
逻辑:由 file_assets.service 创建与更新;ShippingNoticeIntake 等业务通过 asset_id 引用。
"""
from __future__ import annotations
from datetime import datetime
from typing import Optional
from sqlalchemy import DateTime, ForeignKey, Index, Integer, String, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column
from app.models.base import Base
class FileAsset(Base):
"""通用文件资产(私有对象存储 + 审计元数据)。"""
__tablename__ = 'file_assets'
__table_args__ = (
UniqueConstraint('asset_no', name='uq_file_assets_asset_no'),
Index('ix_file_assets_owner_content_hash', 'owner_user_id', 'content_hash'),
Index('ix_file_assets_lifecycle_expires', 'lifecycle_status', 'expires_at'),
Index('ix_file_assets_owner_created', 'owner_user_id', 'created_at'),
)
id: Mapped[int] = mapped_column(primary_key=True)
asset_no: Mapped[str] = mapped_column(String(64), nullable=False)
owner_user_id: Mapped[int] = mapped_column(ForeignKey('users.id'), index=True, nullable=False)
tenant_id: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
original_filename: Mapped[str] = mapped_column(String(255), nullable=False)
storage_provider: Mapped[str] = mapped_column(String(32), default='minio', nullable=False)
storage_bucket: Mapped[str] = mapped_column(String(128), nullable=False)
storage_key: Mapped[str] = mapped_column(String(512), nullable=False)
content_hash: Mapped[str] = mapped_column(String(64), nullable=False)
file_size: Mapped[int] = mapped_column(Integer, nullable=False)
mime_type: Mapped[Optional[str]] = mapped_column(String(128), nullable=True)
extension: Mapped[Optional[str]] = mapped_column(String(32), nullable=True)
upload_status: Mapped[str] = mapped_column(String(32), default='uploading', nullable=False)
lifecycle_status: Mapped[str] = mapped_column(String(32), default='temporary', nullable=False)
reference_count: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
expires_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
deleted_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
created_at: Mapped[datetime] = mapped_column(default=datetime.utcnow, index=True)
updated_at: Mapped[datetime] = mapped_column(default=datetime.utcnow, onupdate=datetime.utcnow)
+45
View File
@@ -83,6 +83,12 @@ class ShippingTask(Base):
source_file_name: Mapped[Optional[str]] = mapped_column(String(255), nullable=True)
source_file_type: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
source_content_hash: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
source_asset_id: Mapped[Optional[int]] = mapped_column(ForeignKey('file_assets.id'), index=True, nullable=True)
source_intake_id: Mapped[Optional[int]] = mapped_column(
ForeignKey('shipping_notice_intakes.id'),
index=True,
nullable=True,
)
batch_index: Mapped[Optional[int]] = mapped_column(Integer, nullable=True)
batch_total: Mapped[Optional[int]] = mapped_column(Integer, nullable=True)
@@ -280,6 +286,45 @@ class ShippingTaskInventoryLink(Base):
)
class ShippingNoticeIntake(Base):
"""发货通知预解析接入记录(上传成功至正式建单前的异步解析阶段)。"""
__tablename__ = 'shipping_notice_intakes'
__table_args__ = (
UniqueConstraint('intake_no', name='uq_shipping_notice_intakes_intake_no'),
UniqueConstraint(
'asset_id',
'purpose',
'parser_version',
name='uq_shipping_notice_intakes_asset_purpose_parser',
),
Index('ix_shipping_notice_intakes_user_conversation_created', 'user_id', 'conversation_id', 'created_at'),
Index('ix_shipping_notice_intakes_parse_status_created', 'parse_status', 'created_at'),
Index('ix_shipping_notice_intakes_expires', 'expires_at'),
)
id: Mapped[int] = mapped_column(primary_key=True)
intake_no: Mapped[str] = mapped_column(String(64), nullable=False)
asset_id: Mapped[int] = mapped_column(ForeignKey('file_assets.id'), index=True, nullable=False)
user_id: Mapped[int] = mapped_column(ForeignKey('users.id'), index=True, nullable=False)
conversation_id: Mapped[Optional[str]] = mapped_column(String(100), nullable=True)
purpose: Mapped[str] = mapped_column(String(32), default='shipping_notice', nullable=False)
parse_status: Mapped[str] = mapped_column(String(32), default='created', nullable=False, index=True)
extracted_text: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
structured_result_json: Mapped[Optional[dict]] = mapped_column(JSON, nullable=True)
parse_warnings_json: Mapped[Optional[list]] = mapped_column(JSON, nullable=True)
parser_version: Mapped[str] = mapped_column(String(32), nullable=False)
parse_job_id: Mapped[Optional[int]] = mapped_column(nullable=True, index=True)
error_code: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
error_message: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
consumed_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
consumed_batch_id: Mapped[Optional[int]] = mapped_column(ForeignKey('shipping_batches.id'), nullable=True)
consumed_task_id: Mapped[Optional[int]] = mapped_column(ForeignKey('shipping_tasks.id'), nullable=True)
expires_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
created_at: Mapped[datetime] = mapped_column(default=datetime.utcnow, index=True)
updated_at: Mapped[datetime] = mapped_column(default=datetime.utcnow, onupdate=datetime.utcnow)
class ShippingInventoryMapping(Base):
"""客户库存 Excel 表头 → 标准字段的列映射缓存(按 customer_code + header_hash 去重)。"""