package com.ruoyi.task.device;

import com.ruoyi.ss.meterReadingRecord.service.ISmMeterReadingRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.concurrent.Executors;

/**
 * @author wjh
 * 2024/4/3
 */
@Component
@Slf4j
public class DeviceStartTask implements ApplicationRunner {

    @Autowired
    private ISmMeterReadingRecordService smMeterReadingRecordService;

    @Value("${device.startRecord}")
    private Boolean startRecord;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        // 异步抄表
        Executors.newSingleThreadExecutor().execute(new Runnable() {
            @Override
            public void run() {
                if (startRecord) {
                    log.info("项目启动时进行抄表");
                    smMeterReadingRecordService.record(null);
                    log.info("项目启动抄表结束");
                }
            }
        });
    }
}
