-- 移库管理菜单及权限。父菜单按“仓储业务”路径查找，脚本可重复执行。
SET @wms_business_menu_id = (
    SELECT id
      FROM system_menu
     WHERE path = 'wms-business'
       AND type = 1
       AND deleted = b'0'
     LIMIT 1
);

INSERT INTO system_menu
    (id, name, permission, type, sort, parent_id, path, icon, component,
     component_name, status, visible, keep_alive, always_show,
     creator, create_time, updater, update_time, deleted)
SELECT 6470, '移库管理', '', 2, 1, @wms_business_menu_id, 'move-inv', 'ep:sort',
       'wms/moveinv/index', 'WmsMoveInv', 0, b'1', b'1', b'1',
       '1', NOW(), '1', NOW(), b'0'
 WHERE @wms_business_menu_id IS NOT NULL
   AND NOT EXISTS (
       SELECT 1 FROM system_menu
        WHERE path = 'move-inv'
          AND parent_id = @wms_business_menu_id
          AND deleted = b'0'
   );

SET @move_inv_menu_id = (
    SELECT id
      FROM system_menu
     WHERE path = 'move-inv'
       AND parent_id = @wms_business_menu_id
       AND deleted = b'0'
     LIMIT 1
);

INSERT INTO system_menu
    (id, name, permission, type, sort, parent_id, path, icon, component,
     component_name, status, visible, keep_alive, always_show,
     creator, create_time, updater, update_time, deleted)
SELECT 6471, '移库单查询', 'wms:movement-order:query', 3, 1, @move_inv_menu_id,
       '', '#', NULL, NULL, 0, b'1', b'1', b'1',
       '1', NOW(), '1', NOW(), b'0'
 WHERE @move_inv_menu_id IS NOT NULL
   AND NOT EXISTS (
       SELECT 1 FROM system_menu
        WHERE permission = 'wms:movement-order:query' AND deleted = b'0'
   );

INSERT INTO system_menu
    (id, name, permission, type, sort, parent_id, path, icon, component,
     component_name, status, visible, keep_alive, always_show,
     creator, create_time, updater, update_time, deleted)
SELECT 6472, '移库单创建', 'wms:movement-order:create', 3, 2, @move_inv_menu_id,
       '', '#', NULL, NULL, 0, b'1', b'1', b'1',
       '1', NOW(), '1', NOW(), b'0'
 WHERE @move_inv_menu_id IS NOT NULL
   AND NOT EXISTS (
       SELECT 1 FROM system_menu
        WHERE permission = 'wms:movement-order:create' AND deleted = b'0'
   );

INSERT INTO system_menu
    (id, name, permission, type, sort, parent_id, path, icon, component,
     component_name, status, visible, keep_alive, always_show,
     creator, create_time, updater, update_time, deleted)
SELECT 6473, '移库单更新', 'wms:movement-order:update', 3, 3, @move_inv_menu_id,
       '', '#', NULL, NULL, 0, b'1', b'1', b'1',
       '1', NOW(), '1', NOW(), b'0'
 WHERE @move_inv_menu_id IS NOT NULL
   AND NOT EXISTS (
       SELECT 1 FROM system_menu
        WHERE permission = 'wms:movement-order:update' AND deleted = b'0'
   );

INSERT INTO system_menu
    (id, name, permission, type, sort, parent_id, path, icon, component,
     component_name, status, visible, keep_alive, always_show,
     creator, create_time, updater, update_time, deleted)
SELECT 6474, '移库单删除', 'wms:movement-order:delete', 3, 4, @move_inv_menu_id,
       '', '#', NULL, NULL, 0, b'1', b'1', b'1',
       '1', NOW(), '1', NOW(), b'0'
 WHERE @move_inv_menu_id IS NOT NULL
   AND NOT EXISTS (
       SELECT 1 FROM system_menu
        WHERE permission = 'wms:movement-order:delete' AND deleted = b'0'
   );
