From 2026ee4b65fe31771db385d18c77537718a619e1 Mon Sep 17 00:00:00 2001 From: "han\\hanst" Date: Tue, 9 Dec 2025 12:35:48 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=80=BB=E6=AF=9B=E9=87=8D?= =?UTF-8?q?=E5=8F=91=E9=82=AE=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/EcssDeclarationHeaderData.java | 1 + .../ecss/service/impl/CoDelServiceImpl.java | 250 +++++++++++++++++- 2 files changed, 250 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/xujie/sys/modules/ecss/entity/EcssDeclarationHeaderData.java b/src/main/java/com/xujie/sys/modules/ecss/entity/EcssDeclarationHeaderData.java index 4d389ddb..019143b9 100644 --- a/src/main/java/com/xujie/sys/modules/ecss/entity/EcssDeclarationHeaderData.java +++ b/src/main/java/com/xujie/sys/modules/ecss/entity/EcssDeclarationHeaderData.java @@ -64,4 +64,5 @@ public class EcssDeclarationHeaderData extends EcssDeclarationHeader{ private String destination; private Boolean highPalletFlag; private Boolean showWeight; + private BigDecimal allWeight; } diff --git a/src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelServiceImpl.java b/src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelServiceImpl.java index 17b34506..a9d44bbe 100644 --- a/src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelServiceImpl.java +++ b/src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelServiceImpl.java @@ -2235,6 +2235,11 @@ public class CoDelServiceImpl implements CoDelService { .filter(Objects::nonNull) // 防止空指针 .reduce(0, Integer::sum); defaultData.setPackageQty(totalPlt); + defaultData.setPalletWeight(palletHeaderDataList.stream() + .map(EcssCoDelPalletHeaderData::getWeight) + .filter(Objects::nonNull) // 防止空指针 + .reduce(BigDecimal.ZERO, BigDecimal::add)); + defaultData.setAllWeight(defaultData.getGrossWeight().add(defaultData.getPalletWeight())); List boxList = coDelMapper.exportCoDelBoxList(notifyHeaderData); // 检查box_qty是否存在null或0 for (Map box : boxList) { @@ -4732,6 +4737,12 @@ public class CoDelServiceImpl implements CoDelService { log.info("=== 开始调整总毛重 ==="); log.info("发货单号: {}, 实际总毛重: {}", delNo, actualGrossWeightObj); + // 获取发货通知单信息 + EcssCoDelNotifyHeaderData notifyHeader = coDelMapper.getEcssCoDelNotifyHeader(site, delNo); + + // 检查发货通知单状态是否为已报关 + boolean isCustomsCleared = "已报关".equals(notifyHeader.getNotifyStatus()); + // 转换实际总毛重为BigDecimal BigDecimal actualTotalGrossWeight; if (actualGrossWeightObj instanceof Number) { @@ -4751,6 +4762,15 @@ public class CoDelServiceImpl implements CoDelService { queryData.setDelNo(delNo); List boxList = coDelMapper.selectBoxList(queryData); + // 如果状态为已报关,保存调整前的箱数据用于邮件对比 + List oldBoxList = null; + if (isCustomsCleared) { + oldBoxList = new ArrayList<>(); + for (Map box : boxList) { + oldBoxList.add(new HashMap<>(box)); + } + } + if (boxList == null || boxList.isEmpty()) { throw new RuntimeException("未找到箱数据"); } @@ -4847,6 +4867,36 @@ public class CoDelServiceImpl implements CoDelService { if (difference.compareTo(new BigDecimal("0.001")) > 0) { log.warn("警告:调整后总毛重与目标值存在误差: {}", difference); } + if (isCustomsCleared) { + log.info("装箱数据删除:发货通知单{}状态为已报关,开始删除对应的报关单", delNo); + + // 查找对应的报关单 + EcssDeclarationHeaderData declarationQuery = new EcssDeclarationHeaderData(); + declarationQuery.setSite(site); + declarationQuery.setDelNo(delNo); + + List deletedDeclarations = coDelMapper.searchDeclarationHeader( + new Page(1, 1000), declarationQuery).getRecords(); + + // 删除找到的报关单 + for (EcssDeclarationHeaderData declaration : deletedDeclarations) { + log.info("删除报关单,报关单号:{}", declaration.getDeclarationNo()); + coDelMapper.deleteDeclarationHeader(declaration); + coDelMapper.deleteDeclarationDetail(declaration); + } + + log.info("已删除发货通知单{}对应的{}个报关单", delNo, deletedDeclarations.size()); + + // 将通知单状态更新为仓库已确认 + notifyHeader.setNotifyStatus("仓库已确认"); + coDelMapper.changeEcssDelStatus(notifyHeader); + + log.info("发货通知单{}状态已更新为仓库已确认", delNo); + } + // 如果状态为已报关,发送邮件通知创建人 + if (isCustomsCleared) { + sendGrossWeightAdjustmentNotificationEmail(notifyHeader, oldBoxList, newBoxDataList, actualTotalGrossWeight, updateBy); + } } /** @@ -6317,7 +6367,6 @@ public class CoDelServiceImpl implements CoDelService { emailContent.append("发货通知单号").append(notifyHeader.getDelNo()).append(""); emailContent.append("发票号").append(notifyHeader.getCmcInvoice() != null ? notifyHeader.getCmcInvoice() : "").append(""); emailContent.append("客户").append(notifyHeader.getCustomerName() != null ? notifyHeader.getCustomerName() : "").append(""); - emailContent.append("原状态"+(notifyHeader.getNotifyStatus())+""); emailContent.append("当前状态仓库已确认"); emailContent.append(""); @@ -6807,6 +6856,205 @@ public class CoDelServiceImpl implements CoDelService { coDelMapper.updatePartPackageNo(updateParams); } + /** + * 发送总毛重调整通知邮件 + * + * @param notifyHeader 发货通知单头数据 + * @param oldBoxList 调整前的箱子列表 + * @param newBoxList 调整后的箱子列表 + * @param targetGrossWeight 目标总毛重 + * @param updateBy 操作人 + * @author AI Assistant + * @date 2024-12-09 + */ + private void sendGrossWeightAdjustmentNotificationEmail(EcssCoDelNotifyHeaderData notifyHeader, + List oldBoxList, + List> newBoxList, + BigDecimal targetGrossWeight, + String updateBy) { + try { + log.info("开始发送总毛重调整通知邮件,发货通知单号:{}", notifyHeader.getDelNo()); + + // 生成邮件内容 + String emailContent = generateGrossWeightAdjustmentEmailContent( + notifyHeader, oldBoxList, newBoxList, targetGrossWeight, updateBy); + + // 获取发货通知单创建人邮箱 + SysUserEntity creator = coDelMapper.queryByUserName(notifyHeader.getCreateBy()); + if (creator == null || StringUtils.isBlank(creator.getEmail())) { + log.warn("发货通知单创建人{}不存在或没有配置邮箱地址", notifyHeader.getCreateBy()); + return; + } + String creatorEmail = creator.getEmail(); + + // 发送邮件 + String subject = String.format("发货通知单%s【发票:%s】总毛重调整通知", + notifyHeader.getDelNo(), notifyHeader.getCmcInvoice()); + String[] mailAddress = {creatorEmail}; + + sendMailUtil(subject, emailContent, mailAddress, notifyHeader); + + log.info("总毛重调整通知邮件发送成功,收件人:{}", creatorEmail); + + } catch (Exception e) { + log.error("发送总毛重调整通知邮件失败,发货通知单号:{}, 错误信息:{}", + notifyHeader.getDelNo(), e.getMessage(), e); + // 邮件发送失败不影响主流程,只记录日志 + } + } + + /** + * 生成总毛重调整邮件内容 + * + * @param notifyHeader 发货通知单头数据 + * @param oldBoxList 调整前的箱子列表 + * @param newBoxList 调整后的箱子列表 + * @param targetGrossWeight 目标总毛重 + * @param updateBy 操作人 + * @return HTML格式的邮件内容 + */ + private String generateGrossWeightAdjustmentEmailContent(EcssCoDelNotifyHeaderData notifyHeader, + List oldBoxList, + List> newBoxList, + BigDecimal targetGrossWeight, + String updateBy) { + StringBuilder emailContent = new StringBuilder(); + + emailContent.append(""); + emailContent.append(""); + emailContent.append(""); + emailContent.append(""); + emailContent.append(""); + emailContent.append(""); + emailContent.append(""); + + // 邮件标题 + emailContent.append("

发货通知单总毛重调整通知

"); + + // 发货通知单基本信息 + emailContent.append("
一、发货通知单信息
"); + emailContent.append(""); + emailContent.append(""); + emailContent.append(""); + emailContent.append(""); + emailContent.append(""); + emailContent.append(""); + emailContent.append("
发货通知单号").append(notifyHeader.getDelNo()).append("
发票号").append(notifyHeader.getCmcInvoice() != null ? notifyHeader.getCmcInvoice() : "").append("
客户").append(notifyHeader.getCustomerName() != null ? notifyHeader.getCustomerName() : "").append("
当前状态").append(notifyHeader.getNotifyStatus()).append("
操作人").append(updateBy).append("
"); + + // 计算总毛重变化 + BigDecimal oldTotalGrossWeight = BigDecimal.ZERO; + BigDecimal newTotalGrossWeight = BigDecimal.ZERO; + + for (Map box : oldBoxList) { + Object grossWeightObj = box.get("grossWeight"); + if (grossWeightObj != null) { + BigDecimal grossWeight = new BigDecimal(grossWeightObj.toString()); + oldTotalGrossWeight = oldTotalGrossWeight.add(grossWeight); + } + } + + for (Map box : newBoxList) { + Object grossWeightObj = box.get("grossWeight"); + if (grossWeightObj != null) { + BigDecimal grossWeight = new BigDecimal(grossWeightObj.toString()); + newTotalGrossWeight = newTotalGrossWeight.add(grossWeight); + } + } + + // 总毛重调整汇总 + emailContent.append("
二、总毛重调整汇总
"); + emailContent.append("
"); + emailContent.append("

调整前总毛重:").append(oldTotalGrossWeight.setScale(3, RoundingMode.HALF_UP)).append(" KG

"); + emailContent.append("

调整后总毛重:").append(newTotalGrossWeight.setScale(3, RoundingMode.HALF_UP)).append(" KG

"); + emailContent.append("

"); + emailContent.append("
"); + + // 箱子详细变化信息 + emailContent.append("
三、箱子重量调整明细
"); + emailContent.append(""); + emailContent.append(""); + emailContent.append(""); + emailContent.append(""); + emailContent.append(""); + emailContent.append(""); + emailContent.append(""); + emailContent.append(""); + emailContent.append(""); + + // 创建箱号到旧数据的映射 + Map oldBoxMap = new HashMap<>(); + for (Map oldBox : oldBoxList) { + String itemNo = oldBox.get("item_no") != null ? oldBox.get("item_no").toString() : ""; + oldBoxMap.put(itemNo, oldBox); + } + + for (Map newBox : newBoxList) { + String itemNo = newBox.get("item_no") != null ? newBox.get("item_no").toString() : ""; + Map oldBox = oldBoxMap.get(itemNo); + + emailContent.append(""); + emailContent.append(""); + emailContent.append(""); + + // 旧毛重 + BigDecimal oldGrossWeight = BigDecimal.ZERO; + if (oldBox != null && oldBox.get("grossWeight") != null) { + oldGrossWeight = new BigDecimal(oldBox.get("grossWeight").toString()); + } + emailContent.append(""); + + // 新毛重 + BigDecimal newGrossWeight = BigDecimal.ZERO; + if (newBox.get("grossWeight") != null) { + newGrossWeight = new BigDecimal(newBox.get("grossWeight").toString()); + } + emailContent.append(""); + + // 新净重 + BigDecimal newNetWeight = BigDecimal.ZERO; + if (newBox.get("netWeight") != null) { + newNetWeight = new BigDecimal(newBox.get("netWeight").toString()); + } + emailContent.append(""); + + // 毛重变化 + BigDecimal weightChange = newGrossWeight.subtract(oldGrossWeight); + emailContent.append(""); + + emailContent.append(""); + } + + emailContent.append("
箱号箱数调整前毛重(KG)调整后毛重(KG)调整后净重(KG)毛重变化
").append(itemNo).append("").append(newBox.get("box_qty") != null ? newBox.get("box_qty").toString() : "0").append("").append(oldGrossWeight.setScale(3, RoundingMode.HALF_UP)).append("").append(newGrossWeight.setScale(3, RoundingMode.HALF_UP)).append("").append(newNetWeight.setScale(3, RoundingMode.HALF_UP)).append(""); + if (weightChange.compareTo(BigDecimal.ZERO) > 0) { + emailContent.append("+"); + } + emailContent.append(weightChange.setScale(3, RoundingMode.HALF_UP)).append("
"); + + // 注意事项 + emailContent.append("
"); + emailContent.append("⚠️ 注意事项:"); + emailContent.append("
    "); + emailContent.append("
  • 此操作已自动按比例调整所有箱的毛重和净重
  • "); + emailContent.append("
  • 净重计算公式:净重 = 毛重 - (箱数 / 2)
  • "); + emailContent.append("
  • 如有疑问,请及时联系仓库或相关负责人确认
  • "); + emailContent.append("
"); + emailContent.append("
"); + + emailContent.append(""); + emailContent.append(""); + + return emailContent.toString(); + } + /** * 获取单元格值为字符串 */