This commit is contained in:
27942
2026-02-06 02:19:54 +08:00
parent 456b7ca03b
commit b3e6235c20

View File

@@ -4246,8 +4246,23 @@ def _extract_all_person_info(info_val):
originals.append(orig)
if names or id_numbers:
return names, id_numbers, originals
# 回退到 parse_person_info 处理普通字符串
# 回退到处理普通字符串
if isinstance(info_val, str):
# 先尝试匹配多个 "name(id)" 格式(如 "张三(123456),李四(789012)"
matches = re.findall(r'([^,(]+?)\s*[(]([^)]*)[)]', info_val)
if matches:
for name, id_num in matches:
name = name.strip()
id_num = id_num.strip()
if name:
names.append(name)
if id_num:
id_numbers.append(id_num)
orig = f"{name}{id_num}" if name and id_num else (name or id_num or '')
if orig:
originals.append(orig)
return names, id_numbers, originals
# 没有匹配到多人格式,回退到单人解析
parsed = parse_person_info(info_val)
if parsed['name']:
names.append(parsed['name'])
@@ -4656,12 +4671,22 @@ class ConflictSearch(APIView):
)
# 归一化冲突记录为前端期望格式 [{ index, name, idNumber }, ...](预立案用 client_username/party_username立项用 client_info/party_info投标用 BiddingUnit
def _normalize_person_list(val):
"""
归一化人员信息,始终返回 list[dict] 或 None。
支持:
- JSON 数组字符串:'[{"name":"张三","idNumber":"111"}]'
- JSON 对象字符串:'{"name":"张三","idNumber":"111"}'
- list / dict已解析的 JSON
- 纯字符串:"张三111""张三(111),李四(222)"
"""
if not val:
return []
try:
lst = json.loads(val) if isinstance(val, str) else val
if isinstance(lst, dict):
lst = [lst]
if not isinstance(lst, list):
return None
raise ValueError("not a list")
out = []
for i, item in enumerate(lst):
if not isinstance(item, dict):
@@ -4679,9 +4704,37 @@ class ConflictSearch(APIView):
})
return out
except (json.JSONDecodeError, TypeError, ValueError):
return None
pass
# 回退:解析纯字符串格式(如 "张三123456" 或 "张三(123),李四(456)"
if isinstance(val, str):
# 尝试匹配多个 "name(id)" 格式
matches = re.findall(r'([^,(]+?)\s*[(]([^)]*)[)]', val)
if matches:
out = []
for i, (name, id_num) in enumerate(matches):
out.append({
'index': i + 1,
'name': name.strip(),
'idNumber': id_num.strip()
})
return out
# 没有括号格式,尝试用 parse_person_info 解析
parsed = parse_person_info(val)
if parsed['name'] or parsed['id_number']:
return [{
'index': 1,
'name': parsed['name'],
'idNumber': parsed['id_number']
}]
return None
def _normalize_conflict_records(records):
"""
归一化冲突记录,将人员信息字段统一转为 JSON 字符串格式:
'[{"index":1,"name":"张三","idNumber":"123456"}]'
确保前端可以使用 isValidFormat() + JSON.parse() 正确展示。
"""
processed = []
for record in records:
new_record = dict(record)
@@ -4690,7 +4743,8 @@ class ConflictSearch(APIView):
continue
normalized = _normalize_person_list(new_record[key])
if normalized is not None:
new_record[key] = normalized
# 转为 JSON 字符串,兼容前端 JSON.parse() 展示
new_record[key] = json.dumps(normalized, ensure_ascii=False)
processed.append(new_record)
return processed