当前位置:网站首页>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文件导出
边栏推荐
- Message queue addition failure
- 【刷题篇】接雨水(一维)
- 在 .NET 6 项目中使用 Startup.cs
- Basic operations of mongodb [add, delete, modify, query]
- [Yu Yue education] reference materials of political communication science of Communication University of China
- [mathematical logic] predicate logic (judge whether the first-order predicate logic formula is true or false | explain | example | predicate logic formula type | forever true | forever false | satisfi
- node,npm以及yarn下载安装
- Numpy warning visibledeprecationwarning: creating an ndarray from ragged needed sequences
- Separable bonds and convertible bonds
- eth入门之DAPP
猜你喜欢

Leetcode: dynamic planning template

递归:深度优先搜索
![[Apple Photo Album push] IMessage group anchor local push](/img/a7/6a27d646ecba0d7c93f8dac38492a2.jpg)
[Apple Photo Album push] IMessage group anchor local push

Appium自动化测试框架

CEPH Shangwen network xUP Nange that releases the power of data

Simple wechat applet development page Jump, data binding, obtaining user information, obtaining user location information

释放数据力量的Ceph-尚文网络xUP楠哥

Recursion: one dimensional linked lists and arrays

npm : 无法将“npm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。

JMeter starts from zero (III) -- simple use of regular expressions
随机推荐
User value is the last word in the competition of mobile phone market
nodejs基础:浅聊url和querystring模块
Ansible introduction [unfinished (semi-finished products)]
What is pytorch? Is pytorch a software?
【学习笔记】seckill-秒杀项目--(11)项目总结
TCP, the heavyweight guest in tcp/ip model -- Kuige of Shangwen network
leetcode:动态规划模板
简易版 微信小程序开发之页面跳转、数据绑定、获取用户信息、获取用户位置信息
eth入门之DAPP
[Blue Bridge Road -- bug free code] interpretation of some codes of matrix keyboard
In Net 6 project using startup cs
Commands related to the startup of redis under Linux server (installation and configuration)
Nodejs Foundation: shallow chat URL and querystring module
[mathematical logic] predicate logic (judge whether the first-order predicate logic formula is true or false | explain | example | predicate logic formula type | forever true | forever false | satisfi
Wechat applet + Alibaba IOT platform + Hezhou air724ug build a serverless IOT system (III) -- wechat applet is directly connected to Alibaba IOT platform aliiot
Docker install and start MySQL service
Wechat applet + Alibaba IOT platform + Hezhou air724ug built with server version system analysis
CEPH Shangwen network xUP Nange that releases the power of data
[Blue Bridge Road - bug free code] pcf8591 - code analysis of AD conversion
Error c2694 "void logger:: log (nvinfer1:: ilogger:: severity, const char *)": rewrite the restrictive exception specification of virtual functions than base class virtual member functions