调用系统BP
示例从收货单配置杂发单(MES对接自动生成场景)

public CommonRes MiscShipCreateFromRcv(string jsonData)
{
CommonRes res = new CommonRes();
var jObj = JObject.Parse(jsonData);
long? id = jObj["ID"]?.Value<long>();
if (!id.HasValue) return res.Fail("收货单主键为空,不能操作");
Receivement rcv = Receivement.Finder.FindByID(id.Value);
if (rcv == null) return res.Fail($"收货单不存在或无权访问:{id}");
Organization org = rcv.Org;
// 查询推式生单配置
GetPushToDocTypeByRule docTypeByRule = new GetPushToDocTypeByRule
{
ConditionValue = new PushToDocTypeConditionValueDTO
{
SourceOrgKey = org.Key,
SourceDocEntityFullName = Receivement.EntityRes.BE_FullName,
TargetOrgKey = org.Key,
TargetDocEntityFullName = MiscShipment.EntityRes.BE_FullName,
ConditionValue1 = rcv.RcvDocTypeKey.ID.ToString() // 条件1 来源单据类型
}
};
List<long> docList = docTypeByRule.Do();
if (docList == null || docList.Count == 0) return res.Fail($"根据收货单:{rcv.DocNo},单据类型:{rcv.RcvDocType.Name},查询推式生单配置失败,请检查是否配置");
MiscShipDocType doctype = MiscShipDocType.Finder.FindByID(docList[0]);
if (doctype == null) return res.Fail($"杂发单单据类型查询失败:{docList[0]}");
// dosomething
return res;
}
c#方法
/// <summary>
/// 推式生单配置
/// </summary>
/// <param name="SrcOrg">来源组织</param>
/// <param name="DocType">来源单据类型</param>
/// <param name="SourceEntityKey">来源实体ID</param>
/// <param name="TargetEntityKey">目标实体ID</param>
/// <returns></returns>
public static string GetPushToDocTypeConfig(Organization SrcOrg, long DocType, long SourceEntityKey, long TargetEntityKey,string tab)
{
// 生单规则
PushToDocTypeRule PTTRData = PushToDocTypeRule.Finder.Find($"PushToDocTypeConfig.SourceEntity = {SourceEntityKey} and PushToDocTypeConfig.TargetEntity = {TargetEntityKey} and TargetOrg = {SrcOrg.ID}");
// 生单规则条件
PushToDocTypeRuleLine PTTRLData = PushToDocTypeRuleLine.Finder.Find($"PushToDocTypeRule = {PTTRData.ID} and SourceOrg = {SrcOrg.ID} and EntityFieldValue{tab} = {DocType}");
return PTTRLData?.TargetDocTypeCode;
}
SQL函数
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: qxq
-- Create date: 2023年8月30日
-- Description: 查询推式生单配置的下游单据类型编码
-- Example: select dbo.Fun_Cust_GetTargetDocTypeCode('UFIDA.U9.SM.ShipPlan.ShipPlan', 'UFIDA.U9.SM.Ship.Ship', 1002109230000231, (select ID from Base_Organization where Code='T001'))
-- =============================================
CREATE OR ALTER FUNCTION Fun_Cust_GetTargetDocTypeCode
(
@SourceEntityName varchar(255), -- 来源实体类型全称
@TargetEntityName varchar(255), -- 目标实体类型全称
@SourceDocType bigint, -- 来源单据类型
@TargetOrg bigint -- 目标组织
)
RETURNS nvarchar(255)
AS
BEGIN
declare @SourceEntity bigint,@TargetEntity bigint,@TargetDocTypeCode nvarchar(255)
select @SourceEntity=Local_ID from UBF_MD_Class where FullName=@SourceEntityName
select @TargetEntity=Local_ID from UBF_MD_Class where FullName=@TargetEntityName
select @TargetDocTypeCode=TargetDocTypeCode from Base_PushToDocTypeRuleLine line
join Base_PushToDocTypeRule head on head.ID=line.PushToDocTypeRule and head.TargetOrg=@TargetOrg
join Base_PushToDocTypeConfig conf on conf.ID=head.PushToDocTypeConfig and SourceEntity=@SourceEntity and TargetEntity=@TargetEntity
where (EntityFieldValue1=@SourceDocType or EntityFieldValue2=@SourceDocType or EntityFieldValue3=@SourceDocType or EntityFieldValue4=@SourceDocType or EntityFieldValue5=@SourceDocType or EntityFieldValue6=@SourceDocType)
return @TargetDocTypeCode
END
GO
评论 (0)