fix:数据查询优化排序问题
This commit is contained in:
@@ -73,24 +73,51 @@ public class FileSizeUtils {
|
||||
* @param unit 文件大小单位 (B, KB, MB, GB, TB)
|
||||
* @return 字节大小
|
||||
*/
|
||||
public static Long convertToBytes(Long size, String unit) {
|
||||
public static Long convertToBytes(BigDecimal size, String unit) {
|
||||
if (size == null || unit == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
BigDecimal result;
|
||||
switch (unit.toUpperCase()) {
|
||||
case "B":
|
||||
return size;
|
||||
case "KB":
|
||||
return size * 1024L;
|
||||
case "MB":
|
||||
return size * 1024L * 1024L;
|
||||
case "GB":
|
||||
return size * 1024L * 1024L * 1024L;
|
||||
case "TB":
|
||||
return size * 1024L * 1024L * 1024L * 1024L;
|
||||
default:
|
||||
return size; // 默认认为是字节
|
||||
case "B" -> result = size;
|
||||
case "KB" -> result = size.multiply(new BigDecimal("1024"));
|
||||
case "MB" -> result = size.multiply(new BigDecimal("1048576")); // 1024^2
|
||||
case "GB" -> result = size.multiply(new BigDecimal("1073741824")); // 1024^3
|
||||
case "TB" -> result = size.multiply(new BigDecimal("1099511627776")); // 1024^4
|
||||
default -> result = size;
|
||||
}
|
||||
|
||||
return result.longValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将格式化后的文件大小字符串转换为字节数
|
||||
* @param formatFileSize 格式化后的文件大小(如 "1.06 KB", "6.02 MB", "1.06KB")
|
||||
* @return 字节数
|
||||
*/
|
||||
public static Long parseFileSizeToBytes(String formatFileSize) {
|
||||
if (formatFileSize == null || formatFileSize.trim().isEmpty()) {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
formatFileSize = formatFileSize.trim().toUpperCase();
|
||||
|
||||
// 使用正则表达式匹配数字和单位
|
||||
// 匹配模式:数字(可能包含小数点)+ 可选的空白 + 单位
|
||||
java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("([\\d.]+)\\s*([A-Z]+)");
|
||||
java.util.regex.Matcher matcher = pattern.matcher(formatFileSize);
|
||||
|
||||
if (!matcher.matches()) {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
try {
|
||||
BigDecimal value = new BigDecimal(matcher.group(1));
|
||||
String unit = matcher.group(2);
|
||||
return convertToBytes(value, unit);
|
||||
} catch (NumberFormatException e) {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -123,6 +123,7 @@ public class DataAnalysisServiceImpl implements IDataAnalysisService {
|
||||
GetSimulationTaskFileReq secondReq = new GetSimulationTaskFileReq();
|
||||
BeanUtils.copyProperties(req, secondReq);
|
||||
// 用二次文件类型比如 曲线文件 替换
|
||||
secondReq.setDictTagIdsCache(null);
|
||||
secondReq.setFileTypeDictValue(secondFileTypeDictValue);
|
||||
Set<Long> secondFileIdsByDictTags = extractFileIdsByTags(secondReq);
|
||||
if(CollectionUtils.isNotEmpty(secondFileIdsByDictTags)){
|
||||
@@ -182,7 +183,9 @@ public class DataAnalysisServiceImpl implements IDataAnalysisService {
|
||||
PageInfo<FileMetadataInfo> page = new PageInfo<>(fileMetadataInfos);
|
||||
|
||||
// 设置tag1-tag10
|
||||
List<SimulationTaskResultCurveResp> finalResultList = hierarchyHelper.processFileHierarchyFromFileMetadata(fileMetadataInfos,SimulationTaskResultCurveResp.class);
|
||||
List<SimulationTaskResultCurveResp> finalResultList = new ArrayList<>(
|
||||
hierarchyHelper.processFileHierarchyFromFileMetadata(fileMetadataInfos, SimulationTaskResultCurveResp.class)
|
||||
);
|
||||
hierarchyHelper.setTagReqFromFileMetadataBatch(finalResultList, SimulationTaskResultCurveResp::getId);
|
||||
|
||||
// 填充文件类型标签信息
|
||||
@@ -199,9 +202,9 @@ public class DataAnalysisServiceImpl implements IDataAnalysisService {
|
||||
Comparator.comparing(SimulationTaskResultCurveResp::getCreateTime, Comparator.nullsLast(LocalDateTime::compareTo))
|
||||
// 第二步:createTime 相同时,按 sortOrder 排序(null 排最后)
|
||||
.thenComparing(SimulationTaskResultCurveResp::getSortOrder, Comparator.nullsLast(Integer::compare))
|
||||
).toList();
|
||||
pageInfo = new PageInfo<>(sortedList);
|
||||
}else {
|
||||
).collect(Collectors.toCollection(ArrayList::new));
|
||||
pageInfo = new PageInfo<>(sortedList);
|
||||
} else {
|
||||
pageInfo = new PageInfo<>(finalResultList);
|
||||
}
|
||||
|
||||
@@ -393,7 +396,7 @@ public class DataAnalysisServiceImpl implements IDataAnalysisService {
|
||||
return item.getOriginalName();
|
||||
}
|
||||
if ("formatFileSize".equalsIgnoreCase(orderBy)) {
|
||||
return item.getFormatFileSize();
|
||||
return String.valueOf(FileSizeUtils.parseFileSizeToBytes(item.getFormatFileSize()));
|
||||
}
|
||||
|
||||
TagReq tagReq = item.getTagReq();
|
||||
|
||||
Reference in New Issue
Block a user