mirror of https://gitee.com/stylefeng/roses
【8.0】【org】组织机构树更新返回展开orgId数组
parent
fd3aa4ef1b
commit
095645d55b
|
@ -9,12 +9,12 @@ 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.entity.HrOrganization;
|
||||||
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.request.CommonOrgTreeRequest;
|
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.request.HrOrganizationRequest;
|
||||||
|
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.response.CommonOrgTreeResponse;
|
||||||
import cn.stylefeng.roses.kernel.sys.modular.org.service.HrOrganizationService;
|
import cn.stylefeng.roses.kernel.sys.modular.org.service.HrOrganizationService;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通用组织机构接口
|
* 通用组织机构接口
|
||||||
|
@ -40,7 +40,7 @@ public class CommonOrgController {
|
||||||
* @since 2023/6/11 10:31
|
* @since 2023/6/11 10:31
|
||||||
*/
|
*/
|
||||||
@PostResource(name = "通用获取组织机构树", path = "/common/org/tree")
|
@PostResource(name = "通用获取组织机构树", path = "/common/org/tree")
|
||||||
public ResponseData<List<HrOrganization>> commonOrgTree(@RequestBody CommonOrgTreeRequest commonOrgTreeRequest) {
|
public ResponseData<CommonOrgTreeResponse> commonOrgTree(@RequestBody CommonOrgTreeRequest commonOrgTreeRequest) {
|
||||||
return new SuccessResponseData<>(hrOrganizationService.commonOrgTree(commonOrgTreeRequest));
|
return new SuccessResponseData<>(hrOrganizationService.commonOrgTree(commonOrgTreeRequest));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -154,13 +154,6 @@ public class HrOrganization extends BaseExpandFieldEntity implements AbstractTre
|
||||||
@ChineseDescription("是否有子级:true-有子级,false-无子级")
|
@ChineseDescription("是否有子级:true-有子级,false-无子级")
|
||||||
private Boolean haveSubOrgFlag = false;
|
private Boolean haveSubOrgFlag = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否要展开显示:true-展开本节点显示,false-不展开显示
|
|
||||||
*/
|
|
||||||
@TableField(exist = false)
|
|
||||||
@ChineseDescription("是否要展开显示:true-展开本节点显示,false-不展开显示")
|
|
||||||
private Boolean expandShowFlag = false;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getNodeId() {
|
public String getNodeId() {
|
||||||
if (this.orgId == null) {
|
if (this.orgId == null) {
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
package cn.stylefeng.roses.kernel.sys.modular.org.pojo.response;
|
||||||
|
|
||||||
|
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||||
|
import cn.stylefeng.roses.kernel.sys.modular.org.entity.HrOrganization;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 组织机构树响应结果
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @since 2023/7/17 11:04
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class CommonOrgTreeResponse {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 组织机构树列表
|
||||||
|
*/
|
||||||
|
@ChineseDescription("组织机构树列表")
|
||||||
|
private List<HrOrganization> orgTreeList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 展开显示组织机构id的列表
|
||||||
|
*/
|
||||||
|
@ChineseDescription("展开显示组织机构id的列表")
|
||||||
|
private List<Long> expandOrgIdList = new ArrayList<>();
|
||||||
|
|
||||||
|
public CommonOrgTreeResponse() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommonOrgTreeResponse(List<HrOrganization> orgTreeList, List<Long> expandOrgIdList) {
|
||||||
|
this.orgTreeList = orgTreeList;
|
||||||
|
this.expandOrgIdList = expandOrgIdList;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -6,6 +6,7 @@ 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.entity.HrOrganization;
|
||||||
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.request.CommonOrgTreeRequest;
|
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.request.HrOrganizationRequest;
|
||||||
|
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.response.CommonOrgTreeResponse;
|
||||||
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.response.HomeCompanyInfo;
|
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.response.HomeCompanyInfo;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
@ -102,7 +103,7 @@ public interface HrOrganizationService extends IService<HrOrganization>, Organiz
|
||||||
* @author fengshuonan
|
* @author fengshuonan
|
||||||
* @since 2023/6/11 10:40
|
* @since 2023/6/11 10:40
|
||||||
*/
|
*/
|
||||||
List<HrOrganization> commonOrgTree(CommonOrgTreeRequest commonOrgTreeRequest);
|
CommonOrgTreeResponse commonOrgTree(CommonOrgTreeRequest commonOrgTreeRequest);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据组织机构id,获取对应的具体的公司和部门信息
|
* 根据组织机构id,获取对应的具体的公司和部门信息
|
||||||
|
|
|
@ -29,6 +29,7 @@ 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.mapper.HrOrganizationMapper;
|
||||||
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.request.CommonOrgTreeRequest;
|
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.request.HrOrganizationRequest;
|
||||||
|
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.response.CommonOrgTreeResponse;
|
||||||
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.response.HomeCompanyInfo;
|
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.response.HomeCompanyInfo;
|
||||||
import cn.stylefeng.roses.kernel.sys.modular.org.service.HrOrganizationService;
|
import cn.stylefeng.roses.kernel.sys.modular.org.service.HrOrganizationService;
|
||||||
import cn.stylefeng.roses.kernel.sys.modular.position.service.HrPositionService;
|
import cn.stylefeng.roses.kernel.sys.modular.position.service.HrPositionService;
|
||||||
|
@ -197,7 +198,7 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<HrOrganization> commonOrgTree(CommonOrgTreeRequest commonOrgTreeRequest) {
|
public CommonOrgTreeResponse commonOrgTree(CommonOrgTreeRequest commonOrgTreeRequest) {
|
||||||
|
|
||||||
// 如果查询带组织机构名称的搜索,则清空其他条件
|
// 如果查询带组织机构名称的搜索,则清空其他条件
|
||||||
if (ObjectUtil.isNotEmpty(commonOrgTreeRequest.getSearchText())) {
|
if (ObjectUtil.isNotEmpty(commonOrgTreeRequest.getSearchText())) {
|
||||||
|
@ -217,7 +218,7 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
|
||||||
List<HrOrganization> hrOrganizationList = this.list(wrapper);
|
List<HrOrganization> hrOrganizationList = this.list(wrapper);
|
||||||
|
|
||||||
if (ObjectUtil.isEmpty(hrOrganizationList)) {
|
if (ObjectUtil.isEmpty(hrOrganizationList)) {
|
||||||
return hrOrganizationList;
|
return new CommonOrgTreeResponse(hrOrganizationList, new ArrayList<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果查询条件不为空,则把相关的查询结果的父级也查询出来,组成一颗完整树
|
// 如果查询条件不为空,则把相关的查询结果的父级也查询出来,组成一颗完整树
|
||||||
|
@ -250,7 +251,11 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
|
||||||
// 遍历所有节点,查询这些节点有没有子级,填充haveSubOrgFlag
|
// 遍历所有节点,查询这些节点有没有子级,填充haveSubOrgFlag
|
||||||
this.fillHaveSubFlag(newNotRepeatList);
|
this.fillHaveSubFlag(newNotRepeatList);
|
||||||
|
|
||||||
return newNotRepeatList;
|
// 遍历这些节点,如果有children的,都展开,并搜集到数组里
|
||||||
|
List<Long> expandOrgIds = new ArrayList<>();
|
||||||
|
this.fillExpandFlag(newNotRepeatList, expandOrgIds);
|
||||||
|
|
||||||
|
return new CommonOrgTreeResponse(newNotRepeatList, expandOrgIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -612,8 +617,6 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
|
||||||
|
|
||||||
// 如果有children则将展开标识填充,并继续向下递归填充
|
// 如果有children则将展开标识填充,并继续向下递归填充
|
||||||
if (ObjectUtil.isNotEmpty(organization.getChildren())) {
|
if (ObjectUtil.isNotEmpty(organization.getChildren())) {
|
||||||
organization.setExpandShowFlag(true);
|
|
||||||
|
|
||||||
fillHaveSubFlag(organization.getChildren());
|
fillHaveSubFlag(organization.getChildren());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -621,6 +624,34 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 填充是否展开的标识
|
||||||
|
* <p>
|
||||||
|
* 判定是否展开,如果有children则展开
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @since 2023/7/17 11:11
|
||||||
|
*/
|
||||||
|
private void fillExpandFlag(List<HrOrganization> organizations, List<Long> expandOrgIds) {
|
||||||
|
|
||||||
|
if (ObjectUtil.isEmpty(organizations)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (HrOrganization organization : organizations) {
|
||||||
|
|
||||||
|
Long orgId = organization.getOrgId();
|
||||||
|
|
||||||
|
// 如果有children则将展开标识填充,并继续向下递归填充
|
||||||
|
if (ObjectUtil.isNotEmpty(organization.getChildren())) {
|
||||||
|
expandOrgIds.add(orgId);
|
||||||
|
|
||||||
|
// 搜集子集的children的展开标识
|
||||||
|
fillExpandFlag(organization.getChildren(), expandOrgIds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 计算获取上级组织机构id
|
* 计算获取上级组织机构id
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue