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

feat(app): 增加原始数据推送功能

- 在 SPARobot 类中添加 __push_origin_data 方法用于推送原始数据
- 在 push_data_queue 方法中调用 __push_origin_data 和 __push_item_data 方法
- 在 run 方法中保存原始文件名
parent 5a54caa4
...@@ -21,6 +21,7 @@ class Spa(AutoInterface): ...@@ -21,6 +21,7 @@ class Spa(AutoInterface):
self.page = page self.page = page
self.country = country self.country = country
self.shop_code = shop_code self.shop_code = shop_code
self.origin_file_name = None
# 获取当前日期和时间并格式化 # 获取当前日期和时间并格式化
current_datetime = datetime.now().strftime('%Y-%m-%d-%H-%M') current_datetime = datetime.now().strftime('%Y-%m-%d-%H-%M')
...@@ -260,10 +261,34 @@ class Spa(AutoInterface): ...@@ -260,10 +261,34 @@ class Spa(AutoInterface):
return round(total_amount, 2) return round(total_amount, 2)
def push_data_queue(self): def push_data_queue(self):
self.logger.info("开始读取数据....") self.logger.info("开始推送原数据...")
self.__push_origin_data()
self.logger.info("开始推送处理后的数据...")
self.__push_item_data()
def __push_origin_data(self):
df = pd.read_excel(self.origin_file_name)
rabbit.connection()
rabbit.connect(queue='spa_origin_robot', routing_key='spa_origin_robot', exchange='reports')
for _, item_row in df.iterrows():
original_balance = item_row.get('Original balance', 0.0)
push_data = {
'invoice_id': item_row.get("Invoice ID",""), # 获取发票 ID
'invoice_date': item_row.get("Invoice date", ""), # 发票日期
'original_balance': helper.extract_numeric_value(original_balance,self.country), # spa费用金额
'funding_type': item_row.get('Funding Type', ""), # 资金类型
'shop_code': self.shop_code, # 店铺code
}
# 推送数据
rabbit.send_message(push_data)
rabbit.close()
def __push_item_data(self):
# 读取Excel文件 # 读取Excel文件
xls = pd.ExcelFile(self.result_file_name) xls = pd.ExcelFile(self.result_file_name)
self.logger.info("开始推送消息....")
rabbit.connection() rabbit.connection()
rabbit.connect(queue='spa_robot', routing_key='spa_robot', exchange='reports') rabbit.connect(queue='spa_robot', routing_key='spa_robot', exchange='reports')
...@@ -348,6 +373,7 @@ class Spa(AutoInterface): ...@@ -348,6 +373,7 @@ class Spa(AutoInterface):
self.logger.info(f"所有sheet的总行数: {total_rows}") self.logger.info(f"所有sheet的总行数: {total_rows}")
self.logger.info(f"所有sheet的总金额: {total_amount}") self.logger.info(f"所有sheet的总金额: {total_amount}")
def run(self, file_name: str): def run(self, file_name: str):
# 获取数据 # 获取数据
relation_data = api.sku_relations(self.country) # 获取 ASIN 与 SKU 的对应关系数据 relation_data = api.sku_relations(self.country) # 获取 ASIN 与 SKU 的对应关系数据
...@@ -355,6 +381,8 @@ class Spa(AutoInterface): ...@@ -355,6 +381,8 @@ class Spa(AutoInterface):
if not os.path.isfile(file_name): if not os.path.isfile(file_name):
raise FileNotFoundError(f"{file_name},文件不存在") raise FileNotFoundError(f"{file_name},文件不存在")
self.origin_file_name = file_name
# 读取数据列表 # 读取数据列表
coop_list = pd.read_excel(file_name) coop_list = pd.read_excel(file_name)
self.logger.info(f"共计: {len(coop_list)} 条数据") self.logger.info(f"共计: {len(coop_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