refactor: 功能用例查询优化

This commit is contained in:
chenjianxing 2022-01-21 17:48:37 +08:00 committed by zhangdahai112
parent 7b3e754035
commit 01484b02aa
4 changed files with 25 additions and 22 deletions

View File

@ -226,14 +226,11 @@
test_case.create_time, test_case.update_time, test_case.test_id, test_case.sort, test_case.num, test_case.create_time, test_case.update_time, test_case.test_id, test_case.sort, test_case.num,
test_case.other_test_name, test_case.review_status, test_case.tags, test_case.other_test_name, test_case.review_status, test_case.tags,
test_case.demand_id, test_case.demand_name, test_case.`status`, test_case.demand_id, test_case.demand_name, test_case.`status`,
test_case.custom_num, test_case.step_model, test_case.create_user,u.name as createName, test_case.custom_num, test_case.step_model, test_case.create_user,
test_case.custom_fields, project.name as projectName , test_case.ref_id test_case.custom_fields, test_case.ref_id
</if> </if>
from test_case left join user u on test_case.create_user=u.id from test_case
left join user deleteUser on test_case.delete_user_id=deleteUser.id left join project_version on project_version.id = test_case.version_id and project_version.project_id = #{request.project_id}
left join project on test_case.project_id = project.id
left join project_version on project.id = project_version.project_id and project_version.id =
test_case.version_id
<include refid="queryWhereCondition"/> <include refid="queryWhereCondition"/>
<include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.orders"/> <include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.orders"/>
</select> </select>

View File

@ -532,9 +532,11 @@ public class TestCaseService {
if (request.getFilters() != null && !request.getFilters().containsKey("status")) { if (request.getFilters() != null && !request.getFilters().containsKey("status")) {
request.getFilters().put("status", new ArrayList<>(0)); request.getFilters().put("status", new ArrayList<>(0));
} }
List<TestCaseDTO> returnList = extTestCaseMapper.list(request); List<TestCaseDTO> list = extTestCaseMapper.list(request);
returnList = this.parseStatus(returnList); buildUserInfo(list);
return returnList; buildProjectInfo(request.getProjectId(), list);
list = this.parseStatus(list);
return list;
} }
public List<TestCaseDTO> publicListTestCase(QueryTestCaseRequest request) { public List<TestCaseDTO> publicListTestCase(QueryTestCaseRequest request) {
@ -2332,7 +2334,8 @@ public class TestCaseService {
TestCaseExample example = new TestCaseExample(); TestCaseExample example = new TestCaseExample();
example.createCriteria().andIdIn(ids).andStatusNotEqualTo("Trash"); example.createCriteria().andIdIn(ids).andStatusNotEqualTo("Trash");
List<TestCaseWithBLOBs> testCaseList = testCaseMapper.selectByExampleWithBLOBs(example); List<TestCaseWithBLOBs> testCaseList = testCaseMapper.selectByExampleWithBLOBs(example);
buildUserInfo(testCaseList);
Map<String, String> userNameMap = ServiceUtils.getUserNameMap(testCaseList.stream().map(TestCaseWithBLOBs::getCreateUser).collect(Collectors.toList()));
Map<String, String> verionNameMap = new HashMap<>(); Map<String, String> verionNameMap = new HashMap<>();
List<String> versionIds = testCaseList.stream().map(TestCase::getVersionId).collect(Collectors.toList()); List<String> versionIds = testCaseList.stream().map(TestCase::getVersionId).collect(Collectors.toList());
@ -2357,7 +2360,7 @@ public class TestCaseService {
continue; // 用例可能在回收站 continue; // 用例可能在回收站
} }
relationshipEdgeDTO.setTargetName(testCase.getName()); relationshipEdgeDTO.setTargetName(testCase.getName());
relationshipEdgeDTO.setCreator(testCase.getCreateUser()); relationshipEdgeDTO.setCreator(userNameMap.get(testCase.getCreateUser()));
relationshipEdgeDTO.setTargetNum(testCase.getNum()); relationshipEdgeDTO.setTargetNum(testCase.getNum());
relationshipEdgeDTO.setTargetCustomNum(testCase.getCustomNum()); relationshipEdgeDTO.setTargetCustomNum(testCase.getCustomNum());
relationshipEdgeDTO.setStatus(testCase.getStatus()); relationshipEdgeDTO.setStatus(testCase.getStatus());
@ -2369,7 +2372,14 @@ public class TestCaseService {
return new ArrayList<>(); return new ArrayList<>();
} }
public void buildUserInfo(List<? extends TestCase> testCases) { public void buildProjectInfo(String projectId, List<TestCaseDTO> list) {
Project project = projectService.getProjectById(projectId);
list.forEach(item -> {
item.setProjectName(project.getName());
});
}
public void buildUserInfo(List<TestCaseDTO> testCases) {
List<String> userIds = new ArrayList(); List<String> userIds = new ArrayList();
userIds.addAll(testCases.stream().map(TestCase::getCreateUser).collect(Collectors.toList())); userIds.addAll(testCases.stream().map(TestCase::getCreateUser).collect(Collectors.toList()));
userIds.addAll(testCases.stream().map(TestCase::getDeleteUserId).collect(Collectors.toList())); userIds.addAll(testCases.stream().map(TestCase::getDeleteUserId).collect(Collectors.toList()));
@ -2377,9 +2387,9 @@ public class TestCaseService {
if (!org.apache.commons.collections.CollectionUtils.isEmpty(userIds)) { if (!org.apache.commons.collections.CollectionUtils.isEmpty(userIds)) {
Map<String, String> userMap = ServiceUtils.getUserNameMap(userIds); Map<String, String> userMap = ServiceUtils.getUserNameMap(userIds);
testCases.forEach(caseResult -> { testCases.forEach(caseResult -> {
caseResult.setCreateUser(userMap.get(caseResult.getCreateUser())); caseResult.setCreateName(userMap.get(caseResult.getCreateUser()));
caseResult.setDeleteUserId(userMap.get(caseResult.getDeleteUserId())); caseResult.setDeleteUserId(userMap.get(caseResult.getDeleteUserId()));
caseResult.setMaintainer(userMap.get(caseResult.getMaintainer())); caseResult.setMaintainerName(userMap.get(caseResult.getMaintainer()));
}); });
} }
} }

View File

@ -98,15 +98,11 @@
</ms-table-column> </ms-table-column>
<ms-table-column <ms-table-column
prop="createUser" prop="createName"
:field="item" :field="item"
:fields-width="fieldsWidth" :fields-width="fieldsWidth"
:label="$t('commons.create_user')" :label="$t('commons.create_user')"
min-width="120"> min-width="120"/>
<template v-slot:default="scope">
{{ memberMap.get(scope.row.createUser) }}
</template>
</ms-table-column>
<ms-table-column <ms-table-column
prop="reviewStatus" prop="reviewStatus"

View File

@ -195,7 +195,7 @@ export let CUSTOM_TABLE_HEADER = {
{id: 'nodePath', key: '5', label: 'test_track.case.module'}, {id: 'nodePath', key: '5', label: 'test_track.case.module'},
{id: 'projectName', key: 'a', label: 'test_track.review.review_project'}, {id: 'projectName', key: 'a', label: 'test_track.review.review_project'},
{id: 'updateTime', key: '6', label: 'commons.update_time'}, {id: 'updateTime', key: '6', label: 'commons.update_time'},
{id: 'createUser', key: '7', label: 'commons.create_user'}, {id: 'createName', key: '7', label: 'commons.create_user'},
{id: 'createTime', key: '8', label: 'commons.create_time'}, {id: 'createTime', key: '8', label: 'commons.create_time'},
{id: 'desc', key: '9', label: 'test_track.case.case_desc'}, {id: 'desc', key: '9', label: 'test_track.case.case_desc'},
{id: 'lastExecResult', key: '0', label: 'test_track.plan_view.execute_result'}, {id: 'lastExecResult', key: '0', label: 'test_track.plan_view.execute_result'},