fix(文件管理): 修复默认多出一个默认模块问题

--bug=1015975 --user=赵勇 【项目设置】文件管理,历史项目有两个默认模块 https://www.tapd.cn/55049933/s/1226824
This commit is contained in:
fit2-zhao 2022-08-18 15:58:36 +08:00 committed by f2c-ci-robot[bot]
parent 918e318d13
commit 578569620a
4 changed files with 9 additions and 29 deletions

View File

@ -30,12 +30,10 @@
</foreach> </foreach>
</when> </when>
<when test="key=='moduleIds'"> <when test="key=='moduleIds'">
and and file_metadata.module_id in
( file_metadata.module_id in
<foreach collection="values" item="value" separator="," open="(" close=")"> <foreach collection="values" item="value" separator="," open="(" close=")">
#{value} #{value}
</foreach> </foreach>
OR file_metadata.module_id is null)
</when> </when>
</choose> </choose>
</if> </if>

View File

@ -3,5 +3,4 @@ package io.metersphere.commons.constants;
public class ApiTestConstants { public class ApiTestConstants {
public static final String JAR_PATH = "JAR_PATH"; public static final String JAR_PATH = "JAR_PATH";
public static final String DEF_MODULE = "DEF_MODULE"; public static final String DEF_MODULE = "DEF_MODULE";
public static final String DEF_MODULE_ID = "moduleIds";
} }

View File

@ -107,18 +107,7 @@ public class FileMetadataService {
this.add(req); this.add(req);
}}); }});
} }
List<FileMetadata> list = extFileMetadataMapper.getProjectFiles(projectId, request); return extFileMetadataMapper.getProjectFiles(projectId, request);
long size = list.stream().filter(t -> StringUtils.isEmpty(t.getModuleId())).count();
if (size > 0) {
// 历史数据处理
String moduleId = fileModuleService.getDefaultNode(projectId).getId();
list.forEach(item -> {
if (StringUtils.isEmpty(item.getModuleId())) {
item.setModuleId(moduleId);
}
});
}
return list;
} }
public void deleteFile(String fileId) { public void deleteFile(String fileId) {
@ -424,7 +413,7 @@ public class FileMetadataService {
fileMetadata.setProjectId(SessionUtils.getCurrentProjectId()); fileMetadata.setProjectId(SessionUtils.getCurrentProjectId());
} }
if (StringUtils.isEmpty(fileMetadata.getModuleId())) { if (StringUtils.isEmpty(fileMetadata.getModuleId())) {
fileMetadata.setModuleId(fileModuleService.getDefaultNode(fileMetadata.getProjectId()).getId()); fileMetadata.setModuleId(fileModuleService.getDefaultNodeId(fileMetadata.getProjectId()));
} }
fileMetadata.setCreateTime(System.currentTimeMillis()); fileMetadata.setCreateTime(System.currentTimeMillis());
fileMetadata.setUpdateTime(System.currentTimeMillis()); fileMetadata.setUpdateTime(System.currentTimeMillis());

View File

@ -60,11 +60,7 @@ public class FileModuleService extends NodeTreeService<FileModuleVo> {
public List<FileModuleVo> getNodeTreeByProjectId(String projectId) { public List<FileModuleVo> getNodeTreeByProjectId(String projectId) {
// 判断当前项目下是否有默认模块没有添加默认模块 // 判断当前项目下是否有默认模块没有添加默认模块
FileModule defaultNode = this.getDefaultNode(projectId); this.initDefaultNode(projectId);
// 历史数据统计
FileMetadataExample example = new FileMetadataExample();
example.createCriteria().andProjectIdEqualTo(projectId).andModuleIdIsNull();
long defaultCount = fileMetadataMapper.countByExample(example);
List<FileModuleVo> modules = extFileModuleMapper.getNodeTreeByProjectId(projectId); List<FileModuleVo> modules = extFileModuleMapper.getNodeTreeByProjectId(projectId);
List<String> ids = modules.stream().map(FileModuleVo::getId).collect(Collectors.toList()); List<String> ids = modules.stream().map(FileModuleVo::getId).collect(Collectors.toList());
@ -85,7 +81,6 @@ public class FileModuleService extends NodeTreeService<FileModuleVo> {
countNum += moduleCountMap.get(moduleId).intValue(); countNum += moduleCountMap.get(moduleId).intValue();
} }
} }
countNum += defaultCount;
node.setCaseNum(countNum); node.setCaseNum(countNum);
}); });
} }
@ -355,7 +350,7 @@ public class FileModuleService extends NodeTreeService<FileModuleVo> {
return fileModuleMapper.countByExample(example); return fileModuleMapper.countByExample(example);
} }
public FileModule getDefaultNode(String projectId) { private FileModule initDefaultNode(String projectId) {
FileModuleExample example = new FileModuleExample(); FileModuleExample example = new FileModuleExample();
example.createCriteria().andProjectIdEqualTo(projectId).andNameEqualTo(ApiTestConstants.DEF_MODULE).andParentIdIsNull(); example.createCriteria().andProjectIdEqualTo(projectId).andNameEqualTo(ApiTestConstants.DEF_MODULE).andParentIdIsNull();
List<FileModule> list = fileModuleMapper.selectByExample(example); List<FileModule> list = fileModuleMapper.selectByExample(example);
@ -379,15 +374,14 @@ public class FileModuleService extends NodeTreeService<FileModuleVo> {
} }
} }
public FileModule getDefaultNodeUnCreateNew(String projectId) { public String getDefaultNodeId(String projectId) {
FileModuleExample example = new FileModuleExample(); FileModuleExample example = new FileModuleExample();
example.createCriteria().andProjectIdEqualTo(projectId).andNameEqualTo(ApiTestConstants.DEF_MODULE).andParentIdIsNull(); example.createCriteria().andProjectIdEqualTo(projectId).andNameEqualTo(ApiTestConstants.DEF_MODULE).andParentIdIsNull();
List<FileModule> list = fileModuleMapper.selectByExample(example); List<FileModule> list = fileModuleMapper.selectByExample(example);
if (CollectionUtils.isEmpty(list)) { if (CollectionUtils.isNotEmpty(list)) {
return null; return list.get(0).getId();
} else {
return list.get(0);
} }
return null;
} }
public String getModuleNameById(String moduleId) { public String getModuleNameById(String moduleId) {