Browse Source

物关系拖拽

2024年10月16日11:16:35
thing_master
lishuai 1 year ago
parent
commit
c9619492d5
  1. 11
      modules/thing/src/main/java/com/thing/thing/relation/detail/controller/IotThingRelationDetailController.java
  2. 2
      modules/thing/src/main/java/com/thing/thing/relation/detail/service/IotThingRelationDetailService.java
  3. 60
      modules/thing/src/main/java/com/thing/thing/relation/detail/service/impl/IotThingRelationDetailServiceImpl.java

11
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="通用拖拉拽") @Operation(summary="通用拖拉拽")
@Parameters({ @Parameters({
@Parameter(name = "id", description = "当前拖拽的关系id", required = true) , @Parameter(name = "id", description = "当前拖拽的关系id", required = true) ,
@Parameter(name = "toId", description = "拖拽目标的关系id", required = true) , @Parameter(name = "toId", description = "拖拽目标的关系id", required = true) ,
@Parameter(name = "toSort", description = "拖拽目标位置", required = true) @Parameter(name = "toSort", description = "拖拽目标位置", required = true)
}) })
public Result<Void> 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<Void> 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<>(); return new Result<>();
} }

2
modules/thing/src/main/java/com/thing/thing/relation/detail/service/IotThingRelationDetailService.java

@ -50,7 +50,7 @@ public interface IotThingRelationDetailService extends IBaseService<IotThingRela
void updateSiblingSort(Long id, Long sort); void updateSiblingSort(Long id, Long sort);
void draggingSort(Long id, Long targetId, Long parentId, Long sort);
void draggingSort(Long id, Long targetId, Long parentId,Long rootThingId, Long sort);
void batchDeleteByIds(Long[] ids); void batchDeleteByIds(Long[] ids);

60
modules/thing/src/main/java/com/thing/thing/relation/detail/service/impl/IotThingRelationDetailServiceImpl.java

@ -632,7 +632,7 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl<IotThingR
} }
@Override @Override
public void draggingSort(Long id, Long targetId, Long parentId, Long sort) {
public void draggingSort(Long id, Long targetId, Long parentId, Long rootThingId, Long sort) {
IotThingRelationDetailEntity sourceEntity = mapper.selectOneById(id); IotThingRelationDetailEntity sourceEntity = mapper.selectOneById(id);
if (Objects.isNull(sourceEntity)) { if (Objects.isNull(sourceEntity)) {
throw new SysException("当前拖拽节点不存在,请重新选择"); throw new SysException("当前拖拽节点不存在,请重新选择");
@ -641,6 +641,21 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl<IotThingR
if (Objects.isNull(targetEntity)) { if (Objects.isNull(targetEntity)) {
throw new SysException("当前目标节点不存在,请重新选择"); throw new SysException("当前目标节点不存在,请重新选择");
} }
//若是不相等则作为targetId的子节点下
List<IotThingRelationDetailEntity> 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<IotThingRelationDetailEntity> allDetailEntities = mapper.selectListByQuery(new QueryWrapper() List<IotThingRelationDetailEntity> allDetailEntities = mapper.selectListByQuery(new QueryWrapper()
.eq(IotThingRelationDetailEntity::getRootId, sourceEntity.getRootId()) .eq(IotThingRelationDetailEntity::getRootId, sourceEntity.getRootId())
.ne(IotThingRelationDetailEntity::getId, id) .ne(IotThingRelationDetailEntity::getId, id)
@ -648,45 +663,17 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl<IotThingR
List<IotThingRelationDetailEntity> resList = new ArrayList<>(); List<IotThingRelationDetailEntity> resList = new ArrayList<>();
//若是相等则作为targetId的子节点下 //若是相等则作为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); 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{ }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); sourceEntity.setSort(sort);
} }
if(targetEntity.getSort()< sort){ if(targetEntity.getSort()< sort){
//向下拖拽 //向下拖拽
List<IotThingRelationDetailEntity> upList = allDetailEntities.stream() List<IotThingRelationDetailEntity> upList = allDetailEntities.stream()
@ -706,7 +693,6 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl<IotThingR
.filter(s -> s.getSort() > sort).sorted(Comparator.comparing(IotThingRelationDetailEntity::getSort)).toList(); .filter(s -> s.getSort() > sort).sorted(Comparator.comparing(IotThingRelationDetailEntity::getSort)).toList();
resList.addAll(downList); resList.addAll(downList);
} }
AtomicLong atomicLong = new AtomicLong(0); AtomicLong atomicLong = new AtomicLong(0);
resList.forEach(s -> resList.forEach(s ->
{ {

Loading…
Cancel
Save