public ApiResult <bool> Enqueue(long sessionId) { if (sessionId <= 0) { return(new ApiResult <bool>(ResultStatus.FAIL, "请选择正确的场次")); } Session session = _sessionRepository.Query(sessionId); if (session == null) { return(new ApiResult <bool>(ResultStatus.FAIL, "场次不存在")); } IEnumerable <SelectSeatTask> tasks = _selectSeatTaskRepository.Query(sessionId, Domain.Cinema.EnumTypes.SelectTaskStatus.未排队); if (tasks.IsNullOrEmpty()) { return(new ApiResult <bool>(ResultStatus.FAIL, "没有为排队的任务")); } foreach (SelectSeatTask task in tasks) { task.CheckIn(); } _selectSeatTaskRepository.CheckIn(tasks); return(new ApiResult <bool>(ResultStatus.SUCCESS, true)); }
public ApiResult <bool> CheckIn(long wizardId, long sessionId) { Session session = _sessionRepository.Query(sessionId); if (session == null) { return(new ApiResult <bool>(ResultStatus.SUCCESS, "场次不存在")); } if (session.Status != SessionStatus.进行中) { return(new ApiResult <bool>(ResultStatus.FAIL, "场次" + session.Status.GetName())); } IEnumerable <SelectSeatTask> tasks = _selectSeatTaskRepository.QueryByWizardId(sessionId, wizardId); if (tasks.IsNullOrEmpty()) { return(new ApiResult <bool>(ResultStatus.FAIL, "你不在排队中,请联系管理员")); } IEnumerable <SelectSeatTask> notInQueueTasks = tasks.Where(x => x.Status == SelectTaskStatus.未排队); IEnumerable <SelectSeatTask> overdueTasks = tasks.Where(x => x.Status == SelectTaskStatus.超时未重排); //if (notInQueueTasks.IsNullOrEmpty() && overdueTasks.IsNullOrEmpty()) // return new ApiResult<bool>(ResultStatus.FAIL, wipTask == null ? "全部都选完了" : "已经可以选了"); //如果有未排队 if (notInQueueTasks.Any()) { var checkedInTasks = notInQueueTasks.Select(task => { task.CheckIn(); return(task); }).ToList(); _selectSeatTaskRepository.CheckIn(checkedInTasks); } SelectSeatTask current = _selectSeatTaskRepository.QueryCurrent(sessionId) ?? _selectSeatTaskRepository.QuerySessionNextTask(sessionId); //有超时的任务,重新插入并排队 if (overdueTasks.Any()) { IEnumerable <SelectSeatTask> newTasks = overdueTasks.Select(x => { var newTask = new SelectSeatTask(NewId.GenerateId(), x, (current ?? x).SerialNo); newTask.CheckIn(); return(newTask); }).ToList(); IEnumerable <SelectSeatTask> oldTasks = overdueTasks.Select(x => { x.CheckInAgain(); return(x); }).ToList(); _selectSeatTaskRepository.BatchInsert(newTasks); _selectSeatTaskRepository.CheckInAgain(oldTasks); } if (current == null) { SelectSeatTask task = _selectSeatTaskRepository.QuerySessionNextTask(sessionId); task?.Begin(); if (task != null) { _selectSeatTaskRepository.Start(task); } } else if (current.WizardId == wizardId && current.Status != SelectTaskStatus.进行中) { current.Begin(); _selectSeatTaskRepository.Start(current); } return(new ApiResult <bool>(ResultStatus.SUCCESS, true)); }