金蝶接口上传附件

本人采用的是eclipse调用

bos中写的上传接口controllerBean中的代码

package com.kingdee.eas.custom.biconmz.app;
import org.apache.log4j.Logger;
import javax.ejb.*;
import java.rmi.RemoteException;
import com.kingdee.bos.*;
import com.kingdee.bos.util.BOSObjectType;
import com.kingdee.bos.metadata.IMetaDataPK;
import com.kingdee.bos.metadata.rule.RuleExecutor;
import com.kingdee.bos.metadata.MetaDataPK;
//import com.kingdee.bos.metadata.entity.EntityViewInfo;
import com.kingdee.bos.framework.ejb.AbstractEntityControllerBean;
import com.kingdee.bos.framework.ejb.AbstractBizControllerBean;
//import com.kingdee.bos.dao.IObjectPK;
import com.kingdee.bos.dao.IObjectValue;
import com.kingdee.bos.dao.IObjectCollection;
import com.kingdee.bos.service.ServiceContext;
import com.kingdee.bos.service.IServiceContext;

import java.lang.String;
import com.kingdee.eas.common.EASBizException;

import org.apache.log4j.Logger;

import sun.misc.BASE64Decoder;

import javax.ejb.*;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.rmi.RemoteException;
import com.kingdee.bos.*;
import com.kingdee.bos.util.BOSObjectType;
import com.kingdee.bos.metadata.IMetaDataPK;
import com.kingdee.bos.metadata.rule.RuleExecutor;
import com.kingdee.bos.metadata.MetaDataPK; //import com.kingdee.bos.metadata.entity.EntityViewInfo;
import com.kingdee.bos.framework.ejb.AbstractEntityControllerBean;
import com.kingdee.bos.framework.ejb.AbstractBizControllerBean; //import com.kingdee.bos.dao.IObjectPK;
import com.kingdee.bos.dao.IObjectValue;
import com.kingdee.bos.dao.IObjectCollection;
import com.kingdee.bos.service.ServiceContext;
import com.kingdee.bos.service.IServiceContext;
import com.kingdee.eas.base.attachment.common.AttachmentClientManager;
import com.kingdee.eas.base.attachment.common.AttachmentManagerFactory;
import com.kingdee.eas.base.attachment.common.AttachmentServerManager;
import com.kingdee.eas.base.attachment.common.SimpleAttachmentInfo;
import com.kingdee.eas.common.EASBizException;

public class UploadFacadeControllerBean extends AbstractUploadFacadeControllerBean
{
    private static Logger logger =
        Logger.getLogger("com.kingdee.eas.custom.biconmz.app.UploadFacadeControllerBean");
	@Override
	protected boolean _fileUpload(Context ctx, String id, String fileStr,
			String fileName, String fileType) throws BOSException,
			EASBizException {
		// TODO Auto-generated method stub
		try {
			//上传附件测试------------------------------------------------------------
			BASE64Decoder Base64 = new BASE64Decoder();
			// try {
			// Base64解码
			byte[] b = Base64.decodeBuffer(fileStr);
			for (int i = 0; i < b.length; ++i) {
				if (b[i] < 0) {// 调整异常数据
					b[i] += 256;
				}
			}
			   AttachmentServerManager serverManager = 
			        AttachmentManagerFactory.getServerManager(ctx);
			      SimpleAttachmentInfo saInfo = new SimpleAttachmentInfo();
			      saInfo.setExtName(fileType);
			      saInfo.setMainName(fileName);
			      saInfo.setContent(b);
			      serverManager.addNewAttachment(ctx, id, saInfo);
			      
			      
			      //客户端调用
			/*      AttachmentClientManager clientManager = AttachmentManagerFactory.getClientManager();
			      SimpleAttachmentInfo saInfo = new SimpleAttachmentInfo();
			      saInfo.setExtName(fileType);
			      saInfo.setMainName(fileName);
			      saInfo.setContent(b);
			      clientManager.addNewAttachment(id, saInfo);
			      */
			      
			      
			      
			//  "C:\\Users\\mz\\Desktop\\新建文件夹\\"+fileName+"."+fileType
			// 生成文件,并保存在服务器硬盘上 /Ikingdee/eas/attach/ 自己在服务器上建个attach目录   这样是在eas服务器上测试,在自己bos上测试,目录要换,参数要换成db
//			  OutputStream out = new FileOutputStream(
//				        "/Ikingdee/eas/myattach/" + fileName + "." + fileType);
//				      out.write(b);
//				      out.flush();
//				      out.close();
//				      String easPath = "/Ikingdee/eas/myattach/" + fileName + "." + fileType;
//				     //File file = new File(easPath);
//				      System.out.println("eas附件路径:" + easPath + ",extName=" + fileType);
				     // file.delete();
				      return true;
		  } catch (Exception e) {
			e.printStackTrace();
			 return super._fileUpload(ctx, id, fileStr, fileName, fileType);
			} 
		}
}

第三方插件eclipse代码

先将文件转换为流

package mytest;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class FileOuttest {

public static String file2Str(String file){
	//将文件转化为字节数组字符串,并对其进行Base64编码处理
	InputStream in = null;
	byte[] data = null;
	//读取文件字节数组
	BASE64Encoder Base64 = new BASE64Encoder();
	try{
		in = new FileInputStream(file);        
		data = new byte[in.available()];
		in.read(data);
		in.close();
	} catch (IOException e) {
		e.printStackTrace();
	}
	System.out.println(Base64.encode(data).toString());
	return new String(Base64.encode(data));

}
//public static void main(String[] args) {
//	 file2Str("C:\\Users\\mz\\Desktop\\过滤面板代码.txt");
//}
// 
}

package client;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.rmi.RemoteException;
import mytest.FileOuttest;
import sun.misc.BASE64Decoder;

import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.message.SOAPHeaderElement;

import _254._112._104._180.ormrpc.services.EASLogin.EASLoginProxyProxy;
import _254._112._104._180.ormrpc.services.WSBanktransactionFacade.WSBanktransactionFacadeSrvProxyServiceLocator;
import _254._112._104._180.ormrpc.services.WSSaleContractSubmitFacade.WSSaleContractSubmitFacadeSrvProxyServiceLocator;
import _254._112._104._180.ormrpc.services.WSSaleDonwoladFacade.WSSaleDonwoladFacadeSrvProxyServiceLocator;
import _254._112._104._180.ormrpc.services.WSSaleattachFileFacade.WSSaleattachFileFacadeSrvProxyServiceLocator;
public class LoginTest {
	public static void main(String[] args) throws ServiceException, IOException {
		//登录接口
	/*	EASLoginProxyProxy proxy = new EASLoginProxyProxy();
		WSContext ctx = proxy.login("user", "*****", "eas", "bicon", "l2", 2); 
		System.out.println(ctx.getSessionId());
		System.out.println(ctx.getUserName());
	// 自己写的单据提交接口方法  5uUAAAAy07gp9V6mg/VSwTh8BqHgUwcCAQrdNSn1XqY=
	   //WSSaleContractSubmitFacadeSrvProxyServiceLocator   locator2= new 	WSSaleContractSubmitFacadeSrvProxyServiceLocator();
	     //boolean saleContractSubmit = locator2.getWSSaleContractSubmitFacade().saleContractSubmit("5uUAAAA0xEsp9V6m");//g/VSwTh8BqHgUwcCAQrdNSn1XqY=  测试账套
	      WSSaleattachFileFacadeSrvProxyServiceLocator locator = new  WSSaleattachFileFacadeSrvProxyServiceLocator(); //5uUAAAA0xEsp9V6m
		  boolean fileUpload = locator.getWSSaleattachFileFacade().fileUpload("5uUAAAA69cAp9V6m",  FileOuttest.file2Str("C:\\Users\\mz\\Desktop\\11.doc"), "11", "doc");
		  System.err.println(fileUpload); */
		  
			//调用登陆接口
	        Service s=new Service();
	        Call call=(Call)s.createCall();
	        call.setOperationName("login");           //改为正确的ip、
	        call.setTargetEndpointAddress("http://180.104.*.*:6888/ormrpc/services/EASLogin?wsdl");
	        call.setReturnType(new QName("urn:client","WSContext"));
	        call.setReturnClass(WSContext.class);
	        call.setReturnQName(new QName("","loginReturn"));
	        //超时
	        call.setTimeout(Integer.valueOf(1000*600000*60));
	        call.setMaintainSession(true);
	        //登陆接口参数                                         //改为正确的ip、
	        WSContext rs=(WSContext)call.invoke(new Object[]{"user", "*****", "eas", "bicon", "l2",   Integer.valueOf(2)});
	        System.out.println(rs.getSessionId());
	        System.out.println(rs.getUserName());
	        //清理
	        call.clearOperation();
	        //调用业务接口
	        call.setOperationName("fileUpload");
	        call.setTargetEndpointAddress("http://180.104.*.254:6888/ormrpc/services/WSSaleattachFileFacade");
	        //call.setReturnType(new QName("urn:lang.java","String"));
	        //call.setReturnClass(String.class);
	        call.setReturnQName(new QName("","fileUploadReturn"));
	        call.setTimeout(Integer.valueOf(1000*600000*60));
	        call.setMaintainSession(true);
	        SOAPHeaderElement header=new SOAPHeaderElement("http://login.webservice.bos.kingdee.com","SessionId", rs.getSessionId());
	        call.addHeader(header);
	        //接口参数
	        // String aa=(String)call.invoke(new Object[]{"user", "kduser"} );
	         FileOuttest fileOuttest = new FileOuttest();
	        call.invoke(new Object[]{"5uUAAAA69cAp9V6m",fileOuttest.file2Str("C:\\Users\\mz\\Desktop\\11.doc"),  "11", "doc"} );
    
         /* WSBanktransactionFacadeSrvProxyServiceLocator locator = new WSBanktransactionFacadeSrvProxyServiceLocator();
		String bankaccounts = locator.getWSBanktransactionFacade().getBankaccounts();
		System.out.println(bankaccounts);
		String banktransactions = locator.getWSBanktransactionFacade().getBanktransactions("", "2018-01-01", "2019-03-03"); 
		System.out.println(banktransactions);*/
		//下载接口测试
  	/*WSSaleDonwoladFacadeSrvProxyServiceLocator locator = new  WSSaleDonwoladFacadeSrvProxyServiceLocator();
	     String attachmentIds = locator.getWSSaleDonwoladFacade().getAttachmentIds("g/VSwTh8BqHgUwcCAQrdNSn1XqY=");
	     System.out.println(attachmentIds);  //得到附件id 名字 类型  大小
	     String attachment = locator.getWSSaleDonwoladFacade().getAttachment("5uUAAAAzJeH0r08D");//加码后的字节字符串
	      System.out.println(attachment.toString());
	     BASE64Decoder Base64 = new BASE64Decoder();
		// try {
		// Base64解码
		byte[] b = Base64.decodeBuffer(attachment);
		for (int i = 0; i < b.length; ++i) {
			if (b[i] < 0) {// 调整异常数据
				b[i] += 256;
			}
		}
		//  "C:\\Users\\mz\\Desktop\\新建文件夹\\"+fileName+"."+fileType
		// 生成文件,并保存在服务器硬盘上 /root/kingdee/eas/attach/ 自己在服务器上建个attach目录   这样是在eas服务器上测试,在自己bos上测试,目录要换,参数要换成db
		  OutputStream out = new FileOutputStream(  "C:\\Users\\mz\\Desktop\\新建文件夹\\jpg.xlsx");
			      out.write(b);
			      out.flush();
			      out.close();  */
	}
}

最后服务器路径下要放总部给的私包

	 
	 /**
     * 附件处理
     * 用于将源单据所包含附件复制到下游单据
     */
 
	public  static  boolean  attachHandle(Context ctx, IObjectValue sourceBill, IObjectValue bill) throws BOSException, EASBizException {
    	
    	IBoAttchAsso iBoAttchAsso = BoAttchAssoFactory.getLocalInstance(ctx); //附件与业务对象关联接口
    	CoreBaseInfo sourceModel = (CoreBaseInfo) sourceBill; //源单据对象
    	CoreBaseInfo billModel = (CoreBaseInfo) bill; //目标单据对象
    	if(sourceModel.getId() == null || billModel.getId() == null){
    		throw new EASBizException(new NumericExceptionSubItem("099", "附件处理失败!"));
    	}
    	
    	FilterInfo filter = new FilterInfo();
    	filter.getFilterItems().add(new FilterItemInfo("boID", sourceModel.getId()));
    	boolean flag = iBoAttchAsso.exists(filter); //是否存在附件
    	if(!flag) return false; //不存在附件,直接返回
    	
    	EntityViewInfo view = new EntityViewInfo();
    	view.setFilter(filter);
    	BoAttchAssoCollection coll = iBoAttchAsso.getBoAttchAssoCollection(view); //查询源单据所有的附件关联
    	for(int i = 0; i < coll.size(); i++){
    		
    		BoAttchAssoInfo sourceAttch = coll.get(i); //源单据附件
    		BoAttchAssoInfo billAttch = new BoAttchAssoInfo(); //目标单据附件
    		billAttch.setBoID(billModel.getId().toString()); //业务单据ID
    		billAttch.setAssoType(sourceAttch.getAssoType()); //类型
    		billAttch.setAttachment(sourceAttch.getAttachment()); //附件
    		billAttch.setAssoBusObjType(billModel.getBOSType().toString()); //关联业务对象的类型
    		iBoAttchAsso.submit(billAttch); //提交目标单据的附件关联
    		
    	}
    	
	return true;
    	
    }

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值