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

import com.chenyang.nse.bussiness.dao.BaseDao;
import com.chenyang.nse.bussiness.entity.vo.Releasecolumn;
import com.google.common.base.Joiner;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.transform.Transformers;
import org.springframework.stereotype.Repository;

@Repository
public class TCoreReleasecolumnDao extends BaseDao<Releasecolumn, String> {
   public List<Releasecolumn> queryTcoreReleasecolumn(List<String> schemas, String projectid, String table) {
      List<String> list = new ArrayList();

      for(int i = 0; i < schemas.size(); ++i) {
         list.add("'" + ((String)schemas.get(i)).split("\\~")[0] + "'");
      }

      String joiner_schemas = Joiner.on(",").join(list);
      String sql = "select * from " + table + "  where tschema in (" + joiner_schemas + ") and projectid  = '" + projectid + "'";
      return this.getSession().createNativeQuery(sql).setResultTransformer(Transformers.aliasToBean(Releasecolumn.class)).getResultList();
   }

   public void deleReleasecolumnByProductId(String projectid, String table) {
      String sql = "delete from " + table + " where projectid = '" + projectid + "'";
      this.getSession().createNativeQuery(sql).executeUpdate();
   }

   public void saveReleasecolumn(StringBuilder sql) {
      this.getSession().createNativeQuery(sql.toString()).executeUpdate();
   }

   public void removeReleasecolumn(StringBuilder sql) {
      this.getSession().createNativeQuery(sql.toString()).executeUpdate();
   }

   public List<Releasecolumn> queryTcoreReleasecolumn(String projectid, String table) {
      String sql = "select *  from " + table + "  where projectid = '" + projectid + "'";
      return this.getSession().createNativeQuery(sql).setResultTransformer(Transformers.aliasToBean(Releasecolumn.class)).getResultList();
   }
}
