-- 公共招聘会信息表（石河子）
-- 瀚高数据库

-- 删除之前创建的不需要的表
DROP TABLE IF EXISTS "public_job_fair_area";
DROP TABLE IF EXISTS "public_job_fair_booth";

-- 删除旧表（如果存在）
DROP TABLE IF EXISTS "public_job_fair_signup";
DROP TABLE IF EXISTS "public_job_fair_job";
DROP TABLE IF EXISTS "public_job_fair_company";
DROP TABLE IF EXISTS "public_job_fair";

-- 招聘会主表
CREATE TABLE "public_job_fair" (
    "job_fair_id" VARCHAR(64) PRIMARY KEY,
    "job_fair_title" VARCHAR(500),
    "job_fair_address" VARCHAR(500),
    "job_fair_type" VARCHAR(10),
    "job_fair_start_time" TIMESTAMP,
    "job_fair_end_time" TIMESTAMP,
    "job_fair_host_unit" VARCHAR(200),
    "job_fair_help_unit" VARCHAR(200),
    "job_fair_organize_unit" VARCHAR(200),
    "job_fair_introduction" TEXT,
    "job_fair_remark" VARCHAR(500),
    "job_fair_phone" VARCHAR(50),
    "job_fair_image" VARCHAR(500),
    "job_fair_area_image" VARCHAR(500),
    "create_by" VARCHAR(64),
    "create_time" TIMESTAMP,
    "update_by" VARCHAR(64),
    "update_time" TIMESTAMP,
    "job_fair_venue_id" VARCHAR(64),
    "job_fair_sign_up_start_time" TIMESTAMP,
    "job_fair_sign_up_end_time" TIMESTAMP,
    "enterprise_num" VARCHAR(20),
    "booth_num" VARCHAR(20),
    "division_name" VARCHAR(200),
    "dept_code_last" VARCHAR(50),
    "dept_code_all" VARCHAR(200),
    "job_fair_category" VARCHAR(50),
    "latitude" DECIMAL(10,7),
    "longitude" DECIMAL(10,7),
    "del_flag" CHAR(1) DEFAULT '0'
);

COMMENT ON TABLE "public_job_fair" IS '公共招聘会信息表';
COMMENT ON COLUMN "public_job_fair"."job_fair_type" IS '招聘会类型 1-线上 2-线下';
COMMENT ON COLUMN "public_job_fair"."latitude" IS '纬度';
COMMENT ON COLUMN "public_job_fair"."longitude" IS '经度';
COMMENT ON COLUMN "public_job_fair"."del_flag" IS '删除标志（0正常 2删除）';

-- 招聘会-企业关联表
CREATE TABLE "public_job_fair_company" (
    "id" VARCHAR(64) PRIMARY KEY,
    "job_fair_id" VARCHAR(64),
    "company_id" BIGINT,
    "create_by" VARCHAR(64),
    "create_time" TIMESTAMP,
    "update_by" VARCHAR(64),
    "update_time" TIMESTAMP,
    "del_flag" CHAR(1) DEFAULT '0'
);

COMMENT ON TABLE "public_job_fair_company" IS '招聘会-企业关联表';

-- 招聘会-岗位关联表
CREATE TABLE "public_job_fair_job" (
    "id" VARCHAR(64) PRIMARY KEY,
    "job_fair_id" VARCHAR(64),
    "job_id" BIGINT,
    "company_id" BIGINT,
    "create_by" VARCHAR(64),
    "create_time" TIMESTAMP,
    "update_by" VARCHAR(64),
    "update_time" TIMESTAMP,
    "del_flag" CHAR(1) DEFAULT '0'
);

COMMENT ON TABLE "public_job_fair_job" IS '招聘会-岗位关联表';

-- 招聘会-用户报名表
CREATE TABLE "public_job_fair_signup" (
    "id" VARCHAR(64) PRIMARY KEY,
    "job_fair_id" VARCHAR(64),
    "person_id" BIGINT,
    "create_by" VARCHAR(64),
    "create_time" TIMESTAMP,
    "update_by" VARCHAR(64),
    "update_time" TIMESTAMP,
    "del_flag" CHAR(1) DEFAULT '0'
);

COMMENT ON TABLE "public_job_fair_signup" IS '招聘会-用户报名表';

-- 创建索引
CREATE INDEX "idx_public_job_fair_type" ON "public_job_fair"("job_fair_type");
CREATE INDEX "idx_public_job_fair_start_time" ON "public_job_fair"("job_fair_start_time");
CREATE INDEX "idx_public_job_fair_company_fair_id" ON "public_job_fair_company"("job_fair_id");
CREATE INDEX "idx_public_job_fair_company_company_id" ON "public_job_fair_company"("company_id");
CREATE INDEX "idx_public_job_fair_job_fair_id" ON "public_job_fair_job"("job_fair_id");
CREATE INDEX "idx_public_job_fair_job_job_id" ON "public_job_fair_job"("job_id");
CREATE INDEX "idx_public_job_fair_signup_fair_id" ON "public_job_fair_signup"("job_fair_id");
CREATE INDEX "idx_public_job_fair_signup_person_id" ON "public_job_fair_signup"("person_id");

-- 插入石河子招聘会测试数据
INSERT INTO "public_job_fair" (
    "job_fair_id", "job_fair_title", "job_fair_address", "job_fair_type",
    "job_fair_start_time", "job_fair_end_time", "job_fair_host_unit", "job_fair_help_unit",
    "job_fair_organize_unit", "job_fair_introduction", "job_fair_phone",
    "create_time", "update_time", "job_fair_venue_id",
    "job_fair_sign_up_start_time", "job_fair_sign_up_end_time",
    "enterprise_num", "booth_num", "division_name", "dept_code_last", "dept_code_all",
    "job_fair_category", "latitude", "longitude", "del_flag"
) VALUES (
    '1',
    '2026年石河子市春风行动暨就业援助月专场招聘会',
    '石河子市人力资源市场（石河子市北四路）',
    '2',
    '2026-01-20 10:00:00',
    '2026-01-20 16:00:00',
    '石河子市人力资源和社会保障局',
    '石河子市就业服务中心',
    '石河子市公共就业服务中心',
    '为促进石河子市劳动者就业创业，搭建用人单位与求职者双向交流平台，特举办本次春风行动暨就业援助月专场招聘会。',
    '0993-2012345',
    '2026-01-10 09:00:00',
    '2026-01-10 09:00:00',
    '1',
    '2026-01-10 09:00:00',
    '2026-01-19 18:00:00',
    '3',
    '10',
    '石河子市',
    '659001000000',
    '659001000000',
    '社会招聘',
    44.3066,
    86.0419,
    '0'
);
