From 80241a394d1b78da6cbe65f6ac631ec8f69293c5 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 5 Jan 2026 00:23:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AE=8C=E5=96=84=E6=89=80=E6=9C=89?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E5=9C=BA=E6=99=AF=E7=9A=84=E9=92=89=E9=92=89?= =?UTF-8?q?=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - NotificationService: sendScoreNotification/sendSystemNotification/batchSendNotification 添加钉钉推送 - TaskService: 补充任务提交/审核通过/审核驳回/任务取消的通知 - 确保所有个人通知都能推送到钉钉工作通知 --- .../service/NotificationService.java | 21 ++++++- .../com/designhub/service/TaskService.java | 56 ++++++++++++++++++- 2 files changed, 73 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/com/designhub/service/NotificationService.java b/backend/src/main/java/com/designhub/service/NotificationService.java index e842e44..6acb623 100644 --- a/backend/src/main/java/com/designhub/service/NotificationService.java +++ b/backend/src/main/java/com/designhub/service/NotificationService.java @@ -78,6 +78,16 @@ public class NotificationService { @Transactional(rollbackFor = Exception.class) public void batchSendNotification(List 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 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); } diff --git a/backend/src/main/java/com/designhub/service/TaskService.java b/backend/src/main/java/com/designhub/service/TaskService.java index ebcade7..c68c6c4 100644 --- a/backend/src/main/java/com/designhub/service/TaskService.java +++ b/backend/src/main/java/com/designhub/service/TaskService.java @@ -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); + } + } } /**