当前位置:网站首页>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楠哥
- SAP UI5 应用开发教程之一百零五 - SAP UI5 Master-Detail 布局模式的联动效果实现明细介绍
- CVPR 2022 | Dalian Institute of technology proposes a self calibration lighting framework for low light level image enhancement of real scenes
- 8.8.2-PointersOnC-20220214
- 学会pytorch能干什么?
- vim 的实用操作
- NPM: the 'NPM' item cannot be recognized as the name of a cmdlet, function, script file, or runnable program. Please check the spelling of the name. If the path is included, make sure the path is corr
- [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
- Web会话管理安全问题
- 2022 Shandong Province safety officer C certificate examination questions and Shandong Province safety officer C certificate simulation examination question bank
猜你喜欢
Bisher - based on SSM pet adoption center
Is pytorch open source?
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
nodejs基础:浅聊url和querystring模块
2022 P cylinder filling examination content and P cylinder filling practice examination video
[home push IMessage] software installation virtual host rental tothebuddy delay
"Designer universe" argument: Data Optimization in the design field is finally reflected in cost, safety and health | chinabrand.com org
SAP ui5 application development tutorial 105 - detailed introduction to the linkage effect implementation of SAP ui5 master detail layout mode
Simple wechat applet development page Jump, data binding, obtaining user information, obtaining user location information
『期末复习』16/32位微处理器(8086)基本寄存器
随机推荐
IPv6 foundation construction experiment
What is pytorch? Is pytorch a software?
Filter
Ffmpeg download and installation tutorial and introduction
Is pytorch open source?
@The difference between Autowired, @qualifier, @resource
CVPR 2022 | Dalian Technology propose un cadre d'éclairage auto - étalonné pour l'amélioration de l'image de faible luminosité de la scène réelle
Social phobia of contemporary young people (III)
TCP/IP模型中的重磅嘉宾TCP--尚文网络奎哥
如何迈向IPv6之IPv6过渡技术-尚文网络奎哥
leetcode:297. 二叉树的序列化与反序列化
IPv6 transition technology-6to4 manual tunnel configuration experiment -- Kuige of Shangwen network
China Mobile Internet of things oneos and onenet were selected in the list of 2021 Internet of things demonstration projects
阿洛对自己的思考
Ffmpeg one / more pictures synthetic video
Message queue addition failure
[Apple Photo Album push] IMessage group anchor local push
错误 C2694 “void Logger::log(nvinfer1::ILogger::Severity,const char *)”: 重写虚函数的限制性异常规范比基类虚成员函数
【刷题篇】接雨水(一维)
Practical operation of vim