check-all-books.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. const { PrismaClient } = require('@prisma/client');
  2. const prisma = new PrismaClient();
  3. async function checkAllBooks() {
  4. const books = await prisma.book.findMany({
  5. orderBy: { id: 'desc' },
  6. take: 10
  7. });
  8. console.log('\n📊 所有书籍生成状态检查:\n');
  9. console.log('=' .repeat(80));
  10. for (const book of books) {
  11. const chapters = await prisma.bookChapter.findMany({
  12. where: { bookId: book.id }
  13. });
  14. const chapterCount = chapters.filter(c => c.level === 1).length;
  15. const sectionCount = chapters.filter(c => c.level === 2).length;
  16. const subsectionCount = chapters.filter(c => c.level === 3).length;
  17. const completedContent = chapters.filter(c => c.level === 3 && c.contentStatus === 'completed').length;
  18. const generatingContent = chapters.filter(c => c.level === 3 && c.contentStatus === 'generating').length;
  19. const failedContent = chapters.filter(c => c.level === 3 && c.contentStatus === 'failed').length;
  20. const totalWords = chapters.reduce((sum, c) => sum + (c.wordCount || 0), 0);
  21. console.log(`\n📖 Book ID: ${book.id}`);
  22. console.log(` 标题: ${book.title}`);
  23. console.log(` 状态: ${book.status}`);
  24. console.log(` 进度: ${book.progress}%`);
  25. console.log(` 规模: ${book.bookScale}`);
  26. console.log(` 大纲: ${chapterCount}章 / ${sectionCount}节 / ${subsectionCount}小节`);
  27. console.log(` 内容: ${completedContent}完成 / ${generatingContent}生成中 / ${failedContent}失败`);
  28. console.log(` 总字数: ${totalWords.toLocaleString()}字`);
  29. // 检查是否有异常
  30. const issues = [];
  31. if (book.status === 'generating' && book.progress > 90) {
  32. issues.push('⚠️ 进度超过90%但仍在generating状态');
  33. }
  34. if (failedContent > 0) {
  35. issues.push(`❌ 有${failedContent}个小节生成失败`);
  36. }
  37. if (book.status === 'failed') {
  38. issues.push(`❌ 书籍状态为failed: ${book.error || '未知错误'}`);
  39. }
  40. if (issues.length > 0) {
  41. console.log(` 问题:`);
  42. issues.forEach(issue => console.log(` ${issue}`));
  43. } else {
  44. console.log(` ✅ 状态正常`);
  45. }
  46. }
  47. console.log('\n' + '='.repeat(80));
  48. console.log('\n检查完成!\n');
  49. await prisma.$disconnect();
  50. }
  51. checkAllBooks().catch(console.error);