diff --git a/src/main/java/neatlogic/module/cmdb/process/stephandler/CmdbSyncProcessComponent.java b/src/main/java/neatlogic/module/cmdb/process/stephandler/CmdbSyncProcessComponent.java index d6bf66f5c632f334a47eb9d5b248c5edd682a243..8ed3c5b0ad525d72608beaf331ea9306bf9d2741 100644 --- a/src/main/java/neatlogic/module/cmdb/process/stephandler/CmdbSyncProcessComponent.java +++ b/src/main/java/neatlogic/module/cmdb/process/stephandler/CmdbSyncProcessComponent.java @@ -28,6 +28,7 @@ import neatlogic.framework.cmdb.dto.ci.CiVo; import neatlogic.framework.cmdb.dto.ci.RelVo; import neatlogic.framework.cmdb.dto.cientity.AttrFilterVo; import neatlogic.framework.cmdb.dto.cientity.CiEntityVo; +import neatlogic.framework.cmdb.dto.cientity.RelEntityVo; import neatlogic.framework.cmdb.dto.globalattr.GlobalAttrItemVo; import neatlogic.framework.cmdb.dto.globalattr.GlobalAttrVo; import neatlogic.framework.cmdb.dto.transaction.AttrEntityTransactionVo; @@ -63,6 +64,7 @@ import neatlogic.module.cmdb.dao.mapper.ci.AttrMapper; import neatlogic.module.cmdb.dao.mapper.ci.CiMapper; import neatlogic.module.cmdb.dao.mapper.ci.RelMapper; import neatlogic.module.cmdb.dao.mapper.cientity.CiEntityMapper; +import neatlogic.module.cmdb.dao.mapper.cientity.RelEntityMapper; import neatlogic.module.cmdb.dao.mapper.globalattr.GlobalAttrMapper; import neatlogic.module.cmdb.process.constvalue.CmdbAuditDetailType; import neatlogic.module.cmdb.process.dto.*; @@ -105,6 +107,9 @@ public class CmdbSyncProcessComponent extends ProcessStepHandlerBase { @Resource private CiEntityService ciEntityService; + @Resource + private RelEntityMapper relEntityMapper; + @Override public String getHandler() { return CmdbProcessStepHandlerType.CMDBSYNC.getHandler(); @@ -684,6 +689,28 @@ public class CmdbSyncProcessComponent extends ProcessStepHandlerBase { } String mappingMode = mappingObj.getMappingMode(); if (Objects.equals(mappingMode, "new")) {// 表示关系 + List alreadyExistRelList = new ArrayList<>(); + List ciEntityIdList = new ArrayList<>(); + List relEntityList; + if (relVo.getDirection().equals(RelDirectionType.FROM.getValue())) { + relEntityList = relEntityMapper.getRelEntityByFromCiEntityIdAndRelId(ciEntityTransactionVo.getCiEntityId(), relVo.getId(), null); + for (RelEntityVo relEntityVo : relEntityList) { + JSONObject jsonObj = new JSONObject(); + jsonObj.put("ciEntityId", relEntityVo.getToCiEntityId()); + jsonObj.put("ciEntityName", relEntityVo.getToCiEntityName()); + jsonObj.put("ciId", relEntityVo.getToCiId()); + alreadyExistRelList.add(jsonObj); + } + } else { + relEntityList = relEntityMapper.getRelEntityByToCiEntityIdAndRelId(ciEntityTransactionVo.getCiEntityId(), relVo.getId(), null); + for (RelEntityVo relEntityVo : relEntityList) { + JSONObject jsonObj = new JSONObject(); + jsonObj.put("ciEntityId", relEntityVo.getFromCiEntityId()); + jsonObj.put("ciEntityName", relEntityVo.getFromCiEntityName()); + jsonObj.put("ciId", relEntityVo.getFromCiId()); + alreadyExistRelList.add(jsonObj); + } + } JSONArray valueList = mappingObj.getValueList(); if (CollectionUtils.isNotEmpty(valueList)) { for (int i = 0; i < valueList.size(); i++) { @@ -719,7 +746,20 @@ public class CmdbSyncProcessComponent extends ProcessStepHandlerBase { valueObj.put("ciEntityId", ciEntityId); } } + ciEntityIdList.add(ciEntityId); } + } else { + valueList = new JSONArray(); + } + + // 关系选择追加模式时,需要将该配置项原来就关联的关系数据补充到valueList中 + for (JSONObject jsonObj : alreadyExistRelList) { + if (ciEntityIdList.contains(jsonObj.getLong("ciEntityId"))) { + continue; + } + valueList.add(jsonObj); + } + if (CollectionUtils.isNotEmpty(valueList)) { JSONObject relEntity = new JSONObject(); relEntity.put("valueList", valueList); relEntityData.put(key, relEntity); @@ -1467,6 +1507,7 @@ public class CmdbSyncProcessComponent extends ProcessStepHandlerBase { newConfigObj.setIsStart(currentConfig.getIsStart()); newConfigObj.setCiIcon(targetCi.getIcon()); newConfigObj.setEditMode(currentConfig.getEditMode()); + newConfigObj.setAction(currentConfig.getAction()); } else { newConfigObj.setCiId(currentConfig.getCiId()); newConfigObj.setCiName(currentConfig.getCiName()); @@ -1474,6 +1515,7 @@ public class CmdbSyncProcessComponent extends ProcessStepHandlerBase { newConfigObj.setIsStart(currentConfig.getIsStart()); newConfigObj.setCiIcon(currentConfig.getCiIcon()); newConfigObj.setEditMode(currentConfig.getEditMode()); + newConfigObj.setAction(currentConfig.getAction()); } List mappingList = currentConfig.getMappingList(); for (CiEntitySyncMappingVo mapping : mappingList) {