package com.brilliance.isc.common.register.diasav;

import com.brilliance.isc.common.cache.atpbch.AtpBchCacheService;
import com.brilliance.isc.common.context.SettleContext;
import com.brilliance.isc.common.context.SpringEnvContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class DiasavRegisterFactory {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private AtpBchCacheService atpBchCacheService;

    public IDiasavRegister getDiasavRegister(String transName) {
        IDiasavRegister diasavRegister = null;
        transName = SettleContext.getTransName();
        try {
            diasavRegister = SpringEnvContext.getBean(atpBchCacheService.getSdTransNameForRegister().toLowerCase() + ".diasavRegister");
        } catch (NoSuchBeanDefinitionException e) {
            logger.warn("没有找到交易{}的备忘录注册类,使用默认备忘录注册类");
            diasavRegister = SpringEnvContext.getBean("default.diasavRegister");
        }
        return diasavRegister;

    }
}
