-- OA 请假申请 DO
CREATE TABLE IF NOT EXISTS `bpm_oa_leave` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `user_id` bigint NULL,
  `type` varchar(63) NULL,
  `reason` varchar(255) NULL,
  `start_time` datetime NULL,
  `end_time` datetime NULL,
  `day` bigint NULL,
  `status` tinyint NULL,
  `process_instance_id` varchar(255) 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 b'0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='OA 请假申请';

-- BPM 工作流的表单定义
CREATE TABLE IF NOT EXISTS `bpm_form` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `name` varchar(63) NOT NULL,
  `status` tinyint NOT NULL DEFAULT 0,
  `fields` text NOT NULL,
  `conf` varchar(255) NOT NULL,
  `remark` varchar(255) 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 b'0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='动态表单';

-- BPM 流程分类
CREATE TABLE IF NOT EXISTS `bpm_category` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `name` varchar(63) NOT NULL,
  `code` varchar(63) NOT NULL,
  `description` varchar(255) NOT NULL,
  `status` tinyint NOT NULL DEFAULT 0,
  `sort` int NOT NULL DEFAULT 0,
  `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 b'0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='分类';

-- BPM 流程定义的拓展信息
CREATE TABLE IF NOT EXISTS `bpm_process_definition_info` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `process_definition_id` varchar(255) NULL,
  `model_id` varchar(255) NULL,
  `model_type` tinyint NULL,
  `category` varchar(63) NULL,
  `icon` varchar(255) NULL,
  `description` varchar(255) NULL,
  `form_type` tinyint 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` tinyint 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` 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 b'0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='流程定义拓展信息';

-- 流程抄送
CREATE TABLE IF NOT EXISTS `bpm_process_instance_copy` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `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` 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 b'0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='流程抄送';

-- BPM 流程监听器
CREATE TABLE IF NOT EXISTS `bpm_process_listener` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `name` varchar(63) NULL,
  `status` tinyint NULL,
  `type` varchar(63) NULL,
  `event` varchar(63) NULL,
  `value_type` varchar(63) NULL,
  `value` varchar(255) 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 b'0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='流程监听器';

-- BPM 流程表达式
CREATE TABLE IF NOT EXISTS `bpm_process_expression` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `name` varchar(63) NULL,
  `status` tinyint NULL,
  `expression` varchar(255) 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 b'0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='流程表达式';

-- BPM 用户组
CREATE TABLE IF NOT EXISTS `bpm_user_group` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `name` varchar(63) NOT NULL,
  `description` varchar(255) NOT NULL,
  `status` tinyint NOT NULL DEFAULT 0,
  `user_ids` varchar(255) 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 b'0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='用户组';



ALTER TABLE `bpm_oa_leave` ADD COLUMN `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号';
ALTER TABLE `bpm_form` ADD COLUMN `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号';
ALTER TABLE `bpm_category` ADD COLUMN `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号';
ALTER TABLE `bpm_process_definition_info` ADD COLUMN `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号';
ALTER TABLE `bpm_process_instance_copy` ADD COLUMN `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号';
ALTER TABLE `bpm_process_listener` ADD COLUMN `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号';
ALTER TABLE `bpm_process_expression` ADD COLUMN `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号';
ALTER TABLE `bpm_user_group` ADD COLUMN `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号';