当前位置:网站首页>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文件导出
边栏推荐
- Applet get user avatar and nickname
- [learning notes] seckill - seckill project - (11) project summary
- Separable bonds and convertible bonds
- sigaction的使用
- 105. SAP UI5 Master-Detail 布局模式的联动效果实现明细介绍
- 中移物联网OneOS与OneNET入选《2021年物联网示范项目名单》
- [mathematical logic] predicate logic (first-order predicate logic formula | example)
- redis在服务器linux下的启动的相关命令(安装和配置)
- 2022 mobile crane driver examination registration and mobile crane driver operation examination question bank
- 2022 tea master (intermediate) examination questions and analysis and tea master (intermediate) practical examination video
猜你喜欢
【刷题篇】接雨水(一维)
How does the pytorch project run?
第十届中国云计算大会·中国站:展望未来十年科技走向
IPv6过渡技术-6to4手工隧道配置实验--尚文网络奎哥
nodejs基础:浅聊url和querystring模块
What can learning pytorch do?
[Apple Push] IMessage group sending condition document (push certificate) development tool pushnotification
Web session management security issues
Download and install captura and configure ffmpeg in captura
Makefile demo
随机推荐
Use of sigaction
在写web项目的时候,文件上传用到了smartupload,用了new string()进行转码,但是在数据库中,还是会出现类似扑克的乱码
[mathematical logic] propositions and connectives (propositions | propositional symbolization | truth connectives | no | conjunction | disjunction | non truth connectives | implication | equivalence)
Dynamic programming: longest common substring and longest common subsequence
npm : 无法将“npm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。
Numpy warning visibledeprecationwarning: creating an ndarray from ragged needed sequences
numpy之 警告VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences
Ffmpeg download and installation tutorial and introduction
Half of 2022 is over, so we must hurry up
JMeter starts from zero (III) -- simple use of regular expressions
Captura下载安装及在Captura配置FFmpeg
Debug: CD cannot be used in kaggle
Dynamic programming: Longest palindrome substring and subsequence
[MySQL] the difference between left join, right join and join
Recursion: depth first search
[mathematical logic] propositional logic (propositional and connective review | propositional formula | connective priority | truth table satisfiable contradiction tautology)
Table structure of Navicat export database
Ffmpeg one / more pictures synthetic video
『期末复习』16/32位微处理器(8086)基本寄存器
Null and undefined