refactor: 自动化关注人多选

This commit is contained in:
CaptainB 2021-10-23 14:37:31 +08:00 committed by 刘瑞斌
parent 2610b0c573
commit 219ccc7c4b
11 changed files with 78 additions and 121 deletions

View File

@ -359,6 +359,9 @@ public class ApiAutomationController {
return apiAutomationService.checkScenarioEnv(request);
}
@GetMapping("/follow/{scenarioId}")
public List<String> getFollows(@PathVariable String scenarioId) {
return apiAutomationService.getFollows(scenarioId);
}
}

View File

@ -34,7 +34,7 @@ public class SaveApiScenarioRequest {
private Integer stepTotal;
private String followPeople;
private List<String> follows;
private String schedule;

View File

@ -142,6 +142,8 @@ public class ApiAutomationService {
private ExtTestPlanScenarioCaseMapper extTestPlanScenarioCaseMapper;
@Resource
private RelationshipEdgeService relationshipEdgeService;
@Resource
private ApiScenarioFollowMapper apiScenarioFollowMapper;
private ThreadLocal<Long> currentScenarioOrder = new ThreadLocal<>();
@ -355,7 +357,7 @@ public class ApiAutomationService {
scenario.setVersion(version + 1);
}
deleteUpdateBodyFile(scenario,beforeScenario);
deleteUpdateBodyFile(scenario, beforeScenario);
List<ApiMethodUrlDTO> useUrl = this.parseUrl(scenario);
scenario.setUseUrl(JSONArray.toJSONString(useUrl));
apiScenarioMapper.updateByPrimaryKeySelective(scenario);
@ -376,7 +378,7 @@ public class ApiAutomationService {
*
* @param scenario
*/
public void deleteUpdateBodyFile(ApiScenarioWithBLOBs scenario,ApiScenarioWithBLOBs oldScenario) {
public void deleteUpdateBodyFile(ApiScenarioWithBLOBs scenario, ApiScenarioWithBLOBs oldScenario) {
Set<String> newRequestIds = getRequestIds(scenario.getScenarioDefinition());
MsTestElement msTestElement = parseScenarioDefinition(oldScenario.getScenarioDefinition());
List<MsHTTPSamplerProxy> oldRequests = MsHTTPSamplerProxy.findHttpSampleFromHashTree(msTestElement);
@ -414,7 +416,6 @@ public class ApiAutomationService {
scenario.setApiScenarioModuleId(request.getApiScenarioModuleId());
scenario.setModulePath(request.getModulePath());
scenario.setLevel(request.getLevel());
scenario.setFollowPeople(request.getFollowPeople());
scenario.setPrincipal(request.getPrincipal());
scenario.setStepTotal(request.getStepTotal());
scenario.setUpdateTime(System.currentTimeMillis());
@ -442,9 +443,24 @@ public class ApiAutomationService {
scenario.setModulePath(modules.get(0).getName());
}
}
saveFollows(scenario.getId(), request.getFollows());
return scenario;
}
private void saveFollows(String scenarioId, List<String> follows) {
ApiScenarioFollowExample example = new ApiScenarioFollowExample();
example.createCriteria().andScenarioIdEqualTo(scenarioId);
apiScenarioFollowMapper.deleteByExample(example);
if (!org.springframework.util.CollectionUtils.isEmpty(follows)) {
for (String follow : follows) {
ApiScenarioFollow apiScenarioFollow = new ApiScenarioFollow();
apiScenarioFollow.setScenarioId(scenarioId);
apiScenarioFollow.setFollowId(follow);
apiScenarioFollowMapper.insert(apiScenarioFollow);
}
}
}
public void delete(String id) {
//及连删除外键表
this.preDelete(id);
@ -2669,4 +2685,14 @@ public class ApiAutomationService {
return this.checkScenarioEnv(request, null);
}
public List<String> getFollows(String scenarioId) {
List<String> result = new ArrayList<>();
if (StringUtils.isBlank(scenarioId)) {
return result;
}
ApiScenarioFollowExample example = new ApiScenarioFollowExample();
example.createCriteria().andScenarioIdEqualTo(scenarioId);
List<ApiScenarioFollow> follows = apiScenarioFollowMapper.selectByExample(example);
return follows.stream().map(ApiScenarioFollow::getFollowId).distinct().collect(Collectors.toList());
}
}

View File

@ -27,8 +27,6 @@ public class ApiScenario implements Serializable {
private Integer stepTotal;
private String followPeople;
private String schedule;
private Long createTime;

View File

@ -864,76 +864,6 @@ public class ApiScenarioExample {
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 andScheduleIsNull() {
addCriterion("schedule is null");
return (Criteria) this;

View File

@ -13,7 +13,6 @@
<result column="status" jdbcType="VARCHAR" property="status" />
<result column="principal" jdbcType="VARCHAR" property="principal" />
<result column="step_total" jdbcType="INTEGER" property="stepTotal" />
<result column="follow_people" jdbcType="VARCHAR" property="followPeople" />
<result column="schedule" jdbcType="VARCHAR" property="schedule" />
<result column="create_time" jdbcType="BIGINT" property="createTime" />
<result column="update_time" jdbcType="BIGINT" property="updateTime" />
@ -95,9 +94,9 @@
</sql>
<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, custom_num, create_user,
version, delete_time, delete_user_id, execute_times, `order`
`status`, principal, step_total, schedule, create_time, update_time, pass_rate, last_result,
report_id, num, original_state, custom_num, create_user, version, delete_time, delete_user_id,
execute_times, `order`
</sql>
<sql id="Blob_Column_List">
scenario_definition, description, use_url
@ -154,25 +153,23 @@
insert into api_scenario (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, custom_num,
create_user, version, delete_time,
delete_user_id, execute_times, `order`,
scenario_definition, description,
use_url)
principal, step_total, schedule,
create_time, update_time, pass_rate,
last_result, report_id, num,
original_state, custom_num, create_user,
version, delete_time, delete_user_id,
execute_times, `order`, scenario_definition,
description, use_url)
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}, #{customNum,jdbcType=VARCHAR},
#{createUser,jdbcType=VARCHAR}, #{version,jdbcType=INTEGER}, #{deleteTime,jdbcType=BIGINT},
#{deleteUserId,jdbcType=VARCHAR}, #{executeTimes,jdbcType=INTEGER}, #{order,jdbcType=BIGINT},
#{scenarioDefinition,jdbcType=LONGVARCHAR}, #{description,jdbcType=LONGVARCHAR},
#{useUrl,jdbcType=LONGVARCHAR})
#{principal,jdbcType=VARCHAR}, #{stepTotal,jdbcType=INTEGER}, #{schedule,jdbcType=VARCHAR},
#{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, #{passRate,jdbcType=VARCHAR},
#{lastResult,jdbcType=VARCHAR}, #{reportId,jdbcType=VARCHAR}, #{num,jdbcType=INTEGER},
#{originalState,jdbcType=VARCHAR}, #{customNum,jdbcType=VARCHAR}, #{createUser,jdbcType=VARCHAR},
#{version,jdbcType=INTEGER}, #{deleteTime,jdbcType=BIGINT}, #{deleteUserId,jdbcType=VARCHAR},
#{executeTimes,jdbcType=INTEGER}, #{order,jdbcType=BIGINT}, #{scenarioDefinition,jdbcType=LONGVARCHAR},
#{description,jdbcType=LONGVARCHAR}, #{useUrl,jdbcType=LONGVARCHAR})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.ApiScenarioWithBLOBs">
insert into api_scenario
@ -210,9 +207,6 @@
<if test="stepTotal != null">
step_total,
</if>
<if test="followPeople != null">
follow_people,
</if>
<if test="schedule != null">
schedule,
</if>
@ -302,9 +296,6 @@
<if test="stepTotal != null">
#{stepTotal,jdbcType=INTEGER},
</if>
<if test="followPeople != null">
#{followPeople,jdbcType=VARCHAR},
</if>
<if test="schedule != null">
#{schedule,jdbcType=VARCHAR},
</if>
@ -403,9 +394,6 @@
<if test="record.stepTotal != null">
step_total = #{record.stepTotal,jdbcType=INTEGER},
</if>
<if test="record.followPeople != null">
follow_people = #{record.followPeople,jdbcType=VARCHAR},
</if>
<if test="record.schedule != null">
schedule = #{record.schedule,jdbcType=VARCHAR},
</if>
@ -478,7 +466,6 @@
`status` = #{record.status,jdbcType=VARCHAR},
principal = #{record.principal,jdbcType=VARCHAR},
step_total = #{record.stepTotal,jdbcType=INTEGER},
follow_people = #{record.followPeople,jdbcType=VARCHAR},
schedule = #{record.schedule,jdbcType=VARCHAR},
create_time = #{record.createTime,jdbcType=BIGINT},
update_time = #{record.updateTime,jdbcType=BIGINT},
@ -514,7 +501,6 @@
`status` = #{record.status,jdbcType=VARCHAR},
principal = #{record.principal,jdbcType=VARCHAR},
step_total = #{record.stepTotal,jdbcType=INTEGER},
follow_people = #{record.followPeople,jdbcType=VARCHAR},
schedule = #{record.schedule,jdbcType=VARCHAR},
create_time = #{record.createTime,jdbcType=BIGINT},
update_time = #{record.updateTime,jdbcType=BIGINT},
@ -567,9 +553,6 @@
<if test="stepTotal != null">
step_total = #{stepTotal,jdbcType=INTEGER},
</if>
<if test="followPeople != null">
follow_people = #{followPeople,jdbcType=VARCHAR},
</if>
<if test="schedule != null">
schedule = #{schedule,jdbcType=VARCHAR},
</if>
@ -639,7 +622,6 @@
`status` = #{status,jdbcType=VARCHAR},
principal = #{principal,jdbcType=VARCHAR},
step_total = #{stepTotal,jdbcType=INTEGER},
follow_people = #{followPeople,jdbcType=VARCHAR},
schedule = #{schedule,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=BIGINT},
@ -672,7 +654,6 @@
`status` = #{status,jdbcType=VARCHAR},
principal = #{principal,jdbcType=VARCHAR},
step_total = #{stepTotal,jdbcType=INTEGER},
follow_people = #{followPeople,jdbcType=VARCHAR},
schedule = #{schedule,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=BIGINT},

View File

@ -916,7 +916,7 @@ public class PerformanceTestService {
}
LoadTestFollowExample example = new LoadTestFollowExample();
example.createCriteria().andTestIdEqualTo(testId);
List<LoadTestFollow> testPlanFollow = loadTestFollowMapper.selectByExample(example);
return testPlanFollow.stream().map(LoadTestFollow::getFollowId).distinct().collect(Collectors.toList());
List<LoadTestFollow> follows = loadTestFollowMapper.selectByExample(example);
return follows.stream().map(LoadTestFollow::getFollowId).distinct().collect(Collectors.toList());
}
}

View File

@ -353,4 +353,18 @@ INSERT INTO load_test_follow
SELECT id, follow_people
FROM load_test
WHERE follow_people IS NOT NULL;
ALTER TABLE load_test DROP COLUMN follow_people;
ALTER TABLE load_test DROP COLUMN follow_people;
-- 自动化关注人
CREATE TABLE IF NOT EXISTS `api_scenario_follow` (
`scenario_id` VARCHAR(50) DEFAULT NULL,
`follow_id` VARCHAR(50) DEFAULT NULL,
UNIQUE KEY `api_scenario_follow_scenario_id_follow_id_pk` (`scenario_id`, `follow_id`),
KEY `api_scenario_follow_id_index` (`follow_id`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci;
-- 自动化关注人数据迁移
INSERT INTO api_scenario_follow
SELECT id, follow_people
FROM api_scenario
WHERE follow_people IS NOT NULL;
ALTER TABLE api_scenario DROP COLUMN follow_people;

View File

@ -78,7 +78,7 @@
<table tableName="test_plan"/>
<table tableName="test_case_test"/>-->
<!-- <table tableName="api_test_environment"></table>-->
<table tableName="load_test">
<table tableName="api_scenario">
<ignoreColumn column="follow_people"/>
</table>
<!-- <table tableName="custom_field"></table>-->

View File

@ -22,7 +22,8 @@
</el-form-item>
<el-form-item :label="$t('api_test.automation.scenario.follow_people')" prop="followPeople">
<el-select v-model="scenarioForm.followPeople"
<el-select v-model="scenarioForm.follows"
multiple
:placeholder="$t('api_test.automation.scenario.follow_people')" filterable size="small"
style="width: 100%">
<el-option
@ -68,7 +69,7 @@
props: {},
data() {
return {
scenarioForm: {},
scenarioForm: {follows:[]},
visible: false,
currentModule: {},
userOptions: [],

View File

@ -60,8 +60,8 @@
</el-col>
<el-col :span="7">
<el-form-item :label="$t('api_test.automation.follow_people')" prop="followPeople">
<el-select v-model="currentScenario.followPeople"
clearable
<el-select v-model="currentScenario.follows"
clearable multiple
:placeholder="$t('api_test.automation.follow_people')" filterable size="small"
class="ms-scenario-input">
<el-option
@ -1368,6 +1368,10 @@ export default {
if (this.currentScenario.copy) {
this.path = "/api/automation/create";
}
this.$get('/api/automation/follow/' + this.currentScenario.id, response => {
// this.$set(this.currentScenario, 'follows', response.data);
this.currentScenario.follows = response.data;
});
}
this.loading = false;
this.setDomain();