|
@@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.lang.tree.Tree;
|
|
|
import cn.hutool.core.lang.tree.TreeNode;
|
|
|
import cn.hutool.core.lang.tree.TreeUtil;
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -20,6 +19,7 @@ import com.xy.service.SysDeptRelationService;
|
|
|
import com.xy.service.SysDeptRoleService;
|
|
|
import com.xy.service.SysDeptService;
|
|
|
import com.xy.service.SysUserDeptService;
|
|
|
+import com.xy.utils.LambdaUtils;
|
|
|
import com.xy.utils.R;
|
|
|
import com.xy.vo.SysDeptVo;
|
|
|
import io.swagger.annotations.Api;
|
|
@@ -32,7 +32,10 @@ import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
-import java.util.*;
|
|
|
+import java.util.Comparator;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.xy.utils.Beans.copy;
|
|
@@ -51,7 +54,6 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|
|
private final SysDeptRoleService sysDeptRoleService;
|
|
|
private final SysUserDeptService sysUserDeptService;
|
|
|
|
|
|
-
|
|
|
@ApiOperation(value = "新增、更新部门信息", notes = "新增、更新部门信息")
|
|
|
@PostMapping("saveOrUpdate")
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -69,15 +71,12 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|
|
isAdd = false;
|
|
|
lqw.ne(SysDept::getId, id);
|
|
|
}
|
|
|
-
|
|
|
long count = count(lqw);
|
|
|
if (count > 0) {
|
|
|
return R.fail("此部门已存在");
|
|
|
}
|
|
|
List<Long> roleIds = sysDeptDto.getRoleIds();
|
|
|
-
|
|
|
SysDept sysDept = copy(SysDept.class, sysDeptDto).saveOrUpdate(loginId, sysDeptDto.getSysId());
|
|
|
-
|
|
|
if (isAdd) {
|
|
|
//新建部门关系
|
|
|
sysDeptRelationService.saveDeptRelation(sysDept);
|
|
@@ -96,22 +95,9 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|
|
sysDeptRoleService.updateDeptRole(sysDept.getId(), roleIds);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
return R.ok(saveOrUpdate(sysDept));
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- @ApiOperation(value = "系统部门树下拉列表", notes = "系统部门树下拉列表")
|
|
|
- @PostMapping("tree/list")
|
|
|
- public R<List<Tree<Long>>> deptTreeList(@Valid @RequestBody SysDeptListDto sysDeptListDto) {
|
|
|
- Long sysId = sysDeptListDto.getSysId();
|
|
|
- String deptName = sysDeptListDto.getName();
|
|
|
- LambdaQueryWrapper<SysDept> lambdaQueryWrapper = Wrappers.<SysDept>lambdaQuery().eq(SysDept::getSysId, sysId)
|
|
|
- .likeRight(StrUtil.isNotBlank(deptName), SysDept::getName, deptName);
|
|
|
- List<Tree<Long>> deptTree = getDeptTree(this.list(lambdaQueryWrapper), 0L);
|
|
|
- return R.ok(deptTree);
|
|
|
- }
|
|
|
-
|
|
|
@ApiOperation(value = "根据ID获取部门信息", notes = "根据ID获取部门信息")
|
|
|
@GetMapping("getById")
|
|
|
public R<SysDeptVo> getById(@Valid @RequestBody CommonIdDto commonIdDto) {
|
|
@@ -120,6 +106,16 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|
|
return R.ok(sysRoleVo);
|
|
|
}
|
|
|
|
|
|
+ @ApiOperation(value = "部门树", notes = "部门树")
|
|
|
+ @PostMapping("tree/list")
|
|
|
+ public R<List<Tree<Long>>> deptTreeList(@Valid @RequestBody SysDeptListDto sysDeptListDto) {
|
|
|
+ Long sysId = sysDeptListDto.getSysId();
|
|
|
+ LambdaQueryWrapper<SysDept> lambdaQueryWrapper = Wrappers.lambdaQuery();
|
|
|
+ RedisCache.getDataAuth(sysId, lambdaQueryWrapper, SysDept::getCreateUser);
|
|
|
+ List<Tree<Long>> deptTree = getDeptTree(this.list(lambdaQueryWrapper), 0L);
|
|
|
+ return R.ok(deptTree);
|
|
|
+ }
|
|
|
+
|
|
|
@ApiOperation(value = "删除部门", notes = "删除部门")
|
|
|
@PostMapping("deleteById")
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -143,18 +139,6 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|
|
return R.ok(Boolean.TRUE);
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "获取指定部门部门树", notes = "获取指定部门部门树")
|
|
|
- @PostMapping("getDeptTreeById")
|
|
|
- public R<List<Tree<Long>>> getDeptTreeById(@Valid @RequestBody CommonIdDto commonIdDto) {
|
|
|
- Long id = commonIdDto.getId();
|
|
|
- List<Long> descendantIdList = sysDeptRelationService
|
|
|
- .list(Wrappers.<SysDeptRelation>query().lambda().eq(SysDeptRelation::getAncestor, id)).stream()
|
|
|
- .map(SysDeptRelation::getDescendant).collect(Collectors.toList());
|
|
|
- List<SysDept> deptList = baseMapper.selectBatchIds(descendantIdList);
|
|
|
- Optional<SysDept> dept = deptList.stream().filter(item -> item.getId() == id).findFirst();
|
|
|
- return R.ok(getDeptTree(deptList, dept.isPresent() ? dept.get().getParentId() : 0L));
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 获得部门树
|
|
|
*
|
|
@@ -163,7 +147,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|
|
* @return
|
|
|
*/
|
|
|
private List<Tree<Long>> getDeptTree(List<SysDept> deptList, Long parentId) {
|
|
|
- List<TreeNode<Long>> collect = deptList.stream().filter(dept -> dept.getId() != dept.getParentId())
|
|
|
+ List<TreeNode<Long>> collect = deptList.stream().filter(dept -> !dept.getId().equals(dept.getParentId()))
|
|
|
.sorted(Comparator.comparingInt(SysDept::getSortNum)).map(dept -> {
|
|
|
TreeNode<Long> treeNode = new TreeNode();
|
|
|
treeNode.setId(dept.getId());
|
|
@@ -172,8 +156,8 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|
|
treeNode.setWeight(dept.getSortNum());
|
|
|
// 扩展属性
|
|
|
Map<String, Object> extra = new HashMap<>(16);
|
|
|
- extra.put("createTime", dept.getCreateTime());
|
|
|
- extra.put("code", dept.getCode());
|
|
|
+ extra.put(LambdaUtils.getProperty(SysDept::getCreateTime), dept.getCreateTime());
|
|
|
+ extra.put(LambdaUtils.getProperty(SysDept::getCode), dept.getCode());
|
|
|
treeNode.setExtra(extra);
|
|
|
return treeNode;
|
|
|
}).collect(Collectors.toList());
|