From bb6385a2c8069b81f62a7d3de5b6cef988243ad8 Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期五, 20 九月 2024 13:42:22 +0800
Subject: [PATCH] 对接邮箱 受理开票后发送
---
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/TAppCouponServiceImpl.java | 10 +++
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TOrderInvoiceController.java | 106 ++++++++++++++++++++++++++++++++++-
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TAdvertisingServiceImpl.java | 5 +
ruoyi-service/ruoyi-order/pom.xml | 11 +++
4 files changed, 128 insertions(+), 4 deletions(-)
diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/TAppCouponServiceImpl.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/TAppCouponServiceImpl.java
index 8c230d6..0d25253 100644
--- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/TAppCouponServiceImpl.java
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/TAppCouponServiceImpl.java
@@ -42,6 +42,7 @@
import java.util.Comparator;
import java.util.Date;
import java.util.List;
+import java.util.stream.Collectors;
/**
* <p>
@@ -76,10 +77,19 @@
List<Integer> integers = new ArrayList<>();
integers.add(1);
integers.add(2);
+
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
QueryWrapper<TAppCoupon> wrapper = new QueryWrapper<>();
wrapper.eq("coupon_id",dto.getCouponId());
wrapper.in("ways_to_obtain",integers);
+ if (StringUtils.hasLength(dto.getPhone())){
+ List<Long> collect = tAppUserMapper.selectList(new QueryWrapper<TAppUser>().like("phone", dto.getPhone())).stream()
+ .map(TAppUser::getId).collect(Collectors.toList());
+ if(collect.isEmpty()){
+ collect.add(-1L);
+ }
+ wrapper.in("id",collect);
+ }
if (dto.getStatus()!=null){
wrapper.eq("status",dto.getStatus());
}
diff --git a/ruoyi-service/ruoyi-order/pom.xml b/ruoyi-service/ruoyi-order/pom.xml
index f5641e4..c0c8fee 100644
--- a/ruoyi-service/ruoyi-order/pom.xml
+++ b/ruoyi-service/ruoyi-order/pom.xml
@@ -15,6 +15,17 @@
</description>
<dependencies>
+ <!--网易邮件-->
+ <dependency>
+ <groupId>javax.mail</groupId>
+ <artifactId>javax.mail-api</artifactId>
+ <version>1.6.2</version>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.mail</groupId>
+ <artifactId>jakarta.mail</artifactId>
+ <version>1.6.5</version>
+ </dependency>
<!-- ruoyi-modules-other-api -->
<dependency>
<groupId>com.ruoyi</groupId>
diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TOrderInvoiceController.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TOrderInvoiceController.java
index 1b2dfc4..5132faf 100644
--- a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TOrderInvoiceController.java
+++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TOrderInvoiceController.java
@@ -20,18 +20,22 @@
import com.ruoyi.order.service.TOrderInvoiceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
+import org.apache.commons.compress.utils.IOUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
+import javax.activation.DataHandler;
+import javax.activation.FileDataSource;
import javax.annotation.Resource;
+import javax.mail.*;
+import javax.mail.internet.*;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
+import java.io.*;
+import java.net.URL;
import java.net.URLEncoder;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
/**
* <p>
@@ -72,6 +76,100 @@
TOrderInvoice orderInvoice = orderInvoiceService.getById(id);
orderInvoice.setInvoiceUrl(invoiceUrl);
orderInvoiceService.updateById(orderInvoice);
+ // 发送邮箱
+ // 收件人电子邮箱,TODO 换成自己的收件箱
+ String to = orderInvoice.getMailbox();
+ // 发件人电子邮箱,TODO 换成自己的发件箱
+ String from = "13281306557@163.com";
+ // 指定发送邮件的主机为
+ String host = "smtp.163.com";
+ // 获取系统属性
+ Properties properties = new Properties();
+ // 设置邮件服务器
+ properties.setProperty("mail.smtp.host", host);
+ // 邮件发送协议
+ properties.setProperty("mail.transport.protocol", "smtp");
+ //是否启用调试模式(启用调试模式可打印客户端与服务器交互过程时一问一答的响应消息)
+ properties.setProperty("mail.debug","true");
+ properties.setProperty("mail.smtp.auth", "true");
+ // 获取默认session对象
+ Session session = Session.getDefaultInstance(properties,new Authenticator(){
+ @Override
+ public PasswordAuthentication getPasswordAuthentication()
+ {
+ //发件人邮件用户名、授权码,换成自己的发件箱及授权码
+ return new PasswordAuthentication("13281306557@163.com", "NUSdxDQqadYvVek2");
+ }
+ });
+
+ try{
+ // 创建默认的 MimeMessage 对象
+ MimeMessage message = new MimeMessage(session);
+ // Set From,设置发件人
+ InternetAddress fromMail = new InternetAddress(from);
+ //设置发件人名称,TODO 换成自己的发件箱
+ fromMail.setPersonal(MimeUtility.encodeText("明星电力<13281306557@163.com>"));
+ message.setFrom(fromMail);
+ // Set To: 设置收件人
+ InternetAddress toMail = new InternetAddress(to);
+ // TODO 换成自己的收件箱
+ InternetAddress toMail2 = new InternetAddress(to);
+ //发多个邮箱
+ Address[] allRecipients = {toMail, toMail2};
+ message.setRecipients(Message.RecipientType.TO, allRecipients);
+ // Set Subject: 邮件主体
+ message.setSubject("明星电力");
+ // 设置消息体
+ message.setSentDate(new Date());
+ // 指定为混合关系
+ MimeMultipart msgMultipart = new MimeMultipart("mixed");
+ message.setContent(msgMultipart);
+ // 邮件信息组装
+ //组装的顺序非常重要,一定要先组装文本域,再组装文件
+ MimeBodyPart htmlPart = new MimeBodyPart();
+ // 组装内容
+ htmlPart.setContent("This is message content", "text/html;charset=UTF-8");
+ msgMultipart.addBodyPart(htmlPart);
+
+ // 组装附件
+ MimeBodyPart filePart = new MimeBodyPart();
+ String imageUrl = invoiceUrl;
+ try {
+ // 下载数据
+ URL url = new URL(imageUrl);
+ InputStream inputStream = url.openStream();
+ byte[] imageBytes = IOUtils.toByteArray(inputStream);
+
+ // 创建临时文件
+ File tempFile = File.createTempFile("tempImage", ".png");
+ try (FileOutputStream fos = new FileOutputStream(tempFile)) {
+ fos.write(imageBytes);
+ }
+
+ // 创建 FileDataSource
+ FileDataSource fileDataSource = new FileDataSource(tempFile);
+ System.out.println("FileDataSource created: " + fileDataSource.getName());
+ // 如果需要,可以使用 DataHandler 进行进一步处理
+ DataHandler dh = new DataHandler(fileDataSource);
+ // 清理:删除临时文件(如果不再需要)
+ tempFile.deleteOnExit(); // 可根据需要保留或删除
+ filePart.setDataHandler(dh);
+ // 附件区别内嵌内容的一个特点是有文件名,为防止中文乱码要编码
+ filePart.setFileName(MimeUtility.encodeText(dh.getName()));
+ msgMultipart.addBodyPart(filePart);
+ message.saveChanges();
+ //发送
+ //Transport.send(message, message.getAllRecipients());
+ Transport.send(message);
+ System.out.println("发送成功");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }catch (MessagingException | UnsupportedEncodingException mex) {
+ mex.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
return AjaxResult.success();
}
diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TAdvertisingServiceImpl.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TAdvertisingServiceImpl.java
index eb228f2..e9f2e51 100644
--- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TAdvertisingServiceImpl.java
+++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TAdvertisingServiceImpl.java
@@ -37,6 +37,11 @@
} else {
tAdvertising.setStartState(2);
}
+ if (tAdvertising.getStatus() == 0 ){
+ // 未上架
+ tAdvertising.setStartState(3);
+
+ }
}
pageInfo.setRecords(list);
return pageInfo;
--
Gitblit v1.7.1