from src.batch.common.batch_context import BatchContext
from src.batch.laundering import (
    create_inst_merge_for_laundering, emp_chg_inst_laundering,
    ult_ident_presc_laundering, sales_results_laundering)
from src.batch.dcf_inst_merge import integrate_dcf_inst_merge
from src.logging.get_logger import get_logger

batch_context = BatchContext.get_instance()

logger = get_logger('実績洗替')


def exec():
    """実績洗替処理"""
    logger.info('実績更新：起動')
    # 営業日ではない場合、実績洗替処理は実行しない
    if batch_context.is_not_business_day:
        logger.info('営業日ではないため、実績洗替処理をスキップします。')
        return
    # 洗替用マスタ作成
    create_inst_merge_for_laundering.exec()
    # DCF施設統合マスタ日次更新
    integrate_dcf_inst_merge.exec()
    # 施設担当者洗替
    emp_chg_inst_laundering.exec()
    # 納入先処方元マスタ洗替
    ult_ident_presc_laundering.exec()
    # 卸販売洗替
    sales_results_laundering.exec()

    # # 並列処理のテスト用コード
    # import time
    # for _ in range(100):
    #     logger.info('実績洗替処理中')
    #     time.sleep(0.25)

    logger.info('実績更新：終了')
