diff --git a/fastapi_modules/fastapi_leaudit/services/impl/documentServiceImpl.py b/fastapi_modules/fastapi_leaudit/services/impl/documentServiceImpl.py index 4e0bff9..daa222b 100644 --- a/fastapi_modules/fastapi_leaudit/services/impl/documentServiceImpl.py +++ b/fastapi_modules/fastapi_leaudit/services/impl/documentServiceImpl.py @@ -3,6 +3,9 @@ from __future__ import annotations import json +import logging + +logger = logging.getLogger(__name__) from typing import Any from datetime import date as date_type, datetime import hashlib @@ -1576,20 +1579,25 @@ class DocumentServiceImpl(IDocumentService): await Session.execute( text( """ - SELECT id + SELECT id, document_type_id, name FROM leaudit_evaluation_point_groups WHERE id = :group_id - AND document_type_id = :doc_type_id AND deleted_at IS NULL AND COALESCE(pid, 0) <> 0 LIMIT 1 """ ), - {"group_id": GroupId, "doc_type_id": TypeId}, + {"group_id": GroupId}, ) ).mappings().first() if not row: - raise LeauditException(StatusCodeEnum.HTTP_400_BAD_REQUEST, "当前子类型不属于所选文档类型,无法上传") + raise LeauditException(StatusCodeEnum.HTTP_400_BAD_REQUEST, f"子类型 (id={GroupId}) 不存在或不是有效的二级分组,无法上传") + if int(row["document_type_id"] or 0) != TypeId: + logger.warning( + "_resolveDocumentGroupId mismatch: TypeId=%s GroupId=%s group_doc_type_id=%s group_name=%s", + TypeId, GroupId, row["document_type_id"], row["name"], + ) + raise LeauditException(StatusCodeEnum.HTTP_400_BAD_REQUEST, f"当前子类型「{row['name']}」(id={GroupId}) 属于文档类型 {row['document_type_id']},与所选文档类型 {TypeId} 不匹配,无法上传") return int(row["id"]) async def _resolveDocumentRootGroupId(self, Session, TypeId: int, GroupId: int | None) -> int | None: