From 72acfd19eb6198698779d8610fefce9cba3cec46 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Wed, 27 Mar 2024 11:46:45 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BF=AE=E5=A4=8D]=20=E7=9F=A9=E9=98=B5?= =?UTF-8?q?=E7=AE=A1=E7=90=86-=E5=AF=BC=E5=87=BA=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E8=A7=86=E5=9B=BE=E7=9F=A9=E9=98=B5=E7=9A=84=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1121049305907200]矩阵管理-导出自定义视图矩阵的数据失败 http://192.168.0.96:8090/demo/rdm.html#/bug-detail/939050947543040/939050947543057/1121049305907200 --- .../CmdbCustomViewDataSourceHandler.java | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/src/main/java/neatlogic/module/cmdb/matrix/handler/CmdbCustomViewDataSourceHandler.java b/src/main/java/neatlogic/module/cmdb/matrix/handler/CmdbCustomViewDataSourceHandler.java index 849a78f2..38baaa97 100644 --- a/src/main/java/neatlogic/module/cmdb/matrix/handler/CmdbCustomViewDataSourceHandler.java +++ b/src/main/java/neatlogic/module/cmdb/matrix/handler/CmdbCustomViewDataSourceHandler.java @@ -44,6 +44,7 @@ import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.io.IOException; +import java.io.OutputStream; import java.util.*; import java.util.stream.Collectors; @@ -177,6 +178,71 @@ public class CmdbCustomViewDataSourceHandler extends MatrixDataSourceHandlerBase return null; } + @Override + protected void myExportMatrix2CSV(MatrixVo matrixVo, OutputStream os) throws IOException { + String matrixUuid = matrixVo.getUuid(); + MatrixCmdbCustomViewVo matrixCmdbCustomViewVo = matrixMapper.getMatrixCmdbCustomViewByMatrixUuid(matrixUuid); + if (matrixCmdbCustomViewVo == null) { + throw new MatrixCmdbCustomViewNotFoundException(matrixUuid); + } + List matrixAttributeList = myGetAttributeList(matrixVo); + Map uuid2LabelMap = matrixAttributeList.stream().collect(Collectors.toMap(e -> e.getUuid(), e -> e.getLabel())); + JSONArray theadList = getTheadList(matrixAttributeList); + StringBuilder header = new StringBuilder(); + List headList = new ArrayList<>(); + for (int i = 0; i < theadList.size(); i++) { + JSONObject obj = theadList.getJSONObject(i); + String title = obj.getString("title"); + String key = obj.getString("key"); + if (StringUtils.isNotBlank(title) && StringUtils.isNotBlank(key)) { + header.append(title).append(","); + String label = uuid2LabelMap.get(key); + if (StringUtils.isNotBlank(label)) { + headList.add(label); + } + } + } + header.append("\n"); + os.write(header.toString().getBytes("GBK")); + os.flush(); + CustomViewConditionVo customViewConditionVo = new CustomViewConditionVo(); + customViewConditionVo.setCustomViewId(matrixCmdbCustomViewVo.getCustomViewId()); + customViewConditionVo.setCurrentPage(1); + customViewConditionVo.setPageSize(1000); + List> dataList = customViewDataService.searchCustomViewData(customViewConditionVo); + Integer rowNum = customViewConditionVo.getRowNum(); + if (rowNum > 0) { + int currentPage = 1; + Integer pageCount = customViewConditionVo.getPageCount(); + while (currentPage <= pageCount) { + List> list = new ArrayList<>(); + if (currentPage == 1) { + list = dataList; + } else { + customViewConditionVo.setCurrentPage(currentPage); + list = customViewDataService.searchCustomViewData(customViewConditionVo); + } + if (CollectionUtils.isNotEmpty(list)) { + StringBuilder content = new StringBuilder(); + for (Map map : list) { + for (String head : headList) { + String value = null; + Object obj = map.get(head); + if (obj != null) { + value = obj.toString(); + } + content.append(value != null ? value.replaceAll("\n", "").replaceAll(",", ",") : StringUtils.EMPTY).append(","); + } + content.append("\n"); + } + os.write(content.toString().getBytes("GBK")); + os.flush(); + } + currentPage++; + } + } + } + @Override protected MatrixVo myExportMatrix(MatrixVo matrixVo) { myGetMatrix(matrixVo); -- Gitee