Пример #1
0
        public ApiResult <bool> SetOverdue(long sessionId, long taskId)
        {
            SelectSeatTask task = _selectSeatTaskRepository.Query(taskId);

            if (task == null)
            {
                return(new ApiResult <bool>(ResultStatus.FAIL, "任务不存在"));
            }

            if (task.SessionId != sessionId)
            {
                return(new ApiResult <bool>(ResultStatus.FAIL, "场次与任务不对应"));
            }

            task.Timedout();

            SelectSeatTask nextTask = _selectSeatTaskRepository.QueryNextTask(task);

            nextTask?.Begin();

            _transactionRepository.UseTransaction(IsolationLevel.ReadCommitted, () =>
            {
                if (nextTask != null && _selectSeatTaskRepository.Start(nextTask) <= 0)
                {
                    throw new Exception("保存时异常0");
                }

                if (_selectSeatTaskRepository.SetTimeout(task) <= 0)
                {
                    throw new Exception("保存时异常1");
                }
            });

            return(new ApiResult <bool>(ResultStatus.SUCCESS, true));
        }
Пример #2
0
        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));
        }
Пример #3
0
        public ApiResult <bool> Select(long sessionId, long wizardId, long taskId, string[] seatNos)
        {
            try
            {
                if (sessionId <= 0)
                {
                    return(new ApiResult <bool>(ResultStatus.FAIL, "sessionId必须大于0"));
                }

                if (wizardId <= 0)
                {
                    return(new ApiResult <bool>(ResultStatus.FAIL, "wizardId须大于0"));
                }

                if (taskId <= 0)
                {
                    return(new ApiResult <bool>(ResultStatus.FAIL, "taskId必须大于0"));
                }

                //if (session.Status != SessionStatus.进行中)
                //    return new ApiResult<bool>(ResultStatus.SUCCESS, "场次" + session.Status.GetName() + ",无法选座");

                Wizards wizard = _wizardRepository.Query(wizardId);
                if (wizard == null)
                {
                    return(new ApiResult <bool>(ResultStatus.FAIL, "巫师未注册"));
                }

                SelectSeatTask selectedTask = _selectSeatTaskRepository.Query(taskId);
                if (selectedTask == null)
                {
                    return(new ApiResult <bool>(ResultStatus.FAIL, "排队号不存在"));
                }

                if (selectedTask.Status != SelectTaskStatus.进行中)
                {
                    return(new ApiResult <bool>(ResultStatus.FAIL, "当前状态" + selectedTask.Status.GetName() + ",不能选座哦,请再等等或刷新!"));
                }

                if (selectedTask.WizardId != wizardId)
                {
                    return(new ApiResult <bool>(ResultStatus.FAIL, "请选择正确的任务"));
                }

                if (selectedTask.Total != seatNos.Length)
                {
                    return(new ApiResult <bool>(ResultStatus.FAIL, "选座数量必须为" + selectedTask.Total + "个"));
                }

                //IEnumerable<SelectSeatTask> tasks = _selectSeatTaskRepository.QueryByWizardId(sessionId, wizardId);
                //if (tasks.IsNullOrEmpty())
                //    return new ApiResult<bool>(ResultStatus.FAIL, "不在队列中");

                //SelectSeatTask canSelectTask = tasks.Where(x => x.Status == SelectTaskStatus.进行中).OrderBy(x => x.SerialNo).FirstOrDefault();
                //if (canSelectTask == null)
                //    return new ApiResult<bool>(ResultStatus.FAIL, "没有可选的名额了");

                //if (canSelectTask.Total != seatNos.Length)
                //    return new ApiResult<bool>(ResultStatus.FAIL, "选座数量必须为" + canSelectTask.Total);

                IEnumerable <Seat> seats = _seatRepository.Query(sessionId, seatNos);
                if (seats.Count() != seatNos.Length)
                {
                    return(new ApiResult <bool>(ResultStatus.FAIL, "seatNos传参错误"));
                }

                var selectedSeats = seats.Select(item =>
                {
                    item.Choose(wizard);
                    return(item);
                }).ToList();

                selectedTask.Select(seatNos);

                Session session = _sessionRepository.Query(sessionId);
                if (session == null)
                {
                    return(new ApiResult <bool>(ResultStatus.FAIL, "场次不存在"));
                }

                SelectSeatTask nextTask = null;
                if (session.Status == SessionStatus.进行中)
                {
                    nextTask = _selectSeatTaskRepository.QueryNextTask(selectedTask);
                    nextTask?.Begin();
                }

                _transactionRepository.UseTransaction(IsolationLevel.ReadUncommitted, () =>
                {
                    if (_seatRepository.BatchUpdate(selectedSeats.ToArray()) < 0)
                    {
                        throw new DomainException("保存时异常0");
                    }

                    if (_selectSeatTaskRepository.Select(selectedTask) < 0)
                    {
                        throw new DomainException("保存时异常1");
                    }

                    if (nextTask != null && _selectSeatTaskRepository.Start(nextTask) < 0)
                    {
                        throw new DomainException("保存时异常2");
                    }
                });

                return(new ApiResult <bool>(ResultStatus.SUCCESS, true));
            }
            catch (Exception ex)
            {
                _logger.LogError("选择座位异常", ex);
                return(new ApiResult <bool>(ResultStatus.EXCEPTION, ex.Message));
            }
        }