package com.usky.cdi.service.util;

import com.usky.cdi.service.impl.IotDataTransferService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 设备数据同步组件（包含定时任务）
 */
@Slf4j
@Component
public class DeviceDataSyncService {

    private final IotDataTransferService iotDataTransferService;

    @Autowired
    public DeviceDataSyncService(IotDataTransferService iotDataTransferService) {
        this.iotDataTransferService = iotDataTransferService;
    }

    /**
     * 定时任务：定期执行设备数据同步上报
     * fixedDelay：任务执行完成后固定延迟29分钟执行下一次
     * initialDelay：初始化后立即执行第一次任务
     */
    // @Scheduled(fixedDelay = 10 * 60 * 1000, initialDelay = 0)
    // public void scheduledDeviceDataSync() {
    //     Integer tenantId = 1222;
    //     Long engineeringId = 3101100021L;
    //     String username = "3101100021";
    //     String password = "SIixzph1";
    //     log.info("开始执行桃浦象屿人防设备数据同步定时任务，租户ID：{}，工程ID：{}", tenantId, engineeringId);
    //
    //     try {
    //         iotDataTransferService.synchronizeDeviceData(tenantId, engineeringId, username, password);
    //     } catch (Exception e) {
    //         log.error("定时任务执行设备数据同步失败：{}", e.getMessage(), e);
    //     }
    // }
}