From 7b92476bc57152a507422a1dbc1f5e64d3e2983d Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 8 Jan 2026 15:56:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BB=9F=E4=B8=80=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E6=A8=A1=E7=89=88=E6=A0=BC=E5=BC=8F=EF=BC=8C?= =?UTF-8?q?=E6=8C=87=E6=B4=BE=E4=BB=BB=E5=8A=A1=E9=80=9A=E7=9F=A5=E4=B8=8E?= =?UTF-8?q?=E6=96=B0=E4=BB=BB=E5=8A=A1=E5=8F=91=E5=B8=83=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E4=BF=9D=E6=8C=81=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/TaskApprovalService.java | 144 ++++++++++++------ 1 file changed, 97 insertions(+), 47 deletions(-) diff --git a/backend/src/main/java/com/designhub/service/TaskApprovalService.java b/backend/src/main/java/com/designhub/service/TaskApprovalService.java index 508a2b6..aa4e712 100644 --- a/backend/src/main/java/com/designhub/service/TaskApprovalService.java +++ b/backend/src/main/java/com/designhub/service/TaskApprovalService.java @@ -269,41 +269,115 @@ public class TaskApprovalService { String receiverName = receiver != null ? receiver.getRealName() : "未知"; String receiverPhone = receiver != null ? receiver.getPhone() : null; - // 1. 发送个人钉钉通知给设计师 - StringBuilder personalContent = new StringBuilder(); - personalContent.append("### 任务已自动分配给您,无需抢单 \n\n"); - personalContent.append("**任务名称**:").append(task.getTitle()).append(" \n"); - personalContent.append("**任务编号**:").append(task.getTaskNo()).append(" \n"); - personalContent.append("**任务积分**:").append(task.getScore()).append(" 分 \n"); + // 1. 构建统一格式的通知内容(与"新任务发布"模版保持一致) + StringBuilder content = new StringBuilder(); - if (task.getEstimatedHours() != null) { - int hours = task.getEstimatedHours().intValue(); - int days = hours / 8; - int remainingHours = hours % 8; - String timeStr = days > 0 ? (days + "天" + (remainingHours > 0 ? remainingHours + "小时" : "")) : (hours + "小时"); - personalContent.append("**时效要求**:").append(timeStr).append(" \n"); - } + // 基本信息 + content.append("**任务名称**:").append(task.getTitle()).append(" \n"); + content.append("**任务编号**:").append(task.getTaskNo()).append(" \n"); + // 任务详情 if (task.getBrandName() != null && !task.getBrandName().isEmpty()) { - personalContent.append("**品牌**:").append(task.getBrandName()).append(" \n"); + content.append("**品牌**:").append(task.getBrandName()).append(" \n"); } if (task.getPlatformName() != null && !task.getPlatformName().isEmpty()) { - personalContent.append("**平台**:").append(task.getPlatformName()).append(" \n"); + content.append("**平台**:").append(task.getPlatformName()).append(" \n"); } if (task.getSpuInfo() != null && !task.getSpuInfo().isEmpty()) { - personalContent.append("**SPU**:").append(task.getSpuInfo()).append(" \n"); + content.append("**SPU**:").append(task.getSpuInfo()).append(" \n"); + } + if (task.getTaskSubType() != null && !task.getTaskSubType().isEmpty()) { + content.append("**任务类型**:").append(task.getTaskSubType()).append(" \n"); } + content.append(" \n"); + + // 查询子任务获取任务类型明细 + List taskItems = taskItemMapper.selectList( + new LambdaQueryWrapper() + .eq(TaskItem::getTaskId, task.getId()) + .orderByAsc(TaskItem::getGroupNo) + ); + + if (!taskItems.isEmpty()) { + content.append("**任务明细**: \n"); + for (TaskItem item : taskItems) { + // 通过任务类型ID获取接单部门名称 + String deptName = "未指定"; + if (item.getTaskTypeId() != null) { + try { + DemandType demandType = configService.getDemandTypeById(item.getTaskTypeId()); + if (demandType != null && demandType.getAllowedDeptIds() != null && !demandType.getAllowedDeptIds().isEmpty()) { + String[] deptIds = demandType.getAllowedDeptIds().split(","); + Long firstDeptId = Long.parseLong(deptIds[0].trim()); + Department dept = departmentMapper.selectById(firstDeptId); + if (dept != null) { + deptName = dept.getDeptName(); + } + } + } catch (Exception e) { + log.warn("获取部门名称失败: {}", e.getMessage()); + } + } + + // 格式化工时显示 + String hoursDisplay = formatEstimatedHours(item.getEstimatedHours()); + + content.append(" \n"); + content.append("▸ **").append(deptName).append("** | ") + .append(item.getTotalScore()).append("分 | ") + .append(hoursDisplay).append(" \n"); + + // 解析并显示任务类型明细 + if (item.getTypeDetails() != null && !item.getTypeDetails().isEmpty()) { + try { + @SuppressWarnings("unchecked") + List> typeDetails = + objectMapper.readValue(item.getTypeDetails(), List.class); + for (java.util.Map detail : typeDetails) { + String typeName = String.valueOf(detail.get("typeName")); + Object qtyObj = detail.get("quantity"); + Object scoreObj = detail.get("totalScore"); + int qty = qtyObj instanceof Number ? ((Number) qtyObj).intValue() : 1; + String score = scoreObj != null ? String.valueOf(scoreObj) : "0"; + content.append("  └ ").append(typeName) + .append(" ×").append(qty) + .append(" = ").append(score).append("分 \n"); + } + } catch (Exception e) { + log.warn("解析任务类型明细失败: {}", e.getMessage()); + } + } + } + } else { + // 没有子任务时显示总积分和工时 + content.append("**任务积分**:").append(task.getScore()).append(" 分 \n"); + if (task.getEstimatedHours() != null) { + content.append("**预估工时**:").append(formatEstimatedHours(task.getEstimatedHours())).append(" \n"); + } + } + + content.append(" \n"); + + // 发起人信息 if (task.getPublisherName() != null && !task.getPublisherName().isEmpty()) { - personalContent.append(" \n**发起人**:").append(task.getPublisherName()).append(" \n"); + content.append("**发起人**:").append(task.getPublisherName()).append(" \n"); + } + if (task.getPublisherDeptName() != null && !task.getPublisherDeptName().isEmpty()) { + content.append("**发起部门**:").append(task.getPublisherDeptName()).append(" \n"); } - personalContent.append(" \n> 💡 任务已开始计时,请前往【我的任务】查看详情"); + // 指派信息 + content.append("**指派给**:").append(receiverName).append(" \n"); + content.append(" \n"); + content.append("点击下方按钮查看详情"); + + // 2. 发送个人钉钉通知给设计师 Notification notification = new Notification(); notification.setReceiverId(finalReceiverId); - notification.setTitle("任务已指派给您(已自动开始)"); - notification.setContent(personalContent.toString()); + notification.setTitle("任务已指派"); + notification.setContent(content.toString()); notification.setNotificationType("TASK_ASSIGNED"); notification.setRelatedType("task"); notification.setRelatedId(task.getId()); @@ -311,36 +385,12 @@ public class TaskApprovalService { notificationService.sendNotification(notification); log.info("任务指派个人通知已发送给设计师: userId={}", finalReceiverId); - // 2. 只有非预先指定的任务才发送群通知(预先指定的任务只发送个人通知) + // 3. 只有非预先指定的任务才发送群通知(预先指定的任务只发送个人通知) if (!isPreAssigned) { - // 发送群通知并@指定的设计师 - String title = "任务已指派"; - StringBuilder content = new StringBuilder(); - content.append("-------------------------------- \n"); - content.append(" 【 任 务 已 指 派 】 \n"); - content.append("-------------------------------- \n\n"); - - content.append("任务名称:").append(task.getTitle()).append(" \n"); - content.append("任务编号:").append(task.getTaskNo()).append(" \n"); - content.append("任务积分:").append(task.getScore()).append(" 分 \n"); - content.append("指派给:").append(receiverName).append(" \n"); - - if (task.getEstimatedHours() != null) { - content.append("预估工时:").append(task.getEstimatedHours().intValue()).append(" 小时 \n"); - } - - if (task.getPublisherName() != null && !task.getPublisherName().isEmpty()) { - content.append("发起人:").append(task.getPublisherName()).append(" \n"); - } - - content.append(" \n"); - content.append("-------------------------------- \n"); - content.append("请尽快处理! \n"); - content.append("--------------------------------"); - + // 发送群通知并@指定的设计师,使用相同的内容模版 java.util.List atMobiles = receiverPhone != null ? java.util.Arrays.asList(receiverPhone) : null; - dingTalkService.sendRobotMessage(title, content.toString(), atMobiles); + dingTalkService.sendRobotMessage("任务已指派", content.toString(), atMobiles); log.info("任务指派群通知已发送,@手机号: {}", receiverPhone); } else { log.info("任务【{}】为预先指定任务,只发送个人通知,不发送群通知", task.getTitle());