Browse Source

物静态属性BUG修复

2024年10月15日13:39:42
thing_master
lishuai 1 year ago
parent
commit
c9d962c974
  1. 5
      modules/thing/src/main/java/com/thing/thing/dictRelation/controller/IotThingStaticDictController.java
  2. 15
      modules/thing/src/main/java/com/thing/thing/relation/detail/controller/IotThingRelationDetailController.java
  3. 3
      modules/thing/src/main/java/com/thing/thing/relation/detail/service/IotThingRelationDetailService.java
  4. 92
      modules/thing/src/main/java/com/thing/thing/relation/detail/service/impl/IotThingRelationDetailServiceImpl.java

5
modules/thing/src/main/java/com/thing/thing/dictRelation/controller/IotThingStaticDictController.java

@ -69,6 +69,11 @@ public class IotThingStaticDictController {
public Result<Void> 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<>();
}

15
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<Void> 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<List<ObjectNode>> nodeTree(@RequestBody List<Long> rootIds){

3
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<IotThingRela
void updateSiblingSort(Long id, Long sort);
void draggingSort(Long id, Long targetId, Long parentId, Long sort);
void batchDeleteByIds(Long[] ids);
List<IotThingRelationDetailDTO> findAllNodesByRootIdAndToId(Long rootId,Long toId);

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

@ -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
public void batchDeleteByIds(Long[] ids) {
//当前节点

Loading…
Cancel
Save