From 14cd8371e7600aaf67d45d28a4ded8c107d68b5b Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Mon, 17 Jun 2024 18:39:38 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92):=20?= =?UTF-8?q?=E8=AE=A1=E5=88=92=E6=89=A7=E8=A1=8C=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plan/service/TestPlanExecuteService.java | 2 +- .../plan/service/TestPlanReportService.java | 11 +++++-- .../service/TestPlanSendNoticeService.java | 33 +++++++++++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanExecuteService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanExecuteService.java index 20e23daa86..6532d9ef52 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanExecuteService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanExecuteService.java @@ -572,7 +572,7 @@ public class TestPlanExecuteService { // 执行生成报告, 执行状态为已完成, 执行及结束时间为当前时间 postParam.setEndTime(System.currentTimeMillis()); postParam.setExecStatus(ExecStatus.COMPLETED.name()); - testPlanReportService.postHandleReport(postParam); + testPlanReportService.postHandleReport(postParam, false); if (!isGroupReport) { TestPlanReport testPlanReport = testPlanReportService.selectById(reportId); diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanReportService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanReportService.java index 62701014c8..493664a4cc 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanReportService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanReportService.java @@ -92,6 +92,8 @@ public class TestPlanReportService { private TestPlanReportAttachmentMapper testPlanReportAttachmentMapper; @Resource private BaseUserMapper baseUserMapper; + @Resource + private TestPlanSendNoticeService testPlanSendNoticeService; /** * 分页查询报告列表 @@ -270,7 +272,7 @@ public class TestPlanReportService { postParam.setExecuteTime(System.currentTimeMillis()); postParam.setEndTime(System.currentTimeMillis()); postParam.setExecStatus(ExecStatus.COMPLETED.name()); - postHandleReport(postParam); + postHandleReport(postParam, true); } preReportMap.put(plan.getId(), preReport.getId()); }); @@ -458,7 +460,7 @@ public class TestPlanReportService { * * @param postParam 后置处理参数 */ - public void postHandleReport(TestPlanReportPostParam postParam) { + public void postHandleReport(TestPlanReportPostParam postParam, boolean useManual) { /* * 处理报告(执行状态, 结束时间) */ @@ -486,6 +488,11 @@ public class TestPlanReportService { } testPlanReportMapper.updateByPrimaryKeySelective(planReport); + + // 发送计划执行通知 + if (!useManual) { + testPlanSendNoticeService.sendExecuteNotice(planReport.getCreateUser(), planReport.getTestPlanId(), planReport.getProjectId(), planReport.getResultStatus()); + } } /** diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanSendNoticeService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanSendNoticeService.java index f6e4d26514..22b5f517f3 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanSendNoticeService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanSendNoticeService.java @@ -10,6 +10,7 @@ import io.metersphere.plan.dto.request.TestPlanCreateRequest; import io.metersphere.plan.dto.request.TestPlanUpdateRequest; import io.metersphere.plan.mapper.TestPlanConfigMapper; import io.metersphere.plan.mapper.TestPlanMapper; +import io.metersphere.sdk.constants.ReportStatus; import io.metersphere.sdk.constants.TestPlanConstants; import io.metersphere.sdk.util.BeanUtils; import io.metersphere.sdk.util.JSON; @@ -25,6 +26,7 @@ import org.apache.commons.beanutils.BeanMap; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -161,4 +163,35 @@ public class TestPlanSendNoticeService { } return null; } + + /** + * 报告汇总-计划执行结束通知 + * @param currentUser 当前用户 + * @param planId 计划ID + * @param projectId 项目ID + * @param executeResult 执行结果 + */ + @Async + public void sendExecuteNotice(String currentUser, String planId, String projectId, String executeResult) { + TestPlan testPlan = testPlanMapper.selectByPrimaryKey(planId); + if (testPlan != null) { + User user = userMapper.selectByPrimaryKey(currentUser); + setLanguage(user.getLanguage()); + Map defaultTemplateMap = MessageTemplateUtils.getDefaultTemplateMap(); + String template = defaultTemplateMap.get(StringUtils.equals(executeResult, ReportStatus.SUCCESS.name()) ? + NoticeConstants.TemplateText.TEST_PLAN_TASK_EXECUTE_SUCCESSFUL : NoticeConstants.TemplateText.TEST_PLAN_TASK_EXECUTE_FAILED); + Map defaultSubjectMap = MessageTemplateUtils.getDefaultTemplateSubjectMap(); + String subject = defaultSubjectMap.get(StringUtils.equals(executeResult, ReportStatus.SUCCESS.name()) ? + NoticeConstants.TemplateText.TEST_PLAN_TASK_EXECUTE_SUCCESSFUL : NoticeConstants.TemplateText.TEST_PLAN_TASK_EXECUTE_FAILED); + Map paramMap = new HashMap<>(4); + paramMap.put(NoticeConstants.RelatedUser.OPERATOR, user.getName()); + paramMap.put("name", testPlan.getName()); + paramMap.put("projectId", projectId); + paramMap.put("Language", user.getLanguage()); + NoticeModel noticeModel = NoticeModel.builder().operator(currentUser).excludeSelf(false) + .context(template).subject(subject).paramMap(paramMap).event(StringUtils.equals(executeResult, ReportStatus.SUCCESS.name()) ? + NoticeConstants.TemplateText.TEST_PLAN_TASK_EXECUTE_SUCCESSFUL : NoticeConstants.TemplateText.TEST_PLAN_TASK_EXECUTE_FAILED).build(); + noticeSendService.send(NoticeConstants.TaskType.TEST_PLAN_TASK, noticeModel); + } + } }