From cc32e4f2578cde8cb0f7d5b1a48d2f75b8a394d4 Mon Sep 17 00:00:00 2001 From: wangjiahao <1522128093@qq.com> Date: Fri, 15 Mar 2024 12:27:08 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E4=BB=AA=E8=A1=A8=E6=9D=BF):=20=E4=BB=AA?= =?UTF-8?q?=E8=A1=A8=E6=9D=BF=E8=B5=84=E6=BA=90=E6=A0=91=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/dataease/constant/SortConstants.java | 14 +++++++++ .../io/dataease/model/BusiNodeRequest.java | 2 ++ .../java/io/dataease/utils/TreeUtils.java | 31 ++++++++++++++----- 3 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 sdk/common/src/main/java/io/dataease/constant/SortConstants.java diff --git a/sdk/common/src/main/java/io/dataease/constant/SortConstants.java b/sdk/common/src/main/java/io/dataease/constant/SortConstants.java new file mode 100644 index 0000000000..07ef912530 --- /dev/null +++ b/sdk/common/src/main/java/io/dataease/constant/SortConstants.java @@ -0,0 +1,14 @@ +package io.dataease.constant; + +public class SortConstants { + + // 名称倒序 + public static final String NAME_DESC = "name_desc"; + // 名称正序 + public static final String NAME_ASC = "name_asc"; + // 时间倒序 + public static final String TIME_DESC = "time_desc"; + // 时间正序 + public static final String TIME_ASC = "time_asc"; + +} diff --git a/sdk/common/src/main/java/io/dataease/model/BusiNodeRequest.java b/sdk/common/src/main/java/io/dataease/model/BusiNodeRequest.java index cc8628d17a..092e481bd4 100644 --- a/sdk/common/src/main/java/io/dataease/model/BusiNodeRequest.java +++ b/sdk/common/src/main/java/io/dataease/model/BusiNodeRequest.java @@ -17,4 +17,6 @@ public class BusiNodeRequest implements Serializable { private Boolean leaf; private Integer weight; + + private String sortType; } diff --git a/sdk/common/src/main/java/io/dataease/utils/TreeUtils.java b/sdk/common/src/main/java/io/dataease/utils/TreeUtils.java index d9e8f71182..d7f2e64e04 100644 --- a/sdk/common/src/main/java/io/dataease/utils/TreeUtils.java +++ b/sdk/common/src/main/java/io/dataease/utils/TreeUtils.java @@ -1,17 +1,14 @@ package io.dataease.utils; -import io.dataease.model.ITreeBase; -import io.dataease.model.TreeBaseModel; -import io.dataease.model.TreeModel; -import io.dataease.model.TreeResultModel; +import io.dataease.constant.SortConstants; +import io.dataease.model.*; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.util.Assert; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; +import java.text.Collator; +import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; @@ -167,4 +164,22 @@ public class TreeUtils { return result; } + public static List customSortVO(List list, String sortType) { + Collator collator = Collator.getInstance(Locale.CHINA); + if (StringUtils.equalsIgnoreCase(SortConstants.NAME_DESC, sortType)) { + Set poSet = new TreeSet<>(Comparator.comparing(BusiNodeVO::getName, collator)); + poSet.addAll(list); + return poSet.stream().collect(Collectors.toList()); + } else if (StringUtils.equalsIgnoreCase(SortConstants.NAME_ASC, sortType)) { + Set poSet = new TreeSet<>(Comparator.comparing(BusiNodeVO::getName, collator).reversed()); + poSet.addAll(list); + return poSet.stream().collect(Collectors.toList()); + } else if (StringUtils.equalsIgnoreCase(SortConstants.TIME_ASC, sortType)) { + Collections.reverse(list); + return list; + } else { + // 默认时间倒序 + return list; + } + } }