refactor(系统设置): 定时任务增加资源类型
This commit is contained in:
parent
133119f41b
commit
72b6e303f7
|
@ -18,7 +18,7 @@ public class Schedule implements Serializable {
|
|||
@Schema(description = "qrtz UUID")
|
||||
private String key;
|
||||
|
||||
@Schema(description = "资源类型", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@Schema(description = "执行类型 cron", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{schedule.type.not_blank}", groups = {Created.class})
|
||||
@Size(min = 1, max = 50, message = "{schedule.type.length_range}", groups = {Created.class, Updated.class})
|
||||
private String type;
|
||||
|
@ -33,6 +33,11 @@ public class Schedule implements Serializable {
|
|||
@Size(min = 1, max = 64, message = "{schedule.job.length_range}", groups = {Created.class, Updated.class})
|
||||
private String job;
|
||||
|
||||
@Schema(description = "资源类型 API/TESL_PLAN", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{schedule.resource_type.not_blank}", groups = {Created.class})
|
||||
@Size(min = 1, max = 50, message = "{schedule.resource_type.length_range}", groups = {Created.class, Updated.class})
|
||||
private String resourceType;
|
||||
|
||||
@Schema(description = "是否开启")
|
||||
private Boolean enable;
|
||||
|
||||
|
@ -65,6 +70,7 @@ public class Schedule implements Serializable {
|
|||
type("type", "type", "VARCHAR", true),
|
||||
value("value", "value", "VARCHAR", true),
|
||||
job("job", "job", "VARCHAR", false),
|
||||
resourceType("resource_type", "resourceType", "VARCHAR", false),
|
||||
enable("enable", "enable", "BIT", true),
|
||||
resourceId("resource_id", "resourceId", "VARCHAR", false),
|
||||
createUser("create_user", "createUser", "VARCHAR", false),
|
||||
|
|
|
@ -454,6 +454,76 @@ public class ScheduleExample {
|
|||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andResourceTypeIsNull() {
|
||||
addCriterion("resource_type is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andResourceTypeIsNotNull() {
|
||||
addCriterion("resource_type is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andResourceTypeEqualTo(String value) {
|
||||
addCriterion("resource_type =", value, "resourceType");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andResourceTypeNotEqualTo(String value) {
|
||||
addCriterion("resource_type <>", value, "resourceType");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andResourceTypeGreaterThan(String value) {
|
||||
addCriterion("resource_type >", value, "resourceType");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andResourceTypeGreaterThanOrEqualTo(String value) {
|
||||
addCriterion("resource_type >=", value, "resourceType");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andResourceTypeLessThan(String value) {
|
||||
addCriterion("resource_type <", value, "resourceType");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andResourceTypeLessThanOrEqualTo(String value) {
|
||||
addCriterion("resource_type <=", value, "resourceType");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andResourceTypeLike(String value) {
|
||||
addCriterion("resource_type like", value, "resourceType");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andResourceTypeNotLike(String value) {
|
||||
addCriterion("resource_type not like", value, "resourceType");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andResourceTypeIn(List<String> values) {
|
||||
addCriterion("resource_type in", values, "resourceType");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andResourceTypeNotIn(List<String> values) {
|
||||
addCriterion("resource_type not in", values, "resourceType");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andResourceTypeBetween(String value1, String value2) {
|
||||
addCriterion("resource_type between", value1, value2, "resourceType");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andResourceTypeNotBetween(String value1, String value2) {
|
||||
addCriterion("resource_type not between", value1, value2, "resourceType");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andEnableIsNull() {
|
||||
addCriterion("`enable` is null");
|
||||
return (Criteria) this;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
<result column="type" jdbcType="VARCHAR" property="type" />
|
||||
<result column="value" jdbcType="VARCHAR" property="value" />
|
||||
<result column="job" jdbcType="VARCHAR" property="job" />
|
||||
<result column="resource_type" jdbcType="VARCHAR" property="resourceType" />
|
||||
<result column="enable" jdbcType="BIT" property="enable" />
|
||||
<result column="resource_id" jdbcType="VARCHAR" property="resourceId" />
|
||||
<result column="create_user" jdbcType="VARCHAR" property="createUser" />
|
||||
|
@ -75,8 +76,8 @@
|
|||
</where>
|
||||
</sql>
|
||||
<sql id="Base_Column_List">
|
||||
id, `key`, `type`, `value`, job, `enable`, resource_id, create_user, create_time,
|
||||
update_time, project_id, `name`, config
|
||||
id, `key`, `type`, `value`, job, resource_type, `enable`, resource_id, create_user,
|
||||
create_time, update_time, project_id, `name`, config
|
||||
</sql>
|
||||
<select id="selectByExample" parameterType="io.metersphere.system.domain.ScheduleExample" resultMap="BaseResultMap">
|
||||
select
|
||||
|
@ -110,15 +111,15 @@
|
|||
</delete>
|
||||
<insert id="insert" parameterType="io.metersphere.system.domain.Schedule">
|
||||
insert into schedule (id, `key`, `type`,
|
||||
`value`, job, `enable`, resource_id,
|
||||
create_user, create_time, update_time,
|
||||
project_id, `name`, config
|
||||
)
|
||||
`value`, job, resource_type,
|
||||
`enable`, resource_id, create_user,
|
||||
create_time, update_time, project_id,
|
||||
`name`, config)
|
||||
values (#{id,jdbcType=VARCHAR}, #{key,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR},
|
||||
#{value,jdbcType=VARCHAR}, #{job,jdbcType=VARCHAR}, #{enable,jdbcType=BIT}, #{resourceId,jdbcType=VARCHAR},
|
||||
#{createUser,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT},
|
||||
#{projectId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{config,jdbcType=VARCHAR}
|
||||
)
|
||||
#{value,jdbcType=VARCHAR}, #{job,jdbcType=VARCHAR}, #{resourceType,jdbcType=VARCHAR},
|
||||
#{enable,jdbcType=BIT}, #{resourceId,jdbcType=VARCHAR}, #{createUser,jdbcType=VARCHAR},
|
||||
#{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, #{projectId,jdbcType=VARCHAR},
|
||||
#{name,jdbcType=VARCHAR}, #{config,jdbcType=VARCHAR})
|
||||
</insert>
|
||||
<insert id="insertSelective" parameterType="io.metersphere.system.domain.Schedule">
|
||||
insert into schedule
|
||||
|
@ -138,6 +139,9 @@
|
|||
<if test="job != null">
|
||||
job,
|
||||
</if>
|
||||
<if test="resourceType != null">
|
||||
resource_type,
|
||||
</if>
|
||||
<if test="enable != null">
|
||||
`enable`,
|
||||
</if>
|
||||
|
@ -179,6 +183,9 @@
|
|||
<if test="job != null">
|
||||
#{job,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="resourceType != null">
|
||||
#{resourceType,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="enable != null">
|
||||
#{enable,jdbcType=BIT},
|
||||
</if>
|
||||
|
@ -229,6 +236,9 @@
|
|||
<if test="record.job != null">
|
||||
job = #{record.job,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.resourceType != null">
|
||||
resource_type = #{record.resourceType,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.enable != null">
|
||||
`enable` = #{record.enable,jdbcType=BIT},
|
||||
</if>
|
||||
|
@ -265,6 +275,7 @@
|
|||
`type` = #{record.type,jdbcType=VARCHAR},
|
||||
`value` = #{record.value,jdbcType=VARCHAR},
|
||||
job = #{record.job,jdbcType=VARCHAR},
|
||||
resource_type = #{record.resourceType,jdbcType=VARCHAR},
|
||||
`enable` = #{record.enable,jdbcType=BIT},
|
||||
resource_id = #{record.resourceId,jdbcType=VARCHAR},
|
||||
create_user = #{record.createUser,jdbcType=VARCHAR},
|
||||
|
@ -292,6 +303,9 @@
|
|||
<if test="job != null">
|
||||
job = #{job,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="resourceType != null">
|
||||
resource_type = #{resourceType,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="enable != null">
|
||||
`enable` = #{enable,jdbcType=BIT},
|
||||
</if>
|
||||
|
@ -325,6 +339,7 @@
|
|||
`type` = #{type,jdbcType=VARCHAR},
|
||||
`value` = #{value,jdbcType=VARCHAR},
|
||||
job = #{job,jdbcType=VARCHAR},
|
||||
resource_type = #{resourceType,jdbcType=VARCHAR},
|
||||
`enable` = #{enable,jdbcType=BIT},
|
||||
resource_id = #{resourceId,jdbcType=VARCHAR},
|
||||
create_user = #{createUser,jdbcType=VARCHAR},
|
||||
|
@ -337,15 +352,15 @@
|
|||
</update>
|
||||
<insert id="batchInsert" parameterType="map">
|
||||
insert into schedule
|
||||
(id, `key`, `type`, `value`, job, `enable`, resource_id, create_user, create_time,
|
||||
update_time, project_id, `name`, config)
|
||||
(id, `key`, `type`, `value`, job, resource_type, `enable`, resource_id, create_user,
|
||||
create_time, update_time, project_id, `name`, config)
|
||||
values
|
||||
<foreach collection="list" item="item" separator=",">
|
||||
(#{item.id,jdbcType=VARCHAR}, #{item.key,jdbcType=VARCHAR}, #{item.type,jdbcType=VARCHAR},
|
||||
#{item.value,jdbcType=VARCHAR}, #{item.job,jdbcType=VARCHAR}, #{item.enable,jdbcType=BIT},
|
||||
#{item.resourceId,jdbcType=VARCHAR}, #{item.createUser,jdbcType=VARCHAR}, #{item.createTime,jdbcType=BIGINT},
|
||||
#{item.updateTime,jdbcType=BIGINT}, #{item.projectId,jdbcType=VARCHAR}, #{item.name,jdbcType=VARCHAR},
|
||||
#{item.config,jdbcType=VARCHAR})
|
||||
#{item.value,jdbcType=VARCHAR}, #{item.job,jdbcType=VARCHAR}, #{item.resourceType,jdbcType=VARCHAR},
|
||||
#{item.enable,jdbcType=BIT}, #{item.resourceId,jdbcType=VARCHAR}, #{item.createUser,jdbcType=VARCHAR},
|
||||
#{item.createTime,jdbcType=BIGINT}, #{item.updateTime,jdbcType=BIGINT}, #{item.projectId,jdbcType=VARCHAR},
|
||||
#{item.name,jdbcType=VARCHAR}, #{item.config,jdbcType=VARCHAR})
|
||||
</foreach>
|
||||
</insert>
|
||||
<insert id="batchInsertSelective" parameterType="map">
|
||||
|
@ -373,6 +388,9 @@
|
|||
<if test="'job'.toString() == column.value">
|
||||
#{item.job,jdbcType=VARCHAR}
|
||||
</if>
|
||||
<if test="'resource_type'.toString() == column.value">
|
||||
#{item.resourceType,jdbcType=VARCHAR}
|
||||
</if>
|
||||
<if test="'enable'.toString() == column.value">
|
||||
#{item.enable,jdbcType=BIT}
|
||||
</if>
|
||||
|
|
|
@ -113,9 +113,10 @@ CREATE TABLE IF NOT EXISTS schedule
|
|||
(
|
||||
`id` VARCHAR(50) NOT NULL COMMENT '',
|
||||
`key` VARCHAR(50) COMMENT 'qrtz UUID',
|
||||
`type` VARCHAR(50) NOT NULL COMMENT '资源类型',
|
||||
`type` VARCHAR(50) NOT NULL COMMENT '执行类型 cron',
|
||||
`value` VARCHAR(255) NOT NULL COMMENT 'cron 表达式',
|
||||
`job` VARCHAR(64) NOT NULL COMMENT 'Schedule Job Class Name',
|
||||
`resource_type` VARCHAR(50) NOT NULL DEFAULT 'NONE' COMMENT '资源类型 API_IMPORT,API_SCENARIO,UI_SCENARIO,LOAD_TEST,TEST_PLAN,CLEAN_REPORT,BUG_SYNC' ,
|
||||
`enable` BIT COMMENT '是否开启',
|
||||
`resource_id` VARCHAR(50) COMMENT '资源ID,api_scenario ui_scenario load_test',
|
||||
`create_user` VARCHAR(50) NOT NULL COMMENT '创建人',
|
||||
|
@ -138,6 +139,7 @@ CREATE INDEX idx_project_id ON schedule (`project_id`);
|
|||
CREATE INDEX idx_enable ON schedule (`enable`);
|
||||
CREATE INDEX idx_name ON schedule (`name`);
|
||||
CREATE INDEX idx_type ON schedule (`type`);
|
||||
CREATE INDEX idx_resource_type ON schedule(`resource_type`);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS service_integration
|
||||
(
|
||||
|
|
|
@ -712,7 +712,7 @@ INSERT INTO message_task_blob(id, template) VALUES (@bug_comment_reply_id, 'mess
|
|||
|
||||
|
||||
-- 初始化定时任务数据
|
||||
INSERT INTO schedule(`id`, `key`, `type`, `value`, `job`, `enable`, `resource_id`, `create_user`, `create_time`, `update_time`, `project_id`, `name`, `config`) VALUES (UUID_SHORT(), '100001100001', 'CRON', '0 0 2 * * ?', 'io.metersphere.project.job.CleanUpReportJob', true, '100001100001', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000, '100001100001', 'Clean Report Job', NULL);
|
||||
INSERT INTO schedule(`id`, `key`, `type`,`resource_type`, `value`, `job`, `enable`, `resource_id`, `create_user`, `create_time`, `update_time`, `project_id`, `name`, `config`) VALUES (UUID_SHORT(), '100001100001', 'CRON','CLEAN_REPORT', '0 0 2 * * ?', 'io.metersphere.project.job.CleanUpReportJob', true, '100001100001', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000, '100001100001', 'Clean Report Job', NULL);
|
||||
|
||||
-- 初始化默认项目版本配置项
|
||||
INSERT INTO project_application (`project_id`, `type`, `type_value`) VALUES ('100001100001', 'VERSION_ENABLE', 'FALSE');
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package io.metersphere.sdk.constants;
|
||||
|
||||
public enum ScheduleResourceType {
|
||||
API_IMPORT,
|
||||
API_SCENARIO,
|
||||
UI_SCENARIO,
|
||||
LOAD_TEST,
|
||||
TEST_PLAN,
|
||||
CLEAN_REPORT,
|
||||
|
||||
BUG_SYNC
|
||||
}
|
|
@ -11,6 +11,7 @@ import io.metersphere.api.utils.ApiDataUtils;
|
|||
import io.metersphere.project.mapper.ProjectMapper;
|
||||
import io.metersphere.sdk.constants.ApplicationNumScope;
|
||||
import io.metersphere.sdk.constants.HttpMethodConstants;
|
||||
import io.metersphere.sdk.constants.ScheduleResourceType;
|
||||
import io.metersphere.sdk.constants.ScheduleType;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
|
@ -66,6 +67,7 @@ public class ApiDefinitionScheduleService {
|
|||
schedule.setResourceId(apiSwagger.getId());
|
||||
schedule.setJob(SwaggerUrlImportJob.class.getName());
|
||||
schedule.setType(ScheduleType.CRON.name());
|
||||
schedule.setResourceType(ScheduleResourceType.API_IMPORT.name());
|
||||
scheduleService.addSchedule(schedule);
|
||||
scheduleService.addOrUpdateCronJob(schedule,
|
||||
SwaggerUrlImportJob.getJobKey(apiSwagger.getId()),
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package io.metersphere.project.service;
|
||||
|
||||
import io.metersphere.project.job.CleanUpReportJob;
|
||||
import io.metersphere.sdk.constants.ScheduleResourceType;
|
||||
import io.metersphere.sdk.constants.ScheduleType;
|
||||
import io.metersphere.system.domain.Schedule;
|
||||
import io.metersphere.system.sechedule.ScheduleService;
|
||||
|
@ -32,6 +33,7 @@ public class CreateApplicationResourceService implements CreateProjectResourceSe
|
|||
// 每天凌晨2点执行清理任务
|
||||
request.setValue("0 0 2 * * ?");
|
||||
request.setJob(CleanUpReportJob.class.getName());
|
||||
request.setResourceType(ScheduleResourceType.CLEAN_REPORT.name());
|
||||
scheduleService.addSchedule(request);
|
||||
scheduleService.addOrUpdateCronJob(request,
|
||||
CleanUpReportJob.getJobKey(projectId),
|
||||
|
|
|
@ -15,6 +15,7 @@ import io.metersphere.project.request.ProjectApplicationRequest;
|
|||
import io.metersphere.project.utils.ModuleSortUtils;
|
||||
import io.metersphere.sdk.constants.OperationLogConstants;
|
||||
import io.metersphere.sdk.constants.ProjectApplicationType;
|
||||
import io.metersphere.sdk.constants.ScheduleResourceType;
|
||||
import io.metersphere.sdk.constants.ScheduleType;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
|
@ -142,6 +143,7 @@ public class ProjectApplicationService {
|
|||
// 每天凌晨2点执行清理任务
|
||||
request.setValue("0 0 2 * * ?");
|
||||
request.setJob(CleanUpReportJob.class.getName());
|
||||
request.setResourceType(ScheduleResourceType.CLEAN_REPORT.name());
|
||||
scheduleService.addSchedule(request);
|
||||
scheduleService.addOrUpdateCronJob(request,
|
||||
CleanUpReportJob.getJobKey(projectId),
|
||||
|
@ -280,6 +282,7 @@ public class ProjectApplicationService {
|
|||
// 每天凌晨2点执行清理任务
|
||||
request.setValue(typeValue);
|
||||
request.setJob(BugSyncJob.class.getName());
|
||||
request.setResourceType(ScheduleResourceType.BUG_SYNC.name());
|
||||
scheduleService.addSchedule(request);
|
||||
scheduleService.addOrUpdateCronJob(request,
|
||||
BugSyncJob.getJobKey(projectId),
|
||||
|
|
Loading…
Reference in New Issue