From 43b6f1560ce0d40da99bcee09d4cca356b2e63d4 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 23 Dec 2021 12:20:07 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9C=BA=E6=99=AF=E4=B8=AD=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E6=9C=AA=E5=8F=8A=E6=97=B6=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scenario/ApiScenarioSerialService.java | 6 +- .../ApiDefinitionExecResultService.java | 5 +- .../api/service/ApiScenarioReportService.java | 51 +++++-------- .../automation/scenario/EditApiScenario.vue | 1 + .../scenario/component/Jsr233Processor.vue | 75 ++++++++++++++++--- 5 files changed, 92 insertions(+), 46 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioSerialService.java b/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioSerialService.java index c0d75599a9..0860218f64 100644 --- a/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioSerialService.java +++ b/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioSerialService.java @@ -71,8 +71,10 @@ public class ApiScenarioSerialService { apiScenarioReportMapper.updateByPrimaryKey(report); } else { ApiDefinitionExecResult execResult = apiDefinitionExecResultMapper.selectByPrimaryKey(queue.getReportId()); - execResult.setStatus(APITestStatus.Running.name()); - apiDefinitionExecResultMapper.updateByPrimaryKey(execResult); + if (execResult != null) { + execResult.setStatus(APITestStatus.Running.name()); + apiDefinitionExecResultMapper.updateByPrimaryKey(execResult); + } } } diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java index 334c80965c..7ad7ebe403 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java @@ -317,7 +317,10 @@ public class ApiDefinitionExecResultService { private ApiDefinitionExecResult save(RequestResult item, String reportId, String console, int expectProcessResultCount, String type, String testId, boolean isFirst) { if (!StringUtils.startsWithAny(item.getName(), "PRE_PROCESSOR_ENV_", "POST_PROCESSOR_ENV_")) { - ApiDefinitionExecResult saveResult = new ApiDefinitionExecResult(); + ApiDefinitionExecResult saveResult = apiDefinitionExecResultMapper.selectByPrimaryKey(reportId); + if (saveResult == null) { + saveResult = new ApiDefinitionExecResult(); + } item.getResponseResult().setConsole(console); saveResult.setId(reportId); saveResult.setActuator("LOCAL"); diff --git a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java index a101e84404..edfb397b07 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java @@ -87,7 +87,6 @@ public class ApiScenarioReportService { apiScenarioReportResultService.save(dto.getReportId(), requestResults); } - public ApiScenarioReport testEnded(ResultDTO dto) { if (!StringUtils.equals(dto.getReportType(), RunModeConstants.SET_REPORT.toString())) { // 更新控制台信息 @@ -179,38 +178,26 @@ public class ApiScenarioReportService { } public ApiScenarioReport editReport(String reportType, String reportId, String status, String runMode) { - try { - ApiScenarioReport report = apiScenarioReportMapper.selectByPrimaryKey(reportId); - if (report == null) { - int index = 0; - while (index < 3) { - LogUtil.info("未获取到报告,尝试重新获取:【" + reportId + "】"); - report = apiScenarioReportMapper.selectByPrimaryKey(reportId); - Thread.sleep(2000); - index++; - } - } - if (report != null) { - if (StringUtils.equals(reportType, RunModeConstants.SET_REPORT.toString())) { - return report; - } - if (runMode.equals("CASE")) { - report.setTriggerMode(TriggerMode.MANUAL.name()); - } - report.setStatus(status); - report.setName(report.getScenarioName() + "-" + DateUtils.getTimeStr(System.currentTimeMillis())); - report.setEndTime(System.currentTimeMillis()); - report.setUpdateTime(System.currentTimeMillis()); - if (StringUtils.isNotEmpty(report.getTriggerMode()) && report.getTriggerMode().equals("CASE")) { - report.setTriggerMode(TriggerMode.MANUAL.name()); - } - apiScenarioReportMapper.updateByPrimaryKeySelective(report); - } - return report; - } catch (Exception e) { - LoggerUtil.error(e); + ApiScenarioReport report = apiScenarioReportMapper.selectByPrimaryKey(reportId); + if (report == null) { + report = new ApiScenarioReport(); + report.setId(reportId); } - return null; + if (StringUtils.equals(reportType, RunModeConstants.SET_REPORT.toString())) { + return report; + } + if (runMode.equals("CASE")) { + report.setTriggerMode(TriggerMode.MANUAL.name()); + } + report.setStatus(status); + report.setName(report.getScenarioName() + "-" + DateUtils.getTimeStr(System.currentTimeMillis())); + report.setEndTime(System.currentTimeMillis()); + report.setUpdateTime(System.currentTimeMillis()); + if (StringUtils.isNotEmpty(report.getTriggerMode()) && report.getTriggerMode().equals("CASE")) { + report.setTriggerMode(TriggerMode.MANUAL.name()); + } + apiScenarioReportMapper.updateByPrimaryKeySelective(report); + return report; } public ApiScenarioReport updateReport(APIScenarioReportResult test) { diff --git a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue index 79bd9b4ef8..89e7188d9e 100644 --- a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue @@ -1144,6 +1144,7 @@ export default { this.clearDebug(); this.clearResult(this.scenarioDefinition); this.clearNodeStatus(this.$refs.stepTree.root.childNodes); + this.sort(); /*触发执行操作*/ this.$refs.currentScenario.validate(async (valid) => { if (valid) { diff --git a/frontend/src/business/components/api/automation/scenario/component/Jsr233Processor.vue b/frontend/src/business/components/api/automation/scenario/component/Jsr233Processor.vue index e549ea8e74..d506d2a2f6 100644 --- a/frontend/src/business/components/api/automation/scenario/component/Jsr233Processor.vue +++ b/frontend/src/business/components/api/automation/scenario/component/Jsr233Processor.vue @@ -18,7 +18,16 @@ :node="node" :is-read-only="this.jsr223Processor.disabled"/> - + @@ -33,6 +42,8 @@ export default { name: "MsJsr233Processor", components: {Jsr233ProcessorContent, ApiBaseComponent, MsDropdown, MsInstructionsIcon, MsCodeEdit}, props: { + request: {}, + message: String, draggable: { type: Boolean, default: false, @@ -48,11 +59,11 @@ export default { isReadOnly: { type: Boolean, default: - false - }, - jsr223Processor: { - type: Object, - }, + false + }, + jsr223Processor: { + type: Object, + }, isPreProcessor: { type: Boolean, default: @@ -63,10 +74,39 @@ export default { backgroundColor: String, node: {}, }, + watch: { + message() { + this.forStatus(); + this.reload(); + }, + }, data() { - return {loading: false} + return { + loading: false, + reqSuccess: true + } }, methods: { + forStatus() { + if (this.jsr223Processor && this.jsr223Processor.result && this.jsr223Processor.result.length > 0) { + this.jsr223Processor.result.forEach(item => { + item.requestResult.forEach(req => { + if (!req.success) { + this.reqSuccess = req.success; + } + }) + }) + } else if (this.jsr223Processor && this.jsr223Processor.requestResult && this.jsr223Processor.requestResult.length > 1) { + this.jsr223Processor.requestResult.forEach(item => { + if (!item.success) { + this.reqSuccess = item.success; + if (this.node && this.node.parent && this.node.parent.data) { + this.node.parent.data.code = 'error'; + } + } + }) + } + }, remove() { this.$emit('remove', this.jsr223Processor, this.node); }, @@ -84,11 +124,24 @@ export default { this.reload(); }, } - } +}