From fb56359f41bdf9da133673958b96e3b26ed35ca2 Mon Sep 17 00:00:00 2001 From: dxc Date: Sat, 28 Feb 2026 14:05:17 +0800 Subject: [PATCH] fix: use ilike and trim for category, company and type filters Co-authored-by: aider (openai/DeepSeek-V3.2-Thinking) --- .../app/services/inbound/base_service.py | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/inventory-backend/app/services/inbound/base_service.py b/inventory-backend/app/services/inbound/base_service.py index 9aaa7c3..3e8c5d8 100644 --- a/inventory-backend/app/services/inbound/base_service.py +++ b/inventory-backend/app/services/inbound/base_service.py @@ -162,14 +162,17 @@ class MaterialBaseService: )) # 2. 精确筛选 - if filters.get('company'): - query = query.filter_by(company_name=filters['company']) + company = filters.get('company') + if company is not None and company != '': + query = query.filter(MaterialBase.company_name.ilike(company.strip())) - if filters.get('category'): - query = query.filter_by(category=filters['category']) + category = filters.get('category') + if category is not None and category != '': + query = query.filter(MaterialBase.category.ilike(category.strip())) - if filters.get('type'): - query = query.filter_by(material_type=filters['type']) + type_val = filters.get('type') + if type_val is not None and type_val != '': + query = query.filter(MaterialBase.material_type.ilike(type_val.strip())) if filters.get('isEnabled') is not None: is_active = bool(int(filters['isEnabled'])) @@ -370,12 +373,15 @@ class MaterialBaseService: MaterialBase.spec_model.ilike(kw), MaterialBase.company_name.ilike(kw) )) - if filters.get('company'): - filter_conditions.append(MaterialBase.company_name == filters['company']) - if filters.get('category'): - filter_conditions.append(MaterialBase.category == filters['category']) - if filters.get('type'): - filter_conditions.append(MaterialBase.material_type == filters['type']) + company = filters.get('company') + if company is not None and company != '': + filter_conditions.append(MaterialBase.company_name.ilike(company.strip())) + category = filters.get('category') + if category is not None and category != '': + filter_conditions.append(MaterialBase.category.ilike(category.strip())) + type_val = filters.get('type') + if type_val is not None and type_val != '': + filter_conditions.append(MaterialBase.material_type.ilike(type_val.strip())) if filters.get('isEnabled') is not None: is_active = bool(int(filters['isEnabled'])) filter_conditions.append(MaterialBase.is_enabled == is_active)