feat(contract): 采购合同对比agent
Signed-off-by: sophie <sophie> Signed-off-by: sophie <sophie>
This commit is contained in:
1 parent
ffccf19ba2
commit
0503ff76a6
90 files changed
+16729
-1344
No files matched your search
@@ -17,6 +17,7 @@ from app.models.maintenance import MaintenanceAuditLog, MaintenanceDevice, Maint
|
||||
from app.models.schedule import ScheduleRun, ScheduleTask, ScheduleTaskConfig
|
||||
from app.models.settings import AppSetting
|
||||
from app.models.file_asset import FileAsset
|
||||
from app.models.contract import ContractReview, ContractRiskRule, ContractTemplate
|
||||
from app.models.shipping import (
|
||||
ShippingBatch,
|
||||
ShippingInventoryFile,
|
||||
@@ -74,6 +75,9 @@ __all__ = [
|
||||
'ShippingNoticeDocument',
|
||||
'ShippingNoticeCandidate',
|
||||
'FileAsset',
|
||||
'ContractTemplate',
|
||||
'ContractReview',
|
||||
'ContractRiskRule',
|
||||
'AgentGuide',
|
||||
'AgentDirectoryMember',
|
||||
'TrainingRecord',
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
"""
|
||||
backend/app/models/contract.py
|
||||
|
||||
用途:采购合同审查域模型——标准模板库与单次审查记录。
|
||||
依赖:models.base.Base、users / agents / file_assets FK。
|
||||
逻辑:Admin 模板库与历史页、Chat/Tool 发起审查均读写本表;不绑定 ScheduleRun。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Any, Optional
|
||||
|
||||
from sqlalchemy import JSON, Boolean, DateTime, ForeignKey, Integer, String, Text, UniqueConstraint
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.models.base import Base
|
||||
|
||||
|
||||
class ContractTemplate(Base):
|
||||
"""管理员维护的标准采购合同模板。"""
|
||||
|
||||
__tablename__ = "contract_templates"
|
||||
__table_args__ = (
|
||||
UniqueConstraint("name", "version", name="uq_contract_templates_name_version"),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
name: Mapped[str] = mapped_column(String(128), nullable=False)
|
||||
version: Mapped[str] = mapped_column(String(32), nullable=False)
|
||||
file_asset_id: Mapped[Optional[int]] = mapped_column(ForeignKey("file_assets.id"), nullable=True)
|
||||
file_name: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
contract_type: Mapped[str] = mapped_column(String(64), default="general_procurement", nullable=False, index=True)
|
||||
applicable_scope: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
||||
change_note: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
||||
comparison_region_config: Mapped[Optional[dict[str, Any]]] = mapped_column(JSON, nullable=True)
|
||||
status: Mapped[str] = mapped_column(String(16), default="enabled", nullable=False, index=True)
|
||||
is_default: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
|
||||
remark: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
||||
created_by: Mapped[Optional[int]] = mapped_column(ForeignKey("users.id"), nullable=True)
|
||||
updated_by: Mapped[Optional[int]] = mapped_column(ForeignKey("users.id"), nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, nullable=False)
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False
|
||||
)
|
||||
|
||||
|
||||
class ContractReview(Base):
|
||||
"""一次单合同审查记录(模板比对或单份审核)。"""
|
||||
|
||||
__tablename__ = "contract_reviews"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
review_no: Mapped[str] = mapped_column(String(64), unique=True, nullable=False, index=True)
|
||||
agent_id: Mapped[Optional[int]] = mapped_column(ForeignKey("agents.id"), nullable=True, index=True)
|
||||
user_id: Mapped[int] = mapped_column(ForeignKey("users.id"), nullable=False, index=True)
|
||||
chat_log_id: Mapped[Optional[int]] = mapped_column(ForeignKey("chat_logs.id"), nullable=True)
|
||||
|
||||
review_mode: Mapped[str] = mapped_column(String(16), nullable=False, index=True) # compare | solo
|
||||
status: Mapped[str] = mapped_column(String(16), default="pending", nullable=False, index=True)
|
||||
|
||||
contract_asset_id: Mapped[Optional[int]] = mapped_column(ForeignKey("file_assets.id"), nullable=True)
|
||||
contract_file_name: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
supplier_name: Mapped[Optional[str]] = mapped_column(String(128), nullable=True, index=True)
|
||||
# 从对方合同正文抽取的业务合同编号(非审查编号 review_no)
|
||||
contract_no: Mapped[Optional[str]] = mapped_column(String(128), nullable=True, index=True)
|
||||
contract_type: Mapped[str] = mapped_column(String(64), default="general_procurement", nullable=False, index=True)
|
||||
|
||||
template_id: Mapped[Optional[int]] = mapped_column(ForeignKey("contract_templates.id"), nullable=True)
|
||||
template_source: Mapped[str] = mapped_column(String(16), nullable=False, default="none")
|
||||
# library | user_upload | none
|
||||
template_asset_id: Mapped[Optional[int]] = mapped_column(ForeignKey("file_assets.id"), nullable=True)
|
||||
template_name: Mapped[Optional[str]] = mapped_column(String(255), nullable=True)
|
||||
|
||||
total_change_count: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
|
||||
high_risk_count: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
|
||||
medium_risk_count: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
|
||||
low_risk_count: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
|
||||
|
||||
summary_json: Mapped[Optional[dict[str, Any]]] = mapped_column(JSON, nullable=True)
|
||||
clauses_json: Mapped[Optional[list[Any]]] = mapped_column(JSON, nullable=True)
|
||||
report_text: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
||||
error_message: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
||||
|
||||
started_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
|
||||
finished_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, nullable=False, index=True)
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False
|
||||
)
|
||||
|
||||
|
||||
class ContractRiskRule(Base):
|
||||
"""Configurable procurement contract risk rule used by solo and compare review."""
|
||||
|
||||
__tablename__ = "contract_risk_rules"
|
||||
__table_args__ = (
|
||||
UniqueConstraint("code", name="uq_contract_risk_rules_code"),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
code: Mapped[str] = mapped_column(String(64), nullable=False)
|
||||
contract_type: Mapped[str] = mapped_column(String(64), default="general_procurement", nullable=False, index=True)
|
||||
clause_category: Mapped[str] = mapped_column(String(64), nullable=False, index=True)
|
||||
title: Mapped[str] = mapped_column(String(128), nullable=False)
|
||||
keywords: Mapped[list[Any]] = mapped_column(JSON, nullable=False, default=list)
|
||||
trigger_type: Mapped[str] = mapped_column(String(32), default="keyword_missing", nullable=False)
|
||||
risk_level: Mapped[str] = mapped_column(String(16), nullable=False, index=True)
|
||||
risk_hint: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
suggestion: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
negotiation_text: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
||||
status: Mapped[str] = mapped_column(String(16), default="enabled", nullable=False, index=True)
|
||||
sort_order: Mapped[int] = mapped_column(Integer, default=100, nullable=False)
|
||||
created_by: Mapped[Optional[int]] = mapped_column(ForeignKey("users.id"), nullable=True)
|
||||
updated_by: Mapped[Optional[int]] = mapped_column(ForeignKey("users.id"), nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, nullable=False)
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False
|
||||
)
|
||||
Reference in new issue
Block a user