feat: 5个列表API新增搜索参数支持

- visits: search沟通内容/客户需求/拜访人/客户名
- daily_notes: search内容
- work_plans: search计划内容/客户名
- mini_business: search产品/跟进/客户名
- key_visits: search描述/拜访人/客户名

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-07-13 00:55:43 +08:00
parent e7125ff930
commit cdbe59e97f
5 changed files with 27 additions and 4 deletions
+6 -1
View File
@@ -3,7 +3,7 @@ from datetime import date
from typing import Optional
from fastapi import APIRouter, Depends, HTTPException, Query
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy import select
from sqlalchemy import select, or_
from app.database import get_db
from app.middleware.auth import get_current_user, require_any_role
from app.utils.timezone import parse_date
@@ -36,6 +36,7 @@ async def _enrich(wp: WorkPlan, db: AsyncSession) -> dict:
async def list_work_plans(
customer_id: Optional[str] = Query(None),
customer_type: Optional[str] = Query(None),
search: Optional[str] = Query(None),
current_user: dict = Depends(get_current_user),
db: AsyncSession = Depends(get_db),
):
@@ -46,6 +47,10 @@ async def list_work_plans(
query = query.where(WorkPlan.customer_id == uuid.UUID(customer_id))
if customer_type:
query = query.join(Customer, WorkPlan.customer_id == Customer.id).where(Customer.customer_type == customer_type)
if search:
query = query.outerjoin(Customer, WorkPlan.customer_id == Customer.id).where(
or_(WorkPlan.plan_content.ilike(f"%{search}%"), Customer.name.ilike(f"%{search}%"))
)
query = query.order_by(WorkPlan.plan_date.desc()).limit(200)
result = await db.execute(query)
return [await _enrich(w, db) for w in result.scalars().all()]