diff --git a/business/views.py b/business/views.py index ff4fd77..4690a9c 100644 --- a/business/views.py +++ b/business/views.py @@ -18,6 +18,63 @@ from django.db.models import Count, Q from django.db import transaction import os +def normalize_match_reason(reason_str): + """ + 将多条重复语义的冲突原因归纳为简洁、易读的一条或几条说明。 + 例如:委托人姓名匹配;相对方与委托人姓名匹配;相对方姓名匹配;委托人与相对方姓名匹配 + 归纳为:委托人姓名与历史记录一致;相对方姓名与历史记录一致 + """ + if not reason_str or reason_str.strip() == '匹配': + return reason_str.strip() or '匹配' + parts = [p.strip() for p in reason_str.split(';') if p.strip()] + # 按类型归纳,避免重复表述 + has_client_name = any( + '委托人姓名匹配' in p or '相对方与委托人姓名匹配' in p for p in parts + ) + has_client_info = any( + '委托人信息匹配' in p or '相对方与委托人信息匹配' in p for p in parts + ) + has_client_id = any('委托人身份证号匹配' in p for p in parts) + has_party_name = any( + '相对方姓名匹配' in p or '委托人与相对方姓名匹配' in p for p in parts + ) + has_party_info = any( + '相对方信息匹配' in p or '委托人与相对方信息匹配' in p for p in parts + ) + has_party_id = any('相对方身份证号匹配' in p for p in parts) + # 立项表:相对方与委托人身份证号匹配 等 + has_party_client_id = any( + '相对方与委托人身份证号匹配' in p or '委托人与相对方身份证号匹配' in p for p in parts + ) + undertaker_parts = [p for p in parts if '承办人员匹配' in p or '承办人' in p] + responsible_parts = [p for p in parts if '负责人匹配' in p] + # 招标单位相关(投标表) + bid_parts = [ + p for p in parts + if '招标单位' in p or '在招标单位中' in p or '在招标单位' in p + ] + result = [] + if has_client_name: + result.append('委托人姓名与历史记录一致') + if has_client_info: + result.append('委托人信息与历史记录一致') + if has_client_id: + result.append('委托人身份证号与历史记录一致') + if has_party_name: + result.append('相对方姓名与历史记录一致') + if has_party_info: + result.append('相对方信息与历史记录一致') + if has_party_id: + result.append('相对方身份证号与历史记录一致') + # 立项表:委托人身份证在相对方字段/相对方身份证在委托人字段出现时 + if has_party_client_id and not (has_client_id or has_party_id): + result.append('委托人或相对方身份证号与历史记录一致') + result.extend(undertaker_parts) + result.extend(responsible_parts) + result.extend(bid_parts) + return ';'.join(result) if result else '匹配' + + def get_user_team_name(username): if not username: return None @@ -4412,7 +4469,7 @@ def conflict_search(client_info=None, party_info=None, undertaker=None, bidding_ 'party_username': pf.party_username, 'description': pf.description, 'Undertaker': pf.Undertaker, - 'match_reason': ';'.join(match_reason) if match_reason else '匹配' + 'match_reason': normalize_match_reason(';'.join(match_reason) if match_reason else '匹配') }) result['prefiling_conflicts'] = matched_prefilings @@ -4517,7 +4574,7 @@ def conflict_search(client_info=None, party_info=None, undertaker=None, bidding_ 'party_info': pro.party_info, 'description': pro.description, 'responsiblefor': pro.responsiblefor, - 'match_reason': ';'.join(match_reason) if match_reason else '匹配' + 'match_reason': normalize_match_reason(';'.join(match_reason) if match_reason else '匹配') }) result['project_conflicts'] = project_list @@ -4570,7 +4627,7 @@ def conflict_search(client_info=None, party_info=None, undertaker=None, bidding_ 'times': bid.times, 'BiddingUnit': bid.BiddingUnit, 'state': bid.state, - 'match_reason': ';'.join(match_reason) if match_reason else '匹配' + 'match_reason': normalize_match_reason(';'.join(match_reason) if match_reason else '匹配') }) result['bid_conflicts'] = bid_list