SET NAMES utf8mb4;
SET
FOREIGN_KEY_CHECKS = 0;

DROP TABLE IF EXISTS `sample_cron_exclusive_task`;
CREATE TABLE `sample_cron_exclusive_task`
(
    `id`          varchar(32) NOT NULL,
    `running`     int          NOT NULL DEFAULT 0,
    `update_time` datetime     NOT NULL,
    `node_tag`    varchar(100) NOT NULL,
    `md5`         varchar(50)  NOT NULL,
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB    ROW_FORMAT = Dynamic;

-- ----------------------------

-- Table structure for sample_lock

-- ----------------------------

DROP TABLE IF EXISTS `sample_lock`;
CREATE TABLE `sample_lock`
(
    `id`          varchar(32) NOT NULL,
    `insert_time` datetime    NOT NULL,
    `expire_time` datetime    NOT NULL,
    `node`        varchar(25) NOT NULL,
    `running`     tinyint(1) NOT NULL,
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB;



-- ----------------------------

-- Table structure for sample_role

-- ----------------------------

DROP TABLE IF EXISTS `sample_role`;
CREATE TABLE `sample_role`
(
    `id`          varchar(32) NOT NULL,
    `info`        varchar(255) NULL DEFAULT NULL,
    `list`        int         NOT NULL,
    `name`        varchar(30) NOT NULL,
    `system_role` int         NOT NULL,
    `unit_id`     varchar(32) NOT NULL,
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE INDEX `uk_name`(`name`) USING BTREE
) ENGINE = InnoDB;

-- ----------------------------


-- ----------------------------

-- Table structure for sample_schedule_log

-- ----------------------------

DROP TABLE IF EXISTS `sample_schedule_log`;
CREATE TABLE `sample_schedule_log`
(
    `id`           varchar(32)  NOT NULL,
    `by_system`    bit(1)       NOT NULL,
    `current_cron` varchar(50)  NOT NULL,
    `end_time`     datetime     NOT NULL,
    `exec_time`    bigint       NOT NULL,
    `start_time`   datetime     NOT NULL,
    `task_name`    varchar(100) NOT NULL,
    PRIMARY KEY (`id`) USING BTREE,
    INDEX          `idx_exec_time`(`exec_time`) USING BTREE
) ENGINE = InnoDB;

-- ----------------------------

-- Table structure for sample_sequence

-- ----------------------------

DROP TABLE IF EXISTS `sample_sequence_num`;
CREATE TABLE `sample_sequence_num`
(
    `id`           varchar(30) NOT NULL,
    `insert_time`  datetime    NOT NULL COMMENT '插入时间',
    `update_time`  datetime    NOT NULL COMMENT '更新时间',
    `sequence_num` bigint      NOT NULL COMMENT '顺序号',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB;

-- ----------------------------

-- Table structure for sample_system_info

-- ----------------------------

DROP TABLE IF EXISTS `sample_system_info`;
CREATE TABLE `sample_system_info`
(
    `id`          varchar(32)   NOT NULL,
    `conf_type`   varchar(20)   NOT NULL,
    `json_str`    varchar(4000) NOT NULL,
    `update_time` datetime NULL DEFAULT NULL,
    `user_id`     varchar(32)   NOT NULL,
    `ziped`       bit(1)        NOT NULL,
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE INDEX `uk_conftype_uid`(`conf_type`, `user_id`) USING BTREE
) ENGINE = InnoDB;

-- ----------------------------

-- Table structure for sample_system_log

-- ----------------------------

DROP TABLE IF EXISTS `sample_system_log`;
CREATE TABLE `sample_system_log`
(
    `id`       varchar(32)  NOT NULL,
    `info`     varchar(300) NOT NULL,
    `ip`       varchar(50)  NOT NULL,
    `log_type` varchar(10)  NOT NULL,
    `op_time`  datetime     NOT NULL,
    `user_id`  varchar(32)  NOT NULL,
    PRIMARY KEY (`id`) USING BTREE,
    INDEX      `idx_user_id`(`user_id`) USING BTREE,
    INDEX      `idx_log_type`(`log_type`) USING BTREE,
    CONSTRAINT `fk_system_log_user` FOREIGN KEY (`user_id`) REFERENCES `sample_user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB;

-- ----------------------------

-- Table structure for sample_unit

-- ----------------------------

DROP TABLE IF EXISTS `sample_unit`;
CREATE TABLE `sample_unit`
(
    `id`          varchar(32)  NOT NULL,
    `list`        int          NOT NULL,
    `name`        varchar(100) NOT NULL,
    `code`        varchar(20)  NOT NULL,
    `parent_id`   varchar(32) NULL DEFAULT NULL,
    `unit_level`  int          NOT NULL,
    `global_list` varchar(30)  NOT NULL,
    PRIMARY KEY (`id`) USING BTREE,
    INDEX `idx_parent_id`(`parent_id`) USING BTREE
) ENGINE = InnoDB;

-- ----------------------------

-- Table structure for sample_user

-- ----------------------------

DROP TABLE IF EXISTS `sample_user`;
CREATE TABLE `sample_user`
(
    `id`         varchar(32)  NOT NULL,
    `email`      varchar(100) NULL DEFAULT NULL,
    `fax`        varchar(50) NULL DEFAULT NULL,
    `login_name` varchar(20)  NOT NULL,
    `male`       bit(1)       NOT NULL,
    `mobile`     varchar(50)  NOT NULL,
    `name`       varchar(50)  NOT NULL,
    `name_py`    varchar(100) NOT NULL,
    `passwd`     varchar(512) NOT NULL,
    `status`     varchar(10)  NOT NULL,
    `tel`        varchar(50) NULL DEFAULT NULL,
    `role_id`    varchar(32)  NOT NULL,
    `unit_id`    varchar(32)  NOT NULL,
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE INDEX `uk_login_name`(`login_name`) USING BTREE,
    INDEX        `idx_role_id`(`role_id`) USING BTREE,
    INDEX        `idx_unit_id`(`unit_id`) USING BTREE,
    CONSTRAINT `fk_user_role` FOREIGN KEY (`role_id`) REFERENCES `sample_role` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
    CONSTRAINT `fk_user_unit` FOREIGN KEY (`unit_id`) REFERENCES `sample_unit` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB;

DROP TABLE IF EXISTS `sample_menu`;
CREATE TABLE `sample_menu`
(
    `id` varchar(32)  NOT NULL COMMENT '资源ID',
    `name` varchar(32)  NOT NULL COMMENT '资源名称',
    `path` varchar(64)  NOT NULL COMMENT '路由路径',
    `component` varchar(64)  NOT NULL COMMENT 'Vue组件',
    `menu_type` varchar(20)  NOT NULL COMMENT '菜单类型（FIRST_MENU:一级菜单,SUB_MENU:子菜单,BUTTON:按钮权限）',
    `parent_id` varchar(32)  NOT NULL COMMENT '父ID',
    `icon` varchar(32)  NULL DEFAULT NULL COMMENT '图标',
    `order_index` int NOT NULL COMMENT '顺序',
    `create_user` varchar(50)  NOT NULL COMMENT '创建人',
    `create_time` datetime NOT NULL COMMENT '创建时间',
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE INDEX `uk_path`(`path`) USING BTREE,
    INDEX `idx_parent_id`(`parent_id`) USING BTREE
) ENGINE = InnoDB  COMMENT = '菜单资源表';


-- ----------------------------
-- Table structure for sample_menu
-- ----------------------------
DROP TABLE IF EXISTS `sample_interface`;
CREATE TABLE `sample_interface`  (
     `id` varchar(32)  NOT NULL COMMENT 'ID',
     `name` varchar(32)  NOT NULL COMMENT '名称',
     `interface_url` varchar(200)  NOT NULL COMMENT '接口URL',
     `interface_type` varchar(20)  NOT NULL COMMENT '接口类型（DIR:目录,API:接口）',
     `parent_id` varchar(32)  NOT NULL COMMENT '父节点',
     `code` varchar(50)  NOT NULL DEFAULT '-1' COMMENT '用来查询后代节点',
     `method_type` varchar(60)  NOT NULL COMMENT 'http类型',
     `order_index` int NOT NULL COMMENT '排序字段',
     `interface_desc` varchar(255)  NULL DEFAULT NULL COMMENT '接口描述',
     `create_user` varchar(50)  NOT NULL COMMENT '创建人',
     `create_time` datetime NOT NULL COMMENT '创建时间',
     PRIMARY KEY (`id`) USING BTREE,
     UNIQUE INDEX `uk_interface_url`(`interface_url`, `method_type`) USING BTREE,
     INDEX `idx_parent_id`(`parent_id`) USING BTREE,
     INDEX `idx_code`(`code`) USING BTREE
) ENGINE = InnoDB  COMMENT = '接口管理';

DROP TABLE IF EXISTS `sample_role_interface`;
CREATE TABLE `sample_role_interface`
(
    `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'ID',
    `role_id`      varchar(32) NOT NULL COMMENT '角色Id',
    `interface_id` varchar(32) NOT NULL COMMENT '接口ID',
    `create_user`    varchar(50)  NOT NULL COMMENT '创建人',
    `create_time`    datetime     NOT NULL COMMENT '创建时间',
    PRIMARY KEY (`id`) USING BTREE,
    INDEX          `fk_ri_role`(`role_id`) USING BTREE,
    INDEX          `fk_ri_interface`(`interface_id`) USING BTREE,
    CONSTRAINT `fk_ri_role` FOREIGN KEY (`role_id`) REFERENCES `sample_role` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
    CONSTRAINT `fk_ri_interface` FOREIGN KEY (`interface_id`) REFERENCES `sample_interface` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB  COMMENT = '角色接口关系表';


DROP TABLE IF EXISTS `sample_role_menu`;
CREATE TABLE `sample_role_menu`
(
    `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'ID',
    `menu_id` varchar(32) NOT NULL COMMENT '菜单ID',
    `role_id`     varchar(32) NOT NULL COMMENT '角色ID',
    `create_user`    varchar(50)  NOT NULL COMMENT '创建人',
    `create_time`    datetime     NOT NULL COMMENT '创建时间',
    PRIMARY KEY (`id`) USING BTREE,
    INDEX         `fk_rm_menu`(`menu_id`) USING BTREE,
    INDEX         `fk_rm_role_id`(`role_id`) USING BTREE,
    CONSTRAINT `fk_rm_menu` FOREIGN KEY (`menu_id`) REFERENCES `sample_menu` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
    CONSTRAINT `fk_rm_role` FOREIGN KEY (`role_id`) REFERENCES `sample_role` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB  COMMENT = '角色菜单关系表';

SET
FOREIGN_KEY_CHECKS = 1;
