package com.its.op.service.its.atrd;

import com.its.op.dto.its.atrd.AtrdRltnIdDto;
import com.its.op.dto.its.atrd.AtrdTrafficStatDto;
import com.its.op.dto.its.atrd.TbAtrdDto;
import com.its.op.dto.its.statistics.*;
import com.its.op.entity.its.atrd.TbAtrd;
import com.its.op.dao.repository.its.atrd.TbAtrdRepository;
import com.its.op.dao.repository.its.atrd.TbAtrdRoadRltnRepository;
import com.its.op.dao.mapper.its.atrd.AtrdTrafficStatisticsMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@RequiredArgsConstructor
@Service
public class AtrdTrafficStatisticsService {

    private final AtrdTrafficStatisticsMapper mapper;
    private final TbAtrdRepository atrdRepo;
    private final TbAtrdRoadRltnRepository atrdRoadRltnRep;

    //////////////////////////////////////////////////////////////
    // LINK_ID, IFSC_ID, ROAD_ID 가 검색 기준
    //////////////////////////////////////////////////////////////
    //////////// 링크 기간검색
    public List<AtrdTrafficStatDto> findAllLink15MTerm(TrafficTermParam cond) {
        cond.setTABLE_NAME("TB_LINK_STAT_15M");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllLinkStatByIdTerm(cond);
    }

    public List<AtrdTrafficStatDto> findAllLinkHHTerm(TrafficTermParam cond) {
        cond.setTABLE_NAME("TB_LINK_STAT_HH");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllLinkStatByIdTerm(cond);
    }

    public List<AtrdTrafficStatDto> findAllLinkDDTerm(TrafficTermParam cond) {
        cond.setTABLE_NAME("TB_LINK_STAT_DD");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 10) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 10), 'YYYY-MM-DD HH24') AS STAT_DT_FMT, ");
        return this.mapper.findAllLinkStatByIdTerm(cond);
    }

    public List<AtrdTrafficStatDto> findAllLinkMNTerm(TrafficTermParam cond) {
        cond.setTABLE_NAME("TB_LINK_STAT_MN");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 8) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 8), 'YYYY-MM-DD') AS STAT_DT_FMT, ");
        return this.mapper.findAllLinkStatByIdTerm(cond);
    }

    public List<AtrdTrafficStatDto> findAllLinkYYTerm(TrafficTermParam cond) {
        cond.setTABLE_NAME("TB_LINK_STAT_YY");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 6) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 6), 'YYYY-MM') AS STAT_DT_FMT, ");
        return this.mapper.findAllLinkStatByIdTerm(cond);
    }

    //////////// 서비스 링크 기간검색
    public List<AtrdTrafficStatDto> findAllIfsc15MTerm(TrafficTermParam cond) {
        cond.setTABLE_NAME("TB_IFSC_STAT_15M");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllIfscStatByIdTerm(cond);
    }

    public List<AtrdTrafficStatDto> findAllIfscHHTerm(TrafficTermParam cond) {
        cond.setTABLE_NAME("TB_IFSC_STAT_HH");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllIfscStatByIdTerm(cond);
    }

    public List<AtrdTrafficStatDto> findAllIfscDDTerm(TrafficTermParam cond) {
        cond.setTABLE_NAME("TB_IFSC_STAT_DD");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 10) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 10), 'YYYY-MM-DD HH24') AS STAT_DT_FMT, ");
        return this.mapper.findAllIfscStatByIdTerm(cond);
    }

    public List<AtrdTrafficStatDto> findAllIfscMNTerm(TrafficTermParam cond) {
        cond.setTABLE_NAME("TB_IFSC_STAT_MN");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 8) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 8), 'YYYY-MM-DD') AS STAT_DT_FMT, ");
        return this.mapper.findAllIfscStatByIdTerm(cond);
    }

    public List<AtrdTrafficStatDto> findAllIfscYYTerm(TrafficTermParam cond) {
        cond.setTABLE_NAME("TB_IFSC_STAT_YY");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 6) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 6), 'YYYY-MM') AS STAT_DT_FMT, ");
        return this.mapper.findAllIfscStatByIdTerm(cond);
    }

    //////////// 도로 기간검색
    public List<AtrdTrafficStatDto> findAllRoad15MTerm(TrafficTermParam cond) {
        cond.setTABLE_NAME("TB_ROAD_STAT_15M");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllRoadStatByIdTerm(cond);
    }

    public List<AtrdTrafficStatDto> findAllRoadHHTerm(TrafficTermParam cond) {
        cond.setTABLE_NAME("TB_ROAD_STAT_HH");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllRoadStatByIdTerm(cond);
    }

    public List<AtrdTrafficStatDto> findAllRoadDDTerm(TrafficTermParam cond) {
        cond.setTABLE_NAME("TB_ROAD_STAT_DD");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 10) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 10), 'YYYY-MM-DD HH24') AS STAT_DT_FMT, ");
        return this.mapper.findAllRoadStatByIdTerm(cond);
    }

    public List<AtrdTrafficStatDto> findAllRoadMNTerm(TrafficTermParam cond) {
        cond.setTABLE_NAME("TB_ROAD_STAT_MN");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 8) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 8), 'YYYY-MM-DD') AS STAT_DT_FMT, ");
        return this.mapper.findAllRoadStatByIdTerm(cond);
    }

    public List<AtrdTrafficStatDto> findAllRoadYYTerm(TrafficTermParam cond) {
        cond.setTABLE_NAME("TB_ROAD_STAT_YY");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 6) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 6), 'YYYY-MM') AS STAT_DT_FMT, ");
        return this.mapper.findAllRoadStatByIdTerm(cond);
    }

    //////////// 링크 시간대검색
    public List<AtrdTrafficStatDto> findAllLink15MHour(TrafficHourParam cond) {
        cond.setTABLE_NAME("TB_LINK_STAT_15M");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllLinkStatByIdHour(cond);
    }

    public List<AtrdTrafficStatDto> findAllLinkHHHour(TrafficHourParam cond) {
        cond.setTABLE_NAME("TB_LINK_STAT_HH");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllLinkStatByIdHour(cond);
    }

    //////////// 서비스 링크 시간대검색
    public List<AtrdTrafficStatDto> findAllIfsc15MHour(TrafficHourParam cond) {
        cond.setTABLE_NAME("TB_IFSC_STAT_15M");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllIfscStatByIdHour(cond);
    }

    public List<AtrdTrafficStatDto> findAllIfscHHHour(TrafficHourParam cond) {
        cond.setTABLE_NAME("TB_IFSC_STAT_HH");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllIfscStatByIdHour(cond);
    }

    //////////// 도로 시간대검색
    public List<AtrdTrafficStatDto> findAllRoad15MHour(TrafficHourParam cond) {
        cond.setTABLE_NAME("TB_ROAD_STAT_15M");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllRoadStatByIdHour(cond);
    }

    public List<AtrdTrafficStatDto> findAllRoadHHHour(TrafficHourParam cond) {
        cond.setTABLE_NAME("TB_ROAD_STAT_HH");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllRoadStatByIdHour(cond);
    }

    //////////// 링크 지정시각검색
    //////////// TODO: 지정일은 반드시 조회조건에 포함시켜야 한다.
    public List<AtrdTrafficStatDto> findAllLink15MSpec(TrafficSpecParam cond) {
        cond.setTABLE_NAME("TB_LINK_STAT_15M");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllLinkStatByIdSpec(cond);
    }

    public List<AtrdTrafficStatDto> findAllLinkHHSpec(TrafficSpecParam cond) {
        cond.setTABLE_NAME("TB_LINK_STAT_HH");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllLinkStatByIdSpec(cond);
    }

    //////////// 서비스 링크 지정시각검색
    public List<AtrdTrafficStatDto> findAllIfsc15MSpec(TrafficSpecParam cond) {
        cond.setTABLE_NAME("TB_IFSC_STAT_15M");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllIfscStatByIdSpec(cond);
    }

    public List<AtrdTrafficStatDto> findAllIfscHHSpec(TrafficSpecParam cond) {
        cond.setTABLE_NAME("TB_IFSC_STAT_HH");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllIfscStatByIdSpec(cond);
    }

    //////////// 도로 지정시각검색
    public List<AtrdTrafficStatDto> findAllRoad15MSpec(TrafficSpecParam cond) {
        cond.setTABLE_NAME("TB_ROAD_STAT_15M");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllRoadStatByIdSpec(cond);
    }

    public List<AtrdTrafficStatDto> findAllRoadHHSpec(TrafficSpecParam cond) {
        cond.setTABLE_NAME("TB_ROAD_STAT_HH");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllRoadStatByIdSpec(cond);
    }

    //////////////////////////////////////////////////////////////
    // ATRD_ID 가 검색 기준
    //////////////////////////////////////////////////////////////
    //////////// 링크 기간검색
    public List<AtrdTrafficStatDto> findAllLink15MByAtrdIdTerm(TrafficTermParam cond) {
        cond.setTABLE_NAME("TB_LINK_STAT_15M");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllLinkStatByAtrdIdTerm(cond);
    }

    public List<AtrdTrafficStatDto> findAllLinkHHByAtrdIdTerm(TrafficTermParam cond) {
        cond.setTABLE_NAME("TB_LINK_STAT_HH");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllLinkStatByAtrdIdTerm(cond);
    }

    public List<AtrdTrafficStatDto> findAllLinkDDByAtrdIdTerm(TrafficTermParam cond) {
        cond.setTABLE_NAME("TB_LINK_STAT_DD");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 10) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 10), 'YYYY-MM-DD HH24') AS STAT_DT_FMT, ");
        return this.mapper.findAllLinkStatByAtrdIdTerm(cond);
    }

    public List<AtrdTrafficStatDto> findAllLinkMNByAtrdIdTerm(TrafficTermParam cond) {
        cond.setTABLE_NAME("TB_LINK_STAT_MN");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 8) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 8), 'YYYY-MM-DD') AS STAT_DT_FMT, ");
        return this.mapper.findAllLinkStatByAtrdIdTerm(cond);
    }

    public List<AtrdTrafficStatDto> findAllLinkYYByAtrdIdTerm(TrafficTermParam cond) {
        cond.setTABLE_NAME("TB_LINK_STAT_YY");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 6) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 6), 'YYYY-MM') AS STAT_DT_FMT, ");
        return this.mapper.findAllLinkStatByAtrdIdTerm(cond);
    }

    //////////// 서비스 링크 기간검색
    public List<AtrdTrafficStatDto> findAllIfsc15MByAtrdIdTerm(TrafficTermParam cond) {
        cond.setTABLE_NAME("TB_IFSC_STAT_15M");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllIfscStatByAtrdIdTerm(cond);
    }

    public List<AtrdTrafficStatDto> findAllIfscHHByAtrdIdTerm(TrafficTermParam cond) {
        cond.setTABLE_NAME("TB_IFSC_STAT_HH");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllIfscStatByAtrdIdTerm(cond);
    }

    public List<AtrdTrafficStatDto> findAllIfscDDByAtrdIdTerm(TrafficTermParam cond) {
        cond.setTABLE_NAME("TB_IFSC_STAT_DD");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 10) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 10), 'YYYY-MM-DD HH24') AS STAT_DT_FMT, ");
        return this.mapper.findAllIfscStatByAtrdIdTerm(cond);
    }

    public List<AtrdTrafficStatDto> findAllIfscMNByAtrdIdTerm(TrafficTermParam cond) {
        cond.setTABLE_NAME("TB_IFSC_STAT_MN");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 8) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 8), 'YYYY-MM-DD') AS STAT_DT_FMT, ");
        return this.mapper.findAllIfscStatByAtrdIdTerm(cond);
    }

    public List<AtrdTrafficStatDto> findAllIfscYYByAtrdIdTerm(TrafficTermParam cond) {
        cond.setTABLE_NAME("TB_IFSC_STAT_YY");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 6) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 6), 'YYYY-MM') AS STAT_DT_FMT, ");
        return this.mapper.findAllIfscStatByAtrdIdTerm(cond);
    }

    //////////// 도로 기간검색
    public List<AtrdTrafficStatDto> findAllRoad15MByAtrdIdTerm(TrafficTermParam cond) {
        cond.setTABLE_NAME("TB_ROAD_STAT_15M");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllRoadStatByAtrdIdTerm(cond);
    }

    public List<AtrdTrafficStatDto> findAllRoadHHByAtrdIdTerm(TrafficTermParam cond) {
        cond.setTABLE_NAME("TB_ROAD_STAT_HH");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllRoadStatByAtrdIdTerm(cond);
    }

    public List<AtrdTrafficStatDto> findAllRoadDDByAtrdIdTerm(TrafficTermParam cond) {
        cond.setTABLE_NAME("TB_ROAD_STAT_DD");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 10) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 10), 'YYYY-MM-DD HH24') AS STAT_DT_FMT, ");
        return this.mapper.findAllRoadStatByAtrdIdTerm(cond);
    }

    public List<AtrdTrafficStatDto> findAllRoadMNByAtrdIdTerm(TrafficTermParam cond) {
        cond.setTABLE_NAME("TB_ROAD_STAT_MN");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 8) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 8), 'YYYY-MM-DD') AS STAT_DT_FMT, ");
        return this.mapper.findAllRoadStatByAtrdIdTerm(cond);
    }

    public List<AtrdTrafficStatDto> findAllRoadYYByAtrdIdTerm(TrafficTermParam cond) {
        cond.setTABLE_NAME("TB_ROAD_STAT_YY");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 6) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 6), 'YYYY-MM') AS STAT_DT_FMT, ");
        return this.mapper.findAllRoadStatByAtrdIdTerm(cond);
    }

    //////////// 링크 시간대검색
    public List<AtrdTrafficStatDto> findAllLink15MByAtrdIdHour(TrafficHourParam cond) {
        cond.setTABLE_NAME("TB_LINK_STAT_15M");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllLinkStatByAtrdIdHour(cond);
    }

    public List<AtrdTrafficStatDto> findAllLinkHHByAtrdIdHour(TrafficHourParam cond) {
        cond.setTABLE_NAME("TB_LINK_STAT_HH");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllLinkStatByAtrdIdHour(cond);
    }

    //////////// 서비스 링크 시간대검색
    public List<AtrdTrafficStatDto> findAllIfsc15MByAtrdIdHour(TrafficHourParam cond) {
        cond.setTABLE_NAME("TB_IFSC_STAT_15M");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllIfscStatByAtrdIdHour(cond);
    }

    public List<AtrdTrafficStatDto> findAllIfscHHByAtrdIdHour(TrafficHourParam cond) {
        cond.setTABLE_NAME("TB_IFSC_STAT_HH");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllIfscStatByAtrdIdHour(cond);
    }

    //////////// 도로 시간대검색
    public List<AtrdTrafficStatDto> findAllRoad15MByAtrdIdHour(TrafficHourParam cond) {
        cond.setTABLE_NAME("TB_ROAD_STAT_15M");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllRoadStatByAtrdIdHour(cond);
    }

    public List<AtrdTrafficStatDto> findAllRoadHHByAtrdIdHour(TrafficHourParam cond) {
        cond.setTABLE_NAME("TB_ROAD_STAT_HH");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllRoadStatByAtrdIdHour(cond);
    }

    //////////// 링크 지정시각검색
    //////////// TODO: 지정일은 반드시 조회조건에 포함시켜야 한다.
    public List<AtrdTrafficStatDto> findAllLink15MByAtrdIdSpec(TrafficSpecParam cond) {
        cond.setTABLE_NAME("TB_LINK_STAT_15M");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllLinkStatByAtrdIdSpec(cond);
    }

    public List<AtrdTrafficStatDto> findAllLinkHHByAtrdIdSpec(TrafficSpecParam cond) {
        cond.setTABLE_NAME("TB_LINK_STAT_HH");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllLinkStatByAtrdIdSpec(cond);
    }

    //////////// 서비스 링크 지정시각검색
    public List<AtrdTrafficStatDto> findAllIfsc15MByAtrdIdSpec(TrafficSpecParam cond) {
        cond.setTABLE_NAME("TB_IFSC_STAT_15M");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllIfscStatByAtrdIdSpec(cond);
    }

    public List<AtrdTrafficStatDto> findAllIfscHHByAtrdIdSpec(TrafficSpecParam cond) {
        cond.setTABLE_NAME("TB_IFSC_STAT_HH");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllIfscStatByAtrdIdSpec(cond);
    }

    //////////// 도로 지정시각검색
    public List<AtrdTrafficStatDto> findAllRoad15MByAtrdIdSpec(TrafficSpecParam cond) {
        cond.setTABLE_NAME("TB_ROAD_STAT_15M");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllRoadStatByAtrdIdSpec(cond);
    }

    public List<AtrdTrafficStatDto> findAllRoadHHByAtrdIdSpec(TrafficSpecParam cond) {
        cond.setTABLE_NAME("TB_ROAD_STAT_HH");
        cond.setDATE_COL_FMT("SUBSTR(A.STAT_DT, 1, 12) AS STAT_DT, TO_DATE(SUBSTR(A.STAT_DT, 1, 12), 'YYYY-MM-DD HH24:MI') AS STAT_DT_FMT, ");
        return this.mapper.findAllRoadStatByAtrdIdSpec(cond);
    }

    // 간선도로 목록 조회
    public List<TbAtrdDto> findAtrdAll() {
        List<TbAtrdDto> result = new ArrayList<>();
        List<TbAtrd> data = this.atrdRepo.findAll();
        if (data != null) {
	        data.forEach(obj -> {
	            if (("N").equals(obj.getDelYn())) {
	                result.add(obj.toDto(new ArrayList<>()));
	            }
	        });
	    }
        return result;
    }

    // 간선도로에 속한 링크 목록
    public List<AtrdRltnIdDto> findAtrdRltnLinkAll(String atrdId) {

        return this.mapper.findAtrdRltnLinkAll(atrdId);
/*
        List<AtrdRltnIdDto> result = new ArrayList<>();
        return result;
*/
    }

    // 간선도로에 속한 정보제공구간 목록
    public List<AtrdRltnIdDto> findAtrdRltnIfscAll(String atrdId) {

        return this.mapper.findAtrdRltnIfscAll(atrdId);
/*
        List<AtrdRltnIdDto> result = new ArrayList<>();
        return result;
*/
    }

    // 간선도로에 속한 도로 목록
    public List<AtrdRltnIdDto> findAtrdRltnRoadAll(String atrdId) {
        return this.mapper.findAtrdRltnRoadAll(atrdId);

/*
        List<AtrdRltnIdDto> result = new ArrayList<>();
        List<TbAtrdRoadRltn> data = this.atrdRoadRltnRep.findRoadRltnById(atrdId);
        data.forEach(obj -> {
            AtrdRltnIdDto rltn = AtrdRltnIdDto.builder()
                    .ord(obj.getOrd())
                    .id(obj.getRoadId())
                    .name(obj.getRoad().getRoadName())
                    .strtNm(obj.getRoad().getStrtNm())
                    .endNm(obj.getRoad().getEndNm())
                    .sectLngt(obj.getRoad().getSectLngt())
                    .build();
            result.add(rltn);
        });
        return result;*/
    }
}
