-- 入库管理菜单。接口沿用出入库单权限，脚本可重复执行。
SET @wms_order_menu_id = (
    SELECT id FROM system_menu
     WHERE (id = 6400 OR path IN ('order', 'wms-business'))
       AND deleted = b'0'
     ORDER BY path = 'wms-business' DESC, id = 6400 DESC
     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 6480, '入库管理', '', 2, 1, @wms_order_menu_id, 'inbound', 'ep:download',
       'wms/inbound/index', 'WmsInboundOrder', 0, b'1', b'1', b'1',
       '1', NOW(), '1', NOW(), b'0'
 WHERE @wms_order_menu_id IS NOT NULL
   AND NOT EXISTS (
       SELECT 1 FROM system_menu
        WHERE parent_id = @wms_order_menu_id
          AND path = 'inbound'
          AND deleted = b'0'
   );

SET @inbound_menu_id = (
    SELECT id FROM system_menu
     WHERE parent_id = @wms_order_menu_id
       AND path = 'inbound'
       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 6481, '入库单查询', 'wms:iostor-inv:query', 3, 1, @inbound_menu_id,
       '', '#', NULL, NULL, 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'
 WHERE @inbound_menu_id IS NOT NULL
   AND NOT EXISTS (
       SELECT 1 FROM system_menu
        WHERE parent_id = @inbound_menu_id AND permission = 'wms:iostor-inv: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 6482, '入库单创建', 'wms:iostor-inv:create', 3, 2, @inbound_menu_id,
       '', '#', NULL, NULL, 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'
 WHERE @inbound_menu_id IS NOT NULL
   AND NOT EXISTS (
       SELECT 1 FROM system_menu
        WHERE parent_id = @inbound_menu_id AND permission = 'wms:iostor-inv: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 6483, '入库单更新', 'wms:iostor-inv:update', 3, 3, @inbound_menu_id,
       '', '#', NULL, NULL, 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'
 WHERE @inbound_menu_id IS NOT NULL
   AND NOT EXISTS (
       SELECT 1 FROM system_menu
        WHERE parent_id = @inbound_menu_id AND permission = 'wms:iostor-inv:update'
          AND deleted = b'0'
   );
