diff --git a/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java b/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java index 2cd73f9ccb..31c17877cd 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java @@ -5,22 +5,26 @@ import io.metersphere.api.service.APITestService; import io.metersphere.base.domain.ApiTestReport; import io.metersphere.commons.constants.APITestStatus; import io.metersphere.commons.constants.ApiRunMode; +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.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.track.service.TestPlanTestCaseService; import org.apache.commons.lang3.StringUtils; -import org.apache.http.protocol.HTTP; import org.apache.jmeter.assertions.AssertionResult; import org.apache.jmeter.samplers.SampleResult; import org.apache.jmeter.visualizers.backend.AbstractBackendListenerClient; import org.apache.jmeter.visualizers.backend.BackendListenerContext; -import org.pac4j.core.context.HttpConstants; import org.springframework.http.HttpMethod; +import javax.mail.MessagingException; import java.io.Serializable; import java.util.*; @@ -63,6 +67,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl super.setupTest(context); } + @Override public void handleSampleResults(List sampleResults, BackendListenerContext context) { queue.addAll(sampleResults); @@ -137,17 +142,79 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl } } - NoticeService noticeService = CommonBeanFactory.getBean(NoticeService.class); + try { - List noticeList = noticeService.queryNotice(testResult.getTestId()); - MailService mailService = CommonBeanFactory.getBean(MailService.class); - mailService.sendApiNotification(report, noticeList); + sendTask(report, testResult); } catch (Exception e) { LogUtil.error(e); } } + private static void sendTask(ApiTestReport report, TestResult testResult) { + NoticeService noticeService = CommonBeanFactory.getBean(NoticeService.class); + 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 noticeList = noticeService.queryNotice(testResult.getTestId()); + mailService.sendApiNotification(report, noticeList); + } + if (StringUtils.equals(NoticeConstants.API, report.getTriggerMode())) { + List userIds = new ArrayList<>(); + MessageSettingDetail messageSettingDetail = noticeService.searchMessage(); + List taskList = messageSettingDetail.getJenkinsTask(); + if (StringUtils.equals(report.getStatus(), "Success")) { + + } + String contextSuccess = report.getName() + "执行成功"; + ; + String contextFailed = report.getName() + "执行失败"; + taskList.forEach(r -> { + switch (r.getType()) { + case NoticeConstants.NAIL_ROBOT: + r.getEvents().forEach(e -> { + if (StringUtils.equals(NoticeConstants.EXECUTE_SUCCESSFUL, e) && StringUtils.equals(report.getStatus(), "Success")) { + dingTaskService.sendNailRobot(r, userIds, contextSuccess, NoticeConstants.EXECUTE_SUCCESSFUL); + } + if (StringUtils.equals(NoticeConstants.EXECUTE_FAILED, e) && StringUtils.equals(report.getStatus(), "Error")) { + dingTaskService.sendNailRobot(r, userIds, contextFailed, NoticeConstants.EXECUTE_FAILED); + } + }); + break; + case NoticeConstants.WECHAT_ROBOT: + r.getEvents().forEach(e -> { + if (StringUtils.equals(NoticeConstants.EXECUTE_SUCCESSFUL, e) && StringUtils.equals(report.getStatus(), "Success")) { + wxChatTaskService.sendWechatRobot(r, userIds, contextSuccess, NoticeConstants.EXECUTE_SUCCESSFUL); + } + if (StringUtils.equals(NoticeConstants.EXECUTE_FAILED, e) && StringUtils.equals(report.getStatus(), "Error")) { + wxChatTaskService.sendWechatRobot(r, userIds, contextFailed, NoticeConstants.EXECUTE_FAILED); + } + }); + break; + case NoticeConstants.EMAIL: + r.getEvents().forEach(e -> { + if (StringUtils.equals(NoticeConstants.EXECUTE_SUCCESSFUL, e) && StringUtils.equals(report.getStatus(), "Success")) { + try { + mailService.sendApiJenkinsNotification(contextSuccess, r); + } catch (MessagingException messagingException) { + messagingException.printStackTrace(); + } + } + if (StringUtils.equals(NoticeConstants.EXECUTE_FAILED, e) && StringUtils.equals(report.getStatus(), "Error")) { + try { + mailService.sendApiJenkinsNotification(contextFailed, r); + } catch (MessagingException messagingException) { + messagingException.printStackTrace(); + } + } + }); + break; + } + }); + } + } + private RequestResult getRequestResult(SampleResult result) { RequestResult requestResult = new RequestResult(); requestResult.setName(result.getSampleLabel()); diff --git a/backend/src/main/java/io/metersphere/base/domain/MessageTaskExample.java b/backend/src/main/java/io/metersphere/base/domain/MessageTaskExample.java index 355a65e638..f81c60fc2c 100644 --- a/backend/src/main/java/io/metersphere/base/domain/MessageTaskExample.java +++ b/backend/src/main/java/io/metersphere/base/domain/MessageTaskExample.java @@ -595,62 +595,62 @@ public class MessageTaskExample { } public Criteria andIsSetIsNull() { - addCriterion("is_Set is null"); + addCriterion("is_set is null"); return (Criteria) this; } public Criteria andIsSetIsNotNull() { - addCriterion("is_Set is not null"); + addCriterion("is_set is not null"); return (Criteria) this; } public Criteria andIsSetEqualTo(Boolean value) { - addCriterion("is_Set =", value, "isSet"); + addCriterion("is_set =", value, "isSet"); return (Criteria) this; } public Criteria andIsSetNotEqualTo(Boolean value) { - addCriterion("is_Set <>", value, "isSet"); + addCriterion("is_set <>", value, "isSet"); return (Criteria) this; } public Criteria andIsSetGreaterThan(Boolean value) { - addCriterion("is_Set >", value, "isSet"); + addCriterion("is_set >", value, "isSet"); return (Criteria) this; } public Criteria andIsSetGreaterThanOrEqualTo(Boolean value) { - addCriterion("is_Set >=", value, "isSet"); + addCriterion("is_set >=", value, "isSet"); return (Criteria) this; } public Criteria andIsSetLessThan(Boolean value) { - addCriterion("is_Set <", value, "isSet"); + addCriterion("is_set <", value, "isSet"); return (Criteria) this; } public Criteria andIsSetLessThanOrEqualTo(Boolean value) { - addCriterion("is_Set <=", value, "isSet"); + addCriterion("is_set <=", value, "isSet"); return (Criteria) this; } public Criteria andIsSetIn(List values) { - addCriterion("is_Set in", values, "isSet"); + addCriterion("is_set in", values, "isSet"); return (Criteria) this; } public Criteria andIsSetNotIn(List values) { - addCriterion("is_Set not in", values, "isSet"); + addCriterion("is_set not in", values, "isSet"); return (Criteria) this; } public Criteria andIsSetBetween(Boolean value1, Boolean value2) { - addCriterion("is_Set between", value1, value2, "isSet"); + addCriterion("is_set between", value1, value2, "isSet"); return (Criteria) this; } public Criteria andIsSetNotBetween(Boolean value1, Boolean value2) { - addCriterion("is_Set not between", value1, value2, "isSet"); + addCriterion("is_set not between", value1, value2, "isSet"); return (Criteria) this; } } diff --git a/backend/src/main/java/io/metersphere/base/domain/TestPlan.java b/backend/src/main/java/io/metersphere/base/domain/TestPlan.java index 50612a4b10..f66f9aa094 100644 --- a/backend/src/main/java/io/metersphere/base/domain/TestPlan.java +++ b/backend/src/main/java/io/metersphere/base/domain/TestPlan.java @@ -1,8 +1,9 @@ package io.metersphere.base.domain; -import java.io.Serializable; import lombok.Data; +import java.io.Serializable; + @Data public class TestPlan implements Serializable { private String id; @@ -25,17 +26,19 @@ public class TestPlan implements Serializable { private String executorMatchRule; + private Long createTime; + + private Long updateTime; + + private Long actualEndTime; + private Long plannedStartTime; private Long plannedEndTime; private Long actualStartTime; - private Long actualEndTime; - - private Long createTime; - - private Long updateTime; + private String creator; private String tags; diff --git a/backend/src/main/java/io/metersphere/base/domain/TestPlanExample.java b/backend/src/main/java/io/metersphere/base/domain/TestPlanExample.java index f7ecdc3069..4512f8f5d2 100644 --- a/backend/src/main/java/io/metersphere/base/domain/TestPlanExample.java +++ b/backend/src/main/java/io/metersphere/base/domain/TestPlanExample.java @@ -923,6 +923,316 @@ public class TestPlanExample { addCriterion("update_time not between", value1, value2, "updateTime"); return (Criteria) this; } + + public Criteria andActualEndTimeIsNull() { + addCriterion("actual_end_time is null"); + return (Criteria) this; + } + + public Criteria andActualEndTimeIsNotNull() { + addCriterion("actual_end_time is not null"); + return (Criteria) this; + } + + public Criteria andActualEndTimeEqualTo(Long value) { + addCriterion("actual_end_time =", value, "actualEndTime"); + return (Criteria) this; + } + + public Criteria andActualEndTimeNotEqualTo(Long value) { + addCriterion("actual_end_time <>", value, "actualEndTime"); + return (Criteria) this; + } + + public Criteria andActualEndTimeGreaterThan(Long value) { + addCriterion("actual_end_time >", value, "actualEndTime"); + return (Criteria) this; + } + + public Criteria andActualEndTimeGreaterThanOrEqualTo(Long value) { + addCriterion("actual_end_time >=", value, "actualEndTime"); + return (Criteria) this; + } + + public Criteria andActualEndTimeLessThan(Long value) { + addCriterion("actual_end_time <", value, "actualEndTime"); + return (Criteria) this; + } + + public Criteria andActualEndTimeLessThanOrEqualTo(Long value) { + addCriterion("actual_end_time <=", value, "actualEndTime"); + return (Criteria) this; + } + + public Criteria andActualEndTimeIn(List values) { + addCriterion("actual_end_time in", values, "actualEndTime"); + return (Criteria) this; + } + + public Criteria andActualEndTimeNotIn(List values) { + addCriterion("actual_end_time not in", values, "actualEndTime"); + return (Criteria) this; + } + + public Criteria andActualEndTimeBetween(Long value1, Long value2) { + addCriterion("actual_end_time between", value1, value2, "actualEndTime"); + return (Criteria) this; + } + + public Criteria andActualEndTimeNotBetween(Long value1, Long value2) { + addCriterion("actual_end_time not between", value1, value2, "actualEndTime"); + return (Criteria) this; + } + + public Criteria andPlannedStartTimeIsNull() { + addCriterion("planned_start_time is null"); + return (Criteria) this; + } + + public Criteria andPlannedStartTimeIsNotNull() { + addCriterion("planned_start_time is not null"); + return (Criteria) this; + } + + public Criteria andPlannedStartTimeEqualTo(Long value) { + addCriterion("planned_start_time =", value, "plannedStartTime"); + return (Criteria) this; + } + + public Criteria andPlannedStartTimeNotEqualTo(Long value) { + addCriterion("planned_start_time <>", value, "plannedStartTime"); + return (Criteria) this; + } + + public Criteria andPlannedStartTimeGreaterThan(Long value) { + addCriterion("planned_start_time >", value, "plannedStartTime"); + return (Criteria) this; + } + + public Criteria andPlannedStartTimeGreaterThanOrEqualTo(Long value) { + addCriterion("planned_start_time >=", value, "plannedStartTime"); + return (Criteria) this; + } + + public Criteria andPlannedStartTimeLessThan(Long value) { + addCriterion("planned_start_time <", value, "plannedStartTime"); + return (Criteria) this; + } + + public Criteria andPlannedStartTimeLessThanOrEqualTo(Long value) { + addCriterion("planned_start_time <=", value, "plannedStartTime"); + return (Criteria) this; + } + + public Criteria andPlannedStartTimeIn(List values) { + addCriterion("planned_start_time in", values, "plannedStartTime"); + return (Criteria) this; + } + + public Criteria andPlannedStartTimeNotIn(List values) { + addCriterion("planned_start_time not in", values, "plannedStartTime"); + return (Criteria) this; + } + + public Criteria andPlannedStartTimeBetween(Long value1, Long value2) { + addCriterion("planned_start_time between", value1, value2, "plannedStartTime"); + return (Criteria) this; + } + + public Criteria andPlannedStartTimeNotBetween(Long value1, Long value2) { + addCriterion("planned_start_time not between", value1, value2, "plannedStartTime"); + return (Criteria) this; + } + + public Criteria andPlannedEndTimeIsNull() { + addCriterion("planned_end_time is null"); + return (Criteria) this; + } + + public Criteria andPlannedEndTimeIsNotNull() { + addCriterion("planned_end_time is not null"); + return (Criteria) this; + } + + public Criteria andPlannedEndTimeEqualTo(Long value) { + addCriterion("planned_end_time =", value, "plannedEndTime"); + return (Criteria) this; + } + + public Criteria andPlannedEndTimeNotEqualTo(Long value) { + addCriterion("planned_end_time <>", value, "plannedEndTime"); + return (Criteria) this; + } + + public Criteria andPlannedEndTimeGreaterThan(Long value) { + addCriterion("planned_end_time >", value, "plannedEndTime"); + return (Criteria) this; + } + + public Criteria andPlannedEndTimeGreaterThanOrEqualTo(Long value) { + addCriterion("planned_end_time >=", value, "plannedEndTime"); + return (Criteria) this; + } + + public Criteria andPlannedEndTimeLessThan(Long value) { + addCriterion("planned_end_time <", value, "plannedEndTime"); + return (Criteria) this; + } + + public Criteria andPlannedEndTimeLessThanOrEqualTo(Long value) { + addCriterion("planned_end_time <=", value, "plannedEndTime"); + return (Criteria) this; + } + + public Criteria andPlannedEndTimeIn(List values) { + addCriterion("planned_end_time in", values, "plannedEndTime"); + return (Criteria) this; + } + + public Criteria andPlannedEndTimeNotIn(List values) { + addCriterion("planned_end_time not in", values, "plannedEndTime"); + return (Criteria) this; + } + + public Criteria andPlannedEndTimeBetween(Long value1, Long value2) { + addCriterion("planned_end_time between", value1, value2, "plannedEndTime"); + return (Criteria) this; + } + + public Criteria andPlannedEndTimeNotBetween(Long value1, Long value2) { + addCriterion("planned_end_time not between", value1, value2, "plannedEndTime"); + return (Criteria) this; + } + + public Criteria andActualStartTimeIsNull() { + addCriterion("actual_start_time is null"); + return (Criteria) this; + } + + public Criteria andActualStartTimeIsNotNull() { + addCriterion("actual_start_time is not null"); + return (Criteria) this; + } + + public Criteria andActualStartTimeEqualTo(Long value) { + addCriterion("actual_start_time =", value, "actualStartTime"); + return (Criteria) this; + } + + public Criteria andActualStartTimeNotEqualTo(Long value) { + addCriterion("actual_start_time <>", value, "actualStartTime"); + return (Criteria) this; + } + + public Criteria andActualStartTimeGreaterThan(Long value) { + addCriterion("actual_start_time >", value, "actualStartTime"); + return (Criteria) this; + } + + public Criteria andActualStartTimeGreaterThanOrEqualTo(Long value) { + addCriterion("actual_start_time >=", value, "actualStartTime"); + return (Criteria) this; + } + + public Criteria andActualStartTimeLessThan(Long value) { + addCriterion("actual_start_time <", value, "actualStartTime"); + return (Criteria) this; + } + + public Criteria andActualStartTimeLessThanOrEqualTo(Long value) { + addCriterion("actual_start_time <=", value, "actualStartTime"); + return (Criteria) this; + } + + public Criteria andActualStartTimeIn(List values) { + addCriterion("actual_start_time in", values, "actualStartTime"); + return (Criteria) this; + } + + public Criteria andActualStartTimeNotIn(List values) { + addCriterion("actual_start_time not in", values, "actualStartTime"); + return (Criteria) this; + } + + public Criteria andActualStartTimeBetween(Long value1, Long value2) { + addCriterion("actual_start_time between", value1, value2, "actualStartTime"); + return (Criteria) this; + } + + public Criteria andActualStartTimeNotBetween(Long value1, Long value2) { + addCriterion("actual_start_time not between", value1, value2, "actualStartTime"); + return (Criteria) this; + } + + public Criteria andCreatorIsNull() { + addCriterion("creator is null"); + return (Criteria) this; + } + + public Criteria andCreatorIsNotNull() { + addCriterion("creator is not null"); + return (Criteria) this; + } + + public Criteria andCreatorEqualTo(String value) { + addCriterion("creator =", value, "creator"); + return (Criteria) this; + } + + public Criteria andCreatorNotEqualTo(String value) { + addCriterion("creator <>", value, "creator"); + return (Criteria) this; + } + + public Criteria andCreatorGreaterThan(String value) { + addCriterion("creator >", value, "creator"); + return (Criteria) this; + } + + public Criteria andCreatorGreaterThanOrEqualTo(String value) { + addCriterion("creator >=", value, "creator"); + return (Criteria) this; + } + + public Criteria andCreatorLessThan(String value) { + addCriterion("creator <", value, "creator"); + return (Criteria) this; + } + + public Criteria andCreatorLessThanOrEqualTo(String value) { + addCriterion("creator <=", value, "creator"); + return (Criteria) this; + } + + public Criteria andCreatorLike(String value) { + addCriterion("creator like", value, "creator"); + return (Criteria) this; + } + + public Criteria andCreatorNotLike(String value) { + addCriterion("creator not like", value, "creator"); + return (Criteria) this; + } + + public Criteria andCreatorIn(List values) { + addCriterion("creator in", values, "creator"); + return (Criteria) this; + } + + public Criteria andCreatorNotIn(List values) { + addCriterion("creator not in", values, "creator"); + return (Criteria) this; + } + + public Criteria andCreatorBetween(String value1, String value2) { + addCriterion("creator between", value1, value2, "creator"); + return (Criteria) this; + } + + public Criteria andCreatorNotBetween(String value1, String value2) { + addCriterion("creator not between", value1, value2, "creator"); + return (Criteria) this; + } } public static class Criteria extends GeneratedCriteria { diff --git a/backend/src/main/java/io/metersphere/base/mapper/MessageTaskMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/MessageTaskMapper.xml index 79a43f34f8..9840abd9e4 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/MessageTaskMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/MessageTaskMapper.xml @@ -9,7 +9,7 @@ - + @@ -70,7 +70,7 @@ - id, `type`, event, user_id, task_type, webhook, identification, is_Set + id, `type`, event, user_id, task_type, webhook, identification, is_set @@ -274,83 +296,88 @@ stage = #{record.stage,jdbcType=VARCHAR}, - - principal = #{record.principal,jdbcType=VARCHAR}, - - - test_case_match_rule = #{record.testCaseMatchRule,jdbcType=VARCHAR}, - - - executor_match_rule = #{record.executorMatchRule,jdbcType=VARCHAR}, - - - planned_start_time = #{record.plannedStartTime,jdbcType=BIGINT}, - - - planned_end_time = #{record.plannedEndTime,jdbcType=BIGINT}, - - - actual_start_time = #{record.actualStartTime,jdbcType=BIGINT}, - - - actual_end_time = #{record.actualEndTime,jdbcType=BIGINT}, - - - create_time = #{record.createTime,jdbcType=BIGINT}, - - - update_time = #{record.updateTime,jdbcType=BIGINT}, - - - tags = #{record.tags,jdbcType=LONGVARCHAR}, - + + principal = #{record.principal,jdbcType=VARCHAR}, + + + test_case_match_rule = #{record.testCaseMatchRule,jdbcType=VARCHAR}, + + + executor_match_rule = #{record.executorMatchRule,jdbcType=VARCHAR}, + + + create_time = #{record.createTime,jdbcType=BIGINT}, + + + update_time = #{record.updateTime,jdbcType=BIGINT}, + + + actual_end_time = #{record.actualEndTime,jdbcType=BIGINT}, + + + planned_start_time = #{record.plannedStartTime,jdbcType=BIGINT}, + + + planned_end_time = #{record.plannedEndTime,jdbcType=BIGINT}, + + + actual_start_time = #{record.actualStartTime,jdbcType=BIGINT}, + + + creator = #{record.creator,jdbcType=VARCHAR}, + + + tags = #{record.tags,jdbcType=LONGVARCHAR}, + - update test_plan - set id = #{record.id,jdbcType=VARCHAR}, - workspace_id = #{record.workspaceId,jdbcType=VARCHAR}, - report_id = #{record.reportId,jdbcType=VARCHAR}, - `name` = #{record.name,jdbcType=VARCHAR}, - description = #{record.description,jdbcType=VARCHAR}, - `status` = #{record.status,jdbcType=VARCHAR}, - stage = #{record.stage,jdbcType=VARCHAR}, - principal = #{record.principal,jdbcType=VARCHAR}, - test_case_match_rule = #{record.testCaseMatchRule,jdbcType=VARCHAR}, - executor_match_rule = #{record.executorMatchRule,jdbcType=VARCHAR}, - planned_start_time = #{record.plannedStartTime,jdbcType=BIGINT}, - planned_end_time = #{record.plannedEndTime,jdbcType=BIGINT}, - actual_start_time = #{record.actualStartTime,jdbcType=BIGINT}, - actual_end_time = #{record.actualEndTime,jdbcType=BIGINT}, - create_time = #{record.createTime,jdbcType=BIGINT}, - update_time = #{record.updateTime,jdbcType=BIGINT}, - tags = #{record.tags,jdbcType=LONGVARCHAR} - + update test_plan + set id = #{record.id,jdbcType=VARCHAR}, + workspace_id = #{record.workspaceId,jdbcType=VARCHAR}, + report_id = #{record.reportId,jdbcType=VARCHAR}, + `name` = #{record.name,jdbcType=VARCHAR}, + description = #{record.description,jdbcType=VARCHAR}, + `status` = #{record.status,jdbcType=VARCHAR}, + stage = #{record.stage,jdbcType=VARCHAR}, + principal = #{record.principal,jdbcType=VARCHAR}, + test_case_match_rule = #{record.testCaseMatchRule,jdbcType=VARCHAR}, + executor_match_rule = #{record.executorMatchRule,jdbcType=VARCHAR}, + create_time = #{record.createTime,jdbcType=BIGINT}, + update_time = #{record.updateTime,jdbcType=BIGINT}, + actual_end_time = #{record.actualEndTime,jdbcType=BIGINT}, + planned_start_time = #{record.plannedStartTime,jdbcType=BIGINT}, + planned_end_time = #{record.plannedEndTime,jdbcType=BIGINT}, + actual_start_time = #{record.actualStartTime,jdbcType=BIGINT}, + creator = #{record.creator,jdbcType=VARCHAR}, + tags = #{record.tags,jdbcType=LONGVARCHAR} + - update test_plan - set id = #{record.id,jdbcType=VARCHAR}, - workspace_id = #{record.workspaceId,jdbcType=VARCHAR}, - report_id = #{record.reportId,jdbcType=VARCHAR}, - `name` = #{record.name,jdbcType=VARCHAR}, - description = #{record.description,jdbcType=VARCHAR}, - `status` = #{record.status,jdbcType=VARCHAR}, - stage = #{record.stage,jdbcType=VARCHAR}, - principal = #{record.principal,jdbcType=VARCHAR}, - test_case_match_rule = #{record.testCaseMatchRule,jdbcType=VARCHAR}, - executor_match_rule = #{record.executorMatchRule,jdbcType=VARCHAR}, - planned_start_time = #{record.plannedStartTime,jdbcType=BIGINT}, - planned_end_time = #{record.plannedEndTime,jdbcType=BIGINT}, - actual_start_time = #{record.actualStartTime,jdbcType=BIGINT}, - actual_end_time = #{record.actualEndTime,jdbcType=BIGINT}, - create_time = #{record.createTime,jdbcType=BIGINT}, - update_time = #{record.updateTime,jdbcType=BIGINT} - + update test_plan + set id = #{record.id,jdbcType=VARCHAR}, + workspace_id = #{record.workspaceId,jdbcType=VARCHAR}, + report_id = #{record.reportId,jdbcType=VARCHAR}, + `name` = #{record.name,jdbcType=VARCHAR}, + description = #{record.description,jdbcType=VARCHAR}, + `status` = #{record.status,jdbcType=VARCHAR}, + stage = #{record.stage,jdbcType=VARCHAR}, + principal = #{record.principal,jdbcType=VARCHAR}, + test_case_match_rule = #{record.testCaseMatchRule,jdbcType=VARCHAR}, + executor_match_rule = #{record.executorMatchRule,jdbcType=VARCHAR}, + create_time = #{record.createTime,jdbcType=BIGINT}, + update_time = #{record.updateTime,jdbcType=BIGINT}, + actual_end_time = #{record.actualEndTime,jdbcType=BIGINT}, + planned_start_time = #{record.plannedStartTime,jdbcType=BIGINT}, + planned_end_time = #{record.plannedEndTime,jdbcType=BIGINT}, + actual_start_time = #{record.actualStartTime,jdbcType=BIGINT}, + creator = #{record.creator,jdbcType=VARCHAR} + @@ -373,78 +400,83 @@ `status` = #{status,jdbcType=VARCHAR}, - stage = #{stage,jdbcType=VARCHAR}, - - - principal = #{principal,jdbcType=VARCHAR}, - - - test_case_match_rule = #{testCaseMatchRule,jdbcType=VARCHAR}, - - - executor_match_rule = #{executorMatchRule,jdbcType=VARCHAR}, - - - planned_start_time = #{plannedStartTime,jdbcType=BIGINT}, - - - planned_end_time = #{plannedEndTime,jdbcType=BIGINT}, - - - actual_start_time = #{actualStartTime,jdbcType=BIGINT}, - - - actual_end_time = #{actualEndTime,jdbcType=BIGINT}, - - - create_time = #{createTime,jdbcType=BIGINT}, - - - update_time = #{updateTime,jdbcType=BIGINT}, - - - tags = #{tags,jdbcType=LONGVARCHAR}, + stage = #{stage,jdbcType=VARCHAR}, + + principal = #{principal,jdbcType=VARCHAR}, + + + test_case_match_rule = #{testCaseMatchRule,jdbcType=VARCHAR}, + + + executor_match_rule = #{executorMatchRule,jdbcType=VARCHAR}, + + + create_time = #{createTime,jdbcType=BIGINT}, + + + update_time = #{updateTime,jdbcType=BIGINT}, + + + actual_end_time = #{actualEndTime,jdbcType=BIGINT}, + + + planned_start_time = #{plannedStartTime,jdbcType=BIGINT}, + + + planned_end_time = #{plannedEndTime,jdbcType=BIGINT}, + + + actual_start_time = #{actualStartTime,jdbcType=BIGINT}, + + + creator = #{creator,jdbcType=VARCHAR}, + + + tags = #{tags,jdbcType=LONGVARCHAR}, + where id = #{id,jdbcType=VARCHAR} - update test_plan - set workspace_id = #{workspaceId,jdbcType=VARCHAR}, - report_id = #{reportId,jdbcType=VARCHAR}, - `name` = #{name,jdbcType=VARCHAR}, - description = #{description,jdbcType=VARCHAR}, - `status` = #{status,jdbcType=VARCHAR}, - stage = #{stage,jdbcType=VARCHAR}, - principal = #{principal,jdbcType=VARCHAR}, - test_case_match_rule = #{testCaseMatchRule,jdbcType=VARCHAR}, - executor_match_rule = #{executorMatchRule,jdbcType=VARCHAR}, - planned_start_time = #{plannedStartTime,jdbcType=BIGINT}, - planned_end_time = #{plannedEndTime,jdbcType=BIGINT}, - actual_start_time = #{actualStartTime,jdbcType=BIGINT}, - actual_end_time = #{actualEndTime,jdbcType=BIGINT}, - create_time = #{createTime,jdbcType=BIGINT}, - update_time = #{updateTime,jdbcType=BIGINT}, - tags = #{tags,jdbcType=LONGVARCHAR} - where id = #{id,jdbcType=VARCHAR} + update test_plan + set workspace_id = #{workspaceId,jdbcType=VARCHAR}, + report_id = #{reportId,jdbcType=VARCHAR}, + `name` = #{name,jdbcType=VARCHAR}, + description = #{description,jdbcType=VARCHAR}, + `status` = #{status,jdbcType=VARCHAR}, + stage = #{stage,jdbcType=VARCHAR}, + principal = #{principal,jdbcType=VARCHAR}, + test_case_match_rule = #{testCaseMatchRule,jdbcType=VARCHAR}, + executor_match_rule = #{executorMatchRule,jdbcType=VARCHAR}, + create_time = #{createTime,jdbcType=BIGINT}, + update_time = #{updateTime,jdbcType=BIGINT}, + actual_end_time = #{actualEndTime,jdbcType=BIGINT}, + planned_start_time = #{plannedStartTime,jdbcType=BIGINT}, + planned_end_time = #{plannedEndTime,jdbcType=BIGINT}, + actual_start_time = #{actualStartTime,jdbcType=BIGINT}, + creator = #{creator,jdbcType=VARCHAR}, + tags = #{tags,jdbcType=LONGVARCHAR} + where id = #{id,jdbcType=VARCHAR} - update test_plan - set workspace_id = #{workspaceId,jdbcType=VARCHAR}, - report_id = #{reportId,jdbcType=VARCHAR}, - `name` = #{name,jdbcType=VARCHAR}, - description = #{description,jdbcType=VARCHAR}, - `status` = #{status,jdbcType=VARCHAR}, - stage = #{stage,jdbcType=VARCHAR}, - principal = #{principal,jdbcType=VARCHAR}, - test_case_match_rule = #{testCaseMatchRule,jdbcType=VARCHAR}, - executor_match_rule = #{executorMatchRule,jdbcType=VARCHAR}, - planned_start_time = #{plannedStartTime,jdbcType=BIGINT}, - planned_end_time = #{plannedEndTime,jdbcType=BIGINT}, - actual_start_time = #{actualStartTime,jdbcType=BIGINT}, - actual_end_time = #{actualEndTime,jdbcType=BIGINT}, - create_time = #{createTime,jdbcType=BIGINT}, - update_time = #{updateTime,jdbcType=BIGINT} - where id = #{id,jdbcType=VARCHAR} + update test_plan + set workspace_id = #{workspaceId,jdbcType=VARCHAR}, + report_id = #{reportId,jdbcType=VARCHAR}, + `name` = #{name,jdbcType=VARCHAR}, + description = #{description,jdbcType=VARCHAR}, + `status` = #{status,jdbcType=VARCHAR}, + stage = #{stage,jdbcType=VARCHAR}, + principal = #{principal,jdbcType=VARCHAR}, + test_case_match_rule = #{testCaseMatchRule,jdbcType=VARCHAR}, + executor_match_rule = #{executorMatchRule,jdbcType=VARCHAR}, + create_time = #{createTime,jdbcType=BIGINT}, + update_time = #{updateTime,jdbcType=BIGINT}, + actual_end_time = #{actualEndTime,jdbcType=BIGINT}, + planned_start_time = #{plannedStartTime,jdbcType=BIGINT}, + planned_end_time = #{plannedEndTime,jdbcType=BIGINT}, + actual_start_time = #{actualStartTime,jdbcType=BIGINT}, + creator = #{creator,jdbcType=VARCHAR} + where id = #{id,jdbcType=VARCHAR} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/commons/constants/NoticeConstants.java b/backend/src/main/java/io/metersphere/commons/constants/NoticeConstants.java index 330c0b11ca..ddd3e67e74 100644 --- a/backend/src/main/java/io/metersphere/commons/constants/NoticeConstants.java +++ b/backend/src/main/java/io/metersphere/commons/constants/NoticeConstants.java @@ -7,15 +7,18 @@ public interface NoticeConstants { String NAIL_ROBOT = "NAIL_ROBOT"; String WECHAT_ROBOT = "WECHAT_ROBOT"; String CREATE = "CREATE"; - String UPDATE = "CREATE"; + String UPDATE = "UPDATE"; String DELETE = "DELETE"; String JENKINS_TASK = "JENKINS_TASK"; String TEST_PLAN_TASK = "TEST_PLAN_TASK"; String REVIEW_TASK = "REVIEW_TASK"; String DEFECT_TASK = "DEFECT_TASK"; - String FOUNDER="FOUNDER"; - String EXECUTOR="EXECUTOR"; - String MAINTAINER="MAINTAINER"; + String FOUNDER = "FOUNDER"; + String EXECUTOR = "EXECUTOR"; + String MAINTAINER = "MAINTAINER"; + String COMMENT = "COMMENT"; + String API = "API"; + String SCHEDULE = "SCHEDULE"; } diff --git a/backend/src/main/java/io/metersphere/notice/service/DingTaskService.java b/backend/src/main/java/io/metersphere/notice/service/DingTaskService.java index 06e480a9ca..e0c052cc7e 100644 --- a/backend/src/main/java/io/metersphere/notice/service/DingTaskService.java +++ b/backend/src/main/java/io/metersphere/notice/service/DingTaskService.java @@ -11,33 +11,47 @@ import io.metersphere.notice.domain.UserDetail; import io.metersphere.service.UserService; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; @Service +@Transactional(rollbackFor = Exception.class) public class DingTaskService { @Resource private UserService userService; - public void sendNailRobot(MessageDetail messageDetail, List userIds, String context, String eventType){ - List addresseeIdList=new ArrayList<>(); - messageDetail.getEvents().forEach(e->{ - if(StringUtils.equals(eventType,e)){ - messageDetail.getUserIds().forEach(u->{ - if(StringUtils.equals(NoticeConstants.FOUNDER,u)){ - addresseeIdList.addAll(userIds); - }else{ + + public void sendNailRobot(MessageDetail messageDetail, List userIds, String context, String eventType) { + List addresseeIdList = new ArrayList<>(); + messageDetail.getEvents().forEach(e -> { + if (StringUtils.equals(eventType, e)) { + messageDetail.getUserIds().forEach(u -> { + if (!StringUtils.equals(NoticeConstants.EXECUTOR, u) && !StringUtils.equals(NoticeConstants.EXECUTOR, u) && !StringUtils.equals(NoticeConstants.MAINTAINER, u)) { addresseeIdList.add(u); } + if (StringUtils.equals(NoticeConstants.CREATE, eventType) && StringUtils.equals(NoticeConstants.EXECUTOR, u)) { + addresseeIdList.addAll(userIds); + } + if (StringUtils.equals(NoticeConstants.UPDATE, eventType) && StringUtils.equals(NoticeConstants.FOUNDER, u)) { + addresseeIdList.addAll(userIds); + } + if (StringUtils.equals(NoticeConstants.DELETE, eventType) && StringUtils.equals(NoticeConstants.FOUNDER, u)) { + addresseeIdList.addAll(userIds); + } + if (StringUtils.equals(NoticeConstants.COMMENT, eventType) && StringUtils.equals(NoticeConstants.MAINTAINER, u)) { + addresseeIdList.addAll(userIds); + } + + }); - sendDingTask(context, addresseeIdList,messageDetail.getWebhook()); + sendDingTask(context, addresseeIdList, messageDetail.getWebhook()); } }); } - public void sendDingTask(String context, List userIds,String Webhook) { + public void sendDingTask(String context, List userIds, String Webhook) { DingTalkClient client = new DefaultDingTalkClient(Webhook); OapiRobotSendRequest request = new OapiRobotSendRequest(); request.setMsgtype("text"); @@ -45,13 +59,12 @@ public class DingTaskService { text.setContent(context); request.setText(text); OapiRobotSendRequest.At at = new OapiRobotSendRequest.At(); - List list=userService.queryTypeByIds(userIds); - List phoneList=new ArrayList<>(); - list.forEach(u->{ + List list = userService.queryTypeByIds(userIds); + List phoneList = new ArrayList<>(); + list.forEach(u -> { phoneList.add(u.getPhone()); }); - /* at.setAtMobiles(phoneList);*/ - at.setAtMobiles(Arrays.asList("15135125273","13718506428")); + at.setAtMobiles(phoneList); request.setAt(at); OapiRobotSendResponse response = null; try { diff --git a/backend/src/main/java/io/metersphere/notice/service/MailService.java b/backend/src/main/java/io/metersphere/notice/service/MailService.java index c033de6c94..891540f154 100644 --- a/backend/src/main/java/io/metersphere/notice/service/MailService.java +++ b/backend/src/main/java/io/metersphere/notice/service/MailService.java @@ -8,6 +8,7 @@ import io.metersphere.commons.constants.APITestStatus; import io.metersphere.commons.constants.NoticeConstants; import io.metersphere.commons.constants.ParamConstants; import io.metersphere.commons.constants.PerformanceTestStatus; +import io.metersphere.commons.user.SessionUser; import io.metersphere.commons.utils.EncryptUtils; import io.metersphere.commons.utils.LogUtil; import io.metersphere.dto.BaseSystemConfigDTO; @@ -17,6 +18,8 @@ import io.metersphere.notice.domain.NoticeDetail; import io.metersphere.notice.domain.UserDetail; import io.metersphere.service.SystemParameterService; import io.metersphere.service.UserService; +import io.metersphere.track.request.testcase.IssuesRequest; +import io.metersphere.track.request.testplan.AddTestPlanRequest; import io.metersphere.track.request.testreview.SaveCommentRequest; import io.metersphere.track.request.testreview.SaveTestCaseReviewRequest; import org.apache.commons.collections4.MapUtils; @@ -27,6 +30,7 @@ import org.springframework.mail.MailException; import org.springframework.mail.javamail.JavaMailSenderImpl; import org.springframework.mail.javamail.MimeMessageHelper; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import javax.mail.MessagingException; @@ -36,9 +40,8 @@ import java.text.SimpleDateFormat; import java.util.*; @Service +@Transactional(rollbackFor = Exception.class) public class MailService { - @Resource - private ApiAndPerformanceHelper apiAndPerformanceHelper; @Resource private UserService userService; @Resource @@ -86,6 +89,27 @@ public class MailService { } } + //jenkins + public void sendApiJenkinsNotification(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 list = userService.queryTypeByIds(messageDetail.getUserIds()); + List 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 noticeList, String status, Map context, String template) throws MessagingException { JavaMailSenderImpl javaMailSender = getMailSender(); MimeMessage mimeMessage = javaMailSender.createMimeMessage(); @@ -98,15 +122,25 @@ public class MailService { javaMailSender.send(mimeMessage); } catch (MailException e) { LogUtil.error(e); - LogUtil.error("Failed to send mail"); } } + //测试评审 public void sendEndNotice(MessageDetail messageDetail, List userIds, SaveTestCaseReviewRequest reviewRequest, String eventType) { Map context = getReviewContext(reviewRequest); try { String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/end.html"), StandardCharsets.UTF_8); - sendReviewNotice(addresseeIdList(messageDetail,userIds,eventType), context, endTemplate); + sendReviewNotice(addresseeIdList(messageDetail, userIds, eventType), context, endTemplate); + } catch (Exception e) { + LogUtil.error(e); + } + } + + public void sendDeleteNotice(MessageDetail messageDetail, List userIds, SaveTestCaseReviewRequest reviewRequest, String eventType) { + Map context = getReviewContext(reviewRequest); + try { + String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/deleteReview.html"), StandardCharsets.UTF_8); + sendReviewNotice(addresseeIdList(messageDetail, userIds, eventType), context, endTemplate); } catch (Exception e) { LogUtil.error(e); } @@ -122,7 +156,7 @@ public class MailService { context.put("id", testCaseWithBLOBs.getId()); try { String commentTemplate = IOUtils.toString(this.getClass().getResource("/mail/comment.html"), StandardCharsets.UTF_8); - sendReviewNotice(userIds, context, commentTemplate); + sendReviewNotice(addresseeIdList(messageDetail, userIds, eventType), context, commentTemplate); } catch (Exception e) { LogUtil.error(e); } @@ -132,7 +166,54 @@ public class MailService { Map context = getReviewContext(reviewRequest); try { String reviewerTemplate = IOUtils.toString(this.getClass().getResource("/mail/reviewer.html"), StandardCharsets.UTF_8); - sendReviewNotice(addresseeIdList(messageDetail,userIds,eventType), context, reviewerTemplate); + sendReviewNotice(addresseeIdList(messageDetail, userIds, eventType), context, reviewerTemplate); + } catch (Exception e) { + LogUtil.error(e); + } + } + + //测试计划 + public void sendTestPlanStartNotice(MessageDetail messageDetail, List userIds, AddTestPlanRequest testPlan, String eventType) { + Map context = getTestPlanContext(testPlan); + context.put("creator", userIds.toString()); + try { + 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 userIds, AddTestPlanRequest testPlan, String eventType) { + Map context = getTestPlanContext(testPlan); + context.put("creator", userIds.toString()); + try { + 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 userIds, AddTestPlanRequest testPlan, String eventType) { + Map context = getTestPlanContext(testPlan); + context.put("creator", userIds.toString()); + try { + 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); + } + } + + //缺陷任务 + public void sendIssuesNotice(MessageDetail messageDetail, List userIds, IssuesRequest issuesRequest, String eventType, SessionUser user) { + Map 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); + sendIssuesNotice(addresseeIdList(messageDetail, userIds, eventType), context, endTemplate); } catch (Exception e) { LogUtil.error(e); } @@ -164,26 +245,87 @@ public class MailService { return context; } + private Map getTestPlanContext(AddTestPlanRequest testPlan) { + Long startTime = testPlan.getPlannedStartTime(); + Long endTime = testPlan.getPlannedEndTime(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String start = null; + String sTime = String.valueOf(startTime); + String eTime = String.valueOf(endTime); + if (!sTime.equals("null")) { + start = sdf.format(new Date(Long.parseLong(sTime))); + } + String end = null; + if (!eTime.equals("null")) { + end = sdf.format(new Date(Long.parseLong(eTime))); + } + + Map context = new HashMap<>(); + BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo(); + context.put("url", baseSystemConfigDTO.getUrl()); + context.put("testPlanName", testPlan.getName()); + context.put("start", start); + context.put("end", end); + context.put("id", testPlan.getId()); + return context; + } + private void sendReviewNotice(List userIds, Map 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("test_review_task_notice")); + helper.setSubject("MeterSphere平台" + Translator.get("test_review_task_notice")); String[] users; List emails = new ArrayList<>(); - try { - List list=userService.queryTypeByIds(userIds); - list.forEach(u->{ - emails.add(u.getEmail()); - }); - } catch (Exception e) { - LogUtil.error("Recipient information is empty"); + List 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 userIds, Map context, String Template) throws MessagingException { + 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 emails = new ArrayList<>(); + List 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 userIds, Map context, String Template) 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_defect_notification")); + String[] users; + List emails = new ArrayList<>(); + List 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() { @@ -266,15 +408,27 @@ public class MailService { messageDetail.getEvents().forEach(e -> { if (StringUtils.equals(eventType, e)) { messageDetail.getUserIds().forEach(u -> { - if (StringUtils.equals(NoticeConstants.FOUNDER, u)) { - addresseeIdList.addAll(userIds); - } else { + if (!StringUtils.equals(NoticeConstants.EXECUTOR, u) && !StringUtils.equals(NoticeConstants.EXECUTOR, u) && !StringUtils.equals(NoticeConstants.MAINTAINER, u)) { addresseeIdList.add(u); } + if (StringUtils.equals(NoticeConstants.CREATE, eventType) && StringUtils.equals(NoticeConstants.EXECUTOR, u)) { + addresseeIdList.addAll(userIds); + } + if (StringUtils.equals(NoticeConstants.UPDATE, eventType) && StringUtils.equals(NoticeConstants.FOUNDER, u)) { + addresseeIdList.addAll(userIds); + } + if (StringUtils.equals(NoticeConstants.DELETE, eventType) && StringUtils.equals(NoticeConstants.FOUNDER, u)) { + addresseeIdList.addAll(userIds); + } + if (StringUtils.equals(NoticeConstants.COMMENT, eventType) && StringUtils.equals(NoticeConstants.MAINTAINER, u)) { + addresseeIdList.addAll(userIds); + } + + }); } }); - return addresseeIdList; + return addresseeIdList; } } diff --git a/backend/src/main/java/io/metersphere/notice/service/NoticeService.java b/backend/src/main/java/io/metersphere/notice/service/NoticeService.java index d1791a369b..c48e2ba854 100644 --- a/backend/src/main/java/io/metersphere/notice/service/NoticeService.java +++ b/backend/src/main/java/io/metersphere/notice/service/NoticeService.java @@ -1,6 +1,9 @@ package io.metersphere.notice.service; -import io.metersphere.base.domain.*; +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; @@ -10,8 +13,8 @@ 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.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.*; @@ -21,6 +24,7 @@ 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; @@ -149,7 +153,7 @@ public class NoticeService { return user.getTaskType() + "#" + user.getIdentification(); } - public int delMessage(String identification){ + public int delMessage(String identification) { MessageTaskExample example = new MessageTaskExample(); example.createCriteria().andIdentificationEqualTo(identification); return messageTaskMapper.deleteByExample(example); diff --git a/backend/src/main/java/io/metersphere/notice/service/WxChatTaskService.java b/backend/src/main/java/io/metersphere/notice/service/WxChatTaskService.java index d7cc443570..9edba93d45 100644 --- a/backend/src/main/java/io/metersphere/notice/service/WxChatTaskService.java +++ b/backend/src/main/java/io/metersphere/notice/service/WxChatTaskService.java @@ -9,6 +9,7 @@ import io.metersphere.notice.util.WxChatbotClient; import io.metersphere.service.UserService; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.io.IOException; @@ -16,35 +17,48 @@ import java.util.ArrayList; import java.util.List; @Service +@Transactional(rollbackFor = Exception.class) public class WxChatTaskService { @Resource private UserService userService; - public void sendWechatRobot(MessageDetail messageDetail, List userIds, String context, String eventType){ - List addresseeIdList=new ArrayList<>(); - messageDetail.getEvents().forEach(e->{ - if(StringUtils.equals(eventType,e)){ - messageDetail.getUserIds().forEach(u->{ - if(StringUtils.equals(NoticeConstants.FOUNDER,u)){ - addresseeIdList.addAll(userIds); - }else{ + + public void sendWechatRobot(MessageDetail messageDetail, List userIds, String context, String eventType) { + List addresseeIdList = new ArrayList<>(); + messageDetail.getEvents().forEach(e -> { + if (StringUtils.equals(eventType, e)) { + messageDetail.getUserIds().forEach(u -> { + if (!StringUtils.equals(NoticeConstants.EXECUTOR, u) && !StringUtils.equals(NoticeConstants.EXECUTOR, u) && !StringUtils.equals(NoticeConstants.MAINTAINER, u)) { addresseeIdList.add(u); } + if (StringUtils.equals(NoticeConstants.CREATE, eventType) && StringUtils.equals(NoticeConstants.EXECUTOR, u)) { + addresseeIdList.addAll(userIds); + } + if (StringUtils.equals(NoticeConstants.UPDATE, eventType) && StringUtils.equals(NoticeConstants.FOUNDER, u)) { + addresseeIdList.addAll(userIds); + } + if (StringUtils.equals(NoticeConstants.DELETE, eventType) && StringUtils.equals(NoticeConstants.FOUNDER, u)) { + addresseeIdList.addAll(userIds); + } + if (StringUtils.equals(NoticeConstants.COMMENT, eventType) && StringUtils.equals(NoticeConstants.MAINTAINER, u)) { + addresseeIdList.addAll(userIds); + } + + }); - enterpriseWechatTask(context, addresseeIdList,messageDetail.getWebhook()); + enterpriseWechatTask(context, addresseeIdList, messageDetail.getWebhook()); } }); } - public void enterpriseWechatTask(String context, List userIds,String Webhook) { + + public void enterpriseWechatTask(String context, List userIds, String Webhook) { TextMessage message = new TextMessage(context); List mentionedMobileList = new ArrayList(); - List list=userService.queryTypeByIds(userIds); - List phoneList=new ArrayList<>(); - list.forEach(u->{ + List list = userService.queryTypeByIds(userIds); + List phoneList = new ArrayList<>(); + list.forEach(u -> { phoneList.add(u.getPhone()); }); mentionedMobileList.addAll(phoneList); - mentionedMobileList.add("15135125273"); - mentionedMobileList.add("18046109770"); message.setMentionedMobileList(mentionedMobileList); try { SendResult result = WxChatbotClient.send(Webhook, message); diff --git a/backend/src/main/java/io/metersphere/service/SystemParameterService.java b/backend/src/main/java/io/metersphere/service/SystemParameterService.java index aacb29db6c..680a0886e0 100644 --- a/backend/src/main/java/io/metersphere/service/SystemParameterService.java +++ b/backend/src/main/java/io/metersphere/service/SystemParameterService.java @@ -15,6 +15,7 @@ import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.mail.javamail.JavaMailSenderImpl; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import javax.mail.MessagingException; @@ -22,6 +23,7 @@ import java.util.*; @Service +@Transactional(rollbackFor = Exception.class) public class SystemParameterService { @Resource @@ -29,9 +31,10 @@ public class SystemParameterService { @Resource private ExtSystemParameterMapper extSystemParameterMapper; - public String searchEmail(){ - return extSystemParameterMapper.email(); - } + public String searchEmail() { + return extSystemParameterMapper.email(); + } + public String getSystemLanguage() { String result = StringUtils.EMPTY; SystemParameterExample example = new SystemParameterExample(); diff --git a/backend/src/main/java/io/metersphere/track/controller/TestCaseReviewController.java b/backend/src/main/java/io/metersphere/track/controller/TestCaseReviewController.java index 7f52fc1bf3..6236c1f20b 100644 --- a/backend/src/main/java/io/metersphere/track/controller/TestCaseReviewController.java +++ b/backend/src/main/java/io/metersphere/track/controller/TestCaseReviewController.java @@ -12,8 +12,8 @@ import io.metersphere.commons.utils.SessionUtils; import io.metersphere.service.CheckOwnerService; import io.metersphere.track.dto.TestCaseReviewDTO; import io.metersphere.track.dto.TestReviewDTOWithMetric; -import io.metersphere.track.request.testreview.ReviewRelevanceRequest; import io.metersphere.track.request.testreview.QueryCaseReviewRequest; +import io.metersphere.track.request.testreview.ReviewRelevanceRequest; import io.metersphere.track.request.testreview.SaveTestCaseReviewRequest; import io.metersphere.track.request.testreview.TestReviewRelevanceRequest; import io.metersphere.track.service.TestCaseReviewService; @@ -21,6 +21,7 @@ import io.metersphere.track.service.TestReviewProjectService; import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.RequiresRoles; import org.springframework.web.bind.annotation.*; + import javax.annotation.Resource; import java.util.List; diff --git a/backend/src/main/java/io/metersphere/track/service/IssuesService.java b/backend/src/main/java/io/metersphere/track/service/IssuesService.java index 8030b09b74..6353e08bfd 100644 --- a/backend/src/main/java/io/metersphere/track/service/IssuesService.java +++ b/backend/src/main/java/io/metersphere/track/service/IssuesService.java @@ -1,23 +1,35 @@ package io.metersphere.track.service; -import io.metersphere.base.domain.*; +import io.metersphere.base.domain.Issues; +import io.metersphere.base.domain.Project; +import io.metersphere.base.domain.ServiceIntegration; +import io.metersphere.base.domain.TestCaseWithBLOBs; import io.metersphere.base.mapper.IssuesMapper; import io.metersphere.commons.constants.IssuesManagePlatform; +import io.metersphere.commons.constants.NoticeConstants; import io.metersphere.commons.user.SessionUser; +import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.SessionUtils; import io.metersphere.controller.request.IntegrationRequest; +import io.metersphere.notice.domain.MessageDetail; +import io.metersphere.notice.domain.MessageSettingDetail; +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.IntegrationService; import io.metersphere.service.ProjectService; import io.metersphere.track.issue.AbstractIssuePlatform; import io.metersphere.track.issue.IssueFactory; import io.metersphere.track.issue.PlatformUser; import io.metersphere.track.request.testcase.IssuesRequest; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.apache.commons.lang3.StringUtils; import javax.annotation.Resource; -import java.util.*; +import java.util.ArrayList; +import java.util.List; @Service @Transactional(rollbackFor = Exception.class) @@ -31,7 +43,14 @@ public class IssuesService { private TestCaseService testCaseService; @Resource private IssuesMapper issuesMapper; - + @Resource + MailService mailService; + @Resource + DingTaskService dingTaskService; + @Resource + WxChatTaskService wxChatTaskService; + @Resource + NoticeService noticeService; public void testAuth(String platform) { AbstractIssuePlatform abstractPlatform = IssueFactory.createPlatform(platform, new IssuesRequest()); @@ -71,6 +90,28 @@ public class IssuesService { platformList.forEach(platform -> { platform.addIssue(issuesRequest); }); + List userIds = new ArrayList<>(); + userIds.add(orgId); + try { + String context = getIssuesContext(user, issuesRequest, NoticeConstants.CREATE); + MessageSettingDetail messageSettingDetail = noticeService.searchMessage(); + List taskList = messageSettingDetail.getDefectTask(); + taskList.forEach(r -> { + switch (r.getType()) { + case NoticeConstants.NAIL_ROBOT: + dingTaskService.sendNailRobot(r, userIds, context, NoticeConstants.CREATE); + break; + case NoticeConstants.WECHAT_ROBOT: + wxChatTaskService.sendWechatRobot(r, userIds, context, NoticeConstants.CREATE); + break; + case NoticeConstants.EMAIL: + mailService.sendIssuesNotice(r, userIds, issuesRequest, NoticeConstants.CREATE, user); + break; + } + }); + } catch (Exception e) { + LogUtil.error(e); + } } @@ -151,4 +192,12 @@ public class IssuesService { public void deleteIssue(String id) { issuesMapper.deleteByPrimaryKey(id); } + + private static String getIssuesContext(SessionUser user, IssuesRequest issuesRequest, String type) { + String context = ""; + if (StringUtils.equals(NoticeConstants.CREATE, type)) { + context = "缺陷任务通知:" + user.getName() + "发起了一个缺陷" + "'" + issuesRequest.getTitle() + "'" + "请跟进"; + } + return context; + } } diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseCommentService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseCommentService.java index ba4afc0df1..b3aeaef768 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseCommentService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseCommentService.java @@ -11,17 +11,20 @@ import io.metersphere.base.mapper.UserMapper; import io.metersphere.commons.constants.NoticeConstants; import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.SessionUtils; +import io.metersphere.notice.domain.MessageDetail; +import io.metersphere.notice.domain.MessageSettingDetail; 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.track.request.testreview.SaveCommentRequest; -import io.metersphere.track.request.testreview.SaveTestCaseReviewRequest; -import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.UUID; @@ -43,6 +46,9 @@ public class TestCaseCommentService { DingTaskService dingTaskService; @Resource WxChatTaskService wxChatTaskService; + @Resource + NoticeService noticeService; + public void saveComment(SaveCommentRequest request) { TestCaseComment testCaseComment = new TestCaseComment(); @@ -55,18 +61,25 @@ public class TestCaseCommentService { testCaseCommentMapper.insert(testCaseComment); TestCaseWithBLOBs testCaseWithBLOBs; testCaseWithBLOBs = testCaseMapper.selectByPrimaryKey(request.getCaseId()); - SaveTestCaseReviewRequest caseReviewRequest = new SaveTestCaseReviewRequest(); List userIds = new ArrayList<>(); - userIds.add(testCaseWithBLOBs.getMaintainer()); - String context = getReviewContext(request, testCaseWithBLOBs); + userIds.add(testCaseWithBLOBs.getMaintainer());//用例维护人 try { - /* if (StringUtils.equals(NoticeConstants.NAIL_ROBOT, "NAIL_ROBOT")) { - dingTaskService.sendDingTask(context, userIds); - } else if (StringUtils.equals(NoticeConstants.WECHAT_ROBOT, "WECHAT_ROBOT")) { - wxChatTaskService.enterpriseWechatTask(); - } else { - mailService.sendCommentNotice(userIds, request, testCaseWithBLOBs); - }*/ + String context = getReviewContext(testCaseComment, testCaseWithBLOBs); + MessageSettingDetail messageSettingDetail = noticeService.searchMessage(); + List taskList = messageSettingDetail.getReviewTask(); + taskList.forEach(r -> { + switch (r.getType()) { + case NoticeConstants.NAIL_ROBOT: + dingTaskService.sendNailRobot(r, userIds, context, NoticeConstants.COMMENT); + break; + case NoticeConstants.WECHAT_ROBOT: + wxChatTaskService.sendWechatRobot(r, userIds, context, NoticeConstants.COMMENT); + break; + case NoticeConstants.EMAIL: + mailService.sendCommentNotice(r, userIds, request, testCaseWithBLOBs, NoticeConstants.COMMENT); + break; + } + }); } catch (Exception e) { LogUtil.error(e); } @@ -93,9 +106,16 @@ public class TestCaseCommentService { testCaseCommentMapper.deleteByExample(testCaseCommentExample); } - private String getReviewContext(SaveCommentRequest request, TestCaseWithBLOBs testCaseWithBLOBs) { + private String getReviewContext(TestCaseComment testCaseComment, TestCaseWithBLOBs testCaseWithBLOBs) { + Long startTime = testCaseComment.getCreateTime(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String start = null; + String sTime = String.valueOf(startTime); + if (!sTime.equals("null")) { + start = sdf.format(new Date(Long.parseLong(sTime))); + } String context = ""; - context = testCaseWithBLOBs.getMaintainer() + "发起的" + "'" + testCaseWithBLOBs.getName() + "'" + "添加评论:" + request.getDescription(); + context = "测试评审任务通知:" + testCaseComment.getAuthor() + "在" + start + "为" + "'" + testCaseWithBLOBs.getName() + "'" + "添加评论:" + testCaseComment.getDescription(); return context; } } diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseReviewService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseReviewService.java index 5b74252573..cb1e875d35 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseReviewService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseReviewService.java @@ -25,7 +25,6 @@ import io.metersphere.service.UserService; import io.metersphere.track.dto.TestCaseReviewDTO; import io.metersphere.track.dto.TestReviewCaseDTO; import io.metersphere.track.dto.TestReviewDTOWithMetric; -import io.metersphere.track.request.testcase.QueryTestCaseRequest; import io.metersphere.track.request.testreview.QueryCaseReviewRequest; import io.metersphere.track.request.testreview.QueryTestReviewRequest; import io.metersphere.track.request.testreview.ReviewRelevanceRequest; @@ -86,10 +85,9 @@ public class TestCaseReviewService { public void saveTestCaseReview(SaveTestCaseReviewRequest reviewRequest) { checkCaseReviewExist(reviewRequest); - String reviewId = UUID.randomUUID().toString(); List projectIds = reviewRequest.getProjectIds(); - List userIds = reviewRequest.getUserIds(); + List userIds = reviewRequest.getUserIds();//执行人 projectIds.forEach(projectId -> { TestCaseReviewProject testCaseReviewProject = new TestCaseReviewProject(); testCaseReviewProject.setProjectId(projectId); @@ -107,23 +105,23 @@ public class TestCaseReviewService { reviewRequest.setId(reviewId); reviewRequest.setCreateTime(System.currentTimeMillis()); reviewRequest.setUpdateTime(System.currentTimeMillis()); - reviewRequest.setCreator(SessionUtils.getUser().getId()); + reviewRequest.setCreator(SessionUtils.getUser().getId());//创建人 reviewRequest.setStatus(TestCaseReviewStatus.Prepare.name()); testCaseReviewMapper.insert(reviewRequest); try { String context = getReviewContext(reviewRequest, NoticeConstants.CREATE); MessageSettingDetail messageSettingDetail = noticeService.searchMessage(); - List taskList=messageSettingDetail.getReviewTask(); - taskList.forEach(r->{ + List taskList = messageSettingDetail.getReviewTask(); + taskList.forEach(r -> { switch (r.getType()) { case NoticeConstants.NAIL_ROBOT: - dingTaskService.sendNailRobot(r,userIds,context,NoticeConstants.CREATE); + dingTaskService.sendNailRobot(r, userIds, context, NoticeConstants.CREATE); break; case NoticeConstants.WECHAT_ROBOT: - wxChatTaskService.sendWechatRobot(r,userIds,context,NoticeConstants.CREATE); + wxChatTaskService.sendWechatRobot(r, userIds, context, NoticeConstants.CREATE); break; case NoticeConstants.EMAIL: - mailService.sendReviewerNotice(r,userIds, reviewRequest,NoticeConstants.CREATE); + mailService.sendReviewerNotice(r, userIds, reviewRequest, NoticeConstants.CREATE); break; } }); @@ -131,7 +129,7 @@ public class TestCaseReviewService { LogUtil.error(e); } - } + } public List listCaseReview(QueryCaseReviewRequest request) { request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); @@ -189,17 +187,17 @@ public class TestCaseReviewService { try { String context = getReviewContext(testCaseReview, NoticeConstants.CREATE); MessageSettingDetail messageSettingDetail = noticeService.searchMessage(); - List taskList=messageSettingDetail.getReviewTask(); - taskList.forEach(r->{ + List taskList = messageSettingDetail.getReviewTask(); + taskList.forEach(r -> { switch (r.getType()) { case NoticeConstants.NAIL_ROBOT: - dingTaskService.sendNailRobot(r,testCaseReview.getUserIds(),context,NoticeConstants.CREATE); + dingTaskService.sendNailRobot(r, testCaseReview.getUserIds(), context, NoticeConstants.CREATE); break; case NoticeConstants.WECHAT_ROBOT: - wxChatTaskService.sendWechatRobot(r,testCaseReview.getUserIds(),context,NoticeConstants.CREATE); + wxChatTaskService.sendWechatRobot(r, testCaseReview.getUserIds(), context, NoticeConstants.CREATE); break; case NoticeConstants.EMAIL: - mailService.sendReviewerNotice(r,testCaseReview.getUserIds(), testCaseReview,NoticeConstants.CREATE); + mailService.sendReviewerNotice(r, testCaseReview.getUserIds(), testCaseReview, NoticeConstants.CREATE); break; } }); @@ -287,10 +285,36 @@ public class TestCaseReviewService { } public void deleteCaseReview(String reviewId) { + TestCaseReview testCaseReview = getTestReview(reviewId); deleteCaseReviewProject(reviewId); deleteCaseReviewUsers(reviewId); deleteCaseReviewTestCase(reviewId); testCaseReviewMapper.deleteByPrimaryKey(reviewId); + List userIds = new ArrayList<>(); + userIds.add(SessionUtils.getUser().getId()); + SaveTestCaseReviewRequest testCaseReviewRequest = new SaveTestCaseReviewRequest(); + try { + BeanUtils.copyProperties(testCaseReviewRequest, testCaseReview); + String context = getReviewContext(testCaseReviewRequest, NoticeConstants.DELETE); + MessageSettingDetail messageSettingDetail = noticeService.searchMessage(); + List taskList = messageSettingDetail.getReviewTask(); + taskList.forEach(r -> { + switch (r.getType()) { + case NoticeConstants.NAIL_ROBOT: + dingTaskService.sendNailRobot(r, userIds, context, NoticeConstants.DELETE); + break; + case NoticeConstants.WECHAT_ROBOT: + wxChatTaskService.sendWechatRobot(r, userIds, context, NoticeConstants.DELETE); + break; + case NoticeConstants.EMAIL: + mailService.sendDeleteNotice(r, userIds, testCaseReviewRequest, NoticeConstants.DELETE); + break; + } + }); + } catch (Exception e) { + LogUtil.error(e); + } + } private void deleteCaseReviewProject(String reviewId) { @@ -405,31 +429,34 @@ public class TestCaseReviewService { } } testCaseReview.setStatus(TestCaseReviewStatus.Completed.name()); + testCaseReviewMapper.updateByPrimaryKeySelective(testCaseReview); SaveTestCaseReviewRequest testCaseReviewRequest = new SaveTestCaseReviewRequest(); TestCaseReview _testCaseReview = testCaseReviewMapper.selectByPrimaryKey(reviewId); List userIds = new ArrayList<>(); userIds.add(_testCaseReview.getCreator()); - testCaseReviewMapper.updateByPrimaryKeySelective(testCaseReview); - try { - BeanUtils.copyProperties(testCaseReviewRequest, _testCaseReview); - String context = getReviewContext(testCaseReviewRequest, NoticeConstants.UPDATE); - MessageSettingDetail messageSettingDetail = noticeService.searchMessage(); - List taskList=messageSettingDetail.getReviewTask(); - taskList.forEach(r->{ - switch (r.getType()) { - case NoticeConstants.NAIL_ROBOT: - dingTaskService.sendNailRobot(r,userIds,context,NoticeConstants.CREATE); - break; - case NoticeConstants.WECHAT_ROBOT: - wxChatTaskService.sendWechatRobot(r,userIds,context,NoticeConstants.CREATE); - break; - case NoticeConstants.EMAIL: - mailService.sendReviewerNotice(r,userIds, testCaseReviewRequest,NoticeConstants.CREATE); - break; - } - }); - } catch (Exception e) { - LogUtil.error(e); + if (StringUtils.equals(TestCaseReviewStatus.Completed.name(), _testCaseReview.getStatus())) { + + try { + BeanUtils.copyProperties(testCaseReviewRequest, _testCaseReview); + String context = getReviewContext(testCaseReviewRequest, NoticeConstants.UPDATE); + MessageSettingDetail messageSettingDetail = noticeService.searchMessage(); + List taskList = messageSettingDetail.getReviewTask(); + taskList.forEach(r -> { + switch (r.getType()) { + case NoticeConstants.NAIL_ROBOT: + dingTaskService.sendNailRobot(r, userIds, context, NoticeConstants.UPDATE); + break; + case NoticeConstants.WECHAT_ROBOT: + wxChatTaskService.sendWechatRobot(r, userIds, context, NoticeConstants.UPDATE); + break; + case NoticeConstants.EMAIL: + mailService.sendReviewerNotice(r, userIds, testCaseReviewRequest, NoticeConstants.UPDATE); + break; + } + }); + } catch (Exception e) { + LogUtil.error(e); + } } } @@ -518,7 +545,8 @@ public class TestCaseReviewService { request.setProjectIds(projectIds); return extTestReviewCaseMapper.list(request); } - /*通知内容*/ + + /*编辑,新建,完成,删除通知内容*/ private static String getReviewContext(SaveTestCaseReviewRequest reviewRequest, String type) { Long startTime = reviewRequest.getCreateTime(); Long endTime = reviewRequest.getEndTime(); @@ -535,12 +563,15 @@ public class TestCaseReviewService { } String context = ""; if (StringUtils.equals(NoticeConstants.CREATE, type)) { - context = reviewRequest.getCreator() + "发起的任务通知" + "'" + reviewRequest.getName() + "'" + "待开始,计划开始时间是" + start + "计划结束时间为" + end + "请跟进"; + context = "测试评审任务通知:" + reviewRequest.getCreator() + "发起的" + "'" + reviewRequest.getName() + "'" + "待开始,计划开始时间是" + start + "计划结束时间为" + end + "请跟进"; } else if (StringUtils.equals(NoticeConstants.UPDATE, type)) { - context = reviewRequest.getCreator() + "发起的任务通知" + "'" + reviewRequest.getName() + "'" + "已完成,计划开始时间是" + start + "计划结束时间为" + end + "已完成"; + context = "测试评审任务通知:" + reviewRequest.getCreator() + "发起的" + "'" + reviewRequest.getName() + "'" + "已完成,计划开始时间是" + start + "计划结束时间为" + end + "已完成"; + } else if (StringUtils.equals(NoticeConstants.DELETE, type)) { + context = "测试评审任务通知:" + reviewRequest.getCreator() + "发起的" + "'" + reviewRequest.getName() + "'" + "计划开始时间是" + start + "计划结束时间为" + end + "已删除"; } return context; } + } diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java index be9d749659..d3dcc11733 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java @@ -9,15 +9,19 @@ import io.metersphere.base.mapper.ext.ExtProjectMapper; import io.metersphere.base.mapper.ext.ExtTestCaseMapper; import io.metersphere.base.mapper.ext.ExtTestPlanMapper; import io.metersphere.base.mapper.ext.ExtTestPlanTestCaseMapper; +import io.metersphere.commons.constants.NoticeConstants; import io.metersphere.commons.constants.TestPlanStatus; import io.metersphere.commons.constants.TestPlanTestCaseStatus; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.user.SessionUser; -import io.metersphere.commons.utils.CommonBeanFactory; -import io.metersphere.commons.utils.MathUtils; -import io.metersphere.commons.utils.ServiceUtils; -import io.metersphere.commons.utils.SessionUtils; +import io.metersphere.commons.utils.*; import io.metersphere.i18n.Translator; +import io.metersphere.notice.domain.MessageDetail; +import io.metersphere.notice.domain.MessageSettingDetail; +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.track.Factory.ReportComponentFactory; import io.metersphere.track.domain.ReportComponent; import io.metersphere.track.dto.TestCaseReportMetricDTO; @@ -25,7 +29,6 @@ import io.metersphere.track.dto.TestPlanCaseDTO; import io.metersphere.track.dto.TestPlanDTO; import io.metersphere.track.dto.TestPlanDTOWithMetric; import io.metersphere.track.request.testcase.PlanCaseRelevanceRequest; -import io.metersphere.track.request.testcase.QueryTestCaseRequest; import io.metersphere.track.request.testcase.QueryTestPlanRequest; import io.metersphere.track.request.testplan.AddTestPlanRequest; import io.metersphere.track.request.testplancase.QueryTestPlanCaseRequest; @@ -39,7 +42,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import javax.annotation.Resource; - +import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; @@ -82,6 +85,14 @@ public class TestPlanService { ProjectMapper projectMapper; @Resource ExtTestCaseMapper extTestCaseMapper; + @Resource + NoticeService noticeService; + @Resource + MailService mailService; + @Resource + DingTaskService dingTaskService; + @Resource + WxChatTaskService wxChatTaskService; public void addTestPlan(AddTestPlanRequest testPlan) { if (getTestPlanByName(testPlan.getName()).size() > 0) { @@ -102,7 +113,31 @@ public class TestPlanService { testPlan.setStatus(TestPlanStatus.Prepare.name()); testPlan.setCreateTime(System.currentTimeMillis()); testPlan.setUpdateTime(System.currentTimeMillis()); + testPlan.setCreator(SessionUtils.getUser().getId()); testPlanMapper.insert(testPlan); + + List userIds = new ArrayList<>(); + userIds.add(testPlan.getPrincipal()); + try { + String context = getTestPlanContext(testPlan, NoticeConstants.CREATE); + MessageSettingDetail messageSettingDetail = noticeService.searchMessage(); + List taskList = messageSettingDetail.getTestCasePlanTask(); + taskList.forEach(r -> { + switch (r.getType()) { + case NoticeConstants.NAIL_ROBOT: + dingTaskService.sendNailRobot(r, userIds, context, NoticeConstants.CREATE); + break; + case NoticeConstants.WECHAT_ROBOT: + wxChatTaskService.sendWechatRobot(r, userIds, context, NoticeConstants.CREATE); + break; + case NoticeConstants.EMAIL: + mailService.sendTestPlanStartNotice(r, userIds, testPlan, NoticeConstants.CREATE); + break; + } + }); + } catch (Exception e) { + LogUtil.error(e); + } } public List getTestPlanByName(String name) { @@ -128,6 +163,30 @@ public class TestPlanService { //已完成,写入实际完成时间 testPlan.setActualEndTime(System.currentTimeMillis()); } + List userIds = new ArrayList<>(); + userIds.add(testPlan.getPrincipal()); + AddTestPlanRequest testPlans = new AddTestPlanRequest(); + /* try { + BeanUtils.copyBean(testPlans, testPlan); + String context = getTestPlanContext(testPlans, NoticeConstants.CREATE); + MessageSettingDetail messageSettingDetail = noticeService.searchMessage(); + List taskList = messageSettingDetail.getReviewTask(); + taskList.forEach(r -> { + switch (r.getType()) { + case NoticeConstants.NAIL_ROBOT: + dingTaskService.sendNailRobot(r, userIds, context, NoticeConstants.CREATE); + break; + case NoticeConstants.WECHAT_ROBOT: + wxChatTaskService.sendWechatRobot(r, userIds, context, NoticeConstants.CREATE); + break; + case NoticeConstants.EMAIL: + mailService.sendTestPlanStartNotice(r, userIds, testPlans, NoticeConstants.CREATE); + break; + } + }); + } catch (Exception e) { + LogUtil.error(e); + }*/ return testPlanMapper.updateByPrimaryKeySelective(testPlan); } @@ -183,9 +242,35 @@ public class TestPlanService { } public int deleteTestPlan(String planId) { + TestPlan testPlan = getTestPlan(planId); deleteTestCaseByPlanId(planId); testPlanProjectService.deleteTestPlanProjectByPlanId(planId); - return testPlanMapper.deleteByPrimaryKey(planId); + int num = testPlanMapper.deleteByPrimaryKey(planId); + List userIds = new ArrayList<>(); + AddTestPlanRequest testPlans = new AddTestPlanRequest(); + userIds.add(testPlan.getCreator()); + try { + BeanUtils.copyBean(testPlans, testPlan); + String context = getTestPlanContext(testPlans, NoticeConstants.DELETE); + MessageSettingDetail messageSettingDetail = noticeService.searchMessage(); + List taskList = messageSettingDetail.getReviewTask(); + taskList.forEach(r -> { + switch (r.getType()) { + case NoticeConstants.NAIL_ROBOT: + dingTaskService.sendNailRobot(r, userIds, context, NoticeConstants.DELETE); + break; + case NoticeConstants.WECHAT_ROBOT: + wxChatTaskService.sendWechatRobot(r, userIds, context, NoticeConstants.DELETE); + break; + case NoticeConstants.EMAIL: + mailService.sendTestPlanDeleteNotice(r, userIds, testPlans, NoticeConstants.DELETE); + break; + } + }); + } catch (Exception e) { + LogUtil.error(e); + } + return num; } public void deleteTestCaseByPlanId(String testPlanId) { @@ -389,7 +474,6 @@ public class TestPlanService { List statusList = extTestPlanTestCaseMapper.getStatusByPlanId(planId); TestPlan testPlan = new TestPlan(); testPlan.setId(planId); - for (String status : statusList) { if (StringUtils.equals(status, TestPlanTestCaseStatus.Prepare.name()) || StringUtils.equals(status, TestPlanTestCaseStatus.Underway.name())) { @@ -400,6 +484,34 @@ public class TestPlanService { } testPlan.setStatus(TestPlanStatus.Completed.name()); testPlanMapper.updateByPrimaryKeySelective(testPlan); + TestPlan testPlans = getTestPlan(planId); + List userIds = new ArrayList<>(); + userIds.add(testPlans.getCreator()); + AddTestPlanRequest _testPlans = new AddTestPlanRequest(); + if (StringUtils.equals(TestPlanStatus.Completed.name(), testPlans.getStatus())) { + try { + BeanUtils.copyBean(_testPlans, testPlans); + String context = getTestPlanContext(_testPlans, NoticeConstants.UPDATE); + MessageSettingDetail messageSettingDetail = noticeService.searchMessage(); + List taskList = messageSettingDetail.getReviewTask(); + taskList.forEach(r -> { + switch (r.getType()) { + case NoticeConstants.NAIL_ROBOT: + dingTaskService.sendNailRobot(r, userIds, context, NoticeConstants.UPDATE); + break; + case NoticeConstants.WECHAT_ROBOT: + wxChatTaskService.sendWechatRobot(r, userIds, context, NoticeConstants.UPDATE); + break; + case NoticeConstants.EMAIL: + mailService.sendTestPlanEndNotice(r, userIds, _testPlans, NoticeConstants.UPDATE); + break; + } + }); + } catch (Exception e) { + LogUtil.error(e); + } + } + } public String getProjectNameByPlanId(String testPlanId) { @@ -420,4 +532,30 @@ public class TestPlanService { return projectName; } + + private static String getTestPlanContext(AddTestPlanRequest testPlan, String type) { + Long startTime = testPlan.getPlannedStartTime(); + Long endTime = testPlan.getPlannedEndTime(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String start = null; + String sTime = String.valueOf(startTime); + String eTime = String.valueOf(endTime); + if (!sTime.equals("null")) { + start = sdf.format(new Date(Long.parseLong(sTime))); + } + String end = null; + if (!eTime.equals("null")) { + end = sdf.format(new Date(Long.parseLong(eTime))); + } + String context = ""; + if (StringUtils.equals(NoticeConstants.CREATE, type)) { + context = "测试计划任务通知:" + testPlan.getCreator() + "创建的" + "'" + testPlan.getName() + "'" + "待开始,计划开始时间是" + start + "计划结束时间为" + end + "请跟进"; + } else if (StringUtils.equals(NoticeConstants.UPDATE, type)) { + context = "测试计划任务通知:" + testPlan.getCreator() + "创建的" + "'" + testPlan.getName() + "'" + "已完成,计划开始时间是" + start + "计划结束时间为" + end + "已完成"; + } else if (StringUtils.equals(NoticeConstants.DELETE, type)) { + context = "测试计划任务通知:" + testPlan.getCreator() + "创建的" + "'" + testPlan.getName() + "'" + "计划开始时间是" + start + "计划结束时间为" + end + "已删除"; + } + return context; + } + } diff --git a/backend/src/main/resources/db/migration/V35__modify_test_plan.sql b/backend/src/main/resources/db/migration/V35__modify_test_plan.sql new file mode 100644 index 0000000000..e743137b42 --- /dev/null +++ b/backend/src/main/resources/db/migration/V35__modify_test_plan.sql @@ -0,0 +1,2 @@ +alter table test_plan + add creator varchar(255) not null; \ No newline at end of file diff --git a/backend/src/main/resources/generatorConfig.xml b/backend/src/main/resources/generatorConfig.xml index a2b8b4801c..2ca4e43942 100644 --- a/backend/src/main/resources/generatorConfig.xml +++ b/backend/src/main/resources/generatorConfig.xml @@ -67,6 +67,7 @@
+
\ No newline at end of file diff --git a/backend/src/main/resources/i18n/messages_en_US.properties b/backend/src/main/resources/i18n/messages_en_US.properties index 03340f13b2..35a6684f21 100644 --- a/backend/src/main/resources/i18n/messages_en_US.properties +++ b/backend/src/main/resources/i18n/messages_en_US.properties @@ -164,4 +164,10 @@ check_owner_test=The current user does not have permission to operate this test check_owner_case=The current user does not have permission to operate this use case check_owner_plan=The current user does not have permission to operate this plan check_owner_review=The current user does not have permission to operate this review -upload_content_is_null=Imported content is empty \ No newline at end of file +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 + + + diff --git a/backend/src/main/resources/i18n/messages_zh_CN.properties b/backend/src/main/resources/i18n/messages_zh_CN.properties index efc123244f..63cc1827e6 100644 --- a/backend/src/main/resources/i18n/messages_zh_CN.properties +++ b/backend/src/main/resources/i18n/messages_zh_CN.properties @@ -164,4 +164,7 @@ check_owner_test=当前用户没有操作此测试的权限 check_owner_case=当前用户没有操作此用例的权限 check_owner_plan=当前用户没有操作此计划的权限 check_owner_review=当前用户没有操作此评审的权限 -upload_content_is_null=导入内容为空 \ No newline at end of file +upload_content_is_null=导入内容为空 +test_plan_notification=测试计划通知 +task_defect_notification=缺陷任务通知 +task_notification=jenkins任务通知 \ No newline at end of file diff --git a/backend/src/main/resources/i18n/messages_zh_TW.properties b/backend/src/main/resources/i18n/messages_zh_TW.properties index 4916b0c676..4141e41639 100644 --- a/backend/src/main/resources/i18n/messages_zh_TW.properties +++ b/backend/src/main/resources/i18n/messages_zh_TW.properties @@ -165,4 +165,8 @@ check_owner_test=當前用戶沒有操作此測試的權限 check_owner_case=當前用戶沒有操作此用例的權限 check_owner_plan=當前用戶沒有操作此計劃的權限 check_owner_review=當前用戶沒有操作此評審的權限 -upload_content_is_null=導入內容為空 \ No newline at end of file +upload_content_is_null=導入內容為空 +test_plan_notification=測試計畫通知 +task_defect_notification=缺陷任務通知 +task_notification=jenkins任務通知 + diff --git a/backend/src/main/resources/mail/deleteReview.html b/backend/src/main/resources/mail/deleteReview.html new file mode 100644 index 0000000000..3293c49f4a --- /dev/null +++ b/backend/src/main/resources/mail/deleteReview.html @@ -0,0 +1,16 @@ + + + + + MeterSphere + + +
+

${creator} 发起的:
+ ${reviewName}
+ 计划开始时间是:${start}
+ 计划结束时间为:${end}
+ 已删除
+

+ + \ No newline at end of file diff --git a/backend/src/main/resources/mail/issuesCreate.html b/backend/src/main/resources/mail/issuesCreate.html new file mode 100644 index 0000000000..26b2b7bca2 --- /dev/null +++ b/backend/src/main/resources/mail/issuesCreate.html @@ -0,0 +1,12 @@ + + + + + MeterSphere + + +
+

${creator}发起了一个缺陷:${issuesName},请跟进

+
+ + \ No newline at end of file diff --git a/backend/src/main/resources/mail/testPlanDelete.html b/backend/src/main/resources/mail/testPlanDelete.html new file mode 100644 index 0000000000..5665452f34 --- /dev/null +++ b/backend/src/main/resources/mail/testPlanDelete.html @@ -0,0 +1,17 @@ + + + + + MeterSphere + + +
+

${creator} 创建的:
+ ${testPlanName}
+ 计划开始时间是:${start}
+ 计划结束时间为:${end}
+ 已删除! +

+
+ + \ No newline at end of file diff --git a/backend/src/main/resources/mail/testPlanEnd.html b/backend/src/main/resources/mail/testPlanEnd.html new file mode 100644 index 0000000000..a4557adca9 --- /dev/null +++ b/backend/src/main/resources/mail/testPlanEnd.html @@ -0,0 +1,18 @@ + + + + + MeterSphere + + +
+

${creator} 创建的:
+ ${testPlanName}已完成
+ 计划开始时间是:${start}
+ 计划结束时间为:${end}
+ 已完成!
+ 点击下面链接进入测试计划页面

+ ${url}/#/track/plan/view +
+ + \ No newline at end of file diff --git a/backend/src/main/resources/mail/testPlanStart.html b/backend/src/main/resources/mail/testPlanStart.html new file mode 100644 index 0000000000..a998b36434 --- /dev/null +++ b/backend/src/main/resources/mail/testPlanStart.html @@ -0,0 +1,18 @@ + + + + + MeterSphere + + +
+

${creator} 创建的:
+ ${testPlanName}
+ 计划开始时间是:${start}
+ 计划结束时间为:${end}
+ 请跟进!
+ 点击下面链接进入测试计划页面

+ ${url}/#/track/plan/view +
+ + \ No newline at end of file diff --git a/frontend/src/business/components/settings/organization/TaskNotification.vue b/frontend/src/business/components/settings/organization/TaskNotification.vue index c1fbf3b932..c46f0fb007 100644 --- a/frontend/src/business/components/settings/organization/TaskNotification.vue +++ b/frontend/src/business/components/settings/organization/TaskNotification.vue @@ -27,8 +27,8 @@