1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# 部门无限极分类案例的建表sql
CREATE TABLE `t_department` (
`id` smallint(6) unsigned NOT NULL AUTO_INCREMENT COMMENT '部门ID',
`name` varchar(45) NOT NULL DEFAULT '""' COMMENT '部门名称',
`created_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `name_UNIQUE` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='部门信息表';
CREATE TABLE `t_department_tree` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`children_id` SMALLINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '子节点ID',
`parent_id` SMALLINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '父节点ID',
`depth`SMALLINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '深度',
PRIMARY KEY (`id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='部门关系树,children_id=parent_id则为初始节点';
INSERT INTO `t_department` (`id`, `name`, `created_time`, `updated_time`)
VALUES
(1, '拓展与加盟中心', '2018-12-19 18:16:10', '2018-12-19 18:17:01'),
(2, '产品中心', '2018-12-19 18:16:10', '2018-12-19 18:17:02'),
(3, '运营中心', '2018-12-19 18:16:10', '2018-12-19 18:17:03'),
(4, '增值与服务中心', '2018-12-19 18:16:10', '2018-12-19 18:17:04'),
(5, '后端支持', '2018-12-19 18:16:10', '2018-12-19 18:17:04'),
(6, '运营管理部', '2019-06-14 12:38:58.000', '2019-06-14 12:38:58.000'),
(7, '客服管理部', '2019-06-14 12:39:11.000', '2019-06-14 12:39:11.000');
INSERT INTO `t_department_tree` (`children_id`,`parent_id`,`depth`)
VALUES
(1,1,0),
(2,2,0),
(3,3,0),
(4,4,0),
(5,5,0),
(6,6,0),
(6,3,1),
(7,3,1),
(7,7,0);
|