package com.sptg.video.cloud.biz.quartz;

import com.sptg.video.cloud.api.dto.VCDeviceDto;
import com.sptg.video.cloud.api.entity.SysParams;
import com.sptg.video.cloud.biz.service.VCDeviceServiceInterface;
import com.sptg.video.cloud.biz.service.VCSysParamsServiceInterface;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Profile;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author zwx
 * @create 2020/12/7 19:02
 */
@Slf4j
@Component
@AllArgsConstructor
@Profile({"prod"})
public class VCDeviceSyncQuartzTask {

    private final VCDeviceServiceInterface vcDeviceServiceInterface;
    private final VCSysParamsServiceInterface vcSysParamsServiceInterface;

    //每天凌晨0点执行一次
    @Scheduled(cron = "0 0 0 * * *")
    public void run(){
        List<SysParams> sysParamsList = vcSysParamsServiceInterface.getList();
        sysParamsList.forEach(sysParams -> {
            VCDeviceDto vcDeviceDto = new VCDeviceDto();
            vcDeviceDto.setAccountName(sysParams.getAccount());
            this.vcDeviceServiceInterface.syncDeviceList(sysParams, vcDeviceDto);
        });
    }
}
