二开案例.表单插件.普通提交和工作流提交

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

二开案例.表单插件.普通提交和工作流提交

【应用场景】

通过插件的方式,提交单据,控制是否要启动工作流。



【案例演示】

采购订单演示普通提交和工作流提交两种提交操作。



【实现步骤】

<1>编写表单插件,代码如下。

using Kingdee.BOS;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Validation;
using Kingdee.BOS.Orm;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Util;
using Kingdee.BOS.WebApi.FormService;
using Kingdee.BOS.Workflow.ServiceHelper;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
namespace Jac.XkDemo.BOS.Business.PlugIn
{
    /// <summary>
    /// 【表单插件】普通提交和工作流提交
    /// </summary>
    [Description("【表单插件】普通提交和工作流提交"), HotUpdate]
    public class WfSubmitFormPlugIn : AbstractDynamicFormPlugIn
    {
        public override void BarItemClick(BarItemClickEventArgs e)
        {
            base.BarItemClick(e);
            if (e.BarItemKey.EqualsIgnoreCase("test1"))
            {
                // 普通提交(不支持工作流)
                var result = Submit(this.Context, this.View.BillBusinessInfo, new[] {this.Model.DataObject});
                this.View.ShowOperateResult(result.OperateResult);
                return;
            }
            if (e.BarItemKey.EqualsIgnoreCase("test2"))
            {
                // 工作流提交(必须配置工作流或者审批流)
                var result = WfSubmit(this.Context, this.View.BillBusinessInfo, new[] {this.Model.DataObject});
                this.View.ShowOperateResult(result.OperateResult);
                return;
            }
            if (e.BarItemKey.EqualsIgnoreCase("test3"))
            {
                // 模拟WebApi提交(支持普通提交和工作流提交)
                var result = SubmitByWebApi(this.Context, this.View.BillBusinessInfo, new[] {this.Model.DataObject});
                this.View.ShowOperateResult(result.OperateResult);
                return;
            }
        }
        /// <summary>
        ///  普通提交(不支持工作流)
        /// </summary>
        private IOperationResult Submit(Context ctx, BusinessInfo businessInfo, DynamicObject[] objs)
        {
            var option = OperateOption.Create();
            // 校验
            var validateResult = BusinessDataServiceHelper.Validate(ctx, businessInfo, objs, "Submit", Enum_TimingPoint.Submit, option);
            if (!validateResult.IsSuccess)
            {
                // 校验失败
                return validateResult;
            }
            // 提交
            option.SetBOSValidateFlag(false);
            var pkids = objs.Select(o => o[0]).ToArray();
            var submitResult = BusinessDataServiceHelper.Submit(ctx, businessInfo, pkids, "Submit", option);
            return submitResult;
        }
        /// <summary>
        /// 工作流提交(必须配置工作流或者审批流)
        /// </summary>
        private IOperationResult WfSubmit(Context ctx, BusinessInfo businessInfo, DynamicObject[] objs)
        {
            var option = OperateOption.Create();
            // 单据校验
            var wfValidateResult = new OperationResult();
            foreach (var obj in objs)
            {
                var id = obj[0].ToString();
                if (ProcManageServiceHelper.CheckUnCompletePrcInstExsit(ctx, businessInfo.GetForm().Id, id))
                {
                    wfValidateResult.IsSuccess = false;
                    wfValidateResult.OperateResult.Add(new OperateResult
                    {
                        PKValue = id,
                        Message = "单据已绑定流程实例,不能进行提交操作!",
                        Name = obj[businessInfo.GetBillNoField().PropertyName].ToString(),
                        SuccessStatus = false
                    });
                }
            }
            if (!wfValidateResult.IsSuccess)
            {
                return wfValidateResult;
            }
            // 单据校验
            var validateResult = BusinessDataServiceHelper.Validate(ctx, businessInfo, objs, "Submit", Enum_TimingPoint.Submit, option);
            if (!validateResult.IsSuccess)
            {
                // 校验失败
                return validateResult;
            }
            // 提交
            option.SetBOSValidateFlag(false);
            var pkids = objs.Select(o => o[0].ToString()).ToArray();
            // 获取流程模板
            var prcList = WorkflowTemplateServiceHelper.GetPrcListByFormID(businessInfo.GetForm().Id, pkids, ctx);
            if (prcList.Count == 0)
            {
                wfValidateResult.IsSuccess = false;
                wfValidateResult.OperateResult.Add(new OperateResult
                {
                    PKValue = 0,
                    Message = "未匹配到流程!",
                    SuccessStatus = false
                });
                return wfValidateResult;
            }
            if (prcList.Count > 1)
            {
                wfValidateResult.IsSuccess = false;
                wfValidateResult.OperateResult.Add(new OperateResult
                {
                    PKValue = 0,
                    Message = "匹配到多个流程,请在单据中发起流程!",
                    SuccessStatus = false
                });
                return wfValidateResult;
            }
            // 多张提交
            var submitResult = BOSWorkflowServiceHelper.ListSubmit(ctx,businessInfo,0,pkids,prcList, option);
            // 单张提交
            //var submitResult = BOSWorkflowServiceHelper.BillSubmit(objs[0], ctx, prcList[0].ProcessIdList[0], 0, businessInfo, option);
            return submitResult;
        }
        /// <summary>
        /// 模拟WebApi提交(支持普通提交和工作流提交)
        /// </summary>
        /// <returns></returns>
        private IOperationResult SubmitByWebApi(Context ctx, BusinessInfo businessInfo, DynamicObject[] objs)
        {
            /*
 {
"Numbers": [],
"Ids": "",
"SelectedPostId": 0
}            
             */
            var ids = string.Join(",", objs.Select(o => o[0]));
            var data = new
            {
                Ids = ids
            };
            var jsonData = JsonConvert.SerializeObject(data);
            var rval = WebApiServiceCall.Submit(ctx, businessInfo.GetForm().Id, jsonData) as Dictionary<string, object>;
            var operationResult = new OperationResult();
            if (rval != null && rval.ContainsKey("Result"))
            {
                var result = rval["Result"] as Dictionary<string, object>;
                if (result != null && result.ContainsKey("ResponseStatus"))
                {
                    var resultResponseStatus = result["ResponseStatus"] as Dictionary<string, object>;
                    if (resultResponseStatus != null && resultResponseStatus.ContainsKey("IsSuccess") && Convert.ToBoolean(resultResponseStatus["IsSuccess"]))
                    {
                        operationResult.IsSuccess = true;
                        operationResult.OperateResult.Add(new OperateResult
                        {
                            PKValue = 0,
                            Message = JsonConvert.SerializeObject(rval),
                            Name = "提交成功",
                            SuccessStatus = true
                        });
                        return operationResult;
                    }
                }
            }
            operationResult.IsSuccess = false;
            operationResult.OperateResult.Add(new OperateResult
            {
                PKValue = 0,
                Message = JsonConvert.SerializeObject(rval),
                Name = "提交失败",
                SuccessStatus = false
            });
            return operationResult;
        }
    }
}


<2>拷贝插件组件到应用站点的WebSite\Bin目录下,重启IIS。


<3>BOSIDE扩展采购订单,菜单集合新增菜单项,注册表单插件,保存元数据,开发完毕。



【功能验证】

<1>登录业务站点,打开采购订单编辑界面,点击工作流提交,即可启动工作流,点击普通提交,则不会启动工作流。

工作流提交:

普通提交:

---------------------------------------------------------------------------------------------------------













【金蝶云星空BOS二次开发案例演示】https://vip.kingdee.com/article/94751030918525696

二开案例.表单插件.普通提交和工作流提交

【应用场景】通过插件的方式,提交单据,控制是否要启动工作流。【案例演示】采购订单演示普通提交和工作流提交两种提交操作。【实现步骤】...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息