예제 #1
0
        /// <summary>
        /// 分配工作(关卡参与人)
        /// </summary>
        /// <param name="listWorker"></param>
        /// <returns></returns>
        public void AssignWork()
        {
            //解析参与人
            IList <int> listWorkerId = this.Activity.ParseParticipant(this.FlowInstance.FlowDefine.ID,
                                                                      this.FlowInstance.FlowNo);

            if (listWorkerId.Count > 0)
            {
                //分配工作
                foreach (int workerId in listWorkerId)
                {
                    WorkItemInstance item = new WorkItemInstance();
                    item.Create(m_ActivityInstanceId, workerId);
                    m_ListWorkItemInstance.Add(item);
                }

                //发送提醒短信
                if (this.Activity.IsSms == "Y")
                {
                    List <string> listMobile = new List <string>();

                    foreach (int workerId in listWorkerId)
                    {
                        IWorker worker = ctx["Worker"] as IWorker;

                        string mobile = worker.GetWorkerById(workerId).Mobile;

                        if (!string.IsNullOrEmpty(mobile))
                        {
                            listMobile.Add(mobile);
                        }
                    }

                    if (listMobile.Count > 0)
                    {
                        ISMS sms = ctx["SMS"] as ISMS;

                        string content = string.Format("您有一笔{0}需要审核", FlowInstance.FlowDefine.Name);

                        Log4Net.LogInfo(content);

                        sms.SendSMG(listMobile, content, "99999");
                    }
                }
            }
            else
            {
                throw new Exception(string.Format("关卡({0})无签核人", this.Activity.Name));
            }
        }
예제 #2
0
파일: Engine.cs 프로젝트: bertyang/Mobile
        /// <summary>
        /// 签核
        /// </summary>
        /// <param name="workItemId">任务ID</param>
        /// <param name="approveValue">签核值:Y同意;N:否决</param>
        /// <param name="approveRemark">签核意见</param>
        /// <param name="transferNext">是否判断转到哪个下一关卡</param>
        /// <returns>成功与否</returns>
        public bool Approve(int workItemId, int approverId, string approveValue,
                            string approveRemark, string nextActivityId)
        {
            //防止重复点击
            //if (Convert.ToString(HttpContext.Current.Session[approverId.ToString()]) == string.Format("WorkItemId:{0}", workItemId))
            //{
            //    return false;
            //}
            //else
            //{
            //    HttpContext.Current.Session[approverId.ToString()] = string.Format("WorkItemId:{0}", workItemId);
            //}


            lock (lockObj)
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions()
                {
                    IsolationLevel = IsolationLevel.ReadCommitted
                }))
                {
                    try
                    {
                        WorkItemInstance instWorkItem = new WorkItemInstance(workItemId);
                        FlowInstance     instFlow     = instWorkItem.ActivityInstance.FlowInstance;
                        ActivityInstance instActivity = instWorkItem.ActivityInstance;

                        //验证数字摘要
                        if (!instFlow.VerifyDigest())
                        {
                            Log4Net.LogError("Workflow_Engine", string.Format("WorkItemID:{0},Message:表单数据变化,无法签核", workItemId));

                            return(false);
                        }

                        //数字签名
                        if (instActivity.Activity.IsSign.ToUpper() == "Y")
                        {
                            instWorkItem.Sign();
                        }

                        //更新工作实例状态
                        instWorkItem.Actorid   = approverId;
                        instWorkItem.AppValue  = approveValue;
                        instWorkItem.AppRemark = approveRemark;
                        instWorkItem.Approve();

                        //否决关闭所有对象
                        if (approveValue == WorkItemAppValue.Reject)
                        {
                            instFlow.ApproveReject += new FlowInstance.ApproveEventHandler(Mail.SendMail);
                            instFlow.ApproveReject += new FlowInstance.ApproveEventHandler(CallBack.Update);

                            Activity endActivity = instFlow.FlowDefine.Activitys.SingleOrDefault(t => t.Type == "end");

                            if (endActivity != null && endActivity.IsSms.ToUpper() == "Y")
                            {
                                instFlow.ApproveReject += new FlowInstance.ApproveEventHandler(Sms.SendSms);
                            }

                            instActivity.Close();
                            instFlow.Reject();

                            //关闭平行关卡
                            List <ActivityInstance> listParallelActivity =
                                instFlow.ActivityInstances.Where(
                                    t => t.State == ActivityInstanceStatus.Active).ToList();

                            foreach (ActivityInstance p in listParallelActivity)
                            {
                                p.Close();
                            }
                        }
                        else if (approveValue == WorkItemAppValue.Return)
                        {
                            //关闭当间关卡实例
                            instActivity.Close();

                            //创建退回关卡实例
                            ActivityInstance instReturnActivity = new ActivityInstance();

                            instReturnActivity.Create(instFlow.ID, int.Parse(nextActivityId));

                            instReturnActivity.Active();

                            instReturnActivity.AssignWork();
                        }
                        else if (approveValue == WorkItemAppValue.Agree)
                        {
                            if (!string.IsNullOrEmpty(nextActivityId))
                            {
                                string[] arrActivityId = nextActivityId.TrimEnd(',').Split(',');

                                List <int> listActivityId = new List <int>();

                                foreach (string id in arrActivityId)
                                {
                                    listActivityId.Add(int.Parse(id));
                                }

                                if (!TransferBack(instWorkItem.ActivityInstance.ID, listActivityId))
                                {
                                    return(false);
                                }
                            }
                        }
                        else if (approveValue == WorkItemAppValue.Reserve)
                        {
                            WorkItemInstance item = new WorkItemInstance();
                            item.Create(instActivity.ID, approverId);
                        }

                        scope.Complete();

                        return(true);
                    }
                    catch (Exception ex)
                    {
                        Log4Net.LogError("Workflow_Engine", string.Format("WorkItemID:{0},Message:{1}", workItemId, ex.ToString()));

                        return(false);
                    }
                }
            }
        }