feat: 消息设置性能测试
This commit is contained in:
parent
d9db503bb3
commit
55d41d50a2
|
@ -9,13 +9,14 @@ import io.metersphere.commons.constants.NoticeConstants;
|
|||
import io.metersphere.commons.constants.TestPlanTestCaseStatus;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.dto.BaseSystemConfigDTO;
|
||||
import io.metersphere.notice.domain.MessageDetail;
|
||||
import io.metersphere.notice.domain.MessageSettingDetail;
|
||||
import io.metersphere.notice.domain.NoticeDetail;
|
||||
import io.metersphere.notice.service.DingTaskService;
|
||||
import io.metersphere.notice.service.MailService;
|
||||
import io.metersphere.notice.service.NoticeService;
|
||||
import io.metersphere.notice.service.WxChatTaskService;
|
||||
import io.metersphere.service.SystemParameterService;
|
||||
import io.metersphere.track.service.TestPlanTestCaseService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.jmeter.assertions.AssertionResult;
|
||||
|
@ -24,7 +25,6 @@ import org.apache.jmeter.visualizers.backend.AbstractBackendListenerClient;
|
|||
import org.apache.jmeter.visualizers.backend.BackendListenerContext;
|
||||
import org.springframework.http.HttpMethod;
|
||||
|
||||
import javax.mail.MessagingException;
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
|
||||
|
@ -174,51 +174,55 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
|
|||
MailService mailService = CommonBeanFactory.getBean(MailService.class);
|
||||
DingTaskService dingTaskService = CommonBeanFactory.getBean(DingTaskService.class);
|
||||
WxChatTaskService wxChatTaskService = CommonBeanFactory.getBean(WxChatTaskService.class);
|
||||
if (StringUtils.equals(NoticeConstants.SCHEDULE, report.getTriggerMode())) {
|
||||
List<NoticeDetail> noticeList = noticeService.queryNotice(testResult.getTestId());
|
||||
mailService.sendApiNotification(report, noticeList);
|
||||
}
|
||||
if (StringUtils.equals(NoticeConstants.API, report.getTriggerMode())) {
|
||||
SystemParameterService systemParameterService = CommonBeanFactory.getBean(SystemParameterService.class);
|
||||
if (StringUtils.equals(NoticeConstants.API, report.getTriggerMode()) || StringUtils.equals(NoticeConstants.SCHEDULE, report.getTriggerMode())) {
|
||||
List<String> userIds = new ArrayList<>();
|
||||
List<MessageDetail> taskList = new ArrayList<>();
|
||||
String successContext = "";
|
||||
String failedContext = "";
|
||||
BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo();
|
||||
String url = baseSystemConfigDTO.getUrl() + "/#/api/report/view/" + report.getId();
|
||||
if (StringUtils.equals(NoticeConstants.API, report.getTriggerMode())) {
|
||||
MessageSettingDetail messageSettingDetail = noticeService.searchMessage();
|
||||
List<MessageDetail> taskList = messageSettingDetail.getJenkinsTask();
|
||||
String contextSuccess = "jenkins任务通知" + report.getName() + "执行成功";
|
||||
String contextFailed = "jenkins任务通知" + report.getName() + "执行失败";
|
||||
taskList = messageSettingDetail.getJenkinsTask();
|
||||
successContext = "jenkins任务通知:" + report.getName() + "执行成功" + "请点击下面链接进入测试报告页面" + url;
|
||||
failedContext = "jenkins任务通知:" + report.getName() + "执行失败" + "请点击下面链接进入测试报告页面" + url;
|
||||
}
|
||||
if (StringUtils.equals(NoticeConstants.SCHEDULE, report.getTriggerMode())) {
|
||||
taskList = noticeService.searchMessageSchedule(testResult.getTestId());
|
||||
successContext = "定时任务通知:" + report.getName() + "执行成功" + "请点击下面链接进入测试报告页面" + url;
|
||||
failedContext = "定时任务通知:" + report.getName() + "执行失败" + "请点击下面链接进入测试报告页面" + url;
|
||||
}
|
||||
String finalSuccessContext = successContext;
|
||||
String finalFailedContext = failedContext;
|
||||
taskList.forEach(r -> {
|
||||
switch (r.getType()) {
|
||||
case NoticeConstants.NAIL_ROBOT:
|
||||
if (StringUtils.equals(NoticeConstants.EXECUTE_SUCCESSFUL, r.getEvent()) && StringUtils.equals(report.getStatus(), "Success")) {
|
||||
dingTaskService.sendNailRobot(r, userIds, contextSuccess, NoticeConstants.EXECUTE_SUCCESSFUL);
|
||||
dingTaskService.sendNailRobot(r, userIds, finalSuccessContext, NoticeConstants.EXECUTE_SUCCESSFUL);
|
||||
}
|
||||
if (StringUtils.equals(NoticeConstants.EXECUTE_FAILED, r.getEvent()) && StringUtils.equals(report.getStatus(), "Error")) {
|
||||
dingTaskService.sendNailRobot(r, userIds, contextFailed, NoticeConstants.EXECUTE_FAILED);
|
||||
dingTaskService.sendNailRobot(r, userIds, finalFailedContext, NoticeConstants.EXECUTE_FAILED);
|
||||
}
|
||||
break;
|
||||
case NoticeConstants.WECHAT_ROBOT:
|
||||
if (StringUtils.equals(NoticeConstants.EXECUTE_SUCCESSFUL, r.getEvent()) && StringUtils.equals(report.getStatus(), "Success")) {
|
||||
wxChatTaskService.sendWechatRobot(r, userIds, contextSuccess, NoticeConstants.EXECUTE_SUCCESSFUL);
|
||||
wxChatTaskService.sendWechatRobot(r, userIds, finalSuccessContext, NoticeConstants.EXECUTE_SUCCESSFUL);
|
||||
}
|
||||
if (StringUtils.equals(NoticeConstants.EXECUTE_FAILED, r.getEvent()) && StringUtils.equals(report.getStatus(), "Error")) {
|
||||
wxChatTaskService.sendWechatRobot(r, userIds, contextFailed, NoticeConstants.EXECUTE_FAILED);
|
||||
wxChatTaskService.sendWechatRobot(r, userIds, finalFailedContext, NoticeConstants.EXECUTE_FAILED);
|
||||
}
|
||||
break;
|
||||
case NoticeConstants.EMAIL:
|
||||
if (StringUtils.equals(NoticeConstants.EXECUTE_SUCCESSFUL, r.getEvent()) && StringUtils.equals(report.getStatus(), "Success")) {
|
||||
try {
|
||||
mailService.sendApiJenkinsNotification(contextSuccess, r);
|
||||
} catch (MessagingException messagingException) {
|
||||
messagingException.printStackTrace();
|
||||
}
|
||||
mailService.sendApiNotification(r, report, NoticeConstants.EXECUTE_SUCCESSFUL);
|
||||
}
|
||||
if (StringUtils.equals(NoticeConstants.EXECUTE_FAILED, r.getEvent()) && StringUtils.equals(report.getStatus(), "Error")) {
|
||||
try {
|
||||
mailService.sendApiJenkinsNotification(contextFailed, r);
|
||||
} catch (MessagingException messagingException) {
|
||||
messagingException.printStackTrace();
|
||||
}
|
||||
mailService.sendApiNotification(r, report, NoticeConstants.EXECUTE_FAILED);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package io.metersphere.base.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class MessageTask implements Serializable {
|
||||
private String id;
|
||||
|
@ -23,5 +24,7 @@ public class MessageTask implements Serializable {
|
|||
|
||||
private String organizationId;
|
||||
|
||||
private String testId;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
|
@ -723,6 +723,76 @@ public class MessageTaskExample {
|
|||
addCriterion("organization_id not between", value1, value2, "organizationId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTestIdIsNull() {
|
||||
addCriterion("test_id is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTestIdIsNotNull() {
|
||||
addCriterion("test_id is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTestIdEqualTo(String value) {
|
||||
addCriterion("test_id =", value, "testId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTestIdNotEqualTo(String value) {
|
||||
addCriterion("test_id <>", value, "testId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTestIdGreaterThan(String value) {
|
||||
addCriterion("test_id >", value, "testId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTestIdGreaterThanOrEqualTo(String value) {
|
||||
addCriterion("test_id >=", value, "testId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTestIdLessThan(String value) {
|
||||
addCriterion("test_id <", value, "testId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTestIdLessThanOrEqualTo(String value) {
|
||||
addCriterion("test_id <=", value, "testId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTestIdLike(String value) {
|
||||
addCriterion("test_id like", value, "testId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTestIdNotLike(String value) {
|
||||
addCriterion("test_id not like", value, "testId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTestIdIn(List<String> values) {
|
||||
addCriterion("test_id in", values, "testId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTestIdNotIn(List<String> values) {
|
||||
addCriterion("test_id not in", values, "testId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTestIdBetween(String value1, String value2) {
|
||||
addCriterion("test_id between", value1, value2, "testId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTestIdNotBetween(String value1, String value2) {
|
||||
addCriterion("test_id not between", value1, value2, "testId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Criteria extends GeneratedCriteria {
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
<result column="identification" jdbcType="VARCHAR" property="identification" />
|
||||
<result column="is_set" jdbcType="BIT" property="isSet" />
|
||||
<result column="organization_id" jdbcType="VARCHAR" property="organizationId" />
|
||||
<result column="test_id" jdbcType="VARCHAR" property="testId"/>
|
||||
</resultMap>
|
||||
<sql id="Example_Where_Clause">
|
||||
<where>
|
||||
|
@ -71,7 +72,8 @@
|
|||
</where>
|
||||
</sql>
|
||||
<sql id="Base_Column_List">
|
||||
id, `type`, event, user_id, task_type, webhook, identification, is_set, organization_id
|
||||
id, `type`, event, user_id, task_type, webhook, identification, is_set, organization_id,
|
||||
test_id
|
||||
</sql>
|
||||
<select id="selectByExample" parameterType="io.metersphere.base.domain.MessageTaskExample" resultMap="BaseResultMap">
|
||||
select
|
||||
|
@ -106,12 +108,12 @@
|
|||
<insert id="insert" parameterType="io.metersphere.base.domain.MessageTask">
|
||||
insert into message_task (id, `type`, event,
|
||||
user_id, task_type, webhook,
|
||||
identification, is_set, organization_id
|
||||
)
|
||||
identification, is_set, organization_id,
|
||||
test_id)
|
||||
values (#{id,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR}, #{event,jdbcType=VARCHAR},
|
||||
#{userId,jdbcType=VARCHAR}, #{taskType,jdbcType=VARCHAR}, #{webhook,jdbcType=VARCHAR},
|
||||
#{identification,jdbcType=VARCHAR}, #{isSet,jdbcType=BIT}, #{organizationId,jdbcType=VARCHAR}
|
||||
)
|
||||
#{identification,jdbcType=VARCHAR}, #{isSet,jdbcType=BIT}, #{organizationId,jdbcType=VARCHAR},
|
||||
#{testId,jdbcType=VARCHAR})
|
||||
</insert>
|
||||
<insert id="insertSelective" parameterType="io.metersphere.base.domain.MessageTask">
|
||||
insert into message_task
|
||||
|
@ -143,6 +145,9 @@
|
|||
<if test="organizationId != null">
|
||||
organization_id,
|
||||
</if>
|
||||
<if test="testId != null">
|
||||
test_id,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">
|
||||
|
@ -172,6 +177,9 @@
|
|||
<if test="organizationId != null">
|
||||
#{organizationId,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="testId != null">
|
||||
#{testId,jdbcType=VARCHAR},
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<select id="countByExample" parameterType="io.metersphere.base.domain.MessageTaskExample" resultType="java.lang.Long">
|
||||
|
@ -210,6 +218,9 @@
|
|||
<if test="record.organizationId != null">
|
||||
organization_id = #{record.organizationId,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.testId != null">
|
||||
test_id = #{record.testId,jdbcType=VARCHAR},
|
||||
</if>
|
||||
</set>
|
||||
<if test="_parameter != null">
|
||||
<include refid="Update_By_Example_Where_Clause" />
|
||||
|
@ -225,7 +236,8 @@
|
|||
webhook = #{record.webhook,jdbcType=VARCHAR},
|
||||
identification = #{record.identification,jdbcType=VARCHAR},
|
||||
is_set = #{record.isSet,jdbcType=BIT},
|
||||
organization_id = #{record.organizationId,jdbcType=VARCHAR}
|
||||
organization_id = #{record.organizationId,jdbcType=VARCHAR},
|
||||
test_id = #{record.testId,jdbcType=VARCHAR}
|
||||
<if test="_parameter != null">
|
||||
<include refid="Update_By_Example_Where_Clause" />
|
||||
</if>
|
||||
|
@ -257,6 +269,9 @@
|
|||
<if test="organizationId != null">
|
||||
organization_id = #{organizationId,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="testId != null">
|
||||
test_id = #{testId,jdbcType=VARCHAR},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id,jdbcType=VARCHAR}
|
||||
</update>
|
||||
|
@ -269,7 +284,8 @@
|
|||
webhook = #{webhook,jdbcType=VARCHAR},
|
||||
identification = #{identification,jdbcType=VARCHAR},
|
||||
is_set = #{isSet,jdbcType=BIT},
|
||||
organization_id = #{organizationId,jdbcType=VARCHAR}
|
||||
organization_id = #{organizationId,jdbcType=VARCHAR},
|
||||
test_id = #{testId,jdbcType=VARCHAR}
|
||||
where id = #{id,jdbcType=VARCHAR}
|
||||
</update>
|
||||
</mapper>
|
|
@ -1,9 +1,8 @@
|
|||
package io.metersphere.notice.controller;
|
||||
|
||||
import io.metersphere.notice.controller.request.MessageRequest;
|
||||
import io.metersphere.notice.controller.request.NoticeRequest;
|
||||
import io.metersphere.notice.domain.MessageDetail;
|
||||
import io.metersphere.notice.domain.MessageSettingDetail;
|
||||
import io.metersphere.notice.domain.NoticeDetail;
|
||||
import io.metersphere.notice.service.NoticeService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
@ -16,16 +15,6 @@ public class NoticeController {
|
|||
@Resource
|
||||
private NoticeService noticeService;
|
||||
|
||||
@PostMapping("/save")
|
||||
public void saveNotice(@RequestBody NoticeRequest noticeRequest) {
|
||||
noticeService.saveNotice(noticeRequest);
|
||||
}
|
||||
|
||||
@GetMapping("/query/{testId}")
|
||||
public List<NoticeDetail> queryNotice(@PathVariable String testId) {
|
||||
return noticeService.queryNotice(testId);
|
||||
}
|
||||
|
||||
@PostMapping("save/message/task")
|
||||
public void saveMessage(@RequestBody MessageRequest messageRequest) {
|
||||
noticeService.saveMessageTask(messageRequest);
|
||||
|
@ -36,6 +25,11 @@ public class NoticeController {
|
|||
return noticeService.searchMessage();
|
||||
}
|
||||
|
||||
@GetMapping("/search/message/{testId}")
|
||||
public List<MessageDetail> searchMessageSchedule(@PathVariable String testId) {
|
||||
return noticeService.searchMessageSchedule(testId);
|
||||
}
|
||||
|
||||
@GetMapping("/delete/message/{identification}")
|
||||
public int deleteMessage(@PathVariable String identification) {
|
||||
return noticeService.delMessage(identification);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package io.metersphere.notice.domain;
|
||||
|
||||
import io.metersphere.base.domain.MessageTask;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -16,4 +15,5 @@ public class MessageDetail {
|
|||
private String identification;
|
||||
private String organizationId;
|
||||
private Boolean isSet;
|
||||
private String testId;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package io.metersphere.notice.service;
|
||||
|
||||
import io.metersphere.base.domain.ApiTestReport;
|
||||
import io.metersphere.base.domain.LoadTestWithBLOBs;
|
||||
import io.metersphere.base.domain.LoadTestReportWithBLOBs;
|
||||
import io.metersphere.base.domain.SystemParameter;
|
||||
import io.metersphere.base.domain.TestCaseWithBLOBs;
|
||||
import io.metersphere.commons.constants.APITestStatus;
|
||||
|
@ -14,7 +14,6 @@ import io.metersphere.commons.utils.LogUtil;
|
|||
import io.metersphere.dto.BaseSystemConfigDTO;
|
||||
import io.metersphere.i18n.Translator;
|
||||
import io.metersphere.notice.domain.MessageDetail;
|
||||
import io.metersphere.notice.domain.NoticeDetail;
|
||||
import io.metersphere.notice.domain.UserDetail;
|
||||
import io.metersphere.service.SystemParameterService;
|
||||
import io.metersphere.service.UserService;
|
||||
|
@ -27,7 +26,6 @@ import org.apache.commons.collections4.MapUtils;
|
|||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.RegExUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.mail.MailException;
|
||||
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -49,32 +47,33 @@ public class MailService {
|
|||
@Resource
|
||||
private SystemParameterService systemParameterService;
|
||||
|
||||
public void sendPerformanceNotification(List<NoticeDetail> noticeList, String status, LoadTestWithBLOBs loadTest, String id) {
|
||||
//接口和性能测试
|
||||
public void sendLoadNotification(MessageDetail messageDetail, LoadTestReportWithBLOBs loadTestReport, String eventType) {
|
||||
List<String> userIds = new ArrayList<>();
|
||||
BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo();
|
||||
Map<String, String> context = new HashMap<>();
|
||||
context.put("title", "Performance" + Translator.get("timing_task_result_notification"));
|
||||
context.put("testName", loadTest.getName());
|
||||
context.put("id", id);
|
||||
context.put("testName", loadTestReport.getName());
|
||||
context.put("id", loadTestReport.getId());
|
||||
context.put("type", "performance");
|
||||
context.put("url", baseSystemConfigDTO.getUrl());
|
||||
String performanceTemplate = "";
|
||||
try {
|
||||
if (StringUtils.equals(status, PerformanceTestStatus.Completed.name())) {
|
||||
performanceTemplate = IOUtils.toString(this.getClass().getResource("/mail/successPerformance.html"), StandardCharsets.UTF_8);
|
||||
} else if (StringUtils.equals(status, PerformanceTestStatus.Error.name())) {
|
||||
performanceTemplate = IOUtils.toString(this.getClass().getResource("/mail/failPerformance.html"), StandardCharsets.UTF_8);
|
||||
if (StringUtils.equals(loadTestReport.getStatus(), PerformanceTestStatus.Completed.name())) {
|
||||
performanceTemplate = IOUtils.toString(this.getClass().getResource("/mail/PerformanceApiSuccessNotification.html"), StandardCharsets.UTF_8);
|
||||
} else if (StringUtils.equals(loadTestReport.getStatus(), PerformanceTestStatus.Error.name())) {
|
||||
performanceTemplate = IOUtils.toString(this.getClass().getResource("/mail/PerformanceFailedNotification.html"), StandardCharsets.UTF_8);
|
||||
}
|
||||
sendHtmlTimeTasks(noticeList, status, context, performanceTemplate);
|
||||
sendApiOrLoadNotification(addresseeIdList(messageDetail, userIds, eventType), context, performanceTemplate, loadTestReport.getTriggerMode());
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void sendApiNotification(ApiTestReport apiTestReport, List<NoticeDetail> noticeList) {
|
||||
public void sendApiNotification(MessageDetail messageDetail, ApiTestReport apiTestReport, String eventType) {
|
||||
List<String> userIds = new ArrayList<>();
|
||||
BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo();
|
||||
Map<String, String> context = new HashMap<>();
|
||||
context.put("title", "api" + Translator.get("timing_task_result_notification"));
|
||||
context.put("testName", apiTestReport.getName());
|
||||
context.put("type", "api");
|
||||
context.put("url", baseSystemConfigDTO.getUrl());
|
||||
|
@ -82,95 +81,63 @@ public class MailService {
|
|||
String apiTemplate = "";
|
||||
try {
|
||||
if (StringUtils.equals(APITestStatus.Success.name(), apiTestReport.getStatus())) {
|
||||
apiTemplate = IOUtils.toString(this.getClass().getResource("/mail/success.html"), StandardCharsets.UTF_8);
|
||||
apiTemplate = IOUtils.toString(this.getClass().getResource("/mail/ApiSuccessfulNotification.html"), StandardCharsets.UTF_8);
|
||||
} else if (StringUtils.equals(APITestStatus.Error.name(), apiTestReport.getStatus())) {
|
||||
apiTemplate = IOUtils.toString(this.getClass().getResource("/mail/fail.html"), StandardCharsets.UTF_8);
|
||||
apiTemplate = IOUtils.toString(this.getClass().getResource("/mail/ApiFailedNotification.html"), StandardCharsets.UTF_8);
|
||||
}
|
||||
sendHtmlTimeTasks(noticeList, apiTestReport.getStatus(), context, apiTemplate);
|
||||
sendApiOrLoadNotification(addresseeIdList(messageDetail, userIds, eventType), context, apiTemplate, apiTestReport.getTriggerMode());
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
//jenkins
|
||||
public void sendApiJenkinsNotification(String context, MessageDetail messageDetail) throws MessagingException {
|
||||
private void sendApiOrLoadNotification(List<String> userIds, Map<String, String> context, String Template, String type) throws MessagingException {
|
||||
if (CollectionUtils.isEmpty(userIds)) {
|
||||
return;
|
||||
}
|
||||
JavaMailSenderImpl javaMailSender = getMailSender();
|
||||
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
|
||||
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
|
||||
helper.setFrom(javaMailSender.getUsername());
|
||||
if (StringUtils.equals(type, NoticeConstants.API)) {
|
||||
helper.setSubject("MeterSphere平台" + Translator.get("task_notification"));
|
||||
helper.setText(context);
|
||||
List<UserDetail> list = userService.queryTypeByIds(messageDetail.getUserIds());
|
||||
List<String> EmailList = new ArrayList<>();
|
||||
}
|
||||
if (StringUtils.equals(type, NoticeConstants.SCHEDULE)) {
|
||||
helper.setSubject("MeterSphere平台" + Translator.get("timing_task_notification"));
|
||||
}
|
||||
String[] users;
|
||||
List<String> emails = new ArrayList<>();
|
||||
List<UserDetail> list = userService.queryTypeByIds(userIds);
|
||||
list.forEach(u -> {
|
||||
EmailList.add(u.getEmail());
|
||||
emails.add(u.getEmail());
|
||||
});
|
||||
helper.setTo(EmailList.toArray(new String[0]));
|
||||
try {
|
||||
users = emails.toArray(new String[0]);
|
||||
helper.setText(getContent(Template, context), true);
|
||||
helper.setTo(users);
|
||||
javaMailSender.send(mimeMessage);
|
||||
} catch (MailException e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
}
|
||||
public void sendLoadJenkinsNotification(String context, MessageDetail messageDetail) throws MessagingException {
|
||||
JavaMailSenderImpl javaMailSender = getMailSender();
|
||||
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
|
||||
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
|
||||
helper.setFrom(javaMailSender.getUsername());
|
||||
helper.setSubject("MeterSphere平台" + Translator.get("task_notification"));
|
||||
helper.setText(context);
|
||||
List<UserDetail> list = userService.queryTypeByIds(messageDetail.getUserIds());
|
||||
List<String> EmailList = new ArrayList<>();
|
||||
list.forEach(u -> {
|
||||
EmailList.add(u.getEmail());
|
||||
});
|
||||
helper.setTo(EmailList.toArray(new String[0]));
|
||||
try {
|
||||
javaMailSender.send(mimeMessage);
|
||||
} catch (MailException e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendHtmlTimeTasks(List<NoticeDetail> noticeList, String status, Map<String, String> context, String template) throws MessagingException {
|
||||
JavaMailSenderImpl javaMailSender = getMailSender();
|
||||
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
|
||||
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
|
||||
helper.setFrom(javaMailSender.getUsername());
|
||||
helper.setSubject(Translator.get("timing_task_result_notification"));
|
||||
helper.setText(getContent(template, context), true);
|
||||
helper.setTo(getRecipientEmail(noticeList, status));
|
||||
try {
|
||||
javaMailSender.send(mimeMessage);
|
||||
} catch (MailException e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
//测试评审
|
||||
|
||||
public void sendEndNotice(MessageDetail messageDetail, List<String> userIds, SaveTestCaseReviewRequest reviewRequest, String eventType) {
|
||||
Map<String, String> context = getReviewContext(reviewRequest);
|
||||
try {
|
||||
String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/end.html"), StandardCharsets.UTF_8);
|
||||
String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/ReviewEnd.html"), StandardCharsets.UTF_8);
|
||||
sendReviewNotice(addresseeIdList(messageDetail, userIds, eventType), context, endTemplate);
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void sendDeleteNotice(MessageDetail messageDetail, List<String> userIds, SaveTestCaseReviewRequest reviewRequest, String eventType) {
|
||||
Map<String, String> context = getReviewContext(reviewRequest);
|
||||
try {
|
||||
String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/deleteReview.html"), StandardCharsets.UTF_8);
|
||||
String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/ReviewDelete.html"), StandardCharsets.UTF_8);
|
||||
sendReviewNotice(addresseeIdList(messageDetail, userIds, eventType), context, endTemplate);
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void sendCommentNotice(MessageDetail messageDetail, List<String> userIds, SaveCommentRequest request, TestCaseWithBLOBs testCaseWithBLOBs, String eventType) {
|
||||
BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo();
|
||||
Map<String, String> context = new HashMap<>();
|
||||
|
@ -180,74 +147,139 @@ public class MailService {
|
|||
context.put("url", baseSystemConfigDTO.getUrl());
|
||||
context.put("id", testCaseWithBLOBs.getId());
|
||||
try {
|
||||
String commentTemplate = IOUtils.toString(this.getClass().getResource("/mail/comment.html"), StandardCharsets.UTF_8);
|
||||
String commentTemplate = IOUtils.toString(this.getClass().getResource("/mail/ReviewComments.html"), StandardCharsets.UTF_8);
|
||||
sendReviewNotice(addresseeIdList(messageDetail, userIds, eventType), context, commentTemplate);
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
//新建评审
|
||||
public void sendReviewerNotice(MessageDetail messageDetail, List<String> userIds, SaveTestCaseReviewRequest reviewRequest, String eventType) {
|
||||
Map<String, String> context = getReviewContext(reviewRequest);
|
||||
try {
|
||||
String reviewerTemplate = IOUtils.toString(this.getClass().getResource("/mail/reviewer.html"), StandardCharsets.UTF_8);
|
||||
String reviewerTemplate = IOUtils.toString(this.getClass().getResource("/mail/ReviewInitiate.html"), StandardCharsets.UTF_8);
|
||||
sendReviewNotice(addresseeIdList(messageDetail, userIds, eventType), context, reviewerTemplate);
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendReviewNotice(List<String> userIds, Map<String, String> context, String Template) throws MessagingException {
|
||||
if (CollectionUtils.isEmpty(userIds)) {
|
||||
return;
|
||||
}
|
||||
JavaMailSenderImpl javaMailSender = getMailSender();
|
||||
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
|
||||
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
|
||||
helper.setFrom(javaMailSender.getUsername());
|
||||
helper.setSubject("MeterSphere平台" + Translator.get("test_review_task_notice"));
|
||||
String[] users;
|
||||
List<String> emails = new ArrayList<>();
|
||||
List<UserDetail> list = userService.queryTypeByIds(userIds);
|
||||
list.forEach(u -> {
|
||||
emails.add(u.getEmail());
|
||||
});
|
||||
users = emails.toArray(new String[0]);
|
||||
helper.setText(getContent(Template, context), true);
|
||||
helper.setTo(users);
|
||||
if (users.length > 0) {
|
||||
javaMailSender.send(mimeMessage);
|
||||
}
|
||||
}
|
||||
|
||||
//测试计划
|
||||
|
||||
public void sendTestPlanStartNotice(MessageDetail messageDetail, List<String> userIds, AddTestPlanRequest testPlan, String eventType) {
|
||||
Map<String, String> context = getTestPlanContext(testPlan);
|
||||
context.put("creator", testPlan.getCreator());
|
||||
try {
|
||||
String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/testPlanStart.html"), StandardCharsets.UTF_8);
|
||||
String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/TestPlanStart.html"), StandardCharsets.UTF_8);
|
||||
sendTestPlanNotice(addresseeIdList(messageDetail, userIds, eventType), context, endTemplate);
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void sendTestPlanEndNotice(MessageDetail messageDetail, List<String> userIds, AddTestPlanRequest testPlan, String eventType) {
|
||||
Map<String, String> context = getTestPlanContext(testPlan);
|
||||
context.put("creator", userIds.toString());
|
||||
try {
|
||||
String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/testPlanEnd.html"), StandardCharsets.UTF_8);
|
||||
String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/TestPlanEnd.html"), StandardCharsets.UTF_8);
|
||||
sendTestPlanNotice(addresseeIdList(messageDetail, userIds, eventType), context, endTemplate);
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void sendTestPlanDeleteNotice(MessageDetail messageDetail, List<String> userIds, AddTestPlanRequest testPlan, String eventType) {
|
||||
Map<String, String> context = getTestPlanContext(testPlan);
|
||||
context.put("creator", userIds.toString());
|
||||
try {
|
||||
String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/testPlanDelete.html"), StandardCharsets.UTF_8);
|
||||
String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/TestPlanDelete.html"), StandardCharsets.UTF_8);
|
||||
sendTestPlanNotice(addresseeIdList(messageDetail, userIds, eventType), context, endTemplate);
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendTestPlanNotice(List<String> userIds, Map<String, String> context, String Template) throws MessagingException {
|
||||
if (CollectionUtils.isEmpty(userIds)) {
|
||||
return;
|
||||
}
|
||||
JavaMailSenderImpl javaMailSender = getMailSender();
|
||||
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
|
||||
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
|
||||
helper.setFrom(javaMailSender.getUsername());
|
||||
helper.setSubject("MeterSphere平台" + Translator.get("test_plan_notification"));
|
||||
String[] users;
|
||||
List<String> emails = new ArrayList<>();
|
||||
List<UserDetail> list = userService.queryTypeByIds(userIds);
|
||||
list.forEach(u -> {
|
||||
emails.add(u.getEmail());
|
||||
});
|
||||
users = emails.toArray(new String[0]);
|
||||
helper.setText(getContent(Template, context), true);
|
||||
helper.setTo(users);
|
||||
javaMailSender.send(mimeMessage);
|
||||
|
||||
}
|
||||
|
||||
//缺陷任务
|
||||
public void sendIssuesNotice(MessageDetail messageDetail, List<String> userIds, IssuesRequest issuesRequest, String eventType, SessionUser user) {
|
||||
Map<String, String> context = new HashMap<>();
|
||||
context.put("issuesName", issuesRequest.getTitle());
|
||||
context.put("creator", user.getName());
|
||||
try {
|
||||
String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/issuesCreate.html"), StandardCharsets.UTF_8);
|
||||
String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/IssuesCreate.html"), StandardCharsets.UTF_8);
|
||||
sendIssuesNotice(addresseeIdList(messageDetail, userIds, eventType), context, endTemplate);
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendIssuesNotice(List<String> userIds, Map<String, String> context, String Template) throws MessagingException {
|
||||
if (CollectionUtils.isEmpty(userIds)) {
|
||||
return;
|
||||
}
|
||||
JavaMailSenderImpl javaMailSender = getMailSender();
|
||||
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
|
||||
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
|
||||
helper.setFrom(javaMailSender.getUsername());
|
||||
helper.setSubject("MeterSphere平台" + Translator.get("task_defect_notification"));
|
||||
String[] users;
|
||||
List<String> emails = new ArrayList<>();
|
||||
List<UserDetail> list = userService.queryTypeByIds(userIds);
|
||||
list.forEach(u -> {
|
||||
emails.add(u.getEmail());
|
||||
});
|
||||
users = emails.toArray(new String[0]);
|
||||
helper.setText(getContent(Template, context), true);
|
||||
helper.setTo(users);
|
||||
javaMailSender.send(mimeMessage);
|
||||
|
||||
}
|
||||
|
||||
//评审内容
|
||||
private Map<String, String> getReviewContext(SaveTestCaseReviewRequest reviewRequest) {
|
||||
Long startTime = reviewRequest.getCreateTime();
|
||||
Long endTime = reviewRequest.getEndTime();
|
||||
|
@ -274,6 +306,7 @@ public class MailService {
|
|||
return context;
|
||||
}
|
||||
|
||||
//计划内容
|
||||
private Map<String, String> getTestPlanContext(AddTestPlanRequest testPlan) {
|
||||
Long startTime = testPlan.getPlannedStartTime();
|
||||
Long endTime = testPlan.getPlannedEndTime();
|
||||
|
@ -299,72 +332,8 @@ public class MailService {
|
|||
return context;
|
||||
}
|
||||
|
||||
private void sendReviewNotice(List<String> userIds, Map<String, String> context, String Template) throws MessagingException {
|
||||
if (CollectionUtils.isEmpty(userIds)) {
|
||||
return;
|
||||
}
|
||||
JavaMailSenderImpl javaMailSender = getMailSender();
|
||||
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
|
||||
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
|
||||
helper.setFrom(javaMailSender.getUsername());
|
||||
helper.setSubject("MeterSphere平台" + Translator.get("test_review_task_notice"));
|
||||
String[] users;
|
||||
List<String> emails = new ArrayList<>();
|
||||
List<UserDetail> list = userService.queryTypeByIds(userIds);
|
||||
list.forEach(u -> {
|
||||
emails.add(u.getEmail());
|
||||
});
|
||||
users = emails.toArray(new String[0]);
|
||||
helper.setText(getContent(Template, context), true);
|
||||
helper.setTo(users);
|
||||
if (users.length > 0) {
|
||||
javaMailSender.send(mimeMessage);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendTestPlanNotice(List<String> userIds, Map<String, String> context, String Template) throws MessagingException {
|
||||
if (CollectionUtils.isEmpty(userIds)) {
|
||||
return;
|
||||
}
|
||||
JavaMailSenderImpl javaMailSender = getMailSender();
|
||||
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
|
||||
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
|
||||
helper.setFrom(javaMailSender.getUsername());
|
||||
helper.setSubject("MeterSphere平台" + Translator.get("test_plan_notification"));
|
||||
String[] users;
|
||||
List<String> emails = new ArrayList<>();
|
||||
List<UserDetail> list = userService.queryTypeByIds(userIds);
|
||||
list.forEach(u -> {
|
||||
emails.add(u.getEmail());
|
||||
});
|
||||
users = emails.toArray(new String[0]);
|
||||
helper.setText(getContent(Template, context), true);
|
||||
helper.setTo(users);
|
||||
javaMailSender.send(mimeMessage);
|
||||
|
||||
}
|
||||
|
||||
private void sendIssuesNotice(List<String> userIds, Map<String, String> context, String Template) throws MessagingException {
|
||||
if (CollectionUtils.isEmpty(userIds)) {
|
||||
return;
|
||||
}
|
||||
JavaMailSenderImpl javaMailSender = getMailSender();
|
||||
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
|
||||
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
|
||||
helper.setFrom(javaMailSender.getUsername());
|
||||
helper.setSubject("MeterSphere平台" + Translator.get("task_defect_notification"));
|
||||
String[] users;
|
||||
List<String> emails = new ArrayList<>();
|
||||
List<UserDetail> list = userService.queryTypeByIds(userIds);
|
||||
list.forEach(u -> {
|
||||
emails.add(u.getEmail());
|
||||
});
|
||||
users = emails.toArray(new String[0]);
|
||||
helper.setText(getContent(Template, context), true);
|
||||
helper.setTo(users);
|
||||
javaMailSender.send(mimeMessage);
|
||||
|
||||
}
|
||||
|
||||
private JavaMailSenderImpl getMailSender() {
|
||||
JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
|
||||
|
@ -404,7 +373,7 @@ public class MailService {
|
|||
for (String k : context.keySet()) {
|
||||
if (StringUtils.isNotBlank(context.get(k))) {
|
||||
template = RegExUtils.replaceAll(template, "\\$\\{" + k + "}", context.get(k));
|
||||
}else{
|
||||
} else {
|
||||
template = RegExUtils.replaceAll(template, "\\$\\{" + k + "}", "");
|
||||
}
|
||||
}
|
||||
|
@ -412,37 +381,6 @@ public class MailService {
|
|||
return template;
|
||||
}
|
||||
|
||||
private String[] getRecipientEmail(List<NoticeDetail> noticeList, String status) {
|
||||
String[] recipientEmails;
|
||||
List<String> successEmailList = new ArrayList<>();
|
||||
List<String> failEmailList = new ArrayList<>();
|
||||
if (noticeList.size() > 0) {
|
||||
for (NoticeDetail n : noticeList) {
|
||||
if (StringUtils.equals(n.getEnable(), "true") && StringUtils.equals(n.getEvent(), NoticeConstants.EXECUTE_SUCCESSFUL)) {
|
||||
List<UserDetail> list = userService.queryTypeByIds(n.getUserIds());
|
||||
list.forEach(u -> {
|
||||
successEmailList.add(u.getEmail());
|
||||
});
|
||||
}
|
||||
if (StringUtils.equals(n.getEnable(), "true") && StringUtils.equals(n.getEvent(), NoticeConstants.EXECUTE_FAILED)) {
|
||||
List<UserDetail> list = userService.queryTypeByIds(n.getUserIds());
|
||||
list.forEach(u -> {
|
||||
failEmailList.add(u.getEmail());
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
LogUtil.error("Recipient information is empty");
|
||||
}
|
||||
|
||||
if (StringUtils.equalsAny(status, PerformanceTestStatus.Completed.name(), APITestStatus.Success.name())) {
|
||||
recipientEmails = successEmailList.toArray(new String[0]);
|
||||
} else {
|
||||
recipientEmails = failEmailList.toArray(new String[0]);
|
||||
}
|
||||
return recipientEmails;
|
||||
}
|
||||
|
||||
private List<String> addresseeIdList(MessageDetail messageDetail, List<String> userIds, String eventType) {
|
||||
List<String> addresseeIdList = new ArrayList<>();
|
||||
if (StringUtils.equals(eventType, messageDetail.getEvent())) {
|
||||
|
@ -468,6 +406,7 @@ public class MailService {
|
|||
}
|
||||
return addresseeIdList;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2,19 +2,13 @@ package io.metersphere.notice.service;
|
|||
|
||||
import io.metersphere.base.domain.MessageTask;
|
||||
import io.metersphere.base.domain.MessageTaskExample;
|
||||
import io.metersphere.base.domain.Notice;
|
||||
import io.metersphere.base.domain.NoticeExample;
|
||||
import io.metersphere.base.mapper.MessageTaskMapper;
|
||||
import io.metersphere.base.mapper.NoticeMapper;
|
||||
import io.metersphere.commons.constants.NoticeConstants;
|
||||
import io.metersphere.commons.user.SessionUser;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.metersphere.notice.controller.request.MessageRequest;
|
||||
import io.metersphere.notice.controller.request.NoticeRequest;
|
||||
import io.metersphere.notice.domain.MessageDetail;
|
||||
import io.metersphere.notice.domain.MessageSettingDetail;
|
||||
import io.metersphere.notice.domain.NoticeDetail;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
@ -22,79 +16,22 @@ import javax.annotation.Resource;
|
|||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static io.metersphere.commons.constants.NoticeConstants.EXECUTE_FAILED;
|
||||
import static io.metersphere.commons.constants.NoticeConstants.EXECUTE_SUCCESSFUL;
|
||||
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class NoticeService {
|
||||
@Resource
|
||||
private NoticeMapper noticeMapper;
|
||||
@Resource
|
||||
private MessageTaskMapper messageTaskMapper;
|
||||
|
||||
public void saveNotice(NoticeRequest noticeRequest) {
|
||||
NoticeExample example = new NoticeExample();
|
||||
example.createCriteria().andTestIdEqualTo(noticeRequest.getTestId());
|
||||
List<Notice> notices = noticeMapper.selectByExample(example);
|
||||
if (notices.size() > 0) {
|
||||
noticeMapper.deleteByExample(example);
|
||||
}
|
||||
noticeRequest.getNotices().forEach(n -> {
|
||||
if (CollectionUtils.isNotEmpty(n.getUserIds())) {
|
||||
for (String x : n.getUserIds()) {
|
||||
Notice notice = new Notice();
|
||||
notice.setId(UUID.randomUUID().toString());
|
||||
notice.setEvent(n.getEvent());
|
||||
notice.setEnable(n.getEnable());
|
||||
notice.setTestId(noticeRequest.getTestId());
|
||||
notice.setUserId(x);
|
||||
notice.setType(n.getType());
|
||||
noticeMapper.insert(notice);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public List<NoticeDetail> queryNotice(String id) {
|
||||
NoticeExample example = new NoticeExample();
|
||||
example.createCriteria().andTestIdEqualTo(id);
|
||||
List<Notice> notices = noticeMapper.selectByExample(example);
|
||||
List<NoticeDetail> result = new ArrayList<>();
|
||||
List<String> successList = new ArrayList<>();
|
||||
List<String> failList = new ArrayList<>();
|
||||
NoticeDetail notice1 = new NoticeDetail();
|
||||
NoticeDetail notice2 = new NoticeDetail();
|
||||
if (notices.size() > 0) {
|
||||
for (Notice n : notices) {
|
||||
if (n.getEvent().equals(EXECUTE_SUCCESSFUL)) {
|
||||
successList.add(n.getUserId());
|
||||
notice1.setEnable(n.getEnable());
|
||||
notice1.setTestId(id);
|
||||
notice1.setType(n.getType());
|
||||
notice1.setEvent(n.getEvent());
|
||||
}
|
||||
if (n.getEvent().equals(EXECUTE_FAILED)) {
|
||||
failList.add(n.getUserId());
|
||||
notice2.setEnable(n.getEnable());
|
||||
notice2.setTestId(id);
|
||||
notice2.setType(n.getType());
|
||||
notice2.setEvent(n.getEvent());
|
||||
}
|
||||
}
|
||||
notice1.setUserIds(successList);
|
||||
notice2.setUserIds(failList);
|
||||
result.add(notice1);
|
||||
result.add(notice2);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void saveMessageTask(MessageRequest messageRequest) {
|
||||
String identification = UUID.randomUUID().toString();
|
||||
SessionUser user = SessionUtils.getUser();
|
||||
String orgId = user.getLastOrganizationId();
|
||||
messageRequest.getMessageDetail().forEach(list -> {
|
||||
MessageTaskExample example = new MessageTaskExample();
|
||||
example.createCriteria().andIdentificationEqualTo(list.getIdentification());
|
||||
List<MessageTask> messageTaskLists = messageTaskMapper.selectByExample(example);
|
||||
if (messageTaskLists.size() > 0) {
|
||||
delMessage(list.getIdentification());
|
||||
String identification = UUID.randomUUID().toString();
|
||||
list.getUserIds().forEach(m -> {
|
||||
MessageTask message = new MessageTask();
|
||||
message.setId(UUID.randomUUID().toString());
|
||||
|
@ -106,11 +43,54 @@ public class NoticeService {
|
|||
message.setIdentification(identification);
|
||||
message.setIsSet(list.getIsSet());
|
||||
message.setOrganizationId(orgId);
|
||||
message.setTestId(list.getTestId());
|
||||
messageTaskMapper.insert(message);
|
||||
});
|
||||
} else {
|
||||
String identification = UUID.randomUUID().toString();
|
||||
list.getUserIds().forEach(m -> {
|
||||
MessageTask message = new MessageTask();
|
||||
message.setId(UUID.randomUUID().toString());
|
||||
message.setEvent(list.getEvent());
|
||||
message.setTaskType(list.getTaskType());
|
||||
message.setUserId(m);
|
||||
message.setType(list.getType());
|
||||
message.setWebhook(list.getWebhook());
|
||||
message.setIdentification(identification);
|
||||
message.setIsSet(list.getIsSet());
|
||||
message.setOrganizationId(orgId);
|
||||
message.setTestId(list.getTestId());
|
||||
messageTaskMapper.insert(message);
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public List<MessageDetail> searchMessageSchedule(String testId) {
|
||||
MessageTaskExample example = new MessageTaskExample();
|
||||
example.createCriteria().andTestIdEqualTo(testId);
|
||||
List<MessageTask> messageTaskLists = messageTaskMapper.selectByExample(example);
|
||||
List<MessageDetail> scheduleMessageTask = new ArrayList<>();
|
||||
Map<String, List<MessageTask>> MessageTaskMap = messageTaskLists.stream().collect(Collectors.groupingBy(e -> e.getIdentification()));
|
||||
MessageTaskMap.forEach((k, v) -> {
|
||||
Set userIds = new HashSet();
|
||||
MessageDetail messageDetail = new MessageDetail();
|
||||
for (MessageTask m : v) {
|
||||
userIds.add(m.getUserId());
|
||||
messageDetail.setEvent(m.getEvent());
|
||||
messageDetail.setTaskType(m.getTaskType());
|
||||
messageDetail.setWebhook(m.getWebhook());
|
||||
messageDetail.setIdentification(m.getIdentification());
|
||||
messageDetail.setType(m.getType());
|
||||
messageDetail.setIsSet(m.getIsSet());
|
||||
}
|
||||
messageDetail.setUserIds(new ArrayList(userIds));
|
||||
scheduleMessageTask.add(messageDetail);
|
||||
});
|
||||
return scheduleMessageTask;
|
||||
}
|
||||
|
||||
public MessageSettingDetail searchMessage() {
|
||||
SessionUser user = SessionUtils.getUser();
|
||||
String orgId = user.getLastOrganizationId();
|
||||
|
|
|
@ -1,24 +1,22 @@
|
|||
package io.metersphere.performance.notice;
|
||||
|
||||
import io.metersphere.base.domain.LoadTest;
|
||||
import io.metersphere.base.domain.LoadTestWithBLOBs;
|
||||
import io.metersphere.base.mapper.LoadTestMapper;
|
||||
import io.metersphere.base.domain.LoadTestReportWithBLOBs;
|
||||
import io.metersphere.commons.constants.NoticeConstants;
|
||||
import io.metersphere.commons.constants.PerformanceTestStatus;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.dto.BaseSystemConfigDTO;
|
||||
import io.metersphere.notice.domain.MessageDetail;
|
||||
import io.metersphere.notice.domain.MessageSettingDetail;
|
||||
import io.metersphere.notice.domain.NoticeDetail;
|
||||
import io.metersphere.notice.service.DingTaskService;
|
||||
import io.metersphere.notice.service.MailService;
|
||||
import io.metersphere.notice.service.NoticeService;
|
||||
import io.metersphere.notice.service.WxChatTaskService;
|
||||
import io.metersphere.service.SystemParameterService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PreDestroy;
|
||||
import javax.annotation.Resource;
|
||||
import javax.mail.MessagingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
@ -35,7 +33,7 @@ public class PerformanceNoticeTask {
|
|||
@Resource
|
||||
private MailService mailService;
|
||||
@Resource
|
||||
private LoadTestMapper loadTestMapper;
|
||||
private SystemParameterService systemParameterService;
|
||||
private final ExecutorService executorService = Executors.newFixedThreadPool(20);
|
||||
private boolean isRunning = true;
|
||||
|
||||
|
@ -43,18 +41,18 @@ public class PerformanceNoticeTask {
|
|||
public void preDestroy() {
|
||||
isRunning = false;
|
||||
}
|
||||
public void registerNoticeTask(String triggerMode,LoadTestWithBLOBs loadTest) {
|
||||
|
||||
public void registerNoticeTask(LoadTestReportWithBLOBs loadTestReport) {
|
||||
executorService.submit(() -> {
|
||||
while (isRunning) {
|
||||
LoadTestWithBLOBs result = loadTestMapper.selectByPrimaryKey(loadTest.getId());
|
||||
if (StringUtils.equals(result.getStatus(), PerformanceTestStatus.Completed.name())) {
|
||||
if (StringUtils.equals(loadTestReport.getStatus(), PerformanceTestStatus.Completed.name())) {
|
||||
isRunning = false;
|
||||
sendSuccessNotice(triggerMode,loadTest);
|
||||
sendSuccessNotice(loadTestReport);
|
||||
return;
|
||||
}
|
||||
if (StringUtils.equals(result.getStatus(), PerformanceTestStatus.Error.name())) {
|
||||
if (StringUtils.equals(loadTestReport.getStatus(), PerformanceTestStatus.Error.name())) {
|
||||
isRunning = false;
|
||||
sendFailNotice(triggerMode,loadTest);
|
||||
sendFailNotice(loadTestReport);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
|
@ -66,83 +64,81 @@ public class PerformanceNoticeTask {
|
|||
});
|
||||
}
|
||||
|
||||
public void sendSuccessNotice(String triggerMode,LoadTestWithBLOBs loadTest) {
|
||||
if (StringUtils.equals(NoticeConstants.API, "API")||StringUtils.equals(NoticeConstants.SCHEDULE,"SCHEDULE")) {
|
||||
public void sendSuccessNotice(LoadTestReportWithBLOBs loadTestReport) {
|
||||
List<String> userIds = new ArrayList<>();
|
||||
List<MessageDetail> taskList = new ArrayList<>();
|
||||
String successContext = "";
|
||||
BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo();
|
||||
String url = baseSystemConfigDTO.getUrl() + "/#/performance/report/view/" + loadTestReport.getId();
|
||||
if (StringUtils.equals(NoticeConstants.API, loadTestReport.getTriggerMode())) {
|
||||
MessageSettingDetail messageSettingDetail = noticeService.searchMessage();
|
||||
List<MessageDetail> taskList = messageSettingDetail.getJenkinsTask();
|
||||
if(StringUtils.equals(triggerMode,NoticeConstants.SCHEDULE)){
|
||||
List<NoticeDetail> noticeList = null;
|
||||
noticeList = noticeService.queryNotice(loadTest.getId());
|
||||
mailService.sendPerformanceNotification(noticeList, PerformanceTestStatus.Completed.name(), loadTest, loadTest.getId()); }else{
|
||||
return;
|
||||
taskList = messageSettingDetail.getJenkinsTask();
|
||||
successContext = "jenkins性能测试任务通知" + loadTestReport.getName() + "执行成功" + "请点击下面链接进入测试报告页面" + url;
|
||||
}
|
||||
|
||||
if(StringUtils.equals(triggerMode,NoticeConstants.SCHEDULE)){
|
||||
String contextSuccess="";
|
||||
contextSuccess = "jenkins任务通知:" + loadTest.getName() + "执行成功";
|
||||
String finalContextSuccess = contextSuccess;
|
||||
if (StringUtils.equals(NoticeConstants.SCHEDULE, loadTestReport.getTriggerMode())) {
|
||||
taskList = noticeService.searchMessageSchedule(loadTestReport.getId());
|
||||
successContext = "定时任务性能测试任务通知" + loadTestReport.getName() + "执行成功" + "请点击下面链接进入测试报告页面" + url;
|
||||
}
|
||||
String finalSuccessContext = successContext;
|
||||
taskList.forEach(r -> {
|
||||
switch (r.getType()) {
|
||||
case NoticeConstants.NAIL_ROBOT:
|
||||
if (StringUtils.equals(NoticeConstants.EXECUTE_SUCCESSFUL, r.getEvent())
|
||||
&& StringUtils.equals(loadTest.getStatus(), PerformanceTestStatus.Completed.name())) {
|
||||
dingTaskService.sendNailRobot(r, userIds, finalContextSuccess, NoticeConstants.EXECUTE_SUCCESSFUL);
|
||||
if (StringUtils.equals(NoticeConstants.EXECUTE_SUCCESSFUL, r.getEvent()) && StringUtils.equals(loadTestReport.getStatus(), PerformanceTestStatus.Completed.name())) {
|
||||
dingTaskService.sendNailRobot(r, userIds, finalSuccessContext, NoticeConstants.EXECUTE_SUCCESSFUL);
|
||||
}
|
||||
break;
|
||||
case NoticeConstants.WECHAT_ROBOT:
|
||||
if (StringUtils.equals(NoticeConstants.EXECUTE_SUCCESSFUL, r.getEvent())
|
||||
&& StringUtils.equals(loadTest.getStatus(), PerformanceTestStatus.Completed.name())) {
|
||||
wxChatTaskService.sendWechatRobot(r, userIds, finalContextSuccess, NoticeConstants.EXECUTE_SUCCESSFUL);
|
||||
if (StringUtils.equals(NoticeConstants.EXECUTE_SUCCESSFUL, r.getEvent()) && StringUtils.equals(loadTestReport.getStatus(), PerformanceTestStatus.Completed.name())) {
|
||||
wxChatTaskService.sendWechatRobot(r, userIds, finalSuccessContext, NoticeConstants.EXECUTE_SUCCESSFUL);
|
||||
}
|
||||
break;
|
||||
case NoticeConstants.EMAIL:
|
||||
if (StringUtils.equals(NoticeConstants.EXECUTE_SUCCESSFUL, r.getEvent())
|
||||
&& StringUtils.equals(loadTest.getStatus(), PerformanceTestStatus.Completed.name())) {
|
||||
try {
|
||||
mailService.sendLoadJenkinsNotification(finalContextSuccess, r);
|
||||
} catch (MessagingException messagingException) {
|
||||
messagingException.printStackTrace();
|
||||
}
|
||||
if (StringUtils.equals(NoticeConstants.EXECUTE_SUCCESSFUL, r.getEvent()) && StringUtils.equals(loadTestReport.getStatus(), PerformanceTestStatus.Completed.name())) {
|
||||
mailService.sendLoadNotification(r, loadTestReport, NoticeConstants.EXECUTE_SUCCESSFUL);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void sendFailNotice(String triggerMode,LoadTestWithBLOBs loadTest) {
|
||||
if (StringUtils.equals(NoticeConstants.API, "API")) {
|
||||
public void sendFailNotice(LoadTestReportWithBLOBs loadTestReport) {
|
||||
List<String> userIds = new ArrayList<>();
|
||||
List<MessageDetail> taskList = new ArrayList<>();
|
||||
String failedContext = "";
|
||||
BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo();
|
||||
String url = baseSystemConfigDTO.getUrl() + "/#/performance/report/view/" + loadTestReport.getId();
|
||||
if (StringUtils.equals(NoticeConstants.API, loadTestReport.getTriggerMode())) {
|
||||
MessageSettingDetail messageSettingDetail = noticeService.searchMessage();
|
||||
List<MessageDetail> taskList = messageSettingDetail.getJenkinsTask();
|
||||
String contextFailed = "jenkins任务通知:" + loadTest.getName() + "执行失败";
|
||||
taskList = messageSettingDetail.getJenkinsTask();
|
||||
failedContext = "jenkins性能测试任务通知" + loadTestReport.getName() + "执行失败" + "请点击下面链接进入测试报告页面" + url;
|
||||
}
|
||||
if (StringUtils.equals(NoticeConstants.SCHEDULE, loadTestReport.getTriggerMode())) {
|
||||
taskList = noticeService.searchMessageSchedule(loadTestReport.getId());
|
||||
failedContext = "定时任务性能测试任务通知" + loadTestReport.getName() + "执行失败" + "请点击下面链接进入测试报告页面" + url;
|
||||
}
|
||||
String finalFailedContext = failedContext;
|
||||
taskList.forEach(r -> {
|
||||
switch (r.getType()) {
|
||||
case NoticeConstants.NAIL_ROBOT:
|
||||
if (StringUtils.equals(NoticeConstants.EXECUTE_FAILED, r.getEvent())) {
|
||||
dingTaskService.sendNailRobot(r, userIds, contextFailed, NoticeConstants.EXECUTE_FAILED);
|
||||
if (StringUtils.equals(NoticeConstants.EXECUTE_FAILED, r.getEvent()) && StringUtils.equals(loadTestReport.getStatus(), PerformanceTestStatus.Error.name())) {
|
||||
dingTaskService.sendNailRobot(r, userIds, finalFailedContext, NoticeConstants.EXECUTE_FAILED);
|
||||
}
|
||||
break;
|
||||
case NoticeConstants.WECHAT_ROBOT:
|
||||
if (StringUtils.equals(NoticeConstants.EXECUTE_FAILED, r.getEvent())) {
|
||||
wxChatTaskService.sendWechatRobot(r, userIds, contextFailed, NoticeConstants.EXECUTE_FAILED);
|
||||
if (StringUtils.equals(NoticeConstants.EXECUTE_FAILED, r.getEvent()) && StringUtils.equals(loadTestReport.getStatus(), PerformanceTestStatus.Error.name())) {
|
||||
wxChatTaskService.sendWechatRobot(r, userIds, finalFailedContext, NoticeConstants.EXECUTE_FAILED);
|
||||
}
|
||||
break;
|
||||
case NoticeConstants.EMAIL:
|
||||
if (StringUtils.equals(NoticeConstants.EXECUTE_FAILED, r.getEvent())) {
|
||||
try {
|
||||
mailService.sendLoadJenkinsNotification(contextFailed, r);
|
||||
} catch (MessagingException messagingException) {
|
||||
messagingException.printStackTrace();
|
||||
}
|
||||
if (StringUtils.equals(NoticeConstants.EXECUTE_FAILED, r.getEvent()) && StringUtils.equals(loadTestReport.getStatus(), PerformanceTestStatus.Error.name())) {
|
||||
mailService.sendLoadNotification(r, loadTestReport, NoticeConstants.EXECUTE_FAILED);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -28,7 +28,6 @@ import io.metersphere.performance.notice.PerformanceNoticeTask;
|
|||
import io.metersphere.service.FileService;
|
||||
import io.metersphere.service.QuotaService;
|
||||
import io.metersphere.service.ScheduleService;
|
||||
import io.metersphere.service.TestResourceService;
|
||||
import io.metersphere.track.request.testplan.*;
|
||||
import io.metersphere.track.service.TestCaseService;
|
||||
import org.apache.commons.collections4.ListUtils;
|
||||
|
@ -235,17 +234,10 @@ public class PerformanceTestService {
|
|||
}
|
||||
|
||||
startEngine(loadTest, engine, request.getTriggerMode());
|
||||
List<NoticeDetail> noticeList = null;
|
||||
if (request.getTriggerMode().equals("SCHEDULE")) {
|
||||
try {
|
||||
noticeList = noticeService.queryNotice(loadTest.getId());
|
||||
mailService.sendPerformanceNotification(noticeList, PerformanceTestStatus.Completed.name(), loadTest, engine.getReportId());
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
if(request.getTriggerMode().equals("API")){
|
||||
performanceNoticeTask.registerNoticeTask(request.getTriggerMode(),loadTest);
|
||||
|
||||
LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(engine.getReportId());
|
||||
if (StringUtils.equals(NoticeConstants.API, loadTestReport.getTriggerMode()) || StringUtils.equals(NoticeConstants.SCHEDULE, loadTestReport.getTriggerMode())) {
|
||||
performanceNoticeTask.registerNoticeTask(loadTestReport);
|
||||
}
|
||||
return engine.getReportId();
|
||||
}
|
||||
|
@ -319,9 +311,9 @@ public class PerformanceTestService {
|
|||
loadTest.setStatus(PerformanceTestStatus.Error.name());
|
||||
loadTest.setDescription(e.getMessage());
|
||||
loadTestMapper.updateByPrimaryKeySelective(loadTest);
|
||||
if (triggerMode.equals("SCHEDULE")) {
|
||||
noticeList = noticeService.queryNotice(loadTest.getId());
|
||||
mailService.sendPerformanceNotification(noticeList, loadTest.getStatus(), loadTest, loadTest.getId());
|
||||
LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(engine.getReportId());
|
||||
if (StringUtils.equals(NoticeConstants.API, loadTestReport.getTriggerMode()) || StringUtils.equals(NoticeConstants.SCHEDULE, loadTestReport.getTriggerMode())) {
|
||||
performanceNoticeTask.registerNoticeTask(loadTestReport);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
@ -447,12 +439,12 @@ public class PerformanceTestService {
|
|||
reportService.updateStatus(reportId, PerformanceTestStatus.Completed.name());
|
||||
List<NoticeDetail> noticeList = null;
|
||||
if (loadTestReport.getTriggerMode().equals("SCHEDULE")) {
|
||||
try {
|
||||
/* try {
|
||||
noticeList = noticeService.queryNotice(loadTest.getId());
|
||||
mailService.sendPerformanceNotification(noticeList, loadTestReport.getStatus(), loadTest, loadTestReport.getId());
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
alter table message_task
|
||||
add test_id varchar(255) null;
|
|
@ -155,7 +155,6 @@ email_subject=Metersphere timing task result notification
|
|||
import_xmind_count_error=The number of use cases imported into the mind map cannot exceed 500
|
||||
import_xmind_not_found=Test case not found
|
||||
license_valid_license_error=Authorization authentication failed
|
||||
timing_task_result_notification=Timing task result notification
|
||||
test_review_task_notice=Test review task notice
|
||||
test_track.length_less_than=The title is too long, the length must be less than
|
||||
# check owner
|
||||
|
@ -168,6 +167,7 @@ upload_content_is_null=Imported content is empty
|
|||
test_plan_notification=Test plan notification
|
||||
task_defect_notification=Task defect notification
|
||||
task_notification=Jenkins Task notification
|
||||
timing_task_notification=Timing task result notification
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -155,7 +155,7 @@ email_subject=MeterSphere定时任务结果通知
|
|||
import_xmind_count_error=思维导图导入用例数量不能超过 500 条
|
||||
license_valid_license_error=授权认证失败
|
||||
import_xmind_not_found=未找到测试用例
|
||||
timing_task_result_notification=定时任务结果通知
|
||||
|
||||
test_review_task_notice=测试评审任务通知
|
||||
test_track.length_less_than=标题过长,字数必须小于
|
||||
# check owner
|
||||
|
@ -168,3 +168,4 @@ upload_content_is_null=导入内容为空
|
|||
test_plan_notification=测试计划通知
|
||||
task_defect_notification=缺陷任务通知
|
||||
task_notification=jenkins任务通知
|
||||
timing_task_notification=定时任务结果通知
|
|
@ -156,7 +156,7 @@ license_valid_license_code=授權碼已經存在
|
|||
email_subject=MeterSphere定時任務結果通知
|
||||
import_xmind_count_error=思維導圖導入用例數量不能超過 500 條
|
||||
import_xmind_not_found=未找到测试用例
|
||||
timing_task_result_notification=定時任務結果通知
|
||||
|
||||
test_review_task_notice=測試評審任務通知
|
||||
test_track.length_less_than=標題過長,字數必須小於
|
||||
# check owner
|
||||
|
@ -169,4 +169,5 @@ upload_content_is_null=導入內容為空
|
|||
test_plan_notification=測試計畫通知
|
||||
task_defect_notification=缺陷任務通知
|
||||
task_notification=jenkins任務通知
|
||||
timing_task_notification=定時任務通知
|
||||
|
||||
|
|
|
@ -6,15 +6,12 @@
|
|||
</head>
|
||||
<body>
|
||||
<div>
|
||||
<div style="text-align: left">
|
||||
<h3>${title}</h3>
|
||||
</div>
|
||||
<div style="text-align: left">
|
||||
<p>尊敬的用户:</p>
|
||||
<p style="margin-left: 60px">您好:
|
||||
</div>
|
||||
<div style="margin-left: 100px">
|
||||
<p>您所执行的 ${testName} 运行失败<br/>
|
||||
<p>您所执行的 ${testName} 接口测试运行失败<br/>
|
||||
请点击下面链接进入测试报告页面</p>
|
||||
<a href="${url}/#/${type}/report/view/${id}">${url}/#/${type}/report/view/${id}</a>
|
||||
</div>
|
|
@ -13,7 +13,7 @@
|
|||
<p style="margin-left: 60px">您好:
|
||||
</div>
|
||||
<div style="margin-left: 100px">
|
||||
<p>您所执行的 ${testName} 运行成功<br/>
|
||||
<p>您所执行的 ${testName} 接口测试运行成功<br/>
|
||||
请点击下面链接进入测试报告页面</p>
|
||||
<a href="${url}/#/${type}/report/view/${id}">${url}/#/${type}/report/view/${id}</a>
|
||||
</div>
|
|
@ -5,9 +5,6 @@
|
|||
<title>MeterSphere</title>
|
||||
</head>
|
||||
<body style="text-align: left">
|
||||
<div style="text-align: left">
|
||||
<h3>${title}</h3>
|
||||
</div>
|
||||
<div style="text-align: left">
|
||||
<p>尊敬的用户:</p>
|
||||
<p style="margin-left: 60px">您好:
|
|
@ -6,9 +6,6 @@
|
|||
</head>
|
||||
<body>
|
||||
<div>
|
||||
<div style="text-align: left">
|
||||
<h3>${title}</h3>
|
||||
</div>
|
||||
<div style="text-align: left">
|
||||
<p>尊敬的用户:</p>
|
||||
<p style="margin-left: 60px">您好:
|
|
@ -3,7 +3,7 @@
|
|||
@close="close">
|
||||
<template>
|
||||
<div>
|
||||
<el-tabs v-model="activeName" @tab-click="handleClick">
|
||||
<el-tabs v-model="activeName">
|
||||
|
||||
<el-tab-pane :label="$t('schedule.edit_timer_task')" name="first">
|
||||
<el-form :model="form" :rules="rules" ref="from">
|
||||
|
@ -31,61 +31,7 @@
|
|||
</el-dialog>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane :label="$t('schedule.task_notification')" name="second">
|
||||
<template>
|
||||
<el-table
|
||||
:data="tableData"
|
||||
style="width: 100%">
|
||||
<el-table-column
|
||||
prop="event"
|
||||
:label="$t('schedule.event')">
|
||||
<template v-slot:default="{row}">
|
||||
<span v-if="row.event === 'EXECUTE_SUCCESSFUL'"> {{ $t('schedule.event_success') }}</span>
|
||||
<span v-else-if="row.event === 'EXECUTE_FAILED'"> {{ $t('schedule.event_failed') }}</span>
|
||||
<span v-else>{{ row.event }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="name"
|
||||
:label="$t('schedule.receiver')"
|
||||
width="240"
|
||||
>
|
||||
<template v-slot:default="{row}">
|
||||
<el-select v-model="row.userIds" filterable multiple
|
||||
:placeholder="$t('commons.please_select')"
|
||||
@click.native="userList()" style="width: 100%;">
|
||||
<el-option
|
||||
v-for="item in options"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="type"
|
||||
:label="$t('schedule.receiving_mode')"
|
||||
>
|
||||
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
:label="$t('test_resource_pool.enable_disable')"
|
||||
prop="enable"
|
||||
>
|
||||
<template v-slot:default="{row}">
|
||||
<el-switch
|
||||
v-model="row.enable"
|
||||
active-value="true"
|
||||
inactive-value="false"
|
||||
inactive-color="#DCDFE6"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div style="padding-top: 20px;">
|
||||
<el-button type="primary" @click="saveNotice">{{ $t('commons.save') }}</el-button>
|
||||
</div>
|
||||
</template>
|
||||
<schedule-task-notification :test-id="testId" :schedule-receiver-options="scheduleReceiverOptions"></schedule-task-notification>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</div>
|
||||
|
@ -94,19 +40,19 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
import {getCurrentUser} from "@/common/js/utils";
|
||||
import Crontab from "../cron/Crontab";
|
||||
import CrontabResult from "../cron/CrontabResult";
|
||||
import {cronValidate} from "@/common/js/cron";
|
||||
import {listenGoBack, removeGoBackListener} from "@/common/js/utils";
|
||||
|
||||
import ScheduleTaskNotification from "../../settings/organization/components/ScheduleTaskNotification";
|
||||
function defaultCustomValidate() {
|
||||
return {pass: true};
|
||||
}
|
||||
|
||||
export default {
|
||||
name: "MsScheduleEdit",
|
||||
components: {CrontabResult, Crontab},
|
||||
components: {CrontabResult, Crontab,ScheduleTaskNotification},
|
||||
props: {
|
||||
testId: String,
|
||||
save: Function,
|
||||
|
@ -145,29 +91,13 @@ export default {
|
|||
}
|
||||
};
|
||||
return {
|
||||
scheduleReceiverOptions:[],
|
||||
operation: true,
|
||||
dialogVisible: false,
|
||||
showCron: false,
|
||||
form: {
|
||||
cronValue: ""
|
||||
},
|
||||
tableData: [
|
||||
{
|
||||
event: "EXECUTE_SUCCESSFUL",
|
||||
type: "EMAIL",
|
||||
userIds: [],
|
||||
enable: false
|
||||
},
|
||||
{
|
||||
event: "EXECUTE_FAILED",
|
||||
type: "EMAIL",
|
||||
userIds: [],
|
||||
enable: false
|
||||
}
|
||||
],
|
||||
options: [{}],
|
||||
enable: true,
|
||||
type: "",
|
||||
activeName: 'first',
|
||||
rules: {
|
||||
cronValue: [{required: true, validator: validateCron, trigger: 'blur'}],
|
||||
|
@ -175,28 +105,26 @@ export default {
|
|||
}
|
||||
},
|
||||
methods: {
|
||||
userList() {
|
||||
this.result = this.$get('user/list', response => {
|
||||
this.options = response.data
|
||||
})
|
||||
currentUser: () => {
|
||||
return getCurrentUser();
|
||||
},
|
||||
handleClick() {
|
||||
if (this.activeName === "second") {
|
||||
this.result = this.$get('notice/query/' + this.testId, response => {
|
||||
if (response.data.length > 0) {
|
||||
this.tableData = response.data
|
||||
initUserList() {
|
||||
let param = {
|
||||
name: '',
|
||||
organizationId: this.currentUser().lastOrganizationId
|
||||
};
|
||||
this.result = this.$post('user/org/member/list/all', param, response => {
|
||||
this.scheduleReceiverOptions = response.data
|
||||
|
||||
this.tableData[0].event = "EXECUTE_SUCCESSFUL"
|
||||
this.tableData[0].type = "EMAIL"
|
||||
this.tableData[1].event = "EXECUTE_FAILED"
|
||||
this.tableData[1].type = "EMAIL"
|
||||
} else {
|
||||
this.tableData[0].userIds = []
|
||||
this.tableData[1].userIds = []
|
||||
}
|
||||
});
|
||||
},
|
||||
/* handleClick() {
|
||||
if (this.activeName === "second") {
|
||||
this.result = this.$get('/notice/search/message/'+this.testId, response => {
|
||||
this.scheduleTask = response.data;
|
||||
})
|
||||
}
|
||||
},
|
||||
},*/
|
||||
buildParam() {
|
||||
let param = {};
|
||||
param.notices = this.tableData
|
||||
|
@ -204,10 +132,10 @@ export default {
|
|||
return param;
|
||||
},
|
||||
open() {
|
||||
this.initUserList();
|
||||
this.dialogVisible = true;
|
||||
this.form.cronValue = this.schedule.value;
|
||||
listenGoBack(this.close);
|
||||
this.handleClick()
|
||||
this.activeName = 'first'
|
||||
},
|
||||
crontabFill(value, resultList) {
|
||||
|
|
|
@ -79,6 +79,12 @@
|
|||
@click.native.prevent="removeRowTask(scope.$index,form.defectTask)"
|
||||
>{{ $t('commons.cancel') }}
|
||||
</el-button>
|
||||
<el-button
|
||||
type="primary"
|
||||
size="mini"
|
||||
v-show="!scope.row.isSet"
|
||||
@click="handleEditTask(scope.$index,scope.row)"
|
||||
>{{ $t('commons.edit') }}</el-button>
|
||||
<el-button
|
||||
type="danger"
|
||||
icon="el-icon-delete"
|
||||
|
@ -141,6 +147,9 @@ export default {
|
|||
data.isReadOnly = !data.isReadOnly
|
||||
}
|
||||
},
|
||||
handleEditTask(index,data){
|
||||
data.isSet = true
|
||||
},
|
||||
handleAddTaskModel(type) {
|
||||
let Task = {};
|
||||
Task.event = [];
|
||||
|
|
|
@ -79,6 +79,13 @@
|
|||
@click.native.prevent="removeRowTask(scope.$index,form.jenkinsTask)"
|
||||
>{{ $t('commons.cancel') }}
|
||||
</el-button>
|
||||
<el-button
|
||||
type="primary"
|
||||
size="mini"
|
||||
v-show="!scope.row.isSet"
|
||||
@click="handleEditTask(scope.$index,scope.row)"
|
||||
>{{ $t('commons.edit') }}
|
||||
</el-button>
|
||||
<el-button
|
||||
type="danger"
|
||||
icon="el-icon-delete"
|
||||
|
@ -168,7 +175,6 @@ export default {
|
|||
}
|
||||
},
|
||||
handleAddTask(index, data) {
|
||||
|
||||
if (data.event && data.userIds.length > 0 && data.type) {
|
||||
console.log(data.type)
|
||||
if (data.type === 'NAIL_ROBOT' || data.type === 'WECHAT_ROBOT') {
|
||||
|
@ -184,6 +190,9 @@ export default {
|
|||
this.$warning(this.$t('organization.message.message'));
|
||||
}
|
||||
},
|
||||
handleEditTask(index,data){
|
||||
data.isSet = true
|
||||
},
|
||||
addTask(data) {
|
||||
let list = []
|
||||
data.isSet = false
|
||||
|
|
|
@ -0,0 +1,222 @@
|
|||
<template>
|
||||
<div>
|
||||
<el-row>
|
||||
<el-col :span="10">
|
||||
<el-button icon="el-icon-circle-plus-outline" plain size="mini" @click="handleAddTaskModel('scheduleTask')">
|
||||
{{ $t('organization.message.create_new_notification') }}
|
||||
</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="24">
|
||||
<el-table
|
||||
:data="form.scheduleTask"
|
||||
class="tb-edit"
|
||||
border
|
||||
size="mini"
|
||||
:cell-style="rowClass"
|
||||
:header-cell-style="headClass">
|
||||
<el-table-column :label="$t('schedule.event')" min-width="20%" prop="events">
|
||||
<template slot-scope="scope">
|
||||
<el-select v-model="scope.row.event"
|
||||
:placeholder="$t('organization.message.select_events')"
|
||||
prop="events" :disabled="!scope.row.isSet">
|
||||
<el-option
|
||||
v-for="item in scheduleEventOptions"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="$t('schedule.receiver')" prop="userIds" min-width="20%">
|
||||
<template v-slot:default="{row}">
|
||||
<el-select v-model="row.userIds" filterable multiple
|
||||
:placeholder="$t('commons.please_select')" style="width: 100%;" :disabled="!row.isSet">
|
||||
<el-option
|
||||
v-for="item in scheduleReceiverOptions"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="$t('schedule.receiving_mode')" min-width="20%" prop="type">
|
||||
<template slot-scope="scope">
|
||||
<el-select v-model="scope.row.type" :placeholder="$t('organization.message.select_receiving_method')"
|
||||
:disabled="!scope.row.isSet" @change="handleEdit(scope.$index, scope.row)"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in receiveTypeOptions"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="webhook" min-width="20%" prop="webhook">
|
||||
<template v-slot:default="scope">
|
||||
<el-input v-model="scope.row.webhook" placeholder="webhook地址"
|
||||
:disabled="!scope.row.isSet||!scope.row.isReadOnly"></el-input>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="$t('commons.operating')" min-width="20%" prop="result">
|
||||
<template v-slot:default="scope">
|
||||
<el-button
|
||||
type="primary"
|
||||
size="mini"
|
||||
v-show="scope.row.isSet"
|
||||
@click="handleAddTask(scope.$index,scope.row)"
|
||||
>{{ $t('commons.add') }}
|
||||
</el-button>
|
||||
<el-button
|
||||
size="mini"
|
||||
v-show="scope.row.isSet"
|
||||
@click.native.prevent="removeRowTask(scope.$index,form.scheduleTask)"
|
||||
>{{ $t('commons.cancel') }}
|
||||
</el-button>
|
||||
<el-button
|
||||
type="primary"
|
||||
size="mini"
|
||||
v-show="!scope.row.isSet"
|
||||
@click="handleEditTask(scope.$index,scope.row)"
|
||||
>{{ $t('commons.edit') }}</el-button>
|
||||
<el-button
|
||||
type="danger"
|
||||
icon="el-icon-delete"
|
||||
size="mini"
|
||||
v-show="!scope.row.isSet"
|
||||
@click.native.prevent="deleteRowTask(scope.$index,scope.row)"
|
||||
></el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
export default {
|
||||
name: "ScheduleTaskNotification",
|
||||
props: {
|
||||
testId:String,
|
||||
scheduleReceiverOptions:Array,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
form: {
|
||||
scheduleTask: [{
|
||||
taskType: "scheduleTask",
|
||||
event: "",
|
||||
userIds: [],
|
||||
type: [],
|
||||
webhook: "",
|
||||
isSet: true,
|
||||
identification: "",
|
||||
isReadOnly: false,
|
||||
testId:this.testId,
|
||||
|
||||
}],
|
||||
},
|
||||
scheduleEventOptions: [
|
||||
{value: 'EXECUTE_SUCCESSFUL', label: this.$t('schedule.event_success')},
|
||||
{value: 'EXECUTE_FAILED', label: this.$t('schedule.event_failed')}
|
||||
],
|
||||
receiveTypeOptions: [
|
||||
{value: 'EMAIL', label: this.$t('organization.message.mail')},
|
||||
{value: 'NAIL_ROBOT', label: this.$t('organization.message.nail_robot')},
|
||||
{value: 'WECHAT_ROBOT', label: this.$t('organization.message.enterprise_wechat_robot')}
|
||||
],
|
||||
}
|
||||
},
|
||||
mounted(){
|
||||
this.initForm()
|
||||
},
|
||||
methods: {
|
||||
initForm(){
|
||||
this.result = this.$get('/notice/search/message/'+this.testId, response => {
|
||||
console.log(response.data);
|
||||
this.form.scheduleTask = response.data;
|
||||
})
|
||||
},
|
||||
handleEdit(index, data) {
|
||||
data.isReadOnly = true;
|
||||
if (data.type === 'EMAIL') {
|
||||
data.isReadOnly = !data.isReadOnly
|
||||
}
|
||||
},
|
||||
handleAddTaskModel(type) {
|
||||
let Task = {};
|
||||
Task.event = [];
|
||||
Task.userIds = [];
|
||||
Task.type = "";
|
||||
Task.webhook = "";
|
||||
Task.isSet = true;
|
||||
Task.identification = "";
|
||||
if (type === 'scheduleTask') {
|
||||
Task.taskType = 'SCHEDULE_TASK'
|
||||
Task.testId=this.testId
|
||||
this.form.scheduleTask.push(Task)
|
||||
}
|
||||
},
|
||||
handleEditTask(index,data){
|
||||
data.isSet = true
|
||||
data.testId=this.testId
|
||||
},
|
||||
handleAddTask(index, data) {
|
||||
if (data.event && data.userIds.length > 0 && data.type) {
|
||||
console.log(data.type)
|
||||
if (data.type === 'NAIL_ROBOT' || data.type === 'WECHAT_ROBOT') {
|
||||
if (!data.webhook) {
|
||||
this.$warning(this.$t('organization.message.message_webhook'));
|
||||
} else {
|
||||
this.addTask(data)
|
||||
}
|
||||
} else {
|
||||
this.addTask(data)
|
||||
}
|
||||
} else {
|
||||
this.$warning(this.$t('organization.message.message'));
|
||||
}
|
||||
},
|
||||
addTask(data) {
|
||||
let list = []
|
||||
data.isSet = false
|
||||
list.push(data)
|
||||
let param = {};
|
||||
param.messageDetail = list
|
||||
this.result = this.$post("/notice/save/message/task", param, () => {
|
||||
this.initForm()
|
||||
this.$success(this.$t('commons.save_success'));
|
||||
})
|
||||
},
|
||||
removeRowTask(index, data) { //移除
|
||||
data.splice(index, 1)
|
||||
},
|
||||
deleteRowTask(index, data) { //删除
|
||||
this.result = this.$get("/notice/delete/message/" + data.identification, response => {
|
||||
this.$success(this.$t('commons.delete_success'));
|
||||
this.initForm()
|
||||
})
|
||||
},
|
||||
rowClass() {
|
||||
return "text-align:center"
|
||||
},
|
||||
headClass() {
|
||||
return "text-align:center;background:'#ededed'"
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.el-row {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -79,6 +79,12 @@
|
|||
@click.native.prevent="removeRowTask(scope.$index,form.testCasePlanTask)"
|
||||
>{{ $t('commons.cancel') }}
|
||||
</el-button>
|
||||
<el-button
|
||||
type="primary"
|
||||
size="mini"
|
||||
v-show="!scope.row.isSet"
|
||||
@click="handleEditTask(scope.$index,scope.row)"
|
||||
>{{ $t('commons.edit') }}</el-button>
|
||||
<el-button
|
||||
type="danger"
|
||||
icon="el-icon-delete"
|
||||
|
@ -147,6 +153,9 @@ export default {
|
|||
data.isReadOnly = !data.isReadOnly
|
||||
}
|
||||
},
|
||||
handleEditTask(index,data){
|
||||
data.isSet = true
|
||||
},
|
||||
handleAddTaskModel(type) {
|
||||
let Task = {};
|
||||
Task.event = [];
|
||||
|
|
|
@ -80,6 +80,12 @@
|
|||
@click.native.prevent="removeRowTask(scope.$index,form.reviewTask)"
|
||||
>{{ $t('commons.cancel') }}
|
||||
</el-button>
|
||||
<el-button
|
||||
type="primary"
|
||||
size="mini"
|
||||
v-show="!scope.row.isSet"
|
||||
@click="handleEditTask(scope.$index,scope.row)"
|
||||
>{{ $t('commons.edit') }}</el-button>
|
||||
<el-button
|
||||
type="danger"
|
||||
icon="el-icon-delete"
|
||||
|
@ -148,6 +154,9 @@ export default {
|
|||
data.isReadOnly = !data.isReadOnly
|
||||
}
|
||||
},
|
||||
handleEditTask(index,data){
|
||||
data.isSet = true
|
||||
},
|
||||
handleAddTaskModel(type) {
|
||||
let Task = {};
|
||||
Task.event = [];
|
||||
|
|
Loading…
Reference in New Issue