From 1f107b69ffd943a2dc20a8bfa276ceb77f32790f Mon Sep 17 00:00:00 2001 From: wenyann <64353056+wenyann@users.noreply.github.com> Date: Tue, 24 Nov 2020 10:33:28 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B6=88=E6=81=AF=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/service/APITestService.java | 6 ++++- .../notice/service/DingTaskService.java | 5 +++- .../notice/service/MailService.java | 23 +++++++++++------ .../notice/service/NoticeService.java | 25 +++++++++++++++---- .../notice/service/WxChatTaskService.java | 5 +++- .../track/service/TestCaseCommentService.java | 8 ++++-- .../track/service/TestCaseReviewService.java | 4 +++ .../track/service/TestPlanService.java | 4 +-- .../resources/i18n/messages_en_US.properties | 1 + .../resources/i18n/messages_zh_CN.properties | 3 ++- .../resources/i18n/messages_zh_TW.properties | 1 + .../components/DefectTaskNotification.vue | 4 +-- .../components/JenkinsNotification.vue | 5 ++-- .../components/ScheduleTaskNotification.vue | 20 +++++++-------- .../components/TestReviewNotification.vue | 2 +- 15 files changed, 80 insertions(+), 36 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/service/APITestService.java b/backend/src/main/java/io/metersphere/api/service/APITestService.java index 9f4a96bd23..85da5303d1 100644 --- a/backend/src/main/java/io/metersphere/api/service/APITestService.java +++ b/backend/src/main/java/io/metersphere/api/service/APITestService.java @@ -25,7 +25,10 @@ import io.metersphere.i18n.Translator; import io.metersphere.job.sechedule.ApiTestJob; import io.metersphere.notice.service.MailService; import io.metersphere.notice.service.NoticeService; -import io.metersphere.service.*; +import io.metersphere.service.FileService; +import io.metersphere.service.QuotaService; +import io.metersphere.service.ScheduleService; +import io.metersphere.service.UserService; import io.metersphere.track.service.TestCaseService; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.constants.CommonConstants; @@ -66,6 +69,7 @@ public class APITestService { @Resource private NoticeService noticeService; + private static final String BODY_FILE_DIR = "/opt/metersphere/data/body"; public List list(QueryAPITestRequest request) { 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 dd30c10ff3..c2d56193ba 100644 --- a/backend/src/main/java/io/metersphere/notice/service/DingTaskService.java +++ b/backend/src/main/java/io/metersphere/notice/service/DingTaskService.java @@ -19,6 +19,7 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; @Service @Transactional(propagation = Propagation.NOT_SUPPORTED) @@ -57,7 +58,9 @@ public class DingTaskService { list.forEach(u -> { phoneList.add(u.getPhone()); }); - at.setAtMobiles(phoneList); + LogUtil.info("收件人地址" + phoneList); + List phoneLists = phoneList.stream().distinct().collect(Collectors.toList()); + at.setAtMobiles(phoneLists); 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 b4237af8ff..6abefde70d 100644 --- a/backend/src/main/java/io/metersphere/notice/service/MailService.java +++ b/backend/src/main/java/io/metersphere/notice/service/MailService.java @@ -37,6 +37,7 @@ import javax.mail.internet.MimeMessage; import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; import java.util.*; +import java.util.stream.Collectors; @Service @Transactional(propagation = Propagation.NOT_SUPPORTED) @@ -111,8 +112,9 @@ public class MailService { list.forEach(u -> { emails.add(u.getEmail()); }); - users = emails.toArray(new String[0]); - LogUtil.info("收件人地址"+users); + List email = emails.stream().distinct().collect(Collectors.toList()); + users = email.toArray(new String[0]); + LogUtil.info("收件人地址" + users); helper.setText(getContent(Template, context), true); helper.setTo(users); try { @@ -144,9 +146,10 @@ public class MailService { } public void sendCommentNotice(MessageDetail messageDetail, List userIds, SaveCommentRequest request, TestCaseWithBLOBs testCaseWithBLOBs, String eventType) { + User user = userMapper.selectByPrimaryKey(testCaseWithBLOBs.getMaintainer()); BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo(); Map context = new HashMap<>(); - context.put("maintainer", testCaseWithBLOBs.getMaintainer()); + context.put("maintainer", user.getName()); context.put("testCaseName", testCaseWithBLOBs.getName()); context.put("description", request.getDescription()); context.put("url", baseSystemConfigDTO.getUrl()); @@ -184,7 +187,9 @@ public class MailService { list.forEach(u -> { emails.add(u.getEmail()); }); - users = emails.toArray(new String[0]); + List email = emails.stream().distinct().collect(Collectors.toList()); + users = email.toArray(new String[0]); + LogUtil.info("收件人地址" + users); helper.setText(getContent(Template, context), true); helper.setTo(users); if (users.length > 0) { @@ -245,7 +250,9 @@ public class MailService { list.forEach(u -> { emails.add(u.getEmail()); }); - users = emails.toArray(new String[0]); + List email = emails.stream().distinct().collect(Collectors.toList()); + users = email.toArray(new String[0]); + LogUtil.info("收件人地址" + users); helper.setText(getContent(Template, context), true); helper.setTo(users); javaMailSender.send(mimeMessage); @@ -280,7 +287,9 @@ public class MailService { list.forEach(u -> { emails.add(u.getEmail()); }); - users = emails.toArray(new String[0]); + List email = emails.stream().distinct().collect(Collectors.toList()); + users = email.toArray(new String[0]); + LogUtil.info("收件人地址" + users); helper.setText(getContent(Template, context), true); helper.setTo(users); javaMailSender.send(mimeMessage); @@ -385,7 +394,7 @@ public class MailService { if (StringUtils.isNotBlank(context.get(k))) { template = RegExUtils.replaceAll(template, "\\$\\{" + k + "}", context.get(k)); } else { - template = RegExUtils.replaceAll(template, "\\$\\{" + k + "}", ""); + template = RegExUtils.replaceAll(template, "\\$\\{" + k + "}", "未设置"); } } } 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 771e651f79..af3257e0cc 100644 --- a/backend/src/main/java/io/metersphere/notice/service/NoticeService.java +++ b/backend/src/main/java/io/metersphere/notice/service/NoticeService.java @@ -5,8 +5,10 @@ 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.exception.MSException; import io.metersphere.commons.user.SessionUser; import io.metersphere.commons.utils.SessionUtils; +import io.metersphere.i18n.Translator; import io.metersphere.notice.controller.request.MessageRequest; import io.metersphere.notice.domain.MessageDetail; import io.metersphere.notice.domain.MessageSettingDetail; @@ -49,6 +51,7 @@ public class NoticeService { long time = System.currentTimeMillis(); String identification = UUID.randomUUID().toString(); list.getUserIds().forEach(m -> { + checkUserIdExist(m, list); MessageTask message = new MessageTask(); message.setId(UUID.randomUUID().toString()); message.setEvent(list.getEvent()); @@ -57,7 +60,7 @@ public class NoticeService { message.setType(list.getType()); message.setWebhook(list.getWebhook()); message.setIdentification(identification); - message.setIsSet(list.getIsSet()); + message.setIsSet(false); message.setOrganizationId(orgId); message.setTestId(list.getTestId()); message.setCreateTime(time); @@ -65,6 +68,14 @@ public class NoticeService { }); } + private void checkUserIdExist(String userId, MessageDetail list) { + MessageTaskExample example = new MessageTaskExample(); + example.createCriteria().andUserIdEqualTo(userId).andEventEqualTo(list.getEvent()).andTypeEqualTo(list.getType()).andTaskTypeEqualTo(list.getTaskType()).andWebhookEqualTo(list.getWebhook()); + if (messageTaskMapper.countByExample(example) > 0) { + MSException.throwException(Translator.get("message_task_already_exists")); + } + } + public List searchMessageSchedule(String testId) { List messageTaskLists = extMessageMapper.searchMessageByTestId(testId); List scheduleMessageTask = new ArrayList<>(); @@ -116,10 +127,14 @@ public class NoticeService { messageDetail.setUserIds(new ArrayList(userIds)); MessageDetailList.add(messageDetail); }); - List jenkinsTask = MessageDetailList.stream().filter(a -> a.getTaskType().equals(NoticeConstants.JENKINS_TASK)).sorted(Comparator.comparing(MessageDetail::getCreateTime, Comparator.nullsLast(Long::compareTo)).reversed()).collect(Collectors.toList()); - List testCasePlanTask = MessageDetailList.stream().filter(a -> a.getTaskType().equals(NoticeConstants.TEST_PLAN_TASK)).sorted(Comparator.comparing(MessageDetail::getCreateTime, Comparator.nullsLast(Long::compareTo)).reversed()).collect(Collectors.toList()); - List reviewTask = MessageDetailList.stream().filter(a -> a.getTaskType().equals(NoticeConstants.REVIEW_TASK)).sorted(Comparator.comparing(MessageDetail::getCreateTime, Comparator.nullsLast(Long::compareTo)).reversed()).collect(Collectors.toList()); - List defectTask = MessageDetailList.stream().filter(a -> a.getTaskType().equals(NoticeConstants.DEFECT_TASK)).sorted(Comparator.comparing(MessageDetail::getCreateTime, Comparator.nullsLast(Long::compareTo)).reversed()).collect(Collectors.toList()); + List jenkinsTask = (MessageDetailList.stream().filter(a -> a.getTaskType().equals(NoticeConstants.JENKINS_TASK)).sorted(Comparator.comparing( + MessageDetail::getCreateTime, Comparator.nullsLast(Long::compareTo)).reversed()).collect(Collectors.toList())).stream().distinct().collect(Collectors.toList()); + List testCasePlanTask = (MessageDetailList.stream().filter(a -> a.getTaskType().equals(NoticeConstants.TEST_PLAN_TASK)).sorted(Comparator.comparing( + MessageDetail::getCreateTime, Comparator.nullsLast(Long::compareTo)).reversed()).collect(Collectors.toList())).stream().distinct().collect(Collectors.toList()); + List reviewTask = (MessageDetailList.stream().filter(a -> a.getTaskType().equals(NoticeConstants.REVIEW_TASK)).sorted(Comparator.comparing( + MessageDetail::getCreateTime, Comparator.nullsLast(Long::compareTo)).reversed()).collect(Collectors.toList())).stream().distinct().collect(Collectors.toList()); + List defectTask = (MessageDetailList.stream().filter(a -> a.getTaskType().equals(NoticeConstants.DEFECT_TASK)).sorted(Comparator.comparing( + MessageDetail::getCreateTime, Comparator.nullsLast(Long::compareTo)).reversed()).collect(Collectors.toList())).stream().distinct().collect(Collectors.toList()); messageSettingDetail.setJenkinsTask(jenkinsTask); messageSettingDetail.setTestCasePlanTask(testCasePlanTask); messageSettingDetail.setReviewTask(reviewTask); 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 10be211dc5..2de762ead7 100644 --- a/backend/src/main/java/io/metersphere/notice/service/WxChatTaskService.java +++ b/backend/src/main/java/io/metersphere/notice/service/WxChatTaskService.java @@ -18,6 +18,7 @@ import javax.annotation.Resource; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; @Service @Transactional(propagation = Propagation.NOT_SUPPORTED) @@ -50,7 +51,9 @@ public class WxChatTaskService { list.forEach(u -> { phoneList.add(u.getPhone()); }); - mentionedMobileList.addAll(phoneList); + LogUtil.info("收件人地址" + phoneList); + List phoneLists = phoneList.stream().distinct().collect(Collectors.toList()); + mentionedMobileList.addAll(phoneLists); message.setMentionedMobileList(mentionedMobileList); try { SendResult result = WxChatbotClient.send(Webhook, message); 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 f7d0f28af4..2ed274c442 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseCommentService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseCommentService.java @@ -3,8 +3,10 @@ package io.metersphere.track.service; import io.metersphere.base.domain.TestCaseComment; import io.metersphere.base.domain.TestCaseCommentExample; import io.metersphere.base.domain.TestCaseWithBLOBs; +import io.metersphere.base.domain.User; import io.metersphere.base.mapper.TestCaseCommentMapper; import io.metersphere.base.mapper.TestCaseMapper; +import io.metersphere.base.mapper.UserMapper; import io.metersphere.base.mapper.ext.ExtTestCaseCommentMapper; import io.metersphere.commons.constants.NoticeConstants; import io.metersphere.commons.exception.MSException; @@ -48,7 +50,8 @@ public class TestCaseCommentService { private NoticeService noticeService; @Resource private ExtTestCaseCommentMapper extTestCaseCommentMapper; - + @Resource + private UserMapper userMapper; public void saveComment(SaveCommentRequest request) { TestCaseComment testCaseComment = new TestCaseComment(); @@ -97,6 +100,7 @@ public class TestCaseCommentService { } private String getReviewContext(TestCaseComment testCaseComment, TestCaseWithBLOBs testCaseWithBLOBs) { + User user = userMapper.selectByPrimaryKey(testCaseComment.getAuthor()); Long startTime = testCaseComment.getCreateTime(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String start = null; @@ -105,7 +109,7 @@ public class TestCaseCommentService { start = sdf.format(new Date(Long.parseLong(sTime))); } String context = ""; - context = "测试评审任务通知:" + testCaseComment.getAuthor() + "在" + start + "为" + "'" + testCaseWithBLOBs.getName() + "'" + "添加评论:" + testCaseComment.getDescription(); + context = "测试评审任务通知:" + user.getName() + "在" + 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 8a76212498..13d75cb5d7 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseReviewService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseReviewService.java @@ -572,10 +572,14 @@ public class TestCaseReviewService { String eTime = String.valueOf(endTime); if (!sTime.equals("null")) { start = sdf.format(new Date(Long.parseLong(sTime))); + } else { + start = "未设置"; } String end = null; if (!eTime.equals("null")) { end = sdf.format(new Date(Long.parseLong(eTime))); + } else { + start = "未设置"; } String context = ""; if (StringUtils.equals(NoticeConstants.CREATE, type)) { 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 c8157e472d..2911fe8605 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java @@ -547,13 +547,13 @@ public class TestPlanService { if (!sTime.equals("null")) { start = sdf.format(new Date(Long.parseLong(sTime))); } else { - start = ""; + start = "未设置"; } String end = null; if (!eTime.equals("null")) { end = sdf.format(new Date(Long.parseLong(eTime))); } else { - end = ""; + end = "未设置"; } String context = ""; if (StringUtils.equals(NoticeConstants.CREATE, type)) { diff --git a/backend/src/main/resources/i18n/messages_en_US.properties b/backend/src/main/resources/i18n/messages_en_US.properties index e13f4ca6ea..bc98163881 100644 --- a/backend/src/main/resources/i18n/messages_en_US.properties +++ b/backend/src/main/resources/i18n/messages_en_US.properties @@ -170,6 +170,7 @@ test_plan_notification=Test plan notification task_defect_notification=Task defect notification task_notification_jenkins=Jenkins Task notification task_notification=Result notification +message_task_already_exists=Task recipient already exists diff --git a/backend/src/main/resources/i18n/messages_zh_CN.properties b/backend/src/main/resources/i18n/messages_zh_CN.properties index 8f5290eeb0..6a4133be16 100644 --- a/backend/src/main/resources/i18n/messages_zh_CN.properties +++ b/backend/src/main/resources/i18n/messages_zh_CN.properties @@ -170,4 +170,5 @@ upload_content_is_null=导入内容为空 test_plan_notification=测试计划通知 task_defect_notification=缺陷任务通知 task_notification_jenkins=jenkins任务通知 -task_notification=任务通知 \ No newline at end of file +task_notification=任务通知 +message_task_already_exists=任务接收人已经存在 \ 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 ec322418ad..9c2402b647 100644 --- a/backend/src/main/resources/i18n/messages_zh_TW.properties +++ b/backend/src/main/resources/i18n/messages_zh_TW.properties @@ -172,4 +172,5 @@ test_plan_notification=測試計畫通知 task_defect_notification=缺陷任務通知 task_notification_jenkins=jenkins任務通知 task_notification=任務通知 +message_task_already_exists=任務接收人已經存在 diff --git a/frontend/src/business/components/settings/organization/components/DefectTaskNotification.vue b/frontend/src/business/components/settings/organization/components/DefectTaskNotification.vue index aa17e59edb..f3d86d02c5 100644 --- a/frontend/src/business/components/settings/organization/components/DefectTaskNotification.vue +++ b/frontend/src/business/components/settings/organization/components/DefectTaskNotification.vue @@ -145,14 +145,14 @@ export default { data.isReadOnly = true; if (data.type === 'EMAIL') { data.isReadOnly = !data.isReadOnly - data.webhook = '' + data.webhook = ''; } }, handleEditTask(index,data) { data.isSet = true if (data.type === 'EMAIL') { data.isReadOnly = false; - data.webhook = '' + data.webhook = ''; } else { data.isReadOnly = true; } diff --git a/frontend/src/business/components/settings/organization/components/JenkinsNotification.vue b/frontend/src/business/components/settings/organization/components/JenkinsNotification.vue index 3cf5f91f2a..56e392c224 100644 --- a/frontend/src/business/components/settings/organization/components/JenkinsNotification.vue +++ b/frontend/src/business/components/settings/organization/components/JenkinsNotification.vue @@ -195,7 +195,7 @@ export default { data.isSet = true if (data.type === 'EMAIL') { data.isReadOnly = false; - data.webhook = '' + data.webhook = ''; } else { data.isReadOnly = true; } @@ -203,7 +203,6 @@ export default { }, addTask(data) { let list = []; - data.isSet = false; list.push(data); let param = {}; param.messageDetail = list; @@ -216,7 +215,7 @@ export default { if (!data[index].identification) { data.splice(index, 1) } else { - data[index].isSet = false; + data[parseInt(index)].isSet = false; } }, diff --git a/frontend/src/business/components/settings/organization/components/ScheduleTaskNotification.vue b/frontend/src/business/components/settings/organization/components/ScheduleTaskNotification.vue index 8cc7cb175c..2cf7f9b523 100644 --- a/frontend/src/business/components/settings/organization/components/ScheduleTaskNotification.vue +++ b/frontend/src/business/components/settings/organization/components/ScheduleTaskNotification.vue @@ -148,21 +148,21 @@ export default { data.isReadOnly = true; if (data.type === 'EMAIL') { data.isReadOnly = !data.isReadOnly; - data.webhook = '' + data.webhook = ''; } }, handleAddTaskModel(type) { let Task = {}; Task.event = []; Task.userIds = []; - Task.type = ""; - Task.webhook = ""; + Task.type = ''; + Task.webhook = ''; Task.isSet = true; - Task.identification = ""; + Task.identification = ''; if (type === 'scheduleTask') { - Task.taskType = 'SCHEDULE_TASK' - Task.testId=this.testId - this.form.scheduleTask.push(Task) + Task.taskType = 'SCHEDULE_TASK'; + Task.testId=this.testId; + this.form.scheduleTask.push(Task); } }, handleEditTask(index,data) { @@ -170,7 +170,7 @@ export default { data.testId = this.testId; if (data.type === 'EMAIL') { data.isReadOnly = false; - data.webhook = '' + data.webhook = ''; } else { data.isReadOnly = true; } @@ -196,7 +196,7 @@ export default { data.isSet = false; list.push(data); let param = {}; - param.messageDetail = list + param.messageDetail = list; this.result = this.$post("/notice/save/message/task", param, () => { this.initForm() this.$success(this.$t('commons.save_success')); @@ -206,7 +206,7 @@ export default { if (!data[index].identification) { data.splice(index, 1) } else { - data[index].isSet = false + data[index].isSet = false; } }, deleteRowTask(index, data) { //删除 diff --git a/frontend/src/business/components/settings/organization/components/TestReviewNotification.vue b/frontend/src/business/components/settings/organization/components/TestReviewNotification.vue index 3dce2c54a9..2cceee7cda 100644 --- a/frontend/src/business/components/settings/organization/components/TestReviewNotification.vue +++ b/frontend/src/business/components/settings/organization/components/TestReviewNotification.vue @@ -221,7 +221,7 @@ export default { if (!data[index].identification) { data.splice(index, 1) } else { - data[index].isSet = false + data[index].isSet = false; } }, deleteRowTask(index, data) { //删除