/// <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(),
            });
        }
Beispiel #2
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);
        }
        /// <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 definition = new BankBranchFileDefinition(new DataExpression(appCon));
            var parser     = new CsvParser {
                Encoding      = encoding,
                StreamCreator = new PlainTextMemoryStreamCreator(),
            };


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

            importer.UserId      = source.LoginUserId;
            importer.UserCode    = loginUser.Code;
            importer.CompanyId   = source.CompanyId;
            importer.CompanyCode = company.Code;

            importer.LoadAsync = () => bankBranchProcessor.GetAsync(new BankBranchSearch {
                CompanyId = source.CompanyId,
            }, token);
            importer.RegisterAsync = async x => {
                foreach (var y in x.New)
                {
                    y.CompanyId = source.CompanyId;
                }
                foreach (var y in x.Dirty)
                {
                    y.CompanyId = source.CompanyId;
                }
                foreach (var y in x.Removed)
                {
                    y.CompanyId = source.CompanyId;
                }
                return(await bankBranchProcessor.ImportAsync(x.New, x.Dirty, x.Removed, token));
            };

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

            result.Logs = importer.GetErrorLogs();

            return(result);
        }
Beispiel #4
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);
            var customerTask = customerProcessor.GetAsync(new CustomerSearch {
                CompanyId = source.CompanyId
            }, token);
            var currencyTask = currencyProcessor.GetAsync(new CurrencySearch {
                CompanyId = source.CompanyId,
            }, token);

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

            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 customerDictionary = customerTask.Result.ToDictionary(x => x.Code);
            var currencyDictionary = currencyTask.Result.ToDictionary(x => x.Code);

            var useForeignCurrency = appCon.UseForeignCurrency == 1;

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


            definition.CurrencyCodeField.Ignored         = !useForeignCurrency;
            definition.CustomerIdField.GetModelsByCode   = val => customerDictionary;
            definition.CurrencyCodeField.GetModelsByCode = code => currencyDictionary;

            var importer = definition.CreateImporter(x => new { x.CustomerCode, x.CurrencyCode, x.Fee }, parser);

            importer.UserId      = source.LoginUserId;
            importer.UserCode    = loginUser.Code;
            importer.CompanyId   = source.CompanyId;
            importer.CompanyCode = company.Code;

            importer.LoadAsync = () => customerFeeProcessor.GetAsync(new CustomerFeeSearch {
                CompanyId = source.CompanyId,
            }, token);
            importer.RegisterAsync = x => customerFeeProcessor.ImportAsync(x.New, x.Dirty, x.Removed, token);

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

            result.Logs = importer.GetErrorLogs();

            return(result);
        }
Beispiel #5
0
        public async Task <ClosingInformation> GetClosingInformationAsync(int companyId, CancellationToken token = default(CancellationToken))
        {
            var closing            = new ClosingInformation();
            var applicationControl = await applicationControlProcessor.GetAsync(companyId, token);

            if (applicationControl?.UseClosing == 1)
            {
                closing.UseClosing = true;
                closing.Closing    = await byCompanyGetClosingQueryProcessor.GetAsync(companyId, token);
            }
            return(closing);
        }
 public async Task <ApplicationControlResult> GetAsync(string sessionKey, int companyId)
 {
     return(await authorizationProcessor.DoAuthorizeAsync(sessionKey, async token =>
     {
         var result = await applicationControlProcessor.GetAsync(companyId, token);
         return new ApplicationControlResult
         {
             ProcessResult = new ProcessResult {
                 Result = true
             },
             ApplicationControl = 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 agencyTask = paymentAgencyProcessor.GetAsync(new MasterSearchOption {
                CompanyId = source.CompanyId,
            }, token);

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

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

            var definition = new KanaHistoryPaymentAgencyFileDefinition(new DataExpression(appCon));

            definition.PaymentAgencyIdField.GetModelsByCode = val => agencyDictionary;
            var parser = new CsvParser {
                Encoding      = encoding,
                StreamCreator = new PlainTextMemoryStreamCreator(),
            };

            var importer = definition.CreateImporter(x => new { x.PayerName, x.SourceBankName, x.SourceBranchName, x.PaymentAgencyId }, parser);

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

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

            result.Logs = importer.GetErrorLogs();

            return(result);
        }
        /// <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);

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

            var company   = companyTask.Result.First();
            var loginUser = loginUserTask.Result.First();
            var appCon    = appConTask.Result;

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

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

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

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

            result.Logs = importer.GetErrorLogs();

            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(),
            });
        }
        /// <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 sectionTask = sectionProcessor.GetAsync(new SectionSearch {
                CompanyId = source.CompanyId,
            }, token);

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

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

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

            var importer = definition.CreateImporter(x => x.Code, parser);

            importer.UserId      = source.LoginUserId;
            importer.UserCode    = loginUser.Code;
            importer.CompanyId   = source.CompanyId;
            importer.CompanyCode = company.Code;

            importer.AdditionalWorker = async worker => {
                var codes = worker.Models.Values.Select(x => x.Code).Where(x => !string.IsNullOrEmpty(x)).Distinct().ToArray();

                if (mode == ImportMethod.Replace)
                {
                    var bankAccountTask = sectionProcessor.GetImportItemsBankAccountAsync(source.CompanyId, codes, token);
                    var swdTask         = sectionProcessor.GetImportItemsSectionWithDepartmentAsync(source.CompanyId, codes, token);
                    var swlTask         = sectionProcessor.GetImportItemsSectionWithLoginUserAsync(source.CompanyId, codes, token);
                    var receiptTask     = sectionProcessor.GetImportItemsReceiptAsync(source.CompanyId, codes, token);
                    var nettingTask     = sectionProcessor.GetImportItemsNettingAsync(source.CompanyId, codes, token);

                    await Task.WhenAll(bankAccountTask, swdTask, swlTask, receiptTask, nettingTask);

                    (worker.RowDef as SectionFileDefinition).SectionCodeField.ValidateAdditional = (val, param) => {
                        var reports = new List <WorkingReport>();
                        reports.AddRange(bankAccountTask.Result.Select(x => new WorkingReport {
                            FieldNo   = definition.SectionCodeField.FieldIndex,
                            FieldName = definition.SectionCodeField.FieldName,
                            Message   = $"銀行口座マスターに存在する{x.Code}:{x.Name}が存在しないため、インポートできません。",
                        }).ToArray());
                        reports.AddRange(swdTask.Result.Select(x => new WorkingReport {
                            FieldNo   = definition.SectionCodeField.FieldIndex,
                            FieldName = definition.SectionCodeField.FieldName,
                            Message   = $"入金・請求部門対応マスターに存在する{x.Code}:{x.Name}が存在しないため、インポートできません。",
                        }).ToArray());
                        reports.AddRange(swlTask.Result.Select(x => new WorkingReport {
                            FieldNo   = definition.SectionCodeField.FieldIndex,
                            FieldName = definition.SectionCodeField.FieldName,
                            Message   = $"入金部門・担当者対応マスターに存在する{x.Code}:{x.Name}が存在しないため、インポートできません。",
                        }).ToArray());
                        reports.AddRange(receiptTask.Result.Select(x => new WorkingReport {
                            FieldNo   = definition.SectionCodeField.FieldIndex,
                            FieldName = definition.SectionCodeField.FieldName,
                            Message   = $"入金データに存在する{x.Code}:{x.Name}が存在しないため、インポートできません。",
                        }).ToArray());
                        reports.AddRange(nettingTask.Result.Select(x => new WorkingReport {
                            FieldNo   = definition.SectionCodeField.FieldIndex,
                            FieldName = definition.SectionCodeField.FieldName,
                            Message   = $"相殺データに存在する{x.Code}:{x.Name}が存在しないため、インポートできません。",
                        }).ToArray());
                        return(reports);
                    };
                }

                var payerCodes = worker.Models.Values.Where(x => !string.IsNullOrEmpty(x.PayerCodeLeft) && !string.IsNullOrEmpty(x.PayerCodeRight))
                                 .Select(x => x.PayerCodeLeft + x.PayerCodeRight).Distinct().ToArray();

                var sections = (await sectionProcessor.GetAsync(new SectionSearch {
                    CompanyId = source.CompanyId, PayerCodes = payerCodes,
                }, token)).ToList();

                (worker.RowDef as SectionFileDefinition).PayerCodeLeftField.ValidateAdditional = (val, param) => {
                    var reports         = new List <WorkingReport>();
                    var def             = (worker.RowDef as SectionFileDefinition);
                    var uniqueKeys      = new Dictionary <string, int>();
                    var duplicatedLines = new List <int>();

                    foreach (var pair in val)
                    {
                        var leftIsEmpty  = string.IsNullOrEmpty(pair.Value.PayerCodeLeft);
                        var rightIsEmpty = string.IsNullOrEmpty(pair.Value.PayerCodeRight);
                        if (leftIsEmpty && rightIsEmpty)
                        {
                            continue;
                        }

                        if (leftIsEmpty ^ rightIsEmpty)
                        {
                            var field = leftIsEmpty ? def.PayerCodeLeftField : def.PayerCodeRightField;
                            reports.Add(new WorkingReport {
                                LineNo    = pair.Key,
                                FieldNo   = field.FieldIndex,
                                FieldName = field.FieldName,
                                Message   = "仮想支店コード・仮想口座番号のどちらかが未入力のため、インポートできません。",
                            });
                            continue;
                        }

                        var payerCode = pair.Value.PayerCodeLeft + pair.Value.PayerCodeRight;
                        if (mode == ImportMethod.InsertOnly)
                        {
                            if (sections.Any(x => x.PayerCode == payerCode))
                            {
                                reports.Add(new WorkingReport {
                                    LineNo    = pair.Key,
                                    FieldNo   = def.PayerCodeLeftField.FieldIndex,
                                    FieldName = "仮想支店コード、仮想口座番号",
                                    Message   = "既に登録されている仮想支店コード、仮想口座番号のため、インポートできません。",
                                    Value     = payerCode,
                                });
                            }
                        }
                        else if (mode == ImportMethod.InsertAndUpdate)
                        {
                            // bug : 更新処理で、振込依頼人番号 の シャッフルができない
                            if (sections.Any(x => x.PayerCode == payerCode && x.Code != pair.Value.Code))
                            {
                                reports.Add(new WorkingReport {
                                    LineNo    = pair.Key,
                                    FieldNo   = def.PayerCodeLeftField.FieldIndex,
                                    FieldName = "仮想支店コード、仮想口座番号",
                                    Message   = "既に登録されている仮想支店コード、仮想口座番号のため、インポートできません。",
                                    Value     = payerCode,
                                });
                            }
                        }
                        if (uniqueKeys.ContainsKey(payerCode))
                        {
                            var line = uniqueKeys[payerCode];
                            if (!duplicatedLines.Contains(line))
                            {
                                duplicatedLines.Add(line);
                            }
                            duplicatedLines.Add(pair.Key);
                        }
                        else
                        {
                            uniqueKeys.Add(payerCode, pair.Key);
                        }
                    }
                    foreach (var line in duplicatedLines)
                    {
                        reports.Add(new WorkingReport {
                            LineNo    = line,
                            FieldNo   = def.PayerCodeLeftField.FieldIndex,
                            FieldName = "仮想支店コード、仮想口座番号",
                            Message   = "仮想支店コード、仮想口座番号が重複しているため、インポートできません。",
                            Value     = val[line].PayerCodeLeft + val[line].PayerCodeRight,
                        });
                    }
                    return(reports);
                };
            };

            importer.LoadAsync = () => sectionProcessor.GetAsync(new SectionSearch {
                CompanyId = source.CompanyId,
            }, token);
            importer.RegisterAsync = x => sectionProcessor.ImportAsync(x.New, x.Dirty, x.Removed, token);

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

            result.Logs = importer.GetErrorLogs();

            return(result);
        }
Beispiel #11
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 sectionTask = sectionProcessor.GetAsync(new SectionSearch {
                CompanyId = source.CompanyId,
            }, token);
            var departmentTask = departmentProcessor.GetAsync(new DepartmentSearch {
                CompanyId = source.CompanyId,
            }, token);

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

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

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

            definition.SectionCodeField.GetModelsByCode    = codes => sectionDictionary;
            definition.DepartmentCodeField.GetModelsByCode = codes => departmentDictionary;

            var importer = definition.CreateImporter(x => new { x.SectionId, x.DepartmentId }, parser);

            importer.UserId      = source.LoginUserId;
            importer.UserCode    = loginUser.Code;
            importer.CompanyId   = source.CompanyId;
            importer.CompanyCode = company.Code;

            importer.AdditionalWorker = async worker => {
                var dbItems = (await sectionWithDepartmentProcessor.GetAsync(new SectionWithDepartmentSearch {
                    CompanyId = source.CompanyId,
                }, token)).ToList();

                var dbDepartmentCheckList = new SortedList <int, SectionWithDepartment[]>(dbItems.GroupBy(x => x.DepartmentId)
                                                                                          .ToDictionary(x => x.Key, x => x.ToArray()));
                var csvDepartmentCheckList = new SortedList <int, SectionWithDepartment[]>(worker.Models.Values
                                                                                           .GroupBy(x => x.DepartmentId)
                                                                                           .ToDictionary(x => x.Key, x => x.ToArray()));

                var def = worker.RowDef as SectionWithDepartmentFileDefinition;
                def.DepartmentCodeField.ValidateAdditional = (val, param) => {
                    var reports = new List <WorkingReport>();

                    foreach (var pair in val)
                    {
                        if (IsDuped(dbDepartmentCheckList,
                                    pair.Value.DepartmentId,
                                    g => g.Any(x => x.SectionId != pair.Value.SectionId)))
                        {
                            reports.Add(new WorkingReport(pair.Key,
                                                          def.DepartmentCodeField.FieldIndex,
                                                          def.DepartmentCodeField.FieldName,
                                                          "他の入金部門に登録されているため、インポートできません。"
                                                          ));
                        }

                        if (IsDuped(csvDepartmentCheckList,
                                    pair.Value.DepartmentId,
                                    g => g.Any(x => x.SectionId != pair.Value.SectionId && pair.Value.DepartmentId != 0)))
                        {
                            reports.Add(new WorkingReport(pair.Key,
                                                          def.DepartmentCodeField.FieldIndex,
                                                          def.DepartmentCodeField.FieldName,
                                                          "他の入金部門に登録されているため、インポートできません。"
                                                          ));
                        }
                    }
                    return(reports);
                };
            };

            importer.LoadAsync = () => sectionWithDepartmentProcessor.GetAsync(new SectionWithDepartmentSearch {
                CompanyId = source.CompanyId,
            }, token);
            importer.RegisterAsync = x => sectionWithDepartmentProcessor.ImportAsync(x.New, x.Dirty, x.Removed, token);

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

            result.Logs = importer.GetErrorLogs();

            return(result);
        }
Beispiel #12
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);
        }
        /// <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 staffsTask = staffProcessor.GetAsync(new StaffSearch {
                CompanyId = source.CompanyId,
            }, token);

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

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

            var definition = new DepartmentFileDefinition(new DataExpression(appCon));

            definition.StaffIdField.GetModelsByCode = codes => staffDictionary;
            var parser = new CsvParser {
                Encoding      = encoding,
                StreamCreator = new PlainTextMemoryStreamCreator(),
            };
            var importer = definition.CreateImporter(x => x.Code, parser);

            importer.UserId      = source.LoginUserId;
            importer.UserCode    = loginUser.Code;
            importer.CompanyId   = source.CompanyId;
            importer.CompanyCode = company.Code;
            if (mode == ImportMethod.Replace)
            {
                importer.AdditionalWorker = async worker => {
                    var codes = worker.Models.Values.Select(x => x.Code).Where(x => !string.IsNullOrEmpty(x)).Distinct().ToArray();

                    var staffItemTask = departmentProcessor.GetImportItemsStaffAsync(source.CompanyId, codes, token);
                    var swdItemTask   = departmentProcessor.GetImportItemsSectionWithDepartmentAsync(source.CompanyId, codes, token);
                    var billItemTask  = departmentProcessor.GetImportItemsBillingAsync(source.CompanyId, codes, token);

                    await Task.WhenAll(staffItemTask, swdItemTask, billItemTask);

                    var staffResult = staffItemTask.Result.ToArray();
                    var swdResult   = swdItemTask.Result.ToArray();
                    var billResult  = billItemTask.Result.ToArray();

                    (worker.RowDef as DepartmentFileDefinition).DepartmentCodeField.ValidateAdditional = (val, param) => {
                        var reports = new List <WorkingReport>();
                        reports.AddRange(staffResult.Select(x => new WorkingReport {
                            FieldNo   = definition.DepartmentCodeField.FieldIndex,
                            FieldName = definition.DepartmentCodeField.FieldName,
                            Message   = $"営業担当者マスターに存在する{x.Code}:{x.Name}が存在しないため、インポートできません。",
                        }).ToArray());
                        reports.AddRange(swdResult.Select(x => new WorkingReport {
                            FieldNo   = definition.DepartmentCodeField.FieldIndex,
                            FieldName = definition.DepartmentCodeField.FieldName,
                            Message   = $"入金・請求部門名対応マスターに存在する{x.Code}:{x.Name}が存在しないため、インポートできません。",
                        }).ToArray());
                        reports.AddRange(billResult.Select(x => new WorkingReport {
                            FieldNo   = definition.DepartmentCodeField.FieldIndex,
                            FieldName = definition.DepartmentCodeField.FieldName,
                            Message   = $"請求データーに存在する{x.Code}:{x.Name}が存在しないため、インポートできません。",
                        }).ToArray());
                        return(reports);
                    };
                }
            }
            ;
            importer.LoadAsync = () => departmentProcessor.GetAsync(new DepartmentSearch {
                CompanyId = source.CompanyId,
            }, token);
            importer.RegisterAsync = x => departmentProcessor.ImportAsync(x.New, x.Dirty, x.Removed, token);

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

            result.Logs = importer.GetErrorLogs();

            return(result);
        }
    }
Beispiel #14
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();
        }
Beispiel #15
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);
            var departmentTask = departmentProcessor.GetAsync(new DepartmentSearch {
                CompanyId = source.CompanyId,
            }, token);
            var staffTask = staffProcessor.GetAsync(new StaffSearch {
                CompanyId = source.CompanyId,
            }, token);

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

            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 departmentDictionary = departmentTask.Result.ToDictionary(x => x.Code);

            var useDistribution = appCon.UseDistribution == 1;

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

            definition.MailField.Required = useDistribution;

            definition.DepartmentIdField.GetModelsByCode = val => departmentDictionary;

            var importer = definition.CreateImporter(x => x.Code, parser);

            importer.UserId      = source.LoginUserId;
            importer.UserCode    = loginUser.Code;
            importer.CompanyId   = source.CompanyId;
            importer.CompanyCode = company.Code;

            if (mode == ImportMethod.Replace)
            {
                importer.AdditionalWorker = async worker => {
                    var codes    = worker.Models.Values.Select(x => x.Code).Distinct().ToArray();
                    var userTask = staffProcessor.GetImportItemsLoginUserAsync(source.CompanyId, codes, token);
                    var custTask = staffProcessor.GetImportItemsCustomerAsync(source.CompanyId, codes, token);
                    var billTask = staffProcessor.GetImportItemsBillingAsync(source.CompanyId, codes, token);

                    await Task.WhenAll(userTask, custTask, billTask);

                    var def = worker.RowDef as StaffFileDefinition;

                    def.StaffCodeField.ValidateAdditional = (val, param) => {
                        var reports = new List <WorkingReport>();

                        reports.AddRange(userTask.Result.Select(x => new WorkingReport {
                            FieldNo   = def.StaffCodeField.FieldIndex,
                            FieldName = def.StaffNameField.FieldName,
                            Message   = $"ログインユーザーマスターに存在する{x.Code}:{x.Name}が存在しないため、インポートできません。",
                        }));

                        reports.AddRange(custTask.Result.Select(x => new WorkingReport {
                            FieldNo   = def.StaffCodeField.FieldIndex,
                            FieldName = def.StaffNameField.FieldName,
                            Message   = $"得意先マスターに存在する{x.Code}:{x.Name}が存在しないため、インポートできません。",
                        }));

                        reports.AddRange(billTask.Result.Select(x => new WorkingReport {
                            FieldNo   = def.StaffCodeField.FieldIndex,
                            FieldName = def.StaffNameField.FieldName,
                            Message   = $"請求データに存在する{x.Code}:{x.Name}が存在しないため、インポートできません。",
                        }));
                        return(reports);
                    };
                };
            }

            importer.LoadAsync = () => staffProcessor.GetAsync(new StaffSearch {
                CompanyId = source.CompanyId,
            }, token);
            importer.RegisterAsync = x => staffProcessor.ImportAsync(x.New, x.Dirty, x.Removed, token);

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

            result.Logs = importer.GetErrorLogs();

            return(result);
        }
        /// <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);
            var customerTask = customerProcessor.GetAsync(new CustomerSearch {
                CompanyId = source.CompanyId
            }, token);
            var departmentTask = departmentProcessor.GetAsync(new DepartmentSearch {
                CompanyId = source.CompanyId,
            }, token);
            var accountTitleTask = accountTitleProcessor.GetAsync(new AccountTitleSearch {
                CompanyId = source.CompanyId,
            }, token);

            await Task.WhenAll(companyTask, loginUsersTask, appConTask, customerTask, departmentTask, accountTitleTask);

            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 customerDictionary     = customerTask.Result.ToDictionary(x => x.Code);
            var departmentDictionary   = departmentTask.Result.ToDictionary(x => x.Code);
            var accountTitleDictionary = accountTitleTask.Result.ToDictionary(x => x.Code);

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

            definition.CustomerIdField.GetModelsByCode      = val => customerDictionary;
            definition.DepartmentId1Field.GetModelsByCode   = val => departmentDictionary;
            definition.DepartmentId2Field.GetModelsByCode   = val => departmentDictionary;
            definition.DepartmentId3Field.GetModelsByCode   = val => departmentDictionary;
            definition.DepartmentId4Field.GetModelsByCode   = val => departmentDictionary;
            definition.DepartmentId5Field.GetModelsByCode   = val => departmentDictionary;
            definition.AccountTitleId1Field.GetModelsByCode = val => accountTitleDictionary;
            definition.AccountTitleId2Field.GetModelsByCode = val => accountTitleDictionary;
            definition.AccountTitleId3Field.GetModelsByCode = val => accountTitleDictionary;
            definition.AccountTitleId4Field.GetModelsByCode = val => accountTitleDictionary;
            definition.AccountTitleId5Field.GetModelsByCode = val => accountTitleDictionary;
            definition.Rate1Field.ValidateAdditional        = (val, param) => ValidateRate(val, param, definition.Rate1Field);
            definition.Rate2Field.ValidateAdditional        = (val, param) => ValidateRate(val, param, definition.Rate2Field);
            definition.Rate3Field.ValidateAdditional        = (val, param) => ValidateRate(val, param, definition.Rate3Field);
            definition.Rate4Field.ValidateAdditional        = (val, param) => ValidateRate(val, param, definition.Rate4Field);
            definition.Rate5Field.ValidateAdditional        = (val, param) => ValidateRate(val, param, definition.Rate5Field);

            var importer = definition.CreateImporter(x => x.CustomerCode, parser);

            importer.UserId      = source.LoginUserId;
            importer.UserCode    = loginUser.Code;
            importer.CompanyId   = source.CompanyId;
            importer.CompanyCode = company.Code;

            importer.LoadAsync = () => customerDiscountProcessor.GetItemsAsync(new CustomerSearch {
                CompanyId = source.CompanyId,
            }, token);
            importer.RegisterAsync = x => customerDiscountProcessor.ImportAsync(x.New, x.Dirty, x.Removed, token);

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

            result.Logs = importer.GetErrorLogs();

            return(result);
        }
Beispiel #17
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);

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

            var company            = companyTask.Result.First();
            var loginUser          = loginUserTask.Result.First();
            var applicationControl = appConTask.Result;
            var definition         = new AccountTitleFileDefinition(new DataExpression(applicationControl));

            var parser = new CsvParser {
                Encoding      = encoding,
                StreamCreator = new PlainTextMemoryStreamCreator(),
            };

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

            importer.UserId      = source.LoginUserId;
            importer.UserCode    = loginUser.Code;
            importer.CompanyId   = source.CompanyId;
            importer.CompanyCode = company.Code;
            if (mode == ImportMethod.Replace)
            {
                importer.AdditionalWorker = async worker => {
                    var codes                 = worker.Models.Values.Select(x => x.Code).Where(x => !string.IsNullOrEmpty(x)).Distinct().ToArray();
                    var categoryItemTask      = accountTitleProcessor.GetImportItemsCategoryAsync(source.CompanyId, codes, token);
                    var customerItemTask      = accountTitleProcessor.GetImportItemsCustomerDiscountAsync(source.CompanyId, codes, token);
                    var debitBillingItemTask  = accountTitleProcessor.GetImportItemsDebitBillingAsync(source.CompanyId, codes, token);
                    var creditBillingItemTask = accountTitleProcessor.GetImportItemsCreditBillingAsync(source.CompanyId, codes, token);

                    await Task.WhenAll(categoryItemTask, customerItemTask, debitBillingItemTask, creditBillingItemTask);


                    (worker.RowDef as AccountTitleFileDefinition).AccountTitleCodeField.ValidateAdditional = (val, param) => {
                        var reports = new List <WorkingReport>();
                        reports.AddRange(categoryItemTask.Result.Select(x => new WorkingReport
                        {
                            FieldNo   = definition.AccountTitleCodeField.FieldIndex,
                            FieldName = definition.AccountTitleCodeField.FieldName,
                            Message   = $"区分マスターに存在する{x.Code}:{x.Name}が存在しないため、インポートできません。",
                        }).ToArray());

                        reports.AddRange(customerItemTask.Result.Select(x => new WorkingReport
                        {
                            FieldNo   = definition.AccountTitleCodeField.FieldIndex,
                            FieldName = definition.AccountTitleCodeField.FieldName,
                            Message   = $"得意先マスター歩引設定に存在する{x.Code}:{x.Name}が存在しないため、インポートできません。",
                        }).ToArray());

                        reports.AddRange(debitBillingItemTask.Result.Select(x => new WorkingReport
                        {
                            FieldNo   = definition.AccountTitleCodeField.FieldIndex,
                            FieldName = definition.AccountTitleCodeField.FieldName,
                            Message   = $"請求データに存在する{x.Code}:{x.Name}が存在しないため、インポートできません。",
                        }).ToArray());

                        reports.AddRange(creditBillingItemTask.Result.Select(x => new WorkingReport
                        {
                            FieldNo   = definition.AccountTitleCodeField.FieldIndex,
                            FieldName = definition.AccountTitleCodeField.FieldName,
                            Message   = $"請求データに存在する{x.Code}:{x.Name}が存在しないため、インポートできません。",
                        }).ToArray());

                        return(reports);
                    };
                }
            }
            ;

            importer.LoadAsync = () => accountTitleProcessor.GetAsync(new AccountTitleSearch {
                CompanyId = source.CompanyId,
            }, token);
            importer.RegisterAsync = x => accountTitleProcessor.ImportAsync(x.New, x.Dirty, x.Removed, token);

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

            result.Logs = importer.GetErrorLogs();

            return(result);
        }
    }
        /// <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 departmentTask = departmentProcessor.GetAsync(new DepartmentSearch {
                CompanyId = source.CompanyId,
            }, token);
            var staffTask = staffProcessor.GetAsync(new StaffSearch {
                CompanyId = source.CompanyId,
            }, token);
            var policyTask = passwordPolicyProcessor.GetAsync(source.CompanyId, token);

            await Task.WhenAll(companyTask, loginUserTask, appConTask, departmentTask, staffTask, policyTask);

            var company   = companyTask.Result.First();
            var loginUser = loginUserTask.Result.First();
            var appCon    = appConTask.Result;
            var deptDic   = departmentTask.Result.ToDictionary(x => x.Code);
            var stffDic   = staffTask.Result.ToDictionary(x => x.Code);
            var policy    = policyTask.Result;

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

            var useDistribution = appCon.UseDistribution == 1;

            definition.MailField.Required        = useDistribution;
            definition.UseClientField.Ignored    = !useDistribution;
            definition.UseWebViewerField.Ignored = !useDistribution;

            definition.DepartmentCodeField.GetModelsByCode = val => deptDic;
            definition.StaffCodeField.GetModelsByCode      = val => stffDic;

            var importer = definition.CreateImporter(x => x.Code, parser);

            importer.UserId      = source.LoginUserId;
            importer.UserCode    = loginUser.Code;
            importer.CompanyId   = source.CompanyId;
            importer.CompanyCode = company.Code;
            importer.LoadAsync   = () => loginUserProcessor.GetAsync(new LoginUserSearch {
                CompanyId = source.CompanyId,
            }, token);

            importer.AdditionalWorker = async worker => {
                var codes = worker.Models.Values.Select(x => x.Code).Where(x => !string.IsNullOrEmpty(x)).Distinct().ToArray();
                var def   = worker.RowDef as LoginUserFileDefinition;

                if (mode == ImportMethod.Replace)
                {
                    var sectionResult = await loginUserProcessor.GetAsync(new LoginUserSearch { CompanyId = source.CompanyId, ExcludeCodes = codes, }, token);

                    def.LoginUserCodeField.ValidateAdditional = (val, param) => {
                        var reports = new List <WorkingReport>();
                        reports.AddRange(sectionResult.Select(x => new WorkingReport {
                            FieldNo   = definition.DepartmentCodeField.FieldIndex,
                            FieldName = definition.DepartmentCodeField.FieldName,
                            Message   = $"入金部門・担当者対応マスターに存在する{x.Code}:{x.Name}が存在しないため、インポートできません。",
                        }).ToArray());

                        return(reports);
                    };
                }

                var dbCodes = (await loginUserProcessor.GetAsync(new LoginUserSearch {
                    CompanyId = source.CompanyId, Codes = codes,
                }, token)).Select(x => x.Code);
                def.InitialPasswordField.ValidateAdditional = (val, param) => {
                    var reports = new List <WorkingReport>();

                    var csvCodes = val.Values.Select(u => u.Code).ToArray();

                    var targetCodes = csvCodes.Except(dbCodes); // 検証対象(=新規登録ユーザ)

                    var addError = new Action <int, string, string>((lineNo, value, message) =>
                    {
                        reports.Add(new WorkingReport {
                            LineNo    = lineNo,
                            FieldNo   = definition.InitialPasswordField.FieldIndex,
                            FieldName = definition.InitialPasswordField.FieldName,
                            Value     = value,
                            Message   = message,
                        });
                    });

                    foreach (var lineNo in val.Keys.Where(lineNo => targetCodes.Contains(val[lineNo].Code)))
                    {
                        var password = val[lineNo].InitialPassword;

                        if (string.IsNullOrEmpty(password))
                        {
                            addError(lineNo, password, $"新規登録ユーザの初回パスワードが空白のため、インポートできません。");
                            continue;
                        }

                        var validationResult = policy.Validate(password);
                        if (validationResult != PasswordValidateResult.Valid)
                        {
                            switch (validationResult)
                            {
                            case PasswordValidateResult.ProhibitionAlphabetChar:
                                addError(lineNo, password, $"アルファベットが使用されているため、インポートできません。");
                                break;

                            case PasswordValidateResult.ProhibitionNumberChar:
                                addError(lineNo, password, $"数字が使用されているため、インポートできません。");
                                break;

                            case PasswordValidateResult.ProhibitionSymbolChar:
                                addError(lineNo, password, $"記号が使用されているため、インポートできません。");
                                break;

                            case PasswordValidateResult.ProhibitionNotAllowedSymbolChar:
                                addError(lineNo, password, $"使用できない文字が含まれているため、インポートできません。");
                                break;

                            case PasswordValidateResult.ShortageAlphabetCharCount:
                                addError(lineNo, password, $"アルファベットが最低{policy.MinAlphabetUseCount}文字含まれていないため、インポートできません。");
                                break;

                            case PasswordValidateResult.ShortageNumberCharCount:
                                addError(lineNo, password, $"数字が最低{policy.MinNumberUseCount}文字含まれていないため、インポートできません。");
                                break;

                            case PasswordValidateResult.ShortageSymbolCharCount:
                                addError(lineNo, password, $"記号が最低{policy.MinSymbolUseCount}文字含まれていないため、インポートできません。");
                                break;

                            case PasswordValidateResult.ShortagePasswordLength:
                                addError(lineNo, password, $"{policy.MinLength}文字以上でないため、インポートできません。");
                                break;

                            case PasswordValidateResult.ExceedPasswordLength:
                                addError(lineNo, password, $"{policy.MaxLength}文字以下でないため、インポートできません。");
                                break;

                            case PasswordValidateResult.ExceedSameRepeatedChar:
                                addError(lineNo, password, $"同じ文字が{policy.MinSameCharacterRepeat}文字以上続いているため、インポートできません。");
                                break;

                            default:
                                throw new NotImplementedException($"PasswordValidateResult = {validationResult.ToString()}");
                            }
                        }
                    }

                    return(reports);
                };
            };

            importer.RegisterAsync = x => loginUserProcessor.ImportAsync(x.New, x.Dirty, x.Removed, token);

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

            result.Logs = importer.GetErrorLogs();

            return(result);
        }
Beispiel #19
0
 private async Task <ApplicationControl> GetApplicationControlAsync(int companyId, CancellationToken token)
 => await applicationControlProcessor.GetAsync(companyId, token);
 public async Task <ApplicationControl> Get([FromBody] int companyId, CancellationToken token)
 => await applicationControlProcessor.GetAsync(companyId, token);