/*
 Navicat Premium Data Transfer

 Source Server         : database
 Source Server Type    : MySQL
 Source Server Version : 50737
 Source Host           : 127.0.0.1:3306
 Source Schema         : database

 Target Server Type    : MySQL
 Target Server Version : 50737
 File Encoding         : 65001

 Date: 01/01/2022 00:00:00
*/

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for sa_flow_group
-- ----------------------------
DROP TABLE IF EXISTS `__PREFIX__flow_group`;
CREATE TABLE `__PREFIX__flow_group` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'id',
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '名称',
  `createtime` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间',
  `createby` int(11) DEFAULT NULL COMMENT '创建人',
  `updatetime` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `updateby` int(11) DEFAULT NULL COMMENT '更新人',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- ----------------------------
-- Records of sa_flow_group
-- ----------------------------
INSERT INTO `__PREFIX__flow_group` VALUES ('1', '行政', '2022-05-16 23:23:30', '1', '2022-05-16 23:23:30', '1');
INSERT INTO `__PREFIX__flow_group` VALUES ('2', '财务', '2022-06-19 19:48:58', '1', '2022-06-19 19:48:58', '1');
INSERT INTO `__PREFIX__flow_group` VALUES ('3', '分组1', '2022-06-19 19:48:56', '1', '2022-06-19 19:48:56', '1');
SET FOREIGN_KEY_CHECKS=1;

SET FOREIGN_KEY_CHECKS=0;

DROP TABLE IF EXISTS `__PREFIX__flow_instance`;
CREATE TABLE `__PREFIX__flow_instance` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'id',
  `originator` char(36) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '发起人',
  `scheme` char(36) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '流程id',
  `createtime` datetime DEFAULT NULL COMMENT '创建时间',
  `instancestatus` int(11) NOT NULL COMMENT '0 草稿1 进行中 2 完成 3 取消',
  `bizobjectid` char(36) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '业务表Id',
  `instancecode` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '实例编码',
  `completedtime` datetime NOT NULL COMMENT '完成时间',
  `title` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '流程标题',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8 COMMENT='流程实例';
SET FOREIGN_KEY_CHECKS=1;


SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for sa_flow_scheme
-- ----------------------------
DROP TABLE IF EXISTS `__PREFIX__flow_scheme`;
CREATE TABLE `__PREFIX__flow_scheme` (
  `id` int(10) NOT NULL AUTO_INCREMENT COMMENT 'id',
  `code` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '流程代码',
  `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '流程名称',
  `type` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '流程类型',
  `version` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '版本',
  `canuser` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '发起人',
  `process` longtext CHARACTER SET utf8 COLLATE utf8_general_ci COMMENT '流程json',
  `formitems` text CHARACTER SET utf8 COLLATE utf8_general_ci COMMENT '表单代码',
  `sort` double DEFAULT NULL COMMENT '排序',
  `remark` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '备注',
  `createtime` datetime DEFAULT NULL COMMENT '创建时间',
  `createby` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '创建人',
  `updatetime` datetime DEFAULT NULL COMMENT '更新时间',
  `updateby` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '更新人',
  `bizscheme` varchar(255) DEFAULT '' COMMENT '对应业务表',
  `isstop` int(1) unsigned zerofill DEFAULT '0' COMMENT '状态',
  `group` int(11) DEFAULT NULL COMMENT '分组id',
  `icon` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT 'el-icon-s-custom' COMMENT '图标',
  `background` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT 'rgba(177, 118, 66, 1)' COMMENT '颜色',
  `tgId` int(11) unsigned zerofill DEFAULT NULL COMMENT 'tgId',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=45 DEFAULT CHARSET=utf8 COMMENT='流程管理';

INSERT INTO `__PREFIX__flow_scheme` VALUES ('33', 'leave', '请假', 'scheme', null, null, '{\"type\":\"ROOT\",\"name\":\"发起人\",\"id\":\"10000\",\"props\":{\"type\":\"ASSIGN_USER\",\"mode\":\"AND\",\"timeLimit\":{\"type\":\"HOUR\",\"limit\":0,\"event\":{\"type\":\"PASS\",\"loop\":false,\"loopTime\":0}},\"sign\":false,\"userEmpty\":\"TO_PASS\",\"leaderLevel\":1,\"endCondition\":\"TOP\",\"targetObj\":{\"multiple\":false,\"roles\":[],\"objs\":[{\"id\":1,\"type\":\"dept\",\"name\":\"北京总部\"}]}},\"node\":{\"id\":\"34962544045\",\"pid\":\"10000\",\"name\":\"审批人1\",\"type\":\"SP\",\"node\":{\"id\":\"56610885785\",\"pid\":\"34962544045\",\"name\":\"审批人\",\"type\":\"SP\",\"props\":{\"type\":\"ROLE\",\"mode\":\"AND\",\"timeLimit\":{\"type\":\"HOUR\",\"limit\":0,\"event\":{\"type\":\"PASS\",\"loop\":false,\"loopTime\":0}},\"sign\":false,\"userEmpty\":\"TO_PASS\",\"leaderLevel\":1,\"endCondition\":\"TOP\",\"targetObj\":{\"multiple\":false,\"roles\":[3,4],\"objs\":[{\"id\":1,\"type\":\"user\",\"name\":\"权栈\"}]}}},\"props\":{\"type\":\"ROLE\",\"mode\":\"AND\",\"timeLimit\":{\"type\":\"HOUR\",\"limit\":0,\"event\":{\"type\":\"PASS\",\"loop\":false,\"loopTime\":0}},\"sign\":false,\"userEmpty\":\"TO_PASS\",\"leaderLevel\":1,\"endCondition\":\"TOP\",\"targetObj\":{\"multiple\":false,\"roles\":[2,3,5],\"objs\":[]}}}}', '{\"widgetList\":[{\"type\":\"date\",\"icon\":\"date-field\",\"formItemFlag\":true,\"options\":{\"name\":\"starttime\",\"label\":\"开始时间\",\"labelAlign\":\"\",\"type\":\"date\",\"defaultValue\":null,\"placeholder\":\"\",\"columnWidth\":\"200px\",\"size\":\"\",\"labelWidth\":null,\"labelHidden\":false,\"readonly\":false,\"disabled\":false,\"hidden\":false,\"clearable\":true,\"editable\":false,\"format\":\"yyyy-MM-dd\",\"valueFormat\":\"yyyy-MM-dd\",\"required\":false,\"validation\":\"\",\"validationHint\":\"\",\"customClass\":[],\"labelIconClass\":null,\"labelIconPosition\":\"rear\",\"labelTooltip\":null,\"onCreated\":\"\",\"onMounted\":\"\",\"onChange\":\"\",\"onFocus\":\"\",\"onBlur\":\"\",\"onValidate\":\"\"},\"id\":\"date78914\"},{\"type\":\"date\",\"icon\":\"date-field\",\"formItemFlag\":true,\"options\":{\"name\":\"endtime\",\"label\":\"结束时间\",\"labelAlign\":\"\",\"type\":\"date\",\"defaultValue\":null,\"placeholder\":\"\",\"columnWidth\":\"200px\",\"size\":\"\",\"labelWidth\":null,\"labelHidden\":false,\"readonly\":false,\"disabled\":false,\"hidden\":false,\"clearable\":true,\"editable\":false,\"format\":\"yyyy-MM-dd\",\"valueFormat\":\"yyyy-MM-dd\",\"required\":false,\"validation\":\"\",\"validationHint\":\"\",\"customClass\":[],\"labelIconClass\":null,\"labelIconPosition\":\"rear\",\"labelTooltip\":null,\"onCreated\":\"\",\"onMounted\":\"\",\"onChange\":\"\",\"onFocus\":\"\",\"onBlur\":\"\",\"onValidate\":\"\"},\"id\":\"date54531\"},{\"type\":\"textarea\",\"icon\":\"textarea-field\",\"formItemFlag\":true,\"options\":{\"name\":\"remark\",\"label\":\"请假原因\",\"labelAlign\":\"\",\"rows\":3,\"defaultValue\":\"\",\"placeholder\":\"\",\"columnWidth\":\"200px\",\"size\":\"\",\"labelWidth\":null,\"labelHidden\":false,\"readonly\":false,\"disabled\":false,\"hidden\":false,\"required\":false,\"validation\":\"\",\"validationHint\":\"\",\"customClass\":\"\",\"labelIconClass\":null,\"labelIconPosition\":\"rear\",\"labelTooltip\":null,\"minLength\":null,\"maxLength\":null,\"showWordLimit\":false,\"onCreated\":\"\",\"onMounted\":\"\",\"onInput\":\"\",\"onChange\":\"\",\"onFocus\":\"\",\"onBlur\":\"\",\"onValidate\":\"\"},\"id\":\"textarea31440\"}],\"formConfig\":{\"modelName\":\"formData\",\"refName\":\"vForm\",\"rulesName\":\"rules\",\"labelWidth\":80,\"labelPosition\":\"left\",\"size\":\"\",\"labelAlign\":\"label-left-align\",\"cssCode\":\"\",\"customClass\":\"\",\"functions\":\"\",\"layoutType\":\"PC\",\"onFormCreated\":\"\",\"onFormMounted\":\"\",\"onFormDataChange\":\"\"}}', null, '请假申请', null, null, '2022-05-14 12:16:58', null, '__PREFIX__leave', '0', '1', 'el-icon-s-tools', 'rgba(59, 191, 33, 1)', '00000000001');

SET FOREIGN_KEY_CHECKS=1;


SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for sa_flow_task
-- ----------------------------
DROP TABLE IF EXISTS `__PREFIX__flow_task`;
CREATE TABLE `__PREFIX__flow_task` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `previd` varchar(255) DEFAULT NULL,
  `prevstepid` varchar(255) DEFAULT NULL,
  `receiveid` char(36) DEFAULT NULL COMMENT '审批人',
  `stepid` varchar(255) DEFAULT NULL COMMENT '步骤id',
  `flowid` int(11) DEFAULT NULL COMMENT '流程id',
  `stepname` varchar(255) DEFAULT NULL COMMENT '步骤名称',
  `instanceid` char(36) DEFAULT NULL COMMENT '实例id',
  `type` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '类型',
  `tittle` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '标题',
  `senderid` int(11) DEFAULT NULL COMMENT '上一步审核人',
  `opentime` datetime DEFAULT NULL COMMENT '打开流程时间',
  `completedtime` datetime DEFAULT NULL COMMENT '审批时间',
  `comment` varchar(255) DEFAULT NULL COMMENT '部门负责人',
  `isSign` varchar(255) DEFAULT NULL,
  `status` int(10) DEFAULT NULL COMMENT '状态 0-审批中 2-完成 3-取消',
  `note` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '备注',
  `sort` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '排序',
  `createtime` datetime DEFAULT NULL COMMENT '创建时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=123 DEFAULT CHARSET=utf8 COMMENT='流程任务';
SET FOREIGN_KEY_CHECKS=1;


SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for sa_leave
-- ----------------------------
DROP TABLE IF EXISTS `__PREFIX__leave`;
CREATE TABLE `__PREFIX__leave` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'id',
  `code` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '编码',
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '名称',
  `starttime` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '开始时间',
  `endtime` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '结束时间',
  `remark` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '请假原因',
  `user` int(11) DEFAULT NULL COMMENT '请假人',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=80 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
SET FOREIGN_KEY_CHECKS=1;

DROP view IF EXISTS `__PREFIX__flow_field_view`;
CREATE ALGORITHM=UNDEFINED SQL SECURITY DEFINER VIEW `__PREFIX__flow_field_view` AS 
select `a`.`TABLE_SCHEMA` AS `TABLE_SCHEMA`,`a`.`COLUMN_KEY` AS `COLUMN_KEY`,
`a`.`COLUMN_NAME` AS `field`,`a`.`TABLE_NAME` AS `table_name`,
ifnull(`a`.`COLUMN_COMMENT`,`a`.`COLUMN_NAME`) AS `fieldname`,1 
AS `read`,0 AS `write`,'' AS `id`,'' AS `flow_id`,'' AS `node_id` 
from `information_schema`.`COLUMNS` `a`;

DROP view IF EXISTS `__PREFIX__flow_instace_view`;
CREATE ALGORITHM=UNDEFINED SQL SECURITY DEFINER VIEW `__PREFIX__flow_instace_view` AS
select a.id,a.title,GROUP_CONCAT(c.nickname) as operater,
case 
when instancestatus =2 then '已归档'
ELSE
 GROUP_CONCAT(b.stepname) end as stepname,a.createtime,a.scheme
,a.instancestatus,a.originator from sa_flow_instance a
left join (select * from  sa_flow_task where `status` = 0 ) b on a.id= b.instanceid
left join sa_admin c on b.receiveid = c.id
group by a.id ,a.title,a.createtime,a.scheme,a.instancestatus,a.originator;


DROP view IF EXISTS `__PREFIX__flow_workitem_view`;
CREATE ALGORITHM=UNDEFINED SQL SECURITY DEFINER VIEW `__PREFIX__flow_workitem_view` AS
SELECT b.title,a.id,a.stepname,d.nickname as createby,b.createtime,b.scheme,a.`status`,a.`comment`,a.instanceid,
a.createtime as taskcreatetime,a.completedtime,b.instancestatus,a.receiveid,c.nickname as receivename
from sa_flow_task a
LEFT JOIN sa_flow_instance b on a.instanceid = b.id
LEFT JOIN sa_admin c on a.receiveid = c.id
LEFT JOIN sa_admin d on b.originator = d.id;