Esempio n. 1
0
        public ApiResult <bool> Create(CreateActivityReqs request)
        {
            try
            {
                Divisions division = _divisionRepository.Query(request.DivisionId);
                if (division == null)
                {
                    return(new ApiResult <bool>(ResultStatus.FAIL, "找不到分部"));
                }

                long id       = NewId.GenerateId();
                var  activity = new Activity(id, request.DivisionId, request.Name, request.Summary, request.Thumbnail, request.Description, request.Address,
                                             request.BeginTime, request.FinishTime, request.RegistrationBeginTime, request.RegistrationFinishTime,
                                             request.Price, request.People, request.CreatorId);

                if (_activityRepository.Insert(activity) <= 0)
                {
                    return(new ApiResult <bool>(ResultStatus.FAIL, "保存时出现问题,请稍后再试"));
                }

                return(new ApiResult <bool>(ResultStatus.SUCCESS, true));
            }
            catch (Exception ex)
            {
                _logger.LogError("创建活动异常", ex);
                return(new ApiResult <bool>(ResultStatus.EXCEPTION, ex.Message));
            }
        }
Esempio n. 2
0
        public ApiResult <bool> CreateDivision(CreateDivisionReqs request)
        {
            if (_divisionRepository.QueryByCityId(request.CityId) != null)
            {
                return(new ApiResult <bool>(ResultStatus.FAIL, "该城市分部已创建"));
            }

            Wizards wizard = _wizardRepository.Query(request.CreatorId);

            if (wizard == null)
            {
                return(new ApiResult <bool>(ResultStatus.FAIL, "你是谁"));
            }

            long divisionId = NewId.GenerateId();

            var division = new Divisions(divisionId, request.CityId, request.Name, request.CreatorId);

            if (_divisionRepository.Insert(division) <= 0)
            {
                return(new ApiResult <bool>(ResultStatus.FAIL, "保存时出错,请稍后再试"));
            }

            return(new ApiResult <bool>(ResultStatus.SUCCESS, true));
        }
Esempio n. 3
0
        public ApiResult <bool> ImportApplicantsFromWeidian(ImportApplicantReqs request)
        {
            Activity activity = _activityRepository.Query(request.ActivityId);

            if (activity == null)
            {
                return(new ApiResult <bool>(ResultStatus.FAIL, "活动不存在"));
            }

            var wizards    = new List <Wizards>();
            var applicants = new List <Applicant>();

            IEnumerable <Wizards>   wizardList    = _wizardRepository.Query(request.Data.Select(x => x.Mobile).ToArray());
            IEnumerable <Applicant> applicantList = _applicantRepository.QueryByActivityId(request.ActivityId);

            request.Data.Where(x => !x.OrderNo.IsNullOrEmpty()).OrderBy(x => x.CreateTime).ForEach(item =>
            {
                Wizards wizard = wizardList.FirstOrDefault(w => w.Account == item.Mobile) ?? wizards.FirstOrDefault(w => w.Account == item.Mobile);
                if (wizard == null)
                {
                    long wizardId = NewId.GenerateId();
                    wizard        = new Wizards(wizardId, item.Mobile, null, item.Mobile.Substring(5, 6));
                    wizard.ChangeInfo(item.WechatName, null, item.Mobile, 0, DateTime.Now, null, 0);
                    wizards.Add(wizard);
                }

                Applicant applicant = applicantList.FirstOrDefault(x => x.ExtOrderNo == item.OrderNo);
                if (applicant == null)
                {
                    applicant = new Applicant(NewId.GenerateId(), wizard.WizardId, activity, item.RealName,
                                              item.WechatName, item.Mobile, item.Count, item.OrderNo, item.CreateTime);
                    applicant.Pay();
                    applicants.Add(applicant);
                }
            });

            _transactionRepository.UseTransaction(IsolationLevel.ReadCommitted, () =>
            {
                if (wizards.Any())
                {
                    _wizardRepository.BatchCreate(wizards);

                    _wizardProfileRepository.BatchInsert(wizards.Select(x => x.Profile));
                }
                if (applicants.Any())
                {
                    _applicantRepository.BatchInsert(applicants);
                }
            });

            return(new ApiResult <bool>(ResultStatus.SUCCESS, true));
        }
Esempio n. 4
0
        public ApiResult <bool> Change(UpdateSessionReqs request)
        {
            try
            {
                Session session = _sessionRepository.Query(request.SessionId);
                if (session == null)
                {
                    return(new ApiResult <bool>(ResultStatus.FAIL, "找不到这个场次了"));
                }

                Activity activity = _activityRepository.Query(request.ActivityId);
                if (activity == null)
                {
                    return(new ApiResult <bool>(ResultStatus.FAIL, "找不到所选的活动"));
                }

                if (activity.Status != Domain.Activity.EnumTypes.ActivityStatus.未启动)
                {
                    return(new ApiResult <bool>(ResultStatus.FAIL, "活动已启动,无法再修改了!"));
                }

                session.Change(activity.DivisionId, activity.ActivityId, request.CinemaId, request.HallId, request.Seats.Select(x => x.SeatNo).ToArray());

                Seat[] seats = request.Seats.Select(seatInfo =>
                {
                    long seatId       = NewId.GenerateId();
                    string[] position = { seatInfo.RowId, seatInfo.ColumnId };
                    return(new Seat(seatId, session.SessionId, activity.ActivityId, seatInfo.SeatNo, position));
                }).ToArray();

                _transactionRepository.UseTransaction(IsolationLevel.ReadUncommitted, () =>
                {
                    _seatRepository.ClearInSession(session.SessionId);
                    _seatRepository.BatchInsert(seats);
                    if (_sessionRepository.Update(session) <= 0)
                    {
                        throw new DomainException("保存时异常,请稍后再试");
                    }
                });

                return(new ApiResult <bool>(ResultStatus.SUCCESS, true));
            }
            catch (Exception ex)
            {
                _logger.LogError("更新场次时异常", ex);
                return(new ApiResult <bool>(ResultStatus.EXCEPTION, ex.Message));
            }
        }
Esempio n. 5
0
        public ApiResult <bool> Register(RegisterWizardReqs request)
        {
            try
            {
                if (_wizardQueryService.Query(request.Account) != null)
                {
                    return(new ApiResult <bool>(ResultStatus.FAIL, "用户名已存在"));
                }

                if (_wizardQueryService.QueryByEmail(request.Email) != null)
                {
                    return(new ApiResult <bool>(ResultStatus.FAIL, "邮箱已被注册"));
                }

                long wizardId = NewId.GenerateId();

                var wizard = new Wizards(wizardId, request.Account, request.Email, request.Passward);

                _transactionRepository.UseTransaction(IsolationLevel.ReadUncommitted, () =>
                {
                    if (_wizardRepository.Create(wizard) <= 0)
                    {
                        throw new Exception("保存时发生异常,请稍后再试(1)");
                    }

                    if (_wizardPRofileRepository.Insert(wizard.Profile) <= 0)
                    {
                        throw new Exception("保存时发生异常,请稍后再试(2)");
                    }
                });

                return(new ApiResult <bool>(ResultStatus.SUCCESS, true));
            }
            catch (Exception ex)
            {
                LoggerExtensions.LogError(_logger, "注册时异常", ex);
                return(new ApiResult <bool>(ResultStatus.EXCEPTION, ex.Message));
            }
        }
Esempio n. 6
0
        public ApiResult <bool> CreateWizard(CreateWizardReqs request)
        {
            if (string.IsNullOrEmpty(request.Account))
            {
                return(new ApiResult <bool>(ResultStatus.FAIL, "巫师名未提交"));
            }

            if (_wizardRepository.Query(request.Account) != null)
            {
                return(new ApiResult <bool>(ResultStatus.FAIL, "巫师名重复了"));
            }

            long wizardId = NewId.GenerateId();
            var  wizard   = new Wizards(wizardId, request.Account, request.Passward, request.DivisionId, request.CreatorId);

            if (_wizardRepository.Create(wizard) <= 0)
            {
                return(new ApiResult <bool>(ResultStatus.FAIL, "保存时异常,请稍后再试"));
            }

            return(new ApiResult <bool>(ResultStatus.SUCCESS, true));
        }
Esempio n. 7
0
        public ApiResult <bool> BeginSelectSeat(long sessionId)
        {
            lock (s_begin_locker)
            {
                try
                {
                    Session session = _sessionRepository.Query(sessionId);
                    if (session == null)
                    {
                        return(new ApiResult <bool>(ResultStatus.FAIL, "所选场次不存在"));
                    }

                    Activity activity = _activityRepository.Query(session.ActivityId);
                    if (activity == null)
                    {
                        return(new ApiResult <bool>(ResultStatus.FAIL, "所选场次对应活动不存在"));
                    }

                    if (activity.Status != Domain.Activity.EnumTypes.ActivityStatus.报名结束)
                    {
                        return(new ApiResult <bool>(ResultStatus.FAIL, $"活动{activity.Status.GetName()}"));
                    }

                    IEnumerable <Applicant> applicants = _applicantRepository.QueryByActivityId(activity.ActivityId);

                    if (applicants.IsNullOrEmpty())
                    {
                        return(new ApiResult <bool>(ResultStatus.FAIL, "没人报名哦"));
                    }

                    session.Start();
                    SelectSeatTask[] tasks = applicants.OrderBy(x => x.ApplyTime).Select((x, i) => new SelectSeatTask(NewId.GenerateId(), session.SessionId, x, i + 1)).ToArray();
                    // tasks[0].CheckIn();

                    _transactionRepository.UseTransaction(IsolationLevel.ReadUncommitted, () =>
                    {
                        _selectSeatTaskRepository.BatchInsert(tasks);

                        if (_sessionRepository.Update(session) <= 0)
                        {
                            throw new Exception("保存时异常");
                        }
                    });

                    return(new ApiResult <bool>(ResultStatus.SUCCESS, true));
                }
                catch (Exception ex)
                {
                    _logger.LogError("场次开始选座时异常", ex);
                    return(new ApiResult <bool>(ResultStatus.EXCEPTION, ex.Message));
                }
            }
        }
Esempio n. 8
0
        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));
        }