# author:qinguanglei
# ddate:2023/11/21 17:12
from common.dbutils import SQLHelper
from common.logger import log


class SwitchAction(object):

    def close_relate_verify(self, company_code):
        # 前关联交易结果
        curr = SQLHelper.fetch_one(
            'select COMPANY_CODE, F_RELATION_CHECK_LEVEL from F_RELATION_CHECK_LEVEL where COMPANY_CODE = %s',
            [company_code])
        log.info(f'当前关联交易结果:{curr}')
        # 关闭关联交易验证，常规测试，关闭该校验
        SQLHelper.update_one('update BO_EU_BSI_COMPANY set F_RELATION_CHECK_LEVEL = %s where COMPANY_CODE = %s',
                             [" ", company_code])
        now = SQLHelper.fetch_one(
            'select COMPANY_CODE, F_RELATION_CHECK_LEVEL from F_RELATION_CHECK_LEVEL where COMPANY_CODE = %s',
            [company_code])
        # 关闭关联交易后结果
        log.info(f'关闭关联交易结果:{now}')

    def open_relate_verify(self, company_code, level):
        # 打开关联交易验证
        # 当前关联交易结果
        curr = SQLHelper.fetch_one(
            'select COMPANY_CODE, F_RELATION_CHECK_LEVEL from F_RELATION_CHECK_LEVEL where COMPANY_CODE = %s',
            [company_code])
        log.info(f'当前关联交易结果:{curr}')
        # 关闭关联交易验证，常规测试，关闭该校验
        SQLHelper.update_one('update BO_EU_BSI_COMPANY set F_RELATION_CHECK_LEVEL = %s where COMPANY_CODE = %s',
                             [level, company_code])
        now = SQLHelper.fetch_one(
            'select COMPANY_CODE, F_RELATION_CHECK_LEVEL from F_RELATION_CHECK_LEVEL where COMPANY_CODE = %s',
            [company_code])
        # 关闭关联交易后结果
        log.info(f'打开关联交易结果:{now}')

    def close_license_verify(self):
        # 关闭证照校验，常规测试，关闭该校验
        pass

    def open_license_verify(self):
        # 打开证照校验
        pass

    def close_credit_control(self, company_address):
        # 关闭信用管控，常规测试，关闭该校验
        # 当前信用管控结果
        curr = SQLHelper.fetch_one(
            'select COMPANY_ADDRESS, LIMIT_CONTROL,PAYDAYS from BO_EU_BSI_CREDIT_CONSTANT where COMPANY_ADDRESS = %s',
            [company_address])
        log.info(f'当前信用管控结果:{curr}')
        SQLHelper.update_one(
            'update BO_EU_BSI_CREDIT_CONSTANT set LIMIT_CONTROL = %s and PAYDAYS = %s where COMPANY_ADDRESS = %s',
            ["N", "N", company_address])
        # 关闭后信用管控结果
        now = SQLHelper.fetch_one(
            'select COMPANY_ADDRESS, LIMIT_CONTROL,PAYDAYS from BO_EU_BSI_CREDIT_CONSTANT where COMPANY_ADDRESS = %s',
            [company_address])
        log.info(f'关闭后信用管控结果:{curr}')
        pass

    def open_credit_control(self, company_address, limit_control, paydays):
        # 打开信用管控
        # 当前信用管控结果
        curr = SQLHelper.fetch_one(
            'select COMPANY_ADDRESS, LIMIT_CONTROL,PAYDAYS from BO_EU_BSI_CREDIT_CONSTANT where COMPANY_ADDRESS = %s',
            [company_address])
        log.info(f'当前信用管控结果:{curr}')
        SQLHelper.update_one(
            'update BO_EU_BSI_CREDIT_CONSTANT set LIMIT_CONTROL = %s and PAYDAYS = %s where COMPANY_ADDRESS = %s',
            [limit_control, paydays, company_address])
        # 关闭后信用管控结果
        now = SQLHelper.fetch_one(
            'select COMPANY_ADDRESS, LIMIT_CONTROL,PAYDAYS from BO_EU_BSI_CREDIT_CONSTANT where COMPANY_ADDRESS = %s',
            [company_address])
        log.info(f'打开后信用管控结果:{now}')
