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; + } + /** * 下达试验单后发送邮件通知计划员 *