/invoiceToUser接口完成部分失败逻辑

This commit is contained in:
wen 2021-12-23 13:42:54 +08:00
parent f0d93937f6
commit 07a23d1d27
6 changed files with 93 additions and 12 deletions

View File

@ -0,0 +1,30 @@
package com.xhpc.invoice.constPackage;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 发票状态常量类
*
* @author WH
* @date 2021/12/23 11:49
* @since version-1.0
*/
@Data
@NoArgsConstructor
public class InvoiceStatusConst {
/**
* 正在等待开票即待处理
*/
public static final Integer INVOICING = 0;
/**
* 开票成功
*/
public static final Integer SUCCESS = 1;
/**
* 开票失败
*/
public static final Integer FAIL = 2;
}

View File

@ -2,6 +2,7 @@ package com.xhpc.invoice.controller;
import com.xhpc.common.core.web.controller.BaseController; import com.xhpc.common.core.web.controller.BaseController;
import com.xhpc.common.core.web.domain.AjaxResult; import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.invoice.constPackage.InvoiceStatusConst;
import com.xhpc.invoice.domain.AllInvoiceOrdersRequest; import com.xhpc.invoice.domain.AllInvoiceOrdersRequest;
import com.xhpc.invoice.domain.AllInvoiceOrdersResponse; import com.xhpc.invoice.domain.AllInvoiceOrdersResponse;
import com.xhpc.invoice.domain.InvoiceToUserRequest; import com.xhpc.invoice.domain.InvoiceToUserRequest;
@ -31,6 +32,7 @@ public class XhpcInvoiceController extends BaseController {
/** /**
* 给指定用户开发票开票完成之后将开出的电子发票发送至用户的接收邮箱 * 给指定用户开发票开票完成之后将开出的电子发票发送至用户的接收邮箱
* 如果失败则标记发票为失败发票
* *
* @author WH * @author WH
* @date 2021/12/22 12:03 * @date 2021/12/22 12:03
@ -42,17 +44,23 @@ public class XhpcInvoiceController extends BaseController {
if (requestData.getInvoiceId() == null) { if (requestData.getInvoiceId() == null) {
AjaxResult.error("必须传递未开发票id"); AjaxResult.error("必须传递未开发票id");
} }
if (requestData.getStatus() == null) { if (requestData.getStatus() == null || requestData.getStatus().equals(InvoiceStatusConst.INVOICING)) {
AjaxResult.error("必须传递发票状态"); AjaxResult.error("必须传递发票状态或发票不能为0");
} }
//捕获参数异常 //开失败发票
try { if (requestData.getStatus().equals(InvoiceStatusConst.FAIL)) {
Boolean flagOfjudge = xhpcInvoiceService.invoiceToUser(requestData); Boolean flagOfjudge = xhpcInvoiceService.failInvoiceToUser(requestData);
if (!flagOfjudge) { } else {
AjaxResult.error("客户邮箱有误,邮件未发送成功,请通知用户修改邮箱"); //开成功发票
try {
//捕获参数异常
Boolean flagOfjudge = xhpcInvoiceService.invoiceToUser(requestData);
if (!flagOfjudge) {
AjaxResult.error("客户邮箱有误,邮件未发送成功,请通知用户修改邮箱");
}
} catch (Exception e) {
return AjaxResult.error(e.getMessage());
} }
} catch (Exception e) {
return AjaxResult.error(e.getMessage());
} }
return AjaxResult.success(); return AjaxResult.success();
} }

View File

@ -83,4 +83,13 @@ public interface XhpcInvoiceMapper {
*/ */
Long invoiceToUser(InvoiceToUserRequest requestData); Long invoiceToUser(InvoiceToUserRequest requestData);
/**
* 更新指定发票状态让其成为开发票失败状态
*
* @author WH
* @date 2021/12/23 13:30
* @since version-1.0
*/
Long failInvoiceToUser(InvoiceToUserRequest requestData);
} }

View File

@ -47,4 +47,17 @@ public interface XhpcInvoiceService {
*/ */
Boolean invoiceToUser(InvoiceToUserRequest requestData); Boolean invoiceToUser(InvoiceToUserRequest requestData);
/**
* 存储发票开失败的状态将该发票所包含的订单释放
* 即将其所包含的历史订单的del_flag设置为1表明已经被删除
* 然后将其发票状态设置为取消开票状态
*
* @param requestData 开票失败所传递的参数
* @return 是否执行成功
* @author WH
* @date 2021/12/23 12:48
* @since version-1.0
*/
Boolean failInvoiceToUser(InvoiceToUserRequest requestData);
} }

View File

@ -106,12 +106,14 @@ public class XhpcInvoiceServiceImpl implements XhpcInvoiceService {
//根据操作人的id查询操作人的名字 //根据操作人的id查询操作人的名字
SysUser sysUser = sysUserMapper.selectUserById(Long.valueOf(requestData.getDrawer())); SysUser sysUser = sysUserMapper.selectUserById(Long.valueOf(requestData.getDrawer()));
requestData.setDrawer(sysUser.getNickName()); requestData.setDrawer(sysUser.getNickName());
//发送电子pdf到接收者邮箱 //发送电子发票pdf到接收者邮箱
XhpcInvoice xhpcInvoice = xhpcInvoiceMapper.selectByPrimaryKey(requestData.getInvoiceId()); XhpcInvoice xhpcInvoice = xhpcInvoiceMapper.selectByPrimaryKey(requestData.getInvoiceId());
String receiveEmail = xhpcInvoice.getReceiveEmail(); String receiveEmail = xhpcInvoice.getReceiveEmail();
File eletricInvoiceFile = new File("D:\\Enterprise_Resources\\ElectricInvoice\\ElectricInvoice.pdf"); File eletricInvoiceFile = new File("D:\\Enterprise_Resources\\ElectricInvoice\\ElectricInvoice.pdf");
String sendEmailInfo = MailUtil.send(receiveEmail, "测试", "邮件来自Hutool测试", false, eletricInvoiceFile); try {
if (sendEmailInfo == null) { MailUtil.send(receiveEmail, "【小华充电】电子发票", "邮件来自小华充电", false, eletricInvoiceFile);
} catch (Exception e) {
System.out.println(e.getMessage());
return Boolean.FALSE; return Boolean.FALSE;
} }
//更新发票数据 //更新发票数据
@ -122,6 +124,15 @@ public class XhpcInvoiceServiceImpl implements XhpcInvoiceService {
return Boolean.TRUE; return Boolean.TRUE;
} }
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean failInvoiceToUser(InvoiceToUserRequest requestData) {
//todo
//最后入库更新
xhpcInvoiceMapper.failInvoiceToUser(requestData);
return null;
}
/** /**
* 通过发票id查找对应的发票数据 * 通过发票id查找对应的发票数据
* *

View File

@ -439,4 +439,14 @@
WHERE invoice_id = #{invoiceId}; WHERE invoice_id = #{invoiceId};
</update> </update>
<update id="failInvoiceToUser">
UPDATE xhpc_invoice
SET finance_notes = #{financeNotes},
invoicing_time = #{invoicingTime},
electric_invoice_url = #{eletricInvoiceUrl},
`status` = #{status},
drawer = #{drawer}
WHERE invoice_id = #{invoiceId}
</update>
</mapper> </mapper>