核心功能: - M3 配方记录: 创建/编辑/详情/可视化编辑/AI提取/版本历史/版本对比 - M1 颜色引擎: D3.js 色相环/滑条微调/ΔE计算/取色棒/AI配色推荐 - M2 可视化编辑器: ECharts饼图/成分滑条/AI预测/雷达图/仪表盘 - M4 配方推演: 约束设置/SSE推演/方案对比/散点图 - 平台: NL智能搜索/项目管理/CSV导出/JWT认证/全局搜索 技术栈: - 前端: React + Vite + Tailwind CSS 4 + Zustand + TanStack Query - 后端: Fastify 5 + Prisma 7 + PostgreSQL + pgvector - AI: OpenAI/DeepSeek API 调用 + Prompt模板 + 缓存/降级/限流 - 测试: Vitest 42 tests (26 API集成 + 16 色彩模块)
177 lines
5.1 KiB
Plaintext
177 lines
5.1 KiB
Plaintext
generator client {
|
|
provider = "prisma-client"
|
|
output = "../src/generated/prisma"
|
|
}
|
|
|
|
datasource db {
|
|
provider = "postgresql"
|
|
}
|
|
|
|
enum UserRole {
|
|
engineer
|
|
admin
|
|
}
|
|
|
|
enum IngredientCategory {
|
|
emulsifier
|
|
humectant
|
|
thickener
|
|
preservative
|
|
antioxidant
|
|
fragrance
|
|
colorant
|
|
ph_adjuster
|
|
sunscreen
|
|
surfactant
|
|
emollient
|
|
other
|
|
}
|
|
|
|
model User {
|
|
id String @id @default(uuid())
|
|
username String @unique
|
|
passwordHash String @map("password_hash")
|
|
role UserRole @default(engineer)
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
formulas Formula[] @relation("FormulaCreator")
|
|
colorFormulas ColorFormula[] @relation("ColorFormulaCreator")
|
|
formulaVersions FormulaVersion[]
|
|
projects Project[]
|
|
|
|
@@map("users")
|
|
}
|
|
|
|
model Project {
|
|
id String @id @default(uuid())
|
|
name String
|
|
description String?
|
|
createdBy String @map("created_by")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
creator User @relation(fields: [createdBy], references: [id])
|
|
formulas Formula[]
|
|
|
|
@@map("projects")
|
|
}
|
|
|
|
model Formula {
|
|
id String @id @default(uuid())
|
|
name String
|
|
description String?
|
|
projectId String? @map("project_id")
|
|
currentVersion Int @default(1) @map("current_version")
|
|
createdBy String @map("created_by")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
embedding Unsupported("vector(1536)")?
|
|
|
|
project Project? @relation(fields: [projectId], references: [id])
|
|
creator User @relation("FormulaCreator", fields: [createdBy], references: [id])
|
|
versions FormulaVersion[]
|
|
colorFormulas ColorFormula[]
|
|
|
|
@@index([projectId])
|
|
@@index([createdBy])
|
|
@@map("formulas")
|
|
}
|
|
|
|
model FormulaVersion {
|
|
id String @id @default(uuid())
|
|
formulaId String @map("formula_id")
|
|
versionNumber Int @map("version_number")
|
|
description String?
|
|
snapshotData Json @map("snapshot_data")
|
|
createdBy String @map("created_by")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
formula Formula @relation(fields: [formulaId], references: [id])
|
|
creator User @relation(fields: [createdBy], references: [id])
|
|
phases Phase[]
|
|
ingredients FormulaIngredient[]
|
|
|
|
@@unique([formulaId, versionNumber])
|
|
@@index([formulaId])
|
|
@@map("formula_versions")
|
|
}
|
|
|
|
model Ingredient {
|
|
id String @id @default(uuid())
|
|
inciName String @map("inci_name")
|
|
chineseName String @map("chinese_name")
|
|
functionCategory IngredientCategory @map("function_category")
|
|
supplier String?
|
|
unit String @default("kg")
|
|
unitPrice Decimal? @map("unit_price") @db.Decimal(10, 2)
|
|
description String?
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
formulaIngredients FormulaIngredient[]
|
|
|
|
@@index([functionCategory])
|
|
@@map("ingredients")
|
|
}
|
|
|
|
model Phase {
|
|
id String @id @default(uuid())
|
|
name String
|
|
formulaId String @map("formula_id")
|
|
sortOrder Int @default(0) @map("sort_order")
|
|
|
|
formulaVersion FormulaVersion @relation(fields: [formulaId], references: [id])
|
|
ingredients FormulaIngredient[]
|
|
|
|
@@index([formulaId])
|
|
@@map("phases")
|
|
}
|
|
|
|
model FormulaIngredient {
|
|
id String @id @default(uuid())
|
|
formulaVersionId String @map("formula_version_id")
|
|
phaseId String? @map("phase_id")
|
|
ingredientId String @map("ingredient_id")
|
|
percentage Decimal @db.Decimal(5, 2)
|
|
processNotes String? @map("process_notes")
|
|
|
|
formulaVersion FormulaVersion @relation(fields: [formulaVersionId], references: [id])
|
|
phase Phase? @relation(fields: [phaseId], references: [id])
|
|
ingredient Ingredient @relation(fields: [ingredientId], references: [id])
|
|
|
|
@@index([formulaVersionId])
|
|
@@index([ingredientId])
|
|
@@map("formula_ingredients")
|
|
}
|
|
|
|
model ColorFormula {
|
|
id String @id @default(uuid())
|
|
name String
|
|
targetLab Json @map("target_lab")
|
|
actualLab Json? @map("actual_lab")
|
|
deltaE Float? @map("delta_e")
|
|
colorantComposition Json? @map("colorant_composition")
|
|
formulaId String? @map("formula_id")
|
|
createdBy String @map("created_by")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
formula Formula? @relation(fields: [formulaId], references: [id])
|
|
creator User @relation("ColorFormulaCreator", fields: [createdBy], references: [id])
|
|
|
|
@@index([formulaId])
|
|
@@index([createdBy])
|
|
@@map("color_formulas")
|
|
}
|
|
|
|
model AiAuditLog {
|
|
id String @id @default(uuid())
|
|
capability String
|
|
modelName String @map("model_name")
|
|
promptHash String @map("prompt_hash")
|
|
tokensUsed Int? @map("tokens_used")
|
|
durationMs Int? @map("duration_ms")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
@@index([capability])
|
|
@@index([createdAt])
|
|
@@map("ai_audit_logs")
|
|
}
|