diff --git a/modules/thing/src/main/java/com/thing/thing/relation/detail/controller/IotThingRelationDetailController.java b/modules/thing/src/main/java/com/thing/thing/relation/detail/controller/IotThingRelationDetailController.java index c614b42..2f78c74 100644 --- a/modules/thing/src/main/java/com/thing/thing/relation/detail/controller/IotThingRelationDetailController.java +++ b/modules/thing/src/main/java/com/thing/thing/relation/detail/controller/IotThingRelationDetailController.java @@ -132,16 +132,19 @@ public class IotThingRelationDetailController { - @GetMapping("dragging/{id}/{targetId}/{parentId}{sort}") + @GetMapping("dragging/{id}/{targetId}/{parentId}/{rootThingId}/{sort}") @Operation(summary="通用拖拉拽") @Parameters({ @Parameter(name = "id", description = "当前拖拽的关系id", required = true) , @Parameter(name = "toId", description = "拖拽目标的关系id", required = true) , @Parameter(name = "toSort", description = "拖拽目标位置", required = true) }) - public Result draggingSort(@PathVariable("id") Long id,@PathVariable("targetId") Long targetId, - @PathVariable("parentId") Long parentId, @PathVariable("sort") Long sort){ - service.draggingSort(id, targetId,parentId,sort); + public Result draggingSort(@PathVariable("id") Long id, + @PathVariable("targetId") Long targetId, + @PathVariable("parentId") Long parentId, + @PathVariable("rootThingId") Long rootThingId, + @PathVariable("sort") Long sort){ + service.draggingSort(id, targetId,parentId,rootThingId,sort); return new Result<>(); } diff --git a/modules/thing/src/main/java/com/thing/thing/relation/detail/service/IotThingRelationDetailService.java b/modules/thing/src/main/java/com/thing/thing/relation/detail/service/IotThingRelationDetailService.java index 62505b2..ab1a7ae 100644 --- a/modules/thing/src/main/java/com/thing/thing/relation/detail/service/IotThingRelationDetailService.java +++ b/modules/thing/src/main/java/com/thing/thing/relation/detail/service/IotThingRelationDetailService.java @@ -50,7 +50,7 @@ public interface IotThingRelationDetailService extends IBaseService parentEntities; + if(!Objects.equals(sourceEntity.getRootId(), parentId)){ + parentEntities = mapper.selectListByQuery(new QueryWrapper().eq(IotThingRelationDetailEntity::getToId, parentId) + .eq(IotThingRelationDetailEntity::getRootThingId, rootThingId)); + if (CollectionUtils.isEmpty(parentEntities)) { + throw new SysException("父节点不存在,请重新选择"); + } + }else{ + IotThingRelationRootDTO relationRootDTO = relationRootsService.findById(parentId); + parentEntities = Lists.newArrayList(new IotThingRelationDetailEntity().setFromId(relationRootDTO.getId()).setFromName(relationRootDTO.getName())) ; + if (CollectionUtils.isEmpty(parentEntities)) { + throw new SysException("父节点不存在,请重新选择"); + } + } List allDetailEntities = mapper.selectListByQuery(new QueryWrapper() .eq(IotThingRelationDetailEntity::getRootId, sourceEntity.getRootId()) .ne(IotThingRelationDetailEntity::getId, id) @@ -648,45 +663,17 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl resList = new ArrayList<>(); //若是相等,则作为targetId的子节点下 - if(Objects.equals(targetId,parentId)){ - sourceEntity.setFromName(targetEntity.getFromName()); - sourceEntity.setFromCode(targetEntity.getFromCode()); - sourceEntity.setId(targetEntity.getId()); + if(!Objects.equals(targetEntity.getFromId(),parentId) && Objects.equals(targetEntity.getRootThingId(),rootThingId)){ + sourceEntity.setFromName(targetEntity.getToName()); + sourceEntity.setFromCode(targetEntity.getToCode()); + sourceEntity.setFromId(targetEntity.getToId()); sourceEntity.setSort(sort); -// if(targetEntity.getSort()< sort){ -// //向下拖拽 -// List upList = allDetailEntities.stream() -// .filter(s -> s.getSort() < sort).sorted(Comparator.comparing(IotThingRelationDetailEntity::getSort)).toList(); -// resList.addAll(upList); -// resList.add(sourceEntity); -// List downList = allDetailEntities.stream() -// .filter(s -> s.getSort() >= sort).sorted(Comparator.comparing(IotThingRelationDetailEntity::getSort)).toList(); -// resList.addAll(downList); -// }else{ -// //向上拖拽 -// List upList = allDetailEntities.stream() -// .filter(s -> s.getSort() <= sort).sorted(Comparator.comparing(IotThingRelationDetailEntity::getSort)).toList(); -// resList.addAll(upList); -// resList.add(sourceEntity); -// List 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.setFromName(parentEntities.get(0).getToName()); + sourceEntity.setFromCode(parentEntities.get(0).getToCode()); + sourceEntity.setFromId(parentEntities.get(0).getToId()); sourceEntity.setSort(sort); - - } - - if(targetEntity.getSort()< sort){ //向下拖拽 List upList = allDetailEntities.stream() @@ -706,7 +693,6 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl s.getSort() > sort).sorted(Comparator.comparing(IotThingRelationDetailEntity::getSort)).toList(); resList.addAll(downList); } - AtomicLong atomicLong = new AtomicLong(0); resList.forEach(s -> {