package com.cesgroup.cesmonitor.dao;

import java.util.List;

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

import com.cesgroup.cesmonitor.bean.Cpu;
import com.cesgroup.cesmonitor.bean.Disk;
import com.cesgroup.cesmonitor.bean.DiskUsageInfo;
import com.cesgroup.cesmonitor.bean.HostByGroup;
import com.cesgroup.cesmonitor.bean.Memory;
import com.cesgroup.cesmonitor.bean.OneHostConfig;
import com.cesgroup.cesmonitor.bean.PriorityCount;
import com.cesgroup.cesmonitor.bean.PriorityDetail;
import com.cesgroup.cesmonitor.bean.ResponseTime;
import com.cesgroup.framework.base.dao.IBaseDao;

/**
 * 这个对应的是图表总览页面的数据展示的DAO 主要包括的是8张表格的展示 这个对应的是图表总览页面的数据展示的DAO 主要包括的是8张表格的展示
 **/
public interface FormViewMapper extends IBaseDao<Object> {

    /**
     * 表的信息类型是：浮点数
     *
     * @param itemName
     *            监控项
     * @param time
     *            时间，单位为秒
     * @return 所有主机CPU的TOPN排行
     *
     */

    @Select("select a.name host_name,a.hostid host_id,a.value cpu_rate " + "from ("
        + "select DISTINCT(h.name),h.hostid,h.host,hi.value from items i,hosts h,history hi "
        + "where i.name=#{param1} "
        + "and i.hostid=h.hostid AND (h.available=1 or h.snmp_available=1) " + "and i.itemid=hi.itemid "
        + "and hi.clock>=#{param2} and h.`status`=0 " + "order by hi.clock desc)" + " as a "
        + "group by a.host ORDER BY a.`value` ${param3} limit #{param4}")
    List<Cpu> findComputerConfigMessageforCpu(String itemName, Long time, String order, Integer num);

    /**
     * 表的信息类型是：浮点数
     *
     * @param itemName
     *            监控项
     * @param time
     *            时间，单位为秒
     * @return 所有主机磁盘利用率的TOPN排行
     */
    @Select("select a.name host_name,a.hostid host_id,a.value disk_rate,a.itemName,a.itemKey " + "from ("
        + "select DISTINCT(h.name),h.hostid,h.host,hi.value,i.name itemName,i.key_ itemKey from items i,"
        + "hosts h,history hi "
        + "where i.name like #{param1} and i.hostid=h.hostid AND (h.available=1 or h.snmp_available=1) "
        + "and h.`status`=0 " + "and i.itemid=hi.itemid and hi.clock>=#{param2} " + "order by hi.clock desc) as a "
        + "group by a.host,a.itemKey ORDER BY a.`value` ${param3} limit #{param4}")
    List<Disk> findComputerConfigMessageforDisk(String itemName, Long time, String order, Integer num);

    /**
     * 表的信息类型是：浮点数
     *
     * @param itemName
     *            监控项
     * @param time
     *            时间，单位为秒
     * @return 所有主机响应时间的TOPN排行
     */
    @Select("select a.name host_name,a.hostid host_id,a.value response_time from "
        + "(select DISTINCT(h.name),h.hostid,h.host,hi.value from items i,hosts h,history hi "
        + "where i.name=#{param1} and i.hostid=h.hostid "
        + "and i.itemid=hi.itemid and hi.clock>=#{param2} and h.`status`=0 "
        + "order by hi.clock desc) as a group by a.host order by a.value ${param3} limit #{param4}")
    List<ResponseTime> findComputerConfigMessageforResponseTime(String itemName, Long time, String order, Integer num);

    @Select("select a.name host_name,a.hostid host_id,a.value memory_rate from ("
        + "select DISTINCT(h.name),h.hostid,h.host,hi.value from items i,hosts h,history hi "
        + "where i.name=#{param1} "
        + "and i.hostid=h.hostid AND (h.available=1 or h.snmp_available=1) " + "and i.itemid=hi.itemid "
        + "and hi.clock>=#{param2} and h.`status`=0 " + "order by hi.clock desc)" + " as a "
        + "group by a.host ORDER BY a.`value` ${param3} limit #{param4}")
    List<Memory> findComputerConfigMessageforMemoryRate(String itemName, Long time, String order, Integer num);

    /**
     * 这个查询是因为这个历史记录表的信息类型是数字（无符号），表是history_uint
     *
     * @param itemName
     *            监控项
     * @param time
     *            时间，单位为秒
     * @return 所有主机针对内存(可用内存)
     */
    @Select("select a.hostid host_id,a.name host_name,a.value free_memory from ("
        + "select DISTINCT(h.name),h.host,h.hostid,hi.value from items i,hosts h,history_uint hi "
        + "where i.name=#{param1} and i.hostid=h.hostid AND (h.available=1 or h.snmp_available=1) "
        + "and i.itemid=hi.itemid and h.`status`=0 and hi.clock>=#{param2} " + "order by hi.clock desc) as a "
        + "group by a.host ORDER BY a.`value` ${param3} limit #{param4}")
    List<Memory> findComputerConfigMessageforFreeMemory(String itemName, Long time, String order, Integer num);

    /**
     * 这个查询是因为这个历史记录表的信息类型是数字（无符号），表是history_uint
     *
     * @param itemName
     *            监控项
     * @param hostId
     *            主机ID
     * @return 根据可用内存查出来的主机内存(总内存)
     */
    @Select("select h.hostid host_id,hi.value total_memory from items i,hosts h,history_uint hi "
        + "where i.name=#{param1} and h.hostid=#{param2} "
        + "AND (h.available=1 or h.snmp_available=1) AND hi.clock >=#{param3} "
        + "and i.hostid=h.hostid and i.itemid=hi.itemid ORDER BY hi.clock DESC LIMIT 1")
    List<Memory> findComputerConfigMessageforTotalMemory(String itemName, Long hostId, Long time);

    /**
     *
     * @param hostId
     *            主机ID
     * @param itemName
     *            监控项
     * @return 具体哪一台主机接口总数
     */
    @Select("SELECT hi.VALUE totalInterFace FROM items i,`hosts` h,history hi "
        + "WHERE h.hostid =#{param1} AND i. NAME =#{param2} "
        + "AND h.`status` = 0 AND h.hostid = i.hostid AND i.itemid = hi.itemid "
        + "AND hi.clock >=#{param3} ORDER BY hi.clock DESC LIMIT 1")
    List<OneHostConfig> findTotalInterface(Long hostId, String itemName, Long time);

    /**
     *
     * @param itemName
     *            监控项
     * @param hostId
     *            主机ID
     * @param time
     *            时间，单位为秒
     * @return 返回具体哪一台主机的cpu
     */
    @Select("select hi.value cpu_rate from items i,hosts h,history hi "
        + "where i.name=#{param1} and h.hostid=#{param2} " + "and h.hostid=i.hostid and i.itemid=hi.itemid "
        + "and i.state=0 and h.status=0 AND (h.available=1 or h.snmp_available=1) "
        + "and hi.clock>=#{param3} ORDER BY hi.clock DESC limit 1")
    List<OneHostConfig> findComputerConfigforCpuByHostId(String itemName, Long hostId, Long time);

    /**
     *
     * @param itemName
     *            监控项
     * @param hostId
     *            主机ID
     * @param time
     *            时间，单位为秒
     * @return 返回具体哪一台主机的disk
     */
    @Select("SELECT hi.VALUE disk_rate FROM items i,`hosts` h,history hi "
        + "WHERE i.key_ like #{param1} AND h.hostid =#{param2} AND h.hostid = i.hostid "
        + "and i.state=0 and h.status=0 AND (h.available=1 or h.snmp_available=1) "
        + "AND i.itemid = hi.itemid AND hi.clock >=#{param3} ORDER BY hi.clock DESC LIMIT 1")
    List<OneHostConfig> findComputerConfigforDiskByHostId(String itemName, Long hostId, Long time);

    /**
     * 这个查询是因为这个历史记录表的信息类型是数字（无符号），表是history_uint
     *
     * @param itemName
     *            监控项
     * @param hostId
     *            主机ID
     * @return 返回具体哪一台主机的配置信息（总内存）
     */
    @Select("select hi.value total_memory from items i,hosts h,history_uint hi "
        + "where i.name=#{param1} and h.hostid=#{param2} and i.state=0 and h.status=0 "
        + "AND (h.available=1 or h.snmp_available=1) AND hi.clock >=#{param3} "
        + "and h.hostid=i.hostid and i.itemid=hi.itemid ORDER BY hi.clock DESC LIMIT 1")
    List<OneHostConfig> findComputerConfigforTotalMemoryByHostId(String itemName, Long hostId, Long time);

    /**
     * 这个查询是因为这个历史记录表的信息类型是数字（无符号），表是history_uint
     *
     * @param itemName
     *            监控项
     * @param hostId
     *            主机ID
     * @param time
     *            时间，单位为秒
     * @return 返回具体哪一台主机的配置信息（可用内存）
     */
    @Select("SELECT hi.VALUE free_memory " + "FROM items i,`hosts` h,history_uint hi "
        + "WHERE i. NAME =#{param1} AND h.hostid =#{param2} " + "AND hi.clock >=#{param3} AND h.hostid = i.hostid "
        + "and i.state=0 and h.status=0 and (h.available=1 or h.snmp_available=1) "
        + "AND i.itemid = hi.itemid ORDER BY hi.clock DESC LIMIT 1")
    List<OneHostConfig> findComputerConfigforFreeMemoryByHostId(String itemName, Long hostId, Long time);

    /**
     *
     * @param itemName
     *          名称
     * @param hostId
     *          主机id
     * @param time
     *          时间
     * @return 返回当前关注中的内存率数据
     */
    @Select("select hi.value memoryRate from items i,hosts h,history hi where i.name=#{param1} "
        + "and h.hostid=#{param2} and h.hostid=i.hostid and h.status = 0 and i.itemid=hi.itemid and hi.clock>=#{param3}"
        + " ORDER BY hi.clock DESC LIMIT 1")
    Double findMemoryRateByHostId(String itemName, String hostId, Long time);

    /**
     *
     * @param itemName
     *          主机名
     * @param hostId
     *          主机id
     * @param time
     *          时间
     * @return 返回当前关注中的内存率数据
     */
    @Select("select hi.value memoryRate from items i,hosts h,history hi where i.name=#{param1} "
        + "and h.hostid=#{param2} and h.hostid=i.hostid and h.status = 0 and i.itemid=hi.itemid and hi.clock>=#{param3}"
        + " ORDER BY hi.clock DESC LIMIT 1")
    Double findMemoryRateByHostIds(String itemName, String hostId, Long time);

    /**
     *
     * @param itemName
     *            空闲率%
     * @param hostId
     *
     * @param time
     *
     * @return 返回磁盘空闲率
     */
    @Select("SELECT a.key_ drive_letter,a.value free_rate from(select i.key_,h.value from `hosts` ho,items i,history h "
        + "WHERE i.name LIKE #{param1} AND h.clock>=#{param3} AND ho.hostid =#{param2} AND ho.hostid=i.hostid and "
        + "i.itemid = h.itemid and ho.`status`=0 and i.`status`=0 ORDER BY h.clock DESC)as a GROUP BY a.key_")
    List<DiskUsageInfo> findFreeRateByHostId(String itemName, String hostId, Long time);

    /**
     *
     * @param hostId
     *            主机ID
     * @return 返回主机的名称及协议可用性
     */
    @Select("select h.name,h.available,h.jmx_available,h.snmp_available,h.ipmi_available "
        + "FROM hosts h where h.hostid=#{param1}")
    List<OneHostConfig> findAvailableByHostId(Long hostId);

    /**
     *
     * @param hostId
     *            主机ID
     * @return 返回具体主机的最高异常
     */
    @Select("SELECT max(t.priority) maxPriority " + "from `hosts` h,items i,functions f,`triggers` t "
        + "where h.hostid=#{param1} and h.hostid=i.hostid and i.itemid=f.itemid "
        + "and f.triggerid=t.triggerid  and t.`value`=1")
    List<OneHostConfig> findMaxPriorityByHostId(Long hostId);

    /**
     * @param hostId
     *            主机ID
     * @return 返回具体主机的异常总数
     */
    @Select("select COUNT(*) totalException from " + "(SELECT COUNT(*) from hosts h,items i,functions f,triggers t "
        + "where h.hostid=#{param1} and i.hostid=h.hostid and i.itemid=f.itemid "
        + "and f.triggerid=t.triggerid and t.`value`=1 GROUP BY t.description ) a")
    List<OneHostConfig> findTotalExceptionByHostId(Long hostId);

    /**
     * @return 按异常等级进行分组，统计每组的数量
     */
    @Select("SELECT a.`name`,a.priority,COUNT(*) count_num "
        + "FROM (SELECT t.priority,g.`name`,t.description,h.`host` "
        + "from `triggers` t,`hosts` h,items i,functions f,hosts_groups hg,groups g "
        + "WHERE ${name} and t.triggerid=f.triggerid and t.`status`=0 and h.`status`=0 "
        + "and t.value=1 AND f.itemid=i.itemid AND h.hostid=i.hostid "
        + "and h.hostid=hg.hostid and hg.groupid=g.groupid GROUP BY t.description,h.`host`,t.priority)"
        + " a GROUP BY a.priority")
    List<PriorityCount> findCountByPriority(@Param("name") String name);

    /**
     *
     * @param priority
     *            异常等级
     * @return 根据异常等级查出来的前20条信息
     */
    @Select("SELECT h.name, t.description, e.objectid,h.host "
        + "FROM `triggers` t,`events` e, functions f,items i,`hosts` h,groups g, hosts_groups hg "
        + "WHERE  t.priority =#{param1} AND ${name} AND e.object = 0 " + "and e.source= 0 AND e.objectid = t.triggerid "
        + "AND f.triggerid = t.triggerid AND f.itemid = i.itemid AND i.hostid = h.hostid "
        + "AND h.hostid=hg.hostid AND g.groupid=hg.groupid AND h.`status` = 0 AND t.status = 0 "
        + "AND t.`value` = 1 GROUP BY description,`host` limit 20")
    List<PriorityDetail> findMessageByPriority(Integer priority, @Param("name") String name);

    /**
     *
     * @param objectId
     *            触发器ID
     * @return 事件是否确认
     */
    @Select("SELECT e.acknowledged  from `events` e where  e.objectid=#{param1}  "
        + "and e.object=0  AND e.`value`=1 ORDER BY e.clock desc limit 1")
    List<PriorityDetail> findAcknowledgeByObjectId(Integer objectId);

    /**
     *
     * @param objectid
     *            触发器ID
     *      param time
     *            触发器开始时间
     * @return 找到这个触发器发生的时间
     */
    @Select("select e.clock start_clock " + "from events e,`triggers` t " + "where e.object=0 and e.objectid=#{param1} "
        + "and e.objectid=t.triggerid  and t.value=1 " + "order by e.clock DESC LIMIT 1")
    List<PriorityDetail> findStartClock(Integer objectid);

    /**
     *
     * @param startTime
     *            开始时间（时间戳）
     * @param endTime
     *            结束时间（时间戳）
     * @return 返回每一天的异常数
     */
    @Select("select count(*) count from `events` e where e.clock BETWEEN #{param1} AND #{param2} "
        + "AND e.object = 0 and e.source = 0 and e.`value` = 1 ")
    int findExceptionNumByDay(Long startTime, Long endTime);

    /**
     *
     * @param groupName
     *            组名
     * @param hostIp
     *            主机
     * @return 根据组的名字查出主机
     */
    @Select("SELECT h.`name` host_name," + "h.hostid ," + "g.`name` group_name  "
        + "from `hosts` h,hosts_groups hg,groups g " + "WHERE g.`name`=#{param1} AND hg.groupid=g.groupid "
        + "AND hg.hostid=h.hostid and h.status=0 " + "AND ${param2}")
    List<HostByGroup> findHostByGroup(String groupName, String hostIp);

    /**
     *
     * @param groupid
     *            组名
     * @param hostIp
     *            主机
     * @return 根据组的名字查出主机
     */
    @Select("SELECT h.`name` host_name," + "h.hostid ," + "g.`name` group_name  "
        + "from `hosts` h,hosts_groups hg,groups g " + "WHERE g.`groupid`=#{param1} AND hg.groupid=g.groupid "
        + "AND hg.hostid=h.hostid and h.status=0 " + "AND ${param2}")
    List<HostByGroup> findHostByGroupId(String groupid, String hostIp);

    /**
     *
     * @param name
     *            组名
     * @return 返回组的ID
     */
    @Select("SELECT groupid from groups WHERE `name`=#{param1}")
    Integer findGroupIdByName(String name);

    /**
     *
     * @param hostid
     *            ID
     * @return 该主机是否存在
     */
    @Select("SELECT count(*) from hosts WHERE hostid=#{param1}")
    Integer findHostIsExist(Integer hostid);

    /**
     *
     * @param hostId
     *            主机的ID号
     * @return 返回主机异常数量
     */
    @Select("SELECT COUNT(*) FROM `triggers` t, `events` e,functions f, items i, `hosts` h "
        + "WHERE e.object = 0 AND h.hostid =#{param1} "
        + "AND h.hostid =i.hostid AND e.source=0 AND e.objectid = t.triggerid "
        + "AND f.triggerid = t.triggerid AND f.itemid = i.itemid AND t.`value` = 1 AND t.status = 0")
    Integer findHostStatus(Integer hostId);

    /**
     *
     * @param alias
     *            用户别名
     * @return 返回用户刷新时间
     */
    @Select("select refresh from users where alias=#{param1}")
    Integer findUserRefreshByAlias(String alias);

    /**
     *
     * @param name
     *            alias
     *            用户name
     * @return 返回用户刷新时间
     */
    @Select("select refresh from users where name=#{param1}")
    Integer findUserRefreshByName(String name);

    /**
     *
     * @param userId
     *            alias
     *            用户name
     * @return 返回用户刷新时间
     */
    @Select("select refresh from users where userid=#{param1}")
    Integer findUserRefreshByUserId(Integer userId);

    @Select("select users_groups.usrgrpid from users_groups where users_groups.userid =#{param1}")
    Integer findUsrgrpIdByUserId(Integer userId);

    @Select("select a.name host_name,a.hostid host_id,a.value cpu_rate from ( "
        + "select DISTINCT(h.name),h.hostid,h.host,hi.value from items i,hosts h,history hi,users "
        + "u,users_groups ug,usrgrp usrg,hosts_groups hg,rights r where i.name=#{param1} and i.hostid=h.hostid "
        + "AND (h.available=1 or h.snmp_available=1) and i.itemid=hi.itemid AND h.hostid=i.hostid "
        + "and h.hostid = hg.hostid and r.id = hg.groupid and r.groupid = ug.usrgrpid and ug.userid = u.userid "
        + "and ug.usrgrpid = usrg.usrgrpid and u.userid =#{param5} and hi.clock>=#{param2} and h.`status`=0 "
        + "group by h.name order by hi.clock desc) as a group by a.host ORDER BY a.`value` ${param3} limit #{param4} ")
    List<Cpu> findComputerConfigMessageforCpuByUser(String itemName, Long time, String order, Integer num,
        Integer userId);

    @Select("select a.name host_name,a.hostid host_id,a.value memory_rate from (select DISTINCT(h.name),"
        + "h.hostid,h.host, "
        + "hi.value from items i,hosts h,history hi,users u,users_groups ug,usrgrp usrg,hosts_groups hg, "
        + "rights r where i.name=#{param1} and i.hostid=h.hostid AND (h.available=1 or h.snmp_available=1) "
        + "and i.itemid=hi.itemid and h.hostid = hg.hostid AND h.hostid = i.hostid and r.id = hg.groupid  "
        + "and r.groupid = ug.usrgrpid and ug.userid = u.userid and ug.usrgrpid = usrg.usrgrpid "
        + "and u.userid =#{param5} and hi.clock>=#{param2} and h.`status`=0 order by hi.clock desc) as a "
        + "group by a.host ORDER BY a.`value` ${param3} limit #{param4} ")
    List<Memory> findComputerConfigMessageforMemoryRateByUser(String useMemoryRate, Long time, String order,
        Integer limit,
        Integer userId);

    @Select("select a.name host_name,a.hostid host_id,a.value disk_rate,a.itemName,a.itemKey from ( "
        + "select DISTINCT(h.name),h.hostid,h.host,hi.value,i.name itemName,i.key_ itemKey from items i, "
        + "hosts h,history hi ,users u,users_groups ug,usrgrp usrg,hosts_groups hg,rights r "
        + "where i.name like #{param1} "
        + "and i.hostid=h.hostid AND (h.available=1 or h.snmp_available=1) and h.`status`=0 and i.itemid=hi.itemid "
        + "and h.hostid = hg.hostid and r.id = hg.groupid AND h.hostid = i.hostid and r.groupid = ug.usrgrpid "
        + "and ug.userid = u.userid and ug.usrgrpid = usrg.usrgrpid and u.userid  =#{param5} and hi.clock>=#{param2} "
        + "order by hi.clock desc) as a group by a.host,a.itemKey ORDER BY a.`value`  ${param3} limit #{param4} ")
    List<Disk> findComputerConfigMessageforDiskByUser(String diskUnusePercent, Long time, String order, Integer limit,
        Integer userId);

    @Select("  select a.name host_name,a.hostid host_id,a.value response_time from "
        + "(select DISTINCT(h.name),h.hostid,h.host,hi.value from items i,hosts h,history hi,users u, "
        + "users_groups ug,usrgrp usrg,hosts_groups hg,rights r where i.name=#{param1} and i.hostid=h.hostid "
        + "and i.itemid=hi.itemid and ug.userid = u.userid and ug.usrgrpid = usrg.usrgrpid "
        + "and h.hostid = hg.hostid and  r.id = hg.groupid AND h.hostid = i.hostid and r.id = hg.groupid "
        + "and r.groupid = ug.usrgrpid and u.userid =#{param5} and hi.clock>=#{param2} and h.`status`=0 "
        + "order by hi.clock desc) as a group by a.host  order by a.`value`  ${param3} limit #{param4} ")
    List<ResponseTime> findComputerConfigMessageforResponseTimeByUser(String icmpResponse, Long time, String order,
        Integer limit, Integer userId);

    /**
     * @return 按异常等级进行分组，统计每组的数量
     */
    @Select("SELECT a.`name`,a.priority,COUNT(*) count_num "
        + "FROM (SELECT t.priority,g.`name`,t.description,h.`host` "
        + "from `triggers` t,`hosts` h,items i,functions f,hosts_groups hg,groups g,users u,"
        + "users_groups ug,usrgrp usrg,rights r "
        + "WHERE 1=1 and t.triggerid=f.triggerid and t.`status`=0 and h.`status`=0 and t.value=1 AND f.itemid=i.itemid "
        + "AND h.hostid=i.hostid and ug.userid = u.userid and ug.usrgrpid = usrg.usrgrpid and h.hostid = hg.hostid "
        + "and h.hostid = hg.hostid and  r.id = hg.groupid and r.groupid = ug.usrgrpid "
        + "and ug.userid =#{param1} and h.hostid=hg.hostid "
        + "and hg.groupid=g.groupid GROUP BY t.description,h.`host`,t.priority) "
        + "a GROUP BY a.priority")
    List<PriorityCount> findCountByPriorityByUser(Integer userId);

    /**
     * @return
     *         返回用户群组
     */
    @Select("select r.id  from users_groups ug,rights r where ug.userid =#{param1} and r.groupid = ug.usrgrpid")
    List<Integer> findgroupIdByUserId(Integer userId);

    /**
     * @return 按异常等级进行分组，统计每组的数量
     */
    @Select("select  count(DISTINCT e.eventid) count from events e, "
        + "triggers t ,functions f ,users_groups ug, items i, hosts h "
        + ",users u, usrgrp usrg, hosts_groups hg, rights r "
        + "where e.clock BETWEEN #{param1} AND #{param2}  AND e.object = 0 and e.source = 0 and e.`value` = 1 "
        + "and t.triggerid = e.objectid and t.triggerid = f.triggerid AND f.itemid=i.itemid AND h.hostid=i.hostid "
        + "and h.hostid = hg.hostid and r.id = hg.groupid and r.groupid = ug.usrgrpid and ug.userid = u.userid "
        + "and ug.usrgrpid = usrg.usrgrpid and u.userid =#{param3} ")
    int findExceptionNumByDayAndUserId(Long startTime, Long endTime, Integer userId);

    @Select("select h.host_type  from hosts h where  h.hostid = #{param1}")
    int findHostType(String hostId);

    @Select("SELECT a.hostid free_rate from( "
        + "select ho.name,i.hostid,i.key_,h.value from `hosts` ho,items i,history h "
        + "WHERE i.name LIKE '空闲率%'  AND h.clock>='1510713401' AND ho.hostid=i.hostid "
        + "and i.itemid = h.itemid and ho.`status`=0 and i.`status`=0 and i.key_ LIKE '%Physical Memory%' "
        + "ORDER BY h.clock DESC)as a GROUP BY a.hostid ")
    List<Long> findAllSnmpFreeRateHost(String diskUnusePercent, long l);

    @Select("SELECT h.name from `hosts` h where h.hostid =#{param1} ")
    String findHostNameByHostId(Long string);

    List<DiskUsageInfo> myfindFreeRateByHostId(String diskUnusePercent, Long long1, long l);

    @Select("SELECT totalException,max(t.priority) maxPriority ,h.name,h.available, "
        + "h.jmx_available,h.snmp_available,h.ipmi_available from  "
        + "(select COUNT(*) totalException from (SELECT COUNT(*) from hosts h,items i,functions f,triggers t "
        + "where h.hostid=#{param1} and i.hostid=h.hostid and i.itemid=f.itemid and f.triggerid=t.triggerid "
        + "and t.`value`=1 GROUP BY t.description ) a) totalException,hosts h,items i,functions f,`triggers` t "
        + "where h.hostid=#{param1} and h.hostid=i.hostid and i.itemid=f.itemid "
        + "and f.triggerid=t.triggerid  and t.`value`=1 ")
    List<OneHostConfig> findOneHostConfigByHostId(Long hostId);

    @Select("select a.memoryRate, b.totalInterFace,c.cpu_rate from (select hi.value memoryRate "
        + "from items i,hosts h,history hi where i.name=#{param2} and h.hostid=#{param1} "
        + "and h.hostid=i.hostid and h.status = 0 and i.itemid=hi.itemid and hi.clock>=#{param5} "
        + "ORDER BY hi.clock DESC LIMIT 1) a,(SELECT hi.VALUE totalInterFace FROM items i,`hosts` h,history hi "
        + "WHERE h.hostid =#{param1} AND i. NAME =#{param3} AND h.`status` = 0 AND h.hostid = i.hostid "
        + "AND i.itemid = hi.itemid AND hi.clock >=#{param5} ORDER BY hi.clock DESC LIMIT 1) b, "
        + "(select hi.value cpu_rate from items i,hosts h,history hi where i.name=#{param4} "
        + "and h.hostid=#{param1} and h.hostid=i.hostid and i.itemid=hi.itemid "
        + "and i.state=0 and h.status=0 AND (h.available=1 or h.snmp_available=1) "
        + "and hi.clock>=#{param5} ORDER BY hi.clock DESC limit 1) c")
    List<com.cesgroup.cesmonitor.bean.OneHostConfig> findOneHostConfigByHostidandTime(Long hostId, String memoryRate,
        String icmpRespose, String cpuRate, long time);

    /**
     *
     * @param diskUnusePercent
     *            itemName
     *            空闲率%
     * @param hostId
     *
     * @param time
     *
     * @return 返回磁盘空闲率
     */
    @Select("SELECT a.key_ drive_letter,a.value free_rate from(select i.key_,h.value from `hosts` ho,items i,history h "
        + "WHERE i.name LIKE #{param1} AND i.key_ LIKE #{param2} AND h.clock>=#{param4} "
        + "AND ho.hostid =#{param3} AND ho.hostid=i.hostid and "
        + "i.itemid = h.itemid and ho.`status`=0 and i.`status`=0 ORDER BY h.clock DESC)as a GROUP BY a.key_")
    List<DiskUsageInfo> findFreeRateByHostIdAndPhysicalMemory(String diskUnusePercent,
        String PhysicalMemory, String string, long l);

}