/// <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; }
/// <summary> /// 提交审核并创建任务和提醒消息 /// </summary> /// <param name="user">用户</param> /// <param name="model">提交审核数据实体</param> /// <param name="master">模版</param> /// <param name="source">数据源</param> /// <param name="task">任务</param> /// <returns></returns> public ResultModel AuditAndCreateTask(UserModel user, IModel model, FlowMaster master, DataSource source, Task task) { ResultModel result = new ResultModel(); try { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { DataSourceDAL dataSourceDAL = new DataSourceDAL(); result = dataSourceDAL.CheckHasSource(new DataSource() { TableCode = model.TableName, RowId = model.Id }); if (result.ResultStatus != 0 || result.AffectCount > 0) { result.Message = "不能重复提交审核"; result.ResultStatus = -1; return result; } Common.Operate operate = Common.Operate.CreateOperate(model, true); if (operate == null) { result.Message = "模版不存在"; result.ResultStatus = -1; return result; } result = operate.Get(user, model.Id); if (result.ResultStatus != 0) return result; IModel resultModel = result.ReturnValue as IModel; if (resultModel == null || resultModel.Id <= 0) { result.ResultStatus = -1; result.Message = "数据不存在,不能提交审核"; return result; } //判断是否可以直接审核通过 FlowMasterConfigDAL flowMasterConfigDAL = new FlowMasterConfigDAL(); result = flowMasterConfigDAL.GetByMasterId(user, master.MasterId); if (result.ResultStatus == 0) { FlowMasterConfig flowMasterConfig = result.ReturnValue as FlowMasterConfig; if (flowMasterConfig != null && flowMasterConfig.ConfigId > 0 && flowMasterConfig.CanPassAudit) { result = RequestCallBackUrlForPass(user, source, true); if (result.ResultStatus != 0) return result; if (result.ResultStatus == 0) scope.Complete(); return result; } } result = operate.Submit(user, resultModel); if (result.ResultStatus != 0) return result; result = this.CreateTask(user, master, source, task); if (result.ResultStatus != 0) return result; int taskId = (int)result.ReturnValue; string aids = string.Empty; AttachBLL attachBLL = new AttachBLL(); result = attachBLL.GetAttachIds(user, resultModel); if (result.ResultStatus == 0) { DataTable dt = result.ReturnValue as DataTable; if (dt != null && dt.Rows.Count > 0) { aids = dt.Rows.Cast<DataRow>().Aggregate(aids, (current, dr) => current + (dr["AttachId"].ToString() + ",")); if (!string.IsNullOrEmpty(aids)) aids = aids.Substring(0, aids.Length - 1); } TaskAttachBLL taskAttachBLL = new TaskAttachBLL(); result = taskAttachBLL.InsertAttach(user, taskId, aids); if (result.ResultStatus != 0) return result; } else result.ResultStatus = 0; scope.Complete(); } } catch (Exception ex) { result.Message = ex.Message; result.ResultStatus = -1; } return result; }