优化案件模块
This commit is contained in:
@@ -1796,10 +1796,12 @@ class loandisplay(APIView):
|
||||
except EmptyPage:
|
||||
user_agents_page = paginator.page(paginator.num_pages)
|
||||
data = []
|
||||
import re
|
||||
from business.models import Case, ProjectRegistration
|
||||
|
||||
for info in user_agents_page.object_list:
|
||||
# 通过合同号查找关联的案件,提取客户名字
|
||||
# 通过合同号查找关联的案件,提取客户名字(只返回纯名字)
|
||||
customer_names = []
|
||||
from business.models import Case, ProjectRegistration
|
||||
|
||||
if info.ContractNo:
|
||||
# 优先从Case(案件管理)中查找
|
||||
@@ -1809,27 +1811,39 @@ class loandisplay(APIView):
|
||||
is_deleted=False
|
||||
).first()
|
||||
if case:
|
||||
# 提取委托人名字
|
||||
# 提取委托人名字(只返回纯名字)
|
||||
if case.client_name:
|
||||
# 提取名字部分(去除身份证号等信息)
|
||||
# 提取名字部分:去除身份证号、括号内容等
|
||||
client_name = case.client_name.split(',')[0].split(',')[0].strip()
|
||||
if client_name:
|
||||
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()
|
||||
if party_name:
|
||||
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()
|
||||
if client_info:
|
||||
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()
|
||||
if party_info:
|
||||
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
|
||||
@@ -1842,15 +1856,21 @@ class loandisplay(APIView):
|
||||
is_deleted=False
|
||||
).first()
|
||||
if project:
|
||||
# 提取委托人名字
|
||||
# 提取委托人名字(只返回纯名字)
|
||||
if project.client_info:
|
||||
client_info = project.client_info.split(',')[0].split(',')[0].strip()
|
||||
if client_info:
|
||||
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()
|
||||
if party_info:
|
||||
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
|
||||
@@ -1860,21 +1880,23 @@ class loandisplay(APIView):
|
||||
# 尝试从CustomerID中提取名字(可能包含多个客户,用逗号或分号分隔)
|
||||
customer_id_str = str(info.CustomerID).strip()
|
||||
if customer_id_str:
|
||||
# 尝试按逗号、分号、空格等分隔
|
||||
import re
|
||||
# 先尝试按常见分隔符分割
|
||||
parts = re.split(r'[,,;;\s]+', customer_id_str)
|
||||
for part in parts:
|
||||
part = part.strip()
|
||||
if part:
|
||||
# 提取名字部分(去除身份证号等信息)
|
||||
name = part.split(',')[0].split(',')[0].split('(')[0].split('(')[0].strip()
|
||||
if name and name not in customer_names:
|
||||
# 提取纯名字部分:去除身份证号、括号内容、特殊字符等
|
||||
# 只保留中文字符、英文字母、数字(用于名字)
|
||||
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)) # 保持顺序去重
|
||||
customer_name_str = ','.join(customer_names) if customer_names else (info.CustomerID or '')
|
||||
customer_name_str = ','.join(customer_names) if customer_names else ''
|
||||
|
||||
itme = {
|
||||
'id': info.id,
|
||||
|
||||
Reference in New Issue
Block a user