Merge branch 'dev' into hugo-shipping-notice
This commit is contained in:
commit
472b530be3
397 files changed
+46450
-34171
No files matched your search
@@ -0,0 +1,235 @@
|
||||
"""
|
||||
backend/migrations/versions/a0b1c2d3e4f5_add_voucher_check_tables.py
|
||||
|
||||
用途:新增立账凭证检核状态/明细表,并种子日批 ScheduleTask(06:00)。
|
||||
依赖:Alembic revision e5f7a9b1c3d4;schedule_runs / users 已存在。
|
||||
逻辑:建表 + 幂等插入 SCH-ACCOUNTING-VOUCHER-CHECK;无用户时跳过种子由应用钩子补建。
|
||||
|
||||
Revision ID: a0b1c2d3e4f5
|
||||
Revises: e5f7a9b1c3d4
|
||||
Create Date: 2026-08-05 10:50:00.000000
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision = "a0b1c2d3e4f5"
|
||||
down_revision = "e5f7a9b1c3d4"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
_SCHEDULE_NO = "SCH-ACCOUNTING-VOUCHER-CHECK"
|
||||
_CRON_EXPR = "0 6 * * *"
|
||||
_TZ_NAME = "Asia/Shanghai"
|
||||
|
||||
_DEFAULT_JOB_PARAMS = {
|
||||
"scope_code": "HXJM",
|
||||
"directory_template": "{root}/{YYYY}/{MM}/{invoice_no}",
|
||||
"required_files": [
|
||||
{
|
||||
"code": "price_check_sheet",
|
||||
"name": "核价单",
|
||||
"required": True,
|
||||
"accepted_filenames": ["核价单.pdf"],
|
||||
},
|
||||
{
|
||||
"code": "purchase_order",
|
||||
"name": "采购单",
|
||||
"required": True,
|
||||
"accepted_filenames": ["采购单.pdf"],
|
||||
},
|
||||
],
|
||||
"filename_case_sensitive": True,
|
||||
"notify_missing_enabled": True,
|
||||
"notify_failure_enabled": True,
|
||||
"same_day_dedup_enabled": True,
|
||||
}
|
||||
|
||||
|
||||
def _compute_next_run_at_utc_naive() -> datetime:
|
||||
try:
|
||||
from croniter import croniter
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
tz = ZoneInfo(_TZ_NAME)
|
||||
base = datetime.now(tz)
|
||||
next_local = croniter(_CRON_EXPR, base).get_next(datetime)
|
||||
if next_local.tzinfo is None:
|
||||
next_local = next_local.replace(tzinfo=tz)
|
||||
return next_local.astimezone(timezone.utc).replace(tzinfo=None)
|
||||
except Exception:
|
||||
tz = timezone(timedelta(hours=8))
|
||||
now_local = datetime.now(tz)
|
||||
next_local = now_local.replace(hour=6, minute=0, second=0, microsecond=0)
|
||||
if next_local <= now_local:
|
||||
next_local = next_local + timedelta(days=1)
|
||||
return next_local.astimezone(timezone.utc).replace(tzinfo=None)
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"voucher_check_invoice_states",
|
||||
sa.Column("id", sa.BigInteger(), primary_key=True, autoincrement=True),
|
||||
sa.Column("scope_code", sa.String(length=32), nullable=False),
|
||||
sa.Column("period_month", sa.Date(), nullable=False),
|
||||
sa.Column("invoice_no", sa.String(length=128), nullable=False),
|
||||
sa.Column("invoice_date", sa.Date(), nullable=True),
|
||||
sa.Column("status", sa.String(length=24), nullable=False),
|
||||
sa.Column("folder_path", sa.String(length=1024), nullable=True),
|
||||
sa.Column("folder_exists", sa.Boolean(), nullable=False, server_default=sa.text("false")),
|
||||
sa.Column("material_fingerprint", sa.String(length=64), nullable=True),
|
||||
sa.Column("matched_files_json", sa.JSON(), nullable=True),
|
||||
sa.Column("missing_materials_json", sa.JSON(), nullable=True),
|
||||
sa.Column("last_actual_run_id", sa.BigInteger(), sa.ForeignKey("schedule_runs.id", ondelete="SET NULL"), nullable=True),
|
||||
sa.Column("last_checked_at", sa.DateTime(), nullable=True),
|
||||
sa.Column("last_seen_erp_at", sa.DateTime(), nullable=True),
|
||||
sa.Column("last_missing_notified_on", sa.Date(), nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(), nullable=False),
|
||||
sa.UniqueConstraint(
|
||||
"scope_code",
|
||||
"period_month",
|
||||
"invoice_no",
|
||||
name="uq_voucher_check_invoice_states_scope_period_invoice",
|
||||
),
|
||||
)
|
||||
op.create_index(
|
||||
"ix_voucher_check_invoice_states_period_status",
|
||||
"voucher_check_invoice_states",
|
||||
["period_month", "status"],
|
||||
)
|
||||
op.create_index(
|
||||
"ix_voucher_check_invoice_states_invoice_no",
|
||||
"voucher_check_invoice_states",
|
||||
["invoice_no"],
|
||||
)
|
||||
op.create_index(
|
||||
"ix_voucher_check_invoice_states_notified_on",
|
||||
"voucher_check_invoice_states",
|
||||
["last_missing_notified_on"],
|
||||
)
|
||||
|
||||
op.create_table(
|
||||
"voucher_check_run_items",
|
||||
sa.Column("id", sa.BigInteger(), primary_key=True, autoincrement=True),
|
||||
sa.Column(
|
||||
"schedule_run_id",
|
||||
sa.BigInteger(),
|
||||
sa.ForeignKey("schedule_runs.id", ondelete="CASCADE"),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column(
|
||||
"invoice_state_id",
|
||||
sa.BigInteger(),
|
||||
sa.ForeignKey("voucher_check_invoice_states.id", ondelete="SET NULL"),
|
||||
nullable=True,
|
||||
),
|
||||
sa.Column("scope_code", sa.String(length=32), nullable=False),
|
||||
sa.Column("period_month", sa.Date(), nullable=False),
|
||||
sa.Column("invoice_no", sa.String(length=128), nullable=False),
|
||||
sa.Column("invoice_date", sa.Date(), nullable=True),
|
||||
sa.Column("result", sa.String(length=24), nullable=False),
|
||||
sa.Column("folder_path", sa.String(length=1024), nullable=True),
|
||||
sa.Column("folder_exists", sa.Boolean(), nullable=False, server_default=sa.text("false")),
|
||||
sa.Column("material_fingerprint", sa.String(length=64), nullable=True),
|
||||
sa.Column("matched_files_json", sa.JSON(), nullable=True),
|
||||
sa.Column("missing_materials_json", sa.JSON(), nullable=True),
|
||||
sa.Column("error_code", sa.String(length=64), nullable=True),
|
||||
sa.Column("error_message", sa.Text(), nullable=True),
|
||||
sa.Column("checked_at", sa.DateTime(), nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||||
sa.UniqueConstraint(
|
||||
"schedule_run_id",
|
||||
"invoice_no",
|
||||
name="uq_voucher_check_run_items_run_invoice",
|
||||
),
|
||||
)
|
||||
op.create_index(
|
||||
"ix_voucher_check_run_items_schedule_run_id",
|
||||
"voucher_check_run_items",
|
||||
["schedule_run_id"],
|
||||
)
|
||||
op.create_index(
|
||||
"ix_voucher_check_run_items_run_result",
|
||||
"voucher_check_run_items",
|
||||
["schedule_run_id", "result"],
|
||||
)
|
||||
op.create_index(
|
||||
"ix_voucher_check_run_items_period_result",
|
||||
"voucher_check_run_items",
|
||||
["period_month", "result"],
|
||||
)
|
||||
|
||||
conn = op.get_bind()
|
||||
exists = conn.execute(
|
||||
sa.text(
|
||||
"SELECT 1 FROM schedule_tasks "
|
||||
"WHERE schedule_no = :sno OR platform_api_path = 'accounting-voucher-check' "
|
||||
"LIMIT 1"
|
||||
),
|
||||
{"sno": _SCHEDULE_NO},
|
||||
).first()
|
||||
if exists:
|
||||
return
|
||||
|
||||
owner = conn.execute(
|
||||
sa.text("SELECT id FROM users WHERE role = 'admin' ORDER BY id ASC LIMIT 1")
|
||||
).first()
|
||||
if owner is None:
|
||||
owner = conn.execute(sa.text("SELECT id FROM users ORDER BY id ASC LIMIT 1")).first()
|
||||
if owner is None:
|
||||
return
|
||||
|
||||
now = datetime.utcnow()
|
||||
next_run = _compute_next_run_at_utc_naive()
|
||||
conn.execute(
|
||||
sa.text(
|
||||
"""
|
||||
INSERT INTO schedule_tasks (
|
||||
schedule_no, name, schedule_type, owner_user_id,
|
||||
cron_expr, schedule_timezone, wait_seconds,
|
||||
platform_api_path, job_params,
|
||||
kb_sync_enabled, notify_enabled,
|
||||
enabled, next_run_at, last_run_at,
|
||||
created_by, updated_by, created_at, updated_at
|
||||
) VALUES (
|
||||
:schedule_no, :name, 'platform_job', :owner_user_id,
|
||||
:cron_expr, 'Asia/Shanghai', 0,
|
||||
'accounting-voucher-check', CAST(:job_params AS JSONB),
|
||||
false, true,
|
||||
true, :next_run_at, NULL,
|
||||
:owner_user_id, :owner_user_id, :now, :now
|
||||
)
|
||||
"""
|
||||
).bindparams(sa.bindparam("job_params", type_=sa.String())),
|
||||
{
|
||||
"schedule_no": _SCHEDULE_NO,
|
||||
"name": "立账凭证检核(日批)",
|
||||
"owner_user_id": int(owner[0]),
|
||||
"cron_expr": _CRON_EXPR,
|
||||
"job_params": json.dumps(_DEFAULT_JOB_PARAMS, ensure_ascii=False),
|
||||
"next_run_at": next_run,
|
||||
"now": now,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
conn = op.get_bind()
|
||||
conn.execute(
|
||||
sa.text("DELETE FROM schedule_tasks WHERE schedule_no = :sno"),
|
||||
{"sno": _SCHEDULE_NO},
|
||||
)
|
||||
op.drop_index("ix_voucher_check_run_items_period_result", table_name="voucher_check_run_items")
|
||||
op.drop_index("ix_voucher_check_run_items_run_result", table_name="voucher_check_run_items")
|
||||
op.drop_index("ix_voucher_check_run_items_schedule_run_id", table_name="voucher_check_run_items")
|
||||
op.drop_table("voucher_check_run_items")
|
||||
op.drop_index("ix_voucher_check_invoice_states_notified_on", table_name="voucher_check_invoice_states")
|
||||
op.drop_index("ix_voucher_check_invoice_states_invoice_no", table_name="voucher_check_invoice_states")
|
||||
op.drop_index("ix_voucher_check_invoice_states_period_status", table_name="voucher_check_invoice_states")
|
||||
op.drop_table("voucher_check_invoice_states")
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
revision = 'a0b1c2d3e4f5'
|
||||
revision = 'a0b1c2d3e4f6'
|
||||
down_revision = '9b0c1d2e3f4a'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
"""Add contract_templates and contract_reviews tables.
|
||||
|
||||
Purpose:
|
||||
Persist procurement contract review templates and per-contract review history.
|
||||
Dependencies:
|
||||
Alembic revision c8d9e0f1a2b3; file_assets / users / agents / chat_logs exist.
|
||||
Flow:
|
||||
Admin manages templates; chat/tool creates contract_reviews rows.
|
||||
|
||||
Revision ID: a1c2d3e4f5b6
|
||||
Revises: c8d9e0f1a2b3
|
||||
Create Date: 2026-07-15 09:30:00.000000
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision = "a1c2d3e4f5b6"
|
||||
down_revision = "c8d9e0f1a2b3"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
"""Create contract_templates and contract_reviews."""
|
||||
op.create_table(
|
||||
"contract_templates",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("name", sa.String(length=128), nullable=False),
|
||||
sa.Column("version", sa.String(length=32), nullable=False),
|
||||
sa.Column("file_asset_id", sa.Integer(), nullable=True),
|
||||
sa.Column("file_name", sa.String(length=255), nullable=False),
|
||||
sa.Column("status", sa.String(length=16), nullable=False),
|
||||
sa.Column("is_default", sa.Boolean(), nullable=False),
|
||||
sa.Column("remark", sa.Text(), nullable=True),
|
||||
sa.Column("created_by", sa.Integer(), nullable=True),
|
||||
sa.Column("updated_by", sa.Integer(), nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(), nullable=False),
|
||||
sa.ForeignKeyConstraint(["created_by"], ["users.id"]),
|
||||
sa.ForeignKeyConstraint(["file_asset_id"], ["file_assets.id"]),
|
||||
sa.ForeignKeyConstraint(["updated_by"], ["users.id"]),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
sa.UniqueConstraint("name", "version", name="uq_contract_templates_name_version"),
|
||||
)
|
||||
op.create_index("ix_contract_templates_status", "contract_templates", ["status"], unique=False)
|
||||
|
||||
op.create_table(
|
||||
"contract_reviews",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("review_no", sa.String(length=64), nullable=False),
|
||||
sa.Column("agent_id", sa.Integer(), nullable=True),
|
||||
sa.Column("user_id", sa.Integer(), nullable=False),
|
||||
sa.Column("chat_log_id", sa.Integer(), nullable=True),
|
||||
sa.Column("review_mode", sa.String(length=16), nullable=False),
|
||||
sa.Column("status", sa.String(length=16), nullable=False),
|
||||
sa.Column("contract_asset_id", sa.Integer(), nullable=True),
|
||||
sa.Column("contract_file_name", sa.String(length=255), nullable=False),
|
||||
sa.Column("template_id", sa.Integer(), nullable=True),
|
||||
sa.Column("template_source", sa.String(length=16), nullable=False),
|
||||
sa.Column("template_asset_id", sa.Integer(), nullable=True),
|
||||
sa.Column("template_name", sa.String(length=255), nullable=True),
|
||||
sa.Column("high_risk_count", sa.Integer(), nullable=False),
|
||||
sa.Column("medium_risk_count", sa.Integer(), nullable=False),
|
||||
sa.Column("low_risk_count", sa.Integer(), nullable=False),
|
||||
sa.Column("summary_json", sa.JSON(), nullable=True),
|
||||
sa.Column("clauses_json", sa.JSON(), nullable=True),
|
||||
sa.Column("report_text", sa.Text(), nullable=True),
|
||||
sa.Column("error_message", sa.Text(), nullable=True),
|
||||
sa.Column("started_at", sa.DateTime(), nullable=True),
|
||||
sa.Column("finished_at", sa.DateTime(), nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(), nullable=False),
|
||||
sa.ForeignKeyConstraint(["agent_id"], ["agents.id"]),
|
||||
sa.ForeignKeyConstraint(["chat_log_id"], ["chat_logs.id"]),
|
||||
sa.ForeignKeyConstraint(["contract_asset_id"], ["file_assets.id"]),
|
||||
sa.ForeignKeyConstraint(["template_asset_id"], ["file_assets.id"]),
|
||||
sa.ForeignKeyConstraint(["template_id"], ["contract_templates.id"]),
|
||||
sa.ForeignKeyConstraint(["user_id"], ["users.id"]),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
sa.UniqueConstraint("review_no"),
|
||||
)
|
||||
op.create_index("ix_contract_reviews_review_no", "contract_reviews", ["review_no"], unique=False)
|
||||
op.create_index("ix_contract_reviews_agent_id", "contract_reviews", ["agent_id"], unique=False)
|
||||
op.create_index("ix_contract_reviews_user_id", "contract_reviews", ["user_id"], unique=False)
|
||||
op.create_index("ix_contract_reviews_review_mode", "contract_reviews", ["review_mode"], unique=False)
|
||||
op.create_index("ix_contract_reviews_status", "contract_reviews", ["status"], unique=False)
|
||||
op.create_index("ix_contract_reviews_created_at", "contract_reviews", ["created_at"], unique=False)
|
||||
|
||||
|
||||
def downgrade():
|
||||
"""Drop contract review tables."""
|
||||
op.drop_index("ix_contract_reviews_created_at", table_name="contract_reviews")
|
||||
op.drop_index("ix_contract_reviews_status", table_name="contract_reviews")
|
||||
op.drop_index("ix_contract_reviews_review_mode", table_name="contract_reviews")
|
||||
op.drop_index("ix_contract_reviews_user_id", table_name="contract_reviews")
|
||||
op.drop_index("ix_contract_reviews_agent_id", table_name="contract_reviews")
|
||||
op.drop_index("ix_contract_reviews_review_no", table_name="contract_reviews")
|
||||
op.drop_table("contract_reviews")
|
||||
op.drop_index("ix_contract_templates_status", table_name="contract_templates")
|
||||
op.drop_table("contract_templates")
|
||||
@@ -3,7 +3,7 @@ from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
revision = 'b17e3d4c5a60'
|
||||
down_revision = 'a0b1c2d3e4f5'
|
||||
down_revision = 'a0b1c2d3e4f6'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
"""Extend procurement contract review rules and metadata.
|
||||
|
||||
Purpose:
|
||||
Add configurable risk rules, richer template metadata, and review search fields.
|
||||
Dependencies:
|
||||
Alembic revision a1c2d3e4f5b6 creates procurement contract base tables.
|
||||
Flow:
|
||||
Admin maintains risk rules; review service stores richer counts and metadata.
|
||||
|
||||
Revision ID: b2c4d6e8f0a1
|
||||
Revises: a1c2d3e4f5b6
|
||||
Create Date: 2026-07-15 11:20:00.000000
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision = "b2c4d6e8f0a1"
|
||||
down_revision = "a1c2d3e4f5b6"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
"""Add rule table and richer procurement contract metadata."""
|
||||
op.add_column(
|
||||
"contract_templates",
|
||||
sa.Column("contract_type", sa.String(length=64), nullable=False, server_default="general_procurement"),
|
||||
)
|
||||
op.add_column("contract_templates", sa.Column("applicable_scope", sa.Text(), nullable=True))
|
||||
op.add_column("contract_templates", sa.Column("change_note", sa.Text(), nullable=True))
|
||||
op.create_index("ix_contract_templates_contract_type", "contract_templates", ["contract_type"], unique=False)
|
||||
|
||||
op.add_column("contract_reviews", sa.Column("supplier_name", sa.String(length=128), nullable=True))
|
||||
op.add_column(
|
||||
"contract_reviews",
|
||||
sa.Column("contract_type", sa.String(length=64), nullable=False, server_default="general_procurement"),
|
||||
)
|
||||
op.add_column("contract_reviews", sa.Column("total_change_count", sa.Integer(), nullable=False, server_default="0"))
|
||||
op.create_index("ix_contract_reviews_supplier_name", "contract_reviews", ["supplier_name"], unique=False)
|
||||
op.create_index("ix_contract_reviews_contract_type", "contract_reviews", ["contract_type"], unique=False)
|
||||
|
||||
op.create_table(
|
||||
"contract_risk_rules",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("code", sa.String(length=64), nullable=False),
|
||||
sa.Column("contract_type", sa.String(length=64), nullable=False),
|
||||
sa.Column("clause_category", sa.String(length=64), nullable=False),
|
||||
sa.Column("title", sa.String(length=128), nullable=False),
|
||||
sa.Column("keywords", sa.JSON(), nullable=False),
|
||||
sa.Column("trigger_type", sa.String(length=32), nullable=False),
|
||||
sa.Column("risk_level", sa.String(length=16), nullable=False),
|
||||
sa.Column("risk_hint", sa.Text(), nullable=False),
|
||||
sa.Column("suggestion", sa.Text(), nullable=False),
|
||||
sa.Column("negotiation_text", sa.Text(), nullable=True),
|
||||
sa.Column("status", sa.String(length=16), nullable=False),
|
||||
sa.Column("sort_order", sa.Integer(), nullable=False),
|
||||
sa.Column("created_by", sa.Integer(), nullable=True),
|
||||
sa.Column("updated_by", sa.Integer(), nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(), nullable=False, server_default=sa.func.now()),
|
||||
sa.Column("updated_at", sa.DateTime(), nullable=False, server_default=sa.func.now()),
|
||||
sa.ForeignKeyConstraint(["created_by"], ["users.id"]),
|
||||
sa.ForeignKeyConstraint(["updated_by"], ["users.id"]),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
sa.UniqueConstraint("code", name="uq_contract_risk_rules_code"),
|
||||
)
|
||||
op.create_index("ix_contract_risk_rules_contract_type", "contract_risk_rules", ["contract_type"], unique=False)
|
||||
op.create_index("ix_contract_risk_rules_clause_category", "contract_risk_rules", ["clause_category"], unique=False)
|
||||
op.create_index("ix_contract_risk_rules_risk_level", "contract_risk_rules", ["risk_level"], unique=False)
|
||||
op.create_index("ix_contract_risk_rules_status", "contract_risk_rules", ["status"], unique=False)
|
||||
|
||||
rule_table = sa.table(
|
||||
"contract_risk_rules",
|
||||
sa.column("code", sa.String),
|
||||
sa.column("contract_type", sa.String),
|
||||
sa.column("clause_category", sa.String),
|
||||
sa.column("title", sa.String),
|
||||
sa.column("keywords", sa.JSON),
|
||||
sa.column("trigger_type", sa.String),
|
||||
sa.column("risk_level", sa.String),
|
||||
sa.column("risk_hint", sa.Text),
|
||||
sa.column("suggestion", sa.Text),
|
||||
sa.column("negotiation_text", sa.Text),
|
||||
sa.column("status", sa.String),
|
||||
sa.column("sort_order", sa.Integer),
|
||||
)
|
||||
op.bulk_insert(
|
||||
rule_table,
|
||||
[
|
||||
{
|
||||
"code": "payment_acceptance_required",
|
||||
"contract_type": "general_procurement",
|
||||
"clause_category": "payment",
|
||||
"title": "付款需绑定验收与发票",
|
||||
"keywords": ["付款", "支付", "结算", "账期", "验收", "发票"],
|
||||
"trigger_type": "keyword_missing",
|
||||
"risk_level": "high",
|
||||
"risk_hint": "付款条款缺少验收或发票前提,可能导致未验收即付款。",
|
||||
"suggestion": "建议恢复或补充“验收合格并收到合规发票后付款”。",
|
||||
"negotiation_text": "我方付款需以交付、验收合格和收到合规发票为前提,请恢复我司模板条款。",
|
||||
"status": "enabled",
|
||||
"sort_order": 10,
|
||||
},
|
||||
{
|
||||
"code": "acceptance_process_required",
|
||||
"contract_type": "general_procurement",
|
||||
"clause_category": "acceptance",
|
||||
"title": "验收标准与不合格处理",
|
||||
"keywords": ["验收", "合格", "不合格", "整改", "退货", "更换"],
|
||||
"trigger_type": "keyword_missing",
|
||||
"risk_level": "high",
|
||||
"risk_hint": "合同缺少验收标准或不合格处理,后续质量争议难以认定。",
|
||||
"suggestion": "建议补充验收流程、验收标准和不合格整改/退换货处理。",
|
||||
"negotiation_text": "验收条款是确认交付质量的基础,请补充明确验收标准和不合格处理方式。",
|
||||
"status": "enabled",
|
||||
"sort_order": 20,
|
||||
},
|
||||
{
|
||||
"code": "liability_required",
|
||||
"contract_type": "general_procurement",
|
||||
"clause_category": "liability",
|
||||
"title": "违约责任不可缺失",
|
||||
"keywords": ["违约", "赔偿", "违约金", "逾期", "延迟交付"],
|
||||
"trigger_type": "keyword_missing",
|
||||
"risk_level": "high",
|
||||
"risk_hint": "合同缺少违约责任,供应商逾期或质量问题的约束不足。",
|
||||
"suggestion": "建议补回逾期交付、质量不合格、保密违约等责任。",
|
||||
"negotiation_text": "违约责任属于基本履约保障,建议保留逾期交付和质量不合格赔偿条款。",
|
||||
"status": "enabled",
|
||||
"sort_order": 30,
|
||||
},
|
||||
{
|
||||
"code": "jurisdiction_required",
|
||||
"contract_type": "general_procurement",
|
||||
"clause_category": "jurisdiction",
|
||||
"title": "争议解决与管辖",
|
||||
"keywords": ["管辖", "仲裁", "人民法院", "争议解决"],
|
||||
"trigger_type": "keyword_missing",
|
||||
"risk_level": "medium",
|
||||
"risk_hint": "合同缺少争议解决约定,发生纠纷时维权成本和不确定性增加。",
|
||||
"suggestion": "建议明确采购方所在地法院或双方认可的仲裁机构。",
|
||||
"negotiation_text": "为便于双方处理争议,请保留我司模板中的争议解决条款。",
|
||||
"status": "enabled",
|
||||
"sort_order": 40,
|
||||
},
|
||||
{
|
||||
"code": "warranty_required",
|
||||
"contract_type": "general_procurement",
|
||||
"clause_category": "warranty",
|
||||
"title": "质保与售后期限",
|
||||
"keywords": ["质保", "保修", "售后", "维修", "更换"],
|
||||
"trigger_type": "keyword_missing",
|
||||
"risk_level": "medium",
|
||||
"risk_hint": "合同缺少质保或售后约定,后续维修更换缺少依据。",
|
||||
"suggestion": "建议明确质保期限、起算点、维修响应和更换责任。",
|
||||
"negotiation_text": "请补充质保期限及售后响应要求,确保交付后质量保障可执行。",
|
||||
"status": "enabled",
|
||||
"sort_order": 50,
|
||||
},
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
"""Remove rule table and added procurement contract metadata."""
|
||||
op.drop_index("ix_contract_risk_rules_status", table_name="contract_risk_rules")
|
||||
op.drop_index("ix_contract_risk_rules_risk_level", table_name="contract_risk_rules")
|
||||
op.drop_index("ix_contract_risk_rules_clause_category", table_name="contract_risk_rules")
|
||||
op.drop_index("ix_contract_risk_rules_contract_type", table_name="contract_risk_rules")
|
||||
op.drop_table("contract_risk_rules")
|
||||
|
||||
op.drop_index("ix_contract_reviews_contract_type", table_name="contract_reviews")
|
||||
op.drop_index("ix_contract_reviews_supplier_name", table_name="contract_reviews")
|
||||
op.drop_column("contract_reviews", "total_change_count")
|
||||
op.drop_column("contract_reviews", "contract_type")
|
||||
op.drop_column("contract_reviews", "supplier_name")
|
||||
|
||||
op.drop_index("ix_contract_templates_contract_type", table_name="contract_templates")
|
||||
op.drop_column("contract_templates", "change_note")
|
||||
op.drop_column("contract_templates", "applicable_scope")
|
||||
op.drop_column("contract_templates", "contract_type")
|
||||
@@ -0,0 +1,35 @@
|
||||
"""Add contract_no to contract_reviews for extracted business contract number.
|
||||
|
||||
Purpose:
|
||||
Persist the counterparty contract number extracted from uploaded contract text.
|
||||
Dependencies:
|
||||
Alembic revision b2c4d6e8f0a1 adds procurement contract review metadata.
|
||||
Flow:
|
||||
Review analysis fills contract_no; Admin history and report export display it.
|
||||
|
||||
Revision ID: c3d5e7f9a1b2
|
||||
Revises: b2c4d6e8f0a1
|
||||
Create Date: 2026-07-17 10:40:00.000000
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision = "c3d5e7f9a1b2"
|
||||
down_revision = "b2c4d6e8f0a1"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
"""Add contract_no column for extracted 合同编号."""
|
||||
op.add_column("contract_reviews", sa.Column("contract_no", sa.String(length=128), nullable=True))
|
||||
op.create_index("ix_contract_reviews_contract_no", "contract_reviews", ["contract_no"], unique=False)
|
||||
|
||||
|
||||
def downgrade():
|
||||
"""Remove contract_no column."""
|
||||
op.drop_index("ix_contract_reviews_contract_no", table_name="contract_reviews")
|
||||
op.drop_column("contract_reviews", "contract_no")
|
||||
@@ -0,0 +1,29 @@
|
||||
"""Add comparison-region config to procurement contract templates.
|
||||
|
||||
Revision ID: d4e6f8a0b2c3
|
||||
Revises: c3d5e7f9a1b2
|
||||
Create Date: 2026-07-24 10:00:00.000000
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision = "d4e6f8a0b2c3"
|
||||
down_revision = "c3d5e7f9a1b2"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
"""Add nullable JSON config so existing templates keep legacy comparison behavior."""
|
||||
op.add_column(
|
||||
"contract_templates",
|
||||
sa.Column("comparison_region_config", sa.JSON(), nullable=True),
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
"""Remove the comparison-region config column."""
|
||||
op.drop_column("contract_templates", "comparison_region_config")
|
||||
@@ -0,0 +1,40 @@
|
||||
"""Add linked_services table for admin-configured peer service entries.
|
||||
|
||||
Revision ID: e5f7a9b1c3d4
|
||||
Revises: d4e6f8a0b2c3
|
||||
Create Date: 2026-07-29 11:50:00.000000
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision = 'e5f7a9b1c3d4'
|
||||
down_revision = 'd4e6f8a0b2c3'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
"""创建关联服务表,供管理台配置名称与 URL。"""
|
||||
op.create_table(
|
||||
'linked_services',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('name', sa.String(length=100), nullable=False),
|
||||
sa.Column('url', sa.String(length=500), nullable=False),
|
||||
sa.Column('is_enabled', sa.Boolean(), nullable=False),
|
||||
sa.Column('sort_order', sa.Integer(), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=False),
|
||||
sa.Column('updated_at', sa.DateTime(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
)
|
||||
op.create_index('ix_linked_services_is_enabled', 'linked_services', ['is_enabled'])
|
||||
op.create_index('ix_linked_services_sort_order', 'linked_services', ['sort_order'])
|
||||
|
||||
|
||||
def downgrade():
|
||||
"""删除关联服务表。"""
|
||||
op.drop_index('ix_linked_services_sort_order', table_name='linked_services')
|
||||
op.drop_index('ix_linked_services_is_enabled', table_name='linked_services')
|
||||
op.drop_table('linked_services')
|
||||
@@ -0,0 +1,24 @@
|
||||
"""Merge voucher-check and shipping migration heads.
|
||||
|
||||
Revision ID: hb8i9j0k1l2m
|
||||
Revises: a0b1c2d3e4f5, ha7i8j9k0l1m
|
||||
Create Date: 2026-08-11
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
|
||||
|
||||
revision = 'hb8i9j0k1l2m'
|
||||
down_revision = ('a0b1c2d3e4f5', 'ha7i8j9k0l1m')
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
"""仅合并迁移图,不修改数据库结构。"""
|
||||
pass
|
||||
|
||||
|
||||
def downgrade():
|
||||
"""回退迁移图合并,不修改数据库结构。"""
|
||||
pass
|
||||
Reference in new issue
Block a user