|
|
@ -57,6 +57,8 @@ import static com.xujie.sys.modules.sys.controller.AbstractController.getUser; |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
public class ErfExpApplyServiceImpl extends ServiceImpl<ErfExpApplyMapper, ErfExpApply> implements ErfExpApplyService { |
|
|
public class ErfExpApplyServiceImpl extends ServiceImpl<ErfExpApplyMapper, ErfExpApply> implements ErfExpApplyService { |
|
|
|
|
|
|
|
|
|
|
|
private static final String APPROVAL_PAGE_URL = "http://172.26.68.20:9001/#/erf-expApplyApproval"; |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
private ErfExpApplyMapper erfExpApplyMapper; |
|
|
private ErfExpApplyMapper erfExpApplyMapper; |
|
|
|
|
|
|
|
|
@ -231,6 +233,9 @@ public class ErfExpApplyServiceImpl extends ServiceImpl<ErfExpApplyMapper, ErfEx |
|
|
action, entity.getApplyNo(), data.getTechManagerId(), data.getProdManagerIds(), |
|
|
action, entity.getApplyNo(), data.getTechManagerId(), data.getProdManagerIds(), |
|
|
data.getQualityManagerIds(), plannerUserIds); |
|
|
data.getQualityManagerIds(), plannerUserIds); |
|
|
|
|
|
|
|
|
|
|
|
// 下达后立即发送邮件通知技术经理处理审批任务 |
|
|
|
|
|
sendTechManagerApprovalTaskNotification(entity, data.getTechManagerId()); |
|
|
|
|
|
|
|
|
// 下达后发送邮件通知所有计划员 |
|
|
// 下达后发送邮件通知所有计划员 |
|
|
sendPlannerSubmitNotification(entity, plannerUserIds); |
|
|
sendPlannerSubmitNotification(entity, plannerUserIds); |
|
|
} |
|
|
} |
|
|
@ -290,6 +295,12 @@ public class ErfExpApplyServiceImpl extends ServiceImpl<ErfExpApplyMapper, ErfEx |
|
|
String nextNodeCode = erfFlowEngineService.getNextNodeCode(data.getApplyNo(), data.getNodeCode()); |
|
|
String nextNodeCode = erfFlowEngineService.getNextNodeCode(data.getApplyNo(), data.getNodeCode()); |
|
|
erfFlowEngineService.moveToNextNode(data.getApplyNo(), data.getNodeCode(), data); |
|
|
erfFlowEngineService.moveToNextNode(data.getApplyNo(), data.getNodeCode(), data); |
|
|
log.info("所有审批完成,流转到下一节点"); |
|
|
log.info("所有审批完成,流转到下一节点"); |
|
|
|
|
|
if ("生产和质量经理审批".equals(nextNodeCode)) { |
|
|
|
|
|
ErfExpApply managerEntity = this.getById(data.getApplyNo()); |
|
|
|
|
|
if (managerEntity != null) { |
|
|
|
|
|
sendProdQualityManagerApprovalTaskNotification(managerEntity); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
if ("计划员排产".equals(nextNodeCode)) { |
|
|
if ("计划员排产".equals(nextNodeCode)) { |
|
|
ErfExpApply approvedEntity = this.getById(data.getApplyNo()); |
|
|
ErfExpApply approvedEntity = this.getById(data.getApplyNo()); |
|
|
if (approvedEntity != null) { |
|
|
if (approvedEntity != null) { |
|
|
@ -1554,6 +1565,163 @@ public class ErfExpApplyServiceImpl extends ServiceImpl<ErfExpApplyMapper, ErfEx |
|
|
return applyNo; |
|
|
return applyNo; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 下达试验单后立即通知技术经理审批 |
|
|
|
|
|
*/ |
|
|
|
|
|
private void sendTechManagerApprovalTaskNotification(ErfExpApply entity, Long techManagerId) { |
|
|
|
|
|
try { |
|
|
|
|
|
if (techManagerId == null) { |
|
|
|
|
|
log.warn("技术经理ID为空,跳过技术经理待审批通知: {}", entity.getApplyNo()); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
UserEmailInfoDto techManager = sysUserDao.getUserEmailInfoById(techManagerId); |
|
|
|
|
|
if (techManager == null) { |
|
|
|
|
|
log.warn("技术经理ID {} 不存在,跳过待审批通知", techManagerId); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
if (StringUtils.isBlank(techManager.getEmail())) { |
|
|
|
|
|
log.warn("技术经理 {} 未配置邮箱,跳过待审批通知", techManager.getUsername()); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
MailSendAddressData mailSendData = qcMapper.getSendMailFromAddress(); |
|
|
|
|
|
if (mailSendData == null) { |
|
|
|
|
|
log.error("邮件发送配置未设置,无法发送技术经理待审批通知"); |
|
|
|
|
|
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); |
|
|
|
|
|
String body = "<html><body>" |
|
|
|
|
|
+ "<h3>尊敬的 " + techManager.getUsername() + ":</h3>" |
|
|
|
|
|
+ "<p>您好!以下工程实验试验单已下达,当前审批节点为<strong>技术经理审批</strong>,请及时处理。</p>" |
|
|
|
|
|
+ "<hr/>" + tableBody |
|
|
|
|
|
+ "<br/><p><a style='color:#0f84b0;' href='" + APPROVAL_PAGE_URL + "'>前往审批待办页面</a></p>" |
|
|
|
|
|
+ "<p style='color:#888;'>发送时间:" |
|
|
|
|
|
+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) |
|
|
|
|
|
+ "</p></body></html>"; |
|
|
|
|
|
|
|
|
|
|
|
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<ErfFlowNodeInstance> managerNodes = erfFlowNodeInstanceMapper.selectList( |
|
|
|
|
|
new QueryWrapper<ErfFlowNodeInstance>() |
|
|
|
|
|
.eq("apply_no", entity.getApplyNo()) |
|
|
|
|
|
.eq("status", "待审核") |
|
|
|
|
|
.in("node_code", "生产经理审批", "质量经理审批") |
|
|
|
|
|
); |
|
|
|
|
|
if (managerNodes == null || managerNodes.isEmpty()) { |
|
|
|
|
|
log.warn("未找到待审核的生产/质量经理节点,跳过通知: {}", entity.getApplyNo()); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Map<Long, Set<String>> 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<String> successEmails = new ArrayList<>(); |
|
|
|
|
|
for (Map.Entry<Long, Set<String>> 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 = "<html><body>" |
|
|
|
|
|
+ "<h3>尊敬的 " + manager.getUsername() + ":</h3>" |
|
|
|
|
|
+ "<p>您好!技术经理已审批通过,以下工程实验试验单已流转到<strong>生产/质量经理审批</strong>环节。</p>" |
|
|
|
|
|
+ "<p>您当前待处理角色:<strong>" + roleText + "</strong></p>" |
|
|
|
|
|
+ "<hr/>" + tableBody |
|
|
|
|
|
+ "<br/><p><a style='color:#0f84b0;' href='" + APPROVAL_PAGE_URL + "'>前往审批待办页面</a></p>" |
|
|
|
|
|
+ "<p style='color:#888;'>发送时间:" |
|
|
|
|
|
+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) |
|
|
|
|
|
+ "</p></body></html>"; |
|
|
|
|
|
|
|
|
|
|
|
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; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 下达试验单后发送邮件通知计划员 |
|
|
* 下达试验单后发送邮件通知计划员 |
|
|
* |
|
|
* |
|
|
|