mirror of
https://gitee.com/xiaonuobase/snowy.git
synced 2026-03-22 02:37:16 +08:00
【更新】机构大数据优化(待完善)
This commit is contained in:
@@ -243,7 +243,7 @@
|
|||||||
treeLoading.value = true
|
treeLoading.value = true
|
||||||
searchMode.value = true
|
searchMode.value = true
|
||||||
bizOrgApi
|
bizOrgApi
|
||||||
.orgTree({ searchKey: value.trim() })
|
.orgTreeLazy({ searchKey: value.trim() })
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res !== null) {
|
if (res !== null) {
|
||||||
treeData.value = res
|
treeData.value = res
|
||||||
@@ -270,8 +270,8 @@
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (isEmpty(defaultExpandedKeys.value)) {
|
if (isEmpty(defaultExpandedKeys.value)) {
|
||||||
// 默认展开第一级
|
// 只有一个根节点时才自动展开
|
||||||
if (treeData.value.length > 0) {
|
if (treeData.value.length === 1) {
|
||||||
defaultExpandedKeys.value.push(treeData.value[0].id)
|
defaultExpandedKeys.value.push(treeData.value[0].id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -287,7 +287,7 @@
|
|||||||
treeLoading.value = true
|
treeLoading.value = true
|
||||||
treeData.value = []
|
treeData.value = []
|
||||||
bizOrgApi
|
bizOrgApi
|
||||||
.orgTree()
|
.orgTreeLazy({ searchKey: '' })
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res !== null) {
|
if (res !== null) {
|
||||||
treeData.value = res
|
treeData.value = res
|
||||||
|
|||||||
@@ -242,7 +242,7 @@
|
|||||||
treeLoading.value = true
|
treeLoading.value = true
|
||||||
searchMode.value = true
|
searchMode.value = true
|
||||||
orgApi
|
orgApi
|
||||||
.orgTree({ searchKey: value.trim() })
|
.orgTreeLazy({ searchKey: value.trim() })
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res !== null) {
|
if (res !== null) {
|
||||||
treeData.value = res
|
treeData.value = res
|
||||||
@@ -269,8 +269,8 @@
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (isEmpty(defaultExpandedKeys.value)) {
|
if (isEmpty(defaultExpandedKeys.value)) {
|
||||||
// 默认展开第一级
|
// 只有一个根节点时才自动展开
|
||||||
if (treeData.value.length > 0) {
|
if (treeData.value.length === 1) {
|
||||||
defaultExpandedKeys.value.push(treeData.value[0].id)
|
defaultExpandedKeys.value.push(treeData.value[0].id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -286,7 +286,7 @@
|
|||||||
treeLoading.value = true
|
treeLoading.value = true
|
||||||
treeData.value = []
|
treeData.value = []
|
||||||
orgApi
|
orgApi
|
||||||
.orgTree()
|
.orgTreeLazy({ searchKey: '' })
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res !== null) {
|
if (res !== null) {
|
||||||
treeData.value = res
|
treeData.value = res
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import org.springframework.validation.annotation.Validated;
|
|||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import vip.xiaonuo.biz.modular.org.entity.BizOrg;
|
import vip.xiaonuo.biz.modular.org.entity.BizOrg;
|
||||||
import vip.xiaonuo.biz.modular.org.enums.BizOrgSourceFromTypeEnum;
|
import vip.xiaonuo.biz.modular.org.enums.BizOrgSourceFromTypeEnum;
|
||||||
@@ -68,20 +67,6 @@ public class BizOrgController {
|
|||||||
return CommonResult.data(bizOrgService.page(bizOrgPageParam));
|
return CommonResult.data(bizOrgService.page(bizOrgPageParam));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取机构树
|
|
||||||
*
|
|
||||||
* @author xuyuxiang
|
|
||||||
* @date 2022/4/24 20:00
|
|
||||||
*/
|
|
||||||
@ApiOperationSupport(order = 2)
|
|
||||||
@Operation(summary = "获取机构树")
|
|
||||||
@SaCheckPermission("/biz/org/tree")
|
|
||||||
@GetMapping("/biz/org/tree")
|
|
||||||
public CommonResult<List<Tree<String>>> tree(@RequestParam(required = false) String searchKey) {
|
|
||||||
return CommonResult.data(bizOrgService.tree(searchKey));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取机构树(懒加载)
|
* 获取机构树(懒加载)
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -29,4 +29,8 @@ public class BizOrgTreeLazyParam {
|
|||||||
/** 父id */
|
/** 父id */
|
||||||
@Schema(description = "父id")
|
@Schema(description = "父id")
|
||||||
private String parentId;
|
private String parentId;
|
||||||
|
|
||||||
|
/** 搜索关键字 */
|
||||||
|
@Schema(description = "搜索关键字")
|
||||||
|
private String searchKey;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,56 +125,12 @@ public class BizOrgServiceImpl extends ServiceImpl<BizOrgMapper, BizOrg> impleme
|
|||||||
return this.page(CommonPageRequest.defaultPage(), queryWrapper);
|
return this.page(CommonPageRequest.defaultPage(), queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Tree<String>> tree() {
|
|
||||||
return this.tree(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Tree<String>> tree(String searchKey) {
|
|
||||||
// 获取所有机构
|
|
||||||
List<BizOrg> allOrgList = this.getAllOrgList();
|
|
||||||
// 定义机构集合
|
|
||||||
Set<BizOrg> bizOrgSet = CollectionUtil.newHashSet();
|
|
||||||
// 校验数据范围
|
|
||||||
List<String> loginUserDataScope = StpLoginUserUtil.getLoginUserDataScope();
|
|
||||||
if(loginUserDataScope != null && loginUserDataScope.isEmpty()) {
|
|
||||||
return CollectionUtil.newArrayList();
|
|
||||||
}
|
|
||||||
if(loginUserDataScope == null) {
|
|
||||||
bizOrgSet.addAll(allOrgList);
|
|
||||||
} else {
|
|
||||||
loginUserDataScope.forEach(orgId -> bizOrgSet.addAll(this.getParentListById(allOrgList, orgId, true)));
|
|
||||||
}
|
|
||||||
|
|
||||||
List<BizOrg> bizOrgArrayList = new ArrayList<>(bizOrgSet);
|
|
||||||
|
|
||||||
// 如果有搜索关键字,过滤匹配的机构及其所有父级
|
|
||||||
if (ObjectUtil.isNotEmpty(searchKey)) {
|
|
||||||
Set<BizOrg> filteredSet = CollectionUtil.newLinkedHashSet();
|
|
||||||
bizOrgArrayList.stream()
|
|
||||||
.filter(org -> StrUtil.containsIgnoreCase(org.getName(), searchKey))
|
|
||||||
.forEach(org -> filteredSet.addAll(this.getParentListById(allOrgList, org.getId(), true)));
|
|
||||||
// 取交集:既在数据范围内,又匹配搜索条件
|
|
||||||
bizOrgArrayList = new ArrayList<>(filteredSet);
|
|
||||||
bizOrgArrayList.retainAll(bizOrgSet);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 修复:使用稳定的排序方式,首先按排序码排序,然后按机构ID排序作为次级条件
|
|
||||||
bizOrgArrayList.sort(Comparator.comparingInt(BizOrg::getSortCode)
|
|
||||||
.thenComparing(BizOrg::getId)); // 添加ID作为次级排序条件
|
|
||||||
|
|
||||||
// 转换为TreeNode并构建树
|
|
||||||
List<TreeNode<String>> treeNodeList = bizOrgArrayList.stream().map(bizOrg ->
|
|
||||||
new TreeNode<>(bizOrg.getId(), bizOrg.getParentId(),
|
|
||||||
bizOrg.getName(), bizOrg.getSortCode()).setExtra(JSONUtil.parseObj(bizOrg)))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
return TreeUtil.build(treeNodeList, "0");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<JSONObject> treeLazy(BizOrgTreeLazyParam bizOrgTreeLazyParam) {
|
public List<JSONObject> treeLazy(BizOrgTreeLazyParam bizOrgTreeLazyParam) {
|
||||||
|
// searchKey不为null时,走全量搜索模式,返回嵌套树结构
|
||||||
|
if (bizOrgTreeLazyParam.getSearchKey() != null) {
|
||||||
|
return this.treeSearch(bizOrgTreeLazyParam.getSearchKey());
|
||||||
|
}
|
||||||
String parentId = ObjectUtil.isNotEmpty(bizOrgTreeLazyParam.getParentId()) ? bizOrgTreeLazyParam.getParentId() : "0";
|
String parentId = ObjectUtil.isNotEmpty(bizOrgTreeLazyParam.getParentId()) ? bizOrgTreeLazyParam.getParentId() : "0";
|
||||||
// 校验数据范围
|
// 校验数据范围
|
||||||
List<String> loginUserDataScope = StpLoginUserUtil.getLoginUserDataScope();
|
List<String> loginUserDataScope = StpLoginUserUtil.getLoginUserDataScope();
|
||||||
@@ -248,6 +204,42 @@ public class BizOrgServiceImpl extends ServiceImpl<BizOrgMapper, BizOrg> impleme
|
|||||||
return this.treeLazy(bizOrgTreeLazyParam);
|
return this.treeLazy(bizOrgTreeLazyParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 全量搜索模式,返回嵌套树结构的JSONObject列表
|
||||||
|
* searchKey为空字符串时返回全量树,非空时按关键字过滤
|
||||||
|
* 保留数据范围过滤逻辑
|
||||||
|
*/
|
||||||
|
private List<JSONObject> treeSearch(String searchKey) {
|
||||||
|
List<BizOrg> allOrgList = this.getAllOrgList();
|
||||||
|
Set<BizOrg> bizOrgSet = CollectionUtil.newHashSet();
|
||||||
|
List<String> loginUserDataScope = StpLoginUserUtil.getLoginUserDataScope();
|
||||||
|
if (loginUserDataScope != null && loginUserDataScope.isEmpty()) {
|
||||||
|
return CollectionUtil.newArrayList();
|
||||||
|
}
|
||||||
|
if (loginUserDataScope == null) {
|
||||||
|
bizOrgSet.addAll(allOrgList);
|
||||||
|
} else {
|
||||||
|
loginUserDataScope.forEach(orgId -> bizOrgSet.addAll(this.getParentListById(allOrgList, orgId, true)));
|
||||||
|
}
|
||||||
|
List<BizOrg> bizOrgArrayList = new ArrayList<>(bizOrgSet);
|
||||||
|
if (ObjectUtil.isNotEmpty(searchKey)) {
|
||||||
|
Set<BizOrg> filteredSet = CollectionUtil.newLinkedHashSet();
|
||||||
|
bizOrgArrayList.stream()
|
||||||
|
.filter(org -> StrUtil.containsIgnoreCase(org.getName(), searchKey))
|
||||||
|
.forEach(org -> filteredSet.addAll(this.getParentListById(allOrgList, org.getId(), true)));
|
||||||
|
bizOrgArrayList = new ArrayList<>(filteredSet);
|
||||||
|
bizOrgArrayList.retainAll(bizOrgSet);
|
||||||
|
}
|
||||||
|
bizOrgArrayList.sort(Comparator.comparingInt(BizOrg::getSortCode)
|
||||||
|
.thenComparing(BizOrg::getId));
|
||||||
|
List<TreeNode<String>> treeNodeList = bizOrgArrayList.stream().map(bizOrg ->
|
||||||
|
new TreeNode<>(bizOrg.getId(), bizOrg.getParentId(),
|
||||||
|
bizOrg.getName(), bizOrg.getSortCode()).setExtra(JSONUtil.parseObj(bizOrg)))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
List<Tree<String>> treeList = TreeUtil.build(treeNodeList, "0");
|
||||||
|
return JSONUtil.toList(JSONUtil.parseArray(treeList), JSONObject.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
@Override
|
@Override
|
||||||
public void add(BizOrgAddParam bizOrgAddParam, String sourceFromType) {
|
public void add(BizOrgAddParam bizOrgAddParam, String sourceFromType) {
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import org.springframework.validation.annotation.Validated;
|
|||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import vip.xiaonuo.common.annotation.CommonLog;
|
import vip.xiaonuo.common.annotation.CommonLog;
|
||||||
import vip.xiaonuo.common.pojo.CommonResult;
|
import vip.xiaonuo.common.pojo.CommonResult;
|
||||||
@@ -66,19 +65,6 @@ public class SysOrgController {
|
|||||||
return CommonResult.data(sysOrgService.page(sysOrgPageParam));
|
return CommonResult.data(sysOrgService.page(sysOrgPageParam));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取组织树
|
|
||||||
*
|
|
||||||
* @author xuyuxiang
|
|
||||||
* @date 2022/4/24 20:00
|
|
||||||
*/
|
|
||||||
@ApiOperationSupport(order = 2)
|
|
||||||
@Operation(summary = "获取组织树")
|
|
||||||
@GetMapping("/sys/org/tree")
|
|
||||||
public CommonResult<List<Tree<String>>> tree(@RequestParam(required = false) String searchKey) {
|
|
||||||
return CommonResult.data(sysOrgService.tree(searchKey));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取组织树(懒加载)
|
* 获取组织树(懒加载)
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -29,4 +29,8 @@ public class SysOrgTreeLazyParam {
|
|||||||
/** 父id */
|
/** 父id */
|
||||||
@Schema(description = "父id")
|
@Schema(description = "父id")
|
||||||
private String parentId;
|
private String parentId;
|
||||||
|
|
||||||
|
/** 搜索关键字 */
|
||||||
|
@Schema(description = "搜索关键字")
|
||||||
|
private String searchKey;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,23 +39,7 @@ public interface SysOrgService extends IService<SysOrg> {
|
|||||||
Page<SysOrg> page(SysOrgPageParam sysOrgPageParam);
|
Page<SysOrg> page(SysOrgPageParam sysOrgPageParam);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取组织树
|
* 获取机构树(懒加载),支持搜索
|
||||||
*
|
|
||||||
* @author xuyuxiang
|
|
||||||
* @date 2022/4/24 20:08
|
|
||||||
*/
|
|
||||||
List<Tree<String>> tree();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取组织树(带搜索关键字)
|
|
||||||
*
|
|
||||||
* @author xuyuxiang
|
|
||||||
* @date 2022/4/24 20:08
|
|
||||||
*/
|
|
||||||
List<Tree<String>> tree(String searchKey);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取机构树(懒加载)
|
|
||||||
*
|
*
|
||||||
* @author xuyuxiang
|
* @author xuyuxiang
|
||||||
* @date 2022/4/21 16:13
|
* @date 2022/4/21 16:13
|
||||||
|
|||||||
@@ -112,71 +112,30 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
|
|||||||
return this.page(CommonPageRequest.defaultPage(), queryWrapper);
|
return this.page(CommonPageRequest.defaultPage(), queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Tree<String>> tree() {
|
|
||||||
return this.tree(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Tree<String>> tree(String searchKey) {
|
|
||||||
List<SysOrg> allOrgList = this.getAllOrgList();
|
|
||||||
List<SysOrg> sysOrgList;
|
|
||||||
// 如果有搜索关键字,过滤匹配的组织及其所有父级
|
|
||||||
if (ObjectUtil.isNotEmpty(searchKey)) {
|
|
||||||
Set<SysOrg> filteredSet = CollectionUtil.newLinkedHashSet();
|
|
||||||
allOrgList.stream()
|
|
||||||
.filter(org -> StrUtil.containsIgnoreCase(org.getName(), searchKey))
|
|
||||||
.forEach(org -> filteredSet.addAll(this.getParentListById(allOrgList, org.getId(), true)));
|
|
||||||
sysOrgList = new ArrayList<>(filteredSet);
|
|
||||||
} else {
|
|
||||||
sysOrgList = allOrgList;
|
|
||||||
}
|
|
||||||
// 使用稳定的排序方式,首先按排序码排序,然后按机构ID排序作为次级条件
|
|
||||||
sysOrgList.sort(Comparator.comparingInt(SysOrg::getSortCode)
|
|
||||||
.thenComparing(SysOrg::getId)); // 添加ID作为次级排序条件
|
|
||||||
List<TreeNode<String>> treeNodeList = sysOrgList.stream().map(sysOrg ->
|
|
||||||
new TreeNode<>(sysOrg.getId(), sysOrg.getParentId(),
|
|
||||||
sysOrg.getName(), sysOrg.getSortCode()).setExtra(JSONUtil.parseObj(sysOrg)))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
return TreeUtil.build(treeNodeList, "0");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<JSONObject> treeLazy(SysOrgTreeLazyParam sysOrgTreeLazyParam) {
|
public List<JSONObject> treeLazy(SysOrgTreeLazyParam sysOrgTreeLazyParam) {
|
||||||
String parentId = ObjectUtil.isNotEmpty(sysOrgTreeLazyParam.getParentId()) ? sysOrgTreeLazyParam.getParentId() : "0";
|
// searchKey不为null时,走全量搜索模式,返回嵌套树结构
|
||||||
List<String> loginUserDataScope = StpLoginUserUtil.getLoginUserDataScope();
|
if (sysOrgTreeLazyParam.getSearchKey() != null) {
|
||||||
|
return this.treeSearch(sysOrgTreeLazyParam.getSearchKey());
|
||||||
// 获取所有机构
|
|
||||||
List<SysOrg> allOrgList = this.getAllOrgList();
|
|
||||||
Set<String> visibleOrgIds = null;
|
|
||||||
|
|
||||||
// 如果数据范围不为空,则计算可见机构ID集合(包含自身及其所有父级)
|
|
||||||
if (ObjectUtil.isNotEmpty(loginUserDataScope)) {
|
|
||||||
Set<SysOrg> sysOrgSet = CollectionUtil.newHashSet();
|
|
||||||
loginUserDataScope.forEach(orgId -> sysOrgSet.addAll(this.getParentListById(allOrgList, orgId, true)));
|
|
||||||
visibleOrgIds = sysOrgSet.stream().map(SysOrg::getId).collect(Collectors.toSet());
|
|
||||||
}
|
}
|
||||||
|
String parentId = ObjectUtil.isNotEmpty(sysOrgTreeLazyParam.getParentId()) ? sysOrgTreeLazyParam.getParentId() : "0";
|
||||||
// 过滤出当前父级下的可见子级
|
// 超管接口,无需数据范围过滤,直接SQL查询当前父级下的子机构
|
||||||
final Set<String> finalVisibleOrgIds = visibleOrgIds;
|
List<SysOrg> childList = this.list(new LambdaQueryWrapper<SysOrg>()
|
||||||
List<SysOrg> sysOrgList = allOrgList.stream()
|
.eq(SysOrg::getParentId, parentId)
|
||||||
.filter(sysOrg -> sysOrg.getParentId().equals(parentId))
|
.orderByAsc(SysOrg::getSortCode)
|
||||||
.filter(sysOrg -> finalVisibleOrgIds == null || finalVisibleOrgIds.contains(sysOrg.getId()))
|
.orderByAsc(SysOrg::getId));
|
||||||
.sorted(Comparator.comparingInt(SysOrg::getSortCode).thenComparing(SysOrg::getId))
|
if (ObjectUtil.isEmpty(childList)) {
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
if (CollectionUtil.isEmpty(sysOrgList)) {
|
|
||||||
return CollectionUtil.newArrayList();
|
return CollectionUtil.newArrayList();
|
||||||
}
|
}
|
||||||
|
// 批量判断哪些子机构还有下级
|
||||||
// 判断这些机构是否还有可见子机构
|
List<String> childIds = childList.stream().map(SysOrg::getId).collect(Collectors.toList());
|
||||||
return sysOrgList.stream().map(sysOrg -> {
|
Set<String> hasChildrenParentIds = this.list(new LambdaQueryWrapper<SysOrg>()
|
||||||
|
.select(SysOrg::getParentId)
|
||||||
|
.in(SysOrg::getParentId, childIds))
|
||||||
|
.stream().map(SysOrg::getParentId).collect(Collectors.toSet());
|
||||||
|
return childList.stream().map(sysOrg -> {
|
||||||
JSONObject jsonObject = JSONUtil.parseObj(sysOrg);
|
JSONObject jsonObject = JSONUtil.parseObj(sysOrg);
|
||||||
// 计算是否有可见的子节点
|
jsonObject.set("isLeaf", !hasChildrenParentIds.contains(sysOrg.getId()));
|
||||||
boolean hasChildren = allOrgList.stream()
|
|
||||||
.anyMatch(item -> item.getParentId().equals(sysOrg.getId()) && (finalVisibleOrgIds == null || finalVisibleOrgIds.contains(item.getId())));
|
|
||||||
|
|
||||||
jsonObject.set("isLeaf", !hasChildren);
|
|
||||||
return jsonObject;
|
return jsonObject;
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
@@ -193,6 +152,32 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
|
|||||||
return this.treeLazy(sysOrgTreeLazyParam);
|
return this.treeLazy(sysOrgTreeLazyParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 全量搜索模式,返回嵌套树结构的JSONObject列表
|
||||||
|
* searchKey为空字符串时返回全量树,非空时按关键字过滤
|
||||||
|
*/
|
||||||
|
private List<JSONObject> treeSearch(String searchKey) {
|
||||||
|
List<SysOrg> allOrgList = this.getAllOrgList();
|
||||||
|
List<SysOrg> sysOrgList;
|
||||||
|
if (ObjectUtil.isNotEmpty(searchKey)) {
|
||||||
|
Set<SysOrg> filteredSet = CollectionUtil.newLinkedHashSet();
|
||||||
|
allOrgList.stream()
|
||||||
|
.filter(org -> StrUtil.containsIgnoreCase(org.getName(), searchKey))
|
||||||
|
.forEach(org -> filteredSet.addAll(this.getParentListById(allOrgList, org.getId(), true)));
|
||||||
|
sysOrgList = new ArrayList<>(filteredSet);
|
||||||
|
} else {
|
||||||
|
sysOrgList = allOrgList;
|
||||||
|
}
|
||||||
|
sysOrgList.sort(Comparator.comparingInt(SysOrg::getSortCode)
|
||||||
|
.thenComparing(SysOrg::getId));
|
||||||
|
List<TreeNode<String>> treeNodeList = sysOrgList.stream().map(sysOrg ->
|
||||||
|
new TreeNode<>(sysOrg.getId(), sysOrg.getParentId(),
|
||||||
|
sysOrg.getName(), sysOrg.getSortCode()).setExtra(JSONUtil.parseObj(sysOrg)))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
List<Tree<String>> treeList = TreeUtil.build(treeNodeList, "0");
|
||||||
|
return JSONUtil.toList(JSONUtil.parseArray(treeList), JSONObject.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
@Override
|
@Override
|
||||||
public void add(SysOrgAddParam sysOrgAddParam, String sourceFromType) {
|
public void add(SysOrgAddParam sysOrgAddParam, String sourceFromType) {
|
||||||
|
|||||||
Reference in New Issue
Block a user