c776af598a
- Add region column to leaudit_documents + LeauditDocument model - AuditServiceImpl: read region from document.region, not APP_REGION - RuleServiceImpl: ListBindings/CreateBinding accept Region parameter - RuleBindingCreateDTO: add region field - RuleController: pass region from query param/DTO to service - APP_REGION removed from binding queries; region flows from document Region is now per-document: each document carries its region at upload time, and rules are matched to the document's region at run time.
46 lines
2.0 KiB
Python
46 lines
2.0 KiB
Python
"""LeAudit 域文档镜像模型 —— leaudit_documents 表。
|
|
|
|
通过 biz_document_id 关联业务 documents 表,不复制业务字段。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from sqlalchemy import BigInteger, String, ForeignKey
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from fastapi_common.fastapi_common_web.models import BaseModel
|
|
|
|
|
|
class LeauditDocument(BaseModel):
|
|
"""LeAudit 文档镜像表。"""
|
|
|
|
__tablename__ = "leaudit_documents"
|
|
|
|
Id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
|
|
bizDocumentId: Mapped[int] = mapped_column(BigInteger, unique=True, comment="关联业务 documents.id")
|
|
typeId: Mapped[int | None] = mapped_column(BigInteger, comment="文档类型ID")
|
|
processingStatus: Mapped[str | None] = mapped_column(String(64), default="waiting", comment="waiting/processing/completed/failed")
|
|
currentRunId: Mapped[int | None] = mapped_column(BigInteger, comment="最新有效 run id")
|
|
region: Mapped[str] = mapped_column(String(32), default="default", comment="所属地区: mz/yf/jy/cz/default")
|
|
|
|
@classmethod
|
|
async def get_by_biz_id(cls, session: AsyncSession, bizDocumentId: int) -> "LeauditDocument | None":
|
|
"""按业务文档 ID 查询。"""
|
|
from sqlalchemy import select
|
|
return await session.scalar(select(cls).where(cls.bizDocumentId == bizDocumentId))
|
|
|
|
@classmethod
|
|
async def upsert_by_biz_id(cls, session: AsyncSession, bizDocumentId: int, **fields) -> "LeauditDocument":
|
|
"""按业务文档 ID 创建或更新。"""
|
|
from sqlalchemy import select
|
|
doc = await session.scalar(select(cls).where(cls.bizDocumentId == bizDocumentId))
|
|
if doc is None:
|
|
doc = cls(bizDocumentId=bizDocumentId, **fields)
|
|
session.add(doc)
|
|
else:
|
|
for k, v in fields.items():
|
|
setattr(doc, k, v)
|
|
await session.flush()
|
|
return doc
|