当前位置:网站首页>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文件导出
边栏推荐
- pytorch怎么下载?pytorch在哪里下载?
- Idea shortcut keys
- Web session management security issues
- 基于Pytorch和RDKit的QSAR模型建立脚本
- @The difference between Autowired, @qualifier, @resource
- 中移物联网OneOS与OneNET入选《2021年物联网示范项目名单》
- nodejs基础:浅聊url和querystring模块
- MPLS setup experiment
- 毕设-基于SSM宠物领养中心
- [Blue Bridge Road -- bug free code] DS18B20 temperature reading code analysis
猜你喜欢
105. Detailed introduction of linkage effect realization of SAP ui5 master detail layout mode
在写web项目的时候,文件上传用到了smartupload,用了new string()进行转码,但是在数据库中,还是会出现类似扑克的乱码
简易版 微信小程序开发之for指令、上传图片及展示效果优化
[home push IMessage] software installation virtual host rental tothebuddy delay
Leetcode: dynamic planning template
Web session management security issues
MPLS setup experiment
Bisher - based on SSM pet adoption center
递归:一维链表和数组
简易版 微信小程序开发之页面跳转、数据绑定、获取用户信息、获取用户位置信息
随机推荐
Web会话管理安全问题
Table structure of Navicat export database
Shardingsphere dynamic data source
小程序获取用户头像和昵称
pytorch开源吗?
递归使用和多维数组对象变一维数组对象
Half of 2022 is over, so we must hurry up
Nodejs Foundation: shallow chat URL and querystring module
ffmpeg录制屏幕和截屏
Without sxid, suid & sgid will be in danger- Shangwen network xUP Nange
[DRM] simple analysis of DRM bridge driver call process
错误 C2694 “void Logger::log(nvinfer1::ILogger::Severity,const char *)”: 重写虚函数的限制性异常规范比基类虚成员函数
Applet (continuous update)
第十届中国云计算大会·中国站:展望未来十年科技走向
Mysql Mac版下载安装教程
记一次 .NET 差旅管理后台 CPU 爆高分析
递归:快速排序,归并排序和堆排序
没有sXid,suid&sgid将进入险境!-尚文网络xUP楠哥
leetcode:动态规划模板
Error in compiled file: error: unmapped character encoding GBK