package com.cesgroup.cesmonitor.dao;

import java.util.List;

import org.apache.ibatis.annotations.Select;

import com.cesgroup.cesmonitor.bean.FastGroup;
import com.cesgroup.cesmonitor.bean.FastGroupGraph;
import com.cesgroup.framework.base.dao.IBaseDao;

/**
 *
 * 上海中信信息发展股份有限公司;
 *
 * @author user
 * @version 1.0.0 2018年1月10日
 */
public interface QuickAccessGraphMapper extends IBaseDao<Object> {

    /**
     *
     * @param userId
     *
     * @return 返回用户所在用户组下的快速访问组
     */
    @Select("select distinct fg.id, fg.name from users u, users_groups ug,usrgrp usrg ,fastgroup_usrgroup fu, "
        + "fast_group fg,fastgroup_graph fgg,rights r   WHERE ug.userid = u.userid and ug.usrgrpid = usrg.usrgrpid "
        + "and fu.usrgroup_id = usrg.usrgrpid and fg.id = fu.fast_group_id and r.groupid = ug.usrgrpid "
        + "and ug.userid = u.userid and ug.usrgrpid = usrg.usrgrpid and u.userid =#{param1} "
        + "and fgg.fast_groupid = fg.id "
        + "and fgg.group_id = r.id and r.groupid = ug.usrgrpid")
    List<FastGroup> findFastGroupByUser(String userId);

    /**
     *
     * @param userId
     *
     * @return 返回用户所在用户组下的快速访问组
     */
    @Select(" select distinct fg.id, fg.name from users u, users_groups ug,usrgrp usrg ,"
        + "fastgroup_usrgroup fu,fast_group fg "
        + " where ug.userid = u.userid and ug.usrgrpid = usrg.usrgrpid " + " and fg.id = fu.fast_group_id ")
    List<FastGroup> superAdminfindFastGroupByUser(String userId);

    /**
     *
     * @param fastGroupId
     *
     * @return 返回指定快速访问组下的主机的图形
     */
    @Select(" select distinct fgg.id,fgg.name,fgg.group_id groupid,fgg.host_id hostid,fgg.graph_id graphid "
        + "from fastgroup_graph fgg, users u,users_groups ug,usrgrp usrg,fastgroup_usrgroup fu,fast_group fg, "
        + "rights r where fgg.fast_groupid =#{param1} and ug.userid = u.userid "
        + "and ug.usrgrpid = usrg.usrgrpid and fu.usrgroup_id = usrg.usrgrpid and fg.id = fu.fast_group_id "
        + "and r.groupid = ug.usrgrpid and ug.userid = u.userid and ug.usrgrpid = usrg.usrgrpid "
        + "and u.userid =#{param2} and fgg.fast_groupid = fg.id and fgg.group_id = r.id and r.groupid = ug.usrgrpid")
    List<FastGroupGraph> getGraphByGroupIdandUser(String fastGroupId, Integer userId);

    /**
     * @param fastGroupId
     *         快速访问群组id
     * @return
     *         图形id
     */
    @Select(" select fg.id,fg.name,fg.group_id groupid,fg.host_id hostid,fg.graph_id graphid "
        + "from fastgroup_graph fg where fg.fast_groupid = #{param1}")
    List<FastGroupGraph> getGraphByGroupId(String fastGroupId);

    /**
     * @return
     *         所有图形
     */
    @Select(" select fg.id,fg.name,fg.group_id groupid,fg.host_id hostid,fg.graph_id graphid from fastgroup_graph fg ")
    List<FastGroupGraph> getAllGraph();

    /**
     * @param userId
     *          用户id
     * @return
     *          用户所有的图形
     */
    @Select("select distinct fgg.id,fgg.name,fgg.group_id groupid,fgg.host_id hostid,fgg.graph_id graphid "
        + "from users u, users_groups ug,usrgrp usrg ,fastgroup_graph fgg, "
        + "rights r WHERE ug.userid = u.userid and ug.usrgrpid = usrg.usrgrpid and ug.userid = u.userid "
        + "and r.groupid = ug.usrgrpid and u.userid =#{param1} and fgg.group_id = r.id ")
    List<FastGroupGraph> getAllGraphByUser(Integer userId);

}
