from data_processor.importer import SalesDataImporter
from data_processor.combined_sales_exporter import CombinedSalesExporter
from data_processor.daily_sales_exporter import DailySalesExporter
from data_processor.daily_zones_exporter import DailyZonesSalesExporter


# 数据库配置建议从环境变量或配置文件中读取
db_config = {
    'host': '10.41.1.220',
    'port': 3306,
    'user': 'it_user',
    'password': 'Goelia*199@5',
    'database': 'sales_data'
}

def data_processor(excel_file, export_file):
    """
    处理销售数据：导入 -> 导出每日销售 -> 导出区域销售 -> 合并导出
    """
    try:
        print("开始导入销售数据")
        importer = SalesDataImporter(db_config, excel_file)
        importer.import_data()
        print("销售数据导入完成")

        print("初始化每日销售导出器")
        daily_sales_exporter = DailySalesExporter(db_config)

        print("初始化区域销售导出器")
        daily_zones_sales_exporter = DailyZonesSalesExporter(db_config)

        print("开始合并导出")
        combined_exporter = CombinedSalesExporter(daily_sales_exporter, daily_zones_sales_exporter)
        combined_exporter.export(export_file)
        print("合并导出完成")

    except Exception as e:
        print(f"数据处理过程中发生错误: {e}")
        raise
