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

import com.chenyang.nse.bussiness.dao.BaseDao;
import com.chenyang.nse.bussiness.entity.orm.table.core.scopeproject.TProEditionScope;
import com.chenyang.nse.bussiness.tools.xml.XmlTool;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.hibernate.transform.Transformers;
import org.springframework.stereotype.Repository;

@Repository
public class TProEditionScopeDao extends BaseDao<TProEditionScope, String> {
   public int removePro(String groupid) {
      String sql = "update t_pro_edition_scope set enable_type = '0' where id = '" + groupid + "'";
      int i = this.getSession().createNativeQuery(sql).executeUpdate();
      return i;
   }

   public int updateScopeEdition(TProEditionScope tes) {
      String sql = XmlTool.getSql("datascope", "updatescopeedition");
      int i = this.getSession().createNativeQuery(sql).setParameter("id", tes.getId()).setParameter("note", tes.getNote()).setParameter("edition_name", tes.getEdition_name()).setParameter("create_user", tes.getCreate_user()).setParameter("create_date", new Date()).executeUpdate();
      return i;
   }

   public List<Map<String, Object>> getdefaultedition(String setuptype, String projectId) {
      String sql = "";
      if ("1".equals(setuptype)) {
         sql = "SELECT id FROM t_pro_edition_scope WHERE scope_level = '0' and enable_type = '1' and projectid = '" + projectId + "' order by default_date desc limit 1";
      } else if ("3".equals(setuptype)) {
         sql = "SELECT id FROM t_pro_edition_scope WHERE scope_level = '1' and enable_type = '1' and projectid = '" + projectId + "' order by default_date desc limit 1";
      }

      List<Map<String, Object>> vo = this.getSession().createNativeQuery(sql).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).getResultList();
      return vo;
   }

   public int setdefaultedition(String setuptype, String editionid) {
      String sql = XmlTool.getSql("datascope", "setdefaultedition");
      return this.getSession().createNativeQuery(sql).setParameter("id", editionid).executeUpdate();
   }

   public String getEditionNameById(String id) {
      String sql = "SELECT IFNULL(edition_name,'') from t_pro_edition_scope WHERE id = '" + id + "' ";
      return this.getSession().createSQLQuery(sql).uniqueResult().toString();
   }
}
