-- ===================================================================
-- 喜颜看板系统 - 菜单配置SQL脚本
-- 使用说明：
-- 1. 先查询当前最大menu_id: SELECT MAX(menu_id) FROM sys_menu;
-- 2. 根据实际情况调整下面SQL中的menu_id值
-- 3. 执行本脚本
-- 4. 为角色分配菜单权限
-- 5. 重新登录系统查看效果
-- ===================================================================

-- ===================================================================
-- 一、看板管理模块
-- ===================================================================

-- 1. 看板管理（顶级菜单）
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2000, '看板管理', 0, 1, 'board', NULL, 1, 0, 'M', '0', '0', NULL, 'dashboard', 'admin', SYSDATE(), '看板管理目录');

-- 2. 生产看板（子菜单）
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2001, '生产看板', 2000, 1, 'kanban', 'board/kanban/index', 1, 0, 'C', '0', '0', 'board:kanban:view', 'data-board', 'admin', SYSDATE(), '生产数据看板');

-- ===================================================================
-- 二、ERP管理模块
-- ===================================================================

-- 1. ERP管理（顶级菜单）
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2100, 'ERP管理', 0, 2, 'erp', NULL, 1, 0, 'M', '0', '0', NULL, 's-cooperation', 'admin', SYSDATE(), 'ERP管理目录');

-- 2. 销售订单
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2101, '销售订单', 2100, 1, 'saleOrder', 'erp/saleOrder/index', 1, 0, 'C', '0', '0', 'erp:saleOrder:list', 's-order', 'admin', SYSDATE(), '销售订单管理');

-- 销售订单-查询按钮
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2102, '销售订单查询', 2101, 1, '', NULL, 1, 0, 'F', '0', '0', 'erp:saleOrder:query', '#', 'admin', SYSDATE(), '');

-- 销售订单-新增按钮
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2103, '销售订单新增', 2101, 2, '', NULL, 1, 0, 'F', '0', '0', 'erp:saleOrder:add', '#', 'admin', SYSDATE(), '');

-- 销售订单-修改按钮
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2104, '销售订单修改', 2101, 3, '', NULL, 1, 0, 'F', '0', '0', 'erp:saleOrder:edit', '#', 'admin', SYSDATE(), '');

-- 销售订单-删除按钮
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2105, '销售订单删除', 2101, 4, '', NULL, 1, 0, 'F', '0', '0', 'erp:saleOrder:remove', '#', 'admin', SYSDATE(), '');

-- 销售订单-导出按钮
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2106, '销售订单导出', 2101, 5, '', NULL, 1, 0, 'F', '0', '0', 'erp:saleOrder:export', '#', 'admin', SYSDATE(), '');

-- 3. 采购订单
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2110, '采购订单', 2100, 2, 'purchaseOrder', 'erp/purchaseOrder/index', 1, 0, 'C', '0', '0', 'erp:purchaseOrder:list', 'shopping-cart-2', 'admin', SYSDATE(), '采购订单管理');

-- 采购订单-按钮权限
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2111, '采购订单查询', 2110, 1, '', NULL, 1, 0, 'F', '0', '0', 'erp:purchaseOrder:query', '#', 'admin', SYSDATE(), '');
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2112, '采购订单新增', 2110, 2, '', NULL, 1, 0, 'F', '0', '0', 'erp:purchaseOrder:add', '#', 'admin', SYSDATE(), '');
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2113, '采购订单修改', 2110, 3, '', NULL, 1, 0, 'F', '0', '0', 'erp:purchaseOrder:edit', '#', 'admin', SYSDATE(), '');
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2114, '采购订单删除', 2110, 4, '', NULL, 1, 0, 'F', '0', '0', 'erp:purchaseOrder:remove', '#', 'admin', SYSDATE(), '');
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2115, '采购订单导出', 2110, 5, '', NULL, 1, 0, 'F', '0', '0', 'erp:purchaseOrder:export', '#', 'admin', SYSDATE(), '');

-- 4. 生产工单
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2120, '生产工单', 2100, 3, 'productionOrder', 'erp/productionOrder/index', 1, 0, 'C', '0', '0', 'erp:productionOrder:list', 's-marketing', 'admin', SYSDATE(), '生产工单管理');

-- 生产工单-按钮权限
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2121, '生产工单查询', 2120, 1, '', NULL, 1, 0, 'F', '0', '0', 'erp:productionOrder:query', '#', 'admin', SYSDATE(), '');
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2122, '生产工单新增', 2120, 2, '', NULL, 1, 0, 'F', '0', '0', 'erp:productionOrder:add', '#', 'admin', SYSDATE(), '');
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2123, '生产工单修改', 2120, 3, '', NULL, 1, 0, 'F', '0', '0', 'erp:productionOrder:edit', '#', 'admin', SYSDATE(), '');
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2124, '生产工单删除', 2120, 4, '', NULL, 1, 0, 'F', '0', '0', 'erp:productionOrder:remove', '#', 'admin', SYSDATE(), '');
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2125, '生产工单导出', 2120, 5, '', NULL, 1, 0, 'F', '0', '0', 'erp:productionOrder:export', '#', 'admin', SYSDATE(), '');

-- 5. 质检单据
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2130, '质检单据', 2100, 4, 'inspectBill', 'erp/inspectBill/index', 1, 0, 'C', '0', '0', 'erp:inspectBill:list', 'document-checked', 'admin', SYSDATE(), '质检单据管理');

-- 质检单据-按钮权限
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2131, '质检单据查询', 2130, 1, '', NULL, 1, 0, 'F', '0', '0', 'erp:inspectBill:query', '#', 'admin', SYSDATE(), '');
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2132, '质检单据新增', 2130, 2, '', NULL, 1, 0, 'F', '0', '0', 'erp:inspectBill:add', '#', 'admin', SYSDATE(), '');
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2133, '质检单据修改', 2130, 3, '', NULL, 1, 0, 'F', '0', '0', 'erp:inspectBill:edit', '#', 'admin', SYSDATE(), '');
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2134, '质检单据删除', 2130, 4, '', NULL, 1, 0, 'F', '0', '0', 'erp:inspectBill:remove', '#', 'admin', SYSDATE(), '');
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2135, '质检单据导出', 2130, 5, '', NULL, 1, 0, 'F', '0', '0', 'erp:inspectBill:export', '#', 'admin', SYSDATE(), '');

-- 6. 生产入库
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2140, '生产入库', 2100, 5, 'productionInstock', 'erp/productionInstock/index', 1, 0, 'C', '0', '0', 'erp:productionInstock:list', 'box', 'admin', SYSDATE(), '生产入库管理');

-- 生产入库-按钮权限
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2141, '生产入库查询', 2140, 1, '', NULL, 1, 0, 'F', '0', '0', 'erp:productionInstock:query', '#', 'admin', SYSDATE(), '');
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2142, '生产入库新增', 2140, 2, '', NULL, 1, 0, 'F', '0', '0', 'erp:productionInstock:add', '#', 'admin', SYSDATE(), '');
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2143, '生产入库修改', 2140, 3, '', NULL, 1, 0, 'F', '0', '0', 'erp:productionInstock:edit', '#', 'admin', SYSDATE(), '');
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2144, '生产入库删除', 2140, 4, '', NULL, 1, 0, 'F', '0', '0', 'erp:productionInstock:remove', '#', 'admin', SYSDATE(), '');
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2145, '生产入库导出', 2140, 5, '', NULL, 1, 0, 'F', '0', '0', 'erp:productionInstock:export', '#', 'admin', SYSDATE(), '');

-- ===================================================================
-- 三、质检管理模块
-- ===================================================================

-- 1. 质检管理（顶级菜单）
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2200, '质检管理', 0, 3, 'qc', NULL, 1, 0, 'M', '0', '0', NULL, 'data-analysis', 'admin', SYSDATE(), '质检管理目录');

-- 2. 质检数据
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2201, '质检数据', 2200, 1, 'data', 'qc/index', 1, 0, 'C', '0', '0', 'qc:data:list', 'data-line', 'admin', SYSDATE(), '质检数据查询');

-- 质检数据-按钮权限
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2202, '质检数据查询', 2201, 1, '', NULL, 1, 0, 'F', '0', '0', 'qc:data:query', '#', 'admin', SYSDATE(), '');
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
VALUES (2203, '质检数据导出', 2201, 2, '', NULL, 1, 0, 'F', '0', '0', 'qc:data:export', '#', 'admin', SYSDATE(), '');

-- ===================================================================
-- 四、为管理员角色分配菜单权限
-- ===================================================================

-- 为管理员角色（role_id=1）分配所有新菜单权限
INSERT INTO sys_role_menu (role_id, menu_id)
SELECT 1, menu_id FROM sys_menu WHERE menu_id >= 2000 AND menu_id < 3000;

-- ===================================================================
-- 五、验证SQL
-- ===================================================================

-- 查询新增的菜单
SELECT menu_id, menu_name, parent_id, path, component, menu_type, perms, icon 
FROM sys_menu 
WHERE menu_id >= 2000 
ORDER BY menu_id;

-- 查询菜单树结构
SELECT 
  CONCAT(REPEAT('  ', CASE WHEN parent_id = 0 THEN 0 ELSE 1 END), menu_name) AS menu_tree,
  menu_id,
  parent_id,
  path,
  menu_type,
  visible,
  status
FROM sys_menu 
WHERE menu_id >= 2000 
ORDER BY parent_id, order_num;

