mysql之table表
DROP TABLE IF EXISTS `auth_department`;
CREATE TABLE `auth_department` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '部门ID',
`department_name` varchar(10) COLLATE utf8_bin NOT NULL COMMENT '部门名称',
`order_num` int(11) unsigned NOT NULL COMMENT '排序',
`status` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '状态,1启用,0.禁用',
`parent_id` int(10) unsigned NOT NULL COMMENT '直属父部门ID',
`creater` varchar(30) COLLATE utf8_bin DEFAULT NULL COMMENT '添加人',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
`modifier` varchar(30) COLLATE utf8_bin DEFAULT NULL COMMENT '修改人',
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
`is_del` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '是否删除(0:否,1:是)',
PRIMARY KEY (`id`) USING BTREE,
KEY `department_name` (`department_name`),
KEY `order_num` (`order_num`),
KEY `status` (`status`),
KEY `parent_id` (`parent_id`),
KEY `create_time` (`create_time`),
KEY `update_time` (`update_time`),
KEY `is_del` (`is_del`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin ROW_FORMAT=DYNAMIC COMMENT='部门表';
pojo实体类
@TableName("auth_department")
@ApiModel(value="Department对象", description="部门表")
public class Department implements Serializable {
private static final long serialVersionUID = 1979258247014728978L;
@TableId(type = IdType.AUTO)
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@ApiModelProperty(value = "部门名称")
private String departmentName;
@ApiModelProperty(value = "排序")
private Integer orderNum;
@ApiModelProperty(value = "状态,1启用,0.禁用")
private Integer status;
@ApiModelProperty(value = "是否删除(0:否,1:是)")
private Integer isDel;
@ApiModelProperty(value = "父部门ID")
private Long parentId;
@ApiModelProperty(value = "添加人")
private String creater;
@ApiModelProperty(value = "添加时间")
private LocalDateTime createTime;
@ApiModelProperty(value = "修改人")
private String modifier;
@ApiModelProperty(value = "修改时间")
private LocalDateTime updateTime;
public String getDepartmentName() {
return departmentName;
}
public void setDepartmentName(String departmentName) {
this.departmentName = departmentName;
}
public Integer getOrderNum() {
return orderNum;
}
public void setOrderNum(Integer orderNum) {
this.orderNum = orderNum;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Integer getIsDel() {
return isDel;
}
public void setIsDel(Integer isDel) {
this.isDel = isDel;
}
public Long getParentId() {
return parentId;
}
public void setParentId(Long parentId) {
this.parentId = parentId;
}
public String getCreater() {
return creater;
}
public void setCreater(String creater) {
this.creater = creater;
}
public LocalDateTime getCreateTime() {
return createTime;
}
public void setCreateTime(LocalDateTime createTime) {
this.createTime = createTime;
}
public String getModifier() {
return modifier;
}
public void setModifier(String modifier) {
this.modifier = modifier;
}
public LocalDateTime getUpdateTime() {
return updateTime;
}
public void setUpdateTime(LocalDateTime updateTime) {
this.updateTime = updateTime;
}
}
ServiceImpl类
/**
* 根据父菜单获取子菜单
*/
private void getChildren(DepartmentQuery query){
//获取当前的子菜单
List<Department> list=baseMapper.selectList(
Wrappers.<Department>lambdaQuery()
.eq(Department::getParentId,query.getId())
.eq(Department::getIsDel,StatusEnum.STATUS_NO.getCode())
.orderByDesc(Department::getOrderNum));
List<DepartmentQuery> vos=list.stream().map(p->{
DepartmentQuery vop=new DepartmentQuery();
vop.setId(p.getId());
vop.setLabel(p.getDepartmentName());
getChildren(vop);
return vop;
}).collect(Collectors.toList());
query.setChildren(vos);
}
/**
* 根据角色id获取权限
*
*/
public List<DepartmentQuery> selectSonDepartmentId(){
//先获取根目录
List<Department> list=baseMapper.selectList(
Wrappers.<Department>lambdaQuery()
.eq(Department::getIsDel,StatusEnum.STATUS_NO.getCode())
.eq(Department::getParentId,0)
.orderByDesc(Department::getOrderNum));
//获取子菜单
List<DepartmentQuery> vos=list.stream().map(po->{
DepartmentQuery voe=new DepartmentQuery();
voe.setId(po.getId());
voe.setLabel(po.getDepartmentName());
getChildren(voe);
return voe;
}).collect(Collectors.toList());
return vos;
}