package cn.yw.nhyw.nhywjjzcxx.service;

import cn.base.bean.BaseService;
import cn.base.util.CommUtils;
import cn.yw.nhyw.nhywjjzcxx.dao.NhywjjzcxxDao;
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("nhywjjzcxxService")
public class NhywjjzcxxService extends BaseService {

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

    @Autowired
    private NhywjjzcxxDao nhywjjzcxxDao;

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


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

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

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

    /**
     * 查询总数
     */

    public Integer count_Nhyjjzcxx(Map map) throws SQLException{
        return nhywjjzcxxDao.count_Nhyjjzcxx(map);
    }


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

    /**
     * 查询一条
     */

	/*
	public Map get_Nhywjjzcxx(Map map) throws SQLException{
		return nhywjjzcxxDao.get_Nhywjjzcxx(map);
	}
	*/

    /**
     * 导出EXCEL
     */

	/*
	public Map exportNhywjjzcxx(Map map) throws SQLException{
		return this.listNhywjjzcxxByPage(map);
	}
	*/

    /**
     * Nhywjjzcxx 分页
     */
    public Map listNhywjjzcxxByPage(Map map) throws SQLException {
        List<Map> list = nhywjjzcxxDao.query_Nhywjjzcxx(map);
        Integer totalCount = nhywjjzcxxDao.count_Nhyjjzcxx(map);
        map.clear();
        map.put("total", totalCount);
        map.put("rows", list);
        return map;
    }


    // 批量增加
    public String  batch_insert_Nhywjjzcxxinfo(List 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);
                nhywjjzcxxDao.batch_insert_Nhywjjzcxxinfo(subList);
            }
            return "1";
        }catch (SQLException ex){
            return "0";
        }

    }
}
