/**
 * <p>Copyright:Copyright(c) 2017</p>
 * <p>Company:上海中信信息发展股份有限公司</p>
 * <p>包名:com.cesgroup.cesmonitor.dao</p>
 * <p>文件名:CommonMapper.java</p>
 * <p>创建时间:2017年5月24日 上午9:47:12</p>
 * <p>作者:user</p>
 */

package com.cesgroup.cesmonitor.dao;

import java.util.List;

import org.apache.ibatis.annotations.Select;

import com.cesgroup.framework.base.dao.IBaseDao;
import com.zabbix4j.host.HostObject;
import com.zabbix4j.hostgroup.HostgroupObject;

/**
 * 报表管理通用查询
 *
 * @author sl
 * @version 1.0.0 2017年5月24日
 */
public interface ReportCommonMapper extends IBaseDao<Object> {

    /**
     * 查询出所有的主机组，剔除掉无主机的
     *
     * @return 所有主机组
     */
    @Select("select g.name name from hosts h,groups g, hosts_groups hg "
        + " where h.hostid = hg.hostid and g.groupid = hg.groupid "
        + " and (h.status = 0 or h.status = 1) group by g.groupid")
    public List<HostgroupObject> selectAllHostGroups();

    /**
     * 查询出所有的主机
     *
     * @return 所有的主机
     */
    @Select("select h.host,h.name from hosts h,groups g, hosts_groups hg "
        + " where h.hostid = hg.hostid and g.groupid = hg.groupid "
        + " and (h.status = 0 or h.status = 1) group by h.name")
    public List<HostObject> selectAllHosts();

    /**
     * 获取特定主机组所属的全部主机
     *
     * @param group
     *            主机组名称
     * @return 特点主机组所属的全部主机
     */
    @Select("select h.host,h.name from hosts h,hosts_groups hg,groups g where h.hostid = hg.hostid"
        + " and hg.groupid = g.groupid" + " and g.name = #{0}")
    public List<HostObject> selectHostByHostGroupName(String group);

    @Select("select DISTINCT(g.name) name from hosts h,groups g, hosts_groups hg, "
        + "users u,usrgrp usrg,rights r  ,users_groups ug where h.hostid = hg.hostid and g.groupid = hg.groupid "
        + "and r.id = hg.groupid and r.groupid = ug.usrgrpid and ug.userid = u.userid "
        + "and ug.usrgrpid = usrg.usrgrpid and u.userid =#{param1}")
    public List<HostgroupObject> selectAllHostGroupsByUser(Integer userId);
}
