const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();

async function checkChapterAudio() {
  console.log('\n📊 检查BookChapter的audioUrl更新情况：\n');
  
  const bookId = 5;
  
  // 检查前5个小节
  const subsections = await prisma.bookChapter.findMany({
    where: {
      bookId,
      level: 3
    },
    select: {
      id: true,
      title: true,
      audioUrl: true,
      audioDuration: true,
    },
    orderBy: { id: 'desc' },
    take: 5
  });
  
  console.log('最近5个小节：\n');
  subsections.forEach((sub, index) => {
    console.log(`${index + 1}. ${sub.title}`);
    console.log(`   audioUrl: ${sub.audioUrl || '无'}`);
    console.log(`   audioDuration: ${sub.audioDuration || 0}秒\n`);
  });
  
  // 统计
  const withAudio = await prisma.bookChapter.count({
    where: {
      bookId,
      level: 3,
      audioUrl: { not: '' }
    }
  });
  
  const totalSubsections = await prisma.bookChapter.count({
    where: {
      bookId,
      level: 3
    }
  });
  
  console.log(`\n📈 统计：`);
  console.log(`  总小节数: ${totalSubsections}`);
  console.log(`  有audioUrl的小节: ${withAudio}`);
  console.log(`  比例: ${(withAudio / totalSubsections * 100).toFixed(1)}%\n`);
  
  await prisma.$disconnect();
}

checkChapterAudio().catch(console.error);
