From 9d596be4e5d7099ff68168efab840dcc08fcdb32 Mon Sep 17 00:00:00 2001 From: zhaoybc Date: Tue, 4 Jan 2022 10:43:28 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=A0=BC=E5=8A=A8=E6=80=81=E8=A7=A3=E6=9E=90=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20=E5=8E=9F=E6=9C=89=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=9A1=E3=80=81=E6=97=A0=E6=B3=95=E5=8E=9F=E6=A0=B7?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E6=95=B0=E6=8D=AE=EF=BC=9B2=E3=80=81?= =?UTF-8?q?=E5=8A=A8=E6=80=81=E6=89=A9=E5=B1=95=E4=BC=9A=E8=A6=86=E7=9B=96?= =?UTF-8?q?=E5=90=8E=E9=9D=A2=E8=A1=8C=E6=95=B0=E7=9A=84=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ReportExcelServiceImpl.java | 58 +++++++++---------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/service/impl/ReportExcelServiceImpl.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/service/impl/ReportExcelServiceImpl.java index 21117400..211a5360 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/service/impl/ReportExcelServiceImpl.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/service/impl/ReportExcelServiceImpl.java @@ -254,6 +254,10 @@ public class ReportExcelServiceImpl implements ReportExcelService { if (dbObject.containsKey("celldata") && null != dbObject.get("celldata")) { List celldata = new ArrayList<>(); celldata.addAll((List) dbObject.get("celldata")); + //清除原有的数据 + dbObject.getJSONArray("celldata").clear(); + //定义存储每一列动态扩展的行数 + Map colAddCntMap = new HashMap<>(); // 遍历已存在的单元格,查看是否存在动态参数 for (int i = 0; i < celldata.size(); i++) { //单元格对象 @@ -269,50 +273,46 @@ public class ReportExcelServiceImpl implements ReportExcelService { if (null != cell && cell.containsKey("v") && StringUtils.isNotBlank(cell.getString("v"))) { String v = cell.getString("v"); DataSetDto dataSet = getDataSet(v, setParam); + + //获取此行已经动态增加的行数,默认0行 + int cnt = colAddCntMap.get(c) == null ? 0 : colAddCntMap.get(c); + if (null != dataSet) { OriginalDataDto originalDataDto = dataSetService.getData(dataSet); if (null != originalDataDto.getData()) { List data = originalDataDto.getData(); for (int j = 0; j < data.size(); j++) { - if (j == 0) { - //处理当前行 - //第一行,作为渲染参照数据 - JSONObject jsonObject = data.get(j); - String fieldLabel = jsonObject.getString(dataSet.getFieldLabel()); - - String replace = v.replace("#{".concat(dataSet.getSetCode()).concat(".").concat(dataSet.getFieldLabel()).concat("}"), fieldLabel); - dbObject.getJSONArray("celldata").getJSONObject(i).getJSONObject("v").put("v", replace); - dbObject.getJSONArray("celldata").getJSONObject(i).getJSONObject("v").put("m", replace); - } else { - //新增的行数据 - JSONObject addCell = data.get(j); - //字段 - String fieldLabel = addCell.getString(dataSet.getFieldLabel()); - String replace = v.replace("#{".concat(dataSet.getSetCode()).concat(".").concat(dataSet.getFieldLabel()).concat("}"), fieldLabel); - //转字符串,解决深拷贝问题 - JSONObject addCellData = JSONObject.parseObject(cellStr); + //新增的行数据 + JSONObject addCell = data.get(j); + //字段 + String fieldLabel = addCell.getString(dataSet.getFieldLabel()); + String replace = v.replace("#{".concat(dataSet.getSetCode()).concat(".").concat(dataSet.getFieldLabel()).concat("}"), fieldLabel); - addCellData.put("r", r + j); - addCellData.put("c", c); - addCellData.getJSONObject("v").put("v", replace); - addCellData.getJSONObject("v").put("m", replace); - dbObject.getJSONArray("celldata").add(addCellData); - - } + //转字符串,解决深拷贝问题 + JSONObject addCellData = JSONObject.parseObject(cellStr); + addCellData.put("r", cnt + r + j); //行数增加 + addCellData.put("c", c); + addCellData.getJSONObject("v").put("v", replace); + addCellData.getJSONObject("v").put("m", replace); + dbObject.getJSONArray("celldata").add(addCellData); } - + //单元格数据动态赋值之后记录此列动态增加的行数 + colAddCntMap.put(c,cnt+data.size() - 1); } - + }else{ + //没有对应的数据源,增加动态行数之后原样输出 + //转字符串,解决深拷贝问题 + JSONObject addCellData = JSONObject.parseObject(cellStr); + addCellData.put("r", cnt + r);//行数增加 + addCellData.put("c", c); //列数不变 + dbObject.getJSONArray("celldata").add(addCellData); } } } - } - - }