From 9000e63385a5a9b9d700b5f5b5e285ee05c3556d Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Mon, 12 Jul 2021 15:36:24 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=B5=8B=E8=AF=95=E8=AE=A1?= =?UTF-8?q?=E5=88=92=E8=8B=A5=E5=B9=B2=E4=BC=98=E5=8C=96#3892?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/dto/automation/ApiScenarioDTO.java | 2 ++ .../dto/definition/TestPlanApiCaseDTO.java | 4 +++- .../mapper/ext/ExtTestPlanApiCaseMapper.xml | 7 +++---- .../ext/ExtTestPlanScenarioCaseMapper.xml | 2 +- .../commons/utils/ServiceUtils.java | 9 ++++++++ .../track/domain/ReportBaseInfoComponent.java | 18 +++++++++++++--- .../track/dto/TestCaseReportDTO.java | 11 ++++++++++ .../track/dto/TestCaseReportMetricDTO.java | 2 ++ .../testcase/PlanCaseRelevanceRequest.java | 1 + .../track/service/TestPlanApiCaseService.java | 17 ++++++++++++++- .../service/TestPlanScenarioCaseService.java | 19 ++++++++++++++++- .../track/service/TestPlanService.java | 4 +++- .../comonents/api/TestPlanApiCaseList.vue | 12 +++++++++-- .../comonents/api/TestPlanApiScenarioList.vue | 21 +++++++++++++++++-- .../TemplateComponent/BaseInfoComponent.vue | 4 ++-- .../src/common/js/default-table-header.js | 4 ++-- 16 files changed, 117 insertions(+), 20 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/track/dto/TestCaseReportDTO.java diff --git a/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioDTO.java b/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioDTO.java index 0bc374ed8b..5d627d3915 100644 --- a/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioDTO.java +++ b/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioDTO.java @@ -12,6 +12,8 @@ public class ApiScenarioDTO extends ApiScenarioWithBLOBs { private String projectName; private String userName; + private String creatorName; + private String principalName; private List tagNames; private String principalName; diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/TestPlanApiCaseDTO.java b/backend/src/main/java/io/metersphere/api/dto/definition/TestPlanApiCaseDTO.java index 53bb34fa5f..b0964474f4 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/TestPlanApiCaseDTO.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/TestPlanApiCaseDTO.java @@ -1,6 +1,5 @@ package io.metersphere.api.dto.definition; -import io.metersphere.base.domain.ApiTestCase; import lombok.Getter; import lombok.Setter; @@ -11,4 +10,7 @@ public class TestPlanApiCaseDTO extends ApiTestCaseDTO { private String caseId; private String execResult; private String userId; + private String creatorName; + private String principalName; + private String updateName; } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.xml index 31dcdf8142..b3cb3c1b14 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.xml @@ -4,9 +4,8 @@ - -- 查询没有数据再插入 - INSERT INTO test_plan_api_case(id, test_plan_id, api_case_id, environment_id, create_time, update_time) - SELECT #{request.id}, #{request.testPlanId}, #{request.apiCaseId}, #{request.environmentId}, #{request.createTime}, #{request.updateTime} + INSERT INTO test_plan_api_case(id, test_plan_id, api_case_id, environment_id, create_time, update_time, create_user) + SELECT #{request.id}, #{request.testPlanId}, #{request.apiCaseId}, #{request.environmentId}, #{request.createTime}, #{request.updateTime}, #{request.createUser} FROM DUAL WHERE NOT EXISTS( SELECT id FROM @@ -19,7 +18,7 @@ select t.id, t.environment_id, t.create_time, t.update_time, c.id as case_id, c.project_id, c.name, c.api_definition_id, c.priority, c.description, c.create_user_id, - c.update_user_id, c.num, c.tags, + c.update_user_id, c.num, c.tags, t.create_user, a.module_id, a.path, a.protocol, t.status execResult, a.user_id from test_plan_api_case t diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.xml index fb324d9cfe..49d535dd02 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.xml @@ -19,7 +19,7 @@ select t.id, t.environment, t.create_time, t.update_time, t.last_result, t.pass_rate, t.report_id, c.scenario_definition, c.id as case_id, c.user_id,c.api_scenario_module_id, c.module_path, c.name, c.level, - c.status, c.principal, c.step_total, c.follow_people, c.schedule, c.description, c.tags, + c.status, c.principal, c.step_total, c.follow_people, c.schedule, c.description, c.tags, t.create_user, p.name as project_name, p.id as project_id, u.name as user_name, if(p.scenario_custom_num = 0, cast(c.num as char), c.custom_num) as custom_num from test_plan_api_scenario t diff --git a/backend/src/main/java/io/metersphere/commons/utils/ServiceUtils.java b/backend/src/main/java/io/metersphere/commons/utils/ServiceUtils.java index 26bac9563c..3a39d9261a 100644 --- a/backend/src/main/java/io/metersphere/commons/utils/ServiceUtils.java +++ b/backend/src/main/java/io/metersphere/commons/utils/ServiceUtils.java @@ -63,4 +63,13 @@ public class ServiceUtils { } return new HashMap<>(); } + + public static Map getUserNameMap(List userIds) { + Map userMap = getUserMap(userIds); + HashMap nameMap = new HashMap<>(); + userMap.forEach((k, v) -> { + nameMap.put(k, v.getName()); + }); + return nameMap; + } } diff --git a/backend/src/main/java/io/metersphere/track/domain/ReportBaseInfoComponent.java b/backend/src/main/java/io/metersphere/track/domain/ReportBaseInfoComponent.java index 04dbfee877..25995409f4 100644 --- a/backend/src/main/java/io/metersphere/track/domain/ReportBaseInfoComponent.java +++ b/backend/src/main/java/io/metersphere/track/domain/ReportBaseInfoComponent.java @@ -1,12 +1,12 @@ package io.metersphere.track.domain; +import io.metersphere.commons.utils.ServiceUtils; import io.metersphere.track.dto.TestCaseReportMetricDTO; import io.metersphere.track.dto.TestPlanCaseDTO; import io.metersphere.track.dto.TestPlanDTO; +import org.apache.commons.lang3.StringUtils; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Set; +import java.util.*; public class ReportBaseInfoComponent extends ReportComponent { private Set executorsSet = new HashSet<>(); @@ -26,5 +26,17 @@ public class ReportBaseInfoComponent extends ReportComponent { testCaseReportMetric.setProjectName(testPlan.getProjectName()); testCaseReportMetric.setPrincipal(testPlan.getPrincipal()); testCaseReportMetric.setExecutors(new ArrayList<>(this.executorsSet)); + List userIds = new ArrayList<>(); + userIds.add(testPlan.getPrincipal()); + userIds.addAll(testCaseReportMetric.getExecutors()); + Map userMap = ServiceUtils.getUserNameMap(userIds); + testCaseReportMetric.setPrincipalName(userMap.get(testCaseReportMetric.getPrincipal())); + List names = new ArrayList<>(); + testCaseReportMetric.getExecutors().forEach(item -> { + if (StringUtils.isNotBlank(item)) { + names.add(userMap.get(item)); + } + }); + testCaseReportMetric.setExecutorNames(names); } } diff --git a/backend/src/main/java/io/metersphere/track/dto/TestCaseReportDTO.java b/backend/src/main/java/io/metersphere/track/dto/TestCaseReportDTO.java new file mode 100644 index 0000000000..b11bafa44c --- /dev/null +++ b/backend/src/main/java/io/metersphere/track/dto/TestCaseReportDTO.java @@ -0,0 +1,11 @@ +package io.metersphere.track.dto; + +import io.metersphere.base.domain.TestCaseReport; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class TestCaseReportDTO extends TestCaseReport { + private String createName; +} diff --git a/backend/src/main/java/io/metersphere/track/dto/TestCaseReportMetricDTO.java b/backend/src/main/java/io/metersphere/track/dto/TestCaseReportMetricDTO.java index 8275120d0b..514fc659bc 100644 --- a/backend/src/main/java/io/metersphere/track/dto/TestCaseReportMetricDTO.java +++ b/backend/src/main/java/io/metersphere/track/dto/TestCaseReportMetricDTO.java @@ -17,7 +17,9 @@ public class TestCaseReportMetricDTO { // private List failureTestCases; private List Issues; private List executors; + private List executorNames; private String principal; + private String principalName; private Long startTime; private Long endTime; private String projectName; diff --git a/backend/src/main/java/io/metersphere/track/request/testcase/PlanCaseRelevanceRequest.java b/backend/src/main/java/io/metersphere/track/request/testcase/PlanCaseRelevanceRequest.java index ad61bf65d6..5df7167ae7 100644 --- a/backend/src/main/java/io/metersphere/track/request/testcase/PlanCaseRelevanceRequest.java +++ b/backend/src/main/java/io/metersphere/track/request/testcase/PlanCaseRelevanceRequest.java @@ -13,6 +13,7 @@ public class PlanCaseRelevanceRequest { * 测试计划ID */ private String planId; + private String executor; private List ids; diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanApiCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanApiCaseService.java index cdb6b2d286..e32cb140dd 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanApiCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanApiCaseService.java @@ -59,10 +59,25 @@ public class TestPlanApiCaseService { if (CollectionUtils.isEmpty(apiTestCases)) { return apiTestCases; } - apiTestCaseService.buildUserInfo(apiTestCases); + buildUserInfo(apiTestCases); return apiTestCases; } + public void buildUserInfo(List apiTestCases) { + List userIds = new ArrayList(); + userIds.addAll(apiTestCases.stream().map(TestPlanApiCaseDTO::getCreateUser).collect(Collectors.toList())); + userIds.addAll(apiTestCases.stream().map(TestPlanApiCaseDTO::getUpdateUser).collect(Collectors.toList())); + userIds.addAll(apiTestCases.stream().map(TestPlanApiCaseDTO::getUserId).collect(Collectors.toList())); + if (!org.apache.commons.collections.CollectionUtils.isEmpty(userIds)) { + Map userMap = ServiceUtils.getUserNameMap(userIds); + apiTestCases.forEach(caseResult -> { + caseResult.setCreatorName(userMap.get(caseResult.getCreateUser())); + caseResult.setUpdateName(userMap.get(caseResult.getUpdateUser())); + caseResult.setPrincipalName(userMap.get(caseResult.getUserId())); + }); + } + } + public List selectIds(ApiTestCaseRequest request) { request.setProjectId(null); request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanScenarioCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanScenarioCaseService.java index 12ac9b3d75..19b6e75208 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanScenarioCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanScenarioCaseService.java @@ -12,12 +12,13 @@ import io.metersphere.base.mapper.ext.ExtTestPlanScenarioCaseMapper; import io.metersphere.commons.constants.ApiRunMode; import io.metersphere.commons.utils.ServiceUtils; import io.metersphere.log.vo.OperatingLogDetails; +import io.metersphere.service.UserService; import io.metersphere.track.dto.RelevanceScenarioRequest; import io.metersphere.track.request.testcase.TestPlanScenarioCaseBatchRequest; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.apache.commons.lang3.StringUtils; import javax.annotation.Resource; import java.util.*; @@ -39,6 +40,8 @@ public class TestPlanScenarioCaseService { ApiScenarioMapper apiScenarioMapper; @Resource private TestPlanMapper testPlanMapper; + @Resource + private UserService userService; public List list(TestPlanScenarioRequest request) { request.setProjectId(null); @@ -47,9 +50,23 @@ public class TestPlanScenarioCaseService { if (CollectionUtils.isEmpty(apiTestCases)) { return apiTestCases; } + buildUserInfo(apiTestCases); return apiTestCases; } + public void buildUserInfo(List apiTestCases) { + List userIds = new ArrayList(); + userIds.addAll(apiTestCases.stream().map(ApiScenarioDTO::getUserId).collect(Collectors.toList())); + userIds.addAll(apiTestCases.stream().map(ApiScenarioDTO::getPrincipal).collect(Collectors.toList())); + if (!CollectionUtils.isEmpty(userIds)) { + Map userMap = ServiceUtils.getUserNameMap(userIds); + apiTestCases.forEach(caseResult -> { + caseResult.setCreatorName(userMap.get(caseResult.getCreateUser())); + caseResult.setPrincipalName(userMap.get(caseResult.getPrincipal())); + }); + } + } + public List selectIds(TestPlanScenarioRequest request) { request.setProjectId(null); request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java index e8de42f31d..033efa482b 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java @@ -456,6 +456,8 @@ public class TestPlanService { TestCaseExample testCaseExample = new TestCaseExample(); testCaseExample.createCriteria().andIdIn(testCaseIds); + List testCaseList = testCaseMapper.selectByExample(testCaseExample); + Map userMap = testCaseList.stream().collect(Collectors.toMap(TestCase::getId, TestCase::getMaintainer)); SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); TestPlanTestCaseMapper batchMapper = sqlSession.getMapper(TestPlanTestCaseMapper.class); @@ -464,7 +466,7 @@ public class TestPlanService { TestPlanTestCaseWithBLOBs testPlanTestCase = new TestPlanTestCaseWithBLOBs(); testPlanTestCase.setId(UUID.randomUUID().toString()); testPlanTestCase.setCreateUser(SessionUtils.getUserId()); - testPlanTestCase.setExecutor(SessionUtils.getUser().getId()); + testPlanTestCase.setExecutor(userMap.get(caseId) == null ? SessionUtils.getUserId() : userMap.get(caseId)); testPlanTestCase.setCaseId(caseId); testPlanTestCase.setCreateTime(System.currentTimeMillis()); testPlanTestCase.setUpdateTime(System.currentTimeMillis()); diff --git a/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiCaseList.vue b/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiCaseList.vue index 8a9c4d739a..97f87e8d81 100644 --- a/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiCaseList.vue +++ b/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiCaseList.vue @@ -62,14 +62,22 @@ sortable min-width="100" :filters="userFilters" - :label="'创建人'"/> + :label="'创建人'"> + + + min-width="120"> + + diff --git a/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiScenarioList.vue b/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiScenarioList.vue index 015bc27d2f..7135179b37 100644 --- a/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiScenarioList.vue +++ b/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiScenarioList.vue @@ -59,8 +59,25 @@ + prop="createUser" + :label="$t('api_test.automation.creator')" + min-width="100px"> + + + + + + + {{$t('test_track.plan.plan_principal')}}: - {{reportInfo.principal}} + {{reportInfo.principalName}} @@ -31,7 +31,7 @@ {{$t('test_track.plan_view.executor')}}: - {{item}} + {{item}} diff --git a/frontend/src/common/js/default-table-header.js b/frontend/src/common/js/default-table-header.js index a0f0347d82..a25da93998 100644 --- a/frontend/src/common/js/default-table-header.js +++ b/frontend/src/common/js/default-table-header.js @@ -159,11 +159,11 @@ export const CUSTOM_TABLE_HEADER = { {id: 'name', key: '2', label: i18n.t('api_test.automation.scenario_name')}, {id: 'level', key: '3', label: i18n.t('api_test.automation.case_level')}, {id: 'tagNames', key: '4', label: i18n.t('api_test.automation.tag')}, - {id: 'stepTotal', key: '7', label: i18n.t('api_test.automation.success')}, + {id: 'stepTotal', key: '7', label: i18n.t( 'api_test.automation.success')}, {id: 'lastResult', key: '8', label: i18n.t('api_test.automation.fail')}, {id: 'passRate', key: '9', label: i18n.t('api_test.automation.passing_rate')}, {id: 'maintainer', key: 'a', label: i18n.t('api_test.definition.request.responsible')}, - {id: 'userId', key: '5', label: i18n.t('api_test.automation.creator')}, + {id: 'createUser', key: '5', label: i18n.t('api_test.automation.creator')}, {id: 'updateTime', key: '6', label: i18n.t('api_test.automation.update_time')}, {id: 'createTime', key: 'b', label: i18n.t('commons.create_time')}, ],