From f0d93937f668f3a83d02962b7e38eb16c8b25067 Mon Sep 17 00:00:00 2001 From: wen <1455474577@qq.com> Date: Wed, 22 Dec 2021 20:16:42 +0800 Subject: [PATCH] =?UTF-8?q?/selectSpecificInvoice=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=B7=B2=E5=AE=8C=E6=88=90=20/invoiceToUser=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=B7=B2=E5=AE=8C=E6=88=90=E6=88=90=E5=8A=9F=E9=83=A8=E5=88=86?= =?UTF-8?q?=EF=BC=8C=E5=A4=B1=E8=B4=A5=E9=83=A8=E5=88=86=E6=98=8E=E5=A4=A9?= =?UTF-8?q?=E5=BC=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xhpc-modules/xhpc-invoice/pom.xml | 7 ++ .../controller/XhpcInvoiceController.java | 65 ++++++++++--- .../invoice/domain/InvoiceToUserRequest.java | 32 ++++++ .../xhpc/invoice/mapper/SysUserMapper.java | 22 +++++ .../invoice/mapper/XhpcInvoiceMapper.java | 58 +++++++++++ .../invoice/service/XhpcInvoiceService.java | 25 +++++ .../service/impl/XhpcInvoiceServiceImpl.java | 94 +++++++++++++++++- .../src/main/resources/config/mail.setting | 4 + .../main/resources/mapper/SysUserMapper.xml | 97 +++++++++++++++++++ .../resources/mapper/XhpcInvoiceMapper.xml | 91 +++++++++++++++++ 10 files changed, 474 insertions(+), 21 deletions(-) create mode 100644 xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/domain/InvoiceToUserRequest.java create mode 100644 xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/mapper/SysUserMapper.java create mode 100644 xhpc-modules/xhpc-invoice/src/main/resources/config/mail.setting create mode 100644 xhpc-modules/xhpc-invoice/src/main/resources/mapper/SysUserMapper.xml diff --git a/xhpc-modules/xhpc-invoice/pom.xml b/xhpc-modules/xhpc-invoice/pom.xml index a4ef328e..0d54c218 100644 --- a/xhpc-modules/xhpc-invoice/pom.xml +++ b/xhpc-modules/xhpc-invoice/pom.xml @@ -22,6 +22,13 @@ + + + com.sun.mail + javax.mail + 1.6.2 + + junit 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 393b0d3c..b811ec51 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 @@ -3,6 +3,8 @@ 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.domain.AllInvoiceOrdersRequest; +import com.xhpc.invoice.domain.AllInvoiceOrdersResponse; +import com.xhpc.invoice.domain.InvoiceToUserRequest; import com.xhpc.invoice.domain.SpecificInvoiceWrap; import com.xhpc.invoice.service.XhpcInvoiceService; import org.springframework.web.bind.annotation.PostMapping; @@ -27,6 +29,53 @@ public class XhpcInvoiceController extends BaseController { @Resource XhpcInvoiceService xhpcInvoiceService; + /** + * 给指定用户开发票,开票完成之后将开出的电子发票发送至用户的接收邮箱 + * + * @author WH + * @date 2021/12/22 12:03 + * @since version-1.0 + */ + @PostMapping("/invoiceToUser") + public AjaxResult invoiceToUser(@RequestBody InvoiceToUserRequest requestData) { + //前置条件 + if (requestData.getInvoiceId() == null) { + AjaxResult.error("必须传递未开发票id"); + } + if (requestData.getStatus() == null) { + AjaxResult.error("必须传递发票状态"); + } + //捕获参数异常 + try { + Boolean flagOfjudge = xhpcInvoiceService.invoiceToUser(requestData); + if (!flagOfjudge) { + AjaxResult.error("客户邮箱有误,邮件未发送成功,请通知用户修改邮箱"); + } + } catch (Exception e) { + return AjaxResult.error(e.getMessage()); + } + return AjaxResult.success(); + } + + /** + * 用于在后台显示所有发票信息,包括待开发票和已开发票的信息 + * + * @param requestData 前端传递过来的要查询的参数 + * @return AllInvoiceOrdersResponse 装着回显数据的包装类 + * @author WH + * @date 2021/12/21 11:33 + * @since version-1.0 + */ + @PostMapping("/selectAllInvoiceOrders") + public AjaxResult selectAllInvoiceOrders(@RequestBody AllInvoiceOrdersRequest requestData) { + + if (requestData.getCurrentPage() == null || requestData.getItems() == null) { + AjaxResult.error("当前页数、每页要显示的条数为必传递项"); + } + AllInvoiceOrdersResponse allInvoiceOrdersResponse = xhpcInvoiceService.selectAllInvoiceOrders(requestData); + return AjaxResult.success(allInvoiceOrdersResponse); + } + /** * 用于在财务点击开票时,回显开票数据 * @@ -46,20 +95,4 @@ public class XhpcInvoiceController extends BaseController { } return AjaxResult.success(specificInvoiceWrap); } - - /** - * 用于在后台显示,所有发票信息,包括待开发票和已开发票的信息 - * - * @param requestData 前端传递过来的要查询的参数 - * @return AllInvoiceOrdersResponse 装着回显数据的包装类 - * @author WH - * @date 2021/12/21 11:33 - * @since version-1.0 - */ - @PostMapping("/selectAllInvoiceOrders") - public AjaxResult selectAllInvoiceOrders(@RequestBody AllInvoiceOrdersRequest requestData) { - - return null; - } - } diff --git a/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/domain/InvoiceToUserRequest.java b/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/domain/InvoiceToUserRequest.java new file mode 100644 index 00000000..d906ca51 --- /dev/null +++ b/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/domain/InvoiceToUserRequest.java @@ -0,0 +1,32 @@ +package com.xhpc.invoice.domain; + + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * InvoiceToUser接口接收数据的包装类 + * + * @author WH + * @date 2021/12/22 14:48 + * @since version-1.0 + */ +@NoArgsConstructor +@Data +public class InvoiceToUserRequest { + + @JsonProperty("invoiceId") + private Long invoiceId; + @JsonProperty("financeNotes") + private String financeNotes; + @JsonProperty("invoicingTime") + private String invoicingTime; + @JsonProperty("eletricInvoiceUrl") + private String eletricInvoiceUrl; + @JsonProperty("status") + private Integer status; + @JsonProperty("drawer") + private String drawer; + +} diff --git a/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/mapper/SysUserMapper.java b/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/mapper/SysUserMapper.java new file mode 100644 index 00000000..886d1287 --- /dev/null +++ b/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/mapper/SysUserMapper.java @@ -0,0 +1,22 @@ +package com.xhpc.invoice.mapper; + +import com.xhpc.system.api.domain.SysUser; + +/** + * 操作后台系统用户表(SysUserMapper)的Mapper + * + * @author WH + * @date 2021/12/22 15:18 + * @since version-1.0 + */ +public interface SysUserMapper { + + /** + * 通过用户ID查询用户 + * + * @param userId 用户ID + * @return 用户对象信息 + */ + SysUser selectUserById(Long userId); + +} 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 6a21515d..d0d49f8f 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 @@ -1,7 +1,12 @@ package com.xhpc.invoice.mapper; +import com.xhpc.invoice.domain.AllInvoiceOrdersRequest; +import com.xhpc.invoice.domain.InvoiceToUserRequest; import com.xhpc.invoice.pojo.XhpcInvoice; +import java.math.BigDecimal; +import java.util.List; + public interface XhpcInvoiceMapper { int deleteByPrimaryKey(Long invoiceId); @@ -25,4 +30,57 @@ public interface XhpcInvoiceMapper { int updateByPrimaryKey(XhpcInvoice record); + /** + * 通过条件来查询每个发票的信息,然后返回 + * + * @param requestData 查询条件 + * @return List 装着指定记录的信息 + * @author WH + * @date 2021/12/21 16:13 + * @since version-1.0 + */ + List selectAllInvoiceOrdersByCondition(AllInvoiceOrdersRequest requestData); + + /** + * 通过条件查询当前发票的总个数,然后返回 + * + * @param requestData 查询条件 + * @return Long 发票总个数 + * @author WH + * @date 2021/12/22 10:01 + * @since version-1.0 + */ + Long sumItemsInvoice(AllInvoiceOrdersRequest requestData); + + /** + * 查询所有已开发票的总金额 + * + * @return BigDecimal 所有已开发票的总金额 + * @author WH + * @date 2021/12/22 11:45 + * @since version-1.0 + */ + BigDecimal allInvoicedMoney(); + + /** + * 查询所有未开发票的总金额 + * + * @return BigDecimal 所有未开发票的总金额 + * @author WH + * @date 2021/12/22 11:53 + * @since version-1.0 + */ + BigDecimal allNotInvoicedMoney(); + + /** + * 更新指定发票状态,让其成为已开发票状态 + * + * @param requestData 更新数据的来源 + * @return Long 返回更新受影响的条数 + * @author WH + * @date 2021/12/22 15:07 + * @since version-1.0 + */ + Long invoiceToUser(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 67ecf7a4..28fd2ba9 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 @@ -1,5 +1,8 @@ package com.xhpc.invoice.service; +import com.xhpc.invoice.domain.AllInvoiceOrdersRequest; +import com.xhpc.invoice.domain.AllInvoiceOrdersResponse; +import com.xhpc.invoice.domain.InvoiceToUserRequest; import com.xhpc.invoice.domain.SpecificInvoiceWrap; /** @@ -22,4 +25,26 @@ public interface XhpcInvoiceService { */ SpecificInvoiceWrap selectSpecificInvoice(Long invoiceId); + /** + * 通过requestData中的申请人、申请人类型、发票状态、发票起始时间、发票申请终止时间、开票起始时间、开票终点时间、当前所在页数、当前页所要显示几行,来查询发票列表信息 + * + * @param requestData 传递过来的查询参数 + * @return AllInvoiceOrdersResponse 发票列表对象 + * @author WH + * @date 2021/12/21 16:02 + * @since version-1.0 + */ + AllInvoiceOrdersResponse selectAllInvoiceOrders(AllInvoiceOrdersRequest requestData); + + /** + * 存储开发票的状态,将开票信息入库,并向指定用户的邮箱发送短信 + * + * @param requestData 要入库的信息 + * @return Boolean 成功还是失败 + * @author WH + * @date 2021/12/22 14:59 + * @since version-1.0 + */ + Boolean invoiceToUser(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 792c6870..f89d0a28 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 @@ -1,19 +1,24 @@ package com.xhpc.invoice.service.impl; +import cn.hutool.extra.mail.MailUtil; import com.xhpc.common.core.utils.DateUtils; import com.xhpc.common.core.utils.bean.BeanUtils; import com.xhpc.common.domain.XhpcChargingStation; +import com.xhpc.invoice.domain.AllInvoiceOrdersRequest; +import com.xhpc.invoice.domain.AllInvoiceOrdersResponse; +import com.xhpc.invoice.domain.InvoiceToUserRequest; import com.xhpc.invoice.domain.SpecificInvoiceWrap; -import com.xhpc.invoice.mapper.XhpcChargingStationMapper; -import com.xhpc.invoice.mapper.XhpcInvoiceMapHistoryOrderMapper; -import com.xhpc.invoice.mapper.XhpcInvoiceMapper; -import com.xhpc.invoice.mapper.XhpcOperatorMapper; +import com.xhpc.invoice.mapper.*; import com.xhpc.invoice.pojo.XhpcInvoice; import com.xhpc.invoice.pojo.XhpcInvoiceMapHistoryOrder; import com.xhpc.invoice.service.XhpcInvoiceService; +import com.xhpc.system.api.domain.SysUser; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.io.File; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -36,6 +41,86 @@ public class XhpcInvoiceServiceImpl implements XhpcInvoiceService { XhpcOperatorMapper xhpcOperatorMapper; @Resource XhpcChargingStationMapper xhpcChargingStationMapper; + @Resource + SysUserMapper sysUserMapper; + + /** + * 通过requestData中的申请人、申请人类型、发票状态、发票起始时间、发票申请终止时间、开票起始时间、开票终点时间、当前所在页数、当前页所要显示几行,来查询发票列表信息 + * + * @param requestData 传递过来的查询参数 + * @return AllInvoiceOrdersResponse 发票列表对象 + * @author WH + * @date 2021/12/21 16:02 + * @since version-1.0 + */ + @Override + public AllInvoiceOrdersResponse selectAllInvoiceOrders(AllInvoiceOrdersRequest requestData) { + //计算分页索引 + requestData.setCurrentPage(requestData.getCurrentPage() - 1); + //获取每个历史订单信息 + List xhpcInvoiceList = xhpcInvoiceMapper.selectAllInvoiceOrdersByCondition(requestData); + //对拷,放置到itemsDTO中,然后将itemsDTO存放到itemsDTOList中 + ArrayList itemsDTOList = new ArrayList<>(); + for (XhpcInvoice xhpcInvoice : xhpcInvoiceList) { + AllInvoiceOrdersResponse.ItemsDTO itemsDTO = new AllInvoiceOrdersResponse.ItemsDTO(); + itemsDTO.setInvoiceId(xhpcInvoice.getInvoiceId()); + itemsDTO.setCreator(xhpcInvoice.getCreator()); + itemsDTO.setCreatorType(xhpcInvoice.getCreatorType()); + itemsDTO.setInvoiceMoney(xhpcInvoice.getInvoiceMoney()); + itemsDTO.setStatus(xhpcInvoice.getStatus()); + itemsDTO.setCreateTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, xhpcInvoice.getCreateTime())); + itemsDTO.setInvoicingTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, xhpcInvoice.getInvoicingTime())); + itemsDTO.setDrawer(xhpcInvoice.getDrawer()); + itemsDTOList.add(itemsDTO); + } + AllInvoiceOrdersResponse allInvoiceOrdersResponse = new AllInvoiceOrdersResponse(); + allInvoiceOrdersResponse.setItems(itemsDTOList); + //获取根据条件查询出来的发票总条数 + Long sumItemsInvoice = xhpcInvoiceMapper.sumItemsInvoice(requestData); + allInvoiceOrdersResponse.setTotalItems(sumItemsInvoice); + //查询所有已开发票总金额 + BigDecimal allInvoicedMoney = xhpcInvoiceMapper.allInvoicedMoney(); + if (allInvoicedMoney == null) { + //如果没有开任何发票,那么总金额就设置成0.00 + allInvoicedMoney = new BigDecimal("0.00"); + } + allInvoiceOrdersResponse.setInvoicedSumMoney(allInvoicedMoney); + //查询所有未开发票总金额 + BigDecimal allNotInvoicedMoney = xhpcInvoiceMapper.allNotInvoicedMoney(); + allInvoiceOrdersResponse.setNotInvoiceSumMoney(allNotInvoicedMoney); + return allInvoiceOrdersResponse; + } + + /** + * 存储成功开发票的状态,将开票信息入库,并向指定用户的邮箱发送短信 + * + * @param requestData 要入库的信息 + * @return Boolean 成功还是失败 + * @author WH + * @date 2021/12/22 14:59 + * @since version-1.0 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public Boolean invoiceToUser(InvoiceToUserRequest requestData) { + //根据操作人的id,查询操作人的名字 + SysUser sysUser = sysUserMapper.selectUserById(Long.valueOf(requestData.getDrawer())); + requestData.setDrawer(sysUser.getNickName()); + //发送电子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) { + return Boolean.FALSE; + } + //更新发票数据 + Long successFlag = xhpcInvoiceMapper.invoiceToUser(requestData); + if (successFlag == 0) { + throw new RuntimeException("无法更新指定发票,传入的数据有问题"); + } + return Boolean.TRUE; + } /** * 通过发票id查找对应的发票数据 @@ -86,5 +171,4 @@ public class XhpcInvoiceServiceImpl implements XhpcInvoiceService { specificInvoiceWrap.setHistoryOrderScope(minTime + "," + maxTime); return specificInvoiceWrap; } - } diff --git a/xhpc-modules/xhpc-invoice/src/main/resources/config/mail.setting b/xhpc-modules/xhpc-invoice/src/main/resources/config/mail.setting new file mode 100644 index 00000000..6685409e --- /dev/null +++ b/xhpc-modules/xhpc-invoice/src/main/resources/config/mail.setting @@ -0,0 +1,4 @@ +# 发件人(必须正确,否则发送失败) +from = coml_aaron@163.com +# 密码(注意,某些邮箱需要为SMTP服务单独设置密码,详情查看相关帮助) +pass = DRTYHUCGNKPOFRVE \ No newline at end of file diff --git a/xhpc-modules/xhpc-invoice/src/main/resources/mapper/SysUserMapper.xml b/xhpc-modules/xhpc-invoice/src/main/resources/mapper/SysUserMapper.xml new file mode 100644 index 00000000..36ab2470 --- /dev/null +++ b/xhpc-modules/xhpc-invoice/src/main/resources/mapper/SysUserMapper.xml @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + select u.user_id, + u.dept_id, + u.user_name, + u.nick_name, + u.email, + u.avatar, + u.phonenumber, + u.password, + u.sex, + u.status, + u.del_flag, + u.login_ip, + u.login_date, + u.create_by, + u.create_time, + u.remark, + d.dept_id, + d.parent_id, + d.dept_name, + d.order_num, + d.leader, + d.status as dept_status, + u.data_power_type, + r.role_id, + r.role_name, + r.role_key, + r.role_sort, + r.data_scope, + r.status as role_status, + u.user_type, + u.operator_id + from sys_user u + left join sys_dept d on u.dept_id = d.dept_id + left join sys_user_role ur on u.user_id = ur.user_id + left join sys_role r on r.role_id = ur.role_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 550ed304..3329afa5 100644 --- a/xhpc-modules/xhpc-invoice/src/main/resources/mapper/XhpcInvoiceMapper.xml +++ b/xhpc-modules/xhpc-invoice/src/main/resources/mapper/XhpcInvoiceMapper.xml @@ -44,6 +44,86 @@ from xhpc_invoice where invoice_id = #{invoiceId,jdbcType=BIGINT} and del_flag is null; + + + + delete from xhpc_invoice @@ -348,4 +428,15 @@ del_flag = #{delFlag,jdbcType=INTEGER} where invoice_id = #{invoiceId,jdbcType=BIGINT} + + + 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