fix(测试跟踪): 测试用例附件丢失

--bug=1013257 --user=李玉号
【测试跟踪】github#13671,测试用例附件丢失-必现
https://www.tapd.cn/55049933/s/1159858

Closes #13671
This commit is contained in:
shiziyuan9527 2022-05-18 16:02:22 +08:00 committed by shiziyuan9527
parent 731db1fb90
commit bdfe33b33f
4 changed files with 32 additions and 22 deletions

View File

@ -22,6 +22,8 @@ public class EditTestCaseRequest extends TestCaseWithBLOBs {
*/
private List<String> fileIds = new ArrayList<>();
private List<List<String>> selected = new ArrayList<>();
// 是否处理附件文件
private boolean handleAttachment = true;
/**
* 创建新版本时 是否连带复制其他信息的配置类

View File

@ -56,6 +56,7 @@ import io.metersphere.xmind.pojo.TestCaseXmindData;
import io.metersphere.xmind.utils.XmindExportUtil;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
@ -1840,30 +1841,33 @@ public class TestCaseService {
MSException.throwException(Translator.get("edit_load_test_not_found") + request.getId());
}
// 新选择了一个文件删除原来的文件
List<FileMetadata> updatedFiles = request.getUpdatedFileList();
List<FileMetadata> originFiles = fileService.getFileMetadataByCaseId(request.getId());
List<String> updatedFileIds = updatedFiles.stream().map(FileMetadata::getId).collect(Collectors.toList());
List<String> originFileIds = originFiles.stream().map(FileMetadata::getId).collect(Collectors.toList());
// 相减
List<String> deleteFileIds = ListUtils.subtract(originFileIds, updatedFileIds);
fileService.deleteFileRelatedByIds(deleteFileIds);
if (BooleanUtils.isTrue(request.isHandleAttachment())) {
// 新选择了一个文件删除原来的文件
List<FileMetadata> updatedFiles = request.getUpdatedFileList();
List<FileMetadata> originFiles = fileService.getFileMetadataByCaseId(request.getId());
List<String> updatedFileIds = updatedFiles.stream().map(FileMetadata::getId).collect(Collectors.toList());
List<String> originFileIds = originFiles.stream().map(FileMetadata::getId).collect(Collectors.toList());
// 相减
List<String> deleteFileIds = ListUtils.subtract(originFileIds, updatedFileIds);
fileService.deleteFileRelatedByIds(deleteFileIds);
if (!CollectionUtils.isEmpty(deleteFileIds)) {
TestCaseFileExample testCaseFileExample = new TestCaseFileExample();
testCaseFileExample.createCriteria().andFileIdIn(deleteFileIds);
testCaseFileMapper.deleteByExample(testCaseFileExample);
if (!CollectionUtils.isEmpty(deleteFileIds)) {
TestCaseFileExample testCaseFileExample = new TestCaseFileExample();
testCaseFileExample.createCriteria().andFileIdIn(deleteFileIds);
testCaseFileMapper.deleteByExample(testCaseFileExample);
}
if (files != null) {
files.forEach(file -> {
final FileMetadata fileMetadata = fileService.saveFile(file, testCaseWithBLOBs.getProjectId());
TestCaseFile testCaseFile = new TestCaseFile();
testCaseFile.setFileId(fileMetadata.getId());
testCaseFile.setCaseId(request.getId());
testCaseFileMapper.insert(testCaseFile);
});
}
}
if (files != null) {
files.forEach(file -> {
final FileMetadata fileMetadata = fileService.saveFile(file, testCaseWithBLOBs.getProjectId());
TestCaseFile testCaseFile = new TestCaseFile();
testCaseFile.setFileId(fileMetadata.getId());
testCaseFile.setCaseId(request.getId());
testCaseFileMapper.insert(testCaseFile);
});
}
this.setNode(request);
return editTestCase(request);
}

View File

@ -89,6 +89,7 @@
:label-width="formLabelWidth" :case-id="form.id"
:type="type" :comments="comments"
@openComment="openComment"
:is-click-attachment-tab.sync="isClickAttachmentTab"
:version-enable="versionEnable"
ref="otherInfo"/>
<test-case-comment :case-id="form.id"
@ -282,6 +283,7 @@ export default {
selectedOtherInfo: null,
currentProjectId: "",
casePublic: false,
isClickAttachmentTab: false,
};
},
props: {
@ -812,6 +814,7 @@ export default {
param.fileIds = [];
param.updatedFileList = [];
}
param.handleAttachment = this.isClickAttachmentTab;
let requestJson = JSON.stringify(param, function (key, value) {
return key === "file" ? undefined : value

View File

@ -131,7 +131,7 @@ export default {
ReviewCommentItem,
FormRichTextItem, TestCaseIssueRelate, TestCaseAttachment, MsRichText, TestCaseRichText
},
props: ['form', 'labelWidth', 'caseId', 'readOnly', 'projectId', 'isTestPlan', 'planId', 'versionEnable', 'isCopy', 'isTestPlanEdit', 'type', 'comments'],
props: ['form', 'labelWidth', 'caseId', 'readOnly', 'projectId', 'isTestPlan', 'planId', 'versionEnable', 'isCopy', 'isTestPlanEdit', 'type', 'comments', 'isClickAttachmentTab'],
data() {
return {
result: {},
@ -291,6 +291,7 @@ export default {
this.$error(this.$t('load_test.file_size_limit'));
},
getFileMetaData(id) {
this.$emit("update:isClickAttachmentTab", true);
// id
if (this.uploadList && this.uploadList.length > 0 && !id) {
return;