From a5a4bf76b8bd9eca48b289852610e105d41a2a2b Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Fri, 21 Jan 2022 17:48:37 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=8A=9F=E8=83=BD=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=E6=9F=A5=E8=AF=A2=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/mapper/ext/ExtTestCaseMapper.xml | 11 +++----- .../track/service/TestCaseService.java | 26 +++++++++++++------ .../track/case/components/TestCaseList.vue | 8 ++---- .../src/common/js/default-table-header.js | 2 +- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml index 9b1ee3a8f9..78355cb18f 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml @@ -226,14 +226,11 @@ 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.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_fields, project.name as projectName , test_case.ref_id + test_case.custom_num, test_case.step_model, test_case.create_user, + test_case.custom_fields, test_case.ref_id - from test_case left join user u on test_case.create_user=u.id - left join user deleteUser on test_case.delete_user_id=deleteUser.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 + from test_case + left join project_version on project_version.id = test_case.version_id and project_version.project_id = #{request.project_id} diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java index 7476dc8feb..9d6a3537d8 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java @@ -532,9 +532,11 @@ public class TestCaseService { if (request.getFilters() != null && !request.getFilters().containsKey("status")) { request.getFilters().put("status", new ArrayList<>(0)); } - List returnList = extTestCaseMapper.list(request); - returnList = this.parseStatus(returnList); - return returnList; + List list = extTestCaseMapper.list(request); + buildUserInfo(list); + buildProjectInfo(request.getProjectId(), list); + list = this.parseStatus(list); + return list; } public List publicListTestCase(QueryTestCaseRequest request) { @@ -2332,7 +2334,8 @@ public class TestCaseService { TestCaseExample example = new TestCaseExample(); example.createCriteria().andIdIn(ids).andStatusNotEqualTo("Trash"); List testCaseList = testCaseMapper.selectByExampleWithBLOBs(example); - buildUserInfo(testCaseList); + + Map userNameMap = ServiceUtils.getUserNameMap(testCaseList.stream().map(TestCaseWithBLOBs::getCreateUser).collect(Collectors.toList())); Map verionNameMap = new HashMap<>(); List versionIds = testCaseList.stream().map(TestCase::getVersionId).collect(Collectors.toList()); @@ -2357,7 +2360,7 @@ public class TestCaseService { continue; // 用例可能在回收站 } relationshipEdgeDTO.setTargetName(testCase.getName()); - relationshipEdgeDTO.setCreator(testCase.getCreateUser()); + relationshipEdgeDTO.setCreator(userNameMap.get(testCase.getCreateUser())); relationshipEdgeDTO.setTargetNum(testCase.getNum()); relationshipEdgeDTO.setTargetCustomNum(testCase.getCustomNum()); relationshipEdgeDTO.setStatus(testCase.getStatus()); @@ -2369,7 +2372,14 @@ public class TestCaseService { return new ArrayList<>(); } - public void buildUserInfo(List testCases) { + public void buildProjectInfo(String projectId, List list) { + Project project = projectService.getProjectById(projectId); + list.forEach(item -> { + item.setProjectName(project.getName()); + }); + } + + public void buildUserInfo(List testCases) { List userIds = new ArrayList(); userIds.addAll(testCases.stream().map(TestCase::getCreateUser).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)) { Map userMap = ServiceUtils.getUserNameMap(userIds); testCases.forEach(caseResult -> { - caseResult.setCreateUser(userMap.get(caseResult.getCreateUser())); + caseResult.setCreateName(userMap.get(caseResult.getCreateUser())); caseResult.setDeleteUserId(userMap.get(caseResult.getDeleteUserId())); - caseResult.setMaintainer(userMap.get(caseResult.getMaintainer())); + caseResult.setMaintainerName(userMap.get(caseResult.getMaintainer())); }); } } diff --git a/frontend/src/business/components/track/case/components/TestCaseList.vue b/frontend/src/business/components/track/case/components/TestCaseList.vue index 2296e5f1f0..d54fad71e9 100644 --- a/frontend/src/business/components/track/case/components/TestCaseList.vue +++ b/frontend/src/business/components/track/case/components/TestCaseList.vue @@ -98,15 +98,11 @@ - - + min-width="120"/>