fix(测试跟踪): 功能用例批量导入问题 (#18410)

--bug=1017686,1017721 --user=宋昌昌 【测试跟踪】导入功能用例,责任人和用例等级不显示 https://www.tapd.cn/55049933/s/1258328

Co-authored-by: song-cc-rock <changchang.song@fit2cloud.com>
This commit is contained in:
MeterSphere Bot 2022-10-12 10:11:49 +08:00 committed by GitHub
parent 54c8bf8430
commit 0bf8760624
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 83 additions and 88 deletions

View File

@ -533,7 +533,6 @@ public class TestCaseNoModelDataListener extends AnalysisEventListener<Map<Integ
this.ids = result2.stream().map(TestCase::getId).collect(Collectors.toList());
updateList.clear();
}
customFieldsMap.clear();
}
private TestCaseWithBLOBs convert2TestCase(TestCaseExcelData data) {
@ -844,6 +843,7 @@ public class TestCaseNoModelDataListener extends AnalysisEventListener<Map<Integ
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
saveData();
list.clear();
customFieldsMap.clear();
}
private void formatHeadMap() {

View File

@ -2321,93 +2321,87 @@ public class TestCaseService {
public String getLogDetails(String id) {
TestCaseWithBLOBs bloBs = testCaseMapper.selectByPrimaryKey(id);
// if (bloBs != null) {
// List<DetailColumn> columns = ReflexObjectUtil.getColumns(bloBs, TestCaseReference.testCaseColumns);
// // 关联内容用例内容
// TestCaseTestExample example = new TestCaseTestExample();
// example.createCriteria().andTestCaseIdEqualTo(id);
// List<TestCaseTest> testCaseTests = testCaseTestMapper.selectByExample(example);
// StringBuilder nameBuilder = new StringBuilder();
// if (CollectionUtils.isNotEmpty(testCaseTests)) {
// List<String> testCaseIds = testCaseTests.stream()
// .filter(user -> user.getTestType().equals("testcase")).map(TestCaseTest::getTestId)
// .collect(Collectors.toList());
//
// List<String> performanceIds = testCaseTests.stream()
// .filter(user -> user.getTestType().equals("performance")).map(TestCaseTest::getTestId)
// .collect(Collectors.toList());
//
// List<String> automationIds = testCaseTests.stream()
// .filter(user -> user.getTestType().equals("automation")).map(TestCaseTest::getTestId)
// .collect(Collectors.toList());
// if (CollectionUtils.isNotEmpty(testCaseIds)) {
// ApiTestCaseExample testCaseExample = new ApiTestCaseExample();
// testCaseExample.createCriteria().andIdIn(testCaseIds);
// List<ApiTestCase> testCases = apiTestCaseMapper.selectByExample(testCaseExample);
// List<String> caseNames = testCases.stream().map(ApiTestCase::getName).collect(Collectors.toList());
// if (CollectionUtils.isNotEmpty(caseNames)) {
// nameBuilder.append("接口用例:").append("\n").append(caseNames).append("\n");
// }
// }
// if (CollectionUtils.isNotEmpty(performanceIds)) {
// LoadTestExample loadTestExample = new LoadTestExample();
// loadTestExample.createCriteria().andIdIn(performanceIds);
// List<LoadTest> loadTests = loadTestMapper.selectByExample(loadTestExample);
// List<String> caseNames = loadTests.stream().map(LoadTest::getName).collect(Collectors.toList());
// if (CollectionUtils.isNotEmpty(caseNames)) {
// nameBuilder.append("性能用例:").append("\n").append(caseNames).append("\n");
// }
// }
// if (CollectionUtils.isNotEmpty(automationIds)) {
// ApiScenarioExample scenarioExample = new ApiScenarioExample();
// scenarioExample.createCriteria().andIdIn(automationIds);
// List<ApiScenario> scenarios = apiScenarioMapper.selectByExample(scenarioExample);
// List<String> caseNames = scenarios.stream().map(ApiScenario::getName).collect(Collectors.toList());
// if (CollectionUtils.isNotEmpty(caseNames)) {
// nameBuilder.append("自动化用例:").append("\n").append(caseNames).append("\n");
// }
// }
// }
// DetailColumn column = new DetailColumn("关联测试", "testcase", nameBuilder.toString(), null);
// columns.add(column);
//
// //关联缺陷
// List<String> issuesNames = new LinkedList<>();
// TestCaseIssuesExample testCaseIssuesExample = new TestCaseIssuesExample();
// testCaseIssuesExample.createCriteria().andResourceIdEqualTo(bloBs.getId());
// List<TestCaseIssues> testCaseIssues = testCaseIssuesMapper.selectByExample(testCaseIssuesExample);
// if (CollectionUtils.isNotEmpty(testCaseIssues)) {
// List<String> issuesIds = testCaseIssues.stream().map(TestCaseIssues::getIssuesId).collect(Collectors.toList());
// IssuesExample issuesExample = new IssuesExample();
// issuesExample.createCriteria().andIdIn(issuesIds);
// List<Issues> issues = issuesMapper.selectByExample(issuesExample);
// if (CollectionUtils.isNotEmpty(issues)) {
// issuesNames = issues.stream().map(Issues::getTitle).collect(Collectors.toList());
// }
// }
// DetailColumn issuesColumn = new DetailColumn("关联缺陷 ", "issues", String.join(",", issuesNames), null);
// columns.add(issuesColumn);
// //附件
// List<FileMetadata> originFiles = attachmentService.getFileMetadataByCaseId(id);
// List<String> fileNames = new LinkedList<>();
// if (CollectionUtils.isNotEmpty(originFiles)) {
// fileNames = originFiles.stream().map(FileMetadata::getName).collect(Collectors.toList());
// }
// DetailColumn fileColumn = new DetailColumn("附件 ", "files", String.join(",", fileNames), null);
// columns.add(fileColumn);
//
// // 增加评论内容
// List<TestCaseCommentDTO> dtos = testCaseCommentService.getCaseComments(id);
// List<String> names = new LinkedList<>();
// if (CollectionUtils.isNotEmpty(dtos)) {
// names = dtos.stream().map(TestCaseCommentDTO::getDescription).collect(Collectors.toList());
// }
// DetailColumn detailColumn = new DetailColumn("评论", "comment", String.join("\n", names), null);
// columns.add(detailColumn);
//
// OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(id), bloBs.getProjectId(), bloBs.getName(), bloBs.getCreateUser(), columns);
// return JSON.toJSONString(details);
// }
if (bloBs != null) {
List<DetailColumn> columns = ReflexObjectUtil.getColumns(bloBs, TestCaseReference.testCaseColumns);
// 关联内容用例内容
TestCaseTestExample example = new TestCaseTestExample();
example.createCriteria().andTestCaseIdEqualTo(id);
List<TestCaseTest> testCaseTests = testCaseTestMapper.selectByExample(example);
StringBuilder nameBuilder = new StringBuilder();
if (CollectionUtils.isNotEmpty(testCaseTests)) {
List<String> testCaseIds = testCaseTests.stream()
.filter(user -> user.getTestType().equals("testcase")).map(TestCaseTest::getTestId)
.collect(Collectors.toList());
List<String> performanceIds = testCaseTests.stream()
.filter(user -> user.getTestType().equals("performance")).map(TestCaseTest::getTestId)
.collect(Collectors.toList());
List<String> automationIds = testCaseTests.stream()
.filter(user -> user.getTestType().equals("automation")).map(TestCaseTest::getTestId)
.collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(testCaseIds)) {
List<ApiTestCase> testCases = relevanceApiCaseService.getApiCaseByIds(testCaseIds);
List<String> caseNames = testCases.stream().map(ApiTestCase::getName).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(caseNames)) {
nameBuilder.append("接口用例:").append("\n").append(caseNames).append("\n");
}
}
if (CollectionUtils.isNotEmpty(performanceIds)) {
List<LoadTest> loadTests = relevanceLoadCaseService.getLoadCaseByIds(performanceIds);
List<String> caseNames = loadTests.stream().map(LoadTest::getName).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(caseNames)) {
nameBuilder.append("性能用例:").append("\n").append(caseNames).append("\n");
}
}
if (CollectionUtils.isNotEmpty(automationIds)) {
List<ApiScenario> scenarios = relevanceApiCaseService.getScenarioCaseByIds(automationIds);
List<String> caseNames = scenarios.stream().map(ApiScenario::getName).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(caseNames)) {
nameBuilder.append("自动化用例:").append("\n").append(caseNames).append("\n");
}
}
}
DetailColumn column = new DetailColumn("关联测试", "testcase", nameBuilder.toString(), null);
columns.add(column);
//关联缺陷
List<String> issuesNames = new LinkedList<>();
TestCaseIssuesExample testCaseIssuesExample = new TestCaseIssuesExample();
testCaseIssuesExample.createCriteria().andResourceIdEqualTo(bloBs.getId());
List<TestCaseIssues> testCaseIssues = testCaseIssuesMapper.selectByExample(testCaseIssuesExample);
if (CollectionUtils.isNotEmpty(testCaseIssues)) {
List<String> issuesIds = testCaseIssues.stream().map(TestCaseIssues::getIssuesId).collect(Collectors.toList());
IssuesExample issuesExample = new IssuesExample();
issuesExample.createCriteria().andIdIn(issuesIds);
List<Issues> issues = issuesMapper.selectByExample(issuesExample);
if (CollectionUtils.isNotEmpty(issues)) {
issuesNames = issues.stream().map(Issues::getTitle).collect(Collectors.toList());
}
}
DetailColumn issuesColumn = new DetailColumn("关联缺陷 ", "issues", String.join(",", issuesNames), null);
columns.add(issuesColumn);
//附件
List<FileMetadata> originFiles = attachmentService.getFileMetadataByCaseId(id);
List<String> fileNames = new LinkedList<>();
if (CollectionUtils.isNotEmpty(originFiles)) {
fileNames = originFiles.stream().map(FileMetadata::getName).collect(Collectors.toList());
}
DetailColumn fileColumn = new DetailColumn("附件 ", "files", String.join(",", fileNames), null);
columns.add(fileColumn);
// 增加评论内容
List<TestCaseCommentDTO> dtos = testCaseCommentService.getCaseComments(id);
List<String> names = new LinkedList<>();
if (CollectionUtils.isNotEmpty(dtos)) {
names = dtos.stream().map(TestCaseCommentDTO::getDescription).collect(Collectors.toList());
}
DetailColumn detailColumn = new DetailColumn("评论", "comment", String.join("\n", names), null);
columns.add(detailColumn);
OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(id), bloBs.getProjectId(), bloBs.getName(), bloBs.getCreateUser(), columns);
return JSON.toJSONString(details);
}
return null;
}

View File

@ -69,6 +69,7 @@
<ms-table-column
v-if="item.id === 'num' && customNum"
:fields-width="fieldsWidth"
:column-key="'customNum'"
prop="customNum"
sortable
:label="$t('commons.id')"