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

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

@Repository
public class TCoreDataareaSecretkeyRelationDao extends BaseDao<TCoreDataareaSecretkeyRelation, String> {
   public List<DataareaSecretkeyRelationVo> queryAllSecretkey(String dataarea_id) {
      String sql = "select r.id, r.secretkey_id, r.encryption_id, r.dataarea_id, r.enc_name, e.encryption_name, s.secret_key_name, r.defaulttype from t_core_dataarea_secretkey_relation r join t_core_secretkey s on r.secretkey_id = s.id  join t_core_encryption e on r.encryption_id = e.id  join t_core_dataarea d on r.dataarea_id = d.id  where r.dataarea_id = '" + dataarea_id + "'";
      if (HibernateConfig.PEIZHIKUDBTYPE.equals("3")) {
         sql = "select r.id as \"id\", r.secretkey_id as \"secretkey_id\", r.encryption_id as \"encryption_id\", r.dataarea_id as \"dataarea_id\", r.enc_name as \"enc_name\", e.encryption_name as \"encryption_name\", s.secret_key_name as \"secret_key_name\", r.defaulttype as \"defaulttype\" from t_core_dataarea_secretkey_relation r join t_core_secretkey s on r.secretkey_id = s.id join t_core_encryption e on r.encryption_id = e.id  join t_core_dataarea d on r.dataarea_id = d.id where r.dataarea_id = '" + dataarea_id + "'";
      }

      List<DataareaSecretkeyRelationVo> list = this.getSession().createNativeQuery(sql).setResultTransformer(Transformers.aliasToBean(DataareaSecretkeyRelationVo.class)).getResultList();
      return list;
   }

   public List<DataareaSecretkeyRelationVo> queryAllSecretkeyDefault(String dataarea_id) {
      String sql = "select r.id, r.secretkey_id, r.encryption_id, r.dataarea_id, r.enc_name, e.encryption_name, s.secret_key_name, r.defaulttype from t_core_dataarea_secretkey_relation r join t_core_secretkey s on r.secretkey_id = s.id join t_core_encryption e on r.encryption_id = e.id  join t_core_dataarea d on r.dataarea_id = d.id where r.defaulttype = '1' and r.dataarea_id = '" + dataarea_id + "'";
      if (HibernateConfig.PEIZHIKUDBTYPE.equals("3")) {
         sql = "select r.id as \"id\", r.secretkey_id as \"secretkey_id\", r.encryption_id as \"encryption_id\", r.dataarea_id as \"dataarea_id\", r.enc_name as \"enc_name\", e.encryption_name as \"encryption_name\", s.secret_key_name as \"secret_key_name\", r.defaulttype as \"defaulttype\" from t_core_dataarea_secretkey_relation r join t_core_secretkey s on r.secretkey_id = s.id join t_core_encryption e on r.encryption_id = e.id  join t_core_dataarea d on r.dataarea_id = d.id where r.defaulttype = '1' and r.dataarea_id = '" + dataarea_id + "'";
      }

      List<DataareaSecretkeyRelationVo> list = this.getSession().createNativeQuery(sql).setResultTransformer(Transformers.aliasToBean(DataareaSecretkeyRelationVo.class)).getResultList();
      return list;
   }
}
