diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtFileMetadataMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtFileMetadataMapper.xml index 83a49af144..22d582b84d 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtFileMetadataMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtFileMetadataMapper.xml @@ -30,10 +30,12 @@ - and file_metadata.module_id in + and + ( file_metadata.module_id in #{value} + OR file_metadata.module_id is null) diff --git a/backend/src/main/java/io/metersphere/commons/constants/ApiTestConstants.java b/backend/src/main/java/io/metersphere/commons/constants/ApiTestConstants.java index 7cffd2a43b..19fd7cf923 100644 --- a/backend/src/main/java/io/metersphere/commons/constants/ApiTestConstants.java +++ b/backend/src/main/java/io/metersphere/commons/constants/ApiTestConstants.java @@ -3,4 +3,5 @@ package io.metersphere.commons.constants; public class ApiTestConstants { public static final String JAR_PATH = "JAR_PATH"; public static final String DEF_MODULE = "DEF_MODULE"; + public static final String DEF_MODULE_ID = "moduleIds"; } diff --git a/backend/src/main/java/io/metersphere/metadata/service/FileMetadataService.java b/backend/src/main/java/io/metersphere/metadata/service/FileMetadataService.java index b46bda8f0d..2f9718f5af 100644 --- a/backend/src/main/java/io/metersphere/metadata/service/FileMetadataService.java +++ b/backend/src/main/java/io/metersphere/metadata/service/FileMetadataService.java @@ -1,6 +1,7 @@ package io.metersphere.metadata.service; import com.alibaba.fastjson.JSON; +import com.alibaba.nacos.common.utils.ByteUtils; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.*; import io.metersphere.base.mapper.ext.ExtFileMetadataMapper; @@ -190,7 +191,8 @@ public class FileMetadataService { // 兼容历史数据 if (StringUtils.isEmpty(fileMetadata.getStorage()) && StringUtils.isEmpty(fileMetadata.getResourceType())) { bytes = getContent(fileMetadata.getId()); - } else { + } + if (ByteUtils.isEmpty(bytes)) { FileRequest request = new FileRequest(fileMetadata.getProjectId(), fileMetadata.getName(), fileMetadata.getType()); request.setResourceType(fileMetadata.getResourceType()); request.setPath(fileMetadata.getPath()); @@ -244,21 +246,20 @@ public class FileMetadataService { public void update(FileMetadata fileMetadata) { this.checkName(fileMetadata); String beforeName = getBeforeName(fileMetadata); - if (!StringUtils.equalsIgnoreCase(beforeName, fileMetadata.getName())) { + if (!StringUtils.equalsIgnoreCase(beforeName, fileMetadata.getName()) + && StringUtils.isNotEmpty(fileMetadata.getStorage()) && StringUtils.isEmpty(fileMetadata.getResourceType())) { boolean isReName = fileManagerService.reName(beforeName, fileMetadata.getName(), fileMetadata.getProjectId()); if (!isReName) { MSException.throwException("重命名失败!"); } } - if (fileMetadataMapper.selectByPrimaryKey(fileMetadata.getId()) != null) { - fileMetadata.setUpdateTime(System.currentTimeMillis()); - fileMetadata.setUpdateUser(SessionUtils.getUserId()); - // 历史数据的路径不做更新 - if (StringUtils.isNotEmpty(fileMetadata.getStorage()) && StringUtils.isEmpty(fileMetadata.getResourceType())) { - fileMetadata.setPath(FileUtils.getFilePath(fileMetadata)); - } - fileMetadataMapper.updateByPrimaryKeySelective(fileMetadata); + fileMetadata.setUpdateTime(System.currentTimeMillis()); + fileMetadata.setUpdateUser(SessionUtils.getUserId()); + // 历史数据的路径不做更新 + if (StringUtils.isNotEmpty(fileMetadata.getStorage()) && StringUtils.isEmpty(fileMetadata.getResourceType())) { + fileMetadata.setPath(FileUtils.getFilePath(fileMetadata)); } + fileMetadataMapper.updateByPrimaryKeySelective(fileMetadata); } public FileMetadata reLoad(FileMetadata fileMetadata, List files) { @@ -277,8 +278,9 @@ public class FileMetadataService { } // 上传文件 FileRequest request = new FileRequest(fileMetadata.getProjectId(), fileMetadata.getName(), fileMetadata.getType()); - fileManagerService.coverFile(files.get(0), request); + String path = fileManagerService.coverFile(files.get(0), request); // 更新关系数据 + fileMetadata.setPath(path); fileMetadata.setUpdateTime(System.currentTimeMillis()); fileMetadata.setUpdateUser(SessionUtils.getUserId()); fileMetadataMapper.updateByPrimaryKeySelective(fileMetadata); diff --git a/backend/src/main/java/io/metersphere/metadata/service/FileModuleService.java b/backend/src/main/java/io/metersphere/metadata/service/FileModuleService.java index 13bcc708c4..d91de0079d 100644 --- a/backend/src/main/java/io/metersphere/metadata/service/FileModuleService.java +++ b/backend/src/main/java/io/metersphere/metadata/service/FileModuleService.java @@ -60,7 +60,12 @@ public class FileModuleService extends NodeTreeService { public List getNodeTreeByProjectId(String projectId) { // 判断当前项目下是否有默认模块,没有添加默认模块 - this.getDefaultNode(projectId); + FileModule defaultNode = this.getDefaultNode(projectId); + // 历史数据统计 + FileMetadataExample example = new FileMetadataExample(); + example.createCriteria().andProjectIdEqualTo(projectId).andModuleIdIsNull(); + long defaultCount = fileMetadataMapper.countByExample(example); + List modules = extFileModuleMapper.getNodeTreeByProjectId(projectId); List ids = modules.stream().map(FileModuleVo::getId).collect(Collectors.toList()); if (CollectionUtils.isEmpty(ids)) { @@ -80,6 +85,7 @@ public class FileModuleService extends NodeTreeService { countNum += moduleCountMap.get(moduleId).intValue(); } } + countNum += defaultCount; node.setCaseNum(countNum); }); }