Пример #1
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));
                }
            }
        }
Пример #2
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));
        }