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 695f3893f47797c0d42f1bf48595ed0d01fc1f0c..0000000000000000000000000000000000000000 --- 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 e1220678784d843e3bc7221c4fdc353d2f6b5853..65c9ef54c9f9d094e6c58f1b99bdff5f8ffbb298 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 061df3971eee70c67cbf41509a6c94823fc24005..ce40a4743aed3cef760a29a56cddfd459166a237 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 1a4ca8ba08f3a5317ed0d49e344a973a11e64bfe..29d1ceae280ca626105b338e21e0c4ad2457ebed 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 74d012acf1ea5bfc65a0921df6e271ebdff4992f..0000000000000000000000000000000000000000 --- 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 8d4c706592f5533c39ae9cc2b52f9c92888c78ea..dbd642242d64621cd0f84825012028228834364a 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 37bbc9bf3abcf66f0d1cae27029cc2b576641588..c66a645482db1da57d99d2cf12e1c2b43c5a68e3 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 2aea8b14af69c1988f65efb630d81ea34cda7eff..51e8ee800c19d1972a0e03b9074959288d669af2 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;