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 f799def70fe8d4d224a96a64a1d9ae76da7d8a21..03f24da95f849a5be8815ddca2d3d5c306a0cbb9 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 0000000000000000000000000000000000000000..33307dba3c287034ebc73c45a1a753ed4b1f5fd3 --- /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 0000000000000000000000000000000000000000..e0aa21c5b540a7b680bf01bc51c1ff5e1a8157ff --- /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 0000000000000000000000000000000000000000..f2469a6847f9772bf08d9c4a9d5ecae0700d2e52 --- /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 cd49c4b8e8776be99b8686c530696d6c78fa825d..680038bfd899e057c1bb0c80fe02bb9d8efe6185 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;