package cn.yw.videosyncchannel.service;

 import cn.yw.videosyncchannel.dao.YwvideosyncchannelDao;

import java.sql.SQLException;
import java.util.HashMap;
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;

@Service("ywvideosyncchannelService")
public class YwvideosyncchannelService extends BaseService {
	
	private static Log log = LogFactory.getLog(YwvideosyncchannelService.class);
	
	@Autowired
	private YwvideosyncchannelDao ywvideosyncchannelDao;
	
	/**
	 * 保存记录
	 */
	public void insert_Ywvideosyncchannel(Map map) throws SQLException{
		CommUtils.addParams(map, false);
		ywvideosyncchannelDao.insert_Ywvideosyncchannel(map);
	}

	/**
	 * 批量新增
	 */
	public void batch_insert_Ywvideosyncchannel(List<Map> params) throws SQLException{
		Map map = new HashMap();
		// 删除全部数据
		ywvideosyncchannelDao.delete_Ywvideosyncchannel(map);
		// 批量插入
		int ListSubSize = 1000;
		int subCount = params.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 = params.subList(fromIndex, toIndex);
            ywvideosyncchannelDao.batch_insert_Ywvideosyncchannel(subList);
        }
	}
	
	/**
	 * 修改记录
	 */
	public Integer update_Ywvideosyncchannel(Map map) throws SQLException{
		CommUtils.validateUpdateParams(map);
		CommUtils.addParams(map, true);
		return ywvideosyncchannelDao.update_Ywvideosyncchannel(map);
	}
	
	/**
	 * 删除记录
	 */
	public Integer delete_Ywvideosyncchannel(Map map) throws SQLException{
		CommUtils.validateDeleteParams(map);
		return ywvideosyncchannelDao.delete_Ywvideosyncchannel(map);
	}

	/**
	 * 删除全部记录
	 */
	public Integer delete_AllYwvideosyncchannel() throws SQLException{
		Map map = new HashMap();
		return ywvideosyncchannelDao.delete_Ywvideosyncchannel(map);
	}
	
	/**
	 * 批处理删除记录
	 */
	/*
	public Integer batch_delete_Ywvideosyncchannel(Map map) throws SQLException{
		return ywvideosyncchannelDao.batch_delete_Ywvideosyncchannel(map);
	}
	*/
	
	/**
	 * 查询总数
	 */
	/*
	public Integer count_Ywvideosyncchannel(Map map) throws SQLException{
		return ywvideosyncchannelDao.count_Ywvideosyncchannel(map);
	}
	*/
	
	/**
	 * 查询列表记录SELECT
	 */
	public List<Map> query_Ywvideosyncchannel(Map map) throws SQLException{
		return ywvideosyncchannelDao.query_Ywvideosyncchannel(map);
	}
	
	/**
	 * 查询一条
	 */
	public Map get_Ywvideosyncchannel(Map map) throws SQLException{
		return ywvideosyncchannelDao.get_Ywvideosyncchannel(map);
	}
	
	/**
	 * 导出EXCEL
	 */
	 
	/*
	public Map exportYwvideosyncchannel(Map map) throws SQLException{
		return this.listYwvideosyncchannelByPage(map);
	}
	*/
	
	/**
	 * Ywvideosyncchannel 分页
	 */
	public Map listYwvideosyncchannelByPage(Map map) throws SQLException {
		List<Map> list = ywvideosyncchannelDao.query_Ywvideosyncchannel(map);
		Integer totalCount = ywvideosyncchannelDao.count_Ywvideosyncchannel(map);
		map.clear();
		map.put("total", totalCount);
		map.put("rows", list);
		return map;
	}
}
