CREATE TABLE IF NOT EXISTS "system_dept" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "name" varchar(30) NOT NULL DEFAULT '',
    "parent_id" bigint NOT NULL DEFAULT '0',
    "sort" int NOT NULL DEFAULT '0',
    "leader" varchar(30) DEFAULT NULL,
    "phone" varchar(11) DEFAULT NULL,
    "email" varchar(50) DEFAULT NULL,
    "status" tinyint NOT NULL,
    "creator" varchar(64) DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar(64) DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    "organ_id" bigint not null default  '0',
    PRIMARY KEY ("id")
) COMMENT '部门表';

CREATE TABLE IF NOT EXISTS "system_dict_data" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "sort" int NOT NULL DEFAULT '0',
    "label" varchar(100) NOT NULL DEFAULT '',
    "value" varchar(100) NOT NULL DEFAULT '',
    "dict_type" varchar(100) NOT NULL DEFAULT '',
    "status" tinyint NOT NULL DEFAULT '0',
    "color_type" varchar(100) NOT NULL DEFAULT '',
    "css_class" varchar(100) NOT NULL DEFAULT '',
    "remark" varchar(500) DEFAULT NULL,
    "creator" varchar(64) DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar(64) DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    PRIMARY KEY ("id")
) COMMENT '字典数据表';

CREATE TABLE IF NOT EXISTS "system_role" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "name" varchar(30) NOT NULL,
    "code" varchar(100) NOT NULL,
    "sort" int NOT NULL,
    "data_scope" tinyint NOT NULL DEFAULT '1',
    "data_scope_dept_ids" varchar(500) NOT NULL DEFAULT '',
    "status" tinyint NOT NULL,
    "type" tinyint NOT NULL,
    "remark" varchar(500) DEFAULT NULL,
    "creator" varchar(64) DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar(64) DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    "tenant_id" bigint not null default  '0',
    PRIMARY KEY ("id")
) COMMENT '角色信息表';

CREATE TABLE IF NOT EXISTS "system_role_menu" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "role_id" bigint NOT NULL,
    "menu_id" bigint NOT NULL,
    "creator" varchar(64) DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar(64) DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    "tenant_id" bigint not null default  '0',
    PRIMARY KEY ("id")
) COMMENT '角色和菜单关联表';

CREATE TABLE IF NOT EXISTS "system_menu" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "name" varchar(50) NOT NULL,
    "permission" varchar(100) NOT NULL DEFAULT '',
    "type" tinyint NOT NULL,
    "sort" int NOT NULL DEFAULT '0',
    "parent_id" bigint NOT NULL DEFAULT '0',
    "path" varchar(200) DEFAULT '',
    "icon" varchar(100) DEFAULT '#',
    "component" varchar(255) DEFAULT NULL,
    "component_name" varchar(255) DEFAULT NULL,
    "status" tinyint NOT NULL DEFAULT '0',
    "visible" bit NOT NULL DEFAULT TRUE,
    "keep_alive" bit NOT NULL DEFAULT TRUE,
    "always_show" bit NOT NULL DEFAULT TRUE,
    "creator" varchar(64) DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar(64) DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    PRIMARY KEY ("id")
) COMMENT '菜单权限表';

CREATE TABLE IF NOT EXISTS "system_user_role" (
     "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
     "user_id" bigint NOT NULL,
     "role_id" bigint NOT NULL,
     "creator" varchar(64) DEFAULT '',
     "create_time" timestamp DEFAULT NULL,
     "updater" varchar(64) DEFAULT '',
     "update_time" timestamp DEFAULT NULL,
     "deleted" bit DEFAULT FALSE,
    "tenant_id" bigint not null default  '0',
    PRIMARY KEY ("id")
) COMMENT '用户和角色关联表';

CREATE TABLE IF NOT EXISTS "system_dict_type" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "name" varchar(100) NOT NULL DEFAULT '',
    "type" varchar(100) NOT NULL DEFAULT '',
    "status" tinyint NOT NULL DEFAULT '0',
    "remark" varchar(500) DEFAULT NULL,
    "creator" varchar(64) DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar(64) DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    "deleted_time" timestamp NOT NULL,
    PRIMARY KEY ("id")
) COMMENT '字典类型表';

CREATE TABLE IF NOT EXISTS `system_user_session` (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    `token` varchar(32) NOT NULL,
    `user_id` bigint DEFAULT NULL,
    "user_type" tinyint NOT NULL,
    `username` varchar(50) NOT NULL DEFAULT '',
    `user_ip` varchar(50) DEFAULT NULL,
    `user_agent` varchar(512) DEFAULT NULL,
    `session_timeout` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "creator" varchar(64) DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updater` varchar(64) DEFAULT '' ,
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    "tenant_id" bigint not null default  '0',
    PRIMARY KEY (`id`)
) COMMENT '用户在线 Session';

CREATE TABLE IF NOT EXISTS "system_post" (
    "id"          bigint      NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "code"        varchar(64) NOT NULL,
    "name"        varchar(50) NOT NULL,
    "sort"        integer     NOT NULL,
    "status"      tinyint     NOT NULL,
    "remark"      varchar(500)         DEFAULT NULL,
    "creator"     varchar(64)          DEFAULT '',
    "create_time" timestamp   NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"     varchar(64)          DEFAULT '',
    "update_time" timestamp   NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted"     bit         NOT NULL DEFAULT FALSE,
    "tenant_id" bigint not null default  '0',
    PRIMARY KEY ("id")
) COMMENT '岗位信息表';

CREATE TABLE IF NOT EXISTS `system_user_post`(
    "id"          bigint    NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "user_id"     bigint             DEFAULT NULL,
    "post_id"     bigint             DEFAULT NULL,
    "creator"     varchar(64)        DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"     varchar(64)        DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted"     bit       NOT NULL DEFAULT FALSE,
    "tenant_id"   bigint    not null default '0',
    PRIMARY KEY (`id`)
) COMMENT ='用户岗位表';

CREATE TABLE IF NOT EXISTS "system_notice" (
	"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
	"title" varchar(50) NOT NULL COMMENT '公告标题',
	"content" text NOT NULL COMMENT '公告内容',
	"type" tinyint NOT NULL COMMENT '公告类型（1通知 2公告）',
	"status" tinyint NOT NULL DEFAULT '0' COMMENT '公告状态（0正常 1关闭）',
	"creator" varchar(64) DEFAULT '' COMMENT '创建者',
	"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
	"updater" varchar(64) DEFAULT '' COMMENT '更新者',
	"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
	"deleted" bit NOT NULL DEFAULT 0 COMMENT '是否删除',
    "tenant_id" bigint not null default  '0',
    PRIMARY KEY("id")
) COMMENT '通知公告表';

CREATE TABLE IF NOT EXISTS `system_login_log` (
    `id`          bigint(20)   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    `log_type`    bigint(4)    NOT NULL,
    "user_id" bigint not null default '0',
    "user_type" tinyint NOT NULL,
    `trace_id`    varchar(64)  NOT NULL DEFAULT '',
    `username`    varchar(50)  NOT NULL DEFAULT '',
    `result`      tinyint(4)   NOT NULL,
    `user_ip`     varchar(50)  NOT NULL,
    `user_agent`  varchar(512) NOT NULL,
    `creator`   varchar(64)           DEFAULT '',
    `create_time` datetime     NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updater`   varchar(64)           DEFAULT '',
    `update_time` datetime     NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `deleted`     bit(1)       NOT NULL DEFAULT '0',
    PRIMARY KEY (`id`)
) COMMENT ='系统访问记录';

CREATE TABLE IF NOT EXISTS `system_operate_log` (
    `id`               bigint(20)    NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    `trace_id`         varchar(64)   NOT NULL DEFAULT '',
    `user_id`          bigint(20)    NOT NULL,
    "user_type" tinyint not null default '0',
    `module`           varchar(50)   NOT NULL,
    `name`             varchar(50)   NOT NULL,
    `type`     bigint(4)     NOT NULL DEFAULT '0',
    `content`          varchar(2000) NOT NULL DEFAULT '',
    `exts`             varchar(512)  NOT NULL DEFAULT '',
    `request_method`   varchar(16)            DEFAULT '',
    `request_url`      varchar(255)           DEFAULT '',
    `user_ip`          varchar(50)            DEFAULT NULL,
    `user_agent`       varchar(200)           DEFAULT NULL,
    `java_method`      varchar(512)  NOT NULL DEFAULT '',
    `java_method_args` varchar(8000)          DEFAULT '',
    `start_time`       datetime      NOT NULL,
    `duration`         int(11)       NOT NULL,
    `result_code`      int(11)       NOT NULL DEFAULT '0',
    `result_msg`       varchar(512)           DEFAULT '',
    `result_data`      varchar(4000)          DEFAULT '',
    `creator`        varchar(64)            DEFAULT '',
    `create_time`      datetime      NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updater`        varchar(64)            DEFAULT '',
    `update_time`      datetime      NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `deleted`          bit(1)        NOT NULL DEFAULT '0',
    "tenant_id"         bigint not null default  '0',
    PRIMARY KEY (`id`)
) COMMENT ='操作日志记录';

CREATE TABLE IF NOT EXISTS "system_users" (
    "id" bigint not null GENERATED BY DEFAULT AS IDENTITY,
    "username" varchar(30) not null,
    "password" varchar(100) not null default '',
    "nickname" varchar(30) not null,
    "remark" varchar(500) default null,
    "dept_id" bigint default null,
    "post_ids" varchar(255) default null,
    "email" varchar(50) default '',
    "mobile" varchar(11) default '',
    "sex" tinyint default '0',
    "avatar" varchar(100) default '',
    "status" tinyint not null default '0',
    "login_ip" varchar(50) default '',
    "login_date" timestamp default null,
    "creator" varchar(64) default '',
    "create_time" timestamp not null default current_timestamp,
    "updater" varchar(64) default '',
    "update_time" timestamp not null default current_timestamp,
    "deleted" bit not null default false,
    "tenant_id" bigint not null default  '0',
    primary key ("id")
) comment '用户信息表';

CREATE TABLE IF NOT EXISTS "system_sms_channel" (
   "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
   "signature" varchar(10) NOT NULL,
   "code" varchar(63) NOT NULL,
   "status" tinyint NOT NULL,
   "remark" varchar(255) DEFAULT NULL,
   "api_key" varchar(63) NOT NULL,
   "api_secret" varchar(63) DEFAULT NULL,
   "callback_url" varchar(255) DEFAULT NULL,
   "creator" varchar(64) DEFAULT '',
   "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
   "updater" varchar(64) DEFAULT '',
   "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
   "deleted" bit NOT NULL DEFAULT FALSE,
   PRIMARY KEY ("id")
) COMMENT '短信渠道';

CREATE TABLE IF NOT EXISTS "system_sms_template" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "type" tinyint NOT NULL,
    "status" tinyint NOT NULL,
    "code" varchar(63) NOT NULL,
    "name" varchar(63) NOT NULL,
    "content" varchar(255) NOT NULL,
    "params" varchar(255) NOT NULL,
    "remark" varchar(255) DEFAULT NULL,
    "api_template_id" varchar(63) NOT NULL,
    "channel_id" bigint NULL,
    "channel_code" varchar(63) NULL,
    "creator" varchar(64) DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar(64) DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    PRIMARY KEY ("id")
) COMMENT '短信模板';

CREATE TABLE IF NOT EXISTS "system_sms_log" (
   "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
   "channel_id" bigint NULL,
   "channel_code" varchar(63) NULL,
   "template_id" bigint NOT NULL,
   "template_code" varchar(63) NOT NULL,
   "template_type" tinyint NOT NULL,
   "template_content" varchar(255) NOT NULL,
   "template_params" varchar(255) NOT NULL,
   "api_template_id" varchar(63) NOT NULL,
   "mobile" varchar(11) NOT NULL,
   "user_id" bigint DEFAULT '0',
   "user_type" tinyint DEFAULT '0',
   "send_status" tinyint NOT NULL DEFAULT '0',
   "send_time" timestamp DEFAULT NULL,
   "send_code" int DEFAULT NULL,
   "send_msg" varchar(255) DEFAULT NULL,
   "api_send_code" varchar(63) DEFAULT NULL,
   "api_send_msg" varchar(255) DEFAULT NULL,
   "api_request_id" varchar(255) DEFAULT NULL,
   "api_serial_no" varchar(255) DEFAULT NULL,
   "receive_status" tinyint NOT NULL DEFAULT '0',
   "receive_time" timestamp DEFAULT NULL,
   "api_receive_code" varchar(63) DEFAULT NULL,
   "api_receive_msg" varchar(255) DEFAULT NULL,
   "creator" varchar(64) DEFAULT '',
   "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
   "updater" varchar(64) DEFAULT '',
   "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
   "deleted" bit NOT NULL DEFAULT FALSE,
   PRIMARY KEY ("id")
) COMMENT '短信日志';

CREATE TABLE IF NOT EXISTS "system_sms_code" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "mobile" varchar(11) NOT NULL,
    "code" varchar(11) NOT NULL,
    "scene" bigint NOT NULL,
    "create_ip" varchar NOT NULL,
    "today_index" int NOT NULL,
    "used" bit NOT NULL DEFAULT FALSE,
    "used_time" timestamp DEFAULT NULL,
    "used_ip" varchar NULL,
    "creator" varchar(64) DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar(64) DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    PRIMARY KEY ("id")
) COMMENT '短信日志';

CREATE TABLE IF NOT EXISTS "system_error_code" (
  "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
  "type" tinyint NOT NULL DEFAULT '0',
  "application_name" varchar(50) NOT NULL,
  "code" int NOT NULL DEFAULT '0',
  "message" varchar(512) NOT NULL DEFAULT '',
  "memo" varchar(512) DEFAULT '',
  "creator" varchar(64) DEFAULT '',
  "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  "updater" varchar(64) DEFAULT '',
  "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  "deleted" bit NOT NULL DEFAULT FALSE,
  PRIMARY KEY ("id")
) COMMENT '错误码表';

CREATE TABLE IF NOT EXISTS "system_social_client" (
  "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
  "name" varchar(255) NOT NULL,
  "social_type" int NOT NULL,
  "user_type" int NOT NULL,
  "client_id" varchar(255) NOT NULL,
  "client_secret" varchar(255) NOT NULL,
  "agent_id" varchar(255) NOT NULL,
  "status" int NOT NULL,
  "creator" varchar(64) DEFAULT '',
  "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  "updater" varchar(64) DEFAULT '',
  "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  "deleted" bit NOT NULL DEFAULT FALSE,
  "tenant_id" bigint not null default  '0',
  PRIMARY KEY ("id")
) COMMENT '社交客户端表';

CREATE TABLE IF NOT EXISTS "system_social_user" (
   "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
   "type" tinyint NOT NULL,
   "openid" varchar(64) NOT NULL,
   "token" varchar(256) DEFAULT NULL,
   "raw_token_info" varchar(1024) NOT NULL,
   "nickname" varchar(32) NOT NULL,
   "avatar" varchar(255) DEFAULT NULL,
   "raw_user_info" varchar(1024) NOT NULL,
   "code" varchar(64) NOT NULL,
   "state" varchar(64),
   "creator" varchar(64) DEFAULT '',
   "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
   "updater" varchar(64) DEFAULT '',
   "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
   "deleted" bit NOT NULL DEFAULT FALSE,
   PRIMARY KEY ("id")
) COMMENT '社交用户';

CREATE TABLE IF NOT EXISTS "system_social_user_bind" (
   "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
   "user_id" bigint NOT NULL,
   "user_type" tinyint NOT NULL,
   "social_type" tinyint NOT NULL,
   "social_user_id" number NOT NULL,
   "creator" varchar(64) DEFAULT '',
   "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
   "updater" varchar(64) DEFAULT '',
   "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
   "deleted" bit NOT NULL DEFAULT FALSE,
   PRIMARY KEY ("id")
) COMMENT '社交用户的绑定';

CREATE TABLE IF NOT EXISTS "system_organization" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "name" varchar(63) NOT NULL,
    "contact_user_id" bigint NOT NULL DEFAULT '0',
    "contact_name" varchar(255) NOT NULL,
    "contact_mobile" varchar(255),
    "status" tinyint NOT NULL,
    "website" varchar(63) DEFAULT '',
    "package_id"  bigint NOT NULL,
    "expire_time" timestamp NOT NULL,
    "account_count" int NOT NULL,
    "creator" varchar(64) DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar(64) DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    PRIMARY KEY ("id")
) COMMENT '组织';

CREATE TABLE IF NOT EXISTS "system_tenant_package" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "name" varchar(30) NOT NULL,
    "status" tinyint NOT NULL,
    "remark" varchar(256),
    "menu_ids" varchar(2048) NOT NULL,
    "creator" varchar(64) DEFAULT '',
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar(64) DEFAULT '',
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    PRIMARY KEY ("id")
) COMMENT '组织套餐表';

CREATE TABLE IF NOT EXISTS "system_sensitive_word" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "name" varchar(255) NOT NULL,
    "tags" varchar(1024) NOT NULL,
    "status" bit NOT NULL DEFAULT FALSE,
    "description" varchar(512),
    "creator" varchar(64) DEFAULT '',
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar(64) DEFAULT '',
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    PRIMARY KEY ("id")
) COMMENT '系统敏感词';

CREATE TABLE IF NOT EXISTS "system_oauth2_client" (
  "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
  "client_id" varchar NOT NULL,
  "secret" varchar NOT NULL,
  "name" varchar NOT NULL,
  "logo" varchar NOT NULL,
  "description" varchar,
  "status" int NOT NULL,
  "access_token_validity_seconds" int NOT NULL,
  "refresh_token_validity_seconds" int NOT NULL,
  "redirect_uris" varchar NOT NULL,
  "authorized_grant_types" varchar NOT NULL,
  "scopes" varchar NOT NULL DEFAULT '',
  "auto_approve_scopes" varchar NOT NULL DEFAULT '',
  "authorities" varchar NOT NULL DEFAULT '',
  "resource_ids" varchar NOT NULL DEFAULT '',
  "additional_information" varchar NOT NULL DEFAULT '',
  "creator" varchar DEFAULT '',
  "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  "updater" varchar DEFAULT '',
  "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  "deleted" bit NOT NULL DEFAULT FALSE,
  PRIMARY KEY ("id")
) COMMENT 'OAuth2 客户端表';

CREATE TABLE IF NOT EXISTS "system_oauth2_approve" (
  "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
  "user_id" bigint NOT NULL,
  "user_type" tinyint NOT NULL,
  "client_id" varchar NOT NULL,
  "scope" varchar NOT NULL,
  "approved" bit NOT NULL DEFAULT FALSE,
  "expires_time" datetime NOT NULL,
  "creator" varchar DEFAULT '',
  "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  "updater" varchar DEFAULT '',
  "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  "deleted" bit NOT NULL DEFAULT FALSE,
  PRIMARY KEY ("id")
) COMMENT 'OAuth2 批准表';

CREATE TABLE IF NOT EXISTS "system_oauth2_access_token" (
   "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
   "user_id" bigint NOT NULL,
   "user_type" tinyint NOT NULL,
   "access_token" varchar NOT NULL,
   "refresh_token" varchar NOT NULL,
   "client_id" varchar NOT NULL,
   "scopes" varchar NOT NULL,
   "approved" bit NOT NULL DEFAULT FALSE,
   "expires_time" datetime NOT NULL,
   "creator" varchar DEFAULT '',
   "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
   "updater" varchar DEFAULT '',
   "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
   "deleted" bit NOT NULL DEFAULT FALSE,
   "tenant_id" bigint NOT NULL,
   PRIMARY KEY ("id")
) COMMENT 'OAuth2 访问令牌';

CREATE TABLE IF NOT EXISTS "system_oauth2_refresh_token" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "user_id" bigint NOT NULL,
    "user_type" tinyint NOT NULL,
    "refresh_token" varchar NOT NULL,
    "client_id" varchar NOT NULL,
    "scopes" varchar NOT NULL,
    "approved" bit NOT NULL DEFAULT FALSE,
    "expires_time" datetime NOT NULL,
    "creator" varchar DEFAULT '',
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar DEFAULT '',
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    PRIMARY KEY ("id")
) COMMENT 'OAuth2 刷新令牌';

CREATE TABLE IF NOT EXISTS "system_oauth2_code" (
     "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
     "user_id" bigint NOT NULL,
     "user_type" tinyint NOT NULL,
     "code" varchar NOT NULL,
     "client_id" varchar NOT NULL,
     "scopes" varchar NOT NULL,
     "expires_time" datetime NOT NULL,
     "redirect_uri" varchar NOT NULL,
     "state" varchar NOT NULL,
     "creator" varchar DEFAULT '',
     "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
     "updater" varchar DEFAULT '',
     "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
     "deleted" bit NOT NULL DEFAULT FALSE,
     PRIMARY KEY ("id")
) COMMENT 'OAuth2 刷新令牌';

CREATE TABLE IF NOT EXISTS "system_mail_account" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "mail" varchar NOT NULL,
    "username" varchar NOT NULL,
    "password" varchar NOT NULL,
    "host" varchar NOT NULL,
    "port" int NOT NULL,
    "ssl_enable" bit NOT NULL,
    "creator" varchar DEFAULT '',
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar DEFAULT '',
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    PRIMARY KEY ("id")
) COMMENT '邮箱账号表';

CREATE TABLE IF NOT EXISTS "system_mail_template" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "name" varchar NOT NULL,
    "code" varchar NOT NULL,
    "account_id" bigint NOT NULL,
    "nickname" varchar,
    "title" varchar NOT NULL,
    "content" varchar NOT NULL,
    "params" varchar NOT NULL,
    "status" varchar NOT NULL,
    "remark" varchar,
    "creator" varchar DEFAULT '',
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar DEFAULT '',
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    PRIMARY KEY ("id")
) COMMENT '邮件模版表';

CREATE TABLE IF NOT EXISTS "system_mail_log" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "user_id" bigint,
    "user_type" varchar,
    "to_mail" varchar NOT NULL,
    "account_id" bigint NOT NULL,
    "from_mail" varchar NOT NULL,
    "template_id" bigint NOT NULL,
    "template_code" varchar NOT NULL,
    "template_nickname" varchar,
    "template_title" varchar NOT NULL,
    "template_content" varchar NOT NULL,
    "template_params" varchar NOT NULL,
    "send_status" varchar NOT NULL,
    "send_time" datetime,
    "send_message_id" varchar,
    "send_exception" varchar,
    "creator" varchar DEFAULT '',
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar DEFAULT '',
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    PRIMARY KEY ("id")
) COMMENT '邮件日志表';

-- 将该建表 SQL 语句，添加到 cf-module-system-biz 模块的 test/resources/sql/create_tables.sql 文件里
CREATE TABLE IF NOT EXISTS "system_notify_template" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "name" varchar NOT NULL,
    "code" varchar NOT NULL,
    "nickname" varchar NOT NULL,
    "content" varchar NOT NULL,
    "type" varchar NOT NULL,
    "params" varchar,
    "status" varchar NOT NULL,
    "remark" varchar,
    "creator" varchar DEFAULT '',
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar DEFAULT '',
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    PRIMARY KEY ("id")
) COMMENT '站内信模板表';

CREATE TABLE IF NOT EXISTS "system_notify_message" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "user_id" bigint NOT NULL,
    "user_type" varchar NOT NULL,
    "template_id" bigint NOT NULL,
    "template_code" varchar NOT NULL,
    "template_nickname" varchar NOT NULL,
    "template_content" varchar NOT NULL,
    "template_type" int NOT NULL,
    "template_params" varchar NOT NULL,
    "read_status" bit NOT NULL,
    "read_time" varchar,
    "creator" varchar DEFAULT '',
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar DEFAULT '',
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    "tenant_id" bigint not null default  '0',
    PRIMARY KEY ("id")
) COMMENT '站内信消息表';

CREATE TABLE IF NOT EXISTS "process" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "organ_id" bigint NOT NULL,
    "name" varchar NOT NULL,
    "piece_rate" varchar NOT NULL,
    "piece_type" int NOT NULL,
    "type" int NOT NULL,
    "is_custom" bit NOT NULL,
    "is_dealer" bit NOT NULL,
    "sort" varchar NOT NULL,
    "hour_capacity" varchar NOT NULL,
    "unit" varchar NOT NULL,
    "is_enabled" bit NOT NULL,
    "prepare_time" varchar NOT NULL,
    "description" varchar NOT NULL,
    "creator" varchar DEFAULT '',
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ,
    "updater" varchar DEFAULT '',
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY ("id")
    ) COMMENT '工序信息表 process';

CREATE TABLE IF NOT EXISTS "process_group" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "organ_id" bigint NOT NULL,
    "name" varchar NOT NULL,
    "is_default" bit NOT NULL,
    "sort" varchar NOT NULL,
    "items" varchar NOT NULL,
    "description" varchar NOT NULL,
    "creator" varchar DEFAULT '',
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar DEFAULT '',
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    PRIMARY KEY ("id")
    ) COMMENT '工序组表 process_group';

CREATE TABLE IF NOT EXISTS "products" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "product_name" varchar(64) NOT NULL,
    "status" tinyint DEFAULT 1 NOT NULL,
    "software_id" bigint NOT NULL,
    "price" decimal(8,2),
    "description" varchar,
    "creator" varchar DEFAULT '',
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar DEFAULT '',
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    PRIMARY KEY ("id")
    ) COMMENT '产品表';

CREATE TABLE IF NOT EXISTS "products_details" (
    "id" BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "product_id" BIGINT NOT NULL,
    "duration" VARCHAR,
    "duration_unit" TINYINT,
    "discount" DECIMAL(3),
    "creator" VARCHAR DEFAULT '',
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar(64) DEFAULT '',
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    PRIMARY KEY ("id")
    ) COMMENT '产品购买信息表 products_details';

CREATE TABLE IF NOT EXISTS "product_promotion" (
    "id" BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY COMMENT '主键，自增ID',
    "activity_name" VARCHAR(32) NOT NULL COMMENT '活动名称',
    "product_id" BIGINT NOT NULL COMMENT '关联产品id',
    "product_name" VARCHAR(64) NOT NULL COMMENT '关联产品名称',
    "purchase_duration" INT NOT NULL COMMENT '购买时长',
    "purchase_duration_unit" TINYINT NOT NULL COMMENT '购买时长单位',
    "gift_duration" INT COMMENT '赠送时长',
    "gift_duration_unit" TINYINT COMMENT '赠送时长单位',
    "start_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '开始时间',
    "end_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '结束时间',
    "remark" VARCHAR(1024) DEFAULT NULL COMMENT '备注',
    "creator" VARCHAR(64) DEFAULT '' COMMENT '创建者',
    "create_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    "updater" VARCHAR(64) DEFAULT '' COMMENT '更新者',
    "update_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
    "deleted" BIT NOT NULL DEFAULT FALSE COMMENT '是否删除：0否 1是',
    PRIMARY KEY ("id")
    ) COMMENT '优惠活动（base表）';

CREATE TABLE IF NOT EXISTS "advertisement" (
    "id" BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY COMMENT '主键，根据ID号规则生成',
    "ad_name" VARCHAR(32) NOT NULL COMMENT '广告名称',
    "software_id" VARCHAR(32) NOT NULL DEFAULT '1' COMMENT '软件id，不同软件的标识',
    "ad_position" VARCHAR(64) NOT NULL COMMENT '广告位置，0首页工作台轮播 1系统管理余额查询轮播 2基础配置资金查询轮播（多选）',
    "ad_image_path" VARCHAR(255) NOT NULL COMMENT '广告图片路径',
    "start_time" DATE NOT NULL COMMENT '投放开始时间',
    "end_time" DATE NOT NULL COMMENT '投放结束时间',
    "ad_redirect_url" VARCHAR(255) DEFAULT NULL COMMENT '广告跳转链接',
    "sort" SMALLINT DEFAULT 0 COMMENT '顺序',
    "status" TINYINT DEFAULT 0 NOT NULL COMMENT '广告状态，0未发布 1已发布 2已结束',
    "creator" VARCHAR(64) DEFAULT NULL COMMENT '创建者/操作人',
    "create_time" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL COMMENT '创建时间/操作时间',
    "updater" VARCHAR(64) DEFAULT NULL COMMENT '更新者',
    "update_time" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL COMMENT '更新时间',
    "deleted" BIT DEFAULT FALSE NOT NULL COMMENT '是否删除，0否1是',
    PRIMARY KEY ("id")
    ) COMMENT '广告表 advertisement';

CREATE TABLE IF NOT EXISTS "product_delay_record"
(
    "id"                  BIGINT      NOT NULL GENERATED BY DEFAULT AS IDENTITY COMMENT '主键，自增',
    "organ_id"            BIGINT      NOT NULL DEFAULT '0' COMMENT '组织ID',
    "organ_name"          VARCHAR(30) NOT NULL COMMENT '组织名称',
    "product_id"          BIGINT      NOT NULL COMMENT '产品编号',
    "product_name"        VARCHAR(64) NOT NULL COMMENT '产品名称',
    "delay_duration"      INT         NOT NULL COMMENT '延期时长',
    "delay_duration_unit" TINYINT     NOT NULL COMMENT '延期时长单位',
    "end_time"            DATE        NOT NULL COMMENT '产品结束时间',
    "delay_time"          DATE        NOT NULL COMMENT '延期后有效时长',
    "purchase_id"         VARCHAR(2048)        DEFAULT NULL COMMENT '购买记录单号',
    "remark"              VARCHAR(1024)        DEFAULT NULL COMMENT '备注',
    "creator"             VARCHAR(64)          DEFAULT NULL COMMENT '创建者',
    "create_time"         TIMESTAMP   NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    "updater"             VARCHAR(64)          DEFAULT NULL COMMENT '更新者',
    "update_time"         TIMESTAMP   NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
    "paid"                BIT                  DEFAULT FALSE COMMENT '是否支付',
    "deleted"             BIT         NOT NULL DEFAULT FALSE COMMENT '是否删除，0否1是',
    PRIMARY KEY ("id")
) COMMENT '产品延期记录表';

CREATE TABLE IF NOT EXISTS "purchase_record"
(
    "id"                     BIGINT         NOT NULL GENERATED BY DEFAULT AS IDENTITY COMMENT '主键，根据ID号规则生成',
    "organ_id"               BIGINT         NOT NULL DEFAULT '0' COMMENT '组织ID',
    "previous_id"            BIGINT                  DEFAULT NULL COMMENT '前序订购记录id',
    "product_id"             BIGINT         NOT NULL COMMENT '产品ID',
    "product_details_id"     BIGINT         NOT NULL COMMENT '产品明细ID',
    "product_promotion_id"   BIGINT                  DEFAULT NULL COMMENT '优惠活动id',
    "product_name"           VARCHAR(64)    NOT NULL COMMENT '产品名称',
    "order_no"               VARCHAR(64)             DEFAULT NULL COMMENT '订单号',
    "purchase_duration"      INT            NOT NULL DEFAULT '0' COMMENT '购买时长',
    "purchase_duration_unit" TINYINT        NOT NULL COMMENT '购买时长单位：0年、1月、2日',
    "gift_duration"          INT                     DEFAULT NULL COMMENT '赠送时长',
    "gift_duration_unit"     TINYINT                 DEFAULT NULL COMMENT '赠送时长单位：0年、1月、2日',
    "start_time"             DATE           NOT NULL COMMENT '产品开始时间',
    "end_time"               DATE           NOT NULL COMMENT '产品结束时间',
    "payment_method"         TINYINT        NOT NULL DEFAULT '0' COMMENT '支付方式：0现金余额；1赠送金；2支付宝；3微信；4现金+赠送金；5现金+支付宝；6现金+微信；7赠送金+支付宝；8赠送金+微信；9现金+赠送金+支付宝；10现金+赠送金+微信',
    "total_amount"           DECIMAL(10, 2) NOT NULL DEFAULT 0.00 COMMENT '订单总额',
    "original_amount"        DECIMAL(10, 2) NOT NULL DEFAULT 0.00 COMMENT '原始价格',
    "month_average_amount"   DECIMAL(10, 2) NOT NULL DEFAULT 0.00 COMMENT '月均单价',
    "external_spent"         DECIMAL(10, 2) NOT NULL DEFAULT 0.00 COMMENT '外部支付金额',
    "currency"               TINYINT                 DEFAULT NULL COMMENT '货币类型',
    "currency_unit"          VARCHAR(10)             DEFAULT NULL COMMENT '货币单位',
    "is_invocing"            TINYINT                 DEFAULT NULL COMMENT '是否开票：0可开票 1待开票 2已开票',
    "initial"                BIT            NOT NULL DEFAULT FALSE COMMENT '是否首次订购',
    "status"                 INT                     DEFAULT '1' COMMENT '购买记录状态，1有效、2等待支付、3作废',
    "creator"                VARCHAR(64)             DEFAULT NULL COMMENT '创建者',
    "create_time"            TIMESTAMP      NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    "updater"                VARCHAR(64)             DEFAULT NULL COMMENT '更新者',
    "update_time"            TIMESTAMP      NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
    "deleted"                BIT            NOT NULL DEFAULT FALSE COMMENT '是否删除：0否 1是',
    PRIMARY KEY ("id")
) COMMENT '购买记录表';

CREATE TABLE IF NOT EXISTS "income_expense_details"
(
    "id"                  BIGINT         NOT NULL GENERATED BY DEFAULT AS IDENTITY COMMENT 'ID，主键',
    "business_no"         VARCHAR(64)             DEFAULT NULL COMMENT '流水号',
    "order_no"            VARCHAR(64)             DEFAULT NULL COMMENT '订单号',
    "gift_money_id"       BIGINT                  DEFAULT NULL COMMENT '充值-赠送金规则ID',
    "purchase_id"         BIGINT                  DEFAULT NULL COMMENT '购买-购买记录ID',
    "organ_id"            BIGINT         NOT NULL DEFAULT '0' COMMENT '组织ID',
    "trade_type"          TINYINT        NOT NULL COMMENT '交易类型 0充值 1软件购买',
    "income_expense_type" TINYINT        NOT NULL COMMENT '收支类型 0收入 1支出',
    "cash_amount_change"  DECIMAL(10, 2) NOT NULL DEFAULT '0.00' COMMENT '支出/入账现金金额',
    "gift_amount_change"  DECIMAL(10, 2) NOT NULL DEFAULT '0.00' COMMENT '支出/入账赠送金金额',
    "available_amount"    DECIMAL(10, 2) NOT NULL DEFAULT '0.00' COMMENT '可用余额（现金+赠送金）',
    "amount"              DECIMAL(10, 2)          DEFAULT NULL COMMENT '现金余额',
    "gift_amount"         DECIMAL(10, 2)          DEFAULT NULL COMMENT '赠送余额',
    "currency"            TINYINT                 DEFAULT NULL COMMENT '货币类型（字典）',
    "currency_unit"       VARCHAR(10)             DEFAULT NULL COMMENT '货币单位',
    "creator"             VARCHAR(64)             DEFAULT NULL COMMENT '创建者/操作人',
    "create_time"         TIMESTAMP      NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间/交易时间',
    "updater"             VARCHAR(64)             DEFAULT NULL COMMENT '更新者',
    "update_time"         TIMESTAMP      NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
    "remark"              VARCHAR(255)            DEFAULT NULL COMMENT '备注',
    "deleted"             BIT            NOT NULL DEFAULT FALSE COMMENT '是否删除 0否 1是',
    PRIMARY KEY ("id")
) COMMENT '收支明细表';

CREATE TABLE IF NOT EXISTS "invoice_title_info"
(
    "id"                 BIGINT      NOT NULL GENERATED BY DEFAULT AS IDENTITY COMMENT '主键，根据ID号规则生成',
    "organ_id"           BIGINT      NOT NULL COMMENT '组织ID',
    "invoice_title"      VARCHAR(64) NOT NULL COMMENT '发票抬头',
    "issue_type"         TINYINT     NOT NULL COMMENT '开具类型，0企业 1个人',
    "invoice_type"       TINYINT     NOT NULL DEFAULT '0' COMMENT '发票类型，0增值税普通发票 1增值税专用发票',
    "tax_number"         VARCHAR(18)          DEFAULT NULL COMMENT '统一社会信用代码',
    "bank_name"          VARCHAR(64)          DEFAULT NULL COMMENT '开户银行名称',
    "bank_account"       VARCHAR(40)          DEFAULT NULL COMMENT '开户银行账号',
    "registered_address" VARCHAR(64)          DEFAULT NULL COMMENT '注册场所地址',
    "fixed_phone"        VARCHAR(20)          DEFAULT NULL COMMENT '注册固定电话',
    "email"              VARCHAR(255)         DEFAULT '' COMMENT '邮箱',
    "creator"            VARCHAR(64)          DEFAULT NULL COMMENT '创建者',
    "create_time"        TIMESTAMP            DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    "updater"            VARCHAR(64)          DEFAULT NULL COMMENT '更新者',
    "update_time"        TIMESTAMP            DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
    "deleted"            BIT                  DEFAULT FALSE COMMENT '是否删除，0否1是',
    PRIMARY KEY ("id")
) COMMENT '发票抬头信息表';

CREATE TABLE IF NOT EXISTS "invoice_records"
(
    "id"                      BIGINT         NOT NULL GENERATED BY DEFAULT AS IDENTITY COMMENT '发票记录ID',
    "organ_id"                BIGINT         NOT NULL DEFAULT '0' COMMENT '组织ID',
    "organ_name"              VARCHAR(30)             DEFAULT NULL COMMENT '组织/发票抬头名称',
    "user_id"                 BIGINT         NOT NULL COMMENT '发票申请人ID',
    "invoice_no"              VARCHAR(32)             DEFAULT NULL COMMENT '发票号',
    "purchase_ids"            VARCHAR(2048)           DEFAULT NULL COMMENT '购买记录id集合',
    "invoice_amount"          DECIMAL(10, 2) NOT NULL DEFAULT '0.00' COMMENT '发票金额',
    "status"                  TINYINT        NOT NULL COMMENT '发票状态 1待开票 2已开票 3开票失败',
    "invoice_attachment_path" VARCHAR(255)            DEFAULT NULL COMMENT '发票附件保存路径',
    "invoice_attachment_id"   BIGINT                  DEFAULT NULL COMMENT '发票附件文件id',
    "invoice_attachment_name" VARCHAR(255)            DEFAULT NULL COMMENT '发票附件名称',
    "invoice_person"          VARCHAR(64)             DEFAULT NULL COMMENT '开票人',
    "invoice_person_id"       BIGINT                  DEFAULT NULL COMMENT '开票人用户ID',
    "invoice_time"            TIMESTAMP               DEFAULT NULL COMMENT '开票时间',
    "invoice_title_id"        BIGINT                  DEFAULT NULL COMMENT '抬头ID',
    "invoice_title_info"      CLOB                    DEFAULT NULL COMMENT '抬头的信息',
    "remark"                  VARCHAR(1024)           DEFAULT NULL COMMENT '备注',
    "creator"                 VARCHAR(64)             DEFAULT NULL COMMENT '创建者/申请人',
    "create_time"             TIMESTAMP      NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间/申请时间',
    "updater"                 VARCHAR(64)             DEFAULT NULL COMMENT '更新者',
    "update_time"             TIMESTAMP      NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
    "deleted"                 BIT            NOT NULL DEFAULT FALSE COMMENT '是否删除 0否1是',
    PRIMARY KEY ("id")
) COMMENT '开票记录表';

CREATE TABLE IF NOT EXISTS "system_config_token"
(
    "id"           BIGINT       NOT NULL GENERATED BY DEFAULT AS IDENTITY COMMENT '编号',
    "organ_id"     BIGINT       NOT NULL DEFAULT 1 COMMENT '组织 ID',
    "app_type"     TINYINT      NOT NULL COMMENT '应用类型，1 WebCAD',
    "app_name"     VARCHAR(64)  NOT NULL COMMENT '用户名称',
    "app_token"    VARCHAR(255) NOT NULL COMMENT '应用token',
    "expires_time" TIMESTAMP    NOT NULL COMMENT '过期时间',
    "time_type"    VARCHAR(16)  NOT NULL DEFAULT '' COMMENT '时间类型',
    "remark"       VARCHAR(255) NOT NULL DEFAULT '' COMMENT '备注',
    "creator"      VARCHAR(64)           DEFAULT NULL COMMENT '创建者',
    "create_time"  TIMESTAMP             DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    "updater"      VARCHAR(64)           DEFAULT NULL COMMENT '更新者',
    "update_time"  TIMESTAMP             DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
    "deleted"      BIT                   DEFAULT FALSE COMMENT '是否删除',
    PRIMARY KEY ("id")
) COMMENT 'Token配置表';

CREATE TABLE IF NOT EXISTS "application" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "app_id" varchar(32) NOT NULL COMMENT '应用唯一标识',
    "app_key" varchar(255) DEFAULT NULL,
    "app_secret" varchar(255) DEFAULT NULL COMMENT '对应私钥',
    "organ_id" bigint NOT NULL COMMENT '组织ID',
    "server_ip" varchar(255) NOT NULL DEFAULT '' COMMENT '服务器IP列表',
    "code" varchar(64) NOT NULL DEFAULT '' COMMENT '应用简称',
    "name" varchar(64) NOT NULL DEFAULT '' COMMENT '应用名',
    "company" varchar(64) NOT NULL DEFAULT '' COMMENT '应用主体',
    "status" bit NOT NULL DEFAULT FALSE COMMENT '状态: 0停用，1正常',
    "remark" varchar(255) NOT NULL DEFAULT '' COMMENT '备注',
    "creator" varchar(64) NOT NULL DEFAULT '' COMMENT '创建人',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    "updater" varchar(64) NOT NULL DEFAULT '' COMMENT '更新人',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    "deleted" bit NOT NULL DEFAULT FALSE COMMENT '删除标识: 0不删除，1已删除',
    CONSTRAINT "idx_app_appid" UNIQUE ("app_id", "status", "deleted"),
    PRIMARY KEY ("id")
) COMMENT '应用注册表';