新增邮件发送接口

This commit is contained in:
2024-07-10 10:54:05 +08:00
parent 715b1d4626
commit 74889d0d4b
4 changed files with 44 additions and 0 deletions
@@ -15,6 +15,7 @@ import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.BatchParam;
import com.gxwebsoft.common.core.annotation.OperationLog;
import com.gxwebsoft.common.system.entity.User;
import com.gxwebsoft.common.system.service.EmailRecordService;
import com.gxwebsoft.shop.entity.Order;
import com.gxwebsoft.shop.service.OrderService;
import io.swagger.annotations.Api;
@@ -22,10 +23,15 @@ import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import nuonuo.open.sdk.NNOpenSDK;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.HashMap;
@@ -46,6 +52,8 @@ public class UserInvoiceController extends BaseController {
private UserInvoiceService userInvoiceService;
@Resource
private OrderService orderService;
@Resource
private EmailRecordService emailRecordService;
@ApiOperation("分页查询发票")
@GetMapping("/page")
@@ -197,6 +205,8 @@ public class UserInvoiceController extends BaseController {
orderInfo.setInvoiceNo(invoiceSerialNum);
System.out.println("invoiceSerialNum = " + invoiceSerialNum);
orderService.updateById(orderInfo);
invoice.setInvoiceNo(invoiceSerialNum);
userInvoiceService.updateById(invoice);
return success("发票开具成功", json);
}
}
@@ -230,6 +240,16 @@ public class UserInvoiceController extends BaseController {
return success("查询成功", result);
}
// @ApiOperation("发送到邮箱")
// @GetMapping("/showInvoice/send/{pdfUrl}")
// public ApiResult<?> sendInvoice(@PathVariable("pdfUrl") String pdfUrl) {
// // 发送邮件通知
// String title = "发票凭证";
// // 发送邮件通知
// emailRecordService.sendEmail(title, pdfUrl, "ip170@163.com");
//
// }
// @ApiOperation("开具发票")
// @GetMapping("/doInvoice/{id}")
// public ApiResult<?> doInvoice(@PathVariable("id") Integer id) {
@@ -61,6 +61,15 @@ public class UserInvoice implements Serializable {
@ApiModelProperty(value = "电子邮箱")
private String email;
@ApiModelProperty(value = "发票流水号")
private String invoiceNo;
@ApiModelProperty(value = "发票预览图片")
private String invoiceImg;
@ApiModelProperty(value = "发票pdf地址")
private String invoicePdf;
@ApiModelProperty(value = "备注")
private String comments;
@@ -47,4 +47,5 @@ public interface EmailRecordService extends IService<EmailRecord> {
void sendHtmlEmail(String title, String path, Map<String, Object> map, String[] toEmails)
throws MessagingException, IOException;
void sendEmail(String title, String content, String receiver);
}
@@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@@ -69,4 +70,17 @@ public class EmailRecordServiceImpl extends ServiceImpl<EmailRecordMapper, Email
sendFullTextEmail(title, html, toEmails); // 发送邮件
}
@Async
@Override
public void sendEmail(String title, String content, String receiver) {
// 发送邮件通知
EmailRecord emailRecord = new EmailRecord();
emailRecord.setTitle(title);
emailRecord.setContent(content);
emailRecord.setReceiver(receiver);
emailRecord.setCreateUserId(42);
sendTextEmail(title,content,receiver.split(","));
save(emailRecord);
}
}