AppKey-level scheme; scene matches one product and one country; stores assessment total hours (days×24) with migration SQL. Co-authored-by: Cursor <cursoragent@cursor.com>
32 lines
1.1 KiB
SQL
32 lines
1.1 KiB
SQL
-- 运输时效:一产品一国国家 + 考核总时效;规则主体按 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 '考核总时效(小时)' 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;
|