优化案件通过标签搜索
This commit is contained in:
@@ -1804,7 +1804,7 @@ class caseManagementDetail(APIView):
|
|||||||
Q_obj &= Q(party_name__icontains=party_name)
|
Q_obj &= Q(party_name__icontains=party_name)
|
||||||
if client_name:
|
if client_name:
|
||||||
Q_obj &= Q(client_name__icontains=client_name)
|
Q_obj &= Q(client_name__icontains=client_name)
|
||||||
# 按标签搜索:tags 可为字符串(名称模糊)或数组(标签ID如 [2,3]);tag_ids 为标签ID列表;满足任一标签即匹配
|
# 按标签搜索:tags 可为字符串(名称模糊)、数组(标签ID)、或 form 传来的字符串 "[2]";tag_ids 为标签ID列表;满足任一标签即匹配
|
||||||
tag_id_list = []
|
tag_id_list = []
|
||||||
if tags is not None and tags != '':
|
if tags is not None and tags != '':
|
||||||
if isinstance(tags, list):
|
if isinstance(tags, list):
|
||||||
@@ -1813,9 +1813,19 @@ class caseManagementDetail(APIView):
|
|||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
pass
|
pass
|
||||||
elif isinstance(tags, str):
|
elif isinstance(tags, str):
|
||||||
tag_id_list.extend(
|
tags_stripped = tags.strip()
|
||||||
CaseTag.objects.filter(name__icontains=tags, is_deleted=False).values_list('id', flat=True)
|
# 前端 form-data 可能把 [2] 或 [2,3] 当成字符串传,先尝试按 JSON 数组解析
|
||||||
)
|
if tags_stripped.startswith('[') and tags_stripped.endswith(']'):
|
||||||
|
try:
|
||||||
|
parsed = json.loads(tags_stripped)
|
||||||
|
if isinstance(parsed, list):
|
||||||
|
tag_id_list.extend([int(x) for x in parsed if x is not None and str(x).strip() != ''])
|
||||||
|
except (ValueError, TypeError, json.JSONDecodeError):
|
||||||
|
pass
|
||||||
|
if not tag_id_list:
|
||||||
|
tag_id_list.extend(
|
||||||
|
CaseTag.objects.filter(name__icontains=tags, is_deleted=False).values_list('id', flat=True)
|
||||||
|
)
|
||||||
if tag_ids:
|
if tag_ids:
|
||||||
try:
|
try:
|
||||||
if isinstance(tag_ids, str):
|
if isinstance(tag_ids, str):
|
||||||
@@ -2434,9 +2444,18 @@ class CaseDropdownList(APIView):
|
|||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
pass
|
pass
|
||||||
elif isinstance(tags, str):
|
elif isinstance(tags, str):
|
||||||
tag_id_list.extend(
|
tags_stripped = tags.strip()
|
||||||
CaseTag.objects.filter(name__icontains=tags, is_deleted=False).values_list('id', flat=True)
|
if tags_stripped.startswith('[') and tags_stripped.endswith(']'):
|
||||||
)
|
try:
|
||||||
|
parsed = json.loads(tags_stripped)
|
||||||
|
if isinstance(parsed, list):
|
||||||
|
tag_id_list.extend([int(x) for x in parsed if x is not None and str(x).strip() != ''])
|
||||||
|
except (ValueError, TypeError, json.JSONDecodeError):
|
||||||
|
pass
|
||||||
|
if not tag_id_list:
|
||||||
|
tag_id_list.extend(
|
||||||
|
CaseTag.objects.filter(name__icontains=tags, is_deleted=False).values_list('id', flat=True)
|
||||||
|
)
|
||||||
if tag_ids:
|
if tag_ids:
|
||||||
try:
|
try:
|
||||||
if isinstance(tag_ids, str):
|
if isinstance(tag_ids, str):
|
||||||
|
|||||||
Reference in New Issue
Block a user