package cn.yw.video.videochannelset.service;

 import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.base.bean.BaseService;
import cn.base.util.CommUtils;
import cn.yw.video.videochannelset.dao.YwvideochannelsetlistDao;

@Service("ywvideochannelsetlistService")
public class YwvideochannelsetlistService extends BaseService {
	
	private static Log log = LogFactory.getLog(YwvideochannelsetlistService.class);
	
	@Autowired
	private YwvideochannelsetlistDao ywvideochannelsetlistDao;
	
	/**
	 * 保存记录
	 */
	public void insert_Ywvideochannelsetlist(Map map) throws SQLException{
		CommUtils.addParams(map, false);
		ywvideochannelsetlistDao.insert_Ywvideochannelsetlist(map);
	}
	public void batch_add_Ywvideochannelsetlist(List list) throws SQLException{
		ywvideochannelsetlistDao.batch_add_Ywvideochannelsetlist(list);
	}

	
	/**
	 * 修改记录
	 */
	public Integer update_Ywvideochannelsetlist(Map map) throws SQLException{
		CommUtils.validateUpdateParams(map);
		CommUtils.addParams(map, true);
		return ywvideochannelsetlistDao.update_Ywvideochannelsetlist(map);
	}
	
	/**
	 * 删除记录
	 */
	public Integer delete_Ywvideochannelsetlist(Map map) throws SQLException{
		CommUtils.validateDeleteParams(map);
		return ywvideochannelsetlistDao.delete_Ywvideochannelsetlist(map);
	}
	
	/**
	 * 批处理删除记录
	 */
	public Integer batch_delete_Ywvideochannelsetlist(List l) throws SQLException{
		return ywvideochannelsetlistDao.batch_delete_Ywvideochannelsetlist(l);
	}
	public Integer update_batch_videomodel(Map map) throws SQLException{
		return ywvideochannelsetlistDao.update_batch_videomodel(map);
	}
	public Integer update_batch_recorddays(Map map) throws SQLException{
		return ywvideochannelsetlistDao.update_batch_recorddays(map);
	}
	public Integer update_batch_ywvideochannelsetlist(Map map) throws SQLException{
		return ywvideochannelsetlistDao.update_batch_ywvideochannelsetlist(map);
	}
	
	/**
	 * 查询总数
	 */
	public Integer count_Ywvideochannelsetlist(Map map) throws SQLException{
		return ywvideochannelsetlistDao.count_Ywvideochannelsetlist(map);
	}
	
	/**
	 * 查询列表记录SELECT
	 */
	public List<Map> query_Ywvideochannelsetlist(Map map) throws SQLException{
		return ywvideochannelsetlistDao.query_Ywvideochannelsetlist(map);
	}
	public List<Map> query_Ywvideochannelsetlist_select(Map map) throws SQLException{
		return ywvideochannelsetlistDao.query_Ywvideochannelsetlist_select(map);
	}
	
	/**
	 * 查询一条
	 */
	 
	public Map get_Ywvideochannelsetlist(Map map) throws SQLException{
		return ywvideochannelsetlistDao.get_Ywvideochannelsetlist(map);
	}
	
	/**
	 * 导出EXCEL
	 */
	 
	public Map exportYwvideochannelsetlist(Map map) throws SQLException{
		return this.listYwvideochannelsetlistByPage(map);
	}
	
	/**
	 * Ywvideochannelsetlist 分页
	 */
	public Map listYwvideochannelsetlistByPage(Map map) throws SQLException {
		List<Map> list = ywvideochannelsetlistDao.query_Ywvideochannelsetlist(map);
		Integer totalCount = ywvideochannelsetlistDao.count_Ywvideochannelsetlist(map);
		map.clear();
		map.put("total", totalCount);
		map.put("rows", list);
		return map;
	}
	
	// 批量增加
	public void insert_batch_Ywvideochannelsetlist(List<Map> list) throws SQLException {
		int ListSubSize = 1000;
        int subCount = list.size();
        int subPageTotal = (subCount / ListSubSize) + ((subCount % ListSubSize > 0) ? 1 : 0);
        //分页计算，根据页码取数据
        for (int i = 0, len = subPageTotal - 1; i <= len; i++) {
            int fromIndex = i * ListSubSize;
            int toIndex = ((i == len) ? subCount : ((i + 1) * ListSubSize));
            List<Map> subList = list.subList(fromIndex, toIndex);
            ywvideochannelsetlistDao.insert_batch_Ywvideochannelsetlist(subList);
		}
//		ywvideochannelsetlistDao.insert_batch_Ywvideochannelsetlist(list);
	}
}
