-- ============================================
-- 将 wor_activity_definition 表中的一两条记录的 pricing_flag 改成 '1'
-- 注意：pricing_flag 是 char(1) 类型，所以要用字符串 '1'
-- ============================================

-- 方式1：更新前两条 pricing_flag = '0' 的记录（推荐）
UPDATE wor_activity_definition
SET pricing_flag = '1',
    update_time = CURRENT_TIMESTAMP
WHERE id IN (
    SELECT id
    FROM wor_activity_definition
    WHERE delete_flag = '0'
      AND pricing_flag = '0'
      AND status_enum = 1  -- 只更新激活状态的项目
    ORDER BY id
    LIMIT 2
);

-- 方式2：更新指定 ID 的记录（更精确，推荐使用）
-- 请将下面的 ID 替换为实际要更新的记录 ID
UPDATE wor_activity_definition
SET pricing_flag = '1',
    update_time = CURRENT_TIMESTAMP
WHERE id IN (1906532604116348929, 1906544768434053121)  -- 替换为实际的 ID
  AND delete_flag = '0';

-- 方式3：更新前两条记录（不管当前 pricing_flag 值是什么）
UPDATE wor_activity_definition
SET pricing_flag = '1',
    update_time = CURRENT_TIMESTAMP
WHERE id IN (
    SELECT id
    FROM wor_activity_definition
    WHERE delete_flag = '0'
      AND status_enum = 1
    ORDER BY id
    LIMIT 2
);

-- 方式4：更新有费用定价但 pricing_flag = '0' 的前两条记录（业务逻辑更合理）
UPDATE wor_activity_definition
SET pricing_flag = '1',
    update_time = CURRENT_TIMESTAMP
WHERE id IN (
    SELECT wad.id
    FROM wor_activity_definition wad
    INNER JOIN adm_charge_item_definition acid
        ON acid.instance_id = wad.id
        AND acid.delete_flag = '0'
        AND acid.status_enum = 1
        AND acid.instance_table = 'wor_activity_definition'
    WHERE wad.delete_flag = '0'
      AND wad.status_enum = 1
      AND wad.pricing_flag = '0'
    ORDER BY wad.id
    LIMIT 2
);

-- ============================================
-- 执行前可以先查询要更新的记录（验证用）
-- ============================================

-- 查询前两条 pricing_flag = '0' 的记录
SELECT 
    id,
    bus_no,
    name AS activity_name,
    pricing_flag,
    status_enum,
    create_time,
    update_time
FROM wor_activity_definition
WHERE delete_flag = '0'
  AND pricing_flag = '0'
  AND status_enum = 1
ORDER BY id
LIMIT 2;

-- 查询有费用定价但 pricing_flag = '0' 的记录
SELECT 
    wad.id,
    wad.bus_no,
    wad.name AS activity_name,
    wad.pricing_flag,
    acid.charge_name,
    acid.price
FROM wor_activity_definition wad
INNER JOIN adm_charge_item_definition acid
    ON acid.instance_id = wad.id
    AND acid.delete_flag = '0'
    AND acid.status_enum = 1
    AND acid.instance_table = 'wor_activity_definition'
WHERE wad.delete_flag = '0'
  AND wad.status_enum = 1
  AND wad.pricing_flag = '0'
ORDER BY wad.id
LIMIT 2;

-- ============================================
-- 执行后验证更新结果
-- ============================================

-- 验证更新是否成功
SELECT 
    id,
    bus_no,
    name AS activity_name,
    pricing_flag,
    update_time
FROM wor_activity_definition
WHERE id IN (
    -- 这里放刚才更新的 ID，或者用子查询
    SELECT id
    FROM wor_activity_definition
    WHERE delete_flag = '0'
      AND pricing_flag = '1'
      AND status_enum = 1
    ORDER BY update_time DESC
    LIMIT 2
);


