fix: fix merge conflicts

This commit is contained in:
sophie committed 2026-09-02 11:49:20 +08:00
commit 03b9b46ebd
114 files changed
+11408 -2996

No files matched your search

+33
View File
@@ -20,6 +20,15 @@ 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.contract_payment import (
ContractPaymentAlert,
ContractPaymentAttachment,
ContractPaymentContract,
ContractPaymentEvent,
ContractPaymentNode,
ContractPaymentSyncState,
ContractPaymentVendorRequest,
)
from app.models.shipping import (
ShippingInventoryFile,
ShippingNotice,
@@ -186,6 +195,16 @@ from app.models.shipping_inventory_mapping import ShippingInventoryMapping
from app.models.training import TrainingRecord, TrainingConfig, TrainingConfigResource
from app.models.user import LoginAudit, User, UserDefaultAgent, UserFavoriteAgent, UserHomepageConfig
from app.models.voucher_check import VoucherCheckInvoiceState, VoucherCheckRunItem
from app.models.contract_payment import (
ContractPaymentAlert,
ContractPaymentAlertBatch,
ContractPaymentAttachment,
ContractPaymentContract,
ContractPaymentEvent,
ContractPaymentNode,
ContractPaymentSyncState,
ContractPaymentVendorRequest,
)
from app.models.wecom import WecomCallbackAudit, WecomNotifyAudit
__all__ = [
@@ -342,6 +361,12 @@ __all__ = [
'ContractTemplate',
'ContractReview',
'ContractRiskRule',
'ContractPaymentContract',
'ContractPaymentAttachment',
'ContractPaymentNode',
'ContractPaymentEvent',
'ContractPaymentVendorRequest',
'ContractPaymentAlert',
'AgentGuide',
'AgentDirectoryMember',
'TrainingRecord',
@@ -356,4 +381,12 @@ __all__ = [
'ShippingTaskInventoryRpaAttempt',
'VoucherCheckInvoiceState',
'VoucherCheckRunItem',
'ContractPaymentContract',
'ContractPaymentAttachment',
'ContractPaymentNode',
'ContractPaymentEvent',
'ContractPaymentVendorRequest',
'ContractPaymentAlert',
'ContractPaymentAlertBatch',
'ContractPaymentSyncState',
]
+208
View File
@@ -0,0 +1,208 @@
"""
backend/app/models/contract_payment.py
用途:采购合同付款预警域模型,保存 OA 合同台账、附件来源、付款节点、履约事件和企微预警幂等记录。
依赖:models.base.Base、users、file_assets。
逻辑:同步服务写入合同、付款请款与事件,解析服务生成付款节点,预警服务按节点状态写入提醒记录并调用企业微信。
"""
from __future__ import annotations
from datetime import date, datetime
from decimal import Decimal
from typing import Any, Optional
from sqlalchemy import Date, DateTime, ForeignKey, Index, JSON, LargeBinary, Numeric, String, Text, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column
from app.models.base import Base
class ContractPaymentContract(Base):
"""OA 归档后的采购合同主记录。"""
__tablename__ = "contract_payment_contracts"
__table_args__ = (
UniqueConstraint("contract_no", name="uq_contract_payment_contracts_contract_no"),
Index("ix_contract_payment_contracts_purchase_order_no", "purchase_order_no"),
Index("ix_contract_payment_contracts_status", "status"),
)
id: Mapped[int] = mapped_column(primary_key=True)
# 合同附件解析前可能为空;OA 表单中的流程编号不再写入此字段。
contract_no: Mapped[Optional[str]] = mapped_column(String(128), nullable=True)
purchase_order_no: Mapped[Optional[str]] = mapped_column(String(128), nullable=True)
supplier_name: Mapped[Optional[str]] = mapped_column(String(255), nullable=True)
applicant_name: Mapped[Optional[str]] = mapped_column(String(128), nullable=True)
total_amount: Mapped[Optional[Decimal]] = mapped_column(Numeric(18, 2), nullable=True)
currency: Mapped[Optional[str]] = mapped_column(String(16), nullable=True)
effective_date: Mapped[Optional[date]] = mapped_column(Date, nullable=True)
delivery_due_date: Mapped[Optional[date]] = mapped_column(Date, nullable=True)
warranty_period_days: Mapped[Optional[int]] = mapped_column(nullable=True)
owner_user_id: Mapped[Optional[int]] = mapped_column(ForeignKey("users.id"), nullable=True, index=True)
oa_record_id: Mapped[Optional[str]] = mapped_column(String(128), nullable=True, index=True)
workflow_no: Mapped[Optional[str]] = mapped_column(String(128), nullable=True, index=True)
oa_archive_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
status: Mapped[str] = mapped_column(String(32), default="active", nullable=False)
parse_status: Mapped[str] = mapped_column(String(32), default="pending", nullable=False, index=True)
plan_status: Mapped[str] = mapped_column(String(32), default="pending", nullable=False, index=True)
source_payload_json: Mapped[Optional[dict[str, Any]]] = mapped_column(JSON, nullable=True)
parse_result_json: Mapped[Optional[dict[str, Any]]] = mapped_column(JSON, 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 ContractPaymentAttachment(Base):
"""合同附件来源记录;OA 为主来源,文档管理系统为延迟补充。"""
__tablename__ = "contract_payment_attachments"
__table_args__ = (
UniqueConstraint("contract_id", "source", "source_key", name="uq_contract_payment_attachments_source"),
Index("ix_contract_payment_attachments_contract", "contract_id"),
)
id: Mapped[int] = mapped_column(primary_key=True)
contract_id: Mapped[int] = mapped_column(ForeignKey("contract_payment_contracts.id", ondelete="CASCADE"), nullable=False)
source: Mapped[str] = mapped_column(String(32), nullable=False) # oa | dms
source_key: Mapped[str] = mapped_column(String(512), nullable=False)
file_name: Mapped[str] = mapped_column(String(255), nullable=False)
mime_type: Mapped[Optional[str]] = mapped_column(String(128), nullable=True)
file_asset_id: Mapped[Optional[int]] = mapped_column(ForeignKey("file_assets.id"), nullable=True)
dms_path: Mapped[Optional[str]] = mapped_column(String(1024), nullable=True)
created_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
metadata_json: Mapped[Optional[dict[str, Any]]] = mapped_column(JSON, nullable=True)
status: Mapped[str] = mapped_column(String(32), default="discovered", nullable=False)
created_record_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, nullable=False)
class ContractPaymentNode(Base):
"""从合同条款编译出的付款节点。"""
__tablename__ = "contract_payment_nodes"
__table_args__ = (
UniqueConstraint("contract_id", "node_code", name="uq_contract_payment_nodes_code"),
Index("ix_contract_payment_nodes_due_date", "due_date", "status"),
)
id: Mapped[int] = mapped_column(primary_key=True)
contract_id: Mapped[int] = mapped_column(ForeignKey("contract_payment_contracts.id", ondelete="CASCADE"), nullable=False)
node_code: Mapped[str] = mapped_column(String(64), nullable=False)
node_type: Mapped[str] = mapped_column(String(32), nullable=False)
amount: Mapped[Optional[Decimal]] = mapped_column(Numeric(18, 2), nullable=True)
percentage: Mapped[Optional[Decimal]] = mapped_column(Numeric(8, 4), nullable=True)
anchor_type: Mapped[Optional[str]] = mapped_column(String(32), nullable=True)
anchor_date: Mapped[Optional[date]] = mapped_column(Date, nullable=True)
offset_days: Mapped[int] = mapped_column(default=0, nullable=False)
due_date: Mapped[Optional[date]] = mapped_column(Date, nullable=True)
reminder_days: Mapped[int] = mapped_column(default=14, nullable=False)
status: Mapped[str] = mapped_column(String(32), default="pending", nullable=False, index=True)
evidence_json: Mapped[Optional[dict[str, Any]]] = mapped_column(JSON, 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 ContractPaymentEvent(Base):
"""OA 验收归档及可选履约事件。"""
__tablename__ = "contract_payment_events"
__table_args__ = (
UniqueConstraint("event_type", "source_event_id", name="uq_contract_payment_events_source"),
Index("ix_contract_payment_events_contract_type", "contract_id", "event_type"),
)
id: Mapped[int] = mapped_column(primary_key=True)
contract_id: Mapped[int] = mapped_column(ForeignKey("contract_payment_contracts.id", ondelete="CASCADE"), nullable=False)
event_type: Mapped[str] = mapped_column(String(32), nullable=False)
event_date: Mapped[date] = mapped_column(Date, nullable=False)
source_event_id: Mapped[str] = mapped_column(String(128), nullable=False)
payload_json: Mapped[Optional[dict[str, Any]]] = mapped_column(JSON, nullable=True)
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, nullable=False)
class ContractPaymentVendorRequest(Base):
"""OA 厂商预付款请款作业的标准化记录,用于判定预付款与出货款是否还需提醒。"""
__tablename__ = "contract_payment_vendor_requests"
__table_args__ = (
UniqueConstraint("source_request_id", name="uq_contract_payment_vendor_requests_source"),
Index("ix_contract_payment_vendor_requests_contract_stage", "contract_id", "payment_stage"),
)
id: Mapped[int] = mapped_column(primary_key=True)
contract_id: Mapped[int] = mapped_column(ForeignKey("contract_payment_contracts.id", ondelete="CASCADE"), nullable=False)
source_request_id: Mapped[str] = mapped_column(String(128), nullable=False)
request_no: Mapped[Optional[str]] = mapped_column(String(128), nullable=True)
payment_stage: Mapped[str] = mapped_column(String(32), nullable=False)
request_status: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
requested_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
payload_json: Mapped[Optional[dict[str, Any]]] = mapped_column(JSON, 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 ContractPaymentAlert(Base):
"""付款预警发送幂等和审计记录。"""
__tablename__ = "contract_payment_alerts"
__table_args__ = (
UniqueConstraint("node_id", "trigger_key", "recipient_user_id", name="uq_contract_payment_alerts_trigger"),
Index("ix_contract_payment_alerts_status_scheduled", "status", "scheduled_at"),
)
id: Mapped[int] = mapped_column(primary_key=True)
contract_id: Mapped[int] = mapped_column(ForeignKey("contract_payment_contracts.id", ondelete="CASCADE"), nullable=False)
node_id: Mapped[int] = mapped_column(ForeignKey("contract_payment_nodes.id", ondelete="CASCADE"), nullable=False)
trigger_key: Mapped[str] = mapped_column(String(64), nullable=False)
scheduled_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
sent_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
recipient_user_id: Mapped[Optional[int]] = mapped_column(ForeignKey("users.id"), nullable=True)
alert_round: Mapped[int] = mapped_column(default=1, nullable=False)
status: Mapped[str] = mapped_column(String(32), default="pending", nullable=False, index=True)
message_json: Mapped[Optional[dict[str, Any]]] = mapped_column(JSON, nullable=True)
error_message: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, nullable=False)
class ContractPaymentAlertBatch(Base):
"""按周、按收件人归并的合同付款预警发送批次。"""
__tablename__ = "contract_payment_alert_batches"
__table_args__ = (
UniqueConstraint("week_key", "recipient_user_id", name="uq_contract_payment_alert_batches_week_recipient"),
Index("ix_contract_payment_alert_batches_status_created", "status", "created_at"),
)
id: Mapped[int] = mapped_column(primary_key=True)
batch_no: Mapped[str] = mapped_column(String(64), unique=True, nullable=False)
week_key: Mapped[str] = mapped_column(String(16), nullable=False)
recipient_user_id: Mapped[int] = mapped_column(ForeignKey("users.id"), nullable=False)
status: Mapped[str] = mapped_column(String(32), default="pending", nullable=False)
summary_json: Mapped[Optional[dict[str, Any]]] = mapped_column(JSON, nullable=True)
excel_file_name: Mapped[Optional[str]] = mapped_column(String(255), nullable=True)
excel_file_data: Mapped[Optional[bytes]] = mapped_column(LargeBinary, nullable=True)
excel_file_size: Mapped[Optional[int]] = mapped_column(nullable=True)
sent_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
wecom_trace_json: Mapped[Optional[dict[str, Any]]] = mapped_column(JSON, nullable=True)
error_message: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, nullable=False)
class ContractPaymentSyncState(Base):
"""合同付款域外部来源的 OA 增量同步断点(游标)。
用途:记录 OA 合同 HTTP 列表与验收 SQL 同步上次成功位置,供时间窗口增量拉取。
依赖:models.base.Base。
逻辑:同一 state_key 只保留一行;合同列表用 `oa-contract-archive`,验收归档用 `oa-acceptance-archive`。
成功同步后更新 last_successful_sync_at,下次以它减去 overlap 作为时间下限。
"""
__tablename__ = "contract_payment_sync_states"
id: Mapped[int] = mapped_column(primary_key=True)
state_key: Mapped[str] = mapped_column(String(64), unique=True, nullable=False)
last_successful_sync_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
last_archive_seen_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
last_run_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
synced_contract_count: Mapped[int] = mapped_column(default=0, nullable=False)
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)
+7 -1
View File
@@ -96,6 +96,8 @@ class User(Base):
'shipping_notice.xfa_split_rule_edit': self.role == 'admin',
'shipping_notice.xfa_split_rule_preview': self.role == 'admin',
'shipping_notice.xfa_split_rule_publish': self.role == 'admin',
# 合同付款预警工作台:admin 默认开;不新建角色,可给采购同事单独授予
'contract_payment.access': self.role == 'admin',
}
def get_feature_permissions(self) -> dict[str, bool]:
@@ -103,7 +105,7 @@ class User(Base):
返回当前用户的有效功能权限。
用途:统一为前端展示、登录态注入与后端业务校验提供同一份权限结果。
核心逻辑:先按角色生成默认权限,再用用户显式配置覆盖,避免把培训类业务权限硬编码在多个模块。
核心逻辑:先按角色生成默认权限,再用用户显式配置覆盖,避免把培训、合同付款等业务权限硬编码在多个模块。
输出约束:仅返回布尔型权限键,缺失项自动回退到角色默认值。
"""
defaults = self._role_default_feature_permissions()
@@ -143,6 +145,10 @@ class User(Base):
"""判断当前用户是否可使用培训 HR 管理面板与接口。"""
return self.has_feature_permission('training_hr_manage')
def can_access_contract_payment(self) -> bool:
"""判断当前用户是否可查看合同付款预警工作台并触发同步/扫描。"""
return self.has_feature_permission('contract_payment.access')
def set_password(self, password: str) -> None:
"""设置密码哈希。"""
self.password_hash = generate_password_hash(password)