当前位置:网站首页>Export of zip file
Export of zip file
2022-07-03 04:00:00 【Captain Greenskin 】
@PostMapping("/download/batch")
@ApiOperation(" Bulk download PDF")
@Export(type = "zip", defaultFileName = " Tax payment certificate ")
@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)) {
// The query data is empty
throw new BizException(ResponseMsgEnum.QUERY_NOT_EXSIST);
}
try (BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
ZipOutputStream out = new ZipOutputStream(bos);
) {
byte[] buf = new byte[1024];
// Deal with the file name problem when the company name is consistent
dealWithSomeCompanyName(receipts);
for (ReceiptPO receipt : receipts) {
ByteArrayInputStream in = new ByteArrayInputStream(receipt.getFile());
// Name the files in the list separately
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(" Failed to export compressed file ", exception);
throw new BizException(ResponseMsgEnum.FILE_DOWNLOAD_ERROR);
}
}private void dealWithSomeCompanyName(List<ReceiptPO> receipts) {
// Sort by company name
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)) {
// Blank indicates that there is no duplicate company name
boolean contains = map.containsKey(receipt.getCompanyName());
if (!contains) {
// The company name does not exist, and there are key in , Then it means that there is a second duplicate company , Value reset calculation
repeat = 0;
}
map.put(receipt.getCompanyName(), receipt);
} else {
// Duplicate companies
repeat++;
String companyName = receipt.getCompanyName() + "(" + repeat + ")";
receipt.setCompanyName(companyName);
}
}
}zip File export
边栏推荐
- 释放数据力量的Ceph-尚文网络xUP楠哥
- 2022 Shandong Province safety officer C certificate examination questions and Shandong Province safety officer C certificate simulation examination question bank
- MPLS setup experiment
- CVPR 2022 | Dalian Institute of technology proposes a self calibration lighting framework for low light level image enhancement of real scenes
- Read a paper_ ChineseBert
- redis在服务器linux下的启动的相关命令(安装和配置)
- ZIP文件的导出
- Interface embedded in golang struct
- How does the pytorch project run?
- Bisher - based on SSM pet adoption center
猜你喜欢

『期末复习』16/32位微处理器(8086)基本寄存器

CVPR 2022 | 大連理工提出自校准照明框架,用於現實場景的微光圖像增强

在 .NET 6 项目中使用 Startup.cs

Message queue addition failure

2022 tea master (primary) examination questions and tea master (primary) examination question bank

IPv6过渡技术-6to4手工隧道配置实验--尚文网络奎哥

When writing a web project, SmartUpload is used for file upload and new string () is used for transcoding, but in the database, there will still be random codes similar to poker
![[brush questions] connected with rainwater (one dimension)](/img/21/318fcb444b17be887562f4a9c1fac2.png)
[brush questions] connected with rainwater (one dimension)

pytorch开源吗?

递归:一维链表和数组
随机推荐
IPv6过渡技术-6to4手工隧道配置实验--尚文网络奎哥
[brush questions] find the number pair distance with the smallest K
2022年已过半,得抓紧
C language hashtable/hashset library summary
[mathematical logic] predicate logic (predicate logic basic equivalent | eliminate quantifier equivalent | quantifier negative equivalent | quantifier scope contraction expansion equivalent | quantifi
树莓派如何连接WiFi
js实现在可视区内,文字图片动画效果
Is pytorch difficult to learn? How to learn pytorch well?
MPLS setup experiment
第十届中国云计算大会·中国站:展望未来十年科技走向
2022 mobile crane driver examination registration and mobile crane driver operation examination question bank
Intercept string fixed length to array
Makefile demo
pytorch怎么下载?pytorch在哪里下载?
Hutool dynamically adds scheduled tasks
[learning notes] seckill - seckill project - (11) project summary
[mathematical logic] predicate logic (first-order predicate logic formula | example)
The latest analysis of the main principals of hazardous chemical business units in 2022 and the simulated examination questions of the main principals of hazardous chemical business units
Write it down once Net travel management background CPU Explosion Analysis
因果AI,下一代可信AI的产业升级新范式?