当前位置:网站首页>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文件导出
边栏推荐
- SAP UI5 应用开发教程之一百零五 - SAP UI5 Master-Detail 布局模式的联动效果实现明细介绍
- 小程序获取用户头像和昵称
- User value is the last word in the competition of mobile phone market
- [Apple Photo Album push] IMessage group anchor local push
- 2022 mobile crane driver examination registration and mobile crane driver operation examination question bank
- What is pytorch? Is pytorch a software?
- 2022 tea master (intermediate) examination questions and analysis and tea master (intermediate) practical examination video
- 8.8.2-PointersOnC-20220214
- JMeter starts from zero (III) -- simple use of regular expressions
- 如何迈向IPv6之IPv6过渡技术-尚文网络奎哥
猜你喜欢

Introduction to mongodb

Hutool动态添加定时任务

numpy之 警告VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences

2022 tea master (intermediate) examination questions and analysis and tea master (intermediate) practical examination video

Docker install and start MySQL service

【刷题篇】多数元素(超级水王问题)

node,npm以及yarn下载安装

Ffmpeg recording screen and screenshot

How to download pytorch? Where can I download pytorch?

Makefile demo
随机推荐
[Blue Bridge Road -- bug free code] DS18B20 temperature reading code analysis
C language hashtable/hashset library summary
【刷题篇】多数元素(超级水王问题)
eth入门之DAPP
Introduction to mongodb
[mathematical logic] propositional logic (equivalent calculus | idempotent law | exchange law | combination law | distribution law | De Morgan law | absorption rate | zero law | identity | exclusion l
[mathematical logic] predicate logic (predicate logic basic equivalent | eliminate quantifier equivalent | quantifier negative equivalent | quantifier scope contraction expansion equivalent | quantifi
Mongodb installation & Deployment
Recursion: depth first search
Ffmpeg recording screen and screenshot
如何迈向IPv6之IPv6过渡技术-尚文网络奎哥
Commands related to the startup of redis under Linux server (installation and configuration)
Arduino application development - LCD display GIF dynamic diagram
leetcode:297. 二叉树的序列化与反序列化
ffmpeg下载安装教程及介绍
105. Detailed introduction of linkage effect realization of SAP ui5 master detail layout mode
pytorch怎么下载?pytorch在哪里下载?
[national programming] [software programming - Lecture Video] [zero foundation introduction to practical application]
vim 的实用操作
pytorch是什么?pytorch是一个软件吗?