fix: 完善所有通知场景的钉钉推送
- NotificationService: sendScoreNotification/sendSystemNotification/batchSendNotification 添加钉钉推送 - TaskService: 补充任务提交/审核通过/审核驳回/任务取消的通知 - 确保所有个人通知都能推送到钉钉工作通知
This commit is contained in:
parent
1d33d453d3
commit
80241a394d
@ -78,6 +78,16 @@ public class NotificationService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void batchSendNotification(List<Long> receiverIds, String title, String content,
|
||||
String notificationType, String relatedType, Long relatedId) {
|
||||
batchSendNotification(receiverIds, title, content, notificationType, relatedType, relatedId, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量发送通知(可选钉钉推送)
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void batchSendNotification(List<Long> receiverIds, String title, String content,
|
||||
String notificationType, String relatedType, Long relatedId,
|
||||
boolean pushDingtalk) {
|
||||
for (Long receiverId : receiverIds) {
|
||||
Notification notification = new Notification();
|
||||
notification.setReceiverId(receiverId);
|
||||
@ -88,9 +98,16 @@ public class NotificationService {
|
||||
notification.setRelatedId(relatedId);
|
||||
notification.setIsRead(0);
|
||||
notification.setPriority(1); // 普通
|
||||
notification.setPushDingtalk(pushDingtalk ? 1 : 0);
|
||||
|
||||
notificationMapper.insert(notification);
|
||||
|
||||
// 如果开启了钉钉推送,异步推送
|
||||
if (pushDingtalk) {
|
||||
asyncPushToDingtalk(notification);
|
||||
}
|
||||
}
|
||||
log.info("批量发送通知成功: count={}", receiverIds.size());
|
||||
log.info("批量发送通知成功: count={}, pushDingtalk={}", receiverIds.size(), pushDingtalk);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -285,6 +302,7 @@ public class NotificationService {
|
||||
notification.setTitle(title);
|
||||
notification.setContent(content);
|
||||
notification.setLinkUrl("/my-score");
|
||||
notification.setPushDingtalk(1); // 积分通知推送钉钉
|
||||
sendNotification(notification);
|
||||
}
|
||||
|
||||
@ -316,6 +334,7 @@ public class NotificationService {
|
||||
notification.setTitle(title);
|
||||
notification.setContent(content);
|
||||
notification.setPriority(priority != null ? convertPriorityToInt(priority) : 1); // 默认普通
|
||||
notification.setPushDingtalk(1); // 系统通知推送钉钉
|
||||
sendNotification(notification);
|
||||
}
|
||||
|
||||
|
||||
@ -864,7 +864,22 @@ public class TaskService {
|
||||
|
||||
taskMapper.updateById(task);
|
||||
|
||||
// TODO: 发送通知给发布人
|
||||
// 发送通知给发布人
|
||||
if (task.getPublisherId() != null) {
|
||||
try {
|
||||
User receiver = userService.getUserById(userId);
|
||||
String receiverName = receiver != null ?
|
||||
(receiver.getRealName() != null ? receiver.getRealName() : receiver.getUsername()) : "设计师";
|
||||
notificationService.sendTaskNotification(
|
||||
task.getPublisherId(),
|
||||
taskId,
|
||||
"任务已提交待审核",
|
||||
String.format("您发布的任务【%s】已由 %s 提交,请及时审核", task.getTitle(), receiverName)
|
||||
);
|
||||
} catch (Exception e) {
|
||||
log.error("发送任务提交通知失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -953,7 +968,30 @@ public class TaskService {
|
||||
|
||||
taskMapper.updateById(task);
|
||||
|
||||
// TODO: 发送通知
|
||||
// 发送通知给设计师
|
||||
if (task.getReceiverId() != null) {
|
||||
try {
|
||||
if (approved) {
|
||||
// 审核通过通知
|
||||
notificationService.sendTaskNotification(
|
||||
task.getReceiverId(),
|
||||
taskId,
|
||||
"任务审核通过",
|
||||
String.format("恭喜!您完成的任务【%s】已审核通过,积分已发放", task.getTitle())
|
||||
);
|
||||
} else {
|
||||
// 驳回通知
|
||||
notificationService.sendTaskNotification(
|
||||
task.getReceiverId(),
|
||||
taskId,
|
||||
"任务被驳回",
|
||||
String.format("您提交的任务【%s】被驳回,原因:%s,请修改后重新提交", task.getTitle(), comment)
|
||||
);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("发送任务审核通知失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -986,7 +1024,19 @@ public class TaskService {
|
||||
teamScorePoolService.addScore(task.getPublisherDeptId(), task.getScore());
|
||||
}
|
||||
|
||||
// TODO: 发送通知
|
||||
// 发送通知给接单设计师
|
||||
if (task.getReceiverId() != null) {
|
||||
try {
|
||||
notificationService.sendTaskNotification(
|
||||
task.getReceiverId(),
|
||||
taskId,
|
||||
"任务已取消",
|
||||
String.format("任务【%s】已被发起人取消,原因:%s", task.getTitle(), reason != null ? reason : "无")
|
||||
);
|
||||
} catch (Exception e) {
|
||||
log.error("发送任务取消通知失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user