gongxiangp2/scripts/archive/check-materials-status.ts

74 lines
1.7 KiB
TypeScript

/**
* 检查所有"任务-详情"素材的状态
*/
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
async function main() {
console.log('='.repeat(60));
console.log('检查"任务-详情"素材状态');
console.log('='.repeat(60));
try {
// 1. 总数
const totalCount = await prisma.material.count({
where: {
materialType: '任务-详情',
deletedAt: null,
},
});
console.log(`总素材数: ${totalCount}`);
// 2. 有资产记录的素材数
const withAssetsCount = await prisma.material.count({
where: {
materialType: '任务-详情',
deletedAt: null,
assets: {
some: {},
},
},
});
console.log(`有资产记录的素材数: ${withAssetsCount}`);
// 3. 查询前5个素材的详细信息
const materials = await prisma.material.findMany({
where: {
materialType: '任务-详情',
deletedAt: null,
},
include: {
assets: {
select: {
assetType: true,
fileUrl: true,
},
},
},
take: 5,
orderBy: { createdAt: 'desc' },
});
console.log('\n前5个素材的资产情况:');
materials.forEach((m) => {
console.log(`\n- ${m.productModel} (${m.id})`);
console.log(` 资产数: ${m.assets.length}`);
console.log(` 资产类型: ${m.assets.map((a) => a.assetType).join(', ')}`);
if (m.assets.length > 0) {
console.log(` 第一个资产URL: ${m.assets[0].fileUrl.substring(0, 80)}...`);
}
});
} catch (error) {
console.error('查询失败:', error);
process.exit(1);
} finally {
await prisma.$disconnect();
}
}
main();