From 8c469a689384ad984cdb0d095f2b1dd5b1da9545 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Wed, 20 Jul 2022 14:56:02 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B6=88=E6=81=AF=E9=80=9A=E7=9F=A5):=20sw?= =?UTF-8?q?agger=E5=AE=9A=E6=97=B6=E5=90=8C=E6=AD=A5=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1014692 --user=李玉号 【消息通知】swagger定时任务导入失败后没有通知 https://www.tapd.cn/55049933/s/1205391 --bug=1014691 --user=李玉号 【消息通知】swagger定时同步,同步成功后,没有发送企业微信通知 https://www.tapd.cn/55049933/s/1205397 --- .../api/service/ApiDefinitionService.java | 43 +++++++++++-------- .../import/SwaggerTaskNotification.vue | 26 +++++------ 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java index eed6b1d6b8..6c7356dca7 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -1549,15 +1549,17 @@ public class ApiDefinitionService { } ApiImportParser runService = ApiDefinitionImportParserFactory.getApiImportParser(request.getPlatform()); ApiDefinitionImport apiImport = null; + Project project = projectMapper.selectByPrimaryKey(request.getProjectId()); if (StringUtils.isNotBlank(request.getSwaggerUrl())) { if (!request.getPlatform().equalsIgnoreCase("Swagger2")) { + this.sendFailMessage(request, project); MSException.throwException("文件格式不符合要求"); } if (!UrlTestUtils.testUrlWithTimeOut(request.getSwaggerUrl(), 30000)) { + this.sendFailMessage(request, project); MSException.throwException(Translator.get("connection_timeout")); } } - Project project = projectMapper.selectByPrimaryKey(request.getProjectId()); if (StringUtils.equals(request.getType(), "schedule")) { request.setProtocol("HTTP"); } @@ -1567,6 +1569,8 @@ public class ApiDefinitionService { apiImport.setMocks(new ArrayList<>()); } } catch (Exception e) { + // 发送通知 + this.sendFailMessage(request, project); LogUtil.error(e.getMessage(), e); String returnThrowException = e.getMessage(); if (StringUtils.contains(returnThrowException, "模块树最大深度为")) { @@ -1578,23 +1582,6 @@ public class ApiDefinitionService { MSException.throwException(Translator.get("parse_data_error")); } } - // 发送通知 - if (StringUtils.equals(request.getType(), "schedule")) { - String scheduleId = scheduleService.getScheduleInfo(request.getResourceId()); - String context = request.getSwaggerUrl() + "导入失败"; - Map paramMap = new HashMap<>(); - paramMap.put("url", request.getSwaggerUrl()); - paramMap.put("projectId", request.getProjectId()); - NoticeModel noticeModel = NoticeModel.builder() - .operator(project.getCreateUser()) - .context(context) - .testId(scheduleId) - .subject(Translator.get("swagger_url_scheduled_import_notification")) - .paramMap(paramMap) - .event(NoticeConstants.Event.IMPORT) - .build(); - noticeSendService.send(NoticeConstants.TaskType.SWAGGER_TASK, noticeModel); - } } try { importApi(request, apiImport); @@ -1621,12 +1608,32 @@ public class ApiDefinitionService { noticeSendService.send(NoticeConstants.Mode.SCHEDULE, "", noticeModel); } } catch (Exception e) { + this.sendFailMessage(request, project); LogUtil.error(e); MSException.throwException(Translator.get("user_import_format_wrong")); } return apiImport; } + private void sendFailMessage(ApiTestImportRequest request, Project project) { + if (StringUtils.equals(request.getType(), "schedule")) { + String scheduleId = scheduleService.getScheduleInfo(request.getResourceId()); + String context = request.getSwaggerUrl() + "导入失败"; + Map paramMap = new HashMap<>(); + paramMap.put("url", request.getSwaggerUrl()); + paramMap.put("projectId", request.getProjectId()); + NoticeModel noticeModel = NoticeModel.builder() + .operator(project.getCreateUser()) + .context(context) + .testId(scheduleId) + .subject(Translator.get("swagger_url_scheduled_import_notification")) + .paramMap(paramMap) + .event(NoticeConstants.Event.EXECUTE_FAILED) + .build(); + noticeSendService.send(NoticeConstants.Mode.SCHEDULE, "", noticeModel); + } + } + private void checkFileSuffixName(ApiTestImportRequest request, String suffixName) { if (suffixName.equalsIgnoreCase("jmx")) { if (!request.getPlatform().equalsIgnoreCase("JMeter")) { diff --git a/frontend/src/business/components/api/definition/components/import/SwaggerTaskNotification.vue b/frontend/src/business/components/api/definition/components/import/SwaggerTaskNotification.vue index 1590ccc1d2..14abc4df07 100644 --- a/frontend/src/business/components/api/definition/components/import/SwaggerTaskNotification.vue +++ b/frontend/src/business/components/api/definition/components/import/SwaggerTaskNotification.vue @@ -84,19 +84,20 @@ export default { initForm() { this.result = this.$get('/notice/search/message/' + this.apiTestId, response => { this.scheduleTask = response.data; + this.scheduleTask.testId = this.apiTestId; }); }, handleAddTaskModel() { - let Task = {}; - Task.event = []; - Task.userIds = []; - Task.type = ''; - Task.webhook = ''; - Task.isSet = true; - Task.identification = ''; - Task.taskType = 'SWAGGER_URL'; - Task.testId = this.testId; - this.scheduleTask.unshift(Task); + let task = {}; + task.event = []; + task.userIds = []; + task.type = ''; + task.webhook = ''; + task.isSet = true; + task.identification = ''; + task.taskType = 'SWAGGER_URL'; + task.testId = this.apiTestId; + this.scheduleTask.unshift(task); }, handleTemplate(index, row) { if (hasLicense()) { @@ -117,11 +118,6 @@ export default { handleReceivers(row) { row.receiverOptions = JSON.parse(JSON.stringify(this.scheduleReceiverOptions)); }, - }, - watch: { - testId() { - this.initForm(); - } } };