当前位置:网站首页>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
边栏推荐
- Is it better to speculate in the short term or the medium and long term? Comparative analysis of differences
- Makefile demo
- Hutool dynamically adds scheduled tasks
- Applet (continuous update)
- Esp32 series (3): GPIO learning (take simple GPIO input and output, ADC, DAC as examples)
- 深潜Kotlin协程(二十):构建 Flow
- TCP/IP模型中的重磅嘉宾TCP--尚文网络奎哥
- 没有sXid,suid&sgid将进入险境!-尚文网络xUP楠哥
- CEPH Shangwen network xUP Nange that releases the power of data
- C language hashtable/hashset library summary
猜你喜欢

pytorch难学吗?如何学好pytorch?

Arduino application development - LCD display GIF dynamic diagram

Ffmpeg download and installation tutorial and introduction

编译文件时报错:错误: 编码GBK的不可映射字符

Esp32 series (3): GPIO learning (take simple GPIO input and output, ADC, DAC as examples)

pytorch项目怎么跑?

【毕业季·进击的技术er】职场人的自白

毕设-基于SSM宠物领养中心

深潜Kotlin协程(十九):Flow 概述

Appium automated testing framework
随机推荐
Recursion: quick sort, merge sort and heap sort
Web会话管理安全问题
Interface embedded in golang struct
105. Detailed introduction of linkage effect realization of SAP ui5 master detail layout mode
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
Mutex and rwmutex in golang
vim 的实用操作
2022deepbrainchain biweekly report no. 104 (01.16-02.15)
深潜Kotlin协程(十九):Flow 概述
在 .NET 6 项目中使用 Startup.cs
[brush questions] most elements (super water king problem)
以两列的瀑布流为例,我们应该怎么构建每一列的数组
Shardingsphere dynamic data source
JS native common knowledge
CVPR 2022 | 大连理工提出自校准照明框架,用于现实场景的微光图像增强
China Mobile Internet of things oneos and onenet were selected in the list of 2021 Internet of things demonstration projects
CVPR 2022 | 大連理工提出自校准照明框架,用於現實場景的微光圖像增强
Applet (continuous update)
ZIP文件的导出
用户体验五要素