-- 考勤打卡记录菜单配置脚本
-- 说明：在“考勤汇总表”同级新增“打卡记录”菜单，并复制原考勤菜单的角色授权

SET @ModuleId = 'attendance-record';
SET @SourceModuleId = '729599328976372997'; -- 考勤汇总表
SET @ParentId = '729569163395204357';

DELETE FROM BASE_MODULE WHERE F_Id = @ModuleId;
DELETE FROM BASE_AUTHORIZE WHERE F_ItemId = @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
)
VALUES (
  @ModuleId, @ParentId, 2, '打卡记录', 'attendanceRecord', 'attendance-record', 'icon-ym icon-ym-clock',
  2, 1, 'Web', NULL, '_self', '{"moduleId":"","iconBackgroundColor":"","isTree":0}',
  1, 1, 1, 1, NOW()
);

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;
