package org.example.Api;

import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import org.example.Impl.BaseImpl;
import org.example.Impl.OptBaseImpl;
import org.example.Impl.Sql.factory.AllInOneSqlFactory;
import org.example.ModuleApi.ModuleAjaxApi.mapper.CRMapper;
import org.example.ModuleApi.ModuleAjaxApi.mapper.DMCrmMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;

import java.io.IOException;

public class OptBaseHandler extends BaseHandler {

    @Autowired
    protected JdbcTemplate jdbcTemplate;


    @Value("${custom.database.type}")
    protected String databaseType;


    @Autowired
    AllInOneSqlFactory allInOneSqlFactory;

    @Autowired
    protected CRMapper crmapper;

    @Autowired
    protected DMCrmMapper DMCrmMapper;



    private BaseImpl _opbImpl = null;

    @Override
    protected void initSystemParams(HttpServletRequest ctx) {
        super.initSystemParams((HttpServletRequest) ctx);
        _opbImpl = null;
    }

    @Override
    protected BaseImpl getBImpl() {
        // 延迟初始化：如果_opbImpl为null，则创建OptBaseImpl实例并赋值
        if (_opbImpl == null) {
            _opbImpl = new OptBaseImpl(jdbcTemplate, databaseType, allInOneSqlFactory, crmapper, DMCrmMapper);
        }
        return _opbImpl;
    }



}
