diff --git a/.changeset/spicy-lies-count.md b/.changeset/spicy-lies-count.md new file mode 100644 index 0000000000..5454b2fc80 --- /dev/null +++ b/.changeset/spicy-lies-count.md @@ -0,0 +1,5 @@ +--- +"@scow/mis-server": patch +--- + +修复设置租户默认阈值时会无视账户阈值的问题,并增加封锁和解封账户的日志 diff --git a/apps/mis-server/src/services/tenant.ts b/apps/mis-server/src/services/tenant.ts index 485a7d2a37..5762187d87 100644 --- a/apps/mis-server/src/services/tenant.ts +++ b/apps/mis-server/src/services/tenant.ts @@ -183,10 +183,15 @@ export const tenantServiceServer = plugin((server) => { tenant.defaultAccountBlockThreshold = new Decimal(moneyToNumber(blockThresholdAmount)); // 判断租户下各账户是否使用该租户封锁阈值,使用后是否需要在集群中进行封锁 - const accounts = await em.find(Account, { tenant: tenant, blockThresholdAmount : {} }, { + const accounts = await em.find(Account, { tenant: tenant, blockThresholdAmount : undefined }, { populate: ["tenant"], }); + const blockedAccounts: string[] = []; + const blockedFailedAccounts: string[] = []; + const unBlockedAccounts: string[] = []; + const unBlockedFailedAccounts: string[] = []; + const currentActivatedClusters = await getActivatedClusters(em, logger); if (accounts.length > 0) { await Promise.allSettled(accounts @@ -202,13 +207,29 @@ export const tenantServiceServer = plugin((server) => { if (shouldBlockInCluster) { logger.info("Account %s may be out of balance when using default tenant block threshold amount. " + "Block the account.", account.accountName); - await blockAccount(account, currentActivatedClusters, server.ext.clusters, logger); + + try { + await blockAccount(account, currentActivatedClusters, server.ext.clusters, logger); + blockedAccounts.push(account.accountName); + } catch (error) { + logger.warn("Failed to block account %s in slurm: %o", account.accountName, error); + blockedFailedAccounts.push(account.accountName); + } + } if (!shouldBlockInCluster) { logger.info("The balance of Account %s is greater than the default tenant block threshold amount. " + "Unblock the account.", account.accountName); - await unblockAccount(account, currentActivatedClusters, server.ext.clusters, logger); + + try { + await unblockAccount(account, currentActivatedClusters, server.ext.clusters, logger); + unBlockedAccounts.push(account.accountName); + } catch (error) { + logger.warn("Failed to unBlock account %s in slurm: %o", account.accountName, error); + unBlockedFailedAccounts.push(account.accountName); + } + } }), ).catch((e) => { @@ -216,6 +237,13 @@ export const tenantServiceServer = plugin((server) => { }); } + + logger.info("Updated block status in slurm of the following accounts: %o", blockedAccounts); + logger.info("Updated block status failed in slurm of the following accounts: %o", blockedFailedAccounts); + + logger.info("Updated unBlock status in slurm of the following accounts: %o", unBlockedAccounts); + logger.info("Updated unBlock status failed in slurm of the following accounts: %o", unBlockedFailedAccounts); + if (accounts.length > 0) { await em.persistAndFlush([...accounts, tenant]); } else {