package com.eactive.eai.rms.onl.loader.dao;

import java.util.HashMap;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import com.eactive.eai.rms.common.base.SqlMapClientForMonitoringTemplateDao;
import com.eactive.eai.rms.onl.loader.vo.RuleDeployJobItemVo;
import com.eactive.eai.rms.onl.loader.vo.RuleDeployJobVo;

@SuppressWarnings("deprecation")
@Repository("ruleDeployJobDao")
public class RuleDeployJobDaoImpl extends SqlMapClientForMonitoringTemplateDao implements RuleDeployJobDao {

	@Override
	public void insert(RuleDeployJobVo jobVo) throws Exception {
		this.template.insert("RuleDeployJob.insert", jobVo);
	}

	@Override
	public void insertItem(RuleDeployJobItemVo itemVo) throws Exception {
		this.template.insert("RuleDeployJob.insertItem", itemVo);
	}

	@Override
	public void update(RuleDeployJobVo jobVo) throws Exception {
		this.template.insert("RuleDeployJob.update", jobVo);
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public RuleDeployJobVo selectOne(String jobId) throws Exception {
		HashMap paramMap = new HashMap();
		paramMap.put("jobId", jobId);
		return (RuleDeployJobVo) template.queryForObject("RuleDeployJob.selectDetail", paramMap);
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public List<RuleDeployJobItemVo> selectItems(String jobId) throws Exception {
		HashMap paramMap = new HashMap();
		paramMap.put("jobId", jobId);
		return (List<RuleDeployJobItemVo>) template.queryForList("RuleDeployJob.selectItems", paramMap);
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public List<RuleDeployJobVo> selectJobAll(RuleDeployJobVo searchJobVo, int startIdx, int endIdx) throws Exception {
		HashMap paramMap = new HashMap();
		paramMap.put("jobId", StringUtils.defaultString(searchJobVo.getJobId()));
		paramMap.put("jobTitle", StringUtils.defaultString(searchJobVo.getJobTitle()));
		paramMap.put("serviceType", StringUtils.defaultString(searchJobVo.getServiceType()));
		paramMap.put("status", StringUtils.defaultString(searchJobVo.getStatus()));
		paramMap.put("scheduledDateTime", StringUtils.defaultString(searchJobVo.getScheduledDateTime()));
		paramMap.put("startNum", startIdx);
		paramMap.put("endNum", endIdx);
		return (List<RuleDeployJobVo>) template.queryForList("RuleDeployJob.selectJobAll", paramMap);
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public void deleteHistory(String dateTime) throws Exception {
		HashMap paramMap = new HashMap();
		paramMap.put("jobId", dateTime);
		this.template.delete("RuleDeployJob.deleteHistory", paramMap);
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public void deleteItemHistory(String dateTime) throws Exception {
		HashMap paramMap = new HashMap();
		paramMap.put("jobId", dateTime);
		this.template.delete("RuleDeployJob.deleteItemHistory", paramMap);
	}

	@SuppressWarnings("rawtypes")
	@Override
	public int selectListCount(HashMap paramMap) throws Exception {
		return (Integer) template.queryForObject("RuleDeployJob.selectListCount", paramMap);
	}

	@SuppressWarnings("rawtypes")
	@Override
	public List selectList(HashMap paramMap) throws Exception {
		return template.queryForList("RuleDeployJob.selectList", paramMap);
	}

	@SuppressWarnings("rawtypes")
	@Override
	public HashMap selectJobDetail(HashMap<String, Object> paramMap) throws Exception {
		return (HashMap) template.queryForObject("RuleDeployJob.selectJobDetail", paramMap);
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public List<HashMap> selectJobItems(HashMap<String, Object> paramMap) throws Exception {
		return template.queryForList("RuleDeployJob.selectListJobItems", paramMap);
	}

	@SuppressWarnings({ "rawtypes" })
	@Override
	public void delete(HashMap paramMap) throws Exception {
		this.template.delete("RuleDeployJob.delete", paramMap);
	}

	@SuppressWarnings({ "rawtypes" })
	@Override
	public void deleteJobItems(HashMap paramMap) throws Exception {
		this.template.delete("RuleDeployJob.deleteJobItems", paramMap);
	}
}
