Objective:Third-party systems can call the K3cloud system inventory data and form data, report data for data analysis;
Experimental Research:Originally intended to use Kingdee collaborative development platform for the Test Development API interface, the test did not succeed, and then began to use the method of early development used to test, and then succeeded! Time is precious, scribbled the following code steps, you can as a reference!
steps:1 vs New class, referencing the required namespaces;
2 vs new Console, in order to test the third-party platform call test success or not;
The code is as follows:
New Class
Using Kingdee.BOS.Core.Metadata;
Using Kingdee.BOS.Core.SqlBuilder;
Using Kingdee.BOS.JSON;
Using Kingdee.BOS.Orm.DataEntity;
Using Kingdee.BOS.Orm.Metadata.DataEntity;
Using Kingdee.BOS.ServiceHelper;
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using Kingdee.BOS.App.Data;
Using System.ComponentModel;
Using Kingdee.BOS.WebApi.ServicesStub;
Namespace API
{
[Description ("Interface Test")]
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, ' none '), 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.FMA Sterid = ML. Fmaterialid)
The left JOIN (select Fstockid,fname,flocaleid from t_bd_stock_l where fstockid>1 and flocaleid=2052) the 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 joins (select Fid,fname from t_bd_stockgroup_l where fid>1 and flocaleid=2052) are 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 joins (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
The LEFT join (select Fid,fnumber from T_bd_materialgroup where fid>1) is T6 on T4. Fparentid=t6.fid
Left joins (select Fid,fname from t_bd_materialgroup_l where fid>1 and flocaleid=2052) are 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, ' none '), 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; }}
}
To create a new console:
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(); }}
}
After the solution is built, the break points are tested with the following results:
API Interface Development Example