refactor: 测试计划若干优化#3892
This commit is contained in:
parent
eb460e8545
commit
9000e63385
|
@ -12,6 +12,8 @@ public class ApiScenarioDTO extends ApiScenarioWithBLOBs {
|
|||
|
||||
private String projectName;
|
||||
private String userName;
|
||||
private String creatorName;
|
||||
private String principalName;
|
||||
private List<String> tagNames;
|
||||
private String principalName;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -4,9 +4,8 @@
|
|||
|
||||
|
||||
<insert id="insertIfNotExists" parameterType="io.metersphere.base.domain.TestPlanApiCase">
|
||||
-- 查询没有数据再插入
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -63,4 +63,13 @@ public class ServiceUtils {
|
|||
}
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
public static Map<String, String> getUserNameMap(List<String> userIds) {
|
||||
Map<String, User> userMap = getUserMap(userIds);
|
||||
HashMap<String, String> nameMap = new HashMap<>();
|
||||
userMap.forEach((k, v) -> {
|
||||
nameMap.put(k, v.getName());
|
||||
});
|
||||
return nameMap;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String> 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<String> userIds = new ArrayList<>();
|
||||
userIds.add(testPlan.getPrincipal());
|
||||
userIds.addAll(testCaseReportMetric.getExecutors());
|
||||
Map<String, String> userMap = ServiceUtils.getUserNameMap(userIds);
|
||||
testCaseReportMetric.setPrincipalName(userMap.get(testCaseReportMetric.getPrincipal()));
|
||||
List<String> names = new ArrayList<>();
|
||||
testCaseReportMetric.getExecutors().forEach(item -> {
|
||||
if (StringUtils.isNotBlank(item)) {
|
||||
names.add(userMap.get(item));
|
||||
}
|
||||
});
|
||||
testCaseReportMetric.setExecutorNames(names);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -17,7 +17,9 @@ public class TestCaseReportMetricDTO {
|
|||
// private List<TestPlanCaseDTO> failureTestCases;
|
||||
private List<IssuesDao> Issues;
|
||||
private List<String> executors;
|
||||
private List<String> executorNames;
|
||||
private String principal;
|
||||
private String principalName;
|
||||
private Long startTime;
|
||||
private Long endTime;
|
||||
private String projectName;
|
||||
|
|
|
@ -13,6 +13,7 @@ public class PlanCaseRelevanceRequest {
|
|||
* 测试计划ID
|
||||
*/
|
||||
private String planId;
|
||||
private String executor;
|
||||
|
||||
private List<String> ids;
|
||||
|
||||
|
|
|
@ -59,10 +59,25 @@ public class TestPlanApiCaseService {
|
|||
if (CollectionUtils.isEmpty(apiTestCases)) {
|
||||
return apiTestCases;
|
||||
}
|
||||
apiTestCaseService.buildUserInfo(apiTestCases);
|
||||
buildUserInfo(apiTestCases);
|
||||
return apiTestCases;
|
||||
}
|
||||
|
||||
public void buildUserInfo(List<? extends TestPlanApiCaseDTO> apiTestCases) {
|
||||
List<String> 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<String, String> 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<String> selectIds(ApiTestCaseRequest request) {
|
||||
request.setProjectId(null);
|
||||
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
|
||||
|
|
|
@ -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<ApiScenarioDTO> 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<? extends ApiScenarioDTO> apiTestCases) {
|
||||
List<String> 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<String, String> userMap = ServiceUtils.getUserNameMap(userIds);
|
||||
apiTestCases.forEach(caseResult -> {
|
||||
caseResult.setCreatorName(userMap.get(caseResult.getCreateUser()));
|
||||
caseResult.setPrincipalName(userMap.get(caseResult.getPrincipal()));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> selectIds(TestPlanScenarioRequest request) {
|
||||
request.setProjectId(null);
|
||||
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
|
||||
|
|
|
@ -456,6 +456,8 @@ public class TestPlanService {
|
|||
|
||||
TestCaseExample testCaseExample = new TestCaseExample();
|
||||
testCaseExample.createCriteria().andIdIn(testCaseIds);
|
||||
List<TestCase> testCaseList = testCaseMapper.selectByExample(testCaseExample);
|
||||
Map<String, String> 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());
|
||||
|
|
|
@ -62,14 +62,22 @@
|
|||
sortable
|
||||
min-width="100"
|
||||
:filters="userFilters"
|
||||
:label="'创建人'"/>
|
||||
:label="'创建人'">
|
||||
<template v-slot:default="scope">
|
||||
{{scope.row.creatorName}}
|
||||
</template>
|
||||
</ms-table-column>
|
||||
|
||||
<ms-table-column
|
||||
v-if="item.id == 'maintainer'"
|
||||
prop="userId"
|
||||
:fields-width="fieldsWidth"
|
||||
:label="$t('custom_field.case_maintainer')"
|
||||
min-width="120"/>
|
||||
min-width="120">
|
||||
<template v-slot:default="scope">
|
||||
{{scope.row.principalName}}
|
||||
</template>
|
||||
</ms-table-column>
|
||||
|
||||
<ms-update-time-column :field="item" :fields-width="fieldsWidth"/>
|
||||
<ms-create-time-column :field="item" :fields-width="fieldsWidth"/>
|
||||
|
|
|
@ -59,8 +59,25 @@
|
|||
|
||||
<ms-table-column :field="item"
|
||||
:fields-width="fieldsWidth"
|
||||
prop="userId" :label="$t('api_test.automation.creator')"
|
||||
min-width="100px"/>
|
||||
prop="createUser"
|
||||
:label="$t('api_test.automation.creator')"
|
||||
min-width="100px">
|
||||
<template v-slot:default="scope">
|
||||
{{scope.row.creatorName}}
|
||||
</template>
|
||||
</ms-table-column>
|
||||
|
||||
<ms-table-column
|
||||
v-if="item.id == 'maintainer'"
|
||||
prop="userId"
|
||||
:fields-width="fieldsWidth"
|
||||
:label="$t('custom_field.case_maintainer')"
|
||||
min-width="120">
|
||||
<template v-slot:default="scope">
|
||||
{{scope.row.principalName}}
|
||||
</template>
|
||||
</ms-table-column>
|
||||
|
||||
|
||||
<ms-table-column
|
||||
:field="item"
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
</el-col>
|
||||
<el-col :span="12">
|
||||
<span>{{$t('test_track.plan.plan_principal')}}:</span>
|
||||
<span class="item-value">{{reportInfo.principal}}</span>
|
||||
<span class="item-value">{{reportInfo.principalName}}</span>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
|
@ -31,7 +31,7 @@
|
|||
<el-row type="flex" justify="space-between">
|
||||
<el-col :span="12">
|
||||
<span>{{$t('test_track.plan_view.executor')}}:</span>
|
||||
<span v-for="item in reportInfo.executors" :key="item">{{item}}</span>
|
||||
<span v-for="item in reportInfo.executorNames" :key="item">{{item}}</span>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
|
|
|
@ -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')},
|
||||
],
|
||||
|
|
Loading…
Reference in New Issue