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

import com.chenyang.nse.bussiness.dao.BaseDao;
import com.chenyang.nse.bussiness.entity.orm.table.core.desensitizationselftask.DesensitizationSelfTask;
import com.chenyang.nse.bussiness.entity.orm.table.core.desensitizationtask.Desensitizationtask;
import com.chenyang.nse.bussiness.tools.xml.XmlTool;
import java.math.BigInteger;
import java.util.List;
import java.util.Map;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.hibernate.transform.Transformers;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;

@Repository
public class DesensitizationSelfTaskDao extends BaseDao<DesensitizationSelfTask, String> {
   static final String CACHE_NAME = "DesensitizationSelfTask";

   public long getExeTaskNum() {
      String sql = "select  count(*) from desensitization_table as a,desensitization_self_task as b  where a.taskid = b.id and taskstatus = 1";
      BigInteger count = (BigInteger)this.getSession().createNativeQuery(sql).uniqueResult();
      return count.longValue();
   }

   public long getTableNum(String taskid) {
      String sql = "select count(*) as count from desensitization_table    where taskid = '" + taskid + "'";
      BigInteger count = (BigInteger)this.getSession().createNativeQuery(sql).uniqueResult();
      return count.longValue();
   }

   public long getTableNumByAll(String sqls) {
      String sql = "select count(*) as count from desensitization_table    where taskid  in (" + sqls + ")";
      BigInteger count = (BigInteger)this.getSession().createNativeQuery(sql).uniqueResult();
      return count.longValue();
   }

   public List<Map<String, Object>> selectCodatabaseDataCount(String id) {
      String sql = "SELECT count(1) as s FROM DESENSITIZATION_SELF_TASK where projectid ='" + id + "'";
      List<Map<String, Object>> vo = this.getSession().createNativeQuery(sql).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).getResultList();
      return vo;
   }

   public List<DesensitizationSelfTask> queryTaskAll() {
      String sql = XmlTool.getSql("getalltask", "selectSelfTaskAllList");
      List<DesensitizationSelfTask> vo = this.getSession().createNativeQuery(sql).setResultTransformer(Transformers.aliasToBean(Desensitizationtask.class)).getResultList();
      return vo;
   }

   public List<DesensitizationSelfTask> queryTaskAllbyprojectid(String projectid) {
      String sql = XmlTool.getSql("getalltask", "selectSelfTaskAllListByProjectid");
      List<DesensitizationSelfTask> vo = this.getSession().createNativeQuery(sql).setParameter("projectid", projectid).setResultTransformer(Transformers.aliasToBean(DesensitizationSelfTask.class)).getResultList();
      return vo;
   }

   @Cacheable(
      cacheNames = {"DesensitizationSelfTask"},
      key = "'DESENSITIZATIONTASK_' + #taskid",
      unless = "#result == null"
   )
   public DesensitizationSelfTask getById(String taskid) {
      DesensitizationSelfTask desensitizationtask = (DesensitizationSelfTask)this.queryUnique(new Criterion[]{Restrictions.eq("id", taskid)});
      return desensitizationtask;
   }
}
