refactor: remove document legacy binding reads
This commit is contained in:
@@ -1186,7 +1186,6 @@ class DocumentServiceImpl(IDocumentService):
|
||||
if not current:
|
||||
raise LeauditException(StatusCodeEnum.HTTP_404_NOT_FOUND, "文档类型不存在")
|
||||
await Session.execute(text("UPDATE leaudit_document_types SET deleted_at = NOW() WHERE id = :id"), {"id": Id})
|
||||
await Session.execute(text("UPDATE leaudit_rule_type_bindings SET deleted_at = NOW() WHERE doc_type_id = :id AND deleted_at IS NULL"), {"id": Id})
|
||||
await Session.commit()
|
||||
|
||||
async def ListDocumentTypeRoots(self, EntryModuleId: int | None = None) -> list[DocumentTypeRootItemVO]:
|
||||
@@ -1362,27 +1361,6 @@ class DocumentServiceImpl(IDocumentService):
|
||||
if normalizedRuleSetId not in current:
|
||||
current.append(normalizedRuleSetId)
|
||||
|
||||
# 兼容历史数据:若某些文档类型尚未完成分组绑定迁移,再回退读取旧绑定表。
|
||||
missingDocTypeIds = [docTypeId for docTypeId, ruleSetIds in bindingsMap.items() if len(ruleSetIds) == 0]
|
||||
if missingDocTypeIds:
|
||||
legacyBindingRows = (
|
||||
await Session.execute(
|
||||
text(
|
||||
"""
|
||||
SELECT doc_type_id, rule_set_id
|
||||
FROM leaudit_rule_type_bindings
|
||||
WHERE doc_type_id = ANY(:ids) AND deleted_at IS NULL AND is_active = true
|
||||
ORDER BY priority DESC
|
||||
"""
|
||||
),
|
||||
{"ids": missingDocTypeIds},
|
||||
)
|
||||
).fetchall()
|
||||
for docTypeId, ruleSetId in legacyBindingRows:
|
||||
current = bindingsMap.setdefault(int(docTypeId), [])
|
||||
normalizedRuleSetId = int(ruleSetId)
|
||||
if normalizedRuleSetId not in current:
|
||||
current.append(normalizedRuleSetId)
|
||||
return rows, bindingsMap
|
||||
|
||||
async def _queryDocumentTypeRoots(self, Session, Ids: list[int] | None = None, EntryModuleId: int | None = None):
|
||||
|
||||
@@ -219,30 +219,15 @@ async def sync_group_bindings_from_doc_type(session, doc_type_id: int, rule_set_
|
||||
group_ids = await ensure_group_for_doc_type(session, doc_type_id)
|
||||
child_group_id = group_ids["child_group_id"]
|
||||
|
||||
legacy_bindings = (
|
||||
await session.execute(
|
||||
text(
|
||||
"""
|
||||
SELECT id, rule_set_id, priority, is_active, note
|
||||
FROM leaudit_rule_type_bindings
|
||||
WHERE doc_type_id = :doc_type_id AND deleted_at IS NULL
|
||||
ORDER BY priority DESC, id ASC
|
||||
"""
|
||||
),
|
||||
{"doc_type_id": doc_type_id},
|
||||
)
|
||||
).mappings().all()
|
||||
binding_map = {int(row["rule_set_id"]): row for row in legacy_bindings}
|
||||
payload: list[dict[str, Any]] = []
|
||||
for index, rule_set_id in enumerate(ids):
|
||||
current = binding_map.get(rule_set_id)
|
||||
payload.append(
|
||||
{
|
||||
"id": current.get("id") if current else None,
|
||||
"rule_set_id": rule_set_id,
|
||||
"priority": int(current.get("priority") if current else 100 - index),
|
||||
"is_active": bool(current.get("is_active") if current else True),
|
||||
"note": current.get("note") if current else None,
|
||||
"id": None,
|
||||
"priority": 100 - index,
|
||||
"is_active": True,
|
||||
"note": None,
|
||||
}
|
||||
)
|
||||
await _replace_group_bindings(session, child_group_id, doc_type_id, payload)
|
||||
|
||||
Reference in New Issue
Block a user