package com.vci.client.portal.platformPortal;
|
|
import java.io.BufferedWriter;
|
import java.io.File;
|
import java.io.FileNotFoundException;
|
import java.io.FileOutputStream;
|
import java.io.IOException;
|
import java.io.OutputStreamWriter;
|
import java.util.List;
|
|
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.common.providers.ServiceProvider;
|
import com.vci.client.omd.provider.ApProvider;
|
import com.vci.client.omd.provider.BtmProvider;
|
import com.vci.client.omd.provider.LinkTypeProvider;
|
import com.vci.client.oq.QTClient;
|
import com.vci.client.oq.QTDClient;
|
import com.vci.client.portal.utility.PRM;
|
import com.vci.client.portal.utility.PRMItem;
|
import com.vci.client.portal.utility.UITools;
|
import com.vci.common.utility.ObjectUtility;
|
import com.vci.corba.common.VCIError;
|
import com.vci.corba.omd.atm.AttribItem;
|
import com.vci.corba.omd.ltm.LinkType;
|
import com.vci.corba.omd.qtm.QTD;
|
import com.vci.corba.omd.qtm.QTInfo;
|
import com.vci.corba.portal.data.PortalVI;
|
|
public class ExportExcel {
|
List<PortalVI> objList ;
|
|
public ExportExcel(List<PortalVI> objList){
|
this.objList = objList;
|
}
|
|
public boolean export(){
|
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 = "";
|
String prmFileName = "";
|
if (showOpenDialog == JFileChooser.APPROVE_OPTION) {
|
File file = jf.getSelectedFile();
|
xfileName = file.getAbsolutePath();
|
if(!xfileName.endsWith(".xls")){
|
xfileName = xfileName+".xls";
|
}
|
}
|
HSSFWorkbook workbook = new HSSFWorkbook();
|
HSSFSheet sheet = workbook.createSheet();
|
workbook.setSheetName(0, "portalvi");
|
|
HSSFSheet qtdSheet = workbook.createSheet();
|
workbook.setSheetName(1, "QTD");
|
|
for(int i=0;i<objList.size();i++){
|
HSSFRow row = sheet.createRow(i);
|
PortalVI portalVI = objList.get(i);
|
// HSSFCell cell = row.createCell(0);
|
// cell.setCellValue(portalVI.id);
|
HSSFCell cell = row.createCell(0);
|
cell.setCellValue(portalVI.typeName);
|
cell = row.createCell(1);
|
cell.setCellValue(portalVI.viName);
|
cell = row.createCell(2);
|
cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
|
cell.setCellValue(portalVI.viType);
|
cell = row.createCell(3);
|
cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
|
cell.setCellValue(portalVI.typeFlag);
|
cell = row.createCell(4);
|
String prmStr = portalVI.prm;
|
String qtName = "";
|
if(portalVI.viType ==0){
|
PRM prmObj = UITools.getPRM(prmStr);
|
List<PRMItem> prmItemList = prmObj.getPrmItemList();
|
qtName = prmObj.getFormQtName();
|
for(int j=0;j<prmItemList.size();j++){
|
PRMItem pit = prmItemList.get(j);
|
PortalVI[] portalViInfos = new PortalVI[0];
|
try {
|
portalViInfos = UITools.getService().getPortalVIArrayByTypeName(portalVI.typeName);
|
for(PortalVI pv : portalViInfos){
|
if(pit.getItemInObj().equals(pv.id)){
|
pit.setItemInObj(portalVI.typeName+":"+pv.viName);
|
}
|
}
|
} catch (VCIError e) {
|
e.printStackTrace();
|
}
|
}
|
try {
|
prmStr = UITools.getPRMText(prmObj);
|
} catch (Throwable e1) {
|
e1.printStackTrace();
|
}
|
}else if(portalVI.viType ==1){
|
PRM prmObj = UITools.getPRM(prmStr);
|
// List<PRMItem> prmItemList = prmObj.getPrmItemList();
|
// for(int j=0;j<prmItemList.size();j++){
|
// PRMItem pit = prmItemList.get(j);
|
qtName = prmObj.getFormQtName();
|
// }
|
}
|
prmFileName = ObjectUtility.getNewObjectID36() + ".txt";
|
String prmFileAllName = xfileName + "." + prmFileName;
|
BufferedWriter clobBW = null;
|
try {
|
File prmFile = new File(prmFileAllName);
|
if(!prmFile.exists()){
|
prmFile.createNewFile();
|
}
|
clobBW = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(prmFile), "Utf-8"));
|
clobBW.write(prmStr);
|
clobBW.flush();
|
// byte[] connentBytes = prmStr.getBytes(s);
|
// fop.write(connentBytes);
|
// fop.flush();
|
// fop.close();
|
cell.setCellValue(prmFileName);
|
} catch (IOException e) {
|
e.printStackTrace();
|
return false;
|
}finally{
|
if(clobBW != null){
|
try {
|
// fop.close();
|
// osw.close();
|
clobBW.close();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
// cell.setCellValue(prmStr);
|
String btmname = "";
|
String linkname = "";
|
AttribItem[] btAbItems=null;
|
if(portalVI.typeFlag==0){
|
btmname = portalVI.typeName;
|
btAbItems = BtmProvider.getInstance().getBtAbItems(btmname);
|
}else if(portalVI.typeFlag==1){
|
try {
|
LinkType linkType = LinkTypeProvider.getInstance().getLinkTypeByName(portalVI.typeName);
|
btmname = linkType.name;
|
linkname = linkType.name;
|
btAbItems = ApProvider.getInstance().getAttribItemsByNames(LinkTypeProvider.getInstance().getAbNames(linkType));
|
} catch (Exception e) {
|
e.printStackTrace();
|
} catch (Throwable e) {
|
e.printStackTrace();
|
}
|
}
|
|
String attr = "";
|
for(AttribItem ait : btAbItems){
|
attr += ait.name +",";
|
}
|
//类型属性:以字符串形式存在
|
cell = row.createCell(5);
|
if(attr==null||"".equals(attr)){
|
cell.setCellValue("");
|
}else{
|
cell.setCellValue(attr.substring(0,attr.length()-1));
|
}
|
BufferedWriter qtbw = null;
|
try {
|
QTInfo qt = ServiceProvider.getOMDService().getQTDService().getQT(qtName);
|
if(qt != null){
|
//查询模板名称
|
cell = row.createCell(6);
|
cell.setCellValue(qtName);
|
//查询模板名称
|
cell = row.createCell(7);
|
String qtFileName = ObjectUtility.getNewObjectID36() + ".txt";
|
String qtFileNameAllName = xfileName + "." + qtFileName;
|
File prmFile = new File(qtFileNameAllName);
|
if(!prmFile.exists()){
|
prmFile.createNewFile();
|
}
|
qtbw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(prmFile), "utf-8"));
|
qtbw.write(qt.qtText);
|
qtbw.flush();
|
// byte[] connentBytes = qt.qtText.getBytes();
|
// qtfop.write(connentBytes);
|
// qtfop.flush();
|
// qtfop.close();
|
cell.setCellValue(qtFileName);
|
//查询模板的业务对象名称
|
cell = row.createCell(8);
|
cell.setCellValue(qt.btmName);
|
}
|
QTD[] qtdsByBtmName = ServiceProvider.getOMDService().getQTDService().getBizTypeQTDs(btmname);
|
for(int qtdIndex =0;qtdIndex<qtdsByBtmName.length;qtdIndex++){
|
HSSFRow qtdRow = qtdSheet.createRow(qtdIndex);
|
QTD qtd = qtdsByBtmName[qtdIndex];
|
HSSFCell qtdCell = qtdRow.createCell(0);
|
qtdCell.setCellValue(qtd.btmName);
|
qtdCell = qtdRow.createCell(1);
|
qtdCell.setCellValue(qtd.linkTypeName);
|
qtdCell = qtdRow.createCell(2);
|
qtdCell.setCellValue(qtd.name);
|
qtdCell = qtdRow.createCell(3);
|
String qtdattr = "";
|
for(String str : qtd.abNames){
|
qtdattr += str+",";
|
}
|
if(qtdattr==null||"".equals(qtdattr)){
|
qtdCell.setCellValue("");
|
}else{
|
qtdCell.setCellValue(qtdattr.substring(0,qtdattr.length()-1));
|
}
|
}
|
QTD[] qtdsByLinkTypeName = ServiceProvider.getOMDService().getQTDService().getLinkTypeQTDs(linkname);
|
for(int qtdLinkIndex =0;qtdLinkIndex<qtdsByLinkTypeName.length;qtdLinkIndex++){
|
HSSFRow qtdRow = qtdSheet.createRow(qtdLinkIndex);
|
QTD qtd = qtdsByLinkTypeName[qtdLinkIndex];
|
HSSFCell qtdCell = qtdRow.createCell(0);
|
qtdCell.setCellValue(qtd.btmName);
|
qtdCell = qtdRow.createCell(1);
|
qtdCell.setCellValue(qtd.linkTypeName);
|
qtdCell = qtdRow.createCell(2);
|
qtdCell.setCellValue(qtd.name);
|
qtdCell = qtdRow.createCell(3);
|
String qtdattr = "";
|
for(String str : qtd.abNames){
|
qtdattr += str+",";
|
}
|
if(qtdattr==null||"".equals(qtdattr)){
|
qtdCell.setCellValue("");
|
}else{
|
qtdCell.setCellValue(qtdattr.substring(0,qtdattr.length()-1));
|
}
|
}
|
} catch (VCIError e) {
|
e.printStackTrace();
|
} catch (FileNotFoundException e) {
|
e.printStackTrace();
|
} catch (IOException e) {
|
e.printStackTrace();
|
} finally{
|
try {
|
if(qtbw != null){
|
qtbw.close();
|
}
|
} catch (IOException e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
}
|
}
|
|
try {
|
FileOutputStream fout = new FileOutputStream(xfileName);
|
workbook.write(fout);
|
fout.flush();
|
fout.close();
|
System.out.println("文件生成.....");
|
return true;
|
} catch (FileNotFoundException e) {
|
e.printStackTrace();
|
return false;
|
} catch (IOException e) {
|
e.printStackTrace();
|
return false;
|
}
|
}
|
}
|