From 45636c518681d43fad9e88be28fd081d515932e4 Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Wed, 8 Sep 2021 14:38:04 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=8E=A5=E5=8F=A3=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=8C=96=E6=89=A7=E8=A1=8C=E5=8F=91=E9=80=81=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/service/ApiScenarioReportService.java | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) 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 5e60cdd7b0..2a30f16764 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java @@ -26,11 +26,13 @@ import io.metersphere.base.mapper.ApiScenarioReportMapper; import io.metersphere.base.mapper.TestPlanApiScenarioMapper; import io.metersphere.base.mapper.ext.ExtApiScenarioReportDetailMapper; import io.metersphere.base.mapper.ext.ExtApiScenarioReportMapper; +import io.metersphere.base.mapper.ext.ExtProjectMapper; import io.metersphere.commons.constants.*; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.*; import io.metersphere.dto.ApiReportCountDTO; import io.metersphere.dto.NodeDTO; +import io.metersphere.dto.UserDTO; import io.metersphere.i18n.Translator; import io.metersphere.log.utils.ReflexObjectUtil; import io.metersphere.log.vo.DetailColumn; @@ -38,6 +40,7 @@ import io.metersphere.log.vo.OperatingLogDetails; import io.metersphere.log.vo.api.ModuleReference; import io.metersphere.notice.sender.NoticeModel; import io.metersphere.notice.service.NoticeSendService; +import io.metersphere.service.UserService; import io.metersphere.track.service.TestPlanReportService; import org.apache.commons.beanutils.BeanMap; import org.apache.commons.collections4.CollectionUtils; @@ -79,6 +82,10 @@ public class ApiScenarioReportService { SqlSessionFactory sqlSessionFactory; @Resource private NoticeSendService noticeSendService; + @Resource + private UserService userService; + @Resource + private ExtProjectMapper extProjectMapper; public ApiScenarioReport complete(TestResult result, String runMode) { // 更新场景 @@ -596,7 +603,7 @@ public class ApiScenarioReportService { apiScenarioMapper.updateByPrimaryKey(scenario); // 发送通知 - sendNotice(scenario); + sendNotice(scenario, report); } lastReport = report; if (report.getExecuteType().equals(ExecuteType.Marge.name())) { @@ -615,28 +622,29 @@ public class ApiScenarioReportService { } - private void sendNotice(ApiScenario result) { + private void sendNotice(ApiScenario scenario, ApiScenarioReport result) { - BeanMap beanMap = new BeanMap(result); + BeanMap beanMap = new BeanMap(scenario); String event; String status; - if (StringUtils.equals(result.getLastResult(), "Success")) { + if (StringUtils.equals(scenario.getLastResult(), "Success")) { event = NoticeConstants.Event.EXECUTE_SUCCESSFUL; status = "成功"; } else { event = NoticeConstants.Event.EXECUTE_FAILED; status = "失败"; } + String userId = result.getCreateUser(); + UserDTO userDTO = userService.getUserDTO(userId); Map paramMap = new HashMap<>(beanMap); - if (SessionUtils.getUser() != null) { - paramMap.put("operator", SessionUtils.getUser().getName()); - } - paramMap.put("status", result.getLastResult()); + paramMap.put("operator", userDTO.getName()); + paramMap.put("status", scenario.getLastResult()); + String context = "${operator}执行接口自动化" + status + ": ${name}"; NoticeModel noticeModel = NoticeModel.builder() - .operator(SessionUtils.getUserId()) + .operator(userId) .context(context) .subject("接口自动化通知") .successMailTemplate("api/ScenarioResult") @@ -645,8 +653,8 @@ public class ApiScenarioReportService { .event(event) .build(); - String taskType = NoticeConstants.TaskType.API_AUTOMATION_TASK; - noticeSendService.send(taskType, noticeModel); + Organization organization = extProjectMapper.getOrganizationByProjectId(scenario.getProjectId()); + noticeSendService.send(organization, NoticeConstants.TaskType.API_AUTOMATION_TASK, noticeModel); } public String update(APIScenarioReportResult test) {