package com.chenyang.nse.bussiness.dao.table.core.encryption;

import com.chenyang.nse.bussiness.config.HibernateConfig;
import com.chenyang.nse.bussiness.dao.BaseDao;
import com.chenyang.nse.bussiness.entity.orm.table.core.encryption.TCoreJiaMiJieMiJinDu;
import java.util.List;
import org.hibernate.transform.Transformers;
import org.springframework.stereotype.Repository;

@Repository
public class TCoreJiaMiJieMiJinDuDao extends BaseDao<TCoreJiaMiJieMiJinDu, String> {
   public List<TCoreJiaMiJieMiJinDu> queryTCoreJiaMiJieMiJinDu(String dataSystemId, String projectId, String schema, String tableName, String flag) {
      String sql = "select id as id,totalcounts,finishcounts,state,starttime,endtime,projectid,datasystemid,schemahh,tablename,flag from t_core_jiamijiemijindu WHERE datasystemid = '" + dataSystemId + "' and projectid = '" + projectId + "' and schemahh='" + schema + "' and tablename='" + tableName + "' and flag='" + flag + "'";
      if (HibernateConfig.PEIZHIKUDBTYPE.equals("3")) {
         sql = "select id as \"id\",totalcounts as \"totalcounts\",finishcounts as \"finishcounts\",state as \"state\",starttime as \"starttime\",endtime as \"endtime\",projectid as \"projectid\",datasystemid as \"datasystemid\",schemahh as \"schemahh\",tablename as \"tablename\",flag as \"flag\" from t_core_jiamijiemijindu WHERE datasystemid = '" + dataSystemId + "' and projectid = '" + projectId + "' and schemahh='" + schema + "' and tablename='" + tableName + "' and flag='" + flag + "'";
      }

      return this.getSession().createNativeQuery(sql).setResultTransformer(Transformers.aliasToBean(TCoreJiaMiJieMiJinDu.class)).getResultList();
   }

   public List<TCoreJiaMiJieMiJinDu> queryTCoreJiaMiJieMiJinD(String dataSystemId, String projectId, String schema, String tableName) {
      String sql = "SELECT id as id,totalcounts,finishcounts,state,starttime,endtime,projectid,datasystemid,schemahh,tablename,flag FROM T_CORE_JIAMIJIEMIJINDU WHERE datasystemid = '" + dataSystemId + "' and projectid = '" + projectId + "' and schemahh='" + schema + "' and tablename='" + tableName + "'order by starttime desc";
      if (HibernateConfig.PEIZHIKUDBTYPE.equals("3")) {
         sql = "SELECT id as \"id\",totalcounts as  \"totalcounts\",finishcounts as  \"finishcounts\",state as  \"state\",starttime as  \"starttime\",endtime as  \"endtime\",projectid as  \"projectid\",datasystemid as \"datasystemid\",schemahh as \"schemahh\",tablename as \"tablename\",flag as \"flag\" FROM T_CORE_JIAMIJIEMIJINDU WHERE datasystemid = '" + dataSystemId + "' and projectid = '" + projectId + "' and schemahh='" + schema + "' and tablename='" + tableName + "'order by starttime desc";
      }

      return this.getSession().createNativeQuery(sql).setResultTransformer(Transformers.aliasToBean(TCoreJiaMiJieMiJinDu.class)).getResultList();
   }

   public List<TCoreJiaMiJieMiJinDu> queryTCoreJiaMiD(String projectId) {
      String sql = "SELECT id as id,totalcounts,finishcounts,state,starttime,endtime,projectid,dataSystemid,schemahh,tablename,columnname,flag FROM T_CORE_JIAMIJIEMIJINDU WHERE projectid = '" + projectId + "'";
      return this.getSession().createNativeQuery(sql).setResultTransformer(Transformers.aliasToBean(TCoreJiaMiJieMiJinDu.class)).getResultList();
   }
}
