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

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

@Repository
public class TCoreAttachmentDirectoryDao extends BaseDao<TCoreAttachmentDirectory, String> {
   public int updateAttachmentDirectory(TCoreAttachmentDirectory comdir) {
      String sql = XmlTool.getSql("compliancedirectory", "updateattachmentdirectory");
      int i = this.getSession().createNativeQuery(sql).setParameter("id", comdir.getId()).setParameter("create_user", comdir.getCreate_user()).setParameter("file_note", comdir.getFile_note()).executeUpdate();
      return i;
   }

   public List<TCoreAttachmentDirectory> getFileLike(TCoreAttachmentDirectory comdir) {
      String sql = "select attachment_name FROM t_core_attachment_directory WHERE\tattachment_name like '" + comdir.getAttachment_name() + "%' and attachment_form = '" + comdir.getAttachment_form() + "'";
      List<TCoreAttachmentDirectory> list = this.getSession().createNativeQuery(sql).setResultTransformer(Transformers.aliasToBean(TCoreAttachmentDirectory.class)).getResultList();
      return list;
   }

   public void removeAttaCompliance(String editionid) {
      String sql = "DELETE c FROM t_core_compliance_directory a,t_core_attachment_directory c WHERE a.id = c.attachment_id and a.edition_id = '" + editionid + "'";
      this.getSession().createNativeQuery(sql).executeUpdate();
   }
}
