mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-15 07:31:19 +00:00
feat: more sub plan info;fix: emprt index (#4997)
* feat: more sub plan info * fix: emprt index * doc
This commit is contained in:
@@ -5,28 +5,9 @@ import { DatasetTypeEnum } from '@fastgpt/global/core/dataset/constants';
|
||||
import { TeamErrEnum } from '@fastgpt/global/common/error/code/team';
|
||||
import { SystemErrEnum } from '@fastgpt/global/common/error/code/system';
|
||||
import { AppTypeEnum } from '@fastgpt/global/core/app/constants';
|
||||
|
||||
export const checkDatasetLimit = async ({
|
||||
teamId,
|
||||
insertLen = 0
|
||||
}: {
|
||||
teamId: string;
|
||||
insertLen?: number;
|
||||
}) => {
|
||||
const { standardConstants, totalPoints, usedPoints, datasetMaxSize, usedDatasetSize } =
|
||||
await getTeamPlanStatus({ teamId });
|
||||
|
||||
if (!standardConstants) return;
|
||||
|
||||
if (usedDatasetSize + insertLen >= datasetMaxSize) {
|
||||
return Promise.reject(TeamErrEnum.datasetSizeNotEnough);
|
||||
}
|
||||
|
||||
if (usedPoints >= totalPoints) {
|
||||
return Promise.reject(TeamErrEnum.aiPointsNotEnough);
|
||||
}
|
||||
return;
|
||||
};
|
||||
import { MongoTeamMember } from '../user/team/teamMemberSchema';
|
||||
import { TeamMemberStatusEnum } from '@fastgpt/global/support/user/team/constant';
|
||||
import { getVectorCountByTeamId } from '../../common/vectorDB/controller';
|
||||
|
||||
export const checkTeamAIPoints = async (teamId: string) => {
|
||||
const { standardConstants, totalPoints, usedPoints } = await getTeamPlanStatus({
|
||||
@@ -45,6 +26,72 @@ export const checkTeamAIPoints = async (teamId: string) => {
|
||||
};
|
||||
};
|
||||
|
||||
export const checkTeamMemberLimit = async (teamId: string, newCount: number) => {
|
||||
const [{ standardConstants }, memberCount] = await Promise.all([
|
||||
getTeamStandPlan({
|
||||
teamId
|
||||
}),
|
||||
MongoTeamMember.countDocuments({
|
||||
teamId,
|
||||
status: { $ne: TeamMemberStatusEnum.leave }
|
||||
})
|
||||
]);
|
||||
|
||||
if (standardConstants && newCount + memberCount > standardConstants.maxTeamMember) {
|
||||
return Promise.reject(TeamErrEnum.teamOverSize);
|
||||
}
|
||||
};
|
||||
|
||||
export const checkTeamAppLimit = async (teamId: string, amount = 1) => {
|
||||
const [{ standardConstants }, appCount] = await Promise.all([
|
||||
getTeamStandPlan({ teamId }),
|
||||
MongoApp.countDocuments({
|
||||
teamId,
|
||||
type: {
|
||||
$in: [AppTypeEnum.simple, AppTypeEnum.workflow, AppTypeEnum.plugin, AppTypeEnum.tool]
|
||||
}
|
||||
})
|
||||
]);
|
||||
|
||||
if (standardConstants && appCount + amount >= standardConstants.maxAppAmount) {
|
||||
return Promise.reject(TeamErrEnum.appAmountNotEnough);
|
||||
}
|
||||
|
||||
// System check
|
||||
if (global?.licenseData?.maxApps && typeof global?.licenseData?.maxApps === 'number') {
|
||||
const totalApps = await MongoApp.countDocuments({
|
||||
type: {
|
||||
$in: [AppTypeEnum.simple, AppTypeEnum.workflow, AppTypeEnum.plugin, AppTypeEnum.tool]
|
||||
}
|
||||
});
|
||||
if (totalApps >= global.licenseData.maxApps) {
|
||||
return Promise.reject(SystemErrEnum.licenseAppAmountLimit);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const checkDatasetIndexLimit = async ({
|
||||
teamId,
|
||||
insertLen = 0
|
||||
}: {
|
||||
teamId: string;
|
||||
insertLen?: number;
|
||||
}) => {
|
||||
const [{ standardConstants, totalPoints, usedPoints, datasetMaxSize }, usedDatasetIndexSize] =
|
||||
await Promise.all([getTeamPlanStatus({ teamId }), getVectorCountByTeamId(teamId)]);
|
||||
|
||||
if (!standardConstants) return;
|
||||
|
||||
if (usedDatasetIndexSize + insertLen >= datasetMaxSize) {
|
||||
return Promise.reject(TeamErrEnum.datasetSizeNotEnough);
|
||||
}
|
||||
|
||||
if (usedPoints >= totalPoints) {
|
||||
return Promise.reject(TeamErrEnum.aiPointsNotEnough);
|
||||
}
|
||||
return;
|
||||
};
|
||||
|
||||
export const checkTeamDatasetLimit = async (teamId: string) => {
|
||||
const [{ standardConstants }, datasetCount] = await Promise.all([
|
||||
getTeamStandPlan({ teamId }),
|
||||
@@ -74,30 +121,12 @@ export const checkTeamDatasetLimit = async (teamId: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const checkTeamAppLimit = async (teamId: string, amount = 1) => {
|
||||
const [{ standardConstants }, appCount] = await Promise.all([
|
||||
getTeamStandPlan({ teamId }),
|
||||
MongoApp.countDocuments({
|
||||
teamId,
|
||||
type: {
|
||||
$in: [AppTypeEnum.simple, AppTypeEnum.workflow, AppTypeEnum.plugin, AppTypeEnum.tool]
|
||||
}
|
||||
})
|
||||
]);
|
||||
export const checkTeamWebSyncPermission = async (teamId: string) => {
|
||||
const { standardConstants } = await getTeamStandPlan({
|
||||
teamId
|
||||
});
|
||||
|
||||
if (standardConstants && appCount + amount >= standardConstants.maxAppAmount) {
|
||||
return Promise.reject(TeamErrEnum.appAmountNotEnough);
|
||||
}
|
||||
|
||||
// System check
|
||||
if (global?.licenseData?.maxApps && typeof global?.licenseData?.maxApps === 'number') {
|
||||
const totalApps = await MongoApp.countDocuments({
|
||||
type: {
|
||||
$in: [AppTypeEnum.simple, AppTypeEnum.workflow, AppTypeEnum.plugin, AppTypeEnum.tool]
|
||||
}
|
||||
});
|
||||
if (totalApps >= global.licenseData.maxApps) {
|
||||
return Promise.reject(SystemErrEnum.licenseAppAmountLimit);
|
||||
}
|
||||
if (standardConstants && !standardConstants?.permissionWebsiteSync) {
|
||||
return Promise.reject(TeamErrEnum.websiteSyncNotEnough);
|
||||
}
|
||||
};
|
||||
|
@@ -52,6 +52,9 @@ const SubSchema = new Schema({
|
||||
type: String,
|
||||
enum: Object.values(StandardSubLevelEnum)
|
||||
},
|
||||
maxTeamMember: Number,
|
||||
maxApp: Number,
|
||||
maxDataset: Number,
|
||||
|
||||
// stand sub and extra points sub. Plan total points
|
||||
totalPoints: {
|
||||
|
@@ -6,10 +6,9 @@ import {
|
||||
} from '@fastgpt/global/support/wallet/sub/constants';
|
||||
import { MongoTeamSub } from './schema';
|
||||
import {
|
||||
type FeTeamPlanStatusType,
|
||||
type TeamPlanStatusType,
|
||||
type TeamSubSchema
|
||||
} from '@fastgpt/global/support/wallet/sub/type.d';
|
||||
import { getVectorCountByTeamId } from '../../../common/vectorDB/controller';
|
||||
import dayjs from 'dayjs';
|
||||
import { type ClientSession } from '../../../common/mongo';
|
||||
import { addMonths } from 'date-fns';
|
||||
@@ -44,12 +43,21 @@ export const getTeamStandPlan = async ({ teamId }: { teamId: string }) => {
|
||||
const standardPlans = global.subPlans?.standard;
|
||||
const standard = plans[0];
|
||||
|
||||
const standardConstants =
|
||||
standard?.currentSubLevel && standardPlans
|
||||
? standardPlans[standard.currentSubLevel]
|
||||
: undefined;
|
||||
|
||||
return {
|
||||
[SubTypeEnum.standard]: standard,
|
||||
standardConstants:
|
||||
standard?.currentSubLevel && standardPlans
|
||||
? standardPlans[standard.currentSubLevel]
|
||||
: undefined
|
||||
standardConstants: standardConstants
|
||||
? {
|
||||
...standardConstants,
|
||||
maxTeamMember: standard?.maxTeamMember || standardConstants.maxTeamMember,
|
||||
maxAppAmount: standard?.maxApp || standardConstants.maxAppAmount,
|
||||
maxDatasetAmount: standard?.maxDataset || standardConstants.maxDatasetAmount
|
||||
}
|
||||
: undefined
|
||||
};
|
||||
};
|
||||
|
||||
@@ -111,14 +119,11 @@ export const getTeamPlanStatus = async ({
|
||||
teamId
|
||||
}: {
|
||||
teamId: string;
|
||||
}): Promise<FeTeamPlanStatusType> => {
|
||||
}): Promise<TeamPlanStatusType> => {
|
||||
const standardPlans = global.subPlans?.standard;
|
||||
|
||||
/* Get all plans and datasetSize */
|
||||
const [plans, usedDatasetSize] = await Promise.all([
|
||||
MongoTeamSub.find({ teamId }).lean(),
|
||||
getVectorCountByTeamId(teamId)
|
||||
]);
|
||||
const plans = await MongoTeamSub.find({ teamId }).lean();
|
||||
|
||||
/* Get all standardPlans and active standardPlan */
|
||||
const teamStandardPlans = sortStandPlans(
|
||||
@@ -158,17 +163,25 @@ export const getTeamPlanStatus = async ({
|
||||
standardMaxDatasetSize +
|
||||
extraDatasetSize.reduce((acc, cur) => acc + (cur.currentExtraDatasetSize || 0), 0);
|
||||
|
||||
const standardConstants =
|
||||
standardPlan?.currentSubLevel && standardPlans
|
||||
? standardPlans[standardPlan.currentSubLevel]
|
||||
: undefined;
|
||||
|
||||
return {
|
||||
[SubTypeEnum.standard]: standardPlan,
|
||||
standardConstants:
|
||||
standardPlan?.currentSubLevel && standardPlans
|
||||
? standardPlans[standardPlan.currentSubLevel]
|
||||
: undefined,
|
||||
standardConstants: standardConstants
|
||||
? {
|
||||
...standardConstants,
|
||||
maxTeamMember: standardPlan?.maxTeamMember || standardConstants.maxTeamMember,
|
||||
maxAppAmount: standardPlan?.maxApp || standardConstants.maxAppAmount,
|
||||
maxDatasetAmount: standardPlan?.maxDataset || standardConstants.maxDatasetAmount
|
||||
}
|
||||
: undefined,
|
||||
|
||||
totalPoints,
|
||||
usedPoints: totalPoints - surplusPoints,
|
||||
|
||||
datasetMaxSize: totalDatasetSize,
|
||||
usedDatasetSize
|
||||
datasetMaxSize: totalDatasetSize
|
||||
};
|
||||
};
|
||||
|
Reference in New Issue
Block a user