feat(rpa): 收料配置与库存同构并统一站点启停
- 删除收料配置 enabled 与 warehouse_ids_json 列(迁移 rc1a2b3c4d5e、rc2b3c4d5e6f,含存量清单转 Warehouse 条件的数据保全) - Warehouse 改为查询条件(多值即逐仓拆分维度),排程/按需触发运行时派生仓库清单并在单元快照剥离该条件 - 站点开关即总开关:四处收料门禁只看站点 enabled;校验要求 DBS 恰一条非空 Warehouse 条件,日期禁填不变 - 站点抽屉改纵向折叠卡片与统一「保存更改」,就绪卡压缩为单行状态条并下移 - technical.md 同步设计边界与接口契约
This commit is contained in:
1 parent
eed1068ae3
commit
2199370065
18 files changed
+412
-223
No files matched your search
@@ -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']},
|
||||
)
|
||||
Reference in new issue
Block a user