From ce447ffcdc305f34a109ab0374f29b615db2dbb2 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Tue, 24 Dec 2024 16:37:03 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E8=A7=86=E5=9B=BE=E6=B7=BB=E5=8A=A0=E5=BC=95=E7=94=A8?= =?UTF-8?q?=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1318860777553920]自定义视图添加引用列表 http://192.168.0.96:8090/demo/rdm.html#/task-detail/939050947543040/939050947543050/1318860777553920 --- .../customview/SearchPublicCustomViewApi.java | 13 ++ .../CiAttr2MatrixAttrDependencyHandler.java | 99 +++++++++++++++ .../CmdbCiMatrixDependencyHandler.java | 119 ++++++++++++++++++ ...mdbCustomView2MatrixDependencyHandler.java | 113 +++++++++++++++++ .../matrix/handler/CiDataSourceHandler.java | 2 +- 5 files changed, 345 insertions(+), 1 deletion(-) create mode 100644 src/main/java/neatlogic/module/cmdb/dependency/CiAttr2MatrixAttrDependencyHandler.java create mode 100644 src/main/java/neatlogic/module/cmdb/dependency/CmdbCiMatrixDependencyHandler.java create mode 100644 src/main/java/neatlogic/module/cmdb/dependency/CmdbCustomView2MatrixDependencyHandler.java diff --git a/src/main/java/neatlogic/module/cmdb/api/customview/SearchPublicCustomViewApi.java b/src/main/java/neatlogic/module/cmdb/api/customview/SearchPublicCustomViewApi.java index f799def7..03f24da9 100644 --- a/src/main/java/neatlogic/module/cmdb/api/customview/SearchPublicCustomViewApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/customview/SearchPublicCustomViewApi.java @@ -20,9 +20,11 @@ import com.alibaba.fastjson.JSONObject; import neatlogic.framework.auth.core.AuthAction; import neatlogic.framework.cmdb.auth.label.CUSTOMVIEW_MODIFY; import neatlogic.framework.cmdb.dto.customview.CustomViewVo; +import neatlogic.framework.cmdb.enums.CmdbFromType; import neatlogic.framework.cmdb.enums.customview.CustomViewType; import neatlogic.framework.common.constvalue.ApiParamType; import neatlogic.framework.common.dto.BasePageVo; +import neatlogic.framework.dependency.core.DependencyManager; import neatlogic.framework.restful.annotation.*; import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; @@ -32,6 +34,8 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; @Service @AuthAction(action = CUSTOMVIEW_MODIFY.class) @@ -72,6 +76,15 @@ public class SearchPublicCustomViewApi extends PrivateApiComponentBase { CustomViewVo customViewVo = JSON.toJavaObject(paramObj, CustomViewVo.class); customViewVo.setType(CustomViewType.PUBLIC.getValue()); List viewList = customViewService.searchCustomView(customViewVo); + List idList = viewList.stream().map(CustomViewVo::getId).collect(Collectors.toList()); + Map countMap = DependencyManager.getBatchDependencyCount(CmdbFromType.CMDBCUSTOMVIEW, idList); + for (CustomViewVo customView : viewList) { + Integer count = countMap.get(customView.getId()); + if (count == null) { + count = 0; + } + customView.setReferenceCount(count); + } return TableResultUtil.getResult(viewList, customViewVo); } diff --git a/src/main/java/neatlogic/module/cmdb/dependency/CiAttr2MatrixAttrDependencyHandler.java b/src/main/java/neatlogic/module/cmdb/dependency/CiAttr2MatrixAttrDependencyHandler.java new file mode 100644 index 00000000..33307dba --- /dev/null +++ b/src/main/java/neatlogic/module/cmdb/dependency/CiAttr2MatrixAttrDependencyHandler.java @@ -0,0 +1,99 @@ +/* + * 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.dependency; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.asynchronization.threadlocal.TenantContext; +import neatlogic.framework.cmdb.enums.CmdbFromType; +import neatlogic.framework.dependency.core.DefaultDependencyHandlerBase; +import neatlogic.framework.dependency.core.IFromType; +import neatlogic.framework.dependency.dto.DependencyInfoVo; +import neatlogic.framework.dependency.dto.DependencyVo; +import neatlogic.framework.matrix.dao.mapper.MatrixMapper; +import neatlogic.framework.matrix.dto.MatrixCiVo; +import neatlogic.framework.matrix.dto.MatrixVo; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; + +/** + * 矩阵属性引用cmdbci模型属性或关系 + * @author linbq + * @since 2022/1/11 13:05 + **/ +@Component +public class CiAttr2MatrixAttrDependencyHandler extends DefaultDependencyHandlerBase { + + @Resource + private MatrixMapper matrixMapper; + + @Override + protected DependencyInfoVo parse(DependencyVo dependencyVo) { + JSONObject config = dependencyVo.getConfig(); + if (MapUtils.isNotEmpty(config)) { + String matrixUuid = config.getString("matrixUuid"); + if (StringUtils.isNotBlank(matrixUuid)) { + MatrixVo matrixVo = matrixMapper.getMatrixByUuid(matrixUuid); + if (matrixVo != null) { + MatrixCiVo matrixCiVo = matrixMapper.getMatrixCiByMatrixUuid(matrixUuid); + if (matrixCiVo != null) { + JSONObject matrixCiconfig = matrixCiVo.getConfig(); + if (MapUtils.isNotEmpty(matrixCiconfig)) { + JSONArray showAttributeArray = matrixCiconfig.getJSONArray("showAttributeList"); + if (CollectionUtils.isNotEmpty(showAttributeArray)) { + for (int i = 0; i < showAttributeArray.size(); i++) { + JSONObject showAttributeObj = showAttributeArray.getJSONObject(i); + if (MapUtils.isNotEmpty(showAttributeObj)) { + String label = showAttributeObj.getString("label"); + if (label.endsWith(dependencyVo.getFrom())) { + JSONObject dependencyInfoConfig = new JSONObject(); + dependencyInfoConfig.put("matrixUuid", matrixVo.getUuid()); + dependencyInfoConfig.put("matrixName", matrixVo.getName()); + dependencyInfoConfig.put("matrixType", matrixVo.getType()); + String toName = showAttributeObj.getString("name"); +// dependencyInfoConfig.put("attributeName", toName); + List pathList = new ArrayList<>(); + pathList.add("矩阵管理"); + pathList.add(matrixVo.getName()); + String lastName = toName; +// String pathFormat = "矩阵-${DATA.matrixName}-${DATA.attributeName}"; + String urlFormat = "/" + TenantContext.get().getTenantUuid() + "/framework.html#/matrix-view-edit?uuid=${DATA.matrixUuid}&name=${DATA.matrixName}&type=${DATA.matrixType}"; + return new DependencyInfoVo(matrixVo.getUuid(), dependencyInfoConfig, lastName, pathList, urlFormat, this.getGroupName()); + } + } + } + } + } + } + } + } + } + return null; + } + + @Override + public IFromType getFromType() { + return CmdbFromType.CMDBCIATTR; + } +} diff --git a/src/main/java/neatlogic/module/cmdb/dependency/CmdbCiMatrixDependencyHandler.java b/src/main/java/neatlogic/module/cmdb/dependency/CmdbCiMatrixDependencyHandler.java new file mode 100644 index 00000000..e0aa21c5 --- /dev/null +++ b/src/main/java/neatlogic/module/cmdb/dependency/CmdbCiMatrixDependencyHandler.java @@ -0,0 +1,119 @@ +/* + * 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.dependency; + +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.asynchronization.threadlocal.TenantContext; +import neatlogic.framework.cmdb.enums.CmdbFromType; +import neatlogic.framework.dependency.core.CustomDependencyHandlerBase; +import neatlogic.framework.dependency.core.IFromType; +import neatlogic.framework.dependency.dto.DependencyInfoVo; +import neatlogic.framework.matrix.dao.mapper.MatrixMapper; +import neatlogic.framework.matrix.dto.MatrixVo; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * 矩阵引用cmdb模型 + * + * @author: linbq + * @since: 2021/4/6 15:21 + **/ +@Service +public class CmdbCiMatrixDependencyHandler extends CustomDependencyHandlerBase { + + @Resource + private MatrixMapper matrixMapper; + + /** + * 表名 + * + * @return + */ + @Override + protected String getTableName() { + return "matrix_ci"; + } + + /** + * 被引用者(上游)字段 + * + * @return + */ + @Override + protected String getFromField() { + return "ci_id"; + } + + /** + * 引用者(下游)字段 + * + * @return + */ + @Override + protected String getToField() { + return "matrix_uuid"; + } + + @Override + protected List getToFieldList() { + return null; + } + + /** + * 解析数据,拼装跳转url,返回引用下拉列表一个选项数据结构 + * + * @param dependencyObj 引用关系数据 + * @return + */ + @Override + protected DependencyInfoVo parse(Object dependencyObj) { + if (dependencyObj instanceof Map) { + Map map = (Map) dependencyObj; + String matrixUuid = (String) map.get("matrix_uuid"); + MatrixVo matrixVo = matrixMapper.getMatrixByUuid(matrixUuid); + if (matrixVo != null) { + JSONObject dependencyInfoConfig = new JSONObject(); + dependencyInfoConfig.put("matrixUuid", matrixVo.getUuid()); + dependencyInfoConfig.put("matrixName", matrixVo.getName()); + dependencyInfoConfig.put("matrixType", matrixVo.getType()); + List pathList = new ArrayList<>(); + pathList.add("矩阵管理"); + String lastName = matrixVo.getName(); +// String pathFormat = "矩阵-${DATA.matrixName}"; + String urlFormat = "/" + TenantContext.get().getTenantUuid() + "/framework.html#/matrix-view-edit?uuid=${DATA.matrixUuid}&name=${DATA.matrixName}&type=${DATA.matrixType}"; + return new DependencyInfoVo(matrixVo.getUuid(), dependencyInfoConfig, lastName, pathList, urlFormat, this.getGroupName()); + } + } + return null; + } + + /** + * 被引用者(上游)类型 + * + * @return + */ + @Override + public IFromType getFromType() { + return CmdbFromType.CMDBCI; + } +} diff --git a/src/main/java/neatlogic/module/cmdb/dependency/CmdbCustomView2MatrixDependencyHandler.java b/src/main/java/neatlogic/module/cmdb/dependency/CmdbCustomView2MatrixDependencyHandler.java new file mode 100644 index 00000000..f2469a68 --- /dev/null +++ b/src/main/java/neatlogic/module/cmdb/dependency/CmdbCustomView2MatrixDependencyHandler.java @@ -0,0 +1,113 @@ +/* + * 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.dependency; + +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.asynchronization.threadlocal.TenantContext; +import neatlogic.framework.cmdb.enums.CmdbFromType; +import neatlogic.framework.dependency.core.CustomDependencyHandlerBase; +import neatlogic.framework.dependency.core.IFromType; +import neatlogic.framework.dependency.dto.DependencyInfoVo; +import neatlogic.framework.matrix.dao.mapper.MatrixMapper; +import neatlogic.framework.matrix.dto.MatrixVo; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +@Component +public class CmdbCustomView2MatrixDependencyHandler extends CustomDependencyHandlerBase { + + @Resource + private MatrixMapper matrixMapper; + + /** + * 表名 + * + * @return + */ + @Override + protected String getTableName() { + return "matrix_cmdb_custom_view"; + } + + /** + * 被引用者(上游)字段 + * + * @return + */ + @Override + protected String getFromField() { + return "custom_view_id"; + } + + /** + * 引用者(下游)字段 + * + * @return + */ + @Override + protected String getToField() { + return "matrix_uuid"; + } + + @Override + protected List getToFieldList() { + return null; + } + + /** + * 解析数据,拼装跳转url,返回引用下拉列表一个选项数据结构 + * + * @param dependencyObj 引用关系数据 + * @return + */ + @Override + protected DependencyInfoVo parse(Object dependencyObj) { + if (dependencyObj instanceof Map) { + Map map = (Map) dependencyObj; + String matrixUuid = (String) map.get("matrix_uuid"); + MatrixVo matrixVo = matrixMapper.getMatrixByUuid(matrixUuid); + if (matrixVo != null) { + JSONObject dependencyInfoConfig = new JSONObject(); + dependencyInfoConfig.put("matrixUuid", matrixVo.getUuid()); + dependencyInfoConfig.put("matrixName", matrixVo.getName()); + dependencyInfoConfig.put("matrixType", matrixVo.getType()); + List pathList = new ArrayList<>(); + pathList.add("矩阵管理"); + String lastName = matrixVo.getName(); +// String pathFormat = "矩阵-${DATA.matrixName}"; + String urlFormat = "/" + TenantContext.get().getTenantUuid() + "/framework.html#/matrix-view-edit?uuid=${DATA.matrixUuid}&name=${DATA.matrixName}&type=${DATA.matrixType}"; + return new DependencyInfoVo(matrixVo.getUuid(), dependencyInfoConfig, lastName, pathList, urlFormat, this.getGroupName()); + } + } + return null; + } + + /** + * 被引用者(上游)类型 + * + * @return + */ + @Override + public IFromType getFromType() { + return CmdbFromType.CMDBCUSTOMVIEW; + } +} diff --git a/src/main/java/neatlogic/module/cmdb/matrix/handler/CiDataSourceHandler.java b/src/main/java/neatlogic/module/cmdb/matrix/handler/CiDataSourceHandler.java index cd49c4b8..680038bf 100644 --- a/src/main/java/neatlogic/module/cmdb/matrix/handler/CiDataSourceHandler.java +++ b/src/main/java/neatlogic/module/cmdb/matrix/handler/CiDataSourceHandler.java @@ -51,7 +51,7 @@ import neatlogic.module.cmdb.dao.mapper.cientity.RelEntityMapper; import neatlogic.module.cmdb.dao.mapper.globalattr.GlobalAttrMapper; import neatlogic.module.cmdb.matrix.constvalue.MatrixType; import neatlogic.module.cmdb.service.cientity.CiEntityService; -import neatlogic.module.framework.dependency.handler.CiAttr2MatrixAttrDependencyHandler; +import neatlogic.module.cmdb.dependency.CiAttr2MatrixAttrDependencyHandler; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; -- Gitee