-- =============================================================================
-- App 菜单：大项目老师明细
-- 说明：
--   1. 菜单挂在 app首页 > 记录查询。
--   2. 本脚本只创建/更新菜单，不自动写入 BASE_AUTHORIZE。
--   3. 上线后由管理端按角色单独授权给大项目老师。
--   4. 脚本按 F_EnCode 幂等，可重复执行。
-- =============================================================================

SET @ModuleId = 'major-project-teacher-detail-app-lq';

SELECT F_Id INTO @ParentId
FROM BASE_MODULE
WHERE F_FullName = '记录查询'
  AND F_Category = 'App'
  AND F_DeleteMark IS NULL
  AND F_ParentId IN (
    SELECT F_Id
    FROM BASE_MODULE
    WHERE F_FullName = 'app首页'
      AND F_Category = 'App'
      AND F_DeleteMark IS NULL
  )
LIMIT 1;

INSERT INTO BASE_MODULE (
  F_Id, F_ParentId, F_Type, F_FullName, F_EnCode, F_UrlAddress, F_Icon,
  F_Description, F_SortCode, F_EnabledMark, F_Category, F_DeleteMark,
  F_LinkTarget, F_PropertyJson, F_IsButtonAuthorize, F_IsColumnAuthorize,
  F_IsDataAuthorize, F_IsFormAuthorize, F_CreatorTime, F_CreatorUserId
)
SELECT
  @ModuleId,
  @ParentId,
  2,
  '大项目老师明细',
  'majorProjectTeacherDetailApp',
  '/pagesA/major-project-teacher-detail/major-project-teacher-detail',
  'icon-ym icon-ym-generator-steps',
  '/static/home/report.png,icon-circle-bg-12',
  3,
  1,
  'App',
  NULL,
  '_self',
  '{"moduleId":"","iconBackgroundColor":"","isTree":0}',
  0,
  0,
  0,
  0,
  NOW(),
  'admin'
FROM (SELECT 1) AS seed
WHERE @ParentId IS NOT NULL
  AND NOT EXISTS (
    SELECT 1
    FROM BASE_MODULE
    WHERE F_EnCode = 'majorProjectTeacherDetailApp'
      AND F_Category = 'App'
      AND F_DeleteMark IS NULL
  );

SELECT F_Id INTO @ActualModuleId
FROM BASE_MODULE
WHERE F_EnCode = 'majorProjectTeacherDetailApp'
  AND F_Category = 'App'
  AND F_DeleteMark IS NULL
LIMIT 1;

UPDATE BASE_MODULE
SET F_ParentId = @ParentId,
    F_Type = 2,
    F_FullName = '大项目老师明细',
    F_UrlAddress = '/pagesA/major-project-teacher-detail/major-project-teacher-detail',
    F_Icon = 'icon-ym icon-ym-generator-steps',
    F_Description = '/static/home/report.png,icon-circle-bg-12',
    F_SortCode = 3,
    F_EnabledMark = 1,
    F_LastModifyTime = NOW(),
    F_LastModifyUserId = 'admin'
WHERE F_Id = @ActualModuleId
  AND @ParentId IS NOT NULL;

-- 校验菜单。角色授权需在管理端单独配置，不在本脚本中自动授予。
SELECT
  F_Id,
  F_ParentId,
  F_FullName,
  F_EnCode,
  F_UrlAddress,
  F_EnabledMark,
  F_Category
FROM BASE_MODULE
WHERE F_Id = @ActualModuleId;
