-- 系统更新说明：管理端动态菜单（挂在「系统管理」下，与「系统公告」同级）
-- 页面：antis-ncc-admin/src/views/lqChangelog/index.vue
-- 路由：/lqChangelog

SET @ModuleId = 'lq-changelog-admin';

SELECT F_Id INTO @ParentId
FROM BASE_MODULE
WHERE F_FullName = '系统管理' AND F_Type = 1 AND F_DeleteMark IS NULL
LIMIT 1;

SELECT F_Id INTO @SourceModuleId
FROM BASE_MODULE
WHERE F_FullName = '系统公告' AND F_Type = 2 AND F_DeleteMark IS NULL
LIMIT 1;

DELETE FROM BASE_AUTHORIZE WHERE F_ItemId = @ModuleId;
DELETE FROM BASE_MODULE WHERE F_Id = @ModuleId;

INSERT INTO BASE_MODULE (
  F_Id, F_ParentId, F_Type, F_FullName, F_EnCode, F_UrlAddress, F_Icon,
  F_SortCode, F_EnabledMark, F_Category, F_DeleteMark, F_LinkTarget,
  F_PropertyJson, F_IsButtonAuthorize, F_IsColumnAuthorize, F_IsDataAuthorize,
  F_IsFormAuthorize, F_CreatorTime, F_CreatorUserId, F_Description
)
VALUES (
  @ModuleId,
  @ParentId,
  2,
  '系统更新说明',
  'system.changelog',
  'lqChangelog',
  'icon-ym icon-ym-generator-notice',
  18,
  1,
  'Web',
  NULL,
  '_self',
  '{"iconBackgroundColor":"","moduleId":""}',
  1, 1, 1, 1,
  NOW(),
  'admin',
  '系统版本更新日志管理（新增/发布）'
);

INSERT INTO BASE_AUTHORIZE (
  F_Id, F_ItemType, F_ItemId, F_ObjectType, F_ObjectId, F_SortCode, F_CreatorTime, F_CreatorUserId
)
SELECT REPLACE(UUID(), '-', ''), 'module', @ModuleId, 'Role', t.F_ObjectId, 1, NOW(), 'admin'
FROM (
  SELECT DISTINCT F_ObjectId
  FROM BASE_AUTHORIZE
  WHERE F_ItemId = @SourceModuleId AND F_ItemType = 'module' AND F_ObjectType = 'Role'
) t;
