feat:[REQ-3488] 替换判空方法,使用hutool提供的工具

This commit is contained in:
liuyang 2025-01-14 16:05:57 +08:00
parent 94fd1421c8
commit cfda8a36b7
2 changed files with 19 additions and 46 deletions

View File

@ -86,7 +86,6 @@ public class CooperateShipServiceImpl implements CooperateShipService {
UnitQueryRepository.UnitResp unit = unitQueryRepository.oneOpt(UnitQueryRepository.OneReq.builder()
.id(node.getId())
.build()).orElseThrow(() -> BizResultCode.ENTITY_NOT_FOUND.toException("单位不存在{}", node.getOrganizationalUnitId()));
SaasCooperateShip cooperateShip = SaasCooperateShip.builder()
.parentId(req.getParentId())
.workspaceId(workspace.getId())
@ -145,15 +144,15 @@ public class CooperateShipServiceImpl implements CooperateShipService {
// 构建查询条件
CooperateShipQueryRepository.ListReq listReq = CooperateShipQueryRepository.ListReq.builder()
.ids(filterNullValues(req.getIds()))
.workspaceIds(filterNullValues(req.getWorkspaceIds()))
.workspaceTypes(filterNullValues(req.getWorkspaceTypes()))
.ouIds(filterNullValues(req.getOuIds()))
.includeCooperateTypes(filterNullValues(req.getIncludeCooperateTypes()))
.excludeCooperateTypes(filterNullValues(req.getExcludeCooperateTypes()))
.organizationNodeIds(filterNullValues(req.getOrganizationNodeIds()))
.partnerShips(filterNullValues(req.getPartnerShips()))
.statuses(filterNullValues(req.getStatuses()))
.ids(CollUtil.removeNull(req.getIds()))
.workspaceIds(CollUtil.removeNull(req.getWorkspaceIds()))
.workspaceTypes(CollUtil.removeNull(req.getWorkspaceTypes()))
.ouIds(CollUtil.removeNull(req.getOuIds()))
.includeCooperateTypes(CollUtil.removeNull(req.getIncludeCooperateTypes()))
.excludeCooperateTypes(CollUtil.removeNull(req.getExcludeCooperateTypes()))
.organizationNodeIds(CollUtil.removeNull(req.getOrganizationNodeIds()))
.partnerShips(CollUtil.removeNull(req.getPartnerShips()))
.statuses(CollUtil.removeNull(req.getStatuses()))
.build();
// 根据入参查询数据
List<SaasCooperateShip> currentNodeList = cooperateShipQueryRepository.list(listReq);
@ -218,17 +217,4 @@ public class CooperateShipServiceImpl implements CooperateShipService {
resultNodeList.sort(Comparator.comparing(SaasCooperateShip::getPath));
return BeanUtil.copyToList(CollUtil.distinct(resultNodeList, SaasCooperateShip::getId, true), OrgCooperateShipDTO.class);
}
/**
* 过滤空值
* @param collection
* @return
* @param <T>
*/
private <C extends Collection<T>, T> C filterNullValues(C collection) {
if (CollUtil.isEmpty(collection)) {
return collection;
}
return CollUtil.filter(collection, Objects::nonNull);
}
}

View File

@ -59,7 +59,7 @@ public class ListNodeCmdExe {
// 条件: 当入参传入岗位标签并且组织用户有数据时
// 场景查询指定人员所在的组织节点并且岗位标签匹配
if (CollUtil.isNotEmpty(req.getJobCodes()) && CollUtil.isNotEmpty(nodeUsers)) {
nodeUserFoundationService.filterByJobs(nodeUsers, filterNullValues(req.getJobCodes()));
nodeUserFoundationService.filterByJobs(nodeUsers, CollUtil.removeNull(req.getJobCodes()));
if (CollUtil.isEmpty(nodeUsers)) {
return emptyPageResp;
}
@ -71,8 +71,8 @@ public class ListNodeCmdExe {
if (CollUtil.isNotEmpty(req.getWorkspaceIds()) || CollUtil.isNotEmpty(req.getWorkspaceOuPairs())) {
List<Long> topNodeIds = CollUtil.map(cooperateShipQueryRepository.list(CooperateShipQueryRepository.ListReq
.builder()
.workspaceIds(filterNullValues((req.getWorkspaceIds())))
.workspaceOuPairs(filterNullValues((req.getWorkspaceOuPairs())))
.workspaceIds(CollUtil.removeNull((req.getWorkspaceIds())))
.workspaceOuPairs(CollUtil.removeNull((req.getWorkspaceOuPairs())))
.build()), SaasCooperateShip::getOrganizationalNodeId, true);
if (CollUtil.isEmpty(topNodeIds)) {
return emptyPageResp;
@ -110,14 +110,14 @@ public class ListNodeCmdExe {
NodeQueryRepository.ListReq listReq = reqListBuilder
.page(req.getPage())
.pageSize(req.getPageSize())
.ids(filterNullValues(req.getIds()))
.parentIds(filterNullValues(req.getParentIds()))
.ouIds(filterNullValues(req.getOuIds()))
.topNodeIds(filterNullValues(req.getTopNodeIds()))
.ids(CollUtil.removeNull(req.getIds()))
.parentIds(CollUtil.removeNull(req.getParentIds()))
.ouIds(CollUtil.removeNull(req.getOuIds()))
.topNodeIds(CollUtil.removeNull(req.getTopNodeIds()))
.nodeName(req.getNodeName())
.nodeNames(filterNullValues(req.getNodeNames()))
.includeOrgNodeTypes(filterNullValues(req.getIncludeOrgNodeTypes()))
.excludeOrgNodeTypes(filterNullValues(req.getExcludeOrgNodeTypes()))
.nodeNames(CollUtil.removeNull(req.getNodeNames()))
.includeOrgNodeTypes(CollUtil.removeNull(req.getIncludeOrgNodeTypes()))
.excludeOrgNodeTypes(CollUtil.removeNull(req.getExcludeOrgNodeTypes()))
.includeDelete(req.getIncludeDelete())
.isSelectTopNodeOnly(req.getIsSelectTopNodeOnly()).build();
@ -263,17 +263,4 @@ public class ListNodeCmdExe {
});
}
/**
* 过滤空值
* @param collection
* @return
* @param <T>
*/
private <C extends Collection<T>, T> C filterNullValues(C collection) {
if (CollUtil.isEmpty(collection)) {
return collection;
}
return CollUtil.filter(collection, Objects::nonNull);
}
}