コード例 #1
0
        /// <summary>
        /// 更新流程步骤下一步
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="nextStep"></param>
        /// <param name="isSaved"></param>
        private void UpdateNextStep(MissionskyOAEntities dbContext, WorkflowStepModel nextStep, bool isSaved = true)
        {
            if (nextStep.PrevStep.HasValue && nextStep.PrevStep.Value > 0)
            {
                var prevStep = dbContext.WorkflowSteps.FirstOrDefault(
                    it => it.FlowId == nextStep.FlowId && it.Id == nextStep.PrevStep.Value);

                if (prevStep == null)
                {
                    Log.Error("流程步骤上一步不存在。");
                    throw new KeyNotFoundException("流程步骤上一步不存在。");
                }

                if (prevStep.NextStep.HasValue && prevStep.NextStep.Value > 0 && prevStep.NextStep.Value != nextStep.Id)
                {
                    Log.Error("流程步骤上一步不存在。");
                    throw new KeyNotFoundException("流程步骤上一步不存在。");
                }

                prevStep.NextStep = nextStep.Id;

                if (isSaved)
                {
                    dbContext.SaveChanges();
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// 获取审批步骤,将[直接领导]审批步骤转换为有效审批步骤
        /// </summary>
        /// <param name="approver"></param>
        /// <param name="curStep"></param>
        /// <param name="workflow"></param>
        /// <returns></returns>
        private WorkflowStepModel GetApproveStepForApprover(UserModel approver, WorkflowStepModel curStep,
                                                            WorkflowModel workflow)
        {
            if (curStep.Id == Constant.WORKFLOW_DIRECT_SUPERVISOR_APPROVE_NODE) //当前步骤是[直接领导审批]
            {
                //按[角色]查找
                curStep =
                    workflow.WorkflowSteps.FirstOrDefault(
                        it =>
                        it.Type == WorkflowStepType.LeaderApprove &&
                        it.OperatorType == WorkflowOperator.Role && it.Operator == approver.Role);

                //按[用户]查找
                curStep = curStep ?? workflow.WorkflowSteps.FirstOrDefault(
                    it =>
                    it.Type == WorkflowStepType.LeaderApprove &&
                    it.OperatorType == WorkflowOperator.User && it.Operator == approver.Id);

                if (curStep == null)
                {
                    Log.Error("直接领导无法审批流程。");
                    throw new InvalidOperationException("直接领导无法审批流程。");
                }
            }

            return(curStep);
        }
コード例 #3
0
        /// <summary>
        /// 流程当前步骤
        /// </summary>
        /// <param name="order"></param>
        /// <param name="workflow"></param>
        /// <param name="operation"></param>
        /// <returns></returns>
        private WorkflowStepModel GetCurrentStep(OrderModel order, WorkflowModel workflow, OperateOrderModel operation)
        {
            WorkflowStepModel curStep = null;

            if (operation.Operation == WorkflowOperation.Apply)
            {
                curStep = workflow.GetUserApplyStep(); //当前步骤为[申请]步骤
            }
            else
            {
                if (order.NextStep.HasValue)
                {
                    curStep = (order.NextStep.Value == Constant.WORKFLOW_DIRECT_SUPERVISOR_APPROVE_NODE
                        ? workflow.GetDirectSupervisorApproveStep() //当前步骤为[直接领导审批]步骤
                        : workflow.WorkflowSteps.FirstOrDefault(it => it.Id == order.NextStep.Value));
                }
            }

            if (curStep == null)
            {
                Log.Error("当前流程步骤无效。");
                throw new KeyNotFoundException("当前流程步骤无效。");
            }

            return(curStep);
        }
コード例 #4
0
        /// <summary>
        /// 添加工作流流骤
        /// </summary>
        /// <param name="model">工作流步骤</param>
        /// <returns>工作流步骤id</returns>
        public int AddWorkflowStep(WorkflowStepModel model)
        {
            if (model == null)
            {
                Log.Error("工作流步骤无效。");
                throw new InvalidOperationException("工作流步骤无效。");
            }

            using (var dbContext = new MissionskyOAEntities())
            {
                ValidWorkflowStep(dbContext, model);

                //添加工作流
                var entity = model.ToEntity();
                entity.CreatedTime = DateTime.Now;

                //不是领导审批,不需要设置时长
                if (model.Type != WorkflowStepType.LeaderApprove)
                {
                    entity.MinTimes = 0.0;
                    entity.MaxTimes = 0.0;
                }

                dbContext.WorkflowSteps.Add(entity);
                dbContext.SaveChanges();

                //更新流程步骤下一步
                model.Id = entity.Id;
                UpdateNextStep(dbContext, model);

                return(model.Id);
            }
        }
コード例 #5
0
        /// <summary>
        /// 获取用户申请的下一审批步骤
        /// </summary>
        /// <param name="director"></param>
        /// <param name="workflow"></param>
        /// <returns></returns>
        private WorkflowStepModel GetNextStepForUserApply(UserModel director, WorkflowModel workflow)
        {
            WorkflowStepModel nextStep = null;

            //无直接领导人, 则到[行政财务]审批
            if (director == null)
            {
                //行政审批
                nextStep = workflow.WorkflowSteps.FirstOrDefault(it => it.Type == WorkflowStepType.AdminReview);
                //财务审批
                nextStep = nextStep ?? workflow.WorkflowSteps.FirstOrDefault(it => it.Type == WorkflowStepType.FinanceReview);
            }
            //[直接领导]审批
            else
            {
                nextStep = workflow.GetDirectSupervisorApproveStep();
                nextStep.OperatorType = WorkflowOperator.User;
                nextStep.Operator     = director.Id; //设置审批人
            }

            if (nextStep == null)
            {
                Log.Error("无效的申请流程。");
                throw new InvalidOperationException("无效的申请流程。");
            }

            return(nextStep);
        }
コード例 #6
0
        /// <summary>
        /// 是否由领导审批流程步骤
        /// </summary>
        /// <param name="model">步骤</param>
        /// <returns>trur or false</returns>
        public static bool IsLeaderApproving(this WorkflowStepModel model)
        {
            if (model == null)
            {
                throw new KeyNotFoundException("Invalid order workflow.");
            }

            return(model.Type == WorkflowStepType.LeaderApprove || model.Type == WorkflowStepType.None);
        }
コード例 #7
0
        /// <summary>
        /// 是否是财务审阅步骤节点
        /// </summary>
        /// <param name="model">步骤</param>
        /// <returns>trur or false</returns>
        public static bool IsFinanceReviewing(this WorkflowStepModel model)
        {
            if (model == null)
            {
                throw new KeyNotFoundException("Invalid order workflow.");
            }

            return(model.Type == WorkflowStepType.FinanceReview);
        }
コード例 #8
0
        /// <summary>
        /// 申请单流程状态转换
        /// </summary>
        /// <param name="order">申请单</param>
        /// <param name="curUser">当前用户</param>
        /// <param name="workflow">流程下一步</param>
        /// <param name="operation">流程操作</param>
        /// <returns>流程下一步状态</returns>
        private WorkflowStepModel GotoNextStep(OrderModel order, UserModel curUser, WorkflowModel workflow, OperateOrderModel operation)
        {
            if (order == null || order.OrderDets == null || order.OrderDets.Count < 1)
            {
                Log.Error("无效的申请单。");
                throw new InvalidOperationException("无效的申请单。");
            }

            if (workflow == null || workflow.WorkflowSteps == null || workflow.WorkflowSteps.Count < 1)
            {
                Log.Error("无效的流程。");
                throw new InvalidOperationException("无效的流程。");
            }

            WorkflowStepModel nextStep = null; //流程下一步

            switch (operation.Operation)
            {
            case WorkflowOperation.Apply:     //申请
            case WorkflowOperation.Revoke:    //撤销
                //直接领导
                var director = curUser.DirectlySupervisorId.HasValue
                        ? _userService.GetUserDetail(curUser.DirectlySupervisorId.Value)
                        : null;

                nextStep = GetNextStepForUserApply(director, workflow);
                break;

            case WorkflowOperation.Approve:                                                                            //审批
                var curStep = GetCurrentStep(order, workflow, operation);                                              //获取流程当前步骤
                curStep = GetApproveStepForApprover(curUser, curStep, workflow);                                       //将[直接领导]审批步骤转换为有效审批步骤

                if (curStep.IsLeaderApproving())                                                                       //当前是[领导审批]
                {
                    nextStep = GetNextStepForLeaderApprove(order, curStep, workflow);                                  //获取[领导审批]的下一步骤
                }
                else if (curStep.IsAdminReviewing())                                                                   //当前是[行政审批]
                {
                    nextStep = workflow.WorkflowSteps.FirstOrDefault(it => it.Type == WorkflowStepType.FinanceReview); //需要[财务审批]
                }
                break;

            case WorkflowOperation.None:     //无效
            case WorkflowOperation.Rejecte:  //拒绝
            case WorkflowOperation.Cancel:   //取消
                break;
            }

            return(nextStep);
        }
コード例 #9
0
        public static WorkflowModel ToModel(this Workflow entity)
        {
            var model = new WorkflowModel()
            {
                Id            = entity.Id,
                Name          = entity.Name ?? string.Empty,
                Desc          = entity.Desc ?? string.Empty,
                CreatedTime   = entity.CreatedTime,
                Type          = (WorkflowType)entity.Type,
                Status        = entity.Status ? WorkflowStatus.Enabled : WorkflowStatus.Disabled,
                Condition     = entity.Condition ?? string.Empty,
                ConditionDesc = entity.ConditionDesc ?? string.Empty,
                WorkflowSteps = new List <WorkflowStepModel>()
            };

            //获取流程步骤
            if (entity.WorkflowSteps != null && entity.WorkflowSteps.Count > 0)
            {
                foreach (var step in entity.WorkflowSteps)
                {
                    WorkflowStepModel stepModel = new WorkflowStepModel()
                    {
                        Id           = step.Id,
                        FlowId       = step.FlowId,
                        Name         = step.Name,
                        MinTimes     = step.MinTimes,
                        MaxTimes     = step.MaxTimes,
                        NextStep     = step.NextStep.HasValue ? step.NextStep.Value : 0,
                        Desc         = step.Desc,
                        CreatedTime  = step.CreatedTime,
                        Operator     = step.Operator,
                        OperatorType = (WorkflowOperator)step.OperatorType,
                        Type         = step.Type.HasValue ? (WorkflowStepType)step.Type.Value : WorkflowStepType.LeaderApprove
                    };

                    if (stepModel.MinTimes == 0)
                    {
                        stepModel.MinTimes = Int16.MinValue;
                    }
                    if (stepModel.MaxTimes == 0)
                    {
                        stepModel.MaxTimes = Int16.MaxValue;
                    }

                    model.WorkflowSteps.Add(stepModel);
                }
            }

            return(model);
        }
コード例 #10
0
        /// <summary>
        /// 验证工作流信息
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="model"></param>
        private void ValidWorkflowStep(MissionskyOAEntities dbContext, WorkflowStepModel model)
        {
            var existedStep =
                dbContext.WorkflowSteps.FirstOrDefault(
                    it =>
                    !string.IsNullOrEmpty(it.Name) &&
                    it.Name.Equals(model.Name, StringComparison.InvariantCultureIgnoreCase) && model.FlowId == it.FlowId && model.Id != it.Id);

            if (existedStep != null)
            {
                Log.Error(string.Format("工作流步骤已经存在,工作流步骤: {0}", model.Name));
                throw new InvalidOperationException(string.Format("工作流步骤已经存在,工作流步骤: {0}", model.Name));
            }
        }
コード例 #11
0
        public static WorkflowStepModel ToModel(this WorkflowStep entity)
        {
            var model = new WorkflowStepModel()
            {
                Id           = entity.Id,
                FlowId       = entity.FlowId,
                Name         = entity.Name,
                MinTimes     = entity.MinTimes,
                MaxTimes     = entity.MaxTimes,
                NextStep     = entity.NextStep,
                Desc         = entity.Desc,
                Type         = entity.Type.HasValue ? (WorkflowStepType)entity.Type.Value : WorkflowStepType.LeaderApprove,
                Operator     = entity.Operator,
                OperatorType = (WorkflowOperator)entity.OperatorType,
                CreatedTime  = entity.CreatedTime
            };

            return(model);
        }
コード例 #12
0
        public static WorkflowStep ToEntity(this WorkflowStepModel model)
        {
            var entity = new WorkflowStep()
            {
                Id           = model.Id,
                FlowId       = model.FlowId,
                Name         = model.Name,
                MinTimes     = model.MinTimes,
                MaxTimes     = model.MaxTimes,
                NextStep     = model.NextStep,
                Operator     = model.Operator,
                OperatorType = model.OperatorType == WorkflowOperator.None ? (int)WorkflowOperator.User : (int)model.OperatorType,
                Desc         = model.Desc,
                Type         = model.Type == WorkflowStepType.None ? (int)WorkflowStepType.LeaderApprove : (int)model.Type,
                CreatedTime  = model.CreatedTime
            };

            return(entity);
        }
コード例 #13
0
        public ActionResult EditStep(WorkflowStepModel model)
        {
            if (string.IsNullOrEmpty(model.Name))
            {
                ModelState.AddModelError("Name", "请输入流程步骤名称.");
            }

            if (model.Type == WorkflowStepType.None)
            {
                ModelState.AddModelError("Type", "请选择流程步骤类型.");
            }

            if (model.Type == WorkflowStepType.LeaderApprove && model.MaxTimes <= 0 && model.MinTimes <= 0)
            {
                ModelState.AddModelError("Type", "请领导审批的时间范围.");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (model.Id <= 0)
                    {
                        WorkflowService.AddWorkflowStep(model);
                    }
                    else
                    {
                        WorkflowService.UpdateWorkflowStep(model);
                    }

                    return(RedirectToAction("Edit", new { id = model.FlowId }));
                }
                catch (Exception ex)
                {
                    Log.Error(ex);
                    ViewBag.Message = ex.Message;
                }
            }

            EditStep(model.FlowId, model.Id);
            return(View(model));
        }
コード例 #14
0
        /// <summary>
        /// 申请单流程状态转换
        /// </summary>
        /// <param name="order">申请单</param>
        /// <param name="nextStep">流程下一步</param>
        /// <param name="operation">流程操作</param>
        /// <returns>流程下一步状态</returns>
        private OrderStatus SwitchStatus(OrderModel order, WorkflowStepModel nextStep, OperateOrderModel operation)
        {
            var nextStatus = OrderStatus.Apply;

            //1, 申请
            if (operation.Operation == WorkflowOperation.Apply)
            {
                nextStatus = OrderStatus.Apply;
            }
            //2, 拒绝
            else if (operation.Operation == WorkflowOperation.Rejecte)
            {
                nextStatus = OrderStatus.Rejected;
            }
            //3, 流程未完成
            else if (nextStep != null && nextStep.Id > 0)
            {
                //3.1, 行政、财务审阅(领导已批准)
                if (nextStep.IsAdminReviewing() || nextStep.IsFinanceReviewing())
                {
                    //nextStatus = OrderStatus.Reviewing;
                    nextStatus = (order.RefOrderId == null || order.RefOrderId.Value < 1
                        ? OrderStatus.Approved
                        : OrderStatus.Revoked);
                }
                //3.2, 领导审批
                else if (nextStep.IsLeaderApproving())
                {
                    nextStatus = OrderStatus.Approving;
                }
            }
            //4, 流程结束
            else
            {
                nextStatus = (order.RefOrderId == null || order.RefOrderId.Value < 1
                    ? OrderStatus.Approved
                    : OrderStatus.Revoked);
            }

            return(nextStatus);
        }
コード例 #15
0
        /// <summary>
        /// 获取[领导审批]的下一步骤
        /// </summary>
        /// <param name="order"></param>
        /// <param name="curStep"></param>
        /// <param name="workflow"></param>
        /// <returns></returns>
        private WorkflowStepModel GetNextStepForLeaderApprove(OrderModel order, WorkflowStepModel curStep, WorkflowModel workflow)
        {
            WorkflowStepModel nextStep = null;
            var detail = order.OrderDets.FirstOrDefault(); //申请单详细

            if (detail == null || detail.IOHours == null || Math.Abs(detail.IOHours.Value) <= 0.0)
            {
                Log.Error("无效的申请单详细。");
                throw new KeyNotFoundException("无效的申请单详细。");
            }

            //在领导审批允许的范围内,则结束[领导审批],转到[行政财务审批]
            if (Math.Abs(detail.IOHours.Value) <= curStep.MaxTimes)
            {
                //行政审批
                nextStep = workflow.WorkflowSteps.FirstOrDefault(it => it.Type == WorkflowStepType.AdminReview);
                //财务审批
                nextStep = nextStep ?? workflow.WorkflowSteps.FirstOrDefault(it => it.Type == WorkflowStepType.FinanceReview);
            }
            else
            {
                curStep.NextStep = curStep.NextStep ?? Constant.WORKFLOW_INVALID_NODE;
                nextStep         = workflow.WorkflowSteps.FirstOrDefault(it => it.Id == curStep.NextStep.Value);

                //领导审批未结束, 则提示异常
                if (nextStep == null || !nextStep.IsLeaderApproving())
                {
                    Log.Error("无效的领导审批流程。");
                    throw new KeyNotFoundException("无效的领导审批流程。");
                }
            }

            if (nextStep == null)
            {
                Log.Error("无效的审批流程。");
                throw new KeyNotFoundException("无效的审批流程。");
            }

            return(nextStep);
        }
コード例 #16
0
        /// <summary>
        /// 转到下一个审批人
        /// </summary>
        /// <param name="dbContext">数据库上下文对象</param>
        /// <param name="nextStep">下一步</param>
        /// <returns></returns>
        private UserModel GotoNextApprover(MissionskyOAEntities dbContext, WorkflowStepModel nextStep)
        {
            UserModel nextApprover = null; //流程下一步审批人

            if (nextStep != null)
            {
                //[用户]审批
                if (nextStep.OperatorType == WorkflowOperator.User)
                {
                    nextApprover = dbContext.Users.FirstOrDefault(it => it.Id == nextStep.Operator).ToModel();
                }
                //[角色]审批
                else
                {
                    var userRole = dbContext.UserRoles.FirstOrDefault(it => it.RoleId == nextStep.Operator);

                    if (userRole == null)
                    {
                        Log.Error("找不到流程的审批人角色。");
                        throw new KeyNotFoundException("找不到流程的审批人角色。");
                    }

                    var nextApproverEntity = dbContext.Users.FirstOrDefault(it => it.Id == userRole.UserId);

                    if (nextApproverEntity == null)
                    {
                        Log.Error("找不到流程审批人。");
                        throw new KeyNotFoundException("找不到流程审批人。");
                    }

                    nextApprover = nextApproverEntity.ToModel();
                }
            }

            return(nextApprover);
        }
コード例 #17
0
        //
        // GET: /Workflow/Edit/5
        public ActionResult EditStep(int flowId, int?id)
        {
            if (flowId < 1)
            {
                return(RedirectToAction("Edit"));
            }

            #region 获取流程步骤类型

            NameValueCollection collection = EnumExtensions.GetDescriptionList(typeof(WorkflowStepType));
            var stepTypes        = new List <SelectListItem>();
            var selectedStepType = (int)WorkflowStepType.None;
            stepTypes.Add(new SelectListItem()
            {
                Value = "0", Text = "请选择流程步骤类型"
            });

            foreach (string key in collection)
            {
                if (key != WorkflowStepType.None.ToString())
                {
                    stepTypes.Add(new SelectListItem()
                    {
                        Value = ((int)Enum.Parse(typeof(WorkflowStepType), key)).ToString(),
                        Text  = collection[key]
                    });
                }
            }

            #endregion

            #region 获取流程步骤类型
            collection = EnumExtensions.GetDescriptionList(typeof(WorkflowOperator));
            var operatorTypes         = new List <SelectListItem>();
            var selectedOperatorTypes = (int)WorkflowOperator.None;

            foreach (string key in collection)
            {
                if (key != WorkflowOperator.None.ToString())
                {
                    operatorTypes.Add(new SelectListItem()
                    {
                        Value = ((int)Enum.Parse(typeof(WorkflowOperator), key)).ToString(),
                        Text  = collection[key]
                    });
                }
            }

            #endregion

            #region 用户角色

            var roleList = this.RoleService.SearchAllRole();
            roleList = roleList ?? new List <RoleModel>();

            var roles = new List <SelectListItem>();
            roles.Add(new SelectListItem()
            {
                Value = "0", Text = "请选择用户角色"
            });

            var selectedRole = 0;

            roleList.ForEach(it => roles.Add(new SelectListItem()
            {
                Value = it.Id.ToString(), Text = it.RoleName
            }));

            #endregion

            #region 审批用户
            var selectedUser = 0;
            var userList     = this.UserService.GetUserList(new SearchUserModel()
            {
                Status = AccountStatus.Normal
            });
            userList = userList ?? new List <UserModel>();

            var users = new List <SelectListItem>();
            users.Add(new SelectListItem()
            {
                Value = "0", Text = "请选择用户"
            });

            //工程师角色
            var eng =
                roleList.FirstOrDefault(
                    it =>
                    it.RoleName == "工程师" ||
                    (!string.IsNullOrEmpty(it.Abbreviation) && it.Abbreviation.ToLower().Equals("eng")));
            eng = eng ?? new RoleModel();

            userList = userList.Where(it => it.Role != 0 && it.Role != eng.Id).ToList(); //不为工程师的其它用户
            userList.ForEach(it =>
            {
                users.Add(new SelectListItem()
                {
                    Value = it.Id.ToString(),
                    Text  = string.Format("{0}({1})", it.EnglishName, it.ChineseName)
                });
            });

            #endregion

            #region 流程

            var workflow = WorkflowService.GetWorkflowDetail(flowId);
            var steps    = new List <SelectListItem>();
            steps.Add(new SelectListItem()
            {
                Value = "0", Text = "请选择流程上一步"
            });
            var prevStep = 0; //上一步

            if (workflow == null)
            {
                throw new KeyNotFoundException("找不到工作流。");
            }

            foreach (var step in workflow.WorkflowSteps)
            {
                steps.Add(new SelectListItem()
                {
                    Value = step.Id.ToString(),
                    Text  = step.Name
                });
            }

            #endregion

            WorkflowStepModel model = null;

            if (!id.HasValue || id.Value < 1) //新增
            {
                model = new WorkflowStepModel()
                {
                    Type         = WorkflowStepType.LeaderApprove,
                    OperatorType = WorkflowOperator.User
                };
            }
            else //修改
            {
                model = WorkflowService.GetStepDetailById(id.Value);

                //流程类型
                selectedStepType = model.Type == WorkflowStepType.None
                    ? (int)WorkflowStepType.LeaderApprove
                    : (int)model.Type;

                //用户角色
                selectedRole = model.OperatorType == WorkflowOperator.Role ? model.Operator : 0;

                //用户
                selectedUser = model.OperatorType == WorkflowOperator.User ? model.Operator : 0;

                //审批人类型
                selectedOperatorTypes = model.OperatorType == WorkflowOperator.None
                    ? (int)WorkflowOperator.User
                    : (int)model.OperatorType;

                //上一步
                var prevStepModel = workflow.WorkflowSteps.FirstOrDefault(it => it.NextStep == id);
                if (prevStepModel != null)
                {
                    prevStep = prevStepModel.Id;
                }
            }

            ViewData["WorkflowSteps"]        = new SelectList(steps, "Value", "Text", prevStep);
            ViewData["WorkflowStepType"]     = new SelectList(stepTypes, "Value", "Text", selectedStepType);
            ViewData["WorkflowOperatorType"] = new SelectList(operatorTypes, "Value", "Text", selectedOperatorTypes);
            ViewData["Roles"] = new SelectList(roles, "Value", "Text", selectedRole);
            ViewData["Users"] = new SelectList(users, "Value", "Text", selectedUser);
            InitWorkflow(flowId);
            //ViewData["Users"] = new SelectList(users, "Value", "Text", selectedUser);

            return(View(model));
        }
コード例 #18
0
        /// <summary>
        /// 更新工作流步骤
        /// </summary>
        /// <param name="model">工作流步骤</param>
        /// <returns>true or false</returns>
        public bool UpdateWorkflowStep(WorkflowStepModel model)
        {
            if (model == null)
            {
                Log.Error("工作流步骤无效。");
                throw new InvalidOperationException("工作流步骤无效。");
            }

            using (var dbContext = new MissionskyOAEntities())
            {
                ValidWorkflowStep(dbContext, model);

                var oldStep = dbContext.WorkflowSteps.FirstOrDefault(it => it.Id == model.Id && it.FlowId == model.FlowId);
                if (oldStep == null)
                {
                    Log.Error(string.Format("找不到工作流步骤, Id: {0}", model.Id));
                    throw new InvalidOperationException(string.Format("找不到工作流步骤, Id: {0}", model.Id));
                }

                //更新工作流步骤
                if (oldStep.Name == null || !oldStep.Name.Equals(model.Name, StringComparison.InvariantCultureIgnoreCase))
                {
                    oldStep.Name = model.Name;
                }

                if (oldStep.Desc == null || !oldStep.Desc.Equals(model.Desc, StringComparison.InvariantCultureIgnoreCase))
                {
                    oldStep.Desc = model.Desc;
                }

                if (oldStep.Type != Convert.ToInt32(model.Type))
                {
                    oldStep.Type = (int)model.Type;
                }

                //更新审批条件
                if (model.Type == WorkflowStepType.LeaderApprove)
                {
                    if (oldStep.MinTimes - model.MinTimes >= 0.000000)
                    {
                        oldStep.MinTimes = model.MinTimes;
                    }

                    if (oldStep.MaxTimes - model.MaxTimes >= 0.000000)
                    {
                        oldStep.MaxTimes = model.MaxTimes;
                    }
                }

                if (oldStep.OperatorType != Convert.ToInt32(model.OperatorType))
                {
                    oldStep.OperatorType = (int)model.OperatorType;
                }

                if (oldStep.Operator != model.Operator)
                {
                    oldStep.Operator = model.Operator;
                }

                #region 审批用户变化,更新Order表
                if ((oldStep.OperatorType == (int)WorkflowOperator.Role && model.OperatorType == WorkflowOperator.User) || //角色审批变为用户审批
                    (model.OperatorType == WorkflowOperator.User &&
                     oldStep.OperatorType != Convert.ToInt32(model.OperatorType) && oldStep.Operator != model.Operator))   //用户审批,审批用户变化
                {
                    dbContext.Orders.Where(it => it.NextStep.HasValue && it.NextStep.Value == model.Id)
                    .ToList()
                    .ForEach(it => it.NextAudit = model.Operator);
                }
                #endregion

                UpdateNextStep(dbContext, model, false); //更新下一步

                //更新工作流
                dbContext.SaveChanges();

                return(true);
            }
        }
コード例 #19
0
        /// <summary>
        /// 更新假期信息
        /// </summary>
        /// <param name="dbContext">数据库上下文</param>
        /// <param name="order">申请单</param>
        /// <param name="workflow">申请单流程</param>
        /// <param name="nextStep">流程下一步</param>
        /// <param name="nextStatus">申请单状态</param>
        private void UpdateAttendanceSummary(MissionskyOAEntities dbContext, OrderModel order, WorkflowModel workflow,
                                             WorkflowStepModel nextStep, OrderStatus nextStatus)
        {
            var detail = order.OrderDets.FirstOrDefault(); //申请单详细

            if (detail == null || detail.IOHours == null || Math.Abs(detail.IOHours.Value) <= 0.0)
            {
                Log.Error("申请单无效");
                throw new InvalidOperationException("申请单无效。");
            }

            var curStep = order.NextStep == Constant.WORKFLOW_DIRECT_SUPERVISOR_APPROVE_NODE
                ? workflow.GetDirectSupervisorApproveStep()
                : workflow.WorkflowSteps.FirstOrDefault(it => it.Id == order.NextStep); //当前步骤

            var isUpdated = false;
            var times     = detail.IOHours.Value;

            //1, 拒绝
            if (nextStatus == OrderStatus.Rejected)
            {
                if (curStep != null && curStep.IsFinanceReviewing()) //当前是[财务审阅]: [行政审批]完成,已经更新了假期,需要[财务审阅]时,取消扣除的假期
                {
                    isUpdated = true;
                    times     = -times;
                }
            }
            //2, 流程结束(只能在没有财务审批节点才更新,避免重复更新(原始需求:完成行政审批就已经更新假期))
            else if (!workflow.NeedFinanceApprove() && nextStep == null)
            {
                isUpdated = true;
            }
            //3, 流程未结束, 转到[财务审阅](完成行政审批就更新)
            else if (nextStep != null && nextStep.IsFinanceReviewing())
            {
                isUpdated = true;
            }

            if (isUpdated)
            {
                order.OrderUsers.ToList().ForEach(user =>
                {
                    var summary = new UpdateAttendanceSummaryModel()
                    {
                        UserId      = user.Id,
                        SummaryYear = DateTime.Now.Year,
                        Times       = times,
                        Type        = order.OrderType
                    };

                    double beforeUpdated = 0.0;
                    double afterUpdated  = 0.0;
                    string auditMsg      = string.Empty;

                    this._attendanceSummaryService.UpdateAttendanceSummary(dbContext, summary, ref beforeUpdated,
                                                                           ref afterUpdated); //更新假期

                    #region 更新剩余结果

                    if (order.OrderType == OrderType.AnnualLeave)
                    {
                        auditMsg = string.Format("剩余年假: 申请前{0}小时,申请后{1}小时", beforeUpdated, afterUpdated);
                    }

                    else if (order.OrderType == OrderType.Overtime)
                    {
                        auditMsg = string.Format("累计加班: 申请前{0}小时,申请后{1}小时", beforeUpdated, afterUpdated);
                    }
                    else if (order.OrderType == OrderType.DaysOff)
                    {
                        auditMsg = string.Format("剩余调休: 申请前{0}小时,申请后{1}小时", beforeUpdated, afterUpdated);
                    }
                    else
                    {
                        auditMsg = string.Format("累计休假: 申请前{0}小时,申请后{1}小时", beforeUpdated, afterUpdated);
                    }

                    if (!string.IsNullOrEmpty(auditMsg))
                    {
                        detail.Audit = auditMsg;
                    }

                    #endregion
                });
            }
        }