public List<ComponentDataDTO> getComponentMinAndMaxData(String tableName, List<AnchorAndComponentDO> anchorAndComponentDOList, LocalDateTime startLocalDateTime, LocalDateTime endLocalDateTime) {
        List<ComponentDataDTO> componentDataDTOList = new ArrayList<>();
        ConcurrentHashMap<String,List<ComponentDataDTO>> componentDataDTOMap = new ConcurrentHashMap<>();
        if(anchorAndComponentDOList!=null && !anchorAndComponentDOList.isEmpty()){
            //多线程调用
            List<CompletableFuture<Boolean>> completableFutureList = anchorAndComponentDOList.stream().map((AnchorAndComponentDO anchorComponent)->
                    CompletableFuture.supplyAsync(()->{
                        try{
                            //调用处理
                            List<ComponentDataDTO> componentMinAndMaxDataList = componentMapper.getComponentMinAndMaxData(tableName, anchorComponent, startLocalDateTime, endLocalDateTime);
                            componentDataDTOMap.put(anchorComponent.getAnchorId()+":"+anchorComponent.getComponentId(),componentMinAndMaxDataList);
                        }catch (Exception e){
                            //记录备注Map
                            logger.error("监测点:"+anchorComponent.getAnchorId()+",监测项:"+anchorComponent.getComponentId()+",获取数据报错:"+e+"-"+e.getMessage());
                            return false;
                        }
                        return true;
                    })).collect(Collectors.toList());
            List<Boolean> collect = completableFutureList.stream().map(CompletableFuture::join).collect(Collectors.toList());
            if(!collect.contains(false)){
                componentDataDTOMap.forEach((k, v) -> componentDataDTOList.addAll(v));
            }
        }
        return componentDataDTOList;
    }

 

相关文章:

  • 2022-02-21
  • 2021-06-03
  • 2021-10-31
  • 2022-12-23
  • 2023-04-06
  • 2021-12-27
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-01
  • 2022-12-23
  • 2021-09-22
  • 2023-03-19
  • 2021-10-14
  • 2023-03-21
相关资源
相似解决方案