|
@@ -1,18 +1,22 @@
|
|
|
package com.fdkankan.sale.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.fdkankan.sale.common.PageInfo;
|
|
|
+import com.fdkankan.sale.common.ResultCode;
|
|
|
+import com.fdkankan.sale.entity.MailTemplate;
|
|
|
import com.fdkankan.sale.entity.RepairInvoice;
|
|
|
+import com.fdkankan.sale.exception.BusinessException;
|
|
|
import com.fdkankan.sale.mapper.IRepairInvoiceMapper;
|
|
|
+import com.fdkankan.sale.service.IMailTemplateService;
|
|
|
import com.fdkankan.sale.service.IRepairInvoiceService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fdkankan.sale.vo.request.RepairInvoiceParam;
|
|
|
import com.fdkankan.sale.vo.response.RepairInvoiceVo;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
/**
|
|
|
* <p>
|
|
|
* 服务实现类
|
|
@@ -24,6 +28,10 @@ import java.util.List;
|
|
|
@Service
|
|
|
public class RepairInvoiceServiceImpl extends ServiceImpl<IRepairInvoiceMapper, RepairInvoice> implements IRepairInvoiceService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ IMailTemplateService mailTemplateService;
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public RepairInvoice getByRepairId(String repairId) {
|
|
|
LambdaQueryWrapper<RepairInvoice> wrapper = new LambdaQueryWrapper<>();
|
|
@@ -32,8 +40,77 @@ public class RepairInvoiceServiceImpl extends ServiceImpl<IRepairInvoiceMapper,
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Object pageList(RepairInvoiceParam param) {
|
|
|
+ public Page<RepairInvoiceVo> pageList(RepairInvoiceParam param) {
|
|
|
Page<RepairInvoiceVo> voList = this.getBaseMapper().pageList(new Page<>(param.getPageNum(),param.getPageSize()),param);
|
|
|
- return PageInfo.PageInfo(voList);
|
|
|
+ return voList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void open(RepairInvoice param, Long userId) {
|
|
|
+ if(param.getInvoiceId() == null ){
|
|
|
+ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
+ }
|
|
|
+ RepairInvoice repairInvoice = this.getById(param.getInvoiceId());
|
|
|
+ if(repairInvoice == null ){
|
|
|
+ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
+ }
|
|
|
+ if(repairInvoice.getStatus() == 1){
|
|
|
+ throw new BusinessException(ResultCode.ORDER_INVOICE_OPEN);
|
|
|
+ }
|
|
|
+ if(repairInvoice.getInvoiceType() == 0){ //普通发票邮件发送,专用发票邮寄
|
|
|
+ if(StringUtils.isBlank(param.getInvoiceNo()) || StringUtils.isBlank(param.getEInvoiceImg())){
|
|
|
+ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
+ }
|
|
|
+ LambdaUpdateWrapper<RepairInvoice> wrapper = new LambdaUpdateWrapper<>();
|
|
|
+ wrapper.eq(RepairInvoice::getInvoiceId,param.getInvoiceId());
|
|
|
+ wrapper.set(RepairInvoice::getInvoiceNo,param.getInvoiceNo());
|
|
|
+ wrapper.set(RepairInvoice::getEInvoiceImg,param.getEInvoiceImg());
|
|
|
+ wrapper.set(RepairInvoice::getStatus,1);
|
|
|
+ wrapper.set(RepairInvoice::getSysUserId,userId);
|
|
|
+ this.update(wrapper);
|
|
|
+
|
|
|
+ MailTemplate mailTemplate = this.setMailMsg(repairInvoice.getRepairId(),repairInvoice.getInvoiceEmail());
|
|
|
+ Boolean mail = mailTemplateService.sendMail(repairInvoice.getInvoiceEmail(), mailTemplate,param.getEInvoiceImg());
|
|
|
+ if(!mail){
|
|
|
+ throw new BusinessException(ResultCode.MAIL_SEND_ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if(repairInvoice.getInvoiceType() == 1){ //普通发票邮件发送,专用发票邮寄
|
|
|
+ if(StringUtils.isBlank(param.getInvoiceNo()) || StringUtils.isBlank(param.getTrackingNum())){
|
|
|
+ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
+ }
|
|
|
+ LambdaUpdateWrapper<RepairInvoice> wrapper = new LambdaUpdateWrapper<>();
|
|
|
+ wrapper.eq(RepairInvoice::getInvoiceId,param.getInvoiceId());
|
|
|
+ wrapper.set(RepairInvoice::getTrackingNum,param.getTrackingNum());
|
|
|
+ wrapper.set(RepairInvoice::getInvoiceNo,param.getInvoiceNo());
|
|
|
+ wrapper.set(RepairInvoice::getStatus,1);
|
|
|
+ wrapper.set(RepairInvoice::getSysUserId,userId);
|
|
|
+ this.update(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private MailTemplate setMailMsg(String orderNum, String userName) {
|
|
|
+ MailTemplate mailTemplate = mailTemplateService.getById(1);
|
|
|
+ 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;
|
|
|
}
|
|
|
}
|