package com.eactive.eai.rms.onl.statistics.backup.dao;

import java.util.HashMap;

import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.stereotype.Repository;

import com.eactive.eai.rms.common.base.SqlMapClientTemplateDao;
import com.eactive.eai.rms.common.datasource.DataSourceContextHolder;
import com.eactive.eai.rms.common.datasource.DataSourceType;
import com.eactive.eai.rms.common.datasource.SpecifiedDataSourceExecutor;
import com.eactive.eai.rms.onl.statistics.backup.vo.Tseaist01VO;
 
@Repository
public class Tseaist01DAO extends SqlMapClientTemplateDao {

    public Tseaist01VO findTseaist01(String date, String statcJobCyclDstcd) {
    	Tseaist01VO result = new Tseaist01VO();
    	DataSourceType dt = DataSourceContextHolder.getDataSourceType();
        final HashMap<String, String> paramMap = new HashMap<String, String>();
        paramMap.put("statcJobYmd", date);
        paramMap.put("statcJobCyclDstcd", statcJobCyclDstcd);
        
        try {
            result = new SpecifiedDataSourceExecutor<Tseaist01VO>(dt) {
                protected Tseaist01VO doExecute() throws Exception {
                    return (Tseaist01VO)template.queryForObject("Tseaist01.findTseaist01", paramMap);
                }
            }.execute();
        } catch (IncorrectResultSizeDataAccessException e) {
            return null;
        }
        return result;
    }

    public void insertTseaist01(String date, String statcJobCyclDstcd,
            String statcJobStartHMS, String statcJobEndHMS, String sucssYn,
            String errMsg) {
    	DataSourceType dt = DataSourceContextHolder.getDataSourceType();
        final HashMap<String, String> paramMap = new HashMap<String, String>();
        paramMap.put("statcJobYmd", date);
        paramMap.put("statcJobCyclDstcd", statcJobCyclDstcd);
        paramMap.put("statcJobStartHMS", statcJobStartHMS);
        paramMap.put("statcJobEndHMS", statcJobEndHMS);
        paramMap.put("sucssYn", sucssYn);
        paramMap.put("errMsg", errMsg);
        
        new SpecifiedDataSourceExecutor<Integer>(dt) {
                protected Integer doExecute() throws Exception {
                    return (Integer)template.insert("Tseaist01.insertTseaist01", paramMap);
                }
            }.execute();
    }

    public void insertTseaist01(Tseaist01VO tseaist01VO) {
        insertTseaist01(tseaist01VO.getStatcJobYmd(),
            tseaist01VO.getStatcJobCyclDstcd(),
            tseaist01VO.getStatcJobStartHMS(), tseaist01VO.getStatcJobEndHMS(),
            tseaist01VO.getSucssYn(), tseaist01VO.getErrMsg());
    }

    public void updateTseaist01(String date, String statcJobCyclDstcd,
            String statcJobStartHMS, String statcJobEndHMS, String sucssYn,
            String errMsg) {
    	DataSourceType dt = DataSourceContextHolder.getDataSourceType();
        final HashMap<String, String> paramMap = new HashMap<String, String>();
        paramMap.put("statcJobYmd", date);
        paramMap.put("statcJobCyclDstcd", statcJobCyclDstcd);
        paramMap.put("statcJobStartHMS", statcJobStartHMS);
        paramMap.put("statcJobEndHMS", statcJobEndHMS);
        paramMap.put("sucssYn", sucssYn);
        paramMap.put("errMsg", errMsg);
        
        new SpecifiedDataSourceExecutor<Integer>(dt) {
                protected Integer doExecute() throws Exception {
                    return (Integer)template.update("Tseaist01.updateTseaist01", paramMap);
                }
            }.execute();
    }

    public void updateTseaist01(Tseaist01VO tseaist01VO) {
        updateTseaist01(tseaist01VO.getStatcJobYmd(),
            tseaist01VO.getStatcJobCyclDstcd(),
            tseaist01VO.getStatcJobStartHMS(), tseaist01VO.getStatcJobEndHMS(),
            tseaist01VO.getSucssYn(), tseaist01VO.getErrMsg());

    }

    public void deleteTseaist01(String date, String statcJobCyclDstcd) {
    	DataSourceType dt = DataSourceContextHolder.getDataSourceType();
        final HashMap<String, String> paramMap = new HashMap<String, String>();
        paramMap.put("statcJobYmd", date);
        paramMap.put("statcJobCyclDstcd", statcJobCyclDstcd);
        
        new SpecifiedDataSourceExecutor<Integer>(dt) {
                protected Integer doExecute() throws Exception {
                    return (Integer)template.delete("Tseaist01.deleteTseaist01", paramMap);
                }
            }.execute();
    }

    public void deleteAllMonthlyData(String month) {

    	DataSourceType dt = DataSourceContextHolder.getDataSourceType();
        final HashMap<String, String> paramMap = new HashMap<String, String>();
        paramMap.put("month", month);
        
        new SpecifiedDataSourceExecutor<Integer>(dt) {
                protected Integer doExecute() throws Exception {
                    return (Integer)template.delete("Tseaist01.deleteTSEAIST01", paramMap);
                }
            }.execute();
        new SpecifiedDataSourceExecutor<Integer>(dt) {
                protected Integer doExecute() throws Exception {
                    return (Integer)template.delete("Tseaist01.deleteTSEAIST02", paramMap);
                }
            }.execute();
        new SpecifiedDataSourceExecutor<Integer>(dt) {
                protected Integer doExecute() throws Exception {
                    return (Integer)template.delete("Tseaist01.deleteTSEAIST03", paramMap);
                }
            }.execute();
        new SpecifiedDataSourceExecutor<Integer>(dt) {
                protected Integer doExecute() throws Exception {
                    return (Integer)template.delete("Tseaist01.deleteTSEAIST04", paramMap);
                }
            }.execute();
    }

}
