zoukankan      html  css  js  c++  java
  • 【转】【金蝶K3Cloud】 在插件中调用工作流

    在插件中可以调用ApprovalAssignmentServiceHelper.SubmitApprovalItems()进行工作流审批。SubmitApprovalItems()需要一个AssignmentContext参数,而AssignmentContext属性非常多,构造起来很麻烦。
    因此我写了两个方法,将SubmitApprovalItems()再次封装,传入几个简单参数,就能完成审批。

      1   /// <summary>
      2         /// 审批单据,actionName为空时,自动寻找第一个同意审批项;
      3         /// 有多个类型为通过的审批项时,可用actionName指定审批项,如actionName="审批通过"
      4         /// </summary>
      5         /// <param name="formId">单据FormId</param>
      6         /// <param name="pKValue">单据主键</param>
      7         /// <param name="receiverName">处理人</param>
      8         /// <param name="disposition">审批意见</param>
      9         /// <param name="isApprovalFlow">是否为审批流</param>
     10         public void ApproveBill(string formId, string pKValue, string receiverName, string disposition, bool isApprovalFlow = false, string actionName = null)
     11         {
     12             List<AssignResult> assignResults = GetApproveActions(formId, pKValue, receiverName);
     13             AssignResult approvalAssignResults = assignResults.FirstOrDefault(r => r.ApprovalType == AssignResultApprovalType.Forward);
     14             if (approvalAssignResults == null) throw new Exception("未找到审批项。");
     15             SubmitWorkflow(formId, pKValue, receiverName, approvalAssignResults.Id, disposition, isApprovalFlow);
     16         }
     17 
     18         /// <summary>
     19         /// 驳回单据,actionName为空时,自动寻找一个驳回审批项;
     20         /// 有多个类型为驳回的审批项时(如驳回、打回发起人),可用actionName指定审批项,如actionName="打回发起人"
     21         /// </summary>
     22         public void RejectBill(string formId, string pKValue, string receiverName, string disposition, bool isApprovalFlow = false, string actionName = null)
     23         {
     24             List<AssignResult> assignResults = GetApproveActions(formId, pKValue, receiverName);
     25             if (!string.IsNullOrEmpty(actionName))
     26                 assignResults = assignResults.Where(r => r.Name.Any(p => p.Value == actionName)).ToList();
     27             else
     28                 assignResults = assignResults.OrderBy(r => r.Name.Any(p => p.Value == "打回发起人")).ToList();
     29             AssignResult rejectAssignResults = assignResults.FirstOrDefault(r => r.ApprovalType == AssignResultApprovalType.Reject);
     30             if (rejectAssignResults == null) throw new Exception("未找到驳回审批项。");
     31             SubmitWorkflow(formId, pKValue, receiverName, rejectAssignResults.Id, disposition, isApprovalFlow);
     32         }
     33 
     34         private List<AssignResult> GetApproveActions(string formId, string pKValue, string receiverName)
     35         {
     36             DataSet ds = DBUtils.ExecuteDataSet(this.Context, @"select b.FASSIGNID,b.FAPPROVALASSIGNID
     37                                 from t_wf_assign a 
     38                                 join T_WF_APPROVALASSIGN b on a.fassignid=b.fassignid 
     39                                 where b.Fobjecttypeid=@FormID 
     40                                 and b.Fkeyvalue=@pKValue and a.FSTATUS=0 and a.FRECEIVERNAMES=@FRECEIVERNAMES",
     41                         new List<SqlParam>
     42                         {
     43                             new SqlParam("@FormID", DbType.String, formId),
     44                             new SqlParam("@pKValue", DbType.String, pKValue),
     45                             new SqlParam("@FRECEIVERNAMES", DbType.String, receiverName)
     46                         });
     47             DataRow row = ds.Tables[0].Rows.Cast<DataRow>().FirstOrDefault();
     48             if (row == null) return new List<AssignResult> { };
     49 
     50             string assignId = row["FASSIGNID"].ToString();
     51             string approvalAssignId = row["FAPPROVALASSIGNID"].ToString();
     52             string _approvalItemId = AssignmentServiceHelper.OpenApprovalItem(this.Context, this.Context.UserId, assignId, false);
     53             var _approvalItem = AssignmentServiceHelper.GetApprovalItemById(this.View.Context, _approvalItemId);
     54             return _approvalItem.Actions.ToList();
     55         }
     56 
     57 
     58         private void SubmitWorkflow(string formId, string pKValue, string receiverName, string actionResult, string disposition, bool isApprovalFlow)
     59         {
     60             DataSet ds = DBUtils.ExecuteDataSet(this.Context, @"select b.FASSIGNID,b.FAPPROVALASSIGNID,a.FACTINSTID
     61                                 from t_wf_assign a 
     62                                 join T_WF_APPROVALASSIGN b on a.fassignid=b.fassignid 
     63                                 where b.Fobjecttypeid=@FormID 
     64                                 and b.Fkeyvalue=@pKValue and a.FSTATUS=0 and a.FRECEIVERNAMES=@FRECEIVERNAMES",
     65                         new List<SqlParam>
     66                         {
     67                             new SqlParam("@FormID", DbType.String, formId),
     68                             new SqlParam("@pKValue", DbType.String, pKValue),
     69                             new SqlParam("@FRECEIVERNAMES", DbType.String, receiverName)
     70                         });
     71             DataRow row = ds.Tables[0].Rows.Cast<DataRow>().FirstOrDefault();
     72             if (row == null) throw new Exception("未找到待办任务");
     73 
     74             string assignId = row["FASSIGNID"].ToString();
     75             string approvalAssignId = row["FAPPROVALASSIGNID"].ToString();
     76             string _approvalItemId = AssignmentServiceHelper.OpenApprovalItem(this.Context, this.Context.UserId, assignId, false);
     77             FormMetadata formMetadata = MetaDataServiceHelper.GetFormMetaData(this.Context, formId);
     78             DynamicObject ObjData = BusinessDataServiceHelper.LoadSingle(this.Context, pKValue, formMetadata.BusinessInfo.GetDynamicObjectType());
     79             BusinessInfo businessInfo = formMetadata.BusinessInfo;
     80 
     81             var _approvalItem = AssignmentServiceHelper.GetApprovalItemById(this.View.Context, _approvalItemId);
     82             if (_approvalItem == null) throw new Exception("待办任务所在的流程实例不在运行中,不能进行处理!");
     83             _approvalItem.ObjData = ObjData;
     84             _approvalItem.ReceiverPostId = 0;
     85             _approvalItem.ActionResult = actionResult;
     86             _approvalItem.Disposition = disposition.ToString();
     87             AssignResult assignResult = _approvalItem.Actions != null ? _approvalItem.Actions.FirstOrDefault(i => i.Id == actionResult) : null;
     88             AssignResultApprovalType approvalType = assignResult != null ? assignResult.ApprovalType : AssignResultApprovalType.None;
     89             _approvalItem.ActionResultType = approvalType;
     90             _approvalItem.Status = ApprovalItemStatus.Completed;
     91             DateTime timeNow = TimeServiceHelper.GetSystemDateTime(this.Context);
     92             _approvalItem.CompletedTime = timeNow;
     93 
     94             ObjectActivityInstance _activityInstance = AssignmentServiceHelper.ConvertActivityModel(
     95                     this.Context, businessInfo, approvalAssignId, _approvalItem);
     96 
     97             var option = OperateOption.Create();
     98 
     99             if (isApprovalFlow)
    100             {
    101                 ApprovalAssignmentContext assignCtx = new ApprovalAssignmentContext()
    102                 {
    103                     ApprovalItems = new List<ApprovalItem>() { _approvalItem },
    104                     Info = businessInfo,
    105                     Option = option
    106                 };
    107                 assignCtx.NextActHandler = null;
    108                 assignCtx.RejectReturn = false;
    109                 assignCtx.ActivityInstance = _activityInstance;
    110                 if (actionResult == AssignResultApprovalType.Reject.ToString())
    111                 {
    112                     string actInstId = row["FACTINSTID"].ToString();
    113                     Kingdee.BOS.Workflow.App.Core.ProcInstService procInstService = new Kingdee.BOS.Workflow.App.Core.ProcInstService();
    114                     var rejectActivityIds = procInstService.GetBackActInstList(this.Context, actInstId, true).Select(r => r.ActivityId);
    115                     if (!rejectActivityIds.Any()) throw new Exception("无驳回节点");
    116                     assignCtx.Target = rejectActivityIds.FirstOrDefault();
    117                 }
    118                 ApprovalAssignmentServiceHelper.SubmitApprovalItem(Context, assignCtx);
    119             }
    120             else
    121             {
    122                 ApprovalAssignmentContext assignCtx = new ApprovalAssignmentContext()
    123                 {
    124                     ApprovalItems = new List<ApprovalItem>() { _approvalItem },
    125                     Info = businessInfo,
    126                     Option = option
    127                 };
    128                 assignCtx.NextActHandler = null;
    129                 assignCtx.RejectReturn = false;
    130                 assignCtx.ActivityInstance = _activityInstance;
    131                 AssignmentServiceHelper.SubmitApprovalItem(Context, assignCtx);
    132             }
    133         }
  • 相关阅读:
    AbsoluteLayout 相框
    Cursor getContentResolver
    Diary DiaryDbAdapter 日记本程序
    Linkify
    Installation error: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED
    exampleuse SharedPreferences
    Gallery
    AbsoluteLayout xiantu
    PRD
    android 拨打电话 号码判断
  • 原文地址:https://www.cnblogs.com/jlz-s/p/9834866.html
Copyright © 2011-2022 走看看