优化
This commit is contained in:
@@ -56,61 +56,6 @@ SET @sql = IF(@resource_tenant_needs_modify > 0,
|
||||
'SELECT 1');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- 船司 FBA 价格是平台公共主数据;迁移前检查版本和有效期冲突,避免静默覆盖客户价格。
|
||||
DROP PROCEDURE IF EXISTS phase2_fba_migrate_carrier_rate_scope;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE phase2_fba_migrate_carrier_rate_scope()
|
||||
BEGIN
|
||||
DECLARE v_conflicts INT DEFAULT 0;
|
||||
|
||||
SELECT COUNT(*) INTO v_conflicts
|
||||
FROM (
|
||||
SELECT rate_code, rate_version
|
||||
FROM fl_carrier_fba_rate
|
||||
GROUP BY rate_code, rate_version
|
||||
HAVING COUNT(*) > 1
|
||||
) AS duplicate_versions;
|
||||
IF v_conflicts > 0 THEN
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MESSAGE_TEXT = 'FBA价格迁移失败:不同客户存在重复价格编码版本,请先合并';
|
||||
END IF;
|
||||
|
||||
SELECT COUNT(*) INTO v_conflicts
|
||||
FROM (
|
||||
SELECT first_rate.id
|
||||
FROM fl_carrier_fba_rate first_rate
|
||||
JOIN fl_carrier_fba_rate second_rate
|
||||
ON first_rate.id < second_rate.id
|
||||
AND first_rate.status = 'ACTIVE'
|
||||
AND second_rate.status = 'ACTIVE'
|
||||
AND first_rate.origin_warehouse_id <=> second_rate.origin_warehouse_id
|
||||
AND first_rate.business_type <=> second_rate.business_type
|
||||
AND first_rate.channel_code <=> second_rate.channel_code
|
||||
AND first_rate.carrier_id <=> second_rate.carrier_id
|
||||
AND first_rate.destination_code <=> second_rate.destination_code
|
||||
AND first_rate.charge_unit <=> second_rate.charge_unit
|
||||
AND first_rate.effective_from < COALESCE(second_rate.effective_to, '9999-12-31 23:59:59.999')
|
||||
AND second_rate.effective_from < COALESCE(first_rate.effective_to, '9999-12-31 23:59:59.999')
|
||||
LIMIT 1
|
||||
) AS overlapping_rates;
|
||||
IF v_conflicts > 0 THEN
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MESSAGE_TEXT = 'FBA价格迁移失败:公共匹配维度存在有效期重叠,请先合并';
|
||||
END IF;
|
||||
|
||||
UPDATE fl_carrier_fba_rate
|
||||
SET tenant_id = 0
|
||||
WHERE tenant_id <> 0;
|
||||
|
||||
IF EXISTS (SELECT 1 FROM fl_carrier_fba_rate WHERE tenant_id <> 0) THEN
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MESSAGE_TEXT = 'FBA价格迁移失败:仍存在非平台价格作用域';
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
CALL phase2_fba_migrate_carrier_rate_scope();
|
||||
DROP PROCEDURE IF EXISTS phase2_fba_migrate_carrier_rate_scope;
|
||||
|
||||
DROP PROCEDURE IF EXISTS phase2_fba_add_column;
|
||||
|
||||
-- 旧索引可能缺少业务类型、船司和结束时间;用新索引名并存,避免破坏线上依赖。
|
||||
|
||||
-14
@@ -38,18 +38,4 @@ class InboundWorkflowSqlContractTest {
|
||||
.contains("SET warehouse_resource_tenant_id = 0")
|
||||
.contains("MODIFY COLUMN warehouse_resource_tenant_id BIGINT UNSIGNED NOT NULL");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("船司价格存量迁移固定到平台作用域并拒绝冲突")
|
||||
void shouldMigrateCarrierRatesToPublicScopeWithoutOverwritingConflicts() throws Exception {
|
||||
String migration = new ClassPathResource("db/phase2-fba-pricing-migration.sql")
|
||||
.getContentAsString(StandardCharsets.UTF_8);
|
||||
|
||||
assertThat(migration)
|
||||
.contains("phase2_fba_migrate_carrier_rate_scope")
|
||||
.contains("GROUP BY rate_code, rate_version")
|
||||
.contains("公共匹配维度存在有效期重叠")
|
||||
.contains("SET tenant_id = 0")
|
||||
.contains("WHERE tenant_id <> 0");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user