Exemple #1
0
        /// <summary>
        /// 创建任务节点
        /// </summary>
        /// <param name="task">任务</param>
        /// <param name="nodeLevel">节点级别</param>
        /// <returns></returns>
        public ResultModel CreateTaskNodes(UserModel user, Task task, int nodeLevel, DataSource source)
        {
            ResultModel result = new ResultModel();
            bool IsCreate = false;

            try
            {
                //通过外部请求获取当前审核数据源
                result = GetConditionUrl(source);
                if (result.ResultStatus != 0)
                    return result;
                Dictionary<string, object> conditionDic = result.ReturnValue as Dictionary<string, object>;

                NodeDAL nodeDAL = new NodeDAL();
                NodeOperateDAL nodeOperateDAL = new NodeOperateDAL();
                NodeOperate nodeOperate = null;
                TaskOperate taskOperate = null;

                DataTable dt = null;
                //获取模板中当前层级的所有节点
                lock (nodeCollection)
                {
                    string key = string.Format("{0}{1}", task.MasterId, nodeLevel);
                    if (nodeCollection.ContainsKey(key))
                        dt = nodeCollection[key];
                    else
                    {
                        SelectModel nodeSelect = new SelectModel();
                        nodeSelect.ColumnName = "*";
                        nodeSelect.OrderStr = "NodeId";
                        nodeSelect.PageIndex = 1;
                        nodeSelect.PageSize = 500;
                        nodeSelect.TableName = "dbo.Wf_Node";
                        nodeSelect.WhereStr = string.Format("MasterId={0} and NodeLevel={1} and NodeStatus = {2}", task.MasterId, nodeLevel, (int)StatusEnum.已生效);
                        result = nodeDAL.Load(user, nodeSelect);
                        if (result.ResultStatus != 0)
                            return result;
                        dt = result.ReturnValue as DataTable;
                        nodeCollection.Add(key, dt);
                    }
                }

                if (dt != null && dt.Rows.Count > 0)
                {
                    TaskNodeDAL taskNodeDAL = new TaskNodeDAL();
                    foreach (DataRow dr in dt.Rows)
                    {
                        //判断是否符合条件
                        result = JudgeNodeCondition(Convert.ToInt32(dr["NodeId"]), task.TaskId, conditionDic);
                        if (result.ResultStatus != 0)
                            return result;

                        bool judge = false;
                        if (result.ResultStatus == 0 && result.ReturnValue != null)
                            bool.TryParse(result.ReturnValue.ToString(), out judge);
                        if (judge)
                        {
                            int nodeId = Convert.ToInt32(dr["NodeId"]);

                            //获取该节点
                            result = nodeDAL.Get(user, nodeId);
                            if (result.ResultStatus != 0)
                                return result;

                            Node node = result.ReturnValue as Node;
                            if (node == null)
                                return result;

                            //判断该节点是否需要操作
                            result = nodeOperateDAL.GetByNodeId(user, node.NodeId);
                            if (result.ResultStatus == 0)
                                nodeOperate = result.ReturnValue as NodeOperate;

                            //获取审核人
                            AuditEmpDAL auditEmpDAl = new AuditEmpDAL();
                            result = auditEmpDAl.GetEmpIdsByAuditEmpId(user, node.AuditEmpId, source);
                            if (result.ResultStatus != 0)
                                return result;

                            DataTable dtvalue = result.ReturnValue as DataTable;
                            //如果不存在审核人,则转到下一个节点
                            if (dtvalue == null || dtvalue.Rows.Count < 1)
                            {
                                //result.ResultStatus = -1;
                                //return result;
                                continue;
                            }

                            //如果存在审核人,则生成相应审核节点
                            foreach (DataRow drValue in dtvalue.Rows)
                            {
                                if (Convert.ToInt32(drValue["EmpId"]) <= 0) continue;

                                TaskNode taskNode = new TaskNode()
                                {
                                    NodeLevel = nodeLevel,
                                    NodeStatus = StatusEnum.待审核,
                                    TaskId = task.Id,
                                    NodeId = nodeId,
                                    AuditTime = DefaultValue.DefaultTime,
                                    EmpId = Convert.ToInt32(drValue["EmpId"])
                                };

                                //如果在一个任务中存在相同的审核人且审核通过,则将新生成的审核人节点状态改为已生效(视为审核通过)
                                result = taskNodeDAL.GetTaskNodeIdBySameAuditEmp(user, task.TaskId, Convert.ToInt32(drValue["EmpId"]));
                                DataTable resultDatatable = result.ReturnValue as DataTable;
                                if (result.ResultStatus == 0 && resultDatatable != null && resultDatatable.Rows.Count > 0 && nodeOperate == null)
                                {
                                    taskNode.NodeStatus = StatusEnum.已生效;
                                    result = taskNodeDAL.Insert(user, taskNode);
                                    if (result.ResultStatus != 0)
                                        return result;

                                    int taskNodeIdValue = (int)result.ReturnValue;

                                    //插入附言
                                    TaskOperateLogDAL taskOperateLogDAL = new TaskOperateLogDAL();
                                    result = taskOperateLogDAL.GetLogByTaskNodeIdAndEmpId(user, Convert.ToInt32(resultDatatable.Rows[0]["TaskNodeId"]), Convert.ToInt32(drValue["EmpId"]));
                                    if (result.ResultStatus != 0)
                                        return result;

                                    TaskOperateLog taskOperateLog = result.ReturnValue as TaskOperateLog;
                                    if (taskOperateLog != null)
                                    {
                                        taskOperateLog.TaskNodeId = taskNodeIdValue;

                                        result = taskOperateLogDAL.Insert(user, taskOperateLog);
                                    }
                                    if (result.ResultStatus != 0)
                                        return result;

                                    IsCreate = true;
                                }
                                else if (result.ResultStatus == 0)//否则添加消息提醒
                                {
                                    result = taskNodeDAL.Insert(user, taskNode);
                                    if (result.ResultStatus != 0)
                                        return result;

                                    int taskNodeIdValue = (int)result.ReturnValue;

                                    if (nodeOperate != null)
                                    {
                                        taskOperate = new TaskOperate()
                                        {
                                            TaskNodeId = taskNodeIdValue,
                                            OperateUrl = nodeOperate.OperateUrl,
                                            OperateStatus = StatusEnum.已生效
                                        };

                                        TaskOperateDAL taskOperateDAL = new TaskOperateDAL();
                                        result = taskOperateDAL.Insert(user, taskOperate);
                                        if (result.ResultStatus != 0)
                                            return result;
                                    }

                                    //添加消息提醒
                                    Sms.Model.Sms sms = new Sms.Model.Sms()
                                    {
                                        SmsTypeId = 1,//to do list
                                        SmsHead = task.TaskName,
                                        SmsStatus = (int)SmsStatusEnum.待处理消息,
                                        SmsBody = task.TaskConnext,
                                        SmsRelTime = DateTime.Now,
                                        SmsLevel = 1,
                                        SourceId = taskNodeIdValue //taskNodeId
                                    };

                                    List<SmsDetail> smsDetails = new List<SmsDetail>();
                                    smsDetails.Add(new SmsDetail()
                                    {
                                        EmpId = Convert.ToInt32(drValue["EmpId"]),
                                        ReadTime = DefaultValue.DefaultTime
                                    });

                                    SmsDAL smsDAL = new SmsDAL();
                                    result = smsDAL.AddSms(user, sms, smsDetails);
                                    if (result.ResultStatus != 0)
                                        return result;

                                    IsCreate = true;
                                }
                            }
                        }
                    }

                    if (!IsCreate)
                    {
                        result.Message = "当前审核层级无审核人员";
                        result.ResultStatus = -1;

                        //递归生成下级节点
                        result = CreateTaskNodes(user, task, ++nodeLevel, source);
                    }
                    else
                    {
                        //如果创建了审核节点,则判断是否所有审核节点都通过了
                        result = this.JudgeSameLevelSuccessHandle(user, task, nodeLevel, source);
                    }
                }
                else
                {
                    result.Message = "不存在下级节点";
                    result.ResultStatus = -1;

                    //是否判断在无下级节点后审核流程结束?审核结果为通过?

                    TaskDAL taskDAL = new TaskDAL();
                    result = taskDAL.Complete(user, task);
                    if (result.ResultStatus != 0)
                        return result;

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

                    result = this.RequestCallBackUrl(user, source, true);
                    if (result.ResultStatus != 0)
                        return result;
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.ReturnValue = ex;
                result.ResultStatus = -1;
            }

            return result;
        }
Exemple #2
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;
        }