feat(接口自动化): 场景ID自定义

This commit is contained in:
shiziyuan9527 2021-05-06 18:06:55 +08:00 committed by 刘瑞斌
parent 345b5d678a
commit a471f3c806
19 changed files with 301 additions and 29 deletions

View File

@ -54,4 +54,6 @@ public class SaveApiScenarioRequest {
private List<String> unSelectIds;
private String customNum;
}

View File

@ -43,6 +43,7 @@ import io.metersphere.track.request.testcase.QueryTestPlanRequest;
import io.metersphere.track.request.testplan.FileOperationRequest;
import io.metersphere.track.service.TestPlanScenarioCaseService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
@ -112,6 +113,8 @@ public class ApiAutomationService {
private SystemParameterService systemParameterService;
@Resource
private ApiScenarioReportService apiScenarioReportService;
@Resource
private ProjectMapper projectMapper;
public ApiScenarioWithBLOBs getDto(String id) {
return apiScenarioMapper.selectByPrimaryKey(id);
@ -225,7 +228,7 @@ public class ApiAutomationService {
public ApiScenario create(SaveApiScenarioRequest request, List<MultipartFile> bodyFiles) {
request.setId(UUID.randomUUID().toString());
checkNameExist(request);
checkScenarioNum(request);
final ApiScenarioWithBLOBs scenario = buildSaveScenario(request);
scenario.setCreateTime(System.currentTimeMillis());
@ -241,6 +244,34 @@ public class ApiAutomationService {
return scenario;
}
private void checkScenarioNum(SaveApiScenarioRequest request) {
if (StringUtils.isNotBlank(request.getCustomNum())) {
String projectId = request.getProjectId();
Project project = projectMapper.selectByPrimaryKey(projectId);
if (project != null) {
Boolean customNum = project.getCustomNum();
// 未开启自定义ID
if (!customNum) {
request.setCustomNum(null);
} else {
checkCustomNumExist(request);
}
} else {
MSException.throwException("add scenario fail, project is not find.");
}
}
}
private void checkCustomNumExist(SaveApiScenarioRequest request) {
ApiScenarioExample example = new ApiScenarioExample();
example.createCriteria().andCustomNumEqualTo(request.getCustomNum())
.andIdNotEqualTo(request.getId());
List<ApiScenario> list = apiScenarioMapper.selectByExample(example);
if (CollectionUtils.isNotEmpty(list)) {
MSException.throwException("自定义ID已存在");
}
}
private int getNextNum(String projectId) {
ApiScenario apiScenario = extApiScenarioMapper.getNextNum(projectId);
if (apiScenario == null) {
@ -252,6 +283,7 @@ public class ApiAutomationService {
public void update(SaveApiScenarioRequest request, List<MultipartFile> bodyFiles) {
checkNameExist(request);
checkScenarioNum(request);
List<String> bodyUploadIds = request.getBodyUploadIds();
FileUtils.createBodyFiles(bodyUploadIds, bodyFiles);
@ -268,6 +300,7 @@ public class ApiAutomationService {
scenario.setId(request.getId());
scenario.setName(request.getName());
scenario.setProjectId(request.getProjectId());
scenario.setCustomNum(request.getCustomNum());
if (StringUtils.equals(request.getTags(), "[]")) {
scenario.setTags("");
} else {
@ -1430,8 +1463,10 @@ public class ApiAutomationService {
ApiScenarioMapper batchMapper = sqlSession.getMapper(ApiScenarioMapper.class);
List<ApiScenarioWithBLOBs> data = apiImport.getData();
int num = 0;
Project project = new Project();
if (!CollectionUtils.isEmpty(data) && data.get(0) != null && data.get(0).getProjectId() != null) {
num = getNextNum(data.get(0).getProjectId());
project = projectMapper.selectByPrimaryKey(data.get(0).getProjectId());
}
for (int i = 0; i < data.size(); i++) {
ApiScenarioWithBLOBs item = data.get(i);
@ -1439,6 +1474,9 @@ public class ApiAutomationService {
item.setName(item.getName().substring(0, 255));
}
item.setNum(num++);
if (BooleanUtils.isTrue(project.getScenarioCustomNum())) {
item.setCustomNum(String.valueOf(num));
}
importCreate(item, batchMapper, request);
if (i % 300 == 0) {
sqlSession.flushStatements();
@ -1715,4 +1753,8 @@ public class ApiAutomationService {
}
return returnList;
}
public void updateCustomNumByProjectId(String id) {
extApiScenarioMapper.updateCustomNumByProjectId(id);
}
}

View File

@ -45,5 +45,7 @@ public class ApiScenario implements Serializable {
private String originalState;
private String customNum;
private static final long serialVersionUID = 1L;
}

View File

@ -1463,6 +1463,76 @@ public class ApiScenarioExample {
addCriterion("original_state not between", value1, value2, "originalState");
return (Criteria) this;
}
public Criteria andCustomNumIsNull() {
addCriterion("custom_num is null");
return (Criteria) this;
}
public Criteria andCustomNumIsNotNull() {
addCriterion("custom_num is not null");
return (Criteria) this;
}
public Criteria andCustomNumEqualTo(String value) {
addCriterion("custom_num =", value, "customNum");
return (Criteria) this;
}
public Criteria andCustomNumNotEqualTo(String value) {
addCriterion("custom_num <>", value, "customNum");
return (Criteria) this;
}
public Criteria andCustomNumGreaterThan(String value) {
addCriterion("custom_num >", value, "customNum");
return (Criteria) this;
}
public Criteria andCustomNumGreaterThanOrEqualTo(String value) {
addCriterion("custom_num >=", value, "customNum");
return (Criteria) this;
}
public Criteria andCustomNumLessThan(String value) {
addCriterion("custom_num <", value, "customNum");
return (Criteria) this;
}
public Criteria andCustomNumLessThanOrEqualTo(String value) {
addCriterion("custom_num <=", value, "customNum");
return (Criteria) this;
}
public Criteria andCustomNumLike(String value) {
addCriterion("custom_num like", value, "customNum");
return (Criteria) this;
}
public Criteria andCustomNumNotLike(String value) {
addCriterion("custom_num not like", value, "customNum");
return (Criteria) this;
}
public Criteria andCustomNumIn(List<String> values) {
addCriterion("custom_num in", values, "customNum");
return (Criteria) this;
}
public Criteria andCustomNumNotIn(List<String> values) {
addCriterion("custom_num not in", values, "customNum");
return (Criteria) this;
}
public Criteria andCustomNumBetween(String value1, String value2) {
addCriterion("custom_num between", value1, value2, "customNum");
return (Criteria) this;
}
public Criteria andCustomNumNotBetween(String value1, String value2) {
addCriterion("custom_num not between", value1, value2, "customNum");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {

View File

@ -31,6 +31,8 @@ public class Project implements Serializable {
private Boolean customNum;
private Boolean scenarioCustomNum;
private static final long serialVersionUID = 1L;
private String protocal;

View File

@ -973,6 +973,66 @@ public class ProjectExample {
addCriterion("custom_num not between", value1, value2, "customNum");
return (Criteria) this;
}
public Criteria andScenarioCustomNumIsNull() {
addCriterion("scenario_custom_num is null");
return (Criteria) this;
}
public Criteria andScenarioCustomNumIsNotNull() {
addCriterion("scenario_custom_num is not null");
return (Criteria) this;
}
public Criteria andScenarioCustomNumEqualTo(Boolean value) {
addCriterion("scenario_custom_num =", value, "scenarioCustomNum");
return (Criteria) this;
}
public Criteria andScenarioCustomNumNotEqualTo(Boolean value) {
addCriterion("scenario_custom_num <>", value, "scenarioCustomNum");
return (Criteria) this;
}
public Criteria andScenarioCustomNumGreaterThan(Boolean value) {
addCriterion("scenario_custom_num >", value, "scenarioCustomNum");
return (Criteria) this;
}
public Criteria andScenarioCustomNumGreaterThanOrEqualTo(Boolean value) {
addCriterion("scenario_custom_num >=", value, "scenarioCustomNum");
return (Criteria) this;
}
public Criteria andScenarioCustomNumLessThan(Boolean value) {
addCriterion("scenario_custom_num <", value, "scenarioCustomNum");
return (Criteria) this;
}
public Criteria andScenarioCustomNumLessThanOrEqualTo(Boolean value) {
addCriterion("scenario_custom_num <=", value, "scenarioCustomNum");
return (Criteria) this;
}
public Criteria andScenarioCustomNumIn(List<Boolean> values) {
addCriterion("scenario_custom_num in", values, "scenarioCustomNum");
return (Criteria) this;
}
public Criteria andScenarioCustomNumNotIn(List<Boolean> values) {
addCriterion("scenario_custom_num not in", values, "scenarioCustomNum");
return (Criteria) this;
}
public Criteria andScenarioCustomNumBetween(Boolean value1, Boolean value2) {
addCriterion("scenario_custom_num between", value1, value2, "scenarioCustomNum");
return (Criteria) this;
}
public Criteria andScenarioCustomNumNotBetween(Boolean value1, Boolean value2) {
addCriterion("scenario_custom_num not between", value1, value2, "scenarioCustomNum");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {

View File

@ -22,6 +22,7 @@
<result column="report_id" jdbcType="VARCHAR" property="reportId" />
<result column="num" jdbcType="INTEGER" property="num" />
<result column="original_state" jdbcType="VARCHAR" property="originalState" />
<result column="custom_num" jdbcType="VARCHAR" property="customNum" />
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.base.domain.ApiScenarioWithBLOBs">
<result column="scenario_definition" jdbcType="LONGVARCHAR" property="scenarioDefinition" />
@ -88,7 +89,7 @@
<sql id="Base_Column_List">
id, project_id, tags, user_id, api_scenario_module_id, module_path, `name`, `level`,
`status`, principal, step_total, follow_people, schedule, create_time, update_time,
pass_rate, last_result, report_id, num, original_state
pass_rate, last_result, report_id, num, original_state, custom_num
</sql>
<sql id="Blob_Column_List">
scenario_definition, description
@ -148,16 +149,18 @@
principal, step_total, follow_people,
schedule, create_time, update_time,
pass_rate, last_result, report_id,
num, original_state, scenario_definition,
description)
num, original_state, custom_num,
scenario_definition, description
)
values (#{id,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{tags,jdbcType=VARCHAR},
#{userId,jdbcType=VARCHAR}, #{apiScenarioModuleId,jdbcType=VARCHAR}, #{modulePath,jdbcType=VARCHAR},
#{name,jdbcType=VARCHAR}, #{level,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR},
#{principal,jdbcType=VARCHAR}, #{stepTotal,jdbcType=INTEGER}, #{followPeople,jdbcType=VARCHAR},
#{schedule,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT},
#{passRate,jdbcType=VARCHAR}, #{lastResult,jdbcType=VARCHAR}, #{reportId,jdbcType=VARCHAR},
#{num,jdbcType=INTEGER}, #{originalState,jdbcType=VARCHAR}, #{scenarioDefinition,jdbcType=LONGVARCHAR},
#{description,jdbcType=LONGVARCHAR})
#{num,jdbcType=INTEGER}, #{originalState,jdbcType=VARCHAR}, #{customNum,jdbcType=VARCHAR},
#{scenarioDefinition,jdbcType=LONGVARCHAR}, #{description,jdbcType=LONGVARCHAR}
)
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.ApiScenarioWithBLOBs">
insert into api_scenario
@ -222,6 +225,9 @@
<if test="originalState != null">
original_state,
</if>
<if test="customNum != null">
custom_num,
</if>
<if test="scenarioDefinition != null">
scenario_definition,
</if>
@ -290,6 +296,9 @@
<if test="originalState != null">
#{originalState,jdbcType=VARCHAR},
</if>
<if test="customNum != null">
#{customNum,jdbcType=VARCHAR},
</if>
<if test="scenarioDefinition != null">
#{scenarioDefinition,jdbcType=LONGVARCHAR},
</if>
@ -367,6 +376,9 @@
<if test="record.originalState != null">
original_state = #{record.originalState,jdbcType=VARCHAR},
</if>
<if test="record.customNum != null">
custom_num = #{record.customNum,jdbcType=VARCHAR},
</if>
<if test="record.scenarioDefinition != null">
scenario_definition = #{record.scenarioDefinition,jdbcType=LONGVARCHAR},
</if>
@ -400,6 +412,7 @@
report_id = #{record.reportId,jdbcType=VARCHAR},
num = #{record.num,jdbcType=INTEGER},
original_state = #{record.originalState,jdbcType=VARCHAR},
custom_num = #{record.customNum,jdbcType=VARCHAR},
scenario_definition = #{record.scenarioDefinition,jdbcType=LONGVARCHAR},
description = #{record.description,jdbcType=LONGVARCHAR}
<if test="_parameter != null">
@ -427,7 +440,8 @@
last_result = #{record.lastResult,jdbcType=VARCHAR},
report_id = #{record.reportId,jdbcType=VARCHAR},
num = #{record.num,jdbcType=INTEGER},
original_state = #{record.originalState,jdbcType=VARCHAR}
original_state = #{record.originalState,jdbcType=VARCHAR},
custom_num = #{record.customNum,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -492,6 +506,9 @@
<if test="originalState != null">
original_state = #{originalState,jdbcType=VARCHAR},
</if>
<if test="customNum != null">
custom_num = #{customNum,jdbcType=VARCHAR},
</if>
<if test="scenarioDefinition != null">
scenario_definition = #{scenarioDefinition,jdbcType=LONGVARCHAR},
</if>
@ -522,6 +539,7 @@
report_id = #{reportId,jdbcType=VARCHAR},
num = #{num,jdbcType=INTEGER},
original_state = #{originalState,jdbcType=VARCHAR},
custom_num = #{customNum,jdbcType=VARCHAR},
scenario_definition = #{scenarioDefinition,jdbcType=LONGVARCHAR},
description = #{description,jdbcType=LONGVARCHAR}
where id = #{id,jdbcType=VARCHAR}
@ -546,7 +564,8 @@
last_result = #{lastResult,jdbcType=VARCHAR},
report_id = #{reportId,jdbcType=VARCHAR},
num = #{num,jdbcType=INTEGER},
original_state = #{originalState,jdbcType=VARCHAR}
original_state = #{originalState,jdbcType=VARCHAR},
custom_num = #{customNum,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper>

View File

@ -15,6 +15,7 @@
<result column="case_template_id" jdbcType="VARCHAR" property="caseTemplateId" />
<result column="issue_template_id" jdbcType="VARCHAR" property="issueTemplateId" />
<result column="custom_num" jdbcType="BIT" property="customNum" />
<result column="scenario_custom_num" jdbcType="BIT" property="scenarioCustomNum" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
@ -76,7 +77,7 @@
</sql>
<sql id="Base_Column_List">
id, workspace_id, `name`, description, create_time, update_time, tapd_id, jira_key,
zentao_id, `repeatable`, case_template_id, issue_template_id, custom_num
zentao_id, `repeatable`, case_template_id, issue_template_id, custom_num, scenario_custom_num
</sql>
<select id="selectByExample" parameterType="io.metersphere.base.domain.ProjectExample" resultMap="BaseResultMap">
select
@ -113,12 +114,12 @@
description, create_time, update_time,
tapd_id, jira_key, zentao_id,
`repeatable`, case_template_id, issue_template_id,
custom_num)
custom_num, scenario_custom_num)
values (#{id,jdbcType=VARCHAR}, #{workspaceId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
#{description,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT},
#{tapdId,jdbcType=VARCHAR}, #{jiraKey,jdbcType=VARCHAR}, #{zentaoId,jdbcType=VARCHAR},
#{repeatable,jdbcType=BIT}, #{caseTemplateId,jdbcType=VARCHAR}, #{issueTemplateId,jdbcType=VARCHAR},
#{customNum,jdbcType=BIT})
#{customNum,jdbcType=BIT}, #{scenarioCustomNum,jdbcType=BIT})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.Project">
insert into project
@ -162,6 +163,9 @@
<if test="customNum != null">
custom_num,
</if>
<if test="scenarioCustomNum != null">
scenario_custom_num,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
@ -203,6 +207,9 @@
<if test="customNum != null">
#{customNum,jdbcType=BIT},
</if>
<if test="scenarioCustomNum != null">
#{scenarioCustomNum,jdbcType=BIT},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="io.metersphere.base.domain.ProjectExample" resultType="java.lang.Long">
@ -253,6 +260,9 @@
<if test="record.customNum != null">
custom_num = #{record.customNum,jdbcType=BIT},
</if>
<if test="record.scenarioCustomNum != null">
scenario_custom_num = #{record.scenarioCustomNum,jdbcType=BIT},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
@ -272,7 +282,8 @@
`repeatable` = #{record.repeatable,jdbcType=BIT},
case_template_id = #{record.caseTemplateId,jdbcType=VARCHAR},
issue_template_id = #{record.issueTemplateId,jdbcType=VARCHAR},
custom_num = #{record.customNum,jdbcType=BIT}
custom_num = #{record.customNum,jdbcType=BIT},
scenario_custom_num = #{record.scenarioCustomNum,jdbcType=BIT}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -316,6 +327,9 @@
<if test="customNum != null">
custom_num = #{customNum,jdbcType=BIT},
</if>
<if test="scenarioCustomNum != null">
scenario_custom_num = #{scenarioCustomNum,jdbcType=BIT},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
@ -332,7 +346,8 @@
`repeatable` = #{repeatable,jdbcType=BIT},
case_template_id = #{caseTemplateId,jdbcType=VARCHAR},
issue_template_id = #{issueTemplateId,jdbcType=VARCHAR},
custom_num = #{customNum,jdbcType=BIT}
custom_num = #{customNum,jdbcType=BIT},
scenario_custom_num = #{scenarioCustomNum,jdbcType=BIT}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper>

View File

@ -41,4 +41,6 @@ public interface ExtApiScenarioMapper {
ApiScenario getNextNum(@Param("projectId") String projectId);
List<String> selectIdsByQuery(@Param("request") ApiScenarioRequest request);
void updateCustomNumByProjectId(@Param("projectId") String projectId);
}

View File

@ -133,7 +133,7 @@
</sql>
<select id="list" resultMap="BaseResultMap">
select api_scenario.id, api_scenario.project_id, api_scenario.tags, api_scenario.user_id, api_scenario.num,
select api_scenario.id, api_scenario.project_id, api_scenario.tags, api_scenario.user_id, api_scenario.num, api_scenario.custom_num,
api_scenario.api_scenario_module_id,api_scenario.module_path, api_scenario.name, api_scenario.level,
api_scenario.status, api_scenario.principal, api_scenario.step_total, api_scenario.follow_people,
api_scenario.last_result,api_scenario.pass_rate,api_scenario.report_id,
@ -159,7 +159,8 @@
<if test="request.name != null">
and (api_scenario.name like CONCAT('%', #{request.name},'%')
or api_scenario.tags like CONCAT('%', #{request.name},'%')
or api_scenario.num like CONCAT('%', #{request.name},'%'))
or api_scenario.num like CONCAT('%', #{request.name},'%')
or api_scenario.custom_num like CONCAT('%', #{request.name},'%'))
</if>
<if test="request.workspaceId != null">
AND project.workspace_id = #{request.workspaceId}
@ -304,6 +305,9 @@
#{v}
</foreach>
</update>
<update id="updateCustomNumByProjectId">
update api_scenario set custom_num = num where (custom_num is null or custom_num = '') and project_id = #{projectId}
</update>
<select id="countByProjectID" resultType="java.lang.Long">
SELECT COUNT(id) AS countNumber FROM api_scenario WHERE project_id = #{0} AND status != 'Trash'

View File

@ -4,7 +4,8 @@
<select id="getProjectWithWorkspace" resultType="io.metersphere.dto.ProjectDTO">
select p.id, p.workspace_id, p.name, p.description, p.update_time, p.issue_template_id, p.case_template_id,
p.create_time, w.id as workspaceId, w.name as workspaceName, p.tapd_id, p.jira_key, p.zentao_id,p.repeatable, p.custom_num
p.create_time, w.id as workspaceId, w.name as workspaceName, p.tapd_id, p.jira_key, p.zentao_id,p.repeatable, p.custom_num,
p.scenario_custom_num
from project p
join workspace w on p.workspace_id = w.id
<where>

View File

@ -18,9 +18,9 @@
<select id="list" resultType="io.metersphere.api.dto.automation.ApiScenarioDTO">
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.project_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.num,
p.name as project_name, p.id as project_id, u.name as user_name
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,
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
inner join
@ -46,6 +46,7 @@
<if test="request.name != null and request.name!=''">
and (c.name like CONCAT('%', #{request.name},'%')
or c.num like CONCAT('%', #{request.name},'%')
or c.custom_num like CONCAT('%', #{request.name},'%')
or c.tags like CONCAT('%', #{request.name},'%'))
</if>
<if test="request.status != null and request.status!=''">

View File

@ -3,11 +3,9 @@ package io.metersphere.service;
import io.metersphere.api.dto.DeleteAPITestRequest;
import io.metersphere.api.dto.QueryAPITestRequest;
import io.metersphere.api.service.APITestService;
import io.metersphere.api.service.ApiAutomationService;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.ApiTestFileMapper;
import io.metersphere.base.mapper.LoadTestFileMapper;
import io.metersphere.base.mapper.LoadTestMapper;
import io.metersphere.base.mapper.ProjectMapper;
import io.metersphere.base.mapper.*;
import io.metersphere.base.mapper.ext.ExtProjectMapper;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.ServiceUtils;
@ -21,6 +19,7 @@ import io.metersphere.performance.service.PerformanceTestService;
import io.metersphere.track.service.TestCaseService;
import io.metersphere.track.service.TestPlanProjectService;
import io.metersphere.track.service.TestPlanService;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -59,6 +58,8 @@ public class ProjectService {
private LoadTestFileMapper loadTestFileMapper;
@Resource
private ApiTestFileMapper apiTestFileMapper;
@Resource
private ApiAutomationService apiAutomationService;
public Project addProject(Project project) {
if (StringUtils.isBlank(project.getName())) {
@ -145,9 +146,12 @@ public class ProjectService {
project.setCreateTime(null);
project.setUpdateTime(System.currentTimeMillis());
checkProjectExist(project);
if (project.getCustomNum()) {
if (BooleanUtils.isTrue(project.getCustomNum())) {
testCaseService.updateTestCaseCustomNumByProjectId(project.getId());
}
if (BooleanUtils.isTrue(project.getScenarioCustomNum())) {
apiAutomationService.updateCustomNumByProjectId(project.getId());
}
projectMapper.updateByPrimaryKeySelective(project);
}

View File

@ -1 +1,4 @@
ALTER TABLE api_scenario_report MODIFY COLUMN scenario_name VARCHAR(3000);
ALTER TABLE api_scenario_report MODIFY COLUMN scenario_name VARCHAR(3000);
alter table project add scenario_custom_num tinyint(1) default 0 null comment '是否开启场景自定义ID(默认关闭)';
alter table api_scenario add custom_num varchar(64) null comment 'custom num';

View File

@ -30,6 +30,7 @@
@openScenario="editScenario"
@edit="editScenario"
@changeSelectDataRangeAll="changeSelectDataRangeAll"
:custom-num="customNum"
ref="apiScenarioList"/>
</el-tab-pane>
@ -41,7 +42,7 @@
closable>
<div class="ms-api-scenario-div">
<ms-edit-api-scenario @refresh="refresh" @openScenario="editScenario" @closePage="closePage" :currentScenario="item.currentScenario"
:moduleOptions="moduleOptions" ref="autoScenarioConfig"/>
:custom-num="customNum" :moduleOptions="moduleOptions" ref="autoScenarioConfig"/>
</div>
</el-tab-pane>
@ -116,8 +117,12 @@
selectNodeIds: [],
nodeTree: [],
currentModulePath: "",
customNum: false
}
},
mounted() {
this.getProject();
},
watch: {
redirectID() {
this.renderComponent = false;
@ -335,6 +340,14 @@
},
enableTrash(data) {
this.trashEnable = data;
},
getProject() {
this.$get("/project/get/" + this.projectId, result => {
let data = result.data;
if (data) {
this.customNum = data.scenarioCustomNum;
}
})
}
}
}

View File

@ -29,7 +29,7 @@
</template>
</el-table-column>
<template v-for="(item, index) in tableLabel">
<el-table-column v-if="item.id == 'num'" prop="num" label="ID"
<el-table-column v-if="item.id == 'num' && !customNum" prop="num" label="ID"
sortable="custom"
min-width="120px"
show-overflow-tooltip :key="index">
@ -40,6 +40,17 @@
</el-tooltip>
</template>
</el-table-column>
<el-table-column v-if="item.id == 'num' && customNum" prop="customNum" label="ID"
sortable="custom"
min-width="120px"
show-overflow-tooltip :key="index">
<template slot-scope="scope">
<span style="cursor:pointer" v-if="isReadOnly"> {{ scope.row.customNum }} </span>
<el-tooltip v-else content="编辑">
<a style="cursor:pointer" @click="edit(scope.row)"> {{ scope.row.customNum }} </a>
</el-tooltip>
</template>
</el-table-column>
<el-table-column v-if="item.id == 'name'" prop="name"
sortable="custom"
:label="$t('api_test.automation.scenario_name')"
@ -247,6 +258,10 @@
isReadOnly: {
type: Boolean,
default: false,
},
customNum: {
type: Boolean,
default: false
}
},
data() {
@ -709,6 +724,7 @@
let rowParam = JSON.parse(JSON.stringify(row));
rowParam.copy = true;
rowParam.name = 'copy_' + rowParam.name;
rowParam.customNum = '';
this.$emit('edit', rowParam);
},
showReport(row) {

View File

@ -85,6 +85,11 @@
:rows="2" size="small"/>
</el-form-item>
</el-col>
<el-col :span="7" v-if="customNum">
<el-form-item label="ID" prop="customNum">
<el-input v-model="currentScenario.customNum" size="small"></el-input>
</el-form-item>
</el-col>
</el-row>
</el-form>
@ -262,7 +267,11 @@
props: {
moduleOptions: Array,
currentScenario: {},
type: String
type: String,
customNum: {
type: Boolean,
default: false
}
},
components: {
MsVariableList,
@ -299,6 +308,10 @@
apiScenarioModuleId: [{required: true, message: this.$t('test_track.case.input_module'), trigger: 'change'}],
status: [{required: true, message: this.$t('commons.please_select'), trigger: 'change'}],
principal: [{required: true, message: this.$t('api_test.definition.request.responsible'), trigger: 'change'}],
customNum: [
{required: true, message: "ID必填", trigger: 'blur'},
{max: 50, message: this.$t('test_track.length_less_than') + '50', trigger: 'blur'}
],
},
environments: [],
currentEnvironmentId: "",

View File

@ -87,6 +87,9 @@
<el-form-item label="测试用例自定义ID" prop="customNum">
<el-switch v-model="form.customNum"></el-switch>
</el-form-item>
<el-form-item label="场景自定义ID" prop="scenarioCustomNum">
<el-switch v-model="form.scenarioCustomNum"></el-switch>
</el-form-item>
</el-form>
<template v-slot:footer>
<div class="dialog-footer">

View File

@ -25,7 +25,7 @@
<template v-for="(item, index) in tableLabel">
<el-table-column
v-if="item.id == 'num'"
prop="num"
prop="customNum"
min-width="80px"
label="ID"
:key="index"/>