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