当前位置: 首页 > news >正文

更新积木报表2.0.0注意事项

一、导出接口变更

导出接口由原来的/jmreport/exportPdfStream更新为/jmreport/exportReport。具体见官方文档;

1、旧接口springboot实现报表生成并存储pdf文件

public String exportPdf(@RequestParam(name = "id", required = true) String id, @RequestParam(name = "excelConfigId", required = true)String excelConfigId, @RequestParam(name = "rootPath", required = true)String rootPath,@RequestParam(name = "url") String url) {// 1、创建url路径 RestUtil.getBaseUrl():你的地址String url = RestUtil.getBaseUrl() + "/jmreport/exportPdfStream";Map<String, Object> map = new HashMap<>();JSONObject object = new JSONObject();// 2、此处为示例,需要传递api和sql的正确参数值object.put("id", id); //积木报表中sql的传参map.put("excelConfigId", excelConfigId); //积木报表idmap.put("queryParam", object);HTTPHeaders headers = new HttpHeaders);headers.add("Content-Type", "application/JSON;charset=UTF-8");HttpEntity<Map<String, Object>> httpEntity = new HttpEntity<>(map, headers);String filePath = "";try {// 3、调用积木报表接口Resource apiResult = restTemplateConfig.restTemplateHttps().postForObject(url, httpEntity, Resource.class);// 4、拿到流InputStream inputStream = apiResult.getInputStream();byte[] bytes = IOUtils.toByteArray(inputStream);String s = "data:application/pdf;base64," + Base64.getEncoder().encodeToString(bytes);ByteArrayInputStream stream = null;BASE64Decoder decoder = new BASE64Decoder();byte[] bt = decoder.decodeBuffer(s);stream = new ByteArrayInputStream(bt);// 5、存储到minio中filePath = MinioUtil.upload(stream,rootPath+"/"+id+".pdf");// 6、关闭流inputStream.close();} catch (RestClientException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();} catch (Exception e) {e.printStackTrace();}return filePath;

2、新接口实现

public String exportYbSbPdf(@RequestParam(name = "batchId", required = true) String batchId, @RequestParam(name = "communityId", required = true) String communityId, @RequestParam(name = "excelConfigId", required = true)String excelConfigId, @RequestParam(name = "rootPath", required = true)String rootPath,@RequestParam(name = "url", required = true)String url) {String filePath = "";try {// 查询参数JSONObject queryParam = new JSONObject();queryParam.put("batchId", batchId);queryParam.put("communityId", communityId);// 请求参数Map<String, Object> exportParams = new HashMap<>();exportParams.put("reportId", excelConfigId);exportParams.put("exportType", "pdf");exportParams.put("queryParam", queryParam);Map<String,Object> map = new HashMap<>();List<Map<String, Object>> list = new ArrayList<>();list.add(exportParams);map.put("exportParams", JSONObject.toJSONString(list));// 请求头HTTPHeaders headers = new HttpHeaders);headers.add("Content-Type", "application/JSON;charset=UTF-8");HttpEntity<Map<String, Object>> httpEntity = new HttpEntity<>(map, headers);url = "你的地址/jmreport/exportReport" + "?token="+((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest().getHeader("X-Access-Token")+"&exportParams=" + UriEncoder.encode(JSONObject.toJSONString(list));ResponseEntity<byte[]> responseEntity = restTemplateConfig.restTemplateHttps().getForEntity(url, byte[].class, httpEntity);if (responseEntity.getStatusCode().is2xxSuccessful()) {byte[] body = responseEntity.getBody();if (body == null || body.length == 0) {throw new RuntimeException("导出内容为空");}ByteArrayInputStream inputStream = new ByteArrayInputStream(body);byte[] bytes = IOUtils.toByteArray(inputStream);String s = "data:application/pdf;base64," + Base64.getEncoder().encodeToString(bytes);ByteArrayInputStream stream = null;BASE64Decoder decoder = new BASE64Decoder();byte[] bt = decoder.decodeBuffer(s);stream = new ByteArrayInputStream(bt);filePath = MinioUtil.upload(stream,rootPath+"/"+batchId+"_"+communityId+".pdf");inputStream.close();} else {throw new RuntimeException("导出失败,HTTP状态码:" + responseEntity.getStatusCode());}} catch (RestClientException | IOException e) {e.printStackTrace();throw new RuntimeException("调用报表导出接口失败:" + e.getMessage());} catch (Exception e) {throw new RuntimeException(e);}return filePath;}

二、积木报表导出pdf出现第一个下面出现大量空白

先说结论:此问题是由于"自动换行"导致的。给单元格设置自动换行其实就是允许单元格根据内容自动调整高度,那么打印时会有以下问题:

  • 单元格自动换行导致当前页面高度超出1页纸了,打印时会将该单元格调整至下一页打印,那么当前页的尾部就会出现部分空白区域:
    在这里插入图片描述

三、积木报表中sql解析后数据类型不正确会导致数据无法预览

解决方案:非必要不填数据类型即可。

四、自我反思

1、升级版本时候要认真阅读升级日志及注意事项;
2、及时查询“调用接口”是否更改;
3、对于上述②③问题,我首先着手通过查看源码以寻求解决方案,最后碰巧解决;因为对于积木报表还是以官方文档为主寻找解决方式。

http://www.xdnf.cn/news/939439.html

相关文章:

  • 第八章 信息安全基础知识
  • 大三下第16周总结
  • 华为OD机考-内存冷热标记-多条件排序
  • 4、docker常用命令
  • 前端八股笔记
  • 设备驱动与文件系统:05 文件使用磁盘的实现
  • 2025-05-01-决策树算法及应用
  • Kotlin REPL初探
  • 单片机 传感器知识讲解 (一)红外避障模块,声控模块,人体红外模块
  • 9.贪心算法(随想录)
  • 电子学会Python考前英语单词
  • art-template模板引擎
  • SpringCloudAlibaba和SpringBoot版本问题
  • 【差分】详解二维前缀和和差分问题
  • [mdm9607] Qualcomm mdm9607新增nand flash支持修改方法
  • Docker部署MySQL
  • Elasticsearch 常用操作命令整合 (cURL 版本)
  • C++.OpenGL (17/64)模型(Model)
  • 堆排序code
  • 第三章 AI应用开发
  • 探秘Transformer系列之(36)--- 大模型量化方案
  • OpenEuler 系统中 WordPress 部署深度指南
  • Pandas中常用函数
  • 2025年- H78-Lc186--763.划分字符串区间(贪心)--Java版
  • 分类数据集 - 场景分类数据集下载
  • Langchian - 实现文本分类实际应用
  • 【Java学习笔记】System类
  • vite ts 配置使用@ 允许js
  • 基于SpringBoot实现的大创管理系统设计与实现【源码+文档】
  • 「Java基本语法」标识符、关键字与常量