package com.vci.client.portal.UI; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.swing.JFileChooser; import javax.swing.filechooser.FileFilter; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import com.vci.client.LogonApplication; import com.vci.client.portal.utility.UITools; import com.vci.client.ui.swing.VCIOptionPane; import com.vci.common.utility.ObjectUtility; import com.vci.corba.common.VCIError; import com.vci.corba.omd.btm.BtmItem; import com.vci.corba.portal.data.PLAction; import com.vci.corba.portal.data.PLCommandParameter; import com.vci.corba.portal.data.PLPageDefination; import com.vci.corba.portal.data.PLUILayout; import com.vci.corba.portal.data.PLTabButton; import com.vci.corba.portal.data.PLTabPage; public class ImportExcel { private BtmItem selectTreeNodeobject; private String plpageLayoutDefinationId = ""; private String plPageContextOId = ""; private String plTableOId = ""; private String plCommandOId = ""; HSSFWorkbook readworkbook; public ImportExcel(BtmItem selectTreeNodeobject){ this.selectTreeNodeobject = selectTreeNodeobject; } public boolean impExcel() { JFileChooser jf = new JFileChooser(); jf.setDialogTitle("打开"); jf.removeChoosableFileFilter(jf.getFileFilter()); jf.setFileFilter(new FileFilter() { @Override public String getDescription() { return "xls"; } @Override public boolean accept(File f) { if(f.isDirectory()||f.getName().endsWith(".xls")){ return true; }else{ return false; } } }); int showOpenDialog = jf.showOpenDialog(LogonApplication.frame); String xfileName = ""; if (showOpenDialog == JFileChooser.APPROVE_OPTION) { File file = jf.getSelectedFile(); xfileName = file.getAbsolutePath(); if(!xfileName.endsWith(".xls")){ xfileName = xfileName+".xls"; } } try { FileInputStream fin = new FileInputStream(xfileName); PLUILayout[] plpagelayoutdefinations = null; try { readworkbook = new HSSFWorkbook(fin); HSSFSheet plpagelayoutdefnationsheet = readworkbook.getSheet("PlpageLayoutDefnation"); HSSFSheet pltabpagesheet = readworkbook.getSheet("Pltabpage"); HSSFSheet plpagedefinationsheet = readworkbook.getSheet("Plpagedefination"); HSSFSheet pltabbuttonsheet = readworkbook.getSheet("Pltabbutton"); HSSFSheet plcommondparamsheet = readworkbook.getSheet("PlcommondParam"); Map> pdMap = new HashMap>(); Map> tdMap = new HashMap>(); Map> dbMap = new HashMap>(); Map> bcMap = new HashMap>(); List plpagelayoutdefinationList = new ArrayList(); List pltabpagelist = new ArrayList(); List plpagedefinationlist = new ArrayList(); List pltabbuttonlist = new ArrayList(); List plcommandparameterlist = new ArrayList(); StringBuffer checkplpagelayoutdefination = new StringBuffer(); StringBuffer checkplpagelayoutdefinationPlcode = new StringBuffer(); StringBuffer plActionIDNulls = new StringBuffer(); String btmName = selectTreeNodeobject.name; //add by caill start 初始化标记 int count=0; int preCount=0; String preOID=""; String doublePreOID=""; //add by caill end PLAction[] allPLAction = UITools.getService().getAllPLAction(); Map relation = null; for(int i=0;i<=plpagelayoutdefnationsheet.getLastRowNum();i++){ pltabpagelist = new ArrayList(); PLUILayout p = new PLUILayout(); HSSFRow readrow = plpagelayoutdefnationsheet.getRow(i); if(readrow==null){ break; } plpagelayoutdefinations = UITools.getService().getPLUILayoutsByRelatedType(btmName); p.plOId = ObjectUtility.getNewObjectID36(); HSSFCell readcell = readrow.getCell(0); p.plName = readcell.getStringCellValue(); readcell = readrow.getCell(1); p.plCode = readcell.getStringCellValue(); //add by caill start //遍历UI名称 for(PLUILayout pd : plpagelayoutdefinations){ if(pd.plName.equals(p.plName)){ int vc=VCIOptionPane.showConfirmDialog(LogonApplication.frame, pd.plName+"名称已经存在,是否覆盖?","温馨提示", VCIOptionPane.YES_NO_OPTION); if(vc==0){ ; }else{ return false; } //checkplpagelayoutdefination.append(pd.plName).append(","); } //根据UI上下文做判断 if(pd.plCode.equals(p.plCode)){ count=1; preOID=pd.plOId; //如果UI上下文相同,就把系统中的id赋值给新导入的id p.plOId=pd.plOId; } } //add by caill end readcell = readrow.getCell(2); plpageLayoutDefinationId = readcell.getStringCellValue(); readcell = readrow.getCell(3); String name = readcell.getStringCellValue(); readcell = readrow.getCell(4); p.plRelatedType = readcell.getStringCellValue(); readcell = readrow.getCell(5); p.plIsShowNavigator = (short) readcell.getNumericCellValue(); readcell = readrow.getCell(6); p.plIsShowTab = (short) readcell.getNumericCellValue(); readcell = readrow.getCell(7); p.plIsShowForm = (short) readcell.getNumericCellValue(); if(!btmName.equals(name)){ VCIOptionPane.showMessage(LogonApplication.frame, "请选择要导入的类型节点名称!"); return false; } /*plpagelayoutdefinations = Tool.getService().getPLUILayoutsByRelatedType(btmName); for(PLUILayout pd : plpagelayoutdefinations){ if(pd.plName.equals(p.plName)){ checkplpagelayoutdefination.append(pd.plName).append(","); } if(pd.plCode.equals(p.plCode)){ if(!checkplpagelayoutdefinationPlcode.toString().contains(p.plCode)){ checkplpagelayoutdefinationPlcode.append(p.plCode).append(","); } } }*/ plpagelayoutdefinationList.add(p); for(int j=0;j<=pltabpagesheet.getLastRowNum();j++){ plpagedefinationlist = new ArrayList(); PLTabPage pt = new PLTabPage(); HSSFRow readrow1 = pltabpagesheet.getRow(j); if(readrow1==null){ break; } pt.plOId = ObjectUtility.getNewObjectID36(); HSSFCell readcell1 = readrow1.getCell(0); pt.plName = readcell1.getStringCellValue(); readcell1 = readrow1.getCell(1); pt.plCode = readcell1.getStringCellValue(); //add by caill start if(count==1) { PLTabPage[] PLTabPages = UITools.getService().getPLTabPagesByPageDefinationOId(preOID); //遍历控制区表格 for(PLTabPage pl : PLTabPages){ if(pl.plCode.equals(pt.plCode)){ pt.plOId=pl.plOId; //如果控制区表格的编码和导入的编码一样,就把控制区id赋值给新导入的id preCount=1; doublePreOID=pl.plOId; } } } //add by caill end readcell1 = readrow1.getCell(2); pt.plSeq = (short) readcell1.getNumericCellValue(); readcell1 = readrow1.getCell(3); pt.plContextOId = readcell1.getStringCellValue(); readcell1 = readrow1.getCell(4); pt.plDesc = readcell1.getStringCellValue(); readcell1 = readrow1.getCell(5); pt.plIsOpen = (short) readcell1.getNumericCellValue(); readcell1 = readrow1.getCell(6); pt.plAreaType = (short) readcell1.getNumericCellValue(); readcell1 = readrow1.getCell(7); pt.plOpenExpression = readcell1.getStringCellValue(); readcell1 = readrow1.getCell(8); pt.plLicensOrs = readcell1.getStringCellValue(); readcell1 = readrow1.getCell(9); pt.plLabel = readcell1.getStringCellValue(); readcell1 = readrow1.getCell(10); plPageContextOId = readcell1.getStringCellValue(); if(pt.plContextOId.equals(plpageLayoutDefinationId)){ pt.plContextOId = p.plOId; pltabpagelist.add(pt); for(int k=0;k<=plpagedefinationsheet.getLastRowNum();k++){ pltabbuttonlist = new ArrayList(); PLPageDefination plpagedefination = new PLPageDefination(); HSSFRow readrow2 = plpagedefinationsheet.getRow(k); if(readrow2==null){ break; } plpagedefination.plOId = ObjectUtility.getNewObjectID36(); HSSFCell readcell2 = readrow2.getCell(0); plpagedefination.name = readcell2.getStringCellValue(); //add by caill start //最后一级的判断 if(preCount==1) { PLPageDefination[] PLPageDefinations = UITools.getService().getPLPageDefinationsByPageContextOId(doublePreOID); for(PLPageDefination plp : PLPageDefinations) { if(plp.name.equals(plpagedefination.name)) { plpagedefination.plOId=plp.plOId; } } } //add by caill end readcell2 = readrow2.getCell(1); plpagedefination.plDefination = readcell2.getStringCellValue(); readcell2 = readrow2.getCell(2); plpagedefination.seq = (short) readcell2.getNumericCellValue(); readcell2 = readrow2.getCell(3); plpagedefination.plTabPageOId = readcell2.getStringCellValue(); readcell2 = readrow2.getCell(4); plpagedefination.desc = readcell2.getStringCellValue(); readcell2 = readrow2.getCell(5); plpagedefination.plType = (short) readcell2.getNumericCellValue(); readcell2 = readrow2.getCell(6); plTableOId = readcell2.getStringCellValue(); if(plpagedefination.plTabPageOId.equals(plPageContextOId)){ plpagedefination.plTabPageOId = pt.plOId; plpagedefinationlist.add(plpagedefination); //保存新旧oid的关系,在确定层级关系时使用 relation = new HashMap(); for(int a=0;a<=pltabbuttonsheet.getLastRowNum();a++){ HSSFRow readrow3 = pltabbuttonsheet.getRow(a); if(readrow3!=null){ HSSFCell readcell3 = readrow3.getCell(7); plCommandOId = readcell3.getStringCellValue(); String newOId = ObjectUtility.getNewObjectID36(); relation.put(plCommandOId, newOId); } } for(int a=0;a<=pltabbuttonsheet.getLastRowNum();a++){ plcommandparameterlist = new ArrayList(); PLTabButton plTabButton = new PLTabButton(); HSSFRow readrow3 = pltabbuttonsheet.getRow(a); if(readrow3==null){ break; } plTabButton.plOId = ObjectUtility.getNewObjectID36(); HSSFCell readcell3 = readrow3.getCell(0); plTabButton.plLabel = readcell3.getStringCellValue(); readcell3 = readrow3.getCell(1); plTabButton.plAreaType = readcell3.getStringCellValue(); readcell3 = readrow3.getCell(2); plTabButton.plTableOId = readcell3.getStringCellValue(); readcell3 = readrow3.getCell(3); plTabButton.plSeq = (short) readcell3.getNumericCellValue(); String plActionId = ""; //PLAction[] allPLAction = Tool.getService().getAllPLAction(); for(PLAction action : allPLAction){ if((readrow3.getCell(4).getStringCellValue()!=null&&!"".equals(readrow3.getCell(4).getStringCellValue()) )&&(readrow3.getCell(4).getStringCellValue().trim().equals(action.plCode.trim())) ){ plActionId = action.plOId; break; } } if(plActionId==null||"".equals(plActionId)){ if(!plActionIDNulls.toString().contains(readrow3.getCell(4).getStringCellValue())){ plActionIDNulls.append("\n\tAction编号:"+readrow3.getCell(4).getStringCellValue()); } } plTabButton.plActionOId = plActionId; readcell3 = readrow3.getCell(5); plTabButton.plAreaType = readcell3.getStringCellValue(); readcell3 = readrow3.getCell(6); plTabButton.plDesc = readcell3.getStringCellValue(); readcell3 = readrow3.getCell(8); String parentOid = readcell3.getStringCellValue();//父oid readcell3 = readrow3.getCell(7); plCommandOId = readcell3.getStringCellValue(); readcell3 = readrow3.getCell(9); if(readcell3 != null) { plTabButton.displayMode = readcell3.getStringCellValue(); } readcell3 = readrow3.getCell(10); if(readcell3 != null) { plTabButton.iconPath = readcell3.getStringCellValue(); } readcell3 = readrow3.getCell(11); if(readcell3 != null) { plTabButton.authorization = readcell3.getStringCellValue(); } readcell3 = readrow3.getCell(12); if(readcell3 != null) { plTabButton.show = readcell3.getStringCellValue(); } //赋予保存好的值,来保证层级关系不会丢失 plTabButton.plOId = relation.get(plCommandOId); if(parentOid != null && parentOid.length() > 0) { plTabButton.plParentOid = relation.get(parentOid) == null ? "" : relation.get(parentOid); } if(plTabButton.plTableOId.equals(plTableOId)){ plTabButton.plTableOId = plpagedefination.plOId; pltabbuttonlist.add(plTabButton); for(int b=0;b<=plcommondparamsheet.getLastRowNum();b++){ PLCommandParameter plCommandParameter = new PLCommandParameter(); HSSFRow readrow4 = plcommondparamsheet.getRow(b); if(readrow4==null){ break; } plCommandParameter.plOId = ObjectUtility.getNewObjectID36(); HSSFCell readcell4 = readrow4.getCell(0); plCommandParameter.plCommandOId = readcell4.getStringCellValue(); readcell4 = readrow4.getCell(1); plCommandParameter.plKey = readcell4.getStringCellValue(); readcell4 = readrow4.getCell(2); plCommandParameter.plValue = readcell4.getStringCellValue(); if(plCommandParameter.plCommandOId.equals(plCommandOId)){ plCommandParameter.plCommandOId = plTabButton.plOId; plcommandparameterlist.add(plCommandParameter); } } bcMap.put(plTabButton, plcommandparameterlist); } } dbMap.put(plpagedefination, pltabbuttonlist); } } tdMap.put(pt, plpagedefinationlist); } } pdMap.put(p, pltabpagelist); } if(plActionIDNulls.length()>0){ VCIOptionPane.showMessage(LogonApplication.frame, plActionIDNulls.toString()+"不存在!"); return false; } //删除原有button数据 if(tdMap.size() > 0) { for(List list : tdMap.values()) { for(PLPageDefination ppd : list) { if(ppd.plOId != null && ppd.plOId.length() > 0) { PLTabButton[] buttons = UITools.getService().getPLTabButtonsByTableOId(ppd.plOId); if(buttons != null && buttons.length > 0) { for(PLTabButton ptb : buttons) { UITools.getService().deletePLTabButtonByID(ptb.plOId); } } } } } } for(PLUILayout plPageLayoutDefination : plpagelayoutdefinationList){ List pltabpagelists = pdMap.get(plPageLayoutDefination); for(PLTabPage pltabpage:pltabpagelists){ List plpagedefinationlists = tdMap.get(pltabpage); for(PLPageDefination plpagedefination : plpagedefinationlists){ List pltabbuttons = dbMap.get(plpagedefination); for(PLTabButton pltabbutton : pltabbuttons){ List plcommandParams = bcMap.get(pltabbutton); for(PLCommandParameter plcommandparameter : plcommandParams){ plcommandparameter.plCreateUser = LogonApplication.getUserEntityObject().getUserName(); plcommandparameter.plModifyUser = LogonApplication.getUserEntityObject().getUserName(); UITools.getService().savePLCommandParameter(plcommandparameter); } pltabbutton.plCreateUser = LogonApplication.getUserEntityObject().getUserName(); pltabbutton.plModifyUser = LogonApplication.getUserEntityObject().getUserName(); UITools.getService().savePLTabButton(pltabbutton); } UITools.getService().savePLPageDefination(plpagedefination); } pltabpage.plCreateUser = LogonApplication.getUserEntityObject().getUserName(); pltabpage.plModifyUser = LogonApplication.getUserEntityObject().getUserName(); UITools.getService().savePLTabPage(pltabpage); } plPageLayoutDefination.plCreateUser = LogonApplication.getUserEntityObject().getUserName(); plPageLayoutDefination.plModifyUser = LogonApplication.getUserEntityObject().getUserName(); UITools.getService().savePLUILayout(plPageLayoutDefination); } return true; } catch (IOException e) { e.printStackTrace(); return false; } catch (VCIError e) { e.printStackTrace(); return false; } } catch (FileNotFoundException e) { e.printStackTrace(); return false; } } }