java8 lamda表达式
list 分组
1.多字段联合,分组
list.stream().collect(Collectors.groupingBy(o -> o.getSkuName() + "_" + o.getOeCode(), Collectors.toList()));
2.求和计算
Integer num =list.stream().mapToInt(n -> n.getNum()).sum();
3.分组-排序
list.stream().collect(Collectors.groupingBy(EnquiryDetail::getQualityId)) .values().stream().map(enquiryDetails -> { List<EnquiryDetail> rspDetails = enquiryDetails.stream().sorted(Comparator.comparing(EnquiryDetail::getQuotePrice)).collect(Collectors.toList()); rspDetails.get(0).setCheck(true); return rspDetails; }).flatMap(Collection::stream).collect(Collectors.toList());
//按价格排序
// List<SupplierEnquiryDetail> details = busGroup.entrySet().stream().map(detail -> {
// SupplierEnquiryDetail supplyEnquiryCompareResp = BeanUtil.copyProperties(detail, SupplierEnquiryDetail.class);
// return supplyEnquiryCompareResp;
// }).sorted(Comparator.comparing(SupplierEnquiryDetail::getTaxQuotePrice) ).collect(Collectors.toList());
// List<SupplierEnquiryDetail> details = busGroup.entrySet().stream().map(detail -> {
// SupplierEnquiryDetail supplyEnquiryCompareResp = BeanUtil.copyProperties(detail, SupplierEnquiryDetail.class);
// return supplyEnquiryCompareResp;
// }).sorted(Comparator.comparing(SupplierEnquiryDetail::getTaxQuotePrice) ).collect(Collectors.toList());
// return respDetails.stream().collect(Collectors.groupingBy(EnquiryCompareResp.EnquiryDetail::getQualityId))
// .values().stream().map(enquiryDetails -> {
// List<EnquiryCompareResp.EnquiryDetail> rspDetails = enquiryDetails.stream().sorted(Comparator.comparing(EnquiryCompareResp.EnquiryDetail::getQuotePrice)).collect(Collectors.toList());
// rspDetails.get(0).setCheck(true);
// return rspDetails;
// }).flatMap(Collection::stream).collect(Collectors.toList());
// .values().stream().map(enquiryDetails -> {
// List<EnquiryCompareResp.EnquiryDetail> rspDetails = enquiryDetails.stream().sorted(Comparator.comparing(EnquiryCompareResp.EnquiryDetail::getQuotePrice)).collect(Collectors.toList());
// rspDetails.get(0).setCheck(true);
// return rspDetails;
// }).flatMap(Collection::stream).collect(Collectors.toList());
过滤
respDetails.stream().filter(item -> !request.getQualityId().contains(item.getQualityId())).collect(Collectors.toList());