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

import com.utic.center.common.annotation.ProcessingElapsed;
import com.utic.center.common.service.AbstractProcessService;
import com.utic.center.common.utils.LogUtils;
import com.utic.center.utic.stat.server.dao.repository.UticStat15MinStatRepository;
import com.utic.center.utic.stat.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 UticStat15MinStatService implements AbstractProcessService {

    private final UticStat15MinStatRepository statRepo;
    private final UticStatPatternService patternService;

    @ProcessingElapsed(type="15MIN", name="정주기 15분 통계생성", starting = false)
    @Override
    public boolean processing() {

        // 통계시각은 YYYYMMDDHH24MI
        final String past30Min = ApplicationRepository.past30Min.substring(0, 12);
        final String past45Min = ApplicationRepository.past45Min.substring(0, 12);
        final String regDate = ApplicationRepository.past30Min;

        log.info("[INF] {}: past30Min[{}], past45Min[{}], patternTime[{}]", LogUtils.elapsedLog("15분 통계시각"), past30Min, past45Min, regDate);

        // 15분 중앙통계
        this.statRepo.insertStat15MinCenter(past30Min, past45Min);

        // 15분 통합배포시스템
//        this.statRepo.insertStat15MinExw(past30Min, past45Min);

        // 15분 수도권연계
        this.statRepo.insertStat15MinLoc(past30Min, past45Min);

        // 15분 패턴 업데이트
        this.patternService.patternUpdate(regDate, false);

        return false;
    }

}
