Exemplo n.º 1
0
        /// <summary>
        /// インポート処理
        /// </summary>
        /// <param name="source"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public async Task <ImportResult> ImportAsync(MasterImportSource source, CancellationToken token = default(CancellationToken))
        {
            var mode     = (ImportMethod)source.ImportMethod;
            var encoding = Encoding.GetEncoding(source.EncodingCodePage);
            var csv      = encoding.GetString(source.Data);

            var companyTask = companyProcessor.GetAsync(new CompanySearch {
                Id = source.CompanyId,
            }, token);
            var loginUserTask = loginUserProcessor.GetAsync(new LoginUserSearch {
                Ids = new[] { source.LoginUserId },
            }, token);
            var appConTask   = applicationControlProcessor.GetAsync(source.CompanyId, token);
            var categoryTask = categoryProcessor.GetAsync(new CategorySearch {
                CompanyId = source.CompanyId, CategoryType = Rac.VOne.Common.CategoryType.Receipt,
            }, token);
            var sectionTask = sectionProcessor.GetAsync(new SectionSearch {
                CompanyId = source.CompanyId,
            }, token);

            await Task.WhenAll(companyTask, loginUserTask, appConTask, categoryTask, sectionTask);

            var company            = companyTask.Result.First();
            var loginUser          = loginUserTask.Result.First();
            var appCon             = appConTask.Result;
            var categoryDictionary = categoryTask.Result.ToDictionary(x => x.Code);
            var sectionDictionary  = sectionTask.Result.ToDictionary(x => x.Code);

            var definition = new BankAccountFileDefinition(new DataExpression(appCon));
            var parser     = new CsvParser {
                Encoding      = encoding,
                StreamCreator = new PlainTextMemoryStreamCreator(),
            };

            definition.CategoryIdField.GetModelsByCode = val => categoryDictionary;
            definition.SectionIdField.Ignored          = appCon.UseReceiptSection == 0;
            definition.SectionIdField.GetModelsByCode  = val => sectionDictionary;

            var importer = definition.CreateImporter(x => new {
                x.BankCode,
                x.BranchCode,
                x.AccountTypeId,
                x.AccountNumber,
            }, parser);

            importer.UserId      = source.LoginUserId;
            importer.UserCode    = loginUser.Code;
            importer.CompanyId   = source.CompanyId;
            importer.CompanyCode = company.Code;
            importer.LoadAsync   = () => bankAccountProcessor.GetAsync(new BankAccountSearch {
                CompanyId = source.CompanyId,
            }, token);
            importer.RegisterAsync = x => bankAccountProcessor.ImportAsync(x.New, x.Dirty, x.Removed, token);

            var result = await importer.ImportAsync(csv, mode, token, null);

            result.Logs = importer.GetErrorLogs();

            return(result);
        }
Exemplo n.º 2
0
 public async Task <CategoriesResult> GetAsync(string SessionKey, int[] Id)
 {
     return(await authorizationProcessor.DoAuthorizeAsync(SessionKey, async token =>
     {
         var result = (await categoryProcessor.GetAsync(new CategorySearch {
             Ids = Id
         }, token)).ToList();
         return new CategoriesResult
         {
             ProcessResult = new ProcessResult {
                 Result = true
             },
             Categories = result,
         };
     }, logger));
 }
        /// <summary>インポート処理</summary>
        /// <param name="source"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public async Task <ImportResult> ImportAsync(MasterImportSource source, CancellationToken token = default(CancellationToken))
        {
            var mode     = (ImportMethod)source.ImportMethod;
            var encoding = Encoding.GetEncoding(source.EncodingCodePage);
            var csv      = encoding.GetString(source.Data);

            var companyTask = companyProcessor.GetAsync(new CompanySearch {
                Id = source.CompanyId,
            }, token);
            var loginUserTask = loginUserProcessor.GetAsync(new LoginUserSearch {
                Ids = new[] { source.LoginUserId },
            }, token);
            var appConTask   = applicationControlProcessor.GetAsync(source.CompanyId, token);
            var categoryTask = categoryProcessor.GetAsync(new CategorySearch {
                CompanyId = source.CompanyId, CategoryType = CategoryType.Exclude,
            }, token);

            await Task.WhenAll(companyTask, loginUserTask, appConTask, categoryTask);

            var company            = companyTask.Result.First();
            var loginUser          = loginUserTask.Result.First();
            var appCon             = appConTask.Result;
            var categoryDictionary = categoryTask.Result.ToDictionary(x => x.Code);

            var definition = new IgnoreKanaFileDefinition(new DataExpression(appCon));
            var parser     = new CsvParser {
                Encoding      = encoding,
                StreamCreator = new PlainTextMemoryStreamCreator(),
            };

            definition.ExcludeCategoryIdField.GetModelsByCode = val => categoryDictionary;

            var importer = definition.CreateImporter(m => m.Kana, parser);

            importer.UserId      = source.LoginUserId;
            importer.UserCode    = loginUser.Code;
            importer.CompanyId   = source.CompanyId;
            importer.CompanyCode = company.Code;
            importer.LoadAsync   = () => ignoreKanaProcessor.GetAsync(new IgnoreKana {
                CompanyId = source.CompanyId,
            }, token);
            importer.RegisterAsync = x => ignoreKanaProcessor.ImportAsync(x.New, x.Dirty, x.Removed, token);

            var result = await importer.ImportAsync(csv, mode, token, null);

            result.Logs = importer.GetErrorLogs();

            return(result);
        }
Exemplo n.º 4
0
 private async Task <List <Category> > GetCategoriesAsync(int companyId, int categoryType, string[] codes, CancellationToken token)
 => (await categoryProcessor.GetAsync(new CategorySearch {
     CompanyId = companyId, CategoryType = categoryType, Codes = codes,
 }, token)).ToList();
Exemplo n.º 5
0
 public async Task <ActionResult <IEnumerable <Category> > > GetItems(CategorySearch option, CancellationToken token)
 => (await categoryProcessor.GetAsync(option, token)).ToArray();
Exemplo n.º 6
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 = 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(),
            });
        }
Exemplo n.º 7
0
        /// <summary>constructor</summary>
        public EbFileImportProcessor(
            ICompanyProcessor companyProcessor,
            ILoginUserProcessor loginUserProcessor,
            IApplicationControlProcessor applicationControlProcessor,
            ICollationSettingProcessor collationSettingProcessor,
            ICategoryProcessor categoryProcessor,
            ICurrencyProcessor currencyProcessor,
            IJuridicalPersonalityProcessor juridicalPersonalityProcessor,
            IBankAccountProcessor bankAccountProcessor,
            ICustomerProcessor customerProcessor,
            IIgnoreKanaProcessor ignoreKanaProcessor,
            IEBExcludeAccountSettingProcessor ebExcludeAccountSettingProcessor,
            ISectionProcessor sectionProcessor,
            IImportFileLogProcessor importFileLogProcessor
            )
        {
            this.companyProcessor                 = companyProcessor;
            this.loginUserProcessor               = loginUserProcessor;
            this.applicationControlProcessor      = applicationControlProcessor;
            this.collationSettingProcessor        = collationSettingProcessor;
            this.categoryProcessor                = categoryProcessor;
            this.currencyProcessor                = currencyProcessor;
            this.juridicalPersonalityProcessor    = juridicalPersonalityProcessor;
            this.bankAccountProcessor             = bankAccountProcessor;
            this.ignoreKanaProcessor              = ignoreKanaProcessor;
            this.customerProcessor                = customerProcessor;
            this.ebExcludeAccountSettingProcessor = ebExcludeAccountSettingProcessor;
            this.sectionProcessor                 = sectionProcessor;
            this.importFileLogProcessor           = importFileLogProcessor;

            importer = new EbDataImporterBase {
                IsAsync     = true,
                IsPlainText = true,
            };

            importer.Helper.InitializeAsync = async token => {
                var applicationControlTask = applicationControlProcessor.GetAsync(importer.Helper.CompanyId, token);
                var collationSettingTask   = collationSettingProcessor.GetAsync(importer.Helper.CompanyId, token);
                var defaultCurrencyTask    = currencyProcessor.GetAsync(new CurrencySearch {
                    CompanyId = importer.Helper.CompanyId,
                    Codes     = new[] { Rac.VOne.Common.Constants.DefaultCurrencyCode },
                }, token);
                var defaultReceiptCategoryTask = categoryProcessor.GetAsync(new CategorySearch {
                    CompanyId    = importer.Helper.CompanyId,
                    CategoryType = CategoryType.Receipt,
                    Codes        = new[] { "01" },
                }, token);
                var juridicalPersonalityTask = juridicalPersonalityProcessor.GetAsync(new JuridicalPersonality {
                    CompanyId = importer.Helper.CompanyId
                }, token);

                await Task.WhenAll(
                    applicationControlTask,
                    collationSettingTask,
                    defaultCurrencyTask,
                    defaultReceiptCategoryTask,
                    juridicalPersonalityTask
                    );

                importer.Helper.ApplicationControl     = applicationControlTask.Result;
                importer.Helper.CollationSetting       = collationSettingTask.Result;
                importer.Helper.DefaultCurrency        = defaultCurrencyTask.Result.First();
                importer.Helper.DefaultReceiptCategory = defaultReceiptCategoryTask.Result.First();
                importer.Helper.LegalPersonalities     = juridicalPersonalityTask.Result.Select(x => x.Kana).ToArray();
            };

            importer.Helper.GetBankAccountAsync = async(bankCode, branchCode, accountTypeId, accountNumber, token) => {
                var result = await bankAccountProcessor.GetAsync(new BankAccountSearch {
                    CompanyId     = importer.Helper.CompanyId,
                    BankCodes     = new[] { bankCode },
                    BranchCodes   = new[] { branchCode },
                    AccountTypeId = accountTypeId,
                    AccountNumber = accountNumber,
                }, token);

                return(result.FirstOrDefault());
            };

            importer.Helper.GetBankAccountByBankNameAsync = async(bankName, branchName, accountTypeId, accountNumber, token) => {
                var result = await bankAccountProcessor.GetAsync(new BankAccountSearch {
                    CompanyId     = importer.Helper.CompanyId,
                    BankName      = bankName,
                    BranchName    = branchName,
                    AccountTypeId = accountTypeId,
                    AccountNumber = accountNumber,
                }, token);

                return(result.FirstOrDefault());
            };

            importer.Helper.GetBankAccountByBranchNameAsync = async(bankCode, branchName, token) => {
                var result = await bankAccountProcessor.GetAsync(new BankAccountSearch {
                    CompanyId  = importer.Helper.CompanyId,
                    BankCodes  = new[] { bankCode },
                    BranchName = branchName,
                }, token);

                return(result.FirstOrDefault());
            };

            importer.Helper.GetBankAccountByBranchNameAndNumberAsync = async(bankCode, branchName, accountTypeId, accountNumber, token) => {
                var result = await bankAccountProcessor.GetAsync(new BankAccountSearch {
                    CompanyId     = importer.Helper.CompanyId,
                    BankCodes     = new[] { bankCode },
                    BranchName    = branchName,
                    AccountTypeId = accountTypeId,
                    AccountNumber = accountNumber,
                }, token);

                return(result.FirstOrDefault());
            };

            importer.Helper.GetCustomerIdByExclusiveInfoAsync = async(bankCode, branchCode, payerCode, token) => {
                var result = await customerProcessor.GetAsync(new CustomerSearch {
                    CompanyId              = importer.Helper.CompanyId,
                    ExclusiveBankCode      = bankCode,
                    ExclusiveBranchCode    = branchCode,
                    ExclusiveAccountNumber = payerCode,
                }, token);

                return(result.FirstOrDefault()?.Id);
            };

            importer.Helper.GetSectionIdByPayerCodeAsync = async(payerCode, token) => {
                var result = await sectionProcessor.GetAsync(new SectionSearch {
                    CompanyId  = importer.Helper.CompanyId,
                    PayerCodes = new[] { payerCode },
                }, token);

                return(result.FirstOrDefault()?.Id);
            };

            importer.Helper.GetExcludeCategoryIdAsync = async(payerName, token) => {
                var result = await ignoreKanaProcessor.GetAsync(new IgnoreKana {
                    CompanyId = importer.Helper.CompanyId,
                    Kana      = payerName,
                }, token);

                return(result.FirstOrDefault()?.ExcludeCategoryId);
            };

            importer.Helper.GetEBExcludeAccountSettingListAsync = async token
                                                                  => (await ebExcludeAccountSettingProcessor.GetAsync(importer.Helper.CompanyId, token)).ToList();

            importer.Helper.SaveDataInnerAsync = async(logs, token)
                                                 => (await importFileLogProcessor.SaveAsync(logs, token)).ToList();
        }
Exemplo n.º 8
0
        /// <summary>インポート処理</summary>
        /// <param name="source"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public async Task <ImportResult> ImportAsync(MasterImportSource source, CancellationToken token = default(CancellationToken))
        {
            var mode     = (ImportMethod)source.ImportMethod;
            var encoding = Encoding.GetEncoding(source.EncodingCodePage);
            var csv      = encoding.GetString(source.Data);

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

            await Task.WhenAll(companyTask, loginUsersTask, appConTask);

            var company             = companyTask.Result.First();
            var loginUserDictionary = loginUsersTask.Result.ToDictionary(x => x.Code);
            var loginUser           = loginUsersTask.Result.First(x => x.Id == source.LoginUserId);
            var appCon = appConTask.Result;

            var importer = new Rac.VOne.Web.Models.Importers.CustomerImporterBase(appCon)
            {
                CompanyId   = source.CompanyId,
                CompanyCode = company.Code,
                LoginUserId = source.LoginUserId,
                PatternNo   = source.ImporterSettingCode,
                Parser      = new CsvParser {
                    Encoding      = encoding,
                    StreamCreator = new PlainTextMemoryStreamCreator(),
                },
                GetCollectCategoryAsync       = async() => (await categoryProcessor.GetAsync(new CategorySearch {
                    CompanyId = source.CompanyId, CategoryType = CategoryType.Collect,
                }, token)).ToList(),
                GetStaffAsync                 = async() => (await staffProcessor.GetAsync(new StaffSearch {
                    CompanyId = source.CompanyId,
                }, token)).ToList(),
                GetLeagalPersonaritiesAsync   = async() => (await juridicalPersonalityProcessor.GetAsync(new JuridicalPersonality {
                    CompanyId = source.CompanyId,
                }, token)).Select(x => x.Kana).ToArray(),
                GetCustomerAsync              = async() => (await customerProcessor.GetAsync(new CustomerSearch {
                    CompanyId = source.CompanyId,
                }, token)).ToList(),
                GetImporterSettingAsync       = async(formatId, code) => (await importerSettingProcessor.GetAsync(new ImporterSetting {
                    CompanyId = source.CompanyId, FormatId = formatId, Code = code,
                }, token)).First(),
                GetImporterSettingDetailAsync = async(formatId, code) => (await importerSettingDetailProcessor.GetAsync(new ImporterSetting {
                    CompanyId = source.CompanyId, FormatId = formatId, Code = code,
                }, token)).ToList(),
                GetRoundingTypeAsync          = async() =>
                {
                    var val           = (await generalSettingProcessor.GetAsync(new GeneralSetting {
                        CompanyId = source.CompanyId, Code = "取込時端数処理",
                    }, token)).FirstOrDefault()?.Value;
                    RoundingType type = RoundingType.Floor;
                    Enum.TryParse(val, out type);
                    return(type);
                },
                GetMasterDataForCustomerGroupParentAsync = async(codes) => (await customerProcessor.GetImportForCustomerGroupParentAsync(source.CompanyId, codes, token)).ToList(),
                GetMasterDataForCustomerGroupChildAsync  = async(codes) => (await customerProcessor.GetImportForCustomerGroupChildAsync(source.CompanyId, codes, token)).ToList(),
                GetMasterDataForKanaHistoryAsync         = async(codes) => (await customerProcessor.GetImportForKanaHistoryAsync(source.CompanyId, codes, token)).ToList(),
                GetMasterDataForBillingAsync             = async(codes) => (await customerProcessor.GetImportForBillingAsync(source.CompanyId, codes, token)).ToList(),
                GetMasterDataForReceiptAsync             = async(codes) => (await customerProcessor.GetImportForReceiptAsync(source.CompanyId, codes, token)).ToList(),
                GetMasterDataForNettingAsync             = async(codes) => (await customerProcessor.GetImportForNettingAsync(source.CompanyId, codes, token)).ToList(),
                ImportCustomerAsync = (insert, update, delete) => customerProcessor.ImportAsync(insert, update, delete, token),
            };
            await importer.InitializeAsync();

            var result = await importer.ImportAsync(csv, source.ImportMethod, null);

            result.Logs = importer.ErrorList;

            return(result);
        }