lyhzzz 6 gün önce
ebeveyn
işleme
2646e98266

+ 19 - 9
src/main/java/com/fdkankan/ucenter/service/impl/InvoiceServiceImpl.java

@@ -16,6 +16,7 @@ import com.fdkankan.ucenter.common.OssPath;
 import com.fdkankan.ucenter.common.PageInfo;
 import com.fdkankan.ucenter.common.RandomCodeUtil;
 import com.fdkankan.ucenter.common.constants.NacosProperty;
+import com.fdkankan.ucenter.config.ThreadPoolConfig;
 import com.fdkankan.ucenter.entity.*;
 import com.fdkankan.ucenter.mapper.IInvoiceMapper;
 import com.fdkankan.ucenter.service.*;
@@ -25,6 +26,7 @@ import com.fdkankan.ucenter.vo.request.InvoiceParam;
 import com.fdkankan.ucenter.vo.request.PlaceOrderParam;
 import com.fdkankan.ucenter.vo.response.OrderVo;
 import com.sun.xml.bind.v2.model.core.ID;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.aspectj.weaver.ast.Or;
 import org.springframework.beans.BeanUtils;
@@ -47,6 +49,7 @@ import java.util.Set;
  * @since 2022-07-13
  */
 @Service
+@Slf4j
 public class InvoiceServiceImpl extends ServiceImpl<IInvoiceMapper, Invoice> implements IInvoiceService {
 
     @Autowired
@@ -248,17 +251,24 @@ public class InvoiceServiceImpl extends ServiceImpl<IInvoiceMapper, Invoice> imp
         return dbEntity;
     }
 
+    @Autowired
+    ThreadPoolConfig threadPoolConfig;
+
     private void sendEmail(Invoice dbEntity) {
         //国际服直接发送邮件
-        if("aws".equals(NacosProperty.uploadType)  && dbEntity.getEmailAddress() != null){
-            MailTemplate mailTemplate = mailTemplateService.getTemplate(14, "en");
-            dbEntity.setCreateTime(DateUtil.format(new Date(),"yyyy-MM-dd HH:mm:ss"));
-            String filePath = MyExcelUtil.excelTemplteToPdf(OssPath.localPath +"/invoice", "invoiceTemplate", dbEntity);
-            mailTemplateService.sendMail(dbEntity.getEmailAddress(),mailTemplate,filePath);
-            FileUtil.delFile(filePath);
-            FileUtil.delFile(filePath+".sy");
-            FileUtil.delFile(filePath.replace(".pdf",".xlsx"));
-        }
+        threadPoolConfig.taskExecutor().execute(() -> {
+            log.info("异步任务执行,当前线程:" + Thread.currentThread().getName());
+            if("aws".equals(NacosProperty.uploadType)  && dbEntity.getEmailAddress() != null){
+                MailTemplate mailTemplate = mailTemplateService.getTemplate(14, "en");
+                dbEntity.setCreateTime(DateUtil.format(new Date(),"yyyy-MM-dd HH:mm:ss"));
+                String filePath = MyExcelUtil.excelTemplteToPdf(OssPath.localPath +"/invoice", "invoiceTemplate", dbEntity);
+                mailTemplateService.sendMail(dbEntity.getEmailAddress(),mailTemplate,filePath);
+                FileUtil.delFile(filePath);
+                FileUtil.delFile(filePath+".sy");
+                FileUtil.delFile(filePath.replace(".pdf",".xlsx"));
+            }
+        });
+
     }
 
     private String updateInvoiceNumber(Long id) {