package com.yihu.hos.monitor.dao;

import com.yihu.hos.system.model.SystemServiceEndpoint;
import com.yihu.hos.system.model.SystemServiceFlow;
import com.yihu.hos.system.model.SystemServiceFlowConfig;
import com.yihu.hos.web.framework.dao.SQLGeneralDAO;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by chenweida on 2016/1/25.
 */
@Repository("ServiceMonitorDao")
public class ServiceMonitorDao extends SQLGeneralDAO {
    public static final String BEAN_ID = "ServiceMonitorDao";

    public List<SystemServiceFlowConfig> getAllFlowEndpoints() throws Exception {
        return (List<SystemServiceFlowConfig>) super.hibernateTemplate.find("from SystemServiceFlowConfig");
    }

    public List<SystemServiceFlow> getAllFlows() throws Exception {
        return (List<SystemServiceFlow>) super.hibernateTemplate.find("from SystemServiceFlow");
    }

    public List<SystemServiceEndpoint> getAllEndpoints() throws Exception {
        return (List<SystemServiceEndpoint>) super.hibernateTemplate.find("from SystemServiceEndpoint");
    }

    public SystemServiceFlow  getFlowById(Integer id) throws Exception {
        return (SystemServiceFlow) super.hibernateTemplate.find("from SystemServiceFlow s where s.id=?", id).get(0);
    }

    public SystemServiceEndpoint getEndpointById(String id) throws Exception {
        return (SystemServiceEndpoint) super.hibernateTemplate.find("from SystemServiceEndpoint s where s.id=?", id).get(0);
    }

    public List<SystemServiceFlow> getFlowsByType(String type) throws Exception {
        return (List<SystemServiceFlow>) super.hibernateTemplate.find("from SystemServiceFlow s where s.fileType=?",type);
    }

}
