From 68d113f0ab84847042ff7f71dd7a198c8d76f35a Mon Sep 17 00:00:00 2001 From: nieziyan Date: Tue, 29 Aug 2023 09:12:45 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E8=B0=B1=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jeecg/common/constant/Prompt.java | 4 +-- .../base/comparator/FileComparator.java | 34 +++++++++++++++++++ .../org/jeecg/modules/base/dto/FileDto.java | 7 +--- .../service/impl/SpectrumFileServiceImpl.java | 7 +++- 4 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/comparator/FileComparator.java diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/Prompt.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/Prompt.java index d09954b2..b37d9ca5 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/Prompt.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/Prompt.java @@ -21,7 +21,7 @@ public interface Prompt { String DATA_NOT_EXITS = "The Query Data Does Not Exist!"; - String DATA_IS_EMPTY = "The Query Data IS Empty!"; + String DATA_IS_EMPTY = "The Query Data Is Empty!"; String FTP_ERR = "FTP Connection Failed!"; @@ -41,7 +41,7 @@ public interface Prompt { String UPLOAD_ERR = "File Upload Failure!"; - String FILE_NAME_REPEAT = "File With The Same Name Appears, Stop Uploading!"; + String FILE_IS_EMPTY = "The List Of Files You Uploaded Is Empty!"; String NEED_TIME = "The Start Time Or End Time Cannot Be Empty!"; } diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/comparator/FileComparator.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/comparator/FileComparator.java new file mode 100644 index 00000000..28626188 --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/comparator/FileComparator.java @@ -0,0 +1,34 @@ +package org.jeecg.modules.base.comparator; + +import cn.hutool.core.util.StrUtil; +import org.jeecg.modules.base.dto.FileDto; +import java.util.Comparator; + +public class FileComparator implements Comparator { + + private String field; + private String order; + + public FileComparator(String field, String order) { + this.field = field; + this.order = order; + } + + @Override + public int compare(FileDto file1, FileDto file2) { + if (StrUtil.equals(order,"asc")) { + if (StrUtil.equals(field,"name")) { + return file1.getName().compareTo(file2.getName()); + } else if (StrUtil.equals(field,"updateDate")) { + return file1.getUpdateDate().compareTo(file2.getUpdateDate()); + } + } else if (StrUtil.equals(order,"desc")) { + if (StrUtil.equals(field,"name")) { + return file2.getName().compareTo(file1.getName()); + } else if (StrUtil.equals(field,"updateDate")) { + return file2.getUpdateDate().compareTo(file1.getUpdateDate()); + } + } + return 0; + } +} diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/FileDto.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/FileDto.java index dde51d38..adc9e4cf 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/FileDto.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/FileDto.java @@ -8,7 +8,7 @@ import org.jetbrains.annotations.NotNull; import java.util.Date; @Data -public class FileDto implements Comparable{ +public class FileDto{ private String name; @@ -16,9 +16,4 @@ public class FileDto implements Comparable{ @JsonFormat(pattern = DateConstant.DATE_TIME,timezone = DateConstant.TIME_ZONE) private Date updateDate; - - @Override - public int compareTo(@NotNull FileDto o) { - return this.name.compareTo(o.getName()); - } } diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumFileServiceImpl.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumFileServiceImpl.java index 21bdfd28..9b50cad2 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumFileServiceImpl.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumFileServiceImpl.java @@ -16,6 +16,7 @@ import org.jeecg.common.constant.enums.FileTypeEnum; import org.jeecg.common.system.vo.LoginUser; import org.jeecg.common.util.FTPUtil; import org.jeecg.common.util.PageUtil; +import org.jeecg.modules.base.comparator.FileComparator; import org.jeecg.modules.base.dto.FileDto; import org.jeecg.modules.base.vo.FileVo; import org.jeecg.modules.service.ISpectrumFileService; @@ -70,6 +71,8 @@ public class SpectrumFileServiceImpl implements ISpectrumFileService { } fileList.add(oneFile); } + if (CollUtil.isEmpty(fileList)) + return Result.error(Prompt.FILE_IS_EMPTY); ftpClient = ftpUtil.LoginFTP(); if (ObjectUtil.isNull(ftpClient)) return Result.error(Prompt.FTP_ERR); @@ -139,7 +142,9 @@ public class SpectrumFileServiceImpl implements ISpectrumFileService { fileDto.setSize(formatSize(size)); fileDtos.add(fileDto); } - Collections.sort(fileDtos); + String field = fileVo.getField(); + String order = fileVo.getOrder(); + fileDtos.sort(new FileComparator(field, order)); List records = PageUtil.page(pageNo, pageSize, fileDtos); page.setRecords(records).setTotal(fileDtos.size()); return Result.OK(page);