feat: 线索池品类筛选改为按标题关键词匹配

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
Sisyphus 2026-06-26 16:24:43 +08:00
parent bd213eb5ec
commit ae72966766
2 changed files with 54 additions and 4 deletions

View File

@ -14,8 +14,9 @@ export class LeadController {
@Query('source') source?: string,
@Query('category') category?: string,
@Query('assignedTo') assignedTo?: string,
@Query('timeRange') timeRange?: string,
) {
return this.leadService.findAll({ status, level, search, star, source, category, assignedTo })
return this.leadService.findAll({ status, level, search, star, source, category, assignedTo, timeRange })
}
@Get('stats')

View File

@ -2,6 +2,25 @@ import { Injectable, NotFoundException, Logger, ServiceUnavailableException } fr
import { PrismaService } from '../prisma/prisma.service'
import { IntegrationService } from '../integration/integration.service'
// 品类 → 标题关键词映射(筛选时按标题模糊匹配,不走 category 字段)
const CATEGORY_KEYWORDS: Record<string, string[]> = {
'防火门': ['防火门', '防火卷帘', '防火窗', '钢质防火', '木质防火'],
'配电箱': ['配电箱', '配电柜', '配电盘', '照明配电箱', '动力配电箱', '电表箱'],
'电线电缆': ['电线', '电缆', '导线', '电力线', '控制电缆', '光缆', '架空线'],
'阀门': ['阀门', '闸阀', '球阀', '蝶阀', '截止阀', '止回阀', '调节阀'],
'钢材': ['钢材', '钢管', '钢板', '钢筋', '型钢', '槽钢', '角钢', '工字钢', 'H型钢', '螺纹钢'],
'涂料': ['涂料', '油漆', '防腐漆', '防火涂料', '乳胶漆', '防水涂料'],
'混凝土': ['混凝土', '商混', '商品砼', '水泥', '砂浆', '砼'],
'变压器': ['变压器', '箱变', '干式变', '油浸变', '电力变压器'],
'水泵': ['水泵', '离心泵', '潜污泵', '消防泵', '排污泵', '循环泵'],
'风机': ['风机', '通风机', '排风机', '轴流风机', '离心风机'],
'管材': ['管材', '管道', 'PVC管', 'PE管', '镀锌管', '无缝管', '螺旋管', '给水管'],
'开关': ['开关', '断路器', '接触器', '继电器', '熔断器', '隔离开关'],
'灯具': ['灯具', '照明灯', '路灯', '防爆灯', 'LED灯', '太阳能灯'],
'仪表': ['仪表', '仪器', '传感器', '变送器', '流量计', '压力表', '温度计'],
'电机': ['电机', '电动机', '减速机', '减速器', '变频电机'],
}
@Injectable()
export class LeadService {
private readonly logger = new Logger(LeadService.name)
@ -11,7 +30,7 @@ export class LeadService {
private integrationService: IntegrationService,
) {}
async findAll(params?: { status?: string; level?: string; search?: string; star?: string; source?: string; category?: string; assignedTo?: string }) {
async findAll(params?: { status?: string; level?: string; search?: string; star?: string; source?: string; category?: string; assignedTo?: string; timeRange?: string }) {
const where: any = {}
if (params?.status) where.status = params.status
if (params?.level) where.level = params.level
@ -28,14 +47,44 @@ export class LeadService {
else if (!isNaN(starVal)) where.star = starVal
}
if (params?.source) where.source = params.source
if (params?.category) where.category = params.category
if (params?.category) {
const keywords = CATEGORY_KEYWORDS[params.category]
if (keywords) {
where.OR = keywords.map(kw => ({ title: { contains: kw } }))
}
}
if (params?.assignedTo) {
where.assignedTo = params.assignedTo === '未分配' ? null : params.assignedTo
}
if (params?.timeRange && params.timeRange !== '全部时间') {
const now = new Date()
const pad = (n: number) => n.toString().padStart(2, '0')
const today = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`
if (params.timeRange === '今天') {
where.publishTime = { startsWith: today }
} else if (params.timeRange === '昨天') {
const y = new Date(now)
y.setDate(y.getDate() - 1)
const yesterday = `${y.getFullYear()}-${pad(y.getMonth() + 1)}-${pad(y.getDate())}`
where.publishTime = { startsWith: yesterday }
} else if (params.timeRange === '本周') {
const day = now.getDay()
const diff = day === 0 ? 6 : day - 1 // Monday
const monday = new Date(now)
monday.setDate(now.getDate() - diff)
const sunday = new Date(monday)
sunday.setDate(monday.getDate() + 6)
const m = `${monday.getFullYear()}-${pad(monday.getMonth() + 1)}-${pad(monday.getDate())}`
const s = `${sunday.getFullYear()}-${pad(sunday.getMonth() + 1)}-${pad(sunday.getDate())}`
where.publishTime = { gte: m, lte: s + ' 23:59:59' }
} else if (params.timeRange === '本月') {
where.publishTime = { startsWith: `${now.getFullYear()}-${pad(now.getMonth() + 1)}` }
}
}
return this.prisma.lead.findMany({
where,
orderBy: [
{ level: 'asc' },
{ deadline: 'desc' },
{ createdAt: 'desc' },
],
})