diff --git a/modules/thing/src/main/java/com/thing/thing/relation/detail/service/impl/IotThingRelationDetailServiceImpl.java b/modules/thing/src/main/java/com/thing/thing/relation/detail/service/impl/IotThingRelationDetailServiceImpl.java index 48eb186..fd5d6f0 100644 --- a/modules/thing/src/main/java/com/thing/thing/relation/detail/service/impl/IotThingRelationDetailServiceImpl.java +++ b/modules/thing/src/main/java/com/thing/thing/relation/detail/service/impl/IotThingRelationDetailServiceImpl.java @@ -996,14 +996,14 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl resList = list.stream().map(node -> { IotThingRelationDetailExcel excel = new IotThingRelationDetailExcel(); excel.setFromName(node.get("fromName").asText()); - excel.setFromCode(node.get("fromCode").isEmpty() ? "" : node.get("fromCode").asText()); + excel.setFromCode(node.get("fromCode").isNull() ? "" : node.get("fromCode").asText()); excel.setToName(node.get("toName").asText()); excel.setToCode(node.get("toCode").asText()); - excel.setConfig(node.get("config").isEmpty() ? "" : node.get("config").asText()); - excel.setRemark(node.get("remark").isEmpty() ? "" : node.get("remark").asText()); + excel.setConfig(node.get("config").isNull() ? "" : node.get("config").asText()); + excel.setRemark(node.get("remark").isNull() ? "" : node.get("remark").asText()); excel.setSort(node.get("sort").asLong()); - excel.setUrl(node.get("url").isEmpty() ? "" : node.get("url").asText()); - excel.setTag(node.get("tag").isEmpty() ? "" : node.get("tag").asText()); + excel.setUrl(node.get("url").isNull() ? "" : node.get("url").asText()); + excel.setTag(node.get("tag").isNull() ? "" : node.get("tag").asText()); long rootThingId = node.get("rootThingId").asLong(); IotThingEntityInfoDTO entity = thingEntitiesService.findEntityById(rootThingId); excel.setRootThingCode(entity.getCode()); @@ -1033,36 +1033,38 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl { - //关系名称 - if(!Objects.isNull(rootDTO)){ - IotThingRelationDetailEntity entity = new IotThingRelationDetailEntity(); + IotThingRelationDetailEntity entity = new IotThingRelationDetailEntity(); + //说明是第一节点 + if(StringUtils.equals(excel.getRootThingCode(),excel.getToCode()) && StringUtils.isBlank(excel.getFromCode())){ + entity.setFromId(rootDTO.getId()); + entity.setFromName(rootDTO.getName()); + }else{ IotThingEntity fromEntity = entities.stream().filter(e -> e.getCode().equals(excel.getFromCode())).findFirst().get(); - IotThingEntity toEntity = entities.stream().filter(e -> e.getCode().equals(excel.getToCode())).findFirst().get(); - IotThingEntity rootEntity = entities.stream().filter(e -> e.getCode().equals(excel.getRootThingCode())).findFirst().get(); - entity.setRootId(rootDTO.getId()); - entity.setFromCode(excel.getFromCode()); - entity.setFromCode(excel.getName()); entity.setFromId(fromEntity.getId()); - entity.setToCode(excel.getToCode()); - entity.setToName(excel.getToName()); - entity.setToId(toEntity.getId()); - entity.setConfig(excel.getConfig()); - entity.setConfig(excel.getRemark()); - entity.setSort(excel.getSort()); - entity.setRootThingId(rootEntity.getId()); - entity.setUrl(excel.getUrl()); - entity.setTag(excel.getTag()); - mapper.insert(entity); - ObjectNode node = JsonConverter.convertToJsonObjectObjectNode(ConvertUtils.sourceToTarget(entity, IotThingRelationDetailDTO.class)); - List mapAccurateKey = cache.findMapAccurateKey(CacheNameEnum.THING_MODEL, entity.getToCode()); - if (CollectionUtils.isNotEmpty(mapAccurateKey)) { - String status = mapAccurateKey.get(0).get(CacheNameEnum.ModelField.THING_MODEL_STATUS.getField()).asText(); - node.put("thingStatus", status); - } - cache.updateAccurateKeyMap(CacheNameEnum.THING_DETAIL_RELATION, - entity.getRootId() + CacheInit.KEY + entity.getId() + CacheInit.KEY + entity.getRootThingId(), node); - + entity.setFromName(excel.getFromName()); + entity.setFromCode(excel.getFromCode()); } + IotThingEntity toEntity = entities.stream().filter(e -> e.getCode().equals(excel.getToCode())).findFirst().get(); + IotThingEntity rootEntity = entities.stream().filter(e -> e.getCode().equals(excel.getRootThingCode())).findFirst().get(); + entity.setRootId(rootDTO.getId()); + entity.setToCode(excel.getToCode()); + entity.setToName(excel.getToName()); + entity.setToId(toEntity.getId()); + entity.setConfig(excel.getConfig()); + entity.setConfig(excel.getRemark()); + entity.setSort(excel.getSort()); + entity.setRootThingId(rootEntity.getId()); + entity.setUrl(excel.getUrl()); + entity.setTag(excel.getTag()); + mapper.insert(entity); + ObjectNode node = JsonConverter.convertToJsonObjectObjectNode(ConvertUtils.sourceToTarget(entity, IotThingRelationDetailDTO.class)); + List mapAccurateKey = cache.findMapAccurateKey(CacheNameEnum.THING_MODEL, entity.getToCode()); + if (CollectionUtils.isNotEmpty(mapAccurateKey)) { + String status = mapAccurateKey.get(0).get(CacheNameEnum.ModelField.THING_MODEL_STATUS.getField()).asText(); + node.put("thingStatus", status); + } + cache.updateAccurateKeyMap(CacheNameEnum.THING_DETAIL_RELATION, + entity.getRootId() + CacheInit.KEY + entity.getId() + CacheInit.KEY + entity.getRootThingId(), node); }); }