stream 流处理

stream

Map<Long, List<ExceptionMessage>> collect1 = records.parallelStream()
        .collect(Collectors.groupingBy(ExceptionMessage::getId));
Map<Long, FileSys> collect2 = fileSys.parallelStream().collect(Collectors.toMap(FileSys::getExceptionMessageId, t -> t));

Map<Long, Long> collect3 = fileSys.parallelStream().collect(Collectors.toMap(FileSys::getExceptionMessageId, FileSys::getExceptionMessageId));

按理将数据组装

  public Result exceptionMessageList(ExceptionMessageListReq dto) {
        Page<ExceptionMessage> page = new Page<ExceptionMessage>(dto.pageIndex, dto.pageSize);

        IPage<ExceptionMessage> userIPage = exceptionMessageMapper.exceptionMessageList(page, dto);

        List<ExceptionMessage> records = userIPage.getRecords();
        List<Long> collect = records.stream()
                .map(ExceptionMessage::getId)
                .collect(Collectors.toList());
        List<FileSys> fileSys = fileSysMapper.selectByExceptionMessageIdList(collect);

        Map<Long, List<FileSys>> collect1 = fileSys.parallelStream()
                .collect(Collectors.groupingBy(FileSys::getExceptionMessageId));
        List<ExceptionMessageItem> collect2 = records.stream().map(t -> {
            try {
                ExceptionMessageItem exceptionMessageItem = new ExceptionMessageItem();
                ReflectUtil.Copy(t, exceptionMessageItem);
                exceptionMessageItem.filePic = collect1.get(exceptionMessageItem.getId());
                return exceptionMessageItem;
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }).collect(Collectors.toList());
        Result<Object> init = Result.init(0);
        HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("list",collect2);
        objectObjectHashMap.put("total",userIPage.getTotal());
        objectObjectHashMap.put("current",userIPage.getCurrent());
        init.setData(objectObjectHashMap);
        return init;
    }
Last Updated:
Contributors: 刘荣杰