feat: add version group tracking to cross-review task documents with auto-chaining on re-upload
This commit is contained in:
@@ -51,6 +51,8 @@ class CrossReviewTaskDocumentVO(BaseModel):
|
|||||||
processingStatus: str | None = Field(None, description="处理状态")
|
processingStatus: str | None = Field(None, description="处理状态")
|
||||||
versionNo: int = Field(1, description="版本号")
|
versionNo: int = Field(1, description="版本号")
|
||||||
isLatestVersion: bool = Field(True, description="是否最新版本")
|
isLatestVersion: bool = Field(True, description="是否最新版本")
|
||||||
|
versionGroupKey: str = Field("", description="版本组Key")
|
||||||
|
totalVersions: int = Field(1, description="版本组总版本数")
|
||||||
auditStatus: int = Field(0, description="任务内完成状态")
|
auditStatus: int = Field(0, description="任务内完成状态")
|
||||||
createdAt: datetime | None = Field(None, description="创建时间")
|
createdAt: datetime | None = Field(None, description="创建时间")
|
||||||
fileSize: int = Field(0, description="文件大小(字节)")
|
fileSize: int = Field(0, description="文件大小(字节)")
|
||||||
|
|||||||
@@ -448,6 +448,8 @@ class CrossReviewServiceImpl(ICrossReviewService):
|
|||||||
) AS processing_status,
|
) AS processing_status,
|
||||||
d.version_no,
|
d.version_no,
|
||||||
d.is_latest_version,
|
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,
|
d.created_at,
|
||||||
td.audit_status,
|
td.audit_status,
|
||||||
COALESCE(dt.name, '') AS type_name,
|
COALESCE(dt.name, '') AS type_name,
|
||||||
@@ -466,6 +468,12 @@ class CrossReviewServiceImpl(ICrossReviewService):
|
|||||||
ORDER BY id ASC
|
ORDER BY id ASC
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
) df ON TRUE
|
) 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}
|
WHERE {whereSql}
|
||||||
ORDER BY d.created_at DESC, d.id DESC
|
ORDER BY d.created_at DESC, d.id DESC
|
||||||
LIMIT :limit OFFSET :offset
|
LIMIT :limit OFFSET :offset
|
||||||
@@ -485,6 +493,8 @@ class CrossReviewServiceImpl(ICrossReviewService):
|
|||||||
processingStatus=row.get("processing_status"),
|
processingStatus=row.get("processing_status"),
|
||||||
versionNo=int(row.get("version_no") or 1),
|
versionNo=int(row.get("version_no") or 1),
|
||||||
isLatestVersion=bool(row.get("is_latest_version")),
|
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),
|
auditStatus=int(row.get("audit_status") or 0),
|
||||||
createdAt=row.get("created_at"),
|
createdAt=row.get("created_at"),
|
||||||
fileSize=int(row.get("file_size") or 0),
|
fileSize=int(row.get("file_size") or 0),
|
||||||
@@ -901,6 +911,30 @@ class CrossReviewServiceImpl(ICrossReviewService):
|
|||||||
await self._ensure_tables_ready(session)
|
await self._ensure_tables_ready(session)
|
||||||
await self._reset_transaction_for_write(session)
|
await self._reset_transaction_for_write(session)
|
||||||
async with session.begin():
|
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(
|
exists = bool(
|
||||||
await session.scalar(
|
await session.scalar(
|
||||||
text(
|
text(
|
||||||
|
|||||||
Reference in New Issue
Block a user