package com.xzzn.quartz.task;

import com.xzzn.common.utils.StringUtils;
import com.xzzn.ems.service.impl.DeviceDataProcessServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component("calcPointTask")
public class CalcPointTask {

    private static final Logger log = LoggerFactory.getLogger(CalcPointTask.class);

    @Autowired
    private DeviceDataProcessServiceImpl deviceDataProcessService;

    public void syncAllSites() {
        log.info("开始执行计算点轮询任务-全站点");
        deviceDataProcessService.syncCalcPointDataFromInfluxByQuartz();
        log.info("结束执行计算点轮询任务-全站点");
    }

    public void syncBySite(String siteId) {
        if (StringUtils.isBlank(siteId)) {
            log.warn("计算点轮询任务参数为空，转为全站点执行");
            syncAllSites();
            return;
        }
        String normalizedSiteId = siteId.trim();
        log.info("开始执行计算点轮询任务-单站点, siteId: {}", normalizedSiteId);
        deviceDataProcessService.syncCalcPointDataFromInfluxByQuartz(normalizedSiteId);
        log.info("结束执行计算点轮询任务-单站点, siteId: {}", normalizedSiteId);
    }
}
