/// <summary>読み込み・検証・一時データ登録処理</summary>
        /// <param name="source"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public async Task <ImportDataResult> ReadAsync(TransactionImportSource source, CancellationToken token = default(CancellationToken))
        {
            var encoding = Encoding.GetEncoding(source.EncodingCodePage);
            var csv      = encoding.GetString(source.Data);

            var companyTask = companyProcessor.GetAsync(new CompanySearch {
                Id = source.CompanyId,
            }, token);
            var appConTask = applicationControlProcessor.GetAsync(source.CompanyId, token);

            await Task.WhenAll(companyTask, appConTask);

            var company            = companyTask.Result.First();
            var applicationControl = appConTask.Result;

            var importer = new BillingImporterBase(applicationControl)
            {
                CompanyId         = source.CompanyId,
                CompanyCode       = company.Code,
                LoginUserId       = source.LoginUserId,
                ImporterSettingId = source.ImporterSettingId,
                FilePath          = csv,
                CsvParser         = new CsvParser {
                    Encoding      = encoding,
                    StreamCreator = new PlainTextMemoryStreamCreator(),
                },
                GetImporterSettingAsync       = settingId => GetImporterSettingAsync(settingId, token),
                GetImporterSettingDetailAsync = settingId => GetImporterSettingDetailsAsync(settingId, token),
                GetCurrencyAsync = companyId => GetCurrenciesAsync(companyId, token),
                GetJuridicalParsonalitiesAsync = companyId => GetJuridicalParsonalitiesAsync(companyId, token),
                GetGeneralSettingValueAsync    = (companyId, code) => GetGeneralSettingValueAsync(companyId, code, token),
                GetTaxClassAsync = () => GetTaxClassesAsync(token),
                GetBillingDivisionContractByCustomerIdsAsync = ids => GetBillingDivisionsByCustomerIdsAsync(ids, token),
                GetHolidayCalendarsAsync           = companyId => GetHolidayCalendarsAsync(companyId, token),
                LoadColumnNameSettingsInnerAsync   = tableName => GetColumnNamesAsync(source.CompanyId, tableName, token),
                BillingImportDuplicationCheckAsync = (companyId, items, details) => GetDuplicationRows(companyId, items, details, token),
                GetCustomerByCodesAsync            = (companyId, codes) => GetCustomersAsync(companyId, codes, token),
                GetDepartmentByCodesAsync          = (companyId, codes) => GetDepartmntsAdync(companyId, codes, token),
                GetAccountTitleByCodesAsync        = (companyId, codes) => GetAccountTitlesAsync(companyId, codes, token),
                GetStaffByCodesAsync       = (companyId, codes) => GetStaffsAsync(companyId, codes, token),
                GetCategoriesByCodesAsync  = (companyId, categoryType, codes) => GetCategoriesAsync(companyId, categoryType, codes, token),
                GetIsEnableToEditNoteAsync = companyId => GetIsEnableToEditNoteAsync(companyId, token),

                Serialize           = item => serializer.PackSingleObject(item),
                SaveImportDataAsync = data => importDataProcessor.SaveAsync(data, token),
            };
            var readResult = await importer.ReadCsvAsync();

            return(new ImportDataResult {
                ImportData = importer.ImportData,
                ReadCount = importer.ReadCount,
                ValidCount = importer.ValidCount,
                InvalidCount = importer.InvalidCount,
                NewCustomerCreationCount = importer.NewCustomerCreationCount,
                Logs = importer.GetValidationLogs(),
            });
        }
示例#2
0
        /// <summary>読込・検証処理</summary>
        /// <param name="source"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public async Task <ImportDataResult> ReadAsync(TransactionImportSource source, CancellationToken token = default(CancellationToken))
        {
            var encoding = Encoding.GetEncoding(source.EncodingCodePage);
            var csv      = encoding.GetString(source.Data);

            var companyTask = GetCompanyAsync(source.CompanyId, token);
            var appConTask  = GetApplicationControlAsync(source.CompanyId, token);

            await Task.WhenAll(companyTask, appConTask);

            var company            = companyTask.Result;
            var applicationControl = appConTask.Result;

            var importer = new PaymentScheduleImporterBase(applicationControl)
            {
                CompanyId         = source.CompanyId,
                CompanyCode       = company.Code,
                LoginUserId       = source.LoginUserId,
                ImporterSettingId = source.ImporterSettingId,
                FilePath          = csv,
                CsvParser         = new CsvParser {
                    Encoding      = encoding,
                    StreamCreator = new PlainTextMemoryStreamCreator(),
                },
                DoTargetNotMatchedData    = source.DoTargetNotMatchedData,
                DoReplaceAmount           = source.DoReplaceAmount,
                DoIgnoreSameCustomerGroup = source.DoIgnoreSameCustomerGroup,

                GetImporterSettingAsync                = settingId => GetImporterSettingAsync(settingId, token),
                GetImporterSettingDetailByIdAsync      = settingId => GetImporterSettingDetailsAsync(settingId, token),
                GetItemsForScheduledPaymentImportAsync = (companyId, items, details) => GetBillingsAsync(companyId, items, details, token),
                GetGeneralSettingValueAsync            = (companyId, code) => GetGeneranSettingValueAsync(companyId, code, token),
                GetCustomerByCodesAsync                = (companyId, codes) => GetCustomersAsync(companyId, codes, token),
                GetDepartmentByCodesAsync              = (companyId, codes) => GetDepartmentsAsync(companyId, codes, token),
                GetAccountTitleByCodesAsync            = (companyId, codes) => GetAccountTitlesAsync(companyId, codes, token),
                GetCategoriesByCodesAsync              = (companyId, categoryType, codes) => GetCategoriesAsync(companyId, categoryType, codes, token),
                GetCurrenciesAsync = (companyId, codes) => GetCurrenciesAsync(companyId, codes, token),

                SerializeScheduledPaymentImport = item => serializerScheduledPaymentImport.PackSingleObject(item),
                SerializePaymentSchedule        = item => serializerPaymentSchedule.PackSingleObject(item),
                SaveImportDataAsync             = data => importDataProcessor.SaveAsync(data, token),
            };

            var readResult = importer.ReadCsvAsync();

            return(new ImportDataResult {
                ImportData = importer.ImportData,
                ReadCount = importer.ReadCount,
                ValidCount = importer.ValidCount,
                InvalidCount = importer.InvalidCount,
                Logs = importer.GetValidationLogs(),
            });
        }
示例#3
0
        /// <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);
        }
        /// <summary>読み込み・検証・一時データ登録処理</summary>
        /// <param name="source"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public async Task <ImportDataResult> ReadAsync(TransactionImportSource source, CancellationToken token = default(CancellationToken))
        {
            var encoding = Encoding.GetEncoding(source.EncodingCodePage);
            var csv      = encoding.GetString(source.Data);

            var companyTask = companyProcessor.GetAsync(new CompanySearch {
                Id = source.CompanyId,
            }, token);
            var appConTask = applicationControlProcessor.GetAsync(source.CompanyId, token);

            await Task.WhenAll(companyTask, appConTask);

            var company            = companyTask.Result.First();
            var applicationControl = appConTask.Result;

            var importer = new ReceiptImporterBase(applicationControl)
            {
                CompanyId         = source.CompanyId,
                CompanyCode       = company.Code,
                LoginUserId       = source.LoginUserId,
                ImporterSettingId = source.ImporterSettingId,
                FilePath          = csv,
                CsvParser         = new CsvParser {
                    Encoding      = encoding,
                    StreamCreator = new PlainTextMemoryStreamCreator(),
                },
                GetImporterSettingAsync            = async settingId => (await importerSettingProcessor.GetAsync(new ImporterSetting {
                    Id = settingId
                }, token)).FirstOrDefault(),
                GetImporterSettingDetailByIdAsync  = async settingId => (await importerSettingDetailProcessor.GetAsync(new ImporterSetting {
                    Id = settingId
                }, token)).ToList(),
                GetGeneralSettingValueAsync        = async(companyId, code) => (await generalSettingProcessor.GetAsync(new GeneralSetting {
                    CompanyId = companyId, Code = code,
                }, token)).FirstOrDefault()?.Value,
                ReceiptImportDuplicationCheckAsync = async(companyid, items, details) => (await receiptProcessor.ReceiptImportDuplicationCheckAsync(companyid, items, details, token)).ToArray(),

                GetCurrenciesAsync               = async(companyId, codes) => (await currencyProcessor.GetAsync(new CurrencySearch {
                    CompanyId = companyId, Codes = codes,
                }, token)).ToList(),
                GetCategoriesByCodesAsync        = async(companyId, categoryType, codes) => (await categoryProcessor.GetAsync(new CategorySearch {
                    CompanyId = companyId, CategoryType = categoryType, Codes = codes,
                }, token)).ToList(),
                GetSectionByCodesAsync           = async(companyId, codes) => (await sectionProcessor.GetAsync(new SectionSearch {
                    CompanyId = companyId, Codes = codes,
                }, token)).ToList(),
                GetCustomerByCodesAsync          = async(companyId, codes) => (await customerProcessor.GetAsync(new CustomerSearch {
                    CompanyId = companyId, Codes = codes,
                }, token)).ToList(),
                GetLegalPersonaritiesAsync       = async(companyId) => (await juridicalPersonalityProcessor.GetAsync(new JuridicalPersonality {
                    CompanyId = companyId,
                }, token)).Select(x => x.Kana).ToArray(),
                GetCollationSettingAsync         = companyId => collationSettingProcessor.GetAsync(companyId, token),
                LoadColumnNameSettingsInnerAsync = async tableName => (await columnNameSettingProcessor.GetAsync(new ColumnNameSetting {
                    CompanyId = source.CompanyId, TableName = tableName,
                }, token)).ToArray(),

                Serialize           = item => serializer.PackSingleObject(item),
                SaveImportDataAsync = data => importDataProcessor.SaveAsync(data, token),
            };

            var readResult = await importer.ReadCsvAsync();

            return(new ImportDataResult {
                ImportData = importer.ImportData,
                ReadCount = importer.ReadCount,
                ValidCount = importer.ValidCount,
                InvalidCount = importer.InvalidCount,
                Logs = importer.GetValidationLogs(),
            });
        }