From e59e5559dd03fa19030a7a54a26e5870791cfbbd Mon Sep 17 00:00:00 2001
From: linbangquan <1437892690@qq.com>
Date: Wed, 20 Mar 2024 18:15:28 +0800
Subject: [PATCH 1/7] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E7=B3=BB=E7=BB=9F?=
=?UTF-8?q?=E8=AE=BE=E7=BD=AE-=E7=9F=A9=E9=98=B5-=E6=95=B0=E6=8D=AE?=
=?UTF-8?q?=E6=BA=90=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89=E8=A7=86?=
=?UTF-8?q?=E5=9B=BE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
关联 #[1115260319137792]系统设置-矩阵-数据源增加自定义视图 http://192.168.0.96:8090/demo/rdm.html#/task-detail/939050947543040/939050947543050/1115260319137792
---
.../cmdb/matrix/constvalue/MatrixType.java | 4 +-
.../CmdbCustomViewDataSourceHandler.java | 145 ++++++++++++++++++
2 files changed, 148 insertions(+), 1 deletion(-)
create mode 100644 src/main/java/neatlogic/module/cmdb/matrix/handler/CmdbCustomViewDataSourceHandler.java
diff --git a/src/main/java/neatlogic/module/cmdb/matrix/constvalue/MatrixType.java b/src/main/java/neatlogic/module/cmdb/matrix/constvalue/MatrixType.java
index 63d42ce4..1c625703 100644
--- a/src/main/java/neatlogic/module/cmdb/matrix/constvalue/MatrixType.java
+++ b/src/main/java/neatlogic/module/cmdb/matrix/constvalue/MatrixType.java
@@ -23,7 +23,9 @@ import neatlogic.framework.util.$;
* @since 2021/11/16 15:21
**/
public enum MatrixType implements IMatrixType {
- CMDBCI("cmdbci", "配置项", "ciId", 4);
+ CMDBCI("cmdbci", "配置项", "ciId", 4),
+ CMDBCUSTOMVIEW("cmdbcustomview", "自定义视图", "customViewId", 5)
+ ;
private String value;
private String name;
diff --git a/src/main/java/neatlogic/module/cmdb/matrix/handler/CmdbCustomViewDataSourceHandler.java b/src/main/java/neatlogic/module/cmdb/matrix/handler/CmdbCustomViewDataSourceHandler.java
new file mode 100644
index 00000000..31e22525
--- /dev/null
+++ b/src/main/java/neatlogic/module/cmdb/matrix/handler/CmdbCustomViewDataSourceHandler.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2024 深圳极向量科技有限公司 All Rights Reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package neatlogic.module.cmdb.matrix.handler;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import neatlogic.framework.cmdb.dto.customview.CustomViewVo;
+import neatlogic.framework.exception.type.ParamNotExistsException;
+import neatlogic.framework.matrix.core.MatrixDataSourceHandlerBase;
+import neatlogic.framework.matrix.dto.MatrixAttributeVo;
+import neatlogic.framework.matrix.dto.MatrixDataVo;
+import neatlogic.framework.matrix.dto.MatrixVo;
+import neatlogic.module.cmdb.dao.mapper.customview.CustomViewMapper;
+import neatlogic.module.cmdb.matrix.constvalue.MatrixType;
+import neatlogic.module.cmdb.service.customview.CustomViewDataService;
+import neatlogic.module.cmdb.workerdispatcher.exception.CmdbDispatcherDispatchFailedException;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.collections4.MapUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.annotation.Resource;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+@Component
+public class CmdbCustomViewDataSourceHandler extends MatrixDataSourceHandlerBase {
+
+ private final static Logger logger = LoggerFactory.getLogger(CmdbCustomViewDataSourceHandler.class);
+
+ @Resource
+ private CustomViewMapper customViewMapper;
+
+ @Resource
+ private CustomViewDataService customViewDataService;
+
+ @Override
+ public String getHandler() {
+ return MatrixType.CMDBCUSTOMVIEW.getValue();
+ }
+
+ @Override
+ protected boolean mySaveMatrix(MatrixVo matrixVo) throws Exception {
+ Long customViewId = matrixVo.getCustomViewId();
+ if (customViewId != null) {
+ throw new ParamNotExistsException("customViewId");
+ }
+ CustomViewVo customView = customViewMapper.getCustomViewById(customViewId);
+ if (customView == null) {
+ throw new CmdbDispatcherDispatchFailedException(customViewId);
+ }
+ JSONObject config = matrixVo.getConfig();
+ if (MapUtils.isEmpty(config)) {
+ throw new ParamNotExistsException("config");
+ }
+ JSONArray showAttributeLabelArray = config.getJSONArray("showAttributeLabelList");
+ if (CollectionUtils.isEmpty(showAttributeLabelArray)) {
+ throw new ParamNotExistsException("config.showAttributeLabelList");
+ }
+ return false;
+ }
+
+ @Override
+ protected void myGetMatrix(MatrixVo matrixVo) {
+
+ }
+
+ @Override
+ protected void myDeleteMatrix(String uuid) {
+
+ }
+
+ @Override
+ protected void myCopyMatrix(String sourceUuid, MatrixVo matrixVo) {
+
+ }
+
+ @Override
+ protected JSONObject myImportMatrix(MatrixVo matrixVo, MultipartFile multipartFile) throws IOException {
+ return null;
+ }
+
+ @Override
+ protected MatrixVo myExportMatrix(MatrixVo matrixVo) {
+ return null;
+ }
+
+ @Override
+ protected void myImportMatrix(MatrixVo matrixVo) {
+
+ }
+
+ @Override
+ protected void mySaveAttributeList(String matrixUuid, List matrixAttributeList) {
+
+ }
+
+ @Override
+ protected List myGetAttributeList(MatrixVo matrixVo) {
+ return null;
+ }
+
+ @Override
+ protected JSONObject myExportAttribute(MatrixVo matrixVo) {
+ return null;
+ }
+
+ @Override
+ protected JSONObject myTableDataSearch(MatrixDataVo dataVo) {
+ return null;
+ }
+
+ @Override
+ protected JSONObject mySaveTableRowData(String matrixUuid, JSONObject rowData) {
+ return null;
+ }
+
+ @Override
+ protected Map myGetTableRowData(MatrixDataVo matrixDataVo) {
+ return null;
+ }
+
+ @Override
+ protected void myDeleteTableRowData(String matrixUuid, List uuidList) {
+
+ }
+}
--
Gitee
From b8f1ac69be337b42e99329a81fec6f5ca7cedbcb Mon Sep 17 00:00:00 2001
From: "1437892690@qq.com" <1437892690@qq.com>
Date: Thu, 21 Mar 2024 16:20:00 +0800
Subject: [PATCH 2/7] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E7=B3=BB=E7=BB=9F?=
=?UTF-8?q?=E8=AE=BE=E7=BD=AE-=E7=9F=A9=E9=98=B5-=E6=95=B0=E6=8D=AE?=
=?UTF-8?q?=E6=BA=90=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89=E8=A7=86?=
=?UTF-8?q?=E5=9B=BE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
关联 #[1115260319137792]系统设置-矩阵-数据源增加自定义视图 http://192.168.0.96:8090/demo/rdm.html#/task-detail/939050947543040/939050947543050/1115260319137792
---
.../CmdbCustomViewDataSourceHandler.java | 237 +++++++++++++++++-
1 file changed, 229 insertions(+), 8 deletions(-)
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 31e22525..9e4d9698 100644
--- a/src/main/java/neatlogic/module/cmdb/matrix/handler/CmdbCustomViewDataSourceHandler.java
+++ b/src/main/java/neatlogic/module/cmdb/matrix/handler/CmdbCustomViewDataSourceHandler.java
@@ -20,17 +20,24 @@ package neatlogic.module.cmdb.matrix.handler;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import neatlogic.framework.cmdb.dto.customview.CustomViewVo;
+import neatlogic.framework.cmdb.exception.customview.CustomViewNotFoundException;
+import neatlogic.framework.dependency.core.DependencyManager;
import neatlogic.framework.exception.type.ParamNotExistsException;
import neatlogic.framework.matrix.core.MatrixDataSourceHandlerBase;
import neatlogic.framework.matrix.dto.MatrixAttributeVo;
+import neatlogic.framework.matrix.dto.MatrixCmdbCustomViewVo;
import neatlogic.framework.matrix.dto.MatrixDataVo;
import neatlogic.framework.matrix.dto.MatrixVo;
+import neatlogic.framework.matrix.exception.MatrixCmdbCustomViewNotFoundException;
+import neatlogic.framework.util.UuidUtil;
import neatlogic.module.cmdb.dao.mapper.customview.CustomViewMapper;
import neatlogic.module.cmdb.matrix.constvalue.MatrixType;
import neatlogic.module.cmdb.service.customview.CustomViewDataService;
import neatlogic.module.cmdb.workerdispatcher.exception.CmdbDispatcherDispatchFailedException;
+import neatlogic.module.framework.dependency.handler.CiAttr2MatrixAttrDependencyHandler;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
+import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@@ -38,8 +45,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOException;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
@Component
public class CmdbCustomViewDataSourceHandler extends MatrixDataSourceHandlerBase {
@@ -75,17 +81,127 @@ public class CmdbCustomViewDataSourceHandler extends MatrixDataSourceHandlerBase
if (CollectionUtils.isEmpty(showAttributeLabelArray)) {
throw new ParamNotExistsException("config.showAttributeLabelList");
}
- return false;
+ Map oldShowAttributeUuidMap = new HashMap<>();
+ MatrixCmdbCustomViewVo oldMatrixCmdbCustomViewVo = matrixMapper.getMatrixCmdbCustomViewByMatrixUuid(matrixVo.getUuid());
+ if (oldMatrixCmdbCustomViewVo != null) {
+ if (customViewId.equals(oldMatrixCmdbCustomViewVo.getCustomViewId())) {
+ JSONObject oldConfig = oldMatrixCmdbCustomViewVo.getConfig();
+ if (MapUtils.isNotEmpty(oldConfig)) {
+ JSONArray oldShowAttributeUuidArray = oldConfig.getJSONArray("showAttributeLabelList");
+ if (CollectionUtils.isNotEmpty(oldShowAttributeUuidArray)) {
+ if (CollectionUtils.isEqualCollection(oldShowAttributeUuidArray, showAttributeLabelArray)) {
+ return false;
+ }
+ JSONArray showAttributeArray = oldConfig.getJSONArray("showAttributeList");
+ if (CollectionUtils.isNotEmpty(showAttributeArray)) {
+ for (int i = 0; i < showAttributeArray.size(); i++) {
+ JSONObject showAttributeObj = showAttributeArray.getJSONObject(i);
+ if (MapUtils.isNotEmpty(showAttributeObj)) {
+ String uuid = showAttributeObj.getString("uuid");
+ if (uuid != null) {
+ oldShowAttributeUuidMap.put(showAttributeObj.getString("label"), uuid);
+ DependencyManager.delete(CiAttr2MatrixAttrDependencyHandler.class, uuid);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+// CiViewVo searchVo = new CiViewVo();
+// searchVo.setCiId(ciId);
+// Map ciViewMap = new HashMap<>();
+// List ciViewList = RelUtil.ClearCiViewRepeatRel(ciViewMapper.getCiViewByCiId(searchVo));
+// for (CiViewVo ciview : ciViewList) {
+// switch (ciview.getType()) {
+// case "attr":
+// ciViewMap.put("attr_" + ciview.getItemId(), ciview);
+// break;
+// case "relfrom":
+// ciViewMap.put("relfrom_" + ciview.getItemId(), ciview);
+// break;
+// case "relto":
+// ciViewMap.put("relto_" + ciview.getItemId(), ciview);
+// break;
+// case "const":
+// //固化属性需要特殊处理
+// ciViewMap.put("const_" + ciview.getItemName().replace("_", ""), ciview);
+// break;
+// }
+// }
+ JSONArray showAttributeArray = new JSONArray();
+ if (!showAttributeLabelArray.contains("const_id")) {
+ showAttributeLabelArray.add(0, "const_id");
+ }
+ Iterator