Merge remote-tracking branch 'origin/master'

This commit is contained in:
wenyann 2020-08-04 16:45:17 +08:00
commit 833d80faf5
23 changed files with 677 additions and 86 deletions

View File

@ -11,6 +11,8 @@ import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.controller.request.QueryScheduleRequest;
import io.metersphere.dto.ScheduleDao;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*;
@ -98,4 +100,15 @@ public class APITestController {
public List<DubboProvider> getProviders(@RequestBody RegistryCenter registry) {
return apiTestService.getProviders(registry);
}
@PostMapping("/list/schedule/{goPage}/{pageSize}")
public List<ScheduleDao> listSchedule(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryScheduleRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return apiTestService.listSchedule(request);
}
@PostMapping("/list/schedule")
public List<ScheduleDao> listSchedule(@RequestBody QueryScheduleRequest request) {
return apiTestService.listSchedule(request);
}
}

View File

@ -21,6 +21,8 @@ import io.metersphere.commons.utils.BeanUtils;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.commons.utils.ServiceUtils;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.controller.request.QueryScheduleRequest;
import io.metersphere.dto.ScheduleDao;
import io.metersphere.i18n.Translator;
import io.metersphere.job.sechedule.ApiTestJob;
import io.metersphere.service.FileService;
@ -310,4 +312,17 @@ public class APITestService {
});
return list;
}
public List<ScheduleDao> listSchedule(QueryScheduleRequest request) {
List<ScheduleDao> schedules = scheduleService.list(request);
List<String> resourceIds = schedules.stream()
.map(Schedule::getResourceId)
.collect(Collectors.toList());
ApiTestExample example = new ApiTestExample();
example.createCriteria().andIdIn(resourceIds);
List<ApiTest> apiTests = apiTestMapper.selectByExample(example);
Map<String, String> apiTestMap = apiTests.stream().collect(Collectors.toMap(ApiTest::getId, ApiTest::getName));
scheduleService.build(apiTestMap, schedules);
return schedules;
}
}

View File

@ -1,8 +1,9 @@
package io.metersphere.base.domain;
import java.io.Serializable;
import lombok.Data;
import java.io.Serializable;
@Data
public class Schedule implements Serializable {
private String id;
@ -23,6 +24,12 @@ public class Schedule implements Serializable {
private String userId;
private String workspaceId;
private Long createTime;
private Long updateTime;
private String customData;
private static final long serialVersionUID = 1L;

View File

@ -723,6 +723,196 @@ public class ScheduleExample {
addCriterion("user_id not between", value1, value2, "userId");
return (Criteria) this;
}
public Criteria andWorkspaceIdIsNull() {
addCriterion("workspace_id is null");
return (Criteria) this;
}
public Criteria andWorkspaceIdIsNotNull() {
addCriterion("workspace_id is not null");
return (Criteria) this;
}
public Criteria andWorkspaceIdEqualTo(String value) {
addCriterion("workspace_id =", value, "workspaceId");
return (Criteria) this;
}
public Criteria andWorkspaceIdNotEqualTo(String value) {
addCriterion("workspace_id <>", value, "workspaceId");
return (Criteria) this;
}
public Criteria andWorkspaceIdGreaterThan(String value) {
addCriterion("workspace_id >", value, "workspaceId");
return (Criteria) this;
}
public Criteria andWorkspaceIdGreaterThanOrEqualTo(String value) {
addCriterion("workspace_id >=", value, "workspaceId");
return (Criteria) this;
}
public Criteria andWorkspaceIdLessThan(String value) {
addCriterion("workspace_id <", value, "workspaceId");
return (Criteria) this;
}
public Criteria andWorkspaceIdLessThanOrEqualTo(String value) {
addCriterion("workspace_id <=", value, "workspaceId");
return (Criteria) this;
}
public Criteria andWorkspaceIdLike(String value) {
addCriterion("workspace_id like", value, "workspaceId");
return (Criteria) this;
}
public Criteria andWorkspaceIdNotLike(String value) {
addCriterion("workspace_id not like", value, "workspaceId");
return (Criteria) this;
}
public Criteria andWorkspaceIdIn(List<String> values) {
addCriterion("workspace_id in", values, "workspaceId");
return (Criteria) this;
}
public Criteria andWorkspaceIdNotIn(List<String> values) {
addCriterion("workspace_id not in", values, "workspaceId");
return (Criteria) this;
}
public Criteria andWorkspaceIdBetween(String value1, String value2) {
addCriterion("workspace_id between", value1, value2, "workspaceId");
return (Criteria) this;
}
public Criteria andWorkspaceIdNotBetween(String value1, String value2) {
addCriterion("workspace_id not between", value1, value2, "workspaceId");
return (Criteria) this;
}
public Criteria andCreateTimeIsNull() {
addCriterion("create_time is null");
return (Criteria) this;
}
public Criteria andCreateTimeIsNotNull() {
addCriterion("create_time is not null");
return (Criteria) this;
}
public Criteria andCreateTimeEqualTo(Long value) {
addCriterion("create_time =", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeNotEqualTo(Long value) {
addCriterion("create_time <>", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeGreaterThan(Long value) {
addCriterion("create_time >", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeGreaterThanOrEqualTo(Long value) {
addCriterion("create_time >=", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeLessThan(Long value) {
addCriterion("create_time <", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeLessThanOrEqualTo(Long value) {
addCriterion("create_time <=", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeIn(List<Long> values) {
addCriterion("create_time in", values, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeNotIn(List<Long> values) {
addCriterion("create_time not in", values, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeBetween(Long value1, Long value2) {
addCriterion("create_time between", value1, value2, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeNotBetween(Long value1, Long value2) {
addCriterion("create_time not between", value1, value2, "createTime");
return (Criteria) this;
}
public Criteria andUpdateTimeIsNull() {
addCriterion("update_time is null");
return (Criteria) this;
}
public Criteria andUpdateTimeIsNotNull() {
addCriterion("update_time is not null");
return (Criteria) this;
}
public Criteria andUpdateTimeEqualTo(Long value) {
addCriterion("update_time =", value, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeNotEqualTo(Long value) {
addCriterion("update_time <>", value, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeGreaterThan(Long value) {
addCriterion("update_time >", value, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeGreaterThanOrEqualTo(Long value) {
addCriterion("update_time >=", value, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeLessThan(Long value) {
addCriterion("update_time <", value, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeLessThanOrEqualTo(Long value) {
addCriterion("update_time <=", value, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeIn(List<Long> values) {
addCriterion("update_time in", values, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeNotIn(List<Long> values) {
addCriterion("update_time not in", values, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeBetween(Long value1, Long value2) {
addCriterion("update_time between", value1, value2, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeNotBetween(Long value1, Long value2) {
addCriterion("update_time not between", value1, value2, "updateTime");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {

View File

@ -2,15 +2,18 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="io.metersphere.base.mapper.ScheduleMapper">
<resultMap id="BaseResultMap" type="io.metersphere.base.domain.Schedule">
<id column="id" jdbcType="VARCHAR" property="id" />
<result column="key" jdbcType="VARCHAR" property="key" />
<result column="type" jdbcType="VARCHAR" property="type" />
<result column="value" jdbcType="VARCHAR" property="value" />
<result column="group" jdbcType="VARCHAR" property="group" />
<result column="job" jdbcType="VARCHAR" property="job" />
<result column="enable" jdbcType="BIT" property="enable" />
<result column="resource_id" jdbcType="VARCHAR" property="resourceId" />
<result column="user_id" jdbcType="VARCHAR" property="userId" />
<id column="id" jdbcType="VARCHAR" property="id"/>
<result column="key" jdbcType="VARCHAR" property="key"/>
<result column="type" jdbcType="VARCHAR" property="type"/>
<result column="value" jdbcType="VARCHAR" property="value"/>
<result column="group" jdbcType="VARCHAR" property="group"/>
<result column="job" jdbcType="VARCHAR" property="job"/>
<result column="enable" jdbcType="BIT" property="enable"/>
<result column="resource_id" jdbcType="VARCHAR" property="resourceId"/>
<result column="user_id" jdbcType="VARCHAR" property="userId"/>
<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" />
@ -74,7 +77,8 @@
</where>
</sql>
<sql id="Base_Column_List">
id, `key`, `type`, `value`, `group`, job, `enable`, resource_id, user_id
id, `key`, `type`, `value`, `group`, job, `enable`, resource_id, user_id, workspace_id,
create_time, update_time
</sql>
<sql id="Blob_Column_List">
custom_data
@ -131,10 +135,12 @@
insert into schedule (id, `key`, `type`,
`value`, `group`, job,
`enable`, resource_id, user_id,
workspace_id, create_time, update_time,
custom_data)
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})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.Schedule">
@ -167,6 +173,15 @@
<if test="userId != null">
user_id,
</if>
<if test="workspaceId != null">
workspace_id,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="updateTime != null">
update_time,
</if>
<if test="customData != null">
custom_data,
</if>
@ -199,6 +214,15 @@
<if test="userId != null">
#{userId,jdbcType=VARCHAR},
</if>
<if test="workspaceId != null">
#{workspaceId,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
#{createTime,jdbcType=BIGINT},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=BIGINT},
</if>
<if test="customData != null">
#{customData,jdbcType=LONGVARCHAR},
</if>
@ -240,6 +264,15 @@
<if test="record.userId != null">
user_id = #{record.userId,jdbcType=VARCHAR},
</if>
<if test="record.workspaceId != null">
workspace_id = #{record.workspaceId,jdbcType=VARCHAR},
</if>
<if test="record.createTime != null">
create_time = #{record.createTime,jdbcType=BIGINT},
</if>
<if test="record.updateTime != null">
update_time = #{record.updateTime,jdbcType=BIGINT},
</if>
<if test="record.customData != null">
custom_data = #{record.customData,jdbcType=LONGVARCHAR},
</if>
@ -251,15 +284,18 @@
<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},
custom_data = #{record.customData,jdbcType=LONGVARCHAR}
`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>
@ -267,14 +303,17 @@
<update id="updateByExample" 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}
`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}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -306,6 +345,15 @@
<if test="userId != null">
user_id = #{userId,jdbcType=VARCHAR},
</if>
<if test="workspaceId != null">
workspace_id = #{workspaceId,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=BIGINT},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=BIGINT},
</if>
<if test="customData != null">
custom_data = #{customData,jdbcType=LONGVARCHAR},
</if>
@ -322,6 +370,9 @@
`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>
@ -334,7 +385,10 @@
job = #{job,jdbcType=VARCHAR},
`enable` = #{enable,jdbcType=BIT},
resource_id = #{resourceId,jdbcType=VARCHAR},
user_id = #{userId,jdbcType=VARCHAR}
user_id = #{userId,jdbcType=VARCHAR},
workspace_id = #{workspaceId,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=BIGINT}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper>

View File

@ -0,0 +1,11 @@
package io.metersphere.base.mapper.ext;
import io.metersphere.controller.request.QueryScheduleRequest;
import io.metersphere.dto.ScheduleDao;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface ExtScheduleMapper {
List<ScheduleDao> list(@Param("request") QueryScheduleRequest request);
}

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="io.metersphere.base.mapper.ext.ExtScheduleMapper">
<select id="list" resultType="io.metersphere.dto.ScheduleDao">
select schedule.* from schedule
<where>
<if test="request.group != null">
and schedule.group = #{request.group}
</if>
<if test="request.workspaceId != null">
and schedule.workspace_id = #{request.workspaceId}
</if>
<if test="request.filters != null and request.filters.size() > 0">
<foreach collection="request.filters.entrySet()" index="key" item="values">
<if test="values != null and values.size() > 0">
<choose>
<when test="key=='type'">
and schedule.group in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
</choose>
</if>
</foreach>
</if>
</where>
<if test="request.orders != null and request.orders.size() > 0">
order by
<foreach collection="request.orders" separator="," item="order">
${order.name} ${order.type}
</foreach>
</if>
</select>
</mapper>

View File

@ -1,14 +1,25 @@
package io.metersphere.controller;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.controller.request.QueryScheduleRequest;
import io.metersphere.dto.ScheduleDao;
import io.metersphere.service.ScheduleService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@RequestMapping("schedule")
@RestController
public class ScheduleController {
@Resource
private ScheduleService scheduleService;
@PostMapping("/list/{goPage}/{pageSize}")
public List<ScheduleDao> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryScheduleRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return scheduleService.list(request);
}
}

View File

@ -0,0 +1,20 @@
package io.metersphere.controller.request;
import io.metersphere.base.domain.Schedule;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
@Getter
@Setter
public class QueryScheduleRequest extends Schedule implements Serializable {
private List<OrderRequest> orders;
private Map<String, List<String>> filters;
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,13 @@
package io.metersphere.dto;
import io.metersphere.base.domain.Schedule;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class ScheduleDao extends Schedule {
private String resourceName;
private String userName;
}

View File

@ -9,8 +9,10 @@ import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.controller.request.QueryScheduleRequest;
import io.metersphere.dto.DashboardTestDTO;
import io.metersphere.dto.LoadTestDTO;
import io.metersphere.dto.ScheduleDao;
import io.metersphere.performance.service.PerformanceTestService;
import io.metersphere.service.FileService;
import io.metersphere.track.request.testplan.*;
@ -141,4 +143,14 @@ public class PerformanceTestController {
performanceTestService.updateSchedule(request);
}
@PostMapping("/list/schedule/{goPage}/{pageSize}")
public List<ScheduleDao> listSchedule(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryScheduleRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return performanceTestService.listSchedule(request);
}
@PostMapping("/list/schedule")
public List<ScheduleDao> listSchedule(@RequestBody QueryScheduleRequest request) {
return performanceTestService.listSchedule(request);
}
}

View File

@ -12,8 +12,10 @@ import io.metersphere.commons.utils.ServiceUtils;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.config.KafkaProperties;
import io.metersphere.controller.request.OrderRequest;
import io.metersphere.controller.request.QueryScheduleRequest;
import io.metersphere.dto.DashboardTestDTO;
import io.metersphere.dto.LoadTestDTO;
import io.metersphere.dto.ScheduleDao;
import io.metersphere.i18n.Translator;
import io.metersphere.job.sechedule.PerformanceTestJob;
import io.metersphere.performance.engine.Engine;
@ -416,4 +418,17 @@ public class PerformanceTestService {
reportService.updateStatus(reportId, PerformanceTestStatus.Completed.name());
}
}
public List<ScheduleDao> listSchedule(QueryScheduleRequest request) {
List<ScheduleDao> schedules = scheduleService.list(request);
List<String> resourceIds = schedules.stream()
.map(Schedule::getResourceId)
.collect(Collectors.toList());
LoadTestExample example = new LoadTestExample();
example.createCriteria().andIdIn(resourceIds);
List<LoadTest> loadTests = loadTestMapper.selectByExample(example);
Map<String, String> loadTestMap = loadTests.stream().collect(Collectors.toMap(LoadTest::getId, LoadTest::getName));
scheduleService.build(loadTestMap, schedules);
return schedules;
}
}

View File

@ -3,10 +3,18 @@ package io.metersphere.service;
import com.alibaba.fastjson.JSON;
import io.metersphere.base.domain.Schedule;
import io.metersphere.base.domain.ScheduleExample;
import io.metersphere.base.domain.User;
import io.metersphere.base.domain.UserExample;
import io.metersphere.base.mapper.ScheduleMapper;
import io.metersphere.base.mapper.UserMapper;
import io.metersphere.base.mapper.ext.ExtScheduleMapper;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.commons.utils.ServiceUtils;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.controller.request.OrderRequest;
import io.metersphere.controller.request.QueryScheduleRequest;
import io.metersphere.dto.ScheduleDao;
import io.metersphere.job.sechedule.ApiTestJob;
import io.metersphere.job.sechedule.ScheduleManager;
import org.apache.commons.lang3.StringUtils;
@ -18,7 +26,9 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
@Service
@Transactional(rollbackFor = Exception.class)
@ -28,9 +38,16 @@ public class ScheduleService {
private ScheduleMapper scheduleMapper;
@Resource
private ScheduleManager scheduleManager;
@Resource
private ExtScheduleMapper extScheduleMapper;
@Resource
private UserMapper userMapper;
public void addSchedule(Schedule schedule) {
schedule.setId(UUID.randomUUID().toString());
schedule.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
schedule.setCreateTime(System.currentTimeMillis());
schedule.setUpdateTime(System.currentTimeMillis());
scheduleMapper.insert(schedule);
}
@ -39,6 +56,7 @@ public class ScheduleService {
}
public int editSchedule(Schedule schedule) {
schedule.setUpdateTime(System.currentTimeMillis());
return scheduleMapper.updateByPrimaryKeySelective(schedule);
}
@ -125,4 +143,23 @@ public class ScheduleService {
}
}
}
public List<ScheduleDao> list(QueryScheduleRequest request) {
List<OrderRequest> orderList = ServiceUtils.getDefaultOrder(request.getOrders());
request.setOrders(orderList);
return extScheduleMapper.list(request);
}
public void build(Map<String, String> resourceNameMap, List<ScheduleDao> schedules) {
List<String> userIds = schedules.stream()
.map(Schedule::getUserId)
.collect(Collectors.toList());
UserExample example = new UserExample();
example.createCriteria().andIdIn(userIds);
Map<String, String> userMap = userMapper.selectByExample(example).stream().collect(Collectors.toMap(User::getId, User::getName));
schedules.forEach(schedule -> {
schedule.setResourceName(resourceNameMap.get(schedule.getResourceId()));
schedule.setUserName(userMap.get(schedule.getUserId()));
});
}
}

View File

@ -0,0 +1,17 @@
ALTER TABLE `schedule` ADD `workspace_id` varchar(50) NOT NULL COMMENT 'Workspace ID this schedule belongs to';
ALTER TABLE `schedule` ADD `create_time` bigint(13) NULL COMMENT 'Create timestamp';
ALTER TABLE `schedule` ADD `update_time` bigint(13) NULL COMMENT 'Update timestamp';
UPDATE schedule INNER JOIN (
SELECT project.workspace_id AS workspace_id, api_test.id AS resource_id,
api_test.create_time AS create_time, api_test.update_time AS update_time
FROM schedule
LEFT JOIN api_test
ON schedule.resource_id = api_test.id
LEFT JOIN project
ON api_test.project_id = project.id
) result
SET schedule.workspace_id = result.workspace_id,
schedule.create_time = result.create_time,
schedule.update_time = result.update_time
WHERE schedule.resource_id = result.resource_id;

View File

@ -64,7 +64,7 @@
<!--要生成的数据库表 -->
<table tableName="test_case"/>
<table tableName="schedule"/>
</context>

View File

@ -13,6 +13,9 @@
<el-col :span="12">
<ms-test-heatmap :values="values"/>
</el-col>
<el-col :span="12">
<ms-api-test-schedule-list :group="'API_TEST'"/>
</el-col>
</el-row>
</ms-main-container>
</ms-container>
@ -25,11 +28,15 @@
import MsApiTestRecentList from "./ApiTestRecentList";
import MsApiReportRecentList from "./ApiReportRecentList";
import MsTestHeatmap from "../../common/components/MsTestHeatmap";
import MsApiTestScheduleList from "./ApiTestScheduleList";
export default {
name: "ApiTestHome",
components: {MsTestHeatmap, MsApiReportRecentList, MsApiTestRecentList, MsMainContainer, MsContainer},
components: {
MsApiTestScheduleList,
MsTestHeatmap, MsApiReportRecentList, MsApiTestRecentList, MsMainContainer, MsContainer
},
data() {
return {

View File

@ -0,0 +1,106 @@
<template>
<el-card class="table-card" v-loading="result.loading">
<template v-slot:header>
<span class="title">{{$t('commons.trigger_mode.schedule')}}</span>
</template>
<el-table height="289" border :data="tableData" class="adjust-table table-content" @row-click="link">
<el-table-column prop="resourceName" :label="$t('schedule.test_name')" width="150" show-overflow-tooltip/>
<el-table-column prop="value" :label="$t('schedule.running_rule')" width="150" show-overflow-tooltip/>
<el-table-column width="100px" :label="$t('schedule.job_status')">
<template v-slot:default="scope">
<el-switch @click.stop.native v-model="scope.row.enable" @change="update(scope.row)"/>
</template>
</el-table-column>
<el-table-column :label="$t('schedule.next_execution_time')">
<template v-slot:default="scope">
<crontab-result :enable-simple-mode="true" :ex="scope.row.value" ref="crontabResult"/>
</template>
</el-table-column>
<el-table-column :label="$t('report.user_name')" prop="userName"/>
<el-table-column :label="$t('commons.update_time')">
<template v-slot:default="scope">
<span>{{ scope.row.updateTime | timestampFormatDate }}</span>
</template>
</el-table-column>
</el-table>
</el-card>
</template>
<script>
import {getCurrentWorkspaceId} from "../../../../common/js/utils";
import CrontabResult from "../../common/cron/CrontabResult";
import {SCHEDULE_TYPE} from "../../../../common/js/constants";
export default {
name: "MsApiTestScheduleList",
components: {CrontabResult},
data() {
return {
result: {},
tableData: [],
loading: false,
operators: {}
}
},
props: {
group: String
},
watch: {
group() {
this.init();
}
},
methods: {
search() {
if (this.operators.listUrl) {
this.result = this.$post(this.operators.listUrl, {
workspaceId: getCurrentWorkspaceId(),
group: this.group
}, response => {
this.tableData = response.data;
});
}
},
link(row) {
this.$router.push({
path: this.operators.linkUrl + '?id=' + row.resourceId,
})
},
update(schedule) {
this.result = this.$post(this.operators.updateUrl, schedule, response => {
this.search();
});
},
init() {
switch (this.group) {
case SCHEDULE_TYPE.API_TEST:
this.operators.listUrl = '/api/list/schedule';
this.operators.updateUrl = '/api/schedule/update';
this.operators.linkUrl = '/api/test/edit';
break;
case SCHEDULE_TYPE.PERFORMANCE_TEST:
this.operators.listUrl = '/performance/list/schedule';
this.operators.updateUrl = '/performance/schedule/update';
this.operators.linkUrl = '/performance//test/edit';
break;
default:
break;
}
this.search();
}
},
created() {
this.init();
},
activated() {
this.init();
}
}
</script>
<style scoped>
.el-table {
cursor: pointer;
}
</style>

View File

@ -60,4 +60,8 @@
<style scoped>
.el-card {
height: 370px;
}
</style>

View File

@ -1,62 +1,71 @@
<template>
<div class="popup-result">
<p class="title">{{$t('schedule.cron.recent_run_time')}}</p>
<ul class="popup-result-scroll">
<template>
<li v-for='item in resultList' :key="item">{{item}}</li>
</template>
</ul>
</div>
<div>
<span v-if="enableSimpleMode">{{resultList && resultList.length > 0 ? resultList[0] : ''}}</span>
<div v-if="!enableSimpleMode" class="popup-result">
<p class="title">{{$t('schedule.cron.recent_run_time')}}</p>
<ul class="popup-result-scroll">
<template>
<li v-for='item in resultList' :key="item">{{item}}</li>
</template>
</ul>
</div>
</div>
</template>
<script>
import {cronValidate} from "../../../../common/js/cron";
import {cronValidate} from "../../../../common/js/cron";
export default {
name: 'CrontabResult',
data() {
return {
dayRule: '',
dayRuleSup: '',
dateArr: [],
resultList: [],
isShow: false
}
},
watch: {
'ex': 'expressionChange'
},
props: ['ex'],
mounted: function () {
//
this.expressionChange();
},
methods: {
//
expressionChange() {
// -
this.isShow = false;
if (!cronValidate(this.ex)) {
this.resultList = [];
this.$emit("resultListChange", this.resultList);
return;
export default {
name: 'CrontabResult',
data() {
return {
dayRule: '',
dayRuleSup: '',
dateArr: [],
resultList: [],
isShow: false
}
// [0123456]
let ruleArr = this.$options.propsData.ex.split(' ');
//
let nums = 0;
//
let resultArr = [];
// []
let nTime = new Date();
let nYear = nTime.getFullYear();
let nMouth = nTime.getMonth() + 1;
let nDay = nTime.getDate();
let nHour = nTime.getHours();
let nMin = nTime.getMinutes();
let nSecond = nTime.getSeconds();
// 100
this.getSecondArr(ruleArr[0]);
},
watch: {
'ex': 'expressionChange'
},
props: {
ex: String,
enableSimpleMode: {
type: Boolean,
default: false
}
},
mounted: function () {
//
this.expressionChange();
},
methods: {
//
expressionChange() {
// -
this.isShow = false;
if (!cronValidate(this.ex)) {
this.resultList = [];
this.$emit("resultListChange", this.resultList);
return;
}
// [0123456]
let ruleArr = this.$options.propsData.ex.split(' ');
//
let nums = 0;
//
let resultArr = [];
// []
let nTime = new Date();
let nYear = nTime.getFullYear();
let nMouth = nTime.getMonth() + 1;
let nDay = nTime.getDate();
let nHour = nTime.getHours();
let nMin = nTime.getMinutes();
let nSecond = nTime.getSeconds();
// 100
this.getSecondArr(ruleArr[0]);
this.getMinArr(ruleArr[1]);
this.getHourArr(ruleArr[2]);
this.getDayArr(ruleArr[3]);

View File

@ -19,6 +19,11 @@ export const ZH_CN = 'zh_CN';
export const ZH_TW = 'zh_TW';
export const EN_US = 'en_US';
export const SCHEDULE_TYPE = {
API_TEST: 'API_TEST',
PERFORMANCE_TEST: 'PERFORMANCE_TEST'
}
export const REQUEST_HEADERS = [
{value: 'Accept'},
{value: 'Accept-Charset'},

View File

@ -710,6 +710,9 @@ export default {
not_set: "Not Set",
next_execution_time: "Next Execution Time",
edit_timer_task: "Edit Timer Task",
test_name: 'Test Name',
running_rule: 'Rule',
job_status: 'Status',
please_input_cron_expression: "Please Input Cron Expression",
generate_expression: "Generate Expression",
cron_expression_format_error: "Cron Expression Format Error",

View File

@ -707,6 +707,9 @@ export default {
},
schedule: {
not_set: "未设置",
test_name: '测试名称',
running_rule: '运行规则',
job_status: '任务状态',
next_execution_time: "下次执行时间",
edit_timer_task: "编辑定时任务",
please_input_cron_expression: "请输入 Cron 表达式",

View File

@ -708,6 +708,9 @@ export default {
not_set: "未設置",
next_execution_time: "下次執行時間",
edit_timer_task: "編輯定時任務",
test_name: '測試名稱',
running_rule: '運行規則',
job_status: '任務狀態',
please_input_cron_expression: "請輸入 Cron 表達式",
generate_expression: "生成表達式",
cron_expression_format_error: "Cron 表達式格式錯誤",