fix(接口场景): 修复带文件的场景转性能测试时附件文件会重复保存的缺陷
修复带文件的场景转性能测试时附件文件会重复保存的缺陷
This commit is contained in:
parent
0ab08dece8
commit
467c034f99
|
@ -459,7 +459,7 @@ public class APITestService {
|
||||||
* @return
|
* @return
|
||||||
* @author song tianyang
|
* @author song tianyang
|
||||||
*/
|
*/
|
||||||
public JmxInfoDTO updateJmxString(String jmx,String projectId) {
|
public JmxInfoDTO updateJmxString(String jmx, String projectId) {
|
||||||
jmx = this.updateJmxMessage(jmx);
|
jmx = this.updateJmxMessage(jmx);
|
||||||
|
|
||||||
//获取要转化的文件
|
//获取要转化的文件
|
||||||
|
@ -495,9 +495,11 @@ public class APITestService {
|
||||||
File file = new File(filePath);
|
File file = new File(filePath);
|
||||||
if (file.exists() && file.isFile()) {
|
if (file.exists() && file.isFile()) {
|
||||||
try {
|
try {
|
||||||
FileMetadata fileMetadata = fileService.saveFile(file, FileUtil.readAsByteArray(file),projectId);
|
FileMetadata fileMetadata = fileService.insertFileByFileName(file, FileUtil.readAsByteArray(file), projectId);
|
||||||
|
if (fileMetadata != null) {
|
||||||
fileMetadataList.add(fileMetadata);
|
fileMetadataList.add(fileMetadata);
|
||||||
attachmentFiles.put(fileMetadata.getId(), fileMetadata.getName());
|
attachmentFiles.put(fileMetadata.getId(), fileMetadata.getName());
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtil.error(e);
|
LogUtil.error(e);
|
||||||
}
|
}
|
||||||
|
@ -623,7 +625,7 @@ public class APITestService {
|
||||||
HashTree hashTree = runRequest.getTestElement().generateHashTree(config);
|
HashTree hashTree = runRequest.getTestElement().generateHashTree(config);
|
||||||
String jmxString = runRequest.getTestElement().getJmx(hashTree);
|
String jmxString = runRequest.getTestElement().getJmx(hashTree);
|
||||||
//将jmx处理封装为通用方法
|
//将jmx处理封装为通用方法
|
||||||
JmxInfoDTO dto = updateJmxString(jmxString,runRequest.getProjectId());
|
JmxInfoDTO dto = updateJmxString(jmxString, runRequest.getProjectId());
|
||||||
dto.setName(runRequest.getName() + ".jmx");
|
dto.setName(runRequest.getName() + ".jmx");
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,8 @@ import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.performance.request.QueryProjectFileRequest;
|
import io.metersphere.performance.request.QueryProjectFileRequest;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.CollectionUtils;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
@ -44,7 +44,7 @@ public class FileService {
|
||||||
|
|
||||||
public void setFileContent(String fileId, byte[] content) {
|
public void setFileContent(String fileId, byte[] content) {
|
||||||
FileContent record = new FileContent();
|
FileContent record = new FileContent();
|
||||||
record .setFile(content);
|
record.setFile(content);
|
||||||
record.setFileId(fileId);
|
record.setFileId(fileId);
|
||||||
fileContentMapper.updateByPrimaryKeySelective(record);
|
fileContentMapper.updateByPrimaryKeySelective(record);
|
||||||
}
|
}
|
||||||
|
@ -121,6 +121,51 @@ public class FileService {
|
||||||
return fileMetadata;
|
return fileMetadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FileMetadata insertFileByFileName(File file, byte[] fileByte, String projectId) {
|
||||||
|
if (StringUtils.isEmpty(file.getName())) {
|
||||||
|
return null;
|
||||||
|
}else {
|
||||||
|
FileMetadataExample example = new FileMetadataExample();
|
||||||
|
example.createCriteria().andProjectIdEqualTo(projectId).andNameEqualTo(file.getName());
|
||||||
|
List<FileMetadata> fileMetadatasInDataBase = fileMetadataMapper.selectByExample(example);
|
||||||
|
if(CollectionUtils.isEmpty(fileMetadatasInDataBase)){
|
||||||
|
final FileMetadata fileMetadata = new FileMetadata();
|
||||||
|
fileMetadata.setId(UUID.randomUUID().toString());
|
||||||
|
fileMetadata.setName(file.getName());
|
||||||
|
fileMetadata.setSize(file.length());
|
||||||
|
fileMetadata.setProjectId(projectId);
|
||||||
|
fileMetadata.setCreateTime(System.currentTimeMillis());
|
||||||
|
fileMetadata.setUpdateTime(System.currentTimeMillis());
|
||||||
|
FileType fileType = getFileType(fileMetadata.getName());
|
||||||
|
fileMetadata.setType(fileType.name());
|
||||||
|
fileMetadataMapper.insert(fileMetadata);
|
||||||
|
|
||||||
|
FileContent fileContent = new FileContent();
|
||||||
|
fileContent.setFileId(fileMetadata.getId());
|
||||||
|
fileContent.setFile(fileByte);
|
||||||
|
fileContentMapper.insert(fileContent);
|
||||||
|
return fileMetadata;
|
||||||
|
}else {
|
||||||
|
FileMetadata fileMetadata = fileMetadatasInDataBase.get(0);
|
||||||
|
fileMetadata.setName(file.getName());
|
||||||
|
fileMetadata.setSize(file.length());
|
||||||
|
fileMetadata.setProjectId(projectId);
|
||||||
|
fileMetadata.setUpdateTime(System.currentTimeMillis());
|
||||||
|
FileType fileType = getFileType(fileMetadata.getName());
|
||||||
|
fileMetadata.setType(fileType.name());
|
||||||
|
fileMetadataMapper.updateByPrimaryKeySelective(fileMetadata);
|
||||||
|
|
||||||
|
fileContentMapper.deleteByPrimaryKey(fileMetadata.getId());
|
||||||
|
FileContent fileContent = new FileContent();
|
||||||
|
fileContent.setFileId(fileMetadata.getId());
|
||||||
|
fileContent.setFile(fileByte);
|
||||||
|
fileContentMapper.insert(fileContent);
|
||||||
|
return fileMetadata;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public FileMetadata saveFile(File file, byte[] fileByte, String projectId) {
|
public FileMetadata saveFile(File file, byte[] fileByte, String projectId) {
|
||||||
final FileMetadata fileMetadata = new FileMetadata();
|
final FileMetadata fileMetadata = new FileMetadata();
|
||||||
fileMetadata.setId(UUID.randomUUID().toString());
|
fileMetadata.setId(UUID.randomUUID().toString());
|
||||||
|
|
|
@ -223,4 +223,7 @@ SET latest = 1;
|
||||||
UPDATE load_test
|
UPDATE load_test
|
||||||
SET latest = 1;
|
SET latest = 1;
|
||||||
|
|
||||||
|
ALTER TABLE file_metadata ADD index file_name (NAME);
|
||||||
|
ALTER TABLE file_content ADD index file_id_index (file_id);
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue