优化案件模块
This commit is contained in:
287
finance/views.py
287
finance/views.py
@@ -1797,6 +1797,7 @@ class loandisplay(APIView):
|
||||
user_agents_page = paginator.page(paginator.num_pages)
|
||||
data = []
|
||||
import re
|
||||
import json
|
||||
from business.models import Case, ProjectRegistration
|
||||
|
||||
for info in user_agents_page.object_list:
|
||||
@@ -1813,38 +1814,139 @@ class loandisplay(APIView):
|
||||
if case:
|
||||
# 提取委托人名字(只返回纯名字)
|
||||
if case.client_name:
|
||||
# 提取名字部分:去除身份证号、括号内容等
|
||||
client_name = case.client_name.split(',')[0].split(',')[0].strip()
|
||||
client_name = re.sub(r'[((].*?[))]', '', client_name) # 去除括号内容
|
||||
client_name = re.sub(r'\d{15,18}', '', client_name) # 去除身份证号
|
||||
client_name = re.sub(r'[^\u4e00-\u9fa5a-zA-Z0-9]', '', client_name).strip() # 只保留中文、英文、数字
|
||||
if client_name and len(client_name) >= 2:
|
||||
customer_names.append(client_name)
|
||||
client_name_str = str(case.client_name).strip()
|
||||
# 先尝试 JSON/ast 解析
|
||||
parsed_client = None
|
||||
try:
|
||||
parsed_client = json.loads(client_name_str)
|
||||
except Exception:
|
||||
try:
|
||||
import ast
|
||||
parsed_client = ast.literal_eval(client_name_str)
|
||||
except Exception:
|
||||
parsed_client = None
|
||||
|
||||
# 从解析结果中提取 name 字段
|
||||
if isinstance(parsed_client, list):
|
||||
for item in parsed_client:
|
||||
if isinstance(item, dict):
|
||||
n = item.get("name")
|
||||
if n:
|
||||
customer_names.append(str(n).strip())
|
||||
elif isinstance(parsed_client, dict):
|
||||
n = parsed_client.get("name")
|
||||
if n:
|
||||
customer_names.append(str(n).strip())
|
||||
else:
|
||||
# 如果不是 JSON/结构体,按字符串处理
|
||||
client_name = client_name_str.split(',')[0].split(',')[0].strip()
|
||||
client_name = re.sub(r'[((].*?[))]', '', client_name) # 去除括号内容
|
||||
client_name = re.sub(r'\d{15,18}', '', client_name) # 去除身份证号
|
||||
client_name = re.sub(r'[^\u4e00-\u9fa5a-zA-Z0-9]', '', client_name).strip() # 只保留中文、英文、数字
|
||||
if client_name and len(client_name) >= 2:
|
||||
customer_names.append(client_name)
|
||||
|
||||
# 提取相对方名字(只返回纯名字)
|
||||
if case.party_name:
|
||||
party_name = case.party_name.split(',')[0].split(',')[0].strip()
|
||||
party_name = re.sub(r'[((].*?[))]', '', party_name) # 去除括号内容
|
||||
party_name = re.sub(r'\d{15,18}', '', party_name) # 去除身份证号
|
||||
party_name = re.sub(r'[^\u4e00-\u9fa5a-zA-Z0-9]', '', party_name).strip() # 只保留中文、英文、数字
|
||||
if party_name and len(party_name) >= 2:
|
||||
customer_names.append(party_name)
|
||||
party_name_str = str(case.party_name).strip()
|
||||
# 先尝试 JSON/ast 解析
|
||||
parsed_party = None
|
||||
try:
|
||||
parsed_party = json.loads(party_name_str)
|
||||
except Exception:
|
||||
try:
|
||||
import ast
|
||||
parsed_party = ast.literal_eval(party_name_str)
|
||||
except Exception:
|
||||
parsed_party = None
|
||||
|
||||
# 从解析结果中提取 name 字段
|
||||
if isinstance(parsed_party, list):
|
||||
for item in parsed_party:
|
||||
if isinstance(item, dict):
|
||||
n = item.get("name")
|
||||
if n:
|
||||
customer_names.append(str(n).strip())
|
||||
elif isinstance(parsed_party, dict):
|
||||
n = parsed_party.get("name")
|
||||
if n:
|
||||
customer_names.append(str(n).strip())
|
||||
else:
|
||||
# 如果不是 JSON/结构体,按字符串处理
|
||||
party_name = party_name_str.split(',')[0].split(',')[0].strip()
|
||||
party_name = re.sub(r'[((].*?[))]', '', party_name) # 去除括号内容
|
||||
party_name = re.sub(r'\d{15,18}', '', party_name) # 去除身份证号
|
||||
party_name = re.sub(r'[^\u4e00-\u9fa5a-zA-Z0-9]', '', party_name).strip() # 只保留中文、英文、数字
|
||||
if party_name and len(party_name) >= 2:
|
||||
customer_names.append(party_name)
|
||||
|
||||
# 如果Case中没有,从关联的project获取
|
||||
if not customer_names and case.project:
|
||||
if case.project.client_info:
|
||||
client_info = case.project.client_info.split(',')[0].split(',')[0].strip()
|
||||
client_info = re.sub(r'[((].*?[))]', '', client_info) # 去除括号内容
|
||||
client_info = re.sub(r'\d{15,18}', '', client_info) # 去除身份证号
|
||||
client_info = re.sub(r'[^\u4e00-\u9fa5a-zA-Z0-9]', '', client_info).strip() # 只保留中文、英文、数字
|
||||
if client_info and len(client_info) >= 2:
|
||||
customer_names.append(client_info)
|
||||
client_info_str = str(case.project.client_info).strip()
|
||||
# 先尝试 JSON/ast 解析
|
||||
parsed_client_info = None
|
||||
try:
|
||||
parsed_client_info = json.loads(client_info_str)
|
||||
except Exception:
|
||||
try:
|
||||
import ast
|
||||
parsed_client_info = ast.literal_eval(client_info_str)
|
||||
except Exception:
|
||||
parsed_client_info = None
|
||||
|
||||
# 从解析结果中提取 name 字段
|
||||
if isinstance(parsed_client_info, list):
|
||||
for item in parsed_client_info:
|
||||
if isinstance(item, dict):
|
||||
n = item.get("name")
|
||||
if n:
|
||||
customer_names.append(str(n).strip())
|
||||
elif isinstance(parsed_client_info, dict):
|
||||
n = parsed_client_info.get("name")
|
||||
if n:
|
||||
customer_names.append(str(n).strip())
|
||||
else:
|
||||
# 如果不是 JSON/结构体,按字符串处理
|
||||
client_info = client_info_str.split(',')[0].split(',')[0].strip()
|
||||
client_info = re.sub(r'[((].*?[))]', '', client_info) # 去除括号内容
|
||||
client_info = re.sub(r'\d{15,18}', '', client_info) # 去除身份证号
|
||||
client_info = re.sub(r'[^\u4e00-\u9fa5a-zA-Z0-9]', '', client_info).strip() # 只保留中文、英文、数字
|
||||
if client_info and len(client_info) >= 2:
|
||||
customer_names.append(client_info)
|
||||
|
||||
if case.project.party_info:
|
||||
party_info = case.project.party_info.split(',')[0].split(',')[0].strip()
|
||||
party_info = re.sub(r'[((].*?[))]', '', party_info) # 去除括号内容
|
||||
party_info = re.sub(r'\d{15,18}', '', party_info) # 去除身份证号
|
||||
party_info = re.sub(r'[^\u4e00-\u9fa5a-zA-Z0-9]', '', party_info).strip() # 只保留中文、英文、数字
|
||||
if party_info and len(party_info) >= 2:
|
||||
customer_names.append(party_info)
|
||||
party_info_str = str(case.project.party_info).strip()
|
||||
# 先尝试 JSON/ast 解析
|
||||
parsed_party_info = None
|
||||
try:
|
||||
parsed_party_info = json.loads(party_info_str)
|
||||
except Exception:
|
||||
try:
|
||||
import ast
|
||||
parsed_party_info = ast.literal_eval(party_info_str)
|
||||
except Exception:
|
||||
parsed_party_info = None
|
||||
|
||||
# 从解析结果中提取 name 字段
|
||||
if isinstance(parsed_party_info, list):
|
||||
for item in parsed_party_info:
|
||||
if isinstance(item, dict):
|
||||
n = item.get("name")
|
||||
if n:
|
||||
customer_names.append(str(n).strip())
|
||||
elif isinstance(parsed_party_info, dict):
|
||||
n = parsed_party_info.get("name")
|
||||
if n:
|
||||
customer_names.append(str(n).strip())
|
||||
else:
|
||||
# 如果不是 JSON/结构体,按字符串处理
|
||||
party_info = party_info_str.split(',')[0].split(',')[0].strip()
|
||||
party_info = re.sub(r'[((].*?[))]', '', party_info) # 去除括号内容
|
||||
party_info = re.sub(r'\d{15,18}', '', party_info) # 去除身份证号
|
||||
party_info = re.sub(r'[^\u4e00-\u9fa5a-zA-Z0-9]', '', party_info).strip() # 只保留中文、英文、数字
|
||||
if party_info and len(party_info) >= 2:
|
||||
customer_names.append(party_info)
|
||||
except:
|
||||
pass
|
||||
|
||||
@@ -1858,41 +1960,124 @@ class loandisplay(APIView):
|
||||
if project:
|
||||
# 提取委托人名字(只返回纯名字)
|
||||
if project.client_info:
|
||||
client_info = project.client_info.split(',')[0].split(',')[0].strip()
|
||||
client_info = re.sub(r'[((].*?[))]', '', client_info) # 去除括号内容
|
||||
client_info = re.sub(r'\d{15,18}', '', client_info) # 去除身份证号
|
||||
client_info = re.sub(r'[^\u4e00-\u9fa5a-zA-Z0-9]', '', client_info).strip() # 只保留中文、英文、数字
|
||||
if client_info and len(client_info) >= 2:
|
||||
customer_names.append(client_info)
|
||||
client_info_str = str(project.client_info).strip()
|
||||
# 先尝试 JSON/ast 解析
|
||||
parsed_client_info = None
|
||||
try:
|
||||
parsed_client_info = json.loads(client_info_str)
|
||||
except Exception:
|
||||
try:
|
||||
import ast
|
||||
parsed_client_info = ast.literal_eval(client_info_str)
|
||||
except Exception:
|
||||
parsed_client_info = None
|
||||
|
||||
# 从解析结果中提取 name 字段
|
||||
if isinstance(parsed_client_info, list):
|
||||
for item in parsed_client_info:
|
||||
if isinstance(item, dict):
|
||||
n = item.get("name")
|
||||
if n:
|
||||
customer_names.append(str(n).strip())
|
||||
elif isinstance(parsed_client_info, dict):
|
||||
n = parsed_client_info.get("name")
|
||||
if n:
|
||||
customer_names.append(str(n).strip())
|
||||
else:
|
||||
# 如果不是 JSON/结构体,按字符串处理
|
||||
client_info = client_info_str.split(',')[0].split(',')[0].strip()
|
||||
client_info = re.sub(r'[((].*?[))]', '', client_info) # 去除括号内容
|
||||
client_info = re.sub(r'\d{15,18}', '', client_info) # 去除身份证号
|
||||
client_info = re.sub(r'[^\u4e00-\u9fa5a-zA-Z0-9]', '', client_info).strip() # 只保留中文、英文、数字
|
||||
if client_info and len(client_info) >= 2:
|
||||
customer_names.append(client_info)
|
||||
|
||||
# 提取相对方名字(只返回纯名字)
|
||||
if project.party_info:
|
||||
party_info = project.party_info.split(',')[0].split(',')[0].strip()
|
||||
party_info = re.sub(r'[((].*?[))]', '', party_info) # 去除括号内容
|
||||
party_info = re.sub(r'\d{15,18}', '', party_info) # 去除身份证号
|
||||
party_info = re.sub(r'[^\u4e00-\u9fa5a-zA-Z0-9]', '', party_info).strip() # 只保留中文、英文、数字
|
||||
if party_info and len(party_info) >= 2:
|
||||
customer_names.append(party_info)
|
||||
party_info_str = str(project.party_info).strip()
|
||||
# 先尝试 JSON/ast 解析
|
||||
parsed_party_info = None
|
||||
try:
|
||||
parsed_party_info = json.loads(party_info_str)
|
||||
except Exception:
|
||||
try:
|
||||
import ast
|
||||
parsed_party_info = ast.literal_eval(party_info_str)
|
||||
except Exception:
|
||||
parsed_party_info = None
|
||||
|
||||
# 从解析结果中提取 name 字段
|
||||
if isinstance(parsed_party_info, list):
|
||||
for item in parsed_party_info:
|
||||
if isinstance(item, dict):
|
||||
n = item.get("name")
|
||||
if n:
|
||||
customer_names.append(str(n).strip())
|
||||
elif isinstance(parsed_party_info, dict):
|
||||
n = parsed_party_info.get("name")
|
||||
if n:
|
||||
customer_names.append(str(n).strip())
|
||||
else:
|
||||
# 如果不是 JSON/结构体,按字符串处理
|
||||
party_info = party_info_str.split(',')[0].split(',')[0].strip()
|
||||
party_info = re.sub(r'[((].*?[))]', '', party_info) # 去除括号内容
|
||||
party_info = re.sub(r'\d{15,18}', '', party_info) # 去除身份证号
|
||||
party_info = re.sub(r'[^\u4e00-\u9fa5a-zA-Z0-9]', '', party_info).strip() # 只保留中文、英文、数字
|
||||
if party_info and len(party_info) >= 2:
|
||||
customer_names.append(party_info)
|
||||
except:
|
||||
pass
|
||||
|
||||
# 如果找不到案件信息,从CustomerID字段中提取名字
|
||||
if not customer_names and info.CustomerID:
|
||||
# 尝试从CustomerID中提取名字(可能包含多个客户,用逗号或分号分隔)
|
||||
customer_id_str = str(info.CustomerID).strip()
|
||||
if customer_id_str:
|
||||
# 先尝试按常见分隔符分割
|
||||
parts = re.split(r'[,,;;\s]+', customer_id_str)
|
||||
for part in parts:
|
||||
part = part.strip()
|
||||
if part:
|
||||
# 提取纯名字部分:去除身份证号、括号内容、特殊字符等
|
||||
# 只保留中文字符、英文字母、数字(用于名字)
|
||||
name = re.sub(r'[((].*?[))]', '', part) # 去除括号内容
|
||||
name = re.sub(r'\d{15,18}', '', name) # 去除身份证号
|
||||
name = re.sub(r'[^\u4e00-\u9fa5a-zA-Z0-9]', '', name) # 只保留中文、英文、数字
|
||||
name = name.strip()
|
||||
if name and len(name) >= 2 and name not in customer_names: # 名字至少2个字符
|
||||
customer_names.append(name)
|
||||
# 先尝试按 JSON 解析(例如:[{"index":1,"name":"测试111","idNumber":"111"}])
|
||||
import json
|
||||
parsed = None
|
||||
try:
|
||||
parsed = json.loads(customer_id_str)
|
||||
except Exception:
|
||||
parsed = None
|
||||
|
||||
# 如果 JSON 解析失败,再尝试按 Python 字面量解析(例如:[{'index': 1, 'name': '测试111'}])
|
||||
if parsed is None:
|
||||
import ast
|
||||
try:
|
||||
parsed = ast.literal_eval(customer_id_str)
|
||||
except Exception:
|
||||
parsed = None
|
||||
|
||||
names_from_struct = []
|
||||
if isinstance(parsed, list):
|
||||
for item in parsed:
|
||||
if isinstance(item, dict):
|
||||
n = item.get("name")
|
||||
if n:
|
||||
names_from_struct.append(str(n).strip())
|
||||
elif isinstance(parsed, dict):
|
||||
n = parsed.get("name")
|
||||
if n:
|
||||
names_from_struct.append(str(n).strip())
|
||||
|
||||
if names_from_struct:
|
||||
for n in names_from_struct:
|
||||
if n and n not in customer_names:
|
||||
customer_names.append(n)
|
||||
else:
|
||||
# 如果既不是 JSON 也不是 Python 结构,再按原有字符串方式解析(逗号/分号分隔)
|
||||
parts = re.split(r'[,,;;\s]+', customer_id_str)
|
||||
for part in parts:
|
||||
part = part.strip()
|
||||
if part:
|
||||
# 提取纯名字部分:去除身份证号、括号内容、特殊字符等
|
||||
# 只保留中文字符、英文字母、数字(用于名字)
|
||||
name = re.sub(r'[((].*?[))]', '', part) # 去除括号内容
|
||||
name = re.sub(r'\d{15,18}', '', name) # 去除身份证号
|
||||
name = re.sub(r'[^\u4e00-\u9fa5a-zA-Z0-9]', '', name) # 只保留中文、英文、数字
|
||||
name = name.strip()
|
||||
if name and len(name) >= 2 and name not in customer_names: # 名字至少2个字符
|
||||
customer_names.append(name)
|
||||
|
||||
# 去重并连接,只返回客户名字
|
||||
customer_names = list(dict.fromkeys(customer_names)) # 保持顺序去重
|
||||
|
||||
Reference in New Issue
Block a user