create table hrsa_sub_table
(
    id bigint primary key ,
    create_time timestamp ,
    update_time timestamp ,
    creator bigint ,
    delete_type int default 0 ,
    tenant_key varchar(10) ,
    sub_table_name varchar(100) not null ,
    dimension varchar(20) not null ,
    start_month varchar(10) ,
    end_month varchar(10) ,
    pay_org_string varchar(500) ,
    pay_agency_string varchar(500) ,
    sub_company_string varchar(500) ,
    depart_string varchar(500) ,
    grade_string varchar(500) ,
    position_string varchar(500) ,
    status_string varchar(500) ,
    employee_type varchar(500) ,
    employee_string varchar(500) ,
    payment_type_string varchar(100) 
)
;

create table hrsa_sub_table_item
(
    id bigint primary key ,
    create_time timestamp ,
    update_time timestamp ,
    creator bigint ,
    delete_type int default 0 ,
    tenant_key varchar(10) ,
    table_id bigint not null ,
    item_name varchar(50) not null ,
    item_value varchar(500) not null ,
    index_value int not null ,
    total_rule varchar(500) ,
    count_rule varchar(500) ,
    unit_type int default 2 
)
;

alter table hrsa_sub_table add table_type int
;

alter table hrsa_sub_table ALTER table_type TYPE int 
;

alter table  hrsa_sub_table ALTER COLUMN table_type set DEFAULT 0
; 



create table hrsa_salary_stats_dim
(
    id bigint primary key ,
    create_time timestamp ,
    update_time timestamp ,
    creator bigint ,
    delete_type int default 0 ,
    tenant_key varchar(10) ,
    dim_name varchar(100) ,
    dim_type varchar(20) ,
    remark varchar(500) ,
    setting varchar(2000) ,
    is_default int ,
    dim_code varchar(50) 
)
;

create table hrsa_salary_stats_report
(
    id bigint primary key ,
    create_time timestamp ,
    update_time timestamp ,
    creator bigint ,
    delete_type int default 0 ,
    tenant_key varchar(10) ,
    report_name varchar(100) ,
    dimension varchar(1000) ,
    tax_agent_setting varchar(1000) ,
    income_category_setting varchar(20) ,
    sub_company_setting varchar(1000) ,
    depart_setting varchar(1000) ,
    grade_setting varchar(1000) ,
    position_setting varchar(1000) ,
    status_setting varchar(1000) ,
    employee_setting varchar(1000) ,
    hiredate_setting varchar(1000) ,
    leavedate_setting varchar(1000) ,
    salary_start_month timestamp ,
    salary_end_month timestamp 
)
;

create table hrsa_salary_statistics_item
(
    id bigint primary key ,
    create_time timestamp ,
    update_time timestamp ,
    creator bigint ,
    delete_type int default 0 ,
    tenant_key varchar(10) ,
    item_name varchar(50) ,
    item_value varchar(1000) ,
    count_rule varchar(500) ,
    sum_rule varchar(500) ,
    avg_rule varchar(500) ,
    max_rule varchar(500) ,
    min_rule varchar(500) ,
    median_rule varchar(500) ,
    index_value int ,
    unit_type int ,
    stat_report_id bigint 
)
;

create table hrsa_charts_setting
(
    id bigint primary key ,
    create_time timestamp ,
    update_time timestamp ,
    creator bigint ,
    delete_type int default 0 ,
    tenant_key varchar(10) ,
    table_id bigint not null ,
    charts_type int not null ,
    item_values varchar(500) ,
    item_col_value varchar(50) not null ,
    dimension_range int not null ,
    item_sort_value varchar(500) ,
    item_col_sort_value varchar(50) ,
    sort_type int ,
    sort_num int 
)
;

create table hrsa_salary_echarts_setting
(
    id bigint primary key ,
    create_time timestamp ,
    update_time timestamp ,
    creator bigint ,
    delete_type int default 0 ,
    tenant_key varchar(10) ,
    report_id bigint not null ,
    charts_type int not null ,
    item_values varchar(500) ,
    item_col_value varchar(50) not null ,
    dimension_range int not null ,
    item_sort_value varchar(500) ,
    item_col_sort_value varchar(50) ,
    sort_type int ,
    sort_num int 
)
;

alter table hrsa_salary_stats_dim alter dim_type TYPE varchar(30)
;

alter table hrsa_salary_stats_report alter income_category_setting TYPE varchar(1000)
;

create table hrsa_statreportlogs_detail
(
    id bigint primary key ,
    create_time timestamp ,
    update_time timestamp ,
    creator bigint ,
    delete_type int default 0 ,
    tenant_key varchar(10) ,
    uuid varchar(36) not null ,
    mainid varchar(36) not null ,
    dataid varchar(50) not null ,
    belongdataid varchar(50) not null ,
    tablename varchar(200) not null ,
    tablenamelabelid varchar(50) default '-1' not null ,
    tablenamedesc varchar(50) not null ,
    fieldname varchar(200) not null ,
    fieldnamelabelid varchar(50) default '-1' not null ,
    newvalue text not null ,
    oldvalue text not null ,
    newrealvalue text not null ,
    oldrealvalue text not null ,
    fielddesc varchar(200) not null ,
    showorder int not null ,
    isdetail int NOT NULL DEFAULT 0 
)
;

create table hrsa_statreportlogs
(
    id bigint primary key  ,
    create_time timestamp ,
    update_time timestamp ,
    creator bigint ,
    delete_type int default 0 ,
    tenant_key varchar(10) ,
    uuid varchar(36) not null ,
    log_date timestamp not null ,
    device varchar(500) not null ,
    log_operator bigint not null ,
    operatorname varchar(100) ,
    targetid bigint NOT NULL DEFAULT -1 ,
    targetname text not null ,
    modulename varchar(100) not null ,
    functionname varchar(100) not null ,
    interfacename varchar(100) not null ,
    requesturl varchar(200) not null ,
    requesturi varchar(200) not null ,
    operatetype varchar(50) not null ,
    operatetypename varchar(100) not null ,
    operatedesc varchar(3000) not null ,
    params text not null ,
    belongmainid varchar(36) not null ,
    clientip varchar(50) not null ,
    groupid varchar(50) not null ,
    groupnamelabel varchar(1000) not null ,
    redoservice varchar(200) not null ,
    redocontext text not null ,
    cancelservice varchar(200) not null ,
    cancelcontext text not null ,
    totalruntime bigint NOT NULL DEFAULT 0 ,
    mainruntime bigint NOT NULL DEFAULT 0 ,
    log_result varchar(100) not null ,
    fromterminal varchar(100) not null ,
    resultdesc text not null ,
    old_content varchar(3000) not null ,
    link_type varchar(20) not null ,
    link_id bigint NOT NULL DEFAULT 0 ,
    old_link_id bigint NOT NULL DEFAULT 0  
)
;

alter table hrsa_salary_stats_report add remark varchar(100)
;

alter table hrsa_salary_stats_report add second_dimension varchar(100)
;

alter table hrsa_salary_stats_report add sort_index varchar(100)
;

alter table hrsa_salary_stats_report add sort_type varchar(100)
;

alter table hrsa_salary_stats_dim add label_id int
;