Core modules: - Laws: CRUD, search, AI-powered QA - Analysis: legal research and case management - Contracts: lifecycle management with templates - Signatures: electronic signature workflow Infrastructure: - FastAPI + SQLite + async SQLAlchemy - Docker deployment support - 54 unit tests passing Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
107 lines
3.5 KiB
Python
107 lines
3.5 KiB
Python
"""Law model for legal regulations."""
|
|
import enum
|
|
from datetime import date, datetime
|
|
from typing import Optional, List
|
|
|
|
from sqlalchemy import String, Text, Date, DateTime, Enum as SQLEnum, Integer, ForeignKey
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.core.database import Base
|
|
|
|
|
|
class LawType(str, enum.Enum):
|
|
"""Law type enumeration."""
|
|
LAW = "law" # 法律
|
|
REGULATION = "regulation" # 法规
|
|
RULE = "rule" # 规章
|
|
JUDICIAL_INTERPRETATION = "judicial_interpretation" # 司法解释
|
|
|
|
|
|
class LawStatus(str, enum.Enum):
|
|
"""Law status enumeration."""
|
|
EFFECTIVE = "effective" # 有效
|
|
REVOKED = "revoked" # 废止
|
|
AMENDED = "amended" # 修订
|
|
|
|
|
|
class Law(Base):
|
|
"""Law model for legal regulations."""
|
|
|
|
__tablename__ = "laws"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
|
title: Mapped[str] = mapped_column(String(200), index=True)
|
|
law_type: Mapped[LawType] = mapped_column(SQLEnum(LawType), nullable=False)
|
|
promulgation_date: Mapped[date] = mapped_column(Date, nullable=False)
|
|
effective_date: Mapped[date] = mapped_column(Date, nullable=False)
|
|
status: Mapped[LawStatus] = mapped_column(
|
|
SQLEnum(LawStatus),
|
|
nullable=False
|
|
)
|
|
issuing_authority: Mapped[str] = mapped_column(String(100))
|
|
content: Mapped[str] = mapped_column(Text)
|
|
document_number: Mapped[Optional[str]] = mapped_column(String(50), nullable=True)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
|
updated_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
|
|
|
# Relationships
|
|
articles: Mapped[List["LawArticle"]] = relationship(
|
|
back_populates="law", cascade="all, delete-orphan"
|
|
)
|
|
|
|
def __init__(
|
|
self,
|
|
title: str,
|
|
law_type: LawType,
|
|
promulgation_date: date,
|
|
effective_date: date,
|
|
issuing_authority: str,
|
|
content: str,
|
|
status: LawStatus = LawStatus.EFFECTIVE,
|
|
document_number: Optional[str] = None,
|
|
**kwargs
|
|
):
|
|
self.title = title
|
|
self.law_type = law_type
|
|
self.promulgation_date = promulgation_date
|
|
self.effective_date = effective_date
|
|
self.status = status
|
|
self.issuing_authority = issuing_authority
|
|
self.content = content
|
|
self.document_number = document_number
|
|
self.created_at = datetime.utcnow()
|
|
self.updated_at = datetime.utcnow()
|
|
|
|
def __repr__(self) -> str:
|
|
return f"<Law(id={self.id}, title={self.title})>"
|
|
|
|
|
|
class LawArticle(Base):
|
|
"""Law article model for individual articles."""
|
|
|
|
__tablename__ = "law_articles"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
|
law_id: Mapped[int] = mapped_column(Integer, ForeignKey("laws.id"), index=True)
|
|
article_number: Mapped[str] = mapped_column(String(20))
|
|
content: Mapped[str] = mapped_column(Text)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
|
|
|
# Relationships
|
|
law: Mapped["Law"] = relationship(back_populates="articles")
|
|
|
|
def __init__(
|
|
self,
|
|
law_id: int,
|
|
article_number: str,
|
|
content: str,
|
|
**kwargs
|
|
):
|
|
self.law_id = law_id
|
|
self.article_number = article_number
|
|
self.content = content
|
|
self.created_at = datetime.utcnow()
|
|
|
|
def __repr__(self) -> str:
|
|
return f"<LawArticle(id={self.id}, article_number={self.article_number})>"
|