USE `ShWasherAdmin`;

-- 流程分类信息表
DROP TABLE IF EXISTS wf_category;
CREATE TABLE wf_category
(
    id            BIGINT       NOT NULL COMMENT '主键' PRIMARY KEY AUTO_INCREMENT,
    category_name VARCHAR(255) NULL COMMENT '分类名称',
    category_code VARCHAR(255) NULL COMMENT '分类编码',
    parent_id     BIGINT       NULL COMMENT '父级id',
    sort_num      INT(19)      NULL COMMENT '排序',
    tenant_id     VARCHAR(20)  NULL COMMENT '租户编号',
    create_org    BIGINT       NULL COMMENT '创建组织结构',
    create_by     BIGINT       NULL COMMENT '创建者',
    create_time   DATETIME     NULL COMMENT '创建时间',
    update_by     BIGINT       NULL COMMENT '更新者',
    update_time   DATETIME     NULL COMMENT '更新时间',
    CONSTRAINT uni_category_code UNIQUE (category_code)
) ENGINE = innodb COMMENT = '流程分类'
  AUTO_INCREMENT = 1000;

DROP TABLE IF EXISTS wf_task_back_node;
CREATE TABLE wf_task_back_node
(
    id          BIGINT        NOT NULL PRIMARY KEY AUTO_INCREMENT,
    node_id     VARCHAR(255)  NOT NULL COMMENT '节点id',
    node_name   VARCHAR(255)  NOT NULL COMMENT '节点名称',
    order_no    INT           NOT NULL COMMENT '排序',
    instance_id VARCHAR(255)  NULL COMMENT '流程实例id',
    task_type   VARCHAR(255)  NOT NULL COMMENT '节点类型',
    assignee    VARCHAR(2000) NOT NULL COMMENT '审批人',
    tenant_id   VARCHAR(20)   NULL COMMENT '租户编号',
    create_org  BIGINT        NULL COMMENT '创建组织结构',
    create_by   BIGINT        NULL COMMENT '创建者',
    create_time DATETIME      NULL COMMENT '创建时间',
    update_by   BIGINT        NULL COMMENT '更新者',
    update_time DATETIME      NULL COMMENT '更新时间'
) ENGINE = innodb COMMENT '节点审批记录'
  AUTO_INCREMENT = 1000;

DROP TABLE IF EXISTS wf_definition_config;
CREATE TABLE wf_definition_config
(
    id            BIGINT                  NOT NULL COMMENT '主键' PRIMARY KEY AUTO_INCREMENT,
    table_name    VARCHAR(255)            NOT NULL COMMENT '表名',
    definition_id VARCHAR(255)            NOT NULL COMMENT '流程定义ID',
    process_key   VARCHAR(255)            NOT NULL COMMENT '流程KEY',
    version       INT(10)                 NOT NULL COMMENT '流程版本',
    create_org    BIGINT                  NULL COMMENT '创建组织结构',
    create_by     BIGINT                  NULL COMMENT '创建者',
    create_time   DATETIME                NULL COMMENT '创建时间',
    update_by     BIGINT                  NULL COMMENT '更新者',
    update_time   DATETIME                NULL COMMENT '更新时间',
    remark        VARCHAR(500) DEFAULT '' NULL COMMENT '备注',
    tenant_id     VARCHAR(20)             NULL COMMENT '租户编号',
    CONSTRAINT uni_definition_id UNIQUE (definition_id)
) ENGINE = innodb COMMENT '流程定义配置'
  AUTO_INCREMENT = 1000;

DROP TABLE IF EXISTS wf_form_manage;
CREATE TABLE wf_form_manage
(
    id          BIGINT       NOT NULL COMMENT '主键' PRIMARY KEY AUTO_INCREMENT,
    form_name   VARCHAR(255) NOT NULL COMMENT '表单名称',
    form_type   VARCHAR(255) NOT NULL COMMENT '表单类型',
    router      VARCHAR(255) NOT NULL COMMENT '路由地址/表单ID',
    remark      VARCHAR(500) NULL COMMENT '备注',
    tenant_id   VARCHAR(20)  NULL COMMENT '租户编号',
    create_org  BIGINT       NULL COMMENT '创建组织结构',
    create_by   BIGINT       NULL COMMENT '创建者',
    create_time DATETIME     NULL COMMENT '创建时间',
    update_by   BIGINT       NULL COMMENT '更新者',
    update_time DATETIME     NULL COMMENT '更新时间'
) ENGINE = innodb COMMENT '表单管理'
  AUTO_INCREMENT = 1000;

DROP TABLE IF EXISTS wf_node_config;
CREATE TABLE wf_node_config
(
    id              BIGINT       NOT NULL COMMENT '主键' PRIMARY KEY AUTO_INCREMENT,
    tenant_id       VARCHAR(20)  NULL COMMENT '租户编号',
    form_id         BIGINT       NULL COMMENT '表单id',
    form_type       VARCHAR(255) NULL COMMENT '表单类型',
    node_name       VARCHAR(255) NOT NULL COMMENT '节点名称',
    node_id         VARCHAR(255) NOT NULL COMMENT '节点id',
    definition_id   VARCHAR(255) NOT NULL COMMENT '流程定义id',
    apply_user_task CHAR(1) DEFAULT '0' COMMENT '是否为申请人节点 （0是 1否）',
    create_org      BIGINT       NULL COMMENT '创建组织结构',
    create_by       BIGINT       NULL COMMENT '创建者',
    create_time     DATETIME     NULL COMMENT '创建时间',
    update_by       BIGINT       NULL COMMENT '更新者',
    update_time     DATETIME     NULL COMMENT '更新时间'
) ENGINE = innodb COMMENT '节点配置'
  AUTO_INCREMENT = 1000;

INSERT INTO wf_category (id, category_name, category_code, parent_id, sort_num, tenant_id, create_org, create_by, create_time, update_by, update_time)
VALUES (1, 'OA', 'OA', 0, 0, '000000', 100, 1, SYSDATE(), NULL, NULL);

INSERT INTO wf_form_manage(id, form_name, form_type, router, remark, tenant_id, create_org, create_by, create_time, update_by, update_time)
VALUES (1, '请假申请', 'static', '/demo/leave/edit', NULL, '000000', 100, 1, SYSDATE(), NULL, NULL);

-- 请假单信息
DROP TABLE IF EXISTS wfi_leave_apply;
CREATE TABLE wfi_leave_apply
(
    id          BIGINT       NOT NULL AUTO_INCREMENT COMMENT '主键',
    leave_type  VARCHAR(255) NOT NULL COMMENT '请假类型',
    start_date  DATETIME     NOT NULL COMMENT '开始时间',
    end_date    DATETIME     NOT NULL COMMENT '结束时间',
    leave_days  INT(10)      NOT NULL COMMENT '请假天数',
    status      VARCHAR(255) NULL COMMENT '状态',
    remark      VARCHAR(255) NULL COMMENT '请假原因',
    create_org  BIGINT       NULL COMMENT '创建组织结构',
    create_by   BIGINT       NULL COMMENT '创建者',
    create_time DATETIME     NULL COMMENT '创建时间',
    update_by   BIGINT       NULL COMMENT '更新者',
    update_time DATETIME     NULL COMMENT '更新时间',
    tenant_id   VARCHAR(20)  NULL COMMENT '租户编号',
    PRIMARY KEY (id) USING BTREE
) ENGINE = InnoDB COMMENT = '请假申请表'
  AUTO_INCREMENT = 1000;

-- 工作流菜单
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, query_param, is_frame, is_cache, menu_type, visible, status, perms, icon, btn_class, btn_script, create_org, create_by, create_time, update_by, update_time, remark)
VALUES (4, '工作流', 0, 4, 'workflow', '', '', '1', '0', 'M', '0', '0', '', 'table', '', '', 100, 1, SYSDATE(), NULL, NULL, ''),
       (151, '流程分类', 4, 1, 'category', 'workflow/category/index', '', '1', '0', 'C', '0', '0', 'workflow:category', 'bookmark-fill', '', '', 100, 1, SYSDATE(), NULL, NULL, ''),
       (1121, '分类查询', 151, 1, '#', '', '', 1, 0, 'F', '0', '0', 'workflow:category:query', 'eye', '', '', 100, 1, SYSDATE(), NULL, NULL, ''),
       (1122, '分类新增', 151, 2, '#', '', '', 1, 0, 'F', '0', '0', 'workflow:category:add', 'plus-square', 'btn btn-light-primary', 'handleCreate', 100, 1, SYSDATE(), NULL, NULL, ''),
       (1123, '分类修改', 151, 3, '#', '', '', 1, 0, 'F', '0', '0', 'workflow:category:edit', 'pencil-square', 'btn btn-light-success', 'handleUpdate@1', 100, 1, SYSDATE(), NULL, NULL, ''),
       (1124, '分类删除', 151, 4, '#', '', '', 1, 0, 'F', '0', '0', 'workflow:category:remove', 'dash-square', 'btn btn-light-danger', 'handleDelete@0', 100, 1, SYSDATE(), NULL, NULL, ''),
       (1125, '分类导出', 151, 5, '#', '', '', 1, 0, 'F', '0', '0', 'workflow:category:export', 'cloud-download', 'btn btn-light-info', 'handleExport', 100, 1, SYSDATE(), NULL, NULL, ''),

       (152, '模型管理', 4, 2, 'model', 'workflow/model/index', '', '1', '1', 'C', '0', '0', 'workflow:model', 'box-seam', '', '', 100, 1, SYSDATE(), NULL, NULL, ''),
       (1131, '模型查询', 152, '1', '#', '', '', 1, 0, 'F', '0', '0', 'workflow:model:query', 'eye', '', '', 100, 1, SYSDATE(), NULL, NULL, ''),
       (1132, '模型新增', 152, 2, '#', '', '', 1, 0, 'F', '0', '0', 'workflow:model:add', 'plus-square', 'btn btn-light-primary', 'handleCreate', 100, 1, SYSDATE(), NULL, NULL, ''),
       (1133, '模型修改', 152, 3, '#', '', '', 1, 0, 'F', '0', '0', 'workflow:model:edit', 'pencil-square', 'btn btn-light-success', 'handleUpdate@1', 100, 1, SYSDATE(), NULL, NULL, ''),
       (1134, '模型删除', 152, 4, '#', '', '', 1, 0, 'F', '0', '0', 'workflow:model:remove', 'dash-square', 'btn btn-light-danger', 'handleDelete@0', 100, 1, SYSDATE(), NULL, NULL, ''),
       (1135, '模型导出', 152, 5, '#', '', '', 1, 0, 'F', '0', '0', 'workflow:model:export', 'cloud-download', 'btn btn-light-info', 'handleExport', 100, 1, SYSDATE(), NULL, NULL, ''),
       (1136, '设计模型', 152, 6, '#', '', '', 1, 0, 'F', '1', '0', 'workflow:model:design', '', '', '', 100, 1, SYSDATE(), NULL, NULL, ''),
       (1137, '部署模型', 152, 7, '#', '', '', 1, 0, 'F', '1', '0', 'workflow:model:deploy', '', '', '', 100, 1, SYSDATE(), NULL, NULL, ''),
       (1138, '复制模型', 152, 8, '#', '', '', 1, 0, 'F', '1', '0', 'workflow:model:copy', '', '', '', 100, 1, SYSDATE(), NULL, NULL, ''),
       (153, '流程定义', 4, 3, 'processDefinition', 'workflow/processDefinition/index', '', '1', '1', 'C', '0', '0', 'workflow:definition', 'aspect-ratio-fill', '', '', 100, 1, SYSDATE(), NULL, NULL, ''),
       (1141, '流程查询', 153, '1', '#', '', '', 1, 0, 'F', '0', '0', 'workflow:definition:query', 'eye', '', '', 100, 1, SYSDATE(), NULL, NULL, ''),
       (1142, '部署流程', 153, '2', '#', '', '', 1, 0, 'F', '0', '0', 'workflow:definition:upload', 'cloud-upload', 'btn btn-light-success', 'handleUpload', 100, 1, SYSDATE(), NULL, NULL, ''),
       (1143, '流程删除', 153, '3', '#', '', '', 1, 0, 'F', '0', '0', 'workflow:definition:remove', 'dash-square', 'btn btn-light-danger', 'handleDelete@0', 100, 1, SYSDATE(), NULL, NULL, ''),

       (154, '流程监控', 4, 4, 'wf_monitor', '', '', '1', '0', 'M', '0', '0', 'workflow:monitor', 'display', '', '', 100, 1, SYSDATE(), NULL, NULL, ''),
       (155, '流程实例', 154, 1, 'processInstance', 'workflow/processInstance/index', '', '1', '1', 'C', '0', '0', 'workflow:monitor:instance', 'database', '', '', 100, 1, SYSDATE(), NULL, NULL, ''),
       (156, '待办任务', 154, 2, 'allTaskWaiting', 'workflow/task/allTaskWaiting', '', '1', '1', 'C', '0', '0', 'workflow:monitor:task', 'list-task', '', '', 100, 1, SYSDATE(), NULL, NULL, ''),
       (157, '表单管理', 4, 5, 'formManage', 'workflow/formManage/index', '', 1, 0, 'C', '0', '0', 'workflow:formManage', 'bounding-box-circles', '', '', 100, 1, SYSDATE(), NULL, NULL, '表单管理菜单'),
       (1201, '表单查询', 157, 1, '#', '', '', 1, 0, 'F', '0', '0', 'workflow:formManage:query', 'eye', '', '', 100, 1, SYSDATE(), NULL, NULL, ''),
       (1202, '表单新增', 157, 2, '#', '', '', 1, 0, 'F', '0', '0', 'workflow:formManage:add', 'plus-square', 'btn btn-light-primary', 'handleCreate', 100, 1, SYSDATE(), NULL, NULL, ''),
       (1203, '表单修改', 157, 3, '#', '', '', 1, 0, 'F', '0', '0', 'workflow:formManage:edit', 'pencil-square', 'btn btn-light-success', 'handleUpdate@1', 100, 1, SYSDATE(), NULL, NULL, ''),
       (1204, '表单删除', 157, 4, '#', '', '', 1, 0, 'F', '0', '0', 'workflow:formManage:remove', 'dash-square', 'btn btn-light-danger', 'handleDelete@0', 100, 1, SYSDATE(), NULL, NULL, ''),
       (1205, '表单导出', 157, 5, '#', '', '', 1, 0, 'F', '0', '0', 'workflow:formManage:export', 'cloud-download', 'btn btn-light-info', 'handleExport', 100, 1, SYSDATE(), NULL, NULL, ''),

       (5, '我的任务', 0, 5, 'task', '', '', '1', '0', 'M', '1', '0', 'workflow:task', 'award', '', '', 100, 1, SYSDATE(), NULL, NULL, ''),
       (161, '我发起的', 5, 1, 'myDocument', 'workflow/task/myDocument', '', '1', '1', 'C', '1', '0', 'workflow:task:my', 'file-person', '', '', 100, 1, SYSDATE(), NULL, NULL, ''),
       (162, '我的待办', 5, 2, 'taskWaiting', 'workflow/task/taskWaiting', '', '1', '1', 'C', '1', '0', 'workflow:task:wait', 'person-fill-exclamation', '', '', 100, 1, SYSDATE(), NULL, NULL, ''),
       (163, '我的已办', 5, 3, 'taskFinish', 'workflow/task/taskFinish', '', '1', '1', 'C', '1', '0', 'workflow:task:finish', 'person-fill-check', '', '', 100, 1, SYSDATE(), NULL, NULL, ''),
       (164, '我的抄送', 5, 4, 'taskCopyList', 'workflow/task/taskCopyList', '', '1', '1', 'C', '1', '0', 'workflow:task:copy', 'person-fill-up', '', '', 100, 1, SYSDATE(), NULL, NULL, '');

-- 请假申请菜单
INSERT INTO sys_menu(menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, btn_class, btn_script, create_org, create_by, create_time, update_by, update_time, remark)
VALUES (171, '请假申请', 91, 1, 'leaveApply', 'demo/leave/index', 1, 0, 'C', '0', '0', 'demo:leave', '#', '', '', 100, 1, SYSDATE(), NULL, NULL, '请假申请菜单'),
       (1281, '申请查询', 171, 1, '#', '', 1, 0, 'F', '0', '0', 'demo:leave:query', 'eye', '', '', 100, 1, SYSDATE(), NULL, NULL, ''),
       (1282, '申请新增', 171, 2, '#', '', 1, 0, 'F', '0', '0', 'demo:leave:add', 'plus-square', 'btn btn-light-primary', 'handleCreate', 100, 1, SYSDATE(), NULL, NULL, ''),
       (1283, '申请修改', 171, 3, '#', '', 1, 0, 'F', '0', '0', 'demo:leave:edit', 'pencil-square', 'btn btn-light-success', 'handleUpdate@1', 100, 1, SYSDATE(), NULL, NULL, ''),
       (1284, '申请删除', 171, 4, '#', '', 1, 0, 'F', '0', '0', 'demo:leave:remove', 'dash-square', 'btn btn-light-danger', 'handleDelete@0', 100, 1, SYSDATE(), NULL, NULL, ''),
       (1285, '申请导出', 171, 5, '#', '', 1, 0, 'F', '0', '0', 'demo:leave:export', 'cloud-download', 'btn btn-light-info', 'handleExport', 100, 1, SYSDATE(), NULL, NULL, '');

-- 业务状态字典
INSERT INTO sys_dict_type(dict_id, tenant_id, dict_name, dict_type, create_org, create_by, create_time, update_by, update_time, remark)
VALUES (21, '000000', '业务状态', 'wf_business_status', 103, 1, SYSDATE(), NULL, NULL, '业务状态列表'),
       (22, '000000', '表单类型', 'wf_form_type', 103, 1, SYSDATE(), NULL, NULL, '表单类型列表');

INSERT INTO sys_dict_data(dict_code, tenant_id, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_org, create_by, create_time, update_by, update_time, remark)
VALUES (51, '000000', 1, '已撤销', 'cancel', 'wf_business_status', '', 'danger', 'N', 103, 1, SYSDATE(), NULL, NULL, '已撤销'),
       (52, '000000', 2, '草稿', 'draft', 'wf_business_status', '', 'info', 'N', 103, 1, SYSDATE(), NULL, NULL, '草稿'),
       (53, '000000', 3, '待审核', 'waiting', 'wf_business_status', '', 'primary', 'N', 103, 1, SYSDATE(), NULL, NULL, '待审核'),
       (54, '000000', 4, '已完成', 'finish', 'wf_business_status', '', 'success', 'N', 103, 1, SYSDATE(), NULL, NULL, '已完成'),
       (55, '000000', 5, '已作废', 'invalid', 'wf_business_status', '', 'danger', 'N', 103, 1, SYSDATE(), NULL, NULL, '已作废'),
       (56, '000000', 6, '已退回', 'back', 'wf_business_status', '', 'danger', 'N', 103, 1, SYSDATE(), NULL, NULL, '已退回'),
       (57, '000000', 7, '已终止', 'termination', 'wf_business_status', '', 'danger', 'N', 103, 1, SYSDATE(), NULL, NULL, '已终止'),
       (61, '000000', 1, '自定义表单', 'static', 'wf_form_type', '', 'success', 'N', 103, 1, SYSDATE(), NULL, NULL, '自定义表单'),
       (62, '000000', 2, '动态表单', 'dynamic', 'wf_form_type', '', 'primary', 'N', 103, 1, SYSDATE(), NULL, NULL, '动态表单');
