create table attachment
(
    id          varchar(255) not null
        constraint attach_file_pkey
            primary key,
    file_name   varchar(256),
    mime_type   varchar(32),
    url         varchar(1024),
    upload_time timestamp(6)
);
comment on table attachment is '附件表';
comment on column attachment.id is '主键';
comment on column attachment.file_name is '文件名 文件名详细说明';
comment on column attachment.mime_type is '附件作用类型';
comment on column attachment.url is '文件下载链接';
comment on column attachment.upload_time is '文件上传时间';
alter table attachment
    owner to postgres;

create table sys_authority
(
    id          bigint       not null
        constraint _copy_8
            primary key,
    name        varchar(255) not null,
    enabled     varchar(5),
    create_by   varchar(255),
    update_by   varchar(255),
    create_time timestamp(6),
    update_time timestamp(6),
    remark      varchar(255)
);
comment on table sys_authority is '权限表';
comment on column sys_authority.id is 'ID';
comment on column sys_authority.name is '名称';
comment on column sys_authority.enabled is '状态';
comment on column sys_authority.create_by is '创建者';
comment on column sys_authority.update_by is '更新者';
comment on column sys_authority.create_time is '创建日期';
comment on column sys_authority.update_time is '更新时间';
alter table sys_authority
    owner to postgres;
create index authority_name_index
    on sys_authority (name);
create unique index uniq_name
    on sys_authority (name);

create table sys_bulletin
(
    id              bigint  not null
        GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    title           varchar,
    state           integer not null,
    top             boolean not null,
    edit_user_id    bigint  not null,
    edit_time       TIMESTAMP,
    publish_user_id bigint,
    publish_time    TIMESTAMP,
    close_user_id   bigint,
    close_time      TIMESTAMP,
    content         varchar,
    create_by       varchar,
    create_time     TIMESTAMP,
    update_by       varchar,
    update_time     TIMESTAMP
);
comment on table sys_bulletin is '公告';
comment on column sys_bulletin.id is '主键';
comment on column sys_bulletin.title is '标题';
comment on column sys_bulletin.state is '状态';
comment on column sys_bulletin.top is '是否置顶';
comment on column sys_bulletin.edit_user_id is '编辑者id';
comment on column sys_bulletin.edit_time is '编辑时间';
comment on column sys_bulletin.publish_user_id is '审核发布者';
comment on column sys_bulletin.publish_time is '审核发布时间';
comment on column sys_bulletin.close_user_id is '关闭者id';
comment on column sys_bulletin.close_time is '关闭时间';
comment on column sys_bulletin.content is '内容';
comment on column sys_bulletin.create_by is '创建者';
comment on column sys_bulletin.create_time is '创建时间';
comment on column sys_bulletin.update_by is '更新者';
comment on column sys_bulletin.update_time is '更新时间';
alter table sys_bulletin
    owner to postgres;

create table sys_bulletin_attach
(
    bulletin_id   bigint  not null,
    attachment_id varchar not null,
    constraint sys_bulletin_attach_pk
        primary key (bulletin_id, attachment_id)
);
alter table sys_bulletin_attach
    owner to postgres;

create table sys_bulletin_user
(
    bulletin_id bigint  not null,
    user_id     bigint  not null,
    is_read     boolean not null,
    constraint sys_bulletin_user_pk
        primary key (bulletin_id, user_id)
);
comment on table sys_bulletin_user is '公告用户关联表';
comment on column sys_bulletin_user.bulletin_id is '公告id';
comment on column sys_bulletin_user.user_id is '用户id';
comment on column sys_bulletin_user.is_read is '已读未读';
alter table sys_bulletin_user
    owner to postgres;

create table sys_dept
(
    id          bigint       not null
        constraint _copy_7
            primary key,
    pid         bigint,
    sub_count   integer,
    name        varchar(255) not null,
    dept_sort   integer,
    enabled     varchar(5),
    create_by   varchar(255),
    update_by   varchar(255),
    create_time timestamp(6),
    update_time timestamp(6),
    remark      varchar(255)
);

comment on table sys_dept is '部门';
comment on column sys_dept.id is 'ID';
comment on column sys_dept.pid is '上级部门';
comment on column sys_dept.sub_count is '子部门数目';
comment on column sys_dept.name is '名称';
comment on column sys_dept.dept_sort is '排序';
comment on column sys_dept.enabled is '状态';
comment on column sys_dept.create_by is '创建者';
comment on column sys_dept.update_by is '更新者';
comment on column sys_dept.create_time is '创建日期';
comment on column sys_dept.update_time is '更新时间';
alter table sys_dept
    owner to postgres;
create index inx_enabled
    on sys_dept (enabled);
create index inx_pid
    on sys_dept (pid);

create table sys_message
(
    id          integer not null
        constraint sys_message_pk
            primary key,
    type        integer not null,
    system      boolean not null,
    email       boolean not null,
    sms         boolean not null,
    html        boolean not null,
    title       varchar,
    content     varchar,
    remark      varchar,
    create_time time,
    create_by   varchar,
    update_time time,
    update_by   varchar
);
comment on table sys_message is '消息';
comment on column sys_message.type is '消息类型';
comment on column sys_message.system is '是否系统生成';
comment on column sys_message.email is '是否需要发送邮件';
comment on column sys_message.sms is '是否需要发送短信';
comment on column sys_message.html is '消息内容是否是富文本，TRUE则义富文本形式发送';
comment on column sys_message.title is '标题';
comment on column sys_message.content is '消息内容';
comment on column sys_message.remark is '说明';
comment on column sys_message.create_time is '创建时间';
comment on column sys_message.create_by is '创建人';
comment on column sys_message.update_time is '更新时间';
comment on column sys_message.update_by is '更新人';
alter table sys_message
    owner to postgres;

create table sys_message_attach
(
    message_id    bigint  not null,
    attachment_id varchar not null,
    constraint sys_message_attach_pk
        primary key (attachment_id, message_id)
);
alter table sys_message_attach
    owner to postgres;

create table sys_message_setting
(
    id    bigint  not null
        constraint sys_message_setting_pk
            primary key,
    email boolean not null,
    sms   boolean not null
);
comment on table sys_message_setting is '消息设置';
comment on column sys_message_setting.id is '消息类型';
comment on column sys_message_setting.email is '是否发送邮件';
comment on column sys_message_setting.sms is '是否发送短信';
alter table sys_message_setting
    owner to postgres;

create table sys_role
(
    id          bigint       not null
        constraint _copy_6
            primary key,
    name        varchar(255) not null,
    create_by   varchar(255),
    update_by   varchar(255),
    create_time timestamp(6),
    update_time timestamp(6),
    enabled     varchar(5),
    remark      varchar(255)
);
comment on table sys_role is '角色表';
comment on column sys_role.id is 'ID';
comment on column sys_role.name is '名称';
comment on column sys_role.create_by is '创建者';
comment on column sys_role.update_by is '更新者';
comment on column sys_role.create_time is '创建日期';
comment on column sys_role.update_time is '更新时间';
comment on column sys_role.enabled is '状态';
alter table sys_role
    owner to postgres;
create index role_name_index
    on sys_role (name);
create unique index uniq_name_copy_1
    on sys_role (name);

create table sys_role_authorities
(
    role_id      bigint not null,
    authority_id bigint not null,
    constraint _copy_5
        primary key (role_id, authority_id)
);
alter table sys_role_authorities
    owner to postgres;
create index "FKbyfnfkpgrf4jmo3nf97arsphd"
    on sys_role_authorities (role_id);

create table sys_roles_depts
(
    role_id bigint not null,
    dept_id bigint not null,
    constraint _copy_4
        primary key (role_id, dept_id)
);
comment on table sys_roles_depts is '角色部门关联';
alter table sys_roles_depts
    owner to postgres;
create index "FK7qg6itn5ajdoa9h9o78v9ksur"
    on sys_roles_depts (dept_id);

create table sys_user
(
    id             bigint       not null
        constraint _copy_3
            primary key,
    dept_id        bigint,
    role_id        bigint,
    username       varchar(20)  not null,
    password       varchar(255) not null,
    phone          varchar(11),
    email          varchar(40),
    name           varchar(255),
    avatar         varchar(255),
    address        varchar(255),
    create_by      varchar(255),
    update_by      varchar(255),
    create_time    timestamp(6),
    update_time    timestamp(6),
    remark         varchar(255),
    enabled_status varchar(5)
);
comment on column sys_user.id is '主键';
comment on column sys_user.dept_id is '部门id';
comment on column sys_user.role_id is '角色id';
comment on column sys_user.username is '用户名';
comment on column sys_user.password is '密码';
comment on column sys_user.phone is '手机号码';
comment on column sys_user.email is '电子邮箱';
comment on column sys_user.name is '昵称';
comment on column sys_user.avatar is '头像';
comment on column sys_user.address is '地址';
comment on column sys_user.create_by is '创建者';
comment on column sys_user.update_by is '更新者';
comment on column sys_user.enabled_status is '状态';
alter table sys_user
    owner to postgres;

create table sys_user_message
(
    id        bigint      not null
        constraint sys_user_message_pk
            primary key,
    "user"    sys_user    not null,
    message   sys_message not null,
    read      boolean     not null,
    read_time time
);
comment on table sys_user_message is '用户消息';
comment on column sys_user_message.id is '主键';
comment on column sys_user_message."user" is '用户';
comment on column sys_user_message.message is '消息';
comment on column sys_user_message.read is '是否已读';
comment on column sys_user_message.read_time is '阅读时间';
alter table sys_user_message
    owner to postgres;

create table sys_users_roles
(
    user_id bigint not null,
    role_id bigint not null,
    constraint _copy_2
        primary key (user_id, role_id)
);
comment on table sys_users_roles is '用户角色关联';
comment on column sys_users_roles.user_id is '用户ID';
comment on column sys_users_roles.role_id is '角色ID';
alter table sys_users_roles
    owner to postgres;
create index "FKq4eq273l04bpu4efj0jd0jb98"
    on sys_users_roles (role_id);

INSERT INTO "sys_dept" VALUES (210, NULL, 0, '管理部门', 999, b'1', NULL, NULL, '2024-01-15 05:59:55', '2024-01-23 08:47:48', '管理部门');
INSERT INTO "sys_dept" VALUES (215, NULL, 0, '华南地区', 999, b'1', NULL, NULL, '2024-01-24 02:21:08', '2024-02-05 03:53:00', '华南地区');
INSERT INTO "sys_dept" VALUES (216, NULL, 0, '华北地区', 999, b'1', NULL, NULL, '2024-01-24 02:23:49', NULL, '华北地区');
INSERT INTO "sys_dept" VALUES (217, NULL, 0, '东北地区', 999, b'1', NULL, NULL, '2024-01-24 02:24:06', NULL, '东北地区');
INSERT INTO "sys_dept" VALUES (218, NULL, 0, '华东地区', 999, b'1', NULL, NULL, '2024-01-24 02:24:28', '2024-02-05 03:53:04', '华东地区');
INSERT INTO "sys_dept" VALUES (219, NULL, 0, '华中地区', 999, b'1', NULL, NULL, '2024-01-24 02:24:49', NULL, '华中地区');
INSERT INTO "sys_dept" VALUES (220, NULL, 0, '西南地区', 999, b'1', NULL, NULL, '2024-01-24 02:25:06', NULL, '西南地区');
INSERT INTO "sys_dept" VALUES (221, NULL, 0, '西北地区', 999, b'1', NULL, NULL, '2024-01-24 02:26:28', NULL, '西北地区');
INSERT INTO "sys_dept" VALUES (222, NULL, 0, '港澳台地区', 999, b'1', NULL, NULL, '2024-01-24 02:26:55', '2024-01-25 11:29:52', '港澳台地区');
INSERT INTO "sys_dept" VALUES (235, NULL, 0, '用户部门', 999, b'1', NULL, NULL, '2024-03-22 00:07:32', NULL, '普通用户');

INSERT INTO "sys_role" VALUES (50, 'admin', NULL, NULL, '2024-01-15 05:59:55', '2024-01-30 08:16:43', b'1', 'admin');
INSERT INTO "sys_role" VALUES (51, 'user', NULL, NULL, '2024-01-16 09:22:30', '2024-02-21 07:06:10', b'1', '客户');
INSERT INTO "sys_role" VALUES (54, 'auditor', NULL, NULL,'2024-01-19 16:15:45', '2024-01-24 14:48:55', b'1', '审核员');

INSERT INTO "sys_authority" VALUES (1,'DEPT_QUERY',true,NULL,NULL,NULL,NULL,'部门管理查');
INSERT INTO "sys_authority" VALUES (2,'DEPT_CREATE',true,NULL,NULL,NULL,NULL,'部门管理增');
INSERT INTO "sys_authority" VALUES (3,'DEPT_UPDATE',true,NULL,NULL,NULL,NULL,'部门管理改');
INSERT INTO "sys_authority" VALUES (4,'DEPT_DELETE',true,NULL,NULL,NULL,NULL,'部门管理删');
INSERT INTO "sys_authority" VALUES (5,'ROLE_CREATE',true,NULL,NULL,NULL,NULL,'角色管理增');
INSERT INTO "sys_authority" VALUES (6,'ROLE_QUERY',true,NULL,NULL,NULL,NULL,'角色管理查');
INSERT INTO "sys_authority" VALUES (7,'ROLE_UPDATE',true,NULL,NULL,NULL,NULL,'角色管理改');
INSERT INTO "sys_authority" VALUES (8,'USER_QUERY',true,NULL,NULL,NULL,NULL,'用户管理查');
INSERT INTO "sys_authority" VALUES (9,'USER_CREATE',true,NULL,NULL,NULL,NULL,'用户管理增');
INSERT INTO "sys_authority" VALUES (10,'USER_UPDATE',true,NULL,NULL,NULL,NULL,'用户管理改');
INSERT INTO "sys_authority" VALUES (11,'USER_DELETE',true,NULL,NULL,NULL,NULL,'用户管理删');
INSERT INTO "sys_authority" VALUES (12,'BILL_QUERY',true,NULL,NULL,NULL,NULL,'票据管理查');
INSERT INTO "sys_authority" VALUES (13,'BILL_CREATE',true,NULL,NULL,NULL,NULL,'票据管理增');
INSERT INTO "sys_authority" VALUES (14,'BILL_UPDATE',true,NULL,NULL,NULL,NULL,'票据管理改');
INSERT INTO "sys_authority" VALUES (15,'BILL_AUDIT',true,NULL,NULL,NULL,NULL,'票据审核');
INSERT INTO "sys_authority" VALUES (16,'BILL_CHOOSE_AUDITOR',true,NULL,NULL,NULL,NULL,'');
INSERT INTO "sys_authority" VALUES (17,'BILL_DELETE',true,NULL,NULL,NULL,NULL,'票据管理删');
INSERT INTO "sys_authority" VALUES (18,'AUTHORITY_QUERY',true,NULL,NULL,NULL,NULL,'权限管理查');
INSERT INTO "sys_authority" VALUES (19,'AUTHORITY_CREATE',true,NULL,NULL,NULL,NULL,'权限管理增');
INSERT INTO "sys_authority" VALUES (20,'AUTHORITY_UPDATE',true,NULL,NULL,NULL,NULL,'权限管理改');
INSERT INTO "sys_authority" VALUES (21,'AUTHORITY_DELETE',true,NULL,NULL,NULL,NULL,'权限管理删');
INSERT INTO "sys_authority" VALUES (22,'AUTHORITY_TOGGLE',true,NULL,NULL,NULL,NULL,'权限启用');
INSERT INTO "sys_authority" VALUES (23,'ROLE_AUTHED',true,NULL,NULL,NULL,NULL,'角色权限增');

INSERT INTO "sys_role_authorities" VALUES (50,5);
INSERT INTO "sys_role_authorities" VALUES (50,1);
INSERT INTO "sys_role_authorities" VALUES (50,4);
INSERT INTO "sys_role_authorities" VALUES (50,6);
INSERT INTO "sys_role_authorities" VALUES (50,7);
INSERT INTO "sys_role_authorities" VALUES (50,10);
INSERT INTO "sys_role_authorities" VALUES (50,8);
INSERT INTO "sys_role_authorities" VALUES (50,9);
INSERT INTO "sys_role_authorities" VALUES (50,3);
INSERT INTO "sys_role_authorities" VALUES (50,11);
INSERT INTO "sys_role_authorities" VALUES (50,2);
INSERT INTO "sys_role_authorities" VALUES (50,13);
INSERT INTO "sys_role_authorities" VALUES (50,12);
INSERT INTO "sys_role_authorities" VALUES (51,6);
INSERT INTO "sys_role_authorities" VALUES (51,13);
INSERT INTO "sys_role_authorities" VALUES (51,9);
INSERT INTO "sys_role_authorities" VALUES (51,2);
INSERT INTO "sys_role_authorities" VALUES (51,12);
INSERT INTO "sys_role_authorities" VALUES (54,12);
INSERT INTO "sys_role_authorities" VALUES (54,15);
INSERT INTO "sys_role_authorities" VALUES (51,14);
INSERT INTO "sys_role_authorities" VALUES (51,17);
INSERT INTO "sys_role_authorities" VALUES (50,22);
INSERT INTO "sys_role_authorities" VALUES (50,18);
INSERT INTO "sys_role_authorities" VALUES (50,19);
INSERT INTO "sys_role_authorities" VALUES (50,20);
INSERT INTO "sys_role_authorities" VALUES (50,21);
INSERT INTO "sys_role_authorities" VALUES (50,23);

INSERT INTO "sys_user" VALUES (1, 210, 50, 'admin', '{bcrypt}$2a$10$lwEbMpGYMIcVpuVXIWBSlOO7d085buqONGjTuY4tg3rz84y/xFQXe', '19897785991', 'zsc3456@qq.com', '林艳燕',  '35bd7d32843a413f3cd2486114318d6ccd5f9d62', '青海省太原市南区阳光小区',NULL, NULL, '2024-01-11 09:57:48', '2024-01-11 18:31:29', NULL, b'1');
INSERT INTO "sys_user" VALUES (2, 215, 51, 'user', '{bcrypt}$2a$10$lwEbMpGYMIcVpuVXIWBSlOO7d085buqONGjTuY4tg3rz84y/xFQXe', '12324352313', 'zsc3456@qq.com', '帐篷',  '35bd7d32843a413f3cd2486114318d6ccd5f9d62', '电子科技大学四川',NULL, NULL, '2024-01-11 09:57:48', '2024-01-11 18:31:29', NULL, b'1');
INSERT INTO "sys_user" VALUES (3, 218, 54, 'auditor', '{bcrypt}$2a$10$lwEbMpGYMIcVpuVXIWBSlOO7d085buqONGjTuY4tg3rz84y/xFQXe', '12345678901', 'zsc3456@qq.com', '王超',  '35bd7d32843a413f3cd2486114318d6ccd5f9d62', '电子科技大学中山',NULL, NULL, '2024-01-11 09:57:48', '2024-01-11 18:31:29', NULL, b'1');

INSERT INTO "attachment" VALUES ('195bd3517bfcd9915906957730bdd6fef7fa5a86', 'Snipaste_2024-02-08_09-26-22.jpg', 'image/jpeg','2024-03-21 15:20:03');
INSERT INTO "attachment" VALUES ('1f744e54c23c388d890a6a3822a87eae32617f29', '6.25-07.jpg', 'image/jpeg','2024-03-07 07:59:34');
INSERT INTO "attachment" VALUES ('35bd7d32843a413f3cd2486114318d6ccd5f9d62', 'Snipaste_2024-03-22_08-11-52.jpg', 'image/jpeg','2024-03-22 00:12:05');
INSERT INTO "attachment" VALUES ('5440f9aa9266589413f015fa673f2f372a86c74e', '各组织活动申报表模板.png', 'image/png','2024-02-11 17:37:44');
INSERT INTO "attachment" VALUES ('5ad6601fd1cf58aa66b25b4f12a83d63b61a681e', '申请表1：模板计算机学院素质拓展活动申请表.doc', 'application/msword','2024-02-05 14:37:10');
INSERT INTO "attachment" VALUES ('6853fd7cf5b0621678377227d299d86d6f90cc97', 'logo02.png', 'image/png','2024-03-07 07:59:11');
INSERT INTO "attachment" VALUES ('84fa4f586f190886ea8708c49e8645f5a9a1ea04', '屏幕截图(1).png', 'image/png','2024-03-21 16:12:46');

INSERT INTO "sys_bulletin" VALUES (1,'测试测试测试测试测试测试测试',1,true,50,'2024-03-21 15:20:03',51,'2024-03-21 15:20:03',54,'2024-03-21 15:20:03','测试测试测试数据',null,null,null,null);

INSERT INTO "sys_bulletin_attach" VALUES (1,'195bd3517bfcd9915906957730bdd6fef7fa5a86')