-- DM8 部门外部组织编码映射菜单与权限脚本
-- 清理旧数据并重新创建目录、页面及操作按钮

-- 保持脚本幂等性，先清理旧数据
DELETE FROM system_role_menu WHERE menu_id IN (6200, 6201, 620101, 620102, 620103, 620104);
DELETE FROM system_menu WHERE id IN (6200, 6201, 620101, 620102, 620103, 620104);

-- 在系统管理（ID=2）下创建目录与页面
INSERT INTO system_menu (
    id, name, permission, type, sort, parent_id,
    path, icon, component, status, component_name
) VALUES (
    6200, '组织编码映射', '', 1, 25, 2,
    'dept-external', 'ep:connection', '', 0, 'DeptExternalCodeRoot'
);

INSERT INTO system_menu (
    id, name, permission, type, sort, parent_id,
    path, icon, component, status, component_name
) VALUES (
    6201, '外部组织编码', '', 2, 1, 6200,
    'dept-external-code', 'ep:connection', 'system/deptExternalCode/index', 0, 'SystemDeptExternalCode'
);

-- 创建操作按钮权限
INSERT INTO system_menu (
    id, name, permission, type, sort, parent_id,
    path, icon, component, status
) VALUES
    (620101, '查询部门外部编码', 'system:dept-external-code:query', 3, 1, 6201, '', '', '', 0),
    (620102, '新增部门外部编码', 'system:dept-external-code:create', 3, 2, 6201, '', '', '', 0),
    (620103, '修改部门外部编码', 'system:dept-external-code:update', 3, 3, 6201, '', '', '', 0),
    (620104, '删除部门外部编码', 'system:dept-external-code:delete', 3, 4, 6201, '', '', '', 0);

-- 如需分配给角色，请按本地序列策略写入 system_role_menu
