package com.ann.demo.primaryRepository;

import com.ann.demo.primaryEntity.ScanningFile;
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 org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface ScanningFileRepository extends JpaRepository<ScanningFile,Integer> {
    // and  FBIHID = '370067' and FBINCU = '4'
    /*@Query(nativeQuery= true,value = "select  top 70 * from  scanning_file where STATUS = 0 order by id")
    public List<ScanningFile> findScanning();*/
    //@Query(nativeQuery= true,value = ":sql")n-m+1
    /*@Query(nativeQuery= true,value = "SELECT DISTINCT c FROM Customer c JOIN c.partyCerts p where p.certNum=?")
    public List<ScanningFile> findScanningFiles(@Param("sql") String sql);*/
    @Query(nativeQuery= true,value = "select  top(?1) * from  scanning_file where STATUS = 0 order by id desc")
    public List<ScanningFile> findScanningFiles(int over);
    @Query(nativeQuery= true,value = "select  top(?1) * from  scanning_file where STATUS = 0 and id not in (select top(?2) id from scanning_file where STATUS = 0 order by id desc) order by id desc")
    public List<ScanningFile> findScanningFilesMore(int length,int start);
    @Query(nativeQuery= true,value = "select  * from scanning_file inner join (select MAX(id) id,FBIHID,FBINCU from scanning_file where STATUS = 0 group by FBIHID,FBINCU) scanning_file1 on scanning_file.id = scanning_file1.id")
    public List<ScanningFile> findScanningFileList();
    @Query(nativeQuery= true,value = "select * from scanning_file where  FBIHID = (?1) and FBINCU = (?2) AND STATUS = 0")
    public List<ScanningFile> findScanningFileDetailList(String inpNo,String visitId);
    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(nativeQuery = true,value="update scanning_file set FREMARK = (?1),STATUS = (?2) where id in (?3)")
    public void updateBatch(String remark,String status,List<Long> ids);

}
