From 28a7c6a35174768f558a0b77379444b72aca1b28 Mon Sep 17 00:00:00 2001 From: lishuai Date: Mon, 30 Sep 2024 11:10:14 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=A9=E5=85=B3=E7=B3=BB=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=202024=E5=B9=B49=E6=9C=8830=E6=97=A511:10:04?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IotThingRelationDetailServiceImpl.java | 92 +++++++++++++++---- 1 file changed, 74 insertions(+), 18 deletions(-) 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 b1511f0..976618f 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 @@ -281,8 +281,14 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl mapAccurateKey = cache.findMapAccurateKey(CacheNameEnum.THING_MODEL, item.getToCode()); + if (CollectionUtils.isNotEmpty(mapAccurateKey)) { + String status = mapAccurateKey.get(0).get(CacheNameEnum.ModelField.THING_MODEL_STATUS.getField()).asText(); + node.put(CacheNameEnum.ModelField.THING_MODEL_STATUS.getField(), status); + } + cache.updateAccurateKeyMap(CacheNameEnum.THING_DETAIL_RELATION, + item.getRootId() + CacheInit.KEY + item.getId() + CacheInit.KEY + item.getRootThingId(), node); }); } @@ -355,8 +361,17 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl cache.updateAccurateKeyEntity(CacheNameEnum.THING_DETAIL_RELATION, - entity.getRootId()+CacheInit.KEY+entity.getId()+CacheInit.KEY+entity.getRootThingId(),ConvertUtils.sourceToTarget(entity, IotThingRelationDetailDTO.class))); + list.forEach(entity -> + { + ObjectNode node = JsonConverter.convertToJsonObjectObjectNode(entity); + 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(CacheNameEnum.ModelField.THING_MODEL_STATUS.getField(), status); + } + cache.updateAccurateKeyMap(CacheNameEnum.THING_DETAIL_RELATION, + entity.getRootId() + CacheInit.KEY + entity.getId() + CacheInit.KEY + entity.getRootThingId(), node); + }); } @Transactional(rollbackFor = Exception.class) @@ -367,13 +382,17 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl mapAccurateKey = cache.findMapAccurateKey(CacheNameEnum.THING_MODEL, sourceEntity.getToCode()); + if(CollectionUtils.isNotEmpty(mapAccurateKey)){ + String status = mapAccurateKey.get(0).get(CacheNameEnum.ModelField.THING_MODEL_STATUS.getField()).asText(); + node.put(CacheNameEnum.ModelField.THING_MODEL_STATUS.getField(), status); + } + cache.updateAccurateKeyMap(CacheNameEnum.THING_DETAIL_RELATION, + sourceEntity.getRootId()+CacheInit.KEY+sourceEntity.getId()+CacheInit.KEY+sourceEntity.getRootThingId(),node); } else { IotThingRelationDetailEntity targetEntity = mapper.selectOneById(dto.getPid()); if (Objects.isNull(targetEntity)) { @@ -384,8 +403,14 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl mapAccurateKey = cache.findMapAccurateKey(CacheNameEnum.THING_MODEL, sourceEntity.getToCode()); + if(CollectionUtils.isNotEmpty(mapAccurateKey)){ + String status = mapAccurateKey.get(0).get(CacheNameEnum.ModelField.THING_MODEL_STATUS.getField()).asText(); + node.put(CacheNameEnum.ModelField.THING_MODEL_STATUS.getField(), status); + } + cache.updateAccurateKeyMap(CacheNameEnum.THING_DETAIL_RELATION, + sourceEntity.getRootId()+CacheInit.KEY+sourceEntity.getId()+CacheInit.KEY+sourceEntity.getRootThingId(),node); }else{ //查询当前关系下所有节点信息 List iotThingRelationDetailEntities = mapper.selectListByQuery(QueryWrapper.create().eq(IotThingRelationDetailEntity::getRootId, dto.getRootId())); @@ -430,8 +455,14 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl mapAccurateKey = cache.findMapAccurateKey(CacheNameEnum.THING_MODEL, sourceEntity.getToCode()); + if(CollectionUtils.isNotEmpty(mapAccurateKey)){ + String status = mapAccurateKey.get(0).get(CacheNameEnum.ModelField.THING_MODEL_STATUS.getField()).asText(); + node.put(CacheNameEnum.ModelField.THING_MODEL_STATUS.getField(), status); + } + cache.updateAccurateKeyMap(CacheNameEnum.THING_DETAIL_RELATION, + sourceEntity.getRootId()+CacheInit.KEY+sourceEntity.getId()+CacheInit.KEY+sourceEntity.getRootThingId(),node); } ); } @@ -544,8 +575,17 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl item.setSort(sort.getAndIncrement())); this.updateBatch(resultList); //更新缓存 - resultList.forEach(s -> cache.updateAccurateKeyEntity(CacheNameEnum.THING_DETAIL_RELATION, - s.getRootId()+CacheInit.KEY+s.getId()+CacheInit.KEY+s.getRootThingId(),ConvertUtils.sourceToTarget(s, IotThingRelationDetailDTO.class))); + resultList.forEach(s -> + { + ObjectNode node = JsonConverter.convertToJsonObjectObjectNode(s); + List mapAccurateKey = cache.findMapAccurateKey(CacheNameEnum.THING_MODEL, s.getToCode()); + if (CollectionUtils.isNotEmpty(mapAccurateKey)) { + String status = mapAccurateKey.get(0).get(CacheNameEnum.ModelField.THING_MODEL_STATUS.getField()).asText(); + node.put(CacheNameEnum.ModelField.THING_MODEL_STATUS.getField(), status); + } + cache.updateAccurateKeyMap(CacheNameEnum.THING_DETAIL_RELATION, + s.getRootId() + CacheInit.KEY + s.getId() + CacheInit.KEY + s.getRootThingId(), node); + }); } @Override @@ -578,8 +618,17 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl item.setSort(sort1.getAndIncrement())); this.updateBatch(reslutList); //更新缓存 - reslutList.forEach(s -> cache.updateAccurateKeyEntity(CacheNameEnum.THING_DETAIL_RELATION, - s.getRootId()+CacheInit.KEY+s.getId()+CacheInit.KEY+s.getRootThingId(),ConvertUtils.sourceToTarget(s, IotThingRelationDetailDTO.class))); + reslutList.forEach(s -> + { + ObjectNode node = JsonConverter.convertToJsonObjectObjectNode(s); + List mapAccurateKey = cache.findMapAccurateKey(CacheNameEnum.THING_MODEL, s.getToCode()); + if (CollectionUtils.isNotEmpty(mapAccurateKey)) { + String status = mapAccurateKey.get(0).get(CacheNameEnum.ModelField.THING_MODEL_STATUS.getField()).asText(); + node.put(CacheNameEnum.ModelField.THING_MODEL_STATUS.getField(), status); + } + cache.updateAccurateKeyMap(CacheNameEnum.THING_DETAIL_RELATION, + s.getRootId() + CacheInit.KEY + s.getId() + CacheInit.KEY + s.getRootThingId(), node); + }); } @Override @@ -609,8 +658,15 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl mapAccurateKey = cache.findMapAccurateKey(CacheNameEnum.THING_MODEL, s.getToCode()); + if (CollectionUtils.isNotEmpty(mapAccurateKey)) { + String status = mapAccurateKey.get(0).get(CacheNameEnum.ModelField.THING_MODEL_STATUS.getField()).asText(); + node.put(CacheNameEnum.ModelField.THING_MODEL_STATUS.getField(), status); + } + cache.updateAccurateKeyMap(CacheNameEnum.THING_DETAIL_RELATION, + s.getRootId() + CacheInit.KEY + s.getId() + CacheInit.KEY + s.getRootThingId(), node); }); }