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

update

parent 3f571899
......@@ -9,7 +9,7 @@ Created on Tue Feb 23 00:36:24 2021
import pandas as pd
import pymssql
from public import Index
import datetime
def get_point_category_params_data(category):
......@@ -33,7 +33,9 @@ def get_point_category_params_data(category):
data = (cursor.fetchall())
export_category = pd.DataFrame(data,columns=[tuple[0] for tuple in cursor.description])
writer = pd.ExcelWriter(f"{category_sheet_name}参数确认.xlsx")
date = str(datetime.datetime.now()).split(' ')[0]
writer = pd.ExcelWriter(f"{category_sheet_name}参数确认{date}.xlsx")
for category_code,category_name in zip(export_category['id'].tolist(),export_category['name'].tolist()):
......@@ -90,6 +92,7 @@ def get_point_category_params_data(category):
data = cursor.fetchall()
params_df = pd.DataFrame(data, columns=[tuple[0] for tuple in cursor.description])
params_df['needed_param'] = params_df['identy'].apply(lambda x: x[0])
params_df['match_param'] = params_df['identy'].apply(lambda x: x[1])
params_df['standard_param'] = params_df['identy'].apply(lambda x: x[2])
params_df = params_df[(params_df['needed_param'] != '0') | (params_df['skuorspu'] == 'spu')]
......@@ -143,10 +146,13 @@ def get_point_category_params_data(category):
res['产品品牌'] = brand_list
res['产品类别'] = category_list
filter_params_col_list = []
for index,row in params_df.iterrows():
param = row['subtitle']
needed_flag = row['needed_param']
match_flag = row['match_param']
standard_flag = row['standard_param']
if param == '产品名称':
continue
......@@ -155,24 +161,66 @@ def get_point_category_params_data(category):
#标记标准项
if needed_flag == '1' and standard_flag == '1':
param = '*' + param
#if match_flag == '1':
# param = '*' + param
# filter_params_col_list.append(param)
exec("res['%s']=%s_list"%(param,param_var))
'''
url_list = []
goods_model_list = []
process_index = 0
index = Index()
for index_,row in res.iterrows():
try:
print(index(process_index,len(res)-1), end='%')
except:
print(index(process_index,1), end='%')
process_index+=1
sku = str(row['产品编码'])
res.to_excel(writer,f"{category_sheet_name}参数数据")
cursor_zdindex.execute(f"select goods_model,goods_url from zd_purchase_price where goods_id = '{sku}' and periods in (select top 1 max(periods) from zd_entry_goods_price) and purchase_id = 'ZC-HEILONGJIANG'")
try:
goods_model,url = tuple(cursor_zdindex.fetchone())
except:
goods_model,url = '无','无'
url_list.append(url)
goods_model_list.append(goods_model)
res['黑龙江采购商品名称'] = goods_model_list
res['链接'] = url_list
'''
cursor_zdindex.execute(f"select goods_id,goods_name,platform_id,goods_url,index_price_wave,final_price from zd_week_price where periods in (select top 1 max(periods) from zd_entry_goods_price) and sub_category_code = {category_code} ")
res.to_excel(writer,f"{category_sheet_name}参数数据")
'''
cursor_zdindex.execute(f"select a.goods_id,a.goods_name,b.goods_name as '链接名称',a.platform_id,a.goods_url,a.index_price_wave,a.final_price from zd_week_price a \
left join (select goods_id,goods_name from zd_purchase_price where periods = '20211216') b \
on a.goods_id = b.goods_id \
where a.periods = '20211216' and a.sub_category_code = {category_code}")
'''
cursor_zdindex.execute(f"select goods_id,goods_name,source_goods_name,platform_id,goods_url,index_price_wave,final_price from zd_week_price \
where periods in (select top 1 max(periods) from zd_entry_goods_price) and sub_category_code = {category_code}")
data = (cursor_zdindex.fetchall())
price_df = pd.DataFrame(data,columns=[tuple[0] for tuple in cursor_zdindex.description])
price_df.to_excel(writer,f"{category_sheet_name}价格链接数据")
filter_res = res[list(res.columns)[0:7] + filter_params_col_list]
combine_df = pd.merge(price_df,filter_res,left_on = 'goods_id',right_on = '产品编码',how='left')
combine_df['指数型号不在原始名称中'] = [1 if str(model).strip().upper() not in str(name).upper() else 0 for model,name in zip(combine_df['*产品型号'].tolist(),combine_df['source_goods_name'].tolist())]
combine_df.to_excel(writer,f"{category_sheet_name}数据合并")
print(f"{category_name}数据导出完毕!")
writer.save()
conn_zi_new.close()
category_list = category_list = ['台式机']
category_list = category_list = ['多功能一体机','激光打印机','喷墨打印机','碎纸机','投影机','针式打印机','扫描仪','高拍仪','传真设备']
for category in category_list:
get_point_category_params_data(category)
\ No newline at end of file
......@@ -78,8 +78,6 @@ def dael_name_content(skuname,brand):
def upload_params_data(category,path,record_code_list):
df = pd.read_excel(path,converters = {'产品编码':str})
#创建新产品库链接
try:
conn_zi_new = pymssql.connect(host='172.17.9.129', user='zgcprice3311',password='zgcprice20200628',database= 'ZI_NEW',autocommit=True)
......@@ -100,13 +98,14 @@ def upload_params_data(category,path,record_code_list):
db_params['subtitle'] = db_params['subtitle'].apply(lambda x: x.strip())
subtitle_list = db_params['subtitle'].tolist()
cursor_zdindex.execute(f"select top 1 max(periods) from zd_entry_goods_price")
periods = cursor_zdindex.fetchone()[0]
subtitle_id_dict = dict(zip(db_params['subtitle'].tolist(),db_params['subtitleid'].tolist()))
subtitle_type_dict = dict(zip(db_params['subtitle'].tolist(),db_params['skuorspu'].tolist()))
#
cursor_zi_new.execute(f"select id,sku,skuname,createddate from p_sku where state = 1 or state = 2 or state = 4")
sku_df = pd.DataFrame(cursor_zi_new.fetchall(), columns=[tuple[0] for tuple in cursor_zi_new.description])
......@@ -139,7 +138,6 @@ def upload_params_data(category,path,record_code_list):
process_index = 0
index_ = Index()
#SPU、SKU命名
for index,row in df.iterrows():
try:
......@@ -147,10 +145,7 @@ def upload_params_data(category,path,record_code_list):
except:
print(index_(process_index,1), end='%')
process_index+=1
try:
sku = row['产品编码']
brandname = row['产品品牌']
try:
......@@ -163,6 +158,7 @@ def upload_params_data(category,path,record_code_list):
if sku in record_code_list:
continue
cursor_zi_new.execute(f"select pid from p_brand where id = {brand_code}")
father_brand_code = cursor_zi_new.fetchone()[0]
......@@ -237,7 +233,11 @@ def upload_params_data(category,path,record_code_list):
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]))
for key in list(params.keys()):
if params[key] == '无参数,需补充':
params.pop(key)
'''
#增加硬盘容量
if '机械硬盘容量' in subtitle_list:
......@@ -444,7 +444,9 @@ def upload_params_data(category,path,record_code_list):
for subtitle in subtitle_list:
value = str(row[subtitle]).strip()
value = str(row[subtitle]).strip().upper()
if value == '无参数,需补充':
continue
subtitleid = subtitle_id_dict[subtitle]
subtitle_type = subtitle_type_dict[subtitle]
......@@ -533,8 +535,8 @@ def upload_params_data(category,path,record_code_list):
if check_df.empty:
cursor_zi_new.execute(f"insert into p_valuemap (spuid,valueid) values ({spuid}, {valueid})")
record_code_list.append(sku)
except:
print("处理异常请重跑")
except Exception as err:
print(err,"处理异常请重跑")
return False,record_code_list
conn_zi_new.close()
......@@ -624,8 +626,8 @@ def check_configure_price(category,path,params_list):
category = '笔记本'
path = '/Users/rico/Downloads/历史数据笔记本参数确认(1)(校验通过).xlsx'
category = '碎纸机'
path = '/Users/rico/WorkSpace/1_Project/Company/中电中采/4_中电商品库功能类/更新库内参数并重新命名/碎纸机参数确认(校验通过).xlsx'
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