Files
BMS/bms-back/sql/price/product_status_alter.sql
T
2026-09-09 17:56:53 +08:00

40 lines
1.7 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.
-- ============================================================
-- bms_product / bms_product_country 自动状态回填
-- ============================================================
-- 背景:
-- bms_product.status char(1) DEFAULT '0' COMMENT '0待生效 1已生效 2已失效'
-- bms_product_country.status char(1) DEFAULT '0' COMMENT '0待生效 1已生效 2已失效'
-- 字典 bms_product_effect_status value=ACTIVE/PENDING/EXPIRED
-- 自动刷新:
-- BmsStatusRefreshTask 每天 02:00 调用两表 Mapper.refreshStatusByDates()
-- 即本文件末尾的回填 SQL(每日定时跑同样效果)
-- 现状验证:
-- bms_product.status 当前值仅 '0' / '1'('2' = EXPIRED 尚未触发,因今天 2026-09-09
-- 还没到任一 expire_date);bms_product_country.status 同上
-- ============================================================
SET NAMES utf8mb4;
-- ---------- 一次性回填(幂等:重跑结果一致) ----------
-- bms_product:
-- expire_date 非空且 <= 今天 → '2' 已失效
-- effective_date 为空 / 未来 → '0' 待生效
-- 其余(已生效且仍在有效期) → '1' 已生效
UPDATE bms_product p
SET p.status = (
CASE
WHEN p.expire_date IS NOT NULL AND p.expire_date <= CURDATE() THEN '2'
WHEN p.effective_date IS NULL OR p.effective_date > CURDATE() THEN '0'
ELSE '1'
END
);
-- bms_product_country:同上规则(多了 detail 级过期判断)
UPDATE bms_product_country c
SET c.status = (
CASE
WHEN c.expire_date IS NOT NULL AND c.expire_date <= CURDATE() THEN '2'
WHEN c.effective_date IS NULL OR c.effective_date > CURDATE() THEN '0'
ELSE '1'
END
);