diff --git a/modules/thing/src/main/java/com/thing/thing/dictRelation/controller/IotThingStaticDictController.java b/modules/thing/src/main/java/com/thing/thing/dictRelation/controller/IotThingStaticDictController.java index 74aa81d..b78e335 100644 --- a/modules/thing/src/main/java/com/thing/thing/dictRelation/controller/IotThingStaticDictController.java +++ b/modules/thing/src/main/java/com/thing/thing/dictRelation/controller/IotThingStaticDictController.java @@ -69,6 +69,11 @@ public class IotThingStaticDictController { public Result save(@RequestBody IotThingStaticDictDTO dto){ //效验数据 ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); + if (dto.getTs() == null) { + dto.setTs(System.currentTimeMillis()); + } else { + dto.setTs(dto.getTs()); + } iotThingStaticDictService.saveDto(dto); return new Result<>(); } 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 2115457..c614b42 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 @@ -130,6 +130,21 @@ public class IotThingRelationDetailController { return new Result<>(); } + + + @GetMapping("dragging/{id}/{targetId}/{parentId}{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); + return new Result<>(); + } + @PostMapping("tree") @Operation(summary="查询树形结构") public Result> nodeTree(@RequestBody List rootIds){ 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 fbf61bc..62505b2 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 @@ -12,6 +12,7 @@ import com.thing.thing.relation.detail.dto.ThingTreeDTO; import com.thing.thing.relation.detail.entity.IotThingRelationDetailEntity; import com.thing.thing.relation.detail.param.IotThingRelationDetailParamDTO; import com.thing.thing.relation.root.dto.ThingSortTreeDTO; +import org.springframework.web.bind.annotation.PathVariable; import java.util.Collection; import java.util.List; @@ -49,6 +50,8 @@ public interface IotThingRelationDetailService extends IBaseService findAllNodesByRootIdAndToId(Long rootId,Long toId); 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 3e7a222..c81c33b 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 @@ -631,6 +631,98 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl allDetailEntities = mapper.selectListByQuery(new QueryWrapper() + .eq(IotThingRelationDetailEntity::getRootId, sourceEntity.getRootId()) + .ne(IotThingRelationDetailEntity::getId, id) + ); + + List 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 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.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); + } + + 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 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 public void batchDeleteByIds(Long[] ids) { //当前节点