完成发票信息导出接口,将发票信息导出至Excel中,然后供用户下载
This commit is contained in:
parent
762fe744ea
commit
cf89e40ccf
@ -15,7 +15,9 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -43,9 +45,12 @@ public class XhpcInvoiceController extends BaseController {
|
|||||||
* @since version-1.0
|
* @since version-1.0
|
||||||
*/
|
*/
|
||||||
@GetMapping("/excel")
|
@GetMapping("/excel")
|
||||||
public AjaxResult exportExcel(@RequestParam("invoiceIds") List<Integer> invoiceIds) {
|
public AjaxResult exportExcel(@RequestParam("invoiceIds") String invoiceIds, HttpServletResponse response) throws IOException {
|
||||||
//todo 将指定发票信息导入到excel表中,然后返回出去
|
//处理字符串,转换成数组
|
||||||
return AjaxResult.success("https://xhpc-bucket1.oss-cn-hangzhou.aliyuncs.com/69852145895461/202109151137358636985214589546101.png");
|
String[] ids = invoiceIds.split(",");
|
||||||
|
List<String> resultList = Arrays.asList(ids);
|
||||||
|
xhpcInvoiceService.exportExcel(resultList, response);
|
||||||
|
return AjaxResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -62,7 +67,7 @@ public class XhpcInvoiceController extends BaseController {
|
|||||||
@PostMapping("/pdf")
|
@PostMapping("/pdf")
|
||||||
public AjaxResult uploadPdf(MultipartFile invoicePdf) throws IOException {
|
public AjaxResult uploadPdf(MultipartFile invoicePdf) throws IOException {
|
||||||
|
|
||||||
String filename = "electronicInvoice" + DateUtils.dateTimeNow() + ".pdf";
|
String filename = "electricInvoice" + DateUtils.dateTimeNow() + ".pdf";
|
||||||
// 上传文件到阿里云
|
// 上传文件到阿里云
|
||||||
OSSClient ossClient = new OSSClient(environment.getProperty("oss.endpoint"), environment.getProperty("oss.access-key"), environment.getProperty("oss.secret-key"));
|
OSSClient ossClient = new OSSClient(environment.getProperty("oss.endpoint"), environment.getProperty("oss.access-key"), environment.getProperty("oss.secret-key"));
|
||||||
// 放置到哪个块中去,key为目录,file为文件
|
// 放置到哪个块中去,key为目录,file为文件
|
||||||
|
|||||||
@ -0,0 +1,47 @@
|
|||||||
|
package com.xhpc.invoice.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用于存储导出发票的一行记录的Bean类
|
||||||
|
*
|
||||||
|
* @author WH
|
||||||
|
* @date 2021/12/30 14:13
|
||||||
|
* @since version-1.0
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class ExcelInvoiceRow {
|
||||||
|
|
||||||
|
private Integer rowsNumber;
|
||||||
|
private String invoiceType;
|
||||||
|
private String receiveEmail;
|
||||||
|
private String titleType;
|
||||||
|
private String titleContent;
|
||||||
|
private String dutyNumber;
|
||||||
|
private String invoiceContent;
|
||||||
|
private String invoiceOrderElectricTotalMoney;
|
||||||
|
private String invoiceOrderServiceTotalMoney;
|
||||||
|
private String firmAddress;
|
||||||
|
private String firmPhone;
|
||||||
|
private String firmBank;
|
||||||
|
private String firmBankAccount;
|
||||||
|
private String isShowDate;
|
||||||
|
private String userNotes;
|
||||||
|
private String creatorType;
|
||||||
|
private String iCreateTime;
|
||||||
|
private String invoicingTime;
|
||||||
|
private String drawer;
|
||||||
|
private String financeNotes;
|
||||||
|
private String electricInvoiceUrl;
|
||||||
|
private String isRead;
|
||||||
|
private String historySerialNumber;
|
||||||
|
private String powerPriceTotal;
|
||||||
|
private String servicePriceTotal;
|
||||||
|
private String promotionDiscount;
|
||||||
|
private String historyActPrice;
|
||||||
|
private String hCreateTime;
|
||||||
|
private String chargingMode;
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
package com.xhpc.invoice.mapper;
|
package com.xhpc.invoice.mapper;
|
||||||
|
|
||||||
import com.xhpc.invoice.domain.AllInvoiceOrdersRequest;
|
import com.xhpc.invoice.domain.AllInvoiceOrdersRequest;
|
||||||
|
import com.xhpc.invoice.domain.ExcelInvoiceRow;
|
||||||
import com.xhpc.invoice.domain.InvoiceHistoryRecordsRequest;
|
import com.xhpc.invoice.domain.InvoiceHistoryRecordsRequest;
|
||||||
import com.xhpc.invoice.domain.InvoiceToUserRequest;
|
import com.xhpc.invoice.domain.InvoiceToUserRequest;
|
||||||
import com.xhpc.invoice.pojo.XhpcInvoice;
|
import com.xhpc.invoice.pojo.XhpcInvoice;
|
||||||
@ -176,4 +177,15 @@ public interface XhpcInvoiceMapper {
|
|||||||
*/
|
*/
|
||||||
void updateByInvoiceId(Long invoiceId);
|
void updateByInvoiceId(Long invoiceId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取发票内容
|
||||||
|
*
|
||||||
|
* @param invoiceId 发票id
|
||||||
|
* @return 专门用于放置到Excel中Map
|
||||||
|
* @author WH
|
||||||
|
* @date 2021/12/30 18:08
|
||||||
|
* @since version-1.0
|
||||||
|
*/
|
||||||
|
List<ExcelInvoiceRow> selectExcelInvoiceById(Long invoiceId);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -2,6 +2,10 @@ package com.xhpc.invoice.service;
|
|||||||
|
|
||||||
import com.xhpc.invoice.domain.*;
|
import com.xhpc.invoice.domain.*;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用于处理发票相关请求的Service
|
* 用于处理发票相关请求的Service
|
||||||
*
|
*
|
||||||
@ -133,4 +137,16 @@ public interface XhpcInvoiceService {
|
|||||||
*/
|
*/
|
||||||
Long findNotReadCount(Long creatorId, Integer creatorType);
|
Long findNotReadCount(Long creatorId, Integer creatorType);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出所有发票记录(已开与未开)到Excel中
|
||||||
|
*
|
||||||
|
* @param invoiceIds 发票id
|
||||||
|
* @param response 响应的response
|
||||||
|
* @throws IOException 该Response对象不存在时,抛出该异常对象
|
||||||
|
* @author WH
|
||||||
|
* @date 2021/12/30 10:16
|
||||||
|
* @since version-1.0
|
||||||
|
*/
|
||||||
|
void exportExcel(List<String> invoiceIds, HttpServletResponse response) throws IOException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
package com.xhpc.invoice.service.impl;
|
package com.xhpc.invoice.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
|
||||||
import cn.hutool.extra.mail.MailUtil;
|
import cn.hutool.extra.mail.MailUtil;
|
||||||
import cn.hutool.http.HttpUtil;
|
import cn.hutool.http.HttpUtil;
|
||||||
import cn.hutool.poi.excel.ExcelUtil;
|
import cn.hutool.poi.excel.ExcelUtil;
|
||||||
@ -22,7 +21,9 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -481,22 +482,94 @@ public class XhpcInvoiceServiceImpl implements XhpcInvoiceService {
|
|||||||
* 导出所有发票记录(已开与未开)到Excel中
|
* 导出所有发票记录(已开与未开)到Excel中
|
||||||
*
|
*
|
||||||
* @param invoiceIds 发票id
|
* @param invoiceIds 发票id
|
||||||
|
* @param response 响应对象
|
||||||
* @author WH
|
* @author WH
|
||||||
* @date 2021/12/30 10:16
|
* @date 2021/12/30 10:16
|
||||||
* @since version-1.0
|
* @since version-1.0
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void exportExcel(List<Integer> invoiceIds) {
|
public void exportExcel(List<String> invoiceIds, HttpServletResponse response) throws IOException {
|
||||||
|
//创建Excel写入对象
|
||||||
Integer integer = invoiceIds.get(0);
|
ExcelWriter writer = ExcelUtil.getWriter("record.xlsx");
|
||||||
//获取要导出的发票记录
|
//设置单元格标题别名
|
||||||
XhpcInvoice xhpcInvoice = xhpcInvoiceMapper.selectByPrimaryKey(Long.valueOf(integer));
|
setExcelCellName(writer);
|
||||||
List<XhpcInvoice> rows = CollUtil.newArrayList(xhpcInvoice);
|
//定义每一行的行号(1,2,3,4...)
|
||||||
//写出记录到excel表中
|
int rowsNumber = 1;
|
||||||
ExcelWriter writer = ExcelUtil.getWriter("d:/writeTest.xlsx");
|
//设定初始合并行参数(即第一行该从哪行开始合并,合并几行)
|
||||||
writer.write(rows);
|
int rowStart = 1;
|
||||||
writer.close();
|
int lastRow = 0;
|
||||||
|
for (String invoiceId : invoiceIds) {
|
||||||
|
List<ExcelInvoiceRow> excelInvoiceRows = xhpcInvoiceMapper.selectExcelInvoiceById(Long.valueOf(invoiceId));
|
||||||
|
//往记录中塞入行号
|
||||||
|
for (ExcelInvoiceRow excelInvoiceRow : excelInvoiceRows) {
|
||||||
|
excelInvoiceRow.setRowsNumber(rowsNumber);
|
||||||
|
}
|
||||||
|
//写入记录
|
||||||
|
writer.write(excelInvoiceRows);
|
||||||
|
int invoiceCount = excelInvoiceRows.size();
|
||||||
|
//如果写入的发票记录只有一个,就不合并单元格,增加合并行索引,为下面需要合并的行做准备。
|
||||||
|
if (invoiceCount == 1) {
|
||||||
|
lastRow = lastRow + 1;
|
||||||
|
rowStart = rowStart + 1;
|
||||||
|
} else {
|
||||||
|
//计算每条要合并发票记录的行的最后一个行号
|
||||||
|
lastRow = lastRow + invoiceCount;
|
||||||
|
//合并单元格
|
||||||
|
for (int columnIndex = 0; columnIndex <= 21; columnIndex++) {
|
||||||
|
writer.merge(rowStart, lastRow, columnIndex, columnIndex, null, false);
|
||||||
|
}
|
||||||
|
//计算每条要合并发票记录的行的第一个行号
|
||||||
|
rowStart = rowStart + invoiceCount;
|
||||||
|
}
|
||||||
|
rowsNumber++;
|
||||||
|
}
|
||||||
|
//设置文件类型
|
||||||
|
response.setContentType(ExcelUtil.XLSX_CONTENT_TYPE);
|
||||||
|
//让浏览器下载
|
||||||
|
response.addHeader("Content-Disposition", "attachment;filename=" + "invoiceRecord.xlsx"); //设置返回的文件名称
|
||||||
//写入到Response中
|
//写入到Response中
|
||||||
|
writer.flush(response.getOutputStream(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置生成的Excel表格单元格标题
|
||||||
|
*
|
||||||
|
* @param writer Excel写入器
|
||||||
|
* @author WH
|
||||||
|
* @date 2021/12/31 11:10
|
||||||
|
* @since version-1.0
|
||||||
|
*/
|
||||||
|
private void setExcelCellName(ExcelWriter writer) {
|
||||||
|
|
||||||
|
writer.addHeaderAlias("rowsNumber", "序号");
|
||||||
|
writer.addHeaderAlias("invoiceType", "发票类型");
|
||||||
|
writer.addHeaderAlias("receiveEmail", "接收邮箱");
|
||||||
|
writer.addHeaderAlias("titleType", "抬头类型");
|
||||||
|
writer.addHeaderAlias("titleContent", "抬头内容");
|
||||||
|
writer.addHeaderAlias("dutyNumber", "税号");
|
||||||
|
writer.addHeaderAlias("invoiceContent", "发票内容");
|
||||||
|
writer.addHeaderAlias("invoiceOrderElectricTotalMoney", "总电量金额");
|
||||||
|
writer.addHeaderAlias("invoiceOrderServiceTotalMoney", "总服务费金额");
|
||||||
|
writer.addHeaderAlias("firmAddress", "地址");
|
||||||
|
writer.addHeaderAlias("firmPhone", "电话号码");
|
||||||
|
writer.addHeaderAlias("firmBank", "开户行");
|
||||||
|
writer.addHeaderAlias("firmBankAccount", "银行开户账号");
|
||||||
|
writer.addHeaderAlias("isShowDate", "用户是否要求展示交易日期");
|
||||||
|
writer.addHeaderAlias("userNotes", "用户备注");
|
||||||
|
writer.addHeaderAlias("creatorType", "用户类型");
|
||||||
|
writer.addHeaderAlias("iCreateTime", "发票申请时间");
|
||||||
|
writer.addHeaderAlias("invoicingTime", "发票开票时间");
|
||||||
|
writer.addHeaderAlias("drawer", "开票人");
|
||||||
|
writer.addHeaderAlias("financeNotes", "财物备注");
|
||||||
|
writer.addHeaderAlias("electricInvoiceUrl", "电子发票地址");
|
||||||
|
writer.addHeaderAlias("isRead", "用户是否阅读发票信息");
|
||||||
|
writer.addHeaderAlias("historySerialNumber", "订单编号");
|
||||||
|
writer.addHeaderAlias("powerPriceTotal", "订单电费");
|
||||||
|
writer.addHeaderAlias("servicePriceTotal", "订单服务费");
|
||||||
|
writer.addHeaderAlias("promotionDiscount", "折扣费用");
|
||||||
|
writer.addHeaderAlias("historyActPrice", "用户实际支付金额");
|
||||||
|
writer.addHeaderAlias("hCreateTime", "订单创建时间");
|
||||||
|
writer.addHeaderAlias("chargingMode", "订单来源");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -188,6 +188,48 @@
|
|||||||
AND creator_id = #{creatorId}
|
AND creator_id = #{creatorId}
|
||||||
AND creator_type = #{creatorType}
|
AND creator_type = #{creatorType}
|
||||||
</select>
|
</select>
|
||||||
|
<select id="selectExcelInvoiceById" resultType="com.xhpc.invoice.domain.ExcelInvoiceRow">
|
||||||
|
SELECT case i.invoice_type when 0 then '普票' when 1 then '专票' end as invoiceType,
|
||||||
|
i.receive_email as receiveEmail,
|
||||||
|
case i.title_type when 0 THEN '企业' ELSE '个人/非企业' END as titleType,
|
||||||
|
i.title_content as titleContent,
|
||||||
|
i.duty_number as dutyNumber,
|
||||||
|
i.invoice_content as invoiceContent,
|
||||||
|
i.invoice_money as invoiceOrderElectricTotalMoney,
|
||||||
|
i.invoice_order_service_total_money as invoiceOrderServiceTotalMoney,
|
||||||
|
i.firm_address as firmAddress,
|
||||||
|
i.firm_phone as firmPhone,
|
||||||
|
i.firm_bank as firmBank,
|
||||||
|
i.firm_bank_account as firmBankAccount,
|
||||||
|
case i.is_show_date when 0 then '开票者要求展示交易日期' ELSE '开票者不要求展示交易日期' END as isShowDate,
|
||||||
|
i.user_notes as userNotes,
|
||||||
|
case i.creator_type
|
||||||
|
when 0 then 'C端用户'
|
||||||
|
when 1 then '流量方'
|
||||||
|
when 2 then '社区用户'
|
||||||
|
when 3
|
||||||
|
then '企业用户' END as creatorType,
|
||||||
|
i.creator as creator,
|
||||||
|
i.create_time as iCreateTime,
|
||||||
|
case i.status when 0 then '未开票' when 1 then '已开票' when 2 then '开票失败' END as status,
|
||||||
|
i.invoicing_time as invoicingTime,
|
||||||
|
i.drawer,
|
||||||
|
i.finance_notes as financeNotes,
|
||||||
|
i.electric_invoice_url as electricInvoiceUrl,
|
||||||
|
case i.is_read when 1 then '已阅读' when 0 then '未阅读' else '该发票还未处理' END as isRead,
|
||||||
|
h.hisotry_serial_number as historySerialNumber,
|
||||||
|
h.power_price_total as powerPriceTotal,
|
||||||
|
h.service_price_total as servicePriceTotal,
|
||||||
|
h.promotion_discount as promotionDiscount,
|
||||||
|
history_act_price as historyActPrice,
|
||||||
|
h.create_time as hCreateTime,
|
||||||
|
h.charging_mode as chargingMode
|
||||||
|
FROM xhpc_invoice AS i
|
||||||
|
INNER JOIN xhpc_invoice_map_history_order AS h ON i.invoice_id = h.invoice_id
|
||||||
|
WHERE i.invoice_id = #{invoiceId}
|
||||||
|
AND i.del_flag IS NULL
|
||||||
|
AND h.del_flag IS NULL
|
||||||
|
</select>
|
||||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
|
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
|
||||||
delete
|
delete
|
||||||
from xhpc_invoice
|
from xhpc_invoice
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user