# 诊单待办事项：菜单按钮权限注册（T5 - 2026-05-05）
# 挂在「中医诊单」(perms=tcm.diagnosis/lists) 菜单下，按钮型权限节点：
#   tcm.diagnosisTodo/lists  待办列表
#   tcm.diagnosisTodo/add    新增待办
#   tcm.diagnosisTodo/cancel 取消待办
# detail 不单独注册（前端不主动调，由列表/详情接口已覆盖）

SET @diag_menu_id := (SELECT id FROM zyt_system_menu WHERE perms = 'tcm.diagnosis/lists' 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
    @diag_menu_id, 'A', '待办列表', '', 60,
    'tcm.diagnosisTodo/lists', '', '',
    '', '', 0, 1, 0, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()
FROM DUAL
WHERE @diag_menu_id IS NOT NULL
  AND NOT EXISTS (SELECT 1 FROM zyt_system_menu WHERE perms = 'tcm.diagnosisTodo/lists');

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
    @diag_menu_id, 'A', '新增待办', '', 61,
    'tcm.diagnosisTodo/add', '', '',
    '', '', 0, 1, 0, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()
FROM DUAL
WHERE @diag_menu_id IS NOT NULL
  AND NOT EXISTS (SELECT 1 FROM zyt_system_menu WHERE perms = 'tcm.diagnosisTodo/add');

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
    @diag_menu_id, 'A', '取消待办', '', 62,
    'tcm.diagnosisTodo/cancel', '', '',
    '', '', 0, 1, 0, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()
FROM DUAL
WHERE @diag_menu_id IS NOT NULL
  AND NOT EXISTS (SELECT 1 FROM zyt_system_menu WHERE perms = 'tcm.diagnosisTodo/cancel');
