|
|
@@ -1,5 +1,6 @@
|
|
|
package com.ytpm.middle.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import com.ytpm.general.RepMessage;
|
|
|
@@ -16,7 +17,9 @@ import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class DeptServiceImpl implements DeptService {
|
|
|
@@ -50,10 +53,26 @@ public class DeptServiceImpl implements DeptService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取部门下拉列表
|
|
|
+ * 查询部门树形菜单
|
|
|
*/
|
|
|
@Override
|
|
|
- public ResultTable<DropDownVO> getDropDownList() {
|
|
|
- return ResultTable.resultTableOk(new PageInfo<>(deptMapper.getDropDownList()));
|
|
|
+ public Result<DropDownVO> getDeptTree() {
|
|
|
+ List<DropDownVO> all = deptMapper.getAllDeptList();
|
|
|
+ DropDownVO parent = all.stream().filter(s -> Objects.isNull(s.getParentId())).collect(Collectors.toList()).get(0);
|
|
|
+ List<DropDownVO> next = all.stream().filter(s -> Objects.nonNull(s.getParentId())).collect(Collectors.toList());
|
|
|
+ recursionChildOption(parent,next);
|
|
|
+ return Result.resultObjOk(parent);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 递归处理部门列表
|
|
|
+ */
|
|
|
+ private void recursionChildOption(DropDownVO parent, List<DropDownVO> next) {
|
|
|
+ List<DropDownVO> collect = next.stream().filter(s -> Objects.equals(s.getParentId(), parent.getOptionVal())).collect(Collectors.toList());
|
|
|
+ if(CollUtil.isEmpty(collect))return;
|
|
|
+ parent.setChildren(collect);
|
|
|
+ for (DropDownVO vo : next) {
|
|
|
+ recursionChildOption(vo,next);
|
|
|
+ }
|
|
|
}
|
|
|
}
|