-- WMS基础模块 - 木箱信息只读菜单，脚本可重复执行。
-- 清理早期误放在“基础数据”下的木箱信息菜单。
DELETE FROM system_menu
WHERE id = 2091000000000000102
  AND permission = 'base:box-info:query';

DELETE FROM system_menu
WHERE id = 2091000000000000101
  AND path = 'box-info'
  AND component = 'base/boxinfo/index';

SET @wms_base_menu_id = (
    SELECT id
    FROM system_menu
    WHERE path = 'wms-base'
      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 2091000000000000101, '木箱信息', '', 2, 4, @wms_base_menu_id,
       'box-info', 'ep:box', 'wms/boxinfo/index', 'WmsBoxInfo',
       0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'
WHERE @wms_base_menu_id IS NOT NULL
  AND NOT EXISTS (
      SELECT 1
      FROM system_menu
      WHERE parent_id = @wms_base_menu_id
        AND path = 'box-info'
        AND deleted = b'0'
  );

SET @box_info_menu_id = (
    SELECT id
    FROM system_menu
    WHERE parent_id = @wms_base_menu_id
      AND path = 'box-info'
      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 2091000000000000102, '木箱信息查询', 'wms:box-info:query', 3, 1,
       @box_info_menu_id, '', '#', NULL, NULL,
       0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'
WHERE @box_info_menu_id IS NOT NULL
  AND NOT EXISTS (
      SELECT 1
      FROM system_menu
      WHERE permission = 'wms:box-info:query'
        AND deleted = b'0'
  );
