package com.yihu.hos.crawler.dao;

import com.yihu.hos.crawler.model.flow.CrawlerFlowModel;
import com.yihu.hos.web.framework.dao.SQLGeneralDAO;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by HZY on 2016/4/27.
 */
@Repository("CrawlerFlowDao")
public class CrawlerFlowDao extends SQLGeneralDAO {
    public static final String BEAN_ID = "CrawlerFlowDao";

    public List<CrawlerFlowModel> getCrawlerFlowList(Integer versionId) {
        String adapterVersionHql = "FROM CrawlerFlowModel where schemeVersionId= :schemeVersionId";
        Query query = getCurrentSession().createQuery(adapterVersionHql);
        query.setParameter("schemeVersionId", versionId);
        List<CrawlerFlowModel> modelList = query.list();
        return modelList;
    }

    public void deleteCrawlerFlowList(Integer versionId)throws Exception  {
        String sql = "delete from crawler_flow where scheme_version_id='"+versionId+"'";
        super.execute(sql);
    }

    public List<CrawlerFlowModel> getCrawlerFlowList(Integer versionId,List<String> datasetCodes) {
        String adapterVersionHql = "FROM CrawlerFlowModel where schemeVersionId= :schemeVersionId and datasetCode in (:datasetCode) and inputDatasetCode in (:inputDatasetCode)";
        Query query = getCurrentSession().createQuery(adapterVersionHql);
        query.setParameter("schemeVersionId", versionId);
        query.setParameterList("datasetCode", datasetCodes);
        query.setParameterList("inputDatasetCode", datasetCodes);
        List<CrawlerFlowModel> modelList = query.list();
        return modelList;
    }

}
