Esempio n. 1
0
        /// <summary>
        /// 审核工作流任务
        /// </summary>
        /// <param name="user">当前审核人</param>
        /// <param name="taskNode">任务节点</param>
        /// <param name="log">任务操作记录</param>
        /// <param name="isPass">true表示通过,false表示不通过</param>
        /// <returns></returns>
        public ResultModel AuditTaskNode(UserModel user, TaskNode taskNode, TaskOperateLog log, List<TaskAttachOperateLog> taskAttachOperateLogs, bool isPass)
        {
            ResultModel result = new ResultModel();

            try
            {
                //插入附言
                TaskOperateLogDAL taskOperateLogDAL = new TaskOperateLogDAL();
                result = taskOperateLogDAL.Insert(user, log);
                if (result.ResultStatus != 0)
                    return result;

                int logId = (int)result.ReturnValue;

                //任务附件操作记录表
                if (taskAttachOperateLogs != null && taskAttachOperateLogs.Any())
                {
                    TaskAttachOperateLogDAL taskAttachOperateLogDAL = new TaskAttachOperateLogDAL();
                    foreach (TaskAttachOperateLog TaskAttachOperateLog in taskAttachOperateLogs)
                    {
                        TaskAttachOperateLog.LogId = logId;
                        result = taskAttachOperateLogDAL.Insert(user, TaskAttachOperateLog);
                        if (result.ResultStatus != 0)
                            return result;
                    }
                }

                //修改taskNode状态
                TaskNodeDAL taskNodeDAL = new TaskNodeDAL();
                result = taskNodeDAL.Audit(user, taskNode, isPass);
                if (result.ResultStatus != 0)
                    return result;

                //获取任务节点对应的任务
                TaskDAL taskDAL = new TaskDAL();
                result = taskDAL.Get(user, taskNode.TaskId);
                if (result.ResultStatus != 0)
                    return result;
                Task task = result.ReturnValue as Task;

                //获取task对应的datasource
                DataSourceDAL dataSourceDAL = new DataSourceDAL();
                result = dataSourceDAL.Get(user, task.DataSourceId);
                if (result.ResultStatus != 0)
                    return result;
                DataSource source = result.ReturnValue as DataSource;

                if (isPass)
                {
                    //获取流程模版配置
                    FlowMasterConfigDAL flowMasterConfigDAL = new FlowMasterConfigDAL();
                    result = flowMasterConfigDAL.GetByMasterId(user, task.MasterId);
                    if (result.ResultStatus == 0)
                    {
                        FlowMasterConfig flowMasterConfig = result.ReturnValue as FlowMasterConfig;
                        //如果同级节点只需一人审核通过就行,则将其他审核人作废
                        if (!flowMasterConfig.IsSeries)
                        {
                            result = taskNodeDAL.UpdateTaskNodeStatusByLevelIdExceptSelf(user, taskNode, StatusEnum.已作废);
                            //if (result.ResultStatus != 0)
                            //    return result;
                        }
                    }

                    result = this.JudgeSameLevelSuccessHandle(user, task, taskNode.NodeLevel, source);
                    if (result.ResultStatus != 0)
                        return result;
                }
                else
                {
                    //修改任务状态(改为已生效,该任务视为结束),并审核拒绝回调
                    result = taskDAL.Complete(user, task);
                    if (result.ResultStatus != 0)
                        return result;

                    ////修改数据源状态(改为已完成)
                    //result = dataSourceDAL.DataSourceComplete(user, source);
                    //if (result.ResultStatus != 0)
                    //    return result;
                    result = dataSourceDAL.Audit(user, source, false);
                    if (result.ResultStatus != 0)
                        return result;

                    result = RequestCallBackUrl(user, source, false);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取或新增消息类型
                    SmsTypeDAL smsTypeDAL = new SmsTypeDAL();
                    result = smsTypeDAL.InsertOrGet(user, task.MasterId);
                    if (result.ResultStatus != 0)
                        return result;

                    int smsTypeId = (int)result.ReturnValue;

                    //找到该任务的发起人,给他发消息提醒
                    Sms.Model.Sms sms = new Sms.Model.Sms()
                    {
                        SmsTypeId = smsTypeId,
                        SmsHead = string.Format("{0}已被退回", task.TaskName),
                        SmsStatus = (int)SmsStatusEnum.待处理消息,
                        SmsBody = task.TaskConnext,
                        SmsRelTime = DateTime.Now,
                        SmsLevel = 1,
                        SourceId = source.RowId
                    };

                    List<SmsDetail> smsDetails = new List<SmsDetail>
                    {
                        new SmsDetail()
                        {
                            EmpId = source.EmpId, //任务的发起人
                            ReadTime = DefaultValue.DefaultTime
                        }
                    };

                    SmsDAL smsDAL = new SmsDAL();
                    result = smsDAL.AddSms(user, sms, smsDetails);
                    if (result.ResultStatus != 0)
                        return result;
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
                result.ReturnValue = ex;
            }
            return result;
        }
Esempio n. 2
0
        public ResultModel ReturnHandle(UserModel user, Model.TaskOperateLog taskOperateLog)
        {
            ResultModel result = new ResultModel();
            FlowOperate flowOperate = new FlowOperate();

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //获取任务节点
                    result = tasknodeDAL.Get(user, taskOperateLog.TaskNodeId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.TaskNode taskNode = result.ReturnValue as Model.TaskNode;
                    if (taskNode == null || taskNode.TaskNodeId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取失败";
                        return result;
                    }

                    if (taskNode.NodeStatus != StatusEnum.待审核)
                    {
                        result.ResultStatus = -1;
                        result.Message = "该节点已审核";
                        return result;
                    }

                    string cmdText = string.Format("select * from dbo.Wf_TaskNode where TaskId = (select TaskId from dbo.Wf_TaskNode where TaskNodeId = {0}) and NodeStatus <> {1} ", taskOperateLog.TaskNodeId, (int)Common.StatusEnum.已作废);
                    result = tasknodeDAL.Load<Model.TaskNode>(user, CommandType.Text, cmdText);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.TaskNode> taskNodes = result.ReturnValue as List<Model.TaskNode>;
                    if (taskNodes == null || !taskNodes.Any())
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取任务节点失败";
                        return result;
                    }

                    //如果是第一层节点就直接拒绝
                    if (taskNodes.Select(a => a.NodeLevel).Where(a => a > 0).Distinct().Count() == 1)
                    {
                        result = flowOperate.AuditTaskNode(user, taskNode, taskOperateLog, null, false);
                        if (result.ResultStatus != 0)
                            return result;
                    }
                    else
                    {
                        //将当前层级上的所有审核人都视为审核拒绝
                        result = tasknodeDAL.UpdateTaskNodeStatusByLevelId(user, taskNode.TaskId, taskNode.NodeLevel, Common.StatusEnum.审核拒绝);
                        if (result.ResultStatus != 0)
                            return result;

                        //写入审核操作记录
                        DAL.TaskOperateLogDAL taskOperateLogDAL = new TaskOperateLogDAL();
                        result = taskOperateLogDAL.Insert(user, taskOperateLog);
                        if (result.ResultStatus != 0)
                            return result;

                        int lastNodeLevel = taskNodes.Where(a => a.NodeLevel < taskNode.NodeLevel).Select(a => a.NodeLevel).Max();

                        //修改上一层节点的状态
                        result = tasknodeDAL.UpdateTaskNodeStatusByLevelId(user, taskNode.TaskId, lastNodeLevel, StatusEnum.已作废);
                        if (result.ResultStatus != 0)
                            return result;

                        //获取数据源
                        DAL.DataSourceDAL dataSourceDAL = new DataSourceDAL();
                        result = dataSourceDAL.GetDataSourceByTaskNodeId(user, taskNode.TaskNodeId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.DataSource dataSource = result.ReturnValue as Model.DataSource;

                        //获取任务
                        DAL.TaskDAL taskDAL = new TaskDAL();
                        result = taskDAL.Get(user, taskNode.TaskId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.Task task = result.ReturnValue as Model.Task;

                        result = flowOperate.CreateTaskNodes(user, task, lastNodeLevel, dataSource);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }
            finally
            {
                if (result.ResultStatus != 0)
                    this.Log.ErrorFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue);
                else if (this.Log.IsInfoEnabled)
                    this.Log.InfoFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue);
            }

            return result;
        }