feat: add version group tracking to cross-review task documents with auto-chaining on re-upload
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user