From 6105ca330d11970da646474f50ffafaaff3ae9f1 Mon Sep 17 00:00:00 2001 From: lishuai Date: Thu, 5 Sep 2024 14:05:02 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A1=BA=E5=BA=8F?= =?UTF-8?q?=E9=97=AE=E9=A2=98=202024=E5=B9=B49=E6=9C=885=E6=97=A514:05:00?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IotThingRelationDetailServiceImpl.java | 135 ++++++++++-------- 1 file changed, 72 insertions(+), 63 deletions(-) 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 5a80001..adfd661 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 @@ -337,70 +337,76 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl iotThingRelationDetailEntities = mapper.selectListByQuery(queryWrapper); - if (CollectionUtils.isEmpty(iotThingRelationDetailEntities)) { - throw new SysException("当前根关系下节点信息列表异常"); - } - //找出当前移动节点的 所有子节点,即所有需要移动的节点集合 - List sourceChildList = Lists.newArrayList(); - findAllChild(iotThingRelationDetailEntities, sourceEntity, sourceChildList); - sourceChildList.add(sourceEntity); - - //获取前端的参数中 父节点的所有子节点的最大顺序的节点 - Optional optionalMax = iotThingRelationDetailEntities.stream() - .filter(item -> Objects.equals(item.getFromId(), targetEntity.getToId()) && Objects.equals(item.getRootThingId(), targetEntity.getRootThingId())) - .max(comparing(IotThingRelationDetailEntity::getSort)); - if(optionalMax.isEmpty()){ - //若没有子节点,那就自己为节点 - optionalMax = iotThingRelationDetailEntities.stream().filter(item -> - Objects.equals(item.getId(), dto.getPid()) - ).findFirst(); - } - //父节点上面的加入到list中 - Optional finalOptionalMax = optionalMax; - //找出目标节点上面的所有节点,但是不包含 移动节点和子节点 - List resList = new ArrayList<>(iotThingRelationDetailEntities.stream() - .filter(item -> item.getSort() <= finalOptionalMax.get().getSort() - && !sourceChildList.stream().map(IotThingRelationDetailEntity::getId).toList().contains(item.getId()) - ).sorted(Comparator.comparing(IotThingRelationDetailEntity::getSort)).toList()); - - sourceChildList.stream().sorted(Comparator.comparing(IotThingRelationDetailEntity::getSort)).forEach(item -> { - if(Objects.equals(item.getId(), sourceEntity.getId())){ - item.setFromId(targetEntity.getFromId()) - .setFromName(targetEntity.getFromName()) - .setFromCode(targetEntity.getFromCode()) - .setRootId(dto.getRootId()) - .setRootThingId(targetEntity.getRootThingId()) - .setToName(sourceEntity.getToName()) - .setTag(dto.getTag()); + + sourceEntity.setTag(StringUtils.isBlank(dto.getTag()) ? dto.getToName() : dto.getTag()); + + if(Objects.isNull(dto.getPid()) || Objects.equals(dto.getPid(), 0L)){ + mapper.update(sourceEntity); + } else { + + + IotThingRelationDetailEntity targetEntity = mapper.selectOneById(dto.getPid()); + if (Objects.isNull(targetEntity)) { + throw new SysException("当前目标节点关系不存在"); + } + if(!Objects.equals(sourceEntity.getRootThingId(), targetEntity.getRootThingId())){ + throw new SysException("当前移动节点和目标节点不在同一个根节点下,无法移动"); + } + + if(sourceEntity.getFromId().equals(targetEntity.getToId())){ + mapper.update(sourceEntity); }else{ - item.setRootThingId(targetEntity.getRootThingId()); + //查询当前关系下所有节点信息 + List iotThingRelationDetailEntities = mapper.selectListByQuery(QueryWrapper.create().eq(IotThingRelationDetailEntity::getRootId, dto.getRootId())); + if (CollectionUtils.isEmpty(iotThingRelationDetailEntities)) { + throw new SysException("当前根关系下节点信息列表异常"); + } + //找出当前移动节点的 所有子节点,即所有需要移动的节点集合 + List sourceChildList = Lists.newArrayList(); + findAllChild(iotThingRelationDetailEntities, sourceEntity, sourceChildList); + sourceChildList.add(sourceEntity); + + List sourceChildIds = sourceChildList.stream().map(IotThingRelationDetailEntity::getId).toList(); + //找出不包源节点 , 目标节点顺序的节点 ,并且顺序大于目标节点顺序的节点 + List dlist = iotThingRelationDetailEntities.stream() + .filter(d -> !sourceChildIds.contains(d.getId()) && targetEntity.getSort() > d.getSort()) + .sorted(Comparator.comparing(IotThingRelationDetailEntity::getSort)) + .toList(); + + List resultList = new ArrayList<>(dlist); + + //找出当前目标节点的所有子节点 + List targetChildList = Lists.newArrayList(); + findAllChild(iotThingRelationDetailEntities, targetEntity, targetChildList); + targetChildList.add(targetEntity); + //将当前目标节点的所有子节点,按照顺序排序 + List list = targetChildList.stream().sorted(comparing(IotThingRelationDetailEntity::getSort)).toList(); + resultList.addAll(list); + + sourceEntity.setFromId(targetEntity.getToId()); + sourceEntity.setFromCode(targetEntity.getToCode()); + sourceEntity.setFromName(targetEntity.getFromName()); + resultList.add(sourceEntity); + + + List targetChildIds = list.stream().map(IotThingRelationDetailEntity::getId).toList(); + + //找出不包源节点 , 目标节点顺序的节点 ,并且顺序小于目标节点顺序的节点 + List xlist = iotThingRelationDetailEntities.stream().filter(d -> !sourceChildIds.contains(d.getId()) && !targetChildIds.contains(d.getId()) + && list.get(list.size()-1).getSort() < d.getSort()).toList(); + + resultList.addAll(xlist); + + //更新排序 + AtomicLong sort = new AtomicLong(0); + resultList.forEach(item -> + { + item.setSort(sort.incrementAndGet()); + mapper.updateByQuery(item, QueryWrapper.create().eq(IotThingRelationDetailEntity::getId, item.getId())); + } + ); } - resList.add(item); - }); - //剩余的节点添加到list中 - iotThingRelationDetailEntities.stream() - .filter(item -> item.getSort() > finalOptionalMax.get().getSort() && !sourceChildList.stream().map(IotThingRelationDetailEntity::getId).toList().contains(item.getId())) - .sorted(Comparator.comparing(IotThingRelationDetailEntity::getSort)) - .forEach(resList::add); - //更新排序 - AtomicLong sort = new AtomicLong(0); - resList.forEach(item -> - { - item.setSort(sort.incrementAndGet()); - mapper.updateByQuery(item, QueryWrapper.create().eq(IotThingRelationDetailEntity::getId, item.getId())); } - ); //更新缓存 cache.clearTopic(CacheNameEnum.THING_DETAIL_RELATION); } @@ -555,11 +561,14 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl findTreeList(List rootIds) { //关系节点 - List rootList = cache.findAllKeyMap(CacheNameEnum.THING_ROOT_RELATION, rootIds.stream().map(String::valueOf).toList()); + String result = rootIds.stream() + .map(Object::toString) // 将每个元素转换为字符串 + .collect(Collectors.joining(",")); + List rootList = relationRootsService.findList(null, null, result, null, null, null); if (CollectionUtils.isEmpty(rootList)) { return Lists.newArrayList(); } - List detailList = cache.findAllKeyMap(CacheNameEnum.THING_DETAIL_RELATION, rootIds.stream().map(String::valueOf).toList()); + List detailList = findList(null, null, result, null, null, null); if (CollectionUtils.isEmpty(detailList)) { return rootList; From fd01bfc2a524eeeb54361e0be22a388d06cd1480 Mon Sep 17 00:00:00 2001 From: xiachao Date: Thu, 5 Sep 2024 14:06:41 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=B0=96=E5=B3=B0=E8=B0=B7=E5=B9=B3?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/CarbonEnergyPriceServiceImpl.java | 22 ++++++++++++++----- .../impl/CarbonPeakConfigServiceImpl.java | 22 +++++++++++++++---- .../thing/sys/tenant/dto/SysTenantDTO.java | 3 +++ .../controller/IotVisualManageController.java | 2 +- 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/modules/report-analysis/src/main/java/com/thing/carbon/config/service/impl/CarbonEnergyPriceServiceImpl.java b/modules/report-analysis/src/main/java/com/thing/carbon/config/service/impl/CarbonEnergyPriceServiceImpl.java index 3e184d6..a55c087 100644 --- a/modules/report-analysis/src/main/java/com/thing/carbon/config/service/impl/CarbonEnergyPriceServiceImpl.java +++ b/modules/report-analysis/src/main/java/com/thing/carbon/config/service/impl/CarbonEnergyPriceServiceImpl.java @@ -242,12 +242,13 @@ public class CarbonEnergyPriceServiceImpl extends BaseServiceImpl params = new HashMap<>(); UserDetail userDetail = SecurityUser.getUser(); Long tenantCode = TenantContext.getTenantCode(userDetail); - List tenantCodeList; + List tenantCodeList = new ArrayList<>(); List resultTenantCodeList = new ArrayList<>(); + boolean flag = true; if (!Objects.equals(userDetail.getSuperAdmin(), SuperAdminEnum.YES.value()) || !Objects.equals(tenantCode, userDetail.getTenantCode())) { - tenantCodeList = sysTenantGroupService.getChildren(tenantCode); + flag = false; tenantCodeList.add(tenantCode); tenantCodeList.add(1001L); QueryWrapper wrapper = new QueryWrapper(); @@ -264,9 +265,20 @@ public class CarbonEnergyPriceServiceImpl extends BaseServiceImpl tenantDTOS = sysTenantDao.queryList(params).parallelStream().sorted(Comparator.comparingLong(SysTenantDTO::getTenantCode)).collect(Collectors.toList()); + if(!flag){ + tenantDTOS.forEach(temp->{ + if(Objects.equals(temp.getTenantCode(), 1001L)){ + temp.setIsOperate(false); + temp.setTenantName("系统默认"); + }else { + temp.setIsOperate(true); + + } + }); + } + return tenantDTOS; } @Override diff --git a/modules/report-analysis/src/main/java/com/thing/carbon/config/service/impl/CarbonPeakConfigServiceImpl.java b/modules/report-analysis/src/main/java/com/thing/carbon/config/service/impl/CarbonPeakConfigServiceImpl.java index b8451b5..ea16cbe 100644 --- a/modules/report-analysis/src/main/java/com/thing/carbon/config/service/impl/CarbonPeakConfigServiceImpl.java +++ b/modules/report-analysis/src/main/java/com/thing/carbon/config/service/impl/CarbonPeakConfigServiceImpl.java @@ -106,15 +106,15 @@ public class CarbonPeakConfigServiceImpl extends BaseServiceImpl tenantList() { + boolean flag = true; Map params = new HashMap<>(); UserDetail userDetail = SecurityUser.getUser(); Long tenantCode = TenantContext.getTenantCode(userDetail); - List tenantCodeList; + List tenantCodeList = new ArrayList<>(); List resultTenantCodeList= new ArrayList<>(); - if(!Objects.equals(userDetail.getSuperAdmin(), SuperAdminEnum.YES.value()) || !Objects.equals(tenantCode, userDetail.getTenantCode())) { - tenantCodeList=sysTenantGroupService.getChildren(tenantCode); + flag = false; tenantCodeList.add(tenantCode); tenantCodeList.add(1001L); QueryWrapper wrapper = new QueryWrapper(); @@ -131,7 +131,21 @@ public class CarbonPeakConfigServiceImpl extends BaseServiceImpl tenantDTOS = sysTenantDao.queryList(params).parallelStream().sorted(Comparator.comparingLong(SysTenantDTO::getTenantCode)).collect(Collectors.toList()); + if(!flag){ + tenantDTOS.forEach(temp->{ + if(Objects.equals(temp.getTenantCode(), 1001L)){ + temp.setIsOperate(false); + temp.setTenantName("系统默认"); + }else { + temp.setIsOperate(true); + + } + }); + } + + return tenantDTOS; } @Override diff --git a/modules/thing/src/main/java/com/thing/sys/tenant/dto/SysTenantDTO.java b/modules/thing/src/main/java/com/thing/sys/tenant/dto/SysTenantDTO.java index 26a7ef7..0a58ff8 100644 --- a/modules/thing/src/main/java/com/thing/sys/tenant/dto/SysTenantDTO.java +++ b/modules/thing/src/main/java/com/thing/sys/tenant/dto/SysTenantDTO.java @@ -114,4 +114,7 @@ public class SysTenantDTO implements Serializable { @Schema(description = "企业物数量") private Integer enterpriseThings; + + @Schema(description = "峰平谷尖/价格配置使用,是否可操作数据节点") + private Boolean isOperate; } \ No newline at end of file diff --git a/modules/visual-design/src/main/java/com/thing/visual/board/controller/IotVisualManageController.java b/modules/visual-design/src/main/java/com/thing/visual/board/controller/IotVisualManageController.java index 0f93f58..9a6dc49 100644 --- a/modules/visual-design/src/main/java/com/thing/visual/board/controller/IotVisualManageController.java +++ b/modules/visual-design/src/main/java/com/thing/visual/board/controller/IotVisualManageController.java @@ -54,7 +54,7 @@ public class IotVisualManageController { @Parameter(name ="name",description ="看板名称"), @Parameter(name ="type",description ="看板类型") }) - public Result> page(@RequestParam Map params){ + public Result> page(@RequestParam Map params){ PageData page = iotVisualManageService.pageIotBoardManageDTO(params); return new Result>().ok(page);