Files
SupplierSystem/migrations/20261084_delivery_loading_backfill_logs.sql
Ubuntu 05b81348c4
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
feat(配送/分拣): 早期任务、全状态发车与库存抵扣闭环
- 下单即建分拣/配送,待取货/散客/独立进货守卫
- 30/40/45 直接发车/分拣,入库与分拣二选一
- 分拣完成补上游、清理 pending 验收,直接配送补分拣
- 库存抵扣/计划/实收 FIFO,软扣部分扣减,并发出库串行
- 结束配送不被库存不足/待入库残留阻断
- 待验收并发唯一索引(含 name-only),finalize 共享连接修复
- 售后自动绑定订单明细、客户取货/采购并发修复
- 仓库表格自适应、弹窗滚动锁闪烁修复
2026-10-26 16:42:53 +08:00

199 lines
5.9 KiB
PL/PgSQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- T3 配送核货补录审计:delivery_loading_backfill_logs
-- 2026-10-26:补入库/补分拣可追溯;只新增表 + 租户登记,不改财务/状态链。
-- 表在 tenant_template 建立后克隆到所有租户 schema;RLS 由 apply_tenant_core_rls 统一应用。
DO $$
DECLARE
sch text;
BEGIN
FOR sch IN
SELECT nspname FROM pg_namespace
WHERE nspname = 'tenant_template' OR nspname LIKE 'tenant\_%'
LOOP
EXECUTE format(
'CREATE TABLE IF NOT EXISTS %I.delivery_loading_backfill_logs (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
branch_code VARCHAR(50),
order_code VARCHAR(100) NOT NULL,
order_item_id UUID,
task_code VARCHAR(100),
sku_code VARCHAR(100),
item_name VARCHAR(255),
supplier_code VARCHAR(100),
purchaser_code VARCHAR(100),
-- 允许值:inbound | picking | inbound_picking | prep(30 直发只完成备货)
missing_stage VARCHAR(32) NOT NULL,
responsible_code VARCHAR(100),
operator_id UUID,
confirmed_qty NUMERIC(14,4) NOT NULL DEFAULT 0,
inbound_qty NUMERIC(14,4) NOT NULL DEFAULT 0,
picking_qty NUMERIC(14,4) NOT NULL DEFAULT 0,
inventory_action VARCHAR(32) NOT NULL DEFAULT ''none'',
inbound_batch_no VARCHAR(100),
pick_code VARCHAR(100),
remark TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
)',
sch
);
EXECUTE format(
'CREATE INDEX IF NOT EXISTS idx_delivery_backfill_order
ON %I.delivery_loading_backfill_logs (order_code, created_at DESC)',
sch
);
EXECUTE format('ALTER TABLE %I.delivery_loading_backfill_logs ENABLE ROW LEVEL SECURITY', sch);
EXECUTE format('ALTER TABLE %I.delivery_loading_backfill_logs FORCE ROW LEVEL SECURITY', sch);
EXECUTE format('DROP POLICY IF EXISTS tenant_isolation_delivery_loading_backfill_logs ON %I.delivery_loading_backfill_logs', sch);
EXECUTE format(
'CREATE POLICY tenant_isolation_delivery_loading_backfill_logs ON %I.delivery_loading_backfill_logs
FOR ALL USING (branch_code::text = current_setting(''app.branch_code'', true))
WITH CHECK (branch_code::text = current_setting(''app.branch_code'', true))',
sch
);
END LOOP;
END $$;
-- 租户业务表登记(新租户/克隆必须包含)
CREATE OR REPLACE FUNCTION public.tenant_business_tables()
RETURNS TEXT[]
LANGUAGE sql
IMMUTABLE
AS $$
SELECT ARRAY[
'main_system_sku_mappings',
'after_sale_returns',
'after_sales',
'ai_prompt_overrides',
'ai_prompt_revisions',
'ai_prompt_templates',
'alias_recognition_logs',
'allocation_tasks',
'assistant_conversations',
'assistant_messages',
'assistant_turns',
'bid_awards',
'bid_invitations',
'bid_prices',
'bid_quotes',
'bid_round_items',
'bid_rounds',
'categories',
'cost_adjustments',
'cost_details',
'customer_alias_stats',
'customer_delivery_assignments',
'customer_portal_users',
'customer_processing_aliases',
'customer_quote_sheet_customers',
'customer_quote_sheet_items',
'customer_quote_sheets',
'customer_quote_versions',
'customer_recipients',
'customer_sku_aliases',
'customer_sku_remarks',
'customer_skus',
'customer_statements',
'customers',
'delivery_location_history',
'delivery_person_locations',
'delivery_person_users',
'delivery_persons',
'delivery_schedules',
'delivery_signatures',
'delivery_tasks',
'delivery_loading_backfill_logs',
'exception_tickets',
'fixed_costs',
'free_cost_invoice_links',
'free_cost_invoices',
'free_cost_payment_vouchers',
'import_mapping_memories',
'inspection_loss_confirmations',
'inspection_photo_archive_entries',
'inspection_photo_archives',
'inspection_returns',
'inspection_review_logs',
'inspections',
'inventory',
'inventory_batch_report_matches',
'inventory_batch_reports',
'inventory_logs',
'inventory_reservations',
'invoice_statement_links',
'invoices',
'market_compare_exclusions',
'market_external_catalog',
'market_price_history',
'market_price_indices',
'market_prices',
'market_sku_external_bindings',
'notifications',
'operation_logs',
'order_allocation_batches',
'order_item_fulfillments',
'order_item_returns',
'order_items',
'orders',
'parse_session_items',
'parse_sessions',
'picking_assign_rules',
'picking_containers',
'picking_items',
'picking_scan_logs',
'picking_tasks',
'price_invert_events',
'print_jobs',
'processing_demand_items',
'processing_demand_picks',
'processing_logs',
'processing_tasks',
'product_catalog',
'product_substitutions',
'purchase_orders',
'purchaser_users',
'quality_report_prep_links',
'quality_reports',
'quote_price_proposals',
'seasonal_recommendations',
'self_purchase_stock_inbounds',
'sign_records',
'sku_direct_delivery_customers',
'sku_suppliers',
'skus',
'smart_classification_rules',
'statement_disputes',
'statement_lines',
'statement_payments',
'supplier_categories',
'supplier_prep_amend_requests',
'supplier_preparations',
'supplier_rating_snapshots',
'supplier_statements',
'supplier_users',
'suppliers',
'system_configs',
'unit_conversions',
'user_preferences',
'voice_recognition_logs',
'warehouse_locations',
'warehouses',
'weigh_devices',
'processing_task_materials',
'processing_task_outputs'
];
$$;
DO $$
BEGIN
PERFORM public.ensure_tenant_schemas_match_template();
EXCEPTION WHEN undefined_function THEN
RAISE NOTICE 'ensure_tenant_schemas_match_template 不存在,跳过';
END $$;
DO $$
BEGIN
PERFORM public.ensure_all_tenant_core_rls();
EXCEPTION WHEN undefined_function THEN
RAISE NOTICE 'ensure_all_tenant_core_rls 不存在,跳过';
END $$;