lyhzzz 2 years ago
parent
commit
75e900ee71

+ 3 - 0
src/main/java/com/fdkankan/manage/service/IMailTemplateService.java

@@ -3,6 +3,8 @@ package com.fdkankan.manage.service;
 import com.fdkankan.manage.entity.MailTemplate;
 import com.fdkankan.manage.entity.MailTemplate;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.baomidou.mybatisplus.extension.service.IService;
 
 
+import java.io.File;
+
 /**
 /**
  * <p>
  * <p>
  *  服务类
  *  服务类
@@ -13,4 +15,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
  */
 public interface IMailTemplateService extends IService<MailTemplate> {
 public interface IMailTemplateService extends IService<MailTemplate> {
 
 
+    Boolean sendMail(String email, Integer emailTemplateId, String file);
 }
 }

+ 7 - 1
src/main/java/com/fdkankan/manage/service/impl/InvoiceServiceImpl.java

@@ -6,6 +6,7 @@ import com.fdkankan.common.constant.ErrorCode;
 import com.fdkankan.common.constant.InvoiceType;
 import com.fdkankan.common.constant.InvoiceType;
 import com.fdkankan.common.exception.BusinessException;
 import com.fdkankan.common.exception.BusinessException;
 import com.fdkankan.common.response.ResultData;
 import com.fdkankan.common.response.ResultData;
+import com.fdkankan.manage.service.IMailTemplateService;
 import com.fdkankan.manage.util.MangerUploadToOssUtil;
 import com.fdkankan.manage.util.MangerUploadToOssUtil;
 import com.fdkankan.manage.common.Dict;
 import com.fdkankan.manage.common.Dict;
 import com.fdkankan.manage.entity.Invoice;
 import com.fdkankan.manage.entity.Invoice;
@@ -45,7 +46,8 @@ public class InvoiceServiceImpl extends ServiceImpl<IInvoiceMapper, Invoice> imp
     private String invoicePrefix;
     private String invoicePrefix;
     @Value("${oss.prefix.url}")
     @Value("${oss.prefix.url}")
     private String ossPrefixUrl;
     private String ossPrefixUrl;
-
+    @Autowired
+    private IMailTemplateService mailTemplateService;
 
 
 
 
     @Autowired
     @Autowired
@@ -91,6 +93,10 @@ public class InvoiceServiceImpl extends ServiceImpl<IInvoiceMapper, Invoice> imp
             String ossFilePath = String.format(invoiceOssDir) + "/" + fileName;
             String ossFilePath = String.format(invoiceOssDir) + "/" + fileName;
             mangeUploadToOssUtil.upload(file.getBytes(), ossFilePath);
             mangeUploadToOssUtil.upload(file.getBytes(), ossFilePath);
             invoiceRegister.setInvoiceUrl(ossPrefixUrl + ossFilePath);
             invoiceRegister.setInvoiceUrl(ossPrefixUrl + ossFilePath);
+            Boolean mail = mailTemplateService.sendMail(invoice.getEmailAddress(), 2,invoiceRegister.getInvoiceUrl());
+            if(!mail){
+                throw new BusinessException(-1,"邮件发送失败");
+            }
         }else{//专用发票
         }else{//专用发票
             if(StrUtil.isEmpty(shipNum)){
             if(StrUtil.isEmpty(shipNum)){
                 throw new BusinessException(ErrorCode.FAILURE_CODE_9003);
                 throw new BusinessException(ErrorCode.FAILURE_CODE_9003);

+ 13 - 0
src/main/java/com/fdkankan/manage/service/impl/MailTemplateServiceImpl.java

@@ -1,11 +1,15 @@
 package com.fdkankan.manage.service.impl;
 package com.fdkankan.manage.service.impl;
 
 
+import com.fdkankan.common.exception.BusinessException;
 import com.fdkankan.manage.entity.MailTemplate;
 import com.fdkankan.manage.entity.MailTemplate;
 import com.fdkankan.manage.mapper.IMailTemplateMapper;
 import com.fdkankan.manage.mapper.IMailTemplateMapper;
 import com.fdkankan.manage.service.IMailTemplateService;
 import com.fdkankan.manage.service.IMailTemplateService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fdkankan.manage.util.SendMailUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
+import java.io.File;
+
 /**
 /**
  * <p>
  * <p>
  *  服务实现类
  *  服务实现类
@@ -17,4 +21,13 @@ import org.springframework.stereotype.Service;
 @Service
 @Service
 public class MailTemplateServiceImpl extends ServiceImpl<IMailTemplateMapper, MailTemplate> implements IMailTemplateService {
 public class MailTemplateServiceImpl extends ServiceImpl<IMailTemplateMapper, MailTemplate> implements IMailTemplateService {
 
 
+    @Override
+    public Boolean sendMail(String email , Integer emailTemplateId, String file) {
+        MailTemplate mailTemplate = this.getById(emailTemplateId);
+        if(mailTemplate == null){
+            throw new BusinessException(-1,"邮件发送模板不存在");
+        }
+       return SendMailUtils.sendMail(mailTemplate.getSendMail(), mailTemplate.getSendPassword(), mailTemplate.getSendHost(),
+               email, mailTemplate.getSubject(), mailTemplate.getMsg(), file);
+    }
 }
 }

+ 1 - 7
src/main/java/com/fdkankan/manage/service/impl/SceneApplyServiceImpl.java

@@ -62,13 +62,7 @@ public class SceneApplyServiceImpl extends ServiceImpl<ISceneApplyMapper, SceneA
         if(sceneApply == null){
         if(sceneApply == null){
             throw new BusinessException(-1,"场景申请不存在");
             throw new BusinessException(-1,"场景申请不存在");
         }
         }
-        MailTemplate mailTemplate = mailTemplateService.getById(emailTemplateId);
-        if(mailTemplate == null){
-            throw new BusinessException(-1,"邮件发送模板不存在");
-        }
-        boolean flag = SendMailUtils.sendMail(mailTemplate.getSendMail(), mailTemplate.getSendPassword(), mailTemplate.getSendHost(),
-                sceneApply.getEmail(), mailTemplate.getSubject(), mailTemplate.getMsg(), null);
-
+        Boolean flag = mailTemplateService.sendMail(sceneApply.getEmail(), emailTemplateId,null);
         if(flag){
         if(flag){
             sceneApply.setState(1);
             sceneApply.setState(1);
         }else {
         }else {