feat: add material search filters to semi, product, service modules

Co-authored-by: aider (openai/DeepSeek-V3.2-Thinking) <aider@aider.chat>
This commit is contained in:
dxc
2026-02-11 14:42:16 +08:00
parent b3fdc65d33
commit 9f0134b2e4
10 changed files with 195 additions and 14 deletions

View File

@ -114,3 +114,15 @@ def get_user_suggestions():
keyword = request.args.get('keyword', '')
data = ProductInboundService.search_system_users(keyword)
return jsonify({"code": 200, "msg": "success", "data": data})
# ------------------------------------------------------------------
# 7. 获取筛选选项
# ------------------------------------------------------------------
@inbound_product_bp.route('/options', methods=['GET'])
def get_options():
try:
data = ProductInboundService.get_filter_options()
return jsonify({"code": 200, "msg": "success", "data": data})
except Exception as e:
return jsonify({"code": 500, "msg": str(e)}), 500

View File

@ -128,3 +128,15 @@ def get_user_suggestions():
keyword = request.args.get('keyword', '')
data = SemiInboundService.search_system_users(keyword)
return jsonify({"code": 200, "msg": "success", "data": data})
# ------------------------------------------------------------------
# 7. 获取筛选选项
# ------------------------------------------------------------------
@inbound_semi_bp.route('/options', methods=['GET'])
def get_options():
try:
data = SemiInboundService.get_filter_options()
return jsonify({"code": 200, "msg": "success", "data": data})
except Exception as e:
return jsonify({"code": 500, "msg": str(e)}), 500

View File

@ -162,3 +162,16 @@ def get_user_suggestions():
keyword = request.args.get('keyword', '')
data = ServiceService.search_system_users(keyword)
return jsonify({'code': 200, 'msg': 'success', 'data': data})
# ------------------------------------------------------------------
# 获取筛选选项
# ------------------------------------------------------------------
@inbound_bp.route('/service/options', methods=['GET'])
@jwt_required()
def get_options():
try:
data = ServiceService.get_filter_options()
return jsonify({'code': 200, 'msg': 'success', 'data': data})
except Exception as e:
return jsonify({'code': 500, 'msg': str(e)}), 500

View File

@ -280,7 +280,7 @@ class ProductInboundService:
# 6. 获取列表
# ============================================================
@staticmethod
def get_list(page, limit, keyword=None, statuses=None):
def get_list(page, limit, keyword=None, statuses=None, category=None, material_type=None):
from app.models.inbound.product import StockProduct
try:
query = db.session.query(StockProduct).outerjoin(MaterialBase, StockProduct.base_id == MaterialBase.id)
@ -295,6 +295,13 @@ class ProductInboundService:
StockProduct.sku.ilike(f'%{keyword}%')
))
# 类别筛选
if category and category.strip():
query = query.filter(MaterialBase.category == category.strip())
# 类型筛选
if material_type and material_type.strip():
query = query.filter(MaterialBase.material_type == material_type.strip())
if not statuses:
statuses = ['在库', '借库']
@ -377,3 +384,25 @@ class ProductInboundService:
return users
except Exception:
return []
# ============================================================
# 8. 获取筛选选项(类别、类型)
# ============================================================
@staticmethod
def get_filter_options():
try:
from app.models.base import MaterialBase
categories = db.session.query(MaterialBase.category) \
.filter(MaterialBase.category != None, MaterialBase.category != '') \
.distinct().all()
types = db.session.query(MaterialBase.material_type) \
.filter(MaterialBase.material_type != None, MaterialBase.material_type != '') \
.distinct().all()
return {
"categories": [r[0] for r in categories],
"types": [r[0] for r in types]
}
except Exception:
import traceback
traceback.print_exc()
return {"categories": [], "types": []}

View File

@ -378,7 +378,7 @@ class SemiInboundService:
# 6. 获取列表
# ============================================================
@staticmethod
def get_list(page, limit, keyword=None, statuses=None):
def get_list(page, limit, keyword=None, statuses=None, category=None, material_type=None):
from app.models.inbound.semi import StockSemi
try:
query = db.session.query(StockSemi).outerjoin(MaterialBase, StockSemi.base_id == MaterialBase.id)
@ -397,6 +397,13 @@ class SemiInboundService:
)
)
# 类别筛选
if category and category.strip():
query = query.filter(MaterialBase.category == category.strip())
# 类型筛选
if material_type and material_type.strip():
query = query.filter(MaterialBase.material_type == material_type.strip())
if not statuses:
statuses = ['在库', '借库']
@ -479,3 +486,25 @@ class SemiInboundService:
return users
except Exception:
return []
# ============================================================
# 8. 获取筛选选项(类别、类型)
# ============================================================
@staticmethod
def get_filter_options():
try:
from app.models.base import MaterialBase
categories = db.session.query(MaterialBase.category) \
.filter(MaterialBase.category != None, MaterialBase.category != '') \
.distinct().all()
types = db.session.query(MaterialBase.material_type) \
.filter(MaterialBase.material_type != None, MaterialBase.material_type != '') \
.distinct().all()
return {
"categories": [r[0] for r in categories],
"types": [r[0] for r in types]
}
except Exception:
import traceback
traceback.print_exc()
return {"categories": [], "types": []}

View File

@ -204,3 +204,25 @@ class ServiceService:
return users
except Exception:
return []
# ============================================================
# 获取筛选选项(类别、类型)
# ============================================================
@classmethod
def get_filter_options(cls):
try:
from app.models.base import MaterialBase
categories = db.session.query(MaterialBase.category) \
.filter(MaterialBase.category != None, MaterialBase.category != '') \
.distinct().all()
types = db.session.query(MaterialBase.material_type) \
.filter(MaterialBase.material_type != None, MaterialBase.material_type != '') \
.distinct().all()
return {
"categories": [r[0] for r in categories],
"types": [r[0] for r in types]
}
except Exception:
import traceback
traceback.print_exc()
return {"categories": [], "types": []}