Commit a607c048 authored by 邱阿朋's avatar 邱阿朋

队列消息

parent e593a3bb
import os.path
import pandas as pd
import argparse
class InvoiceIDComparator:
def __init__(self, file_a, file_b, invoice_column_name):
self.file_a = file_a
......@@ -46,13 +49,20 @@ class InvoiceIDComparator:
def main():
# 设置命令行参数
parser = argparse.ArgumentParser(description="比较两个Excel文件中的Invoice ID差异")
parser.add_argument('--original_file', help="原文件路径")
parser.add_argument('--result_file', help="结果文件路径")
parser.add_argument('--original_file', default="ContraCogsInvoices.xls", help="原文件路径")
parser.add_argument('--result_file', default="result.xls", help="结果文件路径")
parser.add_argument('--invoice_column', default='Invoice ID', help="Invoice ID列的名称")
# 解析命令行参数
args = parser.parse_args()
if os.path.exists(args.original_file) is False:
raise FileExistsError("源文件不存在")
if os.path.exists(args.result_file) is False:
raise FileExistsError("结果文件不存在")
# 创建 InvoiceIDComparator 实例并进行比较
comparator = InvoiceIDComparator(args.original_file, args.result_file, args.invoice_column)
comparator.compare_invoice_ids()
......@@ -60,4 +70,7 @@ def main():
# 程序入口
if __name__ == "__main__":
main()
\ No newline at end of file
try:
main()
except Exception as e:
print(e)
\ No newline at end of file
......@@ -2,17 +2,8 @@
import re
import pandas as pd
import xlrd
from openpyxl.reader.excel import load_workbook
def open_xls(file_path):
# 开始处理excel数据
workbook = xlrd.open_workbook(filename=file_path)
# 选择工作表
return workbook.sheet_by_index(0) # 选择第一个工作表
def save_xls(data, output_file, sheet_name='Sheet1', adjusted=True):
try:
# 如果文件已存在,则追加新的 sheet
......
......@@ -37,7 +37,7 @@ def export_list_read_data():
file_name = "Return_Summary.xls"
if not os.path.isfile(file_name):
raise FileNotFoundError(f"{file_name},文件不存在")
return pd.read_excel(file_name, engine='xlrd')
return pd.read_excel(file_name)
def export_item_read_data(return_id):
......@@ -55,7 +55,7 @@ def export_item_read_data(return_id):
page.refresh()
# 读取回退商品详情
return pd.read_excel(file_name, engine='xlrd')
return pd.read_excel(file_name)
def main():
......@@ -106,6 +106,9 @@ def main():
new_file_name = f"{current_datetime}_{file_name}"
excel.save_xls(new_list_data, new_file_name)
# 推送消息
# push_data_queue(new_file_name)
def push_data_queue(file_name):
rabbit = rabbitmq.RabbitMQClient(host='172.18.218.11', port=15672, username='test', password='khd123456')
......@@ -114,16 +117,16 @@ def push_data_queue(file_name):
data = pd.read_excel(file_name)
for _, item_row in data.iterrows():
push_data = {
'return_id': item_row.get('Return ID'),
'asin': item_row.get('ASIN'), # ASIN
'order_no': item_row.get('Purchase order'), # 订单号
'sku_quantity': item_row.get('Quantity'), # 退回数量
'sku_amount': item_row.get('Total amount'), # Total cost
'currency': data.get('Currency code'), # Currency code
'return_id': item_row.get('Return ID', ''),
'asin': item_row.get('ASIN', ''), # ASIN
'order_no': item_row.get('Purchase order', ''), # 订单号
'sku_quantity': item_row.get('Quantity', 0), # 退回数量
'sku_amount': item_row.get('Total amount', 0), # Total cost
'currency': data.get('Currency code', ''), # Currency code
'data_date': data.get('Return Date').strftime('%Y-%m-%d'), # Return Date
'erp_sku': item_row.get("erp_sku"), # ERP SKU # SKU1匹配
'erp_sku': item_row.get("erp_sku", ''), # ERP SKU # SKU1匹配
'shop_code': shop_code, # 店铺code
'supplier_code': data.get('Vendor code'), # 供应商编码
'supplier_code': data.get('Vendor code', ''), # 供应商编码
}
# 推送数据
......@@ -133,6 +136,10 @@ def push_data_queue(file_name):
if __name__ == '__main__':
try:
country = helper.get_input_with_default("国家(目前支持[DE,FR,JP,CA,UK,US])", "US")
shop_code = helper.get_input_with_default("店铺编码", "US-VC")
if shop_code == "":
raise Exception("店铺编码不能为空")
domain.domain_page(page, country)
main()
page.close()
......
......@@ -2,8 +2,6 @@
# spa查询
import math
import os
import shutil
from concurrent.futures import ThreadPoolExecutor
from datetime import datetime
from urllib.parse import urlparse, parse_qs
......@@ -42,7 +40,7 @@ def export_list_read_data():
file_name = "ContraCogsInvoices.xls"
if not os.path.isfile(file_name):
raise FileNotFoundError(f"{file_name},文件不存在")
return pd.read_excel(file_name, engine='xlrd')
return pd.read_excel(file_name)
def get_report_table_html(invoice_id):
......@@ -220,9 +218,10 @@ def main():
processed_items = process_small_items(item_list, coop, relation_data)
sheet_data.extend(processed_items)
# 保存数据到 Excel 文件
# 保存数据到 Excel 文件
save_excel(sheet_data, large_sheet_data, new_file_name)
# 推送消息
# push_data_queue(new_file_name)
def process_large_items(item_list, relation_data):
"""处理大数据列表 (item_list 长度 >= 10)"""
......@@ -233,6 +232,8 @@ def process_large_items(item_list, relation_data):
continue
relation = relation_data.get(asin, {})
rebate = item.get("Rebate In Agreement Currency", None)
vendor_funding = item.get("Vendor Funding In Agreement Currency", None)
processed_item = item.copy()
processed_item.pop("Title")
......@@ -241,6 +242,7 @@ def process_large_items(item_list, relation_data):
processed_item['ERP SKU'] = relation.get("erp_sku")
processed_item['Group Name'] = relation.get("name")
processed_item['Group Code'] = relation.get("code")
processed_item["Original balance"] = rebate or vendor_funding
processed_items.append(processed_item)
return processed_items
......@@ -257,18 +259,16 @@ def process_small_items(item_list, coop, relation_data):
continue
relation = relation_data.get(asin, {})
rebate = item.get("Rebate In Agreement Currency", None)
vendor_funding = item.get("Vendor Funding In Agreement Currency", None)
processed_item = coop.copy()
processed_item.pop("Agreement title")
processed_item["Order Date"] = item.get("Order Date")
processed_item['Purchase Order'] = relation.get("Purchase Order")
processed_item["Agreement Currency"] = item.get("Agreement Currency")
processed_item["Asin"] = asin
processed_item["ERP SKU"] = relation.get("erp_sku")
processed_item["Group Name"] = relation.get("name")
processed_item['Group Code'] = relation.get("code")
processed_item["Original balance"] = rebate or vendor_funding
processed_items.append(processed_item)
return processed_items
......@@ -297,9 +297,11 @@ def save_excel(sheet_data, large_sheet_data, new_file_name):
# 写入大数据(使用多线程并行写入不同表)
if large_sheet_data:
log.info(f"保存大数据,共计 {sum(len(data) for data in large_sheet_data.values())} 条")
with ThreadPoolExecutor() as executor:
for sheet_name, data in large_sheet_data.items():
executor.submit(write_sheet, writer, data, sheet_name)
for sheet_name, data in large_sheet_data.items():
write_sheet(writer, data, sheet_name)
# with ThreadPoolExecutor() as executor:
# for sheet_name, data in large_sheet_data.items():
# executor.submit(write_sheet, writer, data, sheet_name)
log.info(f"文件 {new_file_name} 保存完成,路径:{os.path.abspath(new_file_name)}")
......@@ -307,30 +309,36 @@ def save_excel(sheet_data, large_sheet_data, new_file_name):
def push_data_queue(file_name):
rabbit = rabbitmq.RabbitMQClient(host='172.18.218.11', port=15672, username='test', password='khd123456')
rabbit.connect(queue='return_robot', routing_key='return_robot', exchange='reports')
data = pd.read_excel(file_name)
for _, item_row in data.iterrows():
push_data = {
'ad_date': item_row.get('Order Date', ""), # spa费用数据日期
'erp_sku': item_row.get('ERP SKU', ""), # ERP SKU
'ad_amount': item_row.get('Original balance', ""), # spa费用金额
'ad_amount_currency': item_row.get('Agreement Currency', ""), # spa费用币制
'amount_type': item_row.get('Order Date', ""), # 费用类型
'group_name': item_row.get('Group Name', ""), # 组别 运营一组 运营二组
'group_code': item_row.get('Group Code', ""), # 组别 T1 T2
'asin': item_row.get('Asin', ""), # ASIN
'shop_code': shop_code, # 店铺code
'type': 2, # 1 sheet1 2 其他sheet
'parent_id': item_row.get('Invoice ID', ""), # sheet1 为Invoice ID 其他sheet为sheet名称
'order_no': item_row.get('Invoice ID', ""), # 订单号
}
# 推送数据
rabbit.send_message(push_data)
log.info("开始推送消息....")
data_dict = pd.read_excel(file_name, sheet_name=None)
for sheet_name, values in data_dict.items():
for _, item_row in values.iterrows():
parent_id = "Sheet1"
if sheet_name != "Sheet1":
parent_id = item_row.get('Invoice ID', "")
push_data = {
'ad_date': item_row.get('Order Date', ""), # spa费用数据日期
'erp_sku': item_row.get('ERP SKU', ""), # ERP SKU
'ad_amount': item_row.get('Original balance', ""), # spa费用金额
'ad_amount_currency': item_row.get('Agreement Currency', ""), # spa费用币制
'funding_type': item_row.get('Funding Type', ""), # 资金类型
'transaction_type': item_row.get('Transaction Type', ""), # 交易类型
'group_name': item_row.get('Group Name', ""), # 组别 运营一组 运营二组
'group_code': item_row.get('Group Code', ""), # 组别 T1 T2
'asin': item_row.get('Asin', ""), # ASIN
'shop_code': shop_code, # 店铺code
'type': 2, # 1 sheet1 2 其他sheet
'parent_id': parent_id, # sheet1 为Invoice ID 其他sheet为sheet名称
'order_no': item_row.get('Purchase Order', ""), # 订单号
}
# 推送数据
rabbit.send_message(push_data)
if __name__ == '__main__':
try:
country = helper.get_input_with_default("国家(目前支持[DE,FR,JP,CA,UK,US])", "US")
shop_code = helper.get_input_with_default("店铺编码", "US-VC")
domain.domain_page(page, country)
main()
page.close()
......
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