From e87ab8e9305da0af804a57d6490ddbb3ba423e13 Mon Sep 17 00:00:00 2001 From: "han\\hanst" Date: Tue, 20 May 2025 16:03:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E8=B4=A7=E9=80=9A=E7=9F=A5=E5=8D=95?= =?UTF-8?q?=E6=94=B9=E5=8D=95=E5=AF=BC=E5=85=A5=E6=B7=BB=E5=8A=A0Customer?= =?UTF-8?q?=20Code=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/xujie/sys/common/utils/MailUtil.java | 42 ++++++ .../modules/ecss/entity/EcssCoDelNotify.java | 2 +- .../sys/modules/ecss/mapper/CoDelMapper.java | 2 +- .../ecss/service/impl/CoDelServiceImpl.java | 134 +++++++----------- .../resources/mapper/ecss/CoDelMapper.xml | 9 +- 5 files changed, 107 insertions(+), 82 deletions(-) create mode 100644 src/main/java/com/xujie/sys/common/utils/MailUtil.java diff --git a/src/main/java/com/xujie/sys/common/utils/MailUtil.java b/src/main/java/com/xujie/sys/common/utils/MailUtil.java new file mode 100644 index 00000000..2b2f37f7 --- /dev/null +++ b/src/main/java/com/xujie/sys/common/utils/MailUtil.java @@ -0,0 +1,42 @@ +package com.xujie.sys.common.utils; + +import com.xujie.sys.modules.pms.data.MailSendAddressData; +import lombok.extern.slf4j.Slf4j; +import org.springframework.mail.javamail.JavaMailSenderImpl; +import org.springframework.mail.javamail.MimeMessageHelper; + +import javax.mail.internet.MimeMessage; +import java.util.Arrays; +import java.util.Properties; + +@Slf4j +public class MailUtil { + public static void sendMail(String textHead, String text, String[] mailAddress, MailSendAddressData mailSendData) { + JavaMailSenderImpl sender = new JavaMailSenderImpl(); + sender.setHost(mailSendData.getHost()); + sender.setPort(mailSendData.getPort()); + sender.setUsername(mailSendData.getUsername()); + sender.setPassword(mailSendData.getPassword()); + sender.setDefaultEncoding("Utf-8"); + Properties p = new Properties(); + p.setProperty("mail.smtp.timeout", mailSendData.getTimeout()); + p.setProperty("mail.smtp.auth", "false"); + p.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); + sender.setJavaMailProperties(p); + MimeMessage mimeMessage = sender.createMimeMessage(); + // 设置utf-8或GBK编码,否则邮件会有乱码 + try { + MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true, "UTF-8"); + messageHelper.setFrom(mailSendData.getEmailForm(), mailSendData.getPersonal()); + messageHelper.setTo(Arrays.stream(mailAddress) + .filter(s -> s != null && !s.trim().isEmpty()) + .toArray(String[]::new)); + messageHelper.setSubject(textHead); // 标题 + messageHelper.setText(text, true); + sender.send(mimeMessage); + log.info(textHead + "通知邮件已发送!收件箱地址:" + Arrays.toString(mailAddress)); + } catch (Exception e) { + log.info("邮件发送失败!"); + } + } +} diff --git a/src/main/java/com/xujie/sys/modules/ecss/entity/EcssCoDelNotify.java b/src/main/java/com/xujie/sys/modules/ecss/entity/EcssCoDelNotify.java index 2f65ff38..619f66de 100644 --- a/src/main/java/com/xujie/sys/modules/ecss/entity/EcssCoDelNotify.java +++ b/src/main/java/com/xujie/sys/modules/ecss/entity/EcssCoDelNotify.java @@ -47,7 +47,7 @@ public class EcssCoDelNotify extends QueryPage { @DateTimeFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") private Date readyDate; - + private String customerCode; /** * */ diff --git a/src/main/java/com/xujie/sys/modules/ecss/mapper/CoDelMapper.java b/src/main/java/com/xujie/sys/modules/ecss/mapper/CoDelMapper.java index 62799e29..7ff3ef06 100644 --- a/src/main/java/com/xujie/sys/modules/ecss/mapper/CoDelMapper.java +++ b/src/main/java/com/xujie/sys/modules/ecss/mapper/CoDelMapper.java @@ -187,7 +187,7 @@ public interface CoDelMapper { List getEcssContacts(@Param("buNo") String buNo); - List getCustomerInfo(@Param("ccusname") String ccusname); + List getCustomerInfo(@Param("ccusname") String ccusname,@Param("ccuscode") String ccuscode); List getCustomerAdd(@Param("ccusname") String ccusname); 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 95490206..9741cd6e 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 @@ -3,9 +3,9 @@ package com.xujie.sys.modules.ecss.service.impl; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.xujie.sys.common.utils.DateUtil; import com.xujie.sys.common.utils.DateUtils; import com.xujie.sys.common.utils.ExcelTemplate; +import com.xujie.sys.common.utils.MailUtil; import com.xujie.sys.common.utils.PageUtils; import com.xujie.sys.modules.attrbute.entity.PropertyModelHeader; import com.xujie.sys.modules.ecss.data.*; @@ -15,8 +15,6 @@ import com.xujie.sys.modules.ecss.service.CoDelService; import com.xujie.sys.modules.orderIssure.entity.PartData; import com.xujie.sys.modules.part.entity.*; import com.xujie.sys.modules.part.mapper.PartInformationMapper; -import com.xujie.sys.modules.pms.data.EamDefectFeedBackInData; -import com.xujie.sys.modules.pms.data.MailAddressData; import com.xujie.sys.modules.pms.data.MailSendAddressData; import com.xujie.sys.modules.pms.data.SendMailRecord; import com.xujie.sys.modules.pms.mapper.EamMapper; @@ -62,8 +60,6 @@ public class CoDelServiceImpl implements CoDelService { @Autowired private CoDelMapper coDelMapper; @Autowired - private EamMapper eamMapper; - @Autowired SqlSession sqlSession; @Override @@ -107,9 +103,6 @@ public class CoDelServiceImpl implements CoDelService { } catch (Exception e) { throw new RuntimeException("导入失败:" + e.getMessage()); } - if (coDelMapper.getCustomerInfo(excelList.get(0).getCustomerName()).isEmpty()) { - throw new RuntimeException("导入失败:客户名称不存在!"); - } // 使用 groupingBy 进行分组 Map> groupedByReadyDateAndCmcInvoice = excelList.stream() @@ -184,37 +177,43 @@ public class CoDelServiceImpl implements CoDelService { if (row.getCell(0) == null ) { throw new RuntimeException("第" + j + "行的Ready Date不能为空!"); } - if (row.getCell(1) == null || StringUtils.isBlank(row.getCell(1).getStringCellValue())) { - throw new RuntimeException("第" + j + "行的Customer Name不能为空!"); + if (row.getCell(1) == null || StringUtils.isBlank(String.valueOf(row.getCell(1)))) { + throw new RuntimeException("第" + j + "行的Customer Code不能为空!"); } - if (row.getCell(2) == null) { + if (row.getCell(3) == null) { throw new RuntimeException("第" + j + "行的PO#不能为空!"); } /* if (row.getCell(3) == null) { throw new RuntimeException("第" + j + "行的SalesOrder不能为空!"); }*/ - if (row.getCell(8) == null) { + if (row.getCell(9) == null) { throw new RuntimeException("第" + j + "行的PN不能为空!"); } - if (row.getCell(10) == null) { + if (row.getCell(11) == null) { throw new RuntimeException("第" + j + "行的Qty不能为空!"); } - if (row.getCell(12) == null) { + if (row.getCell(13) == null) { throw new RuntimeException("第" + j + "行的CMC Invoice不能为空!"); } - if (row.getCell(14) == null) { + if (row.getCell(15) == null) { throw new RuntimeException("第" + j + "行的Destination不能为空!"); } - if (row.getCell(18) == null) { + if (row.getCell(19) == null) { throw new RuntimeException("第" + j + "行的Shipping Mode不能为空!"); } - if (row.getCell(20) == null) { + if (row.getCell(21) == null) { throw new RuntimeException("第" + j + "行的Currency不能为空!"); } - if (row.getCell(21) == null) { + if (row.getCell(22) == null) { throw new RuntimeException("第" + j + "行的TP不能为空!"); } - + List customerInfo = coDelMapper.getCustomerInfo(null, getStringCellValue(row, 1)); + if (customerInfo.isEmpty()) { + throw new RuntimeException("导入失败:Customer Code不存在!"); + } else { + task.setCustomerCode(getStringCellValue(row, 1)); + task.setCustomerName((String) customerInfo.get(0).get("ccusname")); + } // 为对象赋值 task.setSite(site); // site task.setBuNo(inData.getBuNo()); // bu @@ -226,37 +225,36 @@ public class CoDelServiceImpl implements CoDelService { throw new RuntimeException("第" + j + "行的ReadyDate格式有误!"); } task.setReadyDate(readDate); - task.setCustomerName(getStringCellValue(row, 1)); - task.setCustomerPO(getStringCellValue(row, 2)); - task.setSalesOrder(getStringCellValue(row, 3)); - task.setLine(getStringCellValue(row, 4)); - task.setVersion(getStringCellValue(row, 5)); - task.setStatus(getStringCellValue(row, 6)); - task.setFamily(getStringCellValue(row, 7)); - task.setPn(getStringCellValue(row, 8)); + task.setCustomerPO(getStringCellValue(row, 3)); + task.setSalesOrder(getStringCellValue(row, 4)); + task.setLine(getStringCellValue(row, 5)); + task.setVersion(getStringCellValue(row, 6)); + task.setStatus(getStringCellValue(row, 7)); + task.setFamily(getStringCellValue(row, 8)); + task.setPn(getStringCellValue(row, 9)); List parts = coDelMapper.getPartNo(site, task.getPn(), currentUser.getUsername(), inData.getBuNo()); if (parts.isEmpty()) { throw new RuntimeException("导入失败:物料:" + task.getPn() + "不存在!"); } task.setPartNo(parts.get(0).getPartNo()); - task.setPartDescription(getStringCellValue(row, 9)); - task.setQty(getNumericCellValueOrDefault(row, 10)); - task.setLt(getNumericCellValueOrDefault(row, 11)); - task.setCmcInvoice(getStringCellValue(row, 12)); - task.setCmcComment(getStringCellValue(row, 13)); - task.setDestination(getStringCellValue(row, 14)); - task.setSaleType(getStringCellValue(row, 15)); - task.setAwbBl(getStringCellValue(row, 16)); - task.setShippingNumber(getStringCellValue(row, 17)); - task.setShippingMode(getStringCellValue(row, 18)); - task.setForwarderInfo(getStringCellValue(row, 19)); - task.setCurrency(getStringCellValue(row, 20)); - task.setTp(getNumericCellValueOrDefault(row, 21)); - task.setTtlAmount(getNumericCellValueOrDefault(row, 22).setScale(2, RoundingMode.HALF_UP)); - task.setSumPrice(getNumericCellValueOrDefault(row, 23).setScale(2, RoundingMode.HALF_UP)); - task.setUpc(getStringCellValue(row, 24)); - task.setSo(getStringCellValue(row, 25)); - task.setRemark(getStringCellValue(row, 26)); + task.setPartDescription(getStringCellValue(row, 10)); + task.setQty(getNumericCellValueOrDefault(row, 11)); + task.setLt(getNumericCellValueOrDefault(row, 12)); + task.setCmcInvoice(getStringCellValue(row, 13)); + task.setCmcComment(getStringCellValue(row, 14)); + task.setDestination(getStringCellValue(row, 15)); + task.setSaleType(getStringCellValue(row, 16)); + task.setAwbBl(getStringCellValue(row, 17)); + task.setShippingNumber(getStringCellValue(row, 18)); + task.setShippingMode(getStringCellValue(row, 19)); + task.setForwarderInfo(getStringCellValue(row, 20)); + task.setCurrency(getStringCellValue(row, 21)); + task.setTp(getNumericCellValueOrDefault(row, 22)); + task.setTtlAmount(getNumericCellValueOrDefault(row, 23)); + task.setSumPrice(getNumericCellValueOrDefault(row, 24)); + task.setUpc(getStringCellValue(row, 25)); + task.setSo(getStringCellValue(row, 26)); + task.setRemark(getStringCellValue(row, 27)); task.setErpFlag("N"); task.setNotifyStatus("已计划"); task.setUsername(inData.getUsername()); @@ -270,35 +268,8 @@ public class CoDelServiceImpl implements CoDelService { } public void sendMailUtil(String textHead,String text,String[] mailAddress,EcssCoDelNotifyHeaderData data) { - //发送邮件 - JavaMailSenderImpl sender = new JavaMailSenderImpl(); MailSendAddressData mailSendData = qcMapper.getSendMailFromAddress(); - sender.setHost(mailSendData.getHost()); - sender.setPort(mailSendData.getPort()); - sender.setUsername(mailSendData.getUsername()); - sender.setPassword(mailSendData.getPassword()); - sender.setDefaultEncoding("Utf-8"); - Properties p = new Properties(); - p.setProperty("mail.smtp.timeout", mailSendData.getTimeout()); - p.setProperty("mail.smtp.auth", "false"); - p.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); - sender.setJavaMailProperties(p); - MimeMessage mimeMessage = sender.createMimeMessage(); - // 设置utf-8或GBK编码,否则邮件会有乱码 - try { - MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true, "UTF-8"); - messageHelper.setFrom(mailSendData.getEmailForm(), mailSendData.getPersonal()); - messageHelper.setTo(Arrays.stream(mailAddress) - .filter(s -> s != null && !s.trim().isEmpty()) - .toArray(String[]::new)); - messageHelper.setSubject(textHead); // 标题 - messageHelper.setText(text, true); - sender.send(mimeMessage); - log.info(textHead + "通知邮件已发送!收件箱地址:" + Arrays.toString(mailAddress)); - } catch (Exception e) { - log.info("邮件发送失败!"); - return; - } + MailUtil.sendMail(textHead, text, mailAddress, mailSendData); // 保存邮件记录 SendMailRecord mailRecord = new SendMailRecord(); mailRecord.setSite(data.getSite()); @@ -318,10 +289,13 @@ public class CoDelServiceImpl implements CoDelService { @Override public void deleteEcssDelHeader(EcssCoDelNotifyHeaderData data) { List checkEcssCoDelNotifyDetail = coDelMapper.searchEcssCoDelNotifyDetail(data); - if (checkEcssCoDelNotifyDetail.size() > 0) { + /* if (checkEcssCoDelNotifyDetail.size() > 0) { throw new RuntimeException("该发货通知单下有明细无法删除!"); - } + }*/ coDelMapper.deleteEcssDelHeader(data); + for (EcssCoDelNotifyDetailData detailData : checkEcssCoDelNotifyDetail){ + coDelMapper.deleteEcssDelDetail(detailData); + } } @Override @@ -337,7 +311,8 @@ public class CoDelServiceImpl implements CoDelService { coDelMapper.deleteDeclarationDetail(inData); // 取消订单 通知仓库和单证人员 //设置邮件内容 - String text = "" + "
发货通知单" +data.getDelNo()+"【发票:"+ data.getCmcInvoice()+"】订单取消" + "
"; + String text = "" + "
发货通知单" +data.getDelNo()+"【发票:"+ + data.getCmcInvoice()+"】订单取消" + "
"; String textHead = data.getCmcInvoice()+"【发票:"+ data.getCmcInvoice()+"】订单取消"; String[] mailAddress = coDelMapper.queryUsersByRoleName("关务仓库").stream().map(SysUserEntity::getEmail).toArray(String[]::new); String[] mailAddress2 = coDelMapper.queryUsersByRoleName("关务单证").stream().map(SysUserEntity::getEmail).toArray(String[]::new); @@ -421,7 +396,8 @@ public class CoDelServiceImpl implements CoDelService { } // 已下达 通知仓库人员 //设置邮件内容 - String text = "" + "
发货通知单" +data.getDelNo()+"【发票:"+ data.getCmcInvoice()+"】已下达" + "
"; + String text = "" + "
发货通知单" +data.getDelNo()+"【发票:"+ + data.getCmcInvoice()+"】已下达" + "
"; String textHead = "发货通知单"+data.getDelNo()+"【发票:"+ data.getCmcInvoice()+"】下达"; String[] mailAddress = coDelMapper.queryUsersByRoleName("关务仓库").stream().map(SysUserEntity::getEmail).toArray(String[]::new); if (mailAddress.length>0) { @@ -1166,7 +1142,7 @@ public class CoDelServiceImpl implements CoDelService { defaultData.setDelNo(inData.getDelNo()); defaultData.setCreateBy(currentUser.getUsername()); // 从视图获取客户信息 - List customerInfo= coDelMapper.getCustomerInfo(getCoDelNotifyHeaderData.get(0).getCustomerName()); + List customerInfo= coDelMapper.getCustomerInfo(getCoDelNotifyHeaderData.get(0).getCustomerName(),null); if (!customerInfo.isEmpty()) { defaultData.setReceiveArea(customerInfo.get(0).get("cnative")!=null?customerInfo.get(0).get("cnative").toString():""); defaultData.setSalesArea(customerInfo.get(0).get("cnative")!=null?customerInfo.get(0).get("cnative").toString():""); @@ -2209,7 +2185,7 @@ public class CoDelServiceImpl implements CoDelService { public List getCustomerInfo(EcssDeclarationHeaderData data) { // 发货通知单 EcssCoDelNotifyHeaderData notifyHeader = coDelMapper.getEcssCoDelNotifyHeader(data.getSite(), data.getDelNo()); - return coDelMapper.getCustomerInfo(notifyHeader.getCustomerName()); + return coDelMapper.getCustomerInfo(notifyHeader.getCustomerName(),null); } @Override diff --git a/src/main/resources/mapper/ecss/CoDelMapper.xml b/src/main/resources/mapper/ecss/CoDelMapper.xml index bfaa6379..af568df0 100644 --- a/src/main/resources/mapper/ecss/CoDelMapper.xml +++ b/src/main/resources/mapper/ecss/CoDelMapper.xml @@ -876,7 +876,14 @@ left join ecss_CoDelNotifyHeader noHeader on a.site=noHeader.site and a.delNo=no select DISTINCT vcus.ccusname,vcusp.ccontactname,vcusp.cnative from view_custdev_mes_cmc_customer vcus LEFT JOIN view_custdev_mes_cmc_customer_person vcusp on vcus.ccuscode=vcusp.ccuscode - where vcus.ccusname=#{ccusname} + + + and vcus.ccusname=#{ccusname} + + + and vcus.ccuscode=#{ccuscode} + +