package com.yihu.hos.standard.dao;

import com.yihu.hos.standard.model.adapter.AdapterMetadataModel;
import com.yihu.hos.standard.model.standard.StdDataSetModel;
import com.yihu.hos.web.framework.dao.SQLGeneralDAO;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * Created by Administrator on 2016/5/4.
 */
@Repository("stdeAdapterMetadataDao")
public class StdAdapterMetadataDao extends SQLGeneralDAO implements IStdAdapterMetadataDao {
    @Override
    public List<AdapterMetadataModel> getAdapterMetadataByMetadateId(String metedataId) throws Exception {
        String hql = " from StdeAdapterMetadata s where 1=1 ";
        if (!StringUtils.isEmpty(metedataId)) {
            hql += " and s.stdMatadataId='" + metedataId+ "'";
        }
        return super.getEntityList(StdDataSetModel.class, hql);
    }

    @Override
    public List<AdapterMetadataModel> getAdapterMetadataByDatasetIdAndStatus(String id, String s) throws Exception {
        String hql = " from StdeAdapterMetadata s where 1=1 ";
        if (!StringUtils.isEmpty(id)) {
            hql += " and s.stdDatasetId='" + id+ "'";
        }
        if (!StringUtils.isEmpty(s)) {
            hql += " and s.status='" + s+ "'";
        }
        return super.getEntityList(StdDataSetModel.class, hql);
    }

    @Override
    public void updateAdapterMetadataStatus(String id, String s) throws Exception {
//        super.getEntity(AdapterMetadataModel.class,id).setStatus(s);

    }

    @Override
    public List<AdapterMetadataModel> getAdapterMetadataByAdaptMetadateId(String AdaptMetadateId) throws Exception {
        String hql = " from StdeAdapterMetadata s where 1=1 ";
        if (!StringUtils.isEmpty(AdaptMetadateId)) {
            hql += " and s.adapterMatadataId='" + AdaptMetadateId+ "'";
        }
        return super.getEntityList(StdDataSetModel.class, hql);
    }

    @Override
    public List<AdapterMetadataModel> getAdapterMetadataByMetadateIdAndStatus(String id, String type) throws Exception {
        String hql = " from StdeAdapterMetadata s where 1=1 ";
        if (!StringUtils.isEmpty(id)) {
            hql += " and s.stdMatadataId='" + id+ "'";
        }
        if (!StringUtils.isEmpty(type)) {
            hql += " and s.status='" + type+ "'";
        }
        return super.getEntityList(StdDataSetModel.class, hql);
    }

    @Override
    public List<AdapterMetadataModel> getAdapterMetadataByAdaptMetadateIdAndStdDataSetId(String AdaptMetadateId, String stdDataSetId) throws Exception {
        String hql = " from StdeAdapterMetadata s where 1=1 ";
        if (!StringUtils.isEmpty(AdaptMetadateId)) {
            hql += " and s.adapterMatadataId='" + AdaptMetadateId+ "'";
        }
        if (!StringUtils.isEmpty(stdDataSetId)) {
            hql += " and s.stdDatasetId='" + stdDataSetId+ "'";
        }
        return super.getEntityList(StdDataSetModel.class, hql);
    }

    @Override
    public List<AdapterMetadataModel> getAdapterMetadataByProjectId(String id) throws Exception {
        String hql = " from StdeAdapterMetadata s where 1=1 and projectId='"+id+"' ";
        return super.getEntityList(StdDataSetModel.class, hql);
    }

    @Override
    public List<AdapterMetadataModel> getAdapterMetadataByDatasetId(String dataSetId) throws Exception {
        String hql = " from StdeAdapterMetadata s where 1=1 and stdDatasetId='"+dataSetId+"' ";
        return super.getEntityList(StdDataSetModel.class, hql);
    }

}
