gongxiangp2/scripts/check-material-types.ts

72 lines
1.8 KiB
TypeScript

import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
async function main() {
console.log('查询素材类型统计...\n')
// 查询 产品全案 和 任务-详情 的数量
const productPackageCount = await prisma.material.count({
where: {
deletedAt: null,
materialType: '产品全案'
}
})
const taskDetailCount = await prisma.material.count({
where: {
deletedAt: null,
materialType: '任务-详情'
}
})
console.log(`产品全案: ${productPackageCount} 条`)
console.log(`任务-详情: ${taskDetailCount} 条`)
console.log(`总计: ${productPackageCount + taskDetailCount} 条\n`)
// 如果有数据,显示一些示例
if (productPackageCount > 0) {
const examples = await prisma.material.findMany({
where: {
deletedAt: null,
materialType: '产品全案'
},
take: 3,
select: {
id: true,
productModel: true,
taskNo: true,
createdAt: true
}
})
console.log('产品全案示例:')
examples.forEach(m => {
console.log(` - ${m.productModel} (任务号: ${m.taskNo || '无'}, 创建于: ${m.createdAt.toISOString().split('T')[0]})`)
})
}
if (taskDetailCount > 0) {
const examples = await prisma.material.findMany({
where: {
deletedAt: null,
materialType: '任务-详情'
},
take: 3,
select: {
id: true,
productModel: true,
taskNo: true,
createdAt: true
}
})
console.log('\n任务-详情示例:')
examples.forEach(m => {
console.log(` - ${m.productModel} (任务号: ${m.taskNo || '无'}, 创建于: ${m.createdAt.toISOString().split('T')[0]})`)
})
}
}
main()
.catch(console.error)
.finally(() => prisma.$disconnect())