feat: 完成模板管理阶段4闭环

This commit is contained in:
que01 committed 2026-10-17 13:56:19 +08:00
1 parent b1e8012ded
commit d1958a7d7f
26 files changed
+1179 -310

No files matched your search

@@ -0,0 +1,43 @@
-- AlterTable
ALTER TABLE "BrandTemplateInstallation" ADD COLUMN "contentChecksum" TEXT,
ADD COLUMN "templatePackageVersionId" TEXT,
ADD COLUMN "visualTemplateKey" TEXT;
-- CreateTable
CREATE TABLE "TemplateBootstrapImport" (
"id" TEXT NOT NULL,
"brandId" TEXT NOT NULL,
"templatePackageVersionId" TEXT NOT NULL,
"packageKey" TEXT NOT NULL,
"packageVersion" TEXT NOT NULL,
"contentChecksum" TEXT NOT NULL,
"actorId" TEXT NOT NULL,
"strategy" TEXT NOT NULL DEFAULT 'missing_only',
"status" TEXT NOT NULL,
"result" JSONB,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "TemplateBootstrapImport_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE INDEX "BrandTemplateInstallation_templatePackageVersionId_idx" ON "BrandTemplateInstallation"("templatePackageVersionId");
-- CreateIndex
CREATE INDEX "TemplateBootstrapImport_brandId_createdAt_idx" ON "TemplateBootstrapImport"("brandId", "createdAt");
-- CreateIndex
CREATE INDEX "TemplateBootstrapImport_templatePackageVersionId_createdAt_idx" ON "TemplateBootstrapImport"("templatePackageVersionId", "createdAt");
-- CreateIndex
CREATE INDEX "TemplateBootstrapImport_actorId_createdAt_idx" ON "TemplateBootstrapImport"("actorId", "createdAt");
-- AddForeignKey
ALTER TABLE "BrandTemplateInstallation" ADD CONSTRAINT "BrandTemplateInstallation_templatePackageVersionId_fkey" FOREIGN KEY ("templatePackageVersionId") REFERENCES "TemplatePackageVersion"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "TemplateBootstrapImport" ADD CONSTRAINT "TemplateBootstrapImport_brandId_fkey" FOREIGN KEY ("brandId") REFERENCES "BrandProfile"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "TemplateBootstrapImport" ADD CONSTRAINT "TemplateBootstrapImport_templatePackageVersionId_fkey" FOREIGN KEY ("templatePackageVersionId") REFERENCES "TemplatePackageVersion"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
+38 -9
View File
@@ -65,6 +65,7 @@ model BrandProfile {
adminMemberships BrandMembership[]
releases BrandRelease[]
miniAppReleases MiniAppReleaseTask[]
bootstrapImports TemplateBootstrapImport[]
}
model BrandRelease {
@@ -167,18 +168,23 @@ model CapabilityAuditLog {
}
model BrandTemplateInstallation {
id String @id @default(uuid())
brandId String
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
templateKey String
templateVersion String @default("1.0.0")
configSnapshot Json
previousSnapshots Json @default("[]")
installedAt DateTime @default(now())
updatedAt DateTime @updatedAt
id String @id @default(uuid())
brandId String
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
templateKey String
templateVersion String @default("1.0.0")
visualTemplateKey String?
templatePackageVersionId String?
templatePackageVersion TemplatePackageVersion? @relation("BrandTemplateInstallationPackageVersion", fields: [templatePackageVersionId], references: [id], onDelete: SetNull)
contentChecksum String?
configSnapshot Json
previousSnapshots Json @default("[]")
installedAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([brandId, templateKey])
@@index([brandId])
@@index([templatePackageVersionId])
}
model BrandFieldDefinition {
@@ -433,6 +439,8 @@ model TemplatePackageVersion {
importedById String
importedBy AdminUser @relation("TemplatePackageImportedBy", fields: [importedById], references: [id], onDelete: Restrict)
auditLogs TemplatePackageAuditLog[]
installations BrandTemplateInstallation[] @relation("BrandTemplateInstallationPackageVersion")
bootstrapImports TemplateBootstrapImport[]
importedAt DateTime @default(now())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@ -442,6 +450,27 @@ model TemplatePackageVersion {
@@index([importedById, importedAt])
}
model TemplateBootstrapImport {
id String @id @default(uuid())
brandId String
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
templatePackageVersionId String
templatePackageVersion TemplatePackageVersion @relation(fields: [templatePackageVersionId], references: [id], onDelete: Restrict)
packageKey String
packageVersion String
contentChecksum String
actorId String
strategy String @default("missing_only")
status String
result Json?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([brandId, createdAt])
@@index([templatePackageVersionId, createdAt])
@@index([actorId, createdAt])
}
model TemplatePackageAuditLog {
id String @id @default(uuid())
templatePackageVersionId String
+25 -19
View File
@@ -643,23 +643,29 @@ const runtimeSeedTemplates: Record<"personal" | "food" | "doors", RuntimeSeedTem
};
async function ensureRuntimeContent(brandId: string, template: RuntimeSeedTemplate): Promise<void> {
// 这里只初始化明确的开发演示品牌;餐饮结构化槽位和表单取自对应 package,
// 这里只初始化明确的开发演示品牌;业务内容统一来自视觉包 sampleContent,
// 新增生产模板无需添加 seed 分支,品牌样例内容仍须由管理员显式导入。
const offerings = template.offerings;
const foodSample =
template.templateKey === "food"
? getTemplatePackageManifestForVisualKey("acheng-campus-food")?.sampleContent?.food
: undefined;
if (template.templateKey === "food" && !foodSample)
throw new Error("Food development sample is missing");
const trustContent = foodSample
? foodSample.trustContent.map((item) => {
const fixture = template.trustContent.find((entry) => entry.type === item.type);
return { ...item, ...fixture, config: { ...item.config, ...fixture?.config } };
})
: template.trustContent;
const inquiryFields = foodSample?.fields ?? template.inquiryForm?.fieldsSnapshot;
const inquiryFormName = foodSample?.inquiryFormName ?? template.inquiryForm?.name;
const visualKey = template.templateKey === "food" ? "acheng-campus-food" : "linjing-editorial";
const packageSample =
getTemplatePackageManifestForVisualKey(visualKey)?.sampleContent?.[template.templateKey];
if (!packageSample)
throw new Error(`Development sample is missing for ${visualKey}/${template.templateKey}`);
const offerings = packageSample.offerings.map((item) => ({
name: item.name,
summary: item.summary,
image: item.coverUrl ?? "",
kind: item.kind as OfferingKind,
priceText: item.priceText,
priceAmount: item.priceAmount,
config: { categoryKey: item.categoryKey, ...(item.config ?? {}) },
}));
const trustContent = packageSample.trustContent;
const inquiryFields = packageSample.fields;
const inquiryFormName = packageSample.inquiryFormName;
const seedBrandConfig = {
...(packageSample.brandConfig ?? {}),
...template.brandConfig,
};
if (!inquiryFields?.length || !inquiryFormName)
throw new Error("Development inquiry fixture is missing");
const existingBrand = await prisma.brandProfile.findUniqueOrThrow({ where: { id: brandId } });
@@ -672,7 +678,7 @@ async function ensureRuntimeContent(brandId: string, template: RuntimeSeedTempla
await prisma.brandProfile.update({
where: { id: brandId },
data: {
config: { ...existingConfig, ...template.brandConfig } as Prisma.InputJsonValue,
config: { ...existingConfig, ...seedBrandConfig } as Prisma.InputJsonValue,
...(existingBrand.slug === "default-brand" && !existingBrand.avatarUrl
? { avatarUrl: "/assets/owner/portrait.jpg" }
: {}),
@@ -710,7 +716,7 @@ async function ensureRuntimeContent(brandId: string, template: RuntimeSeedTempla
select: { id: true, name: true },
});
for (const [index, item] of incompleteOfferings.entries()) {
const image = template.offerings[index % template.offerings.length]?.image;
const image = offerings[index % offerings.length]?.image;
if (!image) throw new Error("Development fixture has no offering image");
await prisma.offering.update({
where: { id: item.id },
@@ -727,7 +733,7 @@ async function ensureRuntimeContent(brandId: string, template: RuntimeSeedTempla
}
for (const [sortOrder, item] of trustContent.entries()) {
const existing = await prisma.trustContent.findFirst({
where: { brandId, type: item.type },
where: { brandId, type: item.type, title: item.title },
orderBy: [{ isPublished: "desc" }, { sortOrder: "asc" }],
});
const { config, ...fields } = item;