refactor: 测试计划发送成功通知

This commit is contained in:
Captain.B 2021-08-23 10:59:41 +08:00 committed by 刘瑞斌
parent 5cc1b69764
commit 34073ac9db
3 changed files with 37 additions and 24 deletions

View File

@ -6,6 +6,7 @@ import io.metersphere.notice.domain.UserDetail;
import io.metersphere.notice.sender.AbstractNoticeSender;
import io.metersphere.notice.sender.NoticeModel;
import io.metersphere.notice.util.LarkClient;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
@ -26,6 +27,11 @@ public class LarkNoticeSender extends AbstractNoticeSender {
.map(ud -> "<at email=\"" + ud.getEmail() + "\">" + ud.getName() + "</at>")
.collect(Collectors.toList());
// 没有接收人不发通知
if (CollectionUtils.isEmpty(collect)) {
return;
}
context += StringUtils.join(collect, " ");
LarkClient.send(messageDetail.getWebhook(), context);
}

View File

@ -273,8 +273,7 @@ public class TestPlanService {
status = "已完成";
}
context.put("status", status);
User user = userMapper.selectByPrimaryKey(testPlan.getCreator());
context.put("creator", user.getName());
context.put("creator", testPlan.getCreator());
return context;
}
@ -409,7 +408,7 @@ public class TestPlanService {
testPlanWithBLOBs.setStatus(TestPlanStatus.Completed.name());
this.editTestPlan(testPlanWithBLOBs);
// 发送成功通知
sendCompletedNotice(testPlanWithBLOBs);
// sendCompletedNotice(testPlanWithBLOBs);
} else if (prepareNum == 0 && passNum + failNum == statusList.size()) { // 已结束
testPlanWithBLOBs.setStatus(TestPlanStatus.Finished.name());
editTestPlan(testPlanWithBLOBs);

View File

@ -45,6 +45,7 @@ import MsRequestResultTail from "../../components/api/definition/components/resp
import MsTipButton from "@/business/components/common/components/MsTipButton";
import SystemNoticeData from "@/business/components/notice/components/SystemNoticeData";
import MentionedMeData from "@/business/components/notice/components/MentionedMeData";
import {getOperation, getResource} from "@/business/components/notice/util";
export default {
name: "MsNotification",
@ -69,6 +70,7 @@ export default {
visible: false,
showType: "",
userList: [],
userMap: {},
websocket: Object,
activeName: 'mentionedMe',
pageSize: 20,
@ -95,6 +97,10 @@ export default {
getUserList() {
this.$get('/user/list', response => {
this.userList = response.data;
this.userMap = this.userList.reduce((r, c) => {
r[c.id] = c;
return r;
}, {});
});
},
initWebSocket() {
@ -155,12 +161,14 @@ export default {
if (now - d.createTime > 10 * 1000) {
return;
}
d.user = this.userMap[d.operator];
let message = d.user.name + getOperation(d.operation) + getResource(d.resourceType) + ": " + d.resourceName;
let title = d.type === 'MENTIONED_ME' ? '@提到我的' : '系统通知';
setTimeout(() => {
this.$notify({
title: title,
type: 'info',
message: d.content,
message: message,
});
});
});