package com.energy.manage.service.task;

import com.energy.manage.service.service.vibration.VibrationService;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Slf4j
@Component
public class SkfVibrationDataTask {

    @Autowired
    private VibrationService vibrationService;

    // 定义时间格式
    private final String dateTimeFormatter = "yyyyMMdd";

    /**
     * 开始定时器
     */
    @XxlJob(value = "skfVibrationData")
    public void skfVibrationData() {

        log.info(getCurrentDateTim() + "开始抽取skf测点数据 ");

        // 获取昨天的时间
        String yesterdayDate = LocalDate.now().minusDays(1).format(DateTimeFormatter.ofPattern(dateTimeFormatter));
        // vibrationService.extractSkfPointData();

        // 故障频率
//        vibrationService.extracTwindGeneratorSkfMachinePart(yesterdayDate);

        // 振动测点
        vibrationService.extracTwindGeneratorSkfPointData(yesterdayDate);

        log.info(getCurrentDateTim() + "结束抽取skf测点数据 ");
    }


    private String getCurrentDateTim() {
        // 1. 获取当前系统的日期时间（不含时区，适用于本地时间场景）
        LocalDateTime now = LocalDateTime.now();
        System.out.println("当前原始时间：" + now);
        // 2. 定义常用的日期时间格式器（可根据需求自定义格式）
        DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        // 3. 格式化日期时间
        return now.format(formatter1);
    }


}
