|
@@ -31,6 +31,12 @@ dict_role_id = {"0":"tenderee",
|
|
|
"3":"second_tenderer",
|
|
|
"4":"third_tenderer"}
|
|
|
|
|
|
+role2id_dict = {"tenderee":0,
|
|
|
+ "agency":1,
|
|
|
+ "win_tenderer":2,
|
|
|
+ "second_tenderer":3,
|
|
|
+ "third_tenderer":4}
|
|
|
+
|
|
|
def getPackage(packageList,sentence_index,begin_index,roleid,MAX_DIS=None,DIRECT=None):
|
|
|
'''
|
|
|
@param:
|
|
@@ -1097,7 +1103,7 @@ def findAttributeAfterEntity(PackDict,roleSet,PackageList,PackageSet,list_senten
|
|
|
def addRatioByEntity(packDict,packageName,entity,ratio):
|
|
|
for i in range(len(packDict[packageName]["roleList"])):
|
|
|
if packDict[packageName]["roleList"][i].entity_text==entity:
|
|
|
- packDict[packageName]["roleList"][i].ratio = ratio.entity_text
|
|
|
+ packDict[packageName]["roleList"][i].ratio = ratio.ratio_value
|
|
|
def addServiceTimeByEntity(packDict,packageName,entity,serviceTime):
|
|
|
for i in range(len(packDict[packageName]["roleList"])):
|
|
|
if packDict[packageName]["roleList"][i].entity_text==entity:
|
|
@@ -1119,13 +1125,29 @@ def findAttributeAfterEntity(PackDict,roleSet,PackageList,PackageSet,list_senten
|
|
|
p_entity = 0
|
|
|
|
|
|
# 2021/7/19 顺序比较金额,前面是后面的一万倍则把前面金额/10000
|
|
|
- money_list = [it for it in list_entity if it.entity_type=="money"]
|
|
|
- for i in range(len(money_list)-1):
|
|
|
- for j in range(1, len(money_list)):
|
|
|
- if (float(money_list[i].entity_text) > 5000000000 or money_list[j].notes=='大写') and \
|
|
|
- Decimal(money_list[i].entity_text)/Decimal(money_list[j].entity_text)==10000:
|
|
|
- money_list[i].entity_text = str(Decimal(money_list[i].entity_text)/10000)
|
|
|
- # print('连接前修改大于50亿金额:前面是后面的一万倍则把前面金额/10000')
|
|
|
+ # money_list = [it for it in list_entity if it.entity_type=="money"]
|
|
|
+ # for i in range(len(money_list)-1):
|
|
|
+ # for j in range(1, len(money_list)):
|
|
|
+ # if (float(money_list[i].entity_text) > 5000000000 or money_list[j].notes=='大写') and \
|
|
|
+ # Decimal(money_list[i].entity_text)/Decimal(money_list[j].entity_text)==10000:
|
|
|
+ # money_list[i].entity_text = str(Decimal(money_list[i].entity_text)/10000)
|
|
|
+ # # print('连接前修改大于50亿金额:前面是后面的一万倍则把前面金额/10000')
|
|
|
+
|
|
|
+ '''同样金额同时有元及万元单位的,把万元的金额改为元'''
|
|
|
+ wanyuan = []
|
|
|
+ yuan = []
|
|
|
+ for it in list_entity:
|
|
|
+ if it.entity_type == "money" and float(it.entity_text)>5000:
|
|
|
+ if it.money_unit == '万元':
|
|
|
+ wanyuan.append(it)
|
|
|
+ else:
|
|
|
+ yuan.append(it)
|
|
|
+ if wanyuan != [] and yuan != []:
|
|
|
+ for m1 in wanyuan:
|
|
|
+ for m2 in yuan:
|
|
|
+ if Decimal(m1.entity_text)/Decimal(m2.entity_text) == 10000:
|
|
|
+ m1.entity_text = m2.entity_text
|
|
|
+
|
|
|
|
|
|
#遍历所有实体
|
|
|
# while(p_entity<len(list_entity)):
|
|
@@ -1486,7 +1508,6 @@ def findAttributeAfterEntity(PackDict,roleSet,PackageList,PackageSet,list_senten
|
|
|
for one_phone in _phone:
|
|
|
PackDict["Project"]["roleList"][i].linklist.append(("", one_phone))
|
|
|
agency_phone.add(one_phone)
|
|
|
-
|
|
|
# 正则提取电话号码实体
|
|
|
# key_word = re.compile('((?:电话|联系方式|联系人).{0,4}?)([0-1]\d{6,11})')
|
|
|
phone = re.compile('1[3-9][0-9][-—-―]?\d{4}[-—-―]?\d{4}|'
|
|
@@ -1499,14 +1520,18 @@ def findAttributeAfterEntity(PackDict,roleSet,PackageList,PackageSet,list_senten
|
|
|
'0[1-9]\d{1,2}[-—-―]?[1-9]\d{6}\d?(?=[1-9]\d{6,7})|'
|
|
|
'0[1-9]\d{1,2}[-—-―]?[1-9]\d{6}\d?|'
|
|
|
'[\(|\(]0[1-9]\d{1,2}[\)|\)]-?\d{7,8}-?\d{,4}|'
|
|
|
+ '400\d{7}转\d{1,4}|'
|
|
|
'[2-9]\d{6,7}')
|
|
|
- url_pattern = re.compile("http[s]?://(?:[a-zA-Z]|[0-9]|[$\-_@.&+=\?:/]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+")
|
|
|
+ url_pattern = re.compile("http[s]?://(?:[a-zA-Z]|[0-9]|[#$\-_@.&+=\?:/]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+")
|
|
|
email_pattern = re.compile("[a-zA-Z0-9][a-zA-Z0-9_-]+(?:\.[a-zA-Z0-9_-]+)*@"
|
|
|
"[a-zA-Z0-9_-]+(?:\.[a-zA-Z0-9_-]+)*(?:\.[a-zA-Z]{2,})")
|
|
|
phone_entitys = []
|
|
|
code_entitys = [ent for ent in list_entity if ent.entity_type=='code']
|
|
|
for _sentence in list_sentence:
|
|
|
sentence_text = _sentence.sentence_text
|
|
|
+ # 过长数字串直接过滤替换
|
|
|
+ for _re in re.findall("\d{50,}",sentence_text):
|
|
|
+ sentence_text = sentence_text.replace(_re,"#"*len(_re))
|
|
|
in_attachment = _sentence.in_attachment
|
|
|
list_tokenbegin = []
|
|
|
begin = 0
|
|
@@ -1533,6 +1558,8 @@ def findAttributeAfterEntity(PackDict,roleSet,PackageList,PackageSet,list_senten
|
|
|
continue
|
|
|
res_set.add((i.group(), i.start(), i.end()))
|
|
|
res_set = sorted(list(res_set),key=lambda x:x[1])
|
|
|
+ # 限制数量,防止异常数据处理时间过长
|
|
|
+ res_set = res_set[:200]
|
|
|
last_phone_mask = True
|
|
|
error_numStr_index = []
|
|
|
sentence_phone_list = []
|
|
@@ -1554,7 +1581,7 @@ def findAttributeAfterEntity(PackDict,roleSet,PackageList,PackageSet,list_senten
|
|
|
pass
|
|
|
else:
|
|
|
# 排除“传真号”和其它错误项
|
|
|
- if re.search("传,?真|信,?箱|邮,?[箱件]|QQ|qq", phone_left):
|
|
|
+ if re.search("传,?真|信,?箱|邮,?[编箱件]|QQ|qq", phone_left):
|
|
|
if not re.search("电,?话", phone_left):
|
|
|
error_numStr_index.append(numStr_index)
|
|
|
last_phone_mask = False
|
|
@@ -1596,6 +1623,20 @@ def findAttributeAfterEntity(PackDict,roleSet,PackageList,PackageSet,list_senten
|
|
|
error_numStr_index.append(numStr_index)
|
|
|
last_phone_mask = False
|
|
|
continue
|
|
|
+ left_context = re.search("[\da-zA-Z\-—-―]+$",sentence_text[:item[1]])
|
|
|
+ if left_context:
|
|
|
+ if len(left_context.group()) != len("".join(re.findall(phone, left_context.group()))):
|
|
|
+ # if not re.search("(" + phone.pattern + ")$", left_context.group()):
|
|
|
+ error_numStr_index.append(numStr_index)
|
|
|
+ last_phone_mask = False
|
|
|
+ continue
|
|
|
+ right_context = re.search("^[\da-zA-Z\-—-―]+", sentence_text[item[2]:])
|
|
|
+ if right_context:
|
|
|
+ if len(right_context.group()) != len("".join(re.findall(phone, right_context.group()))):
|
|
|
+ # if not re.search("^(" + phone.pattern + ")", right_context.group()):
|
|
|
+ error_numStr_index.append(numStr_index)
|
|
|
+ last_phone_mask = False
|
|
|
+ continue
|
|
|
# if:上一个phone实体不符合条件
|
|
|
if not last_phone_mask:
|
|
|
item_start = item[1]
|
|
@@ -1771,52 +1812,58 @@ def findAttributeAfterEntity(PackDict,roleSet,PackageList,PackageSet,list_senten
|
|
|
break
|
|
|
# print(3,combo[0].entity_text,combo[1].entity_text)
|
|
|
|
|
|
- # "公司——地址" 链接规则补充
|
|
|
- company_lacation_EntityList = [ent for ent in pre_entity if ent.entity_type in ['company', 'org', 'location']]
|
|
|
- company_lacation_EntityList = sorted(company_lacation_EntityList, key=lambda x: (x.sentence_index, x.begin_index))
|
|
|
- t_match_list = []
|
|
|
- for ent_idx in range(len(company_lacation_EntityList)):
|
|
|
- entity = company_lacation_EntityList[ent_idx]
|
|
|
- if entity.entity_type in ['company', 'org']:
|
|
|
- match_nums = 0
|
|
|
- company_nums = 0 # 经过其他公司的数量
|
|
|
- location_nums = 0 # 经过电话的数量
|
|
|
- for after_index in range(ent_idx + 1, min(len(company_lacation_EntityList), ent_idx + 5)):
|
|
|
- after_entity = company_lacation_EntityList[after_index]
|
|
|
- if after_entity.entity_type == "location":
|
|
|
- distance = (tokens_num_dict[after_entity.sentence_index] + after_entity.begin_index) - (
|
|
|
- tokens_num_dict[entity.sentence_index] + entity.end_index)
|
|
|
- location_nums += 1
|
|
|
- if distance > 100 or location_nums >= 3:
|
|
|
- break
|
|
|
- sentence_distance = after_entity.sentence_index - entity.sentence_index
|
|
|
- value = (-1 / 2 * (distance ** 2)) / 10000
|
|
|
- if sentence_distance == 0:
|
|
|
- if distance < 80:
|
|
|
- t_match_list.append(Match(entity, after_entity, value))
|
|
|
- match_nums += 1
|
|
|
- if company_nums:
|
|
|
- break
|
|
|
- else:
|
|
|
- if distance < 50:
|
|
|
- t_match_list.append(Match(entity, after_entity, value))
|
|
|
- match_nums += 1
|
|
|
- if company_nums:
|
|
|
- break
|
|
|
+ # "公司——地址" 链接规则补充
|
|
|
+ company_lacation_EntityList = [ent for ent in pre_entity if ent.entity_type in ['company', 'org', 'location']]
|
|
|
+ # company_lacation_EntityList = [ent for ent in pre_entity if (ent.entity_type in ['company', 'org'] and ent.label!=5) or ent.entity_type=="location"]
|
|
|
+ company_lacation_EntityList = sorted(company_lacation_EntityList, key=lambda x: (x.sentence_index, x.begin_index))
|
|
|
+ t_match_list = []
|
|
|
+ for ent_idx in range(len(company_lacation_EntityList)):
|
|
|
+ entity = company_lacation_EntityList[ent_idx]
|
|
|
+ if entity.entity_type in ['company', 'org'] and entity.label!=5:
|
|
|
+ match_nums = 0
|
|
|
+ company_nums = 0 # 经过其他公司的数量
|
|
|
+ location_nums = 0 # 经过电话的数量
|
|
|
+ for after_index in range(ent_idx + 1, min(len(company_lacation_EntityList), ent_idx + 5)):
|
|
|
+ after_entity = company_lacation_EntityList[after_index]
|
|
|
+ if after_entity.entity_type == "location":
|
|
|
+ distance = (tokens_num_dict[after_entity.sentence_index] + after_entity.begin_index) - (
|
|
|
+ tokens_num_dict[entity.sentence_index] + entity.end_index)
|
|
|
+ location_nums += 1
|
|
|
+ if distance > 100 or location_nums >= 3:
|
|
|
+ break
|
|
|
+ sentence_distance = after_entity.sentence_index - entity.sentence_index
|
|
|
+ value = (-1 / 2 * (distance ** 2)) / 10000
|
|
|
+ if sentence_distance == 0:
|
|
|
+ if distance < 80:
|
|
|
+ t_match_list.append(Match(entity, after_entity, value))
|
|
|
+ match_nums += 1
|
|
|
+ if company_nums:
|
|
|
+ break
|
|
|
else:
|
|
|
- # type:company/org
|
|
|
- company_nums += 1
|
|
|
- if entity.label in [2, 3, 4] and after_entity.label in [0, 1]:
|
|
|
- break
|
|
|
+ if distance < 50:
|
|
|
+ t_match_list.append(Match(entity, after_entity, value))
|
|
|
+ match_nums += 1
|
|
|
+ if company_nums:
|
|
|
+ break
|
|
|
+ else:
|
|
|
+ # type:company/org
|
|
|
+ company_nums += 1
|
|
|
+ if entity.label in [2, 3, 4] and after_entity.label in [0, 1]:
|
|
|
+ break
|
|
|
+ if entity.label in [0, 1] and after_entity.label in [2, 3, 4]:
|
|
|
+ break
|
|
|
|
|
|
- # km算法分配求解
|
|
|
- relate_location_result = dispatch(t_match_list)
|
|
|
- relate_location_result = sorted(relate_location_result, key=lambda x: (x[0].sentence_index, x[0].begin_index))
|
|
|
- for match in relate_location_result:
|
|
|
- _company = match[0]
|
|
|
- _relation = match[1]
|
|
|
- if not _company.pointer_address:
|
|
|
- _company.pointer_address = _relation
|
|
|
+ # km算法分配求解
|
|
|
+ # for item in t_match_list:
|
|
|
+ # print("loc_rela",item.main_role.entity_text,item.attribute.entity_text)
|
|
|
+ relate_location_result = dispatch(t_match_list)
|
|
|
+ relate_location_result = sorted(relate_location_result, key=lambda x: (x[0].sentence_index, x[0].begin_index))
|
|
|
+ for match in relate_location_result:
|
|
|
+ _company = match[0]
|
|
|
+ _relation = match[1]
|
|
|
+ # print("loc_rela2", _company.entity_text, _relation.entity_text, )
|
|
|
+ if not _company.pointer_address:
|
|
|
+ _company.pointer_address = _relation
|
|
|
# "联系人——联系电话" 链接规则补充
|
|
|
person_phone_EntityList = [ent for ent in pre_entity+ phone_entitys if ent.entity_type not in ['company','org','location']]
|
|
|
person_phone_EntityList = sorted(person_phone_EntityList, key=lambda x: (x.sentence_index, x.begin_index))
|
|
@@ -2018,7 +2065,6 @@ def findAttributeAfterEntity(PackDict,roleSet,PackageList,PackageSet,list_senten
|
|
|
for _p in person_phone:
|
|
|
if per.entity_text not in tenderee_contact and _p.entity_text not in tenderee_phone and per.entity_text not in winter_contact:
|
|
|
PackDict[k]["roleList"][i].linklist.append((per.entity_text, _p.entity_text))
|
|
|
-
|
|
|
re_split = re.compile("[^\u4e00-\u9fa5、](十一|十二|十三|十四|十五|一|二|三|四|五|六|七|八|九|十)、")
|
|
|
split_list = [0] * 16
|
|
|
split_dict = {
|
|
@@ -2375,7 +2421,6 @@ def findAttributeAfterEntity(PackDict,roleSet,PackageList,PackageSet,list_senten
|
|
|
prepare_link.append(after_entity)
|
|
|
last_person = after_entity
|
|
|
continue
|
|
|
-
|
|
|
# 统一同类角色的属性
|
|
|
for k in PackDict.keys():
|
|
|
for i in range(len(PackDict[k]["roleList"])):
|
|
@@ -2428,6 +2473,7 @@ def findAttributeAfterEntity(PackDict,roleSet,PackageList,PackageSet,list_senten
|
|
|
PackDict[k]["roleList"][i].linklist.remove(_item)
|
|
|
|
|
|
# PackDict更新company/org地址
|
|
|
+ last_role_prob = {}
|
|
|
for ent in pre_entity:
|
|
|
if ent.entity_type in ['company','org']:
|
|
|
if ent.pointer_address:
|
|
@@ -2436,9 +2482,16 @@ def findAttributeAfterEntity(PackDict,roleSet,PackageList,PackageSet,list_senten
|
|
|
if PackDict[k]["roleList"][i].entity_text == ent.entity_text:
|
|
|
if not PackDict[k]["roleList"][i].address:
|
|
|
PackDict[k]["roleList"][i].address = ent.pointer_address.entity_text
|
|
|
+ last_role_prob[PackDict[k]["roleList"][i].role_name] = ent.values[role2id_dict[PackDict[k]["roleList"][i].role_name]]
|
|
|
else:
|
|
|
- if len(ent.pointer_address.entity_text) > len(PackDict[k]["roleList"][i].address):
|
|
|
- PackDict[k]["roleList"][i].address = ent.pointer_address.entity_text
|
|
|
+ if PackDict[k]["roleList"][i].role_name in ['tenderee','agency']:
|
|
|
+ # 角色为招标/代理人时,取其实体概率高的链接地址作为角色address
|
|
|
+ if ent.values[role2id_dict[PackDict[k]["roleList"][i].role_name]] > last_role_prob[PackDict[k]["roleList"][i].role_name]:
|
|
|
+ PackDict[k]["roleList"][i].address = ent.pointer_address.entity_text
|
|
|
+ last_role_prob[PackDict[k]["roleList"][i].role_name] = ent.values[role2id_dict[PackDict[k]["roleList"][i].role_name]]
|
|
|
+ else:
|
|
|
+ if len(ent.pointer_address.entity_text) > len(PackDict[k]["roleList"][i].address):
|
|
|
+ PackDict[k]["roleList"][i].address = ent.pointer_address.entity_text
|
|
|
|
|
|
# 联系人——电子邮箱链接
|
|
|
temporary_list3 = [entity for entity in list_entity if entity.entity_type=='email' or (entity.entity_type=='person' and entity.label in [1,2,3])]
|
|
@@ -2766,7 +2819,13 @@ def findAttributeAfterEntity(PackDict,roleSet,PackageList,PackageSet,list_senten
|
|
|
for _index in range(len(PackageList)):
|
|
|
if "hit" in PackageList[_index]:
|
|
|
for _hit in list(PackageList[_index]["hit"]):
|
|
|
- _money = float(_hit.split("-")[1]) if _hit.split("-")[0]=="money" else None
|
|
|
+ if len(_hit.split("-"))==3:
|
|
|
+ _money = float(_hit.split("-")[1]) if _hit.split("-")[0]=="money" else None
|
|
|
+ # 补充金额前新增负号‘-’导致错误的规则
|
|
|
+ elif len(_hit.split("-"))==4:
|
|
|
+ _money = float(_hit.split("-")[2]) if _hit.split("-")[0] == "money" else None
|
|
|
+ else:
|
|
|
+ _money = None
|
|
|
if PackageList[_index]["name"] in dict_pack_tenderer_money and _money is not None:
|
|
|
dict_pack_tenderer_money[PackageList[_index]["name"]][1].add(_money)
|
|
|
#只找到一个中标人和中标金额
|
|
@@ -2776,7 +2835,7 @@ def findAttributeAfterEntity(PackDict,roleSet,PackageList,PackageSet,list_senten
|
|
|
# print('一个中标人一个金额:', list(set_tenderer_money)[0])
|
|
|
#找到一个中标人和多个招标金额
|
|
|
if len(set_tenderer_money)>1 and len(set_tenderer_role)==1:
|
|
|
- _maxMoney = 0
|
|
|
+ _maxMoney = list(set_tenderer_money)[0]
|
|
|
_sumMoney = 0
|
|
|
for _m in list(set_tenderer_money):
|
|
|
_sumMoney += _m
|
|
@@ -3033,7 +3092,9 @@ def getTimeAttributes(list_entity,list_sentence):
|
|
|
'time_earnestMoneyStart': [], #10 保证金递交开始时间(保证金递交时间)
|
|
|
'time_earnestMoneyEnd': [] , # 11 保证金递交截止时间
|
|
|
'time_commencement':[] , #13 开工日期
|
|
|
- 'time_completion': [] # 14 竣工日期
|
|
|
+ 'time_completion': [], # 14 竣工日期
|
|
|
+ 'time_listingStart': [], # 15 挂牌开始日期(挂牌时间)
|
|
|
+ 'time_listingEnd': [] # 16 挂牌结束日期、挂牌截止日期
|
|
|
}
|
|
|
last_sentence_index = 0
|
|
|
last_time_type = ""
|
|
@@ -3044,22 +3105,49 @@ def getTimeAttributes(list_entity,list_sentence):
|
|
|
'time_registrationStart':"time_registrationEnd",
|
|
|
'time_earnestMoneyStart':"time_earnestMoneyEnd",
|
|
|
'time_commencement':"time_completion",
|
|
|
+ 'time_listingStart':"time_listingEnd"
|
|
|
}
|
|
|
for entity in time_entitys:
|
|
|
sentence_text = list_sentence[entity.sentence_index].sentence_text
|
|
|
entity_left = sentence_text[max(0, entity.wordOffset_begin - 2):entity.wordOffset_begin]
|
|
|
+ entity_left2 = sentence_text[max(0, entity.wordOffset_begin - 10):entity.wordOffset_begin]
|
|
|
entity_right = sentence_text[entity.wordOffset_end:entity.wordOffset_end + 3]
|
|
|
label_prob = entity.values[entity.label]
|
|
|
entity_text = entity.entity_text
|
|
|
in_attachment = entity.in_attachment
|
|
|
extract_time = my_timeFormat(entity_text)
|
|
|
if extract_time:
|
|
|
+ # 2022/12/12 新增挂牌时间正则
|
|
|
+ if re.search("挂牌.{,4}(?:时间|日期)",entity_left2):
|
|
|
+ if re.search("挂牌.{,4}(?:时间|日期)",entity_left2).end()>len(entity_left2)/2:
|
|
|
+ if len(extract_time) == 1:
|
|
|
+ if re.search("挂牌.?(开始|起始).?(?:时间|日期)",entity_left2):
|
|
|
+ dict_time['time_listingStart'].append((extract_time[0], 0.5, in_attachment))
|
|
|
+ last_time_type = 'time_listingStart'
|
|
|
+ elif re.search("挂牌.?(截[止至]|结束).?(?:时间|日期)",entity_left2):
|
|
|
+ dict_time['time_listingEnd'].append((extract_time[0], 0.5, in_attachment))
|
|
|
+ last_time_type = 'time_listingEnd'
|
|
|
+ elif re.search("挂牌.?(?:时间|日期)",entity_left2):
|
|
|
+ if re.search("前|止|截止",entity_right) or re.search("至|止|到",entity_left) or re.search("前",entity_text[-2:]):
|
|
|
+ dict_time['time_listingEnd'].append((extract_time[0], 0.5, in_attachment))
|
|
|
+ last_time_type = 'time_listingEnd'
|
|
|
+ else:
|
|
|
+ dict_time['time_listingStart'].append((extract_time[0], 0.5, in_attachment))
|
|
|
+ last_time_type = 'time_listingStart'
|
|
|
+ else:
|
|
|
+ dict_time['time_listingStart'].append((extract_time[0], 0.5, in_attachment))
|
|
|
+ dict_time['time_listingEnd'].append((extract_time[1], 0.5, in_attachment))
|
|
|
+ last_time_type = ''
|
|
|
+ last_sentence_index = entity.sentence_index
|
|
|
+ continue
|
|
|
+
|
|
|
if re.search("至|到", entity_left):
|
|
|
if entity.sentence_index == last_sentence_index:
|
|
|
time_type = last_time_index.get(last_time_type)
|
|
|
if time_type:
|
|
|
dict_time[time_type].append((extract_time[0], 0.5 + label_prob / 10,in_attachment))
|
|
|
last_time_type = ""
|
|
|
+ last_sentence_index = entity.sentence_index
|
|
|
continue
|
|
|
if entity.label!=0:
|
|
|
if entity.label==1 and label_prob>0.5:
|
|
@@ -3398,30 +3486,36 @@ def update_prem(old_prem, new_prem):
|
|
|
for k, v in new_prem.items():
|
|
|
if k == 'Project':
|
|
|
if 'Project' in old_prem:
|
|
|
+ tmp_l = [] # 保存新旧同时包含的角色
|
|
|
for d in old_prem['Project']['roleList']:
|
|
|
for d2 in v['roleList']:
|
|
|
- if d['role_name'] == d2['role_name']:
|
|
|
+ if d['role_name'] == d2['role_name']: # 同时包含的角色用表格的替换
|
|
|
+ tmp_l.append(d2)
|
|
|
d['role_text'] = d2['role_text']
|
|
|
- d['role_money']['money'] = d2['role_money']['money']
|
|
|
- d['role_money']['money_unit'] = d2['role_money']['money_unit']
|
|
|
- v['roleList'].remove(d2)
|
|
|
+ if d2['role_money']['money'] != 0: # 如果表格提取的金额不为0才替换
|
|
|
+ d['role_money']['money'] = d2['role_money']['money']
|
|
|
+ d['role_money']['money_unit'] = d2['role_money']['money_unit']
|
|
|
for d2 in v['roleList']:
|
|
|
- old_prem['Project']['roleList'].append(d2)
|
|
|
+ if d2 not in tmp_l: # 把新预测有,旧没有的角色添加上去
|
|
|
+ old_prem['Project']['roleList'].append(d2)
|
|
|
else:
|
|
|
old_prem[k] = v
|
|
|
else:
|
|
|
- if k not in old_prem:
|
|
|
+ if k not in old_prem: # 新有旧没有的包直接添加
|
|
|
old_prem[k] = v
|
|
|
else:
|
|
|
+ tmp_l = [] # 保存新旧同时包含的角色
|
|
|
for d in old_prem[k]['roleList']:
|
|
|
for d2 in v['roleList']:
|
|
|
if d['role_name'] == d2['role_name']:
|
|
|
+ tmp_l.append(d2)
|
|
|
d['role_text'] = d2['role_text']
|
|
|
- d['role_money']['money'] = d2['role_money']['money']
|
|
|
- d['role_money']['money_unit'] = d2['role_money']['money_unit']
|
|
|
- v['roleList'].remove(d2)
|
|
|
+ if d2['role_money']['money'] != 0: # 如果表格提取的金额不为0才替换
|
|
|
+ d['role_money']['money'] = d2['role_money']['money']
|
|
|
+ d['role_money']['money_unit'] = d2['role_money']['money_unit']
|
|
|
for d2 in v['roleList']:
|
|
|
- old_prem[k]['roleList'].append(d2)
|
|
|
+ if d2 not in tmp_l: # 把新预测有,旧没有的角色添加上去
|
|
|
+ old_prem[k]['roleList'].append(d2)
|
|
|
|
|
|
# return old_prem
|
|
|
|