refactor(测试计划): 测试计划优化

This commit is contained in:
shiziyuan9527 2020-12-30 18:15:07 +08:00
parent a683bb27ff
commit 1631803bbd
13 changed files with 224 additions and 44 deletions

View File

@ -1,8 +1,7 @@
package io.metersphere.base.domain;
import lombok.Data;
import java.io.Serializable;
import lombok.Data;
@Data
public class TestPlan implements Serializable {
@ -40,6 +39,8 @@ public class TestPlan implements Serializable {
private String creator;
private String projectId;
private String tags;
private static final long serialVersionUID = 1L;

View File

@ -1233,6 +1233,76 @@ public class TestPlanExample {
addCriterion("creator not between", value1, value2, "creator");
return (Criteria) this;
}
public Criteria andProjectIdIsNull() {
addCriterion("project_id is null");
return (Criteria) this;
}
public Criteria andProjectIdIsNotNull() {
addCriterion("project_id is not null");
return (Criteria) this;
}
public Criteria andProjectIdEqualTo(String value) {
addCriterion("project_id =", value, "projectId");
return (Criteria) this;
}
public Criteria andProjectIdNotEqualTo(String value) {
addCriterion("project_id <>", value, "projectId");
return (Criteria) this;
}
public Criteria andProjectIdGreaterThan(String value) {
addCriterion("project_id >", value, "projectId");
return (Criteria) this;
}
public Criteria andProjectIdGreaterThanOrEqualTo(String value) {
addCriterion("project_id >=", value, "projectId");
return (Criteria) this;
}
public Criteria andProjectIdLessThan(String value) {
addCriterion("project_id <", value, "projectId");
return (Criteria) this;
}
public Criteria andProjectIdLessThanOrEqualTo(String value) {
addCriterion("project_id <=", value, "projectId");
return (Criteria) this;
}
public Criteria andProjectIdLike(String value) {
addCriterion("project_id like", value, "projectId");
return (Criteria) this;
}
public Criteria andProjectIdNotLike(String value) {
addCriterion("project_id not like", value, "projectId");
return (Criteria) this;
}
public Criteria andProjectIdIn(List<String> values) {
addCriterion("project_id in", values, "projectId");
return (Criteria) this;
}
public Criteria andProjectIdNotIn(List<String> values) {
addCriterion("project_id not in", values, "projectId");
return (Criteria) this;
}
public Criteria andProjectIdBetween(String value1, String value2) {
addCriterion("project_id between", value1, value2, "projectId");
return (Criteria) this;
}
public Criteria andProjectIdNotBetween(String value1, String value2) {
addCriterion("project_id not between", value1, value2, "projectId");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {

View File

@ -19,6 +19,7 @@
<result column="planned_end_time" jdbcType="BIGINT" property="plannedEndTime" />
<result column="actual_start_time" jdbcType="BIGINT" property="actualStartTime" />
<result column="creator" jdbcType="VARCHAR" property="creator" />
<result column="project_id" jdbcType="VARCHAR" property="projectId" />
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.base.domain.TestPlan">
<result column="tags" jdbcType="LONGVARCHAR" property="tags" />
@ -84,7 +85,7 @@
<sql id="Base_Column_List">
id, workspace_id, report_id, `name`, description, `status`, stage, principal, test_case_match_rule,
executor_match_rule, create_time, update_time, actual_end_time, planned_start_time,
planned_end_time, actual_start_time, creator
planned_end_time, actual_start_time, creator, project_id
</sql>
<sql id="Blob_Column_List">
tags
@ -143,15 +144,15 @@
stage, principal, test_case_match_rule,
executor_match_rule, create_time, update_time,
actual_end_time, planned_start_time, planned_end_time,
actual_start_time, creator, tags
)
actual_start_time, creator, project_id,
tags)
values (#{id,jdbcType=VARCHAR}, #{workspaceId,jdbcType=VARCHAR}, #{reportId,jdbcType=VARCHAR},
#{name,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR},
#{stage,jdbcType=VARCHAR}, #{principal,jdbcType=VARCHAR}, #{testCaseMatchRule,jdbcType=VARCHAR},
#{executorMatchRule,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT},
#{actualEndTime,jdbcType=BIGINT}, #{plannedStartTime,jdbcType=BIGINT}, #{plannedEndTime,jdbcType=BIGINT},
#{actualStartTime,jdbcType=BIGINT}, #{creator,jdbcType=VARCHAR}, #{tags,jdbcType=LONGVARCHAR}
)
#{actualStartTime,jdbcType=BIGINT}, #{creator,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR},
#{tags,jdbcType=LONGVARCHAR})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.TestPlan">
insert into test_plan
@ -207,6 +208,9 @@
<if test="creator != null">
creator,
</if>
<if test="projectId != null">
project_id,
</if>
<if test="tags != null">
tags,
</if>
@ -263,6 +267,9 @@
<if test="creator != null">
#{creator,jdbcType=VARCHAR},
</if>
<if test="projectId != null">
#{projectId,jdbcType=VARCHAR},
</if>
<if test="tags != null">
#{tags,jdbcType=LONGVARCHAR},
</if>
@ -328,6 +335,9 @@
<if test="record.creator != null">
creator = #{record.creator,jdbcType=VARCHAR},
</if>
<if test="record.projectId != null">
project_id = #{record.projectId,jdbcType=VARCHAR},
</if>
<if test="record.tags != null">
tags = #{record.tags,jdbcType=LONGVARCHAR},
</if>
@ -355,6 +365,7 @@
planned_end_time = #{record.plannedEndTime,jdbcType=BIGINT},
actual_start_time = #{record.actualStartTime,jdbcType=BIGINT},
creator = #{record.creator,jdbcType=VARCHAR},
project_id = #{record.projectId,jdbcType=VARCHAR},
tags = #{record.tags,jdbcType=LONGVARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
@ -378,7 +389,8 @@
planned_start_time = #{record.plannedStartTime,jdbcType=BIGINT},
planned_end_time = #{record.plannedEndTime,jdbcType=BIGINT},
actual_start_time = #{record.actualStartTime,jdbcType=BIGINT},
creator = #{record.creator,jdbcType=VARCHAR}
creator = #{record.creator,jdbcType=VARCHAR},
project_id = #{record.projectId,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -434,6 +446,9 @@
<if test="creator != null">
creator = #{creator,jdbcType=VARCHAR},
</if>
<if test="projectId != null">
project_id = #{projectId,jdbcType=VARCHAR},
</if>
<if test="tags != null">
tags = #{tags,jdbcType=LONGVARCHAR},
</if>
@ -458,6 +473,7 @@
planned_end_time = #{plannedEndTime,jdbcType=BIGINT},
actual_start_time = #{actualStartTime,jdbcType=BIGINT},
creator = #{creator,jdbcType=VARCHAR},
project_id = #{projectId,jdbcType=VARCHAR},
tags = #{tags,jdbcType=LONGVARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
@ -478,7 +494,8 @@
planned_start_time = #{plannedStartTime,jdbcType=BIGINT},
planned_end_time = #{plannedEndTime,jdbcType=BIGINT},
actual_start_time = #{actualStartTime,jdbcType=BIGINT},
creator = #{creator,jdbcType=VARCHAR}
creator = #{creator,jdbcType=VARCHAR},
project_id = #{projectId,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper>

View File

@ -98,9 +98,9 @@
<select id="list" resultType="io.metersphere.track.dto.TestPlanDTOWithMetric"
parameterType="io.metersphere.track.request.testcase.QueryTestPlanRequest">
select DISTINCT test_plan.*, user.name as user_name from test_plan
select DISTINCT test_plan.*, user.name as user_name, project.name as projectName from test_plan
LEFT JOIN user ON user.id = test_plan.principal
JOIN test_plan_project on test_plan.id = test_plan_project.test_plan_id JOIN project on project.id = test_plan_project.project_id
JOIN project on project.id = test_plan.project_id
<where>
<if test="request.combine != null">
<include refid="combine">
@ -115,7 +115,7 @@
AND test_plan.workspace_id = #{request.workspaceId}
</if>
<if test="request.projectId != null">
AND test_plan_project.project_id = #{request.projectId}
AND test_plan.project_id = #{request.projectId}
</if>
<if test="request.id != null">
AND test_plan.id = #{request.id}
@ -190,7 +190,8 @@
</select>
<select id="checkIsHave" resultType="int">
SELECT COUNT(1)
select sum(c) from (
SELECT COUNT(1) as c
FROM test_plan_project, project
WHERE project_id = project.id AND test_plan_id = #{planId}
<if test="workspaceIds != null and workspaceIds.size() > 0">
@ -199,6 +200,15 @@
#{id}
</foreach>
</if>
union
select count(1) as c from test_plan, project
WHERE project_id = project.id AND test_plan.id = #{planId}
<if test="workspaceIds != null and workspaceIds.size() > 0">
AND project.workspace_id IN
<foreach collection="workspaceIds" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</if>) as temp
</select>
<select id="selectTestPlanByRelevancy" resultMap="BaseResultMap" parameterType="io.metersphere.track.request.testcase.QueryTestPlanRequest">

View File

@ -27,4 +27,6 @@ public class QueryTestPlanRequest extends TestPlan {
private Map<String, Object> combine;
private String projectId;
private String projectName;
}

View File

@ -1,10 +1,8 @@
package io.metersphere.track.service;
import io.metersphere.base.domain.Project;
import io.metersphere.base.domain.ProjectExample;
import io.metersphere.base.domain.TestPlanProject;
import io.metersphere.base.domain.TestPlanProjectExample;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.ProjectMapper;
import io.metersphere.base.mapper.TestPlanMapper;
import io.metersphere.base.mapper.TestPlanProjectMapper;
import io.metersphere.track.request.testplancase.TestCaseRelevanceRequest;
import org.apache.commons.lang3.StringUtils;
@ -24,15 +22,22 @@ public class TestPlanProjectService {
TestPlanProjectMapper testPlanProjectMapper;
@Resource
ProjectMapper projectMapper;
@Resource
private TestPlanMapper testPlanMapper;
public List<String> getProjectIdsByPlanId(String planId) {
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(planId);
TestPlanProjectExample example = new TestPlanProjectExample();
example.createCriteria().andTestPlanIdEqualTo(planId);
List<String> projectIds = testPlanProjectMapper.selectByExample(example)
.stream()
.map(TestPlanProject::getProjectId)
.collect(Collectors.toList());
if (testPlan != null && StringUtils.isNotBlank(testPlan.getProjectId())) {
if (!projectIds.contains(testPlan.getProjectId())) {
projectIds.add(testPlan.getProjectId());
}
}
if (projectIds.isEmpty()) {
return null;
}

View File

@ -111,6 +111,7 @@ public class TestPlanService {
testPlan.setCreateTime(System.currentTimeMillis());
testPlan.setUpdateTime(System.currentTimeMillis());
testPlan.setCreator(SessionUtils.getUser().getId());
testPlan.setProjectId(SessionUtils.getCurrentProjectId());
testPlanMapper.insert(testPlan);
List<String> userIds = new ArrayList<>();
@ -177,8 +178,16 @@ public class TestPlanService {
}
private void editTestPlanProject(TestPlanDTO testPlan) {
// 将要进行关联的项目ID
List<String> projectIds = testPlan.getProjectIds();
// 如果将要关联的项目ID中包含测试计划所属ID则进行剔除
if (!CollectionUtils.isEmpty(projectIds)) {
if (projectIds.contains(testPlan.getProjectId())) {
projectIds.remove(testPlan.getProjectId());
}
}
// todo 优化 TestPlanList intoPlan 方法会触发此更新
if (StringUtils.isNotBlank(testPlan.getProjectId())) {
TestPlanProjectExample testPlanProjectExample1 = new TestPlanProjectExample();
testPlanProjectExample1.createCriteria().andTestPlanIdEqualTo(testPlan.getId());
List<TestPlanProject> testPlanProjects = testPlanProjectMapper.selectByExample(testPlanProjectExample1);
@ -195,14 +204,21 @@ public class TestPlanService {
});
TestPlanProjectExample testPlanProjectExample = new TestPlanProjectExample();
testPlanProjectExample.createCriteria().andTestPlanIdEqualTo(testPlan.getId()).andProjectIdNotIn(projectIds);
TestPlanProjectExample.Criteria criteria1 = testPlanProjectExample.createCriteria();
criteria1.andTestPlanIdEqualTo(testPlan.getId());
if (!CollectionUtils.isEmpty(projectIds)) {
criteria1.andProjectIdNotIn(projectIds);
}
testPlanProjectMapper.deleteByExample(testPlanProjectExample);
// 关联的项目下的用例idList
List<String> caseIds = null;
if (!CollectionUtils.isEmpty(projectIds)) {
TestCaseExample example = new TestCaseExample();
example.createCriteria().andProjectIdIn(projectIds);
List<TestCase> caseList = testCaseMapper.selectByExample(example);
List<String> caseIds = caseList.stream().map(TestCase::getId).collect(Collectors.toList());
caseIds = caseList.stream().map(TestCase::getId).collect(Collectors.toList());
}
// 取消关联所属项目下的用例和计划的关系
TestPlanTestCaseExample testPlanTestCaseExample = new TestPlanTestCaseExample();
@ -415,13 +431,13 @@ public class TestPlanService {
if (StringUtils.isBlank(currentWorkspaceId)) {
return null;
}
TestPlanProjectExample testPlanProjectExample = new TestPlanProjectExample();
TestPlanProjectExample.Criteria criteria = testPlanProjectExample.createCriteria();
if (StringUtils.isNotBlank(SessionUtils.getCurrentProjectId())) {
TestPlanExample testPlanExample = new TestPlanExample();
TestPlanExample.Criteria criteria = testPlanExample.createCriteria();
criteria.andProjectIdEqualTo(SessionUtils.getCurrentProjectId());
List<TestPlanProject> testPlanProjects = testPlanProjectMapper.selectByExample(testPlanProjectExample);
if (!CollectionUtils.isEmpty(testPlanProjects)) {
List<String> testPlanIds = testPlanProjects.stream().map(TestPlanProject::getTestPlanId).collect(Collectors.toList());
List<TestPlan> testPlans = testPlanMapper.selectByExample(testPlanExample);
if (!CollectionUtils.isEmpty(testPlans)) {
List<String> testPlanIds = testPlans.stream().map(TestPlan::getId).collect(Collectors.toList());
TestPlanExample testPlanTestCaseExample = new TestPlanExample();
testPlanTestCaseExample.createCriteria().andWorkspaceIdEqualTo(currentWorkspaceId)
.andIdIn(testPlanIds)
@ -434,18 +450,18 @@ public class TestPlanService {
}
public List<TestPlan> listTestAllPlan(String currentWorkspaceId) {
TestPlanProjectExample testPlanProjectExample = new TestPlanProjectExample();
TestPlanProjectExample.Criteria criteria = testPlanProjectExample.createCriteria();
if (StringUtils.isNotBlank(SessionUtils.getCurrentProjectId())) {
criteria.andProjectIdEqualTo(SessionUtils.getCurrentProjectId());
List<TestPlanProject> testPlanProjects = testPlanProjectMapper.selectByExample(testPlanProjectExample);
if (!CollectionUtils.isEmpty(testPlanProjects)) {
List<String> testPlanIds = testPlanProjects.stream().map(TestPlanProject::getTestPlanId).collect(Collectors.toList());
TestPlanExample testPlanExample = new TestPlanExample();
TestPlanExample.Criteria testPlanCriteria = testPlanExample.createCriteria();
TestPlanExample.Criteria criteria = testPlanExample.createCriteria();
criteria.andProjectIdEqualTo(SessionUtils.getCurrentProjectId());
List<TestPlan> testPlans = testPlanMapper.selectByExample(testPlanExample);
if (!CollectionUtils.isEmpty(testPlans)) {
List<String> testPlanIds = testPlans.stream().map(TestPlan::getId).collect(Collectors.toList());
TestPlanExample testPlanExample1 = new TestPlanExample();
TestPlanExample.Criteria testPlanCriteria = testPlanExample1.createCriteria();
testPlanCriteria.andWorkspaceIdEqualTo(currentWorkspaceId);
testPlanCriteria.andIdIn(testPlanIds);
return testPlanMapper.selectByExample(testPlanExample);
return testPlanMapper.selectByExample(testPlanExample1);
}
}

View File

@ -0,0 +1,55 @@
alter table test_plan add project_id varchar(50) null comment '测试计划所属项目';
DROP PROCEDURE IF EXISTS test_cursor;
DELIMITER //
CREATE PROCEDURE test_cursor()
BEGIN
DECLARE planId VARCHAR(64);
DECLARE done INT DEFAULT 0;
DECLARE cursor1 CURSOR FOR (SELECT id
FROM test_plan
WHERE project_id IS NULL);
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN cursor1;
outer_loop:
LOOP
FETCH cursor1 INTO planId;
IF done
THEN
LEAVE outer_loop;
END IF;
select count(1) as s, project_id
into @num, @projectId
from test_plan_test_case
join test_case on case_id = test_case.id
where plan_id = planId
group by project_id
order by s desc
limit 1;
IF @projectId = ''
THEN
select test_plan_project.project_id
into @projectId
from test_plan
join test_plan_project on test_plan.id = test_plan_project.test_plan_id
where test_plan.id = planId
limit 1;
END IF;
UPDATE test_plan SET test_plan.project_id = @projectId WHERE test_plan.id = planId;
DELETE FROM test_plan_project
WHERE test_plan_project.project_id = @projectId
AND test_plan_project.test_plan_id = planId;
SET @projectId = '';
SET done = 0;
END LOOP;
CLOSE cursor1;
END //
DELIMITER ;
CALL test_cursor();
DROP PROCEDURE IF EXISTS test_cursor;

View File

@ -21,10 +21,10 @@
</el-col>
<el-col :span="11" :offset="2">
<el-form-item :label="$t('test_track.plan.plan_project')" :label-width="formLabelWidth" prop="projectIds">
<el-form-item :label="$t('test_track.plan.related_project')" :label-width="formLabelWidth" prop="projectIds">
<el-select
v-model="form.projectIds"
:placeholder="$t('test_track.plan.input_plan_project')"
:placeholder="$t('test_track.plan.input_related_project')"
multiple
style="width: 100%"
filterable>
@ -134,7 +134,7 @@
import {WORKSPACE_ID} from '@/common/js/constants';
import TestPlanStatusButton from "../common/TestPlanStatusButton";
import {listenGoBack, removeGoBackListener} from "@/common/js/utils";
import {getCurrentProjectID, listenGoBack, removeGoBackListener} from "@/common/js/utils";
import {LIST_CHANGE, TrackEvent} from "@/business/components/common/head/ListEvent";
export default {
@ -158,7 +158,7 @@ export default {
{required: true, message: this.$t('test_track.plan.input_plan_name'), trigger: 'blur'},
{max: 30, message: this.$t('test_track.length_less_than') + '30', trigger: 'blur'}
],
projectIds: [{required: true, message: this.$t('test_track.plan.input_plan_project'), trigger: 'change'}],
// projectIds: [{required: true, message: this.$t('test_track.plan.input_plan_project'), trigger: 'change'}],
principal: [{required: true, message: this.$t('test_track.plan.input_plan_principal'), trigger: 'change'}],
stage: [{required: true, message: this.$t('test_track.plan.input_plan_stage'), trigger: 'change'}],
description: [{max: 200, message: this.$t('test_track.length_less_than') + '200', trigger: 'blur'}]
@ -248,7 +248,7 @@ export default {
getProjects() {
this.$get("/project/listAll", (response) => {
if (response.success) {
this.projects = response.data;
this.projects = response.data.filter(da => da.id !== getCurrentProjectID());
} else {
this.$warning()(response.message);
}

View File

@ -228,9 +228,7 @@ export default {
let path = "/test/plan/project";
this.$post(path,{planId: this.tableData[i].id}, res => {
let arr = res.data;
let projectName = arr.map(data => data.name).join("、");
let projectIds = arr.map(data => data.id);
this.$set(this.tableData[i], "projectName", projectName);
let projectIds = arr.filter(d => d.id !== this.tableData[i].projectId).map(data => data.id);
this.$set(this.tableData[i], "projectIds", projectIds);
})
}

View File

@ -1053,6 +1053,7 @@ export default {
edit_plan: "Edit test plan",
plan_name: "Test plan name",
plan_project: "Project",
related_project: "Related Project",
plan_stage: "Stage",
plan_status: "Status",
smoke_test: "Smoke test",
@ -1065,6 +1066,7 @@ export default {
input_plan_name: "Please input plan name",
input_plan_principal: "Please select principal",
input_plan_project: "Please select project",
input_related_project: "Please Related project",
input_plan_stage: "Please select stage",
plan_status_prepare: "Not started",
plan_status_running: "Starting",

View File

@ -1054,6 +1054,7 @@ export default {
edit_plan: "编辑测试计划",
plan_name: "计划名称",
plan_project: "所属项目",
related_project: "关联项目",
plan_stage: "测试阶段",
plan_status: "当前状态",
smoke_test: "冒烟测试",
@ -1066,6 +1067,7 @@ export default {
input_plan_name: "请输入测试计划名称",
input_plan_principal: "请选择负责人",
input_plan_project: "请选择所属项目",
input_related_project: "请选择关联项目",
input_plan_stage: "请选择测试阶段",
plan_status_prepare: "未开始",
plan_status_running: "进行中",

View File

@ -1053,6 +1053,7 @@ export default {
edit_plan: "編輯測試計劃",
plan_name: "計劃名稱",
plan_project: "所屬項目",
related_project: "關聯項目",
plan_stage: "測試階段",
plan_status: "當前狀態",
smoke_test: "冒煙測試",
@ -1065,6 +1066,7 @@ export default {
input_plan_name: "請輸入測試計劃名稱",
input_plan_principal: "請選擇負責人",
input_plan_project: "請選擇所屬項目",
input_related_project: "請選擇關聯項目",
input_plan_stage: "請選擇測試階段",
plan_status_prepare: "未開始",
plan_status_running: "進行中",