From 2fd79fdd5c30e237b3ac546548686cc93e474c05 Mon Sep 17 00:00:00 2001 From: wenyann <64353056+wenyann@users.noreply.github.com> Date: Thu, 29 Oct 2020 17:39:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B6=88=E6=81=AF=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E4=BF=AE=E6=94=B9=EF=BC=8C=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/jmeter/APIBackendListenerClient.java | 10 ++-- .../metersphere/base/domain/MessageTask.java | 2 + .../base/domain/MessageTaskExample.java | 60 +++++++++++++++++++ .../base/mapper/MessageTaskMapper.xml | 43 ++++++++----- .../base/mapper/ext/ExtMessageMapper.java | 12 ++++ .../base/mapper/ext/ExtMessageMapper.xml | 23 +++++++ .../notice/domain/MessageDetail.java | 1 + .../notice/service/MailService.java | 3 +- .../notice/service/NoticeService.java | 22 +++++-- .../V39__modify_message_task_create_time.sql | 2 + .../resources/i18n/messages_en_US.properties | 3 +- .../resources/i18n/messages_zh_CN.properties | 3 +- .../resources/i18n/messages_zh_TW.properties | 3 +- .../mail/ApiSuccessfulNotification.html | 5 +- 14 files changed, 154 insertions(+), 38 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/base/mapper/ext/ExtMessageMapper.java create mode 100644 backend/src/main/java/io/metersphere/base/mapper/ext/ExtMessageMapper.xml create mode 100644 backend/src/main/resources/db/migration/V39__modify_message_task_create_time.sql 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 d4a4a98a8d..1aa3655e5c 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java @@ -158,9 +158,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl } catch (Exception e) { LogUtil.error(e); } - } - try { sendTask(report, testResult); } catch (Exception e) { @@ -185,13 +183,13 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl if (StringUtils.equals(NoticeConstants.API, report.getTriggerMode())) { MessageSettingDetail messageSettingDetail = noticeService.searchMessage(); taskList = messageSettingDetail.getJenkinsTask(); - successContext = "jenkins任务通知:" + report.getName() + "执行成功" + "请点击下面链接进入测试报告页面" + url; - failedContext = "jenkins任务通知:" + report.getName() + "执行失败" + "请点击下面链接进入测试报告页面" + url; + successContext = "jenkins任务通知:'" + report.getName() + "'执行成功" + "\n" + "请点击下面链接进入测试报告页面" + "\n" + url; + failedContext = "jenkins任务通知:'" + report.getName() + "'执行失败" + "\n" + "请点击下面链接进入测试报告页面" + "\n" + url; } if (StringUtils.equals(NoticeConstants.SCHEDULE, report.getTriggerMode())) { taskList = noticeService.searchMessageSchedule(testResult.getTestId()); - successContext = "定时任务通知:" + report.getName() + "执行成功" + "请点击下面链接进入测试报告页面" + url; - failedContext = "定时任务通知:" + report.getName() + "执行失败" + "请点击下面链接进入测试报告页面" + url; + successContext = "定时任务通知:'" + report.getName() + "'执行成功" + "\n" + "请点击下面链接进入测试报告页面" + "\n" + url; + failedContext = "定时任务通知:'" + report.getName() + "'执行失败" + "\n" + "请点击下面链接进入测试报告页面" + "\n" + url; } String finalSuccessContext = successContext; String finalFailedContext = failedContext; diff --git a/backend/src/main/java/io/metersphere/base/domain/MessageTask.java b/backend/src/main/java/io/metersphere/base/domain/MessageTask.java index 4cd0f6414c..286452e5ed 100644 --- a/backend/src/main/java/io/metersphere/base/domain/MessageTask.java +++ b/backend/src/main/java/io/metersphere/base/domain/MessageTask.java @@ -26,5 +26,7 @@ public class MessageTask implements Serializable { private String testId; + private Long createTime; + private static final long serialVersionUID = 1L; } \ No newline at end of file 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 b3d4c40f81..fa4f63c284 100644 --- a/backend/src/main/java/io/metersphere/base/domain/MessageTaskExample.java +++ b/backend/src/main/java/io/metersphere/base/domain/MessageTaskExample.java @@ -793,6 +793,66 @@ public class MessageTaskExample { addCriterion("test_id not between", value1, value2, "testId"); return (Criteria) this; } + + public Criteria andCreateTimeIsNull() { + addCriterion("create_time is null"); + return (Criteria) this; + } + + public Criteria andCreateTimeIsNotNull() { + addCriterion("create_time is not null"); + return (Criteria) this; + } + + public Criteria andCreateTimeEqualTo(Long value) { + addCriterion("create_time =", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotEqualTo(Long value) { + addCriterion("create_time <>", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeGreaterThan(Long value) { + addCriterion("create_time >", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeGreaterThanOrEqualTo(Long value) { + addCriterion("create_time >=", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeLessThan(Long value) { + addCriterion("create_time <", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeLessThanOrEqualTo(Long value) { + addCriterion("create_time <=", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeIn(List values) { + addCriterion("create_time in", values, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotIn(List values) { + addCriterion("create_time not in", values, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeBetween(Long value1, Long value2) { + addCriterion("create_time between", value1, value2, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotBetween(Long value1, Long value2) { + addCriterion("create_time not between", value1, value2, "createTime"); + 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 b1bc62303a..c3d7a6ae5e 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/MessageTaskMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/MessageTaskMapper.xml @@ -2,16 +2,17 @@ - - - - - - - - - + + + + + + + + + + @@ -73,7 +74,7 @@ id, `type`, event, user_id, task_type, webhook, identification, is_set, organization_id, - test_id + test_id, create_time @@ -221,6 +228,9 @@ test_id = #{record.testId,jdbcType=VARCHAR}, + + create_time = #{record.createTime,jdbcType=BIGINT}, + @@ -237,7 +247,8 @@ identification = #{record.identification,jdbcType=VARCHAR}, is_set = #{record.isSet,jdbcType=BIT}, organization_id = #{record.organizationId,jdbcType=VARCHAR}, - test_id = #{record.testId,jdbcType=VARCHAR} + test_id = #{record.testId,jdbcType=VARCHAR}, + create_time = #{record.createTime,jdbcType=BIGINT} @@ -272,6 +283,9 @@ test_id = #{testId,jdbcType=VARCHAR}, + + create_time = #{createTime,jdbcType=BIGINT}, + where id = #{id,jdbcType=VARCHAR} @@ -285,7 +299,8 @@ identification = #{identification,jdbcType=VARCHAR}, is_set = #{isSet,jdbcType=BIT}, organization_id = #{organizationId,jdbcType=VARCHAR}, - test_id = #{testId,jdbcType=VARCHAR} + test_id = #{testId,jdbcType=VARCHAR}, + create_time = #{createTime,jdbcType=BIGINT} where id = #{id,jdbcType=VARCHAR} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtMessageMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtMessageMapper.java new file mode 100644 index 0000000000..f3714f646f --- /dev/null +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtMessageMapper.java @@ -0,0 +1,12 @@ +package io.metersphere.base.mapper.ext; + +import io.metersphere.base.domain.MessageTask; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +public interface ExtMessageMapper { + List searchMessageByTestId(@Param("testId") String testId); + + List searchMessageByOrganizationId(@Param("organizationId") String organizationId); +} diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtMessageMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtMessageMapper.xml new file mode 100644 index 0000000000..f53c48c594 --- /dev/null +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtMessageMapper.xml @@ -0,0 +1,23 @@ + + + + + + + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/notice/domain/MessageDetail.java b/backend/src/main/java/io/metersphere/notice/domain/MessageDetail.java index e3ed51a172..9f4c94ca5f 100644 --- a/backend/src/main/java/io/metersphere/notice/domain/MessageDetail.java +++ b/backend/src/main/java/io/metersphere/notice/domain/MessageDetail.java @@ -16,4 +16,5 @@ public class MessageDetail { private String organizationId; private Boolean isSet; private String testId; + private Long createTime; } 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 86416020a2..d750768e89 100644 --- a/backend/src/main/java/io/metersphere/notice/service/MailService.java +++ b/backend/src/main/java/io/metersphere/notice/service/MailService.java @@ -52,7 +52,6 @@ public class MailService { List userIds = new ArrayList<>(); BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo(); Map context = new HashMap<>(); - context.put("title", "Performance" + Translator.get("timing_task_result_notification")); context.put("testName", loadTestReport.getName()); context.put("id", loadTestReport.getId()); context.put("type", "performance"); @@ -103,7 +102,7 @@ public class MailService { helper.setSubject("MeterSphere平台" + Translator.get("task_notification")); } if (StringUtils.equals(type, NoticeConstants.SCHEDULE)) { - helper.setSubject("MeterSphere平台" + Translator.get("timing_task_notification")); + helper.setSubject("MeterSphere平台" + Translator.get("task_notification_")); } String[] users; List emails = new ArrayList<>(); 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 24ee9ed8fc..43e37fda9c 100644 --- a/backend/src/main/java/io/metersphere/notice/service/NoticeService.java +++ b/backend/src/main/java/io/metersphere/notice/service/NoticeService.java @@ -3,6 +3,7 @@ package io.metersphere.notice.service; import io.metersphere.base.domain.MessageTask; import io.metersphere.base.domain.MessageTaskExample; import io.metersphere.base.mapper.MessageTaskMapper; +import io.metersphere.base.mapper.ext.ExtMessageMapper; import io.metersphere.commons.constants.NoticeConstants; import io.metersphere.commons.user.SessionUser; import io.metersphere.commons.utils.SessionUtils; @@ -21,10 +22,14 @@ import java.util.stream.Collectors; public class NoticeService { @Resource private MessageTaskMapper messageTaskMapper; + @Resource + private ExtMessageMapper extMessageMapper; + public void saveMessageTask(MessageRequest messageRequest) { SessionUser user = SessionUtils.getUser(); String orgId = user.getLastOrganizationId(); + long time = System.currentTimeMillis(); messageRequest.getMessageDetail().forEach(list -> { MessageTaskExample example = new MessageTaskExample(); example.createCriteria().andIdentificationEqualTo(list.getIdentification()); @@ -44,6 +49,7 @@ public class NoticeService { message.setIsSet(list.getIsSet()); message.setOrganizationId(orgId); message.setTestId(list.getTestId()); + message.setCreateTime(time); messageTaskMapper.insert(message); }); } else { @@ -60,6 +66,7 @@ public class NoticeService { message.setIsSet(list.getIsSet()); message.setOrganizationId(orgId); message.setTestId(list.getTestId()); + message.setCreateTime(time); messageTaskMapper.insert(message); }); } @@ -68,9 +75,7 @@ public class NoticeService { } public List searchMessageSchedule(String testId) { - MessageTaskExample example = new MessageTaskExample(); - example.createCriteria().andTestIdEqualTo(testId); - List messageTaskLists = messageTaskMapper.selectByExample(example); + List messageTaskLists = extMessageMapper.searchMessageByTestId(testId); List scheduleMessageTask = new ArrayList<>(); Map> MessageTaskMap = messageTaskLists.stream().collect(Collectors.groupingBy(e -> e.getIdentification())); MessageTaskMap.forEach((k, v) -> { @@ -84,22 +89,22 @@ public class NoticeService { messageDetail.setIdentification(m.getIdentification()); messageDetail.setType(m.getType()); messageDetail.setIsSet(m.getIsSet()); + messageDetail.setCreateTime(m.getCreateTime()); } messageDetail.setUserIds(new ArrayList(userIds)); scheduleMessageTask.add(messageDetail); }); + scheduleMessageTask.sort(Comparator.comparing(MessageDetail::getCreateTime).reversed()); return scheduleMessageTask; } public MessageSettingDetail searchMessage() { SessionUser user = SessionUtils.getUser(); String orgId = user.getLastOrganizationId(); - MessageTaskExample messageTaskExample = new MessageTaskExample(); - messageTaskExample.createCriteria().andOrganizationIdEqualTo(orgId); List messageTaskLists = new ArrayList<>(); MessageSettingDetail messageSettingDetail = new MessageSettingDetail(); List MessageDetailList = new ArrayList<>(); - messageTaskLists = messageTaskMapper.selectByExample(messageTaskExample); + messageTaskLists = extMessageMapper.searchMessageByOrganizationId(orgId); Map> MessageTaskMap = messageTaskLists.stream().collect(Collectors.groupingBy(e -> fetchGroupKey(e))); MessageTaskMap.forEach((k, v) -> { Set userIds = new HashSet(); @@ -112,14 +117,19 @@ public class NoticeService { messageDetail.setIdentification(m.getIdentification()); messageDetail.setType(m.getType()); messageDetail.setIsSet(m.getIsSet()); + messageDetail.setCreateTime(m.getCreateTime()); } messageDetail.setUserIds(new ArrayList(userIds)); MessageDetailList.add(messageDetail); }); List jenkinsTask = MessageDetailList.stream().filter(a -> a.getTaskType().equals(NoticeConstants.JENKINS_TASK)).collect(Collectors.toList()); + jenkinsTask.sort(Comparator.comparing(MessageDetail::getCreateTime).reversed()); List testCasePlanTask = MessageDetailList.stream().filter(a -> a.getTaskType().equals(NoticeConstants.TEST_PLAN_TASK)).collect(Collectors.toList()); + testCasePlanTask.sort(Comparator.comparing(MessageDetail::getCreateTime).reversed()); List reviewTask = MessageDetailList.stream().filter(a -> a.getTaskType().equals(NoticeConstants.REVIEW_TASK)).collect(Collectors.toList()); + reviewTask.sort(Comparator.comparing(MessageDetail::getCreateTime).reversed()); List defectTask = MessageDetailList.stream().filter(a -> a.getTaskType().equals(NoticeConstants.DEFECT_TASK)).collect(Collectors.toList()); + defectTask.sort(Comparator.comparing(MessageDetail::getCreateTime).reversed()); messageSettingDetail.setJenkinsTask(jenkinsTask); messageSettingDetail.setTestCasePlanTask(testCasePlanTask); messageSettingDetail.setReviewTask(reviewTask); diff --git a/backend/src/main/resources/db/migration/V39__modify_message_task_create_time.sql b/backend/src/main/resources/db/migration/V39__modify_message_task_create_time.sql new file mode 100644 index 0000000000..3235c4246d --- /dev/null +++ b/backend/src/main/resources/db/migration/V39__modify_message_task_create_time.sql @@ -0,0 +1,2 @@ +alter table message_task + add create_time bigint(13) null; \ 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 3f568e58ac..9c54d7b580 100644 --- a/backend/src/main/resources/i18n/messages_en_US.properties +++ b/backend/src/main/resources/i18n/messages_en_US.properties @@ -151,7 +151,6 @@ quota_max_threads_excess_workspace=The maximum number of concurrent threads exce quota_max_threads_excess_organization=The maximum number of concurrent threads exceeds the organization quota quota_duration_excess_workspace=The stress test duration exceeds the work space quota quota_duration_excess_organization=The stress test duration exceeds the organization quota -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 @@ -168,7 +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 +task_notification_=Timing task result notification diff --git a/backend/src/main/resources/i18n/messages_zh_CN.properties b/backend/src/main/resources/i18n/messages_zh_CN.properties index dc6f199266..e321dcbcf3 100644 --- a/backend/src/main/resources/i18n/messages_zh_CN.properties +++ b/backend/src/main/resources/i18n/messages_zh_CN.properties @@ -151,7 +151,6 @@ quota_max_threads_excess_workspace=最大并发数超过工作空间限额 quota_max_threads_excess_organization=最大并发数超过组织限额 quota_duration_excess_workspace=压测时长超过工作空间限额 quota_duration_excess_organization=压测时长超过组织限额 -email_subject=MeterSphere定时任务结果通知 import_xmind_count_error=思维导图导入用例数量不能超过 500 条 license_valid_license_error=授权认证失败 import_xmind_not_found=未找到测试用例 @@ -169,4 +168,4 @@ upload_content_is_null=导入内容为空 test_plan_notification=测试计划通知 task_defect_notification=缺陷任务通知 task_notification=jenkins任务通知 -timing_task_notification=定时任务结果通知 \ No newline at end of file +task_notification_=定时任务结果通知 \ 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 fad439a2bf..a1f7c77210 100644 --- a/backend/src/main/resources/i18n/messages_zh_TW.properties +++ b/backend/src/main/resources/i18n/messages_zh_TW.properties @@ -153,7 +153,6 @@ quota_duration_excess_workspace=壓測時長超過工作空間限額 quota_duration_excess_organization=壓測時長超過組織限額 license_valid_license_error=授權驗證失敗 license_valid_license_code=授權碼已經存在 -email_subject=MeterSphere定時任務結果通知 import_xmind_count_error=思維導圖導入用例數量不能超過 500 條 import_xmind_not_found=未找到测试用例 @@ -170,5 +169,5 @@ upload_content_is_null=導入內容為空 test_plan_notification=測試計畫通知 task_defect_notification=缺陷任務通知 task_notification=jenkins任務通知 -timing_task_notification=定時任務通知 +task_notification_=定時任務通知 diff --git a/backend/src/main/resources/mail/ApiSuccessfulNotification.html b/backend/src/main/resources/mail/ApiSuccessfulNotification.html index c951c6b7ab..6512d5089f 100644 --- a/backend/src/main/resources/mail/ApiSuccessfulNotification.html +++ b/backend/src/main/resources/mail/ApiSuccessfulNotification.html @@ -4,10 +4,7 @@ MeterSphere - -
-

${title}

-
+

尊敬的用户:

您好: