【8.0】【system】更新通用组织机构树获取,改为懒加载方式

pull/57/head
fengshuonan 2023-07-13 21:11:47 +08:00
parent 9f5360de43
commit fffb3a603f
4 changed files with 130 additions and 32 deletions

View File

@ -5,9 +5,12 @@ import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.roses.kernel.sys.modular.org.entity.HrOrganization;
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.request.CommonOrgTreeRequest;
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.request.HrOrganizationRequest;
import cn.stylefeng.roses.kernel.sys.modular.org.service.HrOrganizationService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@ -30,13 +33,15 @@ public class CommonOrgController {
*
* <p>
* ps
* <p>
* orgParentId-1
*
* @author fengshuonan
* @since 2023/6/11 10:31
*/
@GetResource(name = "通用获取组织机构树", path = "/common/org/tree")
public ResponseData<List<HrOrganization>> commonOrgTree(HrOrganizationRequest hrOrganizationRequest) {
return new SuccessResponseData<>(hrOrganizationService.commonOrgTree(hrOrganizationRequest));
@PostResource(name = "通用获取组织机构树", path = "/common/org/tree")
public ResponseData<List<HrOrganization>> commonOrgTree(@RequestBody CommonOrgTreeRequest commonOrgTreeRequest) {
return new SuccessResponseData<>(hrOrganizationService.commonOrgTree(commonOrgTreeRequest));
}
/**

View File

@ -0,0 +1,47 @@
package cn.stylefeng.roses.kernel.sys.modular.org.pojo.request;
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
import cn.stylefeng.roses.kernel.rule.constants.TreeConstants;
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Set;
/**
*
*
* @author fengshuonan
* @since 2023/7/13 20:17
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class CommonOrgTreeRequest extends BaseRequest {
/**
* id
* <p>
*
* <p>
*
*/
@ChineseDescription("父级id一级节点父id是-1")
private Long orgParentId = TreeConstants.DEFAULT_PARENT_ID;
/**
* id
* <p>
* 使
*/
@ChineseDescription("定位组织机构状态的组织机构id集合")
private Set<Long> indexOrgIdList;
/**
*
* <p>
* true-false-
*/
@ChineseDescription("是否只查询公司列表")
private Boolean companySearchFlag;
}

View File

@ -3,11 +3,13 @@ package cn.stylefeng.roses.kernel.sys.modular.org.service;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.sys.api.pojo.org.CompanyDeptDTO;
import cn.stylefeng.roses.kernel.sys.modular.org.entity.HrOrganization;
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.request.CommonOrgTreeRequest;
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.request.HrOrganizationRequest;
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.response.HomeCompanyInfo;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
import java.util.Set;
/**
*
@ -99,7 +101,7 @@ public interface HrOrganizationService extends IService<HrOrganization> {
* @author fengshuonan
* @since 2023/6/11 10:40
*/
List<HrOrganization> commonOrgTree(HrOrganizationRequest hrOrganizationRequest);
List<HrOrganization> commonOrgTree(CommonOrgTreeRequest commonOrgTreeRequest);
/**
* id
@ -142,12 +144,11 @@ public interface HrOrganizationService extends IService<HrOrganization> {
HomeCompanyInfo orgStatInfo();
/**
* id
*
*
* @return orgId
* @author fengshuonan
* @since 2023/6/27 14:33
* @since 2023/7/13 20:50
*/
List<Long> getSubOrgIdListOneLevel(Long orgId);
Set<Long> queryOrgIdParentIdList(Set<Long> orgIdList);
}

View File

@ -1,7 +1,6 @@
package cn.stylefeng.roses.kernel.sys.modular.org.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
@ -23,6 +22,7 @@ import cn.stylefeng.roses.kernel.sys.modular.org.constants.OrgConstants;
import cn.stylefeng.roses.kernel.sys.modular.org.entity.HrOrganization;
import cn.stylefeng.roses.kernel.sys.modular.org.factory.OrganizationFactory;
import cn.stylefeng.roses.kernel.sys.modular.org.mapper.HrOrganizationMapper;
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.request.CommonOrgTreeRequest;
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.request.HrOrganizationRequest;
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.response.HomeCompanyInfo;
import cn.stylefeng.roses.kernel.sys.modular.org.service.HrOrganizationService;
@ -187,12 +187,12 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
}
@Override
public List<HrOrganization> commonOrgTree(HrOrganizationRequest hrOrganizationRequest) {
public List<HrOrganization> commonOrgTree(CommonOrgTreeRequest commonOrgTreeRequest) {
// 根据条件查询组织机构列表
LambdaQueryWrapper<HrOrganization> wrapper = this.createWrapper(hrOrganizationRequest);
wrapper.select(HrOrganization::getOrgId, HrOrganization::getOrgParentId, HrOrganization::getOrgPids, HrOrganization::getOrgName,
HrOrganization::getOrgSort, HrOrganization::getOrgType);
LambdaQueryWrapper<HrOrganization> wrapper = this.createCommonTreeWrapper(commonOrgTreeRequest);
wrapper.select(HrOrganization::getOrgId, HrOrganization::getOrgParentId, HrOrganization::getOrgName, HrOrganization::getOrgSort,
HrOrganization::getOrgType);
List<HrOrganization> hrOrganizationList = this.list(wrapper);
if (ObjectUtil.isEmpty(hrOrganizationList)) {
@ -200,7 +200,7 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
}
// 如果查询条件不为空,则把相关的查询结果的父级也查询出来,组成一颗完整树
String searchText = hrOrganizationRequest.getSearchText();
String searchText = commonOrgTreeRequest.getSearchText();
List<HrOrganization> parentOrgList = new ArrayList<>();
if (ObjectUtil.isNotEmpty(searchText)) {
Set<Long> orgParentIdList = OrganizationFactory.getOrgParentIdList(hrOrganizationList);
@ -352,20 +352,35 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
}
@Override
public List<Long> getSubOrgIdListOneLevel(Long orgId) {
LambdaQueryWrapper<HrOrganization> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(HrOrganization::getOrgParentId, orgId);
wrapper.select(HrOrganization::getOrgId);
List<HrOrganization> subOrgList = this.list(wrapper);
public Set<Long> queryOrgIdParentIdList(Set<Long> orgIdList) {
if (ObjectUtil.isEmpty(subOrgList)) {
return ListUtil.list(false, orgId);
Set<Long> parentIdListTotal = new HashSet<>();
if (ObjectUtil.isEmpty(orgIdList)) {
return parentIdListTotal;
}
List<Long> subOrgIdList = subOrgList.stream().map(HrOrganization::getOrgId).collect(Collectors.toList());
subOrgIdList.add(orgId);
LambdaQueryWrapper<HrOrganization> hrOrganizationLambdaQueryWrapper = new LambdaQueryWrapper<>();
hrOrganizationLambdaQueryWrapper.in(HrOrganization::getOrgId, orgIdList);
hrOrganizationLambdaQueryWrapper.select(HrOrganization::getOrgPids);
List<HrOrganization> hrOrganizationList = this.list(hrOrganizationLambdaQueryWrapper);
return subOrgIdList;
for (HrOrganization hrOrganization : hrOrganizationList) {
String orgPids = hrOrganization.getOrgPids();
if (ObjectUtil.isEmpty(orgPids)) {
continue;
}
orgPids = orgPids.replaceAll(LEFT_SQUARE_BRACKETS, "");
orgPids = orgPids.replaceAll(RIGHT_SQUARE_BRACKETS, "");
String[] split = orgPids.split(",");
for (String pidString : split) {
parentIdListTotal.add(Convert.toLong(pidString));
}
}
return parentIdListTotal;
}
/**
@ -411,14 +426,7 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
Long orgId = hrOrganizationRequest.getOrgId();
if (orgId != null) {
// 查询orgId对应的所有子机构包含本orgId
List<Long> subOrgIdListOneLevel = this.getSubOrgIdListOneLevel(orgId);
queryWrapper.in(HrOrganization::getOrgId, subOrgIdListOneLevel);
}
// 如果有筛选公司的标识,则只查询公司列表
Boolean companySearchFlag = hrOrganizationRequest.getCompanySearchFlag();
if (ObjectUtil.isNotEmpty(companySearchFlag) && companySearchFlag) {
queryWrapper.eq(HrOrganization::getOrgType, OrgTypeEnum.COMPANY.getCode());
queryWrapper.eq(HrOrganization::getOrgParentId, orgId);
}
// 根据排序正序查询
@ -427,6 +435,43 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
return queryWrapper;
}
/**
* wrapper
*
* @author fengshuonan
* @date 2023/06/10 21:23
*/
private LambdaQueryWrapper<HrOrganization> createCommonTreeWrapper(CommonOrgTreeRequest commonOrgTreeRequest) {
// 创建基本的wrapper
HrOrganizationRequest hrOrganizationRequest = new HrOrganizationRequest();
hrOrganizationRequest.setSearchText(commonOrgTreeRequest.getSearchText());
LambdaQueryWrapper<HrOrganization> queryWrapper = this.createWrapper(hrOrganizationRequest);
// 如果查询条件有orgId则查询指定机构下的子机构
Long parentId = commonOrgTreeRequest.getOrgParentId();
if (parentId != null) {
queryWrapper.eq(HrOrganization::getOrgParentId, parentId);
}
// 如果有定位状态的组织机构,则需要查询到定位的组织机构的所有子一级
Set<Long> indexOrgIdList = commonOrgTreeRequest.getIndexOrgIdList();
if (ObjectUtil.isNotEmpty(indexOrgIdList)) {
Set<Long> parentIdListTotal = this.queryOrgIdParentIdList(indexOrgIdList);
if (ObjectUtil.isNotEmpty(parentIdListTotal)) {
queryWrapper.in(HrOrganization::getOrgParentId, parentIdListTotal);
}
}
// 如果有筛选公司的标识,则只查询公司列表
Boolean companySearchFlag = commonOrgTreeRequest.getCompanySearchFlag();
if (ObjectUtil.isNotEmpty(companySearchFlag) && companySearchFlag) {
queryWrapper.eq(HrOrganization::getOrgType, OrgTypeEnum.COMPANY.getCode());
}
return queryWrapper;
}
/**
*
*