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)); }
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)); }
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)); }
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)); } }