update 增加归属部门树和单部门查询

This commit is contained in:
AprilWind 2024-04-23 12:19:19 +08:00
parent 11f782ea10
commit 4d40f0052d
2 changed files with 32 additions and 10 deletions

View File

@ -26,11 +26,16 @@ public class SysPostBo extends BaseEntity {
private Long postId;
/**
* 部门id
* 部门id单部门
*/
@NotNull(message = "部门id不能为空")
private Long deptId;
/**
* 归属部门id部门树
*/
private Long belongDeptId;
/**
* 岗位编码
*/

View File

@ -28,6 +28,7 @@ import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* 岗位信息 服务层处理
@ -61,24 +62,40 @@ public class SysPostServiceImpl implements ISysPostService {
.like(StringUtils.isNotBlank(post.getPostCategory()), SysPost::getPostCategory, post.getPostCategory())
.like(StringUtils.isNotBlank(post.getPostName()), SysPost::getPostName, post.getPostName())
.eq(StringUtils.isNotBlank(post.getStatus()), SysPost::getStatus, post.getStatus())
.eq(ObjectUtil.isNotNull(post.getDeptId()), SysPost::getDeptId, post.getDeptId())
.orderByAsc(SysPost::getPostSort)
);
}
/**
* 根据查询条件构建查询包装器
*
* @param bo 查询条件对象
* @return 构建好的查询包装器
*/
private QueryWrapper<SysPost> buildQueryWrapper(SysPostBo bo) {
QueryWrapper<SysPost> wrapper = Wrappers.query();
wrapper.like(StringUtils.isNotBlank(bo.getPostCode()), "post_code", bo.getPostCode())
.like(StringUtils.isNotBlank(bo.getPostName()), "post_name", bo.getPostName())
.like(StringUtils.isNotBlank(bo.getPostCategory()), "post_category", bo.getPostCategory())
.eq(StringUtils.isNotBlank(bo.getStatus()), "status", bo.getStatus())
.and(ObjectUtil.isNotNull(bo.getDeptId()), w -> {
List<SysDept> deptList = deptMapper.selectList(new LambdaQueryWrapper<SysDept>()
.select(SysDept::getDeptId)
.apply(DataBaseHelper.findInSet(bo.getDeptId(), "ancestors")));
List<Long> ids = StreamUtils.toList(deptList, SysDept::getDeptId);
ids.add(bo.getDeptId());
w.in("dept_id", ids);
}).orderByAsc("post_sort");
.eq(StringUtils.isNotBlank(bo.getStatus()), "status", bo.getStatus());
if (ObjectUtil.isNotNull(bo.getDeptId())) {
//优先单部门搜索
wrapper.eq("dept_id", bo.getDeptId());
} else if (ObjectUtil.isNotNull(bo.getBelongDeptId())) {
//部门树搜索
wrapper.and(x -> {
List<Long> deptIds = deptMapper.selectList(new LambdaQueryWrapper<SysDept>()
.select(SysDept::getDeptId)
.apply(DataBaseHelper.findInSet(bo.getBelongDeptId(), "ancestors")))
.stream()
.map(SysDept::getDeptId)
.collect(Collectors.toList());
deptIds.add(bo.getDeptId());
x.in("dept_id", deptIds);
});
}
wrapper.orderByAsc("post_sort");
return wrapper;
}