/// <summary>登録処理</summary> public async Task <AccountTransferImportResult> ImportAsync(AccountTransferImportSource source, CancellationToken token = default(CancellationToken)) { var importDataId = source.ImportDataId ?? 0; var data = await importDataProcessor.GetAsync(importDataId, token : token); var agency = (await paymentAgencyGetByIdsQueryProcessor.GetByIdsAsync(new[] { source.PaymentAgencyId }, token)).First(); var sources = data.Details.Select(x => serializer.UnpackSingleObject(x.RecordItem)).ToArray(); var items = sources.Select(x => new AccountTransferImportData { BillingIdList = x.Billings.Select(y => y.Id).ToArray(), CustomerIds = x.Billings.Select(y => y.CustomerId).ToArray(), ResultCode = x.TransferResultCode, DoUpdateAccountTransferLogId = !x.IgnoreInitialization, DueDate = x.NewDueAt, UpdateBy = source.LoginUserId, DueDateOffset = agency.DueDateOffset, CollectCategoryId = source.NewCollectCategoryId, }).ToArray(); var importResult = await billingAccountTransferProcessor.ImportAsync(items, token); return(new AccountTransferImportResult { ProcessResult = new ProcessResult { Result = true }, }); }
public async Task <byte[]> GetAsync(AccountTransferImportSource source, CancellationToken token = default(CancellationToken)) { var importDataId = source.ImportDataId ?? 0; var importDataTask = importDataProcessor.GetAsync(importDataId, token: token); var companyTask = companyGetByIdsQueryProcessor.GetByIdsAsync(new[] { source.CompanyId }, token); await Task.WhenAll(importDataTask, companyTask); var importData = importDataTask.Result; var company = companyTask.Result.First(); var sources = importData.Details.Select(x => serializer.UnpackSingleObject(x.RecordItem)).ToArray(); var reportSource = sources.Select(x => new AccountTransferImportReport.ReportRow { Billing = x.Billings?.Single(b => b.Id == x.Billings.Min(y => y.Id)), TransferResultCode = x.TransferResultCode, TransferAmount = x.TransferAmount, TransferBankName = x.TransferBankName, TransferBranchName = x.TransferBranchName, TransferCustomerCode = x.TransferCustomerCode, TransferAccountName = x.TransferAccountName, }).ToArray(); if (!(reportSource?.Any() ?? false)) { return(null); } var report = new AccountTransferImportReport() { Name = $"口座振替結果データ一覧_{DateTime.Now:yyyyMMdd_HHmmss}" }; // 帳票生成 report.SetBasicPageSetting(company.Code, company.Name); report.SetData(reportSource); report.Run(); return(report.Convert()); }
/// <summary>取込処理</summary> public async Task <AccountTransferImportResult> ReadAsync(AccountTransferImportSource source, CancellationToken token = default(CancellationToken)) { var encoding = Encoding.GetEncoding(source.EncodingCodePage); var csv = encoding.GetString(source.Data); var companyTask = companyGetByIdQueryProcessor.GetByIdsAsync(new[] { source.CompanyId }, token); var currencyTask = currencyQueryProcessor.GetAsync(new CurrencySearch { CompanyId = source.CompanyId, Codes = new[] { DefaultCurrencyCode }, }, token); var agencyTask = paymentAgencyGetByIdsQueryProcessor.GetByIdsAsync(new[] { source.PaymentAgencyId }, token); await Task.WhenAll(companyTask, currencyTask, agencyTask); var company = companyTask.Result.First(); var currency = currencyTask.Result.First(); var agency = agencyTask.Result.First(); var helper = new Helper { GetBillingsAsync = async(companyId, paymentAgencyId, dueAt) => (await billingQueryProcessor.GetAccountTransferMatchingTargetListAsync(paymentAgencyId, dueAt, currency.Id)).ToList(), GetCustomersAsync = async(ids) => (await customerQueryProcessor.GetAsync(new CustomerSearch { Ids = ids, }, token)).ToDictionary(x => x.Id), }; var reader = helper.CreateReader((AccountTransferFileFormatId)agency.FileFormatId); reader.CompanyId = company.Id; reader.AggregateBillings = company.TransferAggregate == 1; reader.PaymentAgencyId = agency.Id; reader.TransferYear = source.TransferYear; reader.Encoding = encoding; reader.FileName = source.FileName; reader.IsAsync = true; reader.IsPlainText = true; var sources = await reader.ReadAsync(csv); var data = new ImportData { CompanyId = source.CompanyId, FileName = source.FileName, FileSize = encoding.GetByteCount(csv), CreateBy = source.LoginUserId, }; data.Details = sources.Select(x => new ImportDataDetail { ObjectType = 0, RecordItem = serializer.PackSingleObject(x), }).ToArray(); var dataSaved = await importDataProcessor.SaveAsync(data, token); var result = new AccountTransferImportResult { ImportData = dataSaved, ProcessResult = new ProcessResult { Result = true }, }; for (var i = 0; i < sources.Count; i++) { result.ReadCount++; if (sources[i].TransferResultCode == 0) { result.ValidCount++; result.ValidAmount += sources[i].TransferAmount; } else { result.InvalidCount++; result.InvalidAmount += sources[i].TransferAmount; } } result.InvalidSources = sources.Where(x => x.TransferResultCode != 0 || !(x.Billings?.Any() ?? false)).ToList(); result.Logs = sources.SelectMany(x => x.GetInvalidLogs()).ToList(); return(result); }
public async Task <ActionResult <AccountTransferImportResult> > Import(AccountTransferImportSource source, CancellationToken token) => await billingAccountTransferFileImportProcessor.ImportAsync(source, token);