package com.utic.center.utic.traf.server.service;

import com.utic.center.common.annotation.ProcessingElapsed;
import com.utic.center.common.service.AbstractProcessService;
import com.utic.center.common.utils.SleepUtils;
import com.utic.center.utic.traf.server.dao.repository.utic.UticTrafficRepository;
import com.utic.center.utic.traf.server.repository.ApplicationRepository;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Getter
@RequiredArgsConstructor
@Service
public class LinkTrafPrcsAfterService implements AbstractProcessService {

    private final UticTrafficRepository uticRepo;

    @ProcessingElapsed(type="PRCS", name="교통정보 준비 작업", starting = false, endLine = true)
    @Override
    public boolean processing() {

        this.uticRepo.truncateTrafficLoc();         // 지역 교통정보 테이블 초기화
        SleepUtils.safeSleep(100);  // FOR Database
        this.uticRepo.truncateTrafficCenter(ApplicationRepository.nextTrafficCenter); // 작업 할 소통정보 테이블 초기화
        SleepUtils.safeSleep(100);  // FOR Database

        // 작업할 테이블의 인덱스와 키를 비활성화 시킨다.
        this.uticRepo.disableIndexes(ApplicationRepository.nextTrafficCenter, "1");
        this.uticRepo.disableIndexes(ApplicationRepository.nextTrafficCenter, "2");
        this.uticRepo.disablePrimaryKey(ApplicationRepository.nextTrafficCenter);

        return true;
    }
}
