Commit 2c6a3954 authored by 王蔡翾's avatar 王蔡翾
Browse files

短信消息接入其他模块

parent ff1bfb1e
...@@ -251,7 +251,8 @@ public class LeaveManagementServiceImpl implements LeaveManagementService { ...@@ -251,7 +251,8 @@ public class LeaveManagementServiceImpl implements LeaveManagementService {
} }
/** /**
* 审批结果始终反馈给申请学员;批准时额外同步全部管理员,拒绝时不扩大接收范围。 * 审批结果始终反馈给申请学员;批准时另发一条只含审批意见的管理员消息,
* 防止管理员收到面向学员的“您的请假申请”话术。拒绝时不通知管理员。
*/ */
void publishLeaveReview(LeaveApplicationVO leave, String reviewStatus, void publishLeaveReview(LeaveApplicationVO leave, String reviewStatus,
String approverId, String approverRole) { String approverId, String approverRole) {
...@@ -259,25 +260,39 @@ public class LeaveManagementServiceImpl implements LeaveManagementService { ...@@ -259,25 +260,39 @@ public class LeaveManagementServiceImpl implements LeaveManagementService {
String resultName = approved ? "已通过" : "未通过"; String resultName = approved ? "已通过" : "未通过";
String opinion = isBlank(leave.getApprovalOpinion()) String opinion = isBlank(leave.getApprovalOpinion())
? "审批人未填写意见" : leave.getApprovalOpinion(); ? "审批人未填写意见" : leave.getApprovalOpinion();
NotificationPublishDTO message = new NotificationPublishDTO();
message.setEventId("leave-review:" + leave.getId());
message.setMessageType("LEAVE");
message.setTitle("请假审批" + resultName);
message.setSummary("您的请假申请" + resultName);
message.setContent("您的请假申请" + resultName + "。审批意见:" + opinion);
message.setBusinessType("LEAVE");
message.setBusinessId(leave.getId());
message.setActionUrl("/leave/student/" + leave.getId());
message.setPriority(approved ? "NORMAL" : "IMPORTANT");
message.setRecipientUserIds(Collections.singletonList(leave.getStudentId()));
if (approved) {
message.setRecipientRoleNames(Collections.singletonList(AccountAdminConstants.ROLE_ADMIN));
}
String senderName = isBlank(leave.getApproverName()) String senderName = isBlank(leave.getApproverName())
? (LeaveConstants.ROLE_TEACHER.equals(approverRole) ? (LeaveConstants.ROLE_TEACHER.equals(approverRole)
? AccountAdminConstants.ROLE_TEACHER : AccountAdminConstants.ROLE_ADMIN) ? AccountAdminConstants.ROLE_TEACHER : AccountAdminConstants.ROLE_ADMIN)
: leave.getApproverName(); : leave.getApproverName();
notificationPublisher.publish(message, approverId, senderName);
NotificationPublishDTO studentMessage = new NotificationPublishDTO();
studentMessage.setEventId("leave-review:" + leave.getId() + ":student");
studentMessage.setMessageType("LEAVE");
studentMessage.setTitle("请假审批" + resultName);
studentMessage.setSummary("您的请假申请" + resultName);
studentMessage.setContent("您的请假申请" + resultName + "。审批意见:" + opinion);
studentMessage.setBusinessType("LEAVE");
studentMessage.setBusinessId(leave.getId());
studentMessage.setActionUrl("/leave/student/" + leave.getId());
studentMessage.setPriority(approved ? "NORMAL" : "IMPORTANT");
studentMessage.setRecipientUserIds(Collections.singletonList(leave.getStudentId()));
notificationPublisher.publish(studentMessage, approverId, senderName);
if (approved) {
NotificationPublishDTO adminMessage = new NotificationPublishDTO();
adminMessage.setEventId("leave-review:" + leave.getId() + ":admin");
adminMessage.setMessageType("LEAVE");
adminMessage.setTitle("请假审批意见");
adminMessage.setSummary(opinion);
adminMessage.setContent(opinion);
adminMessage.setBusinessType("LEAVE");
adminMessage.setBusinessId(leave.getId());
adminMessage.setActionUrl("/leave/admin/" + leave.getId());
adminMessage.setPriority("NORMAL");
adminMessage.setRecipientRoleNames(
Collections.singletonList(AccountAdminConstants.ROLE_ADMIN));
notificationPublisher.publish(adminMessage, approverId, senderName);
}
} }
@Override @Override
......
...@@ -50,7 +50,7 @@ class LeaveManagementNotificationTest { ...@@ -50,7 +50,7 @@ class LeaveManagementNotificationTest {
} }
@Test @Test
void reviewShouldNotifyStudentAndAddAdminsOnlyWhenApproved() { void reviewShouldSendSeparateAdminOpinionOnlyWhenApproved() {
LeaveApplicationVO leave = leave(); LeaveApplicationVO leave = leave();
leave.setApproverName("王老师"); leave.setApproverName("王老师");
leave.setApprovalOpinion("审批意见"); leave.setApprovalOpinion("审批意见");
...@@ -62,15 +62,22 @@ class LeaveManagementNotificationTest { ...@@ -62,15 +62,22 @@ class LeaveManagementNotificationTest {
ArgumentCaptor<NotificationPublishDTO> messageCaptor = ArgumentCaptor<NotificationPublishDTO> messageCaptor =
ArgumentCaptor.forClass(NotificationPublishDTO.class); ArgumentCaptor.forClass(NotificationPublishDTO.class);
verify(notificationPublisher, times(2)).publish( verify(notificationPublisher, times(3)).publish(
messageCaptor.capture(), eq("teacher-1"), eq("王老师")); messageCaptor.capture(), eq("teacher-1"), eq("王老师"));
NotificationPublishDTO approvedStudent = messageCaptor.getAllValues().get(0);
NotificationPublishDTO approvedAdmin = messageCaptor.getAllValues().get(1);
NotificationPublishDTO rejectedStudent = messageCaptor.getAllValues().get(2);
assertEquals(Collections.singletonList("student-1"), assertEquals(Collections.singletonList("student-1"),
messageCaptor.getAllValues().get(0).getRecipientUserIds()); approvedStudent.getRecipientUserIds());
assertNull(approvedStudent.getRecipientRoleNames());
assertEquals(Collections.singletonList("管理员"), assertEquals(Collections.singletonList("管理员"),
messageCaptor.getAllValues().get(0).getRecipientRoleNames()); approvedAdmin.getRecipientRoleNames());
assertEquals(Collections.singletonList("student-1"), assertNull(approvedAdmin.getRecipientUserIds());
messageCaptor.getAllValues().get(1).getRecipientUserIds()); assertEquals("审批意见", approvedAdmin.getSummary());
assertNull(messageCaptor.getAllValues().get(1).getRecipientRoleNames()); assertEquals("审批意见", approvedAdmin.getContent());
assertEquals(Collections.singletonList("student-1"), rejectedStudent.getRecipientUserIds());
assertNull(rejectedStudent.getRecipientRoleNames());
} }
private LeaveApplicationVO leave() { private LeaveApplicationVO leave() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment