create table if not exists member
(
    pep_user_id           integer not null,
    id_number             varchar(32),
    id_photo              varchar(1024),
    gender                varchar(32),
    birthday              date,
    native_place          varchar(128),
    marital               varchar(32),
    politics_status       varchar(32),
    phone_number          varchar(32),
    work_place            varchar(128),
    graduated_from        varchar(128),
    education_background  varchar(32),
    specialty             varchar(64),
    graduation_date       date,
    hiredate              date,
    turn_probation_period date,
    regular_date          date,
    dimission_date        date,
    experience_year       double precision,
    occupational_history  text,
    vitae                 varchar(1024),
    del                   boolean default false,
    constraint member_pk
        primary key (pep_user_id)
);

comment on column member.pep_user_id is '项企用户id';

comment on column member.id_number is '证件号';

comment on column member.id_photo is '证件照';

comment on column member.gender is '性别';

comment on column member.birthday is '出生年月';

comment on column member.native_place is '籍贯';

comment on column member.marital is '婚育状态';

comment on column member.politics_status is '整治面貌';

comment on column member.work_place is '工作地点';

comment on column member.graduated_from is '毕业院校';

comment on column member.education_background is '学历';

comment on column member.specialty is '专业';

comment on column member.graduation_date is '毕业时间';

comment on column member.hiredate is '入职时间';

comment on column member.turn_probation_period is '转试用期时间';

comment on column member.regular_date is '转正时间';

comment on column member.dimission_date is '离职时间';

comment on column member.experience_year is '工作经验/年';

comment on column member.occupational_history is '工作经历';

comment on column member.vitae is '简历';

create unique index if not exists member_pep_user_id_uindex
    on member (pep_user_id);

create table if not exists vacate
(
    id                   serial    not null,
    pep_user_id          integer   not null,
    start_time           timestamp not null,
    end_time             timestamp not null,
    type                 varchar(32),
    duration             integer,
    pep_process_story_id integer   not null,
    wf_process_state     varchar(32),
    reason               varchar(1024),
    constraint vacate_pk
        primary key (id)
);

comment on table vacate is '假勤之休假申请工作流一维展开数据';

comment on column vacate.type is '请假类别';

comment on column vacate.duration is '时长 s';

comment on column vacate.pep_process_story_id is '和 项企 workflow_process_history 关联';

comment on column vacate.wf_process_state is '流程状态';

comment on column vacate.reason is '原因';

create unique index if not exists vacate_id_uindex
    on vacate (id);

create table if not exists holiday
(
    day     date not null,
    holiday jsonb,
    type    varchar(32),
    constraint holiday_pk
        primary key (day)
);

comment on column holiday.type is 'workday 工作日 / dayoff 休息日 / festivals 节假日';

create unique index if not exists holiday_day_uindex
    on holiday (day);

create table if not exists overtime
(
    id                   serial    not null,
    pep_user_id          integer   not null,
    start_time           timestamp not null,
    end_time             timestamp not null,
    duration             integer,
    pep_process_story_id integer   not null,
    wf_process_state     varchar(32),
    take_rest_workday    integer default 0,
    take_rest_dayoff     integer default 0,
    take_rest_festivals  integer default 0,
    pay_workday          integer default 0,
    pay_dayoff           integer default 0,
    pay_festivals        integer default 0,
    compensate           varchar(32),
    reason               varchar(1024),
    constraint overtime_pk
        primary key (id)
);

comment on table overtime is '假勤之加班申请工作流一维展开数据';

comment on column overtime.take_rest_workday is '工作日调休';

comment on column overtime.take_rest_dayoff is '普假调休';

comment on column overtime.take_rest_festivals is '节假日调休';

comment on column overtime.pay_workday is '工作日补偿';

comment on column overtime.pay_dayoff is '普假补偿';

comment on column overtime.pay_festivals is '节假日补偿';

comment on column overtime.compensate is '补偿方式';

comment on column overtime.reason is '原因';

create unique index if not exists overtime_id_uindex
    on overtime (id);

create table if not exists overtime_day
(
    id          serial not null,
    day         date   not null,
    duration    integer,
    overtime_id integer,
    constraint overtime_day_pk
        primary key (id)
);

create unique index if not exists overtime_day_id_uindex
    on overtime_day (id);

create table if not exists vacate_day
(
    id        serial  not null,
    day       date    not null,
    duration  integer not null,
    vacate_id integer,
    constraint vacate_day_pk
        primary key (id)
);

create unique index if not exists vacate_day_id_uindex
    on vacate_day (id);

