diff --git a/backend/src/main/java/io/metersphere/controller/LoadTestController.java b/backend/src/main/java/io/metersphere/controller/LoadTestController.java index 5bc6ef9aba..b626437a22 100644 --- a/backend/src/main/java/io/metersphere/controller/LoadTestController.java +++ b/backend/src/main/java/io/metersphere/controller/LoadTestController.java @@ -53,6 +53,11 @@ public class LoadTestController { loadTestService.delete(request); } + @PostMapping("/run") + public void delete(@RequestBody RunTestPlanRequest request) { + loadTestService.run(request); + } + @GetMapping("/file/metadata/{testId}") public FileMetadata getFileMetadata(@PathVariable String testId) { return fileService.getFileMetadataByTestId(testId); diff --git a/backend/src/main/java/io/metersphere/controller/request/testplan/RunTestPlanRequest.java b/backend/src/main/java/io/metersphere/controller/request/testplan/RunTestPlanRequest.java new file mode 100644 index 0000000000..f75f808021 --- /dev/null +++ b/backend/src/main/java/io/metersphere/controller/request/testplan/RunTestPlanRequest.java @@ -0,0 +1,4 @@ +package io.metersphere.controller.request.testplan; + +public class RunTestPlanRequest extends TestPlanRequest { +} diff --git a/backend/src/main/java/io/metersphere/service/LoadTestService.java b/backend/src/main/java/io/metersphere/service/LoadTestService.java index 2b4eee5787..11ba8322a0 100644 --- a/backend/src/main/java/io/metersphere/service/LoadTestService.java +++ b/backend/src/main/java/io/metersphere/service/LoadTestService.java @@ -6,10 +6,7 @@ import io.metersphere.base.mapper.ext.ExtLoadTestMapper; import io.metersphere.commons.constants.LoadTestFileType; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.IOUtils; -import io.metersphere.controller.request.testplan.DeleteTestPlanRequest; -import io.metersphere.controller.request.testplan.EditTestPlanRequest; -import io.metersphere.controller.request.testplan.QueryTestPlanRequest; -import io.metersphere.controller.request.testplan.SaveTestPlanRequest; +import io.metersphere.controller.request.testplan.*; import io.metersphere.dto.LoadTestDTO; import org.apache.commons.lang3.RandomUtils; import org.springframework.stereotype.Service; @@ -147,4 +144,13 @@ public class LoadTestService { loadTestMapper.updateByPrimaryKeySelective(loadTest); } } + + public void run(RunTestPlanRequest request) { + final LoadTestWithBLOBs loadTest = loadTestMapper.selectByPrimaryKey(request.getId()); + if (loadTest == null) { + MSException.throwException("无法运行测试,未找到测试:" + request.getId()); + } + + System.out.println("开始运行:" + loadTest.getName()); + } } diff --git a/frontend/src/common/filter.js b/frontend/src/common/filter.js index 9acd46cd07..c0d5cf8bbf 100644 --- a/frontend/src/common/filter.js +++ b/frontend/src/common/filter.js @@ -10,8 +10,36 @@ const options = function (value, array) { return value; }; +const timestampFormatDate = function (timestamp) { + if (!timestamp) { + return timestamp + } + + let date = new Date(timestamp); + + let y = date.getFullYear(); + + let MM = date.getMonth() + 1; + MM = MM < 10 ? ('0' + MM) : MM; + + let d = date.getDate(); + d = d < 10 ? ('0' + d) : d; + + let h = date.getHours(); + h = h < 10 ? ('0' + h) : h; + + let m = date.getMinutes(); + m = m < 10 ? ('0' + m) : m; + + let s = date.getSeconds(); + s = s < 10 ? ('0' + s) : s; + + return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s +}; + const filters = { "options": options, + "timestampFormatDate": timestampFormatDate, }; export default { diff --git a/frontend/src/performance/components/common/filter/TimestampFormatDateFilter.js b/frontend/src/performance/components/common/filter/TimestampFormatDateFilter.js deleted file mode 100644 index 678f3b9de3..0000000000 --- a/frontend/src/performance/components/common/filter/TimestampFormatDateFilter.js +++ /dev/null @@ -1,27 +0,0 @@ -let timestampFormatDate = function (timestamp) { - if (!timestamp) { - return timestamp - } - - let date = new Date(timestamp); - - let y = date.getFullYear(); - - let MM = date.getMonth() + 1; - MM = MM < 10 ? ('0' + MM) : MM; - - let d = date.getDate(); - d = d < 10 ? ('0' + d) : d; - - let h = date.getHours(); - h = h < 10 ? ('0' + h) : h; - - let m = date.getMinutes(); - m = m < 10 ? ('0' + m) : m; - - let s = date.getSeconds(); - s = s < 10 ? ('0' + s) : s; - - return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s -}; -export default timestampFormatDate diff --git a/frontend/src/performance/components/testPlan/CreateTestPlan.vue b/frontend/src/performance/components/testPlan/CreateTestPlan.vue index dafc54bd10..d9fb489ec5 100644 --- a/frontend/src/performance/components/testPlan/CreateTestPlan.vue +++ b/frontend/src/performance/components/testPlan/CreateTestPlan.vue @@ -51,6 +51,7 @@ listProjectPath: "/project/listAll", savePath: "/testplan/save", editPath: "/testplan/edit", + runPath: "/testplan/run", projects: [], active: '0', tabs: [{ @@ -85,28 +86,7 @@ return; } - let formData = new FormData(); - let url = this.testPlan.id ? this.editPath : this.savePath; - - if (!this.testPlan.file.id) { - formData.append("file", this.testPlan.file); - } - // file属性不需要json化 - let requestJson = JSON.stringify(this.testPlan, function (key, value) { - return key === "file" ? undefined : value - }); - formData.append('request', new Blob([requestJson], { - type: "application/json" - })); - - let options = { - method: 'POST', - url: url, - data: formData, - headers: { - 'Content-Type': undefined - } - }; + let options = this.getSaveOption(); this.$request(options).then(response => { if (response) { @@ -122,12 +102,48 @@ return; } - /// todo: saveAndRun - this.$message({ - message: '保存成功,开始运行!', - type: 'success' + let options = this.getSaveOption(); + + this.$request(options).then(response => { + if (response) { + this.$message({ + message: '保存成功!', + type: 'success' + }); + + this.$post(this.runPath, {id: this.testPlan.id}).then(() => { + this.$message({ + message: '正在运行!', + type: 'success' + }); + }) + } }); }, + getSaveOption() { + let formData = new FormData(); + let url = this.testPlan.id ? this.editPath : this.savePath; + + if (!this.testPlan.file.id) { + formData.append("file", this.testPlan.file); + } + // file属性不需要json化 + let requestJson = JSON.stringify(this.testPlan, function (key, value) { + return key === "file" ? undefined : value + }); + formData.append('request', new Blob([requestJson], { + type: "application/json" + })); + + return { + method: 'POST', + url: url, + data: formData, + headers: { + 'Content-Type': undefined + } + }; + }, cancel() { this.$router.push({path: '/'}) }, diff --git a/frontend/src/performance/main.js b/frontend/src/performance/main.js index b89abecb2b..db2d2fbcb4 100644 --- a/frontend/src/performance/main.js +++ b/frontend/src/performance/main.js @@ -8,7 +8,6 @@ import App from './App.vue'; import router from "./components/router/router"; import './permission' // permission control import i18n from "../i18n/i18n"; -import timestampFormatDate from "./components/common/filter/TimestampFormatDateFilter"; import store from "./store"; import {permission} from './permission' @@ -20,9 +19,6 @@ Vue.use(ElementUI, { Vue.use(filters); Vue.use(ajax); -// filter -Vue.filter('timestampFormatDate', timestampFormatDate); - // v-permission Vue.directive('permission', permission)