标签:api
目的:第三方系统可以调用k3cloud系统中的库存数据与表单数据、报表数据进行数据分析;namespace api
{
[Description("接口测试")]
public class Class1 : Kingdee.BOS.WebApi.ServicesStub.AbstractWebApiBusinessService
{
public Class1(Kingdee.BOS.ServiceFacade.KDServiceFx.KDServiceContext context)
: base(context)
{ }
private DynamicObjectCollection GetInven()
{
StringBuilder str = new StringBuilder();
str.Append(@" /dialect/ SELECT t6.FNUMBER,t7.fname,m.FNUMBER, ml.fname,w.fname,isnull(t14.fname,‘无‘) ,TSL.fname,tsl1.FNUMBER ,
sum(TI.FBASEQTY) FBASEQTY,st01.FNAME
FROM (select FBASEQTY,FSTOCKID,FMATERIALID,FSTOCKSTATUSID,FSTOCKORGID from T_STK_INVENTORY where FMATERIALID>1 and FSTOCKSTATUSID=10000 and FOBJECTTYPEID= ‘STK_Inventory‘ and FKEEPERTYPEID=‘BD_KeeperOrg‘and FOWNERTYPEID=‘BD_OwnerOrg‘ and FISEFFECTIVED=1 and FBASEQTY<>0) TI
inner join (select FSTOCKSTATUSID,FNAME From T_BD_STOCKSTATUS_L where FSTOCKSTATUSID>1 and FLOCALEID=2052) st01 on st01.FSTOCKSTATUSID=TI.FSTOCKSTATUSID
inner JOIN (select fnumber,FMASTERID,FMATERIALID,FMATERIALGROUP from T_BD_MATERIAL where FMATERIALID>1 and FDOCUMENTSTATUS=‘C‘ and FFORBIDSTATUS=‘A‘ ) M ON M.FMATERIALID = TI.FMATERIALID
LEFT JOIN (select FMATERIALID,FLOCALEID,fname from T_BD_MATERIAL_L where FMATERIALID>1 and FLOCALEID=2052) ML ON (M.FMASTERID = ML.FMATERIALID)
LEFT JOIN (select FSTOCKID,fname,FLOCALEID From T_BD_STOCK_L where FSTOCKID>1 and FLOCALEID=2052) TSL ON (TSL.FSTOCKID = TI.FSTOCKID)
LEFT JOIN (select fstockid,FGROUP,fnumber from T_BD_STOCK where fstockid>1 and FDOCUMENTSTATUS=‘C‘ and FFORBIDSTATUS=‘A‘) tsl1 on TSL.FSTOCKID=tsl1.fstockid
LEFT join (select FID,fname from T_BD_STOCKGROUP_L where FID>1 and FLOCALEID=2052) t14 on tsl1.FGROUP=t14.fid
inner join (select FMATERIALID,FCATEGORYID From T_BD_MATERIALBASE where FCATEGORYID>1) u0 on m.FMATERIALID=u0.FMATERIALID
left join (select FCATEGORYID,fname From T_BD_MATERIALCATEGORY_L where FCATEGORYID>1 and FLOCALEID=2052) w on u0.FCATEGORYID=w.FCATEGORYID
left join (select fid,FPARENTID From T_BD_MATERIALGROUP where fid>1) t4 on m.FMATERIALGROUP=t4.fid
left join (select fid,FNUMBER From T_BD_MATERIALGROUP where fid>1 ) t6 on t4.FPARENTID=t6.fid
left join (select fid,fname From T_BD_MATERIALGROUP_L where fid>1 and FLOCALEID=2052) t7 on t4.FPARENTID=t7.fid
inner join (select FORGID,fname From T_ORG_ORGANIZATIONS_L where FORGID>1 and FLOCALEID=2052) cc on TI.FSTOCKORGID=cc.FORGID
group by t6.FNUMBER,t7.fname,ml.fname,m.FNUMBER,tsl.fname,w.fname,isnull(t14.fname,‘无‘),TSL.fname,tsl1.FNUMBER,st01.FNAME");
return DBUtils.ExecuteDynamicObject(this.KDContext.Session.AppContext, str.ToString());
}
public JSONArray ExecuteService()
{
DynamicObjectCollection list = GetInven() as DynamicObjectCollection;
JSONArray jsonArray = new JSONArray();
foreach (DynamicObject dynamicObject in list)
{
jsonArray.Add(ConvertDynamicObject2Json(dynamicObject));
}
returnjsonArray;
}
private JSONObject ConvertDynamicObject2Json(DynamicObject dynamicObject)
{
DynamicPropertyCollection dynamicPropertyCollection = dynamicObject.DynamicObjectType.Properties;
JSONObject obj = new JSONObject();
foreach (DynamicProperty property in dynamicPropertyCollection)
{
obj.Put(property.Name, dynamicObject[property.Name]);
}
return obj;
}
}
}
新建控制台:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Kingdee.BOS.WebApi.Client;
using Kingdee.BOS.JSON;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
ApiClient client1 = new Kingdee.BOS.WebApi.Client.ApiClient("http://localhost/k3cloud/");
bool result1 = client1.Login("数据中心id", "用户名", "密码", 2052);
if (result1)
{
object responseOut1 = client1.Execute<JSONArray>("api.Class1.ExecuteService,api",null);
}
Console.Write(responseOut1);
Console.ReadLine();
}
}
}
生成解决方案后,打断点进行测试结果如下:
标签:api
原文地址:http://blog.51cto.com/yataigp/2115046