package cn.yw.video.videochannelset.dao;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Repository;
import com.ibatis.sqlmap.client.SqlMapClient;

import cn.base.dao.BaseSqlMapDAO;

@Repository("sbtdspsrDao")
public class SbtdspsrDao  extends BaseSqlMapDAO{


	/**
	 * 增加记录
	 */
	public void insert_Sbtdspsr(Map map) throws SQLException{
		this.insert("insert_Sbtdspsr",map);
	}
	
	/**
	 * 批处理增加记录
	 */
	/*
	public void batch_insert_Sbtdspsr(List batch) throws SQLException{
		this.getSqlMapClientTemplate().insert("batch_insert_Sbtdspsr",batch);
	}
	*/
	 
	/**
	 * 修改记录
	 * @param map
	 * @return Integer
	 */
	public Integer update_Sbtdspsr(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().update("update_Sbtdspsr",map);
	}
	
	/**
	 * 删除记录
	 */
	public Integer delete_Sbtdspsr(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().delete("delete_Sbtdspsr",map);
	}
	
	/**
	 * 批处理删除记录
	 */
	
	/*
	public Integer batch_delete_Sbtdspsr(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().delete("batch_delete_Sbtdspsr",map);
	}
	*/
	
	/**
	 * 查询总数
	 */
	public Integer count_Sbtdspsr(Map map) throws SQLException{
		return (Integer)this.queryForObject("count_Sbtdspsr",map);
	}
	
	/**
	 * 查询列表记录
	 */
	
	public List<Map> query_Sbtdspsr(Map map) throws SQLException{
		return this.queryForList("query_Sbtdspsr",map);
	}
	public List<Map> listSbtdspsrToChannelSet(Map map) throws SQLException{
		return this.queryForPage("listSbtdspsrToChannelSet",map);
	}
	public Integer countSbtdspsrToChannelSet(Map map) throws SQLException{
		return (Integer) this.queryForObject("countSbtdspsrToChannelSet",map);
	}

	public Integer count_Sbtdspsr_tdxx_ext(Map map) throws SQLException{
		return (Integer)this.queryForObject("count_Sbtdspsr_tdxx_ext",map);
	}

	public List<Map> query_Sbtdspsr_tdxx_ext(Map map) throws SQLException{
		return this.queryForPage("query_Sbtdspsr_tdxx_ext",map);
	}

	/**
	 * 查询列表记录
	 */
	public Map get_Sbtdspsr(Map map) throws SQLException{
		return (Map) this.queryForObject("query_Sbtdspsr",map);
	}
	
	
	// 行政目录管理
	public List<Map> query_Sbtdspsr_ext(Map map) throws SQLException{
		return this.queryForPage("query_Sbtdspsr_ext",map);
	}
	
	public Integer count_Sbtdspsr_ext(Map map) throws SQLException{
		return (Integer) this.queryForObject("count_Sbtdspsr_ext",map);
	}
	
	/**
	 * 修改记录
	 * @param map
	 * @return Integer
	 */
	public Integer batch_update_Sbtdspsr_xh(String xhs,String xzbh) throws SQLException{
		try { 
			this.getSqlMapClient().startTransaction(); 
			this.getSqlMapClient().startBatch();
			String[] p = xhs.split("\\,");
			if(p.length>0){
				for (int i = 0; i < p.length; i++) {
					if(p[i].length()>0){
						Map m = new HashMap();
						m.put("xh", p[i]);
						m.put("xzbh", xzbh);
						this.getSqlMapClient().update("update_SbtdspsrByXh",m);
					}
				}
			}
			this.getSqlMapClient().executeBatch(); 
			this.getSqlMapClient().commitTransaction(); 
			return 1;
			}catch (Exception e) { 
				e.printStackTrace(); 
				return 0;
			} finally { 
					this.getSqlMapClient().endTransaction(); 
			}
		
	}
	
	/**
	 * 批处理删除记录
	 * @param map
	 * @return Integer
	 */
	public Integer batch_delete_Sbtdspsr_xh(String xhs,String xzbh) throws SQLException{
		try { 
			this.getSqlMapClient().startTransaction(); 
			this.getSqlMapClient().startBatch();
			String[] p = xhs.split("\\,");
			if(p.length>0){
				for (int i = 0; i < p.length; i++) {
					if(p[i].length()>0){
						Map m = new HashMap();
						m.put("xh", p[i]);
						m.put("xzbh", xzbh);
						this.getSqlMapClient().update("detach_SbtdspsrByXh",m);
					}
				}
			}
			this.getSqlMapClient().executeBatch(); 
			this.getSqlMapClient().commitTransaction(); 
			return 1;
			}catch (Exception e) { 
				e.printStackTrace(); 
				return 0;
			} finally { 
					this.getSqlMapClient().endTransaction(); 
			}
	}
	
	// 行政目录管理使用 
	public Integer update_SbtdspsrByXzbh(Map map) throws SQLException{
		return this.update("update_SbtdspsrByXzbh",map);
	}

	public Map get_SbtdspsrDetail(Map map) throws SQLException{
		return (Map) this.getSqlMapClientTemplate().queryForObject("get_SbtdspsrDetail",map);
	}

	public Integer updateJdWdByXh(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().update("updateJdWdByXh",map);
	}

	public List<Map> getSbtdspsrList(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("getSbtdspsrList",map);
	}

	public Integer getSbtdspsrCount(Map map) throws SQLException{
		return (Integer)this.getSqlMapClientTemplate().queryForObject("getSbtdspsrCount",map);
	}
}
