fix:数据查询文件,优化多级节点无关联查询
This commit is contained in:
@@ -16,6 +16,9 @@ public class GetSimulationTaskFileReq extends BaseReq {
|
||||
@Schema(description = "文件所属项目节点uuid")
|
||||
private String uuid;
|
||||
|
||||
@Schema(description = "文件dirID")
|
||||
private Long dirId;
|
||||
|
||||
@Schema(description = "文件类型", implementation = FileBizTypeEnum.class)
|
||||
Integer fileBizType;
|
||||
|
||||
@@ -61,37 +64,36 @@ public class GetSimulationTaskFileReq extends BaseReq {
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime endTime;
|
||||
|
||||
@Schema(description = "标签1")
|
||||
private String tag1;
|
||||
|
||||
@Schema(description = "标签2")
|
||||
private String tag2;
|
||||
|
||||
@Schema(description = "标签3")
|
||||
private String tag3;
|
||||
|
||||
@Schema(description = "标签4")
|
||||
private String tag4;
|
||||
|
||||
@Schema(description = "标签5")
|
||||
private String tag5;
|
||||
|
||||
@Schema(description = "标签6")
|
||||
private String tag6;
|
||||
|
||||
@Schema(description = "标签7")
|
||||
private String tag7;
|
||||
|
||||
@Schema(description = "标签8")
|
||||
private String tag8;
|
||||
|
||||
@Schema(description = "标签9")
|
||||
private String tag9;
|
||||
|
||||
@Schema(description = "标签10")
|
||||
private String tag10;
|
||||
|
||||
@Schema(description = "查询层级:task 只查task下面的文件,不查子目录下的")
|
||||
private String level;
|
||||
|
||||
@Schema(description = "项目级 dirId 列表")
|
||||
private List<Long> projectDirIds;
|
||||
@Schema(description = "项目级 dirId 列表")
|
||||
private List<String> projectUUids;
|
||||
|
||||
@Schema(description = "阶段级 dirId 列表")
|
||||
private List<Long> phaseDirIds;
|
||||
@Schema(description = "阶段级 uuids 列表")
|
||||
private List<String> phaseUUids;
|
||||
|
||||
@Schema(description = "机台级 dirId 列表")
|
||||
private List<Long> machineDirIds;
|
||||
@Schema(description = "机台级 uuids 列表")
|
||||
private List<String> machineUUids;
|
||||
|
||||
@Schema(description = "工位级 dirId 列表")
|
||||
private List<Long> workspaceDirIds;
|
||||
@Schema(description = "工位级 uuids 列表")
|
||||
private List<String> workspaceUUids;
|
||||
|
||||
@Schema(description = "任务级 dirId 列表")
|
||||
private List<Long> taskDirIds;
|
||||
@Schema(description = "任务级 uuids 列表")
|
||||
private List<String> taskUUids;
|
||||
|
||||
@Schema(description = "算例级 uuids 列表")
|
||||
private List<Long> runDirIDs;
|
||||
@Schema(description = "算例级 uuids 列表")
|
||||
private List<String> runUUids;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,11 @@ public class QueryBigFileReq extends BaseReq {
|
||||
*/
|
||||
private List<Long> dirIds = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 目录ID列表的大小,用于 HAVING 子句
|
||||
*/
|
||||
private Integer dirIdsCount;
|
||||
|
||||
/**
|
||||
* 目录类型 DirTypeEnum
|
||||
*/
|
||||
|
||||
@@ -26,6 +26,7 @@ import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -66,8 +67,51 @@ public class DataAnalysisServiceImpl implements IDataAnalysisService {
|
||||
QueryBigFileReq queryBigFileReq = new QueryBigFileReq();
|
||||
BeanUtils.copyProperties(getSimulationTaskFileReq, queryBigFileReq);
|
||||
|
||||
// 获取特定 UUID 对应的目录 ID
|
||||
// 步骤 1: 收集所有直接传入的 dirId
|
||||
List<Long> allDirIds = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(getSimulationTaskFileReq.getProjectDirIds())) {
|
||||
allDirIds.addAll(getSimulationTaskFileReq.getProjectDirIds());
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(getSimulationTaskFileReq.getPhaseDirIds())) {
|
||||
allDirIds.addAll(getSimulationTaskFileReq.getPhaseDirIds());
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(getSimulationTaskFileReq.getMachineDirIds())) {
|
||||
allDirIds.addAll(getSimulationTaskFileReq.getMachineDirIds());
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(getSimulationTaskFileReq.getWorkspaceDirIds())) {
|
||||
allDirIds.addAll(getSimulationTaskFileReq.getWorkspaceDirIds());
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(getSimulationTaskFileReq.getTaskDirIds())) {
|
||||
allDirIds.addAll(getSimulationTaskFileReq.getTaskDirIds());
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(getSimulationTaskFileReq.getRunDirIDs())) {
|
||||
allDirIds.addAll(getSimulationTaskFileReq.getRunDirIDs());
|
||||
}
|
||||
|
||||
// 步骤 2: 收集所有需要转换的 UUID
|
||||
List<String> allUuids = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(getSimulationTaskFileReq.getProjectUUids())) {
|
||||
allUuids.addAll(getSimulationTaskFileReq.getProjectUUids());
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(getSimulationTaskFileReq.getPhaseUUids())) {
|
||||
allUuids.addAll(getSimulationTaskFileReq.getPhaseUUids());
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(getSimulationTaskFileReq.getMachineUUids())) {
|
||||
allUuids.addAll(getSimulationTaskFileReq.getMachineUUids());
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(getSimulationTaskFileReq.getWorkspaceUUids())) {
|
||||
allUuids.addAll(getSimulationTaskFileReq.getWorkspaceUUids());
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(getSimulationTaskFileReq.getTaskUUids())) {
|
||||
allUuids.addAll(getSimulationTaskFileReq.getTaskUUids());
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(getSimulationTaskFileReq.getRunUUids())) {
|
||||
allUuids.addAll(getSimulationTaskFileReq.getRunUUids());
|
||||
}
|
||||
|
||||
// 步骤 3: 兼容处理旧的单个 uuid 和 dirId 字段,uuid 优先
|
||||
if (ObjectUtils.isNotEmpty(getSimulationTaskFileReq.getUuid())) {
|
||||
allUuids.add(getSimulationTaskFileReq.getUuid());
|
||||
FileMetadataInfo fileMetadataInfo = fileMetadataInfoService.lambdaQuery()
|
||||
.eq(FileMetadataInfo::getRelatedResourceUuid, getSimulationTaskFileReq.getUuid())
|
||||
.eq(FileMetadataInfo::getTenantId, ThreadLocalContext.getTenantId())
|
||||
@@ -78,7 +122,31 @@ public class DataAnalysisServiceImpl implements IDataAnalysisService {
|
||||
log.error("未找到对应的 UUID 对应的目录");
|
||||
return PageUtils.getJsonObjectSdmResponse(new ArrayList<>(), new PageInfo<>());
|
||||
}
|
||||
} else if (ObjectUtils.isNotEmpty(getSimulationTaskFileReq.getDirId())) {
|
||||
allDirIds.add(getSimulationTaskFileReq.getDirId());
|
||||
}
|
||||
|
||||
// 步骤 4: 批量转换所有收集到的 UUID 并合并
|
||||
if (CollectionUtils.isNotEmpty(allUuids)) {
|
||||
List<Long> dirIdsFromUuids = fileMetadataInfoService.lambdaQuery()
|
||||
.in(FileMetadataInfo::getRelatedResourceUuid, allUuids)
|
||||
.eq(FileMetadataInfo::getTenantId, ThreadLocalContext.getTenantId())
|
||||
.list().stream().map(FileMetadataInfo::getId).collect(Collectors.toList());
|
||||
|
||||
// 因为是交集查询,如果传入了任何UUID,但一个对应的目录都找不到,那么最终结果必定为空。
|
||||
// 直接返回空集可以避免无效的数据库查询。
|
||||
if (CollectionUtils.isEmpty(dirIdsFromUuids)) {
|
||||
log.warn("根据传入的 UUIDs 未找到任何对应的目录: {}", allUuids);
|
||||
return PageUtils.getJsonObjectSdmResponse(new ArrayList<>(), new PageInfo<>());
|
||||
}
|
||||
allDirIds.addAll(dirIdsFromUuids);
|
||||
}
|
||||
|
||||
queryBigFileReq.setDirIds(allDirIds);
|
||||
if (CollectionUtils.isNotEmpty(allDirIds)) {
|
||||
queryBigFileReq.setDirIdsCount(allDirIds.size());
|
||||
}
|
||||
|
||||
// 查询层级是task 只查task目录下的直系文件
|
||||
if (NodeTypeEnum.TASK.getValue().equals(getSimulationTaskFileReq.getLevel())) {
|
||||
return getTaskLevelFile(getSimulationTaskFileReq, queryBigFileReq);
|
||||
|
||||
@@ -209,6 +209,9 @@
|
||||
</if>
|
||||
</where>
|
||||
GROUP BY file_storage.fileName, file_storage.fileId, file_storage.userGroupId, file_storage.userId, file_storage.fileSuffix
|
||||
<if test="queryBigFileReq.dirIds != null and queryBigFileReq.dirIds.size() > 0">
|
||||
HAVING COUNT(DISTINCT file_storage.dirId) = #{queryBigFileReq.dirIdsCount}
|
||||
</if>
|
||||
order by MAX(file_storage.updateTime) desc
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user