二开案例.智能流程服务.单据下推自动提交工作流

栏目:云星空知识作者:金蝶来源:金蝶云社区发布:2024-09-16浏览:1

二开案例.智能流程服务.单据下推自动提交工作流

智能流程服务配置审核后自动下推,下推后自动提交。但是系统只支持普通提交,无法提交到工作流。

可以在下游单据的提交操作上挂插件,调工作流提交。

image.webp

1、创建测试单据testAA、testBB,配置单据转换规则

image.webp


2、配置智能流程策略,在testAA审核时,自动下推单据testBB

image.webp

3、服务参数勾选“保存后自动提交”

image.webp

4、testBB设置工作流

image.webp



4、审核单据testAA,自动下推testBB,但是只调了普通提交,没有走工作流

image.webp

image.webp


5、在testBB的提交操作上挂插件,判断是智能流程调提交时,取消原来的提交操作,改为提交工作流

using Kingdee.BOS;
using Kingdee.BOS.App;
using Kingdee.BOS.Contracts;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Orm;
using Kingdee.BOS.Util;
using Kingdee.BOS.Workflow.Contracts;
using Kingdee.BOS.Workflow.Models.EnumStatus;
using Kingdee.BOS.Workflow.Models.Template;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Test202408
{
    [Kingdee.BOS.Util.HotUpdate]
    public class 智能流程自动提交工作流 : AbstractOperationServicePlugIn
    {
        public override void BeforeExecuteOperationTransaction(BeforeExecuteOperationTransaction e)
        {
            var stackTrace = Environment.StackTrace;

            //判断是来自智能流程服务IBPM的调用
            if (stackTrace.Contains("Kingdee.BOS.IBPM.App.Core.ServiceHandler.ExecutePushServiceHandler.SubmitData") && !stackTrace.Contains("SubmitWorkflow"))
            {
                e.Cancel = true;
                Kingdee.BOS.KDThread.MainWorker.QuequeTask(this.Context, () =>
                {
                    SubmitWorkflow(e);
                }, result => { });
            }
        }

        void SubmitWorkflow(BeforeExecuteOperationTransaction e)
        {
            this.OperationResult.IsShowMessage = true;
            // 本演示只提交一张单据,批量处理,请自行修改代码实现
            string formId = this.BusinessInfo.GetForm().Id;
            string billId = Convert.ToString(e.SelectedRows.First().DataEntity[0]);

            // 首先判断单据是否已经有未完成的工作流
            IProcInstService procInstService = Kingdee.BOS.Workflow.Contracts.ServiceFactory.GetProcInstService(this.Context);
            bool isExist = procInstService.CheckUnCompletePrcInstExsit(this.Context, formId, billId);
            if (isExist == true)
            {
                throw new KDBusinessException("AutoSubmit-001", "该单据已经启动了流程,不允许重复提交!");
            }

            // 读取单据的工作流配置模板
            IWorkflowTemplateService wfTemplateService = Kingdee.BOS.Workflow.Contracts.ServiceFactory.GetWorkflowTemplateService(this.Context);
            List<FindPrcResult> findProcResultList = wfTemplateService.GetPrcListByFormID(
            formId, new string[] { billId }, this.Context);
            if (findProcResultList == null || findProcResultList.Count == 0)
            {
                throw new KDBusinessException("AutoSubmit-002", "查找单据适用的流程模板失败,不允许提交工作流!");
            }

            // 设置提交参数:忽略操作过程中的警告,避免与用户交互
            OperateOption submitOption = OperateOption.Create();
            submitOption.SetIgnoreWarning(true);
            IOperationResult submitResult = null;

            FindPrcResult findProcResult = findProcResultList[0];
            if (findProcResult.Result == TemplateResultType.Error)
            {
                throw new KDBusinessException("AutoSubmit-003", "单据不符合流程启动条件,不允许提交工作流!");
            }
            else if (findProcResult.Result != TemplateResultType.Normal)
            {// 本单无适用的流程图,直接走传统审批
                ISubmitService submitService = ServiceHelper.GetService<ISubmitService>();
                submitResult = submitService.Submit(this.Context, this.BusinessInfo,
                new object[] { billId }, "Submit", submitOption);
            }
            else
            {// 走工作流
                IBOSWorkflowService wfService = Kingdee.BOS.Workflow.Contracts.ServiceFactory.GetBOSWorkflowService(this.Context);
                submitResult = wfService.ListSubmit(this.Context, this.BusinessInfo,
                0, new object[] { billId }, findProcResultList, submitOption);
            }
            // 判断提交结果
            if (submitResult.IsSuccess == true)
            {
                // 自动提交成功,显示空操作本身的成功提示即可
            }
            else
            {
                submitResult.MergeValidateErrors();
                if (submitResult.OperateResult == null)
                {// 未知原因导致提交失败
                    throw new KDBusinessException("AutoSubmit-004", "未知原因导致自动提交失败!");
                }
                else
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("自动提交失败,失败原因:");
                    foreach (var operateResult in submitResult.OperateResult)
                    {
                        sb.AppendLine(operateResult.Message);
                    }
                    throw new KDBusinessException("AutoSubmit-005", sb.ToString());
                }
            }
        }
    }
}


6、再次审核testAA,自动下推的单据testBB走了工作流

image.webp







二开案例.智能流程服务.单据下推自动提交工作流

智能流程服务配置审核后自动下推,下推后自动提交。但是系统只支持普通提交,无法提交到工作流。可以在下游单据的提交操作上挂插件,调工作...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息