流程插件开发系列2:自定义流转条件插件
金蝶云社区-猪飞
猪飞
2人赞赏了该文章 4817次浏览 未经作者许可,禁止转载编辑于2017年06月21日 16:24:23

流程插件开发汇总:
流程插件开发系列1:审批动作服务插件
https://vip.kingdee.com/article/155678
流程插件开发系列2:自定义流转条件插件
https://vip.kingdee.com/article/155777
流程插件开发系列3:自定义参与人插件
https://vip.kingdee.com/article/155821

背景:
目前流程连线上支持单据字段作为条件,决定流程走向;还有其他特殊需求,就希望通过自定义条件插件,编写代码决定流程走向,流程设计将会更加灵活自由。
很高兴告诉各位伙伴们,后续版本(预计在V6.2的7月份补丁、V7.0)将支持流程连线上配置自定义条件,预算模块还内置了“预算条件方案”插件支持预算流转判断。可用于无法从单据字段取值判断的场景,比如需求是用“发起员工所属组织”作为连线条件,连线上仅能判断发起人用户无法获取发起员工及组织,这种场景就可以通过自定义连线条件插件实现。

1. 用户如何配置自定义条件
本例以配置“发起员工所属组织”作为自定义条件,用户可以在条件项中选择基础资料组织“集团本部”,作为参数传入条件插件中解析条件真假;若发起员工的组织是“集团本部”,则流转到“集团本部”这个节点:

2. 开发者如何实现自定义条件插件
2.1. 条件插件基类

Kingdee.BOS.Workflow.Kernel.Condition
. AbstractConditionExecutorPlugIn
引用组件Kingdee.BOS.Workflow.Kernel.dll,开发者编写的条件执行类需要继承该基类。
2.2. 方法Execute
方法说明:条件执行的核心方法。
C#定义
public virtual void Execute(MapStateContext flowSateContext,
List<CustomizeConditionRow> customizeConditionList)
备注:插件中覆写此方法,自行实现条件计算,并将条件计算结果传回流程引擎即可。


[tr][td=176]插件基类
[td=447]AbstractConditionExecutorPlugIn
[tr][td=176]所在组件
[td=447]Kingdee.BOS.Workflow.Kernel.dll
[tr][td=176]条件执行方法
[td=447]void Execute(MapStateContext flowSateContext, List customizeConditionList)
[tr][td=2,1,623] 方法参数说明:
[tr][td=176] flowSateContext[td=447]流程上下文。可以获取BOS上下文、单据FormId、单据实体对象等。比如:// 示例,如何获取BOS上下文等数据:var context = flowSateContext.MapContext.BOSContext; // 获取BOS上下文var formId = flowSateContext.MapContext.BillFormId; // 获取单据FormIdvar data = flowSateContext.MapContext.BillDataObject; // 获取单据实体对象var originatorId = flowSateContext.MapContext.MapInstance.OriginatorId; // 获取流程发起人用户IDvar originatorPostId = flowSateContext.MapContext.MapInstance.OriginatorPostId; // 获取流程发起人岗位ID
[tr][td=176] customizeConditionList[td=447]传入用户在连线上配置的自定义条件集合。可以根据每行条件的conditionRow.ConditionKey属性,获得用户在条件项中配置的基础资料ID,再计算该条件是否满足,计算结果通过conditionRow.ConditionResult传回流程引擎。

2.3. 示例插件代码
以下示例插件,举例说明如何解析“发起员工所属组织”连线条件,示例未经测试仅供参考思路。到K/3 Cloud安装目录的WebSite\Bin子目录,引用如下基本组件(其他组件按需引用):
Kingdee.BOS.dll
Kingdee.BOS.Core.dll
Kingdee.BOS.DataEntity.dll
Kingdee.BOS.ServiceHelper.dll
Kingdee.BOS.Workflow.Kernel.dll
Kingdee.BOS.Workflow.ServiceHelper.dll



using Kingdee.BOS.Condition;using Kingdee.BOS.Core.Metadata;using Kingdee.BOS.Orm.DataEntity;using Kingdee.BOS.ServiceHelper;using Kingdee.BOS.Workflow.Kernel;using Kingdee.BOS.Workflow.Kernel.Condition;using System;using System.Collections.Generic;using System.Linq;using System.Text; namespace Demo.Workflow.PlugIn.CustomizeCondition{ /// /// 以发起员工所属组织作为条件(本插件仅作为参考示例,未经测试) /// public class CustomizeConditionStaffOrg : AbstractConditionExecutorPlugIn { public override void Execute(MapStateContext flowSateContext, List<CustomizeConditionRow> customizeConditionList) { var context =flowSateContext.MapContext.BOSContext; // 获取BOS上下文 var originatorId =flowSateContext.MapContext.MapInstance.OriginatorId; // 获取流程发起人用户ID foreach (CustomizeConditionRow conditionRow in customizeConditionList) { // TODO 此处根据conditionRow.ConditionKey获得每行自定义条件项中基础资料ID,本例中即为组织ID;并计算条件真假,计算结果通过conditionRow.ConditionResult传回流程引擎 // 获取发起人员工 long senderStaffId =Kingdee.BOS.Workflow.ServiceHelper.EntrustServiceHelper.GetStaffByUserId(context,originatorId); FormMetadata senderStaffMeta = MetaDataServiceHelper.Load(context, "BD_Empinfo") as FormMetadata; DynamicObject senderStaff = BusinessDataServiceHelper.LoadSingle(context,senderStaffId, senderStaffMeta.BusinessInfo.GetDynamicObjectType()); // 判断发起人员工所属组织,是否符合自定义条件中的组织要求 string senderStaffOrgId = Convert.ToString(senderStaff["UseOrgId_Id"]); conditionRow.ConditionResult= (senderStaffOrgId == conditionRow.ConditionKey); } } }}
3. 开发者如何注册自定义条件插件
开发好自定义条件插件后,需要注册到数据表T_WF_ConditionType中。用户才能在流程连线的自定义条件设置界面,使用新的条件类型。

例如注册“员工所属组织”条件插件:
该条件类型的编码假定为WfConditionDemo;
该条件类型对应的基础资料组织FormID是ORG_Organizations;
条件插件格式是命名空间+类名, +组件名称,比如:
Demo.Workflow.PlugIn.CustomizeCondition.CustomizeConditionStaffOrg,Demo.Workflow.PlugIn
则在BOS设计器中导入如下KSQL:

DELETE T_WF_ConditionType WHERE FID = '200001';INSERT INTO T_WF_ConditionType(FID,FNUMBER,FCREATORID,FCREATEDATE,FMODIFIERID,FMODIFYDATE,FDOCUMENTSTATUS,FFORBIDSTATUS,FOBJECTTYPEID,FPARSECLASS)VALUES (200001,N'WfConditionDemo',16394,{ts'2017-04-27 10:08:12'},16394,{ts'2017-04-27 10:08:12'},'C','A','ORG_Organizations',N'Demo.Workflow.PlugIn.CustomizeCondition.CustomizeConditionStaffOrg,Demo.Workflow.PlugIn') ;DELETE T_WF_ConditionType_L WHERE FID = '200001' AND FLOCALEID = 2052;INSERT INTO T_WF_ConditionType_L(FPKID,FID,FLOCALEID,FNAME,FDESCRIPTION) VALUES(100001,200001,2052,N'以员工所属组织作为条件',N' ') ;
全文完。