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

import com.its.op.dto.its.common.SttsHsErrCntInf;
import com.its.op.entity.its.vds.TbVdsDtctClctPnst;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface TbVdsDtctClctPnstRepository extends JpaRepository<TbVdsDtctClctPnst, String>, JpaSpecificationExecutor<TbVdsDtctClctPnst> {

    @Query("select p from TbVdsDtctClctPnst p inner join fetch p.dtct m inner join fetch m.vds")
    List<TbVdsDtctClctPnst> findAll();

    @Query("select m.vdsCtlrNmbr as nmbr, count(p.vdsDtctNmbr) as errCnt " +
            "  from TbVdsDtct m, TbVdsDtctClctPnst p " +
            " where m.vdsDtctNmbr = p.vdsDtctNmbr  " +
            "   and p.tfvl > 0 " +
            "   and p.clctDt >= TO_CHAR(SYSDATE-10/1440, 'YYYYMMDDHH24MISS') " +
            " group by m.vdsCtlrNmbr")
    List<SttsHsErrCntInf> findAllCommError();

}
