package cn.im.trafficdevice.dao;

import java.sql.SQLException;
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;

@Repository("trafficdevicerelateDao")
public class TrafficdevicerelateDao  extends SqlMapClientDaoSupport{

	@Autowired 
    private SqlMapClient sqlMapClient;  
      
	@PostConstruct          
    public  void initSqlMapClient(){  
    	super.setSqlMapClient(sqlMapClient);      
    }
	
	
	/**
	 * 增加记录
	 */
	
	public void insert_Trafficdevicerelate(Map map) throws SQLException{
		this.getSqlMapClientTemplate().insert("insert_Trafficdevicerelate",map);
	}
	public List<Map> getTunnelDeviceList() throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("getTunnelDeviceList");
	}
	public List<Map> getTunnelLedDeviceList() throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("getTunnelLedDeviceList");
	}
	public List<Map> getTunnelLightDeviceList() throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("getTunnelLightDeviceList");
	}
	public List<Map> getTunnelAerationDeviceList() throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("getTunnelAerationDeviceList");
	}
	public List<Map> getTunnelLaneindicateDeviceList() throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("getTunnelLaneindicateDeviceList");
	}
	public List<Map> getTunnelBigscreenDeviceList() throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("getTunnelBigscreenDeviceList");
	}
	public List<Map> getTunnelVoicelightDeviceList() throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("getTunnelVoicelightDeviceList");
	}
	public List<Map> getTunnelVoiceDeviceList() throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("getTunnelVoiceDeviceList");
	}
	public List<Map> getTunnelLightcontrolDeviceList() throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("getTunnelLightcontrolDeviceList");
	}
	
	/**
	 * 批处理增加记录
	 */
	
	public void batch_insert_Trafficdevicerelate(List batch) throws SQLException{
		this.getSqlMapClientTemplate().insert("batch_insert_Trafficdevicerelate",batch);
	}
	
	
	public Integer update_TrafficdevicePositionRelate(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().update("update_TrafficdevicePositionRelate",map);
	}
	
	/**
	 * 修改记录
	 */
	public Integer update_Trafficdevicerelate(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().update("update_Trafficdevicerelate",map);
	}
	public Integer updateRemarks(List<Map<String,String>> list) throws SQLException{
//		return this.getSqlMapClientTemplate().update("updateRemarks",map);
		try { 
			this.getSqlMapClient().startTransaction(); 
			this.getSqlMapClient().startBatch();
			for(Map<String,String> m : list){
				this.getSqlMapClient().update("updateRemarks",m);
			}
			this.getSqlMapClient().executeBatch(); 
			this.getSqlMapClient().commitTransaction(); 
			return 1;
			}catch (Exception e) { 
				e.printStackTrace(); 
				return 0;
			} finally { 
					this.getSqlMapClient().endTransaction(); 
			}
	}
	/**
	 * 删除记录
	 */
	
	public Integer delete_Trafficdevicerelate(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().delete("delete_Trafficdevicerelate",map);
	}
	
	
	/**
	 * 批处理删除记录
	 */
	
	
	public Integer batch_delete_Trafficdevicerelate(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().delete("batch_delete_Trafficdevicerelate",map);
	}
	
	
	/**
	 * 查询总数
	 */
	
	public Integer count_Trafficdevicerelate(Map map) throws SQLException{
		return (Integer)this.getSqlMapClientTemplate().queryForObject("count_Trafficdevicerelate",map);
	}
	
	
	/**
	 * 查询列表记录
	 */
	
	
	public List<Map> query_Trafficdevicerelate(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("query_Trafficdevicerelate",map);
	}
	
	/**
	 * 查询预案播放设备
	 * @param map
	 * @return
	 * @throws SQLException
	 */
	public List<Map> getPlanVideoInfo(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("getPlanVideoInfo",map);
	}
	
	/**
	 * 根据roadIds查询路段报警源
	 * @param map
	 * @return
	 * @throws SQLException
	 */
	public List<Map> getRoadAlarmSourceByRoadIds(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("getRoadAlarmSourceByRoadIds",map);
	}
	public List<Map> getRoadDeviceByRoadIds(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("getRoadDeviceByRoadIds",map);
	}
	
	/**
	 * 根据roadIds查询路段监控排序信息
	 * @param map
	 * @return
	 * @throws SQLException
	 */
	public List<Map> query_VideoOrderByRoadId(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("query_VideoOrderByRoadId",map);
	}
	
	/**
	 * 查询总数根据roadId
	 */
	
	public Integer count_RoadAlarmSourceByRoadIds(Map map) throws SQLException{
		return (Integer)this.getSqlMapClientTemplate().queryForObject("count_RoadAlarmSourceByRoadIds",map);
	}
	public Integer count_getRoadDeviceByRoadIds(Map map) throws SQLException{
		return (Integer)this.getSqlMapClientTemplate().queryForObject("count_getRoadDeviceByRoadIds",map);
	}
	
	/**
	 * 查询列表记录
	 */
	/*
	public Map get_Trafficdevicerelate(Map map) throws SQLException{
		return (Map) this.getSqlMapClientTemplate().queryForObject("query_Trafficdevicerelate",map);
	}
	*/
	//查询摄像头并分页
		public List<Map> getVideoListPage(Map map) throws SQLException{
			return this.getSqlMapClientTemplate().queryForList("getVideoListPage",map);
		}
		public Integer getVideoListPageCount(Map map) throws SQLException{
			return (Integer) this.getSqlMapClientTemplate().queryForObject("getVideoListPageCount",map);
		}
		
		//查询情报板并分页
		public List<Map> getLedListPage(Map map) throws SQLException{
			return this.getSqlMapClientTemplate().queryForList("getLedListPage",map);
		}
		public Integer getLedListPageCount(Map map) throws SQLException{
			return (Integer) this.getSqlMapClientTemplate().queryForObject("getLedListPageCount",map);
		}
		
		//查询诱导灯并分页
		public List<Map> getLightListPage(Map map) throws SQLException{
			return this.getSqlMapClientTemplate().queryForList("getLightListPage",map);
		}
		public Integer getLightListPageCount(Map map) throws SQLException{
			return (Integer) this.getSqlMapClientTemplate().queryForObject("getLightListPageCount",map);
		}
		
		//	查询平台行政树信息
		public List<Map> getPtxzsPage(Map map) throws SQLException{
			return this.getSqlMapClientTemplate().queryForList("getPtxzsPage",map);
		}
		public Integer getPtxzsPageCount(Map map) throws SQLException{
			return (Integer) this.getSqlMapClientTemplate().queryForObject("getPtxzsPageCount",map);
		}
		
		// 设备关联页面  全部
		public List getDeviceRelatePage(Map map) throws SQLException{
			return this.getSqlMapClientTemplate().queryForList("getDeviceRelatePage",map);			
		}
		public Integer getDeviceRelatePageCount(Map map) throws SQLException{
			return (Integer) this.getSqlMapClientTemplate().queryForObject("getDeviceRelatePageCount",map);			
		}
		
 /*============== 路段管理页面    增加信息 左侧   /start  =================*/  
		    // 1.摄像头查询
		public List getRoadVideo(Map map) throws SQLException{
			return this.getSqlMapClientTemplate().queryForList("getRoadVideo", map);
		}
		public Integer getRoadVideoCount(Map map) throws SQLException{
			return (Integer) this.getSqlMapClientTemplate().queryForObject("getRoadVideoCount", map);
		}
			// 2.隧道查询
		public List getRoadTunnel(Map map) throws SQLException{
			return this.getSqlMapClientTemplate().queryForList("getRoadTunnel", map);
		}
		public Integer getRoadTunnelCount(Map map) throws SQLException{
			return (Integer) this.getSqlMapClientTemplate().queryForObject("getRoadTunnelCount", map);
		}
			// 3.情报板查询
		public List getRoadLed(Map map) throws SQLException{
			return this.getSqlMapClientTemplate().queryForList("getRoadLed", map);
		}
		public Integer getRoadLedCount(Map map) throws SQLException{
			return (Integer) this.getSqlMapClientTemplate().queryForObject("getRoadLedCount", map);
		}
		//  4. 查询交通信号灯
		public List getRoadLight(Map map) throws SQLException{
			return this.getSqlMapClientTemplate().queryForList("getRoadLight", map);
		}
		public Integer getRoadLightCount(Map map) throws SQLException{
			return (Integer) this.getSqlMapClientTemplate().queryForObject("getRoadLightCount", map);
		}
		//	 5. 查询车道指示器
		public List getRoadLane(Map map) throws SQLException{
			return this.getSqlMapClientTemplate().queryForList("getRoadLane", map);
		}
		public Integer getRoadLaneCount(Map map) throws SQLException{
			return (Integer) this.getSqlMapClientTemplate().queryForObject("getRoadLaneCount", map);
		}
		//	 6. 查询通风控制
		public List getRoadArea(Map map) throws SQLException{
			return this.getSqlMapClientTemplate().queryForList("getRoadArea", map);
		}
		public Integer getRoadAreaCount(Map map) throws SQLException{
			return (Integer) this.getSqlMapClientTemplate().queryForObject("getRoadAreaCount", map);
		}
		//	 7. 查询声光报警 
		public List getRoadVoiLig(Map map) throws SQLException{
			return this.getSqlMapClientTemplate().queryForList("getRoadVoiLig", map);
		}
		public Integer getRoadVoiLigCount(Map map) throws SQLException{
			return (Integer) this.getSqlMapClientTemplate().queryForObject("getRoadVoiLigCount", map);
		}
		//	 8. 查询语音播报
		public List getRoadVoice(Map map) throws SQLException{
			return this.getSqlMapClientTemplate().queryForList("getRoadVoice", map);
		}
		public Integer getRoadVoiceCount(Map map) throws SQLException{
			return (Integer) this.getSqlMapClientTemplate().queryForObject("getRoadVoiceCount", map);
		}
		//	 9. 查询照明控制
		public List getRoadLigCon(Map map) throws SQLException{
			return this.getSqlMapClientTemplate().queryForList("getRoadLigCon", map);
		}
		public Integer getRoadLigConCount(Map map) throws SQLException{
			return (Integer) this.getSqlMapClientTemplate().queryForObject("getRoadLigConCount", map);
		}
		//	10. 查询大屏设备
		public List getBigScreen(Map map) throws SQLException{
			return this.getSqlMapClientTemplate().queryForList("getBigScreen", map);
		}
		public Integer getgetBigScreenCount(Map map) throws SQLException{
			return (Integer) this.getSqlMapClientTemplate().queryForObject("getgetBigScreenCount", map);
		}
/*============== 路段管理页面    增加信息 左侧   /end  =================*/  	
		
		
		
		
//	==========================	查询路段与设备关联信息	start
	// 1. 路段关联交通信号灯
	public List get_roadLight(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("get_roadLight", map);
	}
	public Integer get_roadLightCount(Map map) throws SQLException{
		return (Integer) this.getSqlMapClientTemplate().queryForObject("get_roadLightCount", map);
	}
	
	// 2. 路段关联声光报警设备
	public List get_roadVoicelight(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("get_roadVoicelight", map);
	}
	public Integer get_roadVoicelightCount(Map map) throws SQLException{
		return (Integer) this.getSqlMapClientTemplate().queryForObject("get_roadVoicelightCount", map);
	}	
	
	// 3. 路段关联情报板设备
	public List get_roadLed(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("get_roadLed", map);
	}
	public Integer get_roadLedCount(Map map) throws SQLException{
		return (Integer) this.getSqlMapClientTemplate().queryForObject("get_roadLedCount", map);
	}
	
	// 4. 路段关联照明控制设备
	public List get_roadLightcontrol(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("get_roadLightcontrol", map);
	}
	public Integer get_roadLightcontrolCount(Map map) throws SQLException{
		return (Integer) this.getSqlMapClientTemplate().queryForObject("get_roadLightcontrolCount", map);
	}
	
	// 5. 路段关联外挂语音播报设备
	public List get_roadVoice(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("get_roadVoice", map);
	}
	public Integer get_roadVoiceCount(Map map) throws SQLException{
		return (Integer) this.getSqlMapClientTemplate().queryForObject("get_roadVoiceCount", map);
	}

	// 6. 路段关联车道指示器设备
	public List get_roadlaneind(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("get_roadlaneind", map);
	}
	public Integer get_roadlaneindCount(Map map) throws SQLException{
		return (Integer) this.getSqlMapClientTemplate().queryForObject("get_roadlaneindCount", map);
	}
	
	// 7. 路段关联通风控制设备
	public List get_roadArea(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("get_roadArea", map);
	}
	public Integer get_roadAreaCount(Map map) throws SQLException{
		return (Integer) this.getSqlMapClientTemplate().queryForObject("get_roadAreaCount", map);
	}
	
	// 8. 路段关联监控设备
	public List get_roadVideo(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("get_roadVideo", map);
	}
	public Integer get_roadVideoCount(Map map) throws SQLException{
		return (Integer) this.getSqlMapClientTemplate().queryForObject("get_roadVideoCount", map);
	}
	
	
	// 修改后统一调用此方法
	public List get_roadRelate(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().queryForList("get_roadRelate", map);		
	}
	public Integer get_roadRelateCount(Map map) throws SQLException{
		return (Integer) this.getSqlMapClientTemplate().queryForObject("get_roadRelateCount",map);
	}
//	==========================	查询路段与设备关联信息	end
	
	// 更新 设备点位为null
	public Integer update_TrafficdevicePositionNull(Map map) throws SQLException{
		return this.getSqlMapClientTemplate().update("update_TrafficdevicePositionNull",map);
	}
}
