Steam常见用法

 // 查询身份证号
    private Map queryCustomIdNoByCustIds(List mergeWithholdCollections) {
        List custIds = mergeWithholdCollections.stream()
                .map(PdmWithholdCollectionInfoDto::getCustId)
                .distinct()
                .collect(Collectors.toList());

        List custInfoList = crmCustExternalBusinessHandlerImpl.getCustInfoByCustId(IdsDto.build(custIds));
        return custInfoList.stream()
                .collect(Collectors.toMap(IdAndNameViewDto::getId,
                        IdAndNameViewDto::getIdCode, (x1, x2) -> x2));
    }
private List mergeWithholdCollectionInfo(List withholdCollectionDtos) {

        List originalCollections = withholdCollectionDtos.stream()
                .filter(dto -> Objects.equals(dto.getCollectionType(), BusinessConstants.COLLECTION_RENT)
                        || Objects.equals(dto.getCollectionType(), BusinessConstants.COLLECTION_RECOVER_ADVANCE))
                .collect(Collectors.toList());

        Map> subCollectionMap = withholdCollectionDtos.stream()
                .filter(dto -> Objects.equals(dto.getCollectionType(), BusinessConstants.COLLECTION_BREACH_CONTRACT))
                .collect(Collectors.groupingBy(PdmWithholdCollectionInfoDto::getOriginalCollectionId));

        Map originalCollectionIdMap = originalCollections.parallelStream()
                .filter(dto -> Objects.equals(dto.getCollectionType(), BusinessConstants.COLLECTION_RENT)
                        || Objects.equals(dto.getCollectionType(), BusinessConstants.COLLECTION_RECOVER_ADVANCE))
                .collect(Collectors.toMap(PdmWithholdCollectionInfoDto::getCollectionId,
                        PdmWithholdCollectionInfoDto::getCollectionId,
                        (v1, v2) -> v1));

        originalCollections.forEach(originalCollection -> {
            originalCollection.setOriginalCollectionId(originalCollection.getCollectionId());
            List subCollectionDtos = subCollectionMap.get(originalCollection.getCollectionId());
            if (!CollectionUtils.isEmpty(subCollectionDtos)) {
                subCollectionDtos.forEach(subCollectionDto -> originalCollection.setPenalCollectionId(subCollectionDto.getCollectionId())
                        .setPenalCollectionCheckState(subCollectionDto.getCheckState())
                        .setPenalCollectionLockState(subCollectionDto.getLockState())
                        .setAmtCollection(originalCollection.getAmtCollection().add(subCollectionDto.getAmtCollection()))
                        .setAmtCheck(originalCollection.getAmtCheck().add(subCollectionDto.getAmtCheck())));
            }
        });

        subCollectionMap.forEach((originalCollectionId, dtoList) -> {
            if (originalCollectionIdMap.get(originalCollectionId) == null) {
                dtoList.forEach(dto -> {
                    dto.setPenalCollectionId(dto.getCollectionId());
                    dto.setCollectionType(dto.getPenalOriginalCollectionType());
                });
                originalCollections.addAll(dtoList);
            }
        });

        // 按照实际应收日期排序
        return originalCollections.stream()
                .sorted(Comparator.comparing(PdmWithholdCollectionInfoDto::getDateCollectionActual))
                .collect(Collectors.toList());
    }

你可能感兴趣的:(算法)