add workflow 天润Smart-ccc客户数据,dev
This commit is contained in:
parent
2fcc452226
commit
ba47d55c40
|
@ -25,7 +25,6 @@ upt_sql = "update p61_output.ccc_scrm_cust_label_info set sync_ind=%s, etl_proc_
|
|||
ist_sql = "INSERT INTO p61_output.scrm_leads_external_id_mapping (leads_id, external_type, external_id, etl_proc_dt, etl_tx_dt) VALUES (%s, %s, %s,current_timestamp(0), current_date) on CONFLICT (leads_id, external_type) DO NOTHING;"
|
||||
# ist_sql = "delete from p61_output.scrm_leads_external_id_mapping where leads_id=%s and external_type = %s ; INSERT INTO p61_output.scrm_leads_external_id_mapping (leads_id, external_type, external_id, etl_proc_dt, etl_tx_dt) VALUES (%s, %s, %s,current_timestamp(0), current_date);"
|
||||
|
||||
|
||||
database="daas_mpp"
|
||||
user="dbuser_mpp"
|
||||
password="qwF0GX8"
|
||||
|
@ -83,16 +82,15 @@ def add_leads_id(sql, type, leads_id, extern_id):
|
|||
print(f'添加线索id异常,接口返回信息:{e}')
|
||||
|
||||
def request_custom_id(id):
|
||||
print(f'开始请求线索id:{id}')
|
||||
header={}
|
||||
url='https://api.huiju.cool/v2/customerService/findCustomerByIdentity'
|
||||
body={'access_token':auth['access_token'],'identityType':identityType,'identityValue':id}
|
||||
print(f'body: {body}')
|
||||
dataReqL=requests.get(url,headers=header,params=body)
|
||||
resL=json.loads(dataReqL.text)
|
||||
return resL
|
||||
|
||||
def request_update_tags(idStr, tagId ):
|
||||
print(f'开始请求更新线索标签{idStr}|{tagId}')
|
||||
header={}
|
||||
access_token = auth['access_token']
|
||||
url=f'https://api.huiju.cool/v2/customerTags/bulkAdd?access_token={access_token}'
|
||||
|
@ -113,43 +111,47 @@ if __name__ == "__main__":
|
|||
records = get_data_from_db( sel_sql)
|
||||
if len(records) > 0:
|
||||
print(f'此处需处理{len(records)}条标签信息')
|
||||
i = 0
|
||||
for data in records:
|
||||
i = i+1
|
||||
custId = data[0]
|
||||
id = data[1]
|
||||
idStr = data[2]
|
||||
tagId = data[5]
|
||||
print(f'开始处理客户({id}:{tagId})标签信息')
|
||||
print(f'{i}. 开始处理客户({id}:{tagId})标签信息')
|
||||
try:
|
||||
f = False
|
||||
s = '2'
|
||||
if not idStr:
|
||||
print(f'{i}. 开始请求线索id:{id}')
|
||||
resL = request_custom_id(id)
|
||||
if 'error' in resL and resL['error']['code'] == 400010:
|
||||
get_token(auth_url)
|
||||
resL = request_custom_id(id)
|
||||
if 'error' in resL:
|
||||
print(f'获取客户线索id异常,接口返回信息:{resL}')
|
||||
print(f'{i}. 异常:获取客户线索id异常,接口返回信息:{resL}')
|
||||
continue
|
||||
idStr = resL['idStr']
|
||||
if idStr == '':
|
||||
print(f'获取客户线索id为空,接口返回信息:{resL}')
|
||||
print(f'{i}. 异常:获取客户线索id为空,接口返回信息:{resL}')
|
||||
continue
|
||||
f=True
|
||||
if f:
|
||||
add_leads_id(ist_sql,identityType, idStr, id)
|
||||
if tagId is None:
|
||||
print(f'标签id为空,无法更新标签{tagId}')
|
||||
print(f'{i}. 异常:标签id为空,无法更新标签{tagId}')
|
||||
continue
|
||||
print(f'{i}. 开始请求更新线索标签{idStr}|{tagId}')
|
||||
resU = request_update_tags(idStr,tagId)
|
||||
if 'error' in resU and resU['error']['code'] == 400010:
|
||||
get_token(auth_url)
|
||||
resU = request_update_tags(idStr,tagId)
|
||||
if 'error' in resU:
|
||||
print(f'获取客户线索id异常,接口返回信息:{resU}')
|
||||
print(f'{i} 异常:获取客户线索id失败,接口返回信息:{resU}')
|
||||
continue
|
||||
update_db_flag( upt_sql,s,custId,tagId)
|
||||
except Exception as e:
|
||||
print(f'处理客户({id}:{tagId})标签信息,异常信息:{e}')
|
||||
print(f'{i} 异常:处理客户({id}:{tagId})标签信息,异常信息:{e}')
|
||||
else:
|
||||
print(f'记录数为0,此处无需处理标签信息')
|
||||
print(f'{formatted2_previous_hour(0)}更新标签信息结束')
|
||||
|
|
Loading…
Reference in New Issue