From 002ace6b16db15b570f0c546f8d716ce7f5e7bff Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Tue, 4 Aug 2020 16:37:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95=E9=A6=96?= =?UTF-8?q?=E9=A1=B5=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/APITestController.java | 13 ++ .../api/service/APITestService.java | 15 ++ .../io/metersphere/base/domain/Schedule.java | 9 +- .../base/domain/ScheduleExample.java | 190 ++++++++++++++++++ .../base/mapper/ScheduleMapper.xml | 110 +++++++--- .../base/mapper/ext/ExtScheduleMapper.java | 11 + .../base/mapper/ext/ExtScheduleMapper.xml | 36 ++++ .../controller/ScheduleController.java | 15 +- .../request/QueryScheduleRequest.java | 20 ++ .../java/io/metersphere/dto/ScheduleDao.java | 13 ++ .../controller/PerformanceTestController.java | 12 ++ .../service/PerformanceTestService.java | 15 ++ .../metersphere/service/ScheduleService.java | 37 ++++ .../db/migration/V9__modify_schedule.sql | 17 ++ .../src/main/resources/generatorConfig.xml | 2 +- .../components/api/home/ApiTestHome.vue | 9 +- .../api/home/ApiTestScheduleList.vue | 106 ++++++++++ .../common/components/MsTestHeatmap.vue | 4 + .../components/common/cron/CrontabResult.vue | 115 ++++++----- frontend/src/common/js/constants.js | 5 + frontend/src/i18n/en-US.js | 3 + frontend/src/i18n/zh-CN.js | 3 + frontend/src/i18n/zh-TW.js | 3 + 23 files changed, 677 insertions(+), 86 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/base/mapper/ext/ExtScheduleMapper.java create mode 100644 backend/src/main/java/io/metersphere/base/mapper/ext/ExtScheduleMapper.xml create mode 100644 backend/src/main/java/io/metersphere/controller/request/QueryScheduleRequest.java create mode 100644 backend/src/main/java/io/metersphere/dto/ScheduleDao.java create mode 100644 backend/src/main/resources/db/migration/V9__modify_schedule.sql create mode 100644 frontend/src/business/components/api/home/ApiTestScheduleList.vue diff --git a/backend/src/main/java/io/metersphere/api/controller/APITestController.java b/backend/src/main/java/io/metersphere/api/controller/APITestController.java index 82e9a2819f..39c05e6652 100644 --- a/backend/src/main/java/io/metersphere/api/controller/APITestController.java +++ b/backend/src/main/java/io/metersphere/api/controller/APITestController.java @@ -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.*; @@ -102,4 +104,15 @@ public class APITestController { public List getProviders(@RequestBody RegistryCenter registry) { return apiTestService.getProviders(registry); } + + @PostMapping("/list/schedule/{goPage}/{pageSize}") + public List listSchedule(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryScheduleRequest request) { + Page page = PageHelper.startPage(goPage, pageSize, true); + return apiTestService.listSchedule(request); + } + + @PostMapping("/list/schedule") + public List listSchedule(@RequestBody QueryScheduleRequest request) { + return apiTestService.listSchedule(request); + } } diff --git a/backend/src/main/java/io/metersphere/api/service/APITestService.java b/backend/src/main/java/io/metersphere/api/service/APITestService.java index 44a25e32d9..12f763e550 100644 --- a/backend/src/main/java/io/metersphere/api/service/APITestService.java +++ b/backend/src/main/java/io/metersphere/api/service/APITestService.java @@ -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; @@ -313,4 +315,17 @@ public class APITestService { }); return list; } + + public List listSchedule(QueryScheduleRequest request) { + List schedules = scheduleService.list(request); + List resourceIds = schedules.stream() + .map(Schedule::getResourceId) + .collect(Collectors.toList()); + ApiTestExample example = new ApiTestExample(); + example.createCriteria().andIdIn(resourceIds); + List apiTests = apiTestMapper.selectByExample(example); + Map apiTestMap = apiTests.stream().collect(Collectors.toMap(ApiTest::getId, ApiTest::getName)); + scheduleService.build(apiTestMap, schedules); + return schedules; + } } diff --git a/backend/src/main/java/io/metersphere/base/domain/Schedule.java b/backend/src/main/java/io/metersphere/base/domain/Schedule.java index 1c6f2976e8..c92c80d081 100644 --- a/backend/src/main/java/io/metersphere/base/domain/Schedule.java +++ b/backend/src/main/java/io/metersphere/base/domain/Schedule.java @@ -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; diff --git a/backend/src/main/java/io/metersphere/base/domain/ScheduleExample.java b/backend/src/main/java/io/metersphere/base/domain/ScheduleExample.java index da9a199055..88a8639e63 100644 --- a/backend/src/main/java/io/metersphere/base/domain/ScheduleExample.java +++ b/backend/src/main/java/io/metersphere/base/domain/ScheduleExample.java @@ -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 values) { + addCriterion("workspace_id in", values, "workspaceId"); + return (Criteria) this; + } + + public Criteria andWorkspaceIdNotIn(List 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 values) { + addCriterion("create_time in", values, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotIn(List 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 values) { + addCriterion("update_time in", values, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeNotIn(List 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 { diff --git a/backend/src/main/java/io/metersphere/base/mapper/ScheduleMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ScheduleMapper.xml index 4ce95a2a3f..4e76ebcaea 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ScheduleMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ScheduleMapper.xml @@ -2,15 +2,18 @@ - - - - - - - - - + + + + + + + + + + + + @@ -74,7 +77,8 @@ - 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 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}) @@ -167,6 +173,15 @@ user_id, + + workspace_id, + + + create_time, + + + update_time, + custom_data, @@ -199,6 +214,15 @@ #{userId,jdbcType=VARCHAR}, + + #{workspaceId,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=BIGINT}, + + + #{updateTime,jdbcType=BIGINT}, + #{customData,jdbcType=LONGVARCHAR}, @@ -240,6 +264,15 @@ 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}, @@ -251,15 +284,18 @@ 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} @@ -267,14 +303,17 @@ 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} @@ -306,6 +345,15 @@ 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}, @@ -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} @@ -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} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtScheduleMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtScheduleMapper.java new file mode 100644 index 0000000000..f23d6590d3 --- /dev/null +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtScheduleMapper.java @@ -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 list(@Param("request") QueryScheduleRequest request); +} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtScheduleMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtScheduleMapper.xml new file mode 100644 index 0000000000..8738fdf285 --- /dev/null +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtScheduleMapper.xml @@ -0,0 +1,36 @@ + + + + + + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/controller/ScheduleController.java b/backend/src/main/java/io/metersphere/controller/ScheduleController.java index 0217d1a703..2c1e9759e6 100644 --- a/backend/src/main/java/io/metersphere/controller/ScheduleController.java +++ b/backend/src/main/java/io/metersphere/controller/ScheduleController.java @@ -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 list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryScheduleRequest request) { + Page page = PageHelper.startPage(goPage, pageSize, true); + return scheduleService.list(request); + } + } diff --git a/backend/src/main/java/io/metersphere/controller/request/QueryScheduleRequest.java b/backend/src/main/java/io/metersphere/controller/request/QueryScheduleRequest.java new file mode 100644 index 0000000000..bcea15e090 --- /dev/null +++ b/backend/src/main/java/io/metersphere/controller/request/QueryScheduleRequest.java @@ -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 orders; + + private Map> filters; + + private static final long serialVersionUID = 1L; +} diff --git a/backend/src/main/java/io/metersphere/dto/ScheduleDao.java b/backend/src/main/java/io/metersphere/dto/ScheduleDao.java new file mode 100644 index 0000000000..fc53b9a510 --- /dev/null +++ b/backend/src/main/java/io/metersphere/dto/ScheduleDao.java @@ -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; +} diff --git a/backend/src/main/java/io/metersphere/performance/controller/PerformanceTestController.java b/backend/src/main/java/io/metersphere/performance/controller/PerformanceTestController.java index 39001b136f..fbc5086d11 100644 --- a/backend/src/main/java/io/metersphere/performance/controller/PerformanceTestController.java +++ b/backend/src/main/java/io/metersphere/performance/controller/PerformanceTestController.java @@ -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 listSchedule(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryScheduleRequest request) { + Page page = PageHelper.startPage(goPage, pageSize, true); + return performanceTestService.listSchedule(request); + } + + @PostMapping("/list/schedule") + public List listSchedule(@RequestBody QueryScheduleRequest request) { + return performanceTestService.listSchedule(request); + } } diff --git a/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java index 2c58f48aee..380b5bbaa1 100644 --- a/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java +++ b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java @@ -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 listSchedule(QueryScheduleRequest request) { + List schedules = scheduleService.list(request); + List resourceIds = schedules.stream() + .map(Schedule::getResourceId) + .collect(Collectors.toList()); + LoadTestExample example = new LoadTestExample(); + example.createCriteria().andIdIn(resourceIds); + List loadTests = loadTestMapper.selectByExample(example); + Map loadTestMap = loadTests.stream().collect(Collectors.toMap(LoadTest::getId, LoadTest::getName)); + scheduleService.build(loadTestMap, schedules); + return schedules; + } } diff --git a/backend/src/main/java/io/metersphere/service/ScheduleService.java b/backend/src/main/java/io/metersphere/service/ScheduleService.java index 13c41490ba..6ba14f21db 100644 --- a/backend/src/main/java/io/metersphere/service/ScheduleService.java +++ b/backend/src/main/java/io/metersphere/service/ScheduleService.java @@ -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 list(QueryScheduleRequest request) { + List orderList = ServiceUtils.getDefaultOrder(request.getOrders()); + request.setOrders(orderList); + return extScheduleMapper.list(request); + } + + public void build(Map resourceNameMap, List schedules) { + List userIds = schedules.stream() + .map(Schedule::getUserId) + .collect(Collectors.toList()); + UserExample example = new UserExample(); + example.createCriteria().andIdIn(userIds); + Map 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())); + }); + } } diff --git a/backend/src/main/resources/db/migration/V9__modify_schedule.sql b/backend/src/main/resources/db/migration/V9__modify_schedule.sql new file mode 100644 index 0000000000..db4ba45fa5 --- /dev/null +++ b/backend/src/main/resources/db/migration/V9__modify_schedule.sql @@ -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; \ No newline at end of file diff --git a/backend/src/main/resources/generatorConfig.xml b/backend/src/main/resources/generatorConfig.xml index 2ceb91d446..55775a43d5 100644 --- a/backend/src/main/resources/generatorConfig.xml +++ b/backend/src/main/resources/generatorConfig.xml @@ -64,7 +64,7 @@ - +
diff --git a/frontend/src/business/components/api/home/ApiTestHome.vue b/frontend/src/business/components/api/home/ApiTestHome.vue index 6cf067c57e..431568988b 100644 --- a/frontend/src/business/components/api/home/ApiTestHome.vue +++ b/frontend/src/business/components/api/home/ApiTestHome.vue @@ -13,6 +13,9 @@ + + + @@ -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 { diff --git a/frontend/src/business/components/api/home/ApiTestScheduleList.vue b/frontend/src/business/components/api/home/ApiTestScheduleList.vue new file mode 100644 index 0000000000..3dc5d2e9af --- /dev/null +++ b/frontend/src/business/components/api/home/ApiTestScheduleList.vue @@ -0,0 +1,106 @@ + + + + + diff --git a/frontend/src/business/components/common/components/MsTestHeatmap.vue b/frontend/src/business/components/common/components/MsTestHeatmap.vue index 181df63622..16c00979d5 100644 --- a/frontend/src/business/components/common/components/MsTestHeatmap.vue +++ b/frontend/src/business/components/common/components/MsTestHeatmap.vue @@ -60,4 +60,8 @@ diff --git a/frontend/src/business/components/common/cron/CrontabResult.vue b/frontend/src/business/components/common/cron/CrontabResult.vue index 85bee44d22..fa7f206531 100644 --- a/frontend/src/business/components/common/cron/CrontabResult.vue +++ b/frontend/src/business/components/common/cron/CrontabResult.vue @@ -1,62 +1,71 @@