refactor: 发送站内通知

This commit is contained in:
Captain.B 2021-08-19 16:01:44 +08:00 committed by 刘瑞斌
parent db10190ce6
commit 052112627c
5 changed files with 236 additions and 29 deletions

View File

@ -9,7 +9,6 @@ import io.metersphere.notice.sender.AbstractNoticeSender;
import io.metersphere.notice.sender.NoticeModel;
import io.metersphere.notice.service.NotificationService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@ -21,7 +20,7 @@ public class InSiteNoticeSender extends AbstractNoticeSender {
@Resource
private NotificationService notificationService;
public void sendAnnouncement(NoticeModel noticeModel, String context) {
public void sendAnnouncement(MessageDetail messageDetail, NoticeModel noticeModel, String context) {
List<Receiver> receivers = noticeModel.getReceivers();
if (CollectionUtils.isEmpty(receivers)) {
return;
@ -35,10 +34,7 @@ public class InSiteNoticeSender extends AbstractNoticeSender {
notification.setOperator(noticeModel.getOperator());
notification.setOperation(noticeModel.getEvent());
notification.setResourceId((String) noticeModel.getParamMap().get("id"));
//
String subject = noticeModel.getSubject();
String resource = StringUtils.removeEnd(subject, "通知");
notification.setResourceType(resource);
notification.setResourceType(messageDetail.getTaskType());
//
if (noticeModel.getParamMap().get("name") != null) {
notification.setResourceName((String) noticeModel.getParamMap().get("name"));
@ -59,6 +55,6 @@ public class InSiteNoticeSender extends AbstractNoticeSender {
@Override
public void send(MessageDetail messageDetail, NoticeModel noticeModel) {
String context = super.getContext(messageDetail, noticeModel);
sendAnnouncement(noticeModel, context);
sendAnnouncement(messageDetail, noticeModel, context);
}
}

View File

@ -26,10 +26,10 @@
<div style="margin: 0px 20px 0px">
<el-tabs :active-name="activeName">
<el-tab-pane label="@提到我的" name="mentionedMe">
<mentioned-me-data ref="mentionedMe"/>
<mentioned-me-data ref="mentionedMe" :user-list="userList"/>
</el-tab-pane>
<el-tab-pane label="系统通知" name="systemNotice">
<system-notice-data ref="systemNotice"/>
<system-notice-data ref="systemNotice" :user-list="userList"/>
</el-tab-pane>
</el-tabs>
</div>
@ -40,7 +40,7 @@
<script>
import MsDrawer from "../common/components/MsDrawer";
import {getCurrentProjectID, getCurrentUserId} from "@/common/js/utils";
import {getCurrentUserId} from "@/common/js/utils";
import MsRequestResultTail from "../../components/api/definition/components/response/RequestResultTail";
import MsTipButton from "@/business/components/common/components/MsTipButton";
import SystemNoticeData from "@/business/components/notice/components/SystemNoticeData";
@ -68,7 +68,7 @@ export default {
initEnd: false,
visible: false,
showType: "",
maintainerOptions: [],
userList: [],
websocket: Object,
activeName: 'mentionedMe',
pageSize: 20,
@ -82,7 +82,7 @@ export default {
},
created() {
this.getNotifications();
this.getMaintainerOptions();
this.getUserList();
},
watch: {
taskVisible(v) {
@ -92,9 +92,9 @@ export default {
}
},
methods: {
getMaintainerOptions() {
this.$post('/user/project/member/tester/list', {projectId: getCurrentProjectID()}, response => {
this.maintainerOptions = response.data;
getUserList() {
this.$get('/user/list', response => {
this.userList = response.data;
});
},
initWebSocket() {

View File

@ -18,17 +18,20 @@
<el-card class="ms-card-task">
<el-row type="flex" justify="space-between">
<el-col :span="12">
{{ item.title }}
</el-col>
<el-col :span="6">
{{ item.createTime | timestampFormatDate }}
</el-col>
</el-row>
<span>
{{ item.content }}
</span>
<br/>
<el-row>
<el-row type="flex" align="start" class="current-user">
<div class="icon-title">
{{ item.user.name.substring(0, 1) }}
</div>
<span class="username">{{ item.user.name }}</span>
<span class="operation">
{{ getOperation(item.operation) }}{{ getResource(item.resourceType) }}: {{ item.resourceName }}
</span>
</el-row>
</el-card>
</div>
@ -40,6 +43,8 @@
</template>
<script>
import {getOperation, getResource} from "@/business/components/notice/util";
export default {
name: "MentionedMeData",
data() {
@ -49,12 +54,22 @@ export default {
goPage: 1,
totalPage: 0,
totalCount: 0,
userMap: {}
};
},
props: {
userList: Array
},
created() {
this.init();
this.userMap = this.userList.reduce((r, c) => {
r[c.id] = c;
return r;
}, {});
},
methods: {
getOperation,
getResource,
handleCommand(i) {
this.goPage = i;
this.init();
@ -65,7 +80,10 @@ export default {
this.systemNoticeData = response.data.listObject;
this.totalPage = response.data.pageCount;
this.totalCount = response.data.itemCount;
this.initEnd = true;
this.systemNoticeData.forEach(n => {
n.user = this.userMap[n.operator];
});
});
},
prevPage() {
@ -94,4 +112,52 @@ export default {
min-height: 600px;
overflow-y: auto;
}
.ms-card-task {
padding-bottom: 10px;
}
.current-user .username {
display: inline-block;
font-size: 14px;
font-weight: 500;
margin: 5px;
overflow-x: hidden;
padding-bottom: 0;
text-overflow: ellipsis;
vertical-align: middle;
white-space: nowrap;
max-width: 180px;
}
.current-user .operation {
display: inline-block;
font-size: 14px;
margin: 5px;
overflow-x: hidden;
padding-bottom: 0;
text-overflow: ellipsis;
vertical-align: middle;
white-space: nowrap;
}
.current-user .edit {
opacity: 0;
}
.current-user:hover .edit {
opacity: 1;
}
.icon-title {
color: #fff;
width: 30px;
background-color: #783887;
height: 30px;
line-height: 30px;
text-align: center;
border-radius: 30px;
font-size: 14px;
}
</style>

View File

@ -18,17 +18,20 @@
<el-card class="ms-card-task">
<el-row type="flex" justify="space-between">
<el-col :span="12">
{{ item.title }}
</el-col>
<el-col :span="6">
{{ item.createTime | timestampFormatDate }}
</el-col>
</el-row>
<span>
{{ item.content }}
</span>
<br/>
<el-row>
<el-row type="flex" align="start" class="current-user">
<div class="icon-title">
{{ item.user.name.substring(0, 1) }}
</div>
<span class="username">{{ item.user.name }}</span>
<span class="operation">
{{ getOperation(item.operation) }}{{ getResource(item.resourceType) }}: {{ item.resourceName }}
</span>
</el-row>
</el-card>
</div>
@ -40,6 +43,8 @@
</template>
<script>
import {getOperation, getResource} from "@/business/components/notice/util";
export default {
name: "SystemNoticeData",
data() {
@ -51,10 +56,20 @@ export default {
totalCount: 0,
};
},
props: {
userList: Array,
color: String
},
created() {
this.init();
this.userMap = this.userList.reduce((r, c) => {
r[c.id] = c;
return r;
}, {});
},
methods: {
getOperation,
getResource,
handleCommand(i) {
this.goPage = i;
this.init();
@ -65,7 +80,9 @@ export default {
this.systemNoticeData = response.data.listObject;
this.totalPage = response.data.pageCount;
this.totalCount = response.data.itemCount;
this.initEnd = true;
this.systemNoticeData.forEach(n => {
n.user = this.userMap[n.operator];
});
});
},
prevPage() {
@ -94,4 +111,51 @@ export default {
min-height: 600px;
overflow-y: auto;
}
.ms-card-task {
padding-bottom: 10px;
}
.current-user .username {
display: inline-block;
font-size: 14px;
font-weight: 500;
margin: 5px;
overflow-x: hidden;
padding-bottom: 0;
text-overflow: ellipsis;
vertical-align: middle;
white-space: nowrap;
max-width: 180px;
}
.current-user .operation {
display: inline-block;
font-size: 14px;
margin: 5px;
overflow-x: hidden;
padding-bottom: 0;
text-overflow: ellipsis;
vertical-align: middle;
white-space: nowrap;
}
.current-user .edit {
opacity: 0;
}
.current-user:hover .edit {
opacity: 1;
}
.icon-title {
color: #fff;
width: 30px;
background-color: #783887;
height: 30px;
line-height: 30px;
text-align: center;
border-radius: 30px;
font-size: 14px;
}
</style>

View File

@ -0,0 +1,81 @@
export function getOperation(operation) {
switch (operation) {
case "CREATE":
operation = "创建了";
break;
case "UPDATE":
operation = "更新了";
break;
case "DELETE":
operation = "删除了";
break;
case "COMMENT":
operation = "评论了";
break;
case "CLOSE_SCHEDULE":
operation = "关闭了定时任务";
break;
case "CASE_CREATE":
operation = "创建了接口用例";
break;
case "CASE_UPDATE":
operation = "更新了接口用例";
break;
case "CASE_DELETE":
operation = "删除了接口用例";
break;
default:
break;
}
return operation;
}
export function getResource(resourceType) {
switch (resourceType) {
case "JENKINS_TASK" :
resourceType = "Jenkins";
break;
case "TEST_PLAN_TASK" :
resourceType = "测试计划";
break;
case "REVIEW_TASK" :
resourceType = "测试评审";
break;
case "DEFECT_TASK" :
resourceType = "缺陷";
break;
case "SWAGGER_TASK" :
resourceType = "Swagger";
break;
case "API_AUTOMATION_TASK" :
resourceType = "接口自动化";
break;
case "API_DEFINITION_TASK" :
resourceType = "接口定义";
break;
case "API_HOME_TASK" :
resourceType = "接口测试首页";
break;
case "API_REPORT_TASK" :
resourceType = "接口测试报告";
break;
case "PERFORMANCE_REPORT_TASK" :
resourceType = "性能测试报告";
break;
case "PERFORMANCE_TEST_TASK" :
resourceType = "性能测试";
break;
case "TRACK_TEST_CASE_TASK" :
resourceType = "测试用例";
break;
case "TRACK_HOME_TASK" :
resourceType = "测试跟踪首页";
break;
case "TRACK_REPORT_TASK" :
resourceType = "测试跟踪报告";
break;
default:
break;
}
return resourceType;
}