-- 检查权限分配情况
-- 1. 检查超级管理员用户信息
SELECT 
    u.id,
    u.mobile,
    u.name,
    u.role_id,
    r.name as role_name
FROM sys_user u
LEFT JOIN sys_role r ON u.role_id = r.id
WHERE u.mobile = '15900000000';

-- 2. 检查 delivery:edit 权限是否存在
SELECT 
    id,
    name,
    authority,
    parent_id,
    type
FROM sys_menu 
WHERE authority = 'delivery:edit';

-- 3. 检查超级管理员是否有 delivery:edit 权限
SELECT 
    u.mobile,
    u.name,
    r.name as role_name,
    m.name as menu_name,
    m.authority,
    rm.role_id,
    rm.menu_id
FROM sys_user u
LEFT JOIN sys_role r ON u.role_id = r.id
LEFT JOIN sys_role_menu rm ON r.id = rm.role_id
LEFT JOIN sys_menu m ON rm.menu_id = m.id
WHERE u.mobile = '15900000000'
  AND m.authority = 'delivery:edit';

-- 4. 检查超级管理员是否有通配符权限
SELECT 
    u.mobile,
    u.name,
    r.name as role_name,
    m.name as menu_name,
    m.authority
FROM sys_user u
LEFT JOIN sys_role r ON u.role_id = r.id
LEFT JOIN sys_role_menu rm ON r.id = rm.role_id
LEFT JOIN sys_menu m ON rm.menu_id = m.id
WHERE u.mobile = '15900000000'
  AND m.authority = '*:*:*';

-- 5. 检查所有 delivery 相关权限
SELECT 
    u.mobile,
    u.name,
    r.name as role_name,
    m.name as menu_name,
    m.authority
FROM sys_user u
LEFT JOIN sys_role r ON u.role_id = r.id
LEFT JOIN sys_role_menu rm ON r.id = rm.role_id
LEFT JOIN sys_menu m ON rm.menu_id = m.id
WHERE u.mobile = '15900000000'
  AND m.authority LIKE '%delivery%'
ORDER BY m.authority;
