diff --git a/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/constPackage/InvoiceStatusConst.java b/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/constPackage/InvoiceStatusConst.java new file mode 100644 index 00000000..8615d4af --- /dev/null +++ b/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/constPackage/InvoiceStatusConst.java @@ -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; + +} diff --git a/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/controller/XhpcInvoiceController.java b/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/controller/XhpcInvoiceController.java index b811ec51..767acff2 100644 --- a/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/controller/XhpcInvoiceController.java +++ b/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/controller/XhpcInvoiceController.java @@ -2,6 +2,7 @@ package com.xhpc.invoice.controller; import com.xhpc.common.core.web.controller.BaseController; 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.AllInvoiceOrdersResponse; import com.xhpc.invoice.domain.InvoiceToUserRequest; @@ -31,6 +32,7 @@ public class XhpcInvoiceController extends BaseController { /** * 给指定用户开发票,开票完成之后将开出的电子发票发送至用户的接收邮箱 + * 如果失败,则标记发票为失败发票 * * @author WH * @date 2021/12/22 12:03 @@ -42,17 +44,23 @@ public class XhpcInvoiceController extends BaseController { if (requestData.getInvoiceId() == null) { AjaxResult.error("必须传递未开发票id"); } - if (requestData.getStatus() == null) { - AjaxResult.error("必须传递发票状态"); + if (requestData.getStatus() == null || requestData.getStatus().equals(InvoiceStatusConst.INVOICING)) { + AjaxResult.error("必须传递发票状态或发票不能为0"); } - //捕获参数异常 - try { - Boolean flagOfjudge = xhpcInvoiceService.invoiceToUser(requestData); - if (!flagOfjudge) { - AjaxResult.error("客户邮箱有误,邮件未发送成功,请通知用户修改邮箱"); + //开失败发票 + if (requestData.getStatus().equals(InvoiceStatusConst.FAIL)) { + Boolean flagOfjudge = xhpcInvoiceService.failInvoiceToUser(requestData); + } else { + //开成功发票 + 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(); } diff --git a/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/mapper/XhpcInvoiceMapper.java b/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/mapper/XhpcInvoiceMapper.java index d0d49f8f..700a7870 100644 --- a/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/mapper/XhpcInvoiceMapper.java +++ b/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/mapper/XhpcInvoiceMapper.java @@ -83,4 +83,13 @@ public interface XhpcInvoiceMapper { */ Long invoiceToUser(InvoiceToUserRequest requestData); + /** + * 更新指定发票状态,让其成为开发票失败状态 + * + * @author WH + * @date 2021/12/23 13:30 + * @since version-1.0 + */ + Long failInvoiceToUser(InvoiceToUserRequest requestData); + } \ No newline at end of file diff --git a/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/service/XhpcInvoiceService.java b/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/service/XhpcInvoiceService.java index 28fd2ba9..34185c27 100644 --- a/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/service/XhpcInvoiceService.java +++ b/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/service/XhpcInvoiceService.java @@ -47,4 +47,17 @@ public interface XhpcInvoiceService { */ 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); + } diff --git a/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/service/impl/XhpcInvoiceServiceImpl.java b/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/service/impl/XhpcInvoiceServiceImpl.java index f89d0a28..8dc7574b 100644 --- a/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/service/impl/XhpcInvoiceServiceImpl.java +++ b/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/service/impl/XhpcInvoiceServiceImpl.java @@ -106,12 +106,14 @@ public class XhpcInvoiceServiceImpl implements XhpcInvoiceService { //根据操作人的id,查询操作人的名字 SysUser sysUser = sysUserMapper.selectUserById(Long.valueOf(requestData.getDrawer())); requestData.setDrawer(sysUser.getNickName()); - //发送电子pdf到接收者邮箱 + //发送电子发票pdf到接收者邮箱 XhpcInvoice xhpcInvoice = xhpcInvoiceMapper.selectByPrimaryKey(requestData.getInvoiceId()); String receiveEmail = xhpcInvoice.getReceiveEmail(); File eletricInvoiceFile = new File("D:\\Enterprise_Resources\\ElectricInvoice\\ElectricInvoice.pdf"); - String sendEmailInfo = MailUtil.send(receiveEmail, "测试", "邮件来自Hutool测试", false, eletricInvoiceFile); - if (sendEmailInfo == null) { + try { + MailUtil.send(receiveEmail, "【小华充电】电子发票", "邮件来自小华充电", false, eletricInvoiceFile); + } catch (Exception e) { + System.out.println(e.getMessage()); return Boolean.FALSE; } //更新发票数据 @@ -122,6 +124,15 @@ public class XhpcInvoiceServiceImpl implements XhpcInvoiceService { return Boolean.TRUE; } + @Override + @Transactional(rollbackFor = Exception.class) + public Boolean failInvoiceToUser(InvoiceToUserRequest requestData) { + //todo + //最后入库更新 + xhpcInvoiceMapper.failInvoiceToUser(requestData); + return null; + } + /** * 通过发票id查找对应的发票数据 * diff --git a/xhpc-modules/xhpc-invoice/src/main/resources/mapper/XhpcInvoiceMapper.xml b/xhpc-modules/xhpc-invoice/src/main/resources/mapper/XhpcInvoiceMapper.xml index 3329afa5..1b64c9a9 100644 --- a/xhpc-modules/xhpc-invoice/src/main/resources/mapper/XhpcInvoiceMapper.xml +++ b/xhpc-modules/xhpc-invoice/src/main/resources/mapper/XhpcInvoiceMapper.xml @@ -439,4 +439,14 @@ WHERE invoice_id = #{invoiceId}; + + UPDATE xhpc_invoice + SET finance_notes = #{financeNotes}, + invoicing_time = #{invoicingTime}, + electric_invoice_url = #{eletricInvoiceUrl}, + `status` = #{status}, + drawer = #{drawer} + WHERE invoice_id = #{invoiceId} + + \ No newline at end of file