1. 程式人生 > >java處理匯入Excel資料重複資料,整理後在匯入

java處理匯入Excel資料重複資料,整理後在匯入

SysUser su = (SysUser) ContextUtil.getCurrentUser();
ModelAndView mv = new ModelAndView("hthrmis/htimport/importConfig.jsp");
UtilExcelFile uef=new UtilExcelFile();
List<ImportOrgPic> picllist=uef.readExcelPic(excelPicFile,su,request);
if(picllist.size()>5000){
return mv.addObject("viewOkSizeCount",picllist.size());
}
List<ImportOrgPic> newNoPics = new ArrayList<ImportOrgPic>();
   List<ImportOrgPic> newPics = new ArrayList<ImportOrgPic>();
   List<Long> orgIdslist = new ArrayList<Long>();     
   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<ImportOrgPic> newNoOKPics = new ArrayList<ImportOrgPic>();
  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);