feat:谱文件排序
This commit is contained in:
parent
ebf03f6949
commit
68d113f0ab
|
@ -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!";
|
||||
}
|
||||
|
|
|
@ -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<FileDto> {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@ import org.jetbrains.annotations.NotNull;
|
|||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class FileDto implements Comparable<FileDto>{
|
||||
public class FileDto{
|
||||
|
||||
private String name;
|
||||
|
||||
|
@ -16,9 +16,4 @@ public class FileDto implements Comparable<FileDto>{
|
|||
|
||||
@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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<FileDto> records = PageUtil.page(pageNo, pageSize, fileDtos);
|
||||
page.setRecords(records).setTotal(fileDtos.size());
|
||||
return Result.OK(page);
|
||||
|
|
Loading…
Reference in New Issue
Block a user