销售订单接口

package com.kingdee.eas.custom.mobil.app;

import net.sf.json.JSON;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import javax.ejb.*;
import java.rmi.RemoteException;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;
import java.util.Iterator;

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.IObjectPK;
import com.kingdee.bos.dao.IObjectValue;
import com.kingdee.bos.dao.IObjectCollection;
import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
import com.kingdee.bos.service.ServiceContext;
import com.kingdee.bos.service.IServiceContext;

import java.lang.String;
import java.math.BigDecimal;

import com.kingdee.eas.base.codingrule.CodingRuleManagerFactory;
import com.kingdee.eas.base.codingrule.ICodingRuleManager;
import com.kingdee.eas.base.permission.UserFactory;
import com.kingdee.eas.basedata.assistant.CurrencyFactory;
import com.kingdee.eas.basedata.assistant.MeasureUnitFactory;
import com.kingdee.eas.basedata.assistant.PaymentTypeFactory;
import com.kingdee.eas.basedata.master.material.MaterialFactory;
import com.kingdee.eas.basedata.master.material.MaterialSaleData;
import com.kingdee.eas.basedata.master.material.MaterialSales;
import com.kingdee.eas.basedata.master.material.MaterialSalesInfo;
import com.kingdee.eas.basedata.org.AdminOrgFacadeFactory;
import com.kingdee.eas.basedata.org.CompanyOrgUnitFactory;
import com.kingdee.eas.basedata.org.CtrlUnitFactory;
import com.kingdee.eas.basedata.org.OrgUnitInfo;
import com.kingdee.eas.basedata.org.SaleOrgUnitFactory;
import com.kingdee.eas.basedata.org.SaleOrgUnitInfo;
import com.kingdee.eas.basedata.org.StorageOrgUnitFactory;
import com.kingdee.eas.basedata.person.PersonFactory;
import com.kingdee.eas.basedata.scm.common.BizTypeFactory;
import com.kingdee.eas.basedata.scm.common.DeliveryTypeFactory;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.csinterface.syncdatabase.SQLFacadeFactory;
import com.kingdee.eas.fm.be.jcraft.jsch.jce.Random;
import com.kingdee.eas.framework.AbstractDataBaseInfo;
import com.kingdee.eas.scm.sd.sale.SaleOrderEntryCollection;
import com.kingdee.eas.scm.sd.sale.SaleOrderEntryFactory;
import com.kingdee.eas.scm.sd.sale.SaleOrderEntryInfo;
import com.kingdee.eas.scm.sd.sale.SaleOrderFactory;
import com.kingdee.eas.scm.sd.sale.SaleOrderInfo;
import com.kingdee.eas.util.app.ContextUtil;
import com.kingdee.jdbc.rowset.IRowSet;

public class SaleOrdersFacadeControllerBean extends
		AbstractSaleOrdersFacadeControllerBean {
	private static Logger logger = Logger
			.getLogger("com.kingdee.eas.custom.mobil.app.SaleOrdersFacadeControllerBean");

	@Override
	protected String _saleOrder(Context ctx, String billIds, String saleInfo)
			throws BOSException, EASBizException {
		JSONObject jsonreturninfo = new JSONObject();
		JSONObject jsonObject = JSONObject.fromObject(saleInfo);
		//SaleOrderInfo	 saleOrderInfo = new SaleOrderInfo();
		SaleOrderInfo saleOrderInfo=null;
		if(billIds==null||billIds==""){
			//新增
			 saleOrderInfo = new SaleOrderInfo();
		}else{
			//修改
			 saleOrderInfo =com.kingdee.eas.scm.sd.sale.SaleOrderFactory.getLocalInstance(
					ctx).getSaleOrderInfo(new ObjectUuidPK(billIds));
			 SaleOrderEntryCollection entries = saleOrderInfo.getEntries();
			 //修改前先删除所有分录,后面再把最新的数据加上去
				  entries.clear();
				 // entries.removeObject(iterator);
		}
		saleOrderInfo
				.setCreator(UserFactory
						.getLocalInstance(ctx)
						.getUserByID(
								new ObjectUuidPK(
										"256c221a-0106-1000-e000-10d7c0a813f413B7DE7F")));// 创建者user
		saleOrderInfo.setCreateTime(new Timestamp(new Date().getTime()));// 创建时间

		// 调用销售订单的编码规则新增编码
		// saleOrderInfo.setNumber(jsonObject.getString("number"));// 单据编码
		saleOrderInfo.setBizDate(new Date());// 业务日期
		saleOrderInfo
				.setBizType(BizTypeFactory
						.getLocalInstance(ctx)
						.getBizTypeInfo(
								new ObjectUuidPK(
										"d8e80652-010e-1000-e000-04c5c0a812202407435C"))); // 业务类型

		saleOrderInfo.setIsInnerSale(false);// 内部销售
		saleOrderInfo
				.setOrderCustomer(com.kingdee.eas.basedata.master.cssp.CustomerFactory
						.getLocalInstance(ctx).getCustomerInfo(
								new ObjectUuidPK(jsonObject
										.getString("orderCustomer"))));// 订货客户
		saleOrderInfo
				.setDeliveryType(DeliveryTypeFactory
						.getLocalInstance(ctx)
						.getDeliveryTypeInfo(
								new ObjectUuidPK(
										"51eb893e-0105-1000-e000-0c00c0a8123362E9EE3F")));// 交货方式
		saleOrderInfo
				.setCurrency(CurrencyFactory
						.getLocalInstance(ctx)
						.getCurrencyInfo(
								new ObjectUuidPK(
										"dfd38d11-00fd-1000-e000-1ebdc0a8100dDEB58FDC")));// 币别

		saleOrderInfo.setExchangeRate(new BigDecimal(1.00));// 汇率
		saleOrderInfo
				.setPaymentType(PaymentTypeFactory
						.getLocalInstance(ctx)
						.getPaymentTypeInfo(
								new ObjectUuidPK(
										"91f078d7-fb90-4827-83e2-3538237b67a06BCA0AB5")));// 付款方式
		SaleOrgUnitInfo saleOrgUnitInfo = SaleOrgUnitFactory.getLocalInstance(
				ctx).getSaleOrgUnitInfo(
				new ObjectUuidPK(jsonObject.getString("saleOrgUnit")));
		saleOrderInfo.setSaleOrgUnit(saleOrgUnitInfo);// 销售组织saleOrgUnit
		saleOrderInfo.setAdminOrgUnit(AdminOrgFacadeFactory.getLocalInstance(
				ctx).getComByOrgId(jsonObject.getString("saleOrgUnit")));
		saleOrderInfo.setSalePerson(PersonFactory.getLocalInstance(ctx)
				.getPersonInfo(new ObjectUuidPK("10YAAAAAkquA733t")));// 销售员
		saleOrderInfo.setIsInTax(true);// 是否含税
		saleOrderInfo.setIsCentralBalance(false);// 是否集中结算
		saleOrderInfo.setCU(CtrlUnitFactory.getLocalInstance(ctx)
				.getCtrlUnitInfo(
						new ObjectUuidPK(jsonObject.getString("saleOrgUnit"))));// 控制单元
		//
		saleOrderInfo.setCompanyOrgUnit(CompanyOrgUnitFactory.getLocalInstance(
				ctx).getCompanyOrgUnitInfo(new ObjectUuidPK(jsonObject.getString("saleOrgUnit"))));
		//分录对象可能有多个--------------------------------------------------------------
		// ----------------------
		JSONArray json = jsonObject.getJSONArray("entrys");
		// JSONObject object = jsonObject.getJSONObject("entrys");
		// JSONArray json = JSONArray.fromObject(object);
		for (int i = 0; i < json.size(); i++) {
			JSONObject job = json.getJSONObject(i);
			// System.out.println(job.get("otitle"));
			SaleOrderEntryInfo saleOrderEntryInfo = new SaleOrderEntryInfo();
			saleOrderEntryInfo.setMaterial(MaterialFactory
					.getLocalInstance(ctx).getMaterialInfo(
							new ObjectUuidPK(job.getString("material"))));// 物料

			String sql = "  select    FUnitID  from T_BD_MaterialSales     where  FMATERIALID='"
					+ job.getString("material")
					+ "'  and FORGUNIT='"
					+ jsonObject.getString("saleOrgUnit") + "'    ";
			IRowSet rs = SQLFacadeFactory.getLocalInstance(ctx).getRowset(
					sql.toString());
			String FUnitID = "";
			try {
				while (rs.next()) {
					try {
						FUnitID = rs.getString("FUnitID");
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
			// 计量单位
			saleOrderEntryInfo.setUnit(MeasureUnitFactory.getLocalInstance(ctx)
					.getMeasureUnitInfo(new ObjectUuidPK(FUnitID)));
			saleOrderEntryInfo.setBaseUnit(MaterialFactory
					.getLocalInstance(ctx).getMaterialInfo(
							new ObjectUuidPK(job.getString("material")))
					.getBaseUnit());// 基本计量单位
			saleOrderEntryInfo.setIsPresent(false);// 赠品
			saleOrderEntryInfo.setQty(new BigDecimal(job.getString("qty")));// 数量
			saleOrderEntryInfo.setBaseQty(new BigDecimal(job.getString("qty"))
					.multiply(new BigDecimal("1000")));// 基本计量数量
			saleOrderEntryInfo.setPrice(new BigDecimal(1));// 单价
			saleOrderEntryInfo.setTaxPrice(new BigDecimal(1));// 含税单价
			saleOrderEntryInfo.setAmount(new BigDecimal(job.getString("qty")));// 金额
			saleOrderEntryInfo.setActualPrice(new BigDecimal(1));// 实际单价
			saleOrderEntryInfo.setActualTaxPrice(new BigDecimal(1));// 实际含税单价
			saleOrderEntryInfo.setTaxRate(new BigDecimal(0));// 税率
			saleOrderEntryInfo.setTax(new BigDecimal(0));// 税额
			saleOrderEntryInfo
					.setTaxAmount(new BigDecimal(job.getString("qty")));// 价税合计
			// SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
			// "yyyy-MM-dd HH:mm:ss");
			//		 
			saleOrderEntryInfo.setSendDate(new Date());// 发货日期

			saleOrderEntryInfo.setStorageOrgUnit(StorageOrgUnitFactory
					.getLocalInstance(ctx).getStorageOrgUnitInfo(
							new ObjectUuidPK(jsonObject
									.getString("saleOrgUnit"))));// 发货组织
			saleOrderEntryInfo.setQuantityUnCtrl(false);// 不控制数量
			saleOrderEntryInfo.setTimeUnCtrl(false);// 不控制时间
			saleOrderEntryInfo
					.setDeliveryCustomer(com.kingdee.eas.basedata.master.cssp.CustomerFactory
							.getLocalInstance(ctx).getCustomerInfo(
									new ObjectUuidPK(jsonObject
											.getString("orderCustomer"))));// 送货客户
			saleOrderEntryInfo
					.setPaymentCustomer(com.kingdee.eas.basedata.master.cssp.CustomerFactory
							.getLocalInstance(ctx).getCustomerInfo(
									new ObjectUuidPK(jsonObject
											.getString("orderCustomer"))));// 收款客户
			saleOrderEntryInfo
					.setReceiveCustomer(com.kingdee.eas.basedata.master.cssp.CustomerFactory
							.getLocalInstance(ctx).getCustomerInfo(
									new ObjectUuidPK(jsonObject
											.getString("orderCustomer"))));// 应收客户
			saleOrderEntryInfo.setDeliveryDate(new Date()); // 交货日期
			
			 
			saleOrderInfo.getEntries().add(saleOrderEntryInfo);
		 
			
		}
		//----------------------------------------------------------------------
		// 新增
		String number = "";
		JSONArray array = new JSONArray();
		if (null == billIds || "".equals(billIds)) {
			ICodingRuleManager iCodingRuleManager = null;

			iCodingRuleManager = CodingRuleManagerFactory.getLocalInstance(ctx);
			String saleOrgUnitId = saleOrgUnitInfo.getId().toString();
			if (iCodingRuleManager.isExist(saleOrderInfo, saleOrgUnitId))
				number = iCodingRuleManager.getNumber(saleOrderInfo,
						saleOrgUnitInfo.getId().toString());
			saleOrderInfo.setNumber(number);// 单据编码
			try {
				IObjectPK addnew = SaleOrderFactory.getLocalInstance(ctx)
						.addnew(saleOrderInfo);
				// 插入对象后根据 单据id 开填充dep字段
				// dep 合同号 ,录入来源
				String contractId = jsonObject.getString("contractId");
				String sql2 = "  select FNUMBER  from T_DUC_BreedingContract where fid ='"
						+ contractId + "'   ";
				// 根据合同号查找相关信息
				IRowSet rowSet = SQLFacadeFactory.getLocalInstance(ctx)
						.getRowset(sql2.toString());
				String contractNumber = "";
				try {
					while (rowSet.next()) {
						contractNumber = rowSet.getString("FNUMBER");
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
				String insertSql = "  update T_SD_SaleOrder  set  CFKDTEXTFIELD1='"
						+ contractNumber
						+ "'  , CFOrderresource='移动端'  where fid='"
						+ saleOrderInfo.getId().toString() + "'  ";
				SQLFacadeFactory.getLocalInstance(ctx).exeSQL(insertSql);
				jsonreturninfo.put("number", saleOrderInfo.getNumber());
				jsonreturninfo.put("msg", "新增成功!");
			} catch (Exception e) {
				e.printStackTrace();
				jsonreturninfo.put("number", saleOrderInfo.getNumber());
				jsonreturninfo.put("msg", "新增失败!" + e.getMessage().toString());
			}
		} else {
			// 修改
			JSONObject jsonreturnupdateinfo = new JSONObject();
			try {
				com.kingdee.eas.scm.sd.sale.SaleOrderFactory.getLocalInstance(
						ctx).update(new ObjectUuidPK(billIds), saleOrderInfo);
				jsonreturnupdateinfo.put("number", saleOrderInfo.getNumber());
				jsonreturnupdateinfo.put("msg", "修改成功!");
				array.add(jsonreturnupdateinfo);
				return  array.toString() ;
			} catch (Exception e) {
				e.printStackTrace();
				jsonreturnupdateinfo.put("number", saleOrderInfo.getNumber());
				jsonreturnupdateinfo.put("msg", "修改失败!" + e.getMessage().toString());
				array.add(jsonreturnupdateinfo);
				return  array.toString() ;
			}
		}
		return  array.toString() ;
	}

	// 删除接口
	@Override
	protected String _saleOrderDel(Context ctx, String billIds)
			throws BOSException, EASBizException {
		JSONArray array = new JSONArray();
		// 删除 审核完成的 不允许删除手机端校验
		JSONObject jsonObject = JSONObject.fromObject(billIds);
		JSONArray billIdsjson = jsonObject.getJSONArray("ids");

		Integer[] ids = new Integer[billIdsjson.size()];
		String numbers = " ";

		for (int i = 0; i < billIdsjson.size(); i++) {
			JSONObject jsonreturninfo = new JSONObject();
		 
				JSONObject billId = billIdsjson.getJSONObject(i);
				// 删除的时候回收编码
				SaleOrderInfo saleOrderInfo = com.kingdee.eas.scm.sd.sale.SaleOrderFactory
						.getLocalInstance(ctx).getSaleOrderInfo(
								new ObjectUuidPK(billId.getString("id")
										.toString()));
     			String number = saleOrderInfo.getNumber();
				ICodingRuleManager iCodingRuleManager = CodingRuleManagerFactory
						.getLocalInstance(ctx);
				iCodingRuleManager.recycleNumber(saleOrderInfo, saleOrderInfo
						 .getSaleOrgUnit().getId().toString(), saleOrderInfo
						.getNumber());
				//开始删除
				try {
					com.kingdee.eas.scm.sd.sale.SaleOrderFactory.getLocalInstance(
							ctx).delete(
							new ObjectUuidPK(billId.getString("id").toString()));
					 jsonreturninfo.put("msg", "删除成功!");
					 jsonreturninfo.put("number", number);
				} catch (Exception e) {
					 jsonreturninfo.put("msg", "删除失败!"+e.getMessage());
					 jsonreturninfo.put("number", number);
					e.printStackTrace();
				}
 			 array.add(jsonreturninfo);
		}
		return array.toString();
	}

}
 
package test ;

import java.net.MalformedURLException;
import java.rmi.RemoteException;

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 client.WSContext;
 

public class test  {
	public static void main(String[] args) throws MalformedURLException, ServiceException {
	try {
//		//登录接口
//		EASLoginProxyProxy proxy = new EASLoginProxyProxy();
//		WSContext ctx = proxy.login("usser", "123456", "eas", "test", "l2", 2);
//		System.out.println(ctx.getSessionId());
//		System.out.println(ctx.getUserName());
		
		//调用登陆接口
        Service s=new Service();
        Call call=(Call)s.createCall();
        call.setOperationName("login");
      //  call.setTargetEndpointAddress("http://192.168.91.135:56898/ormrpc/services/EASLogin?wsdl");
        call.setTargetEndpointAddress("http://127.0.0.1:56898/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);
        //登陆接口参数
        WSContext rs=(WSContext)call.invoke(new Object[]{"user", "User@_2019", "eas", "_eas", "l2",  Integer.valueOf(2)});
        System.out.println(rs.getSessionId());
        System.out.println(rs.getUserName());
        //清理
        call.clearOperation();
        //调用业务接口
        call.setOperationName("saleOrder");
      //  call.setOperationName("saleOrderDel");
        call.setTargetEndpointAddress("http://127.0.0.1:56898/ormrpc/services/WSSaleOrdersFacade");
         call.setReturnQName(new QName("","saleOrderReturn"));
        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", "User@_2019"} );
       // FileOuttest fileOuttest = new FileOuttest();
        String aa=(String) call.invoke(new Object[]{"10YAAAGq+UbEikI6"," {  \r\n" + 
        		"    \"contractId\": \"+WU51Dw8RnCYP50uj88LPsVt6Bw=\",\r\n" + 
        		"    \"orderCustomer\": \"10YAAAADAQ6/DAQO\",\r\n" + 
        		"	\"saleOrgUnit\": \"10YAAAAAGSPM567U\",\r\n" + 
        		"    \"entrys\": [{\r\n" + 
        		"        \"material\": \"10YAAAACYH9ECefw\",\r\n" + 
        		"        \"qty\":  \"100000\" \r\n" + 
        		"    }, {\r\n" + 
        		"         \"material\": \"10YAAAACYH9ECefw\",\r\n" + 
        		"        \"qty\":  \"9\" \r\n" + 
        		"    }, {\r\n" + 
        		"          \"material\": \"10YAAAACYH9ECefw\",\r\n" + 
        		"          \"qty\":  \"8\" \r\n" + 
        		"    }, {\r\n" + 
        		"         \"material\": \"10YAAAACYH9ECefw\",\r\n" + 
        		"          \"qty\":  \"7\" \r\n" + 
        		"    }]\r\n" + 
        		"} "} );
        
//    String aa=(String) call.invoke(new Object[]{"{\r\n" + 
//    		"    \"ids\": [{\r\n" + 
//    		"        \"id\": \"10YAAAGq+S3EikI6\"\r\n" + 
//    		"    } ]\r\n" + 
//    		"   }"}); 
		System.out.println(aa);  
	} catch (RemoteException e) {
		e.printStackTrace();
		
	} 
}

}

 

你可能感兴趣的:(金蝶,EAS,BOS开发记录,EAS和BOS开发专栏)