/**
 * <p>Copyright:Copyright(c) 2016</p>
 * <p>Company:上海中信信息发展股份有限公司</p>
 * <p>包名:com.cesgroup.framework.mybatis.base.dao</p>
 * <p>文件名:UserMapper.java</p>
 * <p>类更新历史信息</p>
 * @author huz 
 * @date 2016-07-07 14:39
 * @todo 
 */
package com.cesgroup.cesmonitor.dao;

import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;

import com.cesgroup.cesmonitor.entity.Usage;
import com.cesgroup.framework.mybatis.dao.BaseDao;

/**
 * 用户Mapper
 * @author huz
 * @date 2016-07-07
 * 
 */
public interface UsageMapper extends BaseDao<Usage, Long>{
	
	@Select("select max(end_time) from t_project_usage")
	public Date getMaxEndTime();
	
	
	
	@Delete("delete from t_project_usage where start_time=#{startTime}")
	public void deleteByStartTime(String startTime);
	
	@Select("select h.`name` name,t.description description,count(e.`value`) count from hosts h,items i,functions f,triggers  t,events e"
			+ " where h.hostid=i.hostid"
			+ " and i.itemid=f.itemid"
			+ " and f.triggerid=t.triggerid"
			+ " and e.objectid=t.triggerid"
			+ " and e.`value`=1 and e.object=0"
			+ " and e.clock>=#{0} and e.clock<=#{1}"
			+ " group by h.`name`,t.description")
	public List<Usage> listProblums(long startTime,long endTime);
	
}
