This commit is contained in:
2026-08-06 18:01:59 +08:00
parent 584f1519d1
commit 6e9739826c
24 changed files with 549 additions and 62 deletions
@@ -56,6 +56,61 @@ 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;
-- 旧索引可能缺少业务类型、船司和结束时间;用新索引名并存,避免破坏线上依赖。
@@ -309,8 +309,8 @@ CREATE TABLE IF NOT EXISTS fl_customer_charge_rule (
CREATE TABLE IF NOT EXISTS fl_carrier_fba_rate (
id BIGINT UNSIGNED NOT NULL COMMENT '船司FBA价格ID',
tenant_id BIGINT UNSIGNED NOT NULL COMMENT '数据所属租户ID',
rate_code VARCHAR(50) NOT NULL COMMENT '租户内价格编码',
tenant_id BIGINT UNSIGNED NOT NULL COMMENT '平台价格作用域ID,船司价格固定为0',
rate_code VARCHAR(50) NOT NULL COMMENT '平台公共价格编码',
rate_version INT UNSIGNED NOT NULL COMMENT '价格版本号',
origin_warehouse_id BIGINT UNSIGNED NOT NULL COMMENT '起运仓逻辑ID',
origin_warehouse_name VARCHAR(128) NOT NULL COMMENT '起运仓名称快照',
@@ -32,26 +32,24 @@ paths:
responses: {'200': {description: 成功或业务失败}, '403': {description: 无权限}}
/api/platform/v1/fba-pricing/carrier-rates:
get:
summary: 查询船司 FBA 价格版本
summary: 查询平台公共船司 FBA 价格版本
description: 需要 firstleg:fba-pricing:rate:view 权限
parameters:
- {$ref: '#/components/parameters/OptionalTenantId'}
- {name: rateCode, in: query, schema: {type: string, maxLength: 50}}
responses: {'200': {description: 成功或业务失败}, '403': {description: 无权限}}
/api/platform/v1/fba-pricing/carrier-rates/versions:
post:
summary: 新建船司 FBA 价格版本
parameters: [{$ref: '#/components/parameters/TenantId'}]
summary: 新建平台公共船司 FBA 价格版本
requestBody: {required: true, content: {application/json: {schema: {$ref: '#/components/schemas/CarrierRateVersionRequest'}}}}
responses: {'200': {description: 成功或业务失败}, '403': {description: 无权限}}
/api/platform/v1/fba-pricing/carrier-rates/{id}:
get:
summary: 查询船司 FBA 价格版本详情
parameters: [{$ref: '#/components/parameters/TenantId'}, {$ref: '#/components/parameters/Id'}]
parameters: [{$ref: '#/components/parameters/Id'}]
responses: {'200': {description: 成功或业务失败}, '403': {description: 无权限}}
delete:
summary: 停用船司 FBA 价格版本
parameters: [{$ref: '#/components/parameters/TenantId'}, {$ref: '#/components/parameters/Id'}]
parameters: [{$ref: '#/components/parameters/Id'}]
responses: {'200': {description: 成功或业务失败}, '403': {description: 无权限}}
/api/platform/v1/inbounds/{inboundId}/fees/calculate:
post: