refactor(文件管理): 兼容历史数据处理
This commit is contained in:
parent
3c04ce0c75
commit
3ffb2e6b16
|
@ -30,10 +30,12 @@
|
||||||
</foreach>
|
</foreach>
|
||||||
</when>
|
</when>
|
||||||
<when test="key=='moduleIds'">
|
<when test="key=='moduleIds'">
|
||||||
and file_metadata.module_id in
|
and
|
||||||
|
( 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>
|
||||||
|
|
|
@ -3,4 +3,5 @@ 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";
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package io.metersphere.metadata.service;
|
package io.metersphere.metadata.service;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.nacos.common.utils.ByteUtils;
|
||||||
import io.metersphere.base.domain.*;
|
import io.metersphere.base.domain.*;
|
||||||
import io.metersphere.base.mapper.*;
|
import io.metersphere.base.mapper.*;
|
||||||
import io.metersphere.base.mapper.ext.ExtFileMetadataMapper;
|
import io.metersphere.base.mapper.ext.ExtFileMetadataMapper;
|
||||||
|
@ -190,7 +191,8 @@ public class FileMetadataService {
|
||||||
// 兼容历史数据
|
// 兼容历史数据
|
||||||
if (StringUtils.isEmpty(fileMetadata.getStorage()) && StringUtils.isEmpty(fileMetadata.getResourceType())) {
|
if (StringUtils.isEmpty(fileMetadata.getStorage()) && StringUtils.isEmpty(fileMetadata.getResourceType())) {
|
||||||
bytes = getContent(fileMetadata.getId());
|
bytes = getContent(fileMetadata.getId());
|
||||||
} else {
|
}
|
||||||
|
if (ByteUtils.isEmpty(bytes)) {
|
||||||
FileRequest request = new FileRequest(fileMetadata.getProjectId(), fileMetadata.getName(), fileMetadata.getType());
|
FileRequest request = new FileRequest(fileMetadata.getProjectId(), fileMetadata.getName(), fileMetadata.getType());
|
||||||
request.setResourceType(fileMetadata.getResourceType());
|
request.setResourceType(fileMetadata.getResourceType());
|
||||||
request.setPath(fileMetadata.getPath());
|
request.setPath(fileMetadata.getPath());
|
||||||
|
@ -244,21 +246,20 @@ public class FileMetadataService {
|
||||||
public void update(FileMetadata fileMetadata) {
|
public void update(FileMetadata fileMetadata) {
|
||||||
this.checkName(fileMetadata);
|
this.checkName(fileMetadata);
|
||||||
String beforeName = getBeforeName(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());
|
boolean isReName = fileManagerService.reName(beforeName, fileMetadata.getName(), fileMetadata.getProjectId());
|
||||||
if (!isReName) {
|
if (!isReName) {
|
||||||
MSException.throwException("重命名失败!");
|
MSException.throwException("重命名失败!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fileMetadataMapper.selectByPrimaryKey(fileMetadata.getId()) != null) {
|
fileMetadata.setUpdateTime(System.currentTimeMillis());
|
||||||
fileMetadata.setUpdateTime(System.currentTimeMillis());
|
fileMetadata.setUpdateUser(SessionUtils.getUserId());
|
||||||
fileMetadata.setUpdateUser(SessionUtils.getUserId());
|
// 历史数据的路径不做更新
|
||||||
// 历史数据的路径不做更新
|
if (StringUtils.isNotEmpty(fileMetadata.getStorage()) && StringUtils.isEmpty(fileMetadata.getResourceType())) {
|
||||||
if (StringUtils.isNotEmpty(fileMetadata.getStorage()) && StringUtils.isEmpty(fileMetadata.getResourceType())) {
|
fileMetadata.setPath(FileUtils.getFilePath(fileMetadata));
|
||||||
fileMetadata.setPath(FileUtils.getFilePath(fileMetadata));
|
|
||||||
}
|
|
||||||
fileMetadataMapper.updateByPrimaryKeySelective(fileMetadata);
|
|
||||||
}
|
}
|
||||||
|
fileMetadataMapper.updateByPrimaryKeySelective(fileMetadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileMetadata reLoad(FileMetadata fileMetadata, List<MultipartFile> files) {
|
public FileMetadata reLoad(FileMetadata fileMetadata, List<MultipartFile> files) {
|
||||||
|
@ -277,8 +278,9 @@ public class FileMetadataService {
|
||||||
}
|
}
|
||||||
// 上传文件
|
// 上传文件
|
||||||
FileRequest request = new FileRequest(fileMetadata.getProjectId(), fileMetadata.getName(), fileMetadata.getType());
|
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.setUpdateTime(System.currentTimeMillis());
|
||||||
fileMetadata.setUpdateUser(SessionUtils.getUserId());
|
fileMetadata.setUpdateUser(SessionUtils.getUserId());
|
||||||
fileMetadataMapper.updateByPrimaryKeySelective(fileMetadata);
|
fileMetadataMapper.updateByPrimaryKeySelective(fileMetadata);
|
||||||
|
|
|
@ -60,7 +60,12 @@ public class FileModuleService extends NodeTreeService<FileModuleVo> {
|
||||||
|
|
||||||
public List<FileModuleVo> getNodeTreeByProjectId(String projectId) {
|
public List<FileModuleVo> 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<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());
|
||||||
if (CollectionUtils.isEmpty(ids)) {
|
if (CollectionUtils.isEmpty(ids)) {
|
||||||
|
@ -80,6 +85,7 @@ public class FileModuleService extends NodeTreeService<FileModuleVo> {
|
||||||
countNum += moduleCountMap.get(moduleId).intValue();
|
countNum += moduleCountMap.get(moduleId).intValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
countNum += defaultCount;
|
||||||
node.setCaseNum(countNum);
|
node.setCaseNum(countNum);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue