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 SERIAL 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 timestamp,
    create_by   varchar,
    update_time timestamp,
    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         bigserial NOT NULL
        CONSTRAINT sys_user_message_pk
            PRIMARY KEY,
    user_id    bigint    NOT NULL,
    message_id bigint    NOT NULL,
    is_read    boolean   NOT NULL,
    read_time  timestamp
);

COMMENT ON TABLE sys_user_message IS '用户消息';
COMMENT ON COLUMN sys_user_message.id IS '主键';
COMMENT ON COLUMN sys_user_message.user_id IS '用户';
COMMENT ON COLUMN sys_user_message.message_id IS '消息';
COMMENT ON COLUMN sys_user_message.is_read IS '是否已读';
COMMENT ON COLUMN sys_user_message.read_time IS '阅读时间';

ALTER TABLE sys_user_message
    OWNER TO postgres;

-- 确保序列从1开始
SELECT setval('sys_user_message_id_seq', 1, false);



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

INSERT INTO sys_message (id, type, system, email, sms, html, title, content, remark, create_time, create_by,
                         update_time, update_by)
VALUES (1, 1, TRUE, FALSE, TRUE, FALSE, '系统通知', '系统维护通知', '例行维护', NOW(), 'admin', NOW(), 'admin'),
       (2, 1, FALSE, TRUE, FALSE, TRUE, '用户注册', '欢迎注册我们的平台', '感谢您的注册', NOW() - INTERVAL '1 day',
        'user1', NOW() - INTERVAL '1 day', 'user1'),
       (3, 1, TRUE, TRUE, FALSE, FALSE, '密码重置', '您的密码已重置', '请尽快登录并修改密码', NOW() - INTERVAL '2 days',
        'admin', NOW() - INTERVAL '2 days', 'admin'),
       (4, 1, FALSE, FALSE, TRUE, TRUE, '订单确认', '您的订单已确认', '订单号：123456789', NOW() - INTERVAL '3 days',
        'user2', NOW() - INTERVAL '3 days', 'user2'),
       (5, 1, TRUE, FALSE, TRUE, FALSE, '系统更新', '系统已更新到最新版本', '新功能介绍', NOW() - INTERVAL '4 days',
        'admin', NOW() - INTERVAL '4 days', 'admin'),
       (6, 1, FALSE, TRUE, FALSE, TRUE, '活动邀请', '您被邀请参加我们的活动', '活动详情见附件',
        NOW() - INTERVAL '5 days', 'user3', NOW() - INTERVAL '5 days', 'user3'),
       (7, 1, TRUE, TRUE, FALSE, FALSE, '账户激活', '您的账户已激活', '您可以开始使用了', NOW() - INTERVAL '6 days',
        'admin', NOW() - INTERVAL '6 days', 'admin'),
       (8, 1, FALSE, FALSE, TRUE, TRUE, '支付成功', '您的支付已成功', '感谢您的支持', NOW() - INTERVAL '7 days',
        'user4', NOW() - INTERVAL '7 days', 'user4'),
       (9, 1, TRUE, FALSE, TRUE, FALSE, '安全提醒', '请检查您的账户安全设置', '安全提示', NOW() - INTERVAL '8 days',
        'admin', NOW() - INTERVAL '8 days', 'admin'),
       (10, 1, FALSE, TRUE, FALSE, TRUE, '反馈回复', '感谢您的反馈', '我们会尽快处理', NOW() - INTERVAL '9 days',
        'user5', NOW() - INTERVAL '9 days', 'user5');


INSERT INTO sys_message_setting (id, email, sms)
VALUES (1, TRUE, FALSE),
       (2, FALSE, TRUE),
       (3, TRUE, TRUE),
       (4, FALSE, FALSE),
       (5, TRUE, FALSE),
       (6, FALSE, TRUE),
       (7, TRUE, TRUE),
       (8, FALSE, FALSE),
       (9, TRUE, FALSE),
       (10, FALSE, TRUE);

INSERT INTO attachment (id, file_name, mime_type, url, upload_time)
VALUES ('1', 'document1.pdf', 'application/pdf', 'http://example.com/files/document1.pdf', CURRENT_TIMESTAMP),
       ('2', 'image1.jpg', 'image/jpeg', 'http://example.com/files/image1.jpg', CURRENT_TIMESTAMP - INTERVAL '1 day'),
       ('3', 'presentation.pptx', 'application/pptx', 'http://example.com/files/presentation.pptx',
        CURRENT_TIMESTAMP - INTERVAL '2 days'),
       ('4', 'spreadsheet.xlsx', 'application/xlsx', 'http://example.com/files/spreadsheet.xlsx',
        CURRENT_TIMESTAMP - INTERVAL '3 days'),
       ('5', 'audio.mp3', 'audio/mpeg', 'http://example.com/files/audio.mp3', CURRENT_TIMESTAMP - INTERVAL '4 days');

INSERT INTO iot_device (name, online, state, hardware_version, firmware_version, factory_id, client_id, product_id,
                        extend_params, properties, create_by, create_time, update_by, update_time, remark, dept_id)
VALUES ('Device001', TRUE, 1, 'HW001', 'FW001', 'FAC001', 'CLI001', 101, '[
  {
    "param1"
    "value1"
  }
]', '[
  "prop1",
  "value1"
]', 'admin', CURRENT_TIMESTAMP, 'admin', CURRENT_TIMESTAMP, 'Remark for Device001', 1),
       ('Device002', FALSE, 0, 'HW002', 'FW002', 'FAC002', 'CLI002', 102, '[
         "param2",
         "value2"
       ]', '[
         "prop2",
         "value2"
       ]', 'admin', CURRENT_TIMESTAMP, 'admin', CURRENT_TIMESTAMP, 'Remark for Device002', 2),
       ('Device003', TRUE, 1, 'HW003', 'FW003', 'FAC003', 'CLI003', 103, '[
         "param3",
         "value3"
       ]', '[
         "prop3",
         "value3"
       ]', 'admin', CURRENT_TIMESTAMP, 'admin', CURRENT_TIMESTAMP, 'Remark for Device003', 3),
       ('Device004', FALSE, 0, 'HW004', 'FW004', 'FAC004', 'CLI004', 104, '[
         "param4",
         "value4"
       ]', '[
         "prop4",
         "value4"
       ]', 'admin', CURRENT_TIMESTAMP, 'admin', CURRENT_TIMESTAMP, 'Remark for Device004', 4),
       ('Device005', TRUE, 1, 'HW005', 'FW005', 'FAC005', 'CLI005', 105, '[
         "param5",
         "value5"
       ]', '[
         "prop5",
         "value5"
       ]', 'admin', CURRENT_TIMESTAMP, 'admin', CURRENT_TIMESTAMP, 'Remark for Device005', 5),
       ('Device006', FALSE, 0, 'HW006', 'FW006', 'FAC006', 'CLI006', 106, '[
         "param6",
         "value6"
       ]', '[
         "prop6",
         "value6"
       ]', 'admin', CURRENT_TIMESTAMP, 'admin', CURRENT_TIMESTAMP, 'Remark for Device006', 6),
       ('Device007', TRUE, 1, 'HW007', 'FW007', 'FAC007', 'CLI007', 107, '[
         "param7",
         "value7"
       ]', '[
         "prop7",
         "value7"
       ]', 'admin', CURRENT_TIMESTAMP, 'admin', CURRENT_TIMESTAMP, 'Remark for Device007', 7),
       ('Device008', FALSE, 0, 'HW008', 'FW008', 'FAC008', 'CLI008', 108, '[
         "param8",
         "value8"
       ]', '[
         "prop8",
         "value8"
       ]', 'admin', CURRENT_TIMESTAMP, 'admin', CURRENT_TIMESTAMP, 'Remark for Device008', 8),
       ('Device009', TRUE, 1, 'HW009', 'FW009', 'FAC009', 'CLI009', 109, '[
         "param9",
         "value9"
       ]', '[
         "prop9",
         "value9"
       ]', 'admin', CURRENT_TIMESTAMP, 'admin', CURRENT_TIMESTAMP, 'Remark for Device009', 9),
       ('Device010', FALSE, 0, 'HW010', 'FW010', 'FAC010', 'CLI010', 110, '[
         "param10",
         "value10"
       ]', '[
         "prop10",
         "value10"
       ]', 'admin', CURRENT_TIMESTAMP, 'admin', CURRENT_TIMESTAMP, 'Remark for Device010', 10);

INSERT INTO sys_user_notice (user_id, notice_id, is_read, read_time)
VALUES (1, 101, TRUE, CURRENT_TIMESTAMP - INTERVAL '1 day'),
       (2, 102, FALSE, NULL),
       (3, 103, TRUE, CURRENT_TIMESTAMP - INTERVAL '2 days'),
       (4, 104, TRUE, CURRENT_TIMESTAMP - INTERVAL '3 days'),
       (5, 105, FALSE, NULL),
       (6, 106, TRUE, CURRENT_TIMESTAMP - INTERVAL '4 days'),
       (7, 107, TRUE, CURRENT_TIMESTAMP - INTERVAL '5 days'),
       (8, 108, FALSE, NULL),
       (9, 109, TRUE, CURRENT_TIMESTAMP - INTERVAL '6 days'),
       (10, 110, FALSE, NULL);



INSERT INTO iot_product (name, product_type, model, link, create_by, create_time, update_by, update_time, remark,
                         dept_id)
VALUES ('Product1', 'TypeA', 'ModelX', 1, 'Admin', CURRENT_TIMESTAMP, 'Admin', CURRENT_TIMESTAMP, 'Remark1', 101),
       ('Product2', 'TypeB', 'ModelY', 2, 'Admin', CURRENT_TIMESTAMP, 'Admin', CURRENT_TIMESTAMP, 'Remark2', 102),
       ('Product3', 'TypeA', 'ModelZ', 1, 'Admin', CURRENT_TIMESTAMP, 'Admin', CURRENT_TIMESTAMP, 'Remark3', 103),
       ('Product4', 'TypeC', 'ModelW', 3, 'Admin', CURRENT_TIMESTAMP, 'Admin', CURRENT_TIMESTAMP, 'Remark4', 104),
       ('Product5', 'TypeB', 'ModelV', 2, 'Admin', CURRENT_TIMESTAMP, 'Admin', CURRENT_TIMESTAMP, 'Remark5', 105),
       ('Product6', 'TypeD', 'ModelU', 4, 'Admin', CURRENT_TIMESTAMP, 'Admin', CURRENT_TIMESTAMP, 'Remark6', 106),
       ('Product7', 'TypeA', 'ModelT', 1, 'Admin', CURRENT_TIMESTAMP, 'Admin', CURRENT_TIMESTAMP, 'Remark7', 107),
       ('Product8', 'TypeC', 'ModelS', 3, 'Admin', CURRENT_TIMESTAMP, 'Admin', CURRENT_TIMESTAMP, 'Remark8', 108),
       ('Product9', 'TypeB', 'ModelR', 2, 'Admin', CURRENT_TIMESTAMP, 'Admin', CURRENT_TIMESTAMP, 'Remark9', 109),
       ('Product10', 'TypeD', 'ModelQ', 4, 'Admin', CURRENT_TIMESTAMP, 'Admin', CURRENT_TIMESTAMP, 'Remark10', 110);

INSERT INTO iot_param (id, data_type, uint, type, identifier, name, remark)
VALUES (1, 1, 'm', 1, 'identifier1', 'Parameter1', 'Remark1'),
       (2, 2, 'kg', 2, 'identifier2', 'Parameter2', 'Remark2'),
       (3, 1, 's', 1, 'identifier3', 'Parameter3', 'Remark3'),
       (4, 3, 'A', 2, 'identifier4', 'Parameter4', 'Remark4'),
       (5, 2, 'V', 1, 'identifier5', 'Parameter5', 'Remark5'),
       (6, 1, '°C', 2, 'identifier6', 'Parameter6', 'Remark6'),
       (7, 3, 'Hz', 1, 'identifier7', 'Parameter7', 'Remark7'),
       (8, 2, 'Pa', 2, 'identifier8', 'Parameter8', 'Remark8'),
       (9, 1, 'J', 1, 'identifier9', 'Parameter9', 'Remark9'),
       (10, 3, 'W', 2, 'identifier10', 'Parameter10', 'Remark10');

INSERT INTO iot_event (product_id, type, identifier, name, remark)
VALUES (1, 1, 'event1', '事件1', '这是事件1的备注'),
       (2, 2, 'event2', '事件2', '这是事件2的备注'),
       (3, 1, 'event3', '事件3', '这是事件3的备注'),
       (4, 3, 'event4', '事件4', '这是事件4的备注'),
       (5, 2, 'event5', '事件5', '这是事件5的备注'),
       (6, 1, 'event6', '事件6', '这是事件6的备注'),
       (7, 3, 'event7', '事件7', '这是事件7的备注'),
       (8, 2, 'event8', '事件8', '这是事件8的备注'),
       (9, 1, 'event9', '事件9', '这是事件9的备注'),
       (10, 3, 'event10', '事件10', '这是事件10的备注');

INSERT INTO iot_property (product_id, data_type, io_type, identifier, name, remark)
VALUES (1, 1, 1, 'prop1', 'Property 1', 'This is property 1'),
       (2, 2, 2, 'prop2', 'Property 2', 'This is property 2'),
       (3, 1, 2, 'prop3', 'Property 3', 'This is property 3'),
       (4, 2, 1, 'prop4', 'Property 4', 'This is property 4'),
       (5, 1, 1, 'prop5', 'Property 5', 'This is property 5'),
       (6, 2, 2, 'prop6', 'Property 6', 'This is property 6'),
       (7, 1, 2, 'prop7', 'Property 7', 'This is property 7'),
       (8, 2, 1, 'prop8', 'Property 8', 'This is property 8'),
       (9, 1, 1, 'prop9', 'Property 9', 'This is property 9'),
       (10, 2, 2, 'prop10', 'Property 10', 'This is property 10');

INSERT INTO iot_serve (product_id, identifier, name, remark)
VALUES (1, 'serve1', 'Service 1', 'This is service 1'),
       (2, 'serve2', 'Service 2', 'This is service 2'),
       (3, 'serve3', 'Service 3', 'This is service 3'),
       (4, 'serve4', 'Service 4', 'This is service 4'),
       (5, 'serve5', 'Service 5', 'This is service 5'),
       (6, 'serve6', 'Service 6', 'This is service 6'),
       (7, 'serve7', 'Service 7', 'This is service 7'),
       (8, 'serve8', 'Service 8', 'This is service 8'),
       (9, 'serve9', 'Service 9', 'This is service 9'),
       (10, 'serve10', 'Service 10', 'This is service 10');

alter table iot_device
    add dept_id bigint;

comment on column iot_device.dept_id is '部门权限id';

alter table iot_param
    add dept_id bigint;

comment on column iot_param.dept_id is '部门权限id';

alter table iot_serve
    add dept_id bigint;

comment on column iot_serve.dept_id is '部门权限id';

alter table iot_event
    add dept_id bigint;

comment on column iot_event.dept_id is '部门权限id';

alter table iot_event
    add dept_id bigint;

comment on column iot_event.dept_id is '部门权限id';

alter table sys_bulletin
    add dept_id bigint;

comment on column sys_bulletin.dept_id is '部门权限id';

alter table sys_bulletin
    add dept_id bigint;

comment on column sys_bulletin.dept_id is '部门权限id';

alter table sys_message
    add dept_id bigint;

comment on column sys_message.dept_id is '部门权限id';

alter table sys_authority
    add dept_id bigint;

comment on column sys_authority.dept_id is '部门权限id';

alter table sys_role
    add dept_id bigint;

comment on column sys_role.dept_id is '部门权限id';

INSERT INTO sys_dept (pid, sub_count, name, dept_sort, enabled, create_by, update_by, create_time, update_time, remark)
VALUES (2, 1, '研发部', 1, TRUE, 'admin', 'admin', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, '负责产品研发'),
       (3, 2, '前端组', 2, TRUE, 'admin', 'admin', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, '负责前端开发'),
       (4, 2, '后端组', 3, TRUE, 'admin', 'admin', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, '负责后端开发'),
       (5, 1, '市场部', 4, TRUE, 'admin', 'admin', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, '负责市场推广'),
       (6, 1, '销售组', 5, TRUE, 'admin', 'admin', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, '负责销售'),
       (7, 1, '市场调研组', 6, TRUE, 'admin', 'admin', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, '负责市场调研'),
       (8, 1, '人力资源部', 7, TRUE, 'admin', 'admin', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, '负责人力资源管理'),
       (9, 1, '招聘组', 8, TRUE, 'admin', 'admin', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, '负责招聘'),
       (10, 1, '培训组', 9, TRUE, 'admin', 'admin', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, '负责员工培训'),
       (11, 1, '财务部', 10, TRUE, 'admin', 'admin', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, '负责财务管理');

INSERT INTO sys_message (type, system, email, sms, html, title, content, remark, create_time, create_by, update_time,
                         update_by, dept_id)
VALUES (1, TRUE, TRUE, FALSE, TRUE, '测试消息1', '这是第一条测试消息的内容。', '备注1', NOW(), 'system', NOW(), 'system',
        1),
       (2, FALSE, FALSE, TRUE, FALSE, '测试消息2', '这是第二条测试消息的内容。', '备注2', NOW(), 'user1', NOW(), 'user1',
        2),
       (1, TRUE, TRUE, TRUE, TRUE, '测试消息3', '这是第三条测试消息的内容。', '备注3', NOW(), 'system', NOW(), 'system',
        3),
       (2, FALSE, FALSE, FALSE, FALSE, '测试消息4', '这是第四条测试消息的内容。', '备注4', NOW(), 'user2', NOW(),
        'user2', 4),
       (1, TRUE, TRUE, TRUE, FALSE, '测试消息5', '这是第五条测试消息的内容。', '备注5', NOW(), 'system', NOW(), 'system',
        5),
       (2, FALSE, FALSE, TRUE, TRUE, '测试消息6', '这是第六条测试消息的内容。', '备注6', NOW(), 'user3', NOW(), 'user3',
        6),
       (1, TRUE, TRUE, FALSE, FALSE, '测试消息7', '这是第七条测试消息的内容。', '备注7', NOW(), 'system', NOW(),
        'system', 7),
       (2, FALSE, FALSE, TRUE, TRUE, '测试消息8', '这是第八条测试消息的内容。', '备注8', NOW(), 'user4', NOW(), 'user4',
        8),
       (1, TRUE, TRUE, TRUE, FALSE, '测试消息9', '这是第九条测试消息的内容。', '备注9', NOW(), 'system', NOW(), 'system',
        9),
       (2, FALSE, FALSE, FALSE, TRUE, '测试消息10', '这是第十条测试消息的内容。', '备注10', NOW(), 'user5', NOW(),
        'user5', 10);
-- V2__Alter_sys_user_id_to_bigserial.sql

-- 备份现有数据
CREATE TABLE sys_user_backup AS
SELECT *
FROM sys_user;
-- 删除现有表
DROP TABLE IF EXISTS sys_user;

-- 重新创建表
CREATE TABLE sys_user
(
    id           bigserial   not null
        constraint _copy_3
            primary key,
    dept_id      bigint,
    role_id      bigint,
    username     varchar(20) not null,
    password     varchar     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),
    enable_state varchar(5)
);

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.enable_state is '状态';

alter table sys_user
    owner to gitea;

