package com.cesgroup.cesmonitor.dao;

import java.util.List;

import org.apache.ibatis.annotations.Select;

import com.cesgroup.cesmonitor.bean.AlarmInfo;
import com.cesgroup.framework.base.dao.IBaseDao;

/**
 * 告警列表
 * @author user
 *
 */
public interface AlarmListMapper extends IBaseDao<AlarmInfo> {

    @Select("SELECT  h.hostid hostId, h.`name` hostName,h.host_type hostType ,e.eventid eventid,e.clock startClock,"
        + " e.value status, t.description description, t.priority warningLevel "
        + "FROM `triggers` t, `events` e ,functions f, items i, `hosts` h ,hosts_groups hg , groups g "
        + "WHERE   e.objectid = #{param1}  and e.objectid = t.triggerid and e.source = 0 and e.object = 0 "
        + "and  g.groupid = hg.groupid and h.hostid = hg.hostid "
        + "AND f.triggerid = t.triggerid AND f.itemid = i.itemid and h.hostid =i.hostid "
        + "GROUP BY e.eventid ORDER BY e.clock DESC LIMIT 20")
    public abstract List<AlarmInfo> findAlarmInfo(Integer objectId);

    @Select("SELECT  h.hostid hostId, h.`name` hostName,h.host_type hostType ,e.eventid eventid,e.clock startClock, "
        + "e.value status, t.description description, t.priority warningLevel,e.objectid objectId "
        + "FROM `triggers` t, `events` e ,functions f, items i, `hosts` h ,hosts_groups hg , groups g "
        + "WHERE  ${param1} and ${param2} and ${param3} "
        + "and e.objectid = t.triggerid and e.source = 0 and e.object = 0 "
        + "and  g.groupid = hg.groupid and h.hostid = hg.hostid AND f.triggerid = t.triggerid "
        + "AND f.itemid = i.itemid and h.hostid =i.hostid "
        + "GROUP BY e.eventid ORDER BY e.objectid ,e.clock DESC ")
    public abstract List<AlarmInfo> filterAlarmInfo(String groupId, String hostId, String objectId);

    @Select("SELECT  h.hostid hostId, h.`name` hostName,h.host_type hostType ,e.eventid eventid,e.clock startClock, "
        + "e.value status, t.description description, t.priority warningLevel,e.objectid objectId "
        + "FROM `triggers` t, `events` e ,functions f, items i, `hosts` h ,hosts_groups hg , groups g "
        + "WHERE  e.objectid = t.triggerid and e.source = 0 and e.object = 0 and g.groupid = 9  "
        + "and  g.groupid = hg.groupid and h.hostid = hg.hostid AND f.triggerid = t.triggerid"
        + " AND f.itemid = i.itemid and h.hostid =i.hostid "
        + "GROUP BY e.eventid ORDER BY e.objectid, e.clock DESC ")
    public abstract List<AlarmInfo> findAllAlarmInfo();

}
