package com.its.api.its.repository.ifsc;

import com.its.api.its.model.entity.ifsc.TbReptCngsSect;
import com.its.api.its.model.entity.ifsc.TbReptCngsSectKey;
import com.its.api.its.model.entity.ifsc.TbReptCngsSectTraf;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface TbReptCngsSectTrafRepository extends JpaRepository<TbReptCngsSectTraf, TbReptCngsSectKey>, JpaSpecificationExecutor<TbReptCngsSect> {

    @Query( "select p from TbReptCngsSectTraf p inner join fetch p.ifscTraf traf inner join fetch traf.ifsc ifsc " +
            " where p.dcsnYn = :dcsnYn " +
            "   and p.statYm = to_char(sysdate, 'YYYYMM') " +
            "   and p.cnfsStrtHm <= to_char(sysdate, 'HH24MI') " +
            "   and p.cnfsEndHm  >= to_char(sysdate, 'HH24MI') " +
            "   and p.dayTypeCd = :dayTypeCd")
    List<TbReptCngsSectTraf> findAllCurrent(@Param("dcsnYn") String dcsnYn, @Param("dayTypeCd") String dayTypeCd);

}
