fix(测试计划): 修复报告通知的一揽子问题

--bug=1042840 --user=宋昌昌 【测试计划】报告-删除-接收人为创建人-删除人为其他用户-只有钉钉企业内部应用收到消息通知了 https://www.tapd.cn/55049933/s/1534860
This commit is contained in:
song-cc-rock 2024-06-24 14:53:00 +08:00 committed by 刘瑞斌
parent 87a30e8874
commit 08aad6f490
3 changed files with 17 additions and 4 deletions

View File

@ -16,8 +16,10 @@ import io.metersphere.functional.mapper.FunctionalCaseMapper;
import io.metersphere.plan.domain.TestPlan;
import io.metersphere.plan.domain.TestPlanFollower;
import io.metersphere.plan.domain.TestPlanFollowerExample;
import io.metersphere.plan.domain.TestPlanReport;
import io.metersphere.plan.mapper.TestPlanFollowerMapper;
import io.metersphere.plan.mapper.TestPlanMapper;
import io.metersphere.plan.mapper.TestPlanReportMapper;
import io.metersphere.sdk.util.JSON;
import io.metersphere.sdk.util.LogUtils;
import io.metersphere.system.domain.Schedule;
@ -74,6 +76,8 @@ public abstract class AbstractNoticeSender implements NoticeSender {
private ApiScenarioReportMapper apiScenarioReportMapper;
@Resource
private ScheduleMapper scheduleMapper;
@Resource
private TestPlanReportMapper testPlanReportMapper;
protected String getContext(MessageDetail messageDetail, NoticeModel noticeModel) {
@ -251,6 +255,12 @@ public abstract class AbstractNoticeSender implements NoticeSender {
receiver = new Receiver(schedule.getCreateUser(), NotificationConstants.Type.SYSTEM_NOTICE.name());
}
}
case NoticeConstants.TaskType.TEST_PLAN_REPORT_TASK -> {
TestPlanReport report = testPlanReportMapper.selectByPrimaryKey(id);
if (report != null) {
receiver = new Receiver(report.getCreateUser(), NotificationConstants.Type.SYSTEM_NOTICE.name());
}
}
default -> {
}
}

View File

@ -487,7 +487,7 @@ public class TestPlanReportService {
// 发送计划执行通知
if (!useManual) {
testPlanSendNoticeService.sendExecuteNotice(planReport.getCreateUser(), planReport.getTestPlanId(), planReport.getProjectId(), planReport.getResultStatus());
testPlanSendNoticeService.sendExecuteNotice(planReport.getCreateUser(), planReport.getTestPlanId(), planReport.getProjectId(), planReport.getResultStatus(), planReport.getTriggerMode());
}
}

View File

@ -10,6 +10,7 @@ import io.metersphere.plan.mapper.TestPlanConfigMapper;
import io.metersphere.plan.mapper.TestPlanFollowerMapper;
import io.metersphere.plan.mapper.TestPlanMapper;
import io.metersphere.sdk.constants.ReportStatus;
import io.metersphere.sdk.constants.TaskTriggerMode;
import io.metersphere.sdk.constants.TestPlanConstants;
import io.metersphere.sdk.util.BeanUtils;
import io.metersphere.sdk.util.JSON;
@ -178,7 +179,7 @@ public class TestPlanSendNoticeService {
* @param executeResult 执行结果
*/
@Async
public void sendExecuteNotice(String currentUser, String planId, String projectId, String executeResult) {
public void sendExecuteNotice(String currentUser, String planId, String projectId, String executeResult, String triggerMode) {
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(planId);
if (testPlan != null) {
User user = userMapper.selectByPrimaryKey(currentUser);
@ -193,11 +194,13 @@ public class TestPlanSendNoticeService {
paramMap.put(NoticeConstants.RelatedUser.OPERATOR, user.getName());
paramMap.put("name", testPlan.getName());
paramMap.put("projectId", projectId);
paramMap.put("id", planId);
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.Event.EXECUTE_SUCCESSFUL : NoticeConstants.Event.EXECUTE_FAIL).build();
noticeSendService.send(NoticeConstants.TaskType.TEST_PLAN_TASK, noticeModel);
NoticeConstants.Event.EXECUTE_SUCCESSFUL : NoticeConstants.Event.EXECUTE_FAILED).build();
noticeSendService.send(StringUtils.equals(TaskTriggerMode.API.name(), triggerMode) ?
NoticeConstants.TaskType.JENKINS_TASK : NoticeConstants.TaskType.TEST_PLAN_TASK, noticeModel);
}
}
}