Ejemplo n.º 1
0
 public void AddDestinationUser(ApprovalChainDestinationUser user)
 {
     if (ApproveChainDestinationUsers == null)
     {
         ApproveChainDestinationUsers = new List <ApprovalChainDestinationUser>();
     }
     ApproveChainDestinationUsers.Add(user);
 }
Ejemplo n.º 2
0
        public string ExecuteProcess(string sn, string action, string currentUser, string activityXML)
        {
            try
            {
                int parentProcInstID = K2DBHelper.GetRootParentsID(Convert.ToInt32(sn.Split('_')[0]));

                //获取Approve流程中的Destinations
                CDataFields dataFieldDestinations = new CDataFields("Destinations", "", "DF");
                //获取Approve流程中的节点信息
                dataFieldDestinations.AddDataField(new CDataField("SubApprovalChain", "", "DF"));
                K2Helper.GetProcessDataFields(sn, currentUser, dataFieldDestinations);
                string xmlDestination = dataFieldDestinations.DataFieldLists[0].Value;
                string xmlActivity    = dataFieldDestinations.DataFieldLists[1].Value;

                ApprovalChainDestination destinations = SerializationHelper.Deserialize <ApprovalChainDestination>(xmlDestination);

                ApprovalChainActivity activity = SerializationHelper.Deserialize <ApprovalChainActivity>(xmlActivity);
                //权重类型
                string actionWeightType = activity.ActionWeightType;
                if (actionWeightType == "")
                {
                    actionWeightType = "N";
                }

                //如果权重类型是百分比的情况下并且执行的操作不是Approve,则默认操作为Decline
                if (actionWeightType.Equals(EnumActionWeightType.P.ToString(), StringComparison.CurrentCultureIgnoreCase) &&
                    !action.Equals("Approve", StringComparison.CurrentCultureIgnoreCase))
                {
                    action = "Decline";
                }

                #region 如果执行的是退回到某个节点的操作
                if (action.Equals("GoBack", StringComparison.CurrentCultureIgnoreCase))
                {
                    //当前审批节点ID
                    string currentActivityID = destinations.ActivityID;
                    //要退回到的节点ID并且是没有权重控制的情况下
                    string targetActivityID = K2DBHelper.GetTargetActivityID(currentActivityID);
                    if (!string.IsNullOrEmpty(targetActivityID) &&
                        (actionWeightType.Equals(EnumActionWeightType.N.ToString()) || actionWeightType.Equals(EnumActionWeightType.R.ToString())))
                    {
                        //获取原始审批链
                        string originalProcessApproveChain = K2DBHelper.GetProcessOriginalXMLValue(parentProcInstID);

                        XmlDocument xmlProcess = new XmlDocument();
                        xmlProcess.LoadXml(originalProcessApproveChain);

                        //获取要退回到的节点
                        XmlNode nodeActivity = xmlProcess.SelectSingleNode("/Process/Activity[ID='" + targetActivityID + "' and Status='Completed']");
                        if (nodeActivity != null)
                        {
                            while (true)
                            {
                                nodeActivity.SelectSingleNode("./Status").InnerText       = "Available";
                                nodeActivity.SelectSingleNode("./ActionResult").InnerText = "";
                                XmlNodeList nodeListDestinations = nodeActivity.SelectNodes("./Destination");
                                foreach (XmlNode des in nodeListDestinations)
                                {
                                    des.SelectSingleNode("./Status").InnerText             = "Available";
                                    des.SelectSingleNode("./ActionResult").InnerText       = "";
                                    des.SelectSingleNode("./ActualActionResult").InnerText = "";
                                    //删除加签\会签信息
                                    XmlNode nodeDestinationActivity = des.SelectSingleNode("./Activity");
                                    if (nodeDestinationActivity != null)
                                    {
                                        des.RemoveChild(nodeDestinationActivity);
                                    }
                                }

                                if (nodeActivity.NextSibling != null && nodeActivity.NextSibling.Name.Equals("Activity", StringComparison.CurrentCultureIgnoreCase))
                                {
                                    nodeActivity = nodeActivity.NextSibling;
                                }
                                else
                                {
                                    break;
                                }
                            }

                            //更新原始审批链的状态
                            K2Helper.UpdateProcessDataFields(parentProcInstID, new CDataFields("ProcessApprovalChain", xmlProcess.OuterXml, "XF"));
                        }
                        else
                        {
                            //如果执行的是退回到某个节点的操作,但是没有配置退回到哪个节点,则退回到发起人
                            action = "Decline";
                        }
                    }
                    else
                    {
                        //如果执行的是退回到某个节点的操作,但是没有配置退回到哪个节点,则退回到发起人
                        action = "Decline";
                    }
                }
                #endregion

                //只有在执行同意操作并且(没有权重控制或在权重控制类型为R时)的前提下传递过来的activityXML才做为有效的加签、会签信息
                if (action.Equals("Approve", StringComparison.CurrentCultureIgnoreCase) &&
                    !string.IsNullOrEmpty(activityXML) &&
                    (actionWeightType.Equals(EnumActionWeightType.N.ToString()) || actionWeightType.Equals(EnumActionWeightType.R.ToString())))
                {
                    destinations.AddActivity(SerializationHelper.Deserialize <ApprovalChainActivity>(activityXML));
                }

                //只有在执行同意操作并且(没有权重控制或在权重控制类型为R时)的前提下传递过来的activityXML才做为有效的加签、会签信息
                //if (action.Equals("Approve", StringComparison.CurrentCultureIgnoreCase)
                //    && !string.IsNullOrEmpty(activityXML)
                //    )
                //{
                //    destinations.AddActivity(SerializationHelper.Deserialize<ApprovalChainActivity>(activityXML));
                //}

                //修改User节点的状态,记录User的Action
                ApprovalChainDestinationUser user = destinations.ApproveChainDestinationUsers.Find(d => d.Account.Equals(currentUser, StringComparison.CurrentCultureIgnoreCase));
                if (user != null)
                {
                    user.Executed     = true;
                    user.ActionResult = action;
                }

                destinations.ActionResult  = action;
                destinations.ActualUserID += ";" + currentUser;

                dataFieldDestinations = new CDataFields("Destinations", "", "DF");
                dataFieldDestinations.DataFieldLists[0].Value = SerializationHelper.Serialize(destinations);

                //  K2Helper.ExecuteProcess(sn, "", "", currentUser, dataFieldDestinations);

                //更新用以标识用户是否可以取回任务的DataField
                K2Helper.UpdateProcessDataFields(parentProcInstID, new CDataFields("CallBackProcInstID", sn.Split('_')[0], "DF"));
                //edit by lee
                K2Helper.ExecuteProcess(sn, "", "", currentUser, dataFieldDestinations);

                K2DBHelper.AddApproveLog(parentProcInstID, Convert.ToInt32(sn.Split('_')[0]), action, activityXML, currentUser);

                K2DBHelper.AddActSlot(Convert.ToInt32(sn.Split('_')[0]), parentProcInstID, activity.ID, activity.Name, currentUser, activity.Type);
            }
            catch (Exception ex)
            {
                K2DBHelper.RecoreErrorProfile(ex, "K2HelperWS.ExecuteProcess(SN=" + sn + ";action=" + action + ";currentUser="******";activityXML=" + activityXML + ")", currentUser);
                return(ex.Message);
            }
            return("Success");
        }
Ejemplo n.º 3
0
 public bool RemoveDestinationUser(ApprovalChainDestinationUser user)
 {
     return(ApproveChainDestinationUsers.Remove(user));
 }