From e163714b5c5db622942bda930b720d1d936f5db2 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Fri, 11 Apr 2025 16:54:27 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E5=B7=A1=E6=A3=80=E9=9C=80=E5=AF=B9=E6=89=80=E6=9C=89=E8=AF=A5?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E4=B8=8B=E8=B5=84=E4=BA=A7=E5=B7=A1=E6=A3=80?= =?UTF-8?q?=E8=80=8C=E4=B8=8D=E6=98=AF=E5=AF=B9=E6=9C=89=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E7=9A=84=E8=B5=84=E4=BA=A7=E5=B7=A1=E6=A3=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1397023939461120]应用巡检需对所有该应用下资产巡检而不是对有问题的资产巡检 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1397023939461120 --- .../AppModuleResourceTypeListApi.java | 114 ------------------ .../mapper/resourcecenter/ResourceMapper.java | 2 +- .../mapper/resourcecenter/ResourceMapper.xml | 20 ++- ...ractCiTargetCiIdAttrNotFoundException.java | 4 - .../DataConversionAppendPathException.java | 11 -- .../DefaultResourceCenterDataSourceImpl.java | 46 ++++--- .../service/cientity/CiEntityServiceImpl.java | 26 +--- .../ResourceCenterResourceServiceImpl.java | 9 +- 8 files changed, 52 insertions(+), 180 deletions(-) delete mode 100644 src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/AppModuleResourceTypeListApi.java delete mode 100644 src/main/java/neatlogic/module/cmdb/process/exception/DataConversionAppendPathException.java diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/AppModuleResourceTypeListApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/AppModuleResourceTypeListApi.java deleted file mode 100644 index 695f3893..00000000 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/appmodule/AppModuleResourceTypeListApi.java +++ /dev/null @@ -1,114 +0,0 @@ -package neatlogic.module.cmdb.api.resourcecenter.appmodule; - -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import neatlogic.framework.auth.core.AuthAction; -import neatlogic.framework.cmdb.auth.label.CMDB; -import neatlogic.framework.cmdb.dto.ci.CiVo; -import neatlogic.framework.cmdb.dto.resourcecenter.ResourceVo; -import neatlogic.framework.cmdb.exception.ci.CiNotFoundException; -import neatlogic.framework.cmdb.resourcecenter.datasource.core.IResourceCenterDataSource; -import neatlogic.framework.cmdb.resourcecenter.datasource.core.ResourceCenterDataSourceFactory; -import neatlogic.framework.common.constvalue.ApiParamType; -import neatlogic.framework.common.dto.BasePageVo; -import neatlogic.framework.restful.annotation.*; -import neatlogic.framework.restful.constvalue.OperationTypeEnum; -import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; -import neatlogic.module.cmdb.dao.mapper.ci.CiMapper; -import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceMapper; -import org.apache.commons.collections4.CollectionUtils; -import org.springframework.stereotype.Service; - -import javax.annotation.Resource; -import java.util.*; - -/** - * @author longrf - * @date 2022/3/2 4:10 下午 - */ -@Service -@AuthAction(action = CMDB.class) -@OperationType(type = OperationTypeEnum.SEARCH) -public class AppModuleResourceTypeListApi extends PrivateApiComponentBase { - - @Resource - private CiMapper ciMapper; - - @Resource - ResourceMapper resourceMapper; - - @Override - public String getName() { - return "查询当前模块各环境的需要显示的模型列表"; - } - - @Override - public String getToken() { - return "resourcecenter/appmodule/resource/type/list"; - } - - @Override - public String getConfig() { - return null; - } - - @Override - public boolean disableReturnCircularReferenceDetect() { - return true; - } - - @Input({ - @Param(name = "appModuleId", type = ApiParamType.LONG, isRequired = true, desc = "应用模块id(实例id)") - }) - @Output({ - @Param(desc = "当前模块各环境的需要显示的模型列表") - }) - @Description(desc = "当前模块各环境的需要显示的模型列表") - @Override - public Object myDoService(JSONObject paramObj) throws Exception { - JSONArray returnArray = new JSONArray(); - Long appModuleId = paramObj.getLong("appModuleId"); - List envResourceList = new ArrayList<>(); - BasePageVo search = new BasePageVo(); - search.setCurrentPage(1); - search.setPageSize(100); - List envIdList = resourceMapper.searchAppEnvIdList(search); - if (CollectionUtils.isNotEmpty(envIdList)) { - envResourceList = resourceMapper.searchAppEnvListByIdList(envIdList); - } - //获取数据库所有的模型,用于通过id去获得对应的模型 - Map allCiVoMap = new HashMap<>(); - List allCiVoList = ciMapper.getAllCi(null); - for (CiVo ci : allCiVoList) { - allCiVoMap.put(ci.getId(), ci); - } - //无配置环境 - ResourceVo noSettingEnvResourceVo = new ResourceVo(); - noSettingEnvResourceVo.setId(-2L); - noSettingEnvResourceVo.setName("未配置"); - envResourceList.add(noSettingEnvResourceVo); - for (ResourceVo envResource : envResourceList) { - JSONObject returnObj = new JSONObject(); - Set typeIdSet = new HashSet<>(); - IResourceCenterDataSource resourceCenterDataSource = ResourceCenterDataSourceFactory.getResourceCenterDataSource(); - Map> viewName2TypeIdListMap = resourceCenterDataSource.getAppResourceTypeIdListByAppSystemIdAndAppModuleIdAndEnvId(null, appModuleId, envResource.getId()); - for (Map.Entry> entry : viewName2TypeIdListMap.entrySet()) { - typeIdSet.addAll(entry.getValue()); - } - Set returnCiVoSet = new HashSet<>(); - for (Long typeId : typeIdSet) { - CiVo ciVo = allCiVoMap.get(typeId); - if (ciVo == null) { - throw new CiNotFoundException(typeId); - } - returnCiVoSet.add(ciVo); - } - if (CollectionUtils.isNotEmpty(returnCiVoSet)) { - returnObj.put("env", envResource); - returnObj.put("ciVoList", returnCiVoSet); - returnArray.add(returnObj); - } - } - return returnArray; - } -} diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.java b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.java index e1220678..65c9ef54 100644 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.java +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.java @@ -163,7 +163,7 @@ public interface ResourceMapper extends IResourceCrossoverMapper { List getAppSystemListByKeyword(BasePageVo searchVo); - List getAppEnvListByViewNameAndAppSystemIdAndInspectStatusList(@Param("viewName") String viewName, @Param("appSystemId") Long appSystemId, @Param("inspectStatusList") List inspectStatusList); + List getAppEnvListByViewNameAndAppSystemIdAndAppModuleIdAndInspectStatusList(@Param("viewName") String viewName, @Param("appSystemId") Long appSystemId, @Param("appModuleId") Long appModuleId, @Param("inspectStatusList") List inspectStatusList); List getAppEnvListByAppSystemIdAndAppModuleId(@Param("appSystemId") Long appSystemId, @Param("appModuleId") Long appModuleId); diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml index 061df397..ce40a474 100644 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml @@ -1586,24 +1586,34 @@ along with this program. If not, see .--> - + - SELECT IFNULL(a.env_id, -2) as id, IFNULL(a.env_name, '未配置') as name, IFNULL(a.env_seq_no, 9999) as seqNo, a.app_module_id as moduleId, a.app_module_name as moduleName, - a.app_module_abbr_name as moduleAbbrName + a.app_module_abbr_name as moduleAbbrName, + a.type_id as typeId, + a.type_name as typeName, + a.type_label as typeLabel FROM @{DATA_SCHEMA}.`${viewName}` a WHERE a.`app_system_id` = #{appSystemId} - AND a.app_module_id is not null + + + AND a.app_module_id = #{appModuleId} + + + AND a.app_module_id is not null + + AND a.`inspect_status` IN diff --git a/src/main/java/neatlogic/module/cmdb/process/exception/AbstractCiTargetCiIdAttrNotFoundException.java b/src/main/java/neatlogic/module/cmdb/process/exception/AbstractCiTargetCiIdAttrNotFoundException.java index 1a4ca8ba..29d1ceae 100644 --- a/src/main/java/neatlogic/module/cmdb/process/exception/AbstractCiTargetCiIdAttrNotFoundException.java +++ b/src/main/java/neatlogic/module/cmdb/process/exception/AbstractCiTargetCiIdAttrNotFoundException.java @@ -8,8 +8,4 @@ public class AbstractCiTargetCiIdAttrNotFoundException extends ApiRuntimeExcepti public AbstractCiTargetCiIdAttrNotFoundException(CiVo ciVo) { super("nmcpe.abstractcitargetciidattrnotfoundexception.abstractcitargetciidattrnotfoundexception", ciVo.getLabel(), ciVo.getName()); } - - public AbstractCiTargetCiIdAttrNotFoundException(CiVo ciVo, String configurationPath, String actualPath) { - super("nmcpe.abstractcitargetciidattrnotfoundexception.abstractcitargetciidattrnotfoundexception_b", ciVo.getLabel(), ciVo.getName(), configurationPath, actualPath); - } } diff --git a/src/main/java/neatlogic/module/cmdb/process/exception/DataConversionAppendPathException.java b/src/main/java/neatlogic/module/cmdb/process/exception/DataConversionAppendPathException.java deleted file mode 100644 index 74d012ac..00000000 --- a/src/main/java/neatlogic/module/cmdb/process/exception/DataConversionAppendPathException.java +++ /dev/null @@ -1,11 +0,0 @@ -package neatlogic.module.cmdb.process.exception; - -import neatlogic.framework.exception.core.ApiRuntimeException; -import neatlogic.framework.util.$; - -public class DataConversionAppendPathException extends ApiRuntimeException { - - public DataConversionAppendPathException(Exception e, String configurationPath, String actualPath) { - super($.t("nmcpe.dataconversionappendpathexception.dataconversionappendpathexception", configurationPath, actualPath, e.getMessage()), e); - } -} diff --git a/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java b/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java index 8d4c7065..dbd64224 100644 --- a/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java +++ b/src/main/java/neatlogic/module/cmdb/resourcecenter/datasource/handler/DefaultResourceCenterDataSourceImpl.java @@ -1049,21 +1049,19 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS } @Override - public List getAppEnvListByAppSystemIdAndInspectStatusList(Long appSystemId, List inspectStatusList) { + public List getAppEnvListByAppSystemIdAndAppModuleIdAndInspectStatusList(Long appSystemId, Long appModuleId, List inspectStatusList) { List resultList = new ArrayList<>(); Map appEnvMap = new HashMap<>(); - Map appModuleMap = new HashMap<>(); - Map> appEnvId2AppModuleIdListMap = new HashMap<>(); + Map> appEnvId2AppModuleListMap = new HashMap<>(); List appViewList = getAppViewList(); for (ResourceEntityVo resourceEntityVo : appViewList) { - List appEnvList = resourceMapper.getAppEnvListByViewNameAndAppSystemIdAndInspectStatusList(resourceEntityVo.getName(), appSystemId, inspectStatusList); + List appEnvList = resourceMapper.getAppEnvListByViewNameAndAppSystemIdAndAppModuleIdAndInspectStatusList(resourceEntityVo.getName(), appSystemId, appModuleId, inspectStatusList); for (AppEnvVo appEnvVo : appEnvList) { appEnvMap.put(appEnvVo.getId(), appEnvVo); List appModuleList = appEnvVo.getAppModuleList(); if (CollectionUtils.isNotEmpty(appModuleList)) { for (AppModuleVo appModuleVo : appModuleList) { - appModuleMap.put(appModuleVo.getId(), appModuleVo); - appEnvId2AppModuleIdListMap.computeIfAbsent(appEnvVo.getId(), key -> new HashSet<>()).add(appModuleVo.getId()); + appEnvId2AppModuleListMap.computeIfAbsent(appEnvVo.getId(), key -> new ArrayList<>()).add(appModuleVo); } } @@ -1071,18 +1069,30 @@ public class DefaultResourceCenterDataSourceImpl implements IResourceCenterDataS } for (Map.Entry entry : appEnvMap.entrySet()) { AppEnvVo appEnvVo = entry.getValue(); - List appModuleList = new ArrayList<>(); - Set appModuleIdSet = appEnvId2AppModuleIdListMap.get(appEnvVo.getId()); - for (Long appModuleId : appModuleIdSet) { - AppModuleVo appModuleVo = appModuleMap.get(appModuleId); - AppModuleVo appModule = new AppModuleVo(); - appModule.setId(appModuleVo.getId()); - appModule.setName(appModuleVo.getName()); - appModule.setAbbrName(appModuleVo.getAbbrName()); - appModuleList.add(appModule); - } - appModuleList.sort(Comparator.comparing(AppModuleVo::getId)); - appEnvVo.setAppModuleList(appModuleList); + Map appModuleMap = new HashMap<>(); + List appModuleList = appEnvId2AppModuleListMap.get(appEnvVo.getId()); + for (AppModuleVo appModuleVo : appModuleList) { + AppModuleVo appModule = appModuleMap.get(appModuleVo.getId()); + if (appModule == null) { + appModule = new AppModuleVo(); + appModule.setId(appModuleVo.getId()); + appModule.setName(appModuleVo.getName()); + appModule.setAbbrName(appModuleVo.getAbbrName()); + List ciList = new ArrayList<>(); + if (CollectionUtils.isNotEmpty(appModuleVo.getCiList())) { + ciList.addAll(appModuleVo.getCiList()); + } + appModule.setCiList(ciList); + appModuleMap.put(appModuleVo.getId(), appModule); + } else { + if (CollectionUtils.isNotEmpty(appModuleVo.getCiList())) { + appModule.getCiList().addAll(appModuleVo.getCiList()); + } + } + } + List mergeAppModuleList = new ArrayList<>(appModuleMap.values()); + mergeAppModuleList.sort(Comparator.comparing(AppModuleVo::getId)); + appEnvVo.setAppModuleList(mergeAppModuleList); resultList.add(appEnvVo); } resultList.sort(Comparator.comparing(AppEnvVo::getSeqNo)); diff --git a/src/main/java/neatlogic/module/cmdb/service/cientity/CiEntityServiceImpl.java b/src/main/java/neatlogic/module/cmdb/service/cientity/CiEntityServiceImpl.java index 37bbc9bf..c66a6454 100644 --- a/src/main/java/neatlogic/module/cmdb/service/cientity/CiEntityServiceImpl.java +++ b/src/main/java/neatlogic/module/cmdb/service/cientity/CiEntityServiceImpl.java @@ -67,7 +67,6 @@ import neatlogic.module.cmdb.dao.mapper.globalattr.GlobalAttrMapper; import neatlogic.module.cmdb.dao.mapper.transaction.TransactionMapper; import neatlogic.module.cmdb.fulltextindex.enums.CmdbFullTextIndexType; import neatlogic.module.cmdb.group.CiEntityGroupManager; -import neatlogic.module.cmdb.process.exception.DataConversionAppendPathException; import neatlogic.module.cmdb.relativerel.RelativeRelManager; import neatlogic.module.cmdb.service.ci.CiAuthChecker; import neatlogic.module.cmdb.utils.CiEntityBuilder; @@ -675,27 +674,10 @@ public class CiEntityServiceImpl implements CiEntityService, ICiEntityCrossoverS } for (CiEntityTransactionVo ciEntityTransactionVo : ciEntityTransactionList) { - try { - Long transactionId = saveCiEntity(ciEntityTransactionVo, transactionGroupVo); - if (transactionId > 0L) { - transactionMapper.insertTransactionGroup(transactionGroupVo.getId(), transactionId); - hasTransaction = true; - } - } catch (Exception e) { - if (CollectionUtils.isNotEmpty(ciEntityTransactionVo.getConfigurationPathList()) - || CollectionUtils.isNotEmpty(ciEntityTransactionVo.getActualPathList())) { - String configurationPath = ""; - if (CollectionUtils.isNotEmpty(ciEntityTransactionVo.getConfigurationPathList())) { - configurationPath = String.join(",", ciEntityTransactionVo.getConfigurationPathList()); - } - String actualPath = ""; - if (CollectionUtils.isNotEmpty(ciEntityTransactionVo.getActualPathList())) { - actualPath = String.join(",", ciEntityTransactionVo.getActualPathList()); - } - throw new DataConversionAppendPathException(e, configurationPath, actualPath); - } else { - throw e; - } + Long transactionId = saveCiEntity(ciEntityTransactionVo, transactionGroupVo); + if (transactionId > 0L) { + transactionMapper.insertTransactionGroup(transactionGroupVo.getId(), transactionId); + hasTransaction = true; } } } diff --git a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java index 2aea8b14..51e8ee80 100644 --- a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java +++ b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java @@ -44,9 +44,11 @@ import neatlogic.framework.transaction.core.EscapeTransactionJob; import neatlogic.framework.util.Md5Util; import neatlogic.module.cmdb.dao.mapper.ci.AttrMapper; import neatlogic.module.cmdb.dao.mapper.ci.CiMapper; -import neatlogic.module.cmdb.dao.mapper.cientity.CiEntityMapper; import neatlogic.module.cmdb.dao.mapper.globalattr.GlobalAttrMapper; -import neatlogic.module.cmdb.dao.mapper.resourcecenter.*; +import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceAccountMapper; +import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceEntityMapper; +import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceMapper; +import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceTagMapper; import neatlogic.module.cmdb.utils.ResourceEntityFactory; import net.sf.jsqlparser.schema.Table; import net.sf.jsqlparser.statement.create.table.ColDataType; @@ -85,9 +87,6 @@ public class ResourceCenterResourceServiceImpl implements IResourceCenterResourc @Resource private GlobalAttrMapper globalAttrMapper; - @Resource - private CiEntityMapper ciEntityMapper; - @Resource private ResourceEntityMapper resourceEntityMapper; -- Gitee