项目中有个需求是获取excel中的成员信息,需要剔除重复身份证号以及返回重复身份证号给前端~~
//判断excel导入的成员信息身份证号是否重复
//得到excel表所有成员信息list
List<Map<String,Object>> list = ExcelUtils.parseExcelToObject(sheetTable,strArr);
//得到所有身份证号集合
List<String> stringList = list.stream().map(map -> map.get("sfzh").toString()).collect(Collectors.toList());
//统计stream中元素的个数
Map<String, Long> collect = stringList.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
//返回重复身份证号集合或者使用collect遍历value大于1得到重复值
List<String> result = collect.entrySet().stream().filter(e -> e.getValue() > 1).map(Map.Entry::getKey).collect(Collectors.toList());
//去除重复后的个数
long count1 = stringList.stream().distinct().count();
List<GhxxCyxx> GhxxCyxxList = new ArrayList<>();
//有重复,返回给前端
if (count1 != stringList.size() ){
return RestResponse.failed(result);
}