-- 系统用户表
CREATE TABLE `sys_user` (
  `id`          BIGINT       NOT NULL AUTO_INCREMENT
  COMMENT '主键',
  `user_name`   VARCHAR(100) NOT NULL
  COMMENT '用户名',
  `password`    VARCHAR(100) NOT NULL
  COMMENT '密码',
  `code`        VARCHAR(100) NOT NULL
  COMMENT '编号',
  `gender`      SMALLINT              DEFAULT '0'
  COMMENT '性别,0:男,1:女',
  `email`       VARCHAR(100)          DEFAULT NULL
  COMMENT '邮箱',
  `full_name`   VARCHAR(100)          DEFAULT NULL
  COMMENT '姓名',
  `status`      VARCHAR(100) NOT NULL
  COMMENT '状态,0:启用,1:禁用',
  `create_date` DATETIME                  DEFAULT NULL
  COMMENT '新增日期',
  `create_user` VARCHAR(100)          DEFAULT NULL
  COMMENT '新增人',
  `update_date` DATETIME                  DEFAULT NULL
  COMMENT '更新日期',
  `update_user` VARCHAR(100)          DEFAULT NULL
  COMMENT '更新人',
  `mobile`      VARCHAR(20) COMMENT '手机号',
  `remark`      TEXT,
  PRIMARY KEY (`id`),
  UNIQUE KEY `user_name_unique` (`user_name`),
  UNIQUE KEY `code_unique` (`code`)
)
  ENGINE = InnoDB
  AUTO_INCREMENT = 4
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_0900_ai_ci
-- 用户角色表
CREATE TABLE `sys_user_role` (
  `id`      BIGINT NOT NULL AUTO_INCREMENT
  COMMENT '主键',
  `user_id` BIGINT NOT NULL
  COMMENT '用户id',
  `role_id` BIGINT NOT NULL
  COMMENT '角色ID',
  PRIMARY KEY (`id`)
)
  ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_general_ci;
-- 系统角色表
CREATE TABLE `sys_role` (
  `id`          BIGINT       NOT NULL AUTO_INCREMENT
  COMMENT '主键',
  `name`        VARCHAR(100) NOT NULL
  COMMENT '角色名称',
  `code`        VARCHAR(100) NOT NULL
  COMMENT '角色编码',
  `remark`      BIGINT                DEFAULT NULL
  COMMENT '备注',
  `status`      SMALLINT     NOT NULL
  COMMENT '状态,0:启用,1:禁用',
  `create_user` BIGINT                DEFAULT NULL
  COMMENT '新增人',
  `create_date` DATETIME              DEFAULT NULL
  COMMENT '新增日期',
  `update_date` DATETIME              DEFAULT NULL
  COMMENT '更新日期',
  `update_user` BIGINT                DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `code_unique` (`code`)
)
  ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_general_ci;
-- 系统菜单表
CREATE TABLE `sys_menu` (
  `id`          BIGINT       NOT NULL AUTO_INCREMENT
  COMMENT '主键',
  `parent_id`   BIGINT                DEFAULT NULL
  COMMENT '父级id',
  `name`        VARCHAR(100) NOT NULL
  COMMENT '名称',
  `type`        SMALLINT     NOT NULL
  COMMENT '类型,0:目录,1:菜单,2:按钮',
  `url`         TEXT COMMENT 'url',
  `perms`       TEXT COMMENT '权限',
  `icon`        VARCHAR(100)          DEFAULT NULL
  COMMENT '图标',
  `seq`         INT                   DEFAULT NULL
  COMMENT '排序',
  `create_user` BIGINT                DEFAULT NULL
  COMMENT '新增人',
  `create_date` DATETIME              DEFAULT NULL
  COMMENT '新增日期',
  `update_user` BIGINT                DEFAULT NULL
  COMMENT '更新人',
  `update_date` DATETIME              DEFAULT NULL
  COMMENT '更新日期',
  PRIMARY KEY (`id`),
  UNIQUE KEY `name_unique` (`name`)
)
  ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_general_ci;
-- 角色菜单表
CREATE TABLE `sys_role_menu` (
  `id`      BIGINT NOT NULL AUTO_INCREMENT
  COMMENT '主键',
  `role_id` BIGINT NOT NULL
  COMMENT '角色ID',
  `menu_id` BIGINT NOT NULL
  COMMENT '菜单ID',
  PRIMARY KEY (`id`)
)
  ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_general_ci;
-- 系统日志表
CREATE TABLE `sys_log` (
  `id`           BIGINT       NOT NULL AUTO_INCREMENT
  COMMENT '主键',
  `user_name`    VARCHAR(100) NOT NULL
  COMMENT '用户名',
  `user_code`    VARCHAR(100) NOT NULL
  COMMENT '用户编码',
  `operation`    VARCHAR(100) NOT NULL
  COMMENT '操作',
  `content`      TEXT COMMENT '操作内容',
  `ip`           VARCHAR(100)          DEFAULT NULL
  COMMENT 'ip地址',
  `operate_date` DATETIME     NOT NULL
  COMMENT '操作日期',
  `elapsed_time` BIGINT                DEFAULT NULL
  COMMENT '耗时',
  PRIMARY KEY (`id`)
)
  ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_general_ci;
-- 系统字典类型表
CREATE TABLE `sys_dict_type` (
  `id`          BIGINT       NOT NULL AUTO_INCREMENT
  COMMENT '主键',
  `name`        VARCHAR(100) NOT NULL
  COMMENT '名称',
  `code`        VARCHAR(100) NOT NULL
  COMMENT '编码',
  `create_user` BIGINT                DEFAULT NULL
  COMMENT '新增人',
  `create_date` DATE                  DEFAULT NULL
  COMMENT '新增日期',
  `update_user` BIGINT                DEFAULT NULL
  COMMENT '更新人',
  `update_date` DATETIME              DEFAULT NULL
  COMMENT '更新日期',
  PRIMARY KEY (`id`),
  UNIQUE KEY `code_unique` (`code`)
)
  ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_general_ci;
-- 系统字典表
CREATE TABLE `sys_dict_item` (
  `id`          BIGINT       NOT NULL AUTO_INCREMENT
  COMMENT '主键',
  `type_id`     BIGINT       NOT NULL
  COMMENT '类型ID',
  `type_name`   VARCHAR(100) NOT NULL
  COMMENT '类型名称',
  `type_code`   VARCHAR(100) NOT NULL
  COMMENT '类型编码',
  `name`        VARCHAR(100) NOT NULL
  COMMENT '名称',
  `key`         VARCHAR(100) NOT NULL
  COMMENT '键',
  `value`       VARCHAR(100) NOT NULL
  COMMENT '值',
  `remark`      VARCHAR(100)          DEFAULT NULL
  COMMENT '备注',
  `create_user` BIGINT                DEFAULT NULL
  COMMENT '新增人',
  `create_date` DATETIME              DEFAULT NULL
  COMMENT '新增日期',
  `update_id`   BIGINT                DEFAULT NULL
  COMMENT '更新人',
  `update_date` DATETIME              DEFAULT NULL
  COMMENT '更新日期',
  PRIMARY KEY (`id`),
  UNIQUE KEY `typeid_union_key_unique` (`type_id`, `key`)
)
  ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_general_ci;
-- 流程定义表
CREATE TABLE `biz_workflow` (
  `id`          BIGINT       NOT NULL AUTO_INCREMENT
  COMMENT '主键',
  `code`        VARCHAR(100) NOT NULL
  COMMENT '编码',
  `name`        VARCHAR(100) NOT NULL
  COMMENT '名称',
  `xml`         TEXT         NOT NULL
  COMMENT 'xml',
  `svg`         TEXT         NOT NULL
  COMMENT 'svg',
  `status`      SMALLINT              DEFAULT NULL
  COMMENT '发布,0:已发布,1:未发布',
  `create_user` BIGINT                DEFAULT NULL
  COMMENT '新增人',
  `create_date` DATETIME              DEFAULT NULL
  COMMENT '创建日期',
  `update_date` DATETIME              DEFAULT NULL
  COMMENT '更新日期',
  `更新人`         BIGINT                DEFAULT NULL
  COMMENT '更新人',
  PRIMARY KEY (`id`),
  UNIQUE KEY `biz_workflow_unique` (`code`)
)
  ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_general_ci;
INSERT INTO `sys_menu` (id, parent_id, name, url, perms, type, icon, seq, create_user, create_date) VALUES
  (1, 0, '系统管理', NULL, NULL, 0, 'system', 0, 1, now()),
  (2, 1, '管理员列表', 'sys/user', NULL, 1, 'admin', 1, 1, now()),
  (3, 1, '角色管理', 'sys/role', NULL, 1, 'role', 2, 1, now()),
  (4, 1, '菜单管理', 'sys/menu', NULL, 1, 'menu', 3, 1, now()),
  (6, 1, '定时任务', 'job/schedule', NULL, 1, 'job', 5, 1, now()),
  (7, 6, '查看', NULL, 'sys:schedule:list,sys:schedule:info', 2, NULL, 0, 1, now()),
  (8, 6, '新增', NULL, 'sys:schedule:save', 2, NULL, 0, 1, now()),
  (9, 6, '修改', NULL, 'sys:schedule:update', 2, NULL, 0, 1, now()),
  (10, 6, '删除', NULL, 'sys:schedule:delete', 2, NULL, 0, 1, now()),
  (11, 6, '暂停', NULL, 'sys:schedule:pause', 2, NULL, 0, 1, now()),
  (12, 6, '恢复', NULL, 'sys:schedule:resume', 2, NULL, 0, 1, now()),
  (13, 6, '立即执行', NULL, 'sys:schedule:run', 2, NULL, 0, 1, now()),
  (14, 6, '日志列表', NULL, 'sys:schedule:log', 2, NULL, 0, 1, now()),
  (15, 2, '查看', NULL, 'sys:user:list,sys:user:info', 2, NULL, 0, 1, now()),
  (16, 2, '新增', NULL, 'sys:user:save,sys:role:select', 2, NULL, 0, 1, now()),
  (17, 2, '修改', NULL, 'sys:user:update,sys:role:select', 2, NULL, 0, 1, now()),
  (18, 2, '删除', NULL, 'sys:user:delete', 2, NULL, 0, 1, now()),
  (19, 3, '查看', NULL, 'sys:role:list,sys:role:info', 2, NULL, 0, 1, now()),
  (20, 3, '新增', NULL, 'sys:role:save,sys:menu:list', 2, NULL, 0, 1, now()),
  (21, 3, '修改', NULL, 'sys:role:update,sys:menu:list', 2, NULL, 0, 1, now()),
  (22, 3, '删除', NULL, 'sys:role:delete', 2, NULL, 0, 1, now()),
  (23, 4, '查看', NULL, 'sys:menu:list,sys:menu:info', 2, NULL, 0, 1, now()),
  (24, 4, '新增', NULL, 'sys:menu:save,sys:menu:select', 2, NULL, 0, 1, now()),
  (25, 4, '修改', NULL, 'sys:menu:update,sys:menu:select', 2, NULL, 0, 1, now()),
  (26, 4, '删除', NULL, 'sys:menu:delete', 2, NULL, 0, 1, now()),
  (27, 1, '参数管理', 'sys/config', 'sys:config:list,sys:config:info,sys:config:save,sys:config:update,sys:config:delete', 1, 'config', 6, 1, now()),
  (29, 1, '系统日志', 'sys/log', 'sys:log:list', 1, 'log', 7, 1, now()),
  (36, 0, '设备管理', '', '', 0, 'shouye', 1, 1, now()),
  (45, 36, '设备类型', 'devices/device/devicetype', '', 1, 'menu', 0, 1, now()),
  (46, 36, '设备实例', 'devices/deviceExample/deviceExa', '', 1, 'editor', 3, 1, now()),
  (47, 36, '设备厂家', 'devices/deviceFactory/deviceFac', '', 1, 'role', 1, 1, now()),
  (49, 45, '查看', '', 'device:devicetype:list,device:devicetype:info', 2, '', 0, 1, now()),
  (52, 45, '修改状态', '', 'device:devicetype:status', 2, '', 0, 1, now()),
  (53, 46, '查看', NULL, 'device:accessdeviceinfo:list,device:accessdeviceinfo:info', 2, NULL, 0, 1, now()),
  (54, 46, '新增', NULL, 'device:accessdeviceinfo:save', 2, NULL, 0, 1, now()),
  (55, 46, '删除', NULL, 'device:accessdeviceinfo:delete', 2, NULL, 0, 1, now()),
  (56, 46, '修改', NULL, 'device:accessdeviceinfo:update,device:accessdeviceinfo:updateStatus', 2, NULL, 0, 1, now()),
  (57, 47, '查看', '', 'device:manufacturer:list,device:manufacturer:info', 2, '', 0, 1, now()),
  (60, 47, '修改状态', '', 'device:manufacturer:status', 2, '', 0, 1, now()),
  (65, 36, '区域管理', 'devices/region/index', '', 1, 'config', 2, 1, now()),
  (66, 65, '新增', '', 'device:deviceregion:save', 2, '', 0, 1, now()),
  (67, 65, '查看', '', 'device:deviceregion:list,device:deviceregion:info', 2, '', 0, 1, now()),
  (68, 65, '更新', '', 'device:deviceregion:update', 2, '', 0, 1, now()),
  (69, 65, '删除', '', 'device:deviceregion:delete', 2, '', 0, 1, now()),
  (72, 45, '保存订阅地址', '', 'device:devicetypetemplate:updateSubscribeUrl', 2, '', 0, 1, now()),
  (73, 45, '修改类型模板状态', '', 'device:devicetypetemplate:updateStatus', 2, '', 0, 1, now()),
  (74, 36, '设备告警', 'devices/deviceReport/index', '', 1, '', 5, 1, now());