fix(消息通知): swagger定时同步通知问题

--bug=1014692 --user=李玉号 【消息通知】swagger定时任务导入失败后没有通知
https://www.tapd.cn/55049933/s/1205391
--bug=1014691 --user=李玉号
【消息通知】swagger定时同步,同步成功后,没有发送企业微信通知
https://www.tapd.cn/55049933/s/1205397
This commit is contained in:
shiziyuan9527 2022-07-20 14:56:02 +08:00 committed by shiziyuan9527
parent 6a87a14ff7
commit 2727fd2ee2
2 changed files with 36 additions and 33 deletions

View File

@ -1549,15 +1549,17 @@ public class ApiDefinitionService {
} }
ApiImportParser runService = ApiDefinitionImportParserFactory.getApiImportParser(request.getPlatform()); ApiImportParser runService = ApiDefinitionImportParserFactory.getApiImportParser(request.getPlatform());
ApiDefinitionImport apiImport = null; ApiDefinitionImport apiImport = null;
Project project = projectMapper.selectByPrimaryKey(request.getProjectId());
if (StringUtils.isNotBlank(request.getSwaggerUrl())) { if (StringUtils.isNotBlank(request.getSwaggerUrl())) {
if (!request.getPlatform().equalsIgnoreCase("Swagger2")) { if (!request.getPlatform().equalsIgnoreCase("Swagger2")) {
this.sendFailMessage(request, project);
MSException.throwException("文件格式不符合要求"); MSException.throwException("文件格式不符合要求");
} }
if (!UrlTestUtils.testUrlWithTimeOut(request.getSwaggerUrl(), 30000)) { if (!UrlTestUtils.testUrlWithTimeOut(request.getSwaggerUrl(), 30000)) {
this.sendFailMessage(request, project);
MSException.throwException(Translator.get("connection_timeout")); MSException.throwException(Translator.get("connection_timeout"));
} }
} }
Project project = projectMapper.selectByPrimaryKey(request.getProjectId());
if (StringUtils.equals(request.getType(), "schedule")) { if (StringUtils.equals(request.getType(), "schedule")) {
request.setProtocol("HTTP"); request.setProtocol("HTTP");
} }
@ -1567,6 +1569,8 @@ public class ApiDefinitionService {
apiImport.setMocks(new ArrayList<>()); apiImport.setMocks(new ArrayList<>());
} }
} catch (Exception e) { } catch (Exception e) {
// 发送通知
this.sendFailMessage(request, project);
LogUtil.error(e.getMessage(), e); LogUtil.error(e.getMessage(), e);
String returnThrowException = e.getMessage(); String returnThrowException = e.getMessage();
if (StringUtils.contains(returnThrowException, "模块树最大深度为")) { if (StringUtils.contains(returnThrowException, "模块树最大深度为")) {
@ -1578,23 +1582,6 @@ public class ApiDefinitionService {
MSException.throwException(Translator.get("parse_data_error")); MSException.throwException(Translator.get("parse_data_error"));
} }
} }
// 发送通知
if (StringUtils.equals(request.getType(), "schedule")) {
String scheduleId = scheduleService.getScheduleInfo(request.getResourceId());
String context = request.getSwaggerUrl() + "导入失败";
Map<String, Object> 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 { try {
importApi(request, apiImport); importApi(request, apiImport);
@ -1621,12 +1608,32 @@ public class ApiDefinitionService {
noticeSendService.send(NoticeConstants.Mode.SCHEDULE, "", noticeModel); noticeSendService.send(NoticeConstants.Mode.SCHEDULE, "", noticeModel);
} }
} catch (Exception e) { } catch (Exception e) {
this.sendFailMessage(request, project);
LogUtil.error(e); LogUtil.error(e);
MSException.throwException(Translator.get("user_import_format_wrong")); MSException.throwException(Translator.get("user_import_format_wrong"));
} }
return apiImport; 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<String, Object> 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) { private void checkFileSuffixName(ApiTestImportRequest request, String suffixName) {
if (suffixName.equalsIgnoreCase("jmx")) { if (suffixName.equalsIgnoreCase("jmx")) {
if (!request.getPlatform().equalsIgnoreCase("JMeter")) { if (!request.getPlatform().equalsIgnoreCase("JMeter")) {

View File

@ -84,19 +84,20 @@ export default {
initForm() { initForm() {
this.result = this.$get('/notice/search/message/' + this.apiTestId, response => { this.result = this.$get('/notice/search/message/' + this.apiTestId, response => {
this.scheduleTask = response.data; this.scheduleTask = response.data;
this.scheduleTask.testId = this.apiTestId;
}); });
}, },
handleAddTaskModel() { handleAddTaskModel() {
let Task = {}; let task = {};
Task.event = []; task.event = [];
Task.userIds = []; task.userIds = [];
Task.type = ''; task.type = '';
Task.webhook = ''; task.webhook = '';
Task.isSet = true; task.isSet = true;
Task.identification = ''; task.identification = '';
Task.taskType = 'SWAGGER_URL'; task.taskType = 'SWAGGER_URL';
Task.testId = this.testId; task.testId = this.apiTestId;
this.scheduleTask.unshift(Task); this.scheduleTask.unshift(task);
}, },
handleTemplate(index, row) { handleTemplate(index, row) {
if (hasLicense()) { if (hasLicense()) {
@ -117,11 +118,6 @@ export default {
handleReceivers(row) { handleReceivers(row) {
row.receiverOptions = JSON.parse(JSON.stringify(this.scheduleReceiverOptions)); row.receiverOptions = JSON.parse(JSON.stringify(this.scheduleReceiverOptions));
}, },
},
watch: {
testId() {
this.initForm();
}
} }
}; };
</script> </script>