package cn.yw.archive.videoarchive.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.archive.videoarchive.dao.YwarchivevideoinfoDao;

@Service("ywarchivevideoinfoService")
public class YwarchivevideoinfoService extends BaseService {
	
	private static Log log = LogFactory.getLog(YwarchivevideoinfoService.class);
	
	@Autowired
	private YwarchivevideoinfoDao ywarchivevideoinfoDao;
	
	/**
	 * 保存记录
	 */	
	public void insert_Ywarchivevideoinfo(Map map) throws SQLException{
		CommUtils.addParams(map, false);
		ywarchivevideoinfoDao.insert_Ywarchivevideoinfo(map);
	}
	

	
	/**
	 * 修改记录
	 */
	public Integer update_Ywarchivevideoinfo(Map map) throws SQLException{
		CommUtils.validateUpdateParams(map);
		CommUtils.addParams(map, true);
		return ywarchivevideoinfoDao.update_Ywarchivevideoinfo(map);
	}
	
	
	/**
	 * 删除记录
	 */
	public Integer delete_Ywarchivevideoinfo(Map map) throws SQLException{
		CommUtils.validateDeleteParams(map);
		return ywarchivevideoinfoDao.delete_Ywarchivevideoinfo(map);
	}
	
	
	/**
	 * 批处理删除记录
	 */
	public Integer batch_delete_Ywarchivevideoinfo(Map map) throws SQLException{
		return ywarchivevideoinfoDao.batch_delete_Ywarchivevideoinfo(map);
	}
	
	
	/**
	 * 查询总数
	 */
	public Integer count_Ywarchivevideoinfo(Map map) throws SQLException{
		return ywarchivevideoinfoDao.count_Ywarchivevideoinfo(map);
	}
	
	
	/**
	 * 查询列表记录SELECT
	 */
	public List<Map> query_Ywarchivevideoinfo(Map map) throws SQLException{
		return ywarchivevideoinfoDao.query_Ywarchivevideoinfo(map);
	}
	
	
	/**
	 * 查询一条
	 */
	public Map get_Ywarchivevideoinfo(Map map) throws SQLException{
		return ywarchivevideoinfoDao.get_Ywarchivevideoinfo(map);
	}
	
	
	/**
	 * 导出EXCEL
	 */
	 
	/*
	public Map exportYwarchivevideoinfo(Map map) throws SQLException{
		return this.listYwarchivevideoinfoByPage(map);
	}
	*/
	
	/**
	 * Ywarchivevideoinfo 分页
	 */
	public Map listYwarchivevideoinfoByPage(Map map) throws SQLException {
		List<Map> list = ywarchivevideoinfoDao.query_Ywarchivevideoinfo(map);
		Integer totalCount = ywarchivevideoinfoDao.count_Ywarchivevideoinfo(map);
		map.clear();
		map.put("total", totalCount);
		map.put("rows", list);
		return map;
	}
	
	// 批量增加
	public void batch_insert_Ywarchivevideoinfo(List 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 subList = list.subList(fromIndex, toIndex);
            ywarchivevideoinfoDao.batch_insert_Ywarchivevideoinfo(subList);
		}
//		ywarchivevideoinfoDao.batch_insert_Ywarchivevideoinfo(list);

	}
	
	
	// 查询excel表对应数据库相关信息
	public List<Map> getExeclColname(Map map) throws SQLException{
		return ywarchivevideoinfoDao.getExeclColname(map);
	}

	// 查询需要转换的信息
	public List<Map> getExeclCodeName(Map map) throws SQLException{
		return ywarchivevideoinfoDao.getExeclCodeName(map);
	}
	
	// 根据columnname查询  代码及中文
	public List<Map> queryByColumnname(Map map) throws SQLException{
		return ywarchivevideoinfoDao.queryByColumnname(map);
	}
	
	public List<String> queryOutsidecode(Map map) throws SQLException{
		return ywarchivevideoinfoDao.queryOutsidecode(map);
	}
	
}
