Commit d206e0f2 authored by rico.liu's avatar rico.liu

update

parent 6a1ed07e
...@@ -77,6 +77,8 @@ def dael_name_content(skuname,brand): ...@@ -77,6 +77,8 @@ def dael_name_content(skuname,brand):
def upload_params_data(category,path,record_code_list): def upload_params_data(category,path,record_code_list):
print("初始化。。。")
df = pd.read_excel(path,converters = {'产品编码':str}) df = pd.read_excel(path,converters = {'产品编码':str})
#创建新产品库链接 #创建新产品库链接
try: try:
...@@ -129,6 +131,12 @@ def upload_params_data(category,path,record_code_list): ...@@ -129,6 +131,12 @@ def upload_params_data(category,path,record_code_list):
data_dict['stdvalue'] = data_dict['stdvalue'].apply(lambda x : x.upper()) data_dict['stdvalue'] = data_dict['stdvalue'].apply(lambda x : x.upper())
single_data_dict = data_dict single_data_dict = data_dict
#获取品牌
cursor_zi_new.execute(f"select id,name,pid from p_brand where id not in (select distinct pid from p_brand)")
brand_df = pd.DataFrame(cursor_zi_new.fetchall(), columns=[tuple[0] for tuple in cursor_zi_new.description])
#去掉*标识 #去掉*标识
current_list = df.columns.tolist() current_list = df.columns.tolist()
update_list = [col[1:] if col[0] == '*' else col for col in current_list] update_list = [col[1:] if col[0] == '*' else col for col in current_list]
...@@ -138,6 +146,8 @@ def upload_params_data(category,path,record_code_list): ...@@ -138,6 +146,8 @@ def upload_params_data(category,path,record_code_list):
process_index = 0 process_index = 0
index_ = Index() index_ = Index()
print("初始化完成")
#SPU、SKU命名 #SPU、SKU命名
for index,row in df.iterrows(): for index,row in df.iterrows():
try: try:
...@@ -149,8 +159,7 @@ def upload_params_data(category,path,record_code_list): ...@@ -149,8 +159,7 @@ def upload_params_data(category,path,record_code_list):
sku = row['产品编码'] sku = row['产品编码']
brandname = row['产品品牌'] brandname = row['产品品牌']
try: try:
cursor_zi_new.execute(f"select id from p_brand where name = '{brandname}' and id not in (select distinct pid from p_brand)") brand_code = brand_df[brand_df['name'] == brandname]['id'].tolist()[0]
brand_code = cursor_zi_new.fetchone()[0]
except: except:
print(f"异常品牌: {brandname},请检查产品品牌表") print(f"异常品牌: {brandname},请检查产品品牌表")
break break
...@@ -158,9 +167,7 @@ def upload_params_data(category,path,record_code_list): ...@@ -158,9 +167,7 @@ def upload_params_data(category,path,record_code_list):
if sku in record_code_list: if sku in record_code_list:
continue continue
father_brand_code = brand_df[brand_df['id'] == brand_code]['pid'].tolist()[0]
cursor_zi_new.execute(f"select pid from p_brand where id = {brand_code}")
father_brand_code = cursor_zi_new.fetchone()[0]
#cursor_zi_new.execute(f"select id,spuid from p_sku where sku = '{sku}'") #cursor_zi_new.execute(f"select id,spuid from p_sku where sku = '{sku}'")
searchsku_df = sku_df[sku_df['sku'] == sku][['id']] searchsku_df = sku_df[sku_df['sku'] == sku][['id']]
...@@ -184,8 +191,7 @@ def upload_params_data(category,path,record_code_list): ...@@ -184,8 +191,7 @@ def upload_params_data(category,path,record_code_list):
spu_brandname = brandname spu_brandname = brandname
else: else:
try: try:
cursor_zi_new.execute(f"select name from p_brand where id = {father_brand_code}") father_brand = brand_df[brand_df['id'] == father_brand_code]['name'].tolist()[0]
father_brand = cursor_zi_new.fetchone()[0].strip()
except: except:
print(f"{brandname},异常品牌编码: {father_brand_code},请检查产品品牌表") print(f"{brandname},异常品牌编码: {father_brand_code},请检查产品品牌表")
break break
...@@ -234,7 +240,16 @@ def upload_params_data(category,path,record_code_list): ...@@ -234,7 +240,16 @@ def upload_params_data(category,path,record_code_list):
cursor_zi_new.execute(f"update p_sku set spuid = '{spuid}' where id = '{skuid}'") cursor_zi_new.execute(f"update p_sku set spuid = '{spuid}' where id = '{skuid}'")
params = dict(zip(subtitle_list,[row[subtitle] for subtitle in subtitle_list])) #params = dict(zip(subtitle_list,[row[subtitle] for subtitle in subtitle_list]))
params = {}
for subtitle in subtitle_list:
try:
value = row[subtitle]
except:
continue
params.update({subtitle:value})
for key in list(params.keys()): for key in list(params.keys()):
if params[key] == '无参数,需补充': if params[key] == '无参数,需补充':
params.pop(key) params.pop(key)
...@@ -265,8 +280,7 @@ def upload_params_data(category,path,record_code_list): ...@@ -265,8 +280,7 @@ def upload_params_data(category,path,record_code_list):
if father_brand_code == 0: if father_brand_code == 0:
value = brandname value = brandname
else: else:
cursor_zi_new.execute(f"select name from p_brand where id = {father_brand_code}") father_brand = brand_df[brand_df['id'] == father_brand_code]['name'].tolist()[0]
father_brand = cursor_zi_new.fetchone()[0].strip()
value = father_brand value = father_brand
value = value.replace("FATHER","") value = value.replace("FATHER","")
else: else:
...@@ -443,9 +457,11 @@ def upload_params_data(category,path,record_code_list): ...@@ -443,9 +457,11 @@ def upload_params_data(category,path,record_code_list):
for subtitle in subtitle_list: for subtitle in subtitle_list:
try:
value = str(row[subtitle]).strip().upper() value = str(row[subtitle]).strip().upper()
if value == '无参数,需补充': except:
continue
if value == '无参数,需补充' or value == '无参数,需补充' or value == '暂无数据':
continue continue
subtitleid = subtitle_id_dict[subtitle] subtitleid = subtitle_id_dict[subtitle]
...@@ -626,8 +642,8 @@ def check_configure_price(category,path,params_list): ...@@ -626,8 +642,8 @@ def check_configure_price(category,path,params_list):
category = '碎纸机' category = '多功能一体机'
path = '/Users/rico/WorkSpace/1_Project/Company/中电中采/4_中电商品库功能类/更新库内参数并重新命名/碎纸机参数确认(校验通过).xlsx' path = '/Users/rico/Downloads/多功能一体机参数确认2021-12-24(1)(1)(校验通过).xlsx'
record_code_list = [] record_code_list = []
flag,return_record_code_list = upload_params_data(category,path,record_code_list) flag,return_record_code_list = upload_params_data(category,path,record_code_list)
......
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 to comment