Browse Source

发货通知单改单导入添加Customer Code列

java8
han\hanst 8 months ago
parent
commit
e87ab8e930
  1. 42
      src/main/java/com/xujie/sys/common/utils/MailUtil.java
  2. 2
      src/main/java/com/xujie/sys/modules/ecss/entity/EcssCoDelNotify.java
  3. 2
      src/main/java/com/xujie/sys/modules/ecss/mapper/CoDelMapper.java
  4. 134
      src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelServiceImpl.java
  5. 9
      src/main/resources/mapper/ecss/CoDelMapper.xml

42
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("邮件发送失败!");
}
}
}

2
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") @DateTimeFormat(pattern = "yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date readyDate; private Date readyDate;
private String customerCode;
/** /**
* *
*/ */

2
src/main/java/com/xujie/sys/modules/ecss/mapper/CoDelMapper.java

@ -187,7 +187,7 @@ public interface CoDelMapper {
List<Map> getEcssContacts(@Param("buNo") String buNo); List<Map> getEcssContacts(@Param("buNo") String buNo);
List<Map> getCustomerInfo(@Param("ccusname") String ccusname);
List<Map> getCustomerInfo(@Param("ccusname") String ccusname,@Param("ccuscode") String ccuscode);
List<Map> getCustomerAdd(@Param("ccusname") String ccusname); List<Map> getCustomerAdd(@Param("ccusname") String ccusname);

134
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.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 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.DateUtils;
import com.xujie.sys.common.utils.ExcelTemplate; 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.common.utils.PageUtils;
import com.xujie.sys.modules.attrbute.entity.PropertyModelHeader; import com.xujie.sys.modules.attrbute.entity.PropertyModelHeader;
import com.xujie.sys.modules.ecss.data.*; 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.orderIssure.entity.PartData;
import com.xujie.sys.modules.part.entity.*; import com.xujie.sys.modules.part.entity.*;
import com.xujie.sys.modules.part.mapper.PartInformationMapper; 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.MailSendAddressData;
import com.xujie.sys.modules.pms.data.SendMailRecord; import com.xujie.sys.modules.pms.data.SendMailRecord;
import com.xujie.sys.modules.pms.mapper.EamMapper; import com.xujie.sys.modules.pms.mapper.EamMapper;
@ -62,8 +60,6 @@ public class CoDelServiceImpl implements CoDelService {
@Autowired @Autowired
private CoDelMapper coDelMapper; private CoDelMapper coDelMapper;
@Autowired @Autowired
private EamMapper eamMapper;
@Autowired
SqlSession sqlSession; SqlSession sqlSession;
@Override @Override
@ -107,9 +103,6 @@ public class CoDelServiceImpl implements CoDelService {
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("导入失败:" + e.getMessage()); throw new RuntimeException("导入失败:" + e.getMessage());
} }
if (coDelMapper.getCustomerInfo(excelList.get(0).getCustomerName()).isEmpty()) {
throw new RuntimeException("导入失败:客户名称不存在!");
}
// 使用 groupingBy 进行分组 // 使用 groupingBy 进行分组
Map<String, List<EcssCoDelNotifyData>> groupedByReadyDateAndCmcInvoice = excelList.stream() Map<String, List<EcssCoDelNotifyData>> groupedByReadyDateAndCmcInvoice = excelList.stream()
@ -184,37 +177,43 @@ public class CoDelServiceImpl implements CoDelService {
if (row.getCell(0) == null ) { if (row.getCell(0) == null ) {
throw new RuntimeException("第" + j + "行的Ready Date不能为空!"); 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#不能为空!"); throw new RuntimeException("第" + j + "行的PO#不能为空!");
} }
/* if (row.getCell(3) == null) { /* if (row.getCell(3) == null) {
throw new RuntimeException("第" + j + "行的SalesOrder不能为空!"); throw new RuntimeException("第" + j + "行的SalesOrder不能为空!");
}*/ }*/
if (row.getCell(8) == null) {
if (row.getCell(9) == null) {
throw new RuntimeException("第" + j + "行的PN不能为空!"); throw new RuntimeException("第" + j + "行的PN不能为空!");
} }
if (row.getCell(10) == null) {
if (row.getCell(11) == null) {
throw new RuntimeException("第" + j + "行的Qty不能为空!"); throw new RuntimeException("第" + j + "行的Qty不能为空!");
} }
if (row.getCell(12) == null) {
if (row.getCell(13) == null) {
throw new RuntimeException("第" + j + "行的CMC Invoice不能为空!"); throw new RuntimeException("第" + j + "行的CMC Invoice不能为空!");
} }
if (row.getCell(14) == null) {
if (row.getCell(15) == null) {
throw new RuntimeException("第" + j + "行的Destination不能为空!"); throw new RuntimeException("第" + j + "行的Destination不能为空!");
} }
if (row.getCell(18) == null) {
if (row.getCell(19) == null) {
throw new RuntimeException("第" + j + "行的Shipping Mode不能为空!"); throw new RuntimeException("第" + j + "行的Shipping Mode不能为空!");
} }
if (row.getCell(20) == null) {
if (row.getCell(21) == null) {
throw new RuntimeException("第" + j + "行的Currency不能为空!"); throw new RuntimeException("第" + j + "行的Currency不能为空!");
} }
if (row.getCell(21) == null) {
if (row.getCell(22) == null) {
throw new RuntimeException("第" + j + "行的TP不能为空!"); throw new RuntimeException("第" + j + "行的TP不能为空!");
} }
List<Map> 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.setSite(site); // site
task.setBuNo(inData.getBuNo()); // bu task.setBuNo(inData.getBuNo()); // bu
@ -226,37 +225,36 @@ public class CoDelServiceImpl implements CoDelService {
throw new RuntimeException("第" + j + "行的ReadyDate格式有误!"); throw new RuntimeException("第" + j + "行的ReadyDate格式有误!");
} }
task.setReadyDate(readDate); 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<PartData> parts = coDelMapper.getPartNo(site, task.getPn(), currentUser.getUsername(), inData.getBuNo()); List<PartData> parts = coDelMapper.getPartNo(site, task.getPn(), currentUser.getUsername(), inData.getBuNo());
if (parts.isEmpty()) { if (parts.isEmpty()) {
throw new RuntimeException("导入失败:物料:" + task.getPn() + "不存在!"); throw new RuntimeException("导入失败:物料:" + task.getPn() + "不存在!");
} }
task.setPartNo(parts.get(0).getPartNo()); 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.setErpFlag("N");
task.setNotifyStatus("已计划"); task.setNotifyStatus("已计划");
task.setUsername(inData.getUsername()); task.setUsername(inData.getUsername());
@ -270,35 +268,8 @@ public class CoDelServiceImpl implements CoDelService {
} }
public void sendMailUtil(String textHead,String text,String[] mailAddress,EcssCoDelNotifyHeaderData data) { public void sendMailUtil(String textHead,String text,String[] mailAddress,EcssCoDelNotifyHeaderData data) {
//发送邮件
JavaMailSenderImpl sender = new JavaMailSenderImpl();
MailSendAddressData mailSendData = qcMapper.getSendMailFromAddress(); 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(); SendMailRecord mailRecord = new SendMailRecord();
mailRecord.setSite(data.getSite()); mailRecord.setSite(data.getSite());
@ -318,10 +289,13 @@ public class CoDelServiceImpl implements CoDelService {
@Override @Override
public void deleteEcssDelHeader(EcssCoDelNotifyHeaderData data) { public void deleteEcssDelHeader(EcssCoDelNotifyHeaderData data) {
List<EcssCoDelNotifyDetailData> checkEcssCoDelNotifyDetail = coDelMapper.searchEcssCoDelNotifyDetail(data); List<EcssCoDelNotifyDetailData> checkEcssCoDelNotifyDetail = coDelMapper.searchEcssCoDelNotifyDetail(data);
if (checkEcssCoDelNotifyDetail.size() > 0) {
/* if (checkEcssCoDelNotifyDetail.size() > 0) {
throw new RuntimeException("该发货通知单下有明细无法删除!"); throw new RuntimeException("该发货通知单下有明细无法删除!");
}
}*/
coDelMapper.deleteEcssDelHeader(data); coDelMapper.deleteEcssDelHeader(data);
for (EcssCoDelNotifyDetailData detailData : checkEcssCoDelNotifyDetail){
coDelMapper.deleteEcssDelDetail(detailData);
}
} }
@Override @Override
@ -337,7 +311,8 @@ public class CoDelServiceImpl implements CoDelService {
coDelMapper.deleteDeclarationDetail(inData); coDelMapper.deleteDeclarationDetail(inData);
// 取消订单 通知仓库和单证人员 // 取消订单 通知仓库和单证人员
//设置邮件内容 //设置邮件内容
String text = "<!DOCTYPE>" + "<div>发货通知单" +data.getDelNo()+"【发票:"+ data.getCmcInvoice()+"】订单取消" + "</div>";
String text = "<!DOCTYPE>" + "<div>发货通知单" +data.getDelNo()+"【发票:"+
data.getCmcInvoice()+"】<span style='color:red'>订单取消</span>" + "</div>";
String textHead = data.getCmcInvoice()+"【发票:"+ data.getCmcInvoice()+"】订单取消"; String textHead = data.getCmcInvoice()+"【发票:"+ data.getCmcInvoice()+"】订单取消";
String[] mailAddress = coDelMapper.queryUsersByRoleName("关务仓库").stream().map(SysUserEntity::getEmail).toArray(String[]::new); String[] mailAddress = coDelMapper.queryUsersByRoleName("关务仓库").stream().map(SysUserEntity::getEmail).toArray(String[]::new);
String[] mailAddress2 = 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 = "<!DOCTYPE>" + "<div>发货通知单" +data.getDelNo()+"【发票:"+ data.getCmcInvoice()+"】已下达" + "</div>";
String text = "<!DOCTYPE>" + "<div>发货通知单" +data.getDelNo()+"【发票:"+
data.getCmcInvoice()+"】<span style='color:red'>已下达</span>" + "</div>";
String textHead = "发货通知单"+data.getDelNo()+"【发票:"+ data.getCmcInvoice()+"】下达"; String textHead = "发货通知单"+data.getDelNo()+"【发票:"+ data.getCmcInvoice()+"】下达";
String[] mailAddress = coDelMapper.queryUsersByRoleName("关务仓库").stream().map(SysUserEntity::getEmail).toArray(String[]::new); String[] mailAddress = coDelMapper.queryUsersByRoleName("关务仓库").stream().map(SysUserEntity::getEmail).toArray(String[]::new);
if (mailAddress.length>0) { if (mailAddress.length>0) {
@ -1166,7 +1142,7 @@ public class CoDelServiceImpl implements CoDelService {
defaultData.setDelNo(inData.getDelNo()); defaultData.setDelNo(inData.getDelNo());
defaultData.setCreateBy(currentUser.getUsername()); defaultData.setCreateBy(currentUser.getUsername());
// 从视图获取客户信息 // 从视图获取客户信息
List<Map> customerInfo= coDelMapper.getCustomerInfo(getCoDelNotifyHeaderData.get(0).getCustomerName());
List<Map> customerInfo= coDelMapper.getCustomerInfo(getCoDelNotifyHeaderData.get(0).getCustomerName(),null);
if (!customerInfo.isEmpty()) { if (!customerInfo.isEmpty()) {
defaultData.setReceiveArea(customerInfo.get(0).get("cnative")!=null?customerInfo.get(0).get("cnative").toString():""); 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():""); 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<Map> getCustomerInfo(EcssDeclarationHeaderData data) { public List<Map> getCustomerInfo(EcssDeclarationHeaderData data) {
// 发货通知单 // 发货通知单
EcssCoDelNotifyHeaderData notifyHeader = coDelMapper.getEcssCoDelNotifyHeader(data.getSite(), data.getDelNo()); EcssCoDelNotifyHeaderData notifyHeader = coDelMapper.getEcssCoDelNotifyHeader(data.getSite(), data.getDelNo());
return coDelMapper.getCustomerInfo(notifyHeader.getCustomerName());
return coDelMapper.getCustomerInfo(notifyHeader.getCustomerName(),null);
} }
@Override @Override

9
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 select DISTINCT vcus.ccusname,vcusp.ccontactname,vcusp.cnative
from view_custdev_mes_cmc_customer vcus from view_custdev_mes_cmc_customer vcus
LEFT JOIN view_custdev_mes_cmc_customer_person vcusp on vcus.ccuscode=vcusp.ccuscode LEFT JOIN view_custdev_mes_cmc_customer_person vcusp on vcus.ccuscode=vcusp.ccuscode
where vcus.ccusname=#{ccusname}
<where>
<if test="ccusname != null and ccusname != ''">
and vcus.ccusname=#{ccusname}
</if>
<if test="ccuscode != null and ccuscode != ''">
and vcus.ccuscode=#{ccuscode}
</if>
</where>
</select> </select>
<select id="getCustomerAdd" resultType="java.util.Map"> <select id="getCustomerAdd" resultType="java.util.Map">

Loading…
Cancel
Save