java处理导入Excel数据重复数据,整理后在导入

作者官方网站:http://www.wxl568.cn

SysUser su = (SysUser) ContextUtil.getCurrentUser();
ModelAndView mv = new ModelAndView("hthrmis/htimport/importConfig.jsp");
UtilExcelFile uef=new UtilExcelFile();
List picllist=uef.readExcelPic(excelPicFile,su,request);
if(picllist.size()>5000){
return mv.addObject("viewOkSizeCount",picllist.size());
}
List newNoPics = new ArrayList();
   List newPics = new ArrayList();
   List orgIdslist = new ArrayList();     
   boolean contain;
   for(int i = 0;i < picllist.size();i++){
     contain = orgIdslist.contains(picllist.get(i).getOrgId());   
     if(contain == false){//封装数据
     orgIdslist.add(picllist.get(i).getOrgId());  
             ImportOrgPic newU = new ImportOrgPic();//
             newU.setOrgId(picllist.get(i).getOrgId());
             newU.setOrgCode(picllist.get(i).getOrgCode());
             newU.setOrgName(picllist.get(i).getOrgName());
             newU.setOrgWholeName(picllist.get(i).getOrgWholeName());
             newU.setPrincipalCode(picllist.get(i).getPrincipalCode());
             newU.setPrincipalName(picllist.get(i).getPrincipalName());
             newU.setInvYear(picllist.get(i).getInvYear());
             newU.setOperation(picllist.get(i).getOperation());
             newPics.add(newU);
     }else{//     
     ImportOrgPic newU = new ImportOrgPic();//
              newU.setOrgId(picllist.get(i).getOrgId());
              newU.setOrgCode(picllist.get(i).getOrgCode());
              newU.setOrgName(picllist.get(i).getOrgName());
              newU.setOrgWholeName(picllist.get(i).getOrgWholeName());
              newU.setPrincipalCode(picllist.get(i).getPrincipalCode());
              newU.setPrincipalName(picllist.get(i).getPrincipalName());
              newU.setInvYear(picllist.get(i).getInvYear());
              newU.setOperation(picllist.get(i).getOperation());
              newNoPics.add(newU);     
     }
   }//数据清洗
List newNoOKPics = new ArrayList();
  for(int k = 0; k < newNoPics.size();k++ ){
     for(int p = 0; p < newPics.size();p++ ){
     if(String.valueOf(newPics.get(p).getOrgId()).equals(String.valueOf(newNoPics.get(k).getOrgId()))){
     ImportOrgPic newU = new ImportOrgPic();//id,newName,age
             newU.setOrgId(newPics.get(p).getOrgId());
             newU.setOrgName(newPics.get(p).getOrgName());
             newU.setOrgCode(newPics.get(p).getOrgCode());
             newU.setOrgWholeName(newPics.get(p).getOrgWholeName());
             newU.setPrincipalCode(newPics.get(p).getPrincipalCode());
             newU.setPrincipalName(newPics.get(p).getPrincipalName());
             newU.setInvYear(newPics.get(p).getInvYear());
             newU.setOperation(newPics.get(p).getOperation());
              newNoOKPics.add(newU);
              newPics.remove(p);
              break;
     }
}
   }   
  newNoOKPics.addAll(newNoPics);//数据清洗后
OrgPiclList piclListOne=new OrgPiclList();
piclListOne.setUserId(su.getUserId());
piclListOne.setAccount(su.getAccount());
piclListOne.setOrgPiclist(newPics);
piclListOne.setNewNoOKPics(newNoOKPics);
piclListOne.setCreateEmpId(su.getUserId());
piclListOne.setCreateEmpCode(su.getAccount());
piclListOne.setModifyEmpCode(su.getAccount());
SystemInventoryDateView piclListOneDate=new SystemInventoryDateView();
piclListOneDate.setUserId(su.getUserId());
piclListOneDate.setAccount(su.getAccount());
piclListOneDate.setCreateEmpId(su.getUserId());
piclListOneDate.setCreateEmpCode(su.getAccount());
piclListOneDate.setModifyEmpCode(su.getAccount());
SystemInventoryDateView dateView = getIndexConfig(piclListOneDate);
Date currentDate = new Date();
String startDate="";
String strEndDate="";
String openSystemStatus="";
if(dateView!=null){
startDate=DateUtil.formatDate(dateView.getStartDate(), "yyyy-MM-dd");
strEndDate=DateUtil.formatDate(dateView.getEndDate(), "yyyy-MM-dd");
openSystemStatus=getSystemDate(currentDate, dateView.getStartDate(),dateView.getEndDate());
}
OrgPiclList picruturnlis=htimportServce.setSavePiclList(piclListOne);
String titleName="导入组织负责人";
String typeImpo="indexApic";
Integer addOkSize=0;//添加成功数据
Integer addErrorSize=0;//添加错数据
Integer updateOkSzie=0;//存在更新成功数据
Integer deleteOkSize=0;//删除
if(picruturnlis!=null){
if(picruturnlis.getAddErrorSize()!=null){
 addErrorSize=picruturnlis.getAddErrorSize();
}
if(picruturnlis.getAddOkSize()!=null){
addOkSize=picruturnlis.getAddOkSize();
}
if(picruturnlis.getUpdateOkSzie()!=null){
updateOkSzie=picruturnlis.getUpdateOkSzie();
}
if(picruturnlis.getDeleteOkSize()!=null){
deleteOkSize=picruturnlis.getDeleteOkSize();
}
addOkSize=addOkSize+updateOkSzie;
}
String urlErrDow="hthrmis/htimport/htimportContro/exportExcelOrgPicErr.ht";
return mv.addObject("urlErrDow", urlErrDow).addObject("titleName", titleName).addObject("typeImpo", typeImpo).addObject("deleteOkSize", deleteOkSize).addObject("addOkSize",addOkSize).addObject("updateOkSzie",updateOkSzie).addObject("addErrorSize",addErrorSize).addObject("openSystemStatus", openSystemStatus).addObject("typeImpo", typeImpo).addObject("dateView", dateView).addObject("startDate", startDate).addObject("strEndDate", strEndDate);

你可能感兴趣的:(java)