-- ============================================================
-- 招聘公告数据表设计
-- 说明：分析对象为「招聘公告」，多值属性（招聘届数、批次、标签组、
--       热招城市、岗位大类、学历要求）直接拆关联表存原始值，
--       不引入任何字典表，避免归一化对公告解析结果的限制。
-- ============================================================


-- ============================================================
-- 招聘公告主表
-- ============================================================
CREATE TABLE `bg_recruit_announcement` (
  `id`                BIGINT        NOT NULL AUTO_INCREMENT COMMENT '主键',
  `company_id`        BIGINT        NULL COMMENT '关联企业主表id',
  `company_name`      VARCHAR(128)  NOT NULL DEFAULT '' COMMENT '公司名称',
  `title`             VARCHAR(255)  NOT NULL DEFAULT '' COMMENT '公告标题',
  `company_intro`     TEXT          NULL COMMENT '公司简介',
  `target_audience`   VARCHAR(500)  NULL COMMENT '面向对象，如2027届本硕博',
  `major_require`     VARCHAR(500)  NULL COMMENT '专业要求',
  `remark`            VARCHAR(1000) NULL COMMENT '备注',
  `written_exam`      VARCHAR(16)   NULL COMMENT '是否笔试：有 / 无 / 未明确',
  `apply_start_time`  DATETIME      NULL COMMENT '投递开始时间',
  `apply_end_time`    DATETIME      NULL COMMENT '投递结束时间',
  `apply_end_desc`    VARCHAR(64)   NULL COMMENT '投递截止描述，如"尽快投递"',
  `invite_code`       VARCHAR(64)   NULL COMMENT '专属内推码',
  `announcement_url`  VARCHAR(512)  NULL COMMENT '公告地址',
  `apply_url`         VARCHAR(512)  NULL COMMENT '投递地址',
  `apply_email`       VARCHAR(128)  NULL COMMENT '投递邮箱',
  `source`            VARCHAR(255)  NULL COMMENT '信息来源说明',
  `publish_time`      DATETIME      NULL COMMENT '公告发布/更新时间',
  `create_time`       DATETIME      NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time`       DATETIME      NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (`id`),
  KEY `idx_company_id` (`company_id`),
  KEY `idx_company_name` (`company_name`),
  KEY `idx_written_exam` (`written_exam`),
  KEY `idx_apply_start_time` (`apply_start_time`),
  KEY `idx_announcement_url` (`announcement_url`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='招聘公告主表';


-- ============================================================
-- 招聘届数关联表
-- ============================================================
CREATE TABLE `bg_recruit_announcement_year` (
  `id`               BIGINT   NOT NULL AUTO_INCREMENT COMMENT '主键',
  `announcement_id`  BIGINT   NOT NULL COMMENT '公告id',
  `recruit_year`     SMALLINT NOT NULL COMMENT '招聘届数，如2027',
  `create_time`      DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  PRIMARY KEY (`id`),
  KEY `idx_announcement_id` (`announcement_id`),
  KEY `idx_recruit_year` (`recruit_year`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='招聘公告-招聘届数关联表';


-- ============================================================
-- 批次关联表
-- ============================================================
CREATE TABLE `bg_recruit_announcement_batch` (
  `id`               BIGINT      NOT NULL AUTO_INCREMENT COMMENT '主键',
  `announcement_id`  BIGINT      NOT NULL COMMENT '公告id',
  `batch_name`       VARCHAR(64) NOT NULL COMMENT '批次值，如实习/暑期实习/寒假实习/秋招专场/春招提前批/春招补招',
  `create_time`      DATETIME    NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  PRIMARY KEY (`id`),
  KEY `idx_announcement_id` (`announcement_id`),
  KEY `idx_batch_name` (`batch_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='招聘公告-批次关联表';


-- ============================================================
-- 标签组关联表
-- ============================================================
CREATE TABLE `bg_recruit_announcement_tag` (
  `id`               BIGINT      NOT NULL AUTO_INCREMENT COMMENT '主键',
  `announcement_id`  BIGINT      NOT NULL COMMENT '公告id',
  `tag_name`         VARCHAR(64) NOT NULL COMMENT '标签值，如秋招提前批/竞争力薪酬/校招',
  `create_time`      DATETIME    NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  PRIMARY KEY (`id`),
  KEY `idx_announcement_id` (`announcement_id`),
  KEY `idx_tag_name` (`tag_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='招聘公告-标签组关联表';


-- ============================================================
-- 热招城市关联表
-- ============================================================
CREATE TABLE `bg_recruit_announcement_city` (
  `id`               BIGINT      NOT NULL AUTO_INCREMENT COMMENT '主键',
  `announcement_id`  BIGINT      NOT NULL COMMENT '公告id',
  `city_name`        VARCHAR(64) NOT NULL COMMENT '城市值，如北京市/天津市',
  `create_time`      DATETIME    NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  PRIMARY KEY (`id`),
  KEY `idx_announcement_id` (`announcement_id`),
  KEY `idx_city_name` (`city_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='招聘公告-热招城市关联表';


-- ============================================================
-- 岗位大类关联表
-- ============================================================
CREATE TABLE `bg_recruit_announcement_category` (
  `id`               BIGINT      NOT NULL AUTO_INCREMENT COMMENT '主键',
  `announcement_id`  BIGINT      NOT NULL COMMENT '公告id',
  `category_name`    VARCHAR(64) NOT NULL COMMENT '岗位大类值，如IT技术/人工智能/通信',
  `create_time`      DATETIME    NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  PRIMARY KEY (`id`),
  KEY `idx_announcement_id` (`announcement_id`),
  KEY `idx_category_name` (`category_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='招聘公告-岗位大类关联表';


-- ============================================================
-- 学历要求关联表
-- ============================================================
CREATE TABLE `bg_recruit_announcement_education` (
  `id`               BIGINT      NOT NULL AUTO_INCREMENT COMMENT '主键',
  `announcement_id`  BIGINT      NOT NULL COMMENT '公告id',
  `education_name`   VARCHAR(32) NOT NULL COMMENT '学历值，如本科/硕士/博士',
  `create_time`      DATETIME    NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  PRIMARY KEY (`id`),
  KEY `idx_announcement_id` (`announcement_id`),
  KEY `idx_education_name` (`education_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='招聘公告-学历要求关联表';
