feat: integrate govdoc module into leaudit platform

This commit is contained in:
wren
2026-05-17 19:24:16 +08:00
parent cb13e61d3d
commit a73826dc1d
16 changed files with 2334 additions and 280 deletions
@@ -163,6 +163,7 @@ class DocumentServiceImpl(IDocumentService):
root_group_id=resolvedRootGroupId,
region=normalizedRegion,
normalized_name=normalizedName,
file_ext=fileExt,
)
internalDocumentNo = time.time_ns()
@@ -2712,16 +2713,25 @@ async def _find_latest_version_candidate(
root_group_id: int | None,
region: str,
normalized_name: str,
file_ext: str | None = None,
) -> dict | None:
"""Find the latest primary document version candidate by normalized name.
"""Find the latest primary document version candidate by normalized name + extension."""
ext_clause = ""
ext_params: dict[str, object] = {}
if file_ext:
ext_clause = " AND f.file_ext = :file_ext"
ext_params["file_ext"] = file_ext
Preferred rule: same region + same root group + same normalized name.
Fallback rule: when a root group cannot be resolved, keep the old same-type behavior.
"""
if root_group_id is not None:
params: dict[str, object] = {
"root_group_id": root_group_id,
"region": region,
"normalized_name": normalized_name,
**ext_params,
}
result = await session.execute(
text(
"""
f"""
SELECT
d.id AS document_id,
d.version_group_key,
@@ -2751,7 +2761,7 @@ async def _find_latest_version_candidate(
WHERE d.region = :region
AND d.normalized_name = :normalized_name
AND d.is_latest_version = true
AND d.deleted_at IS NULL
AND d.deleted_at IS NULL{ext_clause}
AND COALESCE(
CASE
WHEN eg.id IS NULL THEN NULL
@@ -2764,19 +2774,21 @@ async def _find_latest_version_candidate(
LIMIT 1
"""
),
{
"root_group_id": root_group_id,
"region": region,
"normalized_name": normalized_name,
},
params,
)
row = result.mappings().first()
if row:
return dict(row)
params = {
"type_id": type_id,
"region": region,
"normalized_name": normalized_name,
**ext_params,
}
result = await session.execute(
text(
"""
f"""
SELECT
d.id AS document_id,
d.version_group_key,
@@ -2791,18 +2803,14 @@ async def _find_latest_version_candidate(
AND f.file_role = 'primary'
WHERE d.type_id = :type_id
AND d.region = :region
AND d.normalized_name = :normalized_name
AND d.normalized_name = :normalized_name{ext_clause}
AND d.is_latest_version = true
AND d.deleted_at IS NULL
ORDER BY d.version_no DESC, d.id DESC
LIMIT 1
"""
),
{
"type_id": type_id,
"region": region,
"normalized_name": normalized_name,
},
params,
)
row = result.mappings().first()
return dict(row) if row else None
File diff suppressed because it is too large Load Diff