track/scripts/sql/20260801_transport_warning_simplify.sql
zzh af86a1fdff Remove KPI warning areas and slim transport warning scene schema.
Drop legacy scene match columns from code/SQL and delete unused area tables guidance for pre-prod cleanup.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-01 11:56:15 +08:00

32 lines
1.1 KiB
SQL
Raw 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.

-- 运输时效:一产品一国国家 + 考核总时效;规则主体按 AppKey 方案级
-- 执行前请备份 t_warning / t_warning_transport_scene
-- 1) 国家列(若已存在可跳过)
ALTER TABLE t_warning_transport_scene
ADD COLUMN CountryCode VARCHAR(16) NULL COMMENT '到达国家二字码(单一,命中订单到达国家)' AFTER ProductCode;
-- 2) 考核总时效(小时)
ALTER TABLE t_warning_transport_scene
ADD COLUMN AssessmentTotalTimeSpan FLOAT NULL COMMENT '考核总时效(小时;前端按天录入后×24入库)' AFTER CountryCode;
-- 3) 运输时效规则主体改为方案级:客户清空
UPDATE t_warning
SET Customer = ''
WHERE WarningType = 1
AND (Customer IS NULL OR Customer <> '');
-- 4) 同一 AppKey 下多个已启用运输时效方案,仅保留 Id 最小的一条
UPDATE t_warning w
INNER JOIN (
SELECT AppKey, MIN(Id) AS KeepId
FROM t_warning
WHERE WarningType = 1
AND IsEnabled = 1
GROUP BY AppKey
HAVING COUNT(1) > 1
) d ON w.AppKey = d.AppKey
SET w.IsEnabled = 0
WHERE w.WarningType = 1
AND w.IsEnabled = 1
AND w.Id <> d.KeepId;