-- 添加日结医保结算菜单项到系统菜单表
-- 假设医保管理模块的父级菜单ID为某个值，这里我们先查询医保管理相关的菜单ID

-- 首先查找医保相关的父菜单ID（如果没有找到，需要手动指定一个合适的父菜单ID）
-- 偌设我们使用一个常见的父级ID，或者创建一个新的医保管理顶级菜单

-- 添加医保管理顶级菜单（如果不存在的话）
INSERT INTO sys_menu 
(menu_name, parent_id, order_num, path, component, query, route_name, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) 
SELECT '医保管理', 0, 7, 'ybmanagement', '', NULL, 'YbManagement', '1', '0', 'M', '0', '0', '', 'medication', 'admin', NOW(), 'admin', NOW(), '医保管理菜单'
WHERE NOT EXISTS (
    SELECT 1 FROM sys_menu WHERE menu_name = '医保管理' AND menu_type = 'M'
);

-- 获取医保管理菜单ID
DO $$
DECLARE
    yb_management_menu_id BIGINT;
BEGIN
    SELECT menu_id INTO yb_management_menu_id FROM sys_menu WHERE menu_name = '医保管理' LIMIT 1;

    -- 添加日结医保结算子菜单
    INSERT INTO sys_menu 
    (menu_name, parent_id, order_num, path, component, query, route_name, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) 
    VALUES 
    ('日结医保结算', yb_management_menu_id, 1, 'dayEndMedicalInsuranceSettlement', 'ybmanagement/dayEndMedicalInsuranceSettlement/index', NULL, 'DayEndMedicalInsuranceSettlement', '1', '0', 'C', '0', '0', 'ybmanage:dayEndMedicalInsuranceSettlement:view', 'document', 'admin', NOW(), 'admin', NOW(), '日结医保结算菜单');
END $$;