|
@@ -356,8 +356,23 @@ export class BookStore {
|
|
|
const bookIdNum = parseInt(bookId);
|
|
const bookIdNum = parseInt(bookId);
|
|
|
// 使用 upsert 避免唯一约束冲突
|
|
// 使用 upsert 避免唯一约束冲突
|
|
|
for (const c of chapters) {
|
|
for (const c of chapters) {
|
|
|
- await prisma.bookChapter.create({
|
|
|
|
|
- data: {
|
|
|
|
|
|
|
+ await prisma.bookChapter.upsert({
|
|
|
|
|
+ where: {
|
|
|
|
|
+ bookId_parentId_level_number: {
|
|
|
|
|
+ bookId: bookIdNum,
|
|
|
|
|
+ parentId: null,
|
|
|
|
|
+ level: 1,
|
|
|
|
|
+ number: c.number,
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ update: {
|
|
|
|
|
+ title: c.title,
|
|
|
|
|
+ summary: c.summary,
|
|
|
|
|
+ keyPoints: c.keyPoints ? JSON.stringify(c.keyPoints) : null,
|
|
|
|
|
+ estimatedWords: c.estimatedWords || 5000,
|
|
|
|
|
+ status: 'completed',
|
|
|
|
|
+ } as any,
|
|
|
|
|
+ create: {
|
|
|
bookId: bookIdNum,
|
|
bookId: bookIdNum,
|
|
|
parentId: null,
|
|
parentId: null,
|
|
|
level: 1,
|
|
level: 1,
|
|
@@ -366,7 +381,7 @@ export class BookStore {
|
|
|
summary: c.summary,
|
|
summary: c.summary,
|
|
|
keyPoints: c.keyPoints ? JSON.stringify(c.keyPoints) : null,
|
|
keyPoints: c.keyPoints ? JSON.stringify(c.keyPoints) : null,
|
|
|
estimatedWords: c.estimatedWords || 5000,
|
|
estimatedWords: c.estimatedWords || 5000,
|
|
|
- status: 'completed', // 大纲已完成
|
|
|
|
|
|
|
+ status: 'completed',
|
|
|
} as any,
|
|
} as any,
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|