package cn.yw.nhyw.nhywjtxcrzgl.dao;
import cn.base.dao.BaseSqlMapDAO;
import cn.base.util.DateUtil;
import cn.base.util.StringUtil;
import cn.base.util.Struts2Utils;
import cn.bsystem.ptuserrole.model.PtyhBean;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.SqlMapClientCallback;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Repository;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapExecutor;

@Repository("nhywjtssxcsbDao")
public class NhywjtssxcsbDao  extends BaseSqlMapDAO{

	/**
	 * 增加记录
	 */
	public void insert_Nhywjtssxcsb(Map map) throws SQLException{
		this.insert("insert_Nhywjtssxcsb",map);
	}
	public void batch_add_Nhywjtssxcsb(final String xcdh,final String xcsblx,final JSONArray json) throws SQLException{
		try { 
			this.getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
				@Override
				public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
					executor.startBatch();
					String username = ((PtyhBean)Struts2Utils.getSession().getAttribute("userInfo")).getYhzh();
					JSONObject object = null;
					for (int i = 0; i < json.size(); i++) {
						object = JSONObject.fromObject(json.get(i));
						Map m = new HashMap();
						m.put("xh", StringUtil.getUUID());
						m.put("xcdh", xcdh);
						m.put("xcsblx", xcsblx);
						m.put("xcsbbh", object.get("videonum"));
						m.put("xcsbtdbh", object.get("channelnum"));
						m.put("xcsbmc", object.get("channelname"));
						m.put("cjry", username);
						m.put("cjrq", DateUtil.currentDateTime());
						m.put("xgry", username);
						m.put("xgrq", DateUtil.currentDateTime());
						executor.insert("insert_Nhywjtssxcsb",m);
					}
					executor.executeBatch();
					return null;
				}
				
			});
		}catch (Exception e) { 
			e.printStackTrace(); 
		} 
	}
/*	public void batch_add_Nhywjtssxcsb(String xcdh,JSONArray json) throws SQLException{
		try { 
			this.getSqlMapClient().startTransaction(); 
			this.getSqlMapClient().startBatch();
			String username = ((PtyhBean)Struts2Utils.getSession().getAttribute("userInfo")).getYhzh();
			JSONObject object = null;
			for (int i = 0; i < json.size(); i++) {
				object = JSONObject.fromObject(json.get(i));
				Map m = new HashMap();
				m.put("xh", StringUtil.getUUID());
				m.put("xcdh", xcdh);
				m.put("xcsblx", "0");
				m.put("xcsbbh", object.get("videonum"));
				m.put("xcsbtdbh", object.get("channelnum"));
				m.put("xcsbmc", object.get("channelname"));
				m.put("cjry", username);
				m.put("cjrq", DateUtil.currentDateTime());
				m.put("xgry", username);
				m.put("xgrq", DateUtil.currentDateTime());
				this.getSqlMapClient().insert("insert_Nhywjtssxcsb",m);
			}
			this.getSqlMapClient().executeBatch(); 
			this.getSqlMapClient().commitTransaction(); 
		}catch (Exception e) { 
			e.printStackTrace(); 
		} finally { 
			this.getSqlMapClient().endTransaction(); 
		}
	}
*/	
	/**
	 * 批处理增加记录
	 */
	public void batch_insert_Nhywjtssxcsb(List batch) throws SQLException{
		this.insert("batch_insert_Nhywjtssxcsb",batch);
	}
	 
	/**
	 * 修改记录
	 */
	public Integer update_Nhywjtssxcsb(Map map) throws SQLException{
		return this.update("update_Nhywjtssxcsb",map);
	}
	
	/**
	 * 删除记录
	 */
	public Integer delete_Nhywjtssxcsb(Map map) throws SQLException{
		return this.delete("delete_Nhywjtssxcsb",map);
	}
	
	/**
	 * 批处理删除记录
	 */
	
	public Integer batch_delete_Nhywjtssxcsb(Map map) throws SQLException{
		return this.delete("batch_delete_Nhywjtssxcsb",map);
	}
	
	/**
	 * 查询总数
	 */
	public Integer count_Nhywjtssxcsb(Map map) throws SQLException{
		return (Integer)this.queryForObject("count_Nhywjtssxcsb",map);
	}
	public Integer countJksbByFwsbh(Map map) throws SQLException{
		return (Integer)this.queryForObject("countJksbByFwsbh",map);
	}
	
	/**
	 * 查询列表记录
	 */
	
	public List<Map> query_Nhywjtssxcsb(Map map) throws SQLException{
		return this.queryForPage("query_Nhywjtssxcsb",map);
	}
	public List<Map> listJksbByFwsbh(Map map) throws SQLException{
		return this.queryForPage("listJksbByFwsbh",map);
	}
	
	/**
	 * 查询列表记录
	 */
	public Map get_Nhywjtssxcsb(Map map) throws SQLException{
		return (Map) this.queryForObject("query_Nhywjtssxcsb",map);
	}
	
	//交通设备 - start
	public List<Map> listJtsbByFwsbh_bx(Map map) throws SQLException{
		return this.queryForPage("listJtsbByFwsbh_bx",map);
	}
	public Integer countJtsbByFwsbh_bx(Map map) throws SQLException{
		return (Integer)this.queryForObject("countJtsbByFwsbh_bx",map);
	}
	public List<Map> listJtsbByFwsbh_bz(Map map) throws SQLException{
		return this.queryForPage("listJtsbByFwsbh_bz",map);
	}
	public Integer countJtsbByFwsbh_bz(Map map) throws SQLException{
		return (Integer)this.queryForObject("countJtsbByFwsbh_bz",map);
	}
	public List<Map> listJtsbByFwsbh_hl(Map map) throws SQLException{
		return this.queryForPage("listJtsbByFwsbh_hl",map);
	}
	public Integer countJtsbByFwsbh_hl(Map map) throws SQLException{
		return (Integer)this.queryForObject("countJtsbByFwsbh_hl",map);
	}
	public List<Map> listJtsbByFwsbh_xhd(Map map) throws SQLException{
		return this.queryForPage("listJtsbByFwsbh_xhd",map);
	}
	public Integer countJtsbByFwsbh_xhd(Map map) throws SQLException{
		return (Integer)this.queryForObject("countJtsbByFwsbh_xhd",map);
	}
	public List<Map> listJtsbByFwsbh_ydp(Map map) throws SQLException{
		return this.queryForPage("listJtsbByFwsbh_ydp",map);
	}
	public List<Map> listJtsbByFwsbh_dc(Map map) throws SQLException{
		return this.queryForPage("listJtsbByFwsbh_dc",map);
	}

	public List<Map> listJtsbByFwsbh_wb(Map map) throws SQLException{
		return this.queryForPage("listJtsbByFwsbh_wb",map);
	}
	public List<Map> listJtsbByFwsbh_ld(Map map) throws SQLException{
		return this.queryForPage("listJtsbByFwsbh_ld",map);
	}
	public Integer countJtsbByFwsbh_ydp(Map map) throws SQLException{
		return (Integer)this.queryForObject("countJtsbByFwsbh_ydp",map);
	}
	public Integer countJtsbByFwsbh_dc(Map map) throws SQLException{
		return (Integer)this.queryForObject("countJtsbByFwsbh_dc",map);
	}
	public Integer countJtsbByFwsbh_wb(Map map) throws SQLException{
		return (Integer)this.queryForObject("countJtsbByFwsbh_wb",map);
	}
	public Integer countJtsbByFwsbh_ld(Map map) throws SQLException{
		return (Integer)this.queryForObject("countJtsbByFwsbh_ld",map);
	}
	//交通设备 - end
	
}
