package com.ssj.framework.files.service;

import com.ssj.bean.common.files.domain.FileInfo;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface FileInfoDao extends JpaRepository<FileInfo, String>{

	@Query(nativeQuery = true, value = " SELECT * FROM `sys_file_info`  t where t.user_id='FACEWORK' AND TO_DAYS(t.created_date)=TO_DAYS(?1)  ORDER BY t.created_date ASC  ")
	public List<FileInfo> findFileInfoByDate(String date);
	
	@Query(nativeQuery = true, value = "DELETE from   sys_file_info where file_path =?1")
	@Modifying
	public void deleteByFilePath(String filePath);

	@Query(nativeQuery = true, value ="SELECT  *  from  sys_file_info where file_code =?1\n" +
			"LIMIT ?2,?3")
	public List<FileInfo> findFileInfoByFileCode(String fileCode,int star,int end);

	@Query(nativeQuery = true, value = "SELECT  count(1)  from  sys_file_info where file_code = (\n" +
			"SELECT  file_code  from  sys_file_info where user_id =?1\n" +
			"and  file_path  =?2)")
	public Long countFileInfoByFilePathAndUserId(String userId,String filePath);
	
	
}
