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.TCoreEncryptionRuleTable;
import java.util.List;
import org.hibernate.transform.Transformers;
import org.springframework.stereotype.Repository;

@Repository
public class TCoreEncryptionTableRuleDao extends BaseDao<TCoreEncryptionRuleTable, String> {
   public void saveData(TCoreEncryptionRuleTable data) {
      super.save(data);
   }

   public TCoreEncryptionRuleTable get(String projectId, String dataSystemId, String schema, String table) {
      String sql = null;
      if (!HibernateConfig.PEIZHIKUDBTYPE.equals("3")) {
         sql = "select * from t_core_encryption_rule_table where  projectid='" + projectId + "'  and datasystemid='" + dataSystemId + "'  and schemaname='" + schema + "'  and tablename='" + table + "'";
      } else {
         sql = "select id as \"id\", projectid as \"projectid\", datasystemid as \"datasystemid\", schemaname as \"schemaname\", tablename as \"tablename\",  enctype as \"enctype\", createtime as \"createtime\", updatetime as \"updatetime\", createuser as \"createuser\", updateuser as \"updateuser\", flag as \"flag\", note as \"note\"  from t_core_encryption_rule_table where  projectid='" + projectId + "'  and datasystemid='" + dataSystemId + "'  and schemaname='" + schema + "'  and tablename='" + table + "'";
      }

      List<TCoreEncryptionRuleTable> resultList = this.getSession().createNativeQuery(sql).setResultTransformer(Transformers.aliasToBean(TCoreEncryptionRuleTable.class)).getResultList();
      return resultList != null && resultList.size() != 0 ? (TCoreEncryptionRuleTable)resultList.get(0) : null;
   }
}
