排序BUG修复

pull/225/head
dxfeng 2 years ago
parent 35cf5dc8f6
commit 1e3cacdc6e

@ -75,7 +75,7 @@ public class CompBO {
.build(); .build();
} }
public static List<CompListDTO> buildCompDTOList(Collection<CompPO> list, List<CompPO> filterList) { public static List<CompListDTO> buildCompDTOList(Collection<CompPO> list, List<CompPO> filterList, String orderType) {
// 搜索结果为空,直接返回空 // 搜索结果为空,直接返回空
if (CollectionUtils.isEmpty(filterList)) { if (CollectionUtils.isEmpty(filterList)) {
return Collections.emptyList(); return Collections.emptyList();
@ -87,10 +87,10 @@ public class CompBO {
dealParentData(addedList, po, poMaps); dealParentData(addedList, po, poMaps);
} }
return buildCompDTOList(addedList); return buildCompDTOList(addedList, orderType);
} }
public static List<CompListDTO> buildCompDTOList(List<CompPO> list) { public static List<CompListDTO> buildCompDTOList(List<CompPO> list, String orderType) {
Map<Integer, CompPO> poMaps = list.stream().collect(Collectors.toMap(CompPO::getId, item -> item)); Map<Integer, CompPO> poMaps = list.stream().collect(Collectors.toMap(CompPO::getId, item -> item));
@ -105,6 +105,7 @@ public class CompBO {
.supSubComName(null == poMaps.get(e.getSupSubComId()) ? "" : poMaps.get(e.getSupSubComId()).getSubCompanyName()) .supSubComName(null == poMaps.get(e.getSupSubComId()) ? "" : poMaps.get(e.getSupSubComId()).getSubCompanyName())
.showOrder(e.getShowOrder()) .showOrder(e.getShowOrder())
.canceled(null == e.getCanceled() ? 0 : e.getCanceled()) .canceled(null == e.getCanceled() ? 0 : e.getCanceled())
.orderType(orderType)
.build()).collect(Collectors.toList()); .build()).collect(Collectors.toList());
Map<Integer, List<CompListDTO>> collects = dtoList.stream().filter(item -> 0 != item.getSupSubComId()).collect(Collectors.groupingBy(CompListDTO::getSupSubComId)); Map<Integer, List<CompListDTO>> collects = dtoList.stream().filter(item -> 0 != item.getSupSubComId()).collect(Collectors.groupingBy(CompListDTO::getSupSubComId));
// 处理被引用数据 // 处理被引用数据

@ -2,12 +2,16 @@ package com.engine.organization.entity.company.dto;
import com.engine.organization.annotation.OrganizationTable; import com.engine.organization.annotation.OrganizationTable;
import com.engine.organization.annotation.TableTitle; import com.engine.organization.annotation.TableTitle;
import com.engine.organization.entity.department.dto.DepartmentListDTO;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.apache.commons.collections.CollectionUtils;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* @author:dxfeng * @author:dxfeng
@ -78,4 +82,17 @@ public class CompListDTO {
public Integer getShowOrder() { public Integer getShowOrder() {
return null == showOrder ? 0 : showOrder; return null == showOrder ? 0 : showOrder;
} }
private String orderType;
public List<CompListDTO> getChildren() {
if (CollectionUtils.isEmpty(children)) {
return children;
}
if ("asc".equalsIgnoreCase(orderType)) {
return children.stream().sorted(Comparator.comparing(CompListDTO::getShowOrder)).collect(Collectors.toList());
} else {
return children.stream().sorted(Comparator.comparing(CompListDTO::getShowOrder).reversed()).collect(Collectors.toList());
}
}
} }

@ -27,6 +27,7 @@ public class DepartmentBO {
/** /**
* *
*
* @param list * @param list
* @return * @return
*/ */
@ -41,7 +42,7 @@ public class DepartmentBO {
).collect(Collectors.toList()); ).collect(Collectors.toList());
} }
public static List<DepartmentListDTO> buildDeptDTOList(Collection<DepartmentPO> list) { public static List<DepartmentListDTO> buildDeptDTOList(Collection<DepartmentPO> list, String orderType) {
// 递归添加父级数据 // 递归添加父级数据
List<DepartmentListDTO> dtoList = list.stream().map(e -> List<DepartmentListDTO> dtoList = list.stream().map(e ->
DepartmentListDTO DepartmentListDTO
@ -54,6 +55,7 @@ public class DepartmentBO {
.supDepId(e.getSupDepId()) .supDepId(e.getSupDepId())
.showOrder(null == e.getShowOrder() ? 0 : e.getShowOrder()) .showOrder(null == e.getShowOrder() ? 0 : e.getShowOrder())
.canceled(null == e.getCanceled() ? 0 : e.getCanceled()) .canceled(null == e.getCanceled() ? 0 : e.getCanceled())
.orderType(orderType)
.build()).collect(Collectors.toList()); .build()).collect(Collectors.toList());
Map<Integer, List<DepartmentListDTO>> collects = dtoList.stream().filter(item -> null != item.getSupDepId() && 0 != item.getSupDepId()).collect(Collectors.groupingBy(DepartmentListDTO::getSupDepId)); Map<Integer, List<DepartmentListDTO>> collects = dtoList.stream().filter(item -> null != item.getSupDepId() && 0 != item.getSupDepId()).collect(Collectors.groupingBy(DepartmentListDTO::getSupDepId));
// 处理被引用数据 // 处理被引用数据
@ -74,7 +76,7 @@ public class DepartmentBO {
}).filter(item -> null == item.getSupDepId() || 0 == item.getSupDepId()).collect(Collectors.toList()); }).filter(item -> null == item.getSupDepId() || 0 == item.getSupDepId()).collect(Collectors.toList());
} }
public static List<DepartmentListDTO> buildDeptDTOList(Collection<DepartmentPO> list, List<DepartmentPO> filterList) { public static List<DepartmentListDTO> buildDeptDTOList(Collection<DepartmentPO> list, List<DepartmentPO> filterList, String orderType) {
// 搜索结果为空,直接返回空 // 搜索结果为空,直接返回空
if (CollectionUtils.isEmpty(filterList)) { if (CollectionUtils.isEmpty(filterList)) {
return Collections.emptyList(); return Collections.emptyList();
@ -85,7 +87,7 @@ public class DepartmentBO {
for (DepartmentPO po : filterList) { for (DepartmentPO po : filterList) {
dealParentData(addedList, po, poMaps); dealParentData(addedList, po, poMaps);
} }
return buildDeptDTOList(addedList); return buildDeptDTOList(addedList, orderType);
} }
public static DepartmentPO convertParamsToPO(DeptSearchParam param, Integer employeeId) { public static DepartmentPO convertParamsToPO(DeptSearchParam param, Integer employeeId) {

@ -7,8 +7,11 @@ import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.apache.commons.collections.CollectionUtils;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* @Author weaver_cl * @Author weaver_cl
@ -91,7 +94,20 @@ public class DepartmentListDTO {
*/ */
private List<DepartmentListDTO> children; private List<DepartmentListDTO> children;
private String orderType;
public Double getShowOrder() { public Double getShowOrder() {
return null == showOrder ? 0 : showOrder; return null == showOrder ? 0 : showOrder;
} }
public List<DepartmentListDTO> getChildren() {
if (CollectionUtils.isEmpty(children)) {
return children;
}
if ("asc".equalsIgnoreCase(orderType)) {
return children.stream().sorted(Comparator.comparing(DepartmentListDTO::getShowOrder)).collect(Collectors.toList());
} else {
return children.stream().sorted(Comparator.comparing(DepartmentListDTO::getShowOrder).reversed()).collect(Collectors.toList());
}
}
} }

@ -83,7 +83,7 @@ public class CompServiceImpl extends Service implements CompService {
new DetachUtil(user).filterCompanyList(filterCompPOs); new DetachUtil(user).filterCompanyList(filterCompPOs);
// 添加父级元素 // 添加父级元素
List<CompListDTO> compListDTOS = CompBO.buildCompDTOList(allList, filterCompPOs); List<CompListDTO> compListDTOS = CompBO.buildCompDTOList(allList, filterCompPOs, orderType.toString());
if ("asc".equalsIgnoreCase(orderType.toString())) { if ("asc".equalsIgnoreCase(orderType.toString())) {
compListDTOS = compListDTOS.stream().sorted(Comparator.comparing(CompListDTO::getShowOrder)).collect(Collectors.toList()); compListDTOS = compListDTOS.stream().sorted(Comparator.comparing(CompListDTO::getShowOrder)).collect(Collectors.toList());
@ -95,7 +95,7 @@ public class CompServiceImpl extends Service implements CompService {
pageInfos.setTotal(compListDTOS.size()); pageInfos.setTotal(compListDTOS.size());
} else { } else {
// 组合list // 组合list
List<CompListDTO> compListDTOS = CompBO.buildCompDTOList(allList); List<CompListDTO> compListDTOS = CompBO.buildCompDTOList(allList, orderType.toString());
List<CompListDTO> subList = PageUtil.subList(params.getCurrent(), params.getPageSize(), compListDTOS); List<CompListDTO> subList = PageUtil.subList(params.getCurrent(), params.getPageSize(), compListDTOS);
pageInfos = new PageInfo<>(subList, CompListDTO.class); pageInfos = new PageInfo<>(subList, CompListDTO.class);
pageInfos.setTotal(compListDTOS.size()); pageInfos.setTotal(compListDTOS.size());

@ -142,7 +142,7 @@ public class DepartmentServiceImpl extends Service implements DepartmentService
List<DepartmentPO> filterDeptPOs = getDepartmentMapper().listByFilter(departmentPO, orderSql); List<DepartmentPO> filterDeptPOs = getDepartmentMapper().listByFilter(departmentPO, orderSql);
new DetachUtil(user).filterDepartmentList(filterDeptPOs); new DetachUtil(user).filterDepartmentList(filterDeptPOs);
// 添加父级元素 // 添加父级元素
List<DepartmentListDTO> compListDTOS = DepartmentBO.buildDeptDTOList(allList, filterDeptPOs); List<DepartmentListDTO> compListDTOS = DepartmentBO.buildDeptDTOList(allList, filterDeptPOs, orderType.toString());
if ("asc".equalsIgnoreCase(orderType.toString())) { if ("asc".equalsIgnoreCase(orderType.toString())) {
compListDTOS = compListDTOS.stream().sorted(Comparator.comparing(DepartmentListDTO::getShowOrder)).collect(Collectors.toList()); compListDTOS = compListDTOS.stream().sorted(Comparator.comparing(DepartmentListDTO::getShowOrder)).collect(Collectors.toList());
@ -154,7 +154,7 @@ public class DepartmentServiceImpl extends Service implements DepartmentService
pageInfos.setTotal(compListDTOS.size()); pageInfos.setTotal(compListDTOS.size());
} else { } else {
// 组合list // 组合list
List<DepartmentListDTO> compListDTOS = DepartmentBO.buildDeptDTOList(allList); List<DepartmentListDTO> compListDTOS = DepartmentBO.buildDeptDTOList(allList, orderType.toString());
List<DepartmentListDTO> subList = PageUtil.subList(param.getCurrent(), param.getPageSize(), compListDTOS); List<DepartmentListDTO> subList = PageUtil.subList(param.getCurrent(), param.getPageSize(), compListDTOS);
pageInfos = new PageInfo<>(DepartmentBO.buildDeptDTOShowNames(subList), DepartmentListDTO.class); pageInfos = new PageInfo<>(DepartmentBO.buildDeptDTOShowNames(subList), DepartmentListDTO.class);
pageInfos.setTotal(compListDTOS.size()); pageInfos.setTotal(compListDTOS.size());

Loading…
Cancel
Save