|
|
|
@@ -0,0 +1,91 @@
|
|
|
|
|
-- 应收应付、预结算及正式结算明细补充收发货地址、联系人及联系方式。
|
|
|
|
|
-- MySQL 5.7+ 兼容,可重复执行。
|
|
|
|
|
|
|
|
|
|
DELIMITER $$
|
|
|
|
|
|
|
|
|
|
DROP PROCEDURE IF EXISTS `upgrade_settlement_detail_address_contact_20260909`$$
|
|
|
|
|
CREATE PROCEDURE `upgrade_settlement_detail_address_contact_20260909`()
|
|
|
|
|
BEGIN
|
|
|
|
|
DECLARE db_name varchar(128);
|
|
|
|
|
SET db_name = DATABASE();
|
|
|
|
|
|
|
|
|
|
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema = db_name AND table_name = 'blade_receivable_payable_detail' AND column_name = 'departure_address') THEN
|
|
|
|
|
ALTER TABLE `blade_receivable_payable_detail` ADD COLUMN `departure_address` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '发货地址' AFTER `vehicle_no`;
|
|
|
|
|
END IF;
|
|
|
|
|
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema = db_name AND table_name = 'blade_receivable_payable_detail' AND column_name = 'arrival_address') THEN
|
|
|
|
|
ALTER TABLE `blade_receivable_payable_detail` ADD COLUMN `arrival_address` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '收货地址' AFTER `departure_address`;
|
|
|
|
|
END IF;
|
|
|
|
|
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema = db_name AND table_name = 'blade_receivable_payable_detail' AND column_name = 'departure_contact') THEN
|
|
|
|
|
ALTER TABLE `blade_receivable_payable_detail` ADD COLUMN `departure_contact` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '发货联系人' AFTER `arrival_address`;
|
|
|
|
|
END IF;
|
|
|
|
|
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema = db_name AND table_name = 'blade_receivable_payable_detail' AND column_name = 'departure_phone') THEN
|
|
|
|
|
ALTER TABLE `blade_receivable_payable_detail` ADD COLUMN `departure_phone` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '发货联系方式' AFTER `departure_contact`;
|
|
|
|
|
END IF;
|
|
|
|
|
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema = db_name AND table_name = 'blade_receivable_payable_detail' AND column_name = 'arrival_contact') THEN
|
|
|
|
|
ALTER TABLE `blade_receivable_payable_detail` ADD COLUMN `arrival_contact` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '收货联系人' AFTER `departure_phone`;
|
|
|
|
|
END IF;
|
|
|
|
|
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema = db_name AND table_name = 'blade_receivable_payable_detail' AND column_name = 'arrival_phone') THEN
|
|
|
|
|
ALTER TABLE `blade_receivable_payable_detail` ADD COLUMN `arrival_phone` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '收货联系方式' AFTER `arrival_contact`;
|
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
|
|
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema = db_name AND table_name = 'blade_pre_settlement_detail' AND column_name = 'departure_contact') THEN
|
|
|
|
|
ALTER TABLE `blade_pre_settlement_detail` ADD COLUMN `departure_contact` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '发货联系人' AFTER `arrival_address`;
|
|
|
|
|
END IF;
|
|
|
|
|
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema = db_name AND table_name = 'blade_pre_settlement_detail' AND column_name = 'departure_phone') THEN
|
|
|
|
|
ALTER TABLE `blade_pre_settlement_detail` ADD COLUMN `departure_phone` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '发货联系方式' AFTER `departure_contact`;
|
|
|
|
|
END IF;
|
|
|
|
|
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema = db_name AND table_name = 'blade_pre_settlement_detail' AND column_name = 'arrival_contact') THEN
|
|
|
|
|
ALTER TABLE `blade_pre_settlement_detail` ADD COLUMN `arrival_contact` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '收货联系人' AFTER `departure_phone`;
|
|
|
|
|
END IF;
|
|
|
|
|
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema = db_name AND table_name = 'blade_pre_settlement_detail' AND column_name = 'arrival_phone') THEN
|
|
|
|
|
ALTER TABLE `blade_pre_settlement_detail` ADD COLUMN `arrival_phone` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '收货联系方式' AFTER `arrival_contact`;
|
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
|
|
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema = db_name AND table_name = 'blade_formal_settlement_detail' AND column_name = 'departure_contact') THEN
|
|
|
|
|
ALTER TABLE `blade_formal_settlement_detail` ADD COLUMN `departure_contact` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '发货联系人' AFTER `arrival_address`;
|
|
|
|
|
END IF;
|
|
|
|
|
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema = db_name AND table_name = 'blade_formal_settlement_detail' AND column_name = 'departure_phone') THEN
|
|
|
|
|
ALTER TABLE `blade_formal_settlement_detail` ADD COLUMN `departure_phone` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '发货联系方式' AFTER `departure_contact`;
|
|
|
|
|
END IF;
|
|
|
|
|
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema = db_name AND table_name = 'blade_formal_settlement_detail' AND column_name = 'arrival_contact') THEN
|
|
|
|
|
ALTER TABLE `blade_formal_settlement_detail` ADD COLUMN `arrival_contact` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '收货联系人' AFTER `departure_phone`;
|
|
|
|
|
END IF;
|
|
|
|
|
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema = db_name AND table_name = 'blade_formal_settlement_detail' AND column_name = 'arrival_phone') THEN
|
|
|
|
|
ALTER TABLE `blade_formal_settlement_detail` ADD COLUMN `arrival_phone` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '收货联系方式' AFTER `arrival_contact`;
|
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
|
|
UPDATE `blade_receivable_payable_detail` source_detail
|
|
|
|
|
INNER JOIN `blade_waybill` waybill ON waybill.`id` = source_detail.`waybill_id` AND waybill.`is_deleted` = 0
|
|
|
|
|
SET source_detail.`departure_address` = COALESCE(NULLIF(source_detail.`departure_address`, ''), NULLIF(waybill.`departure_address`, ''), waybill.`departure_name`),
|
|
|
|
|
source_detail.`arrival_address` = COALESCE(NULLIF(source_detail.`arrival_address`, ''), NULLIF(waybill.`arrival_address`, ''), waybill.`arrival_name`),
|
|
|
|
|
source_detail.`departure_contact` = COALESCE(NULLIF(source_detail.`departure_contact`, ''), waybill.`departure_contact`),
|
|
|
|
|
source_detail.`departure_phone` = COALESCE(NULLIF(source_detail.`departure_phone`, ''), waybill.`departure_phone`),
|
|
|
|
|
source_detail.`arrival_contact` = COALESCE(NULLIF(source_detail.`arrival_contact`, ''), waybill.`arrival_contact`),
|
|
|
|
|
source_detail.`arrival_phone` = COALESCE(NULLIF(source_detail.`arrival_phone`, ''), waybill.`arrival_phone`)
|
|
|
|
|
WHERE source_detail.`is_deleted` = 0;
|
|
|
|
|
|
|
|
|
|
UPDATE `blade_pre_settlement_detail` target_detail
|
|
|
|
|
INNER JOIN `blade_receivable_payable_detail` source_detail ON source_detail.`id` = target_detail.`source_detail_id`
|
|
|
|
|
SET target_detail.`departure_address` = COALESCE(NULLIF(target_detail.`departure_address`, ''), source_detail.`departure_address`),
|
|
|
|
|
target_detail.`arrival_address` = COALESCE(NULLIF(target_detail.`arrival_address`, ''), source_detail.`arrival_address`),
|
|
|
|
|
target_detail.`departure_contact` = COALESCE(NULLIF(target_detail.`departure_contact`, ''), source_detail.`departure_contact`),
|
|
|
|
|
target_detail.`departure_phone` = COALESCE(NULLIF(target_detail.`departure_phone`, ''), source_detail.`departure_phone`),
|
|
|
|
|
target_detail.`arrival_contact` = COALESCE(NULLIF(target_detail.`arrival_contact`, ''), source_detail.`arrival_contact`),
|
|
|
|
|
target_detail.`arrival_phone` = COALESCE(NULLIF(target_detail.`arrival_phone`, ''), source_detail.`arrival_phone`)
|
|
|
|
|
WHERE target_detail.`is_deleted` = 0 AND source_detail.`is_deleted` = 0;
|
|
|
|
|
|
|
|
|
|
UPDATE `blade_formal_settlement_detail` target_detail
|
|
|
|
|
INNER JOIN `blade_receivable_payable_detail` source_detail ON source_detail.`id` = target_detail.`source_detail_id`
|
|
|
|
|
SET target_detail.`departure_address` = COALESCE(NULLIF(target_detail.`departure_address`, ''), source_detail.`departure_address`),
|
|
|
|
|
target_detail.`arrival_address` = COALESCE(NULLIF(target_detail.`arrival_address`, ''), source_detail.`arrival_address`),
|
|
|
|
|
target_detail.`departure_contact` = COALESCE(NULLIF(target_detail.`departure_contact`, ''), source_detail.`departure_contact`),
|
|
|
|
|
target_detail.`departure_phone` = COALESCE(NULLIF(target_detail.`departure_phone`, ''), source_detail.`departure_phone`),
|
|
|
|
|
target_detail.`arrival_contact` = COALESCE(NULLIF(target_detail.`arrival_contact`, ''), source_detail.`arrival_contact`),
|
|
|
|
|
target_detail.`arrival_phone` = COALESCE(NULLIF(target_detail.`arrival_phone`, ''), source_detail.`arrival_phone`)
|
|
|
|
|
WHERE target_detail.`is_deleted` = 0 AND source_detail.`is_deleted` = 0;
|
|
|
|
|
END$$
|
|
|
|
|
|
|
|
|
|
CALL `upgrade_settlement_detail_address_contact_20260909`()$$
|
|
|
|
|
DROP PROCEDURE `upgrade_settlement_detail_address_contact_20260909`$$
|
|
|
|
|
|
|
|
|
|
DELIMITER ;
|