feat(定时任务): 修改schedule表和查询,swagger定时任务也显示在首页 (#1627)

* feat(测试跟踪): 测试用例下载模版增加标签列

* fix(接口定义): 扩大请求头键长度

* feat(定时任务): 修改schedule表和查询,swagger定时任务也显示在首页

增加了schedule表的project ID、name字段,重写了首页定时任务列表的查询语句
This commit is contained in:
Coooder-X 2021-03-15 20:42:38 +08:00 committed by GitHub
parent 90adde0933
commit 0a19204418
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 364 additions and 200 deletions

View File

@ -15,6 +15,7 @@ import io.metersphere.api.service.*;
import io.metersphere.base.domain.ApiTest;
import io.metersphere.base.domain.Schedule;
import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.constants.ScheduleGroup;
import io.metersphere.commons.utils.CronUtils;
import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager;
@ -28,15 +29,13 @@ import io.metersphere.service.ScheduleService;
import org.apache.jorphan.collections.HashTree;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.python.core.AstList;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.*;
import static io.metersphere.commons.utils.JsonPathUtils.getListJson;
@ -345,8 +344,11 @@ public class APITestController {
@GetMapping("/runningTask/{projectID}")
public List<TaskInfoResult> runningTask(@PathVariable String projectID) {
List<TaskInfoResult> resultList = scheduleService.findRunningTaskInfoByProjectID(projectID);
List<String> typeFilter = Arrays.asList( // 首页显示的运行中定时任务只要这3种不需要 性能测试api_test(旧版)
ScheduleGroup.API_SCENARIO_TEST.name(),
ScheduleGroup.SWAGGER_IMPORT.name(),
ScheduleGroup.TEST_PLAN_TEST.name());
List<TaskInfoResult> resultList = scheduleService.findRunningTaskInfoByProjectID(projectID, typeFilter);
int dataIndex = 1;
for (TaskInfoResult taskInfo :
resultList) {

View File

@ -30,6 +30,7 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.net.MalformedURLException;
import java.util.Date;
import java.util.List;
@ -157,7 +158,7 @@ public class ApiDefinitionController {
//定时任务创建
@PostMapping(value = "/schedule/create")
public void createSchedule(@RequestBody ScheduleRequest request) {
public void createSchedule(@RequestBody ScheduleRequest request) throws MalformedURLException {
apiDefinitionService.createSchedule(request);
}
@PostMapping(value = "/schedule/update")

View File

@ -29,5 +29,7 @@ public class TaskInfoResult {
private Long updateTime;
//定时任务类型 情景定时任务/范围计划任务
private String taskType;
//定时任务组别 swagger/scenario/testPlan
private String taskGroup;
}

View File

@ -339,6 +339,8 @@ public class APITestService {
schedule.setJob(ApiTestJob.class.getName());
schedule.setGroup(ScheduleGroup.API_TEST.name());
schedule.setType(ScheduleType.CRON.name());
schedule.setProjectId(request.getProjectId());
schedule.setName(request.getName());
return schedule;
}

View File

@ -24,10 +24,7 @@ import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.ApiScenarioMapper;
import io.metersphere.base.mapper.ApiScenarioReportMapper;
import io.metersphere.base.mapper.TestPlanApiScenarioMapper;
import io.metersphere.base.mapper.ext.ExtApiScenarioMapper;
import io.metersphere.base.mapper.ext.ExtTestPlanApiCaseMapper;
import io.metersphere.base.mapper.ext.ExtTestPlanMapper;
import io.metersphere.base.mapper.ext.ExtTestPlanScenarioCaseMapper;
import io.metersphere.base.mapper.ext.*;
import io.metersphere.commons.constants.*;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.*;
@ -63,6 +60,8 @@ import java.util.stream.Collectors;
@Service
@Transactional(rollbackFor = Exception.class)
public class ApiAutomationService {
@Resource
private ExtScheduleMapper extScheduleMapper;
@Resource
private ApiScenarioMapper apiScenarioMapper;
@Resource
@ -196,6 +195,7 @@ public class ApiAutomationService {
final ApiScenarioWithBLOBs scenario = buildSaveScenario(request);
apiScenarioMapper.updateByPrimaryKeySelective(scenario);
extScheduleMapper.updateNameByResourceID(request.getId(), request.getName());// 修改场景name同步到修改首页定时任务
}
public ApiScenarioWithBLOBs buildSaveScenario(SaveApiScenarioRequest request) {
@ -720,6 +720,9 @@ public class ApiAutomationService {
public void createSchedule(ScheduleRequest request) {
Schedule schedule = scheduleService.buildApiTestSchedule(request);
ApiScenarioWithBLOBs apiScene = apiScenarioMapper.selectByPrimaryKey(request.getResourceId());
schedule.setName(apiScene.getName()); // add场景定时任务时设置新增的数据库表字段的值
schedule.setProjectId(apiScene.getProjectId());
schedule.setJob(ApiScenarioTestJob.class.getName());
schedule.setGroup(ScheduleGroup.API_SCENARIO_TEST.name());
schedule.setType(ScheduleType.CRON.name());

View File

@ -49,6 +49,7 @@ import sun.security.util.Cache;
import javax.annotation.Resource;
import java.io.File;
import java.net.MalformedURLException;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@ -702,7 +703,7 @@ public class ApiDefinitionService {
}
/*swagger定时导入*/
public void createSchedule(ScheduleRequest request) {
public void createSchedule(ScheduleRequest request) throws MalformedURLException {
/*保存swaggerUrl*/
SwaggerUrlProject swaggerUrlProject = new SwaggerUrlProject();
swaggerUrlProject.setId(UUID.randomUUID().toString());
@ -714,6 +715,9 @@ public class ApiDefinitionService {
scheduleService.addSwaggerUrlSchedule(swaggerUrlProject);
request.setResourceId(swaggerUrlProject.getId());
Schedule schedule = scheduleService.buildApiTestSchedule(request);
schedule.setProjectId(swaggerUrlProject.getProjectId());
java.net.URL swaggerUrl = new java.net.URL(swaggerUrlProject.getSwaggerUrl());
schedule.setName(swaggerUrl.getHost()); // swagger 定时任务的 name 设置为 swaggerURL 的域名
schedule.setJob(SwaggerUrlImportJob.class.getName());
schedule.setGroup(ScheduleGroup.SWAGGER_IMPORT.name());
schedule.setType(ScheduleType.CRON.name());

View File

@ -1,8 +1,7 @@
package io.metersphere.base.domain;
import lombok.Data;
import java.io.Serializable;
import lombok.Data;
@Data
public class Schedule implements Serializable {
@ -30,7 +29,9 @@ public class Schedule implements Serializable {
private Long updateTime;
private String customData;
private String projectId;
private String name;
private static final long serialVersionUID = 1L;
}

View File

@ -913,6 +913,146 @@ public class ScheduleExample {
addCriterion("update_time not between", value1, value2, "updateTime");
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 Criteria andNameIsNull() {
addCriterion("`name` is null");
return (Criteria) this;
}
public Criteria andNameIsNotNull() {
addCriterion("`name` is not null");
return (Criteria) this;
}
public Criteria andNameEqualTo(String value) {
addCriterion("`name` =", value, "name");
return (Criteria) this;
}
public Criteria andNameNotEqualTo(String value) {
addCriterion("`name` <>", value, "name");
return (Criteria) this;
}
public Criteria andNameGreaterThan(String value) {
addCriterion("`name` >", value, "name");
return (Criteria) this;
}
public Criteria andNameGreaterThanOrEqualTo(String value) {
addCriterion("`name` >=", value, "name");
return (Criteria) this;
}
public Criteria andNameLessThan(String value) {
addCriterion("`name` <", value, "name");
return (Criteria) this;
}
public Criteria andNameLessThanOrEqualTo(String value) {
addCriterion("`name` <=", value, "name");
return (Criteria) this;
}
public Criteria andNameLike(String value) {
addCriterion("`name` like", value, "name");
return (Criteria) this;
}
public Criteria andNameNotLike(String value) {
addCriterion("`name` not like", value, "name");
return (Criteria) this;
}
public Criteria andNameIn(List<String> values) {
addCriterion("`name` in", values, "name");
return (Criteria) this;
}
public Criteria andNameNotIn(List<String> values) {
addCriterion("`name` not in", values, "name");
return (Criteria) this;
}
public Criteria andNameBetween(String value1, String value2) {
addCriterion("`name` between", value1, value2, "name");
return (Criteria) this;
}
public Criteria andNameNotBetween(String value1, String value2) {
addCriterion("`name` not between", value1, value2, "name");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {

View File

@ -244,6 +244,76 @@ public class TestCaseExample {
return (Criteria) this;
}
public Criteria andTestIdIsNull() {
addCriterion("test_id is null");
return (Criteria) this;
}
public Criteria andTestIdIsNotNull() {
addCriterion("test_id is not null");
return (Criteria) this;
}
public Criteria andTestIdEqualTo(String value) {
addCriterion("test_id =", value, "testId");
return (Criteria) this;
}
public Criteria andTestIdNotEqualTo(String value) {
addCriterion("test_id <>", value, "testId");
return (Criteria) this;
}
public Criteria andTestIdGreaterThan(String value) {
addCriterion("test_id >", value, "testId");
return (Criteria) this;
}
public Criteria andTestIdGreaterThanOrEqualTo(String value) {
addCriterion("test_id >=", value, "testId");
return (Criteria) this;
}
public Criteria andTestIdLessThan(String value) {
addCriterion("test_id <", value, "testId");
return (Criteria) this;
}
public Criteria andTestIdLessThanOrEqualTo(String value) {
addCriterion("test_id <=", value, "testId");
return (Criteria) this;
}
public Criteria andTestIdLike(String value) {
addCriterion("test_id like", value, "testId");
return (Criteria) this;
}
public Criteria andTestIdNotLike(String value) {
addCriterion("test_id not like", value, "testId");
return (Criteria) this;
}
public Criteria andTestIdIn(List<String> values) {
addCriterion("test_id in", values, "testId");
return (Criteria) this;
}
public Criteria andTestIdNotIn(List<String> values) {
addCriterion("test_id not in", values, "testId");
return (Criteria) this;
}
public Criteria andTestIdBetween(String value1, String value2) {
addCriterion("test_id between", value1, value2, "testId");
return (Criteria) this;
}
public Criteria andTestIdNotBetween(String value1, String value2) {
addCriterion("test_id not between", value1, value2, "testId");
return (Criteria) this;
}
public Criteria andNodePathIsNull() {
addCriterion("node_path is null");
return (Criteria) this;
@ -924,76 +994,6 @@ public class TestCaseExample {
return (Criteria) this;
}
public Criteria andTestIdIsNull() {
addCriterion("test_id is null");
return (Criteria) this;
}
public Criteria andTestIdIsNotNull() {
addCriterion("test_id is not null");
return (Criteria) this;
}
public Criteria andTestIdEqualTo(String value) {
addCriterion("test_id =", value, "testId");
return (Criteria) this;
}
public Criteria andTestIdNotEqualTo(String value) {
addCriterion("test_id <>", value, "testId");
return (Criteria) this;
}
public Criteria andTestIdGreaterThan(String value) {
addCriterion("test_id >", value, "testId");
return (Criteria) this;
}
public Criteria andTestIdGreaterThanOrEqualTo(String value) {
addCriterion("test_id >=", value, "testId");
return (Criteria) this;
}
public Criteria andTestIdLessThan(String value) {
addCriterion("test_id <", value, "testId");
return (Criteria) this;
}
public Criteria andTestIdLessThanOrEqualTo(String value) {
addCriterion("test_id <=", value, "testId");
return (Criteria) this;
}
public Criteria andTestIdLike(String value) {
addCriterion("test_id like", value, "testId");
return (Criteria) this;
}
public Criteria andTestIdNotLike(String value) {
addCriterion("test_id not like", value, "testId");
return (Criteria) this;
}
public Criteria andTestIdIn(List<String> values) {
addCriterion("test_id in", values, "testId");
return (Criteria) this;
}
public Criteria andTestIdNotIn(List<String> values) {
addCriterion("test_id not in", values, "testId");
return (Criteria) this;
}
public Criteria andTestIdBetween(String value1, String value2) {
addCriterion("test_id between", value1, value2, "testId");
return (Criteria) this;
}
public Criteria andTestIdNotBetween(String value1, String value2) {
addCriterion("test_id not between", value1, value2, "testId");
return (Criteria) this;
}
public Criteria andSortIsNull() {
addCriterion("sort is null");
return (Criteria) this;

View File

@ -16,21 +16,15 @@ public interface ScheduleMapper {
int insertSelective(Schedule record);
List<Schedule> selectByExampleWithBLOBs(ScheduleExample example);
List<Schedule> selectByExample(ScheduleExample example);
Schedule selectByPrimaryKey(String id);
int updateByExampleSelective(@Param("record") Schedule record, @Param("example") ScheduleExample example);
int updateByExampleWithBLOBs(@Param("record") Schedule record, @Param("example") ScheduleExample example);
int updateByExample(@Param("record") Schedule record, @Param("example") ScheduleExample example);
int updateByPrimaryKeySelective(Schedule record);
int updateByPrimaryKeyWithBLOBs(Schedule record);
int updateByPrimaryKey(Schedule record);
}

View File

@ -14,9 +14,8 @@
<result column="workspace_id" jdbcType="VARCHAR" property="workspaceId" />
<result column="create_time" jdbcType="BIGINT" property="createTime" />
<result column="update_time" jdbcType="BIGINT" property="updateTime" />
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.base.domain.Schedule">
<result column="custom_data" jdbcType="LONGVARCHAR" property="customData" />
<result column="project_id" jdbcType="VARCHAR" property="projectId" />
<result column="name" jdbcType="VARCHAR" property="name" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
@ -78,27 +77,8 @@
</sql>
<sql id="Base_Column_List">
id, `key`, `type`, `value`, `group`, job, `enable`, resource_id, user_id, workspace_id,
create_time, update_time
create_time, update_time, project_id, `name`
</sql>
<sql id="Blob_Column_List">
custom_data
</sql>
<select id="selectByExampleWithBLOBs" parameterType="io.metersphere.base.domain.ScheduleExample" resultMap="ResultMapWithBLOBs">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
from schedule
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByExample" parameterType="io.metersphere.base.domain.ScheduleExample" resultMap="BaseResultMap">
select
<if test="distinct">
@ -113,11 +93,9 @@
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="ResultMapWithBLOBs">
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
from schedule
where id = #{id,jdbcType=VARCHAR}
</select>
@ -136,12 +114,12 @@
`value`, `group`, job,
`enable`, resource_id, user_id,
workspace_id, create_time, update_time,
custom_data)
project_id, `name`)
values (#{id,jdbcType=VARCHAR}, #{key,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR},
#{value,jdbcType=VARCHAR}, #{group,jdbcType=VARCHAR}, #{job,jdbcType=VARCHAR},
#{enable,jdbcType=BIT}, #{resourceId,jdbcType=VARCHAR}, #{userId,jdbcType=VARCHAR},
#{workspaceId,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT},
#{customData,jdbcType=LONGVARCHAR})
#{projectId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.Schedule">
insert into schedule
@ -182,8 +160,11 @@
<if test="updateTime != null">
update_time,
</if>
<if test="customData != null">
custom_data,
<if test="projectId != null">
project_id,
</if>
<if test="name != null">
`name`,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
@ -223,8 +204,11 @@
<if test="updateTime != null">
#{updateTime,jdbcType=BIGINT},
</if>
<if test="customData != null">
#{customData,jdbcType=LONGVARCHAR},
<if test="projectId != null">
#{projectId,jdbcType=VARCHAR},
</if>
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
</trim>
</insert>
@ -273,33 +257,17 @@
<if test="record.updateTime != null">
update_time = #{record.updateTime,jdbcType=BIGINT},
</if>
<if test="record.customData != null">
custom_data = #{record.customData,jdbcType=LONGVARCHAR},
<if test="record.projectId != null">
project_id = #{record.projectId,jdbcType=VARCHAR},
</if>
<if test="record.name != null">
`name` = #{record.name,jdbcType=VARCHAR},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExampleWithBLOBs" parameterType="map">
update schedule
set id = #{record.id,jdbcType=VARCHAR},
`key` = #{record.key,jdbcType=VARCHAR},
`type` = #{record.type,jdbcType=VARCHAR},
`value` = #{record.value,jdbcType=VARCHAR},
`group` = #{record.group,jdbcType=VARCHAR},
job = #{record.job,jdbcType=VARCHAR},
`enable` = #{record.enable,jdbcType=BIT},
resource_id = #{record.resourceId,jdbcType=VARCHAR},
user_id = #{record.userId,jdbcType=VARCHAR},
workspace_id = #{record.workspaceId,jdbcType=VARCHAR},
create_time = #{record.createTime,jdbcType=BIGINT},
update_time = #{record.updateTime,jdbcType=BIGINT},
custom_data = #{record.customData,jdbcType=LONGVARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map">
update schedule
set id = #{record.id,jdbcType=VARCHAR},
@ -313,7 +281,9 @@
user_id = #{record.userId,jdbcType=VARCHAR},
workspace_id = #{record.workspaceId,jdbcType=VARCHAR},
create_time = #{record.createTime,jdbcType=BIGINT},
update_time = #{record.updateTime,jdbcType=BIGINT}
update_time = #{record.updateTime,jdbcType=BIGINT},
project_id = #{record.projectId,jdbcType=VARCHAR},
`name` = #{record.name,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -354,28 +324,15 @@
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=BIGINT},
</if>
<if test="customData != null">
custom_data = #{customData,jdbcType=LONGVARCHAR},
<if test="projectId != null">
project_id = #{projectId,jdbcType=VARCHAR},
</if>
<if test="name != null">
`name` = #{name,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKeyWithBLOBs" parameterType="io.metersphere.base.domain.Schedule">
update schedule
set `key` = #{key,jdbcType=VARCHAR},
`type` = #{type,jdbcType=VARCHAR},
`value` = #{value,jdbcType=VARCHAR},
`group` = #{group,jdbcType=VARCHAR},
job = #{job,jdbcType=VARCHAR},
`enable` = #{enable,jdbcType=BIT},
resource_id = #{resourceId,jdbcType=VARCHAR},
user_id = #{userId,jdbcType=VARCHAR},
workspace_id = #{workspaceId,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=BIGINT},
custom_data = #{customData,jdbcType=LONGVARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="io.metersphere.base.domain.Schedule">
update schedule
set `key` = #{key,jdbcType=VARCHAR},
@ -388,7 +345,9 @@
user_id = #{userId,jdbcType=VARCHAR},
workspace_id = #{workspaceId,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=BIGINT}
update_time = #{updateTime,jdbcType=BIGINT},
project_id = #{projectId,jdbcType=VARCHAR},
`name` = #{name,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper>

View File

@ -15,10 +15,12 @@ public interface ExtScheduleMapper {
long countTaskByProjectIdAndCreateTimeRange(@Param("projectId")String projectId, @Param("startTime") long startTime, @Param("endTime") long endTime);
List<TaskInfoResult> findRunningTaskInfoByProjectID(String workspaceID);
List<TaskInfoResult> findRunningTaskInfoByProjectID(@Param("projectId") String workspaceID, @Param("types") List<String> typeFilter);
void insert(@Param("apiSwaggerUrlDTO") ApiSwaggerUrlDTO apiSwaggerUrlDTO);
ApiSwaggerUrlDTO select(String id);
int updateNameByResourceID(@Param("resourceId") String resourceId, @Param("name") String name);
}

View File

@ -61,35 +61,33 @@
AND create_time BETWEEN #{startTime} and #{endTime}
</select>
<select id="findRunningTaskInfoByProjectID" resultType="io.metersphere.api.dto.datacount.response.TaskInfoResult">
SELECT apiScene.id AS scenarioId,
apiScene.`name` AS `name`,
sch.id AS taskID,
sch.`value` AS rule,
sch.`enable` AS `taskStatus`,
u.`name` AS creator,
sch.update_time AS updateTime,
'scenario' AS taskType
FROM api_scenario apiScene
INNER JOIN `schedule` sch ON apiScene.id = sch.resource_id
INNER JOIN `user` u ON u.id = sch.user_id
SELECT sch.id AS taskID,
sch.`name` AS `name`,
sch.`value` AS rule,
sch.`enable` AS `taskStatus`,
sch.update_time AS updateTime,
sch.id AS taskID,
sch.`value` AS rule,
sch.`enable` AS `taskStatus`,
u.name AS creator,
sch.update_time AS updateTime,
sch.type AS taskType,
sch.group AS taskGroup
FROM (
schedule sch left join user u
ON sch.user_id = u.id
)
WHERE sch.`enable` = true
AND apiScene.project_id = #{0,jdbcType=VARCHAR}
UNION
SELECT testPlan.id AS scenarioId,
testPlan.`name` AS `name`,
sch.id AS taskID,
sch.`value` AS rule,
sch.`enable` AS `taskStatus`,
u.`name` AS creator,
sch.update_time AS updateTime,
'testPlan' AS taskType
FROM test_plan testPlan
INNER JOIN `schedule` sch ON testPlan.id = sch.resource_id
INNER JOIN `user` u ON u.id = sch.user_id
WHERE sch.`enable` = true
AND testPlan.project_id = #{0,jdbcType=VARCHAR}
AND sch.project_id = #{projectId,jdbcType=VARCHAR}
and sch.group in
<foreach collection="types" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</select>
<select id="select" resultType="io.metersphere.api.dto.definition.ApiSwaggerUrlDTO">
select * from swagger_url_project where id=#{id}
</select>
<update id="updateNameByResourceID">
update schedule set name = #{name} where resource_id = #{resourceId}
</update>
</mapper>

View File

@ -4,9 +4,7 @@ import com.alibaba.fastjson.JSON;
import io.metersphere.api.dto.datacount.response.TaskInfoResult;
import io.metersphere.api.dto.definition.ApiSwaggerUrlDTO;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.ScheduleMapper;
import io.metersphere.base.mapper.SwaggerUrlProjectMapper;
import io.metersphere.base.mapper.UserMapper;
import io.metersphere.base.mapper.*;
import io.metersphere.base.mapper.ext.ExtScheduleMapper;
import io.metersphere.commons.constants.ScheduleGroup;
import io.metersphere.commons.constants.ScheduleType;
@ -38,6 +36,10 @@ import java.util.stream.Collectors;
@Transactional(rollbackFor = Exception.class)
public class ScheduleService {
@Resource
private TestPlanMapper testPlanMapper;
@Resource
private ApiScenarioMapper apiScenarioMapper;
@Resource
private ScheduleMapper scheduleMapper;
@Resource
@ -214,8 +216,8 @@ public class ScheduleService {
}
}
public List<TaskInfoResult> findRunningTaskInfoByProjectID(String projectID) {
List<TaskInfoResult> runningTaskInfoList = extScheduleMapper.findRunningTaskInfoByProjectID(projectID);
public List<TaskInfoResult> findRunningTaskInfoByProjectID(String projectID, List<String> typeFilter) {
List<TaskInfoResult> runningTaskInfoList = extScheduleMapper.findRunningTaskInfoByProjectID(projectID, typeFilter);
return runningTaskInfoList;
}
@ -227,13 +229,19 @@ public class ScheduleService {
TriggerKey triggerKey = null;
Class clazz = null;
if("testPlan".equals(request.getScheduleFrom())){
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getResourceId());
schedule.setName(testPlan.getName());
schedule.setProjectId(testPlan.getProjectId());
schedule.setGroup(ScheduleGroup.TEST_PLAN_TEST.name());
schedule.setType(ScheduleType.CRON.name());
jobKey = TestPlanTestJob.getJobKey(request.getResourceId());
triggerKey = TestPlanTestJob.getTriggerKey(request.getResourceId());
clazz = TestPlanTestJob.class;
}else {
}else { // 实际上在场景中添加定时任务并不会执行到这里?
//默认为情景
ApiScenarioWithBLOBs apiScene = apiScenarioMapper.selectByPrimaryKey(request.getResourceId());
schedule.setName(apiScene.getName());
schedule.setProjectId(apiScene.getProjectId());
schedule.setGroup(ScheduleGroup.API_SCENARIO_TEST.name());
schedule.setType(ScheduleType.CRON.name());
jobKey = ApiScenarioTestJob.getJobKey(request.getResourceId());

View File

@ -57,6 +57,8 @@ import java.util.stream.Collectors;
@Service
@Transactional(rollbackFor = Exception.class)
public class TestPlanService {
@Resource
ExtScheduleMapper extScheduleMapper;
@Resource
TestPlanMapper testPlanMapper;
@Resource
@ -179,6 +181,7 @@ public class TestPlanService {
testPlan.setActualEndTime(System.currentTimeMillis());
}
}
extScheduleMapper.updateNameByResourceID(testPlan.getId(), testPlan.getName());// 同步更新该测试的定时任务的name
List<String> userIds = new ArrayList<>();
userIds.add(testPlan.getPrincipal());

View File

@ -96,4 +96,45 @@ alter table file_metadata
alter table api_definition add original_state varchar(64);
alter table api_scenario add original_state varchar(64);
update api_definition set original_state='Underway';
update api_scenario set original_state='Underway';
update api_scenario set original_state='Underway';
-- schedule table add project_id column
alter table schedule add project_id varchar(50) NULL;
-- set values for new colums of exitsting data
update schedule sch inner join test_plan testPlan on
testPlan.id = sch.resource_id
set sch.project_id = testPlan.project_id where
sch.resource_id = testPlan.id;
update schedule sch inner join swagger_url_project sup on
sup.id = sch.resource_id
set sch.project_id = sup.project_id where
sch.resource_id = sup.id;
update schedule sch inner join api_scenario apiScene on
apiScene.id = sch.resource_id
set sch.project_id = apiScene.project_id where
sch.resource_id = apiScene.id;
update schedule sch inner join load_test ldt on
ldt.id = sch.resource_id
set sch.project_id = ldt.project_id where
sch.resource_id = ldt.id;
update schedule sch inner join api_test apiTest on
apiTest.id = sch.resource_id
set sch.project_id = apiTest.project_id where
sch.resource_id = apiTest.id;
-- schedule table add name column
alter table schedule add name varchar(100) NULL;
-- set values for new colums of exitsting data
update schedule sch inner join api_scenario apiScene on
apiScene.id = sch.resource_id
set sch.name = apiScene.name;
update schedule sch inner join test_plan testPlan on
testPlan.id = sch.resource_id
set sch.name = testPlan.name;
update schedule sch inner join load_test ldt on
ldt.id = sch.resource_id
set sch.name = ldt.name;
update schedule sch inner join api_test apiTest on
apiTest.id = sch.resource_id
set sch.name = apiTest.name;
-- delete an unused colum
alter table schedule drop column custom_data;

View File

@ -20,8 +20,9 @@
</el-table-column>
<el-table-column prop="taskType" :label="$t('api_test.home_page.running_task_list.table_coloum.task_type')" width="120" show-overflow-tooltip>
<template v-slot:default="scope">
<ms-tag v-if="scope.row.taskType == 'scenario'" type="success" effect="plain" :content="$t('api_test.home_page.running_task_list.scenario_schedule')"/>
<ms-tag v-if="scope.row.taskType == 'testPlan'" type="warning" effect="plain" :content="$t('api_test.home_page.running_task_list.test_plan_schedule')"/>
<ms-tag v-if="scope.row.taskGroup == 'API_SCENARIO_TEST'" type="success" effect="plain" :content="$t('api_test.home_page.running_task_list.scenario_schedule')"/>
<ms-tag v-if="scope.row.taskGroup == 'TEST_PLAN_TEST'" type="warning" effect="plain" :content="$t('api_test.home_page.running_task_list.test_plan_schedule')"/>
<ms-tag v-if="scope.row.taskGroup == 'SWAGGER_IMPORT'" type="danger" effect="plain" :content="$t('api_test.home_page.running_task_list.swagger_schedule')"/>
</template>
</el-table-column>
<el-table-column prop="rule" :label="$t('api_test.home_page.running_task_list.table_coloum.run_rule')" width="120" show-overflow-tooltip/>

View File

@ -1029,6 +1029,7 @@ export default {
},
scenario_schedule: "Scenario",
test_plan_schedule: "Test plan",
swagger_schedule: "swagger",
confirm: {
close_title: "Do you want to close this scheduled task",
}

View File

@ -1033,6 +1033,7 @@ export default {
},
scenario_schedule: "场景",
test_plan_schedule: "测试计划",
swagger_schedule: "swagger",
confirm: {
close_title: "要关闭这条定时任务吗?",
}

View File

@ -1031,6 +1031,7 @@ export default {
},
scenario_schedule: "場景",
test_plan_schedule: "測試計畫",
swagger_schedule: "swagger",
confirm: {
close_title: "要關閉這條定時任務嗎?",
}