From e6e6bebdcd4e20b6afada3100295c2d8197798ae Mon Sep 17 00:00:00 2001 From: linbangquan <1437892690@qq.com> Date: Fri, 19 Jan 2024 18:16:41 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[=E4=BF=AE=E5=A4=8D]=20cmdb=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E5=90=8C=E6=AD=A5=E4=B8=AD=E5=85=B3=E7=B3=BB=E7=9A=84?= =?UTF-8?q?=E5=B1=80=E9=83=A8=E8=BF=BD=E5=8A=A0=E6=A8=A1=E5=BC=8F=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E7=94=9F=E6=95=88=EF=BC=8C=E7=8E=B0=E5=9C=A8=E5=8F=AA?= =?UTF-8?q?=E6=9C=89=E6=9B=BF=E6=8D=A2=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1072485003395072]cmdb节点同步中关系的局部追加模式没有生效,现在只有替换效果 http://192.168.0.96:8090/demo/rdm.html#/bug-detail/939050947543040/939050947543057/1072485003395072 --- .../stephandler/CmdbSyncProcessComponent.java | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) 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 d6bf66f5..2c523f2c 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(); @@ -675,6 +680,8 @@ public class CmdbSyncProcessComponent extends ProcessStepHandlerBase { Long ciId = mainConfigObj.getCiId(); String uuid = mainConfigObj.getUuid(); CiEntityTransactionVo ciEntityTransactionVo = ciEntityTransactionMap.get(uuid); + + List relList = RelUtil.ClearRepeatRel(relMapper.getRelByCiId(ciId)); for (RelVo relVo : relList) { String key = "rel" + relVo.getDirection() + "_" + relVo.getId(); @@ -684,6 +691,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++) { @@ -710,7 +739,6 @@ public class CmdbSyncProcessComponent extends ProcessStepHandlerBase { valueObj.put("action", RelActionType.REPLACE.getValue()); } } - Long ciEntityId = valueObj.getLong("ciEntityId"); if (ciEntityId == null) { CiEntityTransactionVo tmpVo = ciEntityTransactionMap.get(ciEntityUuid); @@ -719,7 +747,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 +1508,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 +1516,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) { -- Gitee From 169de4358448522813cd8efea3fbb4447ced4a62 Mon Sep 17 00:00:00 2001 From: linbangquan <1437892690@qq.com> Date: Fri, 19 Jan 2024 18:19:02 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[=E4=BF=AE=E5=A4=8D]=20cmdb=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E5=90=8C=E6=AD=A5=E4=B8=AD=E5=85=B3=E7=B3=BB=E7=9A=84?= =?UTF-8?q?=E5=B1=80=E9=83=A8=E8=BF=BD=E5=8A=A0=E6=A8=A1=E5=BC=8F=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E7=94=9F=E6=95=88=EF=BC=8C=E7=8E=B0=E5=9C=A8=E5=8F=AA?= =?UTF-8?q?=E6=9C=89=E6=9B=BF=E6=8D=A2=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1072485003395072]cmdb节点同步中关系的局部追加模式没有生效,现在只有替换效果 http://192.168.0.96:8090/demo/rdm.html#/bug-detail/939050947543040/939050947543057/1072485003395072 --- .../cmdb/process/stephandler/CmdbSyncProcessComponent.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 2c523f2c..8ed3c5b0 100644 --- a/src/main/java/neatlogic/module/cmdb/process/stephandler/CmdbSyncProcessComponent.java +++ b/src/main/java/neatlogic/module/cmdb/process/stephandler/CmdbSyncProcessComponent.java @@ -680,8 +680,6 @@ public class CmdbSyncProcessComponent extends ProcessStepHandlerBase { Long ciId = mainConfigObj.getCiId(); String uuid = mainConfigObj.getUuid(); CiEntityTransactionVo ciEntityTransactionVo = ciEntityTransactionMap.get(uuid); - - List relList = RelUtil.ClearRepeatRel(relMapper.getRelByCiId(ciId)); for (RelVo relVo : relList) { String key = "rel" + relVo.getDirection() + "_" + relVo.getId(); @@ -739,6 +737,7 @@ public class CmdbSyncProcessComponent extends ProcessStepHandlerBase { valueObj.put("action", RelActionType.REPLACE.getValue()); } } + Long ciEntityId = valueObj.getLong("ciEntityId"); if (ciEntityId == null) { CiEntityTransactionVo tmpVo = ciEntityTransactionMap.get(ciEntityUuid); -- Gitee