|
|
@ -631,6 +631,98 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl<IotThingR |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void draggingSort(Long id, Long targetId, Long parentId, Long sort) { |
|
|
|
|
|
IotThingRelationDetailEntity sourceEntity = mapper.selectOneById(id); |
|
|
|
|
|
if (Objects.isNull(sourceEntity)) { |
|
|
|
|
|
throw new SysException("当前拖拽节点不存在,请重新选择"); |
|
|
|
|
|
} |
|
|
|
|
|
IotThingRelationDetailEntity targetEntity = mapper.selectOneById(targetId); |
|
|
|
|
|
if (Objects.isNull(targetEntity)) { |
|
|
|
|
|
throw new SysException("当前目标节点不存在,请重新选择"); |
|
|
|
|
|
} |
|
|
|
|
|
List<IotThingRelationDetailEntity> allDetailEntities = mapper.selectListByQuery(new QueryWrapper() |
|
|
|
|
|
.eq(IotThingRelationDetailEntity::getRootId, sourceEntity.getRootId()) |
|
|
|
|
|
.ne(IotThingRelationDetailEntity::getId, id) |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
List<IotThingRelationDetailEntity> resList = new ArrayList<>(); |
|
|
|
|
|
//若是相等,则作为targetId的子节点下 |
|
|
|
|
|
if(Objects.equals(targetId,parentId)){ |
|
|
|
|
|
sourceEntity.setFromName(targetEntity.getFromName()); |
|
|
|
|
|
sourceEntity.setFromCode(targetEntity.getFromCode()); |
|
|
|
|
|
sourceEntity.setId(targetEntity.getId()); |
|
|
|
|
|
sourceEntity.setSort(sort); |
|
|
|
|
|
// if(targetEntity.getSort()< sort){ |
|
|
|
|
|
// //向下拖拽 |
|
|
|
|
|
// List<IotThingRelationDetailEntity> upList = allDetailEntities.stream() |
|
|
|
|
|
// .filter(s -> s.getSort() < sort).sorted(Comparator.comparing(IotThingRelationDetailEntity::getSort)).toList(); |
|
|
|
|
|
// resList.addAll(upList); |
|
|
|
|
|
// resList.add(sourceEntity); |
|
|
|
|
|
// List<IotThingRelationDetailEntity> downList = allDetailEntities.stream() |
|
|
|
|
|
// .filter(s -> s.getSort() >= sort).sorted(Comparator.comparing(IotThingRelationDetailEntity::getSort)).toList(); |
|
|
|
|
|
// resList.addAll(downList); |
|
|
|
|
|
// }else{ |
|
|
|
|
|
// //向上拖拽 |
|
|
|
|
|
// List<IotThingRelationDetailEntity> upList = allDetailEntities.stream() |
|
|
|
|
|
// .filter(s -> s.getSort() <= sort).sorted(Comparator.comparing(IotThingRelationDetailEntity::getSort)).toList(); |
|
|
|
|
|
// resList.addAll(upList); |
|
|
|
|
|
// resList.add(sourceEntity); |
|
|
|
|
|
// List<IotThingRelationDetailEntity> downList = allDetailEntities.stream() |
|
|
|
|
|
// .filter(s -> s.getSort() > sort).sorted(Comparator.comparing(IotThingRelationDetailEntity::getSort)).toList(); |
|
|
|
|
|
// resList.addAll(downList); |
|
|
|
|
|
// } |
|
|
|
|
|
}else{ |
|
|
|
|
|
//若是不相等,则作为targetId的子节点下 |
|
|
|
|
|
IotThingRelationDetailEntity parentEntity = mapper.selectOneById(parentId); |
|
|
|
|
|
if (Objects.isNull(parentEntity)) { |
|
|
|
|
|
throw new SysException("父节点不存在,请重新选择"); |
|
|
|
|
|
} |
|
|
|
|
|
sourceEntity.setFromName(parentEntity.getFromName()); |
|
|
|
|
|
sourceEntity.setFromCode(parentEntity.getFromCode()); |
|
|
|
|
|
sourceEntity.setId(parentEntity.getId()); |
|
|
|
|
|
sourceEntity.setSort(sort); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(targetEntity.getSort()< sort){ |
|
|
|
|
|
//向下拖拽 |
|
|
|
|
|
List<IotThingRelationDetailEntity> upList = allDetailEntities.stream() |
|
|
|
|
|
.filter(s -> s.getSort() < sort).sorted(Comparator.comparing(IotThingRelationDetailEntity::getSort)).toList(); |
|
|
|
|
|
resList.addAll(upList); |
|
|
|
|
|
resList.add(sourceEntity); |
|
|
|
|
|
List<IotThingRelationDetailEntity> downList = allDetailEntities.stream() |
|
|
|
|
|
.filter(s -> s.getSort() >= sort).sorted(Comparator.comparing(IotThingRelationDetailEntity::getSort)).toList(); |
|
|
|
|
|
resList.addAll(downList); |
|
|
|
|
|
}else{ |
|
|
|
|
|
//向上拖拽 |
|
|
|
|
|
List<IotThingRelationDetailEntity> upList = allDetailEntities.stream() |
|
|
|
|
|
.filter(s -> s.getSort() <= sort).sorted(Comparator.comparing(IotThingRelationDetailEntity::getSort)).toList(); |
|
|
|
|
|
resList.addAll(upList); |
|
|
|
|
|
resList.add(sourceEntity); |
|
|
|
|
|
List<IotThingRelationDetailEntity> downList = allDetailEntities.stream() |
|
|
|
|
|
.filter(s -> s.getSort() > sort).sorted(Comparator.comparing(IotThingRelationDetailEntity::getSort)).toList(); |
|
|
|
|
|
resList.addAll(downList); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
AtomicLong atomicLong = new AtomicLong(0); |
|
|
|
|
|
resList.forEach(s -> |
|
|
|
|
|
{ |
|
|
|
|
|
s.setSort(atomicLong.incrementAndGet()); |
|
|
|
|
|
mapper.update(s); |
|
|
|
|
|
ObjectNode node = JsonConverter.convertToJsonObjectObjectNode(ConvertUtils.sourceToTarget(s, IotThingRelationDetailDTO.class)); |
|
|
|
|
|
List<ObjectNode> 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("thingStatus", status); |
|
|
|
|
|
} |
|
|
|
|
|
cache.updateAccurateKeyMap(CacheNameEnum.THING_DETAIL_RELATION, |
|
|
|
|
|
s.getRootId() + CacheInit.KEY + s.getId() + CacheInit.KEY + s.getRootThingId(), node); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void batchDeleteByIds(Long[] ids) { |
|
|
public void batchDeleteByIds(Long[] ids) { |
|
|
//当前节点 |
|
|
//当前节点 |
|
|
|