46 lines
2.7 KiB
SQL
46 lines
2.7 KiB
SQL
-- 退货按 SKU 件数贴标增量(MySQL 8.0,可重复执行)。
|
|||
|
|
-- 生产及存量库只需执行本文件;新库字段同时维护在 lastleg.sql。
|
||
|
|
USE baiyue_lastleg;
|
||
|
|
|
||
|
|
SET @ddl = (
|
||
|
|
SELECT IF(
|
||
|
|
EXISTS (
|
||
|
|
SELECT 1
|
||
|
|
FROM information_schema.columns
|
||
|
|
WHERE table_schema = DATABASE()
|
||
|
|
AND table_name = 'll_relabel_pda_unit_fact'
|
||
|
|
AND column_name = 'quantity'
|
||
|
|
),
|
||
|
|
'SELECT 1',
|
||
|
|
'ALTER TABLE ll_relabel_pda_unit_fact ADD COLUMN quantity INT NOT NULL DEFAULT 1 COMMENT ''本次事实处理件数,箱级作业固定为1'' AFTER reason'
|
||
|
|
)
|
||
|
|
);
|
||
|
|
PREPARE ll_return_bulk_relabel_quantity_stmt FROM @ddl;
|
||
|
|
EXECUTE ll_return_bulk_relabel_quantity_stmt;
|
||
|
|
DEALLOCATE PREPARE ll_return_bulk_relabel_quantity_stmt;
|
||
|
|
|
||
|
|
SET @ddl = (SELECT IF(EXISTS (SELECT 1 FROM information_schema.table_constraints WHERE constraint_schema=DATABASE() AND table_name='ll_return_inventory_carton' AND constraint_name='chk_ll_return_inventory_carton_quantity'), 'ALTER TABLE ll_return_inventory_carton DROP CHECK chk_ll_return_inventory_carton_quantity', 'SELECT 1'));
|
||
|
|
PREPARE ll_return_relabel_quantity_check_drop_stmt FROM @ddl;
|
||
|
|
EXECUTE ll_return_relabel_quantity_check_drop_stmt;
|
||
|
|
DEALLOCATE PREPARE ll_return_relabel_quantity_check_drop_stmt;
|
||
|
|
ALTER TABLE ll_return_inventory_carton ADD CONSTRAINT chk_ll_return_inventory_carton_quantity CHECK((status IN('AVAILABLE','RELABEL_PENDING','OUTBOUNDED') AND sku_types>0 AND total_quantity>0) OR (status='MERGED' AND sku_types=0 AND total_quantity=0));
|
||
|
|
|
||
|
|
SET @ddl = (SELECT IF(EXISTS (SELECT 1 FROM information_schema.table_constraints WHERE constraint_schema=DATABASE() AND table_name='ll_return_inventory_carton' AND constraint_name='chk_ll_return_inventory_carton_status'), 'ALTER TABLE ll_return_inventory_carton DROP CHECK chk_ll_return_inventory_carton_status', 'SELECT 1'));
|
||
|
|
PREPARE ll_return_relabel_status_check_drop_stmt FROM @ddl;
|
||
|
|
EXECUTE ll_return_relabel_status_check_drop_stmt;
|
||
|
|
DEALLOCATE PREPARE ll_return_relabel_status_check_drop_stmt;
|
||
|
|
ALTER TABLE ll_return_inventory_carton ADD CONSTRAINT chk_ll_return_inventory_carton_status CHECK(status IN('AVAILABLE','RELABEL_PENDING','MERGED','OUTBOUNDED'));
|
||
|
|
|
||
|
|
SELECT COUNT(*) = 1 AS return_bulk_relabel_quantity_ready
|
||
|
|
FROM information_schema.columns
|
||
|
|
WHERE table_schema = DATABASE()
|
||
|
|
AND table_name = 'll_relabel_pda_unit_fact'
|
||
|
|
AND column_name = 'quantity'
|
||
|
|
AND column_comment = '本次事实处理件数,箱级作业固定为1';
|
||
|
|
|
||
|
|
SELECT COUNT(*) = 2 AS return_relabel_carton_checks_ready
|
||
|
|
FROM information_schema.check_constraints
|
||
|
|
WHERE constraint_schema = DATABASE()
|
||
|
|
AND constraint_name IN ('chk_ll_return_inventory_carton_quantity','chk_ll_return_inventory_carton_status')
|
||
|
|
AND check_clause LIKE '%RELABEL_PENDING%';
|