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

import com.chenyang.nse.bussiness.dao.BaseDao;
import com.chenyang.nse.bussiness.engine.infa.powercenter961.pubtool.StringUtil;
import com.chenyang.nse.bussiness.entity.orm.table.core.masking.TCoreDesensitizationRule;
import com.chenyang.nse.bussiness.entity.vo.maskingrule.DesensitizationRuleVO;
import java.util.List;
import org.hibernate.transform.Transformers;
import org.springframework.stereotype.Repository;

@Repository
public class TCoreDesensitizationRuleDao extends BaseDao<TCoreDesensitizationRule, String> {
   public List<DesensitizationRuleVO> queryRuleList(String dataarea) {
      String sql = "";
      if (StringUtil.isBlank(dataarea)) {
         sql = "SELECT a.dataarea,a.id as dataareaId,r.id as ruleId,r.rulename as ruleName,r.expression,r.defaluttype as defaultType \nFROM t_core_dataarea a LEFT JOIN t_core_desensitization_rule r ON a.id = r.dataarea_id";
      } else {
         sql = "SELECT a.dataarea,a.id as dataareaId,r.id as ruleId,r.rulename as ruleName,r.expression,r.defaluttype as defaultType \nFROM t_core_dataarea a LEFT JOIN t_core_desensitization_rule r ON a.id = r.dataarea_id WHERE a.dataarea LIKE CONCAT('%','" + dataarea + "','%') ";
      }

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