From 6cf90db6ba6ff8205107306f54ac2c4a268b9fa5 Mon Sep 17 00:00:00 2001 From: "han\\hanst" Date: Mon, 30 Mar 2026 15:36:30 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=95=E9=AA=8C=E5=8D=95=E4=B8=8B=E8=BE=BE?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E7=AB=8B=E5=8D=B3=E5=8F=91=E9=80=81=E9=82=AE?= =?UTF-8?q?=E4=BB=B6=E7=BB=99=E6=8A=80=E6=9C=AF=E7=BB=8F=E7=90=86=EF=BC=8C?= =?UTF-8?q?=E6=8F=90=E9=86=92=E5=AE=A1=E6=89=B9=E4=BB=BB=E5=8A=A1=EF=BC=9B?= =?UTF-8?q?=E6=8A=80=E6=9C=AF=E7=BB=8F=E7=90=86=E5=AE=A1=E6=89=B9=E9=80=9A?= =?UTF-8?q?=E8=BF=87=E5=90=8E=E9=9C=80=E8=A6=81=E7=AB=8B=E5=8D=B3=E5=8F=91?= =?UTF-8?q?=E9=80=81=E9=82=AE=E4=BB=B6=E7=BB=99=E5=85=B6=E4=BB=962?= =?UTF-8?q?=E4=B8=AA=E7=BB=8F=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ErfExpApplyServiceImpl.java | 168 ++++++++++++++++++ 1 file changed, 168 insertions(+) diff --git a/src/main/java/com/xujie/sys/modules/erf/service/impl/ErfExpApplyServiceImpl.java b/src/main/java/com/xujie/sys/modules/erf/service/impl/ErfExpApplyServiceImpl.java index c9db79f0..1c277673 100644 --- a/src/main/java/com/xujie/sys/modules/erf/service/impl/ErfExpApplyServiceImpl.java +++ b/src/main/java/com/xujie/sys/modules/erf/service/impl/ErfExpApplyServiceImpl.java @@ -57,6 +57,8 @@ import static com.xujie.sys.modules.sys.controller.AbstractController.getUser; @Transactional(rollbackFor = Exception.class) public class ErfExpApplyServiceImpl extends ServiceImpl implements ErfExpApplyService { + private static final String APPROVAL_PAGE_URL = "http://172.26.68.20:9001/#/erf-expApplyApproval"; + @Autowired private ErfExpApplyMapper erfExpApplyMapper; @@ -231,6 +233,9 @@ public class ErfExpApplyServiceImpl extends ServiceImpl尊敬的 " + techManager.getUsername() + ":" + + "

您好!以下工程实验试验单已下达,当前审批节点为技术经理审批,请及时处理。

" + + "
" + tableBody + + "

前往审批待办页面

" + + "

发送时间:" + + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) + + "

"; + + MailUtil.sendMail(subject, body, new String[]{techManager.getEmail()}, mailSendData); + log.info("已向技术经理 {} ({}) 发送待审批通知,试验单: {}", + techManager.getUsername(), techManager.getEmail(), entity.getApplyNo()); + + SendMailRecord mailRecord = new SendMailRecord(); + mailRecord.setType("工程实验申请技术经理待审批通知"); + mailRecord.setDocumentNo(entity.getApplyNo()); + mailRecord.setRecipient(techManager.getEmail()); + mailRecord.setSendDate(new Date()); + qcMapper.saveSendMailRecord(mailRecord); + } catch (Exception e) { + log.error("发送技术经理待审批通知失败,试验单: {}, 错误: {}", entity.getApplyNo(), e.getMessage(), e); + } + } + + /** + * 技术经理审批通过后立即通知生产经理、质量经理审批 + */ + private void sendProdQualityManagerApprovalTaskNotification(ErfExpApply entity) { + try { + MailSendAddressData mailSendData = qcMapper.getSendMailFromAddress(); + if (mailSendData == null) { + log.error("邮件发送配置未设置,无法发送生产/质量经理待审批通知"); + return; + } + + // 从当前待审核节点读取实际需要审批的生产/质量经理(支持多人、多角色) + List managerNodes = erfFlowNodeInstanceMapper.selectList( + new QueryWrapper() + .eq("apply_no", entity.getApplyNo()) + .eq("status", "待审核") + .in("node_code", "生产经理审批", "质量经理审批") + ); + if (managerNodes == null || managerNodes.isEmpty()) { + log.warn("未找到待审核的生产/质量经理节点,跳过通知: {}", entity.getApplyNo()); + return; + } + + Map> roleMapByUser = new LinkedHashMap<>(); + for (ErfFlowNodeInstance node : managerNodes) { + if (node.getAssigneeUserId() == null) { + continue; + } + roleMapByUser + .computeIfAbsent(node.getAssigneeUserId(), key -> new LinkedHashSet<>()) + .add(node.getNodeCode()); + } + if (roleMapByUser.isEmpty()) { + log.warn("待审核节点中无有效审批人,跳过通知: {}", entity.getApplyNo()); + return; + } + + String todayStr = DateTimeFormatter.ofPattern("yyyy-MM-dd").format(LocalDateTime.now()); + String expectedFinishDateStr = entity.getExpectedFinishDate() != null + ? DateTimeFormatter.ofPattern("yyyy-MM-dd") + .format(entity.getExpectedFinishDate().toInstant().atZone(java.time.ZoneId.systemDefault()).toLocalDateTime()) + : todayStr; + String subject = String.format("【工程实验申请待审批】%s - 生产/质量经理审批", entity.getApplyNo()); + String tableBody = buildPlannerNotificationTable(entity, todayStr, expectedFinishDateStr); + + List successEmails = new ArrayList<>(); + for (Map.Entry> entry : roleMapByUser.entrySet()) { + UserEmailInfoDto manager = sysUserDao.getUserEmailInfoById(entry.getKey()); + if (manager == null) { + log.warn("经理ID {} 不存在,跳过待审批通知", entry.getKey()); + continue; + } + if (StringUtils.isBlank(manager.getEmail())) { + log.warn("经理 {} 未配置邮箱,跳过待审批通知", manager.getUsername()); + continue; + } + + String roleText = entry.getValue().stream() + .map(this::getManagerRoleNameByNodeCode) + .collect(Collectors.joining("、")); + String body = "" + + "

尊敬的 " + manager.getUsername() + ":

" + + "

您好!技术经理已审批通过,以下工程实验试验单已流转到生产/质量经理审批环节。

" + + "

您当前待处理角色:" + roleText + "

" + + "
" + tableBody + + "

前往审批待办页面

" + + "

发送时间:" + + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) + + "

"; + + MailUtil.sendMail(subject, body, new String[]{manager.getEmail()}, mailSendData); + successEmails.add(manager.getEmail()); + log.info("已向经理 {} ({}) 发送待审批通知,角色: {}, 试验单: {}", + manager.getUsername(), manager.getEmail(), roleText, entity.getApplyNo()); + } + + if (!successEmails.isEmpty()) { + SendMailRecord mailRecord = new SendMailRecord(); + mailRecord.setType("工程实验申请生产质量经理待审批通知"); + mailRecord.setDocumentNo(entity.getApplyNo()); + mailRecord.setRecipient(String.join(";", successEmails)); + mailRecord.setSendDate(new Date()); + qcMapper.saveSendMailRecord(mailRecord); + } + } catch (Exception e) { + log.error("发送生产/质量经理待审批通知失败,试验单: {}, 错误: {}", entity.getApplyNo(), e.getMessage(), e); + } + } + + /** + * 节点编码转换为角色名称 + */ + private String getManagerRoleNameByNodeCode(String nodeCode) { + if ("生产经理审批".equals(nodeCode)) { + return "生产经理"; + } + if ("质量经理审批".equals(nodeCode)) { + return "质量经理"; + } + return nodeCode; + } + /** * 下达试验单后发送邮件通知计划员 *