【8.0】【org】组织机构树更新返回展开orgId数组

pull/57/head
fengshuonan 2023-07-17 11:16:35 +08:00
parent fd3aa4ef1b
commit 095645d55b
5 changed files with 80 additions and 15 deletions

View File

@ -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.pojo.request.CommonOrgTreeRequest;
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 org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
/**
*
@ -40,7 +40,7 @@ public class CommonOrgController {
* @since 2023/6/11 10:31
*/
@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));
}

View File

@ -154,13 +154,6 @@ public class HrOrganization extends BaseExpandFieldEntity implements AbstractTre
@ChineseDescription("是否有子级true-有子级false-无子级")
private Boolean haveSubOrgFlag = false;
/**
* true-false-
*/
@TableField(exist = false)
@ChineseDescription("是否要展开显示true-展开本节点显示false-不展开显示")
private Boolean expandShowFlag = false;
@Override
public String getNodeId() {
if (this.orgId == null) {

View File

@ -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;
}
}

View File

@ -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.pojo.request.CommonOrgTreeRequest;
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 com.baomidou.mybatisplus.extension.service.IService;
@ -102,7 +103,7 @@ public interface HrOrganizationService extends IService<HrOrganization>, Organiz
* @author fengshuonan
* @since 2023/6/11 10:40
*/
List<HrOrganization> commonOrgTree(CommonOrgTreeRequest commonOrgTreeRequest);
CommonOrgTreeResponse commonOrgTree(CommonOrgTreeRequest commonOrgTreeRequest);
/**
* id

View File

@ -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.pojo.request.CommonOrgTreeRequest;
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.service.HrOrganizationService;
import cn.stylefeng.roses.kernel.sys.modular.position.service.HrPositionService;
@ -197,7 +198,7 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
}
@Override
public List<HrOrganization> commonOrgTree(CommonOrgTreeRequest commonOrgTreeRequest) {
public CommonOrgTreeResponse commonOrgTree(CommonOrgTreeRequest commonOrgTreeRequest) {
// 如果查询带组织机构名称的搜索,则清空其他条件
if (ObjectUtil.isNotEmpty(commonOrgTreeRequest.getSearchText())) {
@ -217,7 +218,7 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
List<HrOrganization> hrOrganizationList = this.list(wrapper);
if (ObjectUtil.isEmpty(hrOrganizationList)) {
return hrOrganizationList;
return new CommonOrgTreeResponse(hrOrganizationList, new ArrayList<>());
}
// 如果查询条件不为空,则把相关的查询结果的父级也查询出来,组成一颗完整树
@ -250,7 +251,11 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
// 遍历所有节点查询这些节点有没有子级填充haveSubOrgFlag
this.fillHaveSubFlag(newNotRepeatList);
return newNotRepeatList;
// 遍历这些节点如果有children的都展开并搜集到数组里
List<Long> expandOrgIds = new ArrayList<>();
this.fillExpandFlag(newNotRepeatList, expandOrgIds);
return new CommonOrgTreeResponse(newNotRepeatList, expandOrgIds);
}
@Override
@ -612,8 +617,6 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
// 如果有children则将展开标识填充并继续向下递归填充
if (ObjectUtil.isNotEmpty(organization.getChildren())) {
organization.setExpandShowFlag(true);
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
*