diff --git a/fastapi_modules/fastapi_leaudit/domian/vo/crossReviewVo.py b/fastapi_modules/fastapi_leaudit/domian/vo/crossReviewVo.py index 31d4768..4e1c7b1 100644 --- a/fastapi_modules/fastapi_leaudit/domian/vo/crossReviewVo.py +++ b/fastapi_modules/fastapi_leaudit/domian/vo/crossReviewVo.py @@ -51,6 +51,8 @@ class CrossReviewTaskDocumentVO(BaseModel): processingStatus: str | None = Field(None, description="处理状态") versionNo: int = Field(1, description="版本号") isLatestVersion: bool = Field(True, description="是否最新版本") + versionGroupKey: str = Field("", description="版本组Key") + totalVersions: int = Field(1, description="版本组总版本数") auditStatus: int = Field(0, description="任务内完成状态") createdAt: datetime | None = Field(None, description="创建时间") fileSize: int = Field(0, description="文件大小(字节)") diff --git a/fastapi_modules/fastapi_leaudit/services/impl/crossReviewServiceImpl.py b/fastapi_modules/fastapi_leaudit/services/impl/crossReviewServiceImpl.py index 1bc80c2..ead14c9 100644 --- a/fastapi_modules/fastapi_leaudit/services/impl/crossReviewServiceImpl.py +++ b/fastapi_modules/fastapi_leaudit/services/impl/crossReviewServiceImpl.py @@ -448,6 +448,8 @@ class CrossReviewServiceImpl(ICrossReviewService): ) AS processing_status, d.version_no, d.is_latest_version, + COALESCE(d.version_group_key, '') AS version_group_key, + COALESCE(vc.total_versions, 1)::int AS total_versions, d.created_at, td.audit_status, COALESCE(dt.name, '') AS type_name, @@ -466,6 +468,12 @@ class CrossReviewServiceImpl(ICrossReviewService): ORDER BY id ASC LIMIT 1 ) df ON TRUE + LEFT JOIN ( + SELECT version_group_key, COUNT(*) AS total_versions + FROM leaudit_documents + WHERE deleted_at IS NULL + GROUP BY version_group_key + ) vc ON vc.version_group_key = d.version_group_key WHERE {whereSql} ORDER BY d.created_at DESC, d.id DESC LIMIT :limit OFFSET :offset @@ -485,6 +493,8 @@ class CrossReviewServiceImpl(ICrossReviewService): processingStatus=row.get("processing_status"), versionNo=int(row.get("version_no") or 1), isLatestVersion=bool(row.get("is_latest_version")), + versionGroupKey=str(row.get("version_group_key") or ""), + totalVersions=int(row.get("total_versions") or 1), auditStatus=int(row.get("audit_status") or 0), createdAt=row.get("created_at"), fileSize=int(row.get("file_size") or 0), @@ -901,6 +911,30 @@ class CrossReviewServiceImpl(ICrossReviewService): await self._ensure_tables_ready(session) await self._reset_transaction_for_write(session) async with session.begin(): + # If this is v{n>1}, retire previous versions in this task + if uploadResult.versionNo > 1 and uploadResult.versionGroupKey: + await session.execute( + text( + """ + UPDATE leaudit_cross_review_task_documents + SET delete_time = NOW() + WHERE task_id = :task_id + AND delete_time IS NULL + AND document_id IN ( + SELECT id FROM leaudit_documents + WHERE version_group_key = :group_key + AND deleted_at IS NULL + AND id != :new_doc_id + ) + """ + ), + { + "task_id": TaskId, + "group_key": uploadResult.versionGroupKey, + "new_doc_id": uploadResult.documentId, + }, + ) + exists = bool( await session.scalar( text(