package org.jeecg.ctop.material.service.support;

import lombok.extern.slf4j.Slf4j;
import org.jeecg.ctop.material.controller.ReportController;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class DashboardStartupWarmup {

    @Resource
    private ReportController reportController;

    @EventListener(ApplicationReadyEvent.class)
    public void warmDashboardSummary() {
        long start = System.currentTimeMillis();
        try {
            reportController.getTotalCharge();
            log.info("dashboard summary warmup finished in {} ms", System.currentTimeMillis() - start);
        } catch (Exception e) {
            log.warn("dashboard summary warmup failed", e);
        }
    }
}
