-- 消费者处方：挂号列表页 consumer/prescription/guahao
-- 列表接口复用 doctor.appointment/lists；编辑接口 doctor.appointment/edit（需在角色中单独勾选）
-- 执行前确认表前缀为 zyt_

SET @rx_pid := (
    SELECT pid FROM zyt_system_menu
    WHERE type = 'C'
      AND (
          component = 'consumer/prescription/index'
          OR component LIKE '%consumer/prescription/index%'
      )
    LIMIT 1
);
SET @rx_pid := IFNULL(@rx_pid, 0);

INSERT INTO zyt_system_menu (
    pid, type, name, icon, sort, perms, paths, component,
    selected, params, is_cache, is_show, is_disable, create_time, update_time
)
SELECT
    @rx_pid, 'C', '挂号列表', '', 47,
    'doctor.appointment/lists', 'consumer/prescription_guahao', 'consumer/prescription/guahao',
    '', '', 0, 1, 0, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()
FROM DUAL
WHERE @rx_pid > 0
  AND NOT EXISTS (SELECT 1 FROM zyt_system_menu WHERE paths = 'consumer/prescription_guahao');

SET @guahao_menu_id := (SELECT id FROM zyt_system_menu WHERE paths = 'consumer/prescription_guahao' LIMIT 1);

INSERT INTO zyt_system_menu (
    pid, type, name, icon, sort, perms, paths, component,
    selected, params, is_cache, is_show, is_disable, create_time, update_time
)
SELECT
    @guahao_menu_id, 'A', '编辑挂号', '', 1,
    'doctor.appointment/edit', '', '',
    '', '', 0, 1, 0, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()
FROM DUAL
WHERE @guahao_menu_id IS NOT NULL
  AND NOT EXISTS (SELECT 1 FROM zyt_system_menu WHERE perms = 'doctor.appointment/edit');
