package com.its.api.its.repository.vds;

import com.its.api.its.model.dto.common.SttsHsErrCntInf;
import com.its.api.its.model.entity.vds.TbVdsDtctRawPnst;
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 TbVdsDtctRawPnstRepository extends JpaRepository<TbVdsDtctRawPnst, String>, JpaSpecificationExecutor<TbVdsDtctRawPnst> {

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

    @Query("select m.ctlrMngmNmbr as nmbr, count(p.dtctNmbr) as errCnt " +
            "  from TbVdsDtct m, TbVdsDtctRawPnst p " +
            " where m.dtctNmbr = p.dtctNmbr  " +
            "   and p.ocrrDt >= TO_CHAR(SYSDATE-10/1440, 'YYYYMMDDHH24MISS') " +
            " group by m.ctlrMngmNmbr")
    List<SttsHsErrCntInf> findAllCommError();

}
