const { PrismaClient } = require('@prisma/client') const prisma = new PrismaClient() const ASSIGNMENTS = [ { keyword: '消毒剂', category: '涂料' }, { keyword: '重水供应', category: '仪表' }, { keyword: '拦污网', category: '杂品' }, { keyword: '110kV变电站施工材料', category: '电线电缆' }, { keyword: '线路金具', category: '电线电缆' }, { keyword: '弱电材料', category: '电线电缆' }, { keyword: '弱电智能化', category: '电线电缆' }, { keyword: '引气剂', category: '涂料' }, { keyword: '光伏支架', category: '钢材' }, { keyword: '淋浴隔断', category: '杂品' }, ] async function main() { const emptyLeads = await prisma.lead.findMany({ where: { OR: [{ category: null }, { category: '' }] }, select: { id: true, title: true }, }) console.log(`剩余空品类线索: ${emptyLeads.length} 条`) let assigned = 0 for (const lead of emptyLeads) { for (const a of ASSIGNMENTS) { if (lead.title.includes(a.keyword)) { await prisma.lead.update({ where: { id: lead.id }, data: { category: a.category } }) assigned++ console.log(`✓ ${lead.title.slice(0, 60)} → ${a.category}`) break } } } const stillEmpty = await prisma.lead.count({ where: { OR: [{ category: null }, { category: '' }] }, }) console.log(`\n已分配: ${assigned}, 剩余空品类: ${stillEmpty}`) } main() .catch((e) => { console.error(e) process.exit(1) }) .finally(() => prisma.$disconnect())