From ffe9f57c7fb04fd1c20d767df9364afab3608ac4 Mon Sep 17 00:00:00 2001 From: linbangquan <1437892690@qq.com> Date: Sun, 21 Jan 2024 17:04:30 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BF=AE=E5=A4=8D]=20cmdb=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=B8=AD=E5=85=B3=E7=B3=BB=E7=9A=84=E5=B1=80?= =?UTF-8?q?=E9=83=A8=E8=BF=BD=E5=8A=A0=E6=A8=A1=E5=BC=8F=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E7=94=9F=E6=95=88=EF=BC=8C=E7=8E=B0=E5=9C=A8=E5=8F=AA=E6=9C=89?= =?UTF-8?q?=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 | 67 +++++++++++-------- 1 file changed, 40 insertions(+), 27 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 8ed3c5b0..1fefb6b4 100644 --- a/src/main/java/neatlogic/module/cmdb/process/stephandler/CmdbSyncProcessComponent.java +++ b/src/main/java/neatlogic/module/cmdb/process/stephandler/CmdbSyncProcessComponent.java @@ -38,7 +38,6 @@ import neatlogic.framework.cmdb.exception.attr.AttrNotFoundException; import neatlogic.framework.cmdb.exception.attr.AttrValueIrregularException; import neatlogic.framework.cmdb.exception.attrtype.AttrTypeNotFoundException; import neatlogic.framework.cmdb.exception.ci.*; -import neatlogic.framework.cmdb.exception.globalattr.GlobalAttrValueIrregularException; import neatlogic.framework.cmdb.utils.RelUtil; import neatlogic.framework.common.constvalue.Expression; import neatlogic.framework.common.constvalue.InputFrom; @@ -691,24 +690,27 @@ public class CmdbSyncProcessComponent extends ProcessStepHandlerBase { 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); + if (Objects.equals(mainConfigObj.getEditMode(), EditModeType.PARTIAL.getValue()) + && !Objects.equals(mainConfigObj.getAction(), "replace")) { + 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(); @@ -784,9 +786,11 @@ public class CmdbSyncProcessComponent extends ProcessStepHandlerBase { String key = "global_" + globalAttrVo.getId(); CiEntitySyncMappingVo mappingObj = mappingMap.get(key); if (mappingObj == null) { - JSONObject globalAttrEntity = new JSONObject(); - globalAttrEntity.put("valueList", new JSONArray()); - globalAttrEntityData.put(key, globalAttrEntity); + if (Objects.equals(mainConfigObj.getEditMode(), EditModeType.GLOBAL.getValue())) { + JSONObject globalAttrEntity = new JSONObject(); + globalAttrEntity.put("valueList", new JSONArray()); + globalAttrEntityData.put(key, globalAttrEntity); + } continue; } JSONArray valueList = new JSONArray(); @@ -798,7 +802,7 @@ public class CmdbSyncProcessComponent extends ProcessStepHandlerBase { if (valueObj instanceof JSONObject) { valueList.add(valueObj); } else { - boolean flag = false; +// boolean flag = false; List itemList = globalAttrVo.getItemList(); for (GlobalAttrItemVo item : itemList) { if (Objects.equals(item.getValue(), valueObj) @@ -809,12 +813,12 @@ public class CmdbSyncProcessComponent extends ProcessStepHandlerBase { jsonObj.put("sort", item.getSort()); jsonObj.put("attrId", globalAttrVo.getId()); valueList.add(jsonObj); - flag = true; +// flag = true; } } - if (!flag) { - throw new GlobalAttrValueIrregularException(globalAttrVo, valueObj.toString()); - } +// if (!flag) { +// throw new GlobalAttrValueIrregularException(globalAttrVo, valueObj.toString()); +// } } } } @@ -1540,6 +1544,9 @@ public class CmdbSyncProcessComponent extends ProcessStepHandlerBase { } IFormCrossoverService formCrossoverService = CrossoverServiceFactory.getApi(IFormCrossoverService.class); String handler = formCrossoverService.getFormAttributeHandler(attributeUuid, formConfig); + if (handler == null) { + return null; + } if (Objects.equals(handler, FormHandler.FORMUPLOAD.getHandler())) { JSONArray resultList = new JSONArray(); if (originalValue instanceof JSONArray) { @@ -1637,8 +1644,14 @@ public class CmdbSyncProcessComponent extends ProcessStepHandlerBase { JSONObject rowDataObj = tempList.getJSONObject(i); for (Map.Entry entry : rowDataObj.entrySet()) { Object valueObj = formAttributeDataAdaptsToCmdb(entry.getKey(), entry.getValue(), formConfig); + if (valueObj == null) { + continue; + } newRowDataObj.put(entry.getKey(), valueObj); } + if (MapUtils.isEmpty(newRowDataObj)) { + continue; + } resultList.add(newRowDataObj); } return resultList; -- Gitee