mirror of https://gitee.com/stylefeng/roses
【8.0】【system】更新通用组织机构树获取,改为懒加载方式
parent
9f5360de43
commit
fffb3a603f
|
@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除组织机构
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue