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

import com.chenyang.nse.bussiness.dao.BaseDao;
import com.chenyang.nse.bussiness.entity.vo.dataproject.TCoreProjectDatasourceVO;
import java.util.List;
import java.util.Map;
import org.hibernate.transform.Transformers;
import org.springframework.stereotype.Repository;

@Repository
public class TCoreProjectDatasourceVoDao extends BaseDao<TCoreProjectDatasourceVO, String> {
   public List<Map<String, String>> queryDatasourceList(String projectid, String discoverytype, String userid) {
      String sql = "select distinct a.systemsource_id as id,a.project_id,b.dbtype,b.pagecode,b.dbip,b.dbport,b.username,b.sysname,b.flag from t_core_project_datasource a LEFT JOIN t_core_datasystem b on a.systemsource_id=b.id LEFT JOIN t_base_usersys us ON a.systemsource_id = us.sysid where a.project_id='" + projectid + "'";
      List<Map<String, String>> vo = this.getSession().createNativeQuery(sql).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).getResultList();
      return vo;
   }

   public List<Map<String, String>> queryDatasystemList(String projectid, String flag, String istargetdb) {
      String sql = "";
      if ("on".equals(istargetdb)) {
         sql = "select a.project_id,a.systemsource_id as id,b.dbtype,b.pagecode,b.dbip,b.dbport,b.username,b.sysname from t_core_project_datasource a LEFT JOIN t_core_datasystem b on a.systemsource_id=b.id where a.project_id='" + projectid + "' and b.flag= '" + flag + "' and b.istargetdb = 'on'";
      } else {
         sql = "select a.project_id,a.systemsource_id as id,b.dbtype,b.pagecode,b.dbip,b.dbport,b.username,b.sysname from t_core_project_datasource a LEFT JOIN t_core_datasystem b on a.systemsource_id=b.id where a.project_id='" + projectid + "' and b.flag= '" + flag + "'";
      }

      List<Map<String, String>> vo = this.getSession().createNativeQuery(sql).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).getResultList();
      return vo;
   }

   public List<Map<String, String>> queryDatasystemListEM(String flag, String istargetdb) {
      String sql = "";
      if ("on".equals(istargetdb)) {
         sql = "select id,dbtype,pagecode,dbip,dbport,username,sysname from t_core_datasystem where flag= '" + flag + "' and istargetdb = 'on' and dbtype = 'ORACLE'";
      } else {
         sql = "select id,dbtype,pagecode,dbip,dbport,username,sysname from t_core_datasystem where flag= '" + flag + "' and dbtype = 'ORACLE'";
      }

      List<Map<String, String>> vo = this.getSession().createNativeQuery(sql).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).getResultList();
      return vo;
   }

   public List<Map<String, String>> queryDatasystemListDataScope(String projectId) {
      String sql = "";
      sql = "select a.project_id,a.systemsource_id as id,b.dbtype,b.pagecode,b.dbip,b.dbport,b.username,b.sysname,b.flag from t_core_project_datasource a LEFT JOIN t_core_datasystem b on a.systemsource_id=b.id where a.project_id='" + projectId + "'";
      List<Map<String, String>> vo = this.getSession().createNativeQuery(sql).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).getResultList();
      return vo;
   }
}
