当前位置:网站首页>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
边栏推荐
- [learning notes] seckill - seckill project - (11) project summary
- Debug: CD cannot be used in kaggle
- 【刷题篇】 找出第 K 小的数对距离
- Filter
- Use of sigaction
- 2022 mobile crane driver examination registration and mobile crane driver operation examination question bank
- Appium自动化测试框架
- 如何迈向IPv6之IPv6过渡技术-尚文网络奎哥
- 105. SAP UI5 Master-Detail 布局模式的联动效果实现明细介绍
- pytorch项目怎么跑?
猜你喜欢

用户体验五要素
![[brush questions] find the number pair distance with the smallest K](/img/e1/4118e2b37b5cea0454d65b877b507f.png)
[brush questions] find the number pair distance with the smallest K

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

Hutool dynamically adds scheduled tasks
![[embedded module] OLED display module](/img/c4/474f5ee580d132654fbd1a4cd53bab.jpg)
[embedded module] OLED display module

Arduino application development - LCD display GIF dynamic diagram

Ffmpeg one / more pictures synthetic video

因果AI,下一代可信AI的产业升级新范式?

Numpy warning visibledeprecationwarning: creating an ndarray from ragged needed sequences

Role of JS No
随机推荐
redis在服务器linux下的启动的相关命令(安装和配置)
Bisher - based on SSM pet adoption center
sigaction的使用
[embedded module] OLED display module
[brush questions] most elements (super water king problem)
2022 tea master (intermediate) examination questions and analysis and tea master (intermediate) practical examination video
2022 tea master (intermediate) examination questions and analysis and tea master (intermediate) practical examination video
vim 的实用操作
2022 Shandong Province safety officer C certificate examination questions and Shandong Province safety officer C certificate simulation examination question bank
How does the pytorch project run?
Interface embedded in golang struct
pytorch难学吗?如何学好pytorch?
Download and install captura and configure ffmpeg in captura
深潜Kotlin协程(十九):Flow 概述
"Designer universe" argument: Data Optimization in the design field is finally reflected in cost, safety and health | chinabrand.com org
[daily question] dichotomy - find a single dog (Bushi)
DAPP for getting started with eth
Practical operation of vim
竞品分析撰写
Ffmpeg one / more pictures synthetic video