Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/java/QianYunTong
| | |
| | | import java.io.Serializable; |
| | | import java.lang.reflect.InvocationTargetException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | List<TripOrderVo> tripOrderVos = processTripOrderVos(orderList); |
| | | String filePath = tripSheetGenerator.generatePdf(tripOrderVos); |
| | | File attachment = new File(filePath); |
| | | emailUtil.sendEmailWithAttachment(tripSheet.getRecipientEmail(), "行程单", "请查收您的行程单", attachment); |
| | | String displayFileName = "贵人家园行程单.pdf"; |
| | | emailUtil.sendEmailWithAttachment(tripSheet.getRecipientEmail(), "行程单", "请查收您的行程单", attachment,displayFileName); |
| | | attachment.delete(); // 发送成功后删除临时文件 |
| | | return ResultUtil.success("邮件发送成功"); |
| | | Map<String, Object> result = new HashMap<>(); |
| | | result.put("orderNum", orderList.size()); |
| | | return ResultUtil.success(result); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return ResultUtil.error("邮件发送失败"); |
| | | return ResultUtil.error("邮件发送失败"+e.getMessage()); |
| | | } |
| | | } |
| | | /** |
| | |
| | | throw new IllegalArgumentException("订单列表不能为空"); |
| | | } |
| | | |
| | | String fileName = "行程单_" + UUID.randomUUID() + ".pdf"; |
| | | String fileName = "贵人家园行程单_" + UUID.randomUUID() + ".pdf"; |
| | | String filePath = pdfDir + fileName; |
| | | File file = new File(filePath); |
| | | FileUtils.forceMkdirParent(file); |
| | |
| | | table.addCell(cell); |
| | | } |
| | | |
| | | private void addTableCell(PdfPTable table, String text, Font font) { |
| | | PdfPCell cell = new PdfPCell(new Paragraph(text != null ? text : "", font)); |
| | | cell.setPadding(5); |
| | | table.addCell(cell); |
| | | } |
| | | |
| | | /** |
| | | * 获取中文字体,优先自定义字体,fallback到 CJK 内置 |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import javax.mail.MessagingException; |
| | | import javax.mail.internet.MimeMessage; |
| | | import javax.mail.internet.MimeUtility; |
| | | import java.io.File; |
| | | import java.io.UnsupportedEncodingException; |
| | | |
| | | @Component |
| | | public class EmailUtil { |
| | |
| | | this.javaMailSender = javaMailSender; |
| | | } |
| | | |
| | | public void sendEmailWithAttachment(String to, String subject, String text, File attachment) throws MessagingException { |
| | | public void sendEmailWithAttachment(String to, String subject, String text, File attachment,String displayFileName) throws MessagingException, UnsupportedEncodingException { |
| | | MimeMessage message = javaMailSender.createMimeMessage(); |
| | | MimeMessageHelper helper = new MimeMessageHelper(message, true); |
| | | |
| | |
| | | // 设置邮件主题和内容 |
| | | helper.setSubject(subject); |
| | | helper.setText(text); |
| | | // 添加附件 |
| | | helper.addAttachment(attachment.getName(), attachment); |
| | | // 使用显示文件名而非原文件名 |
| | | helper.addAttachment( |
| | | MimeUtility.encodeWord(displayFileName), // 编码避免中文乱码 |
| | | attachment |
| | | ); |
| | | |
| | | |
| | | // 发送邮件 |
| | | javaMailSender.send(message); |