From f6d39a4c26d7fb0d32a0b43cf32ed28e4270f05c Mon Sep 17 00:00:00 2001 From: "maruyama.t" Date: Tue, 27 Feb 2024 23:55:44 +0000 Subject: [PATCH] =?UTF-8?q?Merged=20PR=20788:=20[2=E5=9B=9E=E7=9B=AE?= =?UTF-8?q?=E5=AE=9F=E8=A1=8C]=E5=AE=9F=E6=96=BD=E5=BE=8C=E3=81=AE?= =?UTF-8?q?=E5=8B=95=E4=BD=9C=E7=A2=BA=E8=AA=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task3577: [2回目実行]実施後の動作確認](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/3577) accountがCountryの場合に配下のDistributorの親アカウントIDを付け替える処理について、Typeの付け替えができていなかったのを修正。 ライセンスの有効期限が"9999/12/31 23:59:59.997"でフォーマットチェックをしているが、移行元は"9999/12/31 23:59:59"なので移行元に合わせた。 dealerAccountIdが設定されているが、そのdealerが存在しない場合もデータを作ってしまっている。 →該当レコードはエラーファイルを出力する。 ## レビューポイント - エラーファイルの出力処理だが簡素すぎるか? JSONで出力する意味はないが、これまでの動作確認で動作担保できているのでJSONで出しています。 ## 動作確認状況 - ローカルで確認 正常の場合データ変換が行われることを確認。 dealerAccountIdが設定されているが、そのdealerが存在しない場合もデータでテストした場合、error.jsonが作られることを確認。 ## 補足 - 相談、参考資料などがあれば --- .../src/features/transfer/transfer.service.ts | 46 +++++++++++-------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/data_migration_tools/server/src/features/transfer/transfer.service.ts b/data_migration_tools/server/src/features/transfer/transfer.service.ts index c1b0757..cf8dd53 100644 --- a/data_migration_tools/server/src/features/transfer/transfer.service.ts +++ b/data_migration_tools/server/src/features/transfer/transfer.service.ts @@ -50,7 +50,7 @@ export class TransferService { let usersFileLines: UsersFile[] = []; let licensesFileLines: LicensesFile[] = []; let worktypesFileLines: WorktypesFile[] = []; - + let errorArray: string[] = []; let userIdIndex = 0; // authorIdとuserIdの対応関係を保持するMapを定義 const authorIdToUserIdMap: Map = new Map(); @@ -75,9 +75,11 @@ export class TransferService { if (line.parent_id) { parentAccountId = accountIdMap.get(line.parent_id); } - // 万が一parent_idが入力されているのに存在しなかった場合は、nullを設定する。 + // 万が一parent_idが入力されているのに存在しなかった場合は、エラー配列に追加する if (parentAccountId === undefined) { - parentAccountId = null; + errorArray.push( + `parent_id is invalid. parent_id=${line.parent_id}` + ); } // userIdIndexをインクリメントする @@ -126,8 +128,8 @@ export class TransferService { } // ライセンスのデータの作成を行う - // line.expired_dateが9999/12/31 23:59:59.997のデータの場合はデモライセンスなので登録しない - if (line.expired_date !== "9999/12/31 23:59:59.997") { + // line.expired_dateが"9999/12/31 23:59:59"のデータの場合はデモライセンスなので登録しない + if (line.expired_date !== "9999/12/31 23:59:59") { // authorIdが設定されてる場合、statusは"allocated"、allocated_user_idは対象のユーザID // されていない場合、statusは"reusable"、allocated_user_idはnull let status: string; @@ -176,6 +178,15 @@ export class TransferService { } } }); + // エラー配列に値が存在する場合はエラーファイルを出力する + if (errorArray.length > 0) { + const errorFileJson = JSON.stringify(errorArray); + fs.writeFileSync(`error.json`, errorFileJson); + throw new HttpException( + `errorArray is invalid. errorArray=${errorArray}`, + HttpStatus.BAD_REQUEST + ); + } return { accountsFileTypeLines, usersFileLines, @@ -211,24 +222,23 @@ export class TransferService { try { const relocatedAccounts: AccountsFile[] = []; - const countryRecords: Map = new Map(); + const dealerRecords: Map = new Map(); // accountsFileTypeをループ accountsFileType.forEach((account) => { - // Countryの場合はDistributorのアカウントIDと新たな親アカウントID(BC)の組み合わせをMapに登録 - if (account.type === MIGRATION_TYPE.COUNTRY) { - // 配下のDistributorアカウントを取得 - const distributor = accountsFileType.find( - (distributor) => - distributor.dealerAccountId === account.accountId && - distributor.type === MIGRATION_TYPE.DISTRIBUTOR + // Distributorの場合はdealerを検索し、COUNTRYかチェックする + if (account.type === MIGRATION_TYPE.DISTRIBUTOR) { + const distributorParent = accountsFileType.find( + (a) => a.accountId === account.dealerAccountId ); - if (distributor) { - countryRecords.set(distributor.accountId, account.dealerAccountId); + if (distributorParent.type === MIGRATION_TYPE.COUNTRY) { + dealerRecords.set( + account.accountId, + distributorParent.dealerAccountId // Countryの親、BCのIDを設定 + ); } } else { - // Country以外のアカウントの場合は、そのまま登録 - countryRecords.set(account.accountId, account.dealerAccountId); + dealerRecords.set(account.accountId, account.dealerAccountId); } }); @@ -237,7 +247,7 @@ export class TransferService { // Countryのレコードは除外する if (account.type !== MIGRATION_TYPE.COUNTRY) { const dealerAccountId = - countryRecords.get(account.dealerAccountId) ?? + dealerRecords.get(account.dealerAccountId) ?? account.dealerAccountId; const type = this.getAccountType(account.type); const newAccount: AccountsFile = {