Merge branch 'dev' into order-delivery-reply
# Conflicts: # .env.shared # backend/app/api/chat.py # backend/app/core/config/settings.py # backend/app/models/user.py # backend/app/services/admin/permission_service.py # docs/demand.md # frontend/src/app/router/routes/workspace.routes.ts # frontend/src/features/admin/modules/users/components/UserFormModal.vue # frontend/src/features/admin/modules/users/composables/useUsersAdmin.ts # frontend/src/features/admin/types/user.types.ts # frontend/src/features/auth/stores/auth.store.ts # frontend/src/features/user/views/UserProfilePage.vue # frontend/src/locales/en/admin.json # frontend/src/locales/en/errors.json # frontend/src/locales/th/admin.json # frontend/src/locales/th/errors.json # frontend/src/locales/zh-CN/admin.json # frontend/src/locales/zh-CN/errors.json # frontend/src/locales/zh-TW/admin.json # frontend/src/locales/zh-TW/errors.json # frontend/src/shared/utils/auth.ts
This commit is contained in:
commit
616034a4cd
541 files changed
+43805
-14767
No files matched your search
@@ -0,0 +1,24 @@
|
||||
"""merge order-delivery-reply and dev heads
|
||||
|
||||
Revision ID: 959afe816337
|
||||
Revises: a7c1d2e3f4b9, rc2b3c4d5e6f
|
||||
Create Date: 2026-09-22 09:21:43.949845
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '959afe816337'
|
||||
down_revision = ('a7c1d2e3f4b9', 'rc2b3c4d5e6f')
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
pass
|
||||
|
||||
|
||||
def downgrade():
|
||||
pass
|
||||
@@ -0,0 +1,54 @@
|
||||
"""customer odm scope: add odm_ids to shipping_customers
|
||||
|
||||
Revision ID: aa11bb22cc33
|
||||
Revises: fb26bc033d27
|
||||
Create Date: 2026-09-16 00:00:00.000000
|
||||
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
revision = "aa11bb22cc33"
|
||||
down_revision = "fb26bc033d27"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def _add_column(insp, table: str, column: sa.Column) -> None:
|
||||
if table not in set(insp.get_table_names()):
|
||||
return
|
||||
columns = {col["name"] for col in insp.get_columns(table)}
|
||||
if column.name not in columns:
|
||||
with op.batch_alter_table(table, schema=None) as batch_op:
|
||||
batch_op.add_column(column)
|
||||
|
||||
|
||||
def _drop_column(insp, table: str, name: str) -> None:
|
||||
if table not in set(insp.get_table_names()):
|
||||
return
|
||||
columns = {col["name"] for col in insp.get_columns(table)}
|
||||
if name in columns:
|
||||
with op.batch_alter_table(table, schema=None) as batch_op:
|
||||
batch_op.drop_column(name)
|
||||
|
||||
|
||||
def upgrade():
|
||||
insp = sa.inspect(op.get_bind())
|
||||
_add_column(
|
||||
insp,
|
||||
"shipping_customers",
|
||||
sa.Column("odm_ids", sa.JSON(), nullable=True),
|
||||
)
|
||||
_add_column(
|
||||
insp,
|
||||
"shipping_notice_line_inventory_matches",
|
||||
sa.Column("chosen_odm_id", sa.String(length=64), nullable=True),
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
insp = sa.inspect(op.get_bind())
|
||||
_drop_column(insp, "shipping_notice_line_inventory_matches", "chosen_odm_id")
|
||||
_drop_column(insp, "shipping_customers", "odm_ids")
|
||||
@@ -0,0 +1,163 @@
|
||||
"""Seed contract_payment Chat Agent and migrate feature-permission grants.
|
||||
|
||||
Revision ID: cp8a9b0c1d2e
|
||||
Revises: fb26bc033d27
|
||||
Create Date: 2026-09-15 17:50:00.000000
|
||||
|
||||
用途:为合同付款预警注册 builtin Chat Agent,并把旧功能权限 `contract_payment.access`
|
||||
迁移为 user_agent_permissions;随后从 users.feature_permissions 去掉该键。
|
||||
依赖:agents、users、user_agent_permissions 表已存在。
|
||||
逻辑:先按 agent_code 复用已有实例(含停用);没有则插入。插入前把 agents.id
|
||||
序列对齐 MAX(id),避免本地库序列落后时撞主键。显式勾选过访问权的普通用户
|
||||
获得该 Agent;admin 仍按运行时角色看到全部 Agent,不必写关联表。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
from alembic import op
|
||||
from sqlalchemy import text
|
||||
|
||||
|
||||
revision = "cp8a9b0c1d2e"
|
||||
down_revision = "fb26bc033d27"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
AGENT_CODE = "contract_payment"
|
||||
|
||||
|
||||
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 _write_feature_permissions(conn, user_id: int, permissions: dict) -> None:
|
||||
"""把功能权限 JSON 写回 users;psycopg2 不能直接绑定 Python dict。"""
|
||||
conn.execute(
|
||||
text(
|
||||
"UPDATE users SET feature_permissions = CAST(:perms AS JSON) "
|
||||
"WHERE id = :user_id"
|
||||
),
|
||||
{"perms": json.dumps(permissions, ensure_ascii=False), "user_id": user_id},
|
||||
)
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""插入或复用合同付款预警 Agent,并把旧功能权限授予改写为 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},
|
||||
)
|
||||
else:
|
||||
_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,
|
||||
},
|
||||
)
|
||||
agent_id = conn.execute(
|
||||
text(
|
||||
"SELECT id FROM agents WHERE agent_code = :code AND is_active = true "
|
||||
"ORDER BY id ASC LIMIT 1"
|
||||
),
|
||||
{"code": AGENT_CODE},
|
||||
).scalar()
|
||||
|
||||
users = conn.execute(text("SELECT id, feature_permissions FROM users")).fetchall()
|
||||
for user_id, raw_permissions in users:
|
||||
permissions = raw_permissions if isinstance(raw_permissions, dict) else {}
|
||||
granted = bool(permissions.get("contract_payment.access"))
|
||||
if granted and agent_id is not None:
|
||||
conn.execute(
|
||||
text(
|
||||
"""
|
||||
INSERT INTO user_agent_permissions (user_id, agent_id)
|
||||
SELECT :user_id, :agent_id
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM user_agent_permissions
|
||||
WHERE user_id = :user_id AND agent_id = :agent_id
|
||||
)
|
||||
"""
|
||||
),
|
||||
{"user_id": user_id, "agent_id": agent_id},
|
||||
)
|
||||
if "contract_payment.access" in permissions:
|
||||
cleaned = {
|
||||
key: value
|
||||
for key, value in permissions.items()
|
||||
if key != "contract_payment.access"
|
||||
}
|
||||
_write_feature_permissions(conn, user_id, cleaned)
|
||||
|
||||
|
||||
def downgrade() -> 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 None:
|
||||
return
|
||||
granted_user_ids = conn.execute(
|
||||
text("SELECT user_id FROM user_agent_permissions WHERE agent_id = :agent_id"),
|
||||
{"agent_id": agent_id},
|
||||
).fetchall()
|
||||
for (user_id,) in granted_user_ids:
|
||||
row = conn.execute(
|
||||
text("SELECT feature_permissions FROM users WHERE id = :user_id"),
|
||||
{"user_id": user_id},
|
||||
).fetchone()
|
||||
permissions = dict(row[0] if row and isinstance(row[0], dict) else {})
|
||||
permissions["contract_payment.access"] = True
|
||||
_write_feature_permissions(conn, user_id, permissions)
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
"""合并合同付款 Chat Agent 与立账凭证 PO 打印两条 Alembic 头。
|
||||
|
||||
用途:invoice-check 合入 dev 后,``vc4e5f6a7b8c`` 与 ``cp8a9b0c1d2e`` 并列成双 head,
|
||||
导致 ``flask db upgrade`` 无法解析默认 ``head``。
|
||||
依赖:``cp8a9b0c1d2e``(合同付款预警 Chat Agent seed)、
|
||||
``vc4e5f6a7b8c``(立账凭证 PO 订单生成周批 seed)。
|
||||
逻辑:不修改业务表,只声明两条已完成迁移线在此收敛。
|
||||
"""
|
||||
|
||||
from alembic import op # noqa: F401 - Alembic migration module contract
|
||||
|
||||
|
||||
revision = "cp9b0c1d2e3f"
|
||||
down_revision = ("cp8a9b0c1d2e", "vc4e5f6a7b8c")
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""合并合同付款 Agent seed 与 PO 打印排程 seed,不执行数据库结构变更。"""
|
||||
pass
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""撤销合并节点;不会回滚两个父分支的业务变更。"""
|
||||
pass
|
||||
@@ -0,0 +1,25 @@
|
||||
"""merge migration heads
|
||||
|
||||
用途:合并平行迁移分支,恢复 Alembic 单 head 链。
|
||||
依赖:无表结构操作,仅声明多父级(aa11bb22cc33 客户 ODM 字段 × vc6a7b8c9d0e 凭证检核通知配置)。
|
||||
逻辑:hugo-shipping-notice 与 dev 两侧各自新增迁移产生分叉;本 Revision 只做图合并,
|
||||
upgrade/downgrade 均为空操作,实际 DDL 由两个父迁移各自负责。
|
||||
|
||||
Revision ID: dd22ee33ff44
|
||||
Revises: aa11bb22cc33, vc6a7b8c9d0e
|
||||
Create Date: 2026-09-17 00:00:00.000000
|
||||
|
||||
"""
|
||||
|
||||
revision = "dd22ee33ff44"
|
||||
down_revision = ("aa11bb22cc33", "vc6a7b8c9d0e")
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
pass
|
||||
|
||||
|
||||
def downgrade():
|
||||
pass
|
||||
@@ -0,0 +1,34 @@
|
||||
"""
|
||||
backend/migrations/versions/rc1a2b3c4d5e_drop_receipt_config_enabled.py
|
||||
|
||||
用途:删除收料报表配置的独立 enabled 列,站点启停即库存+收料统一开关。
|
||||
依赖:Alembic revision dd22ee33ff44;shipping_receipt_report_configs 已存在。
|
||||
逻辑:收料是否运行改为只看库存站点 enabled 与配置是否存在;四处后端门禁同步去掉该列过滤。
|
||||
|
||||
Revision ID: rc1a2b3c4d5e
|
||||
Revises: dd22ee33ff44
|
||||
Create Date: 2026-09-18 11:30:00.000000
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision = "rc1a2b3c4d5e"
|
||||
down_revision = "dd22ee33ff44"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""删除 shipping_receipt_report_configs.enabled;启用语义统一归属库存站点。"""
|
||||
op.drop_column("shipping_receipt_report_configs", "enabled")
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""恢复 enabled 列并统一置 true;历史双开关状态无法无损还原。"""
|
||||
op.add_column(
|
||||
"shipping_receipt_report_configs",
|
||||
sa.Column("enabled", sa.Boolean(), server_default=sa.text("true"), nullable=False),
|
||||
)
|
||||
@@ -0,0 +1,103 @@
|
||||
"""
|
||||
backend/migrations/versions/rc2b3c4d5e6f_drop_receipt_warehouse_list.py
|
||||
|
||||
用途:删除收料配置的 warehouse_ids_json 列,仓库清单改为查询条件中的 Warehouse 条件。
|
||||
依赖:Alembic revision rc1a2b3c4d5e;shipping_receipt_report_configs 与 shipping_inventory_sources 已存在。
|
||||
逻辑:升级时先把存量 DBS 配置的仓库清单注入为一条 Warehouse 查询条件(数据保全)再删列;
|
||||
降级时从 Warehouse 条件反提清单尽力恢复,条件本身保留。
|
||||
|
||||
Revision ID: rc2b3c4d5e6f
|
||||
Revises: rc1a2b3c4d5e
|
||||
Create Date: 2026-09-18 12:20:00.000000
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from typing import Any
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision = "rc2b3c4d5e6f"
|
||||
down_revision = "rc1a2b3c4d5e"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def _as_list(raw: Any) -> list:
|
||||
"""把 JSON 列读成 list;驱动可能返回 list 或字符串。"""
|
||||
if raw is None:
|
||||
return []
|
||||
if isinstance(raw, list):
|
||||
return list(raw)
|
||||
if isinstance(raw, str):
|
||||
text = raw.strip()
|
||||
if not text:
|
||||
return []
|
||||
loaded = json.loads(text)
|
||||
return list(loaded) if isinstance(loaded, list) else []
|
||||
return []
|
||||
|
||||
|
||||
def _warehouse_values(parameters: list) -> list[str]:
|
||||
"""提取查询条件里的 Warehouse 值(去空去重,保持顺序)。"""
|
||||
values: list[str] = []
|
||||
for item in parameters:
|
||||
if not isinstance(item, dict) or str(item.get('name') or '').strip().lower() != 'warehouse':
|
||||
continue
|
||||
for value in (item.get('values') or []):
|
||||
cleaned = str(value or '').strip()
|
||||
if cleaned and cleaned not in values:
|
||||
values.append(cleaned)
|
||||
return values
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""先把存量 DBS 仓库清单转为 Warehouse 查询条件,再删除 warehouse_ids_json 列。"""
|
||||
conn = op.get_bind()
|
||||
rows = conn.execute(sa.text(
|
||||
"SELECT c.id, c.query_parameters_json, c.warehouse_ids_json"
|
||||
" FROM shipping_receipt_report_configs c"
|
||||
" JOIN shipping_inventory_sources s ON s.id = c.inventory_source_id"
|
||||
" WHERE s.connector_type = 'dbs'"
|
||||
)).mappings().all()
|
||||
for row in rows:
|
||||
parameters = _as_list(row['query_parameters_json'])
|
||||
warehouses = [str(v or '').strip() for v in _as_list(row['warehouse_ids_json']) if str(v or '').strip()]
|
||||
has_warehouse_condition = any(
|
||||
isinstance(item, dict) and str(item.get('name') or '').strip().lower() == 'warehouse'
|
||||
for item in parameters
|
||||
)
|
||||
if warehouses and not has_warehouse_condition:
|
||||
parameters.append({
|
||||
'name': 'Warehouse', 'mode': 'single' if len(warehouses) == 1 else 'multi_text',
|
||||
'values': warehouses, 'required': False, 'select_all': False,
|
||||
})
|
||||
conn.execute(
|
||||
sa.text("UPDATE shipping_receipt_report_configs SET query_parameters_json = CAST(:params AS JSON) WHERE id = :id"),
|
||||
{'params': json.dumps(parameters), 'id': row['id']},
|
||||
)
|
||||
op.drop_column('shipping_receipt_report_configs', 'warehouse_ids_json')
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""恢复 warehouse_ids_json 列并从 Warehouse 条件尽力反提;条件本身保留。"""
|
||||
op.add_column(
|
||||
'shipping_receipt_report_configs',
|
||||
sa.Column('warehouse_ids_json', sa.JSON(), nullable=False, server_default=sa.text("'[]'")),
|
||||
)
|
||||
conn = op.get_bind()
|
||||
rows = conn.execute(sa.text(
|
||||
"SELECT c.id, c.query_parameters_json"
|
||||
" FROM shipping_receipt_report_configs c"
|
||||
" JOIN shipping_inventory_sources s ON s.id = c.inventory_source_id"
|
||||
" WHERE s.connector_type = 'dbs'"
|
||||
)).mappings().all()
|
||||
for row in rows:
|
||||
warehouses = _warehouse_values(_as_list(row['query_parameters_json']))
|
||||
if warehouses:
|
||||
conn.execute(
|
||||
sa.text("UPDATE shipping_receipt_report_configs SET warehouse_ids_json = CAST(:warehouses AS JSON) WHERE id = :id"),
|
||||
{'warehouses': json.dumps(warehouses), 'id': row['id']},
|
||||
)
|
||||
@@ -0,0 +1,136 @@
|
||||
"""
|
||||
backend/migrations/versions/vc4e5f6a7b8c_seed_voucher_po_print_schedule.py
|
||||
|
||||
用途:写入立账凭证 PO 订单生成周批(周二 05:00),早于检核周批(06:00)。
|
||||
依赖:Alembic revision vc3d4e5f6a7b;schedule_tasks / users 已存在。
|
||||
逻辑:有用户则插入 SCH-ACCOUNTING-VOUCHER-PO-PRINT;无用户时跳过,由应用钩子补建。
|
||||
企微接收人尽量从检核排程复制。downgrade 只删本 schedule_no。
|
||||
|
||||
Revision ID: vc4e5f6a7b8c
|
||||
Revises: vc3d4e5f6a7b
|
||||
Create Date: 2026-09-14 19:40:00.000000
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision = "vc4e5f6a7b8c"
|
||||
down_revision = "vc3d4e5f6a7b"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
_SCHEDULE_NO = "SCH-ACCOUNTING-VOUCHER-PO-PRINT"
|
||||
_CRON_EXPR = "0 5 * * 2"
|
||||
_TZ_NAME = "Asia/Shanghai"
|
||||
_JOB_PARAMS = {
|
||||
"profile_code": "sales",
|
||||
"scope_code": "HXJM",
|
||||
"notify_failure_enabled": True,
|
||||
}
|
||||
|
||||
|
||||
def _compute_next_run_at_utc_naive() -> datetime:
|
||||
"""按周二 05:00 Asia/Shanghai 计算下次执行,返回 UTC naive。"""
|
||||
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=5, minute=0, second=0, microsecond=0)
|
||||
while next_local <= now_local or next_local.weekday() != 1:
|
||||
next_local = next_local + timedelta(days=1)
|
||||
next_local = next_local.replace(hour=5, minute=0, second=0, microsecond=0)
|
||||
return next_local.astimezone(timezone.utc).replace(tzinfo=None)
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
conn = op.get_bind()
|
||||
exists = conn.execute(
|
||||
sa.text(
|
||||
"SELECT 1 FROM schedule_tasks "
|
||||
"WHERE schedule_no = :sno OR platform_api_path = 'accounting-voucher-po-print' "
|
||||
"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
|
||||
|
||||
notify_row = conn.execute(
|
||||
sa.text(
|
||||
"SELECT notify_user_ids_json FROM schedule_tasks "
|
||||
"WHERE schedule_no = 'SCH-ACCOUNTING-VOUCHER-CHECK' "
|
||||
" OR platform_api_path = 'accounting-voucher-check' "
|
||||
"LIMIT 1"
|
||||
)
|
||||
).first()
|
||||
notify_ids = notify_row[0] if notify_row and notify_row[0] is not None else []
|
||||
if not isinstance(notify_ids, list):
|
||||
notify_ids = []
|
||||
|
||||
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, notify_user_ids_json,
|
||||
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-po-print', CAST(:job_params AS JSONB), CAST(:notify_ids 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()),
|
||||
sa.bindparam("notify_ids", type_=sa.String()),
|
||||
),
|
||||
{
|
||||
"schedule_no": _SCHEDULE_NO,
|
||||
"name": "立账凭证 PO 订单生成(周批)",
|
||||
"owner_user_id": int(owner[0]),
|
||||
"cron_expr": _CRON_EXPR,
|
||||
"job_params": json.dumps(_JOB_PARAMS, ensure_ascii=False),
|
||||
"notify_ids": json.dumps(notify_ids, ensure_ascii=False),
|
||||
"next_run_at": next_run,
|
||||
"now": now,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""仅删除本迁移约定的 schedule_no,避免误删管理员手工创建的同路径排程。"""
|
||||
conn = op.get_bind()
|
||||
conn.execute(
|
||||
sa.text("DELETE FROM schedule_tasks WHERE schedule_no = :sno"),
|
||||
{"sno": _SCHEDULE_NO},
|
||||
)
|
||||
@@ -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")
|
||||
Reference in new issue
Block a user