saito.k 353d5ad462 Merged PR 918: analysisLicenses修正
## 概要
[Task4313: analysisLicenses修正](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/4313)

- ライセンス推移CSVの出力内容を修正
  - 移行ライセンスの利用状況も出力する
  - 出力する移行ライセンスの条件は以下
     - 第五階層
     - 割り当て済
     - 有効期限が当日以降
     - 年間ライセンス
- テスト修正
  - 移行ライセンスの取得・変換ロジックのテスト修正

## レビューポイント
- 特になし

## UIの変更
- Before/Afterのスクショなど
- スクショ置き場

## クエリの変更
- Repositoryを変更し、クエリが変更された場合は変更内容を確認する
- Before/Afterのクエリ
- クエリ置き場

## 動作確認状況
- ローカルで確認、develop環境で確認など
- 行った修正がデグレを発生させていないことを確認できるか
  - 具体的にどのような確認をしたか
    - どのケースに対してどのような手段でデグレがないことを担保しているか

## 補足
- 相談、参考資料などがあれば
2024-07-23 03:35:55 +00:00

1925 lines
79 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { app, InvocationContext, Timer } from "@azure/functions";
import { DataSource, Between } from "typeorm";
import * as dotenv from "dotenv";
import { Account, AccountArchive } from "../entity/account.entity";
import {
License,
LicenseAllocationHistory,
LicenseArchive,
LicenseAllocationHistoryArchive,
} from "../entity/license.entity";
import { BlobstorageService } from "../blobstorage/blobstorage.service";
import {
LICENSE_ALLOCATED_STATUS,
TIERS,
SWITCH_FROM_TYPE,
LICENSE_COUNT_ANALYSIS_CATEGORY_1,
LICENSE_COUNT_ANALYSIS_LICENSE_TYPE,
LICENSE_COUNT_ANALYSIS_ROLE,
LICENSE_COUNT_ANALYSIS_CATEGORY_2,
BLOB_STORAGE_REGION_AU,
USER_ROLES,
BLOB_STORAGE_REGION_US,
BLOB_STORAGE_REGION_EU,
LICENSE_TYPE,
LICENSE_COUNT_ANALYSIS_HEADER,
LICENSE_COUNT_ANALYSIS_FRONT_STRING,
} from "../constants";
import { DateWithDayEndTime } from "../common/types/types";
import { initializeDataSource } from "../database/initializeDataSource";
import { bigintTransformer } from "../common/entity";
/**
* ライセンス数分析処理のメイン処理:ここから各処理を呼び出す
* @param myTimer
* @param context
*/
export async function analysisLicensesProcessing(
context: InvocationContext,
targetMonthYYYYMM: string,
datasource: DataSource,
blobstorageService: BlobstorageService
) {
try {
context.log("[IN]analysisLicensesProcessing");
const baseData = await getBaseData(context, targetMonthYYYYMM, datasource);
const baseDataFromDeletedAccounts = await getBaseDataFromDeletedAccounts(
context,
targetMonthYYYYMM,
datasource
);
const outputCsvData = await transferData(
context,
baseData,
baseDataFromDeletedAccounts,
targetMonthYYYYMM
);
await outputAnalysisLicensesData(
context,
blobstorageService,
outputCsvData
);
} catch (e) {
context.log("analysisLicensesProcessing failed.");
context.error(e);
throw e;
} finally {
context.log("[OUT]analysisLicensesProcessing");
}
}
/**
* 集計元のデータをDBから取得する処理
* @param context
* @param targetMonthYYYYMM
* @param datasource
* 内部関数だがテスト用にexportする
*/
export async function getBaseData(
context: InvocationContext,
targetMonthYYYYMM: string,
datasource: DataSource
): Promise<BaseData> {
try {
context.log("[IN]getBaseData");
// 第五階層のアカウントとユーザーを取得する
// 第五のアカウントを取得
const accountRepository = datasource.getRepository(Account);
const accountsAndUsersFromTier5 = await accountRepository.find({
where: {
tier: TIERS.TIER5,
},
relations: {
user: true,
userArchive: true,
},
});
// 第五階層が保持する有効なライセンスを取得
const licenseRepository = datasource.getRepository(License);
// 現在時刻を起点とした23:59:59の日付
const currentDateWithDayEndTime = new DateWithDayEndTime();
const avairableLicenses = await licenseRepository
.createQueryBuilder("license")
.innerJoin("license.account", "account")
.where("account.tier = :tier", { tier: TIERS.TIER5 })
.andWhere(
"(license.expiry_date > :currentDateWithDayEndTime OR license.expiry_date IS NULL)",
{
currentDateWithDayEndTime,
}
)
.andWhere("license.status IN (:...statuses)", {
statuses: [
LICENSE_ALLOCATED_STATUS.UNALLOCATED,
LICENSE_ALLOCATED_STATUS.ALLOCATED,
LICENSE_ALLOCATED_STATUS.REUSABLE,
],
})
.getMany();
// 第五階層が保持するその月に発行したライセンスを取得
// timestamp型のDB列をyyyymm形式に変換する場合RDBMS依存の処理が必要になるので、最初の日最後の日のbetweenで判断する
const year = parseInt(targetMonthYYYYMM.slice(0, 4), 10);
const month = parseInt(targetMonthYYYYMM.slice(4), 10) - 1; // JavaScriptの月は0-indexed
const targetMonthStartDate = new Date(year, month, 1, 0, 0, 0, 0);
const targetMonthEndDate = new Date(year, month + 1, 0, 23, 59, 59, 0); // mysql上ミリ秒999を指定すると四捨五入されて翌日になってしまうのでミリ秒は0を指定
const licensesIssuedInTargetMonth = await licenseRepository
.createQueryBuilder("license")
.innerJoin("license.account", "account")
.where("account.tier = :tier", { tier: TIERS.TIER5 })
.andWhere({
created_at: Between(targetMonthStartDate, targetMonthEndDate),
})
.andWhere("license.status IN (:...statuses)", {
statuses: [
LICENSE_ALLOCATED_STATUS.UNALLOCATED,
LICENSE_ALLOCATED_STATUS.ALLOCATED,
LICENSE_ALLOCATED_STATUS.REUSABLE,
],
})
.getMany();
// 第五階層が保持するその月に失効したライセンスを取得
const licensesExpiredInTargetMonth = await licenseRepository
.createQueryBuilder("license")
.innerJoin("license.account", "account")
.where("account.tier = :tier", { tier: TIERS.TIER5 })
.andWhere({
expiry_date: Between(targetMonthStartDate, targetMonthEndDate),
})
.andWhere("license.status IN (:...statuses)", {
statuses: [
LICENSE_ALLOCATED_STATUS.UNALLOCATED,
LICENSE_ALLOCATED_STATUS.ALLOCATED,
LICENSE_ALLOCATED_STATUS.REUSABLE,
],
})
.getMany();
// 第五階層がその月におこなったライセンス切り替え情報を取得
const licenseAllocationHistory = datasource.getRepository(
LicenseAllocationHistory
);
const switchedlicensesInTargetMonth = await licenseAllocationHistory
.createQueryBuilder("licenseAllocationHistory")
.innerJoin(
"accounts",
"account",
"licenseAllocationHistory.account_id = account.id"
)
.where("account.tier = :tier", { tier: TIERS.TIER5 })
.andWhere("licenseAllocationHistory.switch_from_type IN (:...types)", {
types: [SWITCH_FROM_TYPE.CARD, SWITCH_FROM_TYPE.TRIAL],
})
.andWhere({
executed_at: Between(targetMonthStartDate, targetMonthEndDate),
})
.getMany();
return {
accountsAndUsersFromTier5,
avairableLicenses,
licensesIssuedInTargetMonth,
licensesExpiredInTargetMonth,
switchedlicensesInTargetMonth,
};
} catch (e) {
context.log("getBaseData failed.");
context.error(e);
throw e;
} finally {
context.log("[OUT]getBaseData");
}
}
/**
* 集計元のデータ削除されたアカウントの情報をDBから取得する処理
* @param context
* @param targetMonthYYYYMM
* @param datasource
* 内部関数だがテスト用にexportする
*/
export async function getBaseDataFromDeletedAccounts(
context: InvocationContext,
targetMonthYYYYMM: string,
datasource: DataSource
): Promise<BaseDataFromDeletedAccounts> {
try {
context.log("[IN]getBaseDataFromDeletedAccounts");
// 第五階層のアカウントとユーザーを取得する
// 第五のアカウントを取得
const accountArchiveRepository = datasource.getRepository(AccountArchive);
const deletedAccountsAndUsersFromTier5 =
await accountArchiveRepository.find({
where: {
tier: TIERS.TIER5,
},
relations: { userArchive: true },
});
// 第五階層が保持する有効なライセンスを取得
const licenseArchiveRepository = datasource.getRepository(LicenseArchive);
// 現在時刻を起点とした23:59:59の日付
const currentDateWithDayEndTime = new DateWithDayEndTime();
const deletedAvairableLicenses = await licenseArchiveRepository
.createQueryBuilder("license_archive")
.innerJoin("license_archive.accountArchive", "accountArchive")
.where("accountArchive.tier = :tier", { tier: TIERS.TIER5 })
.andWhere(
"(license_archive.expiry_date > :currentDateWithDayEndTime OR license_archive.expiry_date IS NULL)",
{
currentDateWithDayEndTime,
}
)
.andWhere("license_archive.status IN (:...statuses)", {
statuses: [
LICENSE_ALLOCATED_STATUS.UNALLOCATED,
LICENSE_ALLOCATED_STATUS.ALLOCATED,
LICENSE_ALLOCATED_STATUS.REUSABLE,
],
})
.getMany();
// 第五階層が保持するその月に発行したライセンスを取得
// timestamp型のDB列をyyyymm形式に変換する場合RDBMS依存の処理が必要になるので、最初の日最後の日のbetweenで判断する
const year = parseInt(targetMonthYYYYMM.slice(0, 4), 10);
const month = parseInt(targetMonthYYYYMM.slice(4), 10) - 1; // JavaScriptの月は0-indexed
const targetMonthStartDate = new Date(year, month, 1, 0, 0, 0, 0);
const targetMonthEndDate = new Date(year, month + 1, 0, 23, 59, 59, 0); // mysql上ミリ秒999を指定すると四捨五入されて翌日になってしまうのでミリ秒は0を指定
const deletedLicensesIssuedInTargetMonth = await licenseArchiveRepository
.createQueryBuilder("license_archive")
.innerJoin("license_archive.accountArchive", "accountArchive")
.where("accountArchive.tier = :tier", { tier: TIERS.TIER5 })
.andWhere({
created_at: Between(targetMonthStartDate, targetMonthEndDate),
})
.andWhere("license_archive.status IN (:...statuses)", {
statuses: [
LICENSE_ALLOCATED_STATUS.UNALLOCATED,
LICENSE_ALLOCATED_STATUS.ALLOCATED,
LICENSE_ALLOCATED_STATUS.REUSABLE,
],
})
.getMany();
// 第五階層が保持するその月に失効したライセンスを取得
const deletedLicensesExpiredInTargetMonth = await licenseArchiveRepository
.createQueryBuilder("license_archive")
.innerJoin("license_archive.accountArchive", "accountArchive")
.where("accountArchive.tier = :tier", { tier: TIERS.TIER5 })
.andWhere({
expiry_date: Between(targetMonthStartDate, targetMonthEndDate),
})
.andWhere("license_archive.status IN (:...statuses)", {
statuses: [
LICENSE_ALLOCATED_STATUS.UNALLOCATED,
LICENSE_ALLOCATED_STATUS.ALLOCATED,
LICENSE_ALLOCATED_STATUS.REUSABLE,
],
})
.getMany();
// 第五階層がその月におこなったライセンス切り替え情報を取得
const licenseAllocationHistoryArchive = datasource.getRepository(
LicenseAllocationHistoryArchive
);
const deletedSwitchedlicensesInTargetMonth =
await licenseAllocationHistoryArchive
.createQueryBuilder("licenseAllocationHistory_archive")
.innerJoinAndSelect(
"licenseAllocationHistory_archive.userArchive",
"userArchive"
)
.innerJoin("userArchive.accountArchive", "accountArchive")
.where("accountArchive.tier = :tier", { tier: TIERS.TIER5 })
.andWhere(
"licenseAllocationHistory_archive.switch_from_type IN (:...types)",
{
types: [SWITCH_FROM_TYPE.CARD, SWITCH_FROM_TYPE.TRIAL],
}
)
.andWhere({
executed_at: Between(targetMonthStartDate, targetMonthEndDate),
})
.getMany();
return {
deletedAccountsAndUsersFromTier5,
deletedAvairableLicenses,
deletedLicensesIssuedInTargetMonth,
deletedLicensesExpiredInTargetMonth,
deletedSwitchedlicensesInTargetMonth,
};
} catch (e) {
context.log("getBaseDataFromDeletedAccounts failed.");
context.error(e);
throw e;
} finally {
context.log("[OUT]getBaseDataFromDeletedAccounts");
}
}
/**
* ライセンス数分析処理Azure Functionの関数として呼び出される処理
* @param myTimer
* @param context
*/
export async function analysisLicenses(
myTimer: Timer,
context: InvocationContext
): Promise<void> {
context.log("[IN]analysisLicenses");
dotenv.config({ path: ".env" });
dotenv.config({ path: ".env.local", override: true });
try {
const datasource = await initializeDataSource(context);
const blobstorageService = new BlobstorageService(true);
try {
// 現在の日付より、先月の年月をYYYYMM形式で取得
const currentDate = new Date();
currentDate.setMonth(currentDate.getMonth() - 1);
const year = currentDate.getFullYear();
const month = (currentDate.getMonth() + 1).toString().padStart(2, "0"); // 月は0から始まるため+1する
const formattedDate = `${year}${month}`;
await analysisLicensesProcessing(
context,
formattedDate,
datasource,
blobstorageService
);
} catch (e) {
context.log("analysisLicensesProcessing failed.");
context.error(e);
throw e;
}
} finally {
context.log("[OUT]analysisLicenses");
}
}
app.timer("analysisLicenses", {
schedule: "0 0 0 1 * *",
handler: analysisLicenses,
});
type BaseData = {
// 存在するアカウントの集計元情報
accountsAndUsersFromTier5: Account[];
avairableLicenses: License[];
licensesIssuedInTargetMonth: License[];
licensesExpiredInTargetMonth: License[];
switchedlicensesInTargetMonth: LicenseAllocationHistory[];
};
type BaseDataFromDeletedAccounts = {
// 削除されたアカウントの集計元情報
deletedAccountsAndUsersFromTier5: AccountArchive[];
deletedAvairableLicenses: LicenseArchive[];
deletedLicensesIssuedInTargetMonth: LicenseArchive[];
deletedLicensesExpiredInTargetMonth: LicenseArchive[];
deletedSwitchedlicensesInTargetMonth: LicenseAllocationHistoryArchive[];
};
type outputDataAnalysisLicensesCSV = {
outputDataUS: string[];
outputDataEU: string[];
outputDataAU: string[];
};
/**
* アカウントと紐づくユーザー、ライセンスからCSV出力用の配列を作成する
* @param context
* @param baseData
* @param baseDataFromDeletedAccounts
* @param targetMonthYYYYMM
* @returns outputDataAnalysisLicensesCSV
*/
export async function transferData(
context: InvocationContext,
baseData: BaseData,
baseDataFromDeletedAccounts: BaseDataFromDeletedAccounts,
targetMonthYYYYMM: string
): Promise<outputDataAnalysisLicensesCSV> {
context.log("[IN]transferData");
const accountsAndUsersFromTier5 = baseData.accountsAndUsersFromTier5;
const validLicenses = baseData.avairableLicenses;
const currentMonthIssuedLicenses = baseData.licensesIssuedInTargetMonth;
const invalidLicenses = baseData.licensesExpiredInTargetMonth;
const switchedLicenses = baseData.switchedlicensesInTargetMonth;
const deletedAccountsAndUsersFromTier5 =
baseDataFromDeletedAccounts.deletedAccountsAndUsersFromTier5;
const deletedValidLicenses =
baseDataFromDeletedAccounts.deletedAvairableLicenses;
const deletedCurrentMonthIssuedLicenses =
baseDataFromDeletedAccounts.deletedLicensesIssuedInTargetMonth;
const deletedInvalidLicenses =
baseDataFromDeletedAccounts.deletedLicensesExpiredInTargetMonth;
const deletedSwitchedLicenses =
baseDataFromDeletedAccounts.deletedSwitchedlicensesInTargetMonth;
// 出力データ格納配列
let outputDataUS: string[] = [];
let outputDataEU: string[] = [];
let outputDataAU: string[] = [];
// 出力データのヘッダーを作成
const header = [
'"' + LICENSE_COUNT_ANALYSIS_HEADER.ACCOUNT + '",',
'"' + LICENSE_COUNT_ANALYSIS_HEADER.TARGET_YEAE_AND_MONTH + '",',
'"' + LICENSE_COUNT_ANALYSIS_HEADER.CATEGORY_1 + '",',
'"' + LICENSE_COUNT_ANALYSIS_HEADER.CATEGORY_2 + '",',
'"' + LICENSE_COUNT_ANALYSIS_HEADER.LICENSE_TYPE + '",',
'"' + LICENSE_COUNT_ANALYSIS_HEADER.ROLE + '",',
'"' + LICENSE_COUNT_ANALYSIS_HEADER.COUNT + '"\r\n',
] as string[];
// ヘッダーを出力データに追加
outputDataUS.push(...header);
outputDataEU.push(...header);
outputDataAU.push(...header);
// ユーザーIDとロールを格納する配列型が違う為新たに作成する
let tier5userIdAndRoles: { id: number; role: string }[] = [];
try {
// 第五階層のアカウントごとにループ
for (const account of accountsAndUsersFromTier5) {
// account.userとaccount.userArchiveが存在しない場合次のアカウントに進む
if (!account.user && !account.userArchive) {
console.log(
"account.user and account.userArchive is not exist.accountId:" +
account.id
);
continue;
}
// ユーザーとユーザーアーカイブからユーザーIDとロールを取得する
if (account.user) {
tier5userIdAndRoles = account.user.map((user) => {
// XXX entityを修正すべきだが、時期的に影響範囲が大きいため、ここで変換する
// 本対応は#3928で行う
return { id: bigintTransformer.from(user.id), role: user.role };
});
}
if (account.userArchive) {
tier5userIdAndRoles = tier5userIdAndRoles.concat(
account.userArchive.map((userArchive) => {
// XXX entityを修正すべきだが、時期的に影響範囲が大きいため、ここで変換する
// 本対応は#3928で行う
return {
id: bigintTransformer.from(userArchive.id),
role: userArchive.role,
};
})
);
}
// アカウントに紐づくライセンスを取得
const accountLicenses = validLicenses.filter(
(license) => license.account_id === account.id
);
// 抽出したライセンスを種別ごとに分ける。typeカラムで判別トライアル・通常・カード
// 種別にNoneを追加⇒旧システムからの移行分の状況も確認したい 2024年7月9日
const trialLicenses = accountLicenses.filter(
(license) => license.type === LICENSE_TYPE.TRIAL
);
const normalLicenses = accountLicenses.filter(
(license) => license.type === LICENSE_TYPE.NORMAL
);
const cardLicenses = accountLicenses.filter(
(license) => license.type === LICENSE_TYPE.CARD
);
const noneLicense = accountLicenses.filter(
(license) => license.type === LICENSE_TYPE.NONE
);
// 種別ごとのライセンスから使用中のライセンスを抽出statusカラムがAllocated
const usedTrialLicenses = trialLicenses.filter(
(license) => license.status === LICENSE_ALLOCATED_STATUS.ALLOCATED
);
const usedNormalLicenses = normalLicenses.filter(
(license) => license.status === LICENSE_ALLOCATED_STATUS.ALLOCATED
);
const usedCardLicenses = cardLicenses.filter(
(license) => license.status === LICENSE_ALLOCATED_STATUS.ALLOCATED
);
const usedNoneLicense = noneLicense.filter(
(license) => license.status === LICENSE_ALLOCATED_STATUS.ALLOCATED
);
// どのロールのユーザーが使用しているライセンスかを判別し、ロールごとに分ける。
// allcated_user_idからユーザーを特定
// (Author・Typist・None)
const usedTrialLicensesAuthor = usedTrialLicenses.filter((license) =>
tier5userIdAndRoles.find(
(user) =>
user.id === license.allocated_user_id &&
user.role === USER_ROLES.AUTHOR
)
);
const usedTrialLicensesTypist = usedTrialLicenses.filter((license) =>
tier5userIdAndRoles.find(
(user) =>
user.id === license.allocated_user_id &&
user.role === USER_ROLES.TYPIST
)
);
const usedTrialLicensesNone = usedTrialLicenses.filter((license) =>
tier5userIdAndRoles.find(
(user) =>
user.id === license.allocated_user_id &&
user.role === USER_ROLES.NONE
)
);
const usedNormalLicensesAuthor = usedNormalLicenses.filter((license) =>
tier5userIdAndRoles.find(
(user) =>
user.id === license.allocated_user_id &&
user.role === USER_ROLES.AUTHOR
)
);
const usedNormalLicensesTypist = usedNormalLicenses.filter((license) =>
tier5userIdAndRoles.find(
(user) =>
user.id === license.allocated_user_id &&
user.role === USER_ROLES.TYPIST
)
);
const usedNormalLicensesNone = usedNormalLicenses.filter((license) =>
tier5userIdAndRoles.find(
(user) =>
user.id === license.allocated_user_id &&
user.role === USER_ROLES.NONE
)
);
const usedCardLicensesAuthor = usedCardLicenses.filter((license) =>
tier5userIdAndRoles.find(
(user) =>
user.id === license.allocated_user_id &&
user.role === USER_ROLES.AUTHOR
)
);
const usedCardLicensesTypist = usedCardLicenses.filter((license) =>
tier5userIdAndRoles.find(
(user) =>
user.id === license.allocated_user_id &&
user.role === USER_ROLES.TYPIST
)
);
const usedCardLicensesNone = usedCardLicenses.filter((license) =>
tier5userIdAndRoles.find(
(user) =>
user.id === license.allocated_user_id &&
user.role === USER_ROLES.NONE
)
);
// 使用中のライセンスの数をカウント
const trialLicensesCount = trialLicenses.length;
const normalLicensesCount = normalLicenses.length;
const cardLicensesCount = cardLicenses.length;
const usedTrialLicensesAuthorCount = usedTrialLicensesAuthor.length;
const usedTrialLicensesTypistCount = usedTrialLicensesTypist.length;
const usedTrialLicensesNoneCount = usedTrialLicensesNone.length;
const usedNormalLicensesAuthorCount = usedNormalLicensesAuthor.length;
const usedNormalLicensesTypistCount = usedNormalLicensesTypist.length;
const usedNormalLicensesNoneCount = usedNormalLicensesNone.length;
const usedCardLicensesAuthorCount = usedCardLicensesAuthor.length;
const usedCardLicensesTypistCount = usedCardLicensesTypist.length;
const usedCardLicensesNoneCount = usedCardLicensesNone.length;
const usedNoneLicenseCount = usedNoneLicense.length;
// アカウントに紐づく当月発行ライセンスを取得
const accountCurrentMonthIssuedLicenses =
currentMonthIssuedLicenses.filter(
(license) => license.account_id === account.id
);
// 当月発行ライセンスを種別ごとに分ける。typeカラムで判別トライアル・通常・カード
const currentMonthIssuedTrialLicenses =
accountCurrentMonthIssuedLicenses.filter(
(license) => license.type === LICENSE_TYPE.TRIAL
);
const currentMonthIssuedNormalLicenses =
accountCurrentMonthIssuedLicenses.filter(
(license) => license.type === LICENSE_TYPE.NORMAL
);
const currentMonthIssuedCardLicenses =
accountCurrentMonthIssuedLicenses.filter(
(license) => license.type === LICENSE_TYPE.CARD
);
// 当月発行ライセンスの数をカウント
const currentMonthIssuedTrialLicensesCount =
currentMonthIssuedTrialLicenses.length;
const currentMonthIssuedNormalLicensesCount =
currentMonthIssuedNormalLicenses.length;
const currentMonthIssuedCardLicensesCount =
currentMonthIssuedCardLicenses.length;
// アカウントに紐づく失効ライセンスを取得
const accountInvalidLicenses = invalidLicenses.filter(
(license) => license.account_id === account.id
);
// 失効ライセンスを種別ごとに分ける。typeカラムで判別トライアル・通常・カード
const invalidTrialLicenses = accountInvalidLicenses.filter(
(license) => license.type === LICENSE_TYPE.TRIAL
);
const invalidNormalLicenses = accountInvalidLicenses.filter(
(license) => license.type === LICENSE_TYPE.NORMAL
);
const invalidCardLicenses = accountInvalidLicenses.filter(
(license) => license.type === LICENSE_TYPE.CARD
);
// どのロールのユーザーに割り当てたまま失効したライセンスかを判別し、ロールごとに分ける。
//allcated_user_idからユーザーを特定、値がない場合は未割当
// (Author・Typist・None・未割当)
const invalidTrialLicensesAuthor = invalidTrialLicenses.filter(
(license) =>
tier5userIdAndRoles.find(
(user) =>
user.id === license.allocated_user_id &&
user.role === USER_ROLES.AUTHOR
)
);
const invalidTrialLicensesTypist = invalidTrialLicenses.filter(
(license) =>
tier5userIdAndRoles.find(
(user) =>
user.id === license.allocated_user_id &&
user.role === USER_ROLES.TYPIST
)
);
const invalidTrialLicensesNone = invalidTrialLicenses.filter((license) =>
tier5userIdAndRoles.find(
(user) =>
user.id === license.allocated_user_id &&
user.role === USER_ROLES.NONE
)
);
const invalidNormalLicensesAuthor = invalidNormalLicenses.filter(
(license) =>
tier5userIdAndRoles.find(
(user) =>
user.id === license.allocated_user_id &&
user.role === USER_ROLES.AUTHOR
)
);
const invalidNormalLicensesTypist = invalidNormalLicenses.filter(
(license) =>
tier5userIdAndRoles.find(
(user) =>
user.id === license.allocated_user_id &&
user.role === USER_ROLES.TYPIST
)
);
const invalidNormalLicensesNone = invalidNormalLicenses.filter(
(license) =>
tier5userIdAndRoles.find(
(user) =>
user.id === license.allocated_user_id &&
user.role === USER_ROLES.NONE
)
);
const invalidCardLicensesAuthor = invalidCardLicenses.filter((license) =>
tier5userIdAndRoles.find(
(user) =>
user.id === license.allocated_user_id &&
user.role === USER_ROLES.AUTHOR
)
);
const invalidCardLicensesTypist = invalidCardLicenses.filter((license) =>
tier5userIdAndRoles.find(
(user) =>
user.id === license.allocated_user_id &&
user.role === USER_ROLES.TYPIST
)
);
const invalidCardLicensesNone = invalidCardLicenses.filter((license) =>
tier5userIdAndRoles.find(
(user) =>
user.id === license.allocated_user_id &&
user.role === USER_ROLES.NONE
)
);
const invalidTrialLicensesUnallocated = invalidTrialLicenses.filter(
(license) => !license.allocated_user_id
);
const invalidNormalLicensesUnallocated = invalidNormalLicenses.filter(
(license) => !license.allocated_user_id
);
const invalidCardLicensesUnallocated = invalidCardLicenses.filter(
(license) => !license.allocated_user_id
);
// 失効ライセンスの数をカウント
const invalidTrialLicensesAuthorCount = invalidTrialLicensesAuthor.length;
const invalidTrialLicensesTypistCount = invalidTrialLicensesTypist.length;
const invalidTrialLicensesNoneCount = invalidTrialLicensesNone.length;
const invalidTrialLicensesUnallocatedCount =
invalidTrialLicensesUnallocated.length;
const invalidNormalLicensesAuthorCount =
invalidNormalLicensesAuthor.length;
const invalidNormalLicensesTypistCount =
invalidNormalLicensesTypist.length;
const invalidNormalLicensesNoneCount = invalidNormalLicensesNone.length;
const invalidNormalLicensesUnallocatedCount =
invalidNormalLicensesUnallocated.length;
const invalidCardLicensesAuthorCount = invalidCardLicensesAuthor.length;
const invalidCardLicensesTypistCount = invalidCardLicensesTypist.length;
const invalidCardLicensesNoneCount = invalidCardLicensesNone.length;
const invalidCardLicensesUnallocatedCount =
invalidCardLicensesUnallocated.length;
// アカウントに紐づく切り替えライセンスを取得
const accountSwitchedLicenses = switchedLicenses.filter(
(license) => license.account_id === account.id
);
// どの種別のライセンスから切り替えられたかで分けるswitch_from_typeカラムで判別トライアル・カード
const switchedTrialLicenses = accountSwitchedLicenses.filter(
(license) => license.switch_from_type === SWITCH_FROM_TYPE.TRIAL
);
const switchedCardLicenses = accountSwitchedLicenses.filter(
(license) => license.switch_from_type === SWITCH_FROM_TYPE.CARD
);
// どのロールのユーザーに対して切り替えが行われたかで分ける。
//user_idからユーザーを特定
//Typist・Author・None
const switchedTypistLicensesTypist = switchedTrialLicenses.filter(
(license) =>
tier5userIdAndRoles.find(
(user) =>
// XXX entityを修正すべきだが、時期的に影響範囲が大きいため、ここで変換する
// 本対応は#3928で行う
user.id === bigintTransformer.from(license.user_id) &&
user.role === USER_ROLES.TYPIST
)
);
const switchedTypistLicensesAuthor = switchedTrialLicenses.filter(
(license) =>
tier5userIdAndRoles.find(
(user) =>
// XXX entityを修正すべきだが、時期的に影響範囲が大きいため、ここで変換する
// 本対応は#3928で行う
user.id === bigintTransformer.from(license.user_id) &&
user.role === USER_ROLES.AUTHOR
)
);
const switchedTypistLicensesNone = switchedTrialLicenses.filter(
(license) =>
tier5userIdAndRoles.find(
(user) =>
// XXX entityを修正すべきだが、時期的に影響範囲が大きいため、ここで変換する
// 本対応は#3928で行う
user.id === bigintTransformer.from(license.user_id) &&
user.role === USER_ROLES.NONE
)
);
const switchedCardLicensesTypist = switchedCardLicenses.filter(
(license) =>
tier5userIdAndRoles.find(
(user) =>
// XXX entityを修正すべきだが、時期的に影響範囲が大きいため、ここで変換する
// 本対応は#3928で行う
user.id === bigintTransformer.from(license.user_id) &&
user.role === USER_ROLES.TYPIST
)
);
const switchedCardLicensesAuthor = switchedCardLicenses.filter(
(license) =>
tier5userIdAndRoles.find(
(user) =>
// XXX entityを修正すべきだが、時期的に影響範囲が大きいため、ここで変換する
// 本対応は#3928で行う
user.id === bigintTransformer.from(license.user_id) &&
user.role === USER_ROLES.AUTHOR
)
);
const switchedCardLicensesNone = switchedCardLicenses.filter((license) =>
tier5userIdAndRoles.find(
(user) =>
// XXX entityを修正すべきだが、時期的に影響範囲が大きいため、ここで変換する
// 本対応は#3928で行う
user.id === bigintTransformer.from(license.user_id) &&
user.role === USER_ROLES.NONE
)
);
// 切り替えライセンスの数をカウント
const switchedTypistLicensesTypistCount =
switchedTypistLicensesTypist.length;
const switchedTypistLicensesAuthorCount =
switchedTypistLicensesAuthor.length;
const switchedTypistLicensesNoneCount = switchedTypistLicensesNone.length;
const switchedCardLicensesTypistCount = switchedCardLicensesTypist.length;
const switchedCardLicensesAuthorCount = switchedCardLicensesAuthor.length;
const switchedCardLicensesNoneCount = switchedCardLicensesNone.length;
// 国に対応したリージョンに応じた配列に格納する
if (BLOB_STORAGE_REGION_US.includes(account.country)) {
outputDataUS = outputDataUS.concat(
await createOutputData(
context,
account.company_name,
targetMonthYYYYMM,
trialLicensesCount,
normalLicensesCount,
cardLicensesCount,
usedNoneLicenseCount,
usedTrialLicensesAuthorCount,
usedTrialLicensesTypistCount,
usedTrialLicensesNoneCount,
usedNormalLicensesAuthorCount,
usedNormalLicensesTypistCount,
usedNormalLicensesNoneCount,
usedCardLicensesAuthorCount,
usedCardLicensesTypistCount,
usedCardLicensesNoneCount,
currentMonthIssuedTrialLicensesCount,
currentMonthIssuedNormalLicensesCount,
currentMonthIssuedCardLicensesCount,
invalidTrialLicensesAuthorCount,
invalidTrialLicensesTypistCount,
invalidTrialLicensesNoneCount,
invalidTrialLicensesUnallocatedCount,
invalidNormalLicensesAuthorCount,
invalidNormalLicensesTypistCount,
invalidNormalLicensesNoneCount,
invalidNormalLicensesUnallocatedCount,
invalidCardLicensesAuthorCount,
invalidCardLicensesTypistCount,
invalidCardLicensesNoneCount,
invalidCardLicensesUnallocatedCount,
switchedTypistLicensesAuthorCount,
switchedTypistLicensesTypistCount,
switchedTypistLicensesNoneCount,
switchedCardLicensesAuthorCount,
switchedCardLicensesTypistCount,
switchedCardLicensesNoneCount
)
);
} else if (BLOB_STORAGE_REGION_EU.includes(account.country)) {
outputDataEU = outputDataEU.concat(
await createOutputData(
context,
account.company_name,
targetMonthYYYYMM,
trialLicensesCount,
normalLicensesCount,
cardLicensesCount,
usedNoneLicenseCount,
usedTrialLicensesAuthorCount,
usedTrialLicensesTypistCount,
usedTrialLicensesNoneCount,
usedNormalLicensesAuthorCount,
usedNormalLicensesTypistCount,
usedNormalLicensesNoneCount,
usedCardLicensesAuthorCount,
usedCardLicensesTypistCount,
usedCardLicensesNoneCount,
currentMonthIssuedTrialLicensesCount,
currentMonthIssuedNormalLicensesCount,
currentMonthIssuedCardLicensesCount,
invalidTrialLicensesAuthorCount,
invalidTrialLicensesTypistCount,
invalidTrialLicensesNoneCount,
invalidTrialLicensesUnallocatedCount,
invalidNormalLicensesAuthorCount,
invalidNormalLicensesTypistCount,
invalidNormalLicensesNoneCount,
invalidNormalLicensesUnallocatedCount,
invalidCardLicensesAuthorCount,
invalidCardLicensesTypistCount,
invalidCardLicensesNoneCount,
invalidCardLicensesUnallocatedCount,
switchedTypistLicensesAuthorCount,
switchedTypistLicensesTypistCount,
switchedTypistLicensesNoneCount,
switchedCardLicensesAuthorCount,
switchedCardLicensesTypistCount,
switchedCardLicensesNoneCount
)
);
} else if (BLOB_STORAGE_REGION_AU.includes(account.country)) {
outputDataAU = outputDataAU.concat(
await createOutputData(
context,
account.company_name,
targetMonthYYYYMM,
trialLicensesCount,
normalLicensesCount,
cardLicensesCount,
usedNoneLicenseCount,
usedTrialLicensesAuthorCount,
usedTrialLicensesTypistCount,
usedTrialLicensesNoneCount,
usedNormalLicensesAuthorCount,
usedNormalLicensesTypistCount,
usedNormalLicensesNoneCount,
usedCardLicensesAuthorCount,
usedCardLicensesTypistCount,
usedCardLicensesNoneCount,
currentMonthIssuedTrialLicensesCount,
currentMonthIssuedNormalLicensesCount,
currentMonthIssuedCardLicensesCount,
invalidTrialLicensesAuthorCount,
invalidTrialLicensesTypistCount,
invalidTrialLicensesNoneCount,
invalidTrialLicensesUnallocatedCount,
invalidNormalLicensesAuthorCount,
invalidNormalLicensesTypistCount,
invalidNormalLicensesNoneCount,
invalidNormalLicensesUnallocatedCount,
invalidCardLicensesAuthorCount,
invalidCardLicensesTypistCount,
invalidCardLicensesNoneCount,
invalidCardLicensesUnallocatedCount,
switchedTypistLicensesAuthorCount,
switchedTypistLicensesTypistCount,
switchedTypistLicensesNoneCount,
switchedCardLicensesAuthorCount,
switchedCardLicensesTypistCount,
switchedCardLicensesNoneCount
)
);
} else {
throw new Error("invalid country");
}
}
// 削除版
tier5userIdAndRoles = [];
// 第五階層のアカウントごとにループ
for (const account of deletedAccountsAndUsersFromTier5) {
// account.userArchiveが存在しない場合次のアカウントに進む
if (!account.userArchive) {
continue;
}
// アカウントに紐づくユーザーを取得
if (account.userArchive) {
tier5userIdAndRoles = account.userArchive.map((userArchive) => {
return {
// XXX entityを修正すべきだが、時期的に影響範囲が大きいため、ここで変換する
// 本対応は#3928で行う
id: bigintTransformer.from(userArchive.id),
role: userArchive.role,
};
});
}
// アカウントに紐づくライセンスを取得
const accountLicenses = deletedValidLicenses.filter(
(license) => license.account_id === account.id
);
// 抽出したライセンスを種別ごとに分ける。typeカラムで判別トライアル・通常・カード
// 種別にNoneを追加⇒旧システムからの移行分の状況も確認したい 2024年7月9日
const trialLicenses = accountLicenses.filter(
(license) => license.type === LICENSE_TYPE.TRIAL
);
const normalLicenses = accountLicenses.filter(
(license) => license.type === LICENSE_TYPE.NORMAL
);
const cardLicenses = accountLicenses.filter(
(license) => license.type === LICENSE_TYPE.CARD
);
const noneLicense = accountLicenses.filter(
(license) => license.type === LICENSE_TYPE.NONE
);
// 種別ごとのライセンスから使用中のライセンスを抽出statusカラムがAllocated
const usedTrialLicenses = trialLicenses.filter(
(license) => license.status === LICENSE_ALLOCATED_STATUS.ALLOCATED
);
const usedNormalLicenses = normalLicenses.filter(
(license) => license.status === LICENSE_ALLOCATED_STATUS.ALLOCATED
);
const usedCardLicenses = cardLicenses.filter(
(license) => license.status === LICENSE_ALLOCATED_STATUS.ALLOCATED
);
const usedNoneLicense = noneLicense.filter(
(license) => (license.status === LICENSE_ALLOCATED_STATUS.ALLOCATED)
);
// どのロールのユーザーが使用しているライセンスかを判別し、ロールごとに分ける。
// allcated_user_idからユーザーを特定
// (Author・Typist・None)
const usedTrialLicensesAuthor = usedTrialLicenses.filter(
(license) =>
tier5userIdAndRoles?.find(
(user) => user.id === license.allocated_user_id
)?.role === USER_ROLES.AUTHOR
);
const usedTrialLicensesTypist = usedTrialLicenses.filter(
(license) =>
tier5userIdAndRoles?.find(
(user) => user.id === license.allocated_user_id
)?.role === USER_ROLES.TYPIST
);
const usedTrialLicensesNone = usedTrialLicenses.filter(
(license) =>
tier5userIdAndRoles?.find(
(user) => user.id === license.allocated_user_id
)?.role === USER_ROLES.NONE
);
const usedNormalLicensesAuthor = usedNormalLicenses.filter(
(license) =>
tier5userIdAndRoles?.find(
(user) => user.id === license.allocated_user_id
)?.role === USER_ROLES.AUTHOR
);
const usedNormalLicensesTypist = usedNormalLicenses.filter(
(license) =>
tier5userIdAndRoles?.find(
(user) => user.id === license.allocated_user_id
)?.role === USER_ROLES.TYPIST
);
const usedNormalLicensesNone = usedNormalLicenses.filter(
(license) =>
tier5userIdAndRoles?.find(
(user) => user.id === license.allocated_user_id
)?.role === USER_ROLES.NONE
);
const usedCardLicensesAuthor = usedCardLicenses.filter(
(license) =>
tier5userIdAndRoles?.find(
(user) => user.id === license.allocated_user_id
)?.role === USER_ROLES.AUTHOR
);
const usedCardLicensesTypist = usedCardLicenses.filter(
(license) =>
tier5userIdAndRoles?.find(
(user) => user.id === license.allocated_user_id
)?.role === USER_ROLES.TYPIST
);
const usedCardLicensesNone = usedCardLicenses.filter(
(license) =>
tier5userIdAndRoles?.find(
(user) => user.id === license.allocated_user_id
)?.role === USER_ROLES.NONE
);
// 使用中のライセンスの数をカウント
const trialLicensesCount = trialLicenses.length;
const normalLicensesCount = normalLicenses.length;
const cardLicensesCount = cardLicenses.length;
const usedTrialLicensesAuthorCount = usedTrialLicensesAuthor.length;
const usedTrialLicensesTypistCount = usedTrialLicensesTypist.length;
const usedTrialLicensesNoneCount = usedTrialLicensesNone.length;
const usedNormalLicensesAuthorCount = usedNormalLicensesAuthor.length;
const usedNormalLicensesTypistCount = usedNormalLicensesTypist.length;
const usedNormalLicensesNoneCount = usedNormalLicensesNone.length;
const usedCardLicensesAuthorCount = usedCardLicensesAuthor.length;
const usedCardLicensesTypistCount = usedCardLicensesTypist.length;
const usedCardLicensesNoneCount = usedCardLicensesNone.length;
const usedNoneLicenseCount = usedNoneLicense.length;
// アカウントに紐づく当月発行ライセンスを取得
const accountCurrentMonthIssuedLicenses =
deletedCurrentMonthIssuedLicenses.filter(
(license) => license.account_id === account.id
);
// 当月発行ライセンスを種別ごとに分ける。typeカラムで判別トライアル・通常・カード
const currentMonthIssuedTrialLicenses =
accountCurrentMonthIssuedLicenses.filter(
(license) => license.type === LICENSE_TYPE.TRIAL
);
const currentMonthIssuedNormalLicenses =
accountCurrentMonthIssuedLicenses.filter(
(license) => license.type === LICENSE_TYPE.NORMAL
);
const currentMonthIssuedCardLicenses =
accountCurrentMonthIssuedLicenses.filter(
(license) => license.type === LICENSE_TYPE.CARD
);
// 当月発行ライセンスの数をカウント
const currentMonthIssuedTrialLicensesCount =
currentMonthIssuedTrialLicenses.length;
const currentMonthIssuedNormalLicensesCount =
currentMonthIssuedNormalLicenses.length;
const currentMonthIssuedCardLicensesCount =
currentMonthIssuedCardLicenses.length;
// アカウントに紐づく失効ライセンスを取得
const accountInvalidLicenses = deletedInvalidLicenses.filter(
(license) => license.account_id === account.id
);
// 失効ライセンスを種別ごとに分ける。typeカラムで判別トライアル・通常・カード
const invalidTrialLicenses = accountInvalidLicenses.filter(
(license) => license.type === LICENSE_TYPE.TRIAL
);
const invalidNormalLicenses = accountInvalidLicenses.filter(
(license) => license.type === LICENSE_TYPE.NORMAL
);
const invalidCardLicenses = accountInvalidLicenses.filter(
(license) => license.type === LICENSE_TYPE.CARD
);
// どのロールのユーザーに割り当てたまま失効したライセンスかを判別し、ロールごとに分ける。
//allcated_user_idからユーザーを特定、値がない場合は未割当
// (Author・Typist・None・未割当)
const invalidTrialLicensesAuthor = invalidTrialLicenses.filter(
(license) =>
tier5userIdAndRoles?.find(
(user) => user.id === license.allocated_user_id
)?.role === USER_ROLES.AUTHOR
);
const invalidTrialLicensesTypist = invalidTrialLicenses.filter(
(license) =>
tier5userIdAndRoles?.find(
(user) => user.id === license.allocated_user_id
)?.role === USER_ROLES.TYPIST
);
const invalidTrialLicensesNone = invalidTrialLicenses.filter(
(license) =>
tier5userIdAndRoles?.find(
(user) => user.id === license.allocated_user_id
)?.role === USER_ROLES.NONE
);
const invalidNormalLicensesAuthor = invalidNormalLicenses.filter(
(license) =>
tier5userIdAndRoles?.find(
(user) => user.id === license.allocated_user_id
)?.role === USER_ROLES.AUTHOR
);
const invalidNormalLicensesTypist = invalidNormalLicenses.filter(
(license) =>
tier5userIdAndRoles?.find(
(user) => user.id === license.allocated_user_id
)?.role === USER_ROLES.TYPIST
);
const invalidNormalLicensesNone = invalidNormalLicenses.filter(
(license) =>
tier5userIdAndRoles?.find(
(user) => user.id === license.allocated_user_id
)?.role === USER_ROLES.NONE
);
const invalidCardLicensesAuthor = invalidCardLicenses.filter(
(license) =>
tier5userIdAndRoles?.find(
(user) => user.id === license.allocated_user_id
)?.role === USER_ROLES.AUTHOR
);
const invalidCardLicensesTypist = invalidCardLicenses.filter(
(license) =>
tier5userIdAndRoles?.find(
(user) => user.id === license.allocated_user_id
)?.role === USER_ROLES.TYPIST
);
const invalidCardLicensesNone = invalidCardLicenses.filter(
(license) =>
tier5userIdAndRoles?.find(
(user) => user.id === license.allocated_user_id
)?.role === USER_ROLES.NONE
);
const invalidTrialLicensesUnallocated = invalidTrialLicenses.filter(
(license) => !license.allocated_user_id
);
const invalidNormalLicensesUnallocated = invalidNormalLicenses.filter(
(license) => !license.allocated_user_id
);
const invalidCardLicensesUnallocated = invalidCardLicenses.filter(
(license) => !license.allocated_user_id
);
// 失効ライセンスの数をカウント
const invalidTrialLicensesAuthorCount = invalidTrialLicensesAuthor.length;
const invalidTrialLicensesTypistCount = invalidTrialLicensesTypist.length;
const invalidTrialLicensesNoneCount = invalidTrialLicensesNone.length;
const invalidTrialLicensesUnallocatedCount =
invalidTrialLicensesUnallocated.length;
const invalidNormalLicensesAuthorCount =
invalidNormalLicensesAuthor.length;
const invalidNormalLicensesTypistCount =
invalidNormalLicensesTypist.length;
const invalidNormalLicensesNoneCount = invalidNormalLicensesNone.length;
const invalidNormalLicensesUnallocatedCount =
invalidNormalLicensesUnallocated.length;
const invalidCardLicensesAuthorCount = invalidCardLicensesAuthor.length;
const invalidCardLicensesTypistCount = invalidCardLicensesTypist.length;
const invalidCardLicensesNoneCount = invalidCardLicensesNone.length;
const invalidCardLicensesUnallocatedCount =
invalidCardLicensesUnallocated.length;
// アカウントに紐づく切り替えライセンスを取得
const accountSwitchedLicenses = deletedSwitchedLicenses.filter(
(license) => license.account_id === account.id
);
// どの種別のライセンスから切り替えられたかで分けるswitch_from_typeカラムで判別トライアル・カード
const switchedTrialLicenses = accountSwitchedLicenses.filter(
(license) => license.switch_from_type === SWITCH_FROM_TYPE.TRIAL
);
const switchedCardLicenses = accountSwitchedLicenses.filter(
(license) => license.switch_from_type === SWITCH_FROM_TYPE.CARD
);
// どのロールのユーザーに対して切り替えが行われたかで分ける。
//user_idからユーザーを特定
//Typist・Author・None
const switchedTypistLicensesTypist = switchedTrialLicenses.filter(
(license) =>
// XXX entityを修正すべきだが、時期的に影響範囲が大きいため、ここで変換する
// 本対応は#3928で行う
tier5userIdAndRoles?.find(
(user) => user.id === bigintTransformer.from(license.user_id)
)?.role === USER_ROLES.TYPIST
);
const switchedTypistLicensesAuthor = switchedTrialLicenses.filter(
(license) =>
// XXX entityを修正すべきだが、時期的に影響範囲が大きいため、ここで変換する
// 本対応は#3928で行う
tier5userIdAndRoles?.find(
(user) => user.id === bigintTransformer.from(license.user_id)
)?.role === USER_ROLES.AUTHOR
);
const switchedTypistLicensesNone = switchedTrialLicenses.filter(
(license) =>
// XXX entityを修正すべきだが、時期的に影響範囲が大きいため、ここで変換する
// 本対応は#3928で行う
tier5userIdAndRoles?.find(
(user) => user.id === bigintTransformer.from(license.user_id)
)?.role === USER_ROLES.NONE
);
const switchedCardLicensesTypist = switchedCardLicenses.filter(
(license) =>
// XXX entityを修正すべきだが、時期的に影響範囲が大きいため、ここで変換する
// 本対応は#3928で行う
tier5userIdAndRoles?.find(
(user) => user.id === bigintTransformer.from(license.user_id)
)?.role === USER_ROLES.TYPIST
);
const switchedCardLicensesAuthor = switchedCardLicenses.filter(
(license) =>
// XXX entityを修正すべきだが、時期的に影響範囲が大きいため、ここで変換する
// 本対応は#3928で行う
tier5userIdAndRoles?.find(
(user) => user.id === bigintTransformer.from(license.user_id)
)?.role === USER_ROLES.AUTHOR
);
const switchedCardLicensesNone = switchedCardLicenses.filter(
(license) =>
// XXX entityを修正すべきだが、時期的に影響範囲が大きいため、ここで変換する
// 本対応は#3928で行う
tier5userIdAndRoles?.find(
(user) => user.id === bigintTransformer.from(license.user_id)
)?.role === USER_ROLES.NONE
);
// 切り替えライセンスの数をカウント
const switchedTypistLicensesTypistCount =
switchedTypistLicensesTypist.length;
const switchedTypistLicensesAuthorCount =
switchedTypistLicensesAuthor.length;
const switchedTypistLicensesNoneCount = switchedTypistLicensesNone.length;
const switchedCardLicensesTypistCount = switchedCardLicensesTypist.length;
const switchedCardLicensesAuthorCount = switchedCardLicensesAuthor.length;
const switchedCardLicensesNoneCount = switchedCardLicensesNone.length;
// 国に対応したリージョンに応じた配列に格納する
if (BLOB_STORAGE_REGION_US.includes(account.country)) {
outputDataUS = outputDataUS.concat(
await createOutputData(
context,
account.id.toString(),
targetMonthYYYYMM,
trialLicensesCount,
normalLicensesCount,
cardLicensesCount,
usedNoneLicenseCount,
usedTrialLicensesAuthorCount,
usedTrialLicensesTypistCount,
usedTrialLicensesNoneCount,
usedNormalLicensesAuthorCount,
usedNormalLicensesTypistCount,
usedNormalLicensesNoneCount,
usedCardLicensesAuthorCount,
usedCardLicensesTypistCount,
usedCardLicensesNoneCount,
currentMonthIssuedTrialLicensesCount,
currentMonthIssuedNormalLicensesCount,
currentMonthIssuedCardLicensesCount,
invalidTrialLicensesAuthorCount,
invalidTrialLicensesTypistCount,
invalidTrialLicensesNoneCount,
invalidTrialLicensesUnallocatedCount,
invalidNormalLicensesAuthorCount,
invalidNormalLicensesTypistCount,
invalidNormalLicensesNoneCount,
invalidNormalLicensesUnallocatedCount,
invalidCardLicensesAuthorCount,
invalidCardLicensesTypistCount,
invalidCardLicensesNoneCount,
invalidCardLicensesUnallocatedCount,
switchedTypistLicensesAuthorCount,
switchedTypistLicensesTypistCount,
switchedTypistLicensesNoneCount,
switchedCardLicensesAuthorCount,
switchedCardLicensesTypistCount,
switchedCardLicensesNoneCount
)
);
} else if (BLOB_STORAGE_REGION_EU.includes(account.country)) {
outputDataEU = outputDataEU.concat(
await createOutputData(
context,
account.id.toString(),
targetMonthYYYYMM,
trialLicensesCount,
normalLicensesCount,
cardLicensesCount,
usedNoneLicenseCount,
usedTrialLicensesAuthorCount,
usedTrialLicensesTypistCount,
usedTrialLicensesNoneCount,
usedNormalLicensesAuthorCount,
usedNormalLicensesTypistCount,
usedNormalLicensesNoneCount,
usedCardLicensesAuthorCount,
usedCardLicensesTypistCount,
usedCardLicensesNoneCount,
currentMonthIssuedTrialLicensesCount,
currentMonthIssuedNormalLicensesCount,
currentMonthIssuedCardLicensesCount,
invalidTrialLicensesAuthorCount,
invalidTrialLicensesTypistCount,
invalidTrialLicensesNoneCount,
invalidTrialLicensesUnallocatedCount,
invalidNormalLicensesAuthorCount,
invalidNormalLicensesTypistCount,
invalidNormalLicensesNoneCount,
invalidNormalLicensesUnallocatedCount,
invalidCardLicensesAuthorCount,
invalidCardLicensesTypistCount,
invalidCardLicensesNoneCount,
invalidCardLicensesUnallocatedCount,
switchedTypistLicensesAuthorCount,
switchedTypistLicensesTypistCount,
switchedTypistLicensesNoneCount,
switchedCardLicensesAuthorCount,
switchedCardLicensesTypistCount,
switchedCardLicensesNoneCount
)
);
} else if (BLOB_STORAGE_REGION_AU.includes(account.country)) {
outputDataAU = outputDataAU.concat(
await createOutputData(
context,
account.id.toString(),
targetMonthYYYYMM,
trialLicensesCount,
normalLicensesCount,
cardLicensesCount,
usedNoneLicenseCount,
usedTrialLicensesAuthorCount,
usedTrialLicensesTypistCount,
usedTrialLicensesNoneCount,
usedNormalLicensesAuthorCount,
usedNormalLicensesTypistCount,
usedNormalLicensesNoneCount,
usedCardLicensesAuthorCount,
usedCardLicensesTypistCount,
usedCardLicensesNoneCount,
currentMonthIssuedTrialLicensesCount,
currentMonthIssuedNormalLicensesCount,
currentMonthIssuedCardLicensesCount,
invalidTrialLicensesAuthorCount,
invalidTrialLicensesTypistCount,
invalidTrialLicensesNoneCount,
invalidTrialLicensesUnallocatedCount,
invalidNormalLicensesAuthorCount,
invalidNormalLicensesTypistCount,
invalidNormalLicensesNoneCount,
invalidNormalLicensesUnallocatedCount,
invalidCardLicensesAuthorCount,
invalidCardLicensesTypistCount,
invalidCardLicensesNoneCount,
invalidCardLicensesUnallocatedCount,
switchedTypistLicensesAuthorCount,
switchedTypistLicensesTypistCount,
switchedTypistLicensesNoneCount,
switchedCardLicensesAuthorCount,
switchedCardLicensesTypistCount,
switchedCardLicensesNoneCount
)
);
}
}
return {
outputDataUS: outputDataUS,
outputDataEU: outputDataEU,
outputDataAU: outputDataAU,
};
} catch (e) {
context.log("transferData failed.");
context.error(e);
throw e;
} finally {
context.log("[OUT]transferData");
}
}
/**
* 出力データ作成
* @param context
* @param company_name
* @param targetMonthYYYYMM
* @param trialLicensesCount
* @param normalLicensesCount
* @param cardLicensesCount
* @param usedTrialLicensesAuthorCount
* @param usedTrialLicensesTypistCount
* @param usedTrialLicensesNoneCount
* @param usedNormalLicensesAuthorCount
* @param usedNormalLicensesTypistCount
* @param usedNormalLicensesNoneCount
* @param usedCardLicensesAuthorCount
* @param usedCardLicensesTypistCount
* @param usedCardLicensesNoneCount
* @param currentMonthIssuedTrialLicensesCount
* @param currentMonthIssuedNormalLicensesCount
* @param currentMonthIssuedCardLicensesCount
* @param invalidTrialLicensesAuthorCount
* @param invalidTrialLicensesTypistCount
* @param invalidTrialLicensesNoneCount
* @param invalidTrialLicensesUnallocatedCount
* @param invalidNormalLicensesAuthorCount
* @param invalidNormalLicensesTypistCount
* @param invalidNormalLicensesNoneCount
* @param invalidNormalLicensesUnallocatedCount
* @param invalidCardLicensesAuthorCount
* @param invalidCardLicensesTypistCount
* @param invalidCardLicensesNoneCount
* @param invalidCardLicensesUnallocatedCount
* @param switchedTypistLicensesAuthorCount
* @param switchedTypistLicensesTypistCount
* @param switchedTypistLicensesNoneCount
* @param switchedCardLicensesAuthorCount
* @param switchedCardLicensesTypistCount
* @param switchedCardLicensesNoneCount
* @returns string[]
*/
async function createOutputData(
context: InvocationContext,
company_name: string,
targetMonthYYYYMM: string,
trialLicensesCount: number,
normalLicensesCount: number,
cardLicensesCount: number,
usedNoneLicenseCount: number,
usedTrialLicensesAuthorCount: number,
usedTrialLicensesTypistCount: number,
usedTrialLicensesNoneCount: number,
usedNormalLicensesAuthorCount: number,
usedNormalLicensesTypistCount: number,
usedNormalLicensesNoneCount: number,
usedCardLicensesAuthorCount: number,
usedCardLicensesTypistCount: number,
usedCardLicensesNoneCount: number,
currentMonthIssuedTrialLicensesCount: number,
currentMonthIssuedNormalLicensesCount: number,
currentMonthIssuedCardLicensesCount: number,
invalidTrialLicensesAuthorCount: number,
invalidTrialLicensesTypistCount: number,
invalidTrialLicensesNoneCount: number,
invalidTrialLicensesUnallocatedCount: number,
invalidNormalLicensesAuthorCount: number,
invalidNormalLicensesTypistCount: number,
invalidNormalLicensesNoneCount: number,
invalidNormalLicensesUnallocatedCount: number,
invalidCardLicensesAuthorCount: number,
invalidCardLicensesTypistCount: number,
invalidCardLicensesNoneCount: number,
invalidCardLicensesUnallocatedCount: number,
switchedTypistLicensesAuthorCount: number,
switchedTypistLicensesTypistCount: number,
switchedTypistLicensesNoneCount: number,
switchedCardLicensesAuthorCount: number,
switchedCardLicensesTypistCount: number,
switchedCardLicensesNoneCount: number
): Promise<string[]> {
context.log("[IN]createOutputData");
const resultOutputData: string[] = [];
try {
// アカウントが保持するトライアルライセンス[]
resultOutputData.push(
// 会社名(ダブルクォーテーションで囲む)
'"' + company_name + '",',
// 対象年月先月YYYYMM
// 2024年3月に実行した場合202402
'"' + targetMonthYYYYMM + '",',
// カテゴリー1
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.VALID_LICENSES + '",',
// カテゴリー2
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_2.OWNER_LICENSES + '",',
// ライセンス種別
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.TRIAL + '",',
// 役割
'"' + "" + '",',
// 数量
'"' + trialLicensesCount.toString() + '"\r\n'
);
// アカウントが保持する通常ライセンス[]
resultOutputData.push(
'"' + company_name + '",',
'"' + targetMonthYYYYMM + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.VALID_LICENSES + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_2.OWNER_LICENSES + '",',
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.STANDARD + '",',
'"' + "" + '",',
'"' + normalLicensesCount.toString() + '"\r\n'
);
// アカウントが保持するカードライセンス[]
resultOutputData.push(
'"' + company_name + '",',
'"' + targetMonthYYYYMM + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.VALID_LICENSES + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_2.OWNER_LICENSES + '",',
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.CARD + '",',
'"' + "" + '",',
'"' + cardLicensesCount.toString() + '"\r\n'
);
// ユーザーが使用中の移行ライセンス
resultOutputData.push(
'"' + company_name + '",',
'"' + targetMonthYYYYMM + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.VALID_LICENSES + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_2.IN_USE_LICENSES + '",',
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.NONE + '",',
'"' + "" + '",',
'"' + usedNoneLicenseCount.toString() + '"\r\n'
);
// Authorが使用中のトライアルライセンス[]
resultOutputData.push(
'"' + company_name + '",',
'"' + targetMonthYYYYMM + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.VALID_LICENSES + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_2.IN_USE_LICENSES + '",',
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.TRIAL + '",',
'"' + LICENSE_COUNT_ANALYSIS_ROLE.AUTHOR + '",',
'"' + usedTrialLicensesAuthorCount.toString() + '"\r\n'
);
// Typistが使用中のトライアルライセンス[]
resultOutputData.push(
'"' + company_name + '",',
'"' + targetMonthYYYYMM + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.VALID_LICENSES + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_2.IN_USE_LICENSES + '",',
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.TRIAL + '",',
'"' + LICENSE_COUNT_ANALYSIS_ROLE.TYPIST + '",',
'"' + usedTrialLicensesTypistCount.toString() + '"\r\n'
);
// Noneが使用中のトライアルライセンス[]
resultOutputData.push(
'"' + company_name + '",',
'"' + targetMonthYYYYMM + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.VALID_LICENSES + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_2.IN_USE_LICENSES + '",',
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.TRIAL + '",',
'"' + LICENSE_COUNT_ANALYSIS_ROLE.NONE + '",',
'"' + usedTrialLicensesNoneCount.toString() + '"\r\n'
);
// Authorが使用中の通常ライセンス[]
resultOutputData.push(
'"' + company_name + '",',
'"' + targetMonthYYYYMM + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.VALID_LICENSES + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_2.IN_USE_LICENSES + '",',
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.STANDARD + '",',
'"' + LICENSE_COUNT_ANALYSIS_ROLE.AUTHOR + '",',
'"' + usedNormalLicensesAuthorCount.toString() + '"\r\n'
);
// Typistが使用中の通常ライセンス[]
resultOutputData.push(
'"' + company_name + '",',
'"' + targetMonthYYYYMM + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.VALID_LICENSES + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_2.IN_USE_LICENSES + '",',
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.STANDARD + '",',
'"' + LICENSE_COUNT_ANALYSIS_ROLE.TYPIST + '",',
'"' + usedNormalLicensesTypistCount.toString() + '"\r\n'
);
// Noneが使用中の通常ライセンス[]
resultOutputData.push(
'"' + company_name + '",',
'"' + targetMonthYYYYMM + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.VALID_LICENSES + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_2.IN_USE_LICENSES + '",',
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.STANDARD + '",',
'"' + LICENSE_COUNT_ANALYSIS_ROLE.NONE + '",',
'"' + usedNormalLicensesNoneCount.toString() + '"\r\n'
);
// Authorが使用中のカードライセンス[]
resultOutputData.push(
'"' + company_name + '",',
'"' + targetMonthYYYYMM + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.VALID_LICENSES + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_2.IN_USE_LICENSES + '",',
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.CARD + '",',
'"' + LICENSE_COUNT_ANALYSIS_ROLE.AUTHOR + '",',
'"' + usedCardLicensesAuthorCount.toString() + '"\r\n'
);
// Typistが使用中のカードライセンス[]
resultOutputData.push(
'"' + company_name + '",',
'"' + targetMonthYYYYMM + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.VALID_LICENSES + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_2.IN_USE_LICENSES + '",',
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.CARD + '",',
'"' + LICENSE_COUNT_ANALYSIS_ROLE.TYPIST + '",',
'"' + usedCardLicensesTypistCount.toString() + '"\r\n'
);
// Noneが使用中のカードライセンス[]
resultOutputData.push(
'"' + company_name + '",',
'"' + targetMonthYYYYMM + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.VALID_LICENSES + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_2.IN_USE_LICENSES + '",',
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.CARD + '",',
'"' + LICENSE_COUNT_ANALYSIS_ROLE.NONE + '",',
'"' + usedCardLicensesNoneCount.toString() + '"\r\n'
);
// アカウントが保持する当月発行トライアルライセンス[]
resultOutputData.push(
'"' + company_name + '",',
'"' + targetMonthYYYYMM + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.NEW_ISSUE_LICENSES + '",',
'"' + "" + '",',
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.TRIAL + '",',
'"' + "" + '",',
'"' + currentMonthIssuedTrialLicensesCount.toString() + '"\r\n'
);
// アカウントが保持する当月発行通常ライセンス[]
resultOutputData.push(
'"' + company_name + '",',
'"' + targetMonthYYYYMM + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.NEW_ISSUE_LICENSES + '",',
'"' + "" + '",',
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.STANDARD + '",',
'"' + "" + '",',
'"' + currentMonthIssuedNormalLicensesCount.toString() + '"\r\n'
);
// アカウントが保持する当月発行カードライセンス[]
resultOutputData.push(
'"' + company_name + '",',
'"' + targetMonthYYYYMM + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.NEW_ISSUE_LICENSES + '",',
'"' + "" + '",',
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.CARD + '",',
'"' + "" + '",',
'"' + currentMonthIssuedCardLicensesCount.toString() + '"\r\n'
);
// Authorに割り当てられたままの失効トライアルライセンス[]
resultOutputData.push(
'"' + company_name + '",',
'"' + targetMonthYYYYMM + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.INVALID_LICENSES + '",',
'"' + "" + '",',
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.TRIAL + '",',
'"' + LICENSE_COUNT_ANALYSIS_ROLE.AUTHOR + '",',
'"' + invalidTrialLicensesAuthorCount.toString() + '"\r\n'
);
// Typistに割り当てられたままの失効トライアルライセンス[]
resultOutputData.push(
'"' + company_name + '",',
'"' + targetMonthYYYYMM + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.INVALID_LICENSES + '",',
'"' + "" + '",',
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.TRIAL + '",',
'"' + LICENSE_COUNT_ANALYSIS_ROLE.TYPIST + '",',
'"' + invalidTrialLicensesTypistCount.toString() + '"\r\n'
);
// Noneに割り当てられたままの失効トライアルライセンス[]
resultOutputData.push(
'"' + company_name + '",',
'"' + targetMonthYYYYMM + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.INVALID_LICENSES + '",',
'"' + "" + '",',
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.TRIAL + '",',
'"' + LICENSE_COUNT_ANALYSIS_ROLE.NONE + '",',
'"' + invalidTrialLicensesNoneCount.toString() + '"\r\n'
);
// 未割当の失効トライアルライセンス[]
resultOutputData.push(
'"' + company_name + '",',
'"' + targetMonthYYYYMM + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.INVALID_LICENSES + '",',
'"' + "" + '",',
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.TRIAL + '",',
'"' + LICENSE_COUNT_ANALYSIS_ROLE.UNALLOCATED + '",',
'"' + invalidTrialLicensesUnallocatedCount.toString() + '"\r\n'
);
// Authorに割り当てられたままの失効通常ライセンス[]
resultOutputData.push(
'"' + company_name + '",',
'"' + targetMonthYYYYMM + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.INVALID_LICENSES + '",',
'"' + "" + '",',
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.STANDARD + '",',
'"' + LICENSE_COUNT_ANALYSIS_ROLE.AUTHOR + '",',
'"' + invalidNormalLicensesAuthorCount.toString() + '"\r\n'
);
// Typistに割り当てられたままの失効通常ライセンス[]
resultOutputData.push(
'"' + company_name + '",',
'"' + targetMonthYYYYMM + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.INVALID_LICENSES + '",',
'"' + "" + '",',
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.STANDARD + '",',
'"' + LICENSE_COUNT_ANALYSIS_ROLE.TYPIST + '",',
'"' + invalidNormalLicensesTypistCount.toString() + '"\r\n'
);
// Noneに割り当てられたままの失効通常ライセンス[]
resultOutputData.push(
'"' + company_name + '",',
'"' + targetMonthYYYYMM + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.INVALID_LICENSES + '",',
'"' + "" + '",',
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.STANDARD + '",',
'"' + LICENSE_COUNT_ANALYSIS_ROLE.NONE + '",',
'"' + invalidNormalLicensesNoneCount.toString() + '"\r\n'
);
// 未割当の失効通常ライセンス[]
resultOutputData.push(
'"' + company_name + '",',
'"' + targetMonthYYYYMM + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.INVALID_LICENSES + '",',
'"' + "" + '",',
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.STANDARD + '",',
'"' + LICENSE_COUNT_ANALYSIS_ROLE.UNALLOCATED + '",',
'"' + invalidNormalLicensesUnallocatedCount.toString() + '"\r\n'
);
// Authorに割り当てられたままの失効カードライセンス[]
resultOutputData.push(
'"' + company_name + '",',
'"' + targetMonthYYYYMM + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.INVALID_LICENSES + '",',
'"' + "" + '",',
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.CARD + '",',
'"' + LICENSE_COUNT_ANALYSIS_ROLE.AUTHOR + '",',
'"' + invalidCardLicensesAuthorCount.toString() + '"\r\n'
);
// Typistに割り当てられたままの失効カードライセンス[]
resultOutputData.push(
'"' + company_name + '",',
'"' + targetMonthYYYYMM + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.INVALID_LICENSES + '",',
'"' + "" + '",',
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.CARD + '",',
'"' + LICENSE_COUNT_ANALYSIS_ROLE.TYPIST + '",',
'"' + invalidCardLicensesTypistCount.toString() + '"\r\n'
);
// Noneに割り当てられたままの失効カードライセンス[]
resultOutputData.push(
'"' + company_name + '",',
'"' + targetMonthYYYYMM + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.INVALID_LICENSES + '",',
'"' + "" + '",',
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.CARD + '",',
'"' + LICENSE_COUNT_ANALYSIS_ROLE.NONE + '",',
'"' + invalidCardLicensesNoneCount.toString() + '"\r\n'
);
// 未割当の失効カードライセンス[]
resultOutputData.push(
'"' + company_name + '",',
'"' + targetMonthYYYYMM + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.INVALID_LICENSES + '",',
'"' + "" + '",',
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.CARD + '",',
'"' + LICENSE_COUNT_ANALYSIS_ROLE.UNALLOCATED + '",',
'"' + invalidCardLicensesUnallocatedCount.toString() + '"\r\n'
);
// Authorにトライアルライセンスからの切り替え[]
resultOutputData.push(
'"' + company_name + '",',
'"' + targetMonthYYYYMM + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.VALID_LICENSES + '",',
'"' + "" + '",',
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.SWITCH_FROM_TRIAL + '",',
'"' + LICENSE_COUNT_ANALYSIS_ROLE.AUTHOR + '",',
'"' + switchedTypistLicensesAuthorCount.toString() + '"\r\n'
);
// Typistにトライアルライセンスからの切り替え[]
resultOutputData.push(
'"' + company_name + '",',
'"' + targetMonthYYYYMM + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.VALID_LICENSES + '",',
'"' + "" + '",',
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.SWITCH_FROM_TRIAL + '",',
'"' + LICENSE_COUNT_ANALYSIS_ROLE.TYPIST + '",',
'"' + switchedTypistLicensesTypistCount.toString() + '"\r\n'
);
// Noneにトライアルライセンスからの切り替え[]
resultOutputData.push(
'"' + company_name + '",',
'"' + targetMonthYYYYMM + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.VALID_LICENSES + '",',
'"' + "" + '",',
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.SWITCH_FROM_TRIAL + '",',
'"' + LICENSE_COUNT_ANALYSIS_ROLE.NONE + '",',
'"' + switchedTypistLicensesNoneCount.toString() + '"\r\n'
);
// Authorにカードライセンスからの切り替え[]
resultOutputData.push(
'"' + company_name + '",',
'"' + targetMonthYYYYMM + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.VALID_LICENSES + '",',
'"' + "" + '",',
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.SWITCH_FROM_CARD + '",',
'"' + LICENSE_COUNT_ANALYSIS_ROLE.AUTHOR + '",',
'"' + switchedCardLicensesAuthorCount.toString() + '"\r\n'
);
// Typistにカードライセンスからの切り替え[]
resultOutputData.push(
'"' + company_name + '",',
'"' + targetMonthYYYYMM + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.VALID_LICENSES + '",',
'"' + "" + '",',
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.SWITCH_FROM_CARD + '",',
'"' + LICENSE_COUNT_ANALYSIS_ROLE.TYPIST + '",',
'"' + switchedCardLicensesTypistCount.toString() + '"\r\n'
);
// Noneにカードライセンスからの切り替え[]
resultOutputData.push(
'"' + company_name + '",',
'"' + targetMonthYYYYMM + '",',
'"' + LICENSE_COUNT_ANALYSIS_CATEGORY_1.VALID_LICENSES + '",',
'"' + "" + '",',
'"' + LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.SWITCH_FROM_CARD + '",',
'"' + LICENSE_COUNT_ANALYSIS_ROLE.NONE + '",',
'"' + switchedCardLicensesNoneCount.toString() + '"\r\n'
);
return resultOutputData;
} catch (e) {
context.log("createOutputData failed.");
context.error(e);
throw e;
} finally {
context.log("[OUT]createOutputData");
}
}
/**
* 出力データを第一階層のストレージアカウントにCSVファイルとして出力する
* @param context
* @param blobstorageService: BlobstorageService,
* @param outputCsvData: outputDataAnalysisLicensesCSV
*/
export async function outputAnalysisLicensesData(
context: InvocationContext,
blobstorageService: BlobstorageService,
outputCsvData: outputDataAnalysisLicensesCSV
): Promise<boolean> {
context.log("[IN]outputAnalysisLicensesData");
try {
let csvContentUS = "";
let csvContentEU = "";
let csvContentAU = "";
// 出力日時を取得
const outputDateTime = new Date().toISOString();
// YYYYMMDDHH24MISS形式に変換
const outputDateTimeYYYYMMDDHH24MISS = outputDateTime.replace(/[-T:]/g, "");
// 出力ファイル名を作成
const outputFileNameUS =
LICENSE_COUNT_ANALYSIS_FRONT_STRING +
`_US_${outputDateTimeYYYYMMDDHH24MISS}.csv`;
const outputFileNameEU =
LICENSE_COUNT_ANALYSIS_FRONT_STRING +
`_EU_${outputDateTimeYYYYMMDDHH24MISS}.csv`;
const outputFileNameAU =
LICENSE_COUNT_ANALYSIS_FRONT_STRING +
`_AU_${outputDateTimeYYYYMMDDHH24MISS}.csv`;
// outputDataUSの配列をCSV形式に変換
for (let i = 0; i < outputCsvData.outputDataUS.length; i++) {
//カンマ区切りの文字列を作成
csvContentUS += outputCsvData.outputDataUS[i];
}
// outputDataEUの配列をCSV形式に変換
for (let i = 0; i < outputCsvData.outputDataEU.length; i++) {
//カンマ区切りの文字列を作成
csvContentEU += outputCsvData.outputDataEU[i];
}
// outputDataAUの配列をCSV形式に変換
for (let i = 0; i < outputCsvData.outputDataAU.length; i++) {
//カンマ区切りの文字列を作成
csvContentAU += outputCsvData.outputDataAU[i];
}
await blobstorageService.createContainerAnalysis(context);
// 出力ファイル名を指定して出力
const resultUS = await blobstorageService.uploadFileAnalysisLicensesCSV(
context,
outputFileNameUS,
csvContentUS
);
const resultEU = await blobstorageService.uploadFileAnalysisLicensesCSV(
context,
outputFileNameEU,
csvContentEU
);
const resultAU = await blobstorageService.uploadFileAnalysisLicensesCSV(
context,
outputFileNameAU,
csvContentAU
);
// 出力結果を返却
// 3つのリージョンの出力が全て成功した場合にtrueを返却
return resultUS && resultEU && resultAU;
} catch (e) {
context.log("outputAnalysisLicensesData failed.");
context.error(e);
throw e;
} finally {
context.log("[OUT]outputAnalysisLicensesData");
}
}