package com.cesgroup.cesmonitor.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cesgroup.cesmonitor.bean.QuickAccess;
import com.cesgroup.cesmonitor.bean.QuickAccessGraphList;
import com.cesgroup.cesmonitor.service.QuickAccessService;
import com.zabbix4j.graph.GraphObject;
import com.zabbix4j.hostgroup.HostgroupGetResponse;

/**
 * 上海中信信息发展股份有限公司; 创建时间:2018年1月22日;
 *
 * @author luxiao 这里是快速访问的控制层，调用业务层代码，会与前台进行数据的交互，包括返回的JSON，HTML代码;
 */
@Controller
@RequestMapping("/quickaccess")
public class QuickAccessController {

    @Autowired
    private QuickAccessService quickAccessService;

    /**
     *
     * @return 返回主机组和主机
     */
    @RequestMapping(value = "listHostGroupsWithHosts")
    @ResponseBody
    public List<HostgroupGetResponse.Result> listHostGroupsWithHosts() {
        return quickAccessService.listHostGroupsWithHosts();
    }

    /**
     *
     * @return 返回图形列表
     * @throws Exception
     */
    @RequestMapping(value = "findGraphByHostId")
    @ResponseBody
    public List<GraphObject> findGraphByHostId(final Integer hostId) throws Exception {
        return quickAccessService.getGraphByHostId(hostId);
    }

    /**
     *
     * @return 保存快速访问
     */
    @RequestMapping(value = "saveQuickAccess")
    @ResponseBody
    public List<String> saveQuickAccess(final String fastGroupName, final String userId, final String graphName, final int groupId, final int hostId,
        final int graphId) {
        return quickAccessService.saveQuickAccess(fastGroupName, userId, graphName, groupId, hostId, graphId);
    }

    /**
     *
     * @return 保存整个表单并校验
     */
    @RequestMapping(value = "saveQuickGroup")
    @ResponseBody
    public List<String> saveQuickGroup(final String fastGroupName, final String usrGroupId, final String graphName, final int groupId,
        final int hostId, final int graphId) {
        return quickAccessService.saveQuickGroup(fastGroupName, usrGroupId, graphName, groupId, hostId, graphId);

    }

    /**
     *
     * @return 根据当前登录用户返回大列表
     * @throws Exception
     */
    @RequestMapping(value = "findFastGroupGraphByUserId")
    @ResponseBody
    public List<QuickAccessGraphList> findFastGroupGraphByUserId(final String userId) throws Exception {
        return quickAccessService.findFastGroupGraphByUserId(userId);
    }

    /**
     *
     * @return 根据快速访问组返回图形小列表
     */
    @RequestMapping(value = "getGraphsByFastGroupId")
    @ResponseBody
    public List<QuickAccess> getGraphsByFastGroupId(final String FastGroupId) {
        return quickAccessService.getGraphsByFastGroupId(FastGroupId);
    }

    /*
     *
     * @return 返回用户组
     */
    @RequestMapping(value = "findUsrGroup")
    @ResponseBody
    public List<String> getUsrGroup() {
        return quickAccessService.findUsrGroup();
    }

    /**
     *
     * @return 返回主机组
     */
    @RequestMapping(value = "findGroupByUsrgroup")
    @ResponseBody
    public List<String> findGroupByUsrgroup(final String usrgrpid) {
        return quickAccessService.findGroupByUsrgroup(usrgrpid);
    }

    /**
     *
     * @return 返回主机组
     */
    @RequestMapping(value = "findHostByGroupId")
    @ResponseBody
    public List<String> findHostByGroupId(final String usrgrpid, final String groupId) {
        return quickAccessService.findHostByGroupId(usrgrpid, groupId);
    }

    /**
     *
     * @return 返回UsrGrp
     */
    @RequestMapping(value = "findUsrGrpByUserId")
    @ResponseBody
    public List<String> findUsrGrpByUserId(final String userId) {
        return quickAccessService.findUsrGrpByUserId(userId);
    }

    /**
     *
     * @return 返回图形列表
     */
    @RequestMapping(value = "getGraphByHostId2")
    @ResponseBody
    public List<String> getGraphByHostId2(final String usrgrpid, final String groupId, final String hostId) {
        return quickAccessService.getGraphByHostId2(usrgrpid, groupId, hostId);
    }

    /**
     *
     * @return 删除快速访问组
     */
    @RequestMapping(value = "deleteQuickAccess")
    @ResponseBody
    public int deleteQuickAccess(final String fastGroupId) {
        return quickAccessService.deleteQuickAccess(fastGroupId);
    }

    /**
     *
     * @return 删除一条快速访问图形记录
     */
    @RequestMapping(value = "deleteQuickAccessGraph")
    @ResponseBody
    public int deleteQuickAccessGraph(final String fastGroupGraphId) {
        return quickAccessService.deleteQuickAccessGraph(fastGroupGraphId);
    }

    /**
     *
     * @return 更新组名
     */
    @RequestMapping(value = "updateGroup")
    @ResponseBody
    public Integer updateGroup(final String fastGroupName, final String fastGroupId) {
        return quickAccessService.updateGroup(fastGroupId, fastGroupName);

    }

    /**
     *
     * @return 删除一条快速访问图形记录
     */
    @RequestMapping(value = "deleteByFastGroupId")
    @ResponseBody
    public int deleteByFastGroupId(final String fastGroupGraphIds) {
        return quickAccessService.deleteByFastGroupId(fastGroupGraphIds);
    }

    /**
     *
     * @return 新增快速访问图形记录
     */
    @RequestMapping(value = "saveQuickAccessList")
    @ResponseBody
    public int saveQuickAccessList(final String graphArrays) {
        return quickAccessService.saveQuickAccessList(graphArrays);
    }

    /**
     *
     * @return 删除一条快速访问图形记录
     */
    @RequestMapping(value = "deleteQuickAccessGraphList")
    @ResponseBody
    public int deleteQuickAccessGraphList(final String fastGroupGraphIds) {
        return quickAccessService.deleteQuickAccessGraphList(fastGroupGraphIds);
    }

}