Beispiel #1
0
        /// <summary>
        /// 结束任务
        /// </summary>
        /// <param name="taskId"></param>
        /// <param name="approverId"></param>
        public void endTask(int taskId, int approverId)
        {
            // 新增任务记录: 结束任务 任务状态: 待审批
            var taskRecord = new TaskRecord {
                Status = 0, CreateTime = DateTime.Now, Desc = "任务完成", SubmitterId = user.UserId, SubmitterName = user.UserName, TaskId = taskId
            };
            var taskRecordId = Db.Insertable(taskRecord).ExecuteReturnIdentity();

            // 新增任务审批人列表
            var approverList = new List <ApproveApprover>();
            var submitter    = new ApproveApprover {
                DocId = taskRecordId, ApproverId = user.UserId, Type = 1, Level = 0
            };

            approverList.Add(submitter);

            var superiorUserId = getTaskSuperior(taskId, user);    // 获取上级任务负责人
            var approver       = new ApproveApprover {
                DocId = taskRecordId, ApproverId = superiorUserId, Type = 1, Level = 1
            };

            approverList.Add(approver);
            Db.Insertable(approverList).ExecuteReturnIdentity();

            // 新增任务审批记录
            var record = new ApproveRecord {
                DocId = taskRecordId, ApproverId = user.UserId, Type = 1, Opinion = "", Result = "已提交"
            };

            Db.Insertable(record).ExecuteReturnIdentity();
        }
Beispiel #2
0
        /// <summary>
        /// 任务完成情况提交
        /// </summary>
        /// <param name="record"></param>
        /// <returns></returns>
        public TaskRecord addOrUpdateTaskRecord(TaskRecord record)
        {
            record.SubmitterId   = user.UserId;
            record.SubmitterName = user.UserName;
            record.CreateTime    = DateTime.Now;

            Db.Ado.BeginTran();

            // 更新task的进度
            var task = Db.Queryable <Task>().Where(u => u.Id == record.TaskId).Single();

            if (task.Progress + record.Percent > 100)
            {
                throw new Exception($"该任务已经完成{task.Progress}%,无法提交占比{record.Percent}%的完成情况!");
            }

            task.Progress += record.Percent;
            Db.Updateable(task).ExecuteCommand();

            var returnReocrd = Db.Saveable(record).ExecuteReturnEntity();

            // 新增任务审批记录
            var approverList = new List <ApproveApprover>();
            var submitter    = new ApproveApprover {
                DocId = returnReocrd.Id, ApproverId = user.UserId, Type = 2, Level = 0
            };

            approverList.Add(submitter);

            try
            {
                var superiorUserId = getTaskSuperior(record.TaskId, user);

                var approver = new ApproveApprover {
                    DocId = returnReocrd.Id, ApproverId = superiorUserId, Type = 2, Level = 1
                };
                approverList.Add(approver);
                Db.Insertable(approverList).ExecuteReturnIdentity();

                // 新增任务审批记录
                var approveRecord = new ApproveRecord {
                    DocId = returnReocrd.Id, ApproverId = user.UserId, Type = 2, Opinion = "", Result = "已提交"
                };
                Db.Insertable(approveRecord).ExecuteReturnIdentity();

                Db.Ado.CommitTran();
            }
            catch (Exception ex)
            {
                Db.Ado.RollbackTran();

                task.Progress -= record.Percent;
                Db.Updateable(task).ExecuteCommand();

                throw new Exception(ex.Message);
            }

            return(returnReocrd);
        }