diff --git a/src/com/engine/organization/entity/company/bo/CompBO.java b/src/com/engine/organization/entity/company/bo/CompBO.java index 9281b193..99e84519 100644 --- a/src/com/engine/organization/entity/company/bo/CompBO.java +++ b/src/com/engine/organization/entity/company/bo/CompBO.java @@ -75,7 +75,7 @@ public class CompBO { .build(); } - public static List buildCompDTOList(Collection list, List filterList) { + public static List buildCompDTOList(Collection list, List filterList, String orderType) { // 搜索结果为空,直接返回空 if (CollectionUtils.isEmpty(filterList)) { return Collections.emptyList(); @@ -87,10 +87,10 @@ public class CompBO { dealParentData(addedList, po, poMaps); } - return buildCompDTOList(addedList); + return buildCompDTOList(addedList, orderType); } - public static List buildCompDTOList(List list) { + public static List buildCompDTOList(List list, String orderType) { Map 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()) .showOrder(e.getShowOrder()) .canceled(null == e.getCanceled() ? 0 : e.getCanceled()) + .orderType(orderType) .build()).collect(Collectors.toList()); Map> collects = dtoList.stream().filter(item -> 0 != item.getSupSubComId()).collect(Collectors.groupingBy(CompListDTO::getSupSubComId)); // 处理被引用数据 diff --git a/src/com/engine/organization/entity/company/dto/CompListDTO.java b/src/com/engine/organization/entity/company/dto/CompListDTO.java index 56809ee3..d1d5b05a 100644 --- a/src/com/engine/organization/entity/company/dto/CompListDTO.java +++ b/src/com/engine/organization/entity/company/dto/CompListDTO.java @@ -2,12 +2,16 @@ package com.engine.organization.entity.company.dto; import com.engine.organization.annotation.OrganizationTable; import com.engine.organization.annotation.TableTitle; +import com.engine.organization.entity.department.dto.DepartmentListDTO; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; +import org.apache.commons.collections.CollectionUtils; +import java.util.Comparator; import java.util.List; +import java.util.stream.Collectors; /** * @author:dxfeng @@ -78,4 +82,17 @@ public class CompListDTO { public Integer getShowOrder() { return null == showOrder ? 0 : showOrder; } + + private String orderType; + + public List 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()); + } + } } diff --git a/src/com/engine/organization/entity/department/bo/DepartmentBO.java b/src/com/engine/organization/entity/department/bo/DepartmentBO.java index d2ecf751..ac13e899 100644 --- a/src/com/engine/organization/entity/department/bo/DepartmentBO.java +++ b/src/com/engine/organization/entity/department/bo/DepartmentBO.java @@ -27,6 +27,7 @@ public class DepartmentBO { /** * 台账数据、值显示转换 + * * @param list * @return */ @@ -41,7 +42,7 @@ public class DepartmentBO { ).collect(Collectors.toList()); } - public static List buildDeptDTOList(Collection list) { + public static List buildDeptDTOList(Collection list, String orderType) { // 递归添加父级数据 List dtoList = list.stream().map(e -> DepartmentListDTO @@ -54,6 +55,7 @@ public class DepartmentBO { .supDepId(e.getSupDepId()) .showOrder(null == e.getShowOrder() ? 0 : e.getShowOrder()) .canceled(null == e.getCanceled() ? 0 : e.getCanceled()) + .orderType(orderType) .build()).collect(Collectors.toList()); Map> 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()); } - public static List buildDeptDTOList(Collection list, List filterList) { + public static List buildDeptDTOList(Collection list, List filterList, String orderType) { // 搜索结果为空,直接返回空 if (CollectionUtils.isEmpty(filterList)) { return Collections.emptyList(); @@ -85,7 +87,7 @@ public class DepartmentBO { for (DepartmentPO po : filterList) { dealParentData(addedList, po, poMaps); } - return buildDeptDTOList(addedList); + return buildDeptDTOList(addedList, orderType); } public static DepartmentPO convertParamsToPO(DeptSearchParam param, Integer employeeId) { diff --git a/src/com/engine/organization/entity/department/dto/DepartmentListDTO.java b/src/com/engine/organization/entity/department/dto/DepartmentListDTO.java index 12f4d51a..cbb078c5 100644 --- a/src/com/engine/organization/entity/department/dto/DepartmentListDTO.java +++ b/src/com/engine/organization/entity/department/dto/DepartmentListDTO.java @@ -7,8 +7,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; +import org.apache.commons.collections.CollectionUtils; +import java.util.Comparator; import java.util.List; +import java.util.stream.Collectors; /** * @Author weaver_cl @@ -91,7 +94,20 @@ public class DepartmentListDTO { */ private List children; + private String orderType; + public Double getShowOrder() { return null == showOrder ? 0 : showOrder; } + + public List 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()); + } + } } diff --git a/src/com/engine/organization/service/impl/CompServiceImpl.java b/src/com/engine/organization/service/impl/CompServiceImpl.java index c6d40a3f..44950809 100644 --- a/src/com/engine/organization/service/impl/CompServiceImpl.java +++ b/src/com/engine/organization/service/impl/CompServiceImpl.java @@ -83,7 +83,7 @@ public class CompServiceImpl extends Service implements CompService { new DetachUtil(user).filterCompanyList(filterCompPOs); // 添加父级元素 - List compListDTOS = CompBO.buildCompDTOList(allList, filterCompPOs); + List compListDTOS = CompBO.buildCompDTOList(allList, filterCompPOs, orderType.toString()); if ("asc".equalsIgnoreCase(orderType.toString())) { 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()); } else { // 组合list - List compListDTOS = CompBO.buildCompDTOList(allList); + List compListDTOS = CompBO.buildCompDTOList(allList, orderType.toString()); List subList = PageUtil.subList(params.getCurrent(), params.getPageSize(), compListDTOS); pageInfos = new PageInfo<>(subList, CompListDTO.class); pageInfos.setTotal(compListDTOS.size()); diff --git a/src/com/engine/organization/service/impl/DepartmentServiceImpl.java b/src/com/engine/organization/service/impl/DepartmentServiceImpl.java index d73b8171..8b14562c 100644 --- a/src/com/engine/organization/service/impl/DepartmentServiceImpl.java +++ b/src/com/engine/organization/service/impl/DepartmentServiceImpl.java @@ -142,7 +142,7 @@ public class DepartmentServiceImpl extends Service implements DepartmentService List filterDeptPOs = getDepartmentMapper().listByFilter(departmentPO, orderSql); new DetachUtil(user).filterDepartmentList(filterDeptPOs); // 添加父级元素 - List compListDTOS = DepartmentBO.buildDeptDTOList(allList, filterDeptPOs); + List compListDTOS = DepartmentBO.buildDeptDTOList(allList, filterDeptPOs, orderType.toString()); if ("asc".equalsIgnoreCase(orderType.toString())) { 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()); } else { // 组合list - List compListDTOS = DepartmentBO.buildDeptDTOList(allList); + List compListDTOS = DepartmentBO.buildDeptDTOList(allList, orderType.toString()); List subList = PageUtil.subList(param.getCurrent(), param.getPageSize(), compListDTOS); pageInfos = new PageInfo<>(DepartmentBO.buildDeptDTOShowNames(subList), DepartmentListDTO.class); pageInfos.setTotal(compListDTOS.size());