| | |
| | | import com.panzhihua.common.utlis.StringUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | private static final int BATCH_COUNT = 3000; |
| | | private List<EldersAuthElderlyExcelVO> list = new ArrayList<>(); |
| | | |
| | | /** |
| | | * @author cedoo |
| | | * @Description:找出list中的重复数据 |
| | | * @param datas |
| | | * @return |
| | | */ |
| | | public static <T> List<T> findRepeat(Collection<T> datas) { |
| | | if (datas instanceof Set) { |
| | | return new ArrayList<>(); |
| | | } |
| | | HashSet<T> set = new HashSet<T>(); |
| | | List<T> repeatEles = new ArrayList<T>(); |
| | | for (T t : datas) { |
| | | if (set.contains(t)) { |
| | | repeatEles.add(t); |
| | | } else { |
| | | set.add(t); |
| | | } |
| | | } |
| | | return repeatEles; |
| | | } |
| | | |
| | | @Override |
| | | public void invoke(EldersAuthElderlyExcelVO eldersAuthElderlyExcelVO, AnalysisContext analysisContext) { |
| | | if(StringUtils.isEmpty(eldersAuthElderlyExcelVO.getName())){ |
| | |
| | | list.add(eldersAuthElderlyExcelVO); |
| | | // 达到BATCH_COUNT了,需要去存储一次数据库,防止数据几万条数据在内存,容易OOM |
| | | if(list.size() >= BATCH_COUNT){ |
| | | log.info("excel导入数据【{}】", JSONObject.toJSONString(list)); |
| | | List<EldersAuthElderlyExcelVO> newVoList = list.stream().filter(ListUtils.distinctByKey(EldersAuthElderlyExcelVO::getIdCard)).collect(Collectors.toList()); |
| | | R r = this.communityService.listSaveEldersAuthElderlyExcelVO(newVoList,this.communityId,this.createBy); |
| | | if (!R.isOk(r)) { |
| | | throw new ServiceException(r.getMsg()); |
| | | } |
| | | list.clear(); //清空list |
| | | doAfterAllAnalysed(analysisContext); |
| | | list.clear(); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void doAfterAllAnalysed(AnalysisContext analysisContext) { |
| | | //去重 |
| | | List<String> idcardList = new ArrayList<>(); |
| | | list.forEach(voInList -> { |
| | | idcardList.add(voInList.getIdCard()); |
| | | }); |
| | | List<String> repeatList = findRepeat(idcardList); |
| | | if(repeatList!=null && repeatList.size()>0){ |
| | | String repeatedId = StringUtils.join(repeatList, ","); |
| | | throw new ServiceException(repeatedId + " 身份证号码存在多条"); |
| | | } |
| | | List<EldersAuthElderlyExcelVO> newVoList = list.stream().filter(ListUtils.distinctByKey(EldersAuthElderlyExcelVO::getIdCard)).collect(Collectors.toList()); |
| | | R r = this.communityService.listSaveEldersAuthElderlyExcelVO(newVoList,this.communityId,this.createBy); |
| | | if (!R.isOk(r)) { |