refactor: 退役运行时视觉模块并泛化模板门禁

This commit is contained in:
que01 committed 2026-09-26 22:30:26 +08:00
1 parent 25d1fe983c
commit e2e2340bfe
56 files changed
+290 -1037

No files matched your search

+3 -35
View File
@@ -85,15 +85,6 @@ export class TemplateWorkspaceService {
configSnapshot: templatePackageSnapshot as unknown as Prisma.InputJsonValue,
},
});
await tx.brandModule.createMany({
data: template.modules.map(({ type, title }, sortOrder) => ({
brandId,
type,
title,
sortOrder,
source: "template",
})),
});
await tx.brandFieldDefinition.createMany({
data: template.fields.map(({ scope, key, label, type, required }, sortOrder) => ({
brandId,
@@ -118,20 +109,13 @@ export class TemplateWorkspaceService {
const installation = await this.installation(brandId);
const template = getBrandTemplate(installation.templateKey);
if (!template) throw new BadRequestException("已安装模板不存在");
const [modules, fields] = await Promise.all([
this.prisma.brandModule.findMany({ where: { brandId } }),
this.prisma.brandFieldDefinition.findMany({ where: { brandId } }),
]);
const fields = await this.prisma.brandFieldDefinition.findMany({ where: { brandId } });
return {
currentVersion: installation.templateVersion,
latestVersion: template.version,
canUpgrade: installation.templateVersion !== template.version,
canRollback:
Array.isArray(installation.previousSnapshots) && installation.previousSnapshots.length > 0,
missingModules: template.modules.filter(
(item) =>
!modules.some((current) => current.type === item.type && current.source === "template"),
),
missingFields: template.fields.filter(
(item) =>
!fields.some((current) => current.scope === item.scope && current.key === item.key),
@@ -145,27 +129,11 @@ export class TemplateWorkspaceService {
if (installation.templateVersion === template.version)
throw new BadRequestException("当前模板已经是最新版本");
return this.prisma.$transaction(async (tx) => {
const [modules, fields] = await Promise.all([
tx.brandModule.findMany({ where: { brandId } }),
tx.brandFieldDefinition.findMany({ where: { brandId } }),
]);
const addedModules = template.modules.filter(
(item) =>
!modules.some((current) => current.type === item.type && current.source === "template"),
);
const fields = await tx.brandFieldDefinition.findMany({ where: { brandId } });
const addedFields = template.fields.filter(
(item) =>
!fields.some((current) => current.scope === item.scope && current.key === item.key),
);
await tx.brandModule.createMany({
data: addedModules.map(({ type, title }, index) => ({
brandId,
type,
title,
sortOrder: modules.length + index,
source: "template",
})),
});
await tx.brandFieldDefinition.createMany({
data: addedFields.map(({ scope, key, label, type, required }, index) => ({
brandId,
@@ -189,7 +157,7 @@ export class TemplateWorkspaceService {
previousSnapshots: [...history, installation.configSnapshot],
},
});
return { installation: updated, addedModules, addedFields };
return { installation: updated, addedFields };
});
}
async rollback(brandId: string) {