Browse Source

Merge pull request 'master' (#33) from master into V3

Reviewed-on: http://git.lrdaiot.cn:9000/thing/thing_api/pulls/33
qingyuan_dev_new
夏超 1 year ago
parent
commit
eabd5804d5
  1. 22
      modules/report-analysis/src/main/java/com/thing/carbon/config/service/impl/CarbonEnergyPriceServiceImpl.java
  2. 22
      modules/report-analysis/src/main/java/com/thing/carbon/config/service/impl/CarbonPeakConfigServiceImpl.java
  3. 3
      modules/thing/src/main/java/com/thing/sys/tenant/dto/SysTenantDTO.java
  4. 135
      modules/thing/src/main/java/com/thing/thing/relation/detail/service/impl/IotThingRelationDetailServiceImpl.java
  5. 2
      modules/visual-design/src/main/java/com/thing/visual/board/controller/IotVisualManageController.java

22
modules/report-analysis/src/main/java/com/thing/carbon/config/service/impl/CarbonEnergyPriceServiceImpl.java

@ -242,12 +242,13 @@ public class CarbonEnergyPriceServiceImpl extends BaseServiceImpl<CarbonEnergyPr
Map<String, Object> params = new HashMap<>();
UserDetail userDetail = SecurityUser.getUser();
Long tenantCode = TenantContext.getTenantCode(userDetail);
List<Long> tenantCodeList;
List<Long> tenantCodeList = new ArrayList<>();
List<Long> 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<CarbonEnergyPr
resultTenantCodeList.add(-1L);
}
params.put("tenantCodeList", resultTenantCodeList);
return sysTenantDao.queryList(params).parallelStream()
.sorted(Comparator.comparingLong(SysTenantDTO::getTenantCode))
.collect(Collectors.toList());
List<SysTenantDTO> 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

22
modules/report-analysis/src/main/java/com/thing/carbon/config/service/impl/CarbonPeakConfigServiceImpl.java

@ -106,15 +106,15 @@ public class CarbonPeakConfigServiceImpl extends BaseServiceImpl<CarbonPeakConfi
@Override
public List<SysTenantDTO> tenantList() {
boolean flag = true;
Map<String,Object> params = new HashMap<>();
UserDetail userDetail = SecurityUser.getUser();
Long tenantCode = TenantContext.getTenantCode(userDetail);
List<Long> tenantCodeList;
List<Long> tenantCodeList = new ArrayList<>();
List<Long> 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<CarbonPeakConfi
resultTenantCodeList.add(-1L);
}
params.put("tenantCodeList",resultTenantCodeList);
return sysTenantDao.queryList(params).parallelStream().sorted(Comparator.comparingLong(SysTenantDTO::getTenantCode)).collect(Collectors.toList());
List<SysTenantDTO> 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

3
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;
}

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

@ -337,70 +337,76 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl<IotThingR
if (Objects.isNull(sourceEntity)) {
throw new SysException("当前移动节点关系不存在");
}
IotThingRelationDetailEntity targetEntity = mapper.selectOneById(dto.getPid());
if (Objects.isNull(targetEntity)) {
throw new SysException("当前目标节点关系不存在");
}
if(!Objects.equals(sourceEntity.getRootThingId(), targetEntity.getRootThingId())){
throw new SysException("当前移动节点和目标节点不在同一个根节点下,无法移动");
}
//查询当前关系下所有节点信息但是不包括当前节点
QueryWrapper queryWrapper = QueryWrapper.create().eq(IotThingRelationDetailEntity::getRootId, dto.getRootId());
//这里肯定有数据
List<IotThingRelationDetailEntity> iotThingRelationDetailEntities = mapper.selectListByQuery(queryWrapper);
if (CollectionUtils.isEmpty(iotThingRelationDetailEntities)) {
throw new SysException("当前根关系下节点信息列表异常");
}
//找出当前移动节点的 所有子节点,即所有需要移动的节点集合
List<IotThingRelationDetailEntity> sourceChildList = Lists.newArrayList();
findAllChild(iotThingRelationDetailEntities, sourceEntity, sourceChildList);
sourceChildList.add(sourceEntity);
//获取前端的参数中 父节点的所有子节点的最大顺序的节点
Optional<IotThingRelationDetailEntity> 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<IotThingRelationDetailEntity> finalOptionalMax = optionalMax;
//找出目标节点上面的所有节点但是不包含 移动节点和子节点
List<IotThingRelationDetailEntity> 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<IotThingRelationDetailEntity> iotThingRelationDetailEntities = mapper.selectListByQuery(QueryWrapper.create().eq(IotThingRelationDetailEntity::getRootId, dto.getRootId()));
if (CollectionUtils.isEmpty(iotThingRelationDetailEntities)) {
throw new SysException("当前根关系下节点信息列表异常");
}
//找出当前移动节点的 所有子节点,即所有需要移动的节点集合
List<IotThingRelationDetailEntity> sourceChildList = Lists.newArrayList();
findAllChild(iotThingRelationDetailEntities, sourceEntity, sourceChildList);
sourceChildList.add(sourceEntity);
List<Long> sourceChildIds = sourceChildList.stream().map(IotThingRelationDetailEntity::getId).toList();
//找出不包源节点 , 目标节点顺序的节点 并且顺序大于目标节点顺序的节点
List<IotThingRelationDetailEntity> dlist = iotThingRelationDetailEntities.stream()
.filter(d -> !sourceChildIds.contains(d.getId()) && targetEntity.getSort() > d.getSort())
.sorted(Comparator.comparing(IotThingRelationDetailEntity::getSort))
.toList();
List<IotThingRelationDetailEntity> resultList = new ArrayList<>(dlist);
//找出当前目标节点的所有子节点
List<IotThingRelationDetailEntity> targetChildList = Lists.newArrayList();
findAllChild(iotThingRelationDetailEntities, targetEntity, targetChildList);
targetChildList.add(targetEntity);
//将当前目标节点的所有子节点按照顺序排序
List<IotThingRelationDetailEntity> 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<Long> targetChildIds = list.stream().map(IotThingRelationDetailEntity::getId).toList();
//找出不包源节点 , 目标节点顺序的节点 并且顺序小于目标节点顺序的节点
List<IotThingRelationDetailEntity> 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<IotThingR
@Override
public List<ObjectNode> findTreeList(List<Long> rootIds) {
//关系节点
List<ObjectNode> rootList = cache.findAllKeyMap(CacheNameEnum.THING_ROOT_RELATION, rootIds.stream().map(String::valueOf).toList());
String result = rootIds.stream()
.map(Object::toString) // 将每个元素转换为字符串
.collect(Collectors.joining(","));
List<ObjectNode> rootList = relationRootsService.findList(null, null, result, null, null, null);
if (CollectionUtils.isEmpty(rootList)) {
return Lists.newArrayList();
}
List<ObjectNode> detailList = cache.findAllKeyMap(CacheNameEnum.THING_DETAIL_RELATION, rootIds.stream().map(String::valueOf).toList());
List<ObjectNode> detailList = findList(null, null, result, null, null, null);
if (CollectionUtils.isEmpty(detailList)) {
return rootList;

2
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<PageData<IotVisualManageDTO>> page(@RequestParam Map<String, Object> params){
public Result<PageData<IotVisualManageDTO>> page(@RequestParam Map<String, Object> params){
PageData<IotVisualManageDTO> page = iotVisualManageService.pageIotBoardManageDTO(params);
return new Result<PageData<IotVisualManageDTO>>().ok(page);

Loading…
Cancel
Save