|
@@ -6,22 +6,24 @@ import com.fdkankan.common.constant.ErrorCode;
|
|
|
import com.fdkankan.common.constant.InvoiceType;
|
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
|
import com.fdkankan.common.response.ResultData;
|
|
|
-import com.fdkankan.manage.service.IMailTemplateService;
|
|
|
+import com.fdkankan.manage.common.OssPath;
|
|
|
+import com.fdkankan.manage.entity.*;
|
|
|
+import com.fdkankan.manage.service.*;
|
|
|
import com.fdkankan.manage.util.MangerUploadToOssUtil;
|
|
|
import com.fdkankan.manage.common.Dict;
|
|
|
-import com.fdkankan.manage.entity.Invoice;
|
|
|
-import com.fdkankan.manage.entity.InvoiceRegister;
|
|
|
import com.fdkankan.manage.mapper.IInvoiceMapper;
|
|
|
-import com.fdkankan.manage.service.IInvoiceRegisterService;
|
|
|
-import com.fdkankan.manage.service.IInvoiceService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fdkankan.manage.vo.InvoicePageParamVO;
|
|
|
import com.fdkankan.manage.vo.InvoiceRegisterDetailVO;
|
|
|
import com.fdkankan.manage.vo.InvoiceVO;
|
|
|
|
|
|
+import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.util.Date;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.UUID;
|
|
|
+
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
|
@@ -40,15 +42,15 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
@Service
|
|
|
public class InvoiceServiceImpl extends ServiceImpl<IInvoiceMapper, Invoice> implements IInvoiceService {
|
|
|
|
|
|
- @Value("${oss.dir.invoice}")
|
|
|
- private String invoiceOssDir;
|
|
|
- @Value("${invoice.prefix}")
|
|
|
- private String invoicePrefix;
|
|
|
@Value("${oss.prefix.url}")
|
|
|
private String ossPrefixUrl;
|
|
|
+
|
|
|
@Autowired
|
|
|
private IMailTemplateService mailTemplateService;
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private IOrderService orderService;
|
|
|
+ @Autowired
|
|
|
+ private IUserService userService;
|
|
|
|
|
|
@Autowired
|
|
|
private IInvoiceRegisterService invoiceRegisterService;
|
|
@@ -89,11 +91,23 @@ public class InvoiceServiceImpl extends ServiceImpl<IInvoiceMapper, Invoice> imp
|
|
|
if(Objects.isNull(file) || file.isEmpty()){
|
|
|
throw new BusinessException(ErrorCode.FAILURE_CODE_5048);
|
|
|
}
|
|
|
- String fileName = invoicePrefix + invoice.getId() + ".jpg";
|
|
|
- String ossFilePath = String.format(invoiceOssDir) + "/" + fileName;
|
|
|
- mangeUploadToOssUtil.upload(file.getBytes(), ossFilePath);
|
|
|
+ String fileName = file.getOriginalFilename();
|
|
|
+ String suffixName = fileName.substring(fileName.lastIndexOf("."));
|
|
|
+ fileName = UUID.randomUUID().toString().replace("-","");
|
|
|
+ File localFile = File.createTempFile(fileName,suffixName);
|
|
|
+ file.transferTo(localFile);
|
|
|
+ String ossFilePath = OssPath.invoiceOssDir + fileName + suffixName;
|
|
|
+ mangeUploadToOssUtil.upload(localFile.getPath(),ossFilePath);
|
|
|
invoiceRegister.setInvoiceUrl(ossPrefixUrl + ossFilePath);
|
|
|
- Boolean mail = mailTemplateService.sendMail(invoice.getEmailAddress(), 2,invoiceRegister.getInvoiceUrl());
|
|
|
+
|
|
|
+ Order order = orderService.getById(invoice.getOrderId());
|
|
|
+ String orderNum = order == null ? null : order.getOrderSn();
|
|
|
+ User user = userService.getById(invoice.getUserId());
|
|
|
+ String userName = user == null ? null : user.getNickName();
|
|
|
+
|
|
|
+ MailTemplate mailTemplate = this.setMailMsg(orderNum,userName);
|
|
|
+
|
|
|
+ Boolean mail = mailTemplateService.sendMail(invoice.getEmailAddress(), mailTemplate,localFile.getPath());
|
|
|
if(!mail){
|
|
|
throw new BusinessException(-1,"邮件发送失败");
|
|
|
}
|
|
@@ -111,6 +125,28 @@ public class InvoiceServiceImpl extends ServiceImpl<IInvoiceMapper, Invoice> imp
|
|
|
return ResultData.ok();
|
|
|
}
|
|
|
|
|
|
+ private MailTemplate setMailMsg(String orderNum,String userName) {
|
|
|
+ MailTemplate mailTemplate = mailTemplateService.getById(2);
|
|
|
+ if(mailTemplate != null){
|
|
|
+ String subject = mailTemplate.getSubject();
|
|
|
+ if(StringUtils.isNotBlank(orderNum)){
|
|
|
+ subject = subject.replace("${ordernum}",orderNum);
|
|
|
+ }
|
|
|
+ mailTemplate.setSubject(subject);
|
|
|
+
|
|
|
+ String msg = mailTemplate.getMsg();
|
|
|
+ if(StringUtils.isNotBlank(orderNum)){
|
|
|
+ msg = msg.replace("${ordernum}",orderNum);
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(userName)){
|
|
|
+ msg = msg.replace("${username}",userName);
|
|
|
+ }
|
|
|
+ mailTemplate.setMsg(msg);
|
|
|
+
|
|
|
+ }
|
|
|
+ return mailTemplate;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public ResultData getInvoiceRegisterDetail(Long id) {
|
|
|
|