package cn.com.usky.iot.alarm.dao;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import cn.com.usky.utils.DaoQuery;

public class YtiotVAlarmDaoImpl extends HibernateDaoSupport implements YtiotVAlarmDao {

	private DaoQuery daoQuery;

	public DaoQuery getDaoQuery() {
		return daoQuery;
	}

	public void setDaoQuery(DaoQuery daoQuery) {
		this.daoQuery = daoQuery;
	}

	public String tbname(String name) {
		if (name.equals("ytiot_v_hj"))
			return "YtiotVHj";
		if (name.equals("ytiot_v_sj"))
			return "YtiotVSj";
		if (name.equals("ytiot_v_rtu"))
			return "YtiotVRtu";
		if (name.equals("ytiot_v_video2017"))
			return "YtiotVideoAlarm";
		if(name.equals("ytiot_v_sync"))
			return"YtiotVSync";
		if(name.equals("ytiot_v_syncdata"))
			return"YtiotVSyncData";
		if(name.equals("ytiot_v_lift"))
			return"YtiotVLift";
		if(name.equals("ytiot_v_video2017s"))
			return"YtiotVideoOffline";
		if(name.equals("wj_power_monitoring_alarm"))
			return"WjPowerMonitoringAlarm";
		if(name.equals("wj_power_monitoring_site"))
			return"WjPowerMonitoringSite";
		if(name.equals("wj_power_monitoring_analog"))
			return"WjPowerMonitoringAnalog";
		if(name.equals("wj_power_monitoring_device"))
			return"WjPowerMonitoringDevice";
		return name;
	}

	@Override
	public int getCount(String tablename, String sqlwhere) {
		// TODO Auto-generated method stub
		return daoQuery.getCount(tbname(tablename), sqlwhere);
	}

	@Override
	public List query(String tablename, String sqlwhere, String order, String dir, String start, String limit) {
		// TODO Auto-generated method stub
		return daoQuery.query(tbname(tablename), sqlwhere, order, dir, start, limit);
	}

	@Override
	public int getHJCount(String sqlwhere) {
		// TODO Auto-generated method stub
		return getCount("ytiot_v_hj", sqlwhere);
	}

	@Override
	public int getEFCount(String sqlwhere) {
		// TODO Auto-generated method stub
		return getCount("ytiot_v_efire", sqlwhere);
	}

	@Override
	public int getEFireCount(String sqlwhere) {
		return daoQuery.getCount("YtiotVEfire", sqlwhere);
	}

	@Override
	public List HJQuery(String sqlwhere, String order, String dir, String start, String limit) {
		// TODO Auto-generated method stub
		return query("ytiot_v_hj", sqlwhere, order, dir, start, limit);
	}

	@Override
	public List HJ2Query(String sqlwhere, String order, String dir, String start, String limit) {
		// TODO Auto-generated method stub
		return query("ytiot_v_hj2", sqlwhere, order, dir, start, limit);
	}
	
	@Override
	public int getSJCount(String sqlwhere) {
		// TODO Auto-generated method stub
		return getCount("ytiot_v_sj", sqlwhere);
	}

	@Override
	public List SJQuery(String sqlwhere, String order, String dir, String start, String limit) {
		// TODO Auto-generated method stub
		return query("ytiot_v_sj", sqlwhere, order, dir, start, limit);
	}

	@Override
	public int getRTUCount(String sqlwhere) {
		// TODO Auto-generated method stub
		return getCount("ytiot_v_rtu", sqlwhere);
	}

	@Override
	public List RTUQuery(String sqlwhere, String order, String dir, String start, String limit) {
		// TODO Auto-generated method stub
		return query("ytiot_v_rtu", sqlwhere, order, dir, start, limit);
	}
	@Override
	public List VideoAlarmQuery(String sqlwhere, String order, String dir, String start, String limit) {
		// TODO Auto-generated method stub
		return query("ytiot_v_video2017", sqlwhere, order, dir, start, limit);
	}

	@Override
	public int getLiftCount(String sqlwhere) {
		// TODO Auto-generated method stub
		return getCount("ytiot_v_lift", sqlwhere);
	}

	@Override
	public List LiftQuery(String sqlwhere, String order, String dir, String start, String limit) {
		// TODO Auto-generated method stub
		return query("ytiot_v_lift", sqlwhere, order, dir, start, limit);
	}
	
	@Override
	public List EFireQuery(String sqlwhere, String order, String dir, String start, String limit) {
		// TODO Auto-generated method stub
		return query("YtiotVEfire", sqlwhere, order, dir, start, limit);
	}

	@Override
	public int getDeviceCount(String sqlwhere) {
		return getCount("ytiot_v_sync", sqlwhere);
	}

	@Override
	public List DeviceQuery(String sqlwhere, String order, String dir, String start, String limit) {
		return query("YtiotVSync", sqlwhere, order, dir, start, limit);
	}

	@Override
	public List queryBySQL(String sql) {
		// TODO Auto-generated method stub
		System.out.println(sql);
		return daoQuery.queryBySQL(sql);
	}

	@Override
	public void execSQL(String sql) {
		// TODO Auto-generated method stub
//		System.out.println(sql);
		daoQuery.execSQL(sql);
	}
	
	@Override
	public int execSQL1(String sql) {
		// TODO Auto-generated method stub
//		System.out.println(sql);
		return daoQuery.execSQL1(sql);
	}

	/**
	 * 获取数据数量
	 * @param hqlwhere
	 * @return
	 */
	@Override
	public int getVideoCount(String hqlwhere) {
		 return getCount("ytiot_v_video2017s", hqlwhere);
	}

	@Override
	public List<?> videoOfflienQuery(String hqlwhere, String order, String dir, String start, String limit) {
		return query("ytiot_v_video2017s", hqlwhere, order, dir, start, limit);

	}

	/*首页获取各类型设备离线数据*/
	@Override
	public int getHjOfflineCount(String hqlwhere) {
		 return getCount("ytiot_v_userinfocondition", hqlwhere);
	}
	
	/*伍继看板*/
	@Override
	public int getWjAlarmCount(String sqlwhere) {
		// TODO Auto-generated method stub
		return getCount("wj_power_monitoring_alarm", sqlwhere);
	}
	
	@Override
	public List wjAlarmQuery(String sqlwhere, String order, String dir, String start, String limit) {
		// TODO Auto-generated method stub
		return query("wj_power_monitoring_alarm", sqlwhere, order, dir, start, limit);
	}
	
	@Override
	public int getWjDeviceCount(String sqlwhere) {
		// TODO Auto-generated method stub
		return getCount("wj_power_monitoring_device", sqlwhere);
	}
	
	@Override
	public List wjDeviceQuery(String sqlwhere, String order, String dir, String start, String limit) {
		// TODO Auto-generated method stub
		return query("wj_power_monitoring_device", sqlwhere, order, dir, start, limit);
	}
	
	@Override
	public int getWjAnalogCount(String sqlwhere) {
		// TODO Auto-generated method stub
		return getCount("wj_power_monitoring_analog", sqlwhere);
	}
	
	@Override
	public List wjAnalogQuery(String sqlwhere, String order, String dir, String start, String limit) {
		// TODO Auto-generated method stub
		return query("wj_power_monitoring_analog", sqlwhere, order, dir, start, limit);
	}

}
