|
|
|
@ -34,6 +34,7 @@ import com.thing.thing.relation.detail.entity.IotThingRelationDetailEntity; |
|
|
|
import com.thing.thing.relation.detail.mapper.IotThingRelationDetailMapper; |
|
|
|
import com.thing.thing.relation.detail.param.IotThingRelationDetailParamDTO; |
|
|
|
import com.thing.thing.relation.detail.service.IotThingRelationDetailService; |
|
|
|
import com.thing.thing.relation.root.dto.IotThingRelationRootDTO; |
|
|
|
import com.thing.thing.relation.root.dto.ThingSortTreeDTO; |
|
|
|
import com.thing.thing.relation.root.entity.IotThingRelationRootEntity; |
|
|
|
import com.thing.thing.relation.root.service.IotThingRelationRootService; |
|
|
|
@ -115,8 +116,10 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl<IotThingR |
|
|
|
} |
|
|
|
return has; |
|
|
|
}); |
|
|
|
List<ObjectNode> collect = relationDetailList.stream().sorted(Comparator.comparingLong(node -> node.get(CacheNameEnum.RelationDetailField.THING_RELATION_DETAIL_SORT.getField()).asLong())).collect(Collectors.toList()); |
|
|
|
|
|
|
|
//分页 |
|
|
|
List<ObjectNode> resPageList = PageUtils.startPage(relationDetailList, page, limit); |
|
|
|
List<ObjectNode> resPageList = PageUtils.startPage(collect, page, limit); |
|
|
|
/* //找到第一节点 :先保留这个注释代码,可能会用到 |
|
|
|
List<ObjectNode> resList = detailList.stream() |
|
|
|
.filter(d -> StringUtils.equals( |
|
|
|
@ -187,7 +190,15 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl<IotThingR |
|
|
|
return mapper.selectOneByQuery(QueryWrapper.create() |
|
|
|
.eq(IotThingRelationDetailEntity::getRootId, rootId) |
|
|
|
.eq(IotThingRelationDetailEntity::getRootThingId, rootThingId) |
|
|
|
.eq(IotThingRelationDetailEntity::getToId, rootThingId) |
|
|
|
.eq(IotThingRelationDetailEntity::getFromId, rootId)); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public IotThingRelationDetailEntity findByRootIdAndRootThingIdAndToId(Long rootId, Long rootThingId, Long toId) { |
|
|
|
return mapper.selectOneByQuery(QueryWrapper.create() |
|
|
|
.eq(IotThingRelationDetailEntity::getRootId, rootId) |
|
|
|
.eq(IotThingRelationDetailEntity::getRootThingId, rootThingId) |
|
|
|
.eq(IotThingRelationDetailEntity::getToId, toId) |
|
|
|
.eq(IotThingRelationDetailEntity::getFromId, rootId)); |
|
|
|
} |
|
|
|
|
|
|
|
@ -270,9 +281,9 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl<IotThingR |
|
|
|
} else { |
|
|
|
mapper.updateByQuery(item, QueryWrapper.create().eq(IotThingRelationDetailEntity::getId, item.getId())); |
|
|
|
} |
|
|
|
cache.updateAccurateKeyEntity(CacheNameEnum.THING_DETAIL_RELATION, |
|
|
|
item.getRootId()+CacheInit.KEY+item.getId()+CacheInit.KEY+item.getRootThingId(),ConvertUtils.sourceToTarget(item, IotThingRelationDetailDTO.class)); |
|
|
|
}); |
|
|
|
//更新缓存 |
|
|
|
cache.clearTopic(CacheNameEnum.THING_DETAIL_RELATION); |
|
|
|
} |
|
|
|
|
|
|
|
private List<IotThingRelationDetailEntity> buildDetails(IotThingRelationDetailParamDTO dto, List<IotThingRelationDetailParamDTO> subRelationList) { |
|
|
|
@ -306,12 +317,23 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl<IotThingR |
|
|
|
root.setId(request.getRootId()); |
|
|
|
root.setConfig(request.getConfig()); |
|
|
|
relationRootsService.updateById(root); |
|
|
|
//更新缓存 |
|
|
|
ObjectNode nodes = JsonConverter.convertToJsonObjectObjectNode(root); |
|
|
|
nodes.put("fromId", "0"); |
|
|
|
nodes.put("rootId", nodes.get("id").asText()); |
|
|
|
nodes.put("toId", nodes.get("id").asText()); |
|
|
|
nodes.put("toName", nodes.get("name").asText()); |
|
|
|
nodes.put("rootThingId", "0"); |
|
|
|
cache.updateAccurateKeyMap(CacheNameEnum.THING_ROOT_RELATION, |
|
|
|
root.getGroupName()+CacheInit.KEY+root.getName()+CacheInit.KEY+root.getId(),nodes); |
|
|
|
|
|
|
|
//查询当前rootId下的所有关系列表 |
|
|
|
List<IotThingRelationDetailEntity> iotThingRelationDetailEntities = mapper.selectListByQuery(QueryWrapper.create().eq(IotThingRelationDetailEntity::getRootId, request.getRootId())); |
|
|
|
if (CollectionUtils.isNotEmpty(iotThingRelationDetailEntities)) { |
|
|
|
//删除全部关系 |
|
|
|
mapper.deleteByQuery(QueryWrapper.create().eq(IotThingRelationDetailEntity::getRootId, request.getRootId())); |
|
|
|
iotThingRelationDetailEntities.forEach(entity -> cache.deleteKeyMap(CacheNameEnum.THING_DETAIL_RELATION, |
|
|
|
entity.getRootId()+CacheInit.KEY+entity.getId()+CacheInit.KEY+entity.getRootThingId())); |
|
|
|
} |
|
|
|
//重构关系入库 |
|
|
|
List<IotThingRelationDetailEntity> list = detailList.stream().flatMap(item -> { |
|
|
|
@ -333,7 +355,8 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl<IotThingR |
|
|
|
}).toList(); |
|
|
|
mapper.insertBatch(list); |
|
|
|
//更新缓存 |
|
|
|
cache.clearTopic(CacheNameEnum.THING_DETAIL_RELATION); |
|
|
|
list.forEach(entity -> cache.updateAccurateKeyEntity(CacheNameEnum.THING_DETAIL_RELATION, |
|
|
|
entity.getRootId()+CacheInit.KEY+entity.getId()+CacheInit.KEY+entity.getRootThingId(),ConvertUtils.sourceToTarget(entity, IotThingRelationDetailDTO.class))); |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@ -349,9 +372,9 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl<IotThingR |
|
|
|
|
|
|
|
if(Objects.isNull(dto.getPid()) || Objects.equals(dto.getPid(), 0L)){ |
|
|
|
mapper.update(sourceEntity); |
|
|
|
cache.updateAccurateKeyEntity(CacheNameEnum.THING_DETAIL_RELATION, |
|
|
|
sourceEntity.getRootId()+CacheInit.KEY+sourceEntity.getId()+CacheInit.KEY+sourceEntity.getRootThingId(),ConvertUtils.sourceToTarget(sourceEntity, IotThingRelationDetailDTO.class)); |
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
|
|
IotThingRelationDetailEntity targetEntity = mapper.selectOneById(dto.getPid()); |
|
|
|
if (Objects.isNull(targetEntity)) { |
|
|
|
throw new SysException("当前目标节点关系不存在"); |
|
|
|
@ -359,9 +382,10 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl<IotThingR |
|
|
|
if(!Objects.equals(sourceEntity.getRootThingId(), targetEntity.getRootThingId())){ |
|
|
|
throw new SysException("当前移动节点和目标节点不在同一个根节点下,无法移动"); |
|
|
|
} |
|
|
|
|
|
|
|
if(sourceEntity.getFromId().equals(targetEntity.getToId())){ |
|
|
|
mapper.update(sourceEntity); |
|
|
|
cache.updateAccurateKeyEntity(CacheNameEnum.THING_DETAIL_RELATION, |
|
|
|
sourceEntity.getRootId()+CacheInit.KEY+sourceEntity.getId()+CacheInit.KEY+sourceEntity.getRootThingId(),ConvertUtils.sourceToTarget(sourceEntity, IotThingRelationDetailDTO.class)); |
|
|
|
}else{ |
|
|
|
//查询当前关系下所有节点信息 |
|
|
|
List<IotThingRelationDetailEntity> iotThingRelationDetailEntities = mapper.selectListByQuery(QueryWrapper.create().eq(IotThingRelationDetailEntity::getRootId, dto.getRootId())); |
|
|
|
@ -395,27 +419,23 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl<IotThingR |
|
|
|
sourceEntity.setFromName(targetEntity.getFromName()); |
|
|
|
resultList.add(sourceEntity); |
|
|
|
|
|
|
|
|
|
|
|
List<Long> targetChildIds = list.stream().map(IotThingRelationDetailEntity::getId).toList(); |
|
|
|
|
|
|
|
//找出不包源节点 , 目标节点顺序的节点 ,并且顺序小于目标节点顺序的节点 |
|
|
|
List<IotThingRelationDetailEntity> xlist = iotThingRelationDetailEntities.stream().filter(d -> !sourceChildIds.contains(d.getId()) && !targetChildIds.contains(d.getId()) |
|
|
|
&& list.get(list.size()-1).getSort() < d.getSort()).toList(); |
|
|
|
|
|
|
|
resultList.addAll(xlist); |
|
|
|
|
|
|
|
//更新排序 |
|
|
|
AtomicLong sort = new AtomicLong(0); |
|
|
|
resultList.forEach(item -> |
|
|
|
{ |
|
|
|
item.setSort(sort.incrementAndGet()); |
|
|
|
mapper.updateByQuery(item, QueryWrapper.create().eq(IotThingRelationDetailEntity::getId, item.getId())); |
|
|
|
cache.updateAccurateKeyEntity(CacheNameEnum.THING_DETAIL_RELATION, |
|
|
|
item.getRootId()+CacheInit.KEY+item.getId()+CacheInit.KEY+item.getRootThingId(),ConvertUtils.sourceToTarget(item, IotThingRelationDetailDTO.class)); |
|
|
|
} |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
//更新缓存 |
|
|
|
cache.clearTopic(CacheNameEnum.THING_DETAIL_RELATION); |
|
|
|
} |
|
|
|
|
|
|
|
private void findAllChild(List<IotThingRelationDetailEntity> allRelation, |
|
|
|
@ -432,51 +452,134 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl<IotThingR |
|
|
|
|
|
|
|
@Override |
|
|
|
public void deleteByRootId(Long rootId) { |
|
|
|
QueryWrapper eq = QueryWrapper.create().eq(IotThingRelationDetailEntity::getRootId, rootId); |
|
|
|
List<IotThingRelationDetailEntity> relationDetailEntities = mapper.selectListByQuery(eq); |
|
|
|
mapper.deleteByQuery(QueryWrapper.create().eq(IotThingRelationDetailEntity::getRootId, rootId)); |
|
|
|
cache.clearTopic(CacheNameEnum.THING_DETAIL_RELATION); |
|
|
|
relationDetailEntities.forEach(detailEntity -> cache.deleteKeyMap(CacheNameEnum.THING_DETAIL_RELATION, |
|
|
|
detailEntity.getRootId()+CacheInit.KEY+detailEntity.getId()+CacheInit.KEY+detailEntity.getRootThingId())); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void deleteById(Long id) { |
|
|
|
QueryWrapper eq = QueryWrapper.create().eq(IotThingRelationDetailEntity::getId, id); |
|
|
|
IotThingRelationDetailEntity detailEntity = mapper.selectOneByQuery(eq); |
|
|
|
mapper.deleteByQuery(QueryWrapper.create().eq(IotThingRelationDetailEntity::getId, id)); |
|
|
|
cache.clearTopic(CacheNameEnum.THING_DETAIL_RELATION); |
|
|
|
cache.deleteKeyMap(CacheNameEnum.THING_DETAIL_RELATION, |
|
|
|
detailEntity.getRootId()+CacheInit.KEY+detailEntity.getId()+CacheInit.KEY+detailEntity.getRootThingId()); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void updateSort(Long id, Long toSort) { |
|
|
|
//拖拽关系 |
|
|
|
public void updateSort(Long id, Long toId) { |
|
|
|
//d拖拽关系 |
|
|
|
IotThingRelationDetailEntity sourceEntity = mapper.selectOneById(id); |
|
|
|
if (Objects.isNull(sourceEntity)) { |
|
|
|
throw new SysException("当前拖拽的关系不存在,请重新选择"); |
|
|
|
} |
|
|
|
//查询所有同级别的关系记录 |
|
|
|
List<IotThingRelationDetailEntity> sourceList = mapper.selectListByQuery(new QueryWrapper() |
|
|
|
//若id和toId相等,则放置在所有关系的第一层,即顶级关系 |
|
|
|
List<IotThingRelationDetailEntity> resultList = Lists.newArrayList(); |
|
|
|
List<IotThingRelationDetailEntity> resultChildList = Lists.newArrayList(); |
|
|
|
if(Objects.equals(id,toId)){ |
|
|
|
IotThingRelationRootDTO relationRootDTO = relationRootsService.findById(sourceEntity.getRootId()); |
|
|
|
sourceEntity.setFromName(relationRootDTO.getName()); |
|
|
|
sourceEntity.setFromCode(null); |
|
|
|
sourceEntity.setFromId(sourceEntity.getRootId()); |
|
|
|
resultChildList.add(sourceEntity); |
|
|
|
//查询当前节点的所有子节点 |
|
|
|
findAllChildNodesByToId(Lists.newArrayList(id),sourceEntity.getRootId(),sourceEntity.getRootThingId(),resultChildList); |
|
|
|
//排序 |
|
|
|
List<IotThingRelationDetailEntity> list = resultChildList.stream().sorted(comparing(IotThingRelationDetailEntity::getSort)).toList(); |
|
|
|
resultList.addAll(list); |
|
|
|
|
|
|
|
List<Long> allChildIds = resultChildList.stream().map(IotThingRelationDetailEntity::getId).toList(); |
|
|
|
//查询所有其他的物关系记录 |
|
|
|
List<IotThingRelationDetailEntity> otherList = mapper.selectListByQuery(new QueryWrapper() |
|
|
|
.eq(IotThingRelationDetailEntity::getRootId, sourceEntity.getRootId()) |
|
|
|
.eq(IotThingRelationDetailEntity::getRootThingId, sourceEntity.getRootThingId()) |
|
|
|
.eq(IotThingRelationDetailEntity::getFromId, sourceEntity.getFromId()) |
|
|
|
.ne(IotThingRelationDetailEntity::getId, sourceEntity.getId()) |
|
|
|
.notIn(IotThingRelationDetailEntity::getId, allChildIds) |
|
|
|
.orderBy(IotThingRelationDetailEntity::getSort, true)); |
|
|
|
List<IotThingRelationDetailEntity> resultList = Lists.newArrayList(); |
|
|
|
//向上:这里的条件判断是利用list的元素顺序重新给整个节点赋sort值 |
|
|
|
if (sourceEntity.getSort() > toSort) { |
|
|
|
List<IotThingRelationDetailEntity> upList = sourceList.stream().filter(item -> item.getSort() < toSort).toList(); |
|
|
|
resultList.addAll(upList); |
|
|
|
sourceEntity.setSort(toSort); |
|
|
|
resultList.add(sourceEntity); |
|
|
|
List<IotThingRelationDetailEntity> downList = sourceList.stream().filter(item -> item.getSort() >= toSort).toList(); |
|
|
|
resultList.addAll(downList); |
|
|
|
resultList.addAll(otherList); |
|
|
|
}else { |
|
|
|
List<IotThingRelationDetailEntity> upList = sourceList.stream().filter(item -> item.getSort() <= toSort).toList(); |
|
|
|
resultList.addAll(upList); |
|
|
|
sourceEntity.setSort(toSort); |
|
|
|
resultList.add(sourceEntity); |
|
|
|
List<IotThingRelationDetailEntity> downList = sourceList.stream().filter(item -> item.getSort() > toSort).toList(); |
|
|
|
resultList.addAll(downList); |
|
|
|
//查询目标节点 |
|
|
|
IotThingRelationDetailEntity targetEntity = mapper.selectOneById(toId); |
|
|
|
if (Objects.isNull(targetEntity)) { |
|
|
|
throw new SysException("当前拖拽的目标节点关系不存在,请重新选择"); |
|
|
|
} |
|
|
|
//查询当前拖拽节点的所有子节点 |
|
|
|
|
|
|
|
sourceEntity.setFromId(targetEntity.getToId()); |
|
|
|
sourceEntity.setFromCode(targetEntity.getToCode()); |
|
|
|
sourceEntity.setFromName(targetEntity.getFromName()); |
|
|
|
|
|
|
|
resultChildList.add(sourceEntity); |
|
|
|
findAllChildNodesByToId(Lists.newArrayList(id),sourceEntity.getRootId(),sourceEntity.getRootThingId(),resultChildList); |
|
|
|
|
|
|
|
//查询目标节点的子节点 |
|
|
|
List<IotThingRelationDetailEntity> targetChildList = Lists.newArrayList(); |
|
|
|
findAllChildNodesByToId(Lists.newArrayList(id),sourceEntity.getRootId(),sourceEntity.getRootThingId(),targetChildList); |
|
|
|
|
|
|
|
//查询目标节点的所有兄弟节点 |
|
|
|
|
|
|
|
List<Long> allChildIds = resultChildList.stream().map(IotThingRelationDetailEntity::getId).toList(); |
|
|
|
//查询所有其他的物关系记录 |
|
|
|
List<IotThingRelationDetailEntity> otherList = mapper.selectListByQuery(new QueryWrapper() |
|
|
|
.eq(IotThingRelationDetailEntity::getRootId, sourceEntity.getRootId()) |
|
|
|
.eq(IotThingRelationDetailEntity::getRootThingId, sourceEntity.getRootThingId()) |
|
|
|
.notIn(IotThingRelationDetailEntity::getId, allChildIds) |
|
|
|
.le(IotThingRelationDetailEntity::getSort, targetEntity.getSort()) |
|
|
|
.orderBy(IotThingRelationDetailEntity::getSort, true)); |
|
|
|
|
|
|
|
resultChildList.addAll(otherList); |
|
|
|
List<IotThingRelationDetailEntity> list = resultChildList.stream().sorted(comparing(IotThingRelationDetailEntity::getSort)).toList(); |
|
|
|
resultChildList.addAll(list); |
|
|
|
|
|
|
|
List<IotThingRelationDetailEntity> otherList1 = mapper.selectListByQuery(new QueryWrapper() |
|
|
|
.eq(IotThingRelationDetailEntity::getRootId, sourceEntity.getRootId()) |
|
|
|
.eq(IotThingRelationDetailEntity::getRootThingId, sourceEntity.getRootThingId()) |
|
|
|
.notIn(IotThingRelationDetailEntity::getId, allChildIds) |
|
|
|
.gt(IotThingRelationDetailEntity::getSort, targetEntity.getSort()) |
|
|
|
.orderBy(IotThingRelationDetailEntity::getSort, true)); |
|
|
|
resultChildList.addAll(otherList1); |
|
|
|
} |
|
|
|
AtomicLong sort = new AtomicLong(1); |
|
|
|
resultList.forEach(item -> item.setSort(sort.getAndIncrement())); |
|
|
|
this.updateBatch(resultList); |
|
|
|
cache.clearTopic(CacheNameEnum.THING_DETAIL_RELATION); |
|
|
|
//更新缓存 |
|
|
|
resultList.forEach(s -> cache.updateAccurateKeyEntity(CacheNameEnum.THING_DETAIL_RELATION, |
|
|
|
s.getRootId()+CacheInit.KEY+s.getId()+CacheInit.KEY+s.getRootThingId(),ConvertUtils.sourceToTarget(s, IotThingRelationDetailDTO.class))); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void updateSiblingSort(Long id, Long sort) { |
|
|
|
IotThingRelationDetailEntity sourceEntity = mapper.selectOneById(id); |
|
|
|
if (Objects.isNull(sourceEntity)) { |
|
|
|
throw new SysException("当前拖拽的关系不存在,请重新选择"); |
|
|
|
} |
|
|
|
List<IotThingRelationDetailEntity> reslutList = Lists.newArrayList(); |
|
|
|
List<IotThingRelationDetailEntity> otherList = mapper.selectListByQuery(new QueryWrapper() |
|
|
|
.eq(IotThingRelationDetailEntity::getRootId, sourceEntity.getRootId()) |
|
|
|
.eq(IotThingRelationDetailEntity::getRootThingId, sourceEntity.getRootThingId()) |
|
|
|
.notIn(IotThingRelationDetailEntity::getId, sourceEntity.getId()) |
|
|
|
.lt(IotThingRelationDetailEntity::getSort, sort) |
|
|
|
.orderBy(IotThingRelationDetailEntity::getSort, true)); |
|
|
|
|
|
|
|
reslutList.addAll(otherList); |
|
|
|
|
|
|
|
sourceEntity.setSort(sort); |
|
|
|
reslutList.add(sourceEntity); |
|
|
|
List<IotThingRelationDetailEntity> otherList1 = mapper.selectListByQuery(new QueryWrapper() |
|
|
|
.eq(IotThingRelationDetailEntity::getRootId, sourceEntity.getRootId()) |
|
|
|
.eq(IotThingRelationDetailEntity::getRootThingId, sourceEntity.getRootThingId()) |
|
|
|
.notIn(IotThingRelationDetailEntity::getId, sourceEntity.getId()) |
|
|
|
.ge(IotThingRelationDetailEntity::getSort, sort) |
|
|
|
.orderBy(IotThingRelationDetailEntity::getSort, true)); |
|
|
|
reslutList.addAll(otherList1); |
|
|
|
|
|
|
|
AtomicLong sort1 = new AtomicLong(1); |
|
|
|
reslutList.forEach(item -> 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))); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@ -497,14 +600,33 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl<IotThingR |
|
|
|
.orderBy(IotThingRelationDetailEntity::getSort, true); |
|
|
|
List<IotThingRelationDetailEntity> otherRelationList = mapper.selectListByQuery(queryWrapper); |
|
|
|
mapper.deleteBatchByIds(Arrays.asList(ids)); |
|
|
|
//更新缓存 |
|
|
|
iotThingRelationDetailEntities.forEach(entity -> cache.deleteKeyMap(CacheNameEnum.THING_DETAIL_RELATION, |
|
|
|
entity.getRootId()+CacheInit.KEY+entity.getId()+CacheInit.KEY+entity.getRootThingId())); |
|
|
|
//更新序号 |
|
|
|
AtomicLong sort = new AtomicLong(1); |
|
|
|
otherRelationList.forEach(s -> { |
|
|
|
s.setSort(sort.getAndIncrement()); |
|
|
|
mapper.insertOrUpdateSelective(s); |
|
|
|
}); |
|
|
|
//更新缓存 |
|
|
|
cache.clearTopic(CacheNameEnum.THING_DETAIL_RELATION); |
|
|
|
cache.updateAccurateKeyEntity(CacheNameEnum.THING_DETAIL_RELATION, |
|
|
|
s.getRootId()+CacheInit.KEY+s.getId()+CacheInit.KEY+s.getRootThingId(),ConvertUtils.sourceToTarget(s, IotThingRelationDetailDTO.class)); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void findAllChildNodesByToId(List<Long> toIds,Long rootId,Long rootThingId,List<IotThingRelationDetailEntity> resultChildList){ |
|
|
|
List<IotThingRelationDetailEntity> childList = mapper.selectListByQuery(QueryWrapper.create() |
|
|
|
.in(IotThingRelationDetailEntity::getFromId,toIds) |
|
|
|
.in(IotThingRelationDetailEntity::getRootId,rootId) |
|
|
|
.in(IotThingRelationDetailEntity::getRootThingId,rootThingId) |
|
|
|
); |
|
|
|
if(CollectionUtils.isEmpty(childList)){ |
|
|
|
return; |
|
|
|
} |
|
|
|
resultChildList.addAll(childList); |
|
|
|
List<Long> childToId = childList.stream().map(IotThingRelationDetailEntity::getToId).toList(); |
|
|
|
findAllChildNodesByToId(childToId,rootId,rootThingId,resultChildList); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@ -524,7 +646,7 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl<IotThingR |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<IotThingEntityDTO> findAllNotAddNodesById(Long id) { |
|
|
|
List<ObjectNode> relationList = cache.findKeyMap(CacheNameEnum.THING_DETAIL_RELATION, id.toString()); |
|
|
|
List<ObjectNode> relationList = cache.findMapAccurateKey(CacheNameEnum.THING_DETAIL_RELATION, id.toString()); |
|
|
|
if (CollectionUtils.isEmpty(relationList)) { |
|
|
|
throw new SysException("当前物关系不存在"); |
|
|
|
} |
|
|
|
@ -886,8 +1008,8 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl<IotThingR |
|
|
|
rootNode.get(CacheNameEnum.RelationRootField.THING_RELATION_ROOT_GROUP_NAME.getField()).asText()); |
|
|
|
} |
|
|
|
//物实体信息 |
|
|
|
List<ObjectNode> entityNode = cache.findKeyMap(CacheNameEnum.THING_ENTITY, String.valueOf(UserContext.getRealTenantCode()) |
|
|
|
+ ":" + rootChildNode.get(CacheNameEnum.RelationDetailField.THING_RELATION_DETAIL_TO_CODE.getField()).asText()); |
|
|
|
List<ObjectNode> entityNode = cache.findMapAccurateKeys(CacheNameEnum.THING_ENTITY, String.valueOf(UserContext.getRealTenantCode()) |
|
|
|
,rootChildNode.get(CacheNameEnum.RelationDetailField.THING_RELATION_DETAIL_TO_CODE.getField()).asText()); |
|
|
|
if (CollectionUtils.isNotEmpty(entityNode)) { |
|
|
|
rootChildNode.put(CacheNameEnum.RelationRootField.THING_RELATION_ROOT_ENTITY_TYPE.getField(), entityNode.get(0).get(CacheNameEnum.EntityField.THING_ENTITY_TYPE.getField()).asText()); |
|
|
|
} |
|
|
|
@ -929,8 +1051,8 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl<IotThingR |
|
|
|
rootNode.get(CacheNameEnum.RelationRootField.THING_RELATION_ROOT_GROUP_NAME.getField()).asText()); |
|
|
|
} |
|
|
|
//物实体信息 |
|
|
|
List<ObjectNode> entityNode = cache.findKeyMap(CacheNameEnum.THING_ENTITY, String.valueOf(UserContext.getRealTenantCode()) |
|
|
|
+ ":" + rootChildNode.get(CacheNameEnum.RelationDetailField.THING_RELATION_DETAIL_TO_CODE.getField()).asText()); |
|
|
|
List<ObjectNode> entityNode = cache.findMapAccurateKeys(CacheNameEnum.THING_ENTITY, String.valueOf(UserContext.getRealTenantCode()) |
|
|
|
, rootChildNode.get(CacheNameEnum.RelationDetailField.THING_RELATION_DETAIL_TO_CODE.getField()).asText()); |
|
|
|
if (CollectionUtils.isNotEmpty(entityNode)) { |
|
|
|
rootChildNode.put(CacheNameEnum.RelationRootField.THING_RELATION_ROOT_ENTITY_TYPE.getField(), entityNode.get(0).get(CacheNameEnum.EntityField.THING_ENTITY_TYPE.getField()).asText()); |
|
|
|
} |
|
|
|
|