feat: 部门列表添加数据权限控制
This commit is contained in:
@@ -3,6 +3,7 @@ package com.youlai.system.mapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.youlai.system.framework.mybatisplus.DataPermission;
|
||||
import com.youlai.system.pojo.entity.SysDept;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
@@ -13,7 +14,7 @@ import java.util.List;
|
||||
@Mapper
|
||||
public interface SysDeptMapper extends BaseMapper<SysDept> {
|
||||
|
||||
// @DataPermission
|
||||
@DataPermission(deptIdColumnName = "id")
|
||||
@Override
|
||||
List<SysDept> selectList(@Param(Constants.WRAPPER) Wrapper<SysDept> queryWrapper);
|
||||
}
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
package com.youlai.system.pojo.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
import com.youlai.system.common.base.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 部门表
|
||||
* @TableName sys_dept
|
||||
*/
|
||||
@TableName(value ="sys_dept")
|
||||
@Data
|
||||
public class SysDept extends BaseEntity {
|
||||
/**
|
||||
@@ -51,7 +47,8 @@ public class SysDept extends BaseEntity {
|
||||
*/
|
||||
private Integer deleted;
|
||||
|
||||
private Long createBy;
|
||||
|
||||
private Long updateBy;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
@@ -48,7 +48,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
List<SysDept> deptList = this.list(
|
||||
new LambdaQueryWrapper<SysDept>()
|
||||
.like(StrUtil.isNotBlank(keywords), SysDept::getName, keywords)
|
||||
.eq(Validator.isNotNull(status), SysDept::getStatus, status)
|
||||
.eq(status != null, SysDept::getStatus, status)
|
||||
.orderByAsc(SysDept::getSort)
|
||||
);
|
||||
|
||||
@@ -64,7 +64,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
for (SysDept dept : deptList) {
|
||||
Long parentId = dept.getParentId();
|
||||
// 不在缓存ID列表的parentId是顶级节点ID,以此作为递归开始
|
||||
if (cacheDeptIds.contains(parentId) == false) {
|
||||
if (!cacheDeptIds.contains(parentId)) {
|
||||
list.addAll(recurDeptList(parentId, deptList));
|
||||
cacheDeptIds.add(parentId); // 避免重复递归
|
||||
}
|
||||
@@ -107,16 +107,30 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
/**
|
||||
* 部门下拉选项
|
||||
*
|
||||
* @return
|
||||
* @return 部门下拉List集合
|
||||
*/
|
||||
@Override
|
||||
public List<Option> listDeptOptions() {
|
||||
List<Option> options =new ArrayList<>();
|
||||
|
||||
List<SysDept> deptList = this.list(new LambdaQueryWrapper<SysDept>()
|
||||
.eq(SysDept::getStatus, StatusEnum.ENABLE.getValue())
|
||||
.select(SysDept::getId, SysDept::getParentId, SysDept::getName)
|
||||
.orderByAsc(SysDept::getSort)
|
||||
);
|
||||
List<Option> options = recurDeptTreeOptions(SystemConstants.ROOT_NODE_ID, deptList);
|
||||
|
||||
Set<Long> parentIds = deptList.stream().map(SysDept::getParentId)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
Set<Long> childrenIds = deptList.stream().map(SysDept::getId)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
for (Long parentId : parentIds) {
|
||||
if(!childrenIds.contains(parentId)){
|
||||
options.addAll(recurDeptTreeOptions(parentId, deptList));
|
||||
}
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user