-- LMS 备货区域菜单及按钮权限，按菜单路径和权限编码幂等插入。
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 2092000000000000101, '备货区域', '', 2, 10, parent.id, 'stocking-ivt', '',
       'lms/stockingivt/index', 'LmsStockingIvt', 0, b'1', b'1', b'1',
       '1', NOW(), '1', NOW(), b'0'
FROM system_menu parent
WHERE parent.path = '/lms'
  AND parent.deleted = b'0'
  AND NOT EXISTS (
      SELECT 1 FROM system_menu
      WHERE component = 'lms/stockingivt/index' 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 2092000000000000102, '备货区域查询', 'lms:stocking-ivt:query', 3, 1, menu.id, '', '',
       '', '', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'
FROM system_menu menu
WHERE menu.component = 'lms/stockingivt/index'
  AND menu.deleted = b'0'
  AND NOT EXISTS (
      SELECT 1 FROM system_menu
      WHERE permission = 'lms:stocking-ivt: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 2092000000000000103, '备货区域修改', 'lms:stocking-ivt:update', 3, 2, menu.id, '', '',
       '', '', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'
FROM system_menu menu
WHERE menu.component = 'lms/stockingivt/index'
  AND menu.deleted = b'0'
  AND NOT EXISTS (
      SELECT 1 FROM system_menu
      WHERE permission = 'lms:stocking-ivt:update' AND deleted = b'0'
  );
