-- 用途：脚本执行后，人工核查访客最终楼层权限
-- 说明：
--   * 「已授权楼层」＝ image_rule_ref 中 person_delete = 0 的行（与 passRule/image 可查到的楼层一致）
--   * person_delete = 1 为撤销/作废，不参与当前授权
--   将 IN (...) 中的访客 person_id 替换为本次执行的访客集合

-- 主查：仅已授权楼层（推荐与接口 / JSON derived.floors 对拍）
SELECT
  irr.person_id,
  irr.business_id,
  irr.zone_id,
  irr.zone_name,
  irr.last_update_time
FROM `cw-elevator-application`.`image_rule_ref` irr
WHERE irr.person_id IN (
  '1102270499947507712'
  -- ,'替换为其他访客personId'
)
  AND irr.person_delete = 0
ORDER BY irr.person_id, irr.zone_id;

-- 明细（含已撤销历史行，核对 person_delete / 时间线时用）
SELECT
  irr.person_id,
  irr.business_id,
  irr.zone_id,
  irr.zone_name,
  irr.person_delete,
  irr.create_time,
  irr.last_update_time
FROM `cw-elevator-application`.`image_rule_ref` irr
WHERE irr.person_id IN (
  '1102270499947507712'
  -- ,'替换为其他访客personId'
)
ORDER BY irr.person_id, irr.last_update_time DESC, irr.zone_id;

-- 可选：统计每个访客当前「已授权」楼层数量（person_delete = 0）
SELECT
  irr.person_id,
  COUNT(1) AS floor_count
FROM `cw-elevator-application`.`image_rule_ref` irr
WHERE irr.person_id IN (
  '1102270499947507712'
  -- ,'替换为其他访客personId'
)
  AND irr.person_delete = 0
GROUP BY irr.person_id
ORDER BY irr.person_id;
