| | |
| | | package com.panzhihua.common.listen; |
| | | |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.IdcardUtil; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import com.alibaba.excel.context.AnalysisContext; |
| | | import com.alibaba.excel.event.AnalysisEventListener; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.panzhihua.common.enums.EldersAuthLevelEnum; |
| | | import com.panzhihua.common.exceptions.ServiceException; |
| | | import com.panzhihua.common.model.vos.R; |
| | |
| | | import com.panzhihua.common.utlis.DateUtils; |
| | | import com.panzhihua.common.utlis.ListUtils; |
| | | import com.panzhihua.common.utlis.StringUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | import cn.hutool.core.util.IdcardUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | /** |
| | | * @description: 高龄老人导入监听 |
| | |
| | | @Slf4j |
| | | public class ComEldersAuthElderlyExcelListen extends AnalysisEventListener<EldersAuthElderlyExcelVO> { |
| | | |
| | | private static final int BATCH_COUNT = 3000; |
| | | private CommunityService communityService; |
| | | |
| | | private Long communityId; |
| | | |
| | | private Long createBy; |
| | | private List<EldersAuthElderlyExcelVO> list = new ArrayList<>(); |
| | | |
| | | public ComEldersAuthElderlyExcelListen(CommunityService communityService, Long communityId, Long createBy){ |
| | | public ComEldersAuthElderlyExcelListen(CommunityService communityService, Long communityId, Long createBy) { |
| | | this.communityService = communityService; |
| | | this.communityId = communityId; |
| | | this.createBy = createBy; |
| | | } |
| | | |
| | | |
| | | private static final int BATCH_COUNT = 3000; |
| | | private List<EldersAuthElderlyExcelVO> list = new ArrayList<>(); |
| | | |
| | | /** |
| | | * @author cedoo |
| | |
| | | List<T> repeatEles = new ArrayList<T>(); |
| | | for (T t : datas) { |
| | | if (set.contains(t)) { |
| | | if(!repeatEles.contains(t)) { |
| | | if (!repeatEles.contains(t)) { |
| | | repeatEles.add(t); |
| | | } |
| | | } else { |
| | |
| | | |
| | | @Override |
| | | public void invoke(EldersAuthElderlyExcelVO eldersAuthElderlyExcelVO, AnalysisContext analysisContext) { |
| | | if(StringUtils.isEmpty(eldersAuthElderlyExcelVO.getName())){ |
| | | if (StringUtils.isEmpty(eldersAuthElderlyExcelVO.getName())) { |
| | | throw new ServiceException("姓名不可为空"); |
| | | } |
| | | if(StringUtils.isEmpty(eldersAuthElderlyExcelVO.getIsExist())){ |
| | | if (StringUtils.isEmpty(eldersAuthElderlyExcelVO.getIsExist())) { |
| | | eldersAuthElderlyExcelVO.setIsExist("是"); |
| | | } |
| | | if(StringUtils.isEmpty(eldersAuthElderlyExcelVO.getIsBigAge())){ |
| | | if (StringUtils.isEmpty(eldersAuthElderlyExcelVO.getIsBigAge())) { |
| | | eldersAuthElderlyExcelVO.setIsBigAge("是"); |
| | | } |
| | | if(StringUtils.isEmpty(eldersAuthElderlyExcelVO.getIdCard())){ |
| | | if (StringUtils.isEmpty(eldersAuthElderlyExcelVO.getIdCard())) { |
| | | throw new ServiceException("身份证号错误"); |
| | | } |
| | | |
| | | String idCard = eldersAuthElderlyExcelVO.getIdCard(); |
| | | if(idCard!=null && idCard.contains("x")){ |
| | | if (idCard != null && idCard.contains("x")) { |
| | | idCard = idCard.replaceAll("x", "X"); |
| | | } |
| | | eldersAuthElderlyExcelVO.setIdCard(idCard); |
| | |
| | | |
| | | list.add(eldersAuthElderlyExcelVO); |
| | | // 达到BATCH_COUNT了,需要去存储一次数据库,防止数据几万条数据在内存,容易OOM |
| | | if(list.size() >= BATCH_COUNT){ |
| | | if (list.size() >= BATCH_COUNT) { |
| | | doAfterAllAnalysed(analysisContext); |
| | | list.clear(); |
| | | } |
| | |
| | | |
| | | @Override |
| | | public void doAfterAllAnalysed(AnalysisContext analysisContext) { |
| | | //去重 |
| | | List<String> idcardList = new ArrayList<>(); |
| | | // 去重 |
| | | List<String> idcardList = new ArrayList<>(); |
| | | list.forEach(voInList -> { |
| | | idcardList.add(voInList.getIdCard()); |
| | | }); |
| | | List<String> repeatList = findRepeat(idcardList); |
| | | if(repeatList!=null && repeatList.size()>0){ |
| | | 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); |
| | | 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()); |
| | | } |