chore: initial commit — leaudit-platform project skeleton
17-table PostgreSQL schema with full Chinese column comments, FastAPI project structure (admin/common/modules), DSL rule files, and schema migration scripts.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
"""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")
|
||||
|
||||
@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
|
||||
Reference in New Issue
Block a user