package cn.im.trafficalarm.dao;

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.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Repository;
import com.ibatis.sqlmap.client.SqlMapClient;

import cn.im.trafficalarm.model.TrafficaccidentinfoBean;


@Repository("trafficaccidentinfoDao")
public class TrafficaccidentinfoDao  extends SqlMapClientDaoSupport{

	@Autowired 
    private SqlMapClient sqlMapClient;  
      
	@PostConstruct          
    public  void initSqlMapClient(){  
    	super.setSqlMapClient(sqlMapClient);      
    }
	
	
	/**
	 * 增加记录
	 */
	public void insert_Trafficaccidentinfo(Map map) throws SQLException{
		this.getSqlMapClientTemplate().insert("insert_Trafficaccidentinfo_map",map);
	}
	
	
	public void jkdClick(TrafficaccidentinfoBean tb) throws SQLException{
		this.getSqlMapClientTemplate().insert("insert_Trafficaccidentinfo",tb);
	}
	/**
	 * 增加记录
	 */
	public Map insert_Trafficaccidentinfo(TrafficaccidentinfoBean obj) throws SQLException{
		Map map = new HashMap();
		try{	
			this.getSqlMapClientTemplate().insert("insert_Trafficaccidentinfo",obj);
			map.put("msg", "数据新增成功");
			map.put("success", new Boolean(true));	
		}catch(Exception e){
			
		}
		return map;
	}
	
	
	
	
	/**
	 * 批处理增加记录
	 */
	/*
	public void batch_insert_Trafficaccidentinfo(List batch) throws SQLException{
		this.getSqlMapClientTemplate().insert("batch_insert_Trafficaccidentinfo",batch);
	}
	*/
	 
	/**
	 * 修改记录
	 */
	public Integer update_Trafficaccidentinfo(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().update("update_Trafficaccidentinfo",map);
	}
	public Integer updateTrafficaccidentinfo_planEnd(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().update("updateTrafficaccidentinfo_planEnd",map);
	}
	
	/**
	 * 批量修改首页中pushlet后的数据的状态
	 * @param accidentId  事件主键
	 * @param accidentState 事件状态，变更为：0-已展示未查看
	 */
	public Integer batch_update_TrafficHomePageinfo(String accidentId,String accidentState) throws SQLException{
		//return this.getSqlMapClientTemplate().update("update_Trafficaccidentinfo",map);
		try { 
			this.getSqlMapClient().startTransaction(); 
			this.getSqlMapClient().startBatch();
			String[] p = accidentId.split("\\,");
			if(p.length>0){
				for (int i = 0; i < p.length; i++) {
					if(p[i].length()>0){
						Map m = new HashMap();
						m.put("XGTJaccidentId", p[i]);
						m.put("accidentState", accidentState);
						this.getSqlMapClient().update("update_Trafficaccidentinfo",m);
					}
				}
			}
			this.getSqlMapClient().executeBatch(); 
			this.getSqlMapClient().commitTransaction(); 
			return 1;
			}catch (Exception e) { 
				e.printStackTrace(); 
				return 0;
			} finally { 
					this.getSqlMapClient().endTransaction(); 
			}
	}
	
	/**
	 * 删除记录
	 */
	/*
	public Integer delete_Trafficaccidentinfo(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().delete("delete_Trafficaccidentinfo",map);
	}
	*/
	
	/**
	 * 批处理删除记录
	 */
	
	
	public Integer batch_delete_Trafficaccidentinfo(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().delete("batch_delete_Trafficaccidentinfo",map);
	}
	
	
	/**
	 * 查询总数
	 */
	
	public Integer count_Trafficaccidentinfo(Map map) throws SQLException{
		return (Integer)this.getSqlMapClientTemplate().queryForObject("count_Trafficaccidentinfo",map);
	}
	
	
	/**
	 * 查询列表记录
	 */
	public List<Map> query_Trafficaccidentinfo(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("query_Trafficaccidentinfo",map);
	}
	/**
	 * 首页搜索功能
	 */
	public List<Map> query_TrafficHomePagetinfo(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("query_TrafficHomePagetinfo",map);
	}
	/**
	 * 首页搜索总数
	 */
	public Integer count_TrafficHomePagetinfo(Map map) throws SQLException{
		return (Integer)this.getSqlMapClientTemplate().queryForObject("count_TrafficHomePagetinfo",map);
	}
	
	/**
	 * 首页工作台中处理中和未处理数据量
	 */
	public List<Map> query_TrafficHomePageCount(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("query_TrafficHomePagetCount",map);
	}
	
	/**
	 * 查询交通事件信息显示在首页工作台中
	 */
	public List<Map> query_TrafficaccidentPushlet(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("query_TrafficaccidentPushlet",map);
	}
	
	/**
	 * 查询列表记录
	 */
	/*
	public Map get_Trafficaccidentinfo(Map map) throws SQLException{
		return (Map) this.getSqlMapClientTemplate().queryForObject("query_Trafficaccidentinfo",map);
	}
	*/
	
	
	/**
	 * @param map
	 * @return 查询设备信息 id + 名称   
	 * @throws SQLException
	 */
	public List<Map> get_Cameras(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("get_Cameras",map);
	}
	
	// 查询预案
	public Map get_bjya(Map map) throws SQLException{
		return (Map) this.getSqlMapClientTemplate().queryForObject("get_bjya", map);	
	}
	
	/**
	 * 大屏加载摄像头信息
	 */
	public List<Map> query_listBigscreenInitCamere(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("query_listBigscreenInitCamere",map);
	}
	
	/**
	 * 大屏加载隧道信息
	 */
	public List<Map> query_listBigscreenInitTunnel(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("query_listBigscreenInitTunnel",map);
	}
	
	/**
	 * 大屏加载情报板信息
	 */
	public List<Map> query_listBigscreenInitLedBoard(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("query_listBigscreenInitLedBoard",map);
	}
	
	/**
	 * 大屏加载诱导灯信息
	 */
	public List<Map> query_listBigscreenInitTrafficLight(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("query_listBigscreenInitTrafficLight",map);
	}
	
	/**
	 * 大屏加载交通事件信息信息
	 */
	public List<Map> query_listBigscreenInitAlarm(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("query_listBigscreenInitAlarm",map);
	}
	
	
	// 查询预案
	public Map get_Trafficaccidentinfo(Map map) throws SQLException{
		return (Map) this.getSqlMapClientTemplate().queryForObject("query_Trafficaccidentinfo", map);	
	}
	
	
}
