基础信息展示以及搜索逻辑进行修复

This commit is contained in:
dxc
2026-02-11 13:12:05 +08:00
parent d0a237625c
commit 5532c87684
9 changed files with 285 additions and 395 deletions

View File

@ -156,6 +156,31 @@ class MaterialBaseService:
print(f"查询基础信息列表失败: {e}")
return {"total": 0, "items": []}
@staticmethod
def get_distinct_options():
"""
获取所有已存在的类别和类型 (去重)
用于前端下拉筛选
"""
try:
# 查询所有不为空的类别并去重
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": [c[0] for c in categories],
"types": [t[0] for t in types]
}
except Exception as e:
traceback.print_exc()
return {"categories": [], "types": []}
@staticmethod
def create_material(data):
"""新增基础信息"""