【7.2.3】增加获取公司下所有部门接口

pull/30/head
fengshuonan 2022-06-20 10:29:23 +08:00
parent 4734215e97
commit da90444889
3 changed files with 45 additions and 0 deletions

View File

@ -62,4 +62,13 @@ public interface OrganizationServiceApi {
* @date 2022/6/8 14:40
*/
List<OrganizationTreeNode> getOrgTreeList(HrOrganizationRequest hrOrganizationRequest);
/**
*
*
* @author fengshuonan
* @date 2022/6/16 18:26
*/
List<OrganizationTreeNode> getDeptOrgTree(Long orgId);
}

View File

@ -213,4 +213,16 @@ public class HrOrganizationController {
return new SuccessResponseData<>(list);
}
/**
*
*
* @author fengshuonan
* @date 2021/1/9 18:37
*/
@GetResource(name = "获取某个公司下部门的机构树", path = "/hrOrganization/getDeptOrgTree")
public ResponseData<List<OrganizationTreeNode>> getDeptOrgTree(@Validated(HrOrganizationRequest.detail.class) HrOrganizationRequest hrOrganizationRequest) {
List<OrganizationTreeNode> list = hrOrganizationService.getDeptOrgTree(hrOrganizationRequest.getOrgId());
return new SuccessResponseData<>(list);
}
}

View File

@ -33,6 +33,7 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
import cn.stylefeng.roses.kernel.auth.api.enums.DataScopeTypeEnum;
import cn.stylefeng.roses.kernel.db.api.DbOperatorApi;
import cn.stylefeng.roses.kernel.db.api.context.DbOperatorContext;
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
@ -94,6 +95,9 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
@Resource
private ExpandApi expandApi;
@Resource
private DbOperatorApi dbOperatorApi;
@Override
@Transactional(rollbackFor = Exception.class)
public void add(HrOrganizationRequest hrOrganizationRequest) {
@ -388,6 +392,26 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
return new DefaultTreeBuildFactory<OrganizationTreeNode>().doTreeBuild(treeNodeList);
}
@Override
public List<OrganizationTreeNode> getDeptOrgTree(Long orgId) {
// 获取该公司下所有的子部门id集合
Set<Long> deptIds = dbOperatorApi.findSubListByParentId("hr_organization", "org_pids", "org_id", orgId);
deptIds.add(orgId);
LambdaQueryWrapper<HrOrganization> wrapper = new LambdaQueryWrapper<>();
wrapper.in(HrOrganization::getOrgId, deptIds);
List<HrOrganization> hrOrganizationList = this.list(wrapper);
// 组装部门的树形节点
List<OrganizationTreeNode> treeNodeList = CollectionUtil.newArrayList();
for (HrOrganization hrOrganization : hrOrganizationList) {
OrganizationTreeNode treeNode = OrganizationFactory.parseOrganizationTreeNode(hrOrganization);
treeNodeList.add(treeNode);
}
return new DefaultTreeBuildFactory<OrganizationTreeNode>().doTreeBuild(treeNodeList);
}
/**
* wrapper
*