|
@@ -0,0 +1,63 @@
|
|
|
+package com.dragon.tj.portal.auth.controller;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+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.dto.DeptTreeNode;
|
|
|
+import com.dragon.tj.portal.auth.web.entity.SysDept;
|
|
|
+import com.dragon.tj.portal.auth.web.service.SysDeptService;
|
|
|
+import com.dragon.tj.portal.common.base.R;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/dept")
|
|
|
+public class DeptController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysDeptService sysDeptService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DeptTreeNodeConvert deptTreeNodeConvert;
|
|
|
+
|
|
|
+ @GetMapping("/root")
|
|
|
+ public R<List<SysDept>> list() {
|
|
|
+ String orgCode = SecurityUtils.getLoginUser().getOrgCode();
|
|
|
+ List<SysDept> list = new ArrayList<>();
|
|
|
+ list.add(sysDeptService.getOne(Wrappers.<SysDept>query().lambda().eq(SysDept::getOrgCode, orgCode)));
|
|
|
+ return R.ok(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/children")
|
|
|
+ public R<List<SysDept>> list(@RequestParam String upOrgCode) {
|
|
|
+ return R.ok(sysDeptService.list(Wrappers.<SysDept>query().lambda().eq(SysDept::getUpOrgCode, upOrgCode).orderByAsc(SysDept::getOrgCode)));
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/tree")
|
|
|
+ public R<List<DeptTreeNode>> tree() {
|
|
|
+ String rootOrgCode = SecurityUtils.getLoginUser().getOrgCode();
|
|
|
+
|
|
|
+ Pattern pattern = Pattern.compile("^(.*?)(00)*$");
|
|
|
+ Matcher matcher = pattern.matcher(rootOrgCode);
|
|
|
+ String rootOrgCodePrefix = rootOrgCode;
|
|
|
+ while (matcher.find()) {
|
|
|
+ rootOrgCodePrefix = matcher.group(1);
|
|
|
+ }
|
|
|
+ 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());
|
|
|
+ if (orgNodes.size() > 1) {
|
|
|
+ orgNodes = new TreeBuilder(orgNodes).buildTree(rootOrgCode);
|
|
|
+ }
|
|
|
+ return R.ok(orgNodes);
|
|
|
+ }
|
|
|
+}
|