check-book.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. const { PrismaClient } = require('@prisma/client');
  2. const prisma = new PrismaClient();
  3. async function checkBook() {
  4. const book = await prisma.book.findUnique({
  5. where: { id: 1 },
  6. include: {
  7. chapters: {
  8. orderBy: [
  9. { level: 'asc' },
  10. { parentId: 'asc' },
  11. { number: 'asc' }
  12. ]
  13. }
  14. }
  15. });
  16. if (!book) {
  17. console.log('书籍不存在');
  18. return;
  19. }
  20. console.log('=== 书籍信息 ===');
  21. console.log('ID:', book.id);
  22. console.log('标题:', book.title);
  23. console.log('状态:', book.status);
  24. console.log('进度:', book.progress + '%');
  25. console.log('总章节数:', book.totalChapters);
  26. console.log('预估字数:', book.estimatedWords);
  27. console.log('');
  28. console.log('=== 大纲结构 (JSON) ===');
  29. if (book.outlineJson) {
  30. const outline = JSON.parse(book.outlineJson);
  31. console.log('主题:', outline.mainTheme);
  32. console.log('结构逻辑:', outline.structureLogic);
  33. console.log('章数:', outline.chapters.length);
  34. // 检查是否有节和小节
  35. outline.chapters.forEach((ch, idx) => {
  36. console.log(` 第${idx + 1}章: ${ch.title}`);
  37. if (ch.sections && ch.sections.length > 0) {
  38. console.log(` 节数: ${ch.sections.length}`);
  39. ch.sections.forEach((sec, sIdx) => {
  40. console.log(` 第${sIdx + 1}节: ${sec.title}`);
  41. if (sec.subsections && sec.subsections.length > 0) {
  42. console.log(` 小节数: ${sec.subsections.length}`);
  43. } else {
  44. console.log(` ⚠️ 缺少小节`);
  45. }
  46. });
  47. } else {
  48. console.log(` ⚠️ 缺少节`);
  49. }
  50. });
  51. } else {
  52. console.log('⚠️ 无大纲数据');
  53. }
  54. console.log('');
  55. console.log('=== 数据库章节统计 ===');
  56. const level1 = book.chapters.filter(c => c.level === 1).length;
  57. const level2 = book.chapters.filter(c => c.level === 2).length;
  58. const level3 = book.chapters.filter(c => c.level === 3).length;
  59. console.log('一级(章):', level1);
  60. console.log('二级(节):', level2);
  61. console.log('三级(小节):', level3);
  62. console.log('总计:', book.chapters.length);
  63. console.log('');
  64. console.log('=== 章节详细结构 ===');
  65. book.chapters.forEach(c => {
  66. const indent = ' '.repeat(c.level - 1);
  67. const status = c.status || 'pending';
  68. console.log(`${indent}L${c.level} #${c.number} ${c.title} [${status}] (ID:${c.id}, Parent:${c.parentId || 'null'})`);
  69. });
  70. await prisma.$disconnect();
  71. }
  72. checkBook().catch(console.error);