package UIM.WGJ; import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.event.AnalysisEventListener; import CoreFS.SA06.CoreReturnObject; import QCM.COMMUNAL.OrderSqMapper; import QCM.COMMUNAL.VO.ExcelWGJ; import QCM.COMMUNAL.VO.ExcelWGJCF; import QCM.COMMUNAL.VO.ExcelWGJCXN; import QCM.COMMUNAL.VO.ExcelWGJMain; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.SqlSession; public class ExcelModelListener extends AnalysisEventListener { private String opman; public ExcelModelListener(String opman){ this.opman = opman; } private static final int BATCH_COUNT = 1000; List list = new ArrayList(); List list1 = new ArrayList(); List list2 = new ArrayList(); List list3 = new ArrayList(); List list4 = new ArrayList(); //Map map = new HashMap<>(); private static int count = 1; @Override public void invoke(ExcelWGJ data, AnalysisContext context) { list.add(data); count ++; if (list.size() >= BATCH_COUNT) { saveData(); list.clear(); } } @Override public void doAfterAllAnalysed(AnalysisContext context) { saveData(); list.clear(); } private CoreReturnObject saveData() { int i = 0; int count=0; int index = 0; SimpleDateFormat sdf=new SimpleDateFormat("yy"); String date=sdf.format(new Date()); CoreReturnObject cro = new CoreReturnObject(); SqlSession SqlSession = QCM.COMMUNAL.SqlSessionBuilder.openSqlSession(); OrderSqMapper mapper = SqlSession.getMapper(QCM.COMMUNAL.OrderSqMapper.class); try{ for(ExcelWGJ excelWGJ :list){ count = Integer.parseInt(mapper.queryMaxXuHao()); index = Integer.parseInt(excelWGJ.getCoil_no()); /*if(!("".equals(excelWGJ.getKlqd())||null==excelWGJ.getKlqd())){ ExcelWGJCXN ewxn = new ExcelWGJCXN(); ewxn.setSpecimen_no(excelWGJ.getOld_sampl_no()); ewxn.setPhy_name_s("抗拉强度"); ewxn.setVal1(excelWGJ.getKlqd()); //mapper.insertExcelWGJCXN(ewxn); list2.add(ewxn); } if(!("".equals(excelWGJ.getQfqd())||null==excelWGJ.getQfqd())){ ExcelWGJCXN ewxn = new ExcelWGJCXN(); ewxn.setSpecimen_no(excelWGJ.getOld_sampl_no()); ewxn.setPhy_name_s("屈服强度"); ewxn.setVal1(excelWGJ.getQfqd()); //mapper.insertExcelWGJCXN(ewxn); list2.add(ewxn); } if(!("".equals(excelWGJ.getDhscl())||null==excelWGJ.getDhscl())){ ExcelWGJCXN ewxn = new ExcelWGJCXN(); ewxn.setSpecimen_no(excelWGJ.getOld_sampl_no()); ewxn.setPhy_name_s("断后伸长率"); ewxn.setVal1(excelWGJ.getDhscl()); //mapper.insertExcelWGJCXN(ewxn); list2.add(ewxn); }*/ if(excelWGJ.getCoil_no()!=""||excelWGJ.getCoil_no()!=null){ ExcelWGJCXN ewxn = new ExcelWGJCXN(); ewxn.setCoil_no("R"+date+String.format("%06d", count+index)+"W010"); ewxn.setQfqd(excelWGJ.getQfqd()); ewxn.setKlqd(excelWGJ.getKlqd()); ewxn.setDhscl(excelWGJ.getDhscl()); list2.add(ewxn); } /*if(!("".equals(excelWGJ.getCharge_no())||null==excelWGJ.getCharge_no()) &&map.containsKey(excelWGJ.getCharge_no())==false){*/ //if(mapper.haswgjcf("R"+date+String.format("%06d", count+index)+"W")<1){ if(!("".equals(excelWGJ.getC())||null==excelWGJ.getC())){ ExcelWGJCF ewcf = new ExcelWGJCF(); ewcf.setBatch_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setAssay_no("R"+date+String.format("%06d", count+index)+"W"+"CP-2"); ewcf.setMaterial_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setHeat_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setChem_cd("C"); ewcf.setChem_name("C"); ewcf.setChem_value(excelWGJ.getC()); ewcf.setCreate_name(opman); //mapper.insertExcelWGJCF(ewcf); list3.add(ewcf); ExcelWGJCF ewcf1 = new ExcelWGJCF(); ewcf1.setCharge_no("R"+date+String.format("%06d", count+index)+"W"); ewcf1.setChem_cd("C"); ewcf1.setChem_value(excelWGJ.getC()); ewcf1.setChem_value(excelWGJ.getC()); list4.add(ewcf1); } if(!("".equals(excelWGJ.getB())||null==excelWGJ.getB())){ ExcelWGJCF ewcf = new ExcelWGJCF(); ewcf.setBatch_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setAssay_no("R"+date+String.format("%06d", count+index)+"W"+"CP-2"); ewcf.setMaterial_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setHeat_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setChem_cd("B"); ewcf.setChem_name("B"); ewcf.setChem_value(excelWGJ.getB()); ewcf.setCreate_name(opman); //mapper.insertExcelWGJCF(ewcf); list3.add(ewcf); ExcelWGJCF ewcf1 = new ExcelWGJCF(); ewcf1.setCharge_no("R"+date+String.format("%06d", count+index)+"W"); ewcf1.setChem_cd("B"); ewcf1.setChem_value(excelWGJ.getB()); ewcf1.setChem_value(excelWGJ.getB()); list4.add(ewcf1); } if(!("".equals(excelWGJ.getAls())||null==excelWGJ.getAls())){ ExcelWGJCF ewcf = new ExcelWGJCF(); ewcf.setBatch_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setAssay_no("R"+date+String.format("%06d", count+index)+"W"+"CP-2"); ewcf.setMaterial_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setHeat_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setChem_cd("Als"); ewcf.setChem_name("Als"); ewcf.setChem_value(excelWGJ.getAls()); ewcf.setCreate_name(opman); //mapper.insertExcelWGJCF(ewcf); list3.add(ewcf); ExcelWGJCF ewcf1 = new ExcelWGJCF(); ewcf1.setCharge_no("R"+date+String.format("%06d", count+index)+"W"); ewcf1.setChem_cd("Als"); ewcf1.setChem_value(excelWGJ.getAls()); ewcf1.setChem_value(excelWGJ.getAls()); list4.add(ewcf1); } if(!("".equals(excelWGJ.getAlt())||null==excelWGJ.getAlt())){ ExcelWGJCF ewcf = new ExcelWGJCF(); ewcf.setBatch_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setAssay_no("R"+date+String.format("%06d", count+index)+"W"+"CP-2"); ewcf.setMaterial_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setHeat_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setChem_cd("Alt"); ewcf.setChem_name("Alt"); ewcf.setChem_value(excelWGJ.getAlt()); ewcf.setCreate_name(opman); //mapper.insertExcelWGJCF(ewcf); list3.add(ewcf); ExcelWGJCF ewcf1 = new ExcelWGJCF(); ewcf1.setCharge_no("R"+date+String.format("%06d", count+index)+"W"); ewcf1.setChem_cd("Alt"); ewcf1.setChem_value(excelWGJ.getAlt()); ewcf1.setChem_value(excelWGJ.getAlt()); list4.add(ewcf1); } if(!("".equals(excelWGJ.getAs())||null==excelWGJ.getAs())){ ExcelWGJCF ewcf = new ExcelWGJCF(); ewcf.setBatch_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setAssay_no("R"+date+String.format("%06d", count+index)+"W"+"CP-2"); ewcf.setMaterial_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setHeat_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setChem_cd("As"); ewcf.setChem_name("As"); ewcf.setChem_value(excelWGJ.getAs()); ewcf.setCreate_name(opman); //mapper.insertExcelWGJCF(ewcf); list3.add(ewcf); ExcelWGJCF ewcf1 = new ExcelWGJCF(); ewcf1.setCharge_no("R"+date+String.format("%06d", count+index)+"W"); ewcf1.setChem_cd("As"); ewcf1.setChem_value(excelWGJ.getAs()); ewcf1.setChem_value(excelWGJ.getAs()); list4.add(ewcf1); } if(!("".equals(excelWGJ.getMo())||null==excelWGJ.getMo())){ ExcelWGJCF ewcf = new ExcelWGJCF(); ewcf.setBatch_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setAssay_no("R"+date+String.format("%06d", count+index)+"W"+"CP-2"); ewcf.setMaterial_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setHeat_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setChem_cd("Mo"); ewcf.setChem_name("Mo"); ewcf.setChem_value(excelWGJ.getMo()); ewcf.setCreate_name(opman); //mapper.insertExcelWGJCF(ewcf); list3.add(ewcf); ExcelWGJCF ewcf1 = new ExcelWGJCF(); ewcf1.setCharge_no("R"+date+String.format("%06d", count+index)+"W"); ewcf1.setChem_cd("Mo"); ewcf1.setChem_value(excelWGJ.getMo()); ewcf1.setChem_value(excelWGJ.getMo()); list4.add(ewcf1); } if(!("".equals(excelWGJ.getMn())||null==excelWGJ.getMn())){ ExcelWGJCF ewcf = new ExcelWGJCF(); ewcf.setBatch_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setAssay_no("R"+date+String.format("%06d", count+index)+"W"+"CP-2"); ewcf.setMaterial_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setHeat_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setChem_cd("Mn"); ewcf.setChem_name("Mn"); ewcf.setChem_value(excelWGJ.getMn()); ewcf.setCreate_name(opman); //mapper.insertExcelWGJCF(ewcf); list3.add(ewcf); ExcelWGJCF ewcf1 = new ExcelWGJCF(); ewcf1.setCharge_no("R"+date+String.format("%06d", count+index)+"W"); ewcf1.setChem_cd("Mn"); ewcf1.setChem_value(excelWGJ.getMn()); ewcf1.setChem_value(excelWGJ.getMn()); list4.add(ewcf1); } if(!("".equals(excelWGJ.getS())||null==excelWGJ.getS())){ ExcelWGJCF ewcf = new ExcelWGJCF(); ewcf.setBatch_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setAssay_no("R"+date+String.format("%06d", count+index)+"W"+"CP-2"); ewcf.setMaterial_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setHeat_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setChem_cd("S"); ewcf.setChem_name("S"); ewcf.setChem_value(excelWGJ.getS()); ewcf.setCreate_name(opman); //mapper.insertExcelWGJCF(ewcf); list3.add(ewcf); ExcelWGJCF ewcf1 = new ExcelWGJCF(); ewcf1.setCharge_no("R"+date+String.format("%06d", count+index)+"W"); ewcf1.setChem_cd("S"); ewcf1.setChem_value(excelWGJ.getS()); ewcf1.setChem_value(excelWGJ.getS()); list4.add(ewcf1); } if(!("".equals(excelWGJ.getP())||null==excelWGJ.getP())){ ExcelWGJCF ewcf = new ExcelWGJCF(); ewcf.setBatch_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setAssay_no("R"+date+String.format("%06d", count+index)+"W"+"CP-2"); ewcf.setMaterial_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setHeat_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setChem_cd("P"); ewcf.setChem_name("P"); ewcf.setChem_value(excelWGJ.getP()); ewcf.setCreate_name(opman); //mapper.insertExcelWGJCF(ewcf); list3.add(ewcf); ExcelWGJCF ewcf1 = new ExcelWGJCF(); ewcf1.setCharge_no("R"+date+String.format("%06d", count+index)+"W"); ewcf1.setChem_cd("P"); ewcf1.setChem_value(excelWGJ.getP()); ewcf1.setChem_value(excelWGJ.getP()); list4.add(ewcf1); } if(!("".equals(excelWGJ.getSi())||null==excelWGJ.getSi())){ ExcelWGJCF ewcf = new ExcelWGJCF(); ewcf.setBatch_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setAssay_no("R"+date+String.format("%06d", count+index)+"W"+"CP-2"); ewcf.setMaterial_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setHeat_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setChem_cd("Si"); ewcf.setChem_name("Si"); ewcf.setChem_value(excelWGJ.getSi()); ewcf.setCreate_name(opman); //mapper.insertExcelWGJCF(ewcf); list3.add(ewcf); ExcelWGJCF ewcf1 = new ExcelWGJCF(); ewcf1.setCharge_no("R"+date+String.format("%06d", count+index)+"W"); ewcf1.setChem_cd("Si"); ewcf1.setChem_value(excelWGJ.getSi()); ewcf1.setChem_value(excelWGJ.getSi()); list4.add(ewcf1); } if(!("".equals(excelWGJ.getCr())||null==excelWGJ.getCr())){ ExcelWGJCF ewcf = new ExcelWGJCF(); ewcf.setBatch_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setAssay_no("R"+date+String.format("%06d", count+index)+"W"+"CP-2"); ewcf.setMaterial_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setHeat_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setChem_cd("Cr"); ewcf.setChem_name("Cr"); ewcf.setChem_value(excelWGJ.getCr()); ewcf.setCreate_name(opman); //mapper.insertExcelWGJCF(ewcf); list3.add(ewcf); ExcelWGJCF ewcf1 = new ExcelWGJCF(); ewcf1.setCharge_no("R"+date+String.format("%06d", count+index)+"W"); ewcf1.setChem_cd("Cr"); ewcf1.setChem_value(excelWGJ.getCr()); ewcf1.setChem_value(excelWGJ.getCr()); list4.add(ewcf1); } if(!("".equals(excelWGJ.getNi())||null==excelWGJ.getNi())){ ExcelWGJCF ewcf = new ExcelWGJCF(); ewcf.setBatch_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setAssay_no("R"+date+String.format("%06d", count+index)+"W"+"CP-2"); ewcf.setMaterial_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setHeat_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setChem_cd("Ni"); ewcf.setChem_name("Ni"); ewcf.setChem_value(excelWGJ.getNi()); ewcf.setCreate_name(opman); //mapper.insertExcelWGJCF(ewcf); list3.add(ewcf); ExcelWGJCF ewcf1 = new ExcelWGJCF(); ewcf1.setCharge_no("R"+date+String.format("%06d", count+index)+"W"); ewcf1.setChem_cd("Ni"); ewcf1.setChem_value(excelWGJ.getNi()); ewcf1.setChem_value(excelWGJ.getNi()); list4.add(ewcf1); } if(!("".equals(excelWGJ.getCu())||null==excelWGJ.getCu())){ ExcelWGJCF ewcf = new ExcelWGJCF(); ewcf.setBatch_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setAssay_no("R"+date+String.format("%06d", count+index)+"W"+"CP-2"); ewcf.setMaterial_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setHeat_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setChem_cd("Cu"); ewcf.setChem_name("Cu"); ewcf.setChem_value(excelWGJ.getCu()); ewcf.setCreate_name(opman); //mapper.insertExcelWGJCF(ewcf); list3.add(ewcf); ExcelWGJCF ewcf1 = new ExcelWGJCF(); ewcf1.setCharge_no("R"+date+String.format("%06d", count+index)+"W"); ewcf1.setChem_cd("Cu"); ewcf1.setChem_value(excelWGJ.getCu()); ewcf1.setChem_value(excelWGJ.getCu()); list4.add(ewcf1); } if(!("".equals(excelWGJ.getV())||null==excelWGJ.getV())){ ExcelWGJCF ewcf = new ExcelWGJCF(); ewcf.setBatch_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setAssay_no("R"+date+String.format("%06d", count+index)+"W"+"CP-2"); ewcf.setMaterial_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setHeat_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setChem_cd("V"); ewcf.setChem_name("V"); ewcf.setChem_value(excelWGJ.getV()); ewcf.setCreate_name(opman); //mapper.insertExcelWGJCF(ewcf); list3.add(ewcf); ExcelWGJCF ewcf1 = new ExcelWGJCF(); ewcf1.setCharge_no("R"+date+String.format("%06d", count+index)+"W"); ewcf1.setChem_cd("V"); ewcf1.setChem_value(excelWGJ.getV()); ewcf1.setChem_value(excelWGJ.getV()); list4.add(ewcf1); } if(!("".equals(excelWGJ.getTi())||null==excelWGJ.getTi())){ ExcelWGJCF ewcf = new ExcelWGJCF(); ewcf.setBatch_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setAssay_no("R"+date+String.format("%06d", count+index)+"W"+"CP-2"); ewcf.setMaterial_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setHeat_no("R"+date+String.format("%06d", count+index)+"W"); ewcf.setChem_cd("Ti"); ewcf.setChem_name("Ti"); ewcf.setChem_value(excelWGJ.getTi()); ewcf.setCreate_name(opman); //mapper.insertExcelWGJCF(ewcf); list3.add(ewcf); ExcelWGJCF ewcf1 = new ExcelWGJCF(); ewcf1.setCharge_no("R"+date+String.format("%06d", count+index)+"W"); ewcf1.setChem_cd("Ti"); ewcf1.setChem_value(excelWGJ.getTi()); ewcf1.setChem_value(excelWGJ.getTi()); list4.add(ewcf1); } //map.put(excelWGJ.getCharge_no(), 1); //if("PRC".equals(excelWGJ.getCur_prog_cd())){ if(mapper.haswgjcoil_no(excelWGJ.getCoil_no())<1){ ExcelWGJMain ewm = new ExcelWGJMain(); //count = Integer.parseInt(mapper.queryMaxXuHao()); //index = Integer.parseInt(excelWGJ.getCoil_no()); ewm.setSpec_stl_grd(excelWGJ.getSpec_stl_grd()); ewm.setStl_grd(excelWGJ.getSpec_stl_grd()); ewm.setSpec_abbsym(excelWGJ.getSpec_abbsym()); ewm.setSlab_no(excelWGJ.getSlab_no()); ewm.setOrd_fl(excelWGJ.getOrd_fl()); ewm.setOld_sampl_no("R"+date+String.format("%06d", count+index)+"W010"); ewm.setCur_prog_cd(excelWGJ.getCur_prog_cd()); ewm.setCoil_wth(excelWGJ.getCoil_wth()); ewm.setCoil_thk(excelWGJ.getCoil_thk()); //ewm.setCoil_stat(String.valueOf(excelWGJ.getCoil_stat())); ewm.setCoil_outdia(excelWGJ.getCoil_outdia()); ewm.setCoil_no("R"+date+String.format("%06d", count+index)+"W010"); ewm.setCoil_len(excelWGJ.getCoil_len()); ewm.setCoil_india(excelWGJ.getCoil_india()); ewm.setAct_wgt(excelWGJ.getAct_wgt()); //mapper.insertExcelWGJMain(ewm); list1.add(ewm); } i++; if(i > 0 && i%30==0){ if(list1.size()!=0) mapper.insertExcelWGJMain(list1); if(list3.size()!=0) mapper.insertExcelWGJCF(list3); mapper.insertExcelWGJCF1(list4); if(list2.size()!=0) mapper.insertExcelWGJCXN(list2); SqlSession.commit(); list1 = new ArrayList(); list2 = new ArrayList(); list3 = new ArrayList(); } } }catch(Exception e){ e.printStackTrace(); SqlSession.rollback(); SqlSession.close(); }finally{ if(list1.size()!=0) mapper.insertExcelWGJMain(list1); if(list3.size()!=0) mapper.insertExcelWGJCF(list3); mapper.insertExcelWGJCF1(list4); if(list2.size()!=0) mapper.insertExcelWGJCXN(list2); SqlSession.commit(); } SqlSession.close(); cro.setV_errCode(1); return cro; } }