//判断集合中元素的重复 List<User> distinctClass = recordsList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(data -> data.getCustomerCode()))), ArrayList::new)); if(distinctClass.size()!=recordsList.size()) throw new ExcelImortException("1","编码不一致,只能存在一个编码",importResult.getList()); //判断集合中的元素是否存在值 List<User> recordsListNo = recordsList.stream().filter(data -> StringUtils.isNotBlank(data.getErrorMsg())).collect(Collectors.toList()); if(recordsListNo.size() > 0) throw new ExcelImortException("1","有异常数据,请修改完成后重新提交",importResult.getList()); List<User> recordsListYes = recordsList.stream().filter(data -> StringUtils.isEmpty(data.getErrorMsg())).collect(Collectors.toList()); if(recordsListYes.size()==0) throw new ExcelImortException("1","正常数据为空,请修改完成后重新提交",importResult.getList());
detailList.forEach(item->{ UserDetailBiz.insertSelective(item); });
//分组并计算出现次数 Map<String, Long> customerAndCout = list.stream(). collect(Collectors.groupingBy(OrderOutDetail::getCustomerName,Collectors.counting())); //排序 Map<String, String> customerAndCoutMap = new LinkedHashMap<>(); customerAndCout.entrySet().stream().sorted(Map.Entry.<String, Long>comparingByValue().reversed()) .forEachOrdered(e -> customerAndCoutMap.put(e.getKey(), e.getValue().toString()));; //循环赋值 for(String key : customerAndCoutMap.keySet()){ c3=new Cell(new Paragraph(key+": "+customerAndCoutMap.get(key),keyfont)); tFoot.addCell(c3); }