webapi接口下推单据并修改下游单据数据
金蝶云社区-Jaden
Jaden
10人赞赏了该文章 6,968次浏览 未经作者许可,禁止转载编辑于2019年11月06日 16:27:28
summary-icon摘要由AI智能服务提供

本文讨论了两种方案,用于在第三方应用中通过调用WebAPI接口实现销售订单下推生成销售出库单,并修改出库单的实发数量。方案一是在单据转换插件中修改实发数量,但存在需要额外编程和可能导致应发数量不正确的问题。方案二则是先调用下推接口生成出库单,再通过保存接口修改实发数量,详细展示了通过WebAPI接口调用实现该流程的代码示例,包括如何构建下推和保存的参数。

应用场景:第三方应用通过调用webapi接口实现销售订单下推销售出库单,并修改销售出库单的实发数量
解决办法:
方案1:调用下推接口,并在单据转换插件里面修改销售出库单的实发数量。
方案说明:因为销售出库单的实发数量关联了销售订单的订单数量,所以直接在调用服务端的下推接口得到的元数据里面修改实发数量会导致销售订单和销售出库单的关联数量不正确,所以解决方案是在单据转化的时候处理上游单据的数量,让系统认为上有单据的数量刚好等于实发数量,这样系统调用下推接口的时候默认下游单据的实发数量等于上游单据的订单数量
缺点:需要编写单据转换插件,新增单据转换规则,生成的销售出库单的应发数量不正确(应发数量=实发数量)

方案2:调用下推接口,然后调用保存接口修改销售出库单的实发数量
方案说明:调用webapi的下推接口,得到生成的销售出库单,然后调用webapi的保存接口修改销售出库单的实发数量

下推接口:有两种下推接口调用方式,1、服务端的下推接口,如下:
public void TestPush2()
{
using (KDTransactionScope trans = new KDTransactionScope(
System.Transactions.TransactionScopeOption.Required))
{
var rules= ServiceHelper.GetService().GetConvertRules(this.Context, "SAL_SaleOrder", "SAL_OUTSTOCK");
ConvertRuleElement rule = ServiceHelper.GetService().GetConvertRules(this.Context, "SAL_SaleOrder", "SAL_OUTSTOCK").Where(r => r.Id.Equals("SaleOrder - OutStock")).FirstOrDefault();
if (rule == null)
{
return;
}
ListSelectedRow[] rows=new []
{
new ListSelectedRow("100018",null,0,"SAL_SaleOrder") //销售订单内码ID
};
PushArgs pushArgs = new PushArgs(rule,rows);
ConvertOperationResult convertResult = ServiceHelper.GetService().Push(this.Context, pushArgs);
DynamicObject[] destObjs = convertResult.TargetDataEntities.Select(r => r.DataEntity).ToArray();
ISaveService iss = Kingdee.BOS.App.ServiceHelper.GetService();
iss.Save(this.Context, destObjs);
trans.Complete();
}
}

2、调用webapi下推接口:
public void TestPush()
{
using (KDTransactionScope trans = new KDTransactionScope(
System.Transactions.TransactionScopeOption.Required))
{
Dictionary pushresult = WebApiServiceCall.Push(this.Context, "SAL_SaleOrder", GetPushParamStr()) as Dictionary;
trans.Complete();
}
}

public string GetPushParamStr()
{
var param = new
{
Numbers = new[] { "XSDD000002" },
RuleId = "SaleOrder-OutStock"
};
return JsonConvert.SerializeObject(param);
}

调用webapi下推接口+webapi保存接口实现销售订单下推销售出库单并实现修改销售出库单实发数量代码如下:
public void TestPush()
{
using (KDTransactionScope trans = new KDTransactionScope(
System.Transactions.TransactionScopeOption.Required))
{
Dictionary pushresult = WebApiServiceCall.Push(this.Context, "SAL_SaleOrder", GetPushParamStr()) as Dictionary;
Dictionary result = pushresult["Result"] as Dictionary;
Dictionary response = result["ResponseStatus"] as Dictionary;
bool isSuccess = (bool)response["IsSuccess"];
if (isSuccess)
{
List successEntity = response["SuccessEntitys"] as List;
string FID = successEntity.Select(t => ((Dictionary)t)["Id"].ToString()).FirstOrDefault(); //获取生成的销售出库单的内码ID
bool save = true;
if (save)
{
string entryID = "";
List> listResult= WebApiServiceCall.ExecuteBillQuery(this.Context, GetQeuryParamStr(FID)); //查询销售出库单明分录行内码ID
entryID = listResult[0][0].ToString();
var saveResult = WebApiServiceCall.Save(this.Context, "SAL_OUTSTOCK", GetSaveParamStr(FID, entryID));
}
}
trans.Complete();
}
}

///


/// 构造获取分录行内码ID的查询参数
///

///
///
public string GetQeuryParamStr(string FID)
{
var param = new
{
FormId = "SAL_OUTSTOCK",
FieldKeys = "FEntity_FEntryId",
FilterString = "FID="+FID
};
return JsonConvert.SerializeObject(param);
}

///


/// 构造下推参数
///

///
public string GetPushParamStr()
{
var param = new
{
Numbers = new[] { "XSDD000002" }, //销售订单的单号
RuleId = "SaleOrder-OutStock"
};
return JsonConvert.SerializeObject(param);
}

///


/// 构造保存/修改参数
///

///
///
///
public string GetSaveParamStr(string num,string entryid)
{
JObject param = new JObject();
param.Add("Creator", "");
JArray needUpdateFields = new JArray();
needUpdateFields.Add("FEntity");
needUpdateFields.Add("FRealQty");
param.Add("NeedUpDateFields", needUpdateFields);
param.Add("NeedReturnFields", new JArray());
param.Add("IsDeleteEntry", true);
param.Add("SubSystemId", "");
param.Add("IsVerifyBaseDataField", false);
param.Add("IsEntryBatchFill", true);
param.Add("ValidateFlag", true);
param.Add("NumberSearch", true);
param.Add("InterationFlags", "");

JObject order = new JObject();
param.Add("Model", order);
order.Add("FID", num);
JArray entity = new JArray();
order.Add("FEntity", entity);
JObject ent = new JObject();
ent.Add("FENTRYID", entryid);
ent.Add("FRealQty", 1); //销售出库单的实发数量
entity.Add(ent);
return param.ToString();
}

public JObject FNumber(string key, string value)
{
JObject number = new JObject();
number.Add(key, value);
return number;
}