package com.its.op.dao.repository.its.rse;

import com.its.op.entity.its.rse.TbRseObuClctHs;
import com.its.op.entity.its.rse.TbRseObuClctHsKey;
import com.its.op.entity.its.rse.TbRseSectTrafHs;
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 TbRseObuClctHsRepository extends JpaRepository<TbRseObuClctHs, TbRseObuClctHsKey>, JpaSpecificationExecutor<TbRseObuClctHs> {

    @Query("select p from TbRseObuClctHs p")
    List<TbRseObuClctHs> findAll();

    @Query("select p from TbRseObuClctHs p")
    List<TbRseObuClctHs> findAllList();

    @Query("select p from TbRseObuClctHs p inner join fetch p.rse where p.clctDt between :fromDt and :toDt and p.obuKind = :kind and p.rseCtlrNmbr in :ids")
    List<TbRseObuClctHs> findAllCtypByDateRange(@Param("fromDt") String fromDt, @Param("toDt") String toDt, @Param("kind") String kind, @Param("ids") List<Long> ids);

    @Query("select p from TbRseObuClctHs p inner join fetch p.rse where p.clctDt between :fromDt and :toDt and p.ctyp = :type and p.rseCtlrNmbr in :ids")
    List<TbRseObuClctHs> findAllKindByDateRange(@Param("fromDt") String fromDt, @Param("toDt") String toDt, @Param("type") String type, @Param("ids") List<Long> ids);

    @Query("select p from TbRseObuClctHs p inner join fetch p.rse where p.clctDt between :fromDt and :toDt and p.rseCtlrNmbr in :ids")
    List<TbRseObuClctHs> findAllByDateRange(@Param("fromDt") String fromDt, @Param("toDt") String toDt, @Param("ids") List<Long> ids);

    @Query("select p from TbRseObuClctHs p inner join fetch p.rse where p.clctDt between :fromDt and :toDt and p.ctyp = :type and p.obuKind = :kind and p.rseCtlrNmbr in :ids")
    List<TbRseObuClctHs> findAllCKByDateRange(@Param("fromDt") String fromDt, @Param("toDt") String toDt, @Param("type") String type, @Param("kind") String kind, @Param("ids") List<Long> ids);
}
