package cn.yw.nhyw.nhywsbipgl.service;

import cn.base.bean.BaseService;
import cn.base.util.CommUtils;
import cn.yw.nhyw.nhywsbipgl.dao.NhywsbipglDao;
import com.ibatis.common.logging.Log;
import com.ibatis.common.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

@Service("nhywsbipglService")
public class NhywsbipglService extends BaseService {

    private static Log log = LogFactory.getLog(NhywsbipglService.class);

    @Autowired
    private NhywsbipglDao nhywsbipglDao;

    /**
     * 保存记录
     */
    public void insert_Nhywsbipgl(Map map) throws SQLException{
        CommUtils.addParams(map, false);
        nhywsbipglDao.insert_Nhywsbipgl(map);
    }


    /**
     * 修改记录
     */
    public Integer update_Nhywsbipgl(Map map) throws SQLException{
        return nhywsbipglDao.update_Nhywsbipgl(map);
    }

    /**
     * 删除记录
     */
    public Integer delete_Nhywsbipgl(Map map) throws SQLException {
        return nhywsbipglDao.delete_Nhywsbipgl(map);
    }

    /**
     * 批处理删除记录
     */
	/*
	public Integer batch_delete_nhywsbipgl(Map map) throws SQLException{
		return nhywsbipglDao.batch_delete_nhywsbipgl(map);
	}
	*/

    /**
     * 查询总数
     */

    public Integer count_Nhywsbipgl(Map map) throws SQLException{
        return nhywsbipglDao.count_Nhywsbipgl(map);
    }


    /**
     * 查询列表记录SELECT
     */
    public List<Map> query_Nhywsbipgl(Map map) throws SQLException{
        return nhywsbipglDao.query_Nhywsbipgl(map);
    }

    /**
     * 查询一条
     */

	/*
	public Map get_nhywsbipgl(Map map) throws SQLException{
		return nhywsbipglDao.get_nhywsbipgl(map);
	}
	*/

    /**
     * 导出EXCEL
     */

	/*
	public Map exportnhywsbipgl(Map map) throws SQLException{
		return this.listnhywsbipglByPage(map);
	}
	*/

    /**
     * Nhywjjzcxx 分页
     */
    public Map listNhywsbipglByPage(Map map) throws SQLException {
        List<Map> list = nhywsbipglDao.query_Nhywsbipgl(map);
        Integer totalCount = nhywsbipglDao.count_Nhywsbipgl(map);
        map.clear();
        map.put("total", totalCount);
        map.put("rows", list);
        return map;
    }


    // 批量增加
    public String  batch_insertNhywsbipglinfo( List<Map> list) {
        try {
            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);
                nhywsbipglDao.batch_insert_Nhywsbipglinfo(subList);
            }
            return "1";
        }catch (SQLException ex){
            return "0";
        }

    }
}
