From 513e0942b284ecc8e9f3c37c04574063ec14734c Mon Sep 17 00:00:00 2001 From: siyang <2337720667@qq.com> Date: Fri, 11 Oct 2024 09:22:25 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pom.xml b/pom.xml index 2fa0276..991ca6a 100644 --- a/pom.xml +++ b/pom.xml @@ -395,11 +395,6 @@ - - org.thingsboard.common - util - ${thingsboard.version} - org.thingsboard.common data From c9d962c9745dd43a704d6c705ba4cdf81aba7739 Mon Sep 17 00:00:00 2001 From: lishuai Date: Tue, 15 Oct 2024 13:39:45 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=89=A9=E9=9D=99=E6=80=81=E5=B1=9E?= =?UTF-8?q?=E6=80=A7BUG=E4=BF=AE=E5=A4=8D=202024=E5=B9=B410=E6=9C=8815?= =?UTF-8?q?=E6=97=A513:39:42?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IotThingStaticDictController.java | 5 + .../IotThingRelationDetailController.java | 15 +++ .../IotThingRelationDetailService.java | 3 + .../IotThingRelationDetailServiceImpl.java | 92 +++++++++++++++++++ 4 files changed, 115 insertions(+) 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) { //当前节点