-- 教育部经营看板重点品项配置
-- 主键由应用层 YitIdHelper.NextId().ToString() 生成。

CREATE TABLE IF NOT EXISTS `lq_education_dashboard_featured_item` (
  `F_Id` varchar(50) NOT NULL COMMENT '主键',
  `F_ItemId` varchar(50) NOT NULL COMMENT '品项ID（lq_xmzl.F_Id）',
  `F_DisplayName` varchar(200) NOT NULL COMMENT '自定义显示名',
  `F_Sort` int NOT NULL DEFAULT 0 COMMENT '排序号，越小越靠前',
  `F_Enabled` int NOT NULL DEFAULT 1 COMMENT '启用状态：0禁用 1启用',
  `F_CreateUserId` varchar(50) DEFAULT NULL COMMENT '创建人ID（BASE_USER.F_Id）',
  `F_CreateTime` datetime DEFAULT NULL COMMENT '创建时间',
  `F_UpdateUserId` varchar(50) DEFAULT NULL COMMENT '修改人ID（BASE_USER.F_Id）',
  `F_UpdateTime` datetime DEFAULT NULL COMMENT '修改时间',
  PRIMARY KEY (`F_Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='教育部经营看板重点品项配置';

SET @idx_exists := (
  SELECT COUNT(1)
  FROM information_schema.statistics
  WHERE table_schema = DATABASE()
    AND table_name = 'lq_education_dashboard_featured_item'
    AND index_name = 'UK_lq_education_featured_item_ItemId'
);
SET @sql := IF(
  @idx_exists = 0,
  'ALTER TABLE `lq_education_dashboard_featured_item` ADD UNIQUE KEY `UK_lq_education_featured_item_ItemId` (`F_ItemId`)',
  'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @idx_exists := (
  SELECT COUNT(1)
  FROM information_schema.statistics
  WHERE table_schema = DATABASE()
    AND table_name = 'lq_education_dashboard_featured_item'
    AND index_name = 'IDX_lq_education_featured_item_Enabled_Sort'
);
SET @sql := IF(
  @idx_exists = 0,
  'ALTER TABLE `lq_education_dashboard_featured_item` ADD KEY `IDX_lq_education_featured_item_Enabled_Sort` (`F_Enabled`, `F_Sort`)',
  'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
