当前位置:网站首页>ZIP文件的导出
ZIP文件的导出
2022-07-03 03:56:00 【绿皮船长】
@PostMapping("/download/batch")
@ApiOperation("批量下载PDF")
@Export(type = "zip", defaultFileName = "完税证明")
@MenuAuth
public void downloadBatch(@RequestBody ReceiptDownLoadRequest receiptDownLoadRequest,
HttpServletRequest request,
HttpServletResponse response) {
String recordIds = receiptDownLoadRequest.getRecordIds();
List<Long> ids = Arrays.stream(recordIds.split(BaseConstant.COMMA))
.map(Long::parseLong).collect(
Collectors.toList());
List<ReceiptPO> receipts = receitService.getReceipts(ids);
if (CollectionUtils.isEmpty(receipts)) {
//查询到的数据为空
throw new BizException(ResponseMsgEnum.QUERY_NOT_EXSIST);
}
try (BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
ZipOutputStream out = new ZipOutputStream(bos);
) {
byte[] buf = new byte[1024];
//处理公司名字一致时文件名问题
dealWithSomeCompanyName(receipts);
for (ReceiptPO receipt : receipts) {
ByteArrayInputStream in = new ByteArrayInputStream(receipt.getFile());
// 给列表中的文件单独命名
out.putNextEntry(new ZipEntry(receipt.getCompanyName() + ".pdf"));
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.closeEntry();
in.close();
}
} catch (Exception exception) {
log.error("导出压缩文件失败", exception);
throw new BizException(ResponseMsgEnum.FILE_DOWNLOAD_ERROR);
}
}private void dealWithSomeCompanyName(List<ReceiptPO> receipts) {
//按公司名排序
receipts = receipts.stream().sorted(Comparator.comparing(ReceiptPO::getCompanyName))
.collect(Collectors.toList());
HashMap<String, ReceiptPO> map = new HashMap<>();
int repeat = 0;
for (ReceiptPO receipt : receipts) {
ReceiptPO receiptPoByMap = map.get(receipt.getCompanyName());
if (Objects.isNull(receiptPoByMap)) {
//为空表示没出现重复公司名
boolean contains = map.containsKey(receipt.getCompanyName());
if (!contains) {
//公司名不存在已有key中,那么说明出现了第二家重复公司,值清零计算
repeat = 0;
}
map.put(receipt.getCompanyName(), receipt);
} else {
//有重复公司
repeat++;
String companyName = receipt.getCompanyName() + "(" + repeat + ")";
receipt.setCompanyName(companyName);
}
}
}zip文件导出
边栏推荐
- 在写web项目的时候,文件上传用到了smartupload,用了new string()进行转码,但是在数据库中,还是会出现类似扑克的乱码
- Some preliminary preparations for QQ applet development: make an appointment for a development account, download and install developer tools, and create QQ applet
- 2.14 simulation summary
- Mongodb master profile
- Separable bonds and convertible bonds
- 2022年已过半,得抓紧
- Idea shortcut keys
- Cnopendata China Customs Statistics
- ffmpeg录制屏幕和截屏
- eth入门之简介
猜你喜欢

Download and install captura and configure ffmpeg in captura

2022 Shandong Province safety officer C certificate examination questions and Shandong Province safety officer C certificate simulation examination question bank

Captura下载安装及在Captura配置FFmpeg

NPM: the 'NPM' item cannot be recognized as the name of a cmdlet, function, script file, or runnable program. Please check the spelling of the name. If the path is included, make sure the path is corr

Makefile demo

Wechat applet + Alibaba IOT platform + Hezhou air724ug built with server version system analysis

没有sXid,suid&sgid将进入险境!-尚文网络xUP楠哥

在写web项目的时候,文件上传用到了smartupload,用了new string()进行转码,但是在数据库中,还是会出现类似扑克的乱码

学会pytorch能干什么?

Ffmpeg download and installation tutorial and introduction
随机推荐
递归:深度优先搜索
Dynamic programming: Longest palindrome substring and subsequence
sigaction的使用
递归使用和多维数组对象变一维数组对象
递归:一维链表和数组
leetcode:297. 二叉树的序列化与反序列化
How to execute a swift for in loop in one step- How can I do a Swift for-in loop with a step?
Appium自动化测试框架
Docker install and start MySQL service
[combinatorics] brief introduction to generating function (definition of generating function | Newton binomial coefficient | commonly used generating function | correlation with constant | correlation
MPLS setup experiment
[Yu Yue education] reference materials of political communication science of Communication University of China
Is pytorch difficult to learn? How to learn pytorch well?
可分离债券与可转债
Null and undefined
For instruction, uploading pictures and display effect optimization of simple wechat applet development
在写web项目的时候,文件上传用到了smartupload,用了new string()进行转码,但是在数据库中,还是会出现类似扑克的乱码
Role of JS No
Debug: CD cannot be used in kaggle
Mongodb master profile