|
@@ -3,7 +3,6 @@ package com.dragon.tj.portal.auth.controller;
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.dragon.tj.portal.auth.util.SecurityUtils;
|
|
import com.dragon.tj.portal.auth.util.SecurityUtils;
|
|
-import com.dragon.tj.portal.auth.util.TreeBuilder;
|
|
|
|
import com.dragon.tj.portal.auth.web.convert.DeptTreeNodeConvert;
|
|
import com.dragon.tj.portal.auth.web.convert.DeptTreeNodeConvert;
|
|
import com.dragon.tj.portal.auth.web.dto.DeptTreeNode;
|
|
import com.dragon.tj.portal.auth.web.dto.DeptTreeNode;
|
|
import com.dragon.tj.portal.auth.web.entity.SysDept;
|
|
import com.dragon.tj.portal.auth.web.entity.SysDept;
|
|
@@ -16,7 +15,9 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
+import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.Pattern;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -49,11 +50,11 @@ public class DeptController {
|
|
@GetMapping("/tree")
|
|
@GetMapping("/tree")
|
|
public R<List<DeptTreeNode>> tree(@RequestParam(required = false) String upOrgCode, @RequestParam(required = false) boolean fromRoot) {
|
|
public R<List<DeptTreeNode>> tree(@RequestParam(required = false) String upOrgCode, @RequestParam(required = false) boolean fromRoot) {
|
|
String rootOrgCode;
|
|
String rootOrgCode;
|
|
- if(StringUtils.isNotBlank(upOrgCode)){
|
|
|
|
|
|
+ if (StringUtils.isNotBlank(upOrgCode)) {
|
|
rootOrgCode = upOrgCode;
|
|
rootOrgCode = upOrgCode;
|
|
} else if (fromRoot) {
|
|
} else if (fromRoot) {
|
|
rootOrgCode = ROOT_ORG_CODE;
|
|
rootOrgCode = ROOT_ORG_CODE;
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
rootOrgCode = SecurityUtils.getLoginUser().getOrgCode();
|
|
rootOrgCode = SecurityUtils.getLoginUser().getOrgCode();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -66,7 +67,10 @@ public class DeptController {
|
|
List<SysDept> orgs = sysDeptService.list(Wrappers.<SysDept>query().lambda().likeRight(SysDept::getOrgCode, rootOrgCodePrefix).orderByAsc(SysDept::getOrgCode));
|
|
List<SysDept> orgs = sysDeptService.list(Wrappers.<SysDept>query().lambda().likeRight(SysDept::getOrgCode, rootOrgCodePrefix).orderByAsc(SysDept::getOrgCode));
|
|
List<DeptTreeNode> orgNodes = orgs.stream().map(deptTreeNodeConvert::toVo).collect(Collectors.toList());
|
|
List<DeptTreeNode> orgNodes = orgs.stream().map(deptTreeNodeConvert::toVo).collect(Collectors.toList());
|
|
if (orgNodes.size() > 1) {
|
|
if (orgNodes.size() > 1) {
|
|
- orgNodes = new TreeBuilder(orgNodes).buildTree(rootOrgCode);
|
|
|
|
|
|
+ // orgNodes = new TreeBuilder(orgNodes).buildTree(rootOrgCode);
|
|
|
|
+ Map<String, List<DeptTreeNode>> groupMap = orgNodes.stream().collect(Collectors.groupingBy(DeptTreeNode::getUpOrgCode));
|
|
|
|
+ orgNodes.forEach(item -> item.setChildren(groupMap.get(item.getOrgCode())));
|
|
|
|
+ orgNodes = Collections.singletonList(orgNodes.get(0));
|
|
}
|
|
}
|
|
return R.ok(orgNodes);
|
|
return R.ok(orgNodes);
|
|
}
|
|
}
|