public static WorkTask ToEntity(this WorkTaskModel model)
        {
            if (model == null)
            {
                Log.Error("参数无效。");
                throw new InvalidOperationException("参数无效。");
            }

            var entity = new WorkTask()
            {
                Id           = model.Id,
                Outline      = model.Outline,
                Type         = (int)model.Type,
                Status       = (int)model.Status,
                Desc         = model.Desc,
                MeetingId    = model.MeetingId,
                ProjectId    = model.ProjectId,
                Sponsor      = model.Sponsor,
                Supervisor   = model.Supervisor,
                Executor     = model.Executor,
                Source       = (int)model.Source,
                Priority     = (int)model.Priority,
                Urgency      = (int)model.Urgency,
                Importance   = (int)model.Importance,
                Workload     = model.Workload,
                StartTime    = model.StartTime,
                EndTime      = model.EndTime,
                CompleteTime = model.CompleteTime,
                CloseTime    = model.CloseTime,
                CreatedTime  = model.CreatedTime
            };

            return(entity);
        }
Beispiel #2
0
        public IHttpActionResult Patch([FromODataUri] Guid key, Delta <WorkTaskModel> patch)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            WorkTaskModel workTaskModel = db.WorkTaskModels.Find(key);

            if (workTaskModel == null)
            {
                return(NotFound());
            }

            patch.Patch(workTaskModel);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WorkTaskModelExists(key))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Updated(workTaskModel));
        }
Beispiel #3
0
        // PUT odata/WorkTaskModels(5)
        public IHttpActionResult Put([FromODataUri] Guid key, WorkTaskModel workTaskModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (key != workTaskModel.Id)
            {
                return(BadRequest());
            }

            db.Entry(workTaskModel).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WorkTaskModelExists(key))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Updated(workTaskModel));
        }
 public static WorkTask ToDomain(this WorkTaskModel model)
 {
     if (model == null)
     {
         return(null);
     }
     return(new WorkTask(model.Owner, model.Id.ToString(), model.InstructionsCsv.FromCsvArray()));
 }
Beispiel #5
0
        // POST odata/WorkTaskModels
        public IHttpActionResult Post(WorkTaskModel workTaskModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.WorkTaskModels.Add(workTaskModel);
            db.SaveChanges();

            return(Created(workTaskModel));
        }
        public static WorkTaskModel ToModel(this WorkTask entity)
        {
            if (entity == null)
            {
                Log.Error("参数无效。");
                throw new InvalidOperationException("参数无效。");
            }

            var model = new WorkTaskModel()
            {
                Id           = entity.Id,
                Outline      = entity.Outline,
                Type         = (WorkTaskType)entity.Type,
                Status       = (WorkTaskStatus)entity.Status,
                Desc         = entity.Desc,
                MeetingId    = entity.MeetingId,
                ProjectId    = entity.ProjectId,
                Sponsor      = entity.Sponsor,
                Supervisor   = entity.Supervisor,
                Executor     = entity.Executor,
                Source       = (WorkTaskSource)entity.Source,
                Priority     = (WorkTaskPriority)entity.Priority,
                Urgency      = entity.Urgency.HasValue ? (WorkTaskUrgency)entity.Urgency.Value : WorkTaskUrgency.Low,
                Importance   = entity.Importance.HasValue ? (WorkTaskImportance)entity.Importance.Value : WorkTaskImportance.Low,
                Workload     = entity.Workload,
                StartTime    = entity.StartTime,
                EndTime      = entity.EndTime,
                CompleteTime = entity.CompleteTime,
                CloseTime    = entity.CloseTime,
                CreatedTime  = entity.CreatedTime
            };

            #region 生成任务处理列表
            model.Histories = new List <WorkTaskHistoryModel>();

            if (entity.WorkTaskHistories != null)
            {
                entity.WorkTaskHistories.ToList().ForEach(it => model.Histories.Add(it.ToModel()));
            }
            #endregion

            #region 生成评论列表
            model.Comments = new List <WorkTaskCommentModel>();

            if (entity.WorkTaskHistories != null)
            {
                entity.WorkTaskComments.ToList().ForEach(it => model.Comments.Add(it.ToModel()));
            }
            #endregion

            return(model);
        }
 /// <summary>
 ///     Serializes the given values into one task
 ///     Will not remove the existing tasks
 /// </summary>
 /// <param name="owner">>Name of the owning job/category that the batch should belong to</param>
 /// <param name="values"></param>
 public void WriteTasks(string owner, IList <string> values)
 {
     using (var connection = _database.GetOpenConnection())
     {
         var model = new WorkTaskModel
         {
             CheckedOut      = false,
             Owner           = owner,
             InstructionsCsv = values.ToCsvString()
         };
         connection.Insert(model);
     }
 }
Beispiel #8
0
        // DELETE odata/WorkTaskModels(5)
        public IHttpActionResult Delete([FromODataUri] Guid key)
        {
            WorkTaskModel workTaskModel = db.WorkTaskModels.Find(key);

            if (workTaskModel == null)
            {
                return(NotFound());
            }

            db.WorkTaskModels.Remove(workTaskModel);
            db.SaveChanges();

            return(StatusCode(HttpStatusCode.NoContent));
        }
        /// <summary>
        ///     Serializes the given values into tasks
        ///     Will delete any existing tasks
        /// </summary>
        /// <param name="owner">>Name of the owning job/category that the task should belong to</param>
        /// <param name="taskSize">number of values each task should contain</param>
        /// <param name="values"></param>
        /// <returns>Number of batch files created</returns>
        public int WriteTasks(string owner, int taskSize, IList <string> values)
        {
            DeleteAllTasks(owner);

            var numBatches = (values.Count / taskSize) + ((values.Count % taskSize) > 0 ? 1 : 0);

            using (var connection = _database.GetOpenConnection())
            {
                for (var factor = 0; factor < numBatches; factor++)
                {
                    var start       = factor * taskSize;
                    var numElements = (values.Count >= (start + taskSize)) ? (taskSize) : (values.Count - start);
                    var model       = new WorkTaskModel
                    {
                        CheckedOut      = false,
                        Owner           = owner,
                        InstructionsCsv = TakeSubArray(values, start, numElements).ToCsvString()
                    };
                    connection.Insert(model);
                }
            }
            return(numBatches);
        }
        public static WorkTaskModel ToModel(this NewWorkTaskModel model)
        {
            model.Valid(); //验证Task参数是否有效

            var task = new WorkTaskModel()
            {
                Outline     = model.Outline,
                Type        = model.Type,
                Status      = WorkTaskStatus.Started,
                Desc        = model.Desc,
                MeetingId   = model.MeetingId,
                ProjectId   = model.ProjectId,
                Sponsor     = model.Sponsor,
                Supervisor  = model.Supervisor,
                Executor    = model.Executor,
                Source      = model.Source ?? WorkTaskSource.Person,
                Priority    = model.Priority ?? WorkTaskPriority.Normal,
                EndTime     = model.EndTime.Value,
                StartTime   = model.StartTime.Value,
                CreatedTime = DateTime.Now
            };

            return(task);
        }
        /// <summary>
        /// 获取任务详细
        /// </summary>
        /// <param name="task">任务</param>
        /// <param name="isDetail">是否加载详细信息</param>
        /// <returns>图书</returns>
        public WorkTaskModel DoFill(WorkTaskModel task, bool isDetail = true)
        {
            if (task == null)
            {
                Log.Error("无效的工作任务。");
                throw new NullReferenceException("无效的工作任务。");
            }

            using (var dbContext = new MissionskyOAEntities())
            {
                //项目名
                if (task.ProjectId.HasValue)
                {
                    var project = dbContext.Projects.FirstOrDefault(it => it.Id == task.ProjectId.Value);
                    task.ProjectName = project == null ? string.Empty : project.Name;
                }

                //发起人姓名
                var sponsor = _userService.GetUserDetail(task.Sponsor);
                task.SponsorName = sponsor == null ? string.Empty : sponsor.EnglishName;

                //执行人
                if (task.Executor.HasValue)
                {
                    if (task.Executor.Value == task.Sponsor)
                    {
                        task.ExecutorName = task.SponsorName;
                    }
                    else
                    {
                        var executor = _userService.GetUserDetail(task.Executor.Value);
                        task.ExecutorName = executor == null ? string.Empty : executor.EnglishName;
                    }
                }

                //监督人
                if (task.Supervisor.HasValue)
                {
                    if (task.Supervisor.Value == task.Sponsor)
                    {
                        task.SupervisorName = task.SponsorName;
                    }
                    else
                    {
                        var supervisor = _userService.GetUserDetail(task.Supervisor.Value);
                        task.SupervisorName = supervisor == null ? string.Empty : supervisor.EnglishName;
                    }
                }

                //获取更多详细
                if (isDetail)
                {
                    //会议详细
                    task.Meeting = task.MeetingId.HasValue && task.MeetingId.Value > 0 ? _meetingService.GetMeetingDetailsById(task.MeetingId.Value) : null;

                    //工作任务评论
                    task.Comments = _workTaskCommentService.GetWorkTaskCommentList(task.Id);

                    //工作任务操作记录
                    task.Histories = _workTaskHistoryService.GetWorkTaskHistoryList(task.Id);

                    //附件
                    task.Attachments = _attachmentService.GetAttathcmentIds(dbContext, task.Id, Constant.ATTACHMENT_TYPE_WORK_TASK);
                }

                return(task);
            }
        }
        /// <summary>
        /// 工作流处理消息推送
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="task"></param>
        /// <param name="sender">推送消息发送人</param>
        /// <param name="extParam">扩展参数</param>
        /// <remarks>receiverId = 0: 表示默认发送到代申请人</remarks>
        public void AddNotification(MissionskyOAEntities dbContext, WorkTaskModel task, UserModel sender,
                                    object extParam = null)
        {
            //获取工作任务发起人
            var sponsor = dbContext.Users.FirstOrDefault(it => it.Id == task.Sponsor);

            if (sponsor == null)
            {
                Log.Error(string.Format("工作任务发起人无效, 发起人Id: {0}", task.Sponsor));
                throw new InvalidOperationException("工作任务发起人无效");
            }

            //获取工作任务监督人
            var supervisor = task.Sponsor == task.Supervisor
                ? sponsor
                : dbContext.Users.FirstOrDefault(it => it.Id == task.Supervisor);

            if (supervisor == null)
            {
                Log.Error(string.Format("工作任务监督人无效, 监督人Id: {0}", task.Supervisor));
                throw new InvalidOperationException("工作任务监督人无效");
            }

            //获取工作任务监督人
            var executor = task.Sponsor == task.Executor
                ? sponsor
                : dbContext.Users.FirstOrDefault(it => it.Id == task.Executor);

            if (executor == null)
            {
                Log.Error(string.Format("工作任务执行人无效, 执行人Id: {0}", task.Supervisor));
                throw new InvalidOperationException("工作任务执行人无效");
            }

            switch (task.Status)
            {
            case WorkTaskStatus.Created:     //新建
            //case WorkTaskStatus.Transfered: //转移(指派)
            //    //推送给执行人
            //    SendNotification(sender, executor.ToModel(),
            //        string.Format("{0}给指派了一个工作任务:{1}", sender.EnglishName, task.Outline));

            //    //推送给监督人
            //    if (supervisor != executor)
            //    {
            //        SendNotification(sender, supervisor.ToModel(),
            //            string.Format("{0}给{1}指派了一个工作任务:{2}", sender.EnglishName, executor.EnglishName, task.Outline));
            //    }
            //    break;
            case WorkTaskStatus.Started:     //开始
                //推送给发起人
                SendNotification(sender, sponsor.ToModel(),
                                 string.Format("{0}开始执行工作任务:{1}", executor.EnglishName, task.Outline));

                //推送给监督人
                if (supervisor != sponsor)
                {
                    SendNotification(sender, supervisor.ToModel(),
                                     string.Format("{0}开始执行工作任务:{1}", executor.EnglishName, task.Outline));
                }
                break;

            case WorkTaskStatus.Completed:     //完成
                //推送给发起人
                SendNotification(sender, sponsor.ToModel(),
                                 string.Format("{0}已完成工作任务:{1}", executor.EnglishName, task.Outline));

                //推送给监督人
                if (supervisor != sponsor)
                {
                    SendNotification(sender, supervisor.ToModel(),
                                     string.Format("{0}已完成工作任务:{1}", executor.EnglishName, task.Outline));
                }
                break;
            //case WorkTaskStatus.Canceled: //取消
            //    //推送给执行人
            //    SendNotification(sender, executor.ToModel(),
            //        string.Format("{0}取消任务: {1},原因:{2}", sender.EnglishName, task.Outline, extParam));

            //    //推送给监督人
            //    if (supervisor != sponsor)
            //    {
            //        SendNotification(sender, supervisor.ToModel(),
            //            string.Format("{0}取消任务: {1},原因:{2}", sender.EnglishName, task.Outline, extParam));
            //    }
            //    break;
            case WorkTaskStatus.Closed:     //关闭任务
                //推送给执行人
                SendNotification(sender, executor.ToModel(),
                                 string.Format("{0}取消任务: {1},原因:{2}", sender.EnglishName, task.Outline, extParam));

                //推送给监督人
                if (supervisor != sponsor)
                {
                    SendNotification(sender, supervisor.ToModel(),
                                     string.Format("{0}取消任务: {1},原因:{2}", sender.EnglishName, task.Outline, extParam));
                }
                break;
            }
        }