二开案例.WebApi.查询审批路线
【应用场景】
WebApi,查询审批路线。
【案例演示】
采购订单,审批中的工作流,查询审批路线信息。
【数据准备】
新建采购订单,启动工作流。
查询流程实例ID:
SELECT a.FASSIGNID AS 待办任务ID,a.FPROCINSTID AS 流程实例ID,* FROM T_WF_ASSIGN a LEFT JOIN T_WF_PROCINST b ON a.FPROCINSTID=b.FPROCINSTID WHERE b.FNUMBER='CGDD000695_20220902135532'
【实现步骤】
<1>编写自定义WebApi接口,代码如下。
using Kingdee.BOS.ServiceFacade.KDServiceFx; using Kingdee.BOS.WebApi.ServicesStub; using Kingdee.BOS.Workflow.Models.Chart; using Kingdee.BOS.Workflow.ServiceHelper; using System; using System.Collections.Generic; namespace Jac.XkDemo.BOS.WebApi { /// <summary> /// 【WebApi】查询审批路线 /// </summary> public class GetProcessRouterWebApiService : AbstractWebApiBusinessService { public GetProcessRouterWebApiService(KDServiceContext context) : base(context) { // } /// <summary> /// 查询审批路线 /// </summary> /// <param name="assignId">待办任务ID</param> /// <returns>返回审批路线集合</returns> public List<ChartActivityInfo> GetProcessRouterByAssignId(string assignId) { var ctx = KDContext.Session.AppContext; if (ctx == null) { // 会话超时 throw new Exception("ctx = null"); } string versionId, procInstId; AssignmentServiceHelper.GetProcInstIdAndVersionId(ctx, assignId, out versionId, out procInstId); var activityInfos = WorkflowChartServiceHelper.GetProcessRouter(ctx, procInstId); return activityInfos; } /// <summary> /// 查询审批路线 /// </summary> /// <param name="procInstId">流程实例ID</param> /// <returns>返回审批路线集合</returns> public List<ChartActivityInfo> GetProcessRouterByProcInstId(string procInstId) { var ctx = KDContext.Session.AppContext; if (ctx == null) { // 会话超时 throw new Exception("ctx = null"); } var activityInfos = WorkflowChartServiceHelper.GetProcessRouter(ctx, procInstId); return activityInfos; } } }
<2>拷贝WebApi接口组件到应用站点的WebSite\Bin目录下,重启IIS,开发完毕。
【功能验证】
<1>编写接口单元测试代码如下,验证通过。
using Kingdee.BOS.WebApi.Client; using Kingdee.BOS.Workflow.Models.Chart; using Microsoft.VisualStudio.TestTools.UnitTesting; using Newtonsoft.Json; using System; using System.Collections.Generic; namespace Jac.XkDemo.BOS.WebApiTests { /// <summary> /// 【WebApi】查询审批路线Tests /// </summary> [TestClass] public class GetProcessRouterWebApiServiceTests { [TestMethod] public void GetProcessRouterByAssignIdTest() { // Init var url = "http://localhost:1600/k3cloud/"; var dbid = "602f2c09aee85f"; var userName = "demo"; var password = "888888"; int lcid = 2052; var apiClient = new K3CloudApiClient(url); var isLoginOk = apiClient.Login(dbid, userName, password, lcid); // Action if (isLoginOk) { // 待办任务ID var assignId = "63119ad5509c8b022e"; var rval = apiClient.Execute<List<ChartActivityInfo>>("Jac.XkDemo.BOS.WebApi.GetProcessRouterWebApiService.GetProcessRouterByAssignId,Jac.XkDemo.BOS.WebApi", new object[] { assignId }); Assert.IsTrue(rval != null); Console.WriteLine("assignId:" + assignId); Console.WriteLine(JsonConvert.SerializeObject(rval)); return; } // Assert Assert.IsFalse(true); } [TestMethod] public void GetProcessRouterByProcInstIdTest() { // Init var url = "http://localhost:1600/k3cloud/"; var dbid = "602f2c09aee85f"; var userName = "demo"; var password = "888888"; int lcid = 2052; var apiClient = new K3CloudApiClient(url); var isLoginOk = apiClient.Login(dbid, userName, password, lcid); // Action if (isLoginOk) { // 流程实例ID var procInstId = "63119ad4509c910079"; var rval = apiClient.Execute<List<ChartActivityInfo>>("Jac.XkDemo.BOS.WebApi.GetProcessRouterWebApiService.GetProcessRouterByProcInstId,Jac.XkDemo.BOS.WebApi", new object[] { procInstId }); Assert.IsTrue(rval != null); Console.WriteLine("procInstId:" + procInstId); Console.WriteLine(JsonConvert.SerializeObject(rval)); return; } // Assert Assert.IsFalse(true); } } }
【Postman测试结果】
---------------------------------------------------------------------------------------------------------
【更多知识】
获取审批路线信息内部细节,请参考业务对象:流程图_审批路线(WF_D_FlowWay)。
表单插件:Kingdee.BOS.Workflow.PlugIns.Chart.WorkflowChartFlowWay, Kingdee.BOS.Workflow.PlugIns
---------------------------------------------------------------------------------------------------------
【金蝶云星空BOS二次开发案例演示】https://vip.kingdee.com/article/94751030918525696
二开案例.WebApi.查询审批路线
本文2024-09-23 04:01:11发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-162588.html