fix: 消息设置修改

This commit is contained in:
wenyann 2020-11-24 10:33:28 +08:00
parent 4ba24afeee
commit 1f107b69ff
15 changed files with 80 additions and 36 deletions

View File

@ -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<APITestResult> list(QueryAPITestRequest request) {

View File

@ -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<String> phoneLists = phoneList.stream().distinct().collect(Collectors.toList());
at.setAtMobiles(phoneLists);
request.setAt(at);
OapiRobotSendResponse response = null;
try {

View File

@ -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<String> 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<String> userIds, SaveCommentRequest request, TestCaseWithBLOBs testCaseWithBLOBs, String eventType) {
User user = userMapper.selectByPrimaryKey(testCaseWithBLOBs.getMaintainer());
BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo();
Map<String, String> 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<String> 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<String> 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<String> 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 + "}", "未设置");
}
}
}

View File

@ -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<MessageDetail> searchMessageSchedule(String testId) {
List<MessageTask> messageTaskLists = extMessageMapper.searchMessageByTestId(testId);
List<MessageDetail> scheduleMessageTask = new ArrayList<>();
@ -116,10 +127,14 @@ public class NoticeService {
messageDetail.setUserIds(new ArrayList<String>(userIds));
MessageDetailList.add(messageDetail);
});
List<MessageDetail> 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<MessageDetail> 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<MessageDetail> 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<MessageDetail> 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<MessageDetail> 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<MessageDetail> 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<MessageDetail> 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<MessageDetail> 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);

View File

@ -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<String> phoneLists = phoneList.stream().distinct().collect(Collectors.toList());
mentionedMobileList.addAll(phoneLists);
message.setMentionedMobileList(mentionedMobileList);
try {
SendResult result = WxChatbotClient.send(Webhook, message);

View File

@ -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;
}

View File

@ -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)) {

View File

@ -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)) {

View File

@ -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

View File

@ -170,4 +170,5 @@ upload_content_is_null=导入内容为空
test_plan_notification=测试计划通知
task_defect_notification=缺陷任务通知
task_notification_jenkins=jenkins任务通知
task_notification=任务通知
task_notification=任务通知
message_task_already_exists=任务接收人已经存在

View File

@ -172,4 +172,5 @@ test_plan_notification=測試計畫通知
task_defect_notification=缺陷任務通知
task_notification_jenkins=jenkins任務通知
task_notification=任務通知
message_task_already_exists=任務接收人已經存在

View File

@ -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;
}

View File

@ -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;
}
},

View File

@ -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) { //

View File

@ -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) { //