-- OA 请假申请 DO
CREATE TABLE IF NOT EXISTS bpm_oa_leave (
  id bigint GENERATED BY DEFAULT AS IDENTITY,
  user_id bigint NULL,
  type varchar(63) NULL,
  reason varchar(255) NULL,
  start_time timestamp NULL,
  end_time timestamp NULL,
  day bigint NULL,
  status smallint NULL,
  process_instance_id varchar(255) 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(1) NOT NULL DEFAULT B'0',
  PRIMARY KEY (id)
);

-- BPM 工作流的表单定义
CREATE TABLE IF NOT EXISTS bpm_form (
  id bigint GENERATED BY DEFAULT AS IDENTITY,
  name varchar(63) NOT NULL,
  status smallint NOT NULL DEFAULT 0,
  fields text NOT NULL,
  conf varchar(255) NOT NULL,
  remark varchar(255) 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(1) NOT NULL DEFAULT B'0',
  PRIMARY KEY (id)
);

-- BPM 流程分类
CREATE TABLE IF NOT EXISTS bpm_category (
  id bigint GENERATED BY DEFAULT AS IDENTITY,
  name varchar(63) NOT NULL,
  code varchar(63) NOT NULL,
  description varchar(255) NOT NULL,
  status smallint NOT NULL DEFAULT 0,
  sort int NOT NULL DEFAULT 0,
  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(1) NOT NULL DEFAULT B'0',
  PRIMARY KEY (id)
);

-- BPM 流程定义的拓展信息
CREATE TABLE IF NOT EXISTS bpm_process_definition_info (
  id bigint GENERATED BY DEFAULT AS IDENTITY,
  process_definition_id varchar(255) NULL,
  model_id varchar(255) NULL,
  model_type smallint NULL,
  category varchar(63) NULL,
  icon varchar(255) NULL,
  description varchar(255) NULL,
  form_type smallint NULL,
  form_id bigint NULL,
  form_conf varchar(255) NULL,
  form_fields text NULL,
  form_custom_create_path varchar(255) NULL,
  form_custom_view_path varchar(255) NULL,
  simple_model varchar(255) NULL,
  visible bit(1) NULL,
  sort bigint NULL,
  start_user_ids varchar(255) NULL,
  start_dept_ids varchar(255) NULL,
  manager_user_ids varchar(255) NULL,
  allow_cancel_running_process bit(1) NULL,
  allow_withdraw_task bit(1) NULL,
  process_id_rule varchar(255) NULL,
  auto_approval_type smallint NULL,
  title_setting varchar(255) NULL,
  summary_setting varchar(255) NULL,
  process_before_trigger_setting varchar(255) NULL,
  process_after_trigger_setting varchar(255) NULL,
  task_before_trigger_setting varchar(255) NULL,
  task_after_trigger_setting varchar(255) NULL,
  print_template_setting varchar(255) 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(1) NOT NULL DEFAULT B'0',
  PRIMARY KEY (id)
);

-- 流程抄送
CREATE TABLE IF NOT EXISTS bpm_process_instance_copy (
  id bigint GENERATED BY DEFAULT AS IDENTITY,
  start_user_id bigint NULL,
  process_instance_name varchar(63) NULL,
  process_instance_id varchar(255) NULL,
  process_definition_id varchar(255) NULL,
  category varchar(63) NULL,
  activity_id varchar(255) NULL,
  activity_name varchar(63) NULL,
  task_id varchar(255) NULL,
  user_id bigint NULL,
  reason varchar(255) 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(1) NOT NULL DEFAULT B'0',
  PRIMARY KEY (id)
);

-- BPM 流程监听器
CREATE TABLE IF NOT EXISTS bpm_process_listener (
  id bigint GENERATED BY DEFAULT AS IDENTITY,
  name varchar(63) NULL,
  status smallint NULL,
  type varchar(63) NULL,
  event varchar(63) NULL,
  value_type varchar(63) NULL,
  value varchar(255) 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(1) NOT NULL DEFAULT B'0',
  PRIMARY KEY (id)
);

-- BPM 流程表达式
CREATE TABLE IF NOT EXISTS bpm_process_expression (
  id bigint GENERATED BY DEFAULT AS IDENTITY,
  name varchar(63) NULL,
  status smallint NULL,
  expression varchar(255) 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(1) NOT NULL DEFAULT B'0',
  PRIMARY KEY (id)
);

-- BPM 用户组
CREATE TABLE IF NOT EXISTS bpm_user_group (
  id bigint GENERATED BY DEFAULT AS IDENTITY,
  name varchar(63) NOT NULL,
  description varchar(255) NOT NULL,
  status smallint NOT NULL DEFAULT 0,
  user_ids varchar(255) 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(1) NOT NULL DEFAULT B'0',
  PRIMARY KEY (id)
);

ALTER TABLE bpm_oa_leave ADD COLUMN tenant_id bigint NOT NULL DEFAULT 0;
ALTER TABLE bpm_form ADD COLUMN tenant_id bigint NOT NULL DEFAULT 0;
ALTER TABLE bpm_category ADD COLUMN tenant_id bigint NOT NULL DEFAULT 0;
ALTER TABLE bpm_process_definition_info ADD COLUMN tenant_id bigint NOT NULL DEFAULT 0;
ALTER TABLE bpm_process_instance_copy ADD COLUMN tenant_id bigint NOT NULL DEFAULT 0;
ALTER TABLE bpm_process_listener ADD COLUMN tenant_id bigint NOT NULL DEFAULT 0;
ALTER TABLE bpm_process_expression ADD COLUMN tenant_id bigint NOT NULL DEFAULT 0;
ALTER TABLE bpm_user_group ADD COLUMN tenant_id bigint NOT NULL DEFAULT 0;

