Commit 5be99361 by 岳巧源

online

parent 3abc14a9
Showing with 44 additions and 23 deletions
...@@ -2,11 +2,18 @@ import json ...@@ -2,11 +2,18 @@ import json
import mysql.connector import mysql.connector
import requests import requests
import logging
# 线上地址需要更改 # 线上地址需要更改
dev_url = "http://united_data.liexindev.net/sync/Address/updateAddress" #测试环境url dev_url = "http://united_data.liexindev.net/sync/Address/updateAddress" #测试环境url
prod_url = "" #生产环境 prod_url = "" #生产环境
#日志配置
logging.basicConfig(format='%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s',
level=logging.INFO,
filename='data_liexin.log',
filemode='a')
def get_user_detail_address_by_code(province: int, city: int, district: int, detail_address: str) -> str: def get_user_detail_address_by_code(province: int, city: int, district: int, detail_address: str) -> str:
db = mysql.connector.connect( db = mysql.connector.connect(
...@@ -15,22 +22,35 @@ def get_user_detail_address_by_code(province: int, city: int, district: int, det ...@@ -15,22 +22,35 @@ def get_user_detail_address_by_code(province: int, city: int, district: int, det
password="liexin#zsyM", password="liexin#zsyM",
database="liexin" database="liexin"
) )
sql = "select region_name from lie_region where region_id in (" + str(province) + "," + str(city) + "," + str(district) + ") " + "order by field (" + "region_id" + "," + str(province) + "," + str(city) + "," + str(district) + ") " sql1 = "select region_name from lie_region where region_id = " + str(province)
sql2 = "select region_name from lie_region where region_id = " + str(city)
sql3 = "select region_name from lie_region where region_id = " + str(district)
user_detail_address = "" user_detail_address = ""
cursor = db.cursor() cursor = db.cursor()
cursor.execute(sql) # 省
result = cursor.fetchall() cursor.execute(sql1)
for i in range(len(result)): result1 = cursor.fetchall()
if len(result[i]) == 0: for i in range(len(result1)):
continue if len(result1[i]) != 0:
user_detail_address += result[i][0] user_detail_address += result1[i][0]
# 市
cursor.execute(sql2)
result2 = cursor.fetchall()
for i in range(len(result2)):
if len(result2[i]) != 0:
user_detail_address += result2[i][0]
# 区
cursor.execute(sql3)
result3 = cursor.fetchall()
for i in range(len(result3)):
if len(result3[i]) != 0:
user_detail_address += result3[i][0]
user_detail_address += detail_address user_detail_address += detail_address
cursor.close() cursor.close()
db.close() db.cursor()
return user_detail_address return user_detail_address
def pur(): def pur():
db = mysql.connector.connect( db = mysql.connector.connect(
host="master.db2.liexindev.me", host="master.db2.liexindev.me",
...@@ -41,6 +61,7 @@ def pur(): ...@@ -41,6 +61,7 @@ def pur():
cursor = db.cursor() cursor = db.cursor()
cursor.execute("select end_cust_cn, end_cust_en, create_uid, create_name, end_cust_id, com_addr from lie_end_cust_info") cursor.execute("select end_cust_cn, end_cust_en, create_uid, create_name, end_cust_id, com_addr from lie_end_cust_info")
result = cursor.fetchall() result = cursor.fetchall()
logging.info("start pur")
for row in result: for row in result:
end_cust_cn = row[0] end_cust_cn = row[0]
end_cust_en = row[1] end_cust_en = row[1]
...@@ -78,11 +99,13 @@ def pur(): ...@@ -78,11 +99,13 @@ def pur():
}], }],
"is_delete": 0 "is_delete": 0
} }
print(json_map_cn)
print(json_map_en)
post_data_to_update_address(json_map_cn) post_data_to_update_address(json_map_cn)
post_data_to_update_address(json_map_en) post_data_to_update_address(json_map_en)
print("-------------------------pur已更新!--------------------------------") print("-------------------------pur已更新!--------------------------------")
logging.info("-------------------------pur已更新!--------------------------------")
cursor.close() cursor.close()
db.close() db.close()
...@@ -98,6 +121,7 @@ def liexin(): ...@@ -98,6 +121,7 @@ def liexin():
cursor = db.cursor() cursor = db.cursor()
cursor.execute("select tax_title, business_license, tax_id, user_sn, company_address, consignee_province, consignee_city, consignee_district, consignee_address, uc_id from lie_taxinfo") cursor.execute("select tax_title, business_license, tax_id, user_sn, company_address, consignee_province, consignee_city, consignee_district, consignee_address, uc_id from lie_taxinfo")
result = cursor.fetchall() result = cursor.fetchall()
logging.info("start liexin")
for row in result: for row in result:
tax_title = row[0] tax_title = row[0]
business_license = row[1] business_license = row[1]
...@@ -111,15 +135,7 @@ def liexin(): ...@@ -111,15 +135,7 @@ def liexin():
uc_id = row[9] uc_id = row[9]
# 获取收票地址 # 获取收票地址
tax_detail_address = "" tax_detail_address = get_user_detail_address_by_code(consignee_province, consignee_city, consignee_district, consignee_address)
sql = "select region_name from lie_region where region_id in " + "(" + str(consignee_province) + "," + str(consignee_city) + "," + str(consignee_district) + ") " + "order by field (" + "region_id" + "," + str(consignee_province) + "," + str(consignee_city) + "," + str(consignee_district) + ")"
cursor.execute(sql)
tax_address_result = cursor.fetchall()
for i in range(len(tax_address_result)):
if len(tax_address_result[i]) == 0:
continue
tax_detail_address += tax_address_result[i][0]
tax_detail_address += consignee_address
# 获取客户地址 # 获取客户地址
sql_user_address = "select province, city, district, detail_address, address_type from lie_user_address where uc_id = " + str(uc_id) sql_user_address = "select province, city, district, detail_address, address_type from lie_user_address where uc_id = " + str(uc_id)
...@@ -175,6 +191,7 @@ def liexin(): ...@@ -175,6 +191,7 @@ def liexin():
print(json_map) print(json_map)
post_data_to_update_address(json_map) post_data_to_update_address(json_map)
print("-------------------------liexin已更新!--------------------------------") print("-------------------------liexin已更新!--------------------------------")
logging.info("-------------------------liexin已更新!--------------------------------")
cursor.close() cursor.close()
db.close() db.close()
...@@ -193,6 +210,7 @@ def crm(): ...@@ -193,6 +210,7 @@ def crm():
cursor.execute( cursor.execute(
"select com_name, business_license_src, creator_id, creator_name, id, com_addr from lie_company where com_category in (0, 1)") "select com_name, business_license_src, creator_id, creator_name, id, com_addr from lie_company where com_category in (0, 1)")
result = cursor.fetchall() result = cursor.fetchall()
logging.info("---------start crm-----------")
for row in result: for row in result:
com_name = row[0] com_name = row[0]
business_license_src = row[1] business_license_src = row[1]
...@@ -221,17 +239,20 @@ def crm(): ...@@ -221,17 +239,20 @@ def crm():
json_map["address_data"] = [] json_map["address_data"] = []
print(json_map) print(json_map)
post_data_to_update_address(json_map) post_data_to_update_address(json_map)
print("-------------------------crm已更新!--------------------------------") print("-------------------------crm已更新完毕!--------------------------------")
logging.info("-------------------------crm已更新完毕!--------------------------------")
cursor.close() cursor.close()
db.close() db.close()
def post_data_to_update_address(data: dict): def post_data_to_update_address(data: dict):
response = requests.post(url=dev_url, data=json.dumps(data), headers={"Content-Type": "application/json"}) data_str = json.dumps(data)
logging.info(data)
response = requests.post(url=dev_url, data=data_str, headers={"Content-Type": "application/json"})
print("=======" + str(response.status_code) + "======") print("=======" + str(response.status_code) + "======")
logging.info(str(response.status_code))
if __name__ == '__main__': if __name__ == '__main__':
crm()
liexin()
pur() pur()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment