refactor: 接口用例关注人多选

This commit is contained in:
CaptainB 2021-10-23 15:33:56 +08:00 committed by 刘瑞斌
parent 4e5807687a
commit 0b8bd15baa
8 changed files with 67 additions and 103 deletions

View File

@ -204,4 +204,9 @@ public class ApiTestCaseController {
return apiTestCaseService.getExecResult(id);
}
@GetMapping("follow/{testId}")
public List<String> getFollows(@PathVariable String testId) {
return apiTestCaseService.getFollows(testId);
}
}

View File

@ -21,6 +21,8 @@ public class SaveApiTestCaseRequest extends ApiTestCase {
private List<String> bodyUploadIds;
private List<String> follows;
//ESB参数 可为null
private String esbDataStruct;
private String backEsbDataStruct;

View File

@ -99,6 +99,8 @@ public class ApiTestCaseService {
private ExtTestPlanApiCaseMapper extTestPlanApiCaseMapper;
@Resource
private ApiTestEnvironmentMapper apiTestEnvironmentMapper;
@Resource
private ApiTestCaseFollowMapper apiTestCaseFollowMapper;
private static final String BODY_FILE_DIR = FileUtils.BODY_FILE_DIR;
@ -349,17 +351,32 @@ public class ApiTestCaseService {
test.setUpdateTime(System.currentTimeMillis());
test.setDescription(request.getDescription());
test.setVersion(request.getVersion() == null ? 0 : request.getVersion() + 1);
test.setFollowPeople(request.getFollowPeople());
if (StringUtils.equals("[]", request.getTags())) {
test.setTags("");
} else {
test.setTags(request.getTags());
}
apiTestCaseMapper.updateByPrimaryKeySelective(test);
saveFollows(test.getId(), request.getFollows());
}
return test;
}
private void saveFollows(String testId, List<String> follows) {
ApiTestCaseFollowExample example = new ApiTestCaseFollowExample();
example.createCriteria().andCaseIdEqualTo(testId);
apiTestCaseFollowMapper.deleteByExample(example);
if (!org.springframework.util.CollectionUtils.isEmpty(follows)) {
for (String follow : follows) {
ApiTestCaseFollow caseFollow = new ApiTestCaseFollow();
caseFollow.setCaseId(testId);
caseFollow.setFollowId(follow);
apiTestCaseFollowMapper.insert(caseFollow);
}
}
}
private ApiTestCase createTest(SaveApiTestCaseRequest request, List<MultipartFile> bodyFiles) {
checkNameExist(request);
FileUtils.createBodyFiles(request.getId(), bodyFiles);
@ -387,7 +404,6 @@ public class ApiTestCaseService {
test.setUpdateTime(System.currentTimeMillis());
test.setDescription(request.getDescription());
test.setNum(getNextNum(request.getApiDefinitionId()));
test.setFollowPeople(request.getFollowPeople());
test.setOrder(ServiceUtils.getNextOrder(request.getProjectId(), extApiTestCaseMapper::getLastOrder));
if (StringUtils.equals("[]", request.getTags())) {
test.setTags("");
@ -397,6 +413,7 @@ public class ApiTestCaseService {
ApiTestCaseWithBLOBs apiTestCaseWithBLOBs = apiTestCaseMapper.selectByPrimaryKey(test.getId());
if (apiTestCaseWithBLOBs == null) {
apiTestCaseMapper.insert(test);
saveFollows(test.getId(), request.getFollows());
}
return test;
}
@ -1130,8 +1147,19 @@ public class ApiTestCaseService {
environmentId = environmentId.substring(1, environmentId.length() - 1);
return apiTestEnvironmentMapper.selectByPrimaryKey(environmentId);
} catch (Exception e) {
LogUtil.error("api case environmentId incorrect parsing. api case id: " + caseId);
LogUtil.error("api case environmentId incorrect parsing. api case id: " + caseId);
}
return null;
}
public List<String> getFollows(String testId) {
List<String> result = new ArrayList<>();
if (StringUtils.isBlank(testId)) {
return result;
}
ApiTestCaseFollowExample example = new ApiTestCaseFollowExample();
example.createCriteria().andCaseIdEqualTo(testId);
List<ApiTestCaseFollow> follows = apiTestCaseFollowMapper.selectByExample(example);
return follows.stream().map(ApiTestCaseFollow::getFollowId).distinct().collect(Collectors.toList());
}
}

View File

@ -1,8 +1,7 @@
package io.metersphere.base.domain;
import lombok.Data;
import java.io.Serializable;
import lombok.Data;
@Data
public class ApiTestCase implements Serializable {
@ -40,8 +39,6 @@ public class ApiTestCase implements Serializable {
private Integer version;
private String followPeople;
private Long order;
private String caseStatus;

View File

@ -1244,76 +1244,6 @@ public class ApiTestCaseExample {
return (Criteria) this;
}
public Criteria andFollowPeopleIsNull() {
addCriterion("follow_people is null");
return (Criteria) this;
}
public Criteria andFollowPeopleIsNotNull() {
addCriterion("follow_people is not null");
return (Criteria) this;
}
public Criteria andFollowPeopleEqualTo(String value) {
addCriterion("follow_people =", value, "followPeople");
return (Criteria) this;
}
public Criteria andFollowPeopleNotEqualTo(String value) {
addCriterion("follow_people <>", value, "followPeople");
return (Criteria) this;
}
public Criteria andFollowPeopleGreaterThan(String value) {
addCriterion("follow_people >", value, "followPeople");
return (Criteria) this;
}
public Criteria andFollowPeopleGreaterThanOrEqualTo(String value) {
addCriterion("follow_people >=", value, "followPeople");
return (Criteria) this;
}
public Criteria andFollowPeopleLessThan(String value) {
addCriterion("follow_people <", value, "followPeople");
return (Criteria) this;
}
public Criteria andFollowPeopleLessThanOrEqualTo(String value) {
addCriterion("follow_people <=", value, "followPeople");
return (Criteria) this;
}
public Criteria andFollowPeopleLike(String value) {
addCriterion("follow_people like", value, "followPeople");
return (Criteria) this;
}
public Criteria andFollowPeopleNotLike(String value) {
addCriterion("follow_people not like", value, "followPeople");
return (Criteria) this;
}
public Criteria andFollowPeopleIn(List<String> values) {
addCriterion("follow_people in", values, "followPeople");
return (Criteria) this;
}
public Criteria andFollowPeopleNotIn(List<String> values) {
addCriterion("follow_people not in", values, "followPeople");
return (Criteria) this;
}
public Criteria andFollowPeopleBetween(String value1, String value2) {
addCriterion("follow_people between", value1, value2, "followPeople");
return (Criteria) this;
}
public Criteria andFollowPeopleNotBetween(String value1, String value2) {
addCriterion("follow_people not between", value1, value2, "followPeople");
return (Criteria) this;
}
public Criteria andOrderIsNull() {
addCriterion("`order` is null");
return (Criteria) this;

View File

@ -19,7 +19,6 @@
<result column="delete_time" jdbcType="BIGINT" property="deleteTime" />
<result column="delete_user_id" jdbcType="VARCHAR" property="deleteUserId" />
<result column="version" jdbcType="INTEGER" property="version" />
<result column="follow_people" jdbcType="VARCHAR" property="followPeople" />
<result column="order" jdbcType="BIGINT" property="order" />
<result column="case_status" jdbcType="VARCHAR" property="caseStatus" />
</resultMap>
@ -88,7 +87,7 @@
<sql id="Base_Column_List">
id, project_id, `name`, priority, api_definition_id, create_user_id, update_user_id,
create_time, update_time, num, tags, last_result_id, `status`, original_status, delete_time,
delete_user_id, version, follow_people, `order`, case_status
delete_user_id, version, `order`, case_status
</sql>
<sql id="Blob_Column_List">
description, request
@ -147,17 +146,17 @@
update_user_id, create_time, update_time,
num, tags, last_result_id,
`status`, original_status, delete_time,
delete_user_id, version, follow_people,
`order`, case_status, description,
request)
delete_user_id, version, `order`,
case_status, description, request
)
values (#{id,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
#{priority,jdbcType=VARCHAR}, #{apiDefinitionId,jdbcType=VARCHAR}, #{createUserId,jdbcType=VARCHAR},
#{updateUserId,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT},
#{num,jdbcType=INTEGER}, #{tags,jdbcType=VARCHAR}, #{lastResultId,jdbcType=VARCHAR},
#{status,jdbcType=VARCHAR}, #{originalStatus,jdbcType=VARCHAR}, #{deleteTime,jdbcType=BIGINT},
#{deleteUserId,jdbcType=VARCHAR}, #{version,jdbcType=INTEGER}, #{followPeople,jdbcType=VARCHAR},
#{order,jdbcType=BIGINT}, #{caseStatus,jdbcType=VARCHAR}, #{description,jdbcType=LONGVARCHAR},
#{request,jdbcType=LONGVARCHAR})
#{deleteUserId,jdbcType=VARCHAR}, #{version,jdbcType=INTEGER}, #{order,jdbcType=BIGINT},
#{caseStatus,jdbcType=VARCHAR}, #{description,jdbcType=LONGVARCHAR}, #{request,jdbcType=LONGVARCHAR}
)
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.ApiTestCaseWithBLOBs">
insert into api_test_case
@ -213,9 +212,6 @@
<if test="version != null">
version,
</if>
<if test="followPeople != null">
follow_people,
</if>
<if test="order != null">
`order`,
</if>
@ -281,9 +277,6 @@
<if test="version != null">
#{version,jdbcType=INTEGER},
</if>
<if test="followPeople != null">
#{followPeople,jdbcType=VARCHAR},
</if>
<if test="order != null">
#{order,jdbcType=BIGINT},
</if>
@ -358,9 +351,6 @@
<if test="record.version != null">
version = #{record.version,jdbcType=INTEGER},
</if>
<if test="record.followPeople != null">
follow_people = #{record.followPeople,jdbcType=VARCHAR},
</if>
<if test="record.order != null">
`order` = #{record.order,jdbcType=BIGINT},
</if>
@ -397,7 +387,6 @@
delete_time = #{record.deleteTime,jdbcType=BIGINT},
delete_user_id = #{record.deleteUserId,jdbcType=VARCHAR},
version = #{record.version,jdbcType=INTEGER},
follow_people = #{record.followPeople,jdbcType=VARCHAR},
`order` = #{record.order,jdbcType=BIGINT},
case_status = #{record.caseStatus,jdbcType=VARCHAR},
description = #{record.description,jdbcType=LONGVARCHAR},
@ -425,7 +414,6 @@
delete_time = #{record.deleteTime,jdbcType=BIGINT},
delete_user_id = #{record.deleteUserId,jdbcType=VARCHAR},
version = #{record.version,jdbcType=INTEGER},
follow_people = #{record.followPeople,jdbcType=VARCHAR},
`order` = #{record.order,jdbcType=BIGINT},
case_status = #{record.caseStatus,jdbcType=VARCHAR}
<if test="_parameter != null">
@ -483,9 +471,6 @@
<if test="version != null">
version = #{version,jdbcType=INTEGER},
</if>
<if test="followPeople != null">
follow_people = #{followPeople,jdbcType=VARCHAR},
</if>
<if test="order != null">
`order` = #{order,jdbcType=BIGINT},
</if>
@ -519,7 +504,6 @@
delete_time = #{deleteTime,jdbcType=BIGINT},
delete_user_id = #{deleteUserId,jdbcType=VARCHAR},
version = #{version,jdbcType=INTEGER},
follow_people = #{followPeople,jdbcType=VARCHAR},
`order` = #{order,jdbcType=BIGINT},
case_status = #{caseStatus,jdbcType=VARCHAR},
description = #{description,jdbcType=LONGVARCHAR},
@ -544,7 +528,6 @@
delete_time = #{deleteTime,jdbcType=BIGINT},
delete_user_id = #{deleteUserId,jdbcType=VARCHAR},
version = #{version,jdbcType=INTEGER},
follow_people = #{followPeople,jdbcType=VARCHAR},
`order` = #{order,jdbcType=BIGINT},
case_status = #{caseStatus,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR}

View File

@ -381,4 +381,19 @@ INSERT INTO api_definition_follow
SELECT id, follow_people
FROM api_definition
WHERE follow_people IS NOT NULL;
ALTER TABLE api_definition DROP COLUMN follow_people;
ALTER TABLE api_definition DROP COLUMN follow_people;
-- 接口定义关注人
CREATE TABLE IF NOT EXISTS `api_test_case_follow`
(
`case_id` VARCHAR(50) DEFAULT NULL,
`follow_id` VARCHAR(50) DEFAULT NULL,
UNIQUE KEY `api_case_follow_scenario_id_follow_id_pk` (`case_id`, `follow_id`),
KEY `api_case_follow_id_index` (`follow_id`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci;
-- 接口定义数据迁移
INSERT INTO api_test_case_follow
SELECT id, follow_people
FROM api_test_case
WHERE follow_people IS NOT NULL;
ALTER TABLE api_test_case DROP COLUMN follow_people;

View File

@ -63,7 +63,8 @@
</el-col>
<el-col :span="16">
<div class="tag-item" @click.stop>
<el-select v-model="apiCase.followPeople" clearable :placeholder="$t('api_test.automation.follow_people')" filterable size="small"
<el-select v-model="apiCase.follows" multiple clearable
:placeholder="$t('api_test.automation.follow_people')" filterable size="small"
@change="saveTestCase(apiCase,true)" style="width: 100%">
<el-option
v-for="item in maintainerOptions"
@ -279,6 +280,9 @@ export default {
if (requireComponent != null && JSON.stringify(esbDefinition) != '{}' && JSON.stringify(esbDefinitionResponse) != '{}') {
this.showXpackCompnent = true;
}
this.$get('/api/testcase/follow/' + this.apiCase.id, response => {
this.apiCase.follows = response.data;
});
},
watch: {
'apiCase.selected'() {