feat(invoice-check): 立账凭证检核增加收件人配置并迁移到chat页面

This commit is contained in:
sophie committed 2026-09-17 13:17:37 +08:00
1 parent 18e957545c
commit 7b80b4c395
72 files changed
+2705 -263

No files matched your search

@@ -0,0 +1,97 @@
"""Seed voucher_check Chat Agent.
Revision ID: vc5f6a7b8c9d
Revises: cp9b0c1d2e3f
Create Date: 2026-09-16 13:30:00.000000
用途:为立账凭证检核注册 builtin Chat Agent。此前入口在工作台且仅 admin 可见,
没有独立功能权限键可迁移;普通用户需在用户管理授予该 Agent。
依赖:agents 表已存在。
逻辑:先按 agent_code 复用已有实例(含停用);没有则插入。插入前把 agents.id
序列对齐 MAX(id),避免本地库序列落后时撞主键。admin 仍按运行时角色看到
全部 Agent,不必写关联表。
"""
from __future__ import annotations
from alembic import op
from sqlalchemy import text
revision = "vc5f6a7b8c9d"
down_revision = "cp9b0c1d2e3f"
branch_labels = None
depends_on = None
AGENT_CODE = "voucher_check"
def _resync_agents_id_sequence() -> None:
"""把 agents 主键序列对齐现有最大 id,避免 nextval 撞上已占用主键。"""
bind = op.get_bind()
if bind.dialect.name != "postgresql":
return
op.execute(
"""
SELECT setval(
pg_get_serial_sequence('public.agents', 'id'),
COALESCE((SELECT MAX(id) FROM public.agents), 1),
true
)
"""
)
def upgrade() -> None:
"""插入或复用立账凭证检核 Agent。"""
conn = op.get_bind()
agent_id = conn.execute(
text(
"SELECT id FROM agents WHERE agent_code = :code "
"ORDER BY id ASC LIMIT 1"
),
{"code": AGENT_CODE},
).scalar()
if agent_id is not None:
conn.execute(
text(
"""
UPDATE agents
SET is_active = true,
runtime_provider = 'builtin',
conversation_mode = 'task_chat',
dify_app_type = 'chatflow',
updated_at = CURRENT_TIMESTAMP
WHERE id = :agent_id
"""
),
{"agent_id": agent_id},
)
return
_resync_agents_id_sequence()
conn.execute(
text(
"""
INSERT INTO agents (
name, description, type, is_active, is_aggregate,
agent_code, runtime_provider, conversation_mode, dify_app_type,
suggested_questions_style, sort_order, created_at, updated_at
) VALUES (
:name, :description, 'api', true, false,
:code, 'builtin', 'task_chat', 'chatflow',
'plain', 0, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP
)
"""
),
{
"name": "立账凭证",
"description": "查看立账凭证检核任务、最近一次检核进度和企业微信发送记录。",
"code": AGENT_CODE,
},
)
def downgrade() -> None:
"""不删除已创建的 Agent 实例,以免误伤运营配置。"""
return
@@ -0,0 +1,40 @@
"""Add voucher_check_notify_configs.
Revision ID: vc6a7b8c9d0e
Revises: vc5f6a7b8c9d
Create Date: 2026-09-16 15:55:00.000000
用途:按业务方保存立账凭证缺件通知的文件类型接收人。
依赖:voucher_check 引擎表、users 表。
逻辑:与 Profile 版本解耦,换人不需要发版 file_rules。
"""
from __future__ import annotations
from alembic import op
import sqlalchemy as sa
revision = "vc6a7b8c9d0e"
down_revision = "vc5f6a7b8c9d"
branch_labels = None
depends_on = None
def upgrade() -> None:
"""新增按文件类型配置企微接收人的表。"""
op.create_table(
"voucher_check_notify_configs",
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True),
sa.Column("profile_code", sa.String(length=32), nullable=False),
sa.Column("recipients_json", sa.JSON(), nullable=False),
sa.Column("updated_by", sa.Integer(), sa.ForeignKey("users.id", ondelete="SET NULL"), nullable=True),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.Column("updated_at", sa.DateTime(), nullable=False),
sa.UniqueConstraint("profile_code", name="uq_voucher_check_notify_configs_profile"),
)
def downgrade() -> None:
"""删除按文件类型接收人配置表。"""
op.drop_table("voucher_check_notify_configs")